2013-07-14 14:48:40 -04:00
|
|
|
#include <QMap>
|
2012-12-18 17:25:00 -05:00
|
|
|
|
|
|
|
#include "RsGxsUpdateBroadcast.h"
|
2015-03-20 06:39:17 -04:00
|
|
|
#include "gui/notifyqt.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
|
|
|
|
2015-03-20 06:39:17 -04:00
|
|
|
// previously gxs allowed only one event consumer to poll for changes
|
|
|
|
// this required a single broadcast instance per service
|
|
|
|
// now the update notify works through rsnotify and notifyqt
|
|
|
|
// so the single instance per service is not really needed anymore
|
|
|
|
|
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
|
|
|
{
|
2015-03-20 06:39:17 -04:00
|
|
|
connect(NotifyQt::getInstance(), SIGNAL(gxsChange(RsGxsChanges)), this, SLOT(onChangesReceived(RsGxsChanges)));
|
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);
|
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
|
|
|
}
|
|
|
|
|
2015-03-20 06:39:17 -04:00
|
|
|
void RsGxsUpdateBroadcast::onChangesReceived(const RsGxsChanges& changes)
|
2012-12-18 17:25:00 -05:00
|
|
|
{
|
2016-03-16 23:30:23 -04:00
|
|
|
std::cerr << "onChangesReceived()" << std::endl;
|
|
|
|
|
2015-03-20 06:39:17 -04:00
|
|
|
if(changes.mService != mIfaceImpl->getTokenService())
|
|
|
|
return;
|
2013-07-14 14:48:40 -04:00
|
|
|
|
2015-03-20 06:39:17 -04:00
|
|
|
if (!changes.mMsgs.empty() || !changes.mMsgsMeta.empty())
|
|
|
|
{
|
|
|
|
emit msgsChanged(changes.mMsgs, changes.mMsgsMeta);
|
|
|
|
}
|
2013-07-14 14:48:40 -04:00
|
|
|
|
2015-03-20 06:39:17 -04:00
|
|
|
if (!changes.mGrps.empty() || !changes.mGrpsMeta.empty())
|
|
|
|
{
|
|
|
|
emit grpsChanged(changes.mGrps, changes.mGrpsMeta);
|
|
|
|
}
|
2013-07-14 14:48:40 -04:00
|
|
|
|
2015-03-20 06:39:17 -04:00
|
|
|
emit changed();
|
2012-12-18 17:25:00 -05:00
|
|
|
}
|