phonebookui/phonebookservices/src/cntservicecontactfetchview.cpp
changeset 24 0ba2181d7c28
child 25 76a2435edfd4
equal deleted inserted replaced
0:e686773b3f54 24:0ba2181d7c28
       
     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:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "cntservicecontactfetchview.h"
       
    19 
       
    20 #include "cntservicescontact.h"
       
    21 #include "cntservicehandler.h"
       
    22 
       
    23 #include <hbmenu.h>
       
    24 
       
    25 CntServiceContactFetchView::CntServiceContactFetchView(CntServiceHandler *aServiceHandler, CntViewManager *aViewManager, QGraphicsItem *aParent):
       
    26     CntBaseSelectionView(aViewManager,aParent),
       
    27     mServiceHandler(aServiceHandler)
       
    28 {
       
    29 
       
    30 }
       
    31 
       
    32 CntServiceContactFetchView::~CntServiceContactFetchView()
       
    33 {
       
    34 }
       
    35 
       
    36 void CntServiceContactFetchView::addMenuItems()
       
    37 {
       
    38     actions()->clearActionList();
       
    39     actions()->actionList() << actions()->baseAction("cnt:cancel");
       
    40     actions()->addActionsToMenu(menu());
       
    41     
       
    42     connect(actions()->baseAction("cnt:cancel"), SIGNAL(triggered()),
       
    43             this, SLOT (cancelFetch()));
       
    44 }
       
    45 
       
    46 void CntServiceContactFetchView::cancelFetch()
       
    47 {
       
    48     connect(mServiceHandler, SIGNAL(returnValueDelivered()), qApp, SLOT(quit()));
       
    49     CntServicesContactList serviceList;
       
    50     mServiceHandler->completeFetch(serviceList);
       
    51 }
       
    52 
       
    53 void CntServiceContactFetchView::aboutToCloseView()
       
    54 {
       
    55     CntServicesContactList serviceList;
       
    56     QModelIndexList temp = selectionModel()->selection().indexes();
       
    57     for(int i = 0; i < temp.count(); i++ )
       
    58     {
       
    59         QContact contact = contactModel()->contact(temp.at(i));
       
    60         CntServicesContact servicesContact;
       
    61 
       
    62         //get the name
       
    63         servicesContact.mDisplayName = contactManager()->synthesizeDisplayLabel(contact);
       
    64 
       
    65         //get the phonenumber
       
    66         QList<QContactPhoneNumber> phonenumbers = contact.details<QContactPhoneNumber>();
       
    67         if(phonenumbers.count() > 0)
       
    68         {
       
    69             servicesContact.mPhoneNumber = phonenumbers.first().number();
       
    70         }
       
    71         else
       
    72         {
       
    73             servicesContact.mPhoneNumber = "";
       
    74         }
       
    75 
       
    76         //get first email address
       
    77         QList<QContactEmailAddress> emailAddresses = contact.details<QContactEmailAddress>();
       
    78         if(emailAddresses.count() > 0)
       
    79         {
       
    80             servicesContact.mEmailAddress = emailAddresses.first().emailAddress();
       
    81         }
       
    82         //contact id
       
    83         servicesContact.mContactId = contact.localId();
       
    84 
       
    85         //append it to the list
       
    86         serviceList.append(servicesContact);
       
    87     }
       
    88 
       
    89     connect(mServiceHandler, SIGNAL(returnValueDelivered()), qApp, SLOT(quit()));
       
    90     mServiceHandler->completeFetch(serviceList);
       
    91 }
       
    92 
       
    93 
       
    94 void CntServiceContactFetchView::setActionFilter(QString action, QString filter)
       
    95 {
       
    96     Q_UNUSED(filter);
       
    97     
       
    98     if (action == KCntActionSms)
       
    99     {
       
   100         QContactActionFilter actionFilter;
       
   101         actionFilter.setActionName("message");
       
   102         contactModel()->setFilterAndSortOrder(actionFilter);
       
   103     }
       
   104     else if (action == KCntActionCall)
       
   105     {
       
   106         QContactActionFilter actionFilter;
       
   107         actionFilter.setActionName("call");
       
   108         contactModel()->setFilterAndSortOrder(actionFilter);
       
   109     }
       
   110     else if (action == KCntActionEmail)
       
   111     {
       
   112         QContactActionFilter actionFilter;
       
   113         actionFilter.setActionName("email");
       
   114         contactModel()->setFilterAndSortOrder(actionFilter);
       
   115     }
       
   116     else
       
   117     {
       
   118         QContactDetailFilter filter;
       
   119         filter.setDetailDefinitionName(QContactType::DefinitionName, QContactType::FieldType);
       
   120         QString typeContact = QContactType::TypeContact;
       
   121         filter.setValue(typeContact);
       
   122         contactModel()->setFilterAndSortOrder(filter);
       
   123     }
       
   124 
       
   125     // hide my card if it's not set
       
   126     if (contactManager()->selfContactId() == 0)
       
   127     {
       
   128         contactModel()->showMyCard(false);
       
   129     }
       
   130 }
       
   131 
       
   132 // EOF