From 68e027b227a63ed97135f3b7d1ed4ff085f09c15 Mon Sep 17 00:00:00 2001 From: Phenom Date: Tue, 10 Nov 2020 15:32:25 +0100 Subject: [PATCH] Fix GXS (Forum/Channel/Boards) RSLink Have to add ID: tag in Board Filter due to range view. --- .../src/gui/Posted/PostedDialog.cpp | 4 +- .../gui/Posted/PostedListWidgetWithModel.cpp | 62 +++++----- .../gui/Posted/PostedListWidgetWithModel.h | 8 +- .../src/gui/Posted/PostedPostsModel.cpp | 106 +++++++++--------- .../src/gui/gxs/GxsGroupFrameDialog.cpp | 1 + .../src/gui/gxs/GxsGroupFrameDialog.h | 2 +- .../GxsChannelPostsWidgetWithModel.cpp | 58 +++++----- .../GxsChannelPostsWidgetWithModel.h | 3 +- 8 files changed, 138 insertions(+), 106 deletions(-) diff --git a/retroshare-gui/src/gui/Posted/PostedDialog.cpp b/retroshare-gui/src/gui/Posted/PostedDialog.cpp index 327ecdd12..9c84eb06a 100644 --- a/retroshare-gui/src/gui/Posted/PostedDialog.cpp +++ b/retroshare-gui/src/gui/Posted/PostedDialog.cpp @@ -162,8 +162,8 @@ bool PostedDialog::getGroupData(std::list& groupInfo) // request all group infos at once - if(! rsPosted->getBoardsInfo(std::list(),groups)) - return false; + if(! rsPosted->getBoardsInfo(std::list(),groups)) + return false; /* Save groups to fill icons and description */ diff --git a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp index eb1fe9bae..974774417 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp +++ b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp @@ -62,6 +62,8 @@ * #define DEBUG_POSTED ***/ +static const int POSTED_TABS_POSTS = 1; + /* View mode */ #define VIEW_MODE_FEEDS 1 #define VIEW_MODE_FILES 2 @@ -507,7 +509,7 @@ void PostedListWidgetWithModel::showPostDetails() { QModelIndex index = ui->postsTree->selectionModel()->currentIndex(); RsPostedPost post = index.data(Qt::UserRole).value() ; - + QTextDocument doc; doc.setHtml(post.mMsg.c_str()); @@ -529,8 +531,8 @@ void PostedListWidgetWithModel::showPostDetails() if(index.row()==0 && index.column()==0) std::cerr << "here" << std::endl; - std::cerr << "showPostDetails: setting mSelectedPost to current post Id " << post.mMeta.mMsgId << ". Previous value: " << mSelectedPost << std::endl; - mSelectedPost = post.mMeta.mMsgId; + std::cerr << "showPostDetails: setting mLastSelectedPosts[groupId()] to current post Id " << post.mMeta.mMsgId << ". Previous value: " << mLastSelectedPosts[groupId()] << std::endl; + mLastSelectedPosts[groupId()] = post.mMeta.mMsgId; std::list files; for(auto& file:post.mFiles) @@ -625,24 +627,30 @@ void PostedListWidgetWithModel::updateGroupData() void PostedListWidgetWithModel::postPostLoad() { - std::cerr << "Post channel load..." << std::endl; + std::cerr << "Post channel load..." << std::endl; + whileBlocking(ui->filter_LE)->setText(QString()); //Clear it before navigate, as it will update it. - if(!mSelectedPost.isNull()) - { - QModelIndex index = mPostedPostsModel->getIndexOfMessage(mSelectedPost); + if (!mNavigatePendingMsgId.isNull()) + navigate(mNavigatePendingMsgId); - std::cerr << "Setting current index to " << index.row() << ","<< index.column() << " for current post " - << mSelectedPost.toStdString() << std::endl; +#ifdef TO_REMOVE + else if( (mLastSelectedPosts.count(groupId()) > 0) + && !mLastSelectedPosts[groupId()].isNull()) + { + QModelIndex index = mPostedPostsModel->getIndexOfMessage(mLastSelectedPosts[groupId()]); + + std::cerr << "Setting current index to " << index.row() << ","<< index.column() << " for current post " + << mLastSelectedPosts[groupId()].toStdString() << std::endl; ui->postsTree->selectionModel()->setCurrentIndex(index,QItemSelectionModel::ClearAndSelect); ui->postsTree->scrollTo(index);//May change if model reloaded ui->postsTree->setFocus(); - } - else - std::cerr << "No pre-selected channel post." << std::endl; + } +#endif + else + std::cerr << "No pre-selected channel post." << std::endl; - whileBlocking(ui->showLabel)->setText(QString::number(mPostedPostsModel->displayedStartPostIndex()+1)+" - "+QString::number(std::min(mPostedPostsModel->filteredPostsCount(),mPostedPostsModel->displayedStartPostIndex()+POSTS_CHUNK_SIZE+1))); - whileBlocking(ui->filter_LE)->setText(QString()); + whileBlocking(ui->showLabel)->setText(QString::number(mPostedPostsModel->displayedStartPostIndex()+1)+" - "+QString::number(std::min(mPostedPostsModel->filteredPostsCount(),mPostedPostsModel->displayedStartPostIndex()+POSTS_CHUNK_SIZE+1))); } void PostedListWidgetWithModel::forceRedraw() @@ -721,7 +729,7 @@ QString PostedListWidgetWithModel::groupName(bool) return QString::fromUtf8(mGroup.mMeta.mGroupName.c_str()); } -void PostedListWidgetWithModel::groupNameChanged(const QString &name) +void PostedListWidgetWithModel::groupNameChanged(const QString &/*name*/) { } @@ -737,12 +745,12 @@ QIcon PostedListWidgetWithModel::groupIcon() return QIcon(postedImage); } -void PostedListWidgetWithModel::setAllMessagesReadDo(bool read, uint32_t &token) +void PostedListWidgetWithModel::setAllMessagesReadDo(bool read, uint32_t &/*token*/) { if (groupId().isNull() || !IS_GROUP_SUBSCRIBED(mGroup.mMeta.mSubscribeFlags)) return; - QModelIndex src_index; + //QModelIndex src_index; mPostedPostsModel->setAllMsgReadStatus(read); @@ -1126,20 +1134,24 @@ void PostedListWidgetWithModel::blank() bool PostedListWidgetWithModel::navigate(const RsGxsMessageId& msgId) { + ui->filter_LE->setText("ID:" + QString::fromStdString(msgId.toStdString())); + QModelIndex index = mPostedPostsModel->getIndexOfMessage(msgId); - if(!index.isValid()) - { - std::cerr << "(EE) Cannot navigate to msg " << msgId << " in board " << mGroup.mMeta.mGroupId << ": index unknown. Setting mNavigatePendingMsgId." << std::endl; + if(!index.isValid()) + { + std::cerr << "(EE) Cannot navigate to msg " << msgId << " in board " << mGroup.mMeta.mGroupId << ": index unknown. Setting mNavigatePendingMsgId." << std::endl; - mSelectedPost = msgId; // not found. That means the forum may not be loaded yet. So we keep that post in mind, for after loading. - return true; // we have to return true here, otherwise the caller will intepret the async loading as an error. - } + mNavigatePendingMsgId = msgId; // not found. That means the forum may not be loaded yet. So we keep that post in mind, for after loading. + return true; // we have to return true here, otherwise the caller will intepret the async loading as an error. + } - ui->postsTree->selectionModel()->setCurrentIndex(index,QItemSelectionModel::ClearAndSelect); - ui->postsTree->scrollTo(index);//May change if model reloaded ui->postsTree->setFocus(); + ui->tabWidget->setCurrentIndex(POSTED_TABS_POSTS); + + mNavigatePendingMsgId.clear(); + return true; } diff --git a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.h b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.h index 238bdf05b..0c951b664 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.h +++ b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.h @@ -132,6 +132,9 @@ protected: virtual void setAllMessagesReadDo(bool read, uint32_t &token) override; private slots: +#ifdef TO_REMOVE + void showPostDetails(); +#endif void showAuthorInPeople(); void tabCloseRequested(int index); void updateSorting(int); @@ -166,7 +169,10 @@ private: RsPostedPostsModel *mPostedPostsModel; PostedPostDelegate *mPostedPostsDelegate; - RsGxsMessageId mSelectedPost; +#ifdef TO_REMOVE + std::map mLastSelectedPosts; +#endif + RsGxsMessageId mNavigatePendingMsgId; /* UI - from Designer */ Ui::PostedListWidgetWithModel *ui; diff --git a/retroshare-gui/src/gui/Posted/PostedPostsModel.cpp b/retroshare-gui/src/gui/Posted/PostedPostsModel.cpp index afd71d8b1..89a29eec4 100644 --- a/retroshare-gui/src/gui/Posted/PostedPostsModel.cpp +++ b/retroshare-gui/src/gui/Posted/PostedPostsModel.cpp @@ -158,42 +158,47 @@ void RsPostedPostsModel::triggerRedraw() void RsPostedPostsModel::setFilter(const QStringList& strings, uint32_t& count) { - preMods(); + preMods(); beginRemoveRows(QModelIndex(),0,rowCount()-1); - endRemoveRows(); + endRemoveRows(); if(strings.empty()) - { - mFilteredPosts.clear(); - for(int i=0;i(mPosts.size());++i) + { + bool passes_strings = true; for(auto& s:strings) - passes_strings = passes_strings && QString::fromStdString(mPosts[i].mMeta.mMsgName).contains(s,Qt::CaseInsensitive); + { + if (s.startsWith("ID:",Qt::CaseInsensitive)) + passes_strings = passes_strings && mPosts[i].mMeta.mMsgId == RsGxsMessageId(s.right(s.length() - 3).toStdString()); + else + passes_strings = passes_strings && QString::fromStdString(mPosts[i].mMeta.mMsgName).contains(s,Qt::CaseInsensitive); + } - if(passes_strings) - mFilteredPosts.push_back(i); - } - } - count = mFilteredPosts.size(); + if(passes_strings) + mFilteredPosts.push_back(i); + } + } + count = mFilteredPosts.size(); - mDisplayedStartIndex = 0; + mDisplayedStartIndex = 0; mDisplayedNbPosts = std::min(count,DEFAULT_DISPLAYED_NB_POSTS) ; - std::cerr << "After filtering: " << count << " posts remain." << std::endl; + std::cerr << "After filtering: " << count << " posts remain." << std::endl; beginInsertRows(QModelIndex(),0,rowCount()-1); - endInsertRows(); + endInsertRows(); postMods(); } @@ -237,8 +242,8 @@ bool RsPostedPostsModel::getPostData(const QModelIndex& i,RsPostedPost& fmpe) co bool RsPostedPostsModel::hasChildren(const QModelIndex &parent) const { - if(!parent.isValid()) - return true; + if(!parent.isValid()) + return true; return false; // by default, no post has children } @@ -292,8 +297,8 @@ QModelIndex RsPostedPostsModel::index(int row, int column, const QModelIndex & p QModelIndex RsPostedPostsModel::parent(const QModelIndex& index) const { - if(!index.isValid()) - return QModelIndex(); + if(!index.isValid()) + return QModelIndex(); return QModelIndex(); // there's no hierarchy here. So nothing to do! } @@ -333,10 +338,10 @@ quintptr RsPostedPostsModel::getParentRow(quintptr ref,int& row) const int RsPostedPostsModel::getChildrenCount(quintptr ref) const { - uint32_t entry = 0 ; + //uint32_t entry = 0 ; - if(ref == quintptr(0)) - return rowCount()-1; + if(ref == quintptr(0)) + return rowCount()-1; return 0; } @@ -391,7 +396,7 @@ QVariant RsPostedPostsModel::data(const QModelIndex& index, int role) const } } -QVariant RsPostedPostsModel::sizeHintRole(int col) const +QVariant RsPostedPostsModel::sizeHintRole(int /*col*/) const { float factor = QFontMetricsF(QApplication::font()).height()/14.0f ; @@ -483,8 +488,8 @@ void RsPostedPostsModel::setSortingStrategy(RsPostedPostsModel::SortingStrategy void RsPostedPostsModel::setPostsInterval(int start,int nb_posts) { - if(start >= mFilteredPosts.size()) - return; + if(start >= (int)mFilteredPosts.size()) + return; preMods(); @@ -538,8 +543,8 @@ void RsPostedPostsModel::setPosts(const RsPostedGroup& group, std::vector& e1,const std::pair& e2) { return e2.first < e1.first ; } +//static bool decreasing_time_comp(const std::pair& e1,const std::pair& e2) { return e2.first < e1.first ; } void RsPostedPostsModel::createPostsArray(std::vector& posts) { @@ -761,34 +766,35 @@ void RsPostedPostsModel::setMsgReadStatus(const QModelIndex& i,bool read_status) QModelIndex RsPostedPostsModel::getIndexOfMessage(const RsGxsMessageId& mid) const { - // Brutal search. This is not so nice, so dont call that in a loop! If too costly, we'll use a map. + // Brutal search. This is not so nice, so dont call that in a loop! If too costly, we'll use a map. - RsGxsMessageId postId = mid; + RsGxsMessageId postId = mid; - for(uint32_t i=mDisplayedStartIndex;i (size_t)(i) + && mPosts[mFilteredPosts[i]].mMeta.mMsgId == postId ) + { + quintptr ref ; + convertTabEntryToRefPointer(i,ref); // we dont use i+1 here because i is not a row, but an index in the mPosts tab return createIndex(i,0, ref); - } - } + } + } - return QModelIndex(); + return QModelIndex(); } diff --git a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp index a1bfc51e0..776d7ed93 100644 --- a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp +++ b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp @@ -98,6 +98,7 @@ GxsGroupFrameDialog::GxsGroupFrameDialog(RsGxsIfaceHelper *ifaceImpl, QWidget *p mStateHelper = new UIStateHelper(this); mStateHelper->addWidget(TOKEN_TYPE_GROUP_SUMMARY, ui->loadingLabel, UISTATE_LOADING_VISIBLE); + mStateHelper->setLoading(TOKEN_TYPE_GROUP_SUMMARY, true); connect(ui->groupTreeWidget, SIGNAL(treeCustomContextMenuRequested(QPoint)), this, SLOT(groupTreeCustomPopupMenu(QPoint))); connect(ui->groupTreeWidget, SIGNAL(treeCurrentItemChanged(QString)), this, SLOT(changedCurrentGroup(QString))); diff --git a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h index e03bd0038..1cbd1fc8f 100644 --- a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h +++ b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h @@ -166,7 +166,7 @@ private: virtual QWidget *createCommentHeaderWidget(const RsGxsGroupId &/*grpId*/, const RsGxsMessageId &/*msgId*/) { return NULL; } virtual bool getDistantSearchResults(TurtleRequestId /* id */, std::map& /* group_infos */){ return false ;} virtual void clearDistantSearchResults(TurtleRequestId /* id */) {} - virtual RsGxsGenericGroupData *getDistantSearchResultGroupData(const RsGxsGroupId& group_id){ return nullptr ;} + virtual RsGxsGenericGroupData *getDistantSearchResultGroupData(const RsGxsGroupId& /*group_id*/){ return nullptr ;} void initUi(); diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp index bac5e6cb8..959074138 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp @@ -774,31 +774,31 @@ void GxsChannelPostsWidgetWithModel::showPostDetails() std::cerr << "showPostDetails: current index is " << index.row() << "," << index.column() << std::endl; #endif - QTextDocument doc; - doc.setHtml(post.mMsg.c_str()); + //QTextDocument doc; + //doc.setHtml(post.mMsg.c_str()); - if(post.mMeta.mPublishTs == 0) - { - ui->postDetails_TE->clear(); - ui->postLogo_LB->hide(); + if(post.mMeta.mPublishTs == 0) + { + ui->postDetails_TE->clear(); + ui->postLogo_LB->hide(); ui->postName_LB->hide(); ui->postTime_LB->hide(); - mChannelPostFilesModel->clear(); - ui->details_TW->setEnabled(false); - mSelectedPost.clear(); + mChannelPostFilesModel->clear(); + ui->details_TW->setEnabled(false); + //mLastSelectedPosts[groupId()].clear(); - return; - } - ui->details_TW->setEnabled(true); + return; + } + ui->details_TW->setEnabled(true); ui->postLogo_LB->show(); ui->postName_LB->show(); ui->postTime_LB->show(); #ifdef DEBUG_CHANNEL_POSTS_WIDGET - std::cerr << "showPostDetails: setting mSelectedPost to current post Id " << post.mMeta.mMsgId << ". Previous value: " << mSelectedPost << std::endl; + std::cerr << "showPostDetails: setting mLastSelectedPosts[groupId()] to current post Id " << post.mMeta.mMsgId << ". Previous value: " << mLastSelectedPosts[groupId()] << std::endl; #endif - mSelectedPost = post.mMeta.mMsgId; + mLastSelectedPosts[groupId()] = post.mMeta.mMsgId; std::list files; for(auto& file:post.mFiles) @@ -886,7 +886,7 @@ void GxsChannelPostsWidgetWithModel::updateGroupData() RsQThreadUtils::postToObject( [this,group]() { - if(mGroup.mMeta.mGroupId != group.mMeta.mGroupId) // this prevents any attempt to display the wrong index. Navigate() if needed will use mSelectedPost + if(mGroup.mMeta.mGroupId != group.mMeta.mGroupId) // this prevents any attempt to display the wrong index. Navigate() if needed will use mNavigatePendingMsgId { #ifdef DEBUG_CHANNEL_POSTS_WIDGET std::cerr << "Old group: " << mGroup.mMeta.mGroupId << ", new group: " << group.mMeta.mGroupId << ". Celaring selection" << std::endl; @@ -913,12 +913,16 @@ void GxsChannelPostsWidgetWithModel::postChannelPostLoad() { std::cerr << "Post channel load..." << std::endl; - if(!mSelectedPost.isNull()) + if (!mNavigatePendingMsgId.isNull()) + navigate(mNavigatePendingMsgId); + + else if( (mLastSelectedPosts.count(groupId()) > 0) + && !mLastSelectedPosts[groupId()].isNull()) { - QModelIndex index = mChannelPostsModel->getIndexOfMessage(mSelectedPost); + QModelIndex index = mChannelPostsModel->getIndexOfMessage(mLastSelectedPosts[groupId()]); std::cerr << "Setting current index to " << index.row() << ","<< index.column() << " for current post " - << mSelectedPost.toStdString() << std::endl; + << mLastSelectedPosts[groupId()].toStdString() << std::endl; ui->postsTree->selectionModel()->setCurrentIndex(index,QItemSelectionModel::ClearAndSelect); ui->postsTree->scrollTo(index);//May change if model reloaded @@ -1315,20 +1319,22 @@ bool GxsChannelPostsWidgetWithModel::navigate(const RsGxsMessageId& msgId) { QModelIndex index = mChannelPostsModel->getIndexOfMessage(msgId); - if(!index.isValid()) - { - std::cerr << "(EE) Cannot navigate to msg " << msgId << " in channel " << mGroup.mMeta.mGroupId << ": index unknown. Setting mNavigatePendingMsgId." << std::endl; + if(!index.isValid()) + { + std::cerr << "(EE) Cannot navigate to msg " << msgId << " in channel " << mGroup.mMeta.mGroupId << ": index unknown. Setting mNavigatePendingMsgId." << std::endl; - mSelectedPost = msgId; // not found. That means the forum may not be loaded yet. So we keep that post in mind, for after loading. - return true; // we have to return true here, otherwise the caller will intepret the async loading as an error. - } + mNavigatePendingMsgId = msgId; // not found. That means the forum may not be loaded yet. So we keep that post in mind, for after loading. + return true; // we have to return true here, otherwise the caller will intepret the async loading as an error. + } ui->postsTree->selectionModel()->setCurrentIndex(index,QItemSelectionModel::ClearAndSelect); ui->postsTree->scrollTo(index);//May change if model reloaded ui->postsTree->setFocus(); - ui->channel_TW->setCurrentIndex(CHANNEL_TABS_POSTS); - ui->details_TW->setCurrentIndex(CHANNEL_TABS_DETAILS); + ui->channel_TW->setCurrentIndex(CHANNEL_TABS_POSTS); + ui->details_TW->setCurrentIndex(CHANNEL_TABS_DETAILS); + + mNavigatePendingMsgId.clear(); return true; } diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h index 01bb86757..4e74d2f00 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h @@ -190,7 +190,8 @@ private: ChannelPostDelegate *mChannelPostsDelegate; ChannelPostFilesDelegate *mFilesDelegate; - RsGxsMessageId mSelectedPost; + std::map mLastSelectedPosts; + RsGxsMessageId mNavigatePendingMsgId; /* UI - from Designer */ Ui::GxsChannelPostsWidgetWithModel *ui;