phonebookengines/mobcntmodel/src/cntdefaultinfoprovider.cpp
changeset 37 fd64c38c277d
equal deleted inserted replaced
31:2a11b5b00470 37:fd64c38c277d
       
     1 /*
       
     2 * Copyright (c) 2010 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: Default info provider plugin for CntListModel. It can provide
       
    15 *              the phone number and the image url of a contact (text and
       
    16 *              icon1 field respectively).
       
    17 *
       
    18 */
       
    19 
       
    20 #include <qtcontacts.h>
       
    21 #include "cntdefaultinfoprovider.h"
       
    22 
       
    23 /*!
       
    24     /return the info fields supported by this provider
       
    25  */
       
    26 ContactInfoFields CntDefaultInfoProvider::supportedFields() const
       
    27 {
       
    28     // this provider does not have any info for the icon2 field
       
    29     return ContactInfoIcon1Field | ContactInfoTextField;
       
    30 }
       
    31 
       
    32 /*!
       
    33     The contact contains all the info this provider needs, so signals with the requested info
       
    34     fields are emitted immediately.
       
    35 
       
    36     /param contact the contact for which info is requested
       
    37     /param requestedInfo one or more of the flags in ContactInfoFields
       
    38  */
       
    39 void CntDefaultInfoProvider::requestInfo(const QContact& contact, ContactInfoFields requestedInfo)
       
    40 {
       
    41     if (requestedInfo & ContactInfoTextField) {
       
    42         QContactDetail detail = contact.preferredDetail("call");
       
    43         QString number;
       
    44         
       
    45         if (!detail.isEmpty())
       
    46         {
       
    47             number = static_cast<QContactPhoneNumber>(detail).number();
       
    48         }
       
    49         else
       
    50         {
       
    51             number = contact.detail<QContactPhoneNumber>().number();
       
    52         }
       
    53 
       
    54         if (!number.isEmpty()) {
       
    55             emit infoFieldReady(this, contact.localId(), ContactInfoTextField, number);
       
    56         }
       
    57     }
       
    58 
       
    59     if (requestedInfo & ContactInfoIcon1Field) {
       
    60         QString imageUrl = contact.detail<QContactAvatar>().imageUrl().toString();
       
    61         if (!imageUrl.isEmpty()) {
       
    62             emit infoFieldReady(this, contact.localId(), ContactInfoIcon1Field, imageUrl);
       
    63         }
       
    64     }
       
    65 }