mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-12-27 14:14:56 -05:00
remove singleShot calls and use events handlers instead
This commit is contained in:
parent
dfa9e39612
commit
692ee3face
6 changed files with 48 additions and 16 deletions
|
|
@ -36,6 +36,9 @@
|
|||
|
||||
#include "gui/msgs/MessageInterface.h"
|
||||
|
||||
#include "util/qtthreadsutils.h"
|
||||
#include <retroshare/rsevents.h>
|
||||
|
||||
/*****
|
||||
* #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<const RsEvent> e)
|
||||
{
|
||||
RsQThreadUtils::postToObject([=]()
|
||||
{
|
||||
auto fe = dynamic_cast<const RsFriendListEvent*>(e.get());
|
||||
|
||||
if(!fe || fe->mSslId != mPeerId)
|
||||
return;
|
||||
|
||||
updateItem();
|
||||
}
|
||||
, this );
|
||||
}, mEventHandlerId, RsEventType::FRIEND_LIST );
|
||||
}
|
||||
|
||||
ChatMsgItem::~ChatMsgItem()
|
||||
{
|
||||
rsEvents->unregisterEventsHandler(mEventHandlerId);
|
||||
}
|
||||
|
||||
void ChatMsgItem::updateItemStatic()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@
|
|||
#include <retroshare/rspeers.h>
|
||||
#include <retroshare/rsbanlist.h>
|
||||
|
||||
#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<const RsEvent> e)
|
||||
{
|
||||
RsQThreadUtils::postToObject([=]()
|
||||
{
|
||||
updateItem();
|
||||
}
|
||||
, this );
|
||||
}, mEventHandlerId, RsEventType::FRIEND_LIST );
|
||||
}
|
||||
|
||||
uint64_t SecurityIpItem::uniqueIdentifier() const
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@
|
|||
#include "FeedItem.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#include <retroshare/rsevents.h>
|
||||
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -68,7 +68,6 @@ private:
|
|||
std::string mIP;
|
||||
RsFeedTypeFlags mType;
|
||||
bool mIsHome;
|
||||
QTimer *m_updateTimer;
|
||||
|
||||
RsEventsHandlerId_t mEventHandlerId;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue