|
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 <QtDebug> |
|
22 #include <QSignalMapper> |
|
23 #include <QTimer> |
|
24 #include <hbdevicemessagebox.h> |
|
25 #include <hbdeviceprogressdialog.h> |
|
26 #include <hbmessagebox.h> |
|
27 #include <hbprogressnote.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 qDebug() << "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 qDebug() << "PhoneNoteController::~PhoneNoteController"; |
|
43 if (m_timer) { |
|
44 delete m_timer; |
|
45 } |
|
46 } |
|
47 |
|
48 void PhoneNoteController::showGlobalNote(TPhoneCommandParam *commandParam) |
|
49 { |
|
50 qDebug() << "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 if (globalNoteParam->WaitForReady()) { |
|
73 HbDeviceMessageBox messageBox(noteString, type); |
|
74 messageBox.setTimeout(HbDialog::StandardTimeout); |
|
75 messageBox.exec(); |
|
76 } else { |
|
77 HbDeviceMessageBox *messageBox = new HbDeviceMessageBox( |
|
78 noteString, type); |
|
79 messageBox->setTimeout(HbDialog::StandardTimeout); |
|
80 m_messageBoxList.append(messageBox); |
|
81 |
|
82 if (1 == m_messageBoxList.size()) { |
|
83 QObject::connect(messageBox, SIGNAL(aboutToClose()), |
|
84 this, SLOT(destroyDialog())); |
|
85 messageBox->show(); |
|
86 } |
|
87 } |
|
88 } |
|
89 } |
|
90 |
|
91 void PhoneNoteController::showNote(TPhoneCommandParam *commandParam) |
|
92 { |
|
93 qDebug() << "PhoneNoteController::showNote"; |
|
94 |
|
95 TPhoneCmdParamNote* noteParam = static_cast<TPhoneCmdParamNote*>( |
|
96 commandParam ); |
|
97 |
|
98 if ( noteParam->Type() == EPhoneNoteDtmfSending ) { |
|
99 showDtmfNote(noteParam); |
|
100 } |
|
101 |
|
102 } |
|
103 |
|
104 void PhoneNoteController::showQuery(TPhoneCommandParam *commandParam) |
|
105 { |
|
106 qDebug() << "PhoneNoteController::showQuery"; |
|
107 TPhoneCmdParamQuery& params = *static_cast<TPhoneCmdParamQuery*>( commandParam ); |
|
108 |
|
109 if ( EPhoneQueryDialog == params.QueryType() && |
|
110 params.QueryPrompt().Length() ) { |
|
111 showDefaultQuery(¶ms); |
|
112 |
|
113 } else if ( EPhoneGlobalWaitNote == params.QueryType() ) { |
|
114 showGlobalWaitNote(¶ms); |
|
115 |
|
116 } |
|
117 |
|
118 |
|
119 } |
|
120 |
|
121 void PhoneNoteController::removeDtmfNote() |
|
122 { |
|
123 qDebug() << "PhoneNoteController::removeDtmfNote"; |
|
124 if (m_dtmfNote) { |
|
125 m_dtmfNote->close(); |
|
126 } |
|
127 } |
|
128 |
|
129 void PhoneNoteController::removeNote() |
|
130 { |
|
131 qDebug() << "PhoneNoteController::removeNote"; |
|
132 removeDtmfNote(); |
|
133 } |
|
134 |
|
135 void PhoneNoteController::removeQuery() |
|
136 { |
|
137 qDebug() << "PhoneNoteController::removeQuery"; |
|
138 if (m_queryNote) { |
|
139 m_queryNote->close(); |
|
140 } |
|
141 } |
|
142 |
|
143 void PhoneNoteController::removeGlobalWaitNote() |
|
144 { |
|
145 qDebug() << "PhoneNoteController::removeGlobalWaitNote"; |
|
146 if (m_timer) { |
|
147 m_timeoutCommand = -1; |
|
148 m_timer->stop(); |
|
149 } |
|
150 |
|
151 if (m_progressDialog) { |
|
152 m_queryCanceledCommand = -1; |
|
153 m_progressDialog->cancel(); |
|
154 } |
|
155 } |
|
156 |
|
157 void PhoneNoteController::destroyDialog() |
|
158 { |
|
159 qDebug() << "PhoneNoteController::destroyDialog"; |
|
160 HbDeviceMessageBox *messageBox = m_messageBoxList.takeFirst(); |
|
161 messageBox->deleteLater(); |
|
162 messageBox = 0; |
|
163 |
|
164 if ( 0 < m_messageBoxList.size() ) { |
|
165 qDebug() << "PhoneNoteController::show pending note"; |
|
166 HbDeviceMessageBox *messageBoxTemp = m_messageBoxList[0]; |
|
167 QObject::connect(messageBoxTemp, SIGNAL(aboutToClose()), |
|
168 this, SLOT(destroyDialog())); |
|
169 messageBoxTemp->show(); |
|
170 } |
|
171 } |
|
172 |
|
173 void PhoneNoteController::removeMappings() |
|
174 { |
|
175 foreach (HbAction *action, m_actions ) { |
|
176 m_signalMapper->removeMappings(action); |
|
177 } |
|
178 m_actions.clear(); |
|
179 |
|
180 if (m_dtmfNote) { |
|
181 m_dtmfNote->deleteLater(); |
|
182 m_dtmfNote = 0; |
|
183 } |
|
184 if (m_queryNote) { |
|
185 m_queryNote->deleteLater(); |
|
186 m_queryNote = 0; |
|
187 } |
|
188 if (m_progressDialog) { |
|
189 m_progressDialog->deleteLater(); |
|
190 m_progressDialog = 0; |
|
191 } |
|
192 } |
|
193 |
|
194 void PhoneNoteController::queryCancelled() |
|
195 { |
|
196 if (m_timer) { |
|
197 m_timer->stop(); |
|
198 } |
|
199 |
|
200 if (m_queryCanceledCommand != -1) { |
|
201 emit command(m_queryCanceledCommand); |
|
202 } |
|
203 m_queryCanceledCommand = -1; |
|
204 m_timeoutCommand = -1; |
|
205 } |
|
206 |
|
207 void PhoneNoteController::queryTimeout() |
|
208 { |
|
209 int sendCommand = m_timeoutCommand; |
|
210 if (m_progressDialog) { |
|
211 m_queryCanceledCommand = -1; |
|
212 m_progressDialog->cancel(); |
|
213 } |
|
214 if (sendCommand != -1) { |
|
215 emit command(sendCommand); |
|
216 } |
|
217 } |
|
218 |
|
219 QString PhoneNoteController::globalNoteText( |
|
220 TPhoneCommandParam *commandParam) |
|
221 { |
|
222 TPhoneCmdParamGlobalNote* globalNoteParam = |
|
223 static_cast<TPhoneCmdParamGlobalNote*>( commandParam ); |
|
224 |
|
225 QString ret; |
|
226 |
|
227 if ( globalNoteParam->TextResourceId() && |
|
228 KErrNone != globalNoteParam->Text().Compare( KNullDesC() ) ) { |
|
229 // resource and text exists |
|
230 ret = PhoneResourceAdapter::Instance()->convertToString( |
|
231 globalNoteParam->TextResourceId(), |
|
232 QString::fromUtf16(globalNoteParam->Text().Ptr(), |
|
233 globalNoteParam->Text().Length()) ); |
|
234 } else if ( globalNoteParam->TextResourceId() ) { |
|
235 // resource exists |
|
236 ret = PhoneResourceAdapter::Instance()->convertToString( |
|
237 globalNoteParam->TextResourceId()); |
|
238 |
|
239 } else if ( KErrNone != globalNoteParam->Text().Compare( KNullDesC() ) ) { |
|
240 // text exists |
|
241 ret = QString::fromUtf16(globalNoteParam->Text().Ptr(), |
|
242 globalNoteParam->Text().Length()); |
|
243 } |
|
244 |
|
245 return ret; |
|
246 } |
|
247 |
|
248 void PhoneNoteController::showDtmfNote(TPhoneCmdParamNote* noteParam) |
|
249 { |
|
250 if (m_dtmfNote) { |
|
251 m_dtmfNote->setText( QString::fromUtf16(noteParam->Text().Ptr(), |
|
252 noteParam->Text().Length()) ); |
|
253 m_dtmfNote->update(); |
|
254 } else { |
|
255 QList<HbAction*> hbactions = PhoneResourceAdapter::Instance()-> |
|
256 convertToHbActions(noteParam->ResourceId()); |
|
257 |
|
258 if (hbactions.count() > 0) { |
|
259 m_dtmfNote = new HbProgressNote(HbProgressNote::ProgressNote); |
|
260 m_dtmfNote->setText( QString::fromUtf16(noteParam->Text().Ptr(), |
|
261 noteParam->Text().Length()) ); |
|
262 |
|
263 connect(hbactions.at(0), SIGNAL(triggered()), m_signalMapper, SLOT(map())); |
|
264 m_dtmfNote->setPrimaryAction(hbactions.at(0)); |
|
265 m_signalMapper->setMapping(hbactions.at(0), hbactions.at(0)->data().toInt()); |
|
266 |
|
267 QObject::connect(m_dtmfNote, SIGNAL(aboutToClose()), |
|
268 this, SLOT(removeMappings())); |
|
269 |
|
270 m_actions.append(hbactions.at(0)); |
|
271 |
|
272 m_dtmfNote->show(); |
|
273 } |
|
274 } |
|
275 } |
|
276 |
|
277 void PhoneNoteController::showDefaultQuery(TPhoneCmdParamQuery* params) |
|
278 { |
|
279 if (!m_queryNote) { |
|
280 QList<HbAction*> hbactions = PhoneResourceAdapter::Instance()-> |
|
281 convertToHbActions(params->QueryResourceId()); |
|
282 |
|
283 if (hbactions.count() > 0) { |
|
284 m_queryNote = new HbMessageBox(HbMessageBox::MessageTypeQuestion); |
|
285 m_queryNote->setTimeout(HbPopup::NoTimeout); |
|
286 m_queryNote->setDismissPolicy(HbPopup::NoDismiss); |
|
287 m_queryNote->setText(QString::fromUtf16(params->QueryPrompt().Ptr(), |
|
288 params->QueryPrompt().Length())); |
|
289 |
|
290 QObject::connect(m_queryNote, SIGNAL(aboutToClose()), |
|
291 this, SLOT(removeMappings())); |
|
292 |
|
293 for (int i = 0; i < hbactions.count(); ++i) { |
|
294 connect(hbactions.at(i), SIGNAL(triggered()), m_signalMapper, SLOT(map())); |
|
295 m_signalMapper->setMapping(hbactions.at(i), hbactions.at(i)->data().toInt()); |
|
296 m_actions.append(hbactions.at(i)); |
|
297 } |
|
298 |
|
299 if (hbactions.count() == 1) { |
|
300 m_queryNote->setPrimaryAction(hbactions.at(0)); |
|
301 } else if (hbactions.count() > 1) { |
|
302 m_queryNote->setPrimaryAction(hbactions.at(0)); |
|
303 m_queryNote->setSecondaryAction(hbactions.at(1)); |
|
304 } |
|
305 |
|
306 m_queryNote->show(); |
|
307 } |
|
308 } |
|
309 } |
|
310 |
|
311 void PhoneNoteController::showGlobalWaitNote(TPhoneCmdParamQuery* params) |
|
312 { |
|
313 if (!m_progressDialog) { |
|
314 m_queryCanceledCommand = params->CbaCommandMapping(EAknSoftkeyCancel); |
|
315 |
|
316 m_progressDialog = new HbDeviceProgressDialog(HbProgressNote::WaitNote); |
|
317 |
|
318 if (params->QueryPrompt().Length()) { |
|
319 m_progressDialog->setText(QString::fromUtf16(params->QueryPrompt().Ptr(), |
|
320 params->QueryPrompt().Length())); |
|
321 } else if (0 != params->DataText()) { |
|
322 m_progressDialog->setText(QString::fromUtf16(params->DataText()->Ptr(), |
|
323 params->DataText()->Length())); |
|
324 } |
|
325 |
|
326 QObject::connect(m_progressDialog, SIGNAL(aboutToClose()), |
|
327 this, SLOT(removeMappings())); |
|
328 |
|
329 QObject::connect(m_progressDialog, SIGNAL(cancelled()), |
|
330 this, SLOT(queryCancelled())); |
|
331 |
|
332 if (params->TimeOut() != 0) { |
|
333 if (!m_timer) { |
|
334 m_timer = new QTimer(); |
|
335 m_timer->setSingleShot(true); |
|
336 connect(m_timer, SIGNAL(timeout()), SLOT(queryTimeout())); |
|
337 } |
|
338 |
|
339 m_timeoutCommand = -1; |
|
340 int customCommand; |
|
341 if (-1 != params->GetCustomCommandForTimeOut(customCommand)) { |
|
342 m_timeoutCommand = customCommand; |
|
343 } |
|
344 |
|
345 m_timer->start(params->TimeOut()); |
|
346 } |
|
347 |
|
348 m_progressDialog->show(); |
|
349 } |
|
350 } |
|
351 |
|
352 |