telutils/keysequencerecognitionservice/src/manufacturerkeysequencehandler.cpp
changeset 27 7eb70891911c
child 32 1f002146abb4
equal deleted inserted replaced
23:427125ac6cb8 27:7eb70891911c
       
     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: Implements manufacturer key sequence handling.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QDebug>
       
    19 #include <xqserviceutil.h>
       
    20 #include <xqservicerequest.h>
       
    21 #include <hbapplication.h>
       
    22 #include "manufacturerkeysequencehandler.h"
       
    23 #include "keysequencerecognitionservicedefs.h"
       
    24 #include "keysequencerecognitionservicelog.h"
       
    25 
       
    26 /*!
       
    27   ManufacturerKeySequenceHandler::ManufacturerKeySequenceHandler.
       
    28  */
       
    29 ManufacturerKeySequenceHandler::ManufacturerKeySequenceHandler(
       
    30     QObject* parent)
       
    31     : 
       
    32     KeySequenceHandler(parent),
       
    33     m_currentRequest(0)
       
    34 {
       
    35     DPRINT_METHODENTRYEXIT;
       
    36     
       
    37     setKeySequenceValidator(
       
    38         QRegExp::escape(KCodeSwVersion) + "|" +
       
    39         QRegExp::escape(KCodeActivateRfsNormal)  + "|" +
       
    40         QRegExp::escape(KCodeActivateRfsDeep) + "|" +
       
    41         QRegExp::escape(KCodeBtAddress) + "|" +
       
    42         QRegExp::escape(KCodeRFLoopback) + "|" +
       
    43         QRegExp::escape(KCodeBtDebugMode));
       
    44     
       
    45     m_codeToInterfaceMappings[KCodeSwVersion] = InterfaceDescription(
       
    46         "com.nokia.services", "devicemanager", "showVersionNumber()");
       
    47     
       
    48     m_codeToInterfaceMappings[KCodeActivateRfsNormal] = InterfaceDescription(
       
    49         "com.nokia.symbian", "IFactoryReset", "showResetUi()");
       
    50     m_codeToInterfaceMappings[KCodeActivateRfsDeep] = InterfaceDescription(
       
    51         "com.nokia.symbian", "IFactoryReset", "showResetUi()");
       
    52     
       
    53     m_codeToInterfaceMappings[KCodeBtAddress] = InterfaceDescription(
       
    54         "com.nokia.services", "bluetooth", "showBluetoothDeviceAddress()");
       
    55     m_codeToInterfaceMappings[KCodeRFLoopback] = InterfaceDescription(
       
    56         "com.nokia.services", "bluetooth", "showBluetoothLoopback()");
       
    57     m_codeToInterfaceMappings[KCodeBtDebugMode] = InterfaceDescription(
       
    58         "com.nokia.services", "bluetooth", "activateBluetoothDebugMode()");
       
    59 }
       
    60 
       
    61 
       
    62 /*!
       
    63   ManufacturerKeySequenceHandler::~ManufacturerKeySequenceHandler.
       
    64  */
       
    65 ManufacturerKeySequenceHandler::~ManufacturerKeySequenceHandler()
       
    66 {
       
    67     DPRINT_METHODENTRYEXIT;
       
    68 }
       
    69 
       
    70 
       
    71 /*!
       
    72   ManufacturerKeySequenceHandler::executeKeySequence.
       
    73  */
       
    74 bool ManufacturerKeySequenceHandler::executeKeySequence(
       
    75     const QString &keySequence)
       
    76 {
       
    77     DPRINT_METHODENTRYEXIT;
       
    78     
       
    79     bool handled = true;
       
    80     
       
    81     if (m_codeToInterfaceMappings.contains(keySequence)) {
       
    82         handled = issueServiceRequest(m_codeToInterfaceMappings[keySequence]);
       
    83     } else {
       
    84         handled = false;
       
    85     }
       
    86     
       
    87     return handled;
       
    88 }
       
    89 
       
    90 
       
    91 /*!
       
    92   ManufacturerKeySequenceHandler::issueServiceRequest.
       
    93  */
       
    94 bool ManufacturerKeySequenceHandler::issueServiceRequest(
       
    95     const InterfaceDescription &description)
       
    96 {
       
    97     DPRINT_METHODENTRYEXIT;
       
    98     
       
    99     bool serviceRequestOk = false;
       
   100     if (m_currentRequest.isNull()) {
       
   101         const bool isEmbedded = false;
       
   102         QScopedPointer<XQAiwRequest> request(m_aiwManager.create(
       
   103             description.m_service, 
       
   104             description.m_interface, 
       
   105             description.m_method, 
       
   106             isEmbedded));
       
   107         
       
   108         if (!request.isNull()) {
       
   109             m_currentRequest = request.data();
       
   110             
       
   111             // Due to a Qt Highway bug in assignment operator implementation we
       
   112             // need to set request as asynchronous with a setter function.
       
   113             request->setSynchronous(false);
       
   114             
       
   115             connect(
       
   116                 request.data(), SIGNAL(requestOk(const QVariant &)), 
       
   117                 this, SLOT(requestOk(const QVariant &)));
       
   118             connect(
       
   119                 request.data(), SIGNAL(requestError(int, const QString&)), 
       
   120                 this, SLOT(requestError(int, const QString&)));
       
   121             
       
   122             serviceRequestOk = request->send();
       
   123             if (serviceRequestOk) {
       
   124                 m_currentRequest = request.take();
       
   125             } else {
       
   126                 // On a controlled error Qt Highway should call requestError,
       
   127                 // so clean scoped pointer here.
       
   128                 request.take();
       
   129             }
       
   130         }
       
   131     }
       
   132     
       
   133     return serviceRequestOk;
       
   134 }
       
   135 
       
   136 
       
   137 /*!
       
   138   ManufacturerKeySequenceHandler::requestOk.
       
   139  */
       
   140 void ManufacturerKeySequenceHandler::requestOk(
       
   141     const QVariant &returnValue)
       
   142 {
       
   143     DPRINT_METHODENTRYEXIT;
       
   144     
       
   145     Q_UNUSED(returnValue)
       
   146     
       
   147     delete m_currentRequest;
       
   148     m_currentRequest = 0;
       
   149 }
       
   150 
       
   151 
       
   152 /*!
       
   153   ManufacturerKeySequenceHandler::requestError.
       
   154  */
       
   155 void ManufacturerKeySequenceHandler::requestError(
       
   156     int error, const QString& errorMessage)
       
   157 {
       
   158     DPRINT_METHODENTRYEXIT;
       
   159     
       
   160     Q_UNUSED(error)
       
   161     Q_UNUSED(errorMessage)
       
   162     
       
   163     delete m_currentRequest;
       
   164     m_currentRequest = 0;
       
   165 }