phonebookui/phonebookservices/src/cntservicehandler.cpp
changeset 24 0ba2181d7c28
child 27 de1630741fbe
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 "cntservicehandler.h"
       
    19 
       
    20 /* NOTE! THIS SERVICE WILL BE RENAMED TO com.nokia.services.phonebook.Services */
       
    21 CntServiceHandler::CntServiceHandler(QObject *parent):
       
    22     XQServiceProvider(QLatin1String("com.nokia.services.phonebookservices.Fetch"), parent),
       
    23     mCurrentRequestIndex(0)
       
    24 {
       
    25     publishAll();
       
    26 }
       
    27 
       
    28 CntServiceHandler::~CntServiceHandler()
       
    29 {
       
    30 }
       
    31 
       
    32 /*
       
    33 Complete the fetch and return the list selected contacts
       
    34 */
       
    35 void CntServiceHandler::completeFetch( const CntServicesContactList &contactList )
       
    36 {
       
    37     QVariant retValue;
       
    38     retValue.setValue(contactList);
       
    39     completeRequest(mCurrentRequestIndex, retValue);
       
    40     mCurrentRequestIndex = 0;
       
    41 }
       
    42 
       
    43 /*
       
    44 Complete edit and return if contact wasn't modified (-2), was deleted (-1), saved (1) or if saving failed (0)
       
    45 */
       
    46 void CntServiceHandler::completeEdit(int result)
       
    47 {
       
    48     QVariant retValue(result);
       
    49     completeRequest(mCurrentRequestIndex, retValue);
       
    50     mCurrentRequestIndex = 0;
       
    51 }
       
    52 
       
    53 /*
       
    54 Launch fetch service with given parameters
       
    55 */
       
    56 void CntServiceHandler::fetch(const QString &title, const QString &action, const QString &filter)
       
    57 {
       
    58     emit launchFetch(title, action, filter);
       
    59 
       
    60     mCurrentRequestIndex = setCurrentRequestAsync();
       
    61 }
       
    62 
       
    63 /*
       
    64 Launch new contact editor with a given detail
       
    65 */
       
    66 void CntServiceHandler::editCreateNew(const QString &definitionName, const QString &value)
       
    67 {
       
    68     QContact contact;
       
    69     
       
    70     if (definitionName == QContactPhoneNumber::DefinitionName)
       
    71     {
       
    72         QContactPhoneNumber phoneNumber;
       
    73         phoneNumber.setNumber(value);
       
    74         phoneNumber.setSubTypes(QContactPhoneNumber::SubTypeMobile);
       
    75         contact.saveDetail(&phoneNumber);
       
    76     }
       
    77     else if (definitionName == QContactEmailAddress::DefinitionName)
       
    78     {
       
    79         QContactEmailAddress email;
       
    80         email.setEmailAddress(value);
       
    81         contact.saveDetail(&email);
       
    82     }
       
    83     else if (definitionName == QContactOnlineAccount::DefinitionName)
       
    84     {
       
    85         QContactOnlineAccount account;
       
    86         account.setAccountUri(value);
       
    87         account.setSubTypes(QContactOnlineAccount::SubTypeSipVoip);
       
    88         contact.saveDetail(&account);
       
    89     }
       
    90     
       
    91     emit launchEditor(contact);
       
    92 
       
    93     mCurrentRequestIndex = setCurrentRequestAsync();
       
    94 }
       
    95 
       
    96 /*
       
    97 Launch contact selection view with a given detail (selecting detail there opens the editor and adds the new detail)
       
    98 */
       
    99 void CntServiceHandler::editUpdateExisting(const QString &definitionName, const QString &value)
       
   100 {
       
   101     QContactDetail detail;
       
   102     
       
   103     if (definitionName == QContactPhoneNumber::DefinitionName)
       
   104     {
       
   105         QContactPhoneNumber phoneNumber;
       
   106         phoneNumber.setNumber(value);
       
   107         phoneNumber.setSubTypes(QContactPhoneNumber::SubTypeMobile);
       
   108         detail = phoneNumber;
       
   109     }
       
   110     else if (definitionName == QContactEmailAddress::DefinitionName)
       
   111     {
       
   112         QContactEmailAddress email;
       
   113         email.setEmailAddress(value);
       
   114         detail = email;
       
   115     }
       
   116     else if (definitionName == QContactOnlineAccount::DefinitionName)
       
   117     {
       
   118         QContactOnlineAccount account;
       
   119         account.setAccountUri(value);
       
   120         account.setSubTypes(QContactOnlineAccount::SubTypeSipVoip);
       
   121         detail = account;
       
   122     }
       
   123     
       
   124     emit launchContactSelection(detail);
       
   125 
       
   126     mCurrentRequestIndex = setCurrentRequestAsync();
       
   127 }
       
   128 
       
   129 /*
       
   130 Launch communication launcher view for the contact with the given ID (QContactLocalId -> int)
       
   131 */
       
   132 void CntServiceHandler::open(int contactId)
       
   133 {
       
   134     QContactManager manager("symbian");
       
   135     QContact contact = manager.contact(contactId);
       
   136 
       
   137     emit launchContactCard(contact);
       
   138 
       
   139     mCurrentRequestIndex = setCurrentRequestAsync();
       
   140 }
       
   141 
       
   142 /*
       
   143 Launch temporary communication launcher view with the given detail
       
   144 */
       
   145 void CntServiceHandler::open(const QString &definitionName, const QString &value)
       
   146 {
       
   147     QContact contact;
       
   148     QContactDetail detail;
       
   149     
       
   150     if (definitionName == QContactPhoneNumber::DefinitionName)
       
   151     {
       
   152         QContactPhoneNumber phoneNumber;
       
   153         phoneNumber.setNumber(value);
       
   154         phoneNumber.setSubTypes(QContactPhoneNumber::SubTypeMobile);
       
   155         contact.saveDetail(&phoneNumber);
       
   156         detail = phoneNumber;
       
   157     }
       
   158     else if (definitionName == QContactEmailAddress::DefinitionName)
       
   159     {
       
   160         QContactEmailAddress email;
       
   161         email.setEmailAddress(value);
       
   162         contact.saveDetail(&email);
       
   163         detail = email;
       
   164     }
       
   165     else if (definitionName == QContactOnlineAccount::DefinitionName)
       
   166     {
       
   167         QContactOnlineAccount account;
       
   168         account.setAccountUri(value);
       
   169         account.setSubTypes(QContactOnlineAccount::SubTypeSipVoip);
       
   170         contact.saveDetail(&account);
       
   171         detail = account;
       
   172     }
       
   173     
       
   174     emit launchAssignContactCard(contact, detail);
       
   175 
       
   176     mCurrentRequestIndex = setCurrentRequestAsync();
       
   177 }
       
   178 
       
   179 Q_IMPLEMENT_USER_METATYPE(CntServicesContact)
       
   180 Q_IMPLEMENT_USER_METATYPE_NO_OPERATORS(CntServicesContactList)