From 0ce2dd8486a85232e8aa8ffdec23a632aeff9d57 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 12 Jun 2025 21:12:47 +0200 Subject: [PATCH] removed groupsChanged and used rsEvents::FRIEND_LIST instead --- retroshare-gui/src/gui/MainWindow.cpp | 2 ++ retroshare-gui/src/gui/ShareManager.cpp | 20 +++++++++++- retroshare-gui/src/gui/ShareManager.h | 1 + .../src/gui/common/FriendSelectionWidget.cpp | 30 +++++++++++------ .../src/gui/common/FriendSelectionWidget.h | 6 ++-- .../src/gui/common/GroupSelectionBox.cpp | 32 ++++++++++++++++++- .../src/gui/common/GroupSelectionBox.h | 5 +++ .../src/gui/common/NewFriendList.cpp | 4 +-- retroshare-gui/src/gui/common/NewFriendList.h | 2 +- retroshare-gui/src/gui/feeds/PeerItem.cpp | 4 +++ retroshare-gui/src/gui/feeds/PeerItem.h | 1 + retroshare-gui/src/gui/feeds/SecurityItem.cpp | 4 +++ retroshare-gui/src/gui/feeds/SecurityItem.h | 1 + .../gui/gxschannels/GxsChannelPostsModel.cpp | 2 +- .../gui/gxschannels/GxsChannelPostsModel.h | 2 +- retroshare-gui/src/gui/notifyqt.cpp | 3 +- retroshare-gui/src/gui/notifyqt.h | 2 +- .../src/gui/settings/ServerPage.cpp | 6 +++- retroshare-gui/src/gui/settings/ServerPage.h | 2 +- 19 files changed, 106 insertions(+), 23 deletions(-) diff --git a/retroshare-gui/src/gui/MainWindow.cpp b/retroshare-gui/src/gui/MainWindow.cpp index a8ed9bc5d..8803783a4 100644 --- a/retroshare-gui/src/gui/MainWindow.cpp +++ b/retroshare-gui/src/gui/MainWindow.cpp @@ -390,6 +390,8 @@ MainWindow::~MainWindow() Settings->setValueToGroup("MainWindow", "SplitterState", ui->splitter->saveState()); Settings->setValueToGroup("MainWindow", "State", saveState()); + rsEvents->unregisterEventsHandler(mEventHandlerId); + delete statusComboBox; delete peerstatus; delete natstatus; diff --git a/retroshare-gui/src/gui/ShareManager.cpp b/retroshare-gui/src/gui/ShareManager.cpp index 6681e30c5..f22d4182a 100644 --- a/retroshare-gui/src/gui/ShareManager.cpp +++ b/retroshare-gui/src/gui/ShareManager.cpp @@ -38,6 +38,7 @@ #include "gui/notifyqt.h" #include "util/QtVersion.h" #include "util/misc.h" +#include "util/qtthreadsutils.h" #include "gui/common/FilesDefs.h" /* Images for context menu icons */ @@ -73,7 +74,23 @@ ShareManager::ShareManager() connect(ui.shareddirList, SIGNAL(cellDoubleClicked(int,int)), this, SLOT(doubleClickedCell(int,int))); connect(ui.shareddirList, SIGNAL(cellChanged(int,int)), this, SLOT(handleCellChange(int,int))); - connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(reload())); + // connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(reload())); + + mEventHandlerId = 0; + + rsEvents->registerEventsHandler( [this](std::shared_ptr e) + { + RsQThreadUtils::postToObject([=]() + { + auto fe = dynamic_cast(e.get()); + + if(!fe) + return; + + reload(); + } + , this ); + }, mEventHandlerId, RsEventType::FRIEND_LIST ); QHeaderView* header = ui.shareddirList->horizontalHeader(); QHeaderView_setSectionResizeModeColumn(header, COLUMN_PATH, QHeaderView::Stretch); @@ -152,6 +169,7 @@ ShareManager::~ShareManager() { _instance = NULL; + rsEvents->unregisterEventsHandler(mEventHandlerId); Settings->saveWidgetInformation(this); } diff --git a/retroshare-gui/src/gui/ShareManager.h b/retroshare-gui/src/gui/ShareManager.h index 1ddfaa0a9..b6d579894 100644 --- a/retroshare-gui/src/gui/ShareManager.h +++ b/retroshare-gui/src/gui/ShareManager.h @@ -77,6 +77,7 @@ private: Ui::ShareManager ui; std::vector mDirInfos ; + RsEventsHandlerId_t mEventHandlerId; }; #endif diff --git a/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp b/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp index 6e7e89b58..3c7ba5a29 100644 --- a/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp +++ b/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp @@ -101,8 +101,8 @@ FriendSelectionWidget::FriendSelectionWidget(QWidget *parent) connect(ui->friendList, SIGNAL(itemSelectionChanged()), this, SIGNAL(itemSelectionChanged())); connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterItems(QString))); - connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(groupsChanged(int))); - connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(const QString&,int)), this, SLOT(peerStatusChanged(const QString&,int))); + //connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(groupsChanged(int))); + //connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(const QString&,int)), this, SLOT(peerStatusChanged(const QString&,int))); mCompareRole = new RSTreeWidgetItemCompareRole; mActionSortByState = new QAction(tr("Sort by state"), this); @@ -159,7 +159,21 @@ void FriendSelectionWidget::handleEvent_main_thread(std::shared_ptrgetStatus(fp->mSslId,i); + + peerStatusChanged(fp->mSslId,i.status); + } + default: + break ; } } @@ -770,21 +784,18 @@ template<> inline void FriendSelectionWidget::setSelectedIdsdata(COLUMN_DATA, ROLE_ID).toString() == peerId) { + if (RsPeerId(item->data(COLUMN_DATA, ROLE_ID).toString().toStdString()) == peerid) + { if (status != (int) RS_STATUS_OFFLINE) { item->setData(COLUMN_NAME, Qt::ForegroundRole, textColorOnline()); } else { diff --git a/retroshare-gui/src/gui/common/FriendSelectionWidget.h b/retroshare-gui/src/gui/common/FriendSelectionWidget.h index 425e16774..c01c888e7 100644 --- a/retroshare-gui/src/gui/common/FriendSelectionWidget.h +++ b/retroshare-gui/src/gui/common/FriendSelectionWidget.h @@ -137,8 +137,7 @@ public slots: void filterConnected(bool filter); private slots: - void groupsChanged(int type); - void peerStatusChanged(const QString& peerId, int status); + void peerStatusChanged(const RsPeerId &peerid, int status); void filterItems(const QString &text); void contextMenuRequested(const QPoint &pos); void itemDoubleClicked(QTreeWidgetItem *item, int column); @@ -147,7 +146,8 @@ private slots: void deselectAll() ; private: - void fillList(); + void groupsChanged(); + void fillList(); void secured_fillList(); void selectedIds_internal(IdType idType, std::set &ids, bool onlyDirectSelected); diff --git a/retroshare-gui/src/gui/common/GroupSelectionBox.cpp b/retroshare-gui/src/gui/common/GroupSelectionBox.cpp index 18cdff34d..1a1f27a39 100644 --- a/retroshare-gui/src/gui/common/GroupSelectionBox.cpp +++ b/retroshare-gui/src/gui/common/GroupSelectionBox.cpp @@ -24,6 +24,7 @@ #include "GroupSelectionBox.h" #include "GroupDefs.h" #include "gui/notifyqt.h" +#include "util/qtthreadsutils.h" #include @@ -34,11 +35,40 @@ GroupSelectionBox::GroupSelectionBox(QWidget *parent) { setSelectionMode(QAbstractItemView::SingleSelection); - connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(fillGroups())); + //connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(fillGroups())); + + mEventHandlerId = 0; + + rsEvents->registerEventsHandler( [this](std::shared_ptr e) + { + RsQThreadUtils::postToObject([=]() + { + auto fe = dynamic_cast(e.get()); + + if(!fe) + return; + + switch(fe->mEventCode) + { + case RsFriendListEventCode::GROUP_ADDED: + case RsFriendListEventCode::GROUP_REMOVED: + case RsFriendListEventCode::GROUP_CHANGED: fillGroups(); + + default: + break; + } + } + , this ); + }, mEventHandlerId, RsEventType::FRIEND_LIST ); // Fill with available groups fillGroups(); } + +GroupSelectionBox::~GroupSelectionBox() +{ + rsEvents->unregisterEventsHandler(mEventHandlerId); +} void GroupSelectionBox::fillGroups() { std::list selectedIds; diff --git a/retroshare-gui/src/gui/common/GroupSelectionBox.h b/retroshare-gui/src/gui/common/GroupSelectionBox.h index 09ae741c2..6cd4ac9cb 100644 --- a/retroshare-gui/src/gui/common/GroupSelectionBox.h +++ b/retroshare-gui/src/gui/common/GroupSelectionBox.h @@ -21,6 +21,7 @@ #include #include #include +#include class GroupSelectionBox: public QListWidget { @@ -28,6 +29,7 @@ class GroupSelectionBox: public QListWidget public: GroupSelectionBox(QWidget *parent); + virtual ~GroupSelectionBox(); static void selectGroups(const std::list& default_groups) ; @@ -38,6 +40,9 @@ public: private slots: void fillGroups(); + +private: + RsEventsHandlerId_t mEventHandlerId ; }; class GroupSelectionDialog: public QDialog diff --git a/retroshare-gui/src/gui/common/NewFriendList.cpp b/retroshare-gui/src/gui/common/NewFriendList.cpp index 34bc75de2..86966d7fd 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.cpp +++ b/retroshare-gui/src/gui/common/NewFriendList.cpp @@ -195,9 +195,9 @@ NewFriendList::NewFriendList(QWidget */*parent*/) : /* RsAutoUpdatePage(5000,par ui->filterLineEdit->setPlaceholderText(tr("Search")) ; ui->filterLineEdit->showFilterIcon(); +// mEventHandlerId_pssc=0; // forces initialization mEventHandlerId_peer=0; // forces initialization mEventHandlerId_gssp=0; // forces initialization - mEventHandlerId_pssc=0; // forces initialization // rsEvents->registerEventsHandler( [this](std::shared_ptr e) { handleEvent(e); }, mEventHandlerId_pssc, RsEventType::PEER_STATE_CHANGED ); rsEvents->registerEventsHandler( [this](std::shared_ptr e) { handleEvent(e); }, mEventHandlerId_peer, RsEventType::FRIEND_LIST ); @@ -293,7 +293,7 @@ NewFriendList::~NewFriendList() { rsEvents->unregisterEventsHandler(mEventHandlerId_peer); rsEvents->unregisterEventsHandler(mEventHandlerId_gssp); - rsEvents->unregisterEventsHandler(mEventHandlerId_pssc); +// rsEvents->unregisterEventsHandler(mEventHandlerId_pssc); delete mModel; delete mProxyModel; diff --git a/retroshare-gui/src/gui/common/NewFriendList.h b/retroshare-gui/src/gui/common/NewFriendList.h index cf4c68e6f..18a7d4b97 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.h +++ b/retroshare-gui/src/gui/common/NewFriendList.h @@ -127,7 +127,7 @@ private: bool mShowState; RsEventsHandlerId_t mEventHandlerId_peer; RsEventsHandlerId_t mEventHandlerId_gssp; - RsEventsHandlerId_t mEventHandlerId_pssc; +// RsEventsHandlerId_t mEventHandlerId_pssc; std::set openGroups; std::set openPeers; diff --git a/retroshare-gui/src/gui/feeds/PeerItem.cpp b/retroshare-gui/src/gui/feeds/PeerItem.cpp index 43112ced6..388f3cbc8 100644 --- a/retroshare-gui/src/gui/feeds/PeerItem.cpp +++ b/retroshare-gui/src/gui/feeds/PeerItem.cpp @@ -85,6 +85,10 @@ PeerItem::PeerItem(FeedHolder *parent, uint32_t feedId, const RsPeerId &peerId, updateItem(); } +PeerItem::~PeerItem() +{ + rsEvents->unregisterEventsHandler(mEventHandlerId); +} uint64_t PeerItem::uniqueIdentifier() const { return hash_64bits("PeerItem " + mPeerId.toStdString() + " " + QString::number(mType).toStdString()) ; diff --git a/retroshare-gui/src/gui/feeds/PeerItem.h b/retroshare-gui/src/gui/feeds/PeerItem.h index 7e38bb08f..8a7a2abc3 100644 --- a/retroshare-gui/src/gui/feeds/PeerItem.h +++ b/retroshare-gui/src/gui/feeds/PeerItem.h @@ -40,6 +40,7 @@ class PeerItem : public FeedItem, private Ui::PeerItem public: /** Default Constructor */ PeerItem(FeedHolder *parent, uint32_t feedId, const RsPeerId &peerId, uint32_t type, bool isHome); + virtual ~PeerItem(); void updateItemStatic(); diff --git a/retroshare-gui/src/gui/feeds/SecurityItem.cpp b/retroshare-gui/src/gui/feeds/SecurityItem.cpp index 0d0729125..2b5cf281d 100644 --- a/retroshare-gui/src/gui/feeds/SecurityItem.cpp +++ b/retroshare-gui/src/gui/feeds/SecurityItem.cpp @@ -99,6 +99,10 @@ SecurityItem::SecurityItem(FeedHolder *parent, uint32_t feedId, const RsPgpId &g updateItem(); } +SecurityItem::~SecurityItem() +{ + rsEvents->unregisterEventsHandler(mEventHandlerId); +} uint64_t SecurityItem::uniqueIdentifier() const { return hash_64bits("SecurityItem " + QString::number(mType).toStdString() + " " + mSslId.toStdString()); diff --git a/retroshare-gui/src/gui/feeds/SecurityItem.h b/retroshare-gui/src/gui/feeds/SecurityItem.h index c9758107f..b51943f89 100644 --- a/retroshare-gui/src/gui/feeds/SecurityItem.h +++ b/retroshare-gui/src/gui/feeds/SecurityItem.h @@ -39,6 +39,7 @@ class SecurityItem : public FeedItem, private Ui::SecurityItem public: /** Default Constructor */ SecurityItem(FeedHolder *parent, uint32_t feedId, const RsPgpId &gpgId, const RsPeerId &sslId, const std::string &sslCn, const std::string& ip_addr,uint32_t type, bool isHome); + ~SecurityItem(); void updateItemStatic(); diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp index 8b5b7e707..45b465955 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp @@ -53,7 +53,7 @@ RsGxsChannelPostsModel::RsGxsChannelPostsModel(QObject *parent) RsGxsChannelPostsModel::~RsGxsChannelPostsModel() { - rsEvents->unregisterEventsHandler(mEventHandlerId); +// rsEvents->unregisterEventsHandler(mEventHandlerId); } void RsGxsChannelPostsModel::setMode(TreeMode mode) diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.h b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.h index c447f11a3..b0829c28c 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.h @@ -256,6 +256,6 @@ private: QColor mTextColorNotSubscribed ; QColor mTextColorMissing ; - RsEventsHandlerId_t mEventHandlerId ; + //RsEventsHandlerId_t mEventHandlerId ; friend class const_iterator; }; diff --git a/retroshare-gui/src/gui/notifyqt.cpp b/retroshare-gui/src/gui/notifyqt.cpp index 253e66d73..e230b2eb1 100644 --- a/retroshare-gui/src/gui/notifyqt.cpp +++ b/retroshare-gui/src/gui/notifyqt.cpp @@ -618,13 +618,14 @@ void NotifyQt::notifyListChange(int list, int type) #endif emit lobbyListChanged(); break; - +#ifdef TO_REMOVE case NOTIFY_LIST_GROUPLIST: #ifdef NOTIFY_DEBUG std::cerr << "received groups changed" << std::endl ; #endif emit groupsChanged(type); break; +#endif default: break; } diff --git a/retroshare-gui/src/gui/notifyqt.h b/retroshare-gui/src/gui/notifyqt.h index a39f648c3..6e0adb7d8 100644 --- a/retroshare-gui/src/gui/notifyqt.h +++ b/retroshare-gui/src/gui/notifyqt.h @@ -126,7 +126,7 @@ class NotifyQt: public QObject, public NotifyClient void peerStatusChangedSummary() const; void gxsChange(const RsGxsChanges& /* changes */); void chatMessageReceived(ChatMessage msg); - void groupsChanged(int type) const ; +// void groupsChanged(int type) const ; void discInfoChanged() const ; void historyChanged(uint msgId, int type); void chatLobbyInviteReceived() ; diff --git a/retroshare-gui/src/gui/settings/ServerPage.cpp b/retroshare-gui/src/gui/settings/ServerPage.cpp index be2404bc8..72fe6d614 100755 --- a/retroshare-gui/src/gui/settings/ServerPage.cpp +++ b/retroshare-gui/src/gui/settings/ServerPage.cpp @@ -85,7 +85,6 @@ ServerPage::ServerPage(QWidget * parent, Qt::WindowFlags flags) , manager(NULL), mOngoingConnectivityCheck(-1) , mIsHiddenNode(false), mHiddenType(RS_HIDDEN_TYPE_NONE) , mSamAccessible(false) - , mEventHandlerId(0) { /* Invoke the Qt Designer generated object setup routine */ ui.setupUi(this); @@ -262,10 +261,15 @@ ServerPage::ServerPage(QWidget * parent, Qt::WindowFlags flags) if (ui.tabWidget->currentIndex() == TAB_HIDDEN_SERVICE) updateOutProxyIndicator(); + mEventHandlerId = 0; rsEvents->registerEventsHandler( [this](std::shared_ptr event) { handleEvent(event); }, mEventHandlerId, RsEventType::NETWORK ); } +ServerPage::~ServerPage() +{ + rsEvents->unregisterEventsHandler(mEventHandlerId); +} void ServerPage::handleEvent(std::shared_ptr e) { if(e->mType != RsEventType::NETWORK) diff --git a/retroshare-gui/src/gui/settings/ServerPage.h b/retroshare-gui/src/gui/settings/ServerPage.h index 7d82f2190..c6b5e311e 100755 --- a/retroshare-gui/src/gui/settings/ServerPage.h +++ b/retroshare-gui/src/gui/settings/ServerPage.h @@ -53,7 +53,7 @@ class ServerPage: public ConfigPage, public autoProxyCallback public: ServerPage(QWidget * parent = 0, Qt::WindowFlags flags = 0); - ~ServerPage() {} + ~ServerPage() ; /** Loads the settings for this page */ virtual void load();