Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
[libcontacts] Handle presence updates independently
qtcontacts-sqlite allows clients to handle presence change notifications
separately from other contact change notifications.
  • Loading branch information
matthewvogt committed Dec 10, 2013
1 parent 6d62371 commit e201832
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
36 changes: 32 additions & 4 deletions src/seasidecache.cpp
Expand Up @@ -33,8 +33,11 @@

#include "synchronizelists.h"

#include "qtcontacts-extensions_impl.h"
#include "qcontactstatusflags_impl.h"
#include <qtcontacts-extensions_impl.h>
#include <qcontactstatusflags_impl.h>
#include <contactmanagerengine.h>

#include <private/qcontactmanager_p.h>

#include <QCoreApplication>
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
Expand Down Expand Up @@ -98,15 +101,25 @@ QString managerName()
{
#ifdef USING_QTPIM
// Temporary override until qtpim supports QTCONTACTS_MANAGER_OVERRIDE
return QStringLiteral("org.nemomobile.contacts.sqlite");
return QString::fromLatin1("org.nemomobile.contacts.sqlite");
#endif
QByteArray environmentManager = qgetenv("NEMO_CONTACT_MANAGER");
return !environmentManager.isEmpty()
? QString::fromLatin1(environmentManager, environmentManager.length())
: QString();
}

Q_GLOBAL_STATIC_WITH_ARGS(QContactManager, manager, (managerName()))
QMap<QString, QString> managerParameters()
{
QMap<QString, QString> rv;
#ifdef USING_QTPIM
// Report presence changes independently from other contact changes
rv.insert(QString::fromLatin1("mergePresenceChanges"), QString::fromLatin1("false"));
#endif
return rv;
}

Q_GLOBAL_STATIC_WITH_ARGS(QContactManager, manager, (managerName(), managerParameters()))

typedef QList<DetailTypeId> DetailList;

Expand Down Expand Up @@ -514,12 +527,19 @@ SeasideCache::SeasideCache()

QContactManager *mgr(manager());

// The contactsPresenceChanged signal is not exported by QContactManager, so we
// need to find it from the manager's engine object
typedef QtContactsSqliteExtensions::ContactManagerEngine EngineType;
EngineType *cme = dynamic_cast<EngineType *>(QContactManagerData::managerData(mgr)->m_engine);

#ifdef USING_QTPIM
connect(mgr, SIGNAL(dataChanged()), this, SLOT(updateContacts()));
connect(mgr, SIGNAL(contactsAdded(QList<QContactId>)),
this, SLOT(contactsAdded(QList<QContactId>)));
connect(mgr, SIGNAL(contactsChanged(QList<QContactId>)),
this, SLOT(contactsChanged(QList<QContactId>)));
connect(cme, SIGNAL(contactsPresenceChanged(QList<QContactId>)),
this, SLOT(contactsPresenceChanged(QList<QContactId>)));
connect(mgr, SIGNAL(contactsRemoved(QList<QContactId>)),
this, SLOT(contactsRemoved(QList<QContactId>)));
#else
Expand All @@ -528,6 +548,8 @@ SeasideCache::SeasideCache()
this, SLOT(contactsAdded(QList<QContactLocalId>)));
connect(mgr, SIGNAL(contactsChanged(QList<QContactLocalId>)),
this, SLOT(contactsChanged(QList<QContactLocalId>)));
connect(cme, SIGNAL(contactsPresenceChanged(QList<QContactLocalId>)),
this, SLOT(contactsPresenceChanged(QList<QContactLocalId>)));
connect(mgr, SIGNAL(contactsRemoved(QList<QContactLocalId>)),
this, SLOT(contactsRemoved(QList<QContactLocalId>)));
#endif
Expand Down Expand Up @@ -1610,6 +1632,12 @@ void SeasideCache::contactsChanged(const QList<ContactIdType> &ids)
}
}

void SeasideCache::contactsPresenceChanged(const QList<ContactIdType> &ids)
{
// For now, treat presence change equivalently to other changes
contactsChanged(ids);
}

void SeasideCache::contactsRemoved(const QList<ContactIdType> &ids)
{
QList<ContactIdType> presentIds;
Expand Down
2 changes: 2 additions & 0 deletions src/seasidecache.h
Expand Up @@ -363,10 +363,12 @@ private slots:
#ifdef USING_QTPIM
void contactsAdded(const QList<QContactId> &contactIds);
void contactsChanged(const QList<QContactId> &contactIds);
void contactsPresenceChanged(const QList<QContactId> &contactIds);
void contactsRemoved(const QList<QContactId> &contactIds);
#else
void contactsAdded(const QList<QContactLocalId> &contactIds);
void contactsChanged(const QList<QContactLocalId> &contactIds);
void contactsPresenceChanged(const QList<QContactLocalId> &contactIds);
void contactsRemoved(const QList<QContactLocalId> &contactIds);
#endif
void displayLabelOrderChanged();
Expand Down
13 changes: 13 additions & 0 deletions src/src.pro
Expand Up @@ -36,6 +36,19 @@ equals(QT_MAJOR_VERSION, 5) {

DEFINES += CONTACTCACHE_BUILD

# We need access to QtContacts private headers
QT += contacts-private

# We need the moc output for ContactManagerEngine from sqlite-extensions
equals(QT_MAJOR_VERSION, 4) {
extensionsIncludePath = $$system(pkg-config --cflags-only-I qtcontacts-sqlite-extensions)
}
equals(QT_MAJOR_VERSION, 5) {
extensionsIncludePath = $$system(pkg-config --cflags-only-I qtcontacts-sqlite-qt5-extensions)
}
VPATH += $$replace(extensionsIncludePath, -I, )
HEADERS += contactmanagerengine.h

SOURCES += \
$$PWD/seasidecache.cpp \
$$PWD/seasideimport.cpp \
Expand Down

0 comments on commit e201832

Please sign in to comment.