diff --git a/retroshare-gui/src/gui/Posted/PostedItem.cpp b/retroshare-gui/src/gui/Posted/PostedItem.cpp index 3e677af3e..56e26809f 100644 --- a/retroshare-gui/src/gui/Posted/PostedItem.cpp +++ b/retroshare-gui/src/gui/Posted/PostedItem.cpp @@ -175,6 +175,11 @@ RsPostedPost &PostedItem::post() return mPost; } +QString PostedItem::messageName() +{ + return QString::fromUtf8(mPost.mMeta.mMsgName.c_str()); +} + void PostedItem::makeDownVote() { RsGxsGrpMsgIdPair msgId; diff --git a/retroshare-gui/src/gui/Posted/PostedItem.h b/retroshare-gui/src/gui/Posted/PostedItem.h index 94fa70975..3429c2c35 100644 --- a/retroshare-gui/src/gui/Posted/PostedItem.h +++ b/retroshare-gui/src/gui/Posted/PostedItem.h @@ -53,6 +53,8 @@ signals: protected: virtual void loadMessage(const uint32_t &token); + virtual RetroShareLink::enumType getLinkType() { return RetroShareLink::TYPE_UNKNOWN; } + virtual QString messageName(); private: void setup(); diff --git a/retroshare-gui/src/gui/RetroShareLink.cpp b/retroshare-gui/src/gui/RetroShareLink.cpp index 0fffae8d1..64ba7258d 100644 --- a/retroshare-gui/src/gui/RetroShareLink.cpp +++ b/retroshare-gui/src/gui/RetroShareLink.cpp @@ -408,93 +408,37 @@ bool RetroShareLink::createUnknwonSslCertificate(const RsPeerId& sslId, const Rs return false; } -bool RetroShareLink::createForum(const std::string& id, const std::string& msgId) +bool RetroShareLink::createGxsGroupLink(const RetroShareLink::enumType &linkType, const RsGxsGroupId &groupId, const QString &groupName) { clear(); -#if 0 - if (!id.empty()) { - _hash = QString::fromStdString(id); - _msgId = QString::fromStdString(msgId); - - _type = TYPE_FORUM; - - if (msgId.empty()) { - ForumInfo fi; - if (rsForums->getForumInfo(id, fi)) { - _name = QString::fromStdWString(fi.forumName); - } - } else { - ForumMsgInfo mi; - if (rsForums->getForumMessage(id, msgId, mi)) { - _name = ForumsDialog::titleFromInfo(mi); - } - } + if (!groupId.isNull()) { + _hash = QString::fromStdString(groupId.toStdString()); + _type = linkType; + _name = groupName; } -#endif check(); return valid(); } -bool RetroShareLink::createChannel(const std::string &id, const std::string &msgId) +bool RetroShareLink::createGxsMessageLink(const RetroShareLink::enumType &linkType, const RsGxsGroupId &groupId, const RsGxsMessageId &msgId, const QString &msgName) { clear(); -#if 0 - if (!id.empty()) { - _hash = QString::fromStdString(id); - _msgId = QString::fromStdString(msgId); - - _type = TYPE_CHANNEL; - - if (msgId.empty()) { - ChannelInfo ci; - if (rsChannels->getChannelInfo(id, ci)) { - _name = QString::fromStdWString(ci.channelName); - } - } else { - ChannelMsgInfo mi; - if (rsChannels->getChannelMessage(id, msgId, mi)) { - _name = QString::fromStdWString(mi.subject); - } - } + if (!groupId.isNull() && !msgId.isNull()) { + _hash = QString::fromStdString(groupId.toStdString()); + _msgId = QString::fromStdString(msgId.toStdString()); + _type = linkType; + _name = msgName; } -#endif check(); return valid(); } -bool RetroShareLink::createGxsLink(const RsGxsGroupId &id, const RsGxsMessageId &msgId, - const std::string& groupName, const std::string& msgSubject, - const RetroShareLink::enumType &linkType) -{ - clear(); - - if (!id.isNull()) { - _hash = QString::fromStdString(id.toStdString()); - - if(!msgId.isNull()) - _msgId = QString::fromStdString(msgId.toStdString()); - - _type = linkType; - - if (msgId.isNull()) { - _name = QString::fromStdString(groupName); - } else { - _name = QString::fromStdString(msgSubject); - } - } - - check(); - - return valid(); -} - - bool RetroShareLink::createSearch(const QString& keywords) { clear(); diff --git a/retroshare-gui/src/gui/RetroShareLink.h b/retroshare-gui/src/gui/RetroShareLink.h index 964b42541..c36b9ff4d 100644 --- a/retroshare-gui/src/gui/RetroShareLink.h +++ b/retroshare-gui/src/gui/RetroShareLink.h @@ -56,17 +56,18 @@ class RetroShareLink { public: - enum enumType { TYPE_UNKNOWN = 0x00, - TYPE_FILE = 0x01, - TYPE_PERSON = 0x02, - TYPE_FORUM = 0x03, - TYPE_CHANNEL = 0x04, - TYPE_SEARCH = 0x05, - TYPE_MESSAGE = 0x06, - TYPE_CERTIFICATE = 0x07, - TYPE_EXTRAFILE = 0x08, - TYPE_PRIVATE_CHAT = 0x09, - TYPE_PUBLIC_MSG = 0x0a + enum enumType { + TYPE_UNKNOWN = 0x00, + TYPE_FILE = 0x01, + TYPE_PERSON = 0x02, + TYPE_FORUM = 0x03, + TYPE_CHANNEL = 0x04, + TYPE_SEARCH = 0x05, + TYPE_MESSAGE = 0x06, + TYPE_CERTIFICATE = 0x07, + TYPE_EXTRAFILE = 0x08, + TYPE_PRIVATE_CHAT = 0x09, + TYPE_PUBLIC_MSG = 0x0a }; public: @@ -76,18 +77,15 @@ class RetroShareLink bool createFile(const QString& name, uint64_t size, const QString& hash); bool createExtraFile(const QString& name, uint64_t size, const QString& hash, const QString& ssl_id); - bool createPerson(const RsPgpId &id); - bool createForum(const std::string& id, const std::string& msgId); - bool createChannel(const std::string& id, const std::string& msgId); - bool createGxsLink(const RsGxsGroupId &id, const RsGxsMessageId &msgId, - const std::string& groupName, const std::string& msgSubject, - const RetroShareLink::enumType &linkType); + bool createPerson(const RsPgpId &id); + bool createGxsGroupLink(const RetroShareLink::enumType &linkType, const RsGxsGroupId &groupId, const QString &groupName); + bool createGxsMessageLink(const RetroShareLink::enumType &linkType, const RsGxsGroupId &groupId, const RsGxsMessageId &msgId, const QString &msgName); bool createSearch(const QString& keywords); - bool createMessage(const RsPeerId &peerId, const QString& subject); - bool createMessage(const RsGxsId &peerId, const QString& subject); - bool createCertificate(const RsPeerId &ssl_id) ; + bool createMessage(const RsPeerId &peerId, const QString& subject); + bool createMessage(const RsGxsId &peerId, const QString& subject); + bool createCertificate(const RsPeerId &ssl_id) ; bool createPublicMsgInvite(time_t time_stamp,const QString& pgp_id,const QString& hash) ; - bool createUnknwonSslCertificate(const RsPeerId &sslId, const RsPgpId &gpgId = RsPgpId()) ; + bool createUnknwonSslCertificate(const RsPeerId &sslId, const RsPgpId &gpgId = RsPgpId()) ; enumType type() const {return _type; } uint64_t size() const { return _size ; } diff --git a/retroshare-gui/src/gui/common/GroupTreeWidget.cpp b/retroshare-gui/src/gui/common/GroupTreeWidget.cpp index 0213311de..c3f4f9d88 100644 --- a/retroshare-gui/src/gui/common/GroupTreeWidget.cpp +++ b/retroshare-gui/src/gui/common/GroupTreeWidget.cpp @@ -297,22 +297,22 @@ QString GroupTreeWidget::itemId(QTreeWidgetItem *item) return ""; } - return item->data(COLUMN_DATA, ROLE_ID).toString(); -} - -QString GroupTreeWidget::itemIdAt(QPoint &point) -{ - QTreeWidgetItem *item = ui->treeWidget->itemAt(point); - if (item == NULL) { - return ""; - } - - return item->data(COLUMN_DATA, ROLE_ID).toString(); -} - -void GroupTreeWidget::fillGroupItems(QTreeWidgetItem *categoryItem, const QList &itemList) -{ - if (categoryItem == NULL) { + return item->data(COLUMN_DATA, ROLE_ID).toString(); +} + +QString GroupTreeWidget::itemIdAt(QPoint &point) +{ + QTreeWidgetItem *item = ui->treeWidget->itemAt(point); + if (item == NULL) { + return ""; + } + + return item->data(COLUMN_DATA, ROLE_ID).toString(); +} + +void GroupTreeWidget::fillGroupItems(QTreeWidgetItem *categoryItem, const QList &itemList) +{ + if (categoryItem == NULL) { return; } @@ -423,7 +423,6 @@ void GroupTreeWidget::setUnreadCount(QTreeWidgetItem *item, int unreadCount) item->setText(COLUMN_NAME, name); item->setFont(COLUMN_NAME, font); - } QTreeWidgetItem *GroupTreeWidget::getItemFromId(const QString &id) @@ -467,19 +466,16 @@ RSTreeWidget *GroupTreeWidget::treeWidget() return ui->treeWidget; } -bool GroupTreeWidget::getGroupName(QString id, QTreeWidgetItem* categoryItem, QString& name) +bool GroupTreeWidget::getGroupName(QString id, QString& name) { - int childCount = categoryItem->childCount(); - for (int child = 0; child < childCount; child++) { - QTreeWidgetItem *childItem = categoryItem->child(child); - if (childItem->data(COLUMN_DATA, ROLE_ID).toString() == id) { - /* Found child */ + QTreeWidgetItem *item = getItemFromId(id); + if (item == NULL) { + return false; + } - name = childItem->text(COLUMN_NAME); - return true; - } - } - return false; + name = item->data(COLUMN_DATA, ROLE_NAME).toString(); + + return true; } int GroupTreeWidget::subscribeFlags(const QString &id) diff --git a/retroshare-gui/src/gui/common/GroupTreeWidget.h b/retroshare-gui/src/gui/common/GroupTreeWidget.h index abdbd8802..901056a24 100644 --- a/retroshare-gui/src/gui/common/GroupTreeWidget.h +++ b/retroshare-gui/src/gui/common/GroupTreeWidget.h @@ -80,13 +80,13 @@ public: void processSettings(RshareSettings *settings, bool load); // Add a new category item - QTreeWidgetItem *addCategoryItem(const QString &name, const QIcon &icon, bool expand); - // Get id of item - QString itemId(QTreeWidgetItem *item); - QString itemIdAt(QPoint &point); - // Fill items of a group - void fillGroupItems(QTreeWidgetItem *categoryItem, const QList &itemList); - // Set the unread count of an item + QTreeWidgetItem *addCategoryItem(const QString &name, const QIcon &icon, bool expand); + // Get id of item + QString itemId(QTreeWidgetItem *item); + QString itemIdAt(QPoint &point); + // Fill items of a group + void fillGroupItems(QTreeWidgetItem *categoryItem, const QList &itemList); + // Set the unread count of an item void setUnreadCount(QTreeWidgetItem *item, int unreadCount); QTreeWidgetItem *getItemFromId(const QString &id); @@ -99,7 +99,7 @@ public: void setTextColorCategory(QColor color) { mTextColor[GROUPTREEWIDGET_COLOR_CATEGORY] = color; } void setTextColorPrivateKey(QColor color) { mTextColor[GROUPTREEWIDGET_COLOR_PRIVATEKEY] = color; } - bool getGroupName(QString id, QTreeWidgetItem* item, QString& name); + bool getGroupName(QString id, QString& name); int subscribeFlags(const QString &id); diff --git a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp index eb517523d..75e74149f 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp +++ b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp @@ -189,11 +189,11 @@ void GxsChannelPostItem::loadPost(const RsGxsChannelPost &post) { title = tr("Channel Feed") + ": "; RetroShareLink link; - link.createChannel(post.mMeta.mGroupId.toStdString(), ""); + link.createGxsGroupLink(RetroShareLink::TYPE_CHANNEL, post.mMeta.mGroupId, ""); title += link.toHtml(); ui->titleLabel->setText(title); RetroShareLink msgLink; - msgLink.createChannel(post.mMeta.mGroupId.toStdString(), post.mMeta.mMsgId.toStdString()); + msgLink.createGxsMessageLink(RetroShareLink::TYPE_CHANNEL, post.mMeta.mGroupId, post.mMeta.mMsgId, QString::fromUtf8(post.mMeta.mMsgName.c_str())); ui->subjectLabel->setText(msgLink.toHtml()); if (IS_GROUP_SUBSCRIBED(mSubscribeFlags) || IS_GROUP_ADMIN(mSubscribeFlags)) @@ -314,6 +314,11 @@ void GxsChannelPostItem::loadPost(const RsGxsChannelPost &post) mInUpdateItemStatic = false; } +QString GxsChannelPostItem::messageName() +{ + return QString::fromUtf8(mPost.mMeta.mMsgName.c_str()); +} + void GxsChannelPostItem::setReadStatus(bool isNew, bool isUnread) { if (isUnread) @@ -536,25 +541,6 @@ void GxsChannelPostItem::channelMsgReadSatusChanged(const QString& channelId, co #endif } -void GxsChannelPostItem::copyLink() -{ -#if 0 - if (mChanId.empty() || mMsgId.empty()) { - return; - } - - ChannelMsgInfo cmi; - if (rsChannels->getChannelMessage(mChanId, mMsgId, cmi)) { - RetroShareLink link; - if (link.createChannel(cmi.channelId, cmi.msgId)) { - QList urls; - urls.push_back(link); - RSLinkClipboard::copyLinks(urls); - } - } -#endif -} - void GxsChannelPostItem::makeDownVote() { RsGxsGrpMsgIdPair msgId; diff --git a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h index 1f6434282..a05e404a9 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h +++ b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h @@ -55,6 +55,8 @@ public: protected: virtual void loadMessage(const uint32_t &token); + virtual RetroShareLink::enumType getLinkType() { return RetroShareLink::TYPE_CHANNEL; } + virtual QString messageName(); private slots: /* default stuff */ @@ -62,7 +64,6 @@ private slots: void readAndClearItem(); void download(); void play(); - void copyLink(); void loadComments(); void readToggled(bool checked); diff --git a/retroshare-gui/src/gui/gxs/GxsFeedItem.cpp b/retroshare-gui/src/gui/gxs/GxsFeedItem.cpp index cbf41441a..5552526c5 100644 --- a/retroshare-gui/src/gui/gxs/GxsFeedItem.cpp +++ b/retroshare-gui/src/gui/gxs/GxsFeedItem.cpp @@ -97,6 +97,24 @@ void GxsFeedItem::subscribe() } } +void GxsFeedItem::copyLink() +{ + if (mGroupId.isNull() || mMessageId.isNull()) { + return; + } + + if (getLinkType() == RetroShareLink::TYPE_UNKNOWN) { + return; + } + + RetroShareLink link; + if (link.createGxsMessageLink(getLinkType(), mGroupId, mMessageId, messageName())) { + QList urls; + urls.push_back(link); + RSLinkClipboard::copyLinks(urls); + } +} + void GxsFeedItem::updateItemStatic() { std::cerr << "GxsFeedItem::updateItemStatic()"; diff --git a/retroshare-gui/src/gui/gxs/GxsFeedItem.h b/retroshare-gui/src/gui/gxs/GxsFeedItem.h index 328b3fd11..26c14f783 100644 --- a/retroshare-gui/src/gui/gxs/GxsFeedItem.h +++ b/retroshare-gui/src/gui/gxs/GxsFeedItem.h @@ -26,6 +26,8 @@ #include #include "util/TokenQueue.h" +#include "gui/RetroShareLink.h" + #include class FeedHolder; @@ -54,6 +56,9 @@ protected: virtual void loadGroupMeta(const uint32_t &token); virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req); + virtual RetroShareLink::enumType getLinkType() = 0; + virtual QString messageName() = 0; + // general fns that can be implemented here. protected slots: @@ -61,6 +66,7 @@ protected slots: void subscribe(); void unsubscribe(); void removeItem(); + void copyLink(); private slots: /* RsGxsUpdateBroadcastBase */ @@ -85,4 +91,3 @@ private: }; #endif - diff --git a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp index 6e21eff88..24205d59e 100644 --- a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp +++ b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp @@ -386,48 +386,23 @@ void GxsGroupFrameDialog::copyGroupLink() return; } - RetroShareLink link; + RetroShareLink link; - QString name; - if(!getCurrentGroupName(name)) return; + QString name; + if(!getCurrentGroupName(name)) return; - if (link.createGxsLink(mGroupId, RsGxsMessageId(), name.toStdString(), "", getLinkType())) { - QList urls; - urls.push_back(link); - RSLinkClipboard::copyLinks(urls); - } + if (link.createGxsGroupLink(getLinkType(), mGroupId, name)) { + QList urls; + urls.push_back(link); + RSLinkClipboard::copyLinks(urls); + } } - - bool GxsGroupFrameDialog::getCurrentGroupName(QString& name) { - GroupTreeWidget* gtw = ui->groupTreeWidget; - - QString id = QString::fromStdString(mGroupId.toStdString()); - - if(gtw->getGroupName(id, mYourGroups, name)) - { - return true; - } - else if(gtw->getGroupName(id, mSubscribedGroups, name)) - { - return true; - } - else if(gtw->getGroupName(id, mYourGroups, name)) - { - return true; - } - else if(gtw->getGroupName(id, mOtherGroups, name)) - { - return true; - } - - return false; + return ui->groupTreeWidget->getGroupName(QString::fromStdString(mGroupId.toStdString()), name); } - - void GxsGroupFrameDialog::markMsgAsRead() { GxsMessageFrameWidget *msgWidget = messageWidget(mGroupId, false); diff --git a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h index aecdf74c4..0dadae306 100644 --- a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h +++ b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h @@ -73,7 +73,7 @@ public: GxsGroupFrameDialog(RsGxsIfaceHelper *ifaceImpl, QWidget *parent = 0); ~GxsGroupFrameDialog(); - bool navigate(const RsGxsGroupId groupId, const RsGxsMessageId& msgId); + bool navigate(const RsGxsGroupId groupId, const RsGxsMessageId& msgId); // Callback for all Loads. virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req);