mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Added disable/enable of GxsIdDetails process.
Disabled GxsIdDetails process when filling gxs id's in forums. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8556 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
c3b794afb2
commit
227e7121cc
@ -47,8 +47,9 @@
|
||||
#define IMAGE_DEV_PATCHER ":/images/tags/dev-patcher.png"
|
||||
#define IMAGE_DEV_DEVELOPER ":/images/tags/developer.png"
|
||||
|
||||
#define TIMER_INTERVAL 1000
|
||||
#define MAX_ATTEMPTS 10
|
||||
#define TIMER_INTERVAL 500
|
||||
#define MAX_ATTEMPTS 10
|
||||
#define MAX_PROCESS_COUNT_PER_TIMER 50
|
||||
|
||||
const int kRecognTagClass_DEVELOPMENT = 1;
|
||||
|
||||
@ -65,6 +66,7 @@ GxsIdDetails::GxsIdDetails()
|
||||
: QObject()
|
||||
{
|
||||
mCheckTimerId = 0;
|
||||
mProcessDisableCount = 0;
|
||||
|
||||
connect(this, SIGNAL(startTimerFromThread()), this, SLOT(doStartTimer()));
|
||||
}
|
||||
@ -147,37 +149,43 @@ void GxsIdDetails::timerEvent(QTimerEvent *event)
|
||||
if (rsIdentity) {
|
||||
QMutexLocker lock(&mMutex);
|
||||
|
||||
if (!mPendingData.empty()) {
|
||||
/* Check pending id's */
|
||||
QList<CallbackData>::iterator dataIt;
|
||||
for (dataIt = mPendingData.begin(); dataIt != mPendingData.end(); ) {
|
||||
CallbackData &pendingData = *dataIt;
|
||||
if (mProcessDisableCount == 0) {
|
||||
if (!mPendingData.empty()) {
|
||||
/* Check pending id's */
|
||||
int processed = qMin(MAX_PROCESS_COUNT_PER_TIMER, mPendingData.size());
|
||||
while (!mPendingData.isEmpty()) {
|
||||
if (processed-- <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
RsIdentityDetails details;
|
||||
if (rsIdentity->getIdDetails(pendingData.mId, details)) {
|
||||
/* Got details */
|
||||
pendingData.mCallback(GXS_ID_DETAILS_TYPE_DONE, details, pendingData.mObject, pendingData.mData);
|
||||
CallbackData &pendingData = mPendingData.front();
|
||||
|
||||
QObject *object = pendingData.mObject;
|
||||
dataIt = mPendingData.erase(dataIt);
|
||||
connectObject_locked(object, false);
|
||||
RsIdentityDetails details;
|
||||
if (rsIdentity->getIdDetails(pendingData.mId, details)) {
|
||||
/* Got details */
|
||||
pendingData.mCallback(GXS_ID_DETAILS_TYPE_DONE, details, pendingData.mObject, pendingData.mData);
|
||||
|
||||
continue;
|
||||
QObject *object = pendingData.mObject;
|
||||
mPendingData.pop_front();
|
||||
connectObject_locked(object, false);
|
||||
|
||||
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;
|
||||
mPendingData.pop_front();
|
||||
connectObject_locked(object, false);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
mPendingData.move(0, mPendingData.size() - 1);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -206,6 +214,24 @@ void GxsIdDetails::doStartTimer()
|
||||
mCheckTimerId = startTimer(TIMER_INTERVAL);
|
||||
}
|
||||
|
||||
void GxsIdDetails::enableProcess(bool enable)
|
||||
{
|
||||
if (!mInstance) {
|
||||
return;
|
||||
}
|
||||
|
||||
QMutexLocker lock(&mInstance->mMutex);
|
||||
|
||||
if (enable) {
|
||||
--mInstance->mProcessDisableCount;
|
||||
if (mInstance->mProcessDisableCount < 0) {
|
||||
mInstance->mProcessDisableCount = 0;
|
||||
}
|
||||
} else {
|
||||
++mInstance->mProcessDisableCount;
|
||||
}
|
||||
}
|
||||
|
||||
bool GxsIdDetails::process(const RsGxsId &id, GxsIdDetailsCallbackFunction callback, QObject *object, const QVariant &data)
|
||||
{
|
||||
if (!callback) {
|
||||
|
@ -81,6 +81,7 @@ public:
|
||||
static QImage makeDefaultIcon(const RsGxsId& id);
|
||||
|
||||
/* Processing */
|
||||
static void enableProcess(bool enable);
|
||||
static bool process(const RsGxsId &id, GxsIdDetailsCallbackFunction callback, QObject *object, const QVariant &data = QVariant());
|
||||
|
||||
signals:
|
||||
@ -131,7 +132,7 @@ protected:
|
||||
/* Pending data */
|
||||
QList<CallbackData> mPendingData;
|
||||
int mCheckTimerId;
|
||||
std::map<RsGxsId,QImage> image_cache ;
|
||||
int mProcessDisableCount;
|
||||
|
||||
/* Thread safe */
|
||||
QMutex mMutex;
|
||||
|
@ -770,6 +770,8 @@ void GxsForumThreadWidget::fillThreadFinished()
|
||||
mStateHelper->setActive(mTokenTypeInsertThreads, true);
|
||||
ui->threadTreeWidget->setSortingEnabled(false);
|
||||
|
||||
GxsIdDetails::enableProcess(false);
|
||||
|
||||
/* add all messages in! */
|
||||
if (mLastViewType != thread->mViewType || mLastForumID != groupId()) {
|
||||
ui->threadTreeWidget->clear();
|
||||
@ -786,6 +788,27 @@ void GxsForumThreadWidget::fillThreadFinished()
|
||||
cleanupItems(thread->mItems);
|
||||
}
|
||||
|
||||
/* Move value from ROLE_THREAD_AUTHOR to GxsIdRSTreeWidgetItem::setId */
|
||||
QTreeWidgetItemIterator itemIterator(ui->threadTreeWidget);
|
||||
QTreeWidgetItem *item = NULL;
|
||||
while ((item = *itemIterator) != NULL) {
|
||||
++itemIterator;
|
||||
|
||||
QString gxsId = item->data(COLUMN_THREAD_DATA, ROLE_THREAD_AUTHOR).toString();
|
||||
if (gxsId.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
item->setData(COLUMN_THREAD_DATA, ROLE_THREAD_AUTHOR, QVariant());
|
||||
|
||||
GxsIdRSTreeWidgetItem *gxsIdItem = dynamic_cast<GxsIdRSTreeWidgetItem*>(item);
|
||||
if (gxsIdItem) {
|
||||
gxsIdItem->setId(RsGxsId(gxsId.toStdString()), COLUMN_THREAD_AUTHOR, false);
|
||||
}
|
||||
}
|
||||
|
||||
GxsIdDetails::enableProcess(true);
|
||||
|
||||
ui->threadTreeWidget->setSortingEnabled(true);
|
||||
|
||||
if (thread->mFocusMsgId.empty() == false) {
|
||||
@ -880,7 +903,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, false);
|
||||
// Set later with GxsIdRSTreeWidgetItem::setId
|
||||
item->setData(COLUMN_THREAD_DATA, ROLE_THREAD_AUTHOR, QString::fromStdString(msg.mMeta.mAuthorId.toStdString()));
|
||||
//#TODO
|
||||
#if 0
|
||||
@ -1035,20 +1058,7 @@ static void copyItem(QTreeWidgetItem *item, const QTreeWidgetItem *newItem)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < COLUMN_THREAD_COUNT; ++i) {
|
||||
if (i == COLUMN_THREAD_AUTHOR) {
|
||||
QString authorId = newItem->data(COLUMN_THREAD_DATA, ROLE_THREAD_AUTHOR).toString();
|
||||
if (authorId != item->data(COLUMN_THREAD_DATA, ROLE_THREAD_AUTHOR).toString()) {
|
||||
/* Author has changed? */
|
||||
GxsIdRSTreeWidgetItem *gxsIdItem = dynamic_cast<GxsIdRSTreeWidgetItem*>(item);
|
||||
if (gxsIdItem) {
|
||||
/* Set new gxs id */
|
||||
gxsIdItem->setId(RsGxsId(authorId.toStdString()), i, false);
|
||||
} else {
|
||||
/* Copy text */
|
||||
item->setText(i, newItem->text(i));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (i != COLUMN_THREAD_AUTHOR) {
|
||||
/* Copy text */
|
||||
item->setText(i, newItem->text(i));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user