2008-04-09 08:57:26 -04:00
/****************************************************************
* RetroShare is distributed under the following license :
*
* Copyright ( C ) 2008 Robert Fernie
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
2010-05-01 15:03:35 -04:00
* Foundation , Inc . , 51 Franklin Street , Fifth Floor ,
2008-04-09 08:57:26 -04:00
* Boston , MA 02110 - 1301 , USA .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "ForumsDialog.h"
2010-03-10 16:38:26 -05:00
# include "gui/RetroShareLink.h"
2008-04-15 12:40:38 -04:00
# include "gui/forums/CreateForum.h"
# include "gui/forums/CreateForumMsg.h"
2010-01-02 10:47:07 -05:00
# include "gui/forums/ForumDetails.h"
2010-01-09 11:33:00 -05:00
# include "msgs/ChanMsgDialog.h"
2008-04-09 08:57:26 -04:00
# include "rsiface/rsiface.h"
# include "rsiface/rspeers.h"
# include "rsiface/rsmsgs.h"
# include "rsiface/rsforums.h"
2010-01-04 09:29:49 -05:00
2010-05-19 16:17:43 -04:00
# include "settings/rsettings.h"
2008-04-09 08:57:26 -04:00
# include <sstream>
2008-11-02 10:20:42 -05:00
# include <algorithm>
2008-04-09 08:57:26 -04:00
2010-01-04 09:29:49 -05:00
# include <QtGui>
2008-04-09 08:57:26 -04:00
/* Images for context menu icons */
# define IMAGE_MESSAGE ": / images / folder-draft.png"
# define IMAGE_MESSAGEREPLY ": / images / mail_reply.png"
# define IMAGE_MESSAGEREMOVE ": / images / mail_delete.png"
# define IMAGE_DOWNLOAD ": / images / start.png"
# define IMAGE_DOWNLOADALL ": / images / startall.png"
2008-11-26 19:01:46 -05:00
/* Images for TreeWidget */
2008-08-12 08:03:23 -04:00
# define IMAGE_FOLDER ": / images / folder16.png"
2008-08-16 21:09:32 -04:00
# define IMAGE_FOLDERGREEN ": / images / folder_green.png"
# define IMAGE_FOLDERRED ": / images / folder_red.png"
# define IMAGE_FOLDERYELLOW ": / images / folder_yellow.png"
2008-08-12 08:03:23 -04:00
# define IMAGE_FORUM ": / images / konversation16.png"
2009-08-13 09:35:18 -04:00
# define IMAGE_SUBSCRIBE ": / images / edit_add24.png"
2008-08-12 17:07:41 -04:00
# define IMAGE_UNSUBSCRIBE ": / images / cancel.png"
# define IMAGE_INFO ": / images / info16.png"
# define IMAGE_NEWFORUM ": / images / new_forum16.png"
2010-01-01 13:58:39 -05:00
# define IMAGE_FORUMAUTHD ": / images / konv_message2.png"
2008-08-12 17:07:41 -04:00
2010-05-19 16:17:43 -04:00
# define VIEW_LAST_POST 0
# define VIEW_THREADED 1
# define VIEW_FLAT 2
2008-08-12 17:07:41 -04:00
2010-05-19 16:17:43 -04:00
# define COLUMN_COUNT 7
# define COLUMN_DATE 0
# define COLUMN_TITLE 1
# define COLUMN_AUTHOR 2
# define COLUMN_SIGNED 3
# define COLUMN_PARENTID 4
# define COLUMN_MSGID 5
# define COLUMN_CONTENT 6
static int FilterColumnFromComboBox ( int nIndex )
{
switch ( nIndex ) {
case 0 :
return COLUMN_DATE ;
case 1 :
return COLUMN_TITLE ;
case 2 :
return COLUMN_AUTHOR ;
case 3 :
return COLUMN_CONTENT ;
}
2008-08-12 17:07:41 -04:00
2010-05-19 16:17:43 -04:00
return COLUMN_TITLE ;
}
static int FilterColumnToComboBox ( int nIndex )
{
switch ( nIndex ) {
case COLUMN_DATE :
return 0 ;
case COLUMN_TITLE :
return 1 ;
case COLUMN_AUTHOR :
return 2 ;
case COLUMN_CONTENT :
return 3 ;
}
return FilterColumnToComboBox ( COLUMN_TITLE ) ;
}
2008-04-09 08:57:26 -04:00
/** Constructor */
2008-11-26 19:01:46 -05:00
ForumsDialog : : ForumsDialog ( QWidget * parent )
2008-04-09 08:57:26 -04:00
: MainPage ( parent )
{
2010-05-19 16:17:43 -04:00
/* Invoke the Qt Designer generated object setup routine */
ui . setupUi ( this ) ;
2008-04-09 08:57:26 -04:00
2010-05-19 16:17:43 -04:00
connect ( ui . forumTreeWidget , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( forumListCustomPopupMenu ( QPoint ) ) ) ;
connect ( ui . threadTreeWidget , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( threadListCustomPopupMenu ( QPoint ) ) ) ;
2008-04-09 08:57:26 -04:00
2010-05-19 16:17:43 -04:00
connect ( ui . actionCreate_Forum , SIGNAL ( triggered ( ) ) , this , SLOT ( newforum ( ) ) ) ;
connect ( ui . newmessageButton , SIGNAL ( clicked ( ) ) , this , SLOT ( createmessage ( ) ) ) ;
connect ( ui . newthreadButton , SIGNAL ( clicked ( ) ) , this , SLOT ( showthread ( ) ) ) ;
2008-04-15 12:40:38 -04:00
2010-05-19 16:17:43 -04:00
connect ( ui . forumTreeWidget , SIGNAL ( currentItemChanged ( QTreeWidgetItem * , QTreeWidgetItem * ) ) , this , SLOT ( changedForum ( QTreeWidgetItem * , QTreeWidgetItem * ) ) ) ;
2008-04-15 12:40:38 -04:00
2010-05-19 16:17:43 -04:00
connect ( ui . threadTreeWidget , SIGNAL ( itemSelectionChanged ( ) ) , this , SLOT ( changedThread ( ) ) ) ;
connect ( ui . viewBox , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( changedViewBox ( ) ) ) ;
connect ( ui . postText , SIGNAL ( anchorClicked ( const QUrl & ) ) , SLOT ( anchorClicked ( const QUrl & ) ) ) ;
2008-04-15 12:40:38 -04:00
2010-05-19 16:17:43 -04:00
connect ( ui . expandButton , SIGNAL ( clicked ( ) ) , this , SLOT ( togglethreadview ( ) ) ) ;
connect ( ui . previousButton , SIGNAL ( clicked ( ) ) , this , SLOT ( previousMessage ( ) ) ) ;
connect ( ui . nextButton , SIGNAL ( clicked ( ) ) , this , SLOT ( nextMessage ( ) ) ) ;
2010-01-14 08:03:43 -05:00
2010-05-19 16:17:43 -04:00
connect ( ui . clearButton , SIGNAL ( clicked ( ) ) , this , SLOT ( clearFilter ( ) ) ) ;
connect ( ui . filterPatternLineEdit , SIGNAL ( textChanged ( const QString & ) ) , this , SLOT ( filterRegExpChanged ( ) ) ) ;
connect ( ui . filterColumnComboBox , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( filterColumnChanged ( ) ) ) ;
2008-04-15 12:40:38 -04:00
2010-05-19 16:17:43 -04:00
QTimer * timer = new QTimer ( this ) ;
timer - > connect ( timer , SIGNAL ( timeout ( ) ) , this , SLOT ( checkUpdate ( ) ) ) ;
timer - > start ( 1000 ) ;
2008-04-15 12:40:38 -04:00
2010-05-19 16:17:43 -04:00
/* Set header resize modes and initial section sizes */
QHeaderView * ftheader = ui . forumTreeWidget - > header ( ) ;
ftheader - > setResizeMode ( 0 , QHeaderView : : Interactive ) ;
2010-05-01 15:03:35 -04:00
2010-05-19 16:17:43 -04:00
ftheader - > resizeSection ( 0 , 170 ) ;
2010-05-01 15:03:35 -04:00
2010-05-19 16:17:43 -04:00
/* Set header resize modes and initial section sizes */
QHeaderView * ttheader = ui . threadTreeWidget - > header ( ) ;
ttheader - > setResizeMode ( 0 , QHeaderView : : Interactive ) ;
2010-05-01 15:03:35 -04:00
2010-05-19 16:17:43 -04:00
ttheader - > resizeSection ( COLUMN_DATE , 170 ) ;
ttheader - > resizeSection ( COLUMN_TITLE , 170 ) ;
ttheader - > hideSection ( COLUMN_CONTENT ) ;
2008-08-12 08:24:47 -04:00
2009-09-13 09:25:24 -04:00
2010-05-19 16:17:43 -04:00
m_ForumNameFont = QFont ( " Times " , 12 , QFont : : Bold ) ;
ui . forumName - > setFont ( m_ForumNameFont ) ;
ui . threadTitle - > setFont ( m_ForumNameFont ) ;
2010-05-01 15:03:35 -04:00
2010-05-19 16:17:43 -04:00
loadForumEmoticons ( ) ;
2010-05-01 15:03:35 -04:00
2010-05-19 16:17:43 -04:00
QMenu * forummenu = new QMenu ( ) ;
forummenu - > addAction ( ui . actionCreate_Forum ) ;
forummenu - > addSeparator ( ) ;
ui . forumpushButton - > setMenu ( forummenu ) ;
2010-05-01 15:03:35 -04:00
2010-05-19 16:17:43 -04:00
ui . postText - > setOpenExternalLinks ( false ) ;
ui . postText - > setOpenLinks ( false ) ;
2010-05-01 15:03:35 -04:00
/* create forum tree */
m_ItemFont = QFont ( " ARIAL " , 10 ) ;
m_ItemFont . setBold ( true ) ;
QList < QTreeWidgetItem * > TopList ;
YourForums = new QTreeWidgetItem ( ) ;
YourForums - > setText ( 0 , tr ( " Your Forums " ) ) ;
YourForums - > setFont ( 0 , m_ItemFont ) ;
YourForums - > setIcon ( 0 , ( QIcon ( IMAGE_FOLDER ) ) ) ;
TopList . append ( YourForums ) ;
SubscribedForums = new QTreeWidgetItem ( ( QTreeWidget * ) 0 ) ;
SubscribedForums - > setText ( 0 , tr ( " Subscribed Forums " ) ) ;
SubscribedForums - > setFont ( 0 , m_ItemFont ) ;
SubscribedForums - > setIcon ( 0 , ( QIcon ( IMAGE_FOLDERRED ) ) ) ;
TopList . append ( SubscribedForums ) ;
PopularForums = new QTreeWidgetItem ( ) ;
PopularForums - > setText ( 0 , tr ( " Popular Forums " ) ) ;
PopularForums - > setFont ( 0 , m_ItemFont ) ;
PopularForums - > setIcon ( 0 , ( QIcon ( IMAGE_FOLDERGREEN ) ) ) ;
TopList . append ( PopularForums ) ;
OtherForums = new QTreeWidgetItem ( ) ;
OtherForums - > setText ( 0 , tr ( " Other Forums " ) ) ;
OtherForums - > setFont ( 0 , m_ItemFont ) ;
OtherForums - > setIcon ( 0 , ( QIcon ( IMAGE_FOLDERYELLOW ) ) ) ;
TopList . append ( OtherForums ) ;
ui . forumTreeWidget - > addTopLevelItems ( TopList ) ;
YourForums - > setExpanded ( true ) ;
SubscribedForums - > setExpanded ( true ) ;
m_LastViewType = - 1 ;
2008-04-09 08:57:26 -04:00
2010-05-19 16:17:43 -04:00
ui . clearButton - > hide ( ) ;
// load settings
processSettings ( true ) ;
2008-04-09 08:57:26 -04:00
/* Hide platform specific features */
# ifdef Q_WS_WIN
# endif
}
2010-05-19 16:17:43 -04:00
ForumsDialog : : ~ ForumsDialog ( )
{
// save settings
processSettings ( false ) ;
}
void ForumsDialog : : processSettings ( bool bLoad )
{
QHeaderView * pHeader = ui . threadTreeWidget - > header ( ) ;
RSettings settings ( QString ( " ForumsDialog " ) ) ;
if ( bLoad ) {
// load settings
// expandFiles
bool bValue = settings . value ( " expandButton " , true ) . toBool ( ) ;
ui . expandButton - > setChecked ( bValue ) ;
togglethreadview_internal ( ) ;
// filterColumn
int nValue = FilterColumnToComboBox ( settings . value ( " filterColumn " , true ) . toInt ( ) ) ;
ui . filterColumnComboBox - > setCurrentIndex ( nValue ) ;
// index of viewBox
ui . viewBox - > setCurrentIndex ( settings . value ( " viewBox " , VIEW_THREADED ) . toInt ( ) ) ;
// state of thread tree
pHeader - > restoreState ( settings . value ( " ThreadTree " ) . toByteArray ( ) ) ;
// state of splitter
ui . splitter - > restoreState ( settings . value ( " Splitter " ) . toByteArray ( ) ) ;
ui . threadSplitter - > restoreState ( settings . value ( " threadSplitter " ) . toByteArray ( ) ) ;
} else {
// save settings
// state of thread tree
settings . setValue ( " ThreadTree " , pHeader - > saveState ( ) ) ;
// state of splitter
settings . setValue ( " Splitter " , ui . splitter - > saveState ( ) ) ;
settings . setValue ( " threadSplitter " , ui . threadSplitter - > saveState ( ) ) ;
}
}
2008-04-09 08:57:26 -04:00
void ForumsDialog : : forumListCustomPopupMenu ( QPoint point )
{
2010-05-01 15:03:35 -04:00
QMenu contextMnu ( this ) ;
QAction * subForumAct = new QAction ( QIcon ( IMAGE_SUBSCRIBE ) , tr ( " Subscribe to Forum " ) , this ) ;
subForumAct - > setDisabled ( true ) ;
connect ( subForumAct , SIGNAL ( triggered ( ) ) , this , SLOT ( subscribeToForum ( ) ) ) ;
QAction * unsubForumAct = new QAction ( QIcon ( IMAGE_UNSUBSCRIBE ) , tr ( " Unsubscribe to Forum " ) , this ) ;
unsubForumAct - > setDisabled ( true ) ;
connect ( unsubForumAct , SIGNAL ( triggered ( ) ) , this , SLOT ( unsubscribeToForum ( ) ) ) ;
QAction * newForumAct = new QAction ( QIcon ( IMAGE_NEWFORUM ) , tr ( " New Forum " ) , this ) ;
connect ( newForumAct , SIGNAL ( triggered ( ) ) , this , SLOT ( newforum ( ) ) ) ;
QAction * detailsForumAct = new QAction ( QIcon ( IMAGE_INFO ) , tr ( " Show Forum Details " ) , this ) ;
detailsForumAct - > setDisabled ( true ) ;
connect ( detailsForumAct , SIGNAL ( triggered ( ) ) , this , SLOT ( showForumDetails ( ) ) ) ;
ForumInfo fi ;
if ( rsForums & & ! mCurrForumId . empty ( ) ) {
if ( rsForums - > getForumInfo ( mCurrForumId , fi ) ) {
if ( ( fi . subscribeFlags & ( RS_DISTRIB_ADMIN | RS_DISTRIB_SUBSCRIBED ) ) = = 0 ) {
subForumAct - > setEnabled ( true ) ;
}
if ( ( fi . subscribeFlags & ( RS_DISTRIB_ADMIN | RS_DISTRIB_SUBSCRIBED ) ) ! = 0 ) {
unsubForumAct - > setEnabled ( true ) ;
}
}
}
2008-04-09 08:57:26 -04:00
2010-05-01 15:03:35 -04:00
if ( ! mCurrForumId . empty ( ) ) {
detailsForumAct - > setEnabled ( true ) ;
}
2010-01-02 17:50:56 -05:00
2010-05-01 15:03:35 -04:00
contextMnu . addAction ( subForumAct ) ;
contextMnu . addAction ( unsubForumAct ) ;
contextMnu . addSeparator ( ) ;
contextMnu . addAction ( newForumAct ) ;
contextMnu . addAction ( detailsForumAct ) ;
2010-05-14 16:55:44 -04:00
contextMnu . exec ( QCursor : : pos ( ) ) ;
2008-04-09 08:57:26 -04:00
}
void ForumsDialog : : threadListCustomPopupMenu ( QPoint point )
{
2010-05-01 15:03:35 -04:00
QMenu contextMnu ( this ) ;
2008-04-09 08:57:26 -04:00
2010-05-01 15:03:35 -04:00
QAction * replyAct = new QAction ( QIcon ( IMAGE_MESSAGEREPLY ) , tr ( " Reply " ) , this ) ;
replyAct - > setDisabled ( true ) ;
connect ( replyAct , SIGNAL ( triggered ( ) ) , this , SLOT ( createmessage ( ) ) ) ;
2008-04-09 08:57:26 -04:00
2010-05-01 15:03:35 -04:00
QAction * viewAct = new QAction ( QIcon ( IMAGE_DOWNLOADALL ) , tr ( " Start New Thread " ) , this ) ;
viewAct - > setDisabled ( true ) ;
connect ( viewAct , SIGNAL ( triggered ( ) ) , this , SLOT ( showthread ( ) ) ) ;
2008-04-09 08:57:26 -04:00
2010-05-01 15:03:35 -04:00
QAction * replyauthorAct = new QAction ( QIcon ( IMAGE_MESSAGEREPLY ) , tr ( " Reply to Author " ) , this ) ;
replyauthorAct - > setDisabled ( true ) ;
connect ( replyauthorAct , SIGNAL ( triggered ( ) ) , this , SLOT ( replytomessage ( ) ) ) ;
2008-04-09 08:57:26 -04:00
2010-05-01 15:03:35 -04:00
QAction * expandAll = new QAction ( tr ( " Expand all " ) , this ) ;
connect ( expandAll , SIGNAL ( triggered ( ) ) , ui . threadTreeWidget , SLOT ( expandAll ( ) ) ) ;
2008-04-09 08:57:26 -04:00
2010-05-01 15:03:35 -04:00
QAction * collapseAll = new QAction ( tr ( " Collapse all " ) , this ) ;
connect ( collapseAll , SIGNAL ( triggered ( ) ) , ui . threadTreeWidget , SLOT ( collapseAll ( ) ) ) ;
if ( ! mCurrForumId . empty ( ) ) {
viewAct - > setEnabled ( true ) ;
if ( ! mCurrPostId . empty ( ) ) {
replyAct - > setEnabled ( true ) ;
replyauthorAct - > setEnabled ( true ) ;
}
}
contextMnu . addAction ( replyAct ) ;
contextMnu . addAction ( viewAct ) ;
contextMnu . addAction ( replyauthorAct ) ;
contextMnu . addSeparator ( ) ;
contextMnu . addAction ( expandAll ) ;
contextMnu . addAction ( collapseAll ) ;
2010-05-14 16:55:44 -04:00
contextMnu . exec ( QCursor : : pos ( ) ) ;
2008-04-09 08:57:26 -04:00
}
2010-05-19 16:17:43 -04:00
void ForumsDialog : : togglethreadview ( )
2008-04-09 08:57:26 -04:00
{
2010-05-19 16:17:43 -04:00
// save state of button
RSettings settings ( QString ( " ForumsDialog " ) ) ;
settings . setValue ( " expandButton " , ui . expandButton - > isChecked ( ) ) ;
2008-04-09 08:57:26 -04:00
2010-05-19 16:17:43 -04:00
togglethreadview_internal ( ) ;
}
2008-04-09 08:57:26 -04:00
2010-05-19 16:17:43 -04:00
void ForumsDialog : : togglethreadview_internal ( )
{
if ( ui . expandButton - > isChecked ( ) ) {
ui . postText - > setVisible ( true ) ;
ui . expandButton - > setIcon ( QIcon ( QString ( " :/images/edit_remove24.png " ) ) ) ;
ui . expandButton - > setToolTip ( " Hide " ) ;
} else {
ui . postText - > setVisible ( false ) ;
ui . expandButton - > setIcon ( QIcon ( QString ( " :/images/edit_add24.png " ) ) ) ;
ui . expandButton - > setToolTip ( " Expand " ) ;
}
2008-04-15 12:40:38 -04:00
}
void ForumsDialog : : checkUpdate ( )
{
2010-05-19 16:17:43 -04:00
std : : list < std : : string > forumIds ;
std : : list < std : : string > : : iterator it ;
if ( ! rsForums )
return ;
2008-04-15 12:40:38 -04:00
2010-05-19 16:17:43 -04:00
if ( rsForums - > forumsChanged ( forumIds ) )
{
/* update Forums List */
insertForums ( ) ;
it = std : : find ( forumIds . begin ( ) , forumIds . end ( ) , mCurrForumId ) ;
if ( it ! = forumIds . end ( ) )
{
/* update threads as well */
insertThreads ( ) ;
}
}
2008-04-09 08:57:26 -04:00
}
2010-05-01 15:03:35 -04:00
static void CleanupItems ( QList < QTreeWidgetItem * > & Items )
2008-04-09 08:57:26 -04:00
{
2010-05-01 15:03:35 -04:00
QList < QTreeWidgetItem * > : : iterator Item ;
for ( Item = Items . begin ( ) ; Item ! = Items . end ( ) ; Item + + ) {
2010-05-17 17:42:18 -04:00
if ( * Item ) {
delete ( * Item ) ;
}
2010-05-01 15:03:35 -04:00
}
2008-04-09 08:57:26 -04:00
}
void ForumsDialog : : insertForums ( )
{
std : : list < ForumInfo > forumList ;
std : : list < ForumInfo > : : iterator it ;
if ( ! rsForums )
{
return ;
}
rsForums - > getForumList ( forumList ) ;
QList < QTreeWidgetItem * > AdminList ;
QList < QTreeWidgetItem * > SubList ;
QList < QTreeWidgetItem * > PopList ;
QList < QTreeWidgetItem * > OtherList ;
std : : multimap < uint32_t , std : : string > popMap ;
for ( it = forumList . begin ( ) ; it ! = forumList . end ( ) ; it + + )
{
/* sort it into Publish (Own), Subscribed, Popular and Other */
2008-12-05 19:30:56 -05:00
uint32_t flags = it - > subscribeFlags ;
2008-04-09 08:57:26 -04:00
2008-06-13 11:46:34 -04:00
if ( flags & RS_DISTRIB_ADMIN )
2008-04-09 08:57:26 -04:00
{
/* own */
2010-05-01 15:03:35 -04:00
/* Name,
2008-04-09 08:57:26 -04:00
* Type ,
* Rank ,
* LastPost
* ForumId ,
*/
QTreeWidgetItem * item = new QTreeWidgetItem ( ( QTreeWidget * ) 0 ) ;
2008-12-05 19:30:56 -05:00
QString name = QString : : fromStdWString ( it - > forumName ) ;
if ( it - > forumFlags & RS_DISTRIB_AUTHEN_REQ )
{
name + = " (AUTHD) " ;
2010-01-01 13:58:39 -05:00
item - > setIcon ( 0 , ( QIcon ( IMAGE_FORUMAUTHD ) ) ) ;
2008-12-05 19:30:56 -05:00
}
2010-01-01 13:58:39 -05:00
else
{
item - > setIcon ( 0 , ( QIcon ( IMAGE_FORUM ) ) ) ;
}
2010-05-01 15:03:35 -04:00
2008-12-05 19:30:56 -05:00
item - > setText ( 0 , name ) ;
2008-04-09 08:57:26 -04:00
/* (1) Popularity */
{
std : : ostringstream out ;
out < < it - > pop ;
2010-01-02 12:31:43 -05:00
item - > setToolTip ( 0 , tr ( " Popularity: " ) + QString : : fromStdString ( out . str ( ) ) ) ;
2008-04-09 08:57:26 -04:00
}
2010-05-01 15:03:35 -04:00
// Date
2008-04-09 08:57:26 -04:00
{
QDateTime qtime ;
qtime . setTime_t ( it - > lastPost ) ;
QString timestamp = qtime . toString ( " yyyy-MM-dd hh:mm:ss " ) ;
2010-01-02 17:50:56 -05:00
item - > setText ( 1 , timestamp ) ;
2008-04-09 08:57:26 -04:00
}
// Id.
item - > setText ( 4 , QString : : fromStdString ( it - > forumId ) ) ;
AdminList . append ( item ) ;
}
2008-06-13 11:46:34 -04:00
else if ( flags & RS_DISTRIB_SUBSCRIBED )
2008-04-09 08:57:26 -04:00
{
/* subscribed forum */
2010-05-01 15:03:35 -04:00
/* Name,
2008-04-09 08:57:26 -04:00
* Type ,
* Rank ,
* LastPost
* ForumId ,
*/
QTreeWidgetItem * item = new QTreeWidgetItem ( ( QTreeWidget * ) 0 ) ;
2008-12-05 19:30:56 -05:00
QString name = QString : : fromStdWString ( it - > forumName ) ;
if ( it - > forumFlags & RS_DISTRIB_AUTHEN_REQ )
{
name + = " (AUTHD) " ;
2010-01-01 13:58:39 -05:00
item - > setIcon ( 0 , ( QIcon ( IMAGE_FORUMAUTHD ) ) ) ;
}
else
{
item - > setIcon ( 0 , ( QIcon ( IMAGE_FORUM ) ) ) ;
2008-12-05 19:30:56 -05:00
}
2010-05-01 15:03:35 -04:00
2008-12-05 19:30:56 -05:00
item - > setText ( 0 , name ) ;
2008-04-09 08:57:26 -04:00
/* (1) Popularity */
{
std : : ostringstream out ;
out < < it - > pop ;
2010-01-02 07:24:59 -05:00
item - > setToolTip ( 0 , tr ( " Popularity: " ) + QString : : fromStdString ( out . str ( ) ) ) ;
2008-04-09 08:57:26 -04:00
}
2010-05-01 15:03:35 -04:00
// Date
2008-04-09 08:57:26 -04:00
{
QDateTime qtime ;
qtime . setTime_t ( it - > lastPost ) ;
QString timestamp = qtime . toString ( " yyyy-MM-dd hh:mm:ss " ) ;
item - > setText ( 3 , timestamp ) ;
}
// Id.
item - > setText ( 4 , QString : : fromStdString ( it - > forumId ) ) ;
SubList . append ( item ) ;
}
else
{
/* rate the others by popularity */
popMap . insert ( std : : make_pair ( it - > pop , it - > forumId ) ) ;
}
}
/* iterate backwards through popMap - take the top 5 or 10% of list */
uint32_t popCount = 5 ;
if ( popCount < popMap . size ( ) / 10 )
{
popCount = popMap . size ( ) / 10 ;
}
uint32_t i = 0 ;
uint32_t popLimit = 0 ;
std : : multimap < uint32_t , std : : string > : : reverse_iterator rit ;
for ( rit = popMap . rbegin ( ) ; ( ( rit ! = popMap . rend ( ) ) & & ( i < popCount ) ) ; rit + + , i + + ) ;
if ( rit ! = popMap . rend ( ) )
{
popLimit = rit - > first ;
}
for ( it = forumList . begin ( ) ; it ! = forumList . end ( ) ; it + + )
{
/* ignore the ones we've done already */
2008-12-05 19:30:56 -05:00
uint32_t flags = it - > subscribeFlags ;
2008-04-09 08:57:26 -04:00
2008-06-13 11:46:34 -04:00
if ( flags & RS_DISTRIB_ADMIN )
2008-04-09 08:57:26 -04:00
{
continue ;
}
2008-06-13 11:46:34 -04:00
else if ( flags & RS_DISTRIB_SUBSCRIBED )
2008-04-09 08:57:26 -04:00
{
continue ;
}
else
{
2010-01-02 12:31:43 -05:00
/* popular forum */
2010-05-01 15:03:35 -04:00
/* Name,
2008-04-09 08:57:26 -04:00
* Type ,
* Rank ,
* LastPost
* ForumId ,
*/
QTreeWidgetItem * item = new QTreeWidgetItem ( ( QTreeWidget * ) 0 ) ;
2008-12-05 19:30:56 -05:00
QString name = QString : : fromStdWString ( it - > forumName ) ;
if ( it - > forumFlags & RS_DISTRIB_AUTHEN_REQ )
{
name + = " (AUTHD) " ;
2010-01-01 13:58:39 -05:00
item - > setIcon ( 0 , ( QIcon ( IMAGE_FORUMAUTHD ) ) ) ;
}
else
{
item - > setIcon ( 0 , ( QIcon ( IMAGE_FORUM ) ) ) ;
2008-12-05 19:30:56 -05:00
}
2010-05-01 15:03:35 -04:00
2008-12-05 19:30:56 -05:00
item - > setText ( 0 , name ) ;
2010-05-01 15:03:35 -04:00
2008-12-05 19:30:56 -05:00
2008-04-09 08:57:26 -04:00
/* (1) Popularity */
{
std : : ostringstream out ;
out < < it - > pop ;
2010-01-02 08:36:40 -05:00
item - > setToolTip ( 0 , tr ( " Popularity: " ) + QString : : fromStdString ( out . str ( ) ) ) ;
2008-04-09 08:57:26 -04:00
}
2010-05-01 15:03:35 -04:00
// Date
2008-04-09 08:57:26 -04:00
{
QDateTime qtime ;
qtime . setTime_t ( it - > lastPost ) ;
QString timestamp = qtime . toString ( " yyyy-MM-dd hh:mm:ss " ) ;
item - > setText ( 3 , timestamp ) ;
}
// Id.
item - > setText ( 4 , QString : : fromStdString ( it - > forumId ) ) ;
if ( it - > pop < popLimit )
{
OtherList . append ( item ) ;
}
else
{
PopList . append ( item ) ;
}
}
}
/* now we can add them in as a tree! */
2010-05-01 15:03:35 -04:00
FillForums ( YourForums , AdminList ) ;
FillForums ( SubscribedForums , SubList ) ;
FillForums ( PopularForums , PopList ) ;
FillForums ( OtherForums , OtherList ) ;
// cleanup
CleanupItems ( AdminList ) ;
CleanupItems ( SubList ) ;
CleanupItems ( PopList ) ;
CleanupItems ( OtherList ) ;
2008-04-09 08:57:26 -04:00
}
2010-05-01 15:03:35 -04:00
void ForumsDialog : : FillForums ( QTreeWidgetItem * Forum , QList < QTreeWidgetItem * > & ChildList )
2008-04-09 08:57:26 -04:00
{
2010-05-01 15:03:35 -04:00
int ChildIndex ;
int ChildIndexCur = 0 ;
QTreeWidgetItem * Child ;
2010-05-17 17:42:18 -04:00
// iterate all new children
2010-05-01 15:03:35 -04:00
QList < QTreeWidgetItem * > : : iterator NewChild ;
for ( NewChild = ChildList . begin ( ) ; NewChild ! = ChildList . end ( ) ; NewChild + + ) {
// search existing child
int ChildIndexFound = - 1 ;
int ChildCount = Forum - > childCount ( ) ;
for ( ChildIndex = ChildIndexCur ; ChildIndex < ChildCount ; ChildIndex + + ) {
Child = Forum - > child ( ChildIndex ) ;
if ( Child - > text ( 4 ) = = ( * NewChild ) - > text ( 4 ) ) {
// found it
ChildIndexFound = ChildIndex ;
break ;
}
}
if ( ChildIndexFound > = 0 ) {
2010-05-17 17:42:18 -04:00
// delete all children between
2010-05-01 15:03:35 -04:00
while ( ChildIndexCur < ChildIndexFound ) {
Child = Forum - > takeChild ( ChildIndexCur ) ;
delete ( Child ) ;
ChildIndexFound - - ;
}
// set child data
Child = Forum - > child ( ChildIndexFound ) ;
Child - > setIcon ( 0 , ( * NewChild ) - > icon ( 0 ) ) ;
Child - > setToolTip ( 0 , ( * NewChild ) - > toolTip ( 0 ) ) ;
for ( int i = 0 ; i < = 4 ; i + + ) {
Child - > setText ( i , ( * NewChild ) - > text ( i ) ) ;
}
} else {
// insert new child
if ( ChildIndexCur < ChildCount ) {
2010-05-17 17:42:18 -04:00
Forum - > insertChild ( ChildIndexCur , * NewChild ) ;
2010-05-01 15:03:35 -04:00
} else {
2010-05-17 17:42:18 -04:00
Forum - > addChild ( * NewChild ) ;
2010-05-01 15:03:35 -04:00
}
2010-05-17 17:42:18 -04:00
* NewChild = NULL ;
2010-05-01 15:03:35 -04:00
}
ChildIndexCur + + ;
}
// delete rest
while ( ChildIndexCur < Forum - > childCount ( ) ) {
Child = Forum - > takeChild ( ChildIndexCur ) ;
delete ( Child ) ;
}
2008-04-15 12:40:38 -04:00
}
2008-04-09 08:57:26 -04:00
2010-05-01 15:03:35 -04:00
void ForumsDialog : : changedForum ( QTreeWidgetItem * curr , QTreeWidgetItem * prev )
2008-04-15 12:40:38 -04:00
{
2010-05-01 15:03:35 -04:00
insertThreads ( ) ;
2008-04-15 12:40:38 -04:00
}
2008-04-09 08:57:26 -04:00
2010-05-01 15:03:35 -04:00
void ForumsDialog : : changedThread ( )
2008-04-15 12:40:38 -04:00
{
2010-05-01 15:03:35 -04:00
/* just grab the ids of the current item */
QTreeWidgetItem * curr = ui . threadTreeWidget - > currentItem ( ) ;
2008-04-09 08:57:26 -04:00
2010-05-01 15:03:35 -04:00
if ( ( ! curr ) | | ( ! curr - > isSelected ( ) ) ) {
mCurrPostId = " " ;
} else {
2010-05-19 16:17:43 -04:00
mCurrPostId = ( curr - > text ( COLUMN_MSGID ) ) . toStdString ( ) ;
2010-05-01 15:03:35 -04:00
}
insertPost ( ) ;
2008-04-15 12:40:38 -04:00
}
2008-04-09 08:57:26 -04:00
2008-04-15 12:40:38 -04:00
void ForumsDialog : : insertThreads ( )
{
2010-05-19 16:17:43 -04:00
/* get the current Forum */
std : : cerr < < " ForumsDialog::insertThreads() " < < std : : endl ;
2008-04-09 08:57:26 -04:00
2010-05-19 16:17:43 -04:00
QTreeWidgetItem * forumItem = ui . forumTreeWidget - > currentItem ( ) ;
if ( ( ! forumItem ) | | ( forumItem - > parent ( ) = = NULL ) )
{
/* not an actual forum - clear */
ui . threadTreeWidget - > clear ( ) ;
/* when no Thread selected - clear */
ui . forumName - > clear ( ) ;
ui . threadTitle - > clear ( ) ;
ui . postText - > clear ( ) ;
/* clear last stored forumID */
mCurrForumId = " " ;
std : : cerr < < " ForumsDialog::insertThreads() Current Thread Invalid " < < std : : endl ;
2008-04-15 12:40:38 -04:00
2010-05-19 16:17:43 -04:00
return ;
}
2009-09-09 17:17:03 -04:00
2010-05-19 16:17:43 -04:00
/* store forumId */
mCurrForumId = ( forumItem - > text ( 4 ) ) . toStdString ( ) ;
ui . forumName - > setText ( forumItem - > text ( 0 ) ) ;
std : : string fId = mCurrForumId ;
2009-09-09 17:17:03 -04:00
2010-05-19 16:17:43 -04:00
bool flatView = false ;
bool useChildTS = false ;
int ViewType = ui . viewBox - > currentIndex ( ) ;
switch ( ViewType )
{
case VIEW_LAST_POST :
useChildTS = true ;
break ;
case VIEW_FLAT :
flatView = true ;
break ;
default :
case VIEW_THREADED :
break ;
}
2008-12-03 14:39:20 -05:00
2010-05-19 16:17:43 -04:00
int nFilterColumn = FilterColumnFromComboBox ( ui . filterColumnComboBox - > currentIndex ( ) ) ;
2010-05-01 15:03:35 -04:00
2010-05-19 16:17:43 -04:00
std : : list < ThreadInfoSummary > threads ;
std : : list < ThreadInfoSummary > : : iterator tit ;
rsForums - > getForumThreadList ( mCurrForumId , threads ) ;
2010-05-01 15:03:35 -04:00
2010-05-19 16:17:43 -04:00
QList < QTreeWidgetItem * > items ;
for ( tit = threads . begin ( ) ; tit ! = threads . end ( ) ; tit + + )
2010-01-04 11:03:26 -05:00
{
2010-05-19 16:17:43 -04:00
std : : cerr < < " ForumsDialog::insertThreads() Adding TopLevel Thread: mId: " ;
std : : cerr < < tit - > msgId < < std : : endl ;
/* add the top threads */
ForumMsgInfo msg ;
if ( ! rsForums - > getForumMessage ( fId , tit - > threadId , msg ) )
{
std : : cerr < < " ForumsDialog::insertThreads() Failed to Get TopLevel Msg " ;
std : : cerr < < std : : endl ;
continue ;
}
2010-05-01 15:03:35 -04:00
2010-05-19 16:17:43 -04:00
/* add Msg */
/* setup
*
*/
QTreeWidgetItem * item = new QTreeWidgetItem ( ) ;
{
QDateTime qtime ;
if ( useChildTS )
qtime . setTime_t ( tit - > childTS ) ;
else
qtime . setTime_t ( tit - > ts ) ;
QString timestamp = qtime . toString ( " yyyy-MM-dd hh:mm:ss " ) ;
QString txt = timestamp ;
if ( useChildTS )
{
QDateTime qtime2 ;
qtime2 . setTime_t ( tit - > ts ) ;
QString timestamp2 = qtime2 . toString ( " yyyy-MM-dd hh:mm:ss " ) ;
txt + = " / " ;
txt + = timestamp2 ;
}
item - > setText ( COLUMN_DATE , txt ) ;
}
ForumMsgInfo msginfo ;
rsForums - > getForumMessage ( fId , tit - > msgId , msginfo ) ;
2008-04-09 08:57:26 -04:00
2010-05-19 16:17:43 -04:00
item - > setText ( COLUMN_TITLE , QString : : fromStdWString ( tit - > title ) ) ;
2008-04-09 08:57:26 -04:00
2010-05-19 16:17:43 -04:00
if ( rsPeers - > getPeerName ( msginfo . srcId ) ! = " " )
{
item - > setText ( COLUMN_AUTHOR , QString : : fromStdString ( rsPeers - > getPeerName ( msginfo . srcId ) ) ) ;
}
else
{
item - > setText ( COLUMN_AUTHOR , tr ( " Anonymous " ) ) ;
}
2008-04-09 08:57:26 -04:00
2010-05-19 16:17:43 -04:00
if ( msginfo . msgflags & RS_DISTRIB_AUTHEN_REQ )
{
item - > setText ( COLUMN_SIGNED , tr ( " signed " ) ) ;
}
else
{
item - > setText ( COLUMN_SIGNED , tr ( " none " ) ) ;
}
2008-04-09 08:57:26 -04:00
2010-05-19 16:17:43 -04:00
if ( nFilterColumn = = COLUMN_CONTENT ) {
// need content for filter
QTextDocument doc ;
doc . setHtml ( QString : : fromStdWString ( msginfo . msg ) ) ;
item - > setText ( COLUMN_CONTENT , doc . toPlainText ( ) . replace ( QString ( " \n " ) , QString ( " " ) ) ) ;
}
2008-04-09 08:57:26 -04:00
2010-05-19 16:17:43 -04:00
item - > setText ( COLUMN_PARENTID , QString : : fromStdString ( tit - > parentId ) ) ;
item - > setText ( COLUMN_MSGID , QString : : fromStdString ( tit - > msgId ) ) ;
std : : list < QTreeWidgetItem * > threadlist ;
threadlist . push_back ( item ) ;
while ( threadlist . size ( ) > 0 )
{
/* get children */
QTreeWidgetItem * parent = threadlist . front ( ) ;
threadlist . pop_front ( ) ;
std : : string pId = ( parent - > text ( COLUMN_MSGID ) ) . toStdString ( ) ;
std : : list < ThreadInfoSummary > msgs ;
std : : list < ThreadInfoSummary > : : iterator mit ;
std : : cerr < < " ForumsDialog::insertThreads() Getting Children of : " < < pId ;
std : : cerr < < std : : endl ;
if ( rsForums - > getForumThreadMsgList ( fId , pId , msgs ) )
{
std : : cerr < < " ForumsDialog::insertThreads() #Children " < < msgs . size ( ) ;
std : : cerr < < std : : endl ;
/* iterate through child */
for ( mit = msgs . begin ( ) ; mit ! = msgs . end ( ) ; mit + + )
{
std : : cerr < < " ForumsDialog::insertThreads() adding " < < mit - > msgId ;
std : : cerr < < std : : endl ;
QTreeWidgetItem * child = NULL ;
if ( flatView )
{
child = new QTreeWidgetItem ( ) ;
ui . threadTreeWidget - > setRootIsDecorated ( false ) ;
}
else
{
child = new QTreeWidgetItem ( parent ) ;
ui . threadTreeWidget - > setRootIsDecorated ( true ) ;
}
{
QDateTime qtime ;
if ( useChildTS )
qtime . setTime_t ( mit - > childTS ) ;
else
qtime . setTime_t ( mit - > ts ) ;
QString timestamp = qtime . toString ( " yyyy-MM-dd hh:mm:ss " ) ;
QString txt = timestamp ;
if ( useChildTS )
{
QDateTime qtime2 ;
qtime2 . setTime_t ( mit - > ts ) ;
QString timestamp2 = qtime2 . toString ( " yyyy-MM-dd hh:mm:ss " ) ;
txt + = " / " ;
txt + = timestamp2 ;
}
child - > setText ( COLUMN_DATE , txt ) ;
}
ForumMsgInfo msginfo ;
rsForums - > getForumMessage ( fId , mit - > msgId , msginfo ) ;
child - > setText ( COLUMN_TITLE , QString : : fromStdWString ( mit - > title ) ) ;
if ( rsPeers - > getPeerName ( msginfo . srcId ) ! = " " )
{
child - > setText ( COLUMN_AUTHOR , QString : : fromStdString ( rsPeers - > getPeerName ( msginfo . srcId ) ) ) ;
}
else
{
child - > setText ( COLUMN_AUTHOR , tr ( " Anonymous " ) ) ;
}
if ( msginfo . msgflags & RS_DISTRIB_AUTHEN_REQ )
{
child - > setText ( COLUMN_SIGNED , tr ( " signed " ) ) ;
}
else
{
child - > setText ( COLUMN_SIGNED , tr ( " none " ) ) ;
}
if ( nFilterColumn = = COLUMN_CONTENT ) {
// need content for filter
QTextDocument doc ;
doc . setHtml ( QString : : fromStdWString ( msginfo . msg ) ) ;
child - > setText ( COLUMN_CONTENT , doc . toPlainText ( ) . replace ( QString ( " \n " ) , QString ( " " ) ) ) ;
}
child - > setText ( COLUMN_PARENTID , QString : : fromStdString ( mit - > parentId ) ) ;
child - > setText ( COLUMN_MSGID , QString : : fromStdString ( mit - > msgId ) ) ;
/* setup child */
threadlist . push_back ( child ) ;
if ( flatView )
{
items . append ( child ) ;
}
}
}
}
2008-04-09 08:57:26 -04:00
2010-05-19 16:17:43 -04:00
/* add to list */
items . append ( item ) ;
}
2008-04-09 08:57:26 -04:00
2010-05-19 16:17:43 -04:00
ui . postText - > clear ( ) ;
ui . threadTitle - > clear ( ) ;
/* add all messages in! */
if ( m_LastViewType ! = ViewType | | m_LastForumID ! = mCurrForumId ) {
ui . threadTreeWidget - > clear ( ) ;
m_LastViewType = ViewType ;
m_LastForumID = mCurrForumId ;
ui . threadTreeWidget - > insertTopLevelItems ( 0 , items ) ;
} else {
FillThreads ( items ) ;
2010-05-01 15:03:35 -04:00
2010-05-19 16:17:43 -04:00
CleanupItems ( items ) ;
}
2010-05-01 15:03:35 -04:00
2010-05-19 16:17:43 -04:00
if ( ui . filterPatternLineEdit - > text ( ) . isEmpty ( ) = = false ) {
FilterItems ( ) ;
}
2010-05-01 15:03:35 -04:00
2010-05-19 16:17:43 -04:00
insertPost ( ) ;
2008-04-09 08:57:26 -04:00
}
2010-05-01 15:03:35 -04:00
void ForumsDialog : : FillThreads ( QList < QTreeWidgetItem * > & ThreadList )
2008-04-09 08:57:26 -04:00
{
2010-05-12 18:23:05 -04:00
int Index = 0 ;
2010-05-01 15:03:35 -04:00
QTreeWidgetItem * Thread ;
2010-05-17 17:42:18 -04:00
QList < QTreeWidgetItem * > : : iterator NewThread ;
// delete not existing
while ( Index < ui . threadTreeWidget - > topLevelItemCount ( ) ) {
Thread = ui . threadTreeWidget - > topLevelItem ( Index ) ;
// search existing new thread
int Found = - 1 ;
for ( NewThread = ThreadList . begin ( ) ; NewThread ! = ThreadList . end ( ) ; NewThread + + ) {
2010-05-19 16:17:43 -04:00
if ( Thread - > text ( COLUMN_MSGID ) = = ( * NewThread ) - > text ( COLUMN_MSGID ) ) {
2010-05-17 17:42:18 -04:00
// found it
Found = Index ;
break ;
}
}
if ( Found > = 0 ) {
Index + + ;
} else {
delete ( ui . threadTreeWidget - > takeTopLevelItem ( Index ) ) ;
}
}
2010-05-01 15:03:35 -04:00
// iterate all new threads
for ( NewThread = ThreadList . begin ( ) ; NewThread ! = ThreadList . end ( ) ; NewThread + + ) {
// search existing thread
int Found = - 1 ;
int Count = ui . threadTreeWidget - > topLevelItemCount ( ) ;
for ( Index = 0 ; Index < Count ; Index + + ) {
Thread = ui . threadTreeWidget - > topLevelItem ( Index ) ;
2010-05-19 16:17:43 -04:00
if ( Thread - > text ( COLUMN_MSGID ) = = ( * NewThread ) - > text ( COLUMN_MSGID ) ) {
2010-05-01 15:03:35 -04:00
// found it
Found = Index ;
break ;
}
}
if ( Found > = 0 ) {
// set child data
2010-05-19 16:17:43 -04:00
for ( int i = 0 ; i < = COLUMN_COUNT ; i + + ) {
2010-05-01 15:03:35 -04:00
Thread - > setText ( i , ( * NewThread ) - > text ( i ) ) ;
}
// fill recursive
FillChildren ( Thread , * NewThread ) ;
} else {
// add new thread
2010-05-17 17:42:18 -04:00
ui . threadTreeWidget - > addTopLevelItem ( * NewThread ) ;
* NewThread = NULL ;
2010-05-01 15:03:35 -04:00
}
}
2010-05-17 17:42:18 -04:00
}
2010-05-01 15:03:35 -04:00
2010-05-17 17:42:18 -04:00
void ForumsDialog : : FillChildren ( QTreeWidgetItem * Parent , QTreeWidgetItem * NewParent )
{
int Index = 0 ;
int NewIndex ;
int NewCount = NewParent - > childCount ( ) ;
2010-05-01 15:03:35 -04:00
2010-05-17 17:42:18 -04:00
QTreeWidgetItem * Child ;
QTreeWidgetItem * NewChild ;
// delete not existing
while ( Index < Parent - > childCount ( ) ) {
Child = Parent - > child ( Index ) ;
// search existing new child
2010-05-01 15:03:35 -04:00
int Found = - 1 ;
2010-05-17 17:42:18 -04:00
int Count = NewParent - > childCount ( ) ;
for ( NewIndex = 0 ; NewIndex < Count ; NewIndex + + ) {
NewChild = NewParent - > child ( NewIndex ) ;
2010-05-19 16:17:43 -04:00
if ( NewChild - > text ( COLUMN_MSGID ) = = Child - > text ( COLUMN_MSGID ) ) {
2010-05-01 15:03:35 -04:00
// found it
Found = Index ;
break ;
}
}
if ( Found > = 0 ) {
Index + + ;
} else {
2010-05-17 17:42:18 -04:00
delete ( Parent - > takeChild ( Index ) ) ;
2010-05-01 15:03:35 -04:00
}
}
// iterate all new children
for ( NewIndex = 0 ; NewIndex < NewCount ; NewIndex + + ) {
NewChild = NewParent - > child ( NewIndex ) ;
// search existing child
int Found = - 1 ;
int Count = Parent - > childCount ( ) ;
for ( Index = 0 ; Index < Count ; Index + + ) {
Child = Parent - > child ( Index ) ;
2010-05-19 16:17:43 -04:00
if ( Child - > text ( COLUMN_MSGID ) = = NewChild - > text ( COLUMN_MSGID ) ) {
2010-05-01 15:03:35 -04:00
// found it
Found = Index ;
break ;
}
}
if ( Found > = 0 ) {
// set child data
2010-05-19 16:17:43 -04:00
for ( int i = 0 ; i < = COLUMN_COUNT ; i + + ) {
2010-05-01 15:03:35 -04:00
Child - > setText ( i , NewChild - > text ( i ) ) ;
}
// fill recursive
FillChildren ( Child , NewChild ) ;
} else {
// add new child
2010-05-17 17:42:18 -04:00
Parent - > addChild ( NewParent - > takeChild ( NewIndex ) ) ;
NewIndex - - ;
NewCount - - ;
2010-05-01 15:03:35 -04:00
}
}
}
2008-04-09 08:57:26 -04:00
void ForumsDialog : : insertPost ( )
{
2010-05-19 16:17:43 -04:00
if ( ( mCurrForumId = = " " ) | | ( mCurrPostId = = " " ) )
{
ui . postText - > setText ( " " ) ;
ui . threadTitle - > setText ( " " ) ;
ui . previousButton - > setEnabled ( false ) ;
ui . nextButton - > setEnabled ( false ) ;
return ;
}
2008-04-09 08:57:26 -04:00
2010-05-19 16:17:43 -04:00
QTreeWidgetItem * curr = ui . threadTreeWidget - > currentItem ( ) ;
if ( curr ) {
QTreeWidgetItem * Parent = curr - > parent ( ) ;
int Index = Parent ? Parent - > indexOfChild ( curr ) : ui . threadTreeWidget - > indexOfTopLevelItem ( curr ) ;
int Count = Parent ? Parent - > childCount ( ) : ui . threadTreeWidget - > topLevelItemCount ( ) ;
ui . previousButton - > setEnabled ( Index > 0 ) ;
ui . nextButton - > setEnabled ( Index < Count - 1 ) ;
} else {
// there is something wrong
ui . previousButton - > setEnabled ( false ) ;
ui . nextButton - > setEnabled ( false ) ;
}
2010-05-01 15:03:35 -04:00
2010-05-19 16:17:43 -04:00
/* get the Post */
ForumMsgInfo msg ;
if ( ! rsForums - > getForumMessage ( mCurrForumId , mCurrPostId , msg ) )
{
ui . postText - > setText ( " " ) ;
return ;
}
2010-05-01 15:03:35 -04:00
2010-05-19 16:17:43 -04:00
/* get the Thread */
ForumMsgInfo title ;
if ( ! rsForums - > getForumMessage ( mCurrForumId , mCurrPostId , title ) )
{
ui . threadTitle - > setText ( " " ) ;
return ;
}
2010-05-01 15:03:35 -04:00
2010-05-19 16:17:43 -04:00
QString extraTxt ;
extraTxt + = QString : : fromStdWString ( msg . msg ) ;
2010-05-01 15:03:35 -04:00
2010-05-19 16:17:43 -04:00
QHashIterator < QString , QString > i ( smileys ) ;
while ( i . hasNext ( ) )
{
i . next ( ) ;
foreach ( QString code , i . key ( ) . split ( " | " ) )
extraTxt . replace ( code , " <img src= \" " + i . value ( ) + " \" /> " ) ;
}
2008-04-09 08:57:26 -04:00
2010-05-19 16:17:43 -04:00
ui . postText - > setHtml ( extraTxt ) ;
ui . threadTitle - > setText ( QString : : fromStdWString ( title . title ) ) ;
2008-04-09 08:57:26 -04:00
}
2010-05-01 15:03:35 -04:00
void ForumsDialog : : previousMessage ( )
{
QTreeWidgetItem * Item = ui . threadTreeWidget - > currentItem ( ) ;
if ( Item = = NULL ) {
return ;
}
2008-04-09 08:57:26 -04:00
2010-05-01 15:03:35 -04:00
QTreeWidgetItem * Parent = Item - > parent ( ) ;
int Index = Parent ? Parent - > indexOfChild ( Item ) : ui . threadTreeWidget - > indexOfTopLevelItem ( Item ) ;
if ( Index > 0 ) {
QTreeWidgetItem * Previous = Parent ? Parent - > child ( Index - 1 ) : ui . threadTreeWidget - > topLevelItem ( Index - 1 ) ;
if ( Previous ) {
ui . threadTreeWidget - > setCurrentItem ( Previous ) ;
}
}
}
void ForumsDialog : : nextMessage ( )
{
QTreeWidgetItem * Item = ui . threadTreeWidget - > currentItem ( ) ;
if ( Item = = NULL ) {
return ;
}
QTreeWidgetItem * Parent = Item - > parent ( ) ;
int Index = Parent ? Parent - > indexOfChild ( Item ) : ui . threadTreeWidget - > indexOfTopLevelItem ( Item ) ;
int Count = Parent ? Parent - > childCount ( ) : ui . threadTreeWidget - > topLevelItemCount ( ) ;
if ( Index < Count - 1 ) {
QTreeWidgetItem * Next = Parent ? Parent - > child ( Index + 1 ) : ui . threadTreeWidget - > topLevelItem ( Index + 1 ) ;
if ( Next ) {
ui . threadTreeWidget - > setCurrentItem ( Next ) ;
}
}
}
// TODO
2008-04-09 08:57:26 -04:00
bool ForumsDialog : : getCurrentMsg ( std : : string & cid , std : : string & mid )
{
return false ;
}
2010-05-01 15:03:35 -04:00
// TODO
2008-04-09 08:57:26 -04:00
void ForumsDialog : : removemessage ( )
{
#if 0
//std::cerr << "ForumsDialog::removemessage()" << std::endl;
std : : string cid , mid ;
if ( ! getCurrentMsg ( cid , mid ) )
{
//std::cerr << "ForumsDialog::removemessage()";
//std::cerr << " No Message selected" << std::endl;
return ;
}
rsMsgs - > MessageDelete ( mid ) ;
# endif
return ;
}
2010-05-01 15:03:35 -04:00
// TODO
2008-04-09 08:57:26 -04:00
void ForumsDialog : : markMsgAsRead ( )
{
#if 0
//std::cerr << "ForumsDialog::markMsgAsRead()" << std::endl;
std : : string cid , mid ;
if ( ! getCurrentMsg ( cid , mid ) )
{
//std::cerr << "ForumsDialog::markMsgAsRead()";
//std::cerr << " No Message selected" << std::endl;
return ;
}
rsMsgs - > MessageRead ( mid ) ;
# endif
return ;
}
void ForumsDialog : : newforum ( )
{
2010-05-01 15:03:35 -04:00
CreateForum cf ( this ) ;
cf . exec ( ) ;
2008-04-09 08:57:26 -04:00
}
2008-04-15 12:40:38 -04:00
void ForumsDialog : : createmessage ( )
{
2010-05-01 15:03:35 -04:00
if ( mCurrForumId . empty ( ) ) {
return ;
}
CreateForumMsg * cfm = new CreateForumMsg ( mCurrForumId , mCurrPostId ) ;
cfm - > show ( ) ;
2008-04-15 12:40:38 -04:00
2010-05-01 15:03:35 -04:00
/* window will destroy itself! */
2008-04-15 12:40:38 -04:00
}
void ForumsDialog : : showthread ( )
{
2010-05-01 15:03:35 -04:00
if ( mCurrForumId . empty ( ) ) {
QMessageBox : : information ( this , tr ( " RetroShare " ) , tr ( " No Forum Selected! " ) ) ;
return ;
}
CreateForumMsg * cfm = new CreateForumMsg ( mCurrForumId , " " ) ;
cfm - > setWindowTitle ( tr ( " Start New Thread " ) ) ;
cfm - > show ( ) ;
2008-04-15 12:40:38 -04:00
2010-05-01 15:03:35 -04:00
/* window will destroy itself! */
2008-04-15 12:40:38 -04:00
}
2008-06-13 11:46:34 -04:00
void ForumsDialog : : subscribeToForum ( )
{
forumSubscribe ( true ) ;
}
void ForumsDialog : : unsubscribeToForum ( )
{
forumSubscribe ( false ) ;
}
void ForumsDialog : : forumSubscribe ( bool subscribe )
{
QTreeWidgetItem * forumItem = ui . forumTreeWidget - > currentItem ( ) ;
if ( ( ! forumItem ) | | ( forumItem - > parent ( ) = = NULL ) )
{
return ;
}
/* store forumId */
std : : string fId = ( forumItem - > text ( 4 ) ) . toStdString ( ) ;
rsForums - > forumSubscribe ( fId , subscribe ) ;
}
void ForumsDialog : : showForumDetails ( )
{
2010-05-01 15:03:35 -04:00
if ( mCurrForumId = = " " )
{
return ;
}
2010-01-02 10:47:07 -05:00
2010-05-01 15:03:35 -04:00
ForumDetails fui ;
2008-06-13 11:46:34 -04:00
2010-05-01 15:03:35 -04:00
fui . showDetails ( mCurrForumId ) ;
fui . exec ( ) ;
2008-06-13 11:46:34 -04:00
}
2010-01-04 09:29:49 -05:00
void ForumsDialog : : loadForumEmoticons ( )
{
QString sm_codes ;
# if defined(Q_OS_WIN32)
QFile sm_file ( QApplication : : applicationDirPath ( ) + " /emoticons/emotes.acs " ) ;
# else
QFile sm_file ( QString ( " :/smileys/emotes.acs " ) ) ;
# endif
if ( ! sm_file . open ( QIODevice : : ReadOnly ) )
{
std : : cerr < < " Could not open resouce file :/emoticons/emotes.acs " < < std : : endl ;
return ;
}
sm_codes = sm_file . readAll ( ) ;
sm_file . close ( ) ;
sm_codes . remove ( " \n " ) ;
sm_codes . remove ( " \r " ) ;
int i = 0 ;
QString smcode ;
QString smfile ;
while ( sm_codes [ i ] ! = ' { ' )
{
i + + ;
}
while ( i < sm_codes . length ( ) - 2 )
{
smcode = " " ;
smfile = " " ;
while ( sm_codes [ i ] ! = ' \" ' )
{
i + + ;
}
i + + ;
while ( sm_codes [ i ] ! = ' \" ' )
{
smcode + = sm_codes [ i ] ;
i + + ;
}
i + + ;
while ( sm_codes [ i ] ! = ' \" ' )
{
i + + ;
}
i + + ;
while ( sm_codes [ i ] ! = ' \" ' & & sm_codes [ i + 1 ] ! = ' ; ' )
{
smfile + = sm_codes [ i ] ;
i + + ;
}
i + + ;
if ( ! smcode . isEmpty ( ) & & ! smfile . isEmpty ( ) )
# if defined(Q_OS_WIN32)
smileys . insert ( smcode , smfile ) ;
# else
smileys . insert ( smcode , " :/ " + smfile ) ;
# endif
}
}
2010-01-09 11:33:00 -05:00
void ForumsDialog : : replytomessage ( )
{
2010-05-01 15:03:35 -04:00
if ( mCurrForumId = = " " )
{
return ;
}
fId = mCurrForumId ;
pId = mCurrPostId ;
ForumMsgInfo msgInfo ;
rsForums - > getForumMessage ( fId , pId , msgInfo ) ;
if ( rsPeers - > getPeerName ( msgInfo . srcId ) ! = " " )
{
ChanMsgDialog * nMsgDialog = new ChanMsgDialog ( true ) ;
nMsgDialog - > newMsg ( ) ;
nMsgDialog - > insertTitleText ( ( QString ( " Re: " ) + QString : : fromStdWString ( msgInfo . title ) ) . toStdString ( ) ) ;
nMsgDialog - > setWindowTitle ( tr ( " Re: " ) + QString : : fromStdWString ( msgInfo . title ) ) ;
QTextDocument doc ;
doc . setHtml ( QString : : fromStdWString ( msgInfo . msg ) ) ;
std : : string cited_text ( doc . toPlainText ( ) . toStdString ( ) ) ;
nMsgDialog - > insertPastedText ( cited_text ) ;
nMsgDialog - > addRecipient ( msgInfo . srcId ) ;
nMsgDialog - > show ( ) ;
nMsgDialog - > activateWindow ( ) ;
2010-05-02 20:09:55 -04:00
/* window will destroy itself! */
2010-05-01 15:03:35 -04:00
}
else
{
QMessageBox : : information ( this , tr ( " RetroShare " ) , tr ( " You cant reply a Anonymous Author " ) ) ;
}
2010-01-09 11:33:00 -05:00
}
2008-06-13 11:46:34 -04:00
2010-05-01 15:03:35 -04:00
void ForumsDialog : : anchorClicked ( const QUrl & link )
2010-01-14 08:03:43 -05:00
{
# ifdef FORUM_DEBUG
std : : cerr < < " ForumsDialog::anchorClicked link.scheme() : " < < link . scheme ( ) . toStdString ( ) < < std : : endl ;
# endif
2010-05-01 15:03:35 -04:00
2010-01-16 09:31:32 -05:00
if ( link . scheme ( ) = = " retroshare " )
{
2010-03-10 16:38:26 -05:00
RetroShareLink rslnk ( link . toString ( ) ) ;
2010-01-14 08:03:43 -05:00
2010-03-10 16:38:26 -05:00
if ( rslnk . valid ( ) )
2010-01-16 09:31:32 -05:00
{
std : : list < std : : string > srcIds ;
2010-03-10 16:38:26 -05:00
if ( rsFiles - > FileRequest ( rslnk . name ( ) . toStdString ( ) , rslnk . hash ( ) . toStdString ( ) , rslnk . size ( ) , " " , RS_FILE_HINTS_NETWORK_WIDE , srcIds ) )
2010-01-16 10:42:26 -05:00
{
QMessageBox mb ( tr ( " File Request Confirmation " ) , tr ( " The file has been added to your download list. " ) , QMessageBox : : Information , QMessageBox : : Ok , 0 , 0 ) ;
mb . setButtonText ( QMessageBox : : Ok , " OK " ) ;
2010-02-01 12:26:22 -05:00
mb . setWindowIcon ( QIcon ( QString : : fromUtf8 ( " :/images/rstray3.png " ) ) ) ;
2010-01-16 10:42:26 -05:00
mb . exec ( ) ;
}
else
{
QMessageBox mb ( tr ( " File Request canceled " ) , tr ( " The file has not been added to your download list, because you already have it. " ) , QMessageBox : : Information , QMessageBox : : Ok , 0 , 0 ) ;
mb . setButtonText ( QMessageBox : : Ok , " OK " ) ;
mb . exec ( ) ;
}
2010-05-01 15:03:35 -04:00
}
else
2010-01-16 09:31:32 -05:00
{
QMessageBox mb ( tr ( " File Request Error " ) , tr ( " The file link is malformed. " ) , QMessageBox : : Information , QMessageBox : : Ok , 0 , 0 ) ;
mb . setButtonText ( QMessageBox : : Ok , " OK " ) ;
2010-02-01 12:26:22 -05:00
mb . setWindowIcon ( QIcon ( QString : : fromUtf8 ( " :/images/rstray3.png " ) ) ) ;
2010-01-16 09:31:32 -05:00
mb . exec ( ) ;
}
2010-05-01 15:03:35 -04:00
}
else if ( link . scheme ( ) = = " http " )
2010-01-16 09:31:32 -05:00
{
QDesktopServices : : openUrl ( link ) ;
2010-05-01 15:03:35 -04:00
}
else if ( link . scheme ( ) = = " " )
2010-01-16 09:31:32 -05:00
{
//it's probably a web adress, let's add http:// at the beginning of the link
QString newAddress = link . toString ( ) ;
newAddress . prepend ( " http:// " ) ;
QDesktopServices : : openUrl ( QUrl ( newAddress ) ) ;
}
}
2010-05-19 16:17:43 -04:00
void ForumsDialog : : filterRegExpChanged ( )
{
// QRegExp regExp(ui.filterPatternLineEdit->text(), Qt::CaseInsensitive , QRegExp::FixedString);
// proxyModel->setFilterRegExp(regExp);
QString text = ui . filterPatternLineEdit - > text ( ) ;
if ( text . isEmpty ( ) ) {
ui . clearButton - > hide ( ) ;
} else {
ui . clearButton - > show ( ) ;
}
FilterItems ( ) ;
}
/* clear Filter */
void ForumsDialog : : clearFilter ( )
{
ui . filterPatternLineEdit - > clear ( ) ;
ui . filterPatternLineEdit - > setFocus ( ) ;
}
void ForumsDialog : : changedViewBox ( )
{
// save index
RSettings settings ( QString ( " ForumsDialog " ) ) ;
settings . setValue ( " viewBox " , ui . viewBox - > currentIndex ( ) ) ;
insertThreads ( ) ;
}
void ForumsDialog : : filterColumnChanged ( )
{
int nFilterColumn = FilterColumnFromComboBox ( ui . filterColumnComboBox - > currentIndex ( ) ) ;
if ( nFilterColumn = = COLUMN_CONTENT ) {
// need content ... refill
insertThreads ( ) ;
} else {
FilterItems ( ) ;
}
// save index
RSettings settings ( QString ( " ForumsDialog " ) ) ;
settings . setValue ( " filterColumn " , nFilterColumn ) ;
}
void ForumsDialog : : FilterItems ( )
{
QString sPattern = ui . filterPatternLineEdit - > text ( ) ;
int nFilterColumn = FilterColumnFromComboBox ( ui . filterColumnComboBox - > currentIndex ( ) ) ;
int nCount = ui . threadTreeWidget - > topLevelItemCount ( ) ;
for ( int nIndex = 0 ; nIndex < nCount ; nIndex + + ) {
FilterItem ( ui . threadTreeWidget - > topLevelItem ( nIndex ) , sPattern , nFilterColumn ) ;
}
}
bool ForumsDialog : : FilterItem ( QTreeWidgetItem * pItem , QString & sPattern , int nFilterColumn )
{
bool bVisible = true ;
if ( sPattern . isEmpty ( ) = = false ) {
if ( pItem - > text ( nFilterColumn ) . contains ( sPattern , Qt : : CaseInsensitive ) = = false ) {
bVisible = false ;
}
}
int nVisibleChildCount = 0 ;
int nCount = pItem - > childCount ( ) ;
for ( int nIndex = 0 ; nIndex < nCount ; nIndex + + ) {
if ( FilterItem ( pItem - > child ( nIndex ) , sPattern , nFilterColumn ) ) {
nVisibleChildCount + + ;
}
}
if ( bVisible | | nVisibleChildCount ) {
pItem - > setHidden ( false ) ;
} else {
pItem - > setHidden ( true ) ;
}
return ( bVisible | | nVisibleChildCount ) ;
}