messagingapp/msgappfw/server/src/ccscontactsresolver.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Mon, 04 Oct 2010 00:13:15 +0300
changeset 72 6f657153cbc5
parent 44 36f374c67aa8
child 47 5b14749788d7
permissions -rw-r--r--
Revision: 201037 Kit: 201039
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     1
/*
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     2
 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     3
 * All rights reserved.
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     8
 *
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     9
 * Initial Contributors:
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    11
 *
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    12
 * Contributors:
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    13
 *
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    14
 * Description: QT contact resolver interface
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    15
 *
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    16
 */
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    17
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    18
// SYSTEM INCLUDES
44
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    19
#include "qtcontacts.h"
31
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    20
#include "qcontactdetailfilter.h"
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    21
#include <QList>
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    22
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    23
// USER INCLUDES
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    24
#include "ccscontactsresolver.h"
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    25
// ======================== Member Functions ====================
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    26
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    27
// ----------------------------------------------------------------------------
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    28
// CCsContactsResolver::ContactsResolver
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    29
// @see contactsresolver.h
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    30
// ----------------------------------------------------------------------------
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    31
CCsContactsResolver::CCsContactsResolver(QContactManager* manager):
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    32
mPhonebookManager(manager)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    33
        {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    34
        // do nothing
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    35
        }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    36
// ----------------------------------------------------------------------------
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    37
// CCsContactsResolver::~ContactsResolver
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    38
// @see contactsresolver.h
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    39
// ----------------------------------------------------------------------------
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    40
CCsContactsResolver::~CCsContactsResolver()
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    41
    {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    42
    // do nothing
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    43
    }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    44
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    45
// ----------------------------------------------------------------------------
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    46
// CCsContactsResolver::resolveContact
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    47
// @see contactsresolver.h
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    48
// ----------------------------------------------------------------------------
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    49
bool CCsContactsResolver::resolveContact(
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    50
        const QString &address,
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    51
        CCsContactDetail &contactDetail)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    52
    {
44
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    53
    // apply filter on phone number field
31
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    54
    QContactDetailFilter phoneFilter;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    55
    phoneFilter.setDetailDefinitionName(
44
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    56
            QContactPhoneNumber::DefinitionName,
31
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    57
            QContactPhoneNumber::FieldNumber);
44
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    58
31
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    59
    phoneFilter.setValue(address);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    60
    phoneFilter.setMatchFlags(QContactFilter::MatchEndsWith);
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    61
    QList<QContact> matchingContacts = mPhonebookManager->contacts(phoneFilter);
44
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    62
    if ( matchingContacts.count() > 0 ) {
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    63
        QContact match = matchingContacts.at(0);
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    64
        // Fill the contact details
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    65
        contactDetail.contactId = match.localId();
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    66
        contactDetail.displayName = match.displayLabel();
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    67
        return true;
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    68
    }
31
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    69
44
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    70
    // apply filter on email address field
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    71
    QContactDetailFilter emailFilter;
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    72
    emailFilter.setDetailDefinitionName(
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    73
            QContactEmailAddress::DefinitionName,
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    74
            QContactEmailAddress::FieldEmailAddress);
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    75
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    76
    emailFilter.setValue(address);
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    77
    emailFilter.setMatchFlags(QContactFilter::MatchExactly);
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    78
    matchingContacts = mPhonebookManager->contacts(emailFilter);
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    79
    if ( matchingContacts.count() > 0 ) {
31
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    80
        QContact match = matchingContacts.at(0);
44
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    81
        // Fill the contact details
31
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    82
        contactDetail.contactId = match.localId();
44
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    83
        contactDetail.displayName = match.displayLabel();
31
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    84
        return true;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    85
    }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    86
    return false;
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    87
    }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    88
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    89
// ----------------------------------------------------------------------------
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    90
// CCsContactsResolver::resolveContactId
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    91
// @see contactsresolver.h
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    92
// ----------------------------------------------------------------------------
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    93
void CCsContactsResolver::resolveContactId(
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    94
        const quint32 &contactId,
44
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    95
        CCsContactDetail &contactDetail)
31
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    96
    {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    97
    // Fetch back the persisted contact
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    98
    QContact contact = mPhonebookManager->contact(contactId);
44
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
    99
    contactDetail.contactId = contact.localId();
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   100
31
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   101
    contactDetail.displayName = contact.displayLabel();
44
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   102
31
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   103
    QList<QContactPhoneNumber> numbers = contact.details<QContactPhoneNumber>();
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   104
    int numberCount = numbers.count();
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   105
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   106
    for ( int a=0; a<numberCount ;++a)
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   107
        {
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   108
        QString phoneNumber= numbers.at(a).number();
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   109
        contactDetail.addressList.append(phoneNumber);
44
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   110
        }
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   111
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   112
    QList<QContactEmailAddress> emailAddresses = contact.details<QContactEmailAddress>();
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   113
    int emailCount = emailAddresses.count();
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   114
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   115
    for ( int a=0; a<emailCount ;++a)
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   116
        {
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   117
        QString emailAddr= emailAddresses.at(a).emailAddress();
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   118
        contactDetail.addressList.append(emailAddr);
36f374c67aa8 Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 31
diff changeset
   119
        }
31
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   120
    }
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   121
ebfee66fde93 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   122
// EOF