|
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 key sequence recognition filter for Dialpad. |
|
15 * |
|
16 */ |
|
17 #include <QDebug> |
|
18 #include <QKeyEvent> |
|
19 #include <hblineedit.h> |
|
20 #include <hbstringutil.h> |
|
21 #ifdef Q_OS_SYMBIAN |
|
22 #include <xqservicerequest.h> |
|
23 #include <xqserviceutil.h> |
|
24 #endif //Q_OS_SYMBIAN |
|
25 #include "dialpadkeysequenceeventfilter.h" |
|
26 #include "dialpad.h" |
|
27 #include "qtphonesrvlog.h" |
|
28 |
|
29 /*! |
|
30 DialpadKeySequenceEventFilter::DialpadKeySequenceEventFilter. |
|
31 */ |
|
32 DialpadKeySequenceEventFilter::DialpadKeySequenceEventFilter( |
|
33 Dialpad* dialpad, QObject* parent) |
|
34 : |
|
35 QObject(parent), mDialpad(dialpad) |
|
36 { |
|
37 PHONE_TRACE; |
|
38 |
|
39 constructKeySequenceToHandlerMappings(); |
|
40 } |
|
41 |
|
42 |
|
43 /*! |
|
44 DialpadKeySequenceEventFilter::~DialpadKeySequenceEventFilter. |
|
45 */ |
|
46 DialpadKeySequenceEventFilter::~DialpadKeySequenceEventFilter() |
|
47 { |
|
48 PHONE_TRACE; |
|
49 } |
|
50 |
|
51 |
|
52 /*! |
|
53 DialpadKeySequenceEventFilter::eventFilter. |
|
54 */ |
|
55 bool DialpadKeySequenceEventFilter::eventFilter(QObject *watched, QEvent *event) |
|
56 { |
|
57 Q_UNUSED(watched) |
|
58 |
|
59 const bool eventFiltered = false; |
|
60 #ifdef Q_OS_SYMBIAN |
|
61 // Code is executed after '#' is pressed as specified in Dialer UI |
|
62 // specification. |
|
63 if (QEvent::KeyRelease == event->type()){ |
|
64 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); |
|
65 if (Qt::Key_NumberSign == keyEvent->key()) { |
|
66 QString keySequenceCandidate = HbStringUtil::convertDigitsTo( |
|
67 mDialpad->editor().text(), WesternDigit); |
|
68 XQAiwInterfaceDescriptor keySequenceHandler = |
|
69 findKeySequenceHandler(keySequenceCandidate); |
|
70 if (keySequenceHandler.isValid()) { |
|
71 QScopedPointer<XQAiwRequest> request(mAiwMgr.create( |
|
72 keySequenceHandler, |
|
73 "executeKeySequence(QString)", |
|
74 false)); |
|
75 request->setSynchronous(true); |
|
76 request->setBackground(true); |
|
77 QList<QVariant> arguments; |
|
78 arguments << keySequenceCandidate; |
|
79 request->setArguments(arguments); |
|
80 |
|
81 QVariant keySequenceProcessed; |
|
82 bool requestOk = request->send(keySequenceProcessed); |
|
83 if (requestOk && keySequenceProcessed.toBool()) { |
|
84 mDialpad->editor().setText(QString("")); |
|
85 } |
|
86 } |
|
87 } |
|
88 } |
|
89 #else |
|
90 Q_UNUSED(event) |
|
91 #endif // Q_OS_SYMBIAN |
|
92 |
|
93 return eventFiltered; |
|
94 } |
|
95 |
|
96 |
|
97 /*! |
|
98 DialpadKeySequenceEventFilter::constructKeySequenceToHandlerMappings. |
|
99 */ |
|
100 void DialpadKeySequenceEventFilter::constructKeySequenceToHandlerMappings() |
|
101 { |
|
102 PHONE_TRACE; |
|
103 |
|
104 QList<XQAiwInterfaceDescriptor> implementations = mAiwMgr.list( |
|
105 "com.nokia.symbian.IKeySequenceRecognition", |
|
106 ""); |
|
107 |
|
108 foreach (XQAiwInterfaceDescriptor d, implementations) |
|
109 { |
|
110 QScopedPointer<XQAiwRequest> request(mAiwMgr.create( |
|
111 d, |
|
112 "keySequenceValidator()", |
|
113 false)); |
|
114 request->setSynchronous(true); |
|
115 request->setBackground(true); |
|
116 |
|
117 QVariant keySequenceValidator; |
|
118 bool requestOk = request->send(keySequenceValidator); |
|
119 if (requestOk && keySequenceValidator.toString().size()) { |
|
120 QString validator = keySequenceValidator.toString(); |
|
121 mValidators[validator] = d; |
|
122 } |
|
123 } |
|
124 } |
|
125 |
|
126 |
|
127 /*! |
|
128 DialpadKeySequenceEventFilter::findKeySequenceHandler. |
|
129 */ |
|
130 XQAiwInterfaceDescriptor DialpadKeySequenceEventFilter::findKeySequenceHandler( |
|
131 const QString &keySequenceCandidate) |
|
132 { |
|
133 PHONE_TRACE; |
|
134 |
|
135 XQAiwInterfaceDescriptor keySequenceHandler; |
|
136 |
|
137 QList<QString> validatorExpressions = mValidators.keys(); |
|
138 QList<QString>::const_iterator it; |
|
139 for (it = validatorExpressions.constBegin(); |
|
140 (it != validatorExpressions.constEnd()) && (!keySequenceHandler.isValid()); |
|
141 ++it) { |
|
142 QString validatorExpression = *it; |
|
143 QRegExp expression(validatorExpression); |
|
144 if (expression.exactMatch(keySequenceCandidate)) { |
|
145 keySequenceHandler = mValidators.value(*it); |
|
146 } |
|
147 } |
|
148 |
|
149 return keySequenceHandler; |
|
150 } |