mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-08 06:08:12 -05:00
60a67846b0
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7428 b45a01b8-16f6-495d-af2f-9b41ad6348cc
70 lines
1.8 KiB
C++
70 lines
1.8 KiB
C++
//#include <QTimer>
|
|
#include <QMap>
|
|
|
|
#include "RsGxsUpdateBroadcast.h"
|
|
#include "RsProtectedTimer.h"
|
|
|
|
#include <retroshare/rsgxsifacehelper.h>
|
|
|
|
QMap<RsGxsIfaceHelper*, RsGxsUpdateBroadcast*> updateBroadcastMap;
|
|
|
|
RsGxsUpdateBroadcast::RsGxsUpdateBroadcast(RsGxsIfaceHelper *ifaceImpl) :
|
|
QObject(NULL), mIfaceImpl(ifaceImpl)
|
|
{
|
|
mTimer = new RsProtectedTimer(this);
|
|
mTimer->setInterval(1000);
|
|
mTimer->setSingleShot(true);
|
|
connect(mTimer, SIGNAL(timeout()), this, SLOT(poll()));
|
|
}
|
|
|
|
void RsGxsUpdateBroadcast::cleanup()
|
|
{
|
|
QMap<RsGxsIfaceHelper*, RsGxsUpdateBroadcast*>::iterator it;
|
|
for (it = updateBroadcastMap.begin(); it != updateBroadcastMap.end(); ++it) {
|
|
delete(it.value());
|
|
}
|
|
|
|
updateBroadcastMap.clear();
|
|
}
|
|
|
|
RsGxsUpdateBroadcast *RsGxsUpdateBroadcast::get(RsGxsIfaceHelper *ifaceImpl)
|
|
{
|
|
QMap<RsGxsIfaceHelper*, RsGxsUpdateBroadcast*>::iterator it = updateBroadcastMap.find(ifaceImpl);
|
|
if (it != updateBroadcastMap.end()) {
|
|
return it.value();
|
|
}
|
|
|
|
RsGxsUpdateBroadcast *updateBroadcast = new RsGxsUpdateBroadcast(ifaceImpl);
|
|
updateBroadcastMap.insert(ifaceImpl, updateBroadcast);
|
|
updateBroadcast->poll();
|
|
|
|
return updateBroadcast;
|
|
}
|
|
|
|
void RsGxsUpdateBroadcast::poll()
|
|
{
|
|
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > msgs;
|
|
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > msgsMeta;
|
|
std::list<RsGxsGroupId> grps;
|
|
std::list<RsGxsGroupId> grpsMeta;
|
|
|
|
if (mIfaceImpl->updated(true, true))
|
|
{
|
|
mIfaceImpl->msgsChanged(msgs, msgsMeta);
|
|
if (!msgs.empty() || !msgsMeta.empty())
|
|
{
|
|
emit msgsChanged(msgs, msgsMeta);
|
|
}
|
|
|
|
mIfaceImpl->groupsChanged(grps, grpsMeta);
|
|
if (!grps.empty() || !grpsMeta.empty())
|
|
{
|
|
emit grpsChanged(grps, grpsMeta);
|
|
}
|
|
|
|
emit changed();
|
|
}
|
|
|
|
mTimer->start();
|
|
}
|