Skip to content

Commit aa99fa9

Browse files
authored
Merge pull request RetroShare#3072 from jolavillette/RemoveRecursiveSingleShotCalls
Remove recursive singleShot calls on feed items
2 parents 73db13b + 6d3f44d commit aa99fa9

6 files changed

Lines changed: 57 additions & 18 deletions

File tree

retroshare-gui/src/gui/feeds/ChatMsgItem.cpp

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636

3737
#include "gui/msgs/MessageInterface.h"
3838

39+
#include "util/qtthreadsutils.h"
40+
#include "retroshare/rsevents.h"
41+
3942
/*****
4043
* #define DEBUG_ITEM 1
4144
****/
@@ -67,6 +70,27 @@ ChatMsgItem::ChatMsgItem(FeedHolder *parent, uint32_t feedId, const RsPeerId &pe
6770
updateItemStatic();
6871
updateItem();
6972
insertChat(message);
73+
74+
mEventHandlerId = 0;
75+
76+
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e)
77+
{
78+
RsQThreadUtils::postToObject([=]()
79+
{
80+
auto fe = dynamic_cast<const RsFriendListEvent*>(e.get());
81+
82+
if(!fe || fe->mSslId != mPeerId)
83+
return;
84+
85+
updateItem();
86+
}
87+
, this );
88+
}, mEventHandlerId, RsEventType::FRIEND_LIST );
89+
}
90+
91+
ChatMsgItem::~ChatMsgItem()
92+
{
93+
rsEvents->unregisterEventsHandler(mEventHandlerId);
7094
}
7195

7296
void ChatMsgItem::updateItemStatic()
@@ -122,11 +146,6 @@ void ChatMsgItem::updateItem()
122146
msgButton->setEnabled(false);
123147
}
124148
}
125-
126-
/* slow Tick */
127-
int msec_rate = 10129;
128-
129-
QTimer::singleShot( msec_rate, this, SLOT(updateItem( void ) ));
130149
return;
131150
}
132151

retroshare-gui/src/gui/feeds/ChatMsgItem.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class ChatMsgItem : public FeedItem, private Ui::ChatMsgItem
3535
/** Default Constructor */
3636
ChatMsgItem(FeedHolder *parent, uint32_t feedId, const RsPeerId &peerId, const std::string &message);
3737

38+
virtual ~ChatMsgItem();
39+
3840
void updateItemStatic();
3941

4042
virtual uint64_t uniqueIdentifier() const override { return hash_64bits("ChatMsgItem " + mPeerId.toStdString()); }
@@ -60,6 +62,7 @@ private slots:
6062
void insertChat(const std::string &message);
6163

6264
RsPeerId mPeerId;
65+
RsEventsHandlerId_t mEventHandlerId;
6366
};
6467

6568
#endif

retroshare-gui/src/gui/feeds/SecurityIpItem.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#include <retroshare/rspeers.h>
3535
#include <retroshare/rsbanlist.h>
3636

37+
#include "util/qtthreadsutils.h"
38+
3739
/*****
3840
* #define DEBUG_ITEM 1
3941
****/
@@ -53,6 +55,11 @@ SecurityIpItem::SecurityIpItem(FeedHolder *parent, const RsPeerId &sslId, const
5355
setup();
5456
}
5557

58+
SecurityIpItem::~SecurityIpItem()
59+
{
60+
rsEvents->unregisterEventsHandler(mEventHandlerId);
61+
}
62+
5663
void SecurityIpItem::setup()
5764
{
5865
/* Invoke the Qt Designer generated object setup routine */
@@ -76,6 +83,21 @@ void SecurityIpItem::setup()
7683

7784
updateItemStatic();
7885
updateItem();
86+
87+
mEventHandlerId = 0;
88+
89+
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e)
90+
{
91+
RsQThreadUtils::postToObject([=]()
92+
{
93+
// Filter events to only update relevant items.
94+
auto fe = dynamic_cast<const RsFriendListEvent*>(e.get());
95+
if(!fe || fe->mSslId != mSslId)
96+
return;
97+
updateItem();
98+
}
99+
, this );
100+
}, mEventHandlerId, RsEventType::FRIEND_LIST );
79101
}
80102

81103
uint64_t SecurityIpItem::uniqueIdentifier() const
@@ -178,11 +200,6 @@ void SecurityIpItem::updateItem()
178200
ui->peerDetailsButton->setEnabled(true);
179201
}
180202
}
181-
182-
/* slow Tick */
183-
int msec_rate = 10129;
184-
185-
QTimer::singleShot( msec_rate, this, SLOT(updateItem(void)));
186203
}
187204

188205
void SecurityIpItem::toggle()

retroshare-gui/src/gui/feeds/SecurityIpItem.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121
#ifndef _SECURITYIPITEM_H
2222
#define _SECURITYIPITEM_H
2323

24-
#include "retroshare/rstypes.h"
24+
#include <stdint.h>
2525

26+
#include "retroshare/rstypes.h"
27+
#include "retroshare/rsevents.h"
2628
#include "FeedItem.h"
27-
#include <stdint.h>
2829

2930
namespace Ui {
3031
class SecurityIpItem;
@@ -44,6 +45,7 @@ class SecurityIpItem : public FeedItem
4445
void updateItemStatic();
4546

4647
uint64_t uniqueIdentifier() const override;
48+
virtual ~SecurityIpItem();
4749

4850
protected:
4951
/* FeedItem */
@@ -60,12 +62,13 @@ private slots:
6062
void banIpListChanged(const QString &ipAddress);
6163

6264
private:
63-
RsFeedTypeFlags mType;
65+
RsFeedTypeFlags mType;
6466
RsPeerId mSslId;
6567
std::string mIpAddr;
6668
std::string mIpAddrReported;
6769
uint32_t mResult;
6870
bool mIsTest;
71+
RsEventsHandlerId_t mEventHandlerId;
6972

7073
/** Qt Designer generated object */
7174
Ui::SecurityIpItem *ui;

retroshare-gui/src/gui/feeds/SecurityItem.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ SecurityItem::~SecurityItem()
9999
{
100100
rsEvents->unregisterEventsHandler(mEventHandlerId);
101101
}
102+
102103
uint64_t SecurityItem::uniqueIdentifier() const
103104
{
104105
return hash_64bits("SecurityItem " + QString::number((uint)mType).toStdString() + " " + mSslId.toStdString());
@@ -303,10 +304,6 @@ void SecurityItem::updateItem()
303304
//quickmsgButton->show();
304305
}
305306

306-
/* slow Tick */
307-
int msec_rate = 10129;
308-
309-
QTimer::singleShot( msec_rate, this, SLOT(updateItem( void ) ));
310307
return;
311308
}
312309

retroshare-gui/src/gui/feeds/SecurityItem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private slots:
6666
RsPeerId mSslId;
6767
std::string mSslCn;
6868
std::string mIP;
69-
RsFeedTypeFlags mType;
69+
RsFeedTypeFlags mType;
7070
bool mIsHome;
7171

7272
RsEventsHandlerId_t mEventHandlerId;

0 commit comments

Comments
 (0)