#include "commmanager.h" using namespace CommHistory; CommManager::CommManager(StorageManager *storage, ToqManager *toq) : QObject(toq), _toq(toq), _storage(storage), _calls(new CallModel(this)), _convs(new GroupModel(this)), _refreshTimer(new QTimer(this)) { _calls->setTreeMode(false); _calls->setQueryMode(EventModel::AsyncQuery); _calls->setSorting(CallModel::SortByTime); _calls->setResolveContacts(true); _calls->setLimit(20); _convs->setQueryMode(EventModel::AsyncQuery); _convs->setLimit(20); _refreshTimer->setSingleShot(true); _refreshTimer->setInterval(1000); connect(_calls, SIGNAL(modelReady(bool)), this, SLOT(scheduleRefresh())); connect(_calls, SIGNAL(modelReset()), this, SLOT(scheduleRefresh())); connect(_calls, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(scheduleRefresh())); connect(_calls, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(scheduleRefresh())); connect(_convs, SIGNAL(modelReady(bool)), this, SLOT(scheduleRefresh())); connect(_refreshTimer, &QTimer::timeout, this, &CommManager::refresh); if (!_calls->getEvents()) { qWarning() << "Could not get the call log"; } if (!_convs->getGroups()) { qWarning() << "Could not get conversation groups"; } } void CommManager::scheduleRefresh() { if (!_refreshTimer->isActive()) { _refreshTimer->start(); } } void CommManager::refresh() { qDebug() << "refreshing now"; QMultiMap events; int rows = _calls->rowCount(); for (int i = 0; i < rows; i++) { Event e = _calls->event(i); qDebug() << "Got call" << e.toString(); QDateTime dt = e.startTime(); QJsonObject obj; obj.insert("CommsType", QLatin1String("Call")); obj.insert("ReceivedTime", qint64(dt.toTime_t())); obj.insert("CallerId", e.contactName()); obj.insert("ItemId", e.id()); QJsonObject details; details.insert("Duration", e.startTime().secsTo(e.endTime())); details.insert("PhoneType", QLatin1String("Other")); // TODO switch (e.direction()) { case Event::Inbound: details.insert("Direction", QLatin1String("Incoming")); break; case Event::Outbound: details.insert("Direction", QLatin1String("Outgoing")); break; default: details.insert("Direction", QLatin1String("Unknown")); break; } details.insert("IsMissedCall", e.isMissedCall()); obj.insert("CommsDetails", details); events.insert(dt, obj); } rows = _convs->rowCount(); for (int i = 0; i < rows; i++) { Group g = _convs->group(_convs->index(i, 0)); qDebug() << "Chat" << g.contactName(); } }