From 325a383fba40c67af1a0c815c3b69e7e11757296 Mon Sep 17 00:00:00 2001 From: thunder2 Date: Mon, 9 Mar 2015 20:41:14 +0000 Subject: [PATCH] - Added re-check of "Not found" identities for chat lobby participants list. - Added check of RsAutoUpdatePage::eventsLocked to GxsIdDetails::timerEvent. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8006 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/MessagesDialog.cpp | 2 +- .../src/gui/chat/ChatLobbyDialog.cpp | 2 +- .../src/gui/gxs/GxsCommentTreeWidget.cpp | 2 +- retroshare-gui/src/gui/gxs/GxsIdDetails.cpp | 85 +++++++------- .../src/gui/gxs/GxsIdTreeWidgetItem.cpp | 104 ++++++++++++------ .../src/gui/gxs/GxsIdTreeWidgetItem.h | 8 +- .../gui/gxsforums/GxsForumThreadWidget.cpp | 4 +- retroshare-gui/src/rshare.cpp | 5 + retroshare-gui/src/rshare.h | 2 + 9 files changed, 131 insertions(+), 83 deletions(-) diff --git a/retroshare-gui/src/gui/MessagesDialog.cpp b/retroshare-gui/src/gui/MessagesDialog.cpp index 115bac905..9772702e5 100644 --- a/retroshare-gui/src/gui/MessagesDialog.cpp +++ b/retroshare-gui/src/gui/MessagesDialog.cpp @@ -1108,7 +1108,7 @@ void MessagesDialog::insertMessages() setText = false; if (gotInfo || rsMsgs->getMessage(it->msgId, msgInfo)) { gotInfo = true; - item->setId(RsGxsId(msgInfo.rsgxsid_srcId), COLUMN_FROM); + item->setId(RsGxsId(msgInfo.rsgxsid_srcId), COLUMN_FROM, false); } else { std::cerr << "MessagesDialog::insertMsgTxtAndFiles() Couldn't find Msg" << std::endl; } diff --git a/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp b/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp index 81ad956f5..8f856e996 100644 --- a/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp +++ b/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp @@ -395,7 +395,7 @@ void ChatLobbyDialog::updateParticipantsList() // TE: Add Wigdet to participantsList with Checkbox, to mute Participant widgetitem = new GxsIdRSTreeWidgetItem(mParticipantCompareRole); - widgetitem->setId(it2->first,COLUMN_NAME) ; + widgetitem->setId(it2->first,COLUMN_NAME, true) ; //widgetitem->setText(COLUMN_NAME, participant); widgetitem->setText(COLUMN_ACTIVITY,QString::number(time(NULL))); widgetitem->setText(COLUMN_ID,QString::fromStdString(it2->first.toStdString())); diff --git a/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp b/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp index ac0943da2..d03b5c383 100644 --- a/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp +++ b/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp @@ -430,7 +430,7 @@ void GxsCommentTreeWidget::service_loadThread(const uint32_t &token) item->setText(PCITEM_COLUMN_COMMENT, text); RsGxsId authorId = comment.mMeta.mAuthorId; - item->setId(authorId, PCITEM_COLUMN_AUTHOR); + item->setId(authorId, PCITEM_COLUMN_AUTHOR, false); text = QString::number(comment.mScore); item->setText(PCITEM_COLUMN_SCORE, text); diff --git a/retroshare-gui/src/gui/gxs/GxsIdDetails.cpp b/retroshare-gui/src/gui/gxs/GxsIdDetails.cpp index 18dd52a65..f79fe8a4d 100644 --- a/retroshare-gui/src/gui/gxs/GxsIdDetails.cpp +++ b/retroshare-gui/src/gui/gxs/GxsIdDetails.cpp @@ -28,6 +28,7 @@ #include #include "GxsIdDetails.h" +#include "retroshare-gui/RsAutoUpdatePage.h" #include @@ -119,57 +120,59 @@ void GxsIdDetails::connectObject_locked(QObject *object, bool doConnect) void GxsIdDetails::timerEvent(QTimerEvent *event) { if (event->timerId() == mCheckTimerId) { - /* Stop timer */ - killTimer(mCheckTimerId); - mCheckTimerId = 0; + if (!RsAutoUpdatePage::eventsLocked()) { + /* Stop timer */ + killTimer(mCheckTimerId); + mCheckTimerId = 0; - if (rsIdentity) { - QMutexLocker lock(&mMutex); + if (rsIdentity) { + QMutexLocker lock(&mMutex); - if (!mPendingData.empty()) { - /* Check pending id's */ - QList::iterator dataIt; - for (dataIt = mPendingData.begin(); dataIt != mPendingData.end(); ) { - CallbackData &pendingData = *dataIt; + if (!mPendingData.empty()) { + /* Check pending id's */ + QList::iterator dataIt; + for (dataIt = mPendingData.begin(); dataIt != mPendingData.end(); ) { + CallbackData &pendingData = *dataIt; - RsIdentityDetails details; - if (rsIdentity->getIdDetails(pendingData.mId, details)) { - /* Got details */ - pendingData.mCallback(GXS_ID_DETAILS_TYPE_DONE, details, pendingData.mObject, pendingData.mData); + RsIdentityDetails details; + if (rsIdentity->getIdDetails(pendingData.mId, details)) { + /* Got details */ + pendingData.mCallback(GXS_ID_DETAILS_TYPE_DONE, details, pendingData.mObject, pendingData.mData); - QObject *object = pendingData.mObject; - dataIt = mPendingData.erase(dataIt); - connectObject_locked(object, false); + QObject *object = pendingData.mObject; + dataIt = mPendingData.erase(dataIt); + connectObject_locked(object, false); - continue; + continue; + } + + if (++pendingData.mAttempt > MAX_ATTEMPTS) { + /* Max attempts reached, stop trying */ + details.mId = pendingData.mId; + pendingData.mCallback(GXS_ID_DETAILS_TYPE_FAILED, details, pendingData.mObject, pendingData.mData); + + QObject *object = pendingData.mObject; + dataIt = mPendingData.erase(dataIt); + connectObject_locked(object, false); + + continue; + } + + ++dataIt; } - - if (++pendingData.mAttempt > MAX_ATTEMPTS) { - /* Max attempts reached, stop trying */ - details.mId = pendingData.mId; - pendingData.mCallback(GXS_ID_DETAILS_TYPE_FAILED, details, pendingData.mObject, pendingData.mData); - - QObject *object = pendingData.mObject; - dataIt = mPendingData.erase(dataIt); - connectObject_locked(object, false); - - continue; - } - - ++dataIt; } } - } - QMutexLocker lock(&mMutex); + QMutexLocker lock(&mMutex); - if (mPendingData.empty()) { - /* All done */ - mInstance = NULL; - deleteLater(); - } else { - /* Start timer */ - doStartTimer(); + if (mPendingData.empty()) { + /* All done */ + mInstance = NULL; + deleteLater(); + } else { + /* Start timer */ + doStartTimer(); + } } } diff --git a/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.cpp b/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.cpp index f1554ed1a..f66af976a 100644 --- a/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.cpp +++ b/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.cpp @@ -21,6 +21,7 @@ * */ +#include "rshare.h" #include "GxsIdTreeWidgetItem.h" #include "GxsIdDetails.h" #include "util/HandleRichText.h" @@ -40,68 +41,89 @@ GxsIdRSTreeWidgetItem::GxsIdRSTreeWidgetItem(const RSTreeWidgetItemCompareRole * void GxsIdRSTreeWidgetItem::init() { + mIdFound = false; + mRetryWhenFailed = false; } static void fillGxsIdRSTreeWidgetItemCallback(GxsIdDetailsType type, const RsIdentityDetails &details, QObject *object, const QVariant &/*data*/) { - GxsIdRSTreeWidgetItem *item = dynamic_cast(object); - if (!item) { - return; - } + GxsIdRSTreeWidgetItem *item = dynamic_cast(object); + if (!item) { + return; + } - QString toolTip; - QList icons; + QString toolTip; + QList icons; - switch (type) { - case GXS_ID_DETAILS_TYPE_EMPTY: - case GXS_ID_DETAILS_TYPE_FAILED: - break; + switch (type) { + case GXS_ID_DETAILS_TYPE_EMPTY: + item->processResult(true); + break; - case GXS_ID_DETAILS_TYPE_LOADING: - icons.push_back(GxsIdDetails::getLoadingIcon(details.mId)); - break; + case GXS_ID_DETAILS_TYPE_FAILED: + item->processResult(false); + break; - case GXS_ID_DETAILS_TYPE_DONE: - GxsIdDetails::getIcons(details, icons); - break; - } - toolTip = GxsIdDetails::getComment(details); + case GXS_ID_DETAILS_TYPE_LOADING: + icons.push_back(GxsIdDetails::getLoadingIcon(details.mId)); + break; - int column = item->idColumn(); + case GXS_ID_DETAILS_TYPE_DONE: + GxsIdDetails::getIcons(details, icons); + item->processResult(true); + break; + } + toolTip = GxsIdDetails::getComment(details); - item->setText(column, GxsIdDetails::getNameForType(type, details)); - item->setData(column, Qt::UserRole, QString::fromStdString(details.mId.toStdString())); + int column = item->idColumn(); - QPixmap combinedPixmap; - if (!icons.empty()) { - GxsIdDetails::GenerateCombinedPixmap(combinedPixmap, icons, 16); - } - item->setData(column, Qt::DecorationRole, combinedPixmap); - QImage pix ; + item->setText(column, GxsIdDetails::getNameForType(type, details)); + item->setData(column, Qt::UserRole, QString::fromStdString(details.mId.toStdString())); - if(details.mAvatar.mSize == 0 || !pix.loadFromData(details.mAvatar.mData, details.mAvatar.mSize, "PNG")) - pix = GxsIdDetails::makeDefaultIcon(details.mId); + QPixmap combinedPixmap; + if (!icons.empty()) { + GxsIdDetails::GenerateCombinedPixmap(combinedPixmap, icons, 16); + } + item->setData(column, Qt::DecorationRole, combinedPixmap); + QImage pix ; - QString embeddedImage ; + if(details.mAvatar.mSize == 0 || !pix.loadFromData(details.mAvatar.mData, details.mAvatar.mSize, "PNG")) + pix = GxsIdDetails::makeDefaultIcon(details.mId); - if(RsHtml::makeEmbeddedImage(pix.scaled(QSize(64,64),Qt::KeepAspectRatio,Qt::SmoothTransformation),embeddedImage,128*128)) - toolTip = "
"+embeddedImage+"" +toolTip+ "
" ; + QString embeddedImage ; - item->setToolTip(column, toolTip); + if(RsHtml::makeEmbeddedImage(pix.scaled(QSize(64,64),Qt::KeepAspectRatio,Qt::SmoothTransformation),embeddedImage,128*128)) + toolTip = "
"+embeddedImage+"" +toolTip+ "
" ; + + item->setToolTip(column, toolTip); } -void GxsIdRSTreeWidgetItem::setId(const RsGxsId &id, int column) +void GxsIdRSTreeWidgetItem::setId(const RsGxsId &id, int column, bool retryWhenFailed) { //std::cerr << " GxsIdRSTreeWidgetItem::setId(" << id << "," << column << ")"; //std::cerr << std::endl; - if (mColumn == column && mId == id) { - return; + if (mIdFound) { + if (mColumn == column && mId == id) { + return; + } } + mIdFound = false; + mRetryWhenFailed = retryWhenFailed; + mId = id; mColumn = column; + startProcess(); +} + +void GxsIdRSTreeWidgetItem::startProcess() +{ + if (mRetryWhenFailed) { + disconnect(rApp, SIGNAL(minuteTick()), this, SLOT(startProcess())); + } + GxsIdDetails::process(mId, fillGxsIdRSTreeWidgetItemCallback, this); } @@ -110,3 +132,13 @@ bool GxsIdRSTreeWidgetItem::getId(RsGxsId &id) id = mId; return true; } + +void GxsIdRSTreeWidgetItem::processResult(bool success) +{ + mIdFound = success; + + if (!mIdFound && mRetryWhenFailed) { + /* Try again */ + connect(rApp, SIGNAL(minuteTick()), this, SLOT(startProcess())); + } +} diff --git a/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.h b/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.h index 4f9221645..a43ffec64 100644 --- a/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.h +++ b/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.h @@ -42,16 +42,22 @@ public: GxsIdRSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, QTreeWidget *parent = NULL); GxsIdRSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, QTreeWidgetItem *parent); - void setId(const RsGxsId &id, int column); + void setId(const RsGxsId &id, int column, bool retryWhenFailed); bool getId(RsGxsId &id); int idColumn() { return mColumn; } + void processResult(bool success); + +private slots: + void startProcess(); private: void init(); RsGxsId mId; int mColumn; + bool mIdFound; + bool mRetryWhenFailed; }; #endif diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp index 79b896f8c..fa568ef6b 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp @@ -850,7 +850,7 @@ QTreeWidgetItem *GxsForumThreadWidget::convertMsgToThreadWidget(const RsGxsForum item->setText(COLUMN_THREAD_DATE, text); item->setData(COLUMN_THREAD_DATE, ROLE_THREAD_SORT, sort); - item->setId(msg.mMeta.mAuthorId, COLUMN_THREAD_AUTHOR); + item->setId(msg.mMeta.mAuthorId, COLUMN_THREAD_AUTHOR, false); item->setData(COLUMN_THREAD_DATA, ROLE_THREAD_AUTHOR, QString::fromStdString(msg.mMeta.mAuthorId.toStdString())); //#TODO #if 0 @@ -1013,7 +1013,7 @@ static void copyItem(QTreeWidgetItem *item, const QTreeWidgetItem *newItem) GxsIdRSTreeWidgetItem *gxsIdItem = dynamic_cast(item); if (gxsIdItem) { /* Set new gxs id */ - gxsIdItem->setId(RsGxsId(authorId.toStdString()), i); + gxsIdItem->setId(RsGxsId(authorId.toStdString()), i, false); } else { /* Copy text */ item->setText(i, newItem->text(i)); diff --git a/retroshare-gui/src/rshare.cpp b/retroshare-gui/src/rshare.cpp index d1c0e012c..61a5c47fd 100644 --- a/retroshare-gui/src/rshare.cpp +++ b/retroshare-gui/src/rshare.cpp @@ -120,6 +120,11 @@ Rshare::Rshare(QStringList args, int &argc, char **argv, const QString &dir) connect(timer, SIGNAL(timeout()), this, SLOT(blinkTimer())); timer->start(); + timer = new QTimer(this); + timer->setInterval(60000); + connect(timer, SIGNAL(timeout()), this, SIGNAL(minuteTick())); + timer->start(); + /* Read in all our command-line arguments. */ parseArguments(args); diff --git a/retroshare-gui/src/rshare.h b/retroshare-gui/src/rshare.h index 3b5dff78a..4e83b2299 100644 --- a/retroshare-gui/src/rshare.h +++ b/retroshare-gui/src/rshare.h @@ -142,6 +142,8 @@ signals: void blink(bool on); /** Global timer every second */ void secondTick(); + /** Global timer every minute */ + void minuteTick(); private slots: /** Called when the application's main event loop has started. This method