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

@ -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<RsGxsGroupId> &grpIdsMeta = getGrpIdsMeta();
if (std::find(grpIdsMeta.begin(), grpIdsMeta.end(), mChannelId) != grpIdsMeta.end()) {
updateGroup = true;
}
const std::list<RsGxsGroupId> &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;
}
}

View file

@ -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<ChanMsgItem *> mChanMsgItems;
QList<GxsChannelPostItem *> mChannelPostItems;
std::map<std::string, uint32_t> mChanSearchScore; //chanId, score
QAction *mAutoDownloadAction;
UIStateHelper *mStateHelper;

View file

@ -123,6 +123,22 @@
</property>
</widget>
</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>
<spacer name="horizontalSpacer">
<property name="orientation">
@ -227,22 +243,6 @@
</widget>
</item>
</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>scrollArea</zorder>
<zorder>headFrame</zorder>
@ -253,6 +253,11 @@
<extends>QLineEdit</extends>
<header location="global">gui/common/LineEditClear.h</header>
</customwidget>
<customwidget>
<class>SubscribeToolButton</class>
<extends>QToolButton</extends>
<header>gui/Common/SubscribeToolButton.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../images.qrc"/>