From ef9ebf4cf34facd1ccbd11cc3da9c632d036fcc0 Mon Sep 17 00:00:00 2001 From: thunder2 Date: Wed, 28 Nov 2012 12:31:14 +0000 Subject: [PATCH] Added subscribe flags to GroupTreeWidget. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5906 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/GxsForumsDialog.cpp | 32 ++++++------------- retroshare-gui/src/gui/GxsForumsDialog.h | 2 -- .../src/gui/common/GroupTreeWidget.cpp | 25 +++++++++++---- .../src/gui/common/GroupTreeWidget.h | 4 +++ 4 files changed, 32 insertions(+), 31 deletions(-) diff --git a/retroshare-gui/src/gui/GxsForumsDialog.cpp b/retroshare-gui/src/gui/GxsForumsDialog.cpp index dfe21b81d..6d3a4949f 100644 --- a/retroshare-gui/src/gui/GxsForumsDialog.cpp +++ b/retroshare-gui/src/gui/GxsForumsDialog.cpp @@ -133,27 +133,17 @@ void GxsForumsDialog::processSettings(bool bLoad) Settings->endGroup(); } -int GxsForumsDialog::subscribeFlags(const std::string &forumId) -{ - QMap::const_iterator it = mSubscribeFlags.find(mForumId); - if (it != mSubscribeFlags.end()) { - return it.value(); - } - - return 0; -} - void GxsForumsDialog::forumListCustomPopupMenu(QPoint /*point*/) { - int flags = subscribeFlags(mForumId); + int subscribeFlags = ui.forumTreeWidget->subscribeFlags(QString::fromStdString(mForumId)); QMenu contextMnu(this); QAction *action = contextMnu.addAction(QIcon(IMAGE_SUBSCRIBE), tr("Subscribe to Forum"), this, SLOT(subscribeToForum())); - action->setDisabled (mForumId.empty() || IS_GROUP_SUBSCRIBED(flags)); + action->setDisabled (mForumId.empty() || IS_GROUP_SUBSCRIBED(subscribeFlags)); action = contextMnu.addAction(QIcon(IMAGE_UNSUBSCRIBE), tr("Unsubscribe to Forum"), this, SLOT(unsubscribeToForum())); - action->setEnabled (!mForumId.empty() && IS_GROUP_SUBSCRIBED(flags)); + action->setEnabled (!mForumId.empty() && IS_GROUP_SUBSCRIBED(subscribeFlags)); contextMnu.addSeparator(); @@ -163,16 +153,16 @@ void GxsForumsDialog::forumListCustomPopupMenu(QPoint /*point*/) action->setEnabled (!mForumId.empty ()); action = contextMnu.addAction(QIcon(":/images/settings16.png"), tr("Edit Forum Details"), this, SLOT(editForumDetails())); - action->setEnabled (!mForumId.empty () && IS_GROUP_ADMIN(flags)); + action->setEnabled (!mForumId.empty () && IS_GROUP_ADMIN(subscribeFlags)); QAction *shareKeyAct = new QAction(QIcon(":/images/gpgp_key_generate.png"), tr("Share Forum"), &contextMnu); connect( shareKeyAct, SIGNAL( triggered() ), this, SLOT( shareKey() ) ); - shareKeyAct->setEnabled(!mForumId.empty() && IS_GROUP_ADMIN(flags)); + shareKeyAct->setEnabled(!mForumId.empty() && IS_GROUP_ADMIN(subscribeFlags)); contextMnu.addAction( shareKeyAct); QAction *restoreKeysAct = new QAction(QIcon(":/images/settings16.png"), tr("Restore Publish Rights for Forum" ), &contextMnu); connect( restoreKeysAct , SIGNAL( triggered() ), this, SLOT( restoreForumKeys() ) ); - restoreKeysAct->setEnabled(!mForumId.empty() && !IS_GROUP_ADMIN(flags)); + restoreKeysAct->setEnabled(!mForumId.empty() && !IS_GROUP_ADMIN(subscribeFlags)); contextMnu.addAction( restoreKeysAct); action = contextMnu.addAction(QIcon(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyForumLink())); @@ -181,10 +171,10 @@ void GxsForumsDialog::forumListCustomPopupMenu(QPoint /*point*/) contextMnu.addSeparator(); action = contextMnu.addAction(QIcon(":/images/message-mail-read.png"), tr("Mark all as read"), this, SLOT(markMsgAsReadAll())); - action->setEnabled (!mForumId.empty () && IS_GROUP_SUBSCRIBED(flags)); + action->setEnabled (!mForumId.empty () && IS_GROUP_SUBSCRIBED(subscribeFlags)); action = contextMnu.addAction(QIcon(":/images/message-mail.png"), tr("Mark all as unread"), this, SLOT(markMsgAsUnreadAll())); - action->setEnabled (!mForumId.empty () && IS_GROUP_SUBSCRIBED(flags)); + action->setEnabled (!mForumId.empty () && IS_GROUP_SUBSCRIBED(subscribeFlags)); #ifdef DEBUG_FORUMS contextMnu.addSeparator(); @@ -256,6 +246,7 @@ void GxsForumsDialog::forumInfoToGroupItemInfo(const RsGroupMetaData &forumInfo, //groupItemInfo.description = QString::fromUtf8(forumInfo.forumDesc); groupItemInfo.popularity = forumInfo.mPop; groupItemInfo.lastpost = QDateTime::fromTime_t(forumInfo.mLastPost); + groupItemInfo.subscribeFlags = forumInfo.mSubscribeFlags; #if TOGXS if (forumInfo.mGroupFlags & RS_DISTRIB_AUTHEN_REQ) { @@ -285,8 +276,6 @@ void GxsForumsDialog::forumInfoToGroupItemInfo(const RsGroupMetaData &forumInfo, /***** INSERT FORUM LISTS *****/ void GxsForumsDialog::insertForumsData(const std::list &forumList) { - mSubscribeFlags.clear(); - std::list::const_iterator it; QList adminList; @@ -299,9 +288,6 @@ void GxsForumsDialog::insertForumsData(const std::list &forumLi /* sort it into Publish (Own), Subscribed, Popular and Other */ uint32_t flags = it->mSubscribeFlags; - /* store for later use with poll */ - mSubscribeFlags[it->mGroupId] = flags; - GroupItemInfo groupItemInfo; forumInfoToGroupItemInfo(*it, groupItemInfo); diff --git a/retroshare-gui/src/gui/GxsForumsDialog.h b/retroshare-gui/src/gui/GxsForumsDialog.h index 955c1c7ac..5ddd78c3b 100644 --- a/retroshare-gui/src/gui/GxsForumsDialog.h +++ b/retroshare-gui/src/gui/GxsForumsDialog.h @@ -86,7 +86,6 @@ private slots: private: void insertForums(); - int subscribeFlags(const std::string &forumId); void updateMessageSummaryList(std::string forumId); // void forumInfoToGroupItemInfo(const ForumInfo &forumInfo, GroupItemInfo &groupItemInfo); @@ -106,7 +105,6 @@ private: // void loadGroupSummary_CurrentForum(const uint32_t &token); std::string mForumId; - QMap mSubscribeFlags; TokenQueue *mForumQueue; QTreeWidgetItem *yourForums; diff --git a/retroshare-gui/src/gui/common/GroupTreeWidget.cpp b/retroshare-gui/src/gui/common/GroupTreeWidget.cpp index da67704d6..f63282f9c 100644 --- a/retroshare-gui/src/gui/common/GroupTreeWidget.cpp +++ b/retroshare-gui/src/gui/common/GroupTreeWidget.cpp @@ -37,12 +37,13 @@ #define COLUMN_COUNT 2 #define COLUMN_DATA COLUMN_NAME -#define ROLE_ID Qt::UserRole -#define ROLE_NAME Qt::UserRole + 1 -#define ROLE_DESCRIPTION Qt::UserRole + 2 -#define ROLE_POPULARITY Qt::UserRole + 3 -#define ROLE_LASTPOST Qt::UserRole + 4 -#define ROLE_SEARCH_SCORE Qt::UserRole + 5 +#define ROLE_ID Qt::UserRole +#define ROLE_NAME Qt::UserRole + 1 +#define ROLE_DESCRIPTION Qt::UserRole + 2 +#define ROLE_POPULARITY Qt::UserRole + 3 +#define ROLE_LASTPOST Qt::UserRole + 4 +#define ROLE_SEARCH_SCORE Qt::UserRole + 5 +#define ROLE_SUBSCRIBE_FLAGS Qt::UserRole + 6 #define COMBO_NAME_INDEX 0 #define COMBO_DESC_INDEX 1 @@ -299,6 +300,8 @@ void GroupTreeWidget::fillGroupItems(QTreeWidgetItem *categoryItem, const QList< item->setToolTip(COLUMN_NAME, tooltip); item->setToolTip(COLUMN_POPULARITY, tooltip); + item->setData(COLUMN_DATA, ROLE_SUBSCRIBE_FLAGS, itemInfo.subscribeFlags); + /* Set color */ QBrush brush; if (itemInfo.privatekey) { @@ -390,6 +393,16 @@ QTreeWidgetItem *GroupTreeWidget::activateId(const QString &id, bool focus) return item; } +int GroupTreeWidget::subscribeFlags(const QString &id) +{ + QTreeWidgetItem *item = getItemFromId(id); + if (item == NULL) { + return 0; + } + + return item->data(COLUMN_DATA, ROLE_SUBSCRIBE_FLAGS).toInt(); +} + void GroupTreeWidget::calculateScore(QTreeWidgetItem *item, const QString &filterText) { if (item) { diff --git a/retroshare-gui/src/gui/common/GroupTreeWidget.h b/retroshare-gui/src/gui/common/GroupTreeWidget.h index 3cd72e025..0c872a93a 100644 --- a/retroshare-gui/src/gui/common/GroupTreeWidget.h +++ b/retroshare-gui/src/gui/common/GroupTreeWidget.h @@ -42,6 +42,7 @@ public: { popularity = 0; privatekey = false; + subscribeFlags = 0; } public: @@ -52,6 +53,7 @@ public: QDateTime lastpost; QIcon icon; bool privatekey; + int subscribeFlags; }; class GroupTreeWidget : public QWidget @@ -79,6 +81,8 @@ public: QTreeWidgetItem *getItemFromId(const QString &id); QTreeWidgetItem *activateId(const QString &id, bool focus); + int subscribeFlags(const QString &id); + signals: void treeCustomContextMenuRequested(const QPoint &pos); void treeCurrentItemChanged(const QString &id);