From 958db27eaa3a97ee246eee743917ca61dbe31a89 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 21 Apr 2020 20:59:14 +0200 Subject: [PATCH 1/3] started improving Boards the same way than Channels. Not working yet --- .../src/gui/Posted/PostedCardView.cpp | 94 +++++++-------- .../src/gui/Posted/PostedCardView.h | 17 ++- retroshare-gui/src/gui/Posted/PostedItem.cpp | 96 ++++++--------- retroshare-gui/src/gui/Posted/PostedItem.h | 16 +-- .../src/gui/Posted/PostedListWidget.cpp | 19 ++- .../src/gui/Posted/PostedListWidget.h | 2 + .../src/gui/feeds/GxsChannelPostItem.cpp | 111 +++++++++--------- .../src/gui/feeds/GxsChannelPostItem.h | 13 +- 8 files changed, 165 insertions(+), 203 deletions(-) diff --git a/retroshare-gui/src/gui/Posted/PostedCardView.cpp b/retroshare-gui/src/gui/Posted/PostedCardView.cpp index 60e947ec1..f0cbedc73 100644 --- a/retroshare-gui/src/gui/Posted/PostedCardView.cpp +++ b/retroshare-gui/src/gui/Posted/PostedCardView.cpp @@ -40,43 +40,48 @@ /** Constructor */ -PostedCardView::PostedCardView(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate) : - GxsFeedItem(feedHolder, feedId, groupId, messageId, isHome, rsPosted, autoUpdate) +PostedCardView::PostedCardView(FeedHolder *feedHolder, uint32_t feedId, const RsGroupMetaData &group_meta, const RsGxsMessageId &post_id, bool isHome, bool autoUpdate) : + GxsFeedItem(feedHolder, feedId, group_meta.mGroupId, post_id, isHome, rsPosted, autoUpdate), + mGroupMeta(group_meta) { - setup(); + mPost.mMeta.mMsgId = post_id; + mPost.mMeta.mGroupId = mGroupMeta.mGroupId; - requestGroup(); - requestMessage(); - requestComment(); + mLoaded = false; + setup(); } -PostedCardView::PostedCardView(FeedHolder *feedHolder, uint32_t feedId, const RsPostedGroup &group, const RsPostedPost &post, bool isHome, bool autoUpdate) : - GxsFeedItem(feedHolder, feedId, post.mMeta.mGroupId, post.mMeta.mMsgId, isHome, rsPosted, autoUpdate) +PostedCardView::PostedCardView(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate) : + GxsFeedItem(feedHolder, feedId, groupId, post_id, isHome, rsPosted, autoUpdate) { - setup(); - - mMessageId = post.mMeta.mMsgId; + mPost.mMeta.mMsgId = post_id; + mLoaded = false; - - setGroup(group, false); - setPost(post); - requestComment(); -} - -PostedCardView::PostedCardView(FeedHolder *feedHolder, uint32_t feedId, const RsPostedPost &post, bool isHome, bool autoUpdate) : - GxsFeedItem(feedHolder, feedId, post.mMeta.mGroupId, post.mMeta.mMsgId, isHome, rsPosted, autoUpdate) -{ setup(); - requestGroup(); - setPost(post); - requestComment(); + loadGroup(); } PostedCardView::~PostedCardView() { delete(ui); } +void PostedCardView::paintEvent(QPaintEvent *e) +{ + /* This method employs a trick to trigger a deferred loading. The post and group is requested only + * when actually displayed on the screen. */ + + if(!mLoaded) + { + mLoaded = true ; + + fill(); + requestMessage(); + requestComment(); + } + + GxsFeedItem::paintEvent(e) ; +} void PostedCardView::setup() { @@ -125,23 +130,6 @@ void PostedCardView::setup() ui->readAndClearButton->hide(); } -bool PostedCardView::setGroup(const RsPostedGroup &group, bool doFill) -{ - if (groupId() != group.mMeta.mGroupId) { - std::cerr << "PostedCardView::setGroup() - Wrong id, cannot set post"; - std::cerr << std::endl; - return false; - } - - mGroup = group; - - if (doFill) { - fill(); - } - - return true; -} - bool PostedCardView::setPost(const RsPostedPost &post, bool doFill) { if (groupId() != post.mMeta.mGroupId || messageId() != post.mMeta.mMsgId) { @@ -192,7 +180,7 @@ void PostedCardView::loadGroup() * thread, for example to update the data model with new information * after a blocking call to RetroShare API complete */ - setGroup(group); + mGroupMeta = group.mMeta; }, this ); }); @@ -218,7 +206,7 @@ void PostedCardView::loadMessage() std::cerr << (void*)this << ": Obtained post, with msgId = " << posts[0].mMeta.mMsgId << std::endl; const RsPostedPost& post(posts[0]); - RsQThreadUtils::postToObject( [post,this]() { setPost(post); }, this ); + RsQThreadUtils::postToObject( [post,this]() { setPost(post,true); }, this ); } else if(comments.size() == 1) { @@ -461,19 +449,19 @@ void PostedCardView::fill() emit sizeChanged(this); } -const RsPostedPost &PostedCardView::getPost() const -{ - return mPost; -} +//const RsPostedPost &PostedCardView::getPost() const +//{ +// return mPost; +//} -RsPostedPost &PostedCardView::post() -{ - return mPost; -} +//RsPostedPost &PostedCardView::post() +//{ +// return mPost; +//} QString PostedCardView::groupName() { - return QString::fromUtf8(mGroup.mMeta.mGroupName.c_str()); + return QString::fromUtf8(mGroupMeta.mGroupName.c_str()); } QString PostedCardView::messageName() @@ -586,11 +574,11 @@ void PostedCardView::doExpand(bool open) void PostedCardView::copyMessageLink() { - if (groupId().isNull() || mMessageId.isNull()) { + if (groupId().isNull() || messageId().isNull()) { return; } - RetroShareLink link = RetroShareLink::createGxsMessageLink(RetroShareLink::TYPE_POSTED, groupId(), mMessageId, messageName()); + RetroShareLink link = RetroShareLink::createGxsMessageLink(RetroShareLink::TYPE_POSTED, groupId(), messageId(), messageName()); if (link.valid()) { QList urls; diff --git a/retroshare-gui/src/gui/Posted/PostedCardView.h b/retroshare-gui/src/gui/Posted/PostedCardView.h index 49f6e68c4..8a93e6509 100644 --- a/retroshare-gui/src/gui/Posted/PostedCardView.h +++ b/retroshare-gui/src/gui/Posted/PostedCardView.h @@ -38,22 +38,21 @@ class PostedCardView : public GxsFeedItem Q_OBJECT public: - PostedCardView(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate); - PostedCardView(FeedHolder *parent, uint32_t feedId, const RsPostedGroup &group, const RsPostedPost &post, bool isHome, bool autoUpdate); - PostedCardView(FeedHolder *parent, uint32_t feedId, const RsPostedPost &post, bool isHome, bool autoUpdate); + PostedCardView(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId& groupId, const RsGxsMessageId& messageId, bool isHome, bool autoUpdate); + PostedCardView(FeedHolder *parent, uint32_t feedId, const RsGroupMetaData& group_meta, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate); virtual ~PostedCardView(); - bool setGroup(const RsPostedGroup& group, bool doFill = true); bool setPost(const RsPostedPost& post, bool doFill = true); - const RsPostedPost &getPost() const; - RsPostedPost &post(); + const RsPostedPost &getPost() const { return mPost; } + //RsPostedPost& post(); - uint64_t uniqueIdentifier() const override { return hash_64bits("PostedItem " + mMessageId.toStdString()); } + uint64_t uniqueIdentifier() const override { return hash_64bits("PostedItem " + messageId().toStdString()); } protected: /* FeedItem */ virtual void doExpand(bool open); + void paintEvent(QPaintEvent *e) override; private slots: void loadComments(); @@ -84,10 +83,10 @@ private: private: bool mInFill; + bool mLoaded; - RsPostedGroup mGroup; + RsGroupMetaData mGroupMeta; RsPostedPost mPost; - RsGxsMessageId mMessageId; /** Qt Designer generated object */ Ui::PostedCardView *ui; diff --git a/retroshare-gui/src/gui/Posted/PostedItem.cpp b/retroshare-gui/src/gui/Posted/PostedItem.cpp index e2352bd41..859ccf3c1 100644 --- a/retroshare-gui/src/gui/Posted/PostedItem.cpp +++ b/retroshare-gui/src/gui/Posted/PostedItem.cpp @@ -41,37 +41,27 @@ /** Constructor */ -PostedItem::PostedItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate) : - GxsFeedItem(feedHolder, feedId, groupId, messageId, isHome, rsPosted, autoUpdate) +PostedItem::PostedItem(FeedHolder *feedHolder, uint32_t feedId, const RsGroupMetaData &group_meta, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate) : + GxsFeedItem(feedHolder, feedId, group_meta.mGroupId, post_id, isHome, rsPosted, autoUpdate), + mGroupMeta(group_meta) { - setup(); + mPost.mMeta.mMsgId = post_id; + mPost.mMeta.mGroupId = mGroupMeta.mGroupId; - requestGroup(); - requestMessage(); - requestComment(); + mLoaded = false; + + setup(); } -PostedItem::PostedItem(FeedHolder *feedHolder, uint32_t feedId, const RsPostedGroup &group, const RsPostedPost &post, bool isHome, bool autoUpdate) : - GxsFeedItem(feedHolder, feedId, post.mMeta.mGroupId, post.mMeta.mMsgId, isHome, rsPosted, autoUpdate) +PostedItem::PostedItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate) : + GxsFeedItem(feedHolder, feedId, groupId, post_id, isHome, rsPosted, autoUpdate) { + mPost.mMeta.mMsgId = post_id; + + mLoaded = false; + setup(); - - mMessageId = post.mMeta.mMsgId; - - - setGroup(group, false); - setPost(post); - requestComment(); -} - -PostedItem::PostedItem(FeedHolder *feedHolder, uint32_t feedId, const RsPostedPost &post, bool isHome, bool autoUpdate) : - GxsFeedItem(feedHolder, feedId, post.mMeta.mGroupId, post.mMeta.mMsgId, isHome, rsPosted, autoUpdate) -{ - setup(); - - requestGroup(); - setPost(post); - requestComment(); + loadGroup(); } PostedItem::~PostedItem() @@ -79,6 +69,23 @@ PostedItem::~PostedItem() delete(ui); } +void PostedItem::paintEvent(QPaintEvent *e) +{ + /* This method employs a trick to trigger a deferred loading. The post and group is requested only + * when actually displayed on the screen. */ + + if(!mLoaded) + { + mLoaded = true ; + + fill(); + requestMessage(); + requestComment(); + } + + GxsFeedItem::paintEvent(e) ; +} + void PostedItem::setup() { /* Invoke the Qt Designer generated object setup routine */ @@ -137,23 +144,6 @@ void PostedItem::setup() ui->nameLabel->hide(); } -bool PostedItem::setGroup(const RsPostedGroup &group, bool doFill) -{ - if (groupId() != group.mMeta.mGroupId) { - std::cerr << "PostedItem::setGroup() - Wrong id, cannot set post"; - std::cerr << std::endl; - return false; - } - - mGroup = group; - - if (doFill) { - fill(); - } - - return true; -} - bool PostedItem::setPost(const RsPostedPost &post, bool doFill) { if (groupId() != post.mMeta.mGroupId || messageId() != post.mMeta.mMsgId) { @@ -204,7 +194,7 @@ void PostedItem::loadGroup() * thread, for example to update the data model with new information * after a blocking call to RetroShare API complete */ - setGroup(group); + mGroupMeta = group.mMeta; }, this ); }); @@ -303,7 +293,7 @@ void PostedItem::loadComment() void PostedItem::fill() { - RetroShareLink link = RetroShareLink::createGxsGroupLink(RetroShareLink::TYPE_POSTED, mGroup.mMeta.mGroupId, groupName()); + RetroShareLink link = RetroShareLink::createGxsGroupLink(RetroShareLink::TYPE_POSTED, mGroupMeta.mGroupId, groupName()); ui->nameLabel->setText(link.toHtml()); QPixmap sqpixmap2 = QPixmap(":/images/thumb-default.png"); @@ -486,19 +476,9 @@ void PostedItem::fill() emit sizeChanged(this); } -const RsPostedPost &PostedItem::getPost() const -{ - return mPost; -} - -RsPostedPost &PostedItem::post() -{ - return mPost; -} - QString PostedItem::groupName() { - return QString::fromUtf8(mGroup.mMeta.mGroupName.c_str()); + return QString::fromUtf8(mGroupMeta.mGroupName.c_str()); } QString PostedItem::messageName() @@ -619,11 +599,11 @@ void PostedItem::doExpand(bool open) void PostedItem::copyMessageLink() { - if (groupId().isNull() || mMessageId.isNull()) { + if (groupId().isNull() || messageId().isNull()) { return; } - RetroShareLink link = RetroShareLink::createGxsMessageLink(RetroShareLink::TYPE_POSTED, groupId(), mMessageId, messageName()); + RetroShareLink link = RetroShareLink::createGxsMessageLink(RetroShareLink::TYPE_POSTED, groupId(), messageId(), messageName()); if (link.valid()) { QList urls; @@ -663,7 +643,7 @@ void PostedItem::viewPicture() PView->setName(authorID); PView->setTime(timestamp); PView->setGroupId(groupId()); - PView->setMessageId(mMessageId); + PView->setMessageId(messageId()); PView->show(); diff --git a/retroshare-gui/src/gui/Posted/PostedItem.h b/retroshare-gui/src/gui/Posted/PostedItem.h index 0d6a161f6..403298ff4 100644 --- a/retroshare-gui/src/gui/Posted/PostedItem.h +++ b/retroshare-gui/src/gui/Posted/PostedItem.h @@ -38,21 +38,21 @@ class PostedItem : public GxsFeedItem Q_OBJECT public: - PostedItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate); - PostedItem(FeedHolder *parent, uint32_t feedId, const RsPostedGroup &group, const RsPostedPost &post, bool isHome, bool autoUpdate); - PostedItem(FeedHolder *parent, uint32_t feedId, const RsPostedPost &post, bool isHome, bool autoUpdate); + PostedItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId& groupId, const RsGxsMessageId& messageId, bool isHome, bool autoUpdate); + PostedItem(FeedHolder *parent, uint32_t feedId, const RsGroupMetaData& group_meta, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate); + virtual ~PostedItem(); - bool setGroup(const RsPostedGroup& group, bool doFill = true); bool setPost(const RsPostedPost& post, bool doFill = true); - const RsPostedPost& getPost() const; - RsPostedPost &post(); + const RsPostedPost& getPost() const { return mPost ; } + RsPostedPost& getPost() { return mPost ; } uint64_t uniqueIdentifier() const override { return hash_64bits("PostedItem " + messageId().toStdString()); } protected: /* FeedItem */ virtual void doExpand(bool open); + virtual void paintEvent(QPaintEvent *) override; private slots: void loadComments(); @@ -87,10 +87,10 @@ private: private: bool mInFill; + bool mLoaded; - RsPostedGroup mGroup; + RsGroupMetaData mGroupMeta; RsPostedPost mPost; - RsGxsMessageId mMessageId; /** Qt Designer generated object */ Ui::PostedItem *ui; diff --git a/retroshare-gui/src/gui/Posted/PostedListWidget.cpp b/retroshare-gui/src/gui/Posted/PostedListWidget.cpp index 6c6e04158..53f97b7ad 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidget.cpp +++ b/retroshare-gui/src/gui/Posted/PostedListWidget.cpp @@ -481,26 +481,22 @@ void PostedListWidget::insertPostedDetails(const RsPostedGroup &group) /*********************** **** **** **** ***********************/ /*********************** **** **** **** ***********************/ -void PostedListWidget::loadPost(const RsPostedPost &post) +void PostedListWidget::loadPost(const RsPostedPost& post) { /* Group is not always available because of the TokenQueue */ - RsPostedGroup dummyGroup; - dummyGroup.mMeta.mGroupId = groupId(); - PostedItem *item = new PostedItem(this, 0, dummyGroup, post, true, false); + PostedItem *item = new PostedItem(this, 0, mGroup.mMeta, post.mMeta.mMsgId, true, false); connect(item, SIGNAL(vote(RsGxsGrpMsgIdPair,bool)), this, SLOT(submitVote(RsGxsGrpMsgIdPair,bool))); mPosts.insert(post.mMeta.mMsgId, item); mPostItems.push_back(item); } -void PostedListWidget::loadPostCardView(const RsPostedPost &post) +void PostedListWidget::loadPostCardView(const RsPostedPost& post) { /* Group is not always available because of the TokenQueue */ - RsPostedGroup dummyGroup; - dummyGroup.mMeta.mGroupId = groupId(); - PostedCardView *cvitem = new PostedCardView(this, 0, dummyGroup, post, true, false); + PostedCardView *cvitem = new PostedCardView(this, 0, mGroup.mMeta, post.mMeta.mMsgId, true, false); connect(cvitem, SIGNAL(vote(RsGxsGrpMsgIdPair,bool)), this, SLOT(submitVote(RsGxsGrpMsgIdPair,bool))); mCVPosts.insert(post.mMeta.mMsgId, cvitem); @@ -928,7 +924,7 @@ void PostedListWidget::insertPostedPosts(const std::vector& posts) std::cerr << std::endl; #endif /* insert new entry */ - loadPost(p); + //loadPost(p); loadPostCardView(p); } } @@ -937,7 +933,7 @@ void PostedListWidget::insertPostedPosts(const std::vector& posts) QMap::iterator pit; for(pit = mPosts.begin(); pit != mPosts.end(); ++pit) { - (*pit)->post().calculateScores(now); + (*pit)->getPost().calculateScores(now); } applyRanking(); @@ -1067,7 +1063,8 @@ bool PostedListWidget::getGroupData(RsGxsGenericGroupData*& data) if(! rsPosted->getBoardsInfo(std::list({groupId()}),groupInfo) || groupInfo.size() != 1) return false; - data = new RsPostedGroup(groupInfo[0]); + mGroup = groupInfo[0]; + data = new RsPostedGroup(mGroup); return true; } diff --git a/retroshare-gui/src/gui/Posted/PostedListWidget.h b/retroshare-gui/src/gui/Posted/PostedListWidget.h index 06e60493d..a9892d47c 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidget.h +++ b/retroshare-gui/src/gui/Posted/PostedListWidget.h @@ -23,6 +23,7 @@ #include +#include "retroshare/rsposted.h" #include "gui/gxs/GxsMessageFramePostWidget.h" #include "gui/feeds/FeedHolder.h" @@ -127,6 +128,7 @@ private: uint32_t mTokenTypeVote; + RsPostedGroup mGroup; QMap mPosts; QList mPostItems; diff --git a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp index c01ca7315..5678cb018 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp +++ b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp @@ -95,23 +95,23 @@ GxsChannelPostItem::GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, // mPost = post ; // } -void GxsChannelPostItem::init(const RsGxsMessageId& messageId,const std::set& older_versions) -{ - QVector v; - //bool self = false; - - for(std::set::const_iterator it(older_versions.begin());it!=older_versions.end();++it) - v.push_back(*it) ; - - if(older_versions.find(messageId) == older_versions.end()) - v.push_back(messageId); - - setMessageVersions(v) ; - - setup(); - - mLoaded = false ; -} +// void GxsChannelPostItem::init(const RsGxsMessageId& messageId,const std::set& older_versions) +// { +// QVector v; +// //bool self = false; +// +// for(std::set::const_iterator it(older_versions.begin());it!=older_versions.end();++it) +// v.push_back(*it) ; +// +// if(older_versions.find(messageId) == older_versions.end()) +// v.push_back(messageId); +// +// setMessageVersions(v) ; +// +// setup(); +// +// mLoaded = false ; +// } void GxsChannelPostItem::paintEvent(QPaintEvent *e) { @@ -267,6 +267,45 @@ void GxsChannelPostItem::loadComments() comments(title); } +void GxsChannelPostItem::loadGroup() +{ +#ifdef DEBUG_ITEM + std::cerr << "GxsChannelGroupItem::loadGroup()"; + std::cerr << std::endl; +#endif + + RsThread::async([this]() + { + // 1 - get group data + + std::vector groups; + const std::list groupIds = { groupId() }; + + if(!rsGxsChannels->getChannelsInfo(groupIds,groups)) // would be better to call channel Summaries for a single group + { + RsErr() << "GxsGxsChannelGroupItem::loadGroup() ERROR getting data" << std::endl; + return; + } + + if (groups.size() != 1) + { + std::cerr << "GxsGxsChannelGroupItem::loadGroup() Wrong number of Items"; + std::cerr << std::endl; + return; + } + RsGxsChannelGroup group(groups[0]); + + RsQThreadUtils::postToObject( [group,this]() + { + /* Here it goes any code you want to be executed on the Qt Gui + * thread, for example to update the data model with new information + * after a blocking call to RetroShare API complete */ + + mGroupMeta = group.mMeta; + + }, this ); + }); +} void GxsChannelPostItem::loadMessage() { #ifdef DEBUG_ITEM @@ -834,42 +873,4 @@ void GxsChannelPostItem::makeUpVote() emit vote(msgId, true); } -void GxsChannelPostItem::loadGroup() -{ -#ifdef DEBUG_ITEM - std::cerr << "GxsChannelGroupItem::loadGroup()"; - std::cerr << std::endl; -#endif - RsThread::async([this]() - { - // 1 - get group data - - std::vector groups; - const std::list groupIds = { groupId() }; - - if(!rsGxsChannels->getChannelsInfo(groupIds,groups)) // would be better to call channel Summaries for a single group - { - RsErr() << "GxsGxsChannelGroupItem::loadGroup() ERROR getting data" << std::endl; - return; - } - - if (groups.size() != 1) - { - std::cerr << "GxsGxsChannelGroupItem::loadGroup() Wrong number of Items"; - std::cerr << std::endl; - return; - } - RsGxsChannelGroup group(groups[0]); - - RsQThreadUtils::postToObject( [group,this]() - { - /* Here it goes any code you want to be executed on the Qt Gui - * thread, for example to update the data model with new information - * after a blocking call to RetroShare API complete */ - - mGroupMeta = group.mMeta; - - }, this ); - }); -} diff --git a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h index b5dc7ab7f..86aa20371 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h +++ b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h @@ -49,17 +49,12 @@ public: GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGroupMetaData& group, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate, const std::set& older_versions = std::set()); -// // This method can be called when additional information is known about the post. In this case, the widget will be initialized with some -// // minimap information from the post and completed when the use displays it, which shouldn't cost anything more. -// -// GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsChannelPost& post, bool isHome, bool autoUpdate, const std::set& older_versions = std::set()); - virtual ~GxsChannelPostItem(); uint64_t uniqueIdentifier() const override { return hash_64bits("GxsChannelPostItem " + messageId().toStdString()) ; } - bool setGroup(const RsGxsChannelGroup &group, bool doFill = true); - bool setPost(const RsGxsChannelPost &post, bool doFill = true); + bool setGroup(const RsGxsChannelGroup& group, bool doFill = true); + bool setPost(const RsGxsChannelPost& post, bool doFill = true); void setFileCleanUpWarning(uint32_t time_left); @@ -72,7 +67,7 @@ public: static uint64_t computeIdentifier(const RsGxsMessageId& msgid) { return hash64("GxsChannelPostItem " + msgid.toStdString()) ; } protected: - void init(const RsGxsMessageId& messageId,const std::set& older_versions); + //void init(const RsGxsMessageId& messageId,const std::set& older_versions); /* FeedItem */ virtual void doExpand(bool open); @@ -81,7 +76,7 @@ protected: // This does nothing except triggering the loading of the post data and comments. This function is mainly used to detect // when the post is actually made visible. - virtual void paintEvent(QPaintEvent *); + virtual void paintEvent(QPaintEvent *) override; /* GxsGroupFeedItem */ virtual QString groupName(); From 3f72f1ff098c07d9dc9fd3e74b2512d0356186bc Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 22 Apr 2020 21:39:12 +0200 Subject: [PATCH 2/3] splitted PostedCardView/PostedItem into 3 classes, one base and two UI classes, and factored as much as possible. --- .../src/gui/Posted/PostedCardView.cpp | 370 ++--------- .../src/gui/Posted/PostedCardView.h | 55 +- retroshare-gui/src/gui/Posted/PostedItem.cpp | 573 +++++++++--------- retroshare-gui/src/gui/Posted/PostedItem.h | 61 +- 4 files changed, 414 insertions(+), 645 deletions(-) diff --git a/retroshare-gui/src/gui/Posted/PostedCardView.cpp b/retroshare-gui/src/gui/Posted/PostedCardView.cpp index f0cbedc73..7b9dbaabc 100644 --- a/retroshare-gui/src/gui/Posted/PostedCardView.cpp +++ b/retroshare-gui/src/gui/Posted/PostedCardView.cpp @@ -40,48 +40,80 @@ /** Constructor */ -PostedCardView::PostedCardView(FeedHolder *feedHolder, uint32_t feedId, const RsGroupMetaData &group_meta, const RsGxsMessageId &post_id, bool isHome, bool autoUpdate) : - GxsFeedItem(feedHolder, feedId, group_meta.mGroupId, post_id, isHome, rsPosted, autoUpdate), - mGroupMeta(group_meta) +PostedCardView::PostedCardView(FeedHolder *feedHolder, uint32_t feedId, const RsGroupMetaData &group_meta, const RsGxsMessageId &post_id, bool isHome, bool autoUpdate) + : BasePostedItem(feedHolder, feedId, group_meta, post_id, isHome, autoUpdate) { - mPost.mMeta.mMsgId = post_id; - mPost.mMeta.mGroupId = mGroupMeta.mGroupId; - - mLoaded = false; - setup(); + setup(); } -PostedCardView::PostedCardView(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate) : - GxsFeedItem(feedHolder, feedId, groupId, post_id, isHome, rsPosted, autoUpdate) +PostedCardView::PostedCardView(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate) + : BasePostedItem(feedHolder, feedId, groupId, post_id, isHome, autoUpdate) { - mPost.mMeta.mMsgId = post_id; - mLoaded = false; - - setup(); - + setup(); loadGroup(); } +void PostedCardView::setCommentsSize(int comNb) +{ + QString sComButText = tr("Comment"); + if (comNb == 1) + sComButText = sComButText.append("(1)"); + else if(comNb > 1) + sComButText = tr("Comments ").append("(%1)").arg(comNb); + + ui->commentButton->setText(sComButText); +} + +void PostedCardView::makeDownVote() +{ + RsGxsGrpMsgIdPair msgId; + msgId.first = mPost.mMeta.mGroupId; + msgId.second = mPost.mMeta.mMsgId; + + ui->voteUpButton->setEnabled(false); + ui->voteDownButton->setEnabled(false); + + emit vote(msgId, false); +} + +void PostedCardView::makeUpVote() +{ + RsGxsGrpMsgIdPair msgId; + msgId.first = mPost.mMeta.mGroupId; + msgId.second = mPost.mMeta.mMsgId; + + ui->voteUpButton->setEnabled(false); + ui->voteDownButton->setEnabled(false); + + emit vote(msgId, true); +} + +void PostedCardView::setReadStatus(bool isNew, bool isUnread) +{ + if (isUnread) + { + ui->readButton->setChecked(true); + ui->readButton->setIcon(QIcon(":/images/message-state-unread.png")); + } + else + { + ui->readButton->setChecked(false); + ui->readButton->setIcon(QIcon(":/images/message-state-read.png")); + } + + ui->newLabel->setVisible(isNew); + + ui->mainFrame->setProperty("new", isNew); + ui->mainFrame->style()->unpolish(ui->mainFrame); + ui->mainFrame->style()->polish( ui->mainFrame); +} + +void PostedCardView::setComment(const RsGxsComment& cmt) {} + PostedCardView::~PostedCardView() { delete(ui); } -void PostedCardView::paintEvent(QPaintEvent *e) -{ - /* This method employs a trick to trigger a deferred loading. The post and group is requested only - * when actually displayed on the screen. */ - - if(!mLoaded) - { - mLoaded = true ; - - fill(); - requestMessage(); - requestComment(); - } - - GxsFeedItem::paintEvent(e) ; -} void PostedCardView::setup() { @@ -130,144 +162,7 @@ void PostedCardView::setup() ui->readAndClearButton->hide(); } -bool PostedCardView::setPost(const RsPostedPost &post, bool doFill) -{ - if (groupId() != post.mMeta.mGroupId || messageId() != post.mMeta.mMsgId) { - std::cerr << "PostedCardView::setPost() - Wrong id, cannot set post"; - std::cerr << std::endl; - return false; - } - mPost = post; - - if (doFill) { - fill(); - } - - return true; -} - -void PostedCardView::loadGroup() -{ - RsThread::async([this]() - { - // 1 - get group data - -#ifdef DEBUG_FORUMS - std::cerr << "Retrieving post data for post " << mThreadId << std::endl; -#endif - - std::vector groups; - const std::list groupIds = { groupId() }; - - if(!rsPosted->getBoardsInfo(groupIds,groups)) - { - RsErr() << "GxsPostedGroupItem::loadGroup() ERROR getting data" << std::endl; - return; - } - - if (groups.size() != 1) - { - std::cerr << "GxsPostedGroupItem::loadGroup() Wrong number of Items"; - std::cerr << std::endl; - return; - } - RsPostedGroup group(groups[0]); - - RsQThreadUtils::postToObject( [group,this]() - { - /* Here it goes any code you want to be executed on the Qt Gui - * thread, for example to update the data model with new information - * after a blocking call to RetroShare API complete */ - - mGroupMeta = group.mMeta; - - }, this ); - }); -} - -void PostedCardView::loadMessage() -{ - RsThread::async([this]() - { - // 1 - get group data - - std::vector posts; - std::vector comments; - - if(! rsPosted->getBoardContent( groupId(), std::set( { messageId() } ),posts,comments)) - { - RsErr() << "PostedItem::loadMessage() ERROR getting data" << std::endl; - return; - } - - if (posts.size() == 1) - { - std::cerr << (void*)this << ": Obtained post, with msgId = " << posts[0].mMeta.mMsgId << std::endl; - const RsPostedPost& post(posts[0]); - - RsQThreadUtils::postToObject( [post,this]() { setPost(post,true); }, this ); - } - else if(comments.size() == 1) - { - const RsGxsComment& cmt = comments[0]; - std::cerr << (void*)this << ": Obtained comment, setting messageId to threadID = " << cmt.mMeta.mThreadId << std::endl; - - RsQThreadUtils::postToObject( [cmt,this]() - { - //Change this item to be uploaded with thread element. - setMessageId(cmt.mMeta.mThreadId); - requestMessage(); - - }, this ); - - } - else - { - std::cerr << "GxsChannelPostItem::loadMessage() Wrong number of Items. Remove It."; - std::cerr << std::endl; - - RsQThreadUtils::postToObject( [this]() { removeItem(); }, this ); - } - }); - -} - -void PostedCardView::loadComment() -{ - RsThread::async([this]() - { - // 1 - get group data - - std::set msgIds; - - for(auto MsgId: messageVersions()) - msgIds.insert(MsgId); - - std::vector posts; - std::vector comments; - - if(! rsPosted->getBoardContent( groupId(),msgIds,posts,comments)) - { - RsErr() << "PostedCardView::loadGroup() ERROR getting data" << std::endl; - return; - } - - int comNb = comments.size(); - - RsQThreadUtils::postToObject( [comNb,this]() - { - QString sComButText = tr("Comment"); - if (comNb == 1) - sComButText = sComButText.append("(1)"); - else if(comNb > 1) - sComButText = tr("Comments ").append("(%1)").arg(comNb); - - ui->commentButton->setText(sComButText); - - }, this ); - }); -} void PostedCardView::fill() { @@ -448,141 +343,4 @@ void PostedCardView::fill() emit sizeChanged(this); } - -//const RsPostedPost &PostedCardView::getPost() const -//{ -// return mPost; -//} - -//RsPostedPost &PostedCardView::post() -//{ -// return mPost; -//} - -QString PostedCardView::groupName() -{ - return QString::fromUtf8(mGroupMeta.mGroupName.c_str()); -} - -QString PostedCardView::messageName() -{ - return QString::fromUtf8(mPost.mMeta.mMsgName.c_str()); -} - -void PostedCardView::makeDownVote() -{ - RsGxsGrpMsgIdPair msgId; - msgId.first = mPost.mMeta.mGroupId; - msgId.second = mPost.mMeta.mMsgId; - - ui->voteUpButton->setEnabled(false); - ui->voteDownButton->setEnabled(false); - - emit vote(msgId, false); -} - -void PostedCardView::makeUpVote() -{ - RsGxsGrpMsgIdPair msgId; - msgId.first = mPost.mMeta.mGroupId; - msgId.second = mPost.mMeta.mMsgId; - - ui->voteUpButton->setEnabled(false); - ui->voteDownButton->setEnabled(false); - - emit vote(msgId, true); -} - -void PostedCardView::loadComments() -{ - std::cerr << "PostedCardView::loadComments()"; - std::cerr << std::endl; - - if (mFeedHolder) - { - QString title = QString::fromUtf8(mPost.mMeta.mMsgName.c_str()); - -#warning (csoler) Posted item versions not handled yet. When it is the case, start here. - - QVector post_versions ; - post_versions.push_back(mPost.mMeta.mMsgId) ; - - mFeedHolder->openComments(0, mPost.mMeta.mGroupId, post_versions,mPost.mMeta.mMsgId, title); - } -} - -void PostedCardView::setReadStatus(bool isNew, bool isUnread) -{ - if (isUnread) - { - ui->readButton->setChecked(true); - ui->readButton->setIcon(QIcon(":/images/message-state-unread.png")); - } - else - { - ui->readButton->setChecked(false); - ui->readButton->setIcon(QIcon(":/images/message-state-read.png")); - } - - ui->newLabel->setVisible(isNew); - - ui->mainFrame->setProperty("new", isNew); - ui->mainFrame->style()->unpolish(ui->mainFrame); - ui->mainFrame->style()->polish( ui->mainFrame); -} - -void PostedCardView::readToggled(bool checked) -{ - if (mInFill) { - return; - } - - RsGxsGrpMsgIdPair msgPair = std::make_pair(groupId(), messageId()); - - uint32_t token; - rsPosted->setMessageReadStatus(token, msgPair, !checked); - - setReadStatus(false, checked); -} - -void PostedCardView::readAndClearItem() -{ -#ifdef DEBUG_ITEM - std::cerr << "PostedCardView::readAndClearItem()"; - std::cerr << std::endl; -#endif - - readToggled(false); - removeItem(); -} - - -void PostedCardView::doExpand(bool open) -{ - /*if (open) - { - - } - else - { - - } - - emit sizeChanged(this);*/ - -} - -void PostedCardView::copyMessageLink() -{ - if (groupId().isNull() || messageId().isNull()) { - return; - } - - RetroShareLink link = RetroShareLink::createGxsMessageLink(RetroShareLink::TYPE_POSTED, groupId(), messageId(), messageName()); - - if (link.valid()) { - QList urls; - urls.push_back(link); - RSLinkClipboard::copyLinks(urls); - } -} +void PostedCardView::toggleNotes() {} diff --git a/retroshare-gui/src/gui/Posted/PostedCardView.h b/retroshare-gui/src/gui/Posted/PostedCardView.h index 8a93e6509..79c9c3fdb 100644 --- a/retroshare-gui/src/gui/Posted/PostedCardView.h +++ b/retroshare-gui/src/gui/Posted/PostedCardView.h @@ -24,7 +24,7 @@ #include #include -#include "gui/gxs/GxsFeedItem.h" +#include "PostedItem.h" namespace Ui { class PostedCardView; @@ -33,7 +33,7 @@ class PostedCardView; class FeedHolder; class RsPostedPost; -class PostedCardView : public GxsFeedItem +class PostedCardView : public BasePostedItem { Q_OBJECT @@ -42,52 +42,21 @@ public: PostedCardView(FeedHolder *parent, uint32_t feedId, const RsGroupMetaData& group_meta, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate); virtual ~PostedCardView(); - bool setPost(const RsPostedPost& post, bool doFill = true); - - const RsPostedPost &getPost() const { return mPost; } - //RsPostedPost& post(); - - uint64_t uniqueIdentifier() const override { return hash_64bits("PostedItem " + messageId().toStdString()); } - -protected: - /* FeedItem */ - virtual void doExpand(bool open); - void paintEvent(QPaintEvent *e) override; - -private slots: - void loadComments(); - void makeUpVote(); - void makeDownVote(); - void readToggled(bool checked); - void readAndClearItem(); - void copyMessageLink(); - -signals: - void vote(const RsGxsGrpMsgIdPair& msgId, bool up); - protected: /* GxsGroupFeedItem */ - virtual QString groupName(); - virtual void loadGroup() override; - virtual RetroShareLink::enumType getLinkType() { return RetroShareLink::TYPE_UNKNOWN; } - /* GxsFeedItem */ - virtual QString messageName(); - virtual void loadMessage(); - virtual void loadComment(); + void setup() override; + void fill() override; + void doExpand(bool open) override {} + void setComment(const RsGxsComment&) override; + void setReadStatus(bool isNew, bool isUnread) override; + void toggle() override {} + void setCommentsSize(int comNb) override; + void makeUpVote() override; + void makeDownVote() override; + void toggleNotes() override; private: - void setup(); - void fill(); - void setReadStatus(bool isNew, bool isUnread); - -private: - bool mInFill; - bool mLoaded; - - RsGroupMetaData mGroupMeta; - RsPostedPost mPost; - /** Qt Designer generated object */ Ui::PostedCardView *ui; }; diff --git a/retroshare-gui/src/gui/Posted/PostedItem.cpp b/retroshare-gui/src/gui/Posted/PostedItem.cpp index 859ccf3c1..6e8a58359 100644 --- a/retroshare-gui/src/gui/Posted/PostedItem.cpp +++ b/retroshare-gui/src/gui/Posted/PostedItem.cpp @@ -41,35 +41,27 @@ /** Constructor */ -PostedItem::PostedItem(FeedHolder *feedHolder, uint32_t feedId, const RsGroupMetaData &group_meta, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate) : +//======================================================================================== +// BasePostedItem // +//======================================================================================== + +BasePostedItem::BasePostedItem(FeedHolder *feedHolder, uint32_t feedId, const RsGroupMetaData &group_meta, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate) : GxsFeedItem(feedHolder, feedId, group_meta.mGroupId, post_id, isHome, rsPosted, autoUpdate), mGroupMeta(group_meta) { mPost.mMeta.mMsgId = post_id; mPost.mMeta.mGroupId = mGroupMeta.mGroupId; - mLoaded = false; - - setup(); } -PostedItem::PostedItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate) : +BasePostedItem::BasePostedItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate) : GxsFeedItem(feedHolder, feedId, groupId, post_id, isHome, rsPosted, autoUpdate) { mPost.mMeta.mMsgId = post_id; - mLoaded = false; - - setup(); - loadGroup(); } -PostedItem::~PostedItem() -{ - delete(ui); -} - -void PostedItem::paintEvent(QPaintEvent *e) +void BasePostedItem::paintEvent(QPaintEvent *e) { /* This method employs a trick to trigger a deferred loading. The post and group is requested only * when actually displayed on the screen. */ @@ -78,7 +70,6 @@ void PostedItem::paintEvent(QPaintEvent *e) { mLoaded = true ; - fill(); requestMessage(); requestComment(); } @@ -86,6 +77,254 @@ void PostedItem::paintEvent(QPaintEvent *e) GxsFeedItem::paintEvent(e) ; } +bool BasePostedItem::setPost(const RsPostedPost &post, bool doFill) +{ + if (groupId() != post.mMeta.mGroupId || messageId() != post.mMeta.mMsgId) { + std::cerr << "BasePostedItem::setPost() - Wrong id, cannot set post"; + std::cerr << std::endl; + return false; + } + + mPost = post; + + if (doFill) + fill(); + + return true; +} + +void BasePostedItem::loadGroup() +{ + RsThread::async([this]() + { + // 1 - get group data + +#ifdef DEBUG_FORUMS + std::cerr << "Retrieving post data for post " << mThreadId << std::endl; +#endif + + std::vector groups; + const std::list groupIds = { groupId() }; + + if(!rsPosted->getBoardsInfo(groupIds,groups)) + { + RsErr() << "GxsPostedGroupItem::loadGroup() ERROR getting data" << std::endl; + return; + } + + if (groups.size() != 1) + { + std::cerr << "GxsPostedGroupItem::loadGroup() Wrong number of Items"; + std::cerr << std::endl; + return; + } + RsPostedGroup group(groups[0]); + + RsQThreadUtils::postToObject( [group,this]() + { + /* Here it goes any code you want to be executed on the Qt Gui + * thread, for example to update the data model with new information + * after a blocking call to RetroShare API complete */ + + mGroupMeta = group.mMeta; + + }, this ); + }); +} + +void BasePostedItem::loadMessage() +{ + RsThread::async([this]() + { + // 1 - get group data + + std::vector posts; + std::vector comments; + + if(! rsPosted->getBoardContent( groupId(), std::set( { messageId() } ),posts,comments)) + { + RsErr() << "BasePostedItem::loadMessage() ERROR getting data" << std::endl; + return; + } + + if (posts.size() == 1) + { + std::cerr << (void*)this << ": Obtained post, with msgId = " << posts[0].mMeta.mMsgId << std::endl; + const RsPostedPost& post(posts[0]); + + RsQThreadUtils::postToObject( [post,this]() { setPost(post,true); }, this ); + } + else if(comments.size() == 1) + { + const RsGxsComment& cmt = comments[0]; + std::cerr << (void*)this << ": Obtained comment, setting messageId to threadID = " << cmt.mMeta.mThreadId << std::endl; + + RsQThreadUtils::postToObject( [cmt,this]() + { + setComment(cmt); + + //Change this item to be uploaded with thread element. + setMessageId(cmt.mMeta.mThreadId); + requestMessage(); + + }, this ); + + } + else + { + std::cerr << "GxsChannelPostItem::loadMessage() Wrong number of Items. Remove It."; + std::cerr << std::endl; + + RsQThreadUtils::postToObject( [this]() { removeItem(); }, this ); + } + }); +} + + +void BasePostedItem::loadComment() +{ +#ifdef DEBUG_ITEM + std::cerr << "GxsChannelPostItem::loadComment()"; + std::cerr << std::endl; +#endif + + RsThread::async([this]() + { + // 1 - get group data + + std::set msgIds; + + for(auto MsgId: messageVersions()) + msgIds.insert(MsgId); + + std::vector posts; + std::vector comments; + + if(! rsPosted->getBoardContent( groupId(),msgIds,posts,comments)) + { + RsErr() << "BasePostedItem::loadGroup() ERROR getting data" << std::endl; + return; + } + + int comNb = comments.size(); + + RsQThreadUtils::postToObject( [comNb,this]() + { + setCommentsSize(comNb); + + }, this ); + }); +} + +QString BasePostedItem::groupName() +{ + return QString::fromUtf8(mGroupMeta.mGroupName.c_str()); +} + +QString BasePostedItem::messageName() +{ + return QString::fromUtf8(mPost.mMeta.mMsgName.c_str()); +} + +void BasePostedItem::loadComments() +{ + std::cerr << "BasePostedItem::loadComments()"; + std::cerr << std::endl; + + if (mFeedHolder) + { + QString title = QString::fromUtf8(mPost.mMeta.mMsgName.c_str()); + +#warning (csoler) Posted item versions not handled yet. When it is the case, start here. + + QVector post_versions ; + post_versions.push_back(mPost.mMeta.mMsgId) ; + + mFeedHolder->openComments(0, mPost.mMeta.mGroupId, post_versions,mPost.mMeta.mMsgId, title); + } +} +void BasePostedItem::readToggled(bool checked) +{ + if (mInFill) { + return; + } + + RsGxsGrpMsgIdPair msgPair = std::make_pair(groupId(), messageId()); + + uint32_t token; + rsPosted->setMessageReadStatus(token, msgPair, !checked); + + setReadStatus(false, checked); +} + +void BasePostedItem::readAndClearItem() +{ +#ifdef DEBUG_ITEM + std::cerr << "BasePostedItem::readAndClearItem()"; + std::cerr << std::endl; +#endif + + readToggled(false); + removeItem(); +} +void BasePostedItem::copyMessageLink() +{ + if (groupId().isNull() || messageId().isNull()) { + return; + } + + RetroShareLink link = RetroShareLink::createGxsMessageLink(RetroShareLink::TYPE_POSTED, groupId(), messageId(), messageName()); + + if (link.valid()) { + QList urls; + urls.push_back(link); + RSLinkClipboard::copyLinks(urls); + } +} + +void BasePostedItem::viewPicture() +{ + if(mPost.mImage.mData == NULL) { + return; + } + + QString timestamp = misc::timeRelativeToNow(mPost.mMeta.mPublishTs); + QPixmap pixmap; + GxsIdDetails::loadPixmapFromData(mPost.mImage.mData, mPost.mImage.mSize, pixmap,GxsIdDetails::ORIGINAL); + RsGxsId authorID = mPost.mMeta.mAuthorId; + + PhotoView *PView = new PhotoView(this); + + PView->setPixmap(pixmap); + PView->setTitle(messageName()); + PView->setName(authorID); + PView->setTime(timestamp); + PView->setGroupId(groupId()); + PView->setMessageId(messageId()); + + PView->show(); + + /* window will destroy itself! */ +} + +//======================================================================================== +// PostedItem // +//======================================================================================== + +PostedItem::PostedItem(FeedHolder *feedHolder, uint32_t feedId, const RsGroupMetaData &group_meta, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate) : + BasePostedItem(feedHolder, feedId, group_meta, post_id, isHome, autoUpdate) +{ + setup(); +} + +PostedItem::PostedItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate) : + BasePostedItem(feedHolder, feedId, groupId, post_id, isHome, autoUpdate) +{ + setup(); + loadGroup(); +} + + void PostedItem::setup() { /* Invoke the Qt Designer generated object setup routine */ @@ -126,7 +365,7 @@ void PostedItem::setup() int S = QFontMetricsF(font()).height() ; - + ui->voteUpButton->setIconSize(QSize(S*1.5,S*1.5)); ui->voteDownButton->setIconSize(QSize(S*1.5,S*1.5)); ui->commentButton->setIconSize(QSize(S*1.5,S*1.5)); @@ -134,7 +373,7 @@ void PostedItem::setup() ui->notesButton->setIconSize(QSize(S*1.5,S*1.5)); ui->readButton->setIconSize(QSize(S*1.5,S*1.5)); ui->shareButton->setIconSize(QSize(S*1.5,S*1.5)); - + QMenu *menu = new QMenu(); menu->addAction(CopyLinkAction); ui->shareButton->setMenu(menu); @@ -144,155 +383,51 @@ void PostedItem::setup() ui->nameLabel->hide(); } -bool PostedItem::setPost(const RsPostedPost &post, bool doFill) +void PostedItem::makeDownVote() { - if (groupId() != post.mMeta.mGroupId || messageId() != post.mMeta.mMsgId) { - std::cerr << "PostedItem::setPost() - Wrong id, cannot set post"; - std::cerr << std::endl; - return false; - } + RsGxsGrpMsgIdPair msgId; + msgId.first = mPost.mMeta.mGroupId; + msgId.second = mPost.mMeta.mMsgId; - mPost = post; + ui->voteUpButton->setEnabled(false); + ui->voteDownButton->setEnabled(false); - if (doFill) { - fill(); - } - - return true; + emit vote(msgId, false); } -void PostedItem::loadGroup() +void PostedItem::makeUpVote() { - RsThread::async([this]() - { - // 1 - get group data + RsGxsGrpMsgIdPair msgId; + msgId.first = mPost.mMeta.mGroupId; + msgId.second = mPost.mMeta.mMsgId; -#ifdef DEBUG_FORUMS - std::cerr << "Retrieving post data for post " << mThreadId << std::endl; -#endif + ui->voteUpButton->setEnabled(false); + ui->voteDownButton->setEnabled(false); - std::vector groups; - const std::list groupIds = { groupId() }; - - if(!rsPosted->getBoardsInfo(groupIds,groups)) - { - RsErr() << "GxsPostedGroupItem::loadGroup() ERROR getting data" << std::endl; - return; - } - - if (groups.size() != 1) - { - std::cerr << "GxsPostedGroupItem::loadGroup() Wrong number of Items"; - std::cerr << std::endl; - return; - } - RsPostedGroup group(groups[0]); - - RsQThreadUtils::postToObject( [group,this]() - { - /* Here it goes any code you want to be executed on the Qt Gui - * thread, for example to update the data model with new information - * after a blocking call to RetroShare API complete */ - - mGroupMeta = group.mMeta; - - }, this ); - }); + emit vote(msgId, true); } -void PostedItem::loadMessage() + + +void PostedItem::setComment(const RsGxsComment& cmt) { - RsThread::async([this]() - { - // 1 - get group data - - std::vector posts; - std::vector comments; - - if(! rsPosted->getBoardContent( groupId(), std::set( { messageId() } ),posts,comments)) - { - RsErr() << "PostedItem::loadMessage() ERROR getting data" << std::endl; - return; - } - - if (posts.size() == 1) - { - std::cerr << (void*)this << ": Obtained post, with msgId = " << posts[0].mMeta.mMsgId << std::endl; - const RsPostedPost& post(posts[0]); - - RsQThreadUtils::postToObject( [post,this]() { setPost(post); }, this ); - } - else if(comments.size() == 1) - { - const RsGxsComment& cmt = comments[0]; - std::cerr << (void*)this << ": Obtained comment, setting messageId to threadID = " << cmt.mMeta.mThreadId << std::endl; - - RsQThreadUtils::postToObject( [cmt,this]() - { - ui->newCommentLabel->show(); - ui->commLabel->show(); - ui->commLabel->setText(QString::fromUtf8(cmt.mComment.c_str())); - - //Change this item to be uploaded with thread element. - setMessageId(cmt.mMeta.mThreadId); - requestMessage(); - - }, this ); - - } - else - { - std::cerr << "GxsChannelPostItem::loadMessage() Wrong number of Items. Remove It."; - std::cerr << std::endl; - - RsQThreadUtils::postToObject( [this]() { removeItem(); }, this ); - } - }); + ui->newCommentLabel->show(); + ui->commLabel->show(); + ui->commLabel->setText(QString::fromUtf8(cmt.mComment.c_str())); } - -void PostedItem::loadComment() +void PostedItem::setCommentsSize(int comNb) { -#ifdef DEBUG_ITEM - std::cerr << "GxsChannelPostItem::loadComment()"; - std::cerr << std::endl; -#endif + QString sComButText = tr("Comment"); + if (comNb == 1) + sComButText = sComButText.append("(1)"); + else if(comNb > 1) + sComButText = tr("Comments ").append("(%1)").arg(comNb); - RsThread::async([this]() - { - // 1 - get group data - - std::set msgIds; - - for(auto MsgId: messageVersions()) - msgIds.insert(MsgId); - - std::vector posts; - std::vector comments; - - if(! rsPosted->getBoardContent( groupId(),msgIds,posts,comments)) - { - RsErr() << "PostedItem::loadGroup() ERROR getting data" << std::endl; - return; - } - - int comNb = comments.size(); - - RsQThreadUtils::postToObject( [comNb,this]() - { - QString sComButText = tr("Comment"); - if (comNb == 1) - sComButText = sComButText.append("(1)"); - else if(comNb > 1) - sComButText = tr("Comments ").append("(%1)").arg(comNb); - - ui->commentButton->setText(sComButText); - - }, this ); - }); + ui->commentButton->setText(sComButText); } void PostedItem::fill() -{ +{ RetroShareLink link = RetroShareLink::createGxsGroupLink(RetroShareLink::TYPE_POSTED, mGroupMeta.mGroupId, groupName()); ui->nameLabel->setText(link.toHtml()); @@ -317,20 +452,21 @@ void PostedItem::fill() QUrl url = QUrl::fromEncoded(urlarray.trimmed()); QString urlstr = "Invalid Link"; QString sitestr = "Invalid Link"; + bool urlOkay = url.isValid(); if (urlOkay) { QString scheme = url.scheme(); - if ((scheme != "https") + if ((scheme != "https") && (scheme != "http") - && (scheme != "ftp") - && (scheme != "retroshare")) + && (scheme != "ftp") + && (scheme != "retroshare")) { urlOkay = false; sitestr = "Invalid Link Scheme"; } } - + if (urlOkay) { urlstr = QString(" %2 ").arg(siteurl).arg(siteurl); - + ui->titleLabel->setText(urlstr); }else { @@ -355,13 +491,13 @@ void PostedItem::fill() } ui->siteLabel->setText(sitestr); - + if(mPost.mImage.mData != NULL) { QPixmap pixmap; GxsIdDetails::loadPixmapFromData(mPost.mImage.mData, mPost.mImage.mSize, pixmap,GxsIdDetails::ORIGINAL); // Wiping data - as its been passed to thumbnail. - + QPixmap sqpixmap = pixmap.scaled(desired_width,desired_height, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); ui->thumbnailLabel->setPixmap(sqpixmap); ui->thumbnailLabel->setToolTip(tr("Click to view Picture")); @@ -370,7 +506,7 @@ void PostedItem::fill() if(pixmap.width() > 800){ QPixmap scaledpixmap = pixmap.scaledToWidth(800, Qt::SmoothTransformation); ui->pictureLabel->setPixmap(scaledpixmap); - }else{ + }else{ ui->pictureLabel->setPixmap(pixmap); } } @@ -387,7 +523,7 @@ void PostedItem::fill() //QString score = "Hot" + QString::number(post.mHotScore); - //score += " Top" + QString::number(post.mTopScore); + //score += " Top" + QString::number(post.mTopScore); //score += " New" + QString::number(post.mNewScore); QString score = QString::number(mPost.mTopScore); @@ -399,7 +535,7 @@ void PostedItem::fill() QTextDocument doc; doc.setHtml(ui->notes->text()); - + if(doc.toPlainText().trimmed().isEmpty()) ui->notesButton->hide(); // differences between Feed or Top of Comment. @@ -455,7 +591,7 @@ void PostedItem::fill() #if 0 uint32_t up, down, nComments; - + bool ok = rsPosted->retrieveScores(mPost.mMeta.mServiceString, up, down, nComments); if(ok) @@ -476,57 +612,6 @@ void PostedItem::fill() emit sizeChanged(this); } -QString PostedItem::groupName() -{ - return QString::fromUtf8(mGroupMeta.mGroupName.c_str()); -} - -QString PostedItem::messageName() -{ - return QString::fromUtf8(mPost.mMeta.mMsgName.c_str()); -} - -void PostedItem::makeDownVote() -{ - RsGxsGrpMsgIdPair msgId; - msgId.first = mPost.mMeta.mGroupId; - msgId.second = mPost.mMeta.mMsgId; - - ui->voteUpButton->setEnabled(false); - ui->voteDownButton->setEnabled(false); - - emit vote(msgId, false); -} - -void PostedItem::makeUpVote() -{ - RsGxsGrpMsgIdPair msgId; - msgId.first = mPost.mMeta.mGroupId; - msgId.second = mPost.mMeta.mMsgId; - - ui->voteUpButton->setEnabled(false); - ui->voteDownButton->setEnabled(false); - - emit vote(msgId, true); -} - -void PostedItem::loadComments() -{ - std::cerr << "PostedItem::loadComments()"; - std::cerr << std::endl; - - if (mFeedHolder) - { - QString title = QString::fromUtf8(mPost.mMeta.mMsgName.c_str()); - -#warning (csoler) Posted item versions not handled yet. When it is the case, start here. - - QVector post_versions ; - post_versions.push_back(mPost.mMeta.mMsgId) ; - - mFeedHolder->openComments(0, mPost.mMeta.mGroupId, post_versions,mPost.mMeta.mMsgId, title); - } -} void PostedItem::setReadStatus(bool isNew, bool isUnread) { @@ -548,30 +633,6 @@ void PostedItem::setReadStatus(bool isNew, bool isUnread) ui->mainFrame->style()->polish( ui->mainFrame); } -void PostedItem::readToggled(bool checked) -{ - if (mInFill) { - return; - } - - RsGxsGrpMsgIdPair msgPair = std::make_pair(groupId(), messageId()); - - uint32_t token; - rsPosted->setMessageReadStatus(token, msgPair, !checked); - - setReadStatus(false, checked); -} - -void PostedItem::readAndClearItem() -{ -#ifdef DEBUG_ITEM - std::cerr << "PostedItem::readAndClearItem()"; - std::cerr << std::endl; -#endif - - readToggled(false); - removeItem(); -} void PostedItem::toggle() { @@ -597,21 +658,6 @@ void PostedItem::doExpand(bool open) } -void PostedItem::copyMessageLink() -{ - if (groupId().isNull() || messageId().isNull()) { - return; - } - - RetroShareLink link = RetroShareLink::createGxsMessageLink(RetroShareLink::TYPE_POSTED, groupId(), messageId(), messageName()); - - if (link.valid()) { - QList urls; - urls.push_back(link); - RSLinkClipboard::copyLinks(urls); - } -} - void PostedItem::toggleNotes() { if (ui->notesButton->isChecked()) @@ -619,33 +665,10 @@ void PostedItem::toggleNotes() ui->frame_notes->show(); } else - { + { ui->frame_notes->hide(); } } -void PostedItem::viewPicture() -{ - if(mPost.mImage.mData == NULL) { - return; - } - QString timestamp = misc::timeRelativeToNow(mPost.mMeta.mPublishTs); - QPixmap pixmap; - GxsIdDetails::loadPixmapFromData(mPost.mImage.mData, mPost.mImage.mSize, pixmap,GxsIdDetails::ORIGINAL); - RsGxsId authorID = mPost.mMeta.mAuthorId; - - PhotoView *PView = new PhotoView(this); - - PView->setPixmap(pixmap); - PView->setTitle(messageName()); - PView->setName(authorID); - PView->setTime(timestamp); - PView->setGroupId(groupId()); - PView->setMessageId(messageId()); - - PView->show(); - - /* window will destroy itself! */ -} diff --git a/retroshare-gui/src/gui/Posted/PostedItem.h b/retroshare-gui/src/gui/Posted/PostedItem.h index 403298ff4..e6557548f 100644 --- a/retroshare-gui/src/gui/Posted/PostedItem.h +++ b/retroshare-gui/src/gui/Posted/PostedItem.h @@ -33,15 +33,14 @@ class PostedItem; class FeedHolder; class RsPostedPost; -class PostedItem : public GxsFeedItem +class BasePostedItem : public GxsFeedItem { Q_OBJECT public: - PostedItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId& groupId, const RsGxsMessageId& messageId, bool isHome, bool autoUpdate); - PostedItem(FeedHolder *parent, uint32_t feedId, const RsGroupMetaData& group_meta, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate); - - virtual ~PostedItem(); + BasePostedItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId& groupId, const RsGxsMessageId& messageId, bool isHome, bool autoUpdate); + BasePostedItem(FeedHolder *parent, uint32_t feedId, const RsGroupMetaData& group_meta, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate); + virtual ~BasePostedItem()=default; bool setPost(const RsPostedPost& post, bool doFill = true); @@ -49,26 +48,21 @@ public: RsPostedPost& getPost() { return mPost ; } uint64_t uniqueIdentifier() const override { return hash_64bits("PostedItem " + messageId().toStdString()); } -protected: - /* FeedItem */ - virtual void doExpand(bool open); - virtual void paintEvent(QPaintEvent *) override; private slots: void loadComments(); - void makeUpVote(); - void makeDownVote(); void readToggled(bool checked); void readAndClearItem(); - void toggle() override; void copyMessageLink(); - void toggleNotes(); void viewPicture(); signals: void vote(const RsGxsGrpMsgIdPair& msgId, bool up); protected: + /* FeedItem */ + virtual void paintEvent(QPaintEvent *) override; + /* GxsGroupFeedItem */ virtual QString groupName(); virtual void loadGroup() override; @@ -80,18 +74,43 @@ protected: virtual void loadMessage(); virtual void loadComment(); -private: - void setup(); - void fill(); - void setReadStatus(bool isNew, bool isUnread); - -private: bool mInFill; - bool mLoaded; - RsGroupMetaData mGroupMeta; RsPostedPost mPost; + virtual void setup()=0; + virtual void fill()=0; + virtual void doExpand(bool open)=0; + virtual void setComment(const RsGxsComment&)=0; + virtual void setReadStatus(bool isNew, bool isUnread)=0; + virtual void setCommentsSize(int comNb)=0; + virtual void makeUpVote()=0; + virtual void makeDownVote()=0; + virtual void toggleNotes()=0; + +private: + bool mLoaded; +}; + +class PostedItem: public BasePostedItem +{ +public: + PostedItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId& groupId, const RsGxsMessageId& messageId, bool isHome, bool autoUpdate); + PostedItem(FeedHolder *parent, uint32_t feedId, const RsGroupMetaData& group_meta, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate); + +protected: + void setup() override; + void fill() override; + void doExpand(bool open) override; + void setComment(const RsGxsComment&) override; + void setReadStatus(bool isNew, bool isUnread) override; + void toggle() override ; + void setCommentsSize(int comNb) override; + void makeUpVote() override; + void makeDownVote() override; + void toggleNotes() override; + +private: /** Qt Designer generated object */ Ui::PostedItem *ui; }; From 02466e32702bad25d77dd388709f8e6e2f4be2dc Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 22 Apr 2020 21:46:49 +0200 Subject: [PATCH 3/3] using Icon/Pixmap cache in Boards --- retroshare-gui/src/gui/Posted/PostedCardView.cpp | 5 +++-- retroshare-gui/src/gui/Posted/PostedItem.cpp | 11 ++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/retroshare-gui/src/gui/Posted/PostedCardView.cpp b/retroshare-gui/src/gui/Posted/PostedCardView.cpp index 7b9dbaabc..e75c2fb62 100644 --- a/retroshare-gui/src/gui/Posted/PostedCardView.cpp +++ b/retroshare-gui/src/gui/Posted/PostedCardView.cpp @@ -28,6 +28,7 @@ #include "gui/feeds/FeedHolder.h" #include "gui/gxs/GxsIdDetails.h" #include "util/misc.h" +#include "gui/common/FilesDefs.h" #include "util/qtthreadsutils.h" #include "util/HandleRichText.h" @@ -93,12 +94,12 @@ void PostedCardView::setReadStatus(bool isNew, bool isUnread) if (isUnread) { ui->readButton->setChecked(true); - ui->readButton->setIcon(QIcon(":/images/message-state-unread.png")); + ui->readButton->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/message-state-unread.png")); } else { ui->readButton->setChecked(false); - ui->readButton->setIcon(QIcon(":/images/message-state-read.png")); + ui->readButton->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/message-state-read.png")); } ui->newLabel->setVisible(isNew); diff --git a/retroshare-gui/src/gui/Posted/PostedItem.cpp b/retroshare-gui/src/gui/Posted/PostedItem.cpp index 6e8a58359..8f3352735 100644 --- a/retroshare-gui/src/gui/Posted/PostedItem.cpp +++ b/retroshare-gui/src/gui/Posted/PostedItem.cpp @@ -29,6 +29,7 @@ #include "gui/RetroShareLink.h" #include "gui/gxs/GxsIdDetails.h" #include "util/misc.h" +#include "gui/common/FilesDefs.h" #include "util/qtthreadsutils.h" #include "util/HandleRichText.h" #include "PhotoView.h" @@ -513,7 +514,7 @@ void PostedItem::fill() else if (urlOkay && (mPost.mImage.mData == NULL)) { ui->expandButton->setDisabled(true); - ui->thumbnailLabel->setPixmap(QPixmap(LINK_IMAGE)); + ui->thumbnailLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(LINK_IMAGE)); } else { @@ -618,12 +619,12 @@ void PostedItem::setReadStatus(bool isNew, bool isUnread) if (isUnread) { ui->readButton->setChecked(true); - ui->readButton->setIcon(QIcon(":/images/message-state-unread.png")); + ui->readButton->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/message-state-unread.png")); } else { ui->readButton->setChecked(false); - ui->readButton->setIcon(QIcon(":/images/message-state-read.png")); + ui->readButton->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/message-state-read.png")); } ui->newLabel->setVisible(isNew); @@ -644,13 +645,13 @@ void PostedItem::doExpand(bool open) if (open) { ui->frame_picture->show(); - ui->expandButton->setIcon(QIcon(QString(":/images/decrease.png"))); + ui->expandButton->setIcon(FilesDefs::getIconFromQtResourcePath(QString(":/images/decrease.png"))); ui->expandButton->setToolTip(tr("Hide")); } else { ui->frame_picture->hide(); - ui->expandButton->setIcon(QIcon(QString(":/images/expand.png"))); + ui->expandButton->setIcon(FilesDefs::getIconFromQtResourcePath(QString(":/images/expand.png"))); ui->expandButton->setToolTip(tr("Expand")); }