messagingapp/msgappfw/server/src/ccscontactsmanager.cpp
branchRCL_3
changeset 57 ebe688cedc25
equal deleted inserted replaced
54:fa1df4b99609 57:ebe688cedc25
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:QT contact manager interface
       
    15  *
       
    16  */
       
    17 
       
    18 // System includes
       
    19 #include <QList>
       
    20 // User includes
       
    21 #include "ccscontactsmanager.h"
       
    22 #include "ccscontactsresolver.h"
       
    23 
       
    24 // ========================== Member Functions ===============================
       
    25 
       
    26 // ----------------------------------------------------------------------------
       
    27 // ContactsManager::ContactsManager
       
    28 // @see contactsmanager.h
       
    29 // ----------------------------------------------------------------------------
       
    30 CCsContactsManager::CCsContactsManager(QObject* parent):QObject(parent)
       
    31 {
       
    32     mPhonebookManager = new QContactManager("symbian");
       
    33 
       
    34     // Connect to QContactManager signals
       
    35     connect(mPhonebookManager, 
       
    36             SIGNAL(contactsAdded(const QList<QContactLocalId>&)), 
       
    37             this, 
       
    38             SLOT(handleContactsAdded(const QList<QContactLocalId>&)));
       
    39 
       
    40     connect(mPhonebookManager, 
       
    41             SIGNAL(contactsChanged(const QList<QContactLocalId>&)), 
       
    42             this, 
       
    43             SLOT(handleContactsChanged(const QList<QContactLocalId>&)));
       
    44 
       
    45     connect(mPhonebookManager, 
       
    46             SIGNAL(contactsRemoved(QList<QContactLocalId>)), 
       
    47             this, 
       
    48             SLOT(handleContactsRemoved(QList<QContactLocalId>)));
       
    49 
       
    50     mContactsResolver = new CCsContactsResolver(mPhonebookManager);
       
    51 }
       
    52 // ----------------------------------------------------------------------------
       
    53 // ContactsManager::~ContactsManager
       
    54 // @see contactsmanager.h
       
    55 // ----------------------------------------------------------------------------
       
    56 CCsContactsManager::~CCsContactsManager()
       
    57 {
       
    58     delete mContactsResolver;
       
    59     mContactsResolver = NULL;
       
    60     delete mPhonebookManager;
       
    61     mPhonebookManager = NULL;
       
    62     mObserverList.clear();
       
    63 }
       
    64 // ----------------------------------------------------------------------------
       
    65 // ContactsManager::resolver
       
    66 // @see contactsmanager.h
       
    67 // ----------------------------------------------------------------------------
       
    68 CCsContactsResolver* CCsContactsManager::resolver() const
       
    69 {
       
    70     return mContactsResolver;
       
    71 }
       
    72 
       
    73 // ----------------------------------------------------------------------------
       
    74 // ContactsManager::handleContactsAdded
       
    75 // @see contactsmanager.h
       
    76 // ----------------------------------------------------------------------------
       
    77 void CCsContactsManager::handleContactsAdded(
       
    78                                           const QList<QContactLocalId>& contactIds)
       
    79 {
       
    80     int contactsCount = contactIds.count();
       
    81     for (int i = 0; i < contactsCount; ++i)
       
    82     {
       
    83         CCsContactDetail detail;        
       
    84         mContactsResolver->resolveContactId(contactIds.at(i), detail);
       
    85                            
       
    86         //notify observers
       
    87         int count = mObserverList.count();
       
    88         for (int observerCount=0; observerCount < count; observerCount++)
       
    89         {
       
    90             MCsContactsManagerObserver* observer = mObserverList.at(observerCount);
       
    91             observer->HandleAddContact(detail);
       
    92         }            
       
    93     }
       
    94 }
       
    95 
       
    96 // ----------------------------------------------------------------------------
       
    97 // ContactsManager::handleContactsChanged
       
    98 // @see contactsmanager.h
       
    99 // ----------------------------------------------------------------------------
       
   100 void CCsContactsManager::handleContactsChanged(
       
   101                                             const QList<QContactLocalId>& contactIds)
       
   102 {
       
   103     int contactsCount = contactIds.count();
       
   104     for (int i = 0; i < contactsCount; ++i)
       
   105     {
       
   106         CCsContactDetail detail;
       
   107         mContactsResolver->resolveContactId(contactIds.at(i), detail);
       
   108         
       
   109         //notify observers
       
   110         int count = mObserverList.count();
       
   111         for (int observerCount=0; observerCount < count; observerCount++)
       
   112         {
       
   113             MCsContactsManagerObserver* observer = mObserverList.at(observerCount);
       
   114             observer->HandleContactChange(detail);
       
   115         }    
       
   116     }
       
   117 }
       
   118 
       
   119 // ----------------------------------------------------------------------------
       
   120 // ContactsManager::handleContactsRemoved
       
   121 // @see contactsmanager.h
       
   122 // ----------------------------------------------------------------------------
       
   123 void CCsContactsManager::handleContactsRemoved(const QList<QContactLocalId> &contactIds)
       
   124 {
       
   125     CCsContactDetail detail;
       
   126     int idCount = contactIds.count();
       
   127     for (int i = 0; i < idCount; i++)
       
   128     {
       
   129         detail.contactId = contactIds.value(i);
       
   130 
       
   131         //notify observers
       
   132         int count = mObserverList.count();
       
   133         for (int observerCount=0; observerCount < count; observerCount++)
       
   134         {
       
   135             MCsContactsManagerObserver* observer = mObserverList.at(observerCount);
       
   136             observer->HandleDeleteContact(detail);
       
   137         } 
       
   138     }
       
   139 
       
   140 }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // CCsContactsManager::addObserver
       
   144 // Register for events.
       
   145 // ---------------------------------------------------------------------------
       
   146 void CCsContactsManager::addObserver(MCsContactsManagerObserver* aObserver)
       
   147 {
       
   148     mObserverList.append(aObserver);
       
   149 }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // CCsContactsManager::removeObserver
       
   153 // DeRegister for events.
       
   154 // ---------------------------------------------------------------------------
       
   155 void CCsContactsManager::removeObserver(MCsContactsManagerObserver* aObserver)
       
   156 {
       
   157     int index = mObserverList.indexOf(aObserver);
       
   158     if ( index >= 0)
       
   159     {
       
   160         mObserverList.removeAt(index);
       
   161     }
       
   162 }
       
   163 
       
   164 // EOF