logsui/logsengine/src/logscontact.cpp
changeset 16 c5af8598d22c
parent 14 f27aebe284bb
child 17 90fe74753f71
equal deleted inserted replaced
14:f27aebe284bb 16:c5af8598d22c
    24 #include "logsdbconnector.h"
    24 #include "logsdbconnector.h"
    25 #include "logscommondata.h"
    25 #include "logscommondata.h"
    26 
    26 
    27 //SYSTEM
    27 //SYSTEM
    28 #include <QVariant>
    28 #include <QVariant>
    29 #include <xqservicerequest.h>
       
    30 #include <qcontactmanager.h>
    29 #include <qcontactmanager.h>
       
    30 #include <xqappmgr.h>
       
    31 #include <cntservicescontact.h>
    31 
    32 
    32 // -----------------------------------------------------------------------------
    33 // -----------------------------------------------------------------------------
    33 //
    34 //
    34 // -----------------------------------------------------------------------------
    35 // -----------------------------------------------------------------------------
    35 //
    36 //
    36 LogsContact::LogsContact(LogsEvent& event, LogsDbConnector& dbConnector)
    37 LogsContact::LogsContact(LogsEvent& event, LogsDbConnector& dbConnector)
    37   :  QObject(), 
    38   :  QObject(), 
    38      mDbConnector(dbConnector),
    39      mDbConnector(dbConnector),
    39      mService(0),
    40      mAiwRequest(0),
    40      mCurrentRequest(TypeLogsContactSave),
    41      mCurrentRequest(TypeLogsContactSave),
    41      mContactId(0),
    42      mContactId(0),
    42      mSaveAsOnlineAccount(false)
    43      mSaveAsOnlineAccount(false)
    43 {
    44 {
    44     mNumber = event.getNumberForCalling();
    45     mNumber = event.getNumberForCalling();
    58 LogsContact::LogsContact(const QString& number, 
    59 LogsContact::LogsContact(const QString& number, 
    59                          LogsDbConnector& dbConnector,
    60                          LogsDbConnector& dbConnector,
    60                          unsigned int contactId)
    61                          unsigned int contactId)
    61   :  QObject(), 
    62   :  QObject(), 
    62      mDbConnector(dbConnector),
    63      mDbConnector(dbConnector),
    63      mService(0),
    64      mAiwRequest(0),
    64      mCurrentRequest(TypeLogsContactSave),
    65      mCurrentRequest(TypeLogsContactSave),
    65      mNumber(number),
    66      mNumber(number),
    66      mContactId(contactId),
    67      mContactId(contactId),
    67      mSaveAsOnlineAccount(false)
    68      mSaveAsOnlineAccount(false)
    68 {
    69 {
    74 // -----------------------------------------------------------------------------
    75 // -----------------------------------------------------------------------------
    75 //
    76 //
    76 LogsContact::~LogsContact()
    77 LogsContact::~LogsContact()
    77 {
    78 {
    78     LOGS_QDEBUG( "logs [ENG] <-> LogsContact::~LogsContact()" )
    79     LOGS_QDEBUG( "logs [ENG] <-> LogsContact::~LogsContact()" )
    79     delete mService;
    80     delete mAiwRequest;
    80 }
    81 }
    81     
    82     
    82 // ----------------------------------------------------------------------------
    83 // ----------------------------------------------------------------------------
    83 //
    84 //
    84 // ----------------------------------------------------------------------------
    85 // ----------------------------------------------------------------------------
   114     LOGS_QDEBUG( "logs [ENG] -> LogsContact::open()")
   115     LOGS_QDEBUG( "logs [ENG] -> LogsContact::open()")
   115     bool ret = false;
   116     bool ret = false;
   116     if ( allowedRequestType() == TypeLogsContactOpen ) {
   117     if ( allowedRequestType() == TypeLogsContactOpen ) {
   117         mCurrentRequest = TypeLogsContactOpen;
   118         mCurrentRequest = TypeLogsContactOpen;
   118 
   119 
       
   120         QString interface("com.nokia.symbian.IContactsView");
       
   121         QString operation("openContactCard(int)");
   119         QList<QVariant> arguments;
   122         QList<QVariant> arguments;
   120         arguments.append( QVariant(mContactId) );
   123         arguments.append( QVariant(mContactId) );
   121         ret = requestFetchService( "open(int)", arguments );
   124         ret = requestPhonebookService( interface, operation, arguments );
   122     }
   125     }
   123     
   126     
   124     LOGS_QDEBUG_2( "logs [ENG] <- LogsContact::open(): ", ret )
   127     LOGS_QDEBUG_2( "logs [ENG] <- LogsContact::open(): ", ret )
   125     return ret;
   128     return ret;
   126 }
   129 }
   158 // ----------------------------------------------------------------------------
   161 // ----------------------------------------------------------------------------
   159 //
   162 //
   160 void LogsContact::cancelServiceRequest()
   163 void LogsContact::cancelServiceRequest()
   161 {
   164 {
   162     LOGS_QDEBUG( "logs [ENG] -> LogsContact::cancelServiceRequest()" )
   165     LOGS_QDEBUG( "logs [ENG] -> LogsContact::cancelServiceRequest()" )
   163     delete mService;
   166     delete mAiwRequest;
   164     mService = 0;
   167     mAiwRequest = 0;
   165     LOGS_QDEBUG( "logs [ENG] <- LogsContact::cancelServiceRequest()" )
   168     LOGS_QDEBUG( "logs [ENG] <- LogsContact::cancelServiceRequest()" )
   166 }
   169 }
   167 
   170 
   168 // ----------------------------------------------------------------------------
   171 // ----------------------------------------------------------------------------
   169 //
   172 //
   170 // ----------------------------------------------------------------------------
   173 // ----------------------------------------------------------------------------
   171 //
   174 //
   172 bool LogsContact::save(QString message)
   175 bool LogsContact::save(const QString& operation)
   173 {
   176 {
   174     QList<QVariant> arguments;
   177     QList<QVariant> arguments;
   175  
   178  
   176     if ( !mNumber.isEmpty() ) {
   179     if ( !mNumber.isEmpty() ) {
   177         if ( mSaveAsOnlineAccount ){
   180         if ( mSaveAsOnlineAccount ){
   186     
   189     
   187     bool ret(false);
   190     bool ret(false);
   188     
   191     
   189     if ( arguments.count() == 2 ) {
   192     if ( arguments.count() == 2 ) {
   190         mCurrentRequest = TypeLogsContactSave;
   193         mCurrentRequest = TypeLogsContactSave;
   191         ret = requestFetchService( message, arguments );
   194         QString interface("com.nokia.symbian.IContactsEdit");
       
   195         ret = requestPhonebookService( interface, operation, arguments );        
   192     } else {
   196     } else {
   193         LOGS_QDEBUG( "logs [ENG]  !No Caller ID, not saving the contact..")
   197         LOGS_QDEBUG( "logs [ENG]  !No Caller ID, not saving the contact..")
   194     }
   198     }
   195     
   199     
   196     return ret;
   200     return ret;
   198 
   202 
   199 // ----------------------------------------------------------------------------
   203 // ----------------------------------------------------------------------------
   200 //
   204 //
   201 // ----------------------------------------------------------------------------
   205 // ----------------------------------------------------------------------------
   202 //
   206 //
   203 bool LogsContact::requestFetchService( QString message, 
   207 bool LogsContact::requestPhonebookService(const QString& interface, 
   204         const QList<QVariant> &arguments, bool sync )
   208                              const QString& operation,
   205 {
   209                              const QList<QVariant>& arguments)
   206     QString service("com.nokia.services.phonebookservices.Fetch");
   210 {
       
   211     bool ret = false;
   207     cancelServiceRequest();
   212     cancelServiceRequest();
   208     mService = new XQServiceRequest(service, message, sync);
   213     XQApplicationManager appMng;
   209     connect(mService, SIGNAL(requestCompleted(QVariant)), this, 
   214     mAiwRequest = appMng.create( interface, operation, true); // embedded 
   210             SLOT(handleRequestCompleted(QVariant)));
   215     if (mAiwRequest) {
   211 
   216         connect(mAiwRequest, SIGNAL(requestOk(const QVariant&)), 
   212     mService->setArguments(arguments);
   217                 this, SLOT(handleRequestCompleted(const QVariant&)));
   213     XQRequestInfo info;
   218         connect(mAiwRequest, SIGNAL(requestError(int,const QString&)), 
   214     info.setEmbedded(true);
   219                 this, SLOT(handleError(int,const QString&)));
   215     mService->setInfo(info);
   220 
   216     
   221         mAiwRequest->setArguments(arguments);
   217     QVariant retValue;
   222         mAiwRequest->setSynchronous(false);
   218     return mService->send(retValue);
   223         ret = mAiwRequest->send();
       
   224     }
       
   225     return ret;
       
   226 }
       
   227 
       
   228 // ----------------------------------------------------------------------------
       
   229 //
       
   230 // ----------------------------------------------------------------------------
       
   231 //
       
   232 void LogsContact::handleError(int errorCode, const QString& errorMessage)
       
   233 {
       
   234     LOGS_QDEBUG_4( "logs [ENG] <-> LogsContact::handleError(): ", errorCode,
       
   235             " ,msg: ", errorMessage)
       
   236     cancelServiceRequest();
   219 }
   237 }
   220 
   238 
   221 // ----------------------------------------------------------------------------
   239 // ----------------------------------------------------------------------------
   222 // Phonebookservices define following return values:
   240 // Phonebookservices define following return values:
   223 // - contact wasn't modified (-2)
   241 // KCntServicesReturnValueContactNotModified = 0;
   224 // - was deleted (-1)
   242 // KCntServicesReturnValueContactDeleted     = -1;
   225 // - was saved (1)
   243 // KCntServicesReturnValueContactSaved       = 1;
   226 // - saving failed (0)
   244 // KCntServicesTerminated = -2;
   227 // ----------------------------------------------------------------------------
   245 // ----------------------------------------------------------------------------
   228 //
   246 //
   229 void LogsContact::handleRequestCompleted(const QVariant& result)
   247 void LogsContact::handleRequestCompleted(const QVariant& result)
   230 {
   248 {
   231     delete mService;
   249     delete mAiwRequest;
   232     mService = 0;
   250     mAiwRequest = 0;
   233     bool retValOk = false;
   251     bool retValOk = false;
   234     int serviceRetVal = result.toInt(&retValOk);
   252     int serviceRetVal = result.toInt(&retValOk);
   235     LOGS_QDEBUG_3( "logs [ENG] -> LogsContact::handleRequestCompleted(), (retval, is_ok)", 
   253     LOGS_QDEBUG_3( "logs [ENG] -> LogsContact::handleRequestCompleted(), (retval, is_ok)", 
   236                    serviceRetVal, retValOk )
   254                    serviceRetVal, retValOk )
   237     
   255     
   238     bool modified = ( retValOk && serviceRetVal == 1 );
   256     bool modified = ( retValOk 
       
   257                       && (serviceRetVal == KCntServicesReturnValueContactSaved 
       
   258                       || serviceRetVal == KCntServicesReturnValueContactDeleted) );
   239     
   259     
   240     //If existing contact was modified, cached match for the contact should be 
   260     //If existing contact was modified, cached match for the contact should be 
   241     //cleaned up, since remote party info might have been changed.
   261     //cleaned up, since remote party info might have been changed.
   242     //However, if remote party info is taken from symbian DB, it won't be 
   262     //However, if remote party info is taken from symbian DB, it won't be 
   243     //updated
   263     //updated