1 /*! |
|
2 * Copyright (c) 2009 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: Handles phone notes. |
|
15 */ |
|
16 |
|
17 #include "phonenotecontroller.h" |
|
18 #include "tphonecmdparamglobalnote.h" |
|
19 #include "tphonecmdparamquery.h" |
|
20 #include "phoneresourceadapter.h" |
|
21 #include "qtphonelog.h" |
|
22 #include <QSignalMapper> |
|
23 #include <QTimer> |
|
24 #include <hbdevicemessagebox.h> |
|
25 #include <hbdeviceprogressdialog.h> |
|
26 #include <hbmessagebox.h> |
|
27 #include <hbprogressdialog.h> |
|
28 #include <hbaction.h> |
|
29 #include <phoneappcommands.hrh> |
|
30 |
|
31 PhoneNoteController::PhoneNoteController(QObject *parent) : |
|
32 QObject(parent), m_timer(0), m_progressDialog(0), m_dtmfNote(0), |
|
33 m_queryNote(0), m_queryCanceledCommand(-1), m_timeoutCommand(-1) |
|
34 { |
|
35 PHONE_DEBUG("PhoneNoteController::PhoneNoteController"); |
|
36 m_signalMapper = new QSignalMapper(this); |
|
37 connect(m_signalMapper, SIGNAL(mapped(int)), this, SIGNAL(command (int))); |
|
38 } |
|
39 |
|
40 PhoneNoteController::~PhoneNoteController() |
|
41 { |
|
42 PHONE_DEBUG("PhoneNoteController::~PhoneNoteController"); |
|
43 if (m_timer) { |
|
44 delete m_timer; |
|
45 } |
|
46 } |
|
47 |
|
48 void PhoneNoteController::showGlobalNote(TPhoneCommandParam *commandParam) |
|
49 { |
|
50 PHONE_DEBUG("PhoneNoteController::showGlobalNote"); |
|
51 Q_ASSERT (commandParam->ParamId () == TPhoneCommandParam::EPhoneParamIdGlobalNote); |
|
52 |
|
53 TPhoneCmdParamGlobalNote* globalNoteParam = |
|
54 static_cast<TPhoneCmdParamGlobalNote*>( commandParam ); |
|
55 |
|
56 |
|
57 HbMessageBox::MessageBoxType type; |
|
58 |
|
59 switch( globalNoteParam->Type() ) { |
|
60 case EAknGlobalInformationNote: |
|
61 type = HbMessageBox::MessageTypeInformation; |
|
62 break; |
|
63 case EAknGlobalWarningNote: |
|
64 default: |
|
65 type = HbMessageBox::MessageTypeWarning; |
|
66 break; |
|
67 } |
|
68 |
|
69 QString noteString = globalNoteText(globalNoteParam); |
|
70 |
|
71 if (false == noteString.isNull()) { |
|
72 bool showNote(true); |
|
73 for (int i = 0; i < m_messageBoxList.count(); ++i) { |
|
74 // Do not show same note/text several times, e.g when user hits |
|
75 // the end button several times we should show only one "not allowed" |
|
76 // note. |
|
77 if (noteString == m_messageBoxList.at(i)->text()) { |
|
78 showNote = false; |
|
79 break; |
|
80 } |
|
81 } |
|
82 |
|
83 if (showNote) { |
|
84 QScopedPointer<HbDeviceMessageBox> messageBox( |
|
85 new HbDeviceMessageBox(noteString, type)); |
|
86 |
|
87 int timeout = globalNoteParam->Timeout(); |
|
88 if (timeout == 0) { |
|
89 messageBox->setTimeout(HbDialog::StandardTimeout); |
|
90 } else { |
|
91 messageBox->setTimeout(timeout); |
|
92 } |
|
93 |
|
94 HbDeviceMessageBox *messageBoxPtr = messageBox.data(); |
|
95 m_messageBoxList.append(messageBoxPtr); |
|
96 messageBox.take(); |
|
97 |
|
98 if (1 == m_messageBoxList.size()) { |
|
99 QObject::connect(messageBoxPtr, SIGNAL(aboutToClose()), |
|
100 this, SLOT(destroyDialog())); |
|
101 messageBoxPtr->show(); |
|
102 } |
|
103 } |
|
104 } |
|
105 } |
|
106 |
|
107 void PhoneNoteController::showNote(TPhoneCommandParam *commandParam) |
|
108 { |
|
109 PHONE_DEBUG("PhoneNoteController::showNote"); |
|
110 |
|
111 TPhoneCmdParamNote* noteParam = static_cast<TPhoneCmdParamNote*>( |
|
112 commandParam ); |
|
113 |
|
114 if ( noteParam->Type() == EPhoneNoteDtmfSending ) { |
|
115 showDtmfNote(noteParam); |
|
116 } |
|
117 |
|
118 } |
|
119 |
|
120 void PhoneNoteController::showQuery(TPhoneCommandParam *commandParam) |
|
121 { |
|
122 PHONE_DEBUG("PhoneNoteController::showQuery"); |
|
123 TPhoneCmdParamQuery& params = *static_cast<TPhoneCmdParamQuery*>( commandParam ); |
|
124 |
|
125 if ( EPhoneQueryDialog == params.QueryType() && |
|
126 params.QueryPrompt().Length() ) { |
|
127 showDefaultQuery(¶ms); |
|
128 |
|
129 } else if ( EPhoneGlobalWaitNote == params.QueryType() ) { |
|
130 showGlobalWaitNote(¶ms); |
|
131 |
|
132 } |
|
133 |
|
134 |
|
135 } |
|
136 |
|
137 void PhoneNoteController::removeDtmfNote() |
|
138 { |
|
139 PHONE_DEBUG("PhoneNoteController::removeDtmfNote"); |
|
140 if (m_dtmfNote) { |
|
141 m_dtmfNote->close(); |
|
142 } |
|
143 } |
|
144 |
|
145 void PhoneNoteController::removeNote() |
|
146 { |
|
147 PHONE_DEBUG("PhoneNoteController::removeNote"); |
|
148 removeDtmfNote(); |
|
149 } |
|
150 |
|
151 void PhoneNoteController::removeQuery() |
|
152 { |
|
153 PHONE_DEBUG("PhoneNoteController::removeQuery"); |
|
154 if (m_queryNote) { |
|
155 m_queryNote->close(); |
|
156 } |
|
157 } |
|
158 |
|
159 void PhoneNoteController::removeGlobalWaitNote() |
|
160 { |
|
161 PHONE_DEBUG("PhoneNoteController::removeGlobalWaitNote"); |
|
162 if (m_timer) { |
|
163 m_timeoutCommand = -1; |
|
164 m_timer->stop(); |
|
165 } |
|
166 |
|
167 if (m_progressDialog) { |
|
168 m_queryCanceledCommand = -1; |
|
169 m_progressDialog->close(); |
|
170 } |
|
171 } |
|
172 |
|
173 void PhoneNoteController::destroyDialog() |
|
174 { |
|
175 PHONE_DEBUG("PhoneNoteController::destroyDialog"); |
|
176 HbDeviceMessageBox *messageBox = m_messageBoxList.takeFirst(); |
|
177 messageBox->deleteLater(); |
|
178 messageBox = 0; |
|
179 |
|
180 if ( 0 < m_messageBoxList.size() ) { |
|
181 PHONE_DEBUG("PhoneNoteController::show pending note"); |
|
182 HbDeviceMessageBox *messageBoxTemp = m_messageBoxList[0]; |
|
183 QObject::connect(messageBoxTemp, SIGNAL(aboutToClose()), |
|
184 this, SLOT(destroyDialog())); |
|
185 messageBoxTemp->show(); |
|
186 } |
|
187 } |
|
188 |
|
189 void PhoneNoteController::removeMappings() |
|
190 { |
|
191 foreach (HbAction *action, m_actions ) { |
|
192 m_signalMapper->removeMappings(action); |
|
193 } |
|
194 m_actions.clear(); |
|
195 |
|
196 if (m_dtmfNote) { |
|
197 m_dtmfNote->deleteLater(); |
|
198 m_dtmfNote = 0; |
|
199 } |
|
200 if (m_queryNote) { |
|
201 m_queryNote->deleteLater(); |
|
202 m_queryNote = 0; |
|
203 } |
|
204 if (m_progressDialog) { |
|
205 m_progressDialog->deleteLater(); |
|
206 m_progressDialog = 0; |
|
207 } |
|
208 } |
|
209 |
|
210 void PhoneNoteController::queryCancelled() |
|
211 { |
|
212 if (m_timer) { |
|
213 m_timer->stop(); |
|
214 } |
|
215 |
|
216 if (m_queryCanceledCommand != -1) { |
|
217 emit command(m_queryCanceledCommand); |
|
218 } |
|
219 m_queryCanceledCommand = -1; |
|
220 m_timeoutCommand = -1; |
|
221 } |
|
222 |
|
223 void PhoneNoteController::queryTimeout() |
|
224 { |
|
225 int sendCommand = m_timeoutCommand; |
|
226 if (m_progressDialog) { |
|
227 m_queryCanceledCommand = -1; |
|
228 m_progressDialog->close(); |
|
229 } |
|
230 if (sendCommand != -1) { |
|
231 emit command(sendCommand); |
|
232 } |
|
233 } |
|
234 |
|
235 QString PhoneNoteController::globalNoteText( |
|
236 TPhoneCommandParam *commandParam) |
|
237 { |
|
238 TPhoneCmdParamGlobalNote* globalNoteParam = |
|
239 static_cast<TPhoneCmdParamGlobalNote*>( commandParam ); |
|
240 |
|
241 QString ret; |
|
242 |
|
243 if ( globalNoteParam->TextResourceId() && |
|
244 KErrNone != globalNoteParam->Text().Compare( KNullDesC() ) ) { |
|
245 // resource and text exists |
|
246 ret = PhoneResourceAdapter::Instance()->convertToString( |
|
247 globalNoteParam->TextResourceId(), |
|
248 QString::fromUtf16(globalNoteParam->Text().Ptr(), |
|
249 globalNoteParam->Text().Length()) ); |
|
250 } else if ( globalNoteParam->TextResourceId() ) { |
|
251 // resource exists |
|
252 ret = PhoneResourceAdapter::Instance()->convertToString( |
|
253 globalNoteParam->TextResourceId()); |
|
254 |
|
255 } else if ( KErrNone != globalNoteParam->Text().Compare( KNullDesC() ) ) { |
|
256 // text exists |
|
257 ret = QString::fromUtf16(globalNoteParam->Text().Ptr(), |
|
258 globalNoteParam->Text().Length()); |
|
259 } |
|
260 |
|
261 return ret; |
|
262 } |
|
263 |
|
264 void PhoneNoteController::showDtmfNote(TPhoneCmdParamNote* noteParam) |
|
265 { |
|
266 if (m_dtmfNote) { |
|
267 m_dtmfNote->setText( QString::fromUtf16(noteParam->Text().Ptr(), |
|
268 noteParam->Text().Length()) ); |
|
269 m_dtmfNote->update(); |
|
270 } else { |
|
271 QList<HbAction*> hbactions = PhoneResourceAdapter::Instance()-> |
|
272 convertToHbActions(noteParam->ResourceId()); |
|
273 |
|
274 if (hbactions.count() > 0) { |
|
275 m_dtmfNote = new HbProgressDialog(HbProgressDialog::ProgressDialog); |
|
276 m_dtmfNote->setText( QString::fromUtf16(noteParam->Text().Ptr(), |
|
277 noteParam->Text().Length()) ); |
|
278 |
|
279 connect(hbactions.at(0), SIGNAL(triggered()), m_signalMapper, SLOT(map())); |
|
280 |
|
281 int count = m_dtmfNote->actions().count(); |
|
282 for (int i=count;0<i;i--) { |
|
283 QAction *action = m_dtmfNote->actions().at(i-1); |
|
284 m_dtmfNote->removeAction(action); |
|
285 //TODO |
|
286 //delete action; |
|
287 } |
|
288 m_dtmfNote->addAction(hbactions.at(0)); |
|
289 m_signalMapper->setMapping(hbactions.at(0), hbactions.at(0)->data().toInt()); |
|
290 |
|
291 QObject::connect(m_dtmfNote, SIGNAL(aboutToClose()), |
|
292 this, SLOT(removeMappings())); |
|
293 |
|
294 m_actions.append(hbactions.at(0)); |
|
295 |
|
296 m_dtmfNote->show(); |
|
297 } |
|
298 } |
|
299 } |
|
300 |
|
301 void PhoneNoteController::showDefaultQuery(TPhoneCmdParamQuery* params) |
|
302 { |
|
303 if (!m_queryNote) { |
|
304 QList<HbAction*> hbactions = PhoneResourceAdapter::Instance()-> |
|
305 convertToHbActions(params->QueryResourceId()); |
|
306 |
|
307 if (hbactions.count() > 0) { |
|
308 m_queryNote = new HbMessageBox(HbMessageBox::MessageTypeQuestion); |
|
309 m_queryNote->setTimeout(HbPopup::NoTimeout); |
|
310 m_queryNote->setDismissPolicy(HbPopup::NoDismiss); |
|
311 m_queryNote->setText(QString::fromUtf16(params->QueryPrompt().Ptr(), |
|
312 params->QueryPrompt().Length())); |
|
313 |
|
314 QObject::connect(m_queryNote, SIGNAL(aboutToClose()), |
|
315 this, SLOT(removeMappings())); |
|
316 |
|
317 for (int i = 0; i < hbactions.count(); ++i) { |
|
318 connect(hbactions.at(i), SIGNAL(triggered()), m_signalMapper, SLOT(map())); |
|
319 m_signalMapper->setMapping(hbactions.at(i), hbactions.at(i)->data().toInt()); |
|
320 m_actions.append(hbactions.at(i)); |
|
321 } |
|
322 |
|
323 int count = m_queryNote->actions().count(); |
|
324 for (int i=count;0<i;i--) { |
|
325 QAction *action = m_queryNote->actions().at(i-1); |
|
326 m_queryNote->removeAction(action); |
|
327 //TODO |
|
328 //delete action; |
|
329 } |
|
330 |
|
331 for (int i=0;i<hbactions.count();i++) { |
|
332 m_queryNote->addAction(hbactions.at(i)); |
|
333 } |
|
334 |
|
335 m_queryNote->show(); |
|
336 } |
|
337 } |
|
338 } |
|
339 |
|
340 void PhoneNoteController::showGlobalWaitNote(TPhoneCmdParamQuery* params) |
|
341 { |
|
342 if (!m_progressDialog) { |
|
343 m_queryCanceledCommand = params->CbaCommandMapping(EAknSoftkeyCancel); |
|
344 |
|
345 m_progressDialog = new HbDeviceProgressDialog(HbProgressDialog::WaitDialog); |
|
346 |
|
347 if (params->QueryPrompt().Length()) { |
|
348 m_progressDialog->setText(QString::fromUtf16(params->QueryPrompt().Ptr(), |
|
349 params->QueryPrompt().Length())); |
|
350 } else if (0 != params->DataText()) { |
|
351 m_progressDialog->setText(QString::fromUtf16(params->DataText()->Ptr(), |
|
352 params->DataText()->Length())); |
|
353 } |
|
354 |
|
355 QObject::connect(m_progressDialog, SIGNAL(aboutToClose()), |
|
356 this, SLOT(removeMappings())); |
|
357 |
|
358 QObject::connect(m_progressDialog, SIGNAL(cancelled()), |
|
359 this, SLOT(queryCancelled())); |
|
360 |
|
361 if (params->TimeOut() != 0) { |
|
362 if (!m_timer) { |
|
363 m_timer = new QTimer(); |
|
364 m_timer->setSingleShot(true); |
|
365 connect(m_timer, SIGNAL(timeout()), SLOT(queryTimeout())); |
|
366 } |
|
367 |
|
368 m_timeoutCommand = -1; |
|
369 int customCommand; |
|
370 if (-1 != params->GetCustomCommandForTimeOut(customCommand)) { |
|
371 m_timeoutCommand = customCommand; |
|
372 } |
|
373 |
|
374 m_timer->start(params->TimeOut()); |
|
375 } |
|
376 |
|
377 m_progressDialog->show(); |
|
378 } |
|
379 } |
|
380 |
|
381 |
|