From 444730d19c460f1de6ec674688358571f1a4dd88 Mon Sep 17 00:00:00 2001 From: electron128 Date: Sun, 3 May 2015 12:28:08 +0000 Subject: [PATCH] fixed performance problem in 8207 git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8213 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- .../gui/gxsforums/GxsForumThreadWidget.cpp | 66 +++++++++++-------- .../src/gui/gxsforums/GxsForumThreadWidget.h | 5 +- 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp index 496ecb0c7..7a48596c6 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp @@ -686,43 +686,51 @@ void GxsForumThreadWidget::insertGroupData() #ifdef DEBUG_FORUMS std::cerr << "GxsForumThreadWidget::insertGroupData" << std::endl; #endif - const RsGxsForumGroup& group = mForumGroup; + GxsIdDetails::process(mForumGroup.mMeta.mAuthorId, &loadAuthorIdCallback, this); + calculateIconsAndFonts(); +} + +/*static*/ void GxsForumThreadWidget::loadAuthorIdCallback(GxsIdDetailsType type, const RsIdentityDetails &details, QObject *object, const QVariant &) +{ + GxsForumThreadWidget *tw = dynamic_cast(object); + if(!tw) + return; QString author; - if(group.mMeta.mAuthorId.isNull()) - author = tr("no author"); - else - { - RsIdentityDetails details; - if(!rsIdentity->getIdDetails(group.mMeta.mAuthorId, details)) - { - // try again later - QTimer::singleShot(200, this, SLOT(insertGroupData())); - author = tr("loading..."); - } - else - author = QString::fromUtf8(details.mNickname.c_str()); + switch (type) { + case GXS_ID_DETAILS_TYPE_EMPTY: + author = GxsIdDetails::getEmptyIdText(); + break; + case GXS_ID_DETAILS_TYPE_FAILED: + author = GxsIdDetails::getFailedText(details.mId); + break; + case GXS_ID_DETAILS_TYPE_LOADING: + author = GxsIdDetails::getLoadingText(details.mId); + break; + case GXS_ID_DETAILS_TYPE_DONE: + author = GxsIdDetails::getName(details); + break; } - mSubscribeFlags = group.mMeta.mSubscribeFlags; - ui->forumName->setText(QString::fromUtf8(group.mMeta.mGroupName.c_str())); + const RsGxsForumGroup& group = tw->mForumGroup; - mForumDescription = QString("%1: \t%2
").arg(tr("Forum name"), QString::fromUtf8( group.mMeta.mGroupName.c_str())); - mForumDescription += QString("%1: \t%2
").arg(tr("Subscribers")).arg(group.mMeta.mPop); - mForumDescription += QString("%1: \t%2
").arg(tr("Posts (at neighbor nodes)")).arg(group.mMeta.mVisibleMsgCount); - mForumDescription += QString("%1: \t%2
").arg(tr("Author"), author); - mForumDescription += QString("%1:

%2").arg(tr("Description"), QString::fromUtf8(group.mDescription.c_str())); + tw->mSubscribeFlags = group.mMeta.mSubscribeFlags; + tw->ui->forumName->setText(QString::fromUtf8(group.mMeta.mGroupName.c_str())); - ui->subscribeToolButton->setSubscribed(IS_GROUP_SUBSCRIBED(mSubscribeFlags)); - mStateHelper->setWidgetEnabled(ui->newthreadButton, (IS_GROUP_SUBSCRIBED(mSubscribeFlags))); + tw->mForumDescription = QString("%1: \t%2
").arg(tr("Forum name"), QString::fromUtf8( group.mMeta.mGroupName.c_str())); + tw->mForumDescription += QString("%1: \t%2
").arg(tr("Subscribers")).arg(group.mMeta.mPop); + tw->mForumDescription += QString("%1: \t%2
").arg(tr("Posts (at neighbor nodes)")).arg(group.mMeta.mVisibleMsgCount); + tw->mForumDescription += QString("%1: \t%2
").arg(tr("Author"), author); + tw->mForumDescription += QString("%1:

%2").arg(tr("Description"), QString::fromUtf8(group.mDescription.c_str())); - if (mThreadId.isNull() && !mStateHelper->isLoading(mTokenTypeMessageData)) - { + tw->ui->subscribeToolButton->setSubscribed(IS_GROUP_SUBSCRIBED(tw->mSubscribeFlags)); + tw->mStateHelper->setWidgetEnabled(tw->ui->newthreadButton, (IS_GROUP_SUBSCRIBED(tw->mSubscribeFlags))); + + if (tw->mThreadId.isNull() && !tw->mStateHelper->isLoading(tw->mTokenTypeMessageData)) + { //ui->threadTitle->setText(tr("Forum Description")); - ui->postText->setText(mForumDescription); - } - - calculateIconsAndFonts(); + tw->ui->postText->setText(tw->mForumDescription); + } } void GxsForumThreadWidget::fillThreadFinished() diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h index 6fb258bb9..311024f07 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h @@ -3,6 +3,7 @@ #include "gui/gxs/GxsMessageFrameWidget.h" #include +#include "gui/gxs/GxsIdDetails.h" class QTreeWidgetItem; class RSTreeWidgetItemCompareRole; @@ -132,9 +133,9 @@ private: void requestGroupData(); void loadGroupData(const uint32_t &token); -private slots: void insertGroupData(); -private: + static void loadAuthorIdCallback(GxsIdDetailsType type, const RsIdentityDetails &details, QObject *object, const QVariant &/*data*/); + void requestMessageData(const RsGxsGrpMsgIdPair &msgId); void loadMessageData(const uint32_t &token); void requestMsgData_ReplyMessage(const RsGxsGrpMsgIdPair &msgId);