messagingapp/msgui/msgapp/src/msgserviceinterface.cpp
changeset 23 238255e8b033
child 25 84d9eb65b26f
equal deleted inserted replaced
5:4697dfb2d7ad 23:238255e8b033
       
     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: Message Application Launcher interface used for interfacing between
       
    15  *              QT highway and other applications
       
    16  *
       
    17  */
       
    18 
       
    19 //TODO: to be deprecated
       
    20 #include <qtcontactsglobal.h>
       
    21 #include "qcontactdetailfilter.h"
       
    22 #include "qcontactdetail.h"
       
    23 #include "qtcontacts.h" 
       
    24 #include "convergedmessageaddress.h"
       
    25 
       
    26 #include "msgserviceinterface.h"
       
    27 #include "msgviewmanager.h"
       
    28 //INCLUDES
       
    29 
       
    30 MsgServiceInterface::MsgServiceInterface(QObject* parent, MsgViewManager* manager)
       
    31 :XQServiceProvider( QLatin1String("com.nokia.services.hbserviceprovider.conversationview"),parent),
       
    32 mViewManager(manager)
       
    33     {
       
    34     publishAll();    
       
    35     }
       
    36 
       
    37 MsgServiceInterface::~MsgServiceInterface()
       
    38     {
       
    39     }
       
    40 
       
    41 void MsgServiceInterface::send(const QString phoneNumber, const qint32 contactId, const QString displayName)
       
    42     {   
       
    43     mViewManager->setServiceRequest(true);
       
    44     mViewManager->send(contactId, phoneNumber, displayName);    
       
    45     }
       
    46 
       
    47 void MsgServiceInterface::open(qint64 conversationId)
       
    48     {
       
    49     mViewManager->setServiceRequest(false);
       
    50     mViewManager->open(conversationId); 
       
    51     }
       
    52 
       
    53 void MsgServiceInterface::send(QVariant data)
       
    54     {   
       
    55     mViewManager->setServiceRequest(true);
       
    56     mViewManager->send(data);    
       
    57     }
       
    58 
       
    59 void MsgServiceInterface::openConversationView(QString number, QString name)
       
    60     {
       
    61     mViewManager->setServiceRequest(true);
       
    62         
       
    63     QString resolvedName;
       
    64     if(name.isEmpty())
       
    65         {
       
    66         ConvergedMessageAddress address;
       
    67         address.setAddress(number);
       
    68         address.setAlias(name);        
       
    69         
       
    70         ContactDetail contactDetail;
       
    71         bool ret = resolveContact(address, contactDetail);
       
    72         if(ret)
       
    73             {
       
    74             if(!contactDetail.lastName.isEmpty())
       
    75                 {
       
    76                 resolvedName += contactDetail.lastName;
       
    77                 if(!contactDetail.firstName.isEmpty())
       
    78                     {
       
    79                     resolvedName += ", ";
       
    80                     }
       
    81                 }
       
    82             resolvedName += contactDetail.firstName;
       
    83             }
       
    84         }
       
    85     mViewManager->openEditor(number,resolvedName);
       
    86     }
       
    87 
       
    88 bool MsgServiceInterface::resolveContact(const ConvergedMessageAddress &address,
       
    89         ContactDetail &contactDetail)
       
    90     {
       
    91     QContactManager* mPhonebookManager = new QContactManager("symbian");
       
    92     QContactDetailFilter phoneFilter;
       
    93     phoneFilter.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber);
       
    94     phoneFilter.setValue(address.address());
       
    95     phoneFilter.setMatchFlags(QContactFilter::MatchEndsWith);
       
    96 
       
    97     QList<QContactLocalId> matchingContacts = mPhonebookManager->contacts(phoneFilter);
       
    98 
       
    99     if ( matchingContacts.count() > 0 ) {       
       
   100     // Fill the contact details
       
   101     contactDetail.contactId = matchingContacts.at(0);
       
   102     QContact match = mPhonebookManager->contact(matchingContacts.at(0));
       
   103 
       
   104     QContactName nameDetails = match.detail(QContactName::DefinitionName);
       
   105 
       
   106     QContactName name = match.detail(QContactName::DefinitionName);
       
   107     contactDetail.firstName = name.first();
       
   108     contactDetail.lastName = name.last();
       
   109     return true;
       
   110     }
       
   111     
       
   112     return false;
       
   113     }
       
   114