messagingapp/msgappfw/server/src/ccscontactsmanager.cpp
changeset 31 ebfee66fde93
parent 23 238255e8b033
child 37 518b245aa84c
equal deleted inserted replaced
30:6a20128ce557 31:ebfee66fde93
       
     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 "qtcontacts.h" 
       
    20 #include <QList>
       
    21 // User includes
       
    22 #include "ccscontactsmanager.h"
       
    23 #include "ccscontactsresolver.h"
       
    24 
       
    25 // ========================== Member Functions ===============================
       
    26 
       
    27 // ----------------------------------------------------------------------------
       
    28 // ContactsManager::ContactsManager
       
    29 // @see contactsmanager.h
       
    30 // ----------------------------------------------------------------------------
       
    31 CCsContactsManager::CCsContactsManager(QObject* parent):QObject(parent)
       
    32 {
       
    33     mPhonebookManager = new QContactManager("symbian");
       
    34 
       
    35     // Connect to QContactManager signals
       
    36     connect(mPhonebookManager, 
       
    37             SIGNAL(contactsAdded(const QList<QContactLocalId>&)), 
       
    38             this, 
       
    39             SLOT(handleContactsAdded(const QList<QContactLocalId>&)));
       
    40 
       
    41     connect(mPhonebookManager, 
       
    42             SIGNAL(contactsChanged(const QList<QContactLocalId>&)), 
       
    43             this, 
       
    44             SLOT(handleContactsChanged(const QList<QContactLocalId>&)));
       
    45 
       
    46     connect(mPhonebookManager, 
       
    47             SIGNAL(contactsRemoved(QList<QContactLocalId>)), 
       
    48             this, 
       
    49             SLOT(handleContactsRemoved(QList<QContactLocalId>)));
       
    50 
       
    51     mContactsResolver = new CCsContactsResolver(mPhonebookManager);
       
    52 }
       
    53 // ----------------------------------------------------------------------------
       
    54 // ContactsManager::~ContactsManager
       
    55 // @see contactsmanager.h
       
    56 // ----------------------------------------------------------------------------
       
    57 CCsContactsManager::~CCsContactsManager()
       
    58 {
       
    59     delete mContactsResolver;
       
    60     mContactsResolver = NULL;
       
    61     delete mPhonebookManager;
       
    62     mPhonebookManager = NULL;
       
    63     mObserverList.clear();
       
    64 }
       
    65 // ----------------------------------------------------------------------------
       
    66 // ContactsManager::resolver
       
    67 // @see contactsmanager.h
       
    68 // ----------------------------------------------------------------------------
       
    69 CCsContactsResolver* CCsContactsManager::resolver() const
       
    70 {
       
    71     return mContactsResolver;
       
    72 }
       
    73 
       
    74 // ----------------------------------------------------------------------------
       
    75 // ContactsManager::handleContactsAdded
       
    76 // @see contactsmanager.h
       
    77 // ----------------------------------------------------------------------------
       
    78 void CCsContactsManager::handleContactsAdded(
       
    79                                           const QList<QContactLocalId>& contactIds)
       
    80 {
       
    81     int contactsCount = contactIds.count();
       
    82     for (int i = 0; i < contactsCount; ++i)
       
    83     {
       
    84         CCsContactDetail detail;        
       
    85         mContactsResolver->resolveContactId(contactIds.at(i), detail);
       
    86                            
       
    87         //notify observers
       
    88         int count = mObserverList.count();
       
    89         for (int observerCount=0; observerCount < count; observerCount++)
       
    90         {
       
    91             MCsContactsManagerObserver* observer = mObserverList.at(observerCount);
       
    92             observer->HandleAddContact(detail);
       
    93         }            
       
    94     }
       
    95 }
       
    96 
       
    97 // ----------------------------------------------------------------------------
       
    98 // ContactsManager::handleContactsChanged
       
    99 // @see contactsmanager.h
       
   100 // ----------------------------------------------------------------------------
       
   101 void CCsContactsManager::handleContactsChanged(
       
   102                                             const QList<QContactLocalId>& contactIds)
       
   103 {
       
   104     int contactsCount = contactIds.count();
       
   105     for (int i = 0; i < contactsCount; ++i)
       
   106     {
       
   107         CCsContactDetail detail;
       
   108         mContactsResolver->resolveContactId(contactIds.at(i), detail);
       
   109         
       
   110         //notify observers
       
   111         int count = mObserverList.count();
       
   112         for (int observerCount=0; observerCount < count; observerCount++)
       
   113         {
       
   114             MCsContactsManagerObserver* observer = mObserverList.at(observerCount);
       
   115             observer->HandleContactChange(detail);
       
   116         }    
       
   117     }
       
   118 }
       
   119 
       
   120 // ----------------------------------------------------------------------------
       
   121 // ContactsManager::handleContactsRemoved
       
   122 // @see contactsmanager.h
       
   123 // ----------------------------------------------------------------------------
       
   124 void CCsContactsManager::handleContactsRemoved(const QList<QContactLocalId> &contactIds)
       
   125 {
       
   126     CCsContactDetail detail;
       
   127     int idCount = contactIds.count();
       
   128     for (int i = 0; i < idCount; i++)
       
   129     {
       
   130         detail.contactId = contactIds.value(i);
       
   131 
       
   132         //notify observers
       
   133         int count = mObserverList.count();
       
   134         for (int observerCount=0; observerCount < count; observerCount++)
       
   135         {
       
   136             MCsContactsManagerObserver* observer = mObserverList.at(observerCount);
       
   137             observer->HandleDeleteContact(detail);
       
   138         } 
       
   139     }
       
   140 
       
   141 }
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // CCsContactsManager::addObserver
       
   145 // Register for events.
       
   146 // ---------------------------------------------------------------------------
       
   147 void CCsContactsManager::addObserver(MCsContactsManagerObserver* aObserver)
       
   148 {
       
   149     mObserverList.append(aObserver);
       
   150 }
       
   151 
       
   152 // ---------------------------------------------------------------------------
       
   153 // CCsContactsManager::removeObserver
       
   154 // DeRegister for events.
       
   155 // ---------------------------------------------------------------------------
       
   156 void CCsContactsManager::removeObserver(MCsContactsManagerObserver* aObserver)
       
   157 {
       
   158     int index = mObserverList.indexOf(aObserver);
       
   159     if ( index >= 0)
       
   160     {
       
   161         mObserverList.removeAt(index);
       
   162     }
       
   163 }
       
   164 
       
   165 // EOF