diff -r 6a20128ce557 -r ebfee66fde93 messagingapp/msgappfw/server/src/ccscontactsmanager.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/messagingapp/msgappfw/server/src/ccscontactsmanager.cpp Fri Jun 04 10:25:39 2010 +0100 @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of "Eclipse Public License v1.0" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Nokia Corporation - initial contribution. + * + * Contributors: + * + * Description:QT contact manager interface + * + */ + +// System includes +#include "qtcontacts.h" +#include +// User includes +#include "ccscontactsmanager.h" +#include "ccscontactsresolver.h" + +// ========================== Member Functions =============================== + +// ---------------------------------------------------------------------------- +// ContactsManager::ContactsManager +// @see contactsmanager.h +// ---------------------------------------------------------------------------- +CCsContactsManager::CCsContactsManager(QObject* parent):QObject(parent) +{ + mPhonebookManager = new QContactManager("symbian"); + + // Connect to QContactManager signals + connect(mPhonebookManager, + SIGNAL(contactsAdded(const QList&)), + this, + SLOT(handleContactsAdded(const QList&))); + + connect(mPhonebookManager, + SIGNAL(contactsChanged(const QList&)), + this, + SLOT(handleContactsChanged(const QList&))); + + connect(mPhonebookManager, + SIGNAL(contactsRemoved(QList)), + this, + SLOT(handleContactsRemoved(QList))); + + mContactsResolver = new CCsContactsResolver(mPhonebookManager); +} +// ---------------------------------------------------------------------------- +// ContactsManager::~ContactsManager +// @see contactsmanager.h +// ---------------------------------------------------------------------------- +CCsContactsManager::~CCsContactsManager() +{ + delete mContactsResolver; + mContactsResolver = NULL; + delete mPhonebookManager; + mPhonebookManager = NULL; + mObserverList.clear(); +} +// ---------------------------------------------------------------------------- +// ContactsManager::resolver +// @see contactsmanager.h +// ---------------------------------------------------------------------------- +CCsContactsResolver* CCsContactsManager::resolver() const +{ + return mContactsResolver; +} + +// ---------------------------------------------------------------------------- +// ContactsManager::handleContactsAdded +// @see contactsmanager.h +// ---------------------------------------------------------------------------- +void CCsContactsManager::handleContactsAdded( + const QList& contactIds) +{ + int contactsCount = contactIds.count(); + for (int i = 0; i < contactsCount; ++i) + { + CCsContactDetail detail; + mContactsResolver->resolveContactId(contactIds.at(i), detail); + + //notify observers + int count = mObserverList.count(); + for (int observerCount=0; observerCount < count; observerCount++) + { + MCsContactsManagerObserver* observer = mObserverList.at(observerCount); + observer->HandleAddContact(detail); + } + } +} + +// ---------------------------------------------------------------------------- +// ContactsManager::handleContactsChanged +// @see contactsmanager.h +// ---------------------------------------------------------------------------- +void CCsContactsManager::handleContactsChanged( + const QList& contactIds) +{ + int contactsCount = contactIds.count(); + for (int i = 0; i < contactsCount; ++i) + { + CCsContactDetail detail; + mContactsResolver->resolveContactId(contactIds.at(i), detail); + + //notify observers + int count = mObserverList.count(); + for (int observerCount=0; observerCount < count; observerCount++) + { + MCsContactsManagerObserver* observer = mObserverList.at(observerCount); + observer->HandleContactChange(detail); + } + } +} + +// ---------------------------------------------------------------------------- +// ContactsManager::handleContactsRemoved +// @see contactsmanager.h +// ---------------------------------------------------------------------------- +void CCsContactsManager::handleContactsRemoved(const QList &contactIds) +{ + CCsContactDetail detail; + int idCount = contactIds.count(); + for (int i = 0; i < idCount; i++) + { + detail.contactId = contactIds.value(i); + + //notify observers + int count = mObserverList.count(); + for (int observerCount=0; observerCount < count; observerCount++) + { + MCsContactsManagerObserver* observer = mObserverList.at(observerCount); + observer->HandleDeleteContact(detail); + } + } + +} + +// --------------------------------------------------------------------------- +// CCsContactsManager::addObserver +// Register for events. +// --------------------------------------------------------------------------- +void CCsContactsManager::addObserver(MCsContactsManagerObserver* aObserver) +{ + mObserverList.append(aObserver); +} + +// --------------------------------------------------------------------------- +// CCsContactsManager::removeObserver +// DeRegister for events. +// --------------------------------------------------------------------------- +void CCsContactsManager::removeObserver(MCsContactsManagerObserver* aObserver) +{ + int index = mObserverList.indexOf(aObserver); + if ( index >= 0) + { + mObserverList.removeAt(index); + } +} + +// EOF