From 692ee3face71ec7729a22282f0280caab80eee47 Mon Sep 17 00:00:00 2001 From: jolavillette Date: Thu, 18 Dec 2025 14:21:16 +0100 Subject: [PATCH] remove singleShot calls and use events handlers instead --- retroshare-gui/src/gui/feeds/ChatMsgItem.cpp | 27 ++++++++++++++++--- retroshare-gui/src/gui/feeds/ChatMsgItem.h | 4 ++- .../src/gui/feeds/SecurityIpItem.cpp | 21 ++++++++++++--- retroshare-gui/src/gui/feeds/SecurityIpItem.h | 5 +++- retroshare-gui/src/gui/feeds/SecurityItem.cpp | 6 +---- retroshare-gui/src/gui/feeds/SecurityItem.h | 1 - 6 files changed, 48 insertions(+), 16 deletions(-) diff --git a/retroshare-gui/src/gui/feeds/ChatMsgItem.cpp b/retroshare-gui/src/gui/feeds/ChatMsgItem.cpp index 02b1a3409..9fb334cbc 100644 --- a/retroshare-gui/src/gui/feeds/ChatMsgItem.cpp +++ b/retroshare-gui/src/gui/feeds/ChatMsgItem.cpp @@ -36,6 +36,9 @@ #include "gui/msgs/MessageInterface.h" +#include "util/qtthreadsutils.h" +#include + /***** * #define DEBUG_ITEM 1 ****/ @@ -68,10 +71,26 @@ ChatMsgItem::ChatMsgItem(FeedHolder *parent, uint32_t feedId, const RsPeerId &pe updateItem(); insertChat(message); - m_updateTimer = new QTimer(this); - m_updateTimer->setSingleShot(false); - connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updateItem())); - m_updateTimer->start(1000); + mEventHandlerId = 0; + + rsEvents->registerEventsHandler( [this](std::shared_ptr e) + { + RsQThreadUtils::postToObject([=]() + { + auto fe = dynamic_cast(e.get()); + + if(!fe || fe->mSslId != mPeerId) + return; + + updateItem(); + } + , this ); + }, mEventHandlerId, RsEventType::FRIEND_LIST ); +} + +ChatMsgItem::~ChatMsgItem() +{ + rsEvents->unregisterEventsHandler(mEventHandlerId); } void ChatMsgItem::updateItemStatic() diff --git a/retroshare-gui/src/gui/feeds/ChatMsgItem.h b/retroshare-gui/src/gui/feeds/ChatMsgItem.h index d9216def9..0515b925e 100644 --- a/retroshare-gui/src/gui/feeds/ChatMsgItem.h +++ b/retroshare-gui/src/gui/feeds/ChatMsgItem.h @@ -35,6 +35,8 @@ public: /** Default Constructor */ ChatMsgItem(FeedHolder *parent, uint32_t feedId, const RsPeerId &peerId, const std::string &message); + virtual ~ChatMsgItem(); + void updateItemStatic(); virtual uint64_t uniqueIdentifier() const override { return hash_64bits("ChatMsgItem " + mPeerId.toStdString()); } @@ -60,7 +62,7 @@ private: void insertChat(const std::string &message); RsPeerId mPeerId; - QTimer *m_updateTimer; + RsEventsHandlerId_t mEventHandlerId; }; #endif diff --git a/retroshare-gui/src/gui/feeds/SecurityIpItem.cpp b/retroshare-gui/src/gui/feeds/SecurityIpItem.cpp index 7d49945b4..df79c7df9 100644 --- a/retroshare-gui/src/gui/feeds/SecurityIpItem.cpp +++ b/retroshare-gui/src/gui/feeds/SecurityIpItem.cpp @@ -34,6 +34,8 @@ #include #include +#include "util/qtthreadsutils.h" + /***** * #define DEBUG_ITEM 1 ****/ @@ -53,6 +55,11 @@ SecurityIpItem::SecurityIpItem(FeedHolder *parent, const RsPeerId &sslId, const setup(); } +SecurityIpItem::~SecurityIpItem() +{ + rsEvents->unregisterEventsHandler(mEventHandlerId); +} + void SecurityIpItem::setup() { /* Invoke the Qt Designer generated object setup routine */ @@ -77,10 +84,16 @@ void SecurityIpItem::setup() updateItemStatic(); updateItem(); - m_updateTimer = new QTimer(this); - m_updateTimer->setSingleShot(false); - connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updateItem())); - m_updateTimer->start(1000); + mEventHandlerId = 0; + + rsEvents->registerEventsHandler( [this](std::shared_ptr e) + { + RsQThreadUtils::postToObject([=]() + { + updateItem(); + } + , this ); + }, mEventHandlerId, RsEventType::FRIEND_LIST ); } uint64_t SecurityIpItem::uniqueIdentifier() const diff --git a/retroshare-gui/src/gui/feeds/SecurityIpItem.h b/retroshare-gui/src/gui/feeds/SecurityIpItem.h index 58cfc4ff5..50c56ec5a 100644 --- a/retroshare-gui/src/gui/feeds/SecurityIpItem.h +++ b/retroshare-gui/src/gui/feeds/SecurityIpItem.h @@ -26,6 +26,8 @@ #include "FeedItem.h" #include +#include + namespace Ui { class SecurityIpItem; } @@ -44,6 +46,7 @@ public: void updateItemStatic(); uint64_t uniqueIdentifier() const override; + virtual ~SecurityIpItem(); protected: /* FeedItem */ @@ -66,7 +69,7 @@ private: std::string mIpAddrReported; uint32_t mResult; bool mIsTest; - QTimer *m_updateTimer; + RsEventsHandlerId_t mEventHandlerId; /** Qt Designer generated object */ Ui::SecurityIpItem *ui; diff --git a/retroshare-gui/src/gui/feeds/SecurityItem.cpp b/retroshare-gui/src/gui/feeds/SecurityItem.cpp index bec9d019f..4d21440a4 100644 --- a/retroshare-gui/src/gui/feeds/SecurityItem.cpp +++ b/retroshare-gui/src/gui/feeds/SecurityItem.cpp @@ -93,17 +93,13 @@ SecurityItem::SecurityItem(FeedHolder *parent, uint32_t feedId, const RsPgpId &g updateItemStatic(); updateItem(); - - m_updateTimer = new QTimer(this); - m_updateTimer->setSingleShot(false); - connect(m_updateTimer, &QTimer::timeout, this, &SecurityItem::updateItem); - m_updateTimer->start(1000); } SecurityItem::~SecurityItem() { rsEvents->unregisterEventsHandler(mEventHandlerId); } + uint64_t SecurityItem::uniqueIdentifier() const { return hash_64bits("SecurityItem " + QString::number((uint)mType).toStdString() + " " + mSslId.toStdString()); diff --git a/retroshare-gui/src/gui/feeds/SecurityItem.h b/retroshare-gui/src/gui/feeds/SecurityItem.h index 6f34af8fe..e2ba2b394 100644 --- a/retroshare-gui/src/gui/feeds/SecurityItem.h +++ b/retroshare-gui/src/gui/feeds/SecurityItem.h @@ -68,7 +68,6 @@ private: std::string mIP; RsFeedTypeFlags mType; bool mIsHome; - QTimer *m_updateTimer; RsEventsHandlerId_t mEventHandlerId; };