From 48e5a49cd5e363def744307add0e0b57fd4aef95 Mon Sep 17 00:00:00 2001 From: thunder2 Date: Sat, 5 Jul 2014 18:33:11 +0000 Subject: [PATCH] Added new base class for a subscribe button - SubscribeToolButton. Added subscribe and auto-download button to channel dialog. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7431 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- .../src/gui/common/SubscribeToolButton.cpp | 92 +++++++++++++++++++ .../src/gui/common/SubscribeToolButton.h | 31 +++++++ .../src/gui/gxs/GxsGroupFrameDialog.cpp | 38 ++++---- .../src/gui/gxs/GxsGroupFrameDialog.h | 2 +- .../src/gui/gxs/RsGxsUpdateBroadcastPage.cpp | 20 ++++ .../src/gui/gxs/RsGxsUpdateBroadcastPage.h | 4 + .../gui/gxschannels/GxsChannelPostsWidget.cpp | 70 ++++++++++++-- .../gui/gxschannels/GxsChannelPostsWidget.h | 6 +- .../gui/gxschannels/GxsChannelPostsWidget.ui | 37 ++++---- retroshare-gui/src/retroshare-gui.pro | 2 + 10 files changed, 260 insertions(+), 42 deletions(-) create mode 100644 retroshare-gui/src/gui/common/SubscribeToolButton.cpp create mode 100644 retroshare-gui/src/gui/common/SubscribeToolButton.h diff --git a/retroshare-gui/src/gui/common/SubscribeToolButton.cpp b/retroshare-gui/src/gui/common/SubscribeToolButton.cpp new file mode 100644 index 000000000..cd7321b6f --- /dev/null +++ b/retroshare-gui/src/gui/common/SubscribeToolButton.cpp @@ -0,0 +1,92 @@ +#include + +#include "SubscribeToolButton.h" + +/* Use MenuButtonPopup, because the arrow of InstantPopup is too small */ +#define USE_MENUBUTTONPOPUP + +SubscribeToolButton::SubscribeToolButton(QWidget *parent) : + QToolButton(parent) +{ + mSubscribed = false; + + setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + +#ifdef USE_MENUBUTTONPOPUP + connect(this, SIGNAL(clicked()), this, SLOT(subscribePrivate())); +#endif + + updateUi(); +} + +void SubscribeToolButton::setSubscribed(bool subscribed) +{ + if (mSubscribed == subscribed) { + return; + } + + mSubscribed = subscribed; + + updateUi(); +} + +void SubscribeToolButton::addSubscribedAction(QAction *action) +{ + mSubscribedActions.push_back(action); +} + +void SubscribeToolButton::updateUi() +{ + if (mSubscribed) { +#ifdef USE_MENUBUTTONPOPUP + setPopupMode(QToolButton::MenuButtonPopup); +#else + setPopupMode(QToolButton::InstantPopup); +#endif + setIcon(QIcon(":/images/accepted16.png")); + setText(tr("Subscribed")); + + QMenu *menu = new QMenu; + menu->addAction(QIcon(":/images/cancel.png"), tr("Unsubscribe"), this, SLOT(unsubscribePrivate())); + + if (!mSubscribedActions.empty()) { + menu->addSeparator(); + menu->addActions(mSubscribedActions); + } + setMenu(menu); + +#ifndef USE_MENUBUTTONPOPUP + disconnect(this, SIGNAL(clicked()), this, SLOT(subscribePrivate())); +#endif + } else { + setPopupMode(QToolButton::DelayedPopup); + setMenu(NULL); + setIcon(QIcon()); + setText(tr("Subscribe")); + +#ifndef USE_MENUBUTTONPOPUP + connect(this, SIGNAL(clicked()), this, SLOT(subscribePrivate())); +#endif + } +} + +void SubscribeToolButton::subscribePrivate() +{ + if (menu()) { +#ifdef USE_MENUBUTTONPOPUP + showMenu(); +#endif + return; + } + + emit subscribe(true); + + setSubscribed(true); +} + +void SubscribeToolButton::unsubscribePrivate() +{ + emit subscribe(false); + + setSubscribed(false); +} diff --git a/retroshare-gui/src/gui/common/SubscribeToolButton.h b/retroshare-gui/src/gui/common/SubscribeToolButton.h new file mode 100644 index 000000000..38056923d --- /dev/null +++ b/retroshare-gui/src/gui/common/SubscribeToolButton.h @@ -0,0 +1,31 @@ +#ifndef SUBSCRIBETOOLBUTTON_H +#define SUBSCRIBETOOLBUTTON_H + +#include + +class SubscribeToolButton : public QToolButton +{ + Q_OBJECT + +public: + explicit SubscribeToolButton(QWidget *parent = 0); + + void setSubscribed(bool subscribed); + void addSubscribedAction(QAction *action); + +signals: + void subscribe(bool subscribe); + +private slots: + void subscribePrivate(); + void unsubscribePrivate(); + +private: + void updateUi(); + +private: + bool mSubscribed; + QList mSubscribedActions; +}; + +#endif // SUBSCRIBETOOLBUTTON_H diff --git a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp index 310d5f610..39848b3bf 100644 --- a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp +++ b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp @@ -49,7 +49,7 @@ #define IMAGE_COMMENT "" #define TOKEN_TYPE_GROUP_SUMMARY 1 -#define TOKEN_TYPE_SUBSCRIBE_CHANGE 2 +//#define TOKEN_TYPE_SUBSCRIBE_CHANGE 2 //#define TOKEN_TYPE_CURRENTGROUP 3 #define MAX_COMMENT_TITLE 32 @@ -193,7 +193,7 @@ void GxsGroupFrameDialog::setSingleTab(bool singleTab) void GxsGroupFrameDialog::updateDisplay(bool complete) { - if (complete || !getGrpIds().empty()) { + if (complete || !getGrpIds().empty() || !getGrpIdsMeta().empty()) { /* Update group list */ requestGroupSummary(); } @@ -312,7 +312,8 @@ void GxsGroupFrameDialog::groupSubscribe(bool subscribe) uint32_t token; mInterface->subscribeToGroup(token, mGroupId, subscribe); - mTokenQueue->queueRequest(token, 0, RS_TOKREQ_ANSTYPE_ACK, TOKEN_TYPE_SUBSCRIBE_CHANGE); +// Replaced by meta data changed +// mTokenQueue->queueRequest(token, 0, RS_TOKREQ_ANSTYPE_ACK, TOKEN_TYPE_SUBSCRIBE_CHANGE); } void GxsGroupFrameDialog::showGroupDetails() @@ -720,6 +721,11 @@ void GxsGroupFrameDialog::insertGroupsData(const std::list &gro ui->groupTreeWidget->fillGroupItems(mPopularGroups, popList); ui->groupTreeWidget->fillGroupItems(mOtherGroups, otherList); + /* Re-fill group */ + if (!ui->groupTreeWidget->activateId(QString::fromStdString(mGroupId.toStdString()), true)) { + mGroupId.clear(); + } + updateMessageSummaryList(RsGxsGroupId()); } @@ -814,18 +820,18 @@ void GxsGroupFrameDialog::loadGroupSummary(const uint32_t &token) /*********************** **** **** **** ***********************/ /*********************** **** **** **** ***********************/ -void GxsGroupFrameDialog::acknowledgeSubscribeChange(const uint32_t &token) -{ -#ifdef DEBUG_GROUPFRAMEDIALOG - std::cerr << "GxsGroupFrameDialog::acknowledgeSubscribeChange()"; - std::cerr << std::endl; -#endif +//void GxsGroupFrameDialog::acknowledgeSubscribeChange(const uint32_t &token) +//{ +//#ifdef DEBUG_GROUPFRAMEDIALOG +// std::cerr << "GxsGroupFrameDialog::acknowledgeSubscribeChange()"; +// std::cerr << std::endl; +//#endif - RsGxsGroupId groupId; - mInterface->acknowledgeGrp(token, groupId); +// RsGxsGroupId groupId; +// mInterface->acknowledgeGrp(token, groupId); - fillComplete(); -} +// fillComplete(); +//} /*********************** **** **** **** ***********************/ /*********************** **** **** **** ***********************/ @@ -887,9 +893,9 @@ void GxsGroupFrameDialog::loadRequest(const TokenQueue *queue, const TokenReques loadGroupSummary(req.mToken); break; - case TOKEN_TYPE_SUBSCRIBE_CHANGE: - acknowledgeSubscribeChange(req.mToken); - break; +// case TOKEN_TYPE_SUBSCRIBE_CHANGE: +// acknowledgeSubscribeChange(req.mToken); +// break; // case TOKEN_TYPE_CURRENTGROUP: // loadGroupSummary_CurrentGroup(req.mToken); diff --git a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h index 392dae3d5..d5d272780 100644 --- a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h +++ b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h @@ -148,7 +148,7 @@ private: void loadGroupSummary(const uint32_t &token); // subscribe/unsubscribe ack. - void acknowledgeSubscribeChange(const uint32_t &token); +// void acknowledgeSubscribeChange(const uint32_t &token); GxsMessageFrameWidget *messageWidget(const RsGxsGroupId &groupId, bool ownTab); GxsMessageFrameWidget *createMessageWidget(const RsGxsGroupId &groupId); diff --git a/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastPage.cpp b/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastPage.cpp index 8f00f339d..5eba14b89 100644 --- a/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastPage.cpp +++ b/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastPage.cpp @@ -22,11 +22,31 @@ void RsGxsUpdateBroadcastPage::setUpdateWhenInvisible(bool update) mBase->setUpdateWhenInvisible(update); } +const std::list &RsGxsUpdateBroadcastPage::getGrpIdsMeta() +{ + return mBase->getGrpIdsMeta(); +} + +void RsGxsUpdateBroadcastPage::getAllGrpIds(std::list &grpIds) +{ + mBase->getAllGrpIds(grpIds); +} + const std::list &RsGxsUpdateBroadcastPage::getGrpIds() { return mBase->getGrpIds(); } +const std::map > &RsGxsUpdateBroadcastPage::getMsgIdsMeta() +{ + return mBase->getMsgIdsMeta(); +} + +void RsGxsUpdateBroadcastPage::getAllMsgIds(std::map > &msgIds) +{ + mBase->getAllMsgIds(msgIds); +} + const std::map > &RsGxsUpdateBroadcastPage::getMsgIds() { return mBase->getMsgIds(); diff --git a/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastPage.h b/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastPage.h index 9db362fd8..299e7e2a7 100644 --- a/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastPage.h +++ b/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastPage.h @@ -25,7 +25,11 @@ public: void fillComplete(); void setUpdateWhenInvisible(bool update); const std::list &getGrpIds(); + const std::list &getGrpIdsMeta(); + void getAllGrpIds(std::list &grpIds); const std::map > &getMsgIds(); + const std::map > &getMsgIdsMeta(); + void getAllMsgIds(std::map > &msgIds); protected: virtual void showEvent(QShowEvent *event); diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp index 365d9b6ff..5f515eaa4 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp @@ -68,11 +68,14 @@ GxsChannelPostsWidget::GxsChannelPostsWidget(const RsGxsGroupId &channelId, QWid mStateHelper->addWidget(TOKEN_TYPE_GROUP_DATA, ui->postButton); mStateHelper->addWidget(TOKEN_TYPE_GROUP_DATA, ui->logoLabel); + mStateHelper->addWidget(TOKEN_TYPE_GROUP_DATA, ui->subscribeToolButton); mChannelQueue = new TokenQueue(rsGxsChannels->getTokenService(), this); connect(ui->postButton, SIGNAL(clicked()), this, SLOT(createMsg())); + connect(ui->subscribeToolButton, SIGNAL(subscribe(bool)), this, SLOT(subscribeGroup(bool))); // connect(NotifyQt::getInstance(), SIGNAL(channelMsgReadSatusChanged(QString,QString,int)), this, SLOT(channelMsgReadSatusChanged(QString,QString,int))); + /* add filter actions */ ui->filterLineEdit->addFilter(QIcon(), tr("Title"), FILTER_TITLE, tr("Search Title")); ui->filterLineEdit->addFilter(QIcon(), tr("Message"), FILTER_MSG, tr("Search Message")); @@ -94,7 +97,18 @@ GxsChannelPostsWidget::GxsChannelPostsWidget(const RsGxsGroupId &channelId, QWid /* load settings */ processSettings(true); + /* Initialize subscribe button */ + QIcon icon; + icon.addPixmap(QPixmap(":/images/redled.png"), QIcon::Normal, QIcon::On); + icon.addPixmap(QPixmap(":/images/start.png"), QIcon::Normal, QIcon::Off); + mAutoDownloadAction = new QAction(icon, "", this); + mAutoDownloadAction->setCheckable(true); + connect(mAutoDownloadAction, SIGNAL(triggered()), this, SLOT(toggleAutoDownload())); + + ui->subscribeToolButton->addSubscribedAction(mAutoDownloadAction); + /* Initialize GUI */ + setAutoDownload(false); setGroupId(channelId); } @@ -102,6 +116,8 @@ GxsChannelPostsWidget::~GxsChannelPostsWidget() { // save settings processSettings(false); + + delete(mAutoDownloadAction); } void GxsChannelPostsWidget::updateDisplay(bool complete) @@ -113,9 +129,19 @@ void GxsChannelPostsWidget::updateDisplay(bool complete) return; } + bool updateGroup = false; + if (mChannelId.isNull()) { + return; + } + + const std::list &grpIdsMeta = getGrpIdsMeta(); + if (std::find(grpIdsMeta.begin(), grpIdsMeta.end(), mChannelId) != grpIdsMeta.end()) { + updateGroup = true; + } + const std::list &grpIds = getGrpIds(); if (!mChannelId.isNull() && std::find(grpIds.begin(), grpIds.end(), mChannelId) != grpIds.end()) { - requestGroupData(mChannelId); + updateGroup = true; /* Do we need to fill all posts? */ requestPosts(mChannelId); } else { @@ -130,6 +156,10 @@ void GxsChannelPostsWidget::updateDisplay(bool complete) } } } + + if (updateGroup) { + requestGroupData(mChannelId); + } } //UserNotify *GxsChannelPostsWidget::getUserNotify(QObject *parent) @@ -257,7 +287,10 @@ void GxsChannelPostsWidget::insertChannelDetails(const RsGxsChannelGroup &group) mStateHelper->setWidgetEnabled(ui->postButton, false); } - setAutoDownloadButton(group.mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED); + ui->subscribeToolButton->setSubscribed(IS_GROUP_SUBSCRIBED(group.mMeta.mSubscribeFlags)); + + bool autoDownload = rsGxsChannels->getChannelAutoDownload(group.mMeta.mGroupId); + setAutoDownload(autoDownload); } static bool sortChannelMsgSummaryAsc(const RsGxsChannelPost &msg1, const RsGxsChannelPost &msg2) @@ -551,12 +584,35 @@ void GxsChannelPostsWidget::setAllMessagesRead(bool read) #endif } -void GxsChannelPostsWidget::setAutoDownloadButton(bool autoDl) +void GxsChannelPostsWidget::subscribeGroup(bool subscribe) { - if (autoDl) { - ui->actionEnable_Auto_Download->setText(tr("Disable Auto-Download")); - }else{ - ui->actionEnable_Auto_Download->setText(tr("Enable Auto-Download")); + if (mChannelId.isNull()) { + return; + } + + uint32_t token; + rsGxsChannels->subscribeToGroup(token, mChannelId, subscribe); +// mChannelQueue->queueRequest(token, 0, RS_TOKREQ_ANSTYPE_ACK, TOKEN_TYPE_SUBSCRIBE_CHANGE); +} + +void GxsChannelPostsWidget::setAutoDownload(bool autoDl) +{ + mAutoDownloadAction->setChecked(autoDl); + mAutoDownloadAction->setText(autoDl ? tr("Disable Auto-Download") : tr("Enable Auto-Download")); +} + +void GxsChannelPostsWidget::toggleAutoDownload() +{ + RsGxsGroupId grpId = groupId(); + if (grpId.isNull()) { + return; + } + + bool autoDownload = rsGxsChannels->getChannelAutoDownload(grpId); + if (!rsGxsChannels->setChannelAutoDownload(grpId, !autoDownload)) + { + std::cerr << "GxsChannelDialog::toggleAutoDownload() Auto Download failed to set"; + std::cerr << std::endl; } } diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.h b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.h index c4cc26d11..a72187c59 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.h @@ -71,6 +71,8 @@ protected: private slots: void createMsg(); + void toggleAutoDownload(); + void subscribeGroup(bool subscribe); void filterChanged(int filter); void filterItems(const QString& text); @@ -80,7 +82,7 @@ private slots: private: void processSettings(bool load); - void setAutoDownloadButton(bool autoDl); + void setAutoDownload(bool autoDl); void clearPosts(); /* NEW GXS FNS */ @@ -109,7 +111,7 @@ private: //QList mChanMsgItems; QList mChannelPostItems; - std::map mChanSearchScore; //chanId, score + QAction *mAutoDownloadAction; UIStateHelper *mStateHelper; diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.ui b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.ui index 356543e1e..feb0001cd 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.ui +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.ui @@ -123,6 +123,22 @@ + + + + + 0 + 0 + + + + Subscribe + + + true + + + @@ -227,22 +243,6 @@ - - - Set all as read - - - Set all as read - - - - - Enable Auto-Download - - - Enable Auto-Download - - toolBarFrame scrollArea headFrame @@ -253,6 +253,11 @@ QLineEdit
gui/common/LineEditClear.h
+ + SubscribeToolButton + QToolButton +
gui/Common/SubscribeToolButton.h
+
diff --git a/retroshare-gui/src/retroshare-gui.pro b/retroshare-gui/src/retroshare-gui.pro index df18d6817..29112156a 100644 --- a/retroshare-gui/src/retroshare-gui.pro +++ b/retroshare-gui/src/retroshare-gui.pro @@ -459,6 +459,7 @@ HEADERS += rshare.h \ gui/common/MimeTextEdit.h \ gui/common/UIStateHelper.h \ gui/common/FloatingHelpBrowser.h \ + gui/common/SubscribeToolButton.h \ gui/style/RSStyle.h \ gui/style/StyleDialog.h \ gui/MessagesDialog.h \ @@ -746,6 +747,7 @@ SOURCES += main.cpp \ gui/common/MimeTextEdit.cpp \ gui/common/UIStateHelper.cpp \ gui/common/FloatingHelpBrowser.cpp \ + gui/common/SubscribeToolButton.cpp \ gui/style/RSStyle.cpp \ gui/style/StyleDialog.cpp \ gui/settings/rsharesettings.cpp \