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
This commit is contained in:
thunder2 2014-07-05 18:33:11 +00:00
parent 30681ed205
commit 48e5a49cd5
10 changed files with 260 additions and 42 deletions

View File

@ -0,0 +1,92 @@
#include <QMenu>
#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);
}

View File

@ -0,0 +1,31 @@
#ifndef SUBSCRIBETOOLBUTTON_H
#define SUBSCRIBETOOLBUTTON_H
#include <QToolButton>
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<QAction*> mSubscribedActions;
};
#endif // SUBSCRIBETOOLBUTTON_H

View File

@ -49,7 +49,7 @@
#define IMAGE_COMMENT "" #define IMAGE_COMMENT ""
#define TOKEN_TYPE_GROUP_SUMMARY 1 #define TOKEN_TYPE_GROUP_SUMMARY 1
#define TOKEN_TYPE_SUBSCRIBE_CHANGE 2 //#define TOKEN_TYPE_SUBSCRIBE_CHANGE 2
//#define TOKEN_TYPE_CURRENTGROUP 3 //#define TOKEN_TYPE_CURRENTGROUP 3
#define MAX_COMMENT_TITLE 32 #define MAX_COMMENT_TITLE 32
@ -193,7 +193,7 @@ void GxsGroupFrameDialog::setSingleTab(bool singleTab)
void GxsGroupFrameDialog::updateDisplay(bool complete) void GxsGroupFrameDialog::updateDisplay(bool complete)
{ {
if (complete || !getGrpIds().empty()) { if (complete || !getGrpIds().empty() || !getGrpIdsMeta().empty()) {
/* Update group list */ /* Update group list */
requestGroupSummary(); requestGroupSummary();
} }
@ -312,7 +312,8 @@ void GxsGroupFrameDialog::groupSubscribe(bool subscribe)
uint32_t token; uint32_t token;
mInterface->subscribeToGroup(token, mGroupId, subscribe); 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() void GxsGroupFrameDialog::showGroupDetails()
@ -720,6 +721,11 @@ void GxsGroupFrameDialog::insertGroupsData(const std::list<RsGroupMetaData> &gro
ui->groupTreeWidget->fillGroupItems(mPopularGroups, popList); ui->groupTreeWidget->fillGroupItems(mPopularGroups, popList);
ui->groupTreeWidget->fillGroupItems(mOtherGroups, otherList); ui->groupTreeWidget->fillGroupItems(mOtherGroups, otherList);
/* Re-fill group */
if (!ui->groupTreeWidget->activateId(QString::fromStdString(mGroupId.toStdString()), true)) {
mGroupId.clear();
}
updateMessageSummaryList(RsGxsGroupId()); updateMessageSummaryList(RsGxsGroupId());
} }
@ -814,18 +820,18 @@ void GxsGroupFrameDialog::loadGroupSummary(const uint32_t &token)
/*********************** **** **** **** ***********************/ /*********************** **** **** **** ***********************/
/*********************** **** **** **** ***********************/ /*********************** **** **** **** ***********************/
void GxsGroupFrameDialog::acknowledgeSubscribeChange(const uint32_t &token) //void GxsGroupFrameDialog::acknowledgeSubscribeChange(const uint32_t &token)
{ //{
#ifdef DEBUG_GROUPFRAMEDIALOG //#ifdef DEBUG_GROUPFRAMEDIALOG
std::cerr << "GxsGroupFrameDialog::acknowledgeSubscribeChange()"; // std::cerr << "GxsGroupFrameDialog::acknowledgeSubscribeChange()";
std::cerr << std::endl; // std::cerr << std::endl;
#endif //#endif
RsGxsGroupId groupId; // RsGxsGroupId groupId;
mInterface->acknowledgeGrp(token, groupId); // mInterface->acknowledgeGrp(token, groupId);
fillComplete(); // fillComplete();
} //}
/*********************** **** **** **** ***********************/ /*********************** **** **** **** ***********************/
/*********************** **** **** **** ***********************/ /*********************** **** **** **** ***********************/
@ -887,9 +893,9 @@ void GxsGroupFrameDialog::loadRequest(const TokenQueue *queue, const TokenReques
loadGroupSummary(req.mToken); loadGroupSummary(req.mToken);
break; break;
case TOKEN_TYPE_SUBSCRIBE_CHANGE: // case TOKEN_TYPE_SUBSCRIBE_CHANGE:
acknowledgeSubscribeChange(req.mToken); // acknowledgeSubscribeChange(req.mToken);
break; // break;
// case TOKEN_TYPE_CURRENTGROUP: // case TOKEN_TYPE_CURRENTGROUP:
// loadGroupSummary_CurrentGroup(req.mToken); // loadGroupSummary_CurrentGroup(req.mToken);

View File

@ -148,7 +148,7 @@ private:
void loadGroupSummary(const uint32_t &token); void loadGroupSummary(const uint32_t &token);
// subscribe/unsubscribe ack. // subscribe/unsubscribe ack.
void acknowledgeSubscribeChange(const uint32_t &token); // void acknowledgeSubscribeChange(const uint32_t &token);
GxsMessageFrameWidget *messageWidget(const RsGxsGroupId &groupId, bool ownTab); GxsMessageFrameWidget *messageWidget(const RsGxsGroupId &groupId, bool ownTab);
GxsMessageFrameWidget *createMessageWidget(const RsGxsGroupId &groupId); GxsMessageFrameWidget *createMessageWidget(const RsGxsGroupId &groupId);

View File

@ -22,11 +22,31 @@ void RsGxsUpdateBroadcastPage::setUpdateWhenInvisible(bool update)
mBase->setUpdateWhenInvisible(update); mBase->setUpdateWhenInvisible(update);
} }
const std::list<RsGxsGroupId> &RsGxsUpdateBroadcastPage::getGrpIdsMeta()
{
return mBase->getGrpIdsMeta();
}
void RsGxsUpdateBroadcastPage::getAllGrpIds(std::list<RsGxsGroupId> &grpIds)
{
mBase->getAllGrpIds(grpIds);
}
const std::list<RsGxsGroupId> &RsGxsUpdateBroadcastPage::getGrpIds() const std::list<RsGxsGroupId> &RsGxsUpdateBroadcastPage::getGrpIds()
{ {
return mBase->getGrpIds(); return mBase->getGrpIds();
} }
const std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &RsGxsUpdateBroadcastPage::getMsgIdsMeta()
{
return mBase->getMsgIdsMeta();
}
void RsGxsUpdateBroadcastPage::getAllMsgIds(std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &msgIds)
{
mBase->getAllMsgIds(msgIds);
}
const std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &RsGxsUpdateBroadcastPage::getMsgIds() const std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &RsGxsUpdateBroadcastPage::getMsgIds()
{ {
return mBase->getMsgIds(); return mBase->getMsgIds();

View File

@ -25,7 +25,11 @@ public:
void fillComplete(); void fillComplete();
void setUpdateWhenInvisible(bool update); void setUpdateWhenInvisible(bool update);
const std::list<RsGxsGroupId> &getGrpIds(); const std::list<RsGxsGroupId> &getGrpIds();
const std::list<RsGxsGroupId> &getGrpIdsMeta();
void getAllGrpIds(std::list<RsGxsGroupId> &grpIds);
const std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &getMsgIds(); const std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &getMsgIds();
const std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &getMsgIdsMeta();
void getAllMsgIds(std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &msgIds);
protected: protected:
virtual void showEvent(QShowEvent *event); virtual void showEvent(QShowEvent *event);

View File

@ -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->postButton);
mStateHelper->addWidget(TOKEN_TYPE_GROUP_DATA, ui->logoLabel); mStateHelper->addWidget(TOKEN_TYPE_GROUP_DATA, ui->logoLabel);
mStateHelper->addWidget(TOKEN_TYPE_GROUP_DATA, ui->subscribeToolButton);
mChannelQueue = new TokenQueue(rsGxsChannels->getTokenService(), this); mChannelQueue = new TokenQueue(rsGxsChannels->getTokenService(), this);
connect(ui->postButton, SIGNAL(clicked()), this, SLOT(createMsg())); 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))); // connect(NotifyQt::getInstance(), SIGNAL(channelMsgReadSatusChanged(QString,QString,int)), this, SLOT(channelMsgReadSatusChanged(QString,QString,int)));
/* add filter actions */ /* add filter actions */
ui->filterLineEdit->addFilter(QIcon(), tr("Title"), FILTER_TITLE, tr("Search Title")); ui->filterLineEdit->addFilter(QIcon(), tr("Title"), FILTER_TITLE, tr("Search Title"));
ui->filterLineEdit->addFilter(QIcon(), tr("Message"), FILTER_MSG, tr("Search Message")); ui->filterLineEdit->addFilter(QIcon(), tr("Message"), FILTER_MSG, tr("Search Message"));
@ -94,7 +97,18 @@ GxsChannelPostsWidget::GxsChannelPostsWidget(const RsGxsGroupId &channelId, QWid
/* load settings */ /* load settings */
processSettings(true); 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 */ /* Initialize GUI */
setAutoDownload(false);
setGroupId(channelId); setGroupId(channelId);
} }
@ -102,6 +116,8 @@ GxsChannelPostsWidget::~GxsChannelPostsWidget()
{ {
// save settings // save settings
processSettings(false); processSettings(false);
delete(mAutoDownloadAction);
} }
void GxsChannelPostsWidget::updateDisplay(bool complete) void GxsChannelPostsWidget::updateDisplay(bool complete)
@ -113,9 +129,19 @@ void GxsChannelPostsWidget::updateDisplay(bool complete)
return; return;
} }
bool updateGroup = false;
if (mChannelId.isNull()) {
return;
}
const std::list<RsGxsGroupId> &grpIdsMeta = getGrpIdsMeta();
if (std::find(grpIdsMeta.begin(), grpIdsMeta.end(), mChannelId) != grpIdsMeta.end()) {
updateGroup = true;
}
const std::list<RsGxsGroupId> &grpIds = getGrpIds(); const std::list<RsGxsGroupId> &grpIds = getGrpIds();
if (!mChannelId.isNull() && std::find(grpIds.begin(), grpIds.end(), mChannelId) != grpIds.end()) { if (!mChannelId.isNull() && std::find(grpIds.begin(), grpIds.end(), mChannelId) != grpIds.end()) {
requestGroupData(mChannelId); updateGroup = true;
/* Do we need to fill all posts? */ /* Do we need to fill all posts? */
requestPosts(mChannelId); requestPosts(mChannelId);
} else { } else {
@ -130,6 +156,10 @@ void GxsChannelPostsWidget::updateDisplay(bool complete)
} }
} }
} }
if (updateGroup) {
requestGroupData(mChannelId);
}
} }
//UserNotify *GxsChannelPostsWidget::getUserNotify(QObject *parent) //UserNotify *GxsChannelPostsWidget::getUserNotify(QObject *parent)
@ -257,7 +287,10 @@ void GxsChannelPostsWidget::insertChannelDetails(const RsGxsChannelGroup &group)
mStateHelper->setWidgetEnabled(ui->postButton, false); 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) static bool sortChannelMsgSummaryAsc(const RsGxsChannelPost &msg1, const RsGxsChannelPost &msg2)
@ -551,12 +584,35 @@ void GxsChannelPostsWidget::setAllMessagesRead(bool read)
#endif #endif
} }
void GxsChannelPostsWidget::setAutoDownloadButton(bool autoDl) void GxsChannelPostsWidget::subscribeGroup(bool subscribe)
{ {
if (autoDl) { if (mChannelId.isNull()) {
ui->actionEnable_Auto_Download->setText(tr("Disable Auto-Download")); return;
}else{ }
ui->actionEnable_Auto_Download->setText(tr("Enable Auto-Download"));
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;
} }
} }

