From 87e92e52292104b18c27081ef5a63a192cbc69d7 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 2 Mar 2020 22:08:13 +0100 Subject: [PATCH 1/4] simplified loginc in deleting duplicate items --- retroshare-gui/src/gui/Identity/IdDialog.cpp | 161 +++++++++---------- 1 file changed, 74 insertions(+), 87 deletions(-) diff --git a/retroshare-gui/src/gui/Identity/IdDialog.cpp b/retroshare-gui/src/gui/Identity/IdDialog.cpp index bf5502fea..e4e91e82a 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdDialog.cpp @@ -515,6 +515,68 @@ void IdDialog::updateCircles() }); } +static QTreeWidgetItem *setChildItem(QTreeWidgetItem *item, const RsGroupMetaData& circle_group) +{ + QString test_str = QString::fromStdString(circle_group.mGroupId.toStdString()); + + // 1 - check if the item already exists and remove possible duplicates + + std::vector found_indices; + + for(uint32_t k=0; k < (uint32_t)item->childCount(); ++k) + if( item->child(k)->data(CIRCLEGROUP_CIRCLE_COL_GROUPID,Qt::UserRole).toString() == test_str) + found_indices.push_back(k); + + while(found_indices.size() > 1) // delete duplicates, starting from the end in order that deletion preserves indices + { + delete item->takeChild(found_indices.back()); + found_indices.pop_back(); + } + + if(!found_indices.empty()) + { + QTreeWidgetItem *subitem = item->child(found_indices[0]); + + if(subitem->text(CIRCLEGROUP_CIRCLE_COL_GROUPNAME) != QString::fromUtf8(circle_group.mGroupName.c_str())) + { +#ifdef ID_DEBUG + std::cerr << " Existing circle has a new name. Updating it in the tree." << std::endl; +#endif + subitem->setText(CIRCLEGROUP_CIRCLE_COL_GROUPNAME, QString::fromUtf8(circle_group.mGroupName.c_str())); + } + + return subitem; + } + + // 2 - if not, create + + QTreeWidgetItem *subitem = new QTreeWidgetItem(); + + subitem->setText(CIRCLEGROUP_CIRCLE_COL_GROUPNAME, QString::fromUtf8(circle_group.mGroupName.c_str())); + subitem->setData(CIRCLEGROUP_CIRCLE_COL_GROUPID,Qt::UserRole, QString::fromStdString(circle_group.mGroupId.toStdString())); + subitem->setData(CIRCLEGROUP_CIRCLE_COL_GROUPFLAGS, Qt::UserRole, QVariant(circle_group.mSubscribeFlags)); + + item->addChild(subitem); + + return subitem; +} + +static void removeChildItem(QTreeWidgetItem *item, const RsGroupMetaData& circle_group) +{ + QString test_str = QString::fromStdString(circle_group.mGroupId.toStdString()); + + // 1 - check if the item already exists and remove possible duplicates + + std::list found_indices; + + for(uint32_t k=0; k < (uint32_t)item->childCount(); ++k) + if( item->child(k)->data(CIRCLEGROUP_CIRCLE_COL_GROUPID,Qt::UserRole).toString() == test_str) + found_indices.push_front(k); + + for(auto k:found_indices) + delete item->takeChild(k); // delete items in the reverse order (because of the push_front()), so that indices are preserved +} + void IdDialog::loadCircles(const std::list& groupInfo) { #ifdef ID_DEBUG @@ -561,102 +623,27 @@ void IdDialog::loadCircles(const std::list& groupInfo) bool am_I_in_circle = details.mAmIAllowed ; bool am_I_admin (vit->mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN) ; bool am_I_subscribed (vit->mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED) ; - QTreeWidgetItem *item = NULL ; - #ifdef ID_DEBUG std::cerr << "Loaded info for circle " << vit->mGroupId << ". am_I_in_circle=" << am_I_in_circle << std::endl; #endif - // find already existing items for this circle - - // implement the search manually, because there's no find based on user role. - //QList clist = ui->treeWidget_membership->findItems( QString::fromStdString(vit->mGroupId.toStdString()), Qt::MatchExactly|Qt::MatchRecursive, CIRCLEGROUP_CIRCLE_COL_GROUPID); - QList clist ; - QString test_str = QString::fromStdString(vit->mGroupId.toStdString()) ; - for(QTreeWidgetItemIterator itt(ui->treeWidget_membership);*itt;++itt) - if( (*itt)->data(CIRCLEGROUP_CIRCLE_COL_GROUPID,Qt::UserRole).toString() == test_str) - clist.push_back(*itt) ; - - if(!clist.empty()) - { - // delete all duplicate items. This should not happen, but just in case it does. - - while(clist.size() > 1) - { -#ifdef ID_DEBUG - std::cerr << " more than 1 item correspond to this ID. Removing!" << std::endl; -#endif - delete clist.front() ; - clist.pop_front(); - } - - item = clist.front() ; - -#ifdef CIRCLE_MEMBERSHIP_CATEGORIES - if(am_I_in_circle && item->parent() != mExternalBelongingCircleItem) - { -#ifdef ID_DEBUG - std::cerr << " Existing circle is not in subscribed items although it is subscribed. Removing." << std::endl; -#endif - delete item ; - item = NULL ; - } - else if(!am_I_in_circle && item->parent() != mExternalOtherCircleItem) - { -#ifdef ID_DEBUG - std::cerr << " Existing circle is not in subscribed items although it is subscribed. Removing." << std::endl; -#endif - delete item ; - item = NULL ; - } - else -#endif - should_re_add = false ; // item already exists - } - - /* Add Widget, and request Pages */ - - if(should_re_add) - { - item = new QTreeWidgetItem(); - - item->setText(CIRCLEGROUP_CIRCLE_COL_GROUPNAME, QString::fromUtf8(vit->mGroupName.c_str())); - item->setData(CIRCLEGROUP_CIRCLE_COL_GROUPID,Qt::UserRole, QString::fromStdString(vit->mGroupId.toStdString())); - item->setData(CIRCLEGROUP_CIRCLE_COL_GROUPFLAGS, Qt::UserRole, QVariant(vit->mSubscribeFlags)); - -#ifdef CIRCLE_MEMBERSHIP_CATEGORIES - if(am_I_in_circle) - { -#ifdef ID_DEBUG - std::cerr << " adding item for circle " << vit->mGroupId << " to own circles"<< std::endl; -#endif - mExternalBelongingCircleItem->addChild(item); - } - else - { -#ifdef ID_DEBUG - std::cerr << " adding item for circle " << vit->mGroupId << " to others"<< std::endl; -#endif - mExternalOtherCircleItem->addChild(item); - } -#else - ui->treeWidget_membership->addTopLevelItem(item) ; -#endif - } - else if(item->text(CIRCLEGROUP_CIRCLE_COL_GROUPNAME) != QString::fromUtf8(vit->mGroupName.c_str())) - { -#ifdef ID_DEBUG - std::cerr << " Existing circle has a new name. Updating it in the tree." << std::endl; -#endif - item->setText(CIRCLEGROUP_CIRCLE_COL_GROUPNAME, QString::fromUtf8(vit->mGroupName.c_str())); - } - // just in case. + // Find already existing items for this circle, or create one. + QTreeWidgetItem *item = NULL ; + if(am_I_in_circle) + { + item = setChildItem(mExternalBelongingCircleItem,*vit); + removeChildItem(mExternalOtherCircleItem,*vit); + } + else + { + item = setChildItem(mExternalOtherCircleItem,*vit); + removeChildItem(mExternalBelongingCircleItem,*vit); + } item->setData(CIRCLEGROUP_CIRCLE_COL_GROUPFLAGS, Qt::UserRole, QVariant(vit->mSubscribeFlags)); QString tooltip ; tooltip += tr("Circle ID: ")+QString::fromStdString(vit->mGroupId.toStdString()) ; - tooltip += "\n"+tr("Visibility: "); if(details.mRestrictedCircleId == details.mCircleId) From 48d09b5867e9cee54af4123d2d750264be881fbe Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 4 Mar 2020 22:43:17 +0100 Subject: [PATCH 2/4] fixed bug in calling setItemWidget on a possibly null item --- retroshare-gui/src/gui/Identity/IdDialog.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/retroshare-gui/src/gui/Identity/IdDialog.cpp b/retroshare-gui/src/gui/Identity/IdDialog.cpp index e4e91e82a..d59b5bcf2 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdDialog.cpp @@ -1519,11 +1519,12 @@ void IdDialog::loadIdentities(const std::map& ids_set contactsItem->addChild(item); else allItem->addChild(item); - } - GxsIdLabel *label = new GxsIdLabel(); - label->setId(RsGxsId(data.mMeta.mGroupId)) ; - ui->treeWidget_membership->setItemWidget(item,0,label) ; + GxsIdLabel *label = new GxsIdLabel(); + label->setId(RsGxsId(data.mMeta.mGroupId)) ; + + ui->treeWidget_membership->setItemWidget(item,0,label) ; + } } /* count items */ From 09fe628415af123bbc6a349a8c08eafae129d6c5 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 5 Mar 2020 20:50:25 +0100 Subject: [PATCH 3/4] removed debug info --- libretroshare/src/services/p3idservice.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libretroshare/src/services/p3idservice.cc b/libretroshare/src/services/p3idservice.cc index 254d89db1..4d4d5ac5e 100644 --- a/libretroshare/src/services/p3idservice.cc +++ b/libretroshare/src/services/p3idservice.cc @@ -3002,9 +3002,11 @@ void p3IdService::requestIdsFromNet() } else { +#ifdef DEBUG_IDS RsInfo() << __PRETTY_FUNCTION__ << " no online peers among supplied" << " list in request for RsGxsId: " << gxsId << ". Keeping it until peers show up."<< std::endl; +#endif ++cit; } } From f59193b625a367331648a6a197528227af49f885 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 5 Mar 2020 20:51:02 +0100 Subject: [PATCH 4/4] fixed bug in SQL access where timeout was compared to a negative value --- libretroshare/src/util/retrodb.cc | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libretroshare/src/util/retrodb.cc b/libretroshare/src/util/retrodb.cc index a539c1676..122f3e6a1 100644 --- a/libretroshare/src/util/retrodb.cc +++ b/libretroshare/src/util/retrodb.cc @@ -185,7 +185,7 @@ bool RetroDb::execSQL(const std::string &query){ uint32_t delta = 3; - rstime_t stamp = time(NULL), now = 0; + rstime_t stamp = time(NULL); bool timeOut = false, ok = false; while(!timeOut){ @@ -202,10 +202,8 @@ bool RetroDb::execSQL(const std::string &query){ break; } - now = time(NULL); - delta = stamp - now; - - if(delta > TIME_LIMIT){ + if(time(NULL) > stamp + TIME_LIMIT) + { ok = false; timeOut = true; }