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: |
|
15 * |
|
16 */ |
|
17 #include <QKeyEvent> |
|
18 #include <hblineedit.h> |
|
19 #include <hbstringutil.h> |
|
20 #include "dialpademergencycalleventfilter.h" |
|
21 #include "dialpad.h" |
|
22 #include "qtphonesrvlog.h" |
|
23 |
|
24 #ifdef Q_OS_SYMBIAN |
|
25 #include <cphcltemergencycall.h> |
|
26 #include <phclttypes.h> |
|
27 #endif //Q_OS_SYMBIAN |
|
28 |
|
29 |
|
30 DialpadEmergencyCallEventFilter::DialpadEmergencyCallEventFilter(Dialpad* dialpad, QObject* parent) : |
|
31 QObject(parent), mDialpad(dialpad), mEmergency(0) |
|
32 { |
|
33 PHONE_TRACE; |
|
34 #ifdef Q_OS_SYMBIAN |
|
35 TRAP_IGNORE(mEmergency = CPhCltEmergencyCall::NewL( NULL )); |
|
36 #endif // Q_OS_SYMBIAN |
|
37 mDialpad->setCallButtonEnabled(false); |
|
38 connect(&mDialpad->editor(),SIGNAL(contentsChanged()), |
|
39 this,SLOT(editorTextChanged())); |
|
40 } |
|
41 |
|
42 DialpadEmergencyCallEventFilter::~DialpadEmergencyCallEventFilter() |
|
43 { |
|
44 } |
|
45 |
|
46 bool DialpadEmergencyCallEventFilter::eventFilter(QObject *watched, QEvent *event) |
|
47 { |
|
48 PHONE_TRACE; |
|
49 Q_UNUSED(watched) |
|
50 |
|
51 bool eventFiltered = false; |
|
52 #ifdef Q_OS_SYMBIAN |
|
53 |
|
54 const int eventType = event->type(); |
|
55 |
|
56 if (eventType == QEvent::KeyPress) { |
|
57 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); |
|
58 const int keyCode = keyEvent->key(); |
|
59 if (keyCode == Qt::Key_Yes || |
|
60 keyCode == Qt::Key_Enter) { |
|
61 if (isEmergencyNumber(editorText())) { |
|
62 createCall(editorText()); |
|
63 eventFiltered = true; |
|
64 } |
|
65 } |
|
66 } |
|
67 #else |
|
68 Q_UNUSED(event) |
|
69 #endif // Q_OS_SYMBIAN |
|
70 |
|
71 return eventFiltered; |
|
72 } |
|
73 |
|
74 bool DialpadEmergencyCallEventFilter::isEmergencyNumber(QString string) |
|
75 { |
|
76 PHONE_TRACE; |
|
77 bool ret = false; |
|
78 #ifdef Q_OS_SYMBIAN |
|
79 if (KPhCltTelephoneNumberLength >= string.length()) { |
|
80 TBool emergency; |
|
81 TPhCltTelephoneNumber number(reinterpret_cast<const TUint16*>(string.utf16())); |
|
82 if (mEmergency && |
|
83 KErrNone == mEmergency->IsEmergencyPhoneNumber(number, emergency)) { |
|
84 ret = emergency; |
|
85 } |
|
86 } |
|
87 #else |
|
88 Q_UNUSED(string) |
|
89 #endif // Q_OS_SYMBIAN |
|
90 return ret; |
|
91 } |
|
92 |
|
93 QString DialpadEmergencyCallEventFilter::editorText() |
|
94 { |
|
95 PHONE_TRACE; |
|
96 return HbStringUtil::convertDigitsTo( |
|
97 mDialpad->editor().text(), WesternDigit); |
|
98 } |
|
99 |
|
100 void DialpadEmergencyCallEventFilter::createCall(const QString &phoneNumber) |
|
101 { |
|
102 PHONE_TRACE2("phoneNumber:", phoneNumber); |
|
103 #ifdef Q_OS_SYMBIAN |
|
104 TPtrC number (static_cast<const TUint16*>(phoneNumber.utf16()), |
|
105 phoneNumber.length()); |
|
106 TRAP_IGNORE(mEmergency->DialEmergencyCallL(number)); |
|
107 #endif // Q_OS_SYMBIAN |
|
108 } |
|
109 |
|
110 void DialpadEmergencyCallEventFilter::editorTextChanged() |
|
111 { |
|
112 mDialpad->setCallButtonEnabled(isEmergencyNumber(editorText())); |
|
113 } |
|
114 |
|