2013-07-14 14:48:40 -04:00
|
|
|
//#include <QTimer>
|
|
|
|
#include <QMap>
|
2012-12-18 17:25:00 -05:00
|
|
|
|
|
|
|
#include "RsGxsUpdateBroadcast.h"
|
2013-07-14 14:48:40 -04:00
|
|
|
#include "RsProtectedTimer.h"
|
2012-12-18 17:25:00 -05:00
|
|
|
|
2013-07-14 14:48:40 -04:00
|
|
|
#include <retroshare/rsgxsifacehelper.h>
|
2012-12-18 17:25:00 -05:00
|
|
|
|
2013-07-14 14:48:40 -04:00
|
|
|
QMap<RsGxsIfaceHelper*, RsGxsUpdateBroadcast*> updateBroadcastMap;
|
|
|
|
|
|
|
|
RsGxsUpdateBroadcast::RsGxsUpdateBroadcast(RsGxsIfaceHelper *ifaceImpl) :
|
|
|
|
QObject(NULL), mIfaceImpl(ifaceImpl)
|
2012-12-18 17:25:00 -05:00
|
|
|
{
|
2013-07-14 14:48:40 -04:00
|
|
|
mTimer = new RsProtectedTimer(this);
|
|
|
|
mTimer->setInterval(1000);
|
|
|
|
mTimer->setSingleShot(true);
|
|
|
|
connect(mTimer, SIGNAL(timeout()), this, SLOT(poll()));
|
2012-12-18 17:25:00 -05:00
|
|
|
}
|
|
|
|
|
2013-07-14 14:48:40 -04:00
|
|
|
void RsGxsUpdateBroadcast::cleanup()
|
2012-12-18 17:25:00 -05:00
|
|
|
{
|
2013-07-14 14:48:40 -04:00
|
|
|
QMap<RsGxsIfaceHelper*, RsGxsUpdateBroadcast*>::iterator it;
|
|
|
|
for (it = updateBroadcastMap.begin(); it != updateBroadcastMap.end(); ++it) {
|
|
|
|
delete(it.value());
|
|
|
|
}
|
2012-12-18 17:25:00 -05:00
|
|
|
|
2013-07-14 14:48:40 -04:00
|
|
|
updateBroadcastMap.clear();
|
|
|
|
}
|
2012-12-18 17:25:00 -05:00
|
|
|
|
2013-07-14 14:48:40 -04:00
|
|
|
RsGxsUpdateBroadcast *RsGxsUpdateBroadcast::get(RsGxsIfaceHelper *ifaceImpl)
|
2012-12-18 17:25:00 -05:00
|
|
|
{
|
2013-07-14 14:48:40 -04:00
|
|
|
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();
|
2012-12-18 17:25:00 -05:00
|
|
|
|
2013-07-14 14:48:40 -04:00
|
|
|
return updateBroadcast;
|
2012-12-18 17:25:00 -05:00
|
|
|
}
|
|
|
|
|
2013-07-14 14:48:40 -04:00
|
|
|
void RsGxsUpdateBroadcast::poll()
|
2012-12-18 17:25:00 -05:00
|
|
|
{
|
2013-07-14 14:48:40 -04:00
|
|
|
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > msgs;
|
2014-07-04 17:51:17 -04:00
|
|
|
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > msgsMeta;
|
2013-07-14 14:48:40 -04:00
|
|
|
std::list<RsGxsGroupId> grps;
|
2014-07-04 17:51:17 -04:00
|
|
|
std::list<RsGxsGroupId> grpsMeta;
|
2013-07-14 14:48:40 -04:00
|
|
|
|
|
|
|
if (mIfaceImpl->updated(true, true))
|
|
|
|
{
|
2014-07-04 17:51:17 -04:00
|
|
|
mIfaceImpl->msgsChanged(msgs, msgsMeta);
|
|
|
|
if (!msgs.empty() || !msgsMeta.empty())
|
2013-07-14 14:48:40 -04:00
|
|
|
{
|
2014-07-04 17:51:17 -04:00
|
|
|
emit msgsChanged(msgs, msgsMeta);
|
2013-07-14 14:48:40 -04:00
|
|
|
}
|
|
|
|
|
2014-07-04 17:51:17 -04:00
|
|
|
mIfaceImpl->groupsChanged(grps, grpsMeta);
|
|
|
|
if (!grps.empty() || !grpsMeta.empty())
|
2013-07-14 14:48:40 -04:00
|
|
|
{
|
2014-07-04 17:51:17 -04:00
|
|
|
emit grpsChanged(grps, grpsMeta);
|
2013-07-14 14:48:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
emit changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
mTimer->start();
|
2012-12-18 17:25:00 -05:00
|
|
|
}
|