View File

@ -71,6 +71,8 @@ protected:
private slots: private slots:
void createMsg(); void createMsg();
void toggleAutoDownload();
void subscribeGroup(bool subscribe);
void filterChanged(int filter); void filterChanged(int filter);
void filterItems(const QString& text); void filterItems(const QString& text);
@ -80,7 +82,7 @@ private slots:
private: private:
void processSettings(bool load); void processSettings(bool load);
void setAutoDownloadButton(bool autoDl); void setAutoDownload(bool autoDl);
void clearPosts(); void clearPosts();
/* NEW GXS FNS */ /* NEW GXS FNS */
@ -109,7 +111,7 @@ private:
//QList<ChanMsgItem *> mChanMsgItems; //QList<ChanMsgItem *> mChanMsgItems;
QList<GxsChannelPostItem *> mChannelPostItems; QList<GxsChannelPostItem *> mChannelPostItems;
std::map<std::string, uint32_t> mChanSearchScore; //chanId, score QAction *mAutoDownloadAction;
UIStateHelper *mStateHelper; UIStateHelper *mStateHelper;

View File

@ -123,6 +123,22 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="SubscribeToolButton" name="subscribeToolButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true">Subscribe</string>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item> <item>
<spacer name="horizontalSpacer"> <spacer name="horizontalSpacer">
<property name="orientation"> <property name="orientation">
@ -227,22 +243,6 @@
</widget> </widget>
</item> </item>
</layout> </layout>
<action name="actionsetAllAsRead">
<property name="text">
<string>Set all as read</string>
</property>
<property name="toolTip">
<string>Set all as read</string>
</property>
</action>
<action name="actionEnable_Auto_Download">
<property name="text">
<string>Enable Auto-Download</string>
</property>
<property name="toolTip">
<string>Enable Auto-Download</string>
</property>
</action>
<zorder>toolBarFrame</zorder> <zorder>toolBarFrame</zorder>
<zorder>scrollArea</zorder> <zorder>scrollArea</zorder>
<zorder>headFrame</zorder> <zorder>headFrame</zorder>
@ -253,6 +253,11 @@
<extends>QLineEdit</extends> <extends>QLineEdit</extends>
<header location="global">gui/common/LineEditClear.h</header> <header location="global">gui/common/LineEditClear.h</header>
</customwidget> </customwidget>
<customwidget>
<class>SubscribeToolButton</class>
<extends>QToolButton</extends>
<header>gui/Common/SubscribeToolButton.h</header>
</customwidget>
</customwidgets> </customwidgets>
<resources> <resources>
<include location="../images.qrc"/> <include location="../images.qrc"/>

View File

@ -459,6 +459,7 @@ HEADERS += rshare.h \
gui/common/MimeTextEdit.h \ gui/common/MimeTextEdit.h \
gui/common/UIStateHelper.h \ gui/common/UIStateHelper.h \
gui/common/FloatingHelpBrowser.h \ gui/common/FloatingHelpBrowser.h \
gui/common/SubscribeToolButton.h \
gui/style/RSStyle.h \ gui/style/RSStyle.h \
gui/style/StyleDialog.h \ gui/style/StyleDialog.h \
gui/MessagesDialog.h \ gui/MessagesDialog.h \
@ -746,6 +747,7 @@ SOURCES += main.cpp \
gui/common/MimeTextEdit.cpp \ gui/common/MimeTextEdit.cpp \
gui/common/UIStateHelper.cpp \ gui/common/UIStateHelper.cpp \
gui/common/FloatingHelpBrowser.cpp \ gui/common/FloatingHelpBrowser.cpp \
gui/common/SubscribeToolButton.cpp \
gui/style/RSStyle.cpp \ gui/style/RSStyle.cpp \
gui/style/StyleDialog.cpp \ gui/style/StyleDialog.cpp \
gui/settings/rsharesettings.cpp \ gui/settings/rsharesettings.cpp \