messagingapp/msgappfw/server/src/ccscontactsresolver.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Mon, 03 May 2010 12:29:07 +0300
changeset 25 84d9eb65b26f
parent 23 238255e8b033
child 27 e4592d119491
child 37 518b245aa84c
permissions -rw-r--r--
Revision: 201015 Kit: 201018

/*
 * 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 resolver interface
 *
 */

// SYSTEM INCLUDES
#include "qtcontacts.h" 
#include "qcontactdetailfilter.h"
#include <QList>

// USER INCLUDES
#include "ccscontactsresolver.h"
// ======================== Member Functions ====================

// ----------------------------------------------------------------------------
// CCsContactsResolver::ContactsResolver
// @see contactsresolver.h
// ----------------------------------------------------------------------------
CCsContactsResolver::CCsContactsResolver(QContactManager* manager):
mPhonebookManager(manager)
        {
        // do nothing
        }
// ----------------------------------------------------------------------------
// CCsContactsResolver::~ContactsResolver
// @see contactsresolver.h
// ----------------------------------------------------------------------------
CCsContactsResolver::~CCsContactsResolver()
    {
    // do nothing
    }

// ----------------------------------------------------------------------------
// CCsContactsResolver::resolveContact
// @see contactsresolver.h
// ----------------------------------------------------------------------------
bool CCsContactsResolver::resolveContact(
        const QString &address,
        CCsContactDetail &contactDetail)
    {
    QContactDetailFilter phoneFilter;
    phoneFilter.setDetailDefinitionName(
            QContactPhoneNumber::DefinitionName, 
            QContactPhoneNumber::FieldNumber);
    
    phoneFilter.setValue(address);
    phoneFilter.setMatchFlags(QContactFilter::MatchEndsWith);

    QList<QContactSortOrder> sortOrder;
    QList<QContact> matchingContacts = mPhonebookManager->contacts(
                                                phoneFilter,
                                                sortOrder,
                                                QStringList());

    if ( matchingContacts.count() > 0 ) {	        
        QContact match = matchingContacts.at(0);
        // Fill the contact details        
        contactDetail.contactId = match.localId();
        contactDetail.displayName = match.displayLabel();   
        return true;
    }
    return false;
    }

// ----------------------------------------------------------------------------
// CCsContactsResolver::resolveContactId
// @see contactsresolver.h
// ----------------------------------------------------------------------------
void CCsContactsResolver::resolveContactId(
        const quint32 &contactId,
        CCsContactDetail &contactDetail)	
    {
    // Fetch back the persisted contact
    QContact contact = mPhonebookManager->contact(contactId);
    contactDetail.contactId = contact.localId(); 
    
    contactDetail.displayName = contact.displayLabel();
        
    QList<QContactPhoneNumber> numbers = contact.details<QContactPhoneNumber>();
    int numberCount = numbers.count();

    for ( int a=0; a<numberCount ;++a)
        {
        QString phoneNumber= numbers.at(a).number();
        contactDetail.addressList.append(phoneNumber);
        }    
    }

// EOF