|
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 |
|
40 |
|
41 /*! |
|
42 DialpadKeySequenceEventFilter::~DialpadKeySequenceEventFilter. |
|
43 */ |
|
44 DialpadKeySequenceEventFilter::~DialpadKeySequenceEventFilter() |
|
45 { |
|
46 PHONE_TRACE; |
|
47 } |
|
48 |
|
49 |
|
50 /*! |
|
51 DialpadKeySequenceEventFilter::eventFilter. |
|
52 */ |
|
53 bool DialpadKeySequenceEventFilter::eventFilter(QObject *watched, QEvent *event) |
|
54 { |
|
55 PHONE_TRACE; |
|
56 Q_UNUSED(watched) |
|
57 |
|
58 const bool eventFiltered = false; |
|
59 #ifdef Q_OS_SYMBIAN |
|
60 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); |
|
61 const int keyCode = keyEvent->key(); |
|
62 const int eventType = event->type(); |
|
63 |
|
64 // Code is executed after '#' is pressed as specified in Dialer UI |
|
65 // specification. |
|
66 QString keySequenceCandidate = HbStringUtil::convertDigitsTo( |
|
67 mDialpad->editor().text(), WesternDigit); |
|
68 if (QEvent::KeyRelease == eventType && |
|
69 Qt::Key_NumberSign == keyCode && |
|
70 preValidateKeySequence(keySequenceCandidate)) { |
|
71 XQServiceRequest request( |
|
72 "com.nokia.services.telephony", |
|
73 "executeKeySequence(QString)", |
|
74 true); |
|
75 |
|
76 // Workaround for getting focus back to dialer after service request. |
|
77 XQRequestInfo requestInfo; |
|
78 requestInfo.setBackground(true); |
|
79 request.setInfo(requestInfo); |
|
80 |
|
81 QVariant keySequenceProcessed; |
|
82 request << keySequenceCandidate; |
|
83 bool requestOk = request.send(keySequenceProcessed); |
|
84 if (requestOk && keySequenceProcessed.toBool()) { |
|
85 mDialpad->editor().setText(QString("")); |
|
86 } |
|
87 } |
|
88 #else |
|
89 Q_UNUSED(event) |
|
90 #endif // Q_OS_SYMBIAN |
|
91 |
|
92 return eventFiltered; |
|
93 } |
|
94 |
|
95 |
|
96 /*! |
|
97 DialpadKeySequenceEventFilter::preValidateKeySequence. |
|
98 Checks that key sequence starts with '*#'and ends with '#'. |
|
99 */ |
|
100 bool DialpadKeySequenceEventFilter::preValidateKeySequence( |
|
101 const QString &sequence) |
|
102 { |
|
103 const int KMinimumLength = 4; |
|
104 bool isValid = false; |
|
105 |
|
106 int lengthOfSequence = sequence.length(); |
|
107 if (KMinimumLength <= lengthOfSequence) { |
|
108 isValid = |
|
109 (sequence.at(0) == '*') && |
|
110 (sequence.at(1) == '#') && |
|
111 (sequence.at(lengthOfSequence - 1) == '#'); |
|
112 } |
|
113 |
|
114 return isValid; |
|
115 } |