diff --git a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp index 634ba768f..313cc4590 100644 --- a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp +++ b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp @@ -648,7 +648,7 @@ void GxsGroupFrameDialog::messageTabInfoChanged(QWidget *widget) } ///***** INSERT GROUP LISTS *****/ -void GxsGroupFrameDialog::groupInfoToGroupItemInfo(const RsGroupMetaData &groupInfo, GroupItemInfo &groupItemInfo) +void GxsGroupFrameDialog::groupInfoToGroupItemInfo(const RsGroupMetaData &groupInfo, GroupItemInfo &groupItemInfo, const RsUserdata */*userdata*/) { groupItemInfo.id = QString::fromStdString(groupInfo.mGroupId.toStdString()); groupItemInfo.name = QString::fromUtf8(groupInfo.mGroupName.c_str()); @@ -669,7 +669,7 @@ void GxsGroupFrameDialog::groupInfoToGroupItemInfo(const RsGroupMetaData &groupI } } -void GxsGroupFrameDialog::insertGroupsData(const std::list &groupList) +void GxsGroupFrameDialog::insertGroupsData(const std::list &groupList, const RsUserdata *userdata) { if (!mInitialized) { return; @@ -688,7 +688,7 @@ void GxsGroupFrameDialog::insertGroupsData(const std::list &gro uint32_t flags = it->mSubscribeFlags; GroupItemInfo groupItemInfo; - groupInfoToGroupItemInfo(*it, groupItemInfo); + groupInfoToGroupItemInfo(*it, groupItemInfo, userdata); if (IS_GROUP_SUBSCRIBED(flags)) { @@ -788,12 +788,18 @@ void GxsGroupFrameDialog::requestGroupSummary() mTokenQueue->cancelActiveRequestTokens(TOKEN_TYPE_GROUP_SUMMARY); RsTokReqOptions opts; - opts.mReqType = GXS_REQUEST_TYPE_GROUP_META; + opts.mReqType = requestGroupSummaryType(); uint32_t token; mTokenQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, TOKEN_TYPE_GROUP_SUMMARY); } +void GxsGroupFrameDialog::loadGroupSummaryToken(const uint32_t &token, std::list &groupInfo, RsUserdata *&/*userdata*/) +{ + /* Default implementation for request type GXS_REQUEST_TYPE_GROUP_META */ + mInterface->getGroupSummary(token, groupInfo); +} + void GxsGroupFrameDialog::loadGroupSummary(const uint32_t &token) { #ifdef DEBUG_GROUPFRAMEDIALOG @@ -802,23 +808,16 @@ void GxsGroupFrameDialog::loadGroupSummary(const uint32_t &token) #endif std::list groupInfo; - mInterface->getGroupSummary(token, groupInfo); + RsUserdata *userdata = NULL; + loadGroupSummaryToken(token, groupInfo, userdata); - if (groupInfo.size() > 0) - { - mStateHelper->setActive(TOKEN_TYPE_GROUP_SUMMARY, true); - - insertGroupsData(groupInfo); - } - else - { - std::cerr << "GxsGroupFrameDialog::loadGroupSummary() ERROR No Groups..."; - std::cerr << std::endl; - - mStateHelper->setActive(TOKEN_TYPE_GROUP_SUMMARY, false); - } + insertGroupsData(groupInfo, userdata); mStateHelper->setLoading(TOKEN_TYPE_GROUP_SUMMARY, false); + + if (userdata) { + delete(userdata); + } } /*********************** **** **** **** ***********************/ diff --git a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h index 4e6613f18..4f649b588 100644 --- a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h +++ b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h @@ -26,6 +26,7 @@ #include "RsAutoUpdatePage.h" #include "gui/RetroShareLink.h" #include "gui/settings/rsharesettings.h" +#include "util/RsUserdata.h" #include @@ -90,6 +91,7 @@ protected: bool getCurrentGroupName(QString& name); virtual RetroShareLink::enumType getLinkType() = 0; virtual GroupFrameSettings::Type groupFrameSettingsType() { return GroupFrameSettings::Nothing; } + virtual void groupInfoToGroupItemInfo(const RsGroupMetaData &groupInfo, GroupItemInfo &groupItemInfo, const RsUserdata *userdata); private slots: void todo(); @@ -139,7 +141,6 @@ private: void initUi(); void updateMessageSummaryList(RsGxsGroupId groupId); - void groupInfoToGroupItemInfo(const RsGroupMetaData &groupInfo, GroupItemInfo &groupItemInfo); void openGroupInNewTab(const RsGxsGroupId &groupId); void groupSubscribe(bool subscribe); @@ -147,10 +148,12 @@ private: void processSettings(bool load); // New Request/Response Loading Functions. - void insertGroupsData(const std::list &groupList); + void insertGroupsData(const std::list &groupList, const RsUserdata *userdata); void requestGroupSummary(); void loadGroupSummary(const uint32_t &token); + virtual uint32_t requestGroupSummaryType() { return GXS_REQUEST_TYPE_GROUP_META; } // request only meta data + virtual void loadGroupSummaryToken(const uint32_t &token, std::list &groupInfo, RsUserdata* &userdata); // use with requestGroupSummaryType void requestGroupStatistics(const RsGxsGroupId &groupId); void loadGroupStatistics(const uint32_t &token); diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp index dea42319e..c4bda400a 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp @@ -27,6 +27,16 @@ #include "gui/feeds/GxsChannelPostItem.h" #include "gui/settings/rsharesettings.h" #include "gui/notifyqt.h" +#include "gui/common/GroupTreeWidget.h" + +class GxsChannelGroupInfoData : public RsUserdata +{ +public: + GxsChannelGroupInfoData() : RsUserdata() {} + +public: + QMap mIcon; +}; /** Constructor */ GxsChannelDialog::GxsChannelDialog(QWidget *parent) @@ -168,3 +178,42 @@ void GxsChannelDialog::toggleAutoDownload() std::cerr << std::endl; } } + +void GxsChannelDialog::loadGroupSummaryToken(const uint32_t &token, std::list &groupInfo, RsUserdata *&userdata) +{ + std::vector groups; + rsGxsChannels->getGroupData(token, groups); + + /* Save groups to fill icons */ + GxsChannelGroupInfoData *channelData = new GxsChannelGroupInfoData; + userdata = channelData; + + std::vector::iterator groupIt; + for (groupIt = groups.begin(); groupIt != groups.end(); ++groupIt) { + RsGxsChannelGroup &group = *groupIt; + groupInfo.push_back(group.mMeta); + + if (group.mImage.mData != NULL) { + QPixmap image; + image.loadFromData(group.mImage.mData, group.mImage.mSize, "PNG"); + channelData->mIcon[group.mMeta.mGroupId] = image; + } + } +} + +void GxsChannelDialog::groupInfoToGroupItemInfo(const RsGroupMetaData &groupInfo, GroupItemInfo &groupItemInfo, const RsUserdata *userdata) +{ + GxsGroupFrameDialog::groupInfoToGroupItemInfo(groupInfo, groupItemInfo, userdata); + + const GxsChannelGroupInfoData *channelData = dynamic_cast(userdata); + if (!channelData) { + std::cerr << "GxsChannelDialog::groupInfoToGroupItemInfo() Failed to cast data to GxsChannelGroupInfoData"; + std::cerr << std::endl; + return; + } + + QMap::const_iterator iconIt = channelData->mIcon.find(groupInfo.mGroupId); + if (iconIt != channelData->mIcon.end()) { + groupItemInfo.icon = iconIt.value(); + } +} diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.h b/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.h index db22b6b4a..6fb99b9c8 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.h @@ -43,9 +43,11 @@ public: virtual UserNotify *getUserNotify(QObject *parent); protected: + /* GxsGroupFrameDialog */ virtual RetroShareLink::enumType getLinkType() { return RetroShareLink::TYPE_CHANNEL; } virtual GroupFrameSettings::Type groupFrameSettingsType() { return GroupFrameSettings::Channel; } virtual QString getHelpString() const ; + virtual void groupInfoToGroupItemInfo(const RsGroupMetaData &groupInfo, GroupItemInfo &groupItemInfo, const RsUserdata *userdata); private slots: void toggleAutoDownload(); @@ -62,6 +64,8 @@ private: virtual void groupTreeCustomActions(RsGxsGroupId grpId, int subscribeFlags, QList &actions); virtual RsGxsCommentService *getCommentService(); virtual QWidget *createCommentHeaderWidget(const RsGxsGroupId &grpId, const RsGxsMessageId &msgId); + virtual uint32_t requestGroupSummaryType() { return GXS_REQUEST_TYPE_GROUP_DATA; } // request complete group data + virtual void loadGroupSummaryToken(const uint32_t &token, std::list &groupInfo, RsUserdata* &userdata); }; #endif diff --git a/retroshare-gui/src/retroshare-gui.pro b/retroshare-gui/src/retroshare-gui.pro index ce632d0f0..8bd897d0d 100644 --- a/retroshare-gui/src/retroshare-gui.pro +++ b/retroshare-gui/src/retroshare-gui.pro @@ -367,6 +367,7 @@ HEADERS += rshare.h \ util/Widget.h \ util/rsguiversion.h \ util/RsAction.h \ + util/RsUserdata.h \ util/printpreview.h \ util/log.h \ util/misc.h \ diff --git a/retroshare-gui/src/util/RsUserdata.h b/retroshare-gui/src/util/RsUserdata.h new file mode 100644 index 000000000..204c0ebeb --- /dev/null +++ b/retroshare-gui/src/util/RsUserdata.h @@ -0,0 +1,34 @@ +/**************************************************************** + * This file is distributed under the following license: + * + * Copyright (c) 2014, RetroShare Team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + ****************************************************************/ + +#ifndef _RSUSERDATA_H +#define _RSUSERDATA_H + +class RsUserdata +{ +protected: + RsUserdata() {} + +public: + virtual ~RsUserdata() {} +}; + +#endif