Commit 3e0f808b authored by mvogt's avatar mvogt

[libcontacts] Allow multiple listeners for any contact

parent 4ac0ef8a
......@@ -1227,7 +1227,6 @@ bool SeasideCache::event(QEvent *event)
QHash<quint32, CacheItem>::iterator cacheItem = m_people.find(iid);
if (cacheItem != m_people.end()) {
delete cacheItem->itemData;
delete cacheItem->modelData;
m_people.erase(cacheItem);
}
}
......@@ -1281,6 +1280,15 @@ void SeasideCache::contactsRemoved(const QList<ContactIdType> &ids)
foreach (ChangeListener *listener, m_changeListeners) {
listener->itemAboutToBeRemoved(item);
}
ItemListener *listener = item->listeners;
while (listener) {
ItemListener *next = listener->next;
listener->itemAboutToBeRemoved(item);
listener = next;
}
item->listeners = 0;
if (!m_keepPopulated) {
presentIds.append(id);
}
......@@ -1376,9 +1384,13 @@ void SeasideCache::updateCache(CacheItem *item, const QContact &contact, bool pa
}
item->statusFlags = contact.detail<QContactStatusFlags>().flagsValue();
if (item->modelData) {
item->modelData->contactChanged(contact, item->contactState);
ItemListener *listener = item->listeners;
while (listener) {
listener->itemUpdated(item);
listener = listener->next;
}
if (item->itemData) {
item->itemData->updateContact(contact, &item->contact, item->contactState);
} else {
......
......@@ -134,28 +134,60 @@ public:
virtual QList<int> constituents() const = 0;
};
struct ModelData
struct CacheItem;
struct ItemListener
{
virtual ~ModelData() {}
ItemListener() : next(0), key(0) {}
virtual ~ItemListener() {}
virtual void contactChanged(const QContact &newContact, ContactState state) = 0;
virtual void itemUpdated(CacheItem *item) = 0;
virtual void itemAboutToBeRemoved(CacheItem *item) = 0;
ItemListener *next;
void *key;
};
struct CacheItem
{
CacheItem() : itemData(0), modelData(0), iid(0), contactState(ContactAbsent) {}
CacheItem() : itemData(0), iid(0), contactState(ContactAbsent), listeners(0) {}
CacheItem(const QContact &contact)
: contact(contact), itemData(0), modelData(0), iid(internalId(contact)),
statusFlags(contact.detail<QContactStatusFlags>().flagsValue()), contactState(ContactAbsent) {}
: contact(contact), itemData(0), iid(internalId(contact)),
statusFlags(contact.detail<QContactStatusFlags>().flagsValue()), contactState(ContactAbsent), listeners(0) {}
ContactIdType apiId() const { return SeasideCache::apiId(contact); }
ItemListener *appendListener(ItemListener *listener, void *key)
{
if (listeners) {
ItemListener *existing(listeners);
while (existing->next) {
existing = existing->next;
}
existing->next = listener;
} else {
listeners = listener;
}
listener->next = 0;
listener->key = key;
return listener;
}
ItemListener *listener(void *key)
{
ItemListener *l(listeners);
while (l && (l->key != key) && (l->next)) {
l = l->next;
}
return (l && (l->key == key)) ? l : 0;
}
QContact contact;
ItemData *itemData;
ModelData *modelData;
quint32 iid;
quint64 statusFlags;
ContactState contactState;
ItemListener *listeners;
};
struct ContactLinkRequest
......
......@@ -10,7 +10,7 @@ target.path = $$PREFIX/lib
INSTALLS += target
# set version for generated pkgconfig files
VERSION=0.0.7
VERSION=0.0.9
QMAKE_PKGCONFIG_INCDIR = $$PREFIX/include/$${PACKAGENAME}
QMAKE_PKGCONFIG_LIBDIR = $$PREFIX/lib
QMAKE_PKGCONFIG_DESTDIR = pkgconfig
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment