diff --git a/retroshare-gui/src/gui/ForumsDialog.cpp b/retroshare-gui/src/gui/ForumsDialog.cpp index 8a4690155..184baf418 100644 --- a/retroshare-gui/src/gui/ForumsDialog.cpp +++ b/retroshare-gui/src/gui/ForumsDialog.cpp @@ -31,6 +31,8 @@ #include "rsiface/rsmsgs.h" #include "rsiface/rsforums.h" +#include "settings/rsettings.h" + #include #include @@ -55,66 +57,111 @@ #define IMAGE_NEWFORUM ":/images/new_forum16.png" #define IMAGE_FORUMAUTHD ":/images/konv_message2.png" +#define VIEW_LAST_POST 0 +#define VIEW_THREADED 1 +#define VIEW_FLAT 2 +#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; + } + + 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); +} /** Constructor */ ForumsDialog::ForumsDialog(QWidget *parent) : MainPage(parent) { - /* Invoke the Qt Designer generated object setup routine */ - ui.setupUi(this); + /* Invoke the Qt Designer generated object setup routine */ + ui.setupUi(this); - connect( ui.forumTreeWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( forumListCustomPopupMenu( QPoint ) ) ); - connect( ui.threadTreeWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( threadListCustomPopupMenu( QPoint ) ) ); + connect( ui.forumTreeWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( forumListCustomPopupMenu( QPoint ) ) ); + connect( ui.threadTreeWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( threadListCustomPopupMenu( QPoint ) ) ); - 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())); + 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())); - connect( ui.forumTreeWidget, SIGNAL( currentItemChanged ( QTreeWidgetItem *, QTreeWidgetItem *) ), this, - SLOT( changedForum( QTreeWidgetItem *, QTreeWidgetItem * ) ) ); + connect( ui.forumTreeWidget, SIGNAL( currentItemChanged ( QTreeWidgetItem *, QTreeWidgetItem *) ), this, SLOT( changedForum( QTreeWidgetItem *, QTreeWidgetItem * ) ) ); + + 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 &))); + + connect(ui.expandButton, SIGNAL(clicked()), this, SLOT(togglethreadview())); + connect(ui.previousButton, SIGNAL(clicked()), this, SLOT(previousMessage())); + connect(ui.nextButton, SIGNAL(clicked()), this, SLOT(nextMessage())); + + 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())); + + QTimer *timer = new QTimer(this); + timer->connect(timer, SIGNAL(timeout()), this, SLOT(checkUpdate())); + timer->start(1000); + + /* Set header resize modes and initial section sizes */ + QHeaderView * ftheader = ui.forumTreeWidget->header () ; + ftheader->setResizeMode (0, QHeaderView::Interactive); + + ftheader->resizeSection ( 0, 170 ); + + /* Set header resize modes and initial section sizes */ + QHeaderView * ttheader = ui.threadTreeWidget->header () ; + ttheader->setResizeMode (0, QHeaderView::Interactive); + + ttheader->resizeSection ( COLUMN_DATE, 170 ); + ttheader->resizeSection ( COLUMN_TITLE, 170 ); + ttheader->hideSection (COLUMN_CONTENT); - connect( ui.threadTreeWidget, SIGNAL( itemSelectionChanged() ), this, SLOT( changedThread () ) ); - connect( ui.viewBox, SIGNAL( currentIndexChanged ( int ) ), this, SLOT( insertThreads() ) ); - connect( ui.postText, SIGNAL( anchorClicked(const QUrl &)), SLOT(anchorClicked(const QUrl &))); + m_ForumNameFont = QFont("Times", 12, QFont::Bold); + ui.forumName->setFont(m_ForumNameFont); + ui.threadTitle->setFont(m_ForumNameFont); - connect(ui.expandButton, SIGNAL(clicked()), this, SLOT(togglefileview())); - connect(ui.previousButton, SIGNAL(clicked()), this, SLOT(previousMessage())); - connect(ui.nextButton, SIGNAL(clicked()), this, SLOT(nextMessage())); + loadForumEmoticons(); - QTimer *timer = new QTimer(this); - timer->connect(timer, SIGNAL(timeout()), this, SLOT(checkUpdate())); - timer->start(1000); + QMenu *forummenu = new QMenu(); + forummenu->addAction(ui.actionCreate_Forum); + forummenu->addSeparator(); + ui.forumpushButton->setMenu(forummenu); - /* Set header resize modes and initial section sizes */ - QHeaderView * ftheader = ui.forumTreeWidget->header () ; - ftheader->setResizeMode (0, QHeaderView::Interactive); - - ftheader->resizeSection ( 0, 170 ); - - /* Set header resize modes and initial section sizes */ - QHeaderView * ttheader = ui.threadTreeWidget->header () ; - ttheader->setResizeMode (0, QHeaderView::Interactive); - - ttheader->resizeSection ( 0, 170 ); - ttheader->resizeSection ( 1, 170 ); - - - m_ForumNameFont = QFont("Times", 12, QFont::Bold); - ui.forumName->setFont(m_ForumNameFont); - ui.threadTitle->setFont(m_ForumNameFont); - - loadForumEmoticons(); - - QMenu *forummenu = new QMenu(); - forummenu->addAction(ui.actionCreate_Forum); - forummenu->addSeparator(); - ui.forumpushButton->setMenu(forummenu); - - ui.postText->setOpenExternalLinks ( false ); - ui.postText->setOpenLinks ( false ); + ui.postText->setOpenExternalLinks ( false ); + ui.postText->setOpenLinks ( false ); /* create forum tree */ m_ItemFont = QFont("ARIAL", 10); @@ -153,12 +200,62 @@ ForumsDialog::ForumsDialog(QWidget *parent) m_LastViewType = -1; + ui.clearButton->hide(); + + // load settings + processSettings(true); + /* Hide platform specific features */ #ifdef Q_WS_WIN #endif } +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()); + } +} + void ForumsDialog::forumListCustomPopupMenu( QPoint point ) { QMenu contextMnu( this ); @@ -244,80 +341,47 @@ void ForumsDialog::threadListCustomPopupMenu( QPoint point ) contextMnu.exec(QCursor::pos()); } -void ForumsDialog::togglefileview() +void ForumsDialog::togglethreadview() { - /* if msg header visible -> hide by changing splitter - * three widgets... - */ + // save state of button + RSettings settings(QString("ForumsDialog")); + settings.setValue("expandButton", ui.expandButton->isChecked()); - QList sizeList = ui.msgSplitter->sizes(); - QList::iterator it; + togglethreadview_internal(); +} - int listSize = 0; - int msgSize = 0; - int i = 0; - - for(it = sizeList.begin(); it != sizeList.end(); it++, i++) - { - if (i == 0) - { - listSize = (*it); - } - else if (i == 1) - { - msgSize = (*it); - } - } - - int totalSize = listSize + msgSize; - - bool toShrink = true; - if (msgSize < (int) totalSize / 10) - { - toShrink = false; - } - - QList newSizeList; - if (toShrink) - { - newSizeList.push_back(totalSize); - newSizeList.push_back(0); - ui.expandButton->setIcon(QIcon(QString(":/images/edit_add24.png"))); - ui.expandButton->setToolTip("Expand"); - } - else - { - /* no change */ - int nlistSize = (totalSize / 2); - int nMsgSize = (totalSize / 2); - newSizeList.push_back(nlistSize); - newSizeList.push_back(nMsgSize); - ui.expandButton->setIcon(QIcon(QString(":/images/edit_remove24.png"))); - ui.expandButton->setToolTip("Hide"); - } - - ui.msgSplitter->setSizes(newSizeList); +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"); + } } void ForumsDialog::checkUpdate() { - std::list forumIds; - std::list::iterator it; - if (!rsForums) - return; + std::list forumIds; + std::list::iterator it; + if (!rsForums) + return; - if (rsForums->forumsChanged(forumIds)) - { - /* update Forums List */ - insertForums(); + 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(); - } - } + it = std::find(forumIds.begin(), forumIds.end(), mCurrForumId); + if (it != forumIds.end()) + { + /* update threads as well */ + insertThreads(); + } + } } @@ -614,246 +678,261 @@ void ForumsDialog::changedThread () if ((!curr) || (!curr->isSelected())) { mCurrPostId = ""; } else { - mCurrPostId = (curr->text(5)).toStdString(); + mCurrPostId = (curr->text(COLUMN_MSGID)).toStdString(); } insertPost(); } void ForumsDialog::insertThreads() { - /* get the current Forum */ - std::cerr << "ForumsDialog::insertThreads()" << std::endl; + /* get the current Forum */ + std::cerr << "ForumsDialog::insertThreads()" << std::endl; - 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; - - return; - } - - /* store forumId */ - mCurrForumId = (forumItem->text(4)).toStdString(); - ui.forumName->setText(forumItem->text(0)); - std::string fId = mCurrForumId; - -#define VIEW_LAST_POST 0 -#define VIEW_THREADED 1 -#define VIEW_FLAT 2 - - 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; - } - - std::list threads; - std::list::iterator tit; - rsForums->getForumThreadList(mCurrForumId, threads); - - QList items; - for(tit = threads.begin(); tit != threads.end(); tit++) - { - 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; - } - - /* 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(0, txt); - } - ForumMsgInfo msginfo ; - rsForums->getForumMessage(fId,tit->msgId,msginfo) ; - - item->setText(1, QString::fromStdWString(tit->title)); - - if (rsPeers->getPeerName(msginfo.srcId) !="") - { - item->setText(2, QString::fromStdString(rsPeers->getPeerName(msginfo.srcId))); - } - else - { - item->setText(2, tr("Anonymous")); - } - - if (msginfo.msgflags & RS_DISTRIB_AUTHEN_REQ) + QTreeWidgetItem *forumItem = ui.forumTreeWidget->currentItem(); + if ((!forumItem) || (forumItem->parent() == NULL)) { - item->setText(3, tr("signed")); - } - else - { - item->setText(3, tr("none")); + /* 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; + + return; } - item->setText(4, QString::fromStdString(tit->parentId)); - item->setText(5, QString::fromStdString(tit->msgId)); + /* store forumId */ + mCurrForumId = (forumItem->text(4)).toStdString(); + ui.forumName->setText(forumItem->text(0)); + std::string fId = mCurrForumId; - std::list threadlist; - threadlist.push_back(item); + 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; + } - while (threadlist.size() > 0) - { - /* get children */ - QTreeWidgetItem *parent = threadlist.front(); - threadlist.pop_front(); - std::string pId = (parent->text(5)).toStdString(); + int nFilterColumn = FilterColumnFromComboBox(ui.filterColumnComboBox->currentIndex()); - std::list msgs; - std::list::iterator mit; + std::list threads; + std::list::iterator tit; + rsForums->getForumThreadList(mCurrForumId, threads); - std::cerr << "ForumsDialog::insertThreads() Getting Children of : " << pId; - std::cerr << std::endl; + QList items; + for(tit = threads.begin(); tit != threads.end(); tit++) + { + std::cerr << "ForumsDialog::insertThreads() Adding TopLevel Thread: mId: "; + std::cerr << tit->msgId << 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(0, txt); - } - ForumMsgInfo msginfo ; - rsForums->getForumMessage(fId,mit->msgId,msginfo) ; - - child->setText(1, QString::fromStdWString(mit->title)); - - if (rsPeers->getPeerName(msginfo.srcId) !="") - { - child->setText(2, QString::fromStdString(rsPeers->getPeerName(msginfo.srcId))); - } - else - { - child->setText(2, tr("Anonymous")); - } - - if (msginfo.msgflags & RS_DISTRIB_AUTHEN_REQ) - { - child->setText(3, tr("signed")); - } - else - { - child->setText(3, tr("none")); - } - - child->setText(4, QString::fromStdString(mit->parentId)); - child->setText(5, QString::fromStdString(mit->msgId)); - - /* setup child */ - threadlist.push_back(child); - - if (flatView) - { - items.append(child); - } - } - } - } - - /* add to list */ - items.append(item); - } - - - 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); - - CleanupItems (items); + /* 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; } - insertPost (); + /* 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) ; + + item->setText(COLUMN_TITLE, QString::fromStdWString(tit->title)); + + if (rsPeers->getPeerName(msginfo.srcId) !="") + { + item->setText(COLUMN_AUTHOR, QString::fromStdString(rsPeers->getPeerName(msginfo.srcId))); + } + else + { + item->setText(COLUMN_AUTHOR, tr("Anonymous")); + } + + if (msginfo.msgflags & RS_DISTRIB_AUTHEN_REQ) + { + item->setText(COLUMN_SIGNED, tr("signed")); + } + else + { + item->setText(COLUMN_SIGNED, tr("none")); + } + + 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(" "))); + } + + item->setText(COLUMN_PARENTID, QString::fromStdString(tit->parentId)); + item->setText(COLUMN_MSGID, QString::fromStdString(tit->msgId)); + + std::list 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 msgs; + std::list::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); + } + } + } + } + + /* add to list */ + items.append(item); + } + + 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); + + CleanupItems (items); + } + + if (ui.filterPatternLineEdit->text().isEmpty() == false) { + FilterItems(); + } + + insertPost (); } void ForumsDialog::FillThreads(QList &ThreadList) @@ -869,7 +948,7 @@ void ForumsDialog::FillThreads(QList &ThreadList) // search existing new thread int Found = -1; for (NewThread = ThreadList.begin (); NewThread != ThreadList.end (); NewThread++) { - if (Thread->text (5) == (*NewThread)->text (5)) { + if (Thread->text (COLUMN_MSGID) == (*NewThread)->text (COLUMN_MSGID)) { // found it Found = Index; break; @@ -889,7 +968,7 @@ void ForumsDialog::FillThreads(QList &ThreadList) int Count = ui.threadTreeWidget->topLevelItemCount (); for (Index = 0; Index < Count; Index++) { Thread = ui.threadTreeWidget->topLevelItem (Index); - if (Thread->text (5) == (*NewThread)->text (5)) { + if (Thread->text (COLUMN_MSGID) == (*NewThread)->text (COLUMN_MSGID)) { // found it Found = Index; break; @@ -897,7 +976,7 @@ void ForumsDialog::FillThreads(QList &ThreadList) } if (Found >= 0) { // set child data - for (int i = 0; i <= 5; i++) { + for (int i = 0; i <= COLUMN_COUNT; i++) { Thread->setText (i, (*NewThread)->text (i)); } @@ -929,7 +1008,7 @@ void ForumsDialog::FillChildren(QTreeWidgetItem *Parent, QTreeWidgetItem *NewPar int Count = NewParent->childCount(); for (NewIndex = 0; NewIndex < Count; NewIndex++) { NewChild = NewParent->child (NewIndex); - if (NewChild->text (5) == Child->text (5)) { + if (NewChild->text (COLUMN_MSGID) == Child->text (COLUMN_MSGID)) { // found it Found = Index; break; @@ -951,7 +1030,7 @@ void ForumsDialog::FillChildren(QTreeWidgetItem *Parent, QTreeWidgetItem *NewPar int Count = Parent->childCount(); for (Index = 0; Index < Count; Index++) { Child = Parent->child (Index); - if (Child->text (5) == NewChild->text (5)) { + if (Child->text (COLUMN_MSGID) == NewChild->text (COLUMN_MSGID)) { // found it Found = Index; break; @@ -959,7 +1038,7 @@ void ForumsDialog::FillChildren(QTreeWidgetItem *Parent, QTreeWidgetItem *NewPar } if (Found >= 0) { // set child data - for (int i = 0; i <= 5; i++) { + for (int i = 0; i <= COLUMN_COUNT; i++) { Child->setText (i, NewChild->text (i)); } @@ -976,60 +1055,57 @@ void ForumsDialog::FillChildren(QTreeWidgetItem *Parent, QTreeWidgetItem *NewPar void ForumsDialog::insertPost() { - if ((mCurrForumId == "") || (mCurrPostId == "")) - { - /* - */ + if ((mCurrForumId == "") || (mCurrPostId == "")) + { + ui.postText->setText(""); + ui.threadTitle->setText(""); + ui.previousButton->setEnabled(false); + ui.nextButton->setEnabled(false); + return; + } - ui.postText->setText(""); - ui.threadTitle->setText(""); - ui.previousButton->setEnabled(false); - ui.nextButton->setEnabled(false); - return; - } + 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); + } - 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); - } + /* get the Post */ + ForumMsgInfo msg; + if (!rsForums->getForumMessage(mCurrForumId, mCurrPostId, msg)) + { + ui.postText->setText(""); + return; + } - /* get the Post */ - ForumMsgInfo msg; - if (!rsForums->getForumMessage(mCurrForumId, mCurrPostId, msg)) - { - ui.postText->setText(""); - return; - } + /* get the Thread */ + ForumMsgInfo title; + if (!rsForums->getForumMessage(mCurrForumId, mCurrPostId, title)) + { + ui.threadTitle->setText(""); + return; + } - /* get the Thread */ - ForumMsgInfo title; - if (!rsForums->getForumMessage(mCurrForumId, mCurrPostId, title)) - { - ui.threadTitle->setText(""); - return; - } + QString extraTxt; + extraTxt += QString::fromStdWString(msg.msg); - QString extraTxt; - extraTxt += QString::fromStdWString(msg.msg); + QHashIterator i(smileys); + while(i.hasNext()) + { + i.next(); + foreach(QString code, i.key().split("|")) + extraTxt.replace(code, ""); + } - QHashIterator i(smileys); - while(i.hasNext()) - { - i.next(); - foreach(QString code, i.key().split("|")) - extraTxt.replace(code, ""); - } - - ui.postText->setHtml(extraTxt); - ui.threadTitle->setText(QString::fromStdWString(title.title)); + ui.postText->setHtml(extraTxt); + ui.threadTitle->setText(QString::fromStdWString(title.title)); } void ForumsDialog::previousMessage () @@ -1334,3 +1410,88 @@ void ForumsDialog::anchorClicked (const QUrl& link ) QDesktopServices::openUrl(QUrl(newAddress)); } } + +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); +} diff --git a/retroshare-gui/src/gui/ForumsDialog.h b/retroshare-gui/src/gui/ForumsDialog.h index e91753320..3f21c5e9e 100644 --- a/retroshare-gui/src/gui/ForumsDialog.h +++ b/retroshare-gui/src/gui/ForumsDialog.h @@ -31,6 +31,7 @@ class ForumsDialog : public MainPage public: ForumsDialog(QWidget *parent = 0); + ~ForumsDialog(); void insertForums(); void insertPost(); @@ -53,7 +54,6 @@ private slots: void changedForum( QTreeWidgetItem *curr, QTreeWidgetItem *prev ); void changedThread(); - void replytomessage(); //void print(); //void printpreview(); @@ -62,7 +62,7 @@ private slots: void markMsgAsRead(); /* handle splitter */ - void togglefileview(); + void togglethreadview(); void showthread(); void createmessage(); @@ -75,6 +75,12 @@ private slots: void previousMessage (); void nextMessage (); + void changedViewBox(); + + void filterColumnChanged(); + void filterRegExpChanged(); + void clearFilter(); + private: void forumSubscribe(bool subscribe); @@ -83,6 +89,12 @@ private: void FillThreads(QList &ThreadList); void FillChildren(QTreeWidgetItem *Parent, QTreeWidgetItem *NewParent); + void processSettings(bool bLoad); + void togglethreadview_internal(); + + void FilterItems(); + bool FilterItem(QTreeWidgetItem *pItem, QString &sPattern, int nFilterColumn); + QTreeWidgetItem *YourForums; QTreeWidgetItem *SubscribedForums; QTreeWidgetItem *PopularForums; @@ -91,14 +103,14 @@ private: std::string mCurrForumId; std::string mCurrThreadId; std::string mCurrPostId; - + QFont m_ForumNameFont; QFont m_ItemFont; int m_LastViewType; std::string m_LastForumID; - + QHash smileys; - + std::string fId; std::string pId; diff --git a/retroshare-gui/src/gui/ForumsDialog.ui b/retroshare-gui/src/gui/ForumsDialog.ui index 4538bfc19..1e0336640 100644 --- a/retroshare-gui/src/gui/ForumsDialog.ui +++ b/retroshare-gui/src/gui/ForumsDialog.ui @@ -6,7 +6,7 @@ 0 0 - 600 + 732 420 @@ -792,7 +792,7 @@ p, li { white-space: pre-wrap; } - + Qt::Vertical @@ -866,6 +866,90 @@ background: white;} + + + + 1 + + + + + + + + + 16 + 16 + + + + + 16 + 16 + + + + + MS Shell Dlg 2 + + + + Reset + + + QPushButton +{ + border-image: url(:/images/closenormal.png) +} + +QPushButton:hover +{ +border-image: url(:/images/closehover.png) +} + +QPushButton:pressed { +border-image: url(:/images/closepressed.png) +} + + + + + + + + + + + MS Shell Dlg 2 + + + + 1 + + + + Date + + + + + Title + + + + + Author + + + + + Content + + + + + + @@ -1044,6 +1128,12 @@ background: white;} :/images/edit_remove24.png:/images/edit_remove24.png + + true + + + true +