|
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 Life Timer key sequence handling. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QDebug> |
|
19 #include <hbmessagebox.h> |
|
20 #include <hbdevicemessagebox.h> |
|
21 #include <hbextendedlocale.h> |
|
22 #include <etelmm.h> |
|
23 #include <rmmcustomapi.h> |
|
24 #include <mmtsy_names.h> |
|
25 #include <xqconversions.h> |
|
26 #include "lifetimerkeysequencehandler.h" |
|
27 #include "keysequencerecognitionservicedefs.h" |
|
28 #include "telservicesinternalcrkeys.h" |
|
29 #include "telservicesvariant.hrh" |
|
30 #include "keysequencerecognitionservicelog.h" |
|
31 |
|
32 /*! |
|
33 LifeTimerKeySequenceHandler::LifeTimerKeySequenceHandler. |
|
34 */ |
|
35 LifeTimerKeySequenceHandler::LifeTimerKeySequenceHandler( |
|
36 QObject* parent) |
|
37 : |
|
38 KeySequenceHandler(parent), |
|
39 m_messageBox(0), |
|
40 m_repository(0) |
|
41 { |
|
42 DPRINT_METHODENTRYEXIT; |
|
43 |
|
44 CRepository *repository = 0; |
|
45 QT_TRAP_THROWING(repository = CRepository::NewL(KCRUidTelSrvVariation)) |
|
46 m_repository.reset(repository); |
|
47 |
|
48 if (lifeTimerFeatureEnabled()) { |
|
49 setKeySequenceValidator(QRegExp::escape(KCodeLifeTimer)); |
|
50 } |
|
51 } |
|
52 |
|
53 |
|
54 /*! |
|
55 LifeTimerKeySequenceHandler::~LifeTimerKeySequenceHandler. |
|
56 */ |
|
57 LifeTimerKeySequenceHandler::~LifeTimerKeySequenceHandler() |
|
58 { |
|
59 DPRINT_METHODENTRYEXIT; |
|
60 |
|
61 destroyMessageBox(); |
|
62 } |
|
63 |
|
64 |
|
65 /*! |
|
66 LifeTimerKeySequenceHandler::executeKeySequence. |
|
67 */ |
|
68 bool LifeTimerKeySequenceHandler::executeKeySequence( |
|
69 const QString &keySequence) |
|
70 { |
|
71 DPRINT_METHODENTRYEXIT; |
|
72 |
|
73 bool handled = true; |
|
74 |
|
75 if (KCodeLifeTimer == keySequence && lifeTimerFeatureEnabled()) { |
|
76 launchLifeTimerDialog(); |
|
77 } else { |
|
78 handled = false; |
|
79 } |
|
80 |
|
81 return handled; |
|
82 } |
|
83 |
|
84 |
|
85 /*! |
|
86 LifeTimerKeySequenceHandler::launchLifeTimerDialog(). |
|
87 */ |
|
88 void LifeTimerKeySequenceHandler::launchLifeTimerDialog() |
|
89 { |
|
90 DPRINT_METHODENTRYEXIT; |
|
91 |
|
92 destroyMessageBox(); |
|
93 |
|
94 QString lifeTimerData = constructLifeTimerData(); |
|
95 QString lifeTimerNoteText = |
|
96 hbTrId("txt_phone_info_life_timer").arg(lifeTimerData); |
|
97 m_messageBox = new HbDeviceMessageBox( |
|
98 lifeTimerNoteText, |
|
99 HbMessageBox::MessageTypeInformation); |
|
100 m_messageBox->setTimeout(HbPopup::NoTimeout); |
|
101 |
|
102 QObject::connect( |
|
103 m_messageBox, SIGNAL(aboutToClose()), |
|
104 this, SLOT(destroyMessageBox())); |
|
105 |
|
106 m_messageBox->show(); |
|
107 } |
|
108 |
|
109 |
|
110 /*! |
|
111 LifeTimerKeySequenceHandler::constructLifeTimerData. |
|
112 */ |
|
113 QString LifeTimerKeySequenceHandler::constructLifeTimerData() |
|
114 { |
|
115 DPRINT_METHODENTRYEXIT; |
|
116 |
|
117 QString lifeTimerText; |
|
118 |
|
119 RTelServer telephonyServer; |
|
120 RMobilePhone mobilePhone; |
|
121 RMmCustomAPI mmCustomApi; |
|
122 QT_TRAP_THROWING( |
|
123 openEtelConnectionL(telephonyServer, mobilePhone, mmCustomApi); |
|
124 ) |
|
125 |
|
126 RMmCustomAPI::TLifeTimeData lifeTimeData; |
|
127 RMmCustomAPI::TLifeTimeDataPckg dataPckg(lifeTimeData); |
|
128 int lifeTimeDataQueryResult = mmCustomApi.GetLifeTime(dataPckg); |
|
129 closeEtelConnection(telephonyServer, mobilePhone, mmCustomApi); |
|
130 |
|
131 if (KErrNone == lifeTimeDataQueryResult) { |
|
132 lifeTimeData = dataPckg(); |
|
133 |
|
134 HbExtendedLocale locale = HbExtendedLocale::system(); |
|
135 lifeTimerText.append(QString::number(lifeTimeData.iHours)); |
|
136 const int KMinuteSeparatorInd = 2; |
|
137 lifeTimerText.append(locale.timeSeparator(KMinuteSeparatorInd)); |
|
138 lifeTimerText.append( |
|
139 QString::number(static_cast<int>(lifeTimeData.iMinutes))); |
|
140 // pad hour field to a length of 6 digits |
|
141 const int KLifeTimerDataFieldLength = 9; |
|
142 lifeTimerText = lifeTimerText.rightJustified( |
|
143 KLifeTimerDataFieldLength, QChar('0')); |
|
144 } |
|
145 |
|
146 return lifeTimerText; |
|
147 } |
|
148 |
|
149 |
|
150 /*! |
|
151 LifeTimerKeySequenceHandler::openEtelConnectionL. |
|
152 */ |
|
153 void LifeTimerKeySequenceHandler::openEtelConnectionL( |
|
154 RTelServer &telephonyServer, |
|
155 RMobilePhone &mobilePhone, |
|
156 RMmCustomAPI &mmCustomApi) |
|
157 { |
|
158 DPRINT_METHODENTRYEXIT; |
|
159 |
|
160 User::LeaveIfError(telephonyServer.Connect()); |
|
161 User::LeaveIfError(mobilePhone.Open(telephonyServer, KMmTsyPhoneName())); |
|
162 User::LeaveIfError(mmCustomApi.Open(mobilePhone)); |
|
163 } |
|
164 |
|
165 |
|
166 /*! |
|
167 LifeTimerKeySequenceHandler::closeEtelConnection. |
|
168 */ |
|
169 void LifeTimerKeySequenceHandler::closeEtelConnection( |
|
170 RTelServer &telephonyServer, |
|
171 RMobilePhone &mobilePhone, |
|
172 RMmCustomAPI &mmCustomApi) |
|
173 { |
|
174 DPRINT_METHODENTRYEXIT; |
|
175 |
|
176 mmCustomApi.Close(); |
|
177 mobilePhone.Close(); |
|
178 telephonyServer.Close(); |
|
179 } |
|
180 |
|
181 |
|
182 /*! |
|
183 LifeTimerKeySequenceHandler::lifeTimerFeatureEnabled. |
|
184 */ |
|
185 bool LifeTimerKeySequenceHandler::lifeTimerFeatureEnabled() |
|
186 { |
|
187 DPRINT_METHODENTRYEXIT; |
|
188 |
|
189 TInt telephoneVariant = 0; |
|
190 TInt result = m_repository->Get(KTelSrvVariationFlags, telephoneVariant); |
|
191 return (KErrNone == result) |
|
192 ? static_cast<bool>(telephoneVariant & KTelSrvLVFlagLifeTimer) |
|
193 : false; |
|
194 } |
|
195 |
|
196 |
|
197 /*! |
|
198 LifeTimerKeySequenceHandler::destroyMessageBox. |
|
199 */ |
|
200 void LifeTimerKeySequenceHandler::destroyMessageBox() |
|
201 { |
|
202 DPRINT_METHODENTRYEXIT; |
|
203 |
|
204 if (m_messageBox) { |
|
205 m_messageBox->deleteLater(); |
|
206 m_messageBox = 0; |
|
207 } |
|
208 } |