|
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 |
|
44 m_codeToInterfaceMappings[KCodeSwVersion] = InterfaceDescription( |
|
45 "com.nokia.services", "devicemanager", "showVersionNumber()"); |
|
46 |
|
47 m_codeToInterfaceMappings[KCodeActivateRfsNormal] = InterfaceDescription( |
|
48 "com.nokia.symbian", "IFactoryReset", "showResetUi()"); |
|
49 m_codeToInterfaceMappings[KCodeActivateRfsDeep] = InterfaceDescription( |
|
50 "com.nokia.symbian", "IFactoryReset", "showResetUi()"); |
|
51 |
|
52 m_codeToInterfaceMappings[KCodeBtAddress] = InterfaceDescription( |
|
53 "com.nokia.services", "bluetooth", "showBluetoothDeviceAddress()"); |
|
54 m_codeToInterfaceMappings[KCodeRFLoopback] = InterfaceDescription( |
|
55 "com.nokia.services", "bluetooth", "showBluetoothLoopback()"); |
|
56 } |
|
57 |
|
58 |
|
59 /*! |
|
60 ManufacturerKeySequenceHandler::~ManufacturerKeySequenceHandler. |
|
61 */ |
|
62 ManufacturerKeySequenceHandler::~ManufacturerKeySequenceHandler() |
|
63 { |
|
64 DPRINT_METHODENTRYEXIT; |
|
65 } |
|
66 |
|
67 |
|
68 /*! |
|
69 ManufacturerKeySequenceHandler::executeKeySequence. |
|
70 */ |
|
71 bool ManufacturerKeySequenceHandler::executeKeySequence( |
|
72 const QString &keySequence) |
|
73 { |
|
74 DPRINT_METHODENTRYEXIT; |
|
75 |
|
76 bool handled = true; |
|
77 |
|
78 if (m_codeToInterfaceMappings.contains(keySequence)) { |
|
79 handled = issueServiceRequest(m_codeToInterfaceMappings[keySequence]); |
|
80 } else { |
|
81 handled = false; |
|
82 } |
|
83 |
|
84 return handled; |
|
85 } |
|
86 |
|
87 |
|
88 /*! |
|
89 ManufacturerKeySequenceHandler::issueServiceRequest. |
|
90 */ |
|
91 bool ManufacturerKeySequenceHandler::issueServiceRequest( |
|
92 const InterfaceDescription &description) |
|
93 { |
|
94 DPRINT_METHODENTRYEXIT; |
|
95 |
|
96 bool serviceRequestOk = false; |
|
97 if (m_currentRequest.isNull()) { |
|
98 const bool isEmbedded = false; |
|
99 QScopedPointer<XQAiwRequest> request(m_aiwManager.create( |
|
100 description.m_service, |
|
101 description.m_interface, |
|
102 description.m_method, |
|
103 isEmbedded)); |
|
104 |
|
105 if (!request.isNull()) { |
|
106 m_currentRequest = request.data(); |
|
107 |
|
108 // Due to a Qt Highway bug in assignment operator implementation we |
|
109 // need to set request as asynchronous with a setter function. |
|
110 request->setSynchronous(false); |
|
111 |
|
112 connect( |
|
113 request.data(), SIGNAL(requestOk(const QVariant &)), |
|
114 this, SLOT(requestOk(const QVariant &))); |
|
115 connect( |
|
116 request.data(), SIGNAL(requestError(int, const QString&)), |
|
117 this, SLOT(requestError(int, const QString&))); |
|
118 |
|
119 serviceRequestOk = request->send(); |
|
120 if (serviceRequestOk) { |
|
121 m_currentRequest = request.take(); |
|
122 } else { |
|
123 // On a controlled error Qt Highway should call requestError, |
|
124 // so clean scoped pointer here. |
|
125 request.take(); |
|
126 } |
|
127 } |
|
128 } |
|
129 |
|
130 return serviceRequestOk; |
|
131 } |
|
132 |
|
133 |
|
134 /*! |
|
135 ManufacturerKeySequenceHandler::requestOk. |
|
136 */ |
|
137 void ManufacturerKeySequenceHandler::requestOk( |
|
138 const QVariant &returnValue) |
|
139 { |
|
140 DPRINT_METHODENTRYEXIT; |
|
141 |
|
142 Q_UNUSED(returnValue) |
|
143 |
|
144 delete m_currentRequest; |
|
145 m_currentRequest = 0; |
|
146 } |
|
147 |
|
148 |
|
149 /*! |
|
150 ManufacturerKeySequenceHandler::requestError. |
|
151 */ |
|
152 void ManufacturerKeySequenceHandler::requestError( |
|
153 int error, const QString& errorMessage) |
|
154 { |
|
155 DPRINT_METHODENTRYEXIT; |
|
156 |
|
157 Q_UNUSED(error) |
|
158 Q_UNUSED(errorMessage) |
|
159 |
|
160 delete m_currentRequest; |
|
161 m_currentRequest = 0; |
|
162 } |