65
|
1 |
/*
|
|
2 |
* cpdivertquery.cpp
|
|
3 |
*
|
|
4 |
* Created on: Aug 10, 2010
|
|
5 |
* Author: jahelaak
|
|
6 |
*/
|
|
7 |
|
|
8 |
#include "cpdivertquery.h"
|
|
9 |
#include "cpplugincommon.h"
|
|
10 |
#include "cppluginlogging.h"
|
|
11 |
#include <psuinotes.h>
|
|
12 |
#include <hblineedit.h>
|
|
13 |
#include <hbinputeditorinterface.h>
|
|
14 |
#include <hbcombobox.h>
|
|
15 |
#include <hbdeviceprogressdialog.h>
|
|
16 |
#include <hbaction.h>
|
|
17 |
#include <hblistwidget.h>
|
|
18 |
#include <hblistwidgetitem.h>
|
|
19 |
#include <hblabel.h>
|
|
20 |
#include <hbdevicemessagebox.h>
|
|
21 |
#include <hbparameterlengthlimiter.h>
|
|
22 |
|
|
23 |
|
|
24 |
// CONSTANTS
|
|
25 |
const QString KOtherNumber("otherNumber");
|
|
26 |
|
|
27 |
CpDivertQuery::CpDivertQuery(PSetCallDivertingWrapper &callDivertingWrapper) :
|
|
28 |
m_callDivertingWrapper(callDivertingWrapper),
|
|
29 |
m_activateDivertPhase(NonePhase),
|
|
30 |
m_needTimeOutInfo(false),
|
|
31 |
m_dialog(0)
|
|
32 |
{
|
|
33 |
|
|
34 |
}
|
|
35 |
|
|
36 |
CpDivertQuery::~CpDivertQuery()
|
|
37 |
{
|
|
38 |
delete m_dialog;
|
|
39 |
}
|
|
40 |
|
|
41 |
|
|
42 |
void CpDivertQuery::show(
|
|
43 |
const QString &heading,
|
|
44 |
PSCallDivertingCommand command,
|
|
45 |
bool needTimeOutInfo)
|
|
46 |
{
|
|
47 |
m_divertCommand = command;
|
|
48 |
m_needTimeOutInfo = needTimeOutInfo;
|
|
49 |
m_activateDivertPhase = PopUpVoiceNumberListQueryPhase;
|
|
50 |
popUpVoiceNumberListQuery(heading, m_divertCommand.iServiceGroup);
|
|
51 |
}
|
|
52 |
|
|
53 |
/*!
|
|
54 |
CpDivertQuery::popUpVoiceNumberListQuery.
|
|
55 |
*/
|
|
56 |
void CpDivertQuery::popUpVoiceNumberListQuery(
|
|
57 |
const QString& heading, PsServiceGroup serviceGroup)
|
|
58 |
{
|
|
59 |
DPRINT << ": IN";
|
|
60 |
if (m_dialog) {
|
|
61 |
m_dialog->deleteLater();
|
|
62 |
m_dialog = NULL;
|
|
63 |
}
|
|
64 |
|
|
65 |
m_divertCommand.iNumber.clear();
|
|
66 |
QStringList defNumbers;
|
|
67 |
QScopedPointer<HbDialog> dialog(createDialog(heading));
|
|
68 |
HbListWidget *list = new HbListWidget(dialog.data());
|
|
69 |
|
|
70 |
QString vmbxNumber;
|
|
71 |
int vmbxErr = 0;
|
|
72 |
if (serviceGroup == ServiceGroupVoice) {
|
|
73 |
vmbxErr = m_callDivertingWrapper.getVoiceMailBoxNumber(
|
|
74 |
vmbxNumber, ServiceGroupVoice);
|
|
75 |
|
|
76 |
} else if(serviceGroup == ServiceGroupData) {
|
|
77 |
vmbxErr = m_callDivertingWrapper.getVoiceMailBoxNumber(
|
|
78 |
vmbxNumber, ServiceGroupData);
|
|
79 |
|
|
80 |
} else {
|
|
81 |
vmbxErr = -1;
|
|
82 |
// Skip
|
|
83 |
}
|
|
84 |
|
|
85 |
if (!vmbxErr) {
|
|
86 |
if (serviceGroup == ServiceGroupVoice) {
|
|
87 |
addItemToListWidget(
|
|
88 |
list,
|
|
89 |
hbTrId("txt_phone_list_to_voice_mailbox"),
|
|
90 |
vmbxNumber );
|
|
91 |
|
|
92 |
} else {
|
|
93 |
addItemToListWidget(
|
|
94 |
list,
|
|
95 |
hbTrId("txt_phone_setlabel_video_mbx"),
|
|
96 |
vmbxNumber );
|
|
97 |
}
|
|
98 |
}
|
|
99 |
|
|
100 |
// Add "old" divert number to list
|
|
101 |
m_callDivertingWrapper.getDefaultNumbers(defNumbers);
|
|
102 |
int count(defNumbers.count());
|
|
103 |
for (int i = 0; i < count; i++) {
|
|
104 |
addItemToListWidget(list, defNumbers[i], defNumbers[i]);
|
|
105 |
}
|
|
106 |
addItemToListWidget(
|
|
107 |
list,
|
|
108 |
hbTrId("txt_phone_list_enter_number_manually"),
|
|
109 |
KOtherNumber );
|
|
110 |
dialog->setContentWidget(list);
|
|
111 |
|
|
112 |
// Connect list item activation signal to close the popup
|
|
113 |
QObject::connect(list,
|
|
114 |
SIGNAL(activated(HbListWidgetItem*)),
|
|
115 |
dialog.data(),
|
|
116 |
SLOT(close()),
|
|
117 |
Qt::UniqueConnection);
|
|
118 |
|
|
119 |
// Sets the "Cancel"-action/button
|
|
120 |
HbAction *cancelAction = new HbAction(hbTrId(
|
|
121 |
"txt_common_button_cancel"),
|
|
122 |
dialog.data());
|
|
123 |
dialog->addAction(cancelAction);
|
|
124 |
QObject::connect(cancelAction,
|
|
125 |
SIGNAL(triggered(bool)),
|
|
126 |
dialog.data(),
|
|
127 |
SLOT(close()));
|
|
128 |
|
|
129 |
dialog->open(this, SLOT(voiceNumberListQueryClosed(HbAction *)));
|
|
130 |
m_dialog = dialog.take();
|
|
131 |
DPRINT << ": OUT";
|
|
132 |
}
|
|
133 |
|
|
134 |
|
|
135 |
/*!
|
|
136 |
CpDivertQuery::voiceNumberListQueryClosed()
|
|
137 |
*/
|
|
138 |
void CpDivertQuery::voiceNumberListQueryClosed(HbAction* action)
|
|
139 |
{
|
|
140 |
DPRINT << ": IN";
|
|
141 |
HbListWidget *list(NULL);
|
|
142 |
m_divertCommand.iNumber.clear();
|
|
143 |
bool processNextPhase(true);
|
|
144 |
int queryResult(0);
|
|
145 |
|
|
146 |
if (m_dialog) {
|
|
147 |
bool err = QObject::disconnect(m_dialog->contentWidget(),
|
|
148 |
SIGNAL(activated(HbListWidgetItem*)),
|
|
149 |
m_dialog,
|
|
150 |
SLOT(close()));
|
|
151 |
list = qobject_cast<HbListWidget*>(m_dialog->contentWidget());
|
|
152 |
m_dialog->deleteLater();
|
|
153 |
m_dialog = NULL;
|
|
154 |
}
|
|
155 |
|
|
156 |
// Enter if cancel wasn't selected
|
|
157 |
if (!action && list) {
|
|
158 |
// Update the view with selected text
|
|
159 |
QString data = list->currentItem()->data().toString();
|
|
160 |
QString text = list->currentItem()->text();
|
|
161 |
|
|
162 |
DPRINT << ": data: " << data;
|
|
163 |
DPRINT << ": text: " << text;
|
|
164 |
|
|
165 |
if (data == KOtherNumber) {
|
|
166 |
DPRINT << ": open popUpNumberEditor";
|
|
167 |
processNextPhase = false;
|
|
168 |
popUpNumberEditor(hbTrId("txt_phone_info_number"));
|
|
169 |
} else if (text == hbTrId("txt_phone_list_to_voice_mailbox")) {
|
|
170 |
DPRINT << ": get voicemailboxnumber";
|
|
171 |
m_callDivertingWrapper.getVoiceMailBoxNumber(
|
|
172 |
m_divertCommand.iNumber, ServiceGroupVoice);
|
|
173 |
if (m_divertCommand.iNumber.isEmpty()) {
|
|
174 |
DPRINT << ": voicemailboxnumber query";
|
|
175 |
queryResult = m_callDivertingWrapper.queryVoiceMailBoxNumber(
|
|
176 |
m_divertCommand.iNumber, ServiceGroupVoice);
|
|
177 |
}
|
|
178 |
} else if (text == hbTrId("txt_phone_setlabel_video_mbx")) {
|
|
179 |
DPRINT << ": get videomailboxnumber";
|
|
180 |
m_callDivertingWrapper.getVoiceMailBoxNumber(
|
|
181 |
m_divertCommand.iNumber, ServiceGroupData);
|
|
182 |
if (m_divertCommand.iNumber.isEmpty()) {
|
|
183 |
DPRINT << ": videomailboxnumber query";
|
|
184 |
queryResult = m_callDivertingWrapper.queryVoiceMailBoxNumber(
|
|
185 |
m_divertCommand.iNumber, ServiceGroupData);
|
|
186 |
}
|
|
187 |
} else {
|
|
188 |
//TODO if matched contact name not work
|
|
189 |
DPRINT << ": else";
|
|
190 |
m_divertCommand.iNumber = data;
|
|
191 |
}
|
|
192 |
}
|
|
193 |
if(KErrNone != queryResult){
|
|
194 |
emit handleDivertingError(queryResult);
|
|
195 |
processNextPhase = false;
|
|
196 |
m_activateDivertPhase = NonePhase;
|
|
197 |
}
|
|
198 |
DPRINT << ": processNextPhase: " << processNextPhase;
|
|
199 |
DPRINT << ": m_divertCommand.iNumber: " << m_divertCommand.iNumber;
|
|
200 |
if (processNextPhase) {
|
|
201 |
if (m_divertCommand.iNumber.isEmpty()) {
|
|
202 |
nextPhaseForActivateDivert(false);
|
|
203 |
} else {
|
|
204 |
nextPhaseForActivateDivert(true);
|
|
205 |
}
|
|
206 |
}
|
|
207 |
|
|
208 |
DPRINT << ": OUT";
|
|
209 |
}
|
|
210 |
|
|
211 |
|
|
212 |
/*!
|
|
213 |
CpDivertQuery::popUpNumberEditor.
|
|
214 |
*/
|
|
215 |
void CpDivertQuery::popUpNumberEditor(
|
|
216 |
const QString& heading)
|
|
217 |
{
|
|
218 |
DPRINT << ": IN";
|
|
219 |
|
|
220 |
if (m_dialog) {
|
|
221 |
m_dialog->deleteLater();
|
|
222 |
m_dialog = NULL;
|
|
223 |
}
|
|
224 |
QScopedPointer<HbDialog> dialog(createDialog(heading));
|
|
225 |
|
|
226 |
HbLineEdit *editor = new HbLineEdit(dialog.data());
|
|
227 |
editor->setInputMethodHints(Qt::ImhDialableCharactersOnly);
|
|
228 |
//Ownership is transferred
|
|
229 |
dialog->setContentWidget(editor);
|
|
230 |
|
|
231 |
HbAction *okAction = new HbAction(
|
|
232 |
hbTrId("txt_common_button_ok"),
|
|
233 |
dialog.data());
|
|
234 |
dialog->addAction(okAction);
|
|
235 |
|
|
236 |
HbAction *cancelAction = new HbAction(
|
|
237 |
hbTrId("txt_common_button_cancel"),
|
|
238 |
dialog.data());
|
|
239 |
dialog->addAction(cancelAction);
|
|
240 |
dialog->open(this, SLOT(popUpNumberEditorClosed(HbAction*)));
|
|
241 |
m_dialog = dialog.take();
|
|
242 |
DPRINT << ": OUT";
|
|
243 |
}
|
|
244 |
|
|
245 |
/*!
|
|
246 |
CpDivertQuery::popUpNumberEditorClosed.
|
|
247 |
*/
|
|
248 |
void CpDivertQuery::popUpNumberEditorClosed(HbAction* action)
|
|
249 |
{
|
|
250 |
DPRINT << ": IN";
|
|
251 |
bool cancelled(true);
|
|
252 |
if (action) {
|
|
253 |
if (action->text() == hbTrId("txt_common_button_ok")) {
|
|
254 |
cancelled = false;
|
|
255 |
DPRINT << ": ok selected";
|
|
256 |
}
|
|
257 |
}
|
|
258 |
|
|
259 |
if (!cancelled) {
|
|
260 |
HbLineEdit *editor = qobject_cast<HbLineEdit *>(m_dialog->contentWidget());
|
|
261 |
if (editor) {
|
|
262 |
m_divertCommand.iNumber = editor->text();
|
|
263 |
}
|
|
264 |
|
|
265 |
DPRINT << ": m_divertCommand.iNumber "
|
|
266 |
<< m_divertCommand.iNumber;
|
|
267 |
if (m_divertCommand.iNumber.isEmpty()) {
|
|
268 |
PsUiNotes::instance()->showNotificationDialog(
|
|
269 |
hbTrId("txt_phone_info_invalid_phone_number"));
|
|
270 |
}
|
|
271 |
}
|
|
272 |
if (m_dialog) {
|
|
273 |
m_dialog->deleteLater();
|
|
274 |
m_dialog = NULL;
|
|
275 |
}
|
|
276 |
|
|
277 |
nextPhaseForActivateDivert(!cancelled);
|
|
278 |
|
|
279 |
DPRINT << ": OUT";
|
|
280 |
}
|
|
281 |
|
|
282 |
|
|
283 |
/*!
|
|
284 |
CpDivertQuery::popUpTimerQuery.
|
|
285 |
*/
|
|
286 |
void CpDivertQuery::popUpTimerQuery()
|
|
287 |
{
|
|
288 |
DPRINT << ": IN";
|
|
289 |
|
|
290 |
m_divertCommand.iNoReplyTimer = 0;
|
|
291 |
|
|
292 |
QScopedPointer<HbDialog> dialog(createDialog(hbTrId("txt_phone_title_delay")));
|
|
293 |
HbListWidget *list = new HbListWidget(dialog.data());
|
|
294 |
|
|
295 |
HbParameterLengthLimiter pluralLimiter;
|
|
296 |
pluralLimiter = HbParameterLengthLimiter("txt_phone_list_ln_seconds", 5);
|
|
297 |
addItemToListWidget(list, pluralLimiter, 5 );
|
|
298 |
pluralLimiter = HbParameterLengthLimiter("txt_phone_list_ln_seconds", 10);
|
|
299 |
addItemToListWidget(list, pluralLimiter, 10);
|
|
300 |
pluralLimiter = HbParameterLengthLimiter("txt_phone_list_ln_seconds", 15);
|
|
301 |
addItemToListWidget(list, pluralLimiter, 15);
|
|
302 |
pluralLimiter = HbParameterLengthLimiter("txt_phone_list_ln_seconds", 20);
|
|
303 |
addItemToListWidget(list, pluralLimiter, 20);
|
|
304 |
pluralLimiter = HbParameterLengthLimiter("txt_phone_list_ln_seconds", 25);
|
|
305 |
addItemToListWidget(list, pluralLimiter, 25);
|
|
306 |
pluralLimiter = HbParameterLengthLimiter("txt_phone_list_ln_seconds", 30);
|
|
307 |
addItemToListWidget(list, pluralLimiter, 30);
|
|
308 |
|
|
309 |
// Connect list item activation signal to close the popup
|
|
310 |
QObject::connect(
|
|
311 |
list, SIGNAL(activated(HbListWidgetItem*)),
|
|
312 |
dialog.data(), SLOT(close()),
|
|
313 |
Qt::UniqueConnection);
|
|
314 |
|
|
315 |
// Sets the "Cancel"-action/button
|
|
316 |
HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_cancel"));
|
|
317 |
dialog->addAction(cancelAction);
|
|
318 |
dialog->setContentWidget(list);
|
|
319 |
|
|
320 |
dialog->open(this, SLOT(popUpTimerQueryClosed(HbAction *)));
|
|
321 |
if (m_dialog) {
|
|
322 |
m_dialog->deleteLater();
|
|
323 |
m_dialog = NULL;
|
|
324 |
}
|
|
325 |
m_dialog = dialog.take();
|
|
326 |
|
|
327 |
DPRINT << ": OUT";
|
|
328 |
}
|
|
329 |
|
|
330 |
/*!
|
|
331 |
CpDivertQuery::popUpTimerQueryClosed.
|
|
332 |
*/
|
|
333 |
void CpDivertQuery::popUpTimerQueryClosed(HbAction* action)
|
|
334 |
{
|
|
335 |
DPRINT << ": IN";
|
|
336 |
|
|
337 |
// If not cancel action selected
|
|
338 |
bool cancelled(true);
|
|
339 |
if (!action) {
|
|
340 |
cancelled = false;
|
|
341 |
// Update the view with selected text
|
|
342 |
HbListWidget *list = qobject_cast<HbListWidget*>(m_dialog->contentWidget());
|
|
343 |
if (list && list->currentItem()) {
|
|
344 |
m_divertCommand.iNoReplyTimer =
|
|
345 |
list->currentItem()->data().toInt();
|
|
346 |
}
|
|
347 |
}
|
|
348 |
|
|
349 |
if (m_dialog) {
|
|
350 |
m_dialog->deleteLater();
|
|
351 |
m_dialog = NULL;
|
|
352 |
}
|
|
353 |
|
|
354 |
nextPhaseForActivateDivert(!cancelled);
|
|
355 |
|
|
356 |
DPRINT << ": OUT: timeout: " << m_divertCommand.iNoReplyTimer;
|
|
357 |
}
|
|
358 |
|
|
359 |
|
|
360 |
void CpDivertQuery::nextPhaseForActivateDivert(bool ok)
|
|
361 |
{
|
|
362 |
DPRINT << ": IN";
|
|
363 |
|
|
364 |
if (ok) {
|
|
365 |
switch (m_activateDivertPhase) {
|
|
366 |
case PopUpVoiceNumberListQueryPhase: {
|
|
367 |
if (m_needTimeOutInfo) {
|
|
368 |
m_activateDivertPhase = PopUpTimerQueryPhase;
|
|
369 |
popUpTimerQuery();
|
|
370 |
} else {
|
|
371 |
m_activateDivertPhase = NonePhase;
|
|
372 |
emit result(m_divertCommand);
|
|
373 |
}
|
|
374 |
}
|
|
375 |
break;
|
|
376 |
case PopUpTimerQueryPhase: {
|
|
377 |
m_activateDivertPhase = NonePhase;
|
|
378 |
emit result(m_divertCommand);
|
|
379 |
}
|
|
380 |
break;
|
|
381 |
default:
|
|
382 |
DPRINT << "Error: unknown enum value";
|
|
383 |
break;
|
|
384 |
}
|
|
385 |
} else {
|
|
386 |
// Query was cancelled
|
|
387 |
m_activateDivertPhase = NonePhase;
|
|
388 |
emit cancelled(m_divertCommand);
|
|
389 |
}
|
|
390 |
|
|
391 |
DPRINT << ": OUT";
|
|
392 |
}
|
|
393 |
|
|
394 |
/*!
|
|
395 |
CpDivertQuery::createDialog.
|
|
396 |
*/
|
|
397 |
HbDialog* CpDivertQuery::createDialog( const QString& heading ) const
|
|
398 |
{
|
|
399 |
DPRINT << ": IN";
|
|
400 |
|
|
401 |
HbDialog *dialog = new HbDialog();
|
|
402 |
dialog->setDismissPolicy(HbDialog::NoDismiss);
|
|
403 |
dialog->setTimeout(HbDialog::NoTimeout);
|
|
404 |
dialog->setHeadingWidget(new HbLabel(heading));
|
|
405 |
|
|
406 |
DPRINT << ": OUT";
|
|
407 |
return dialog;
|
|
408 |
}
|
|
409 |
|
|
410 |
/*!
|
|
411 |
CpDivertQuery::addItemToListWidget.
|
|
412 |
*/
|
|
413 |
void CpDivertQuery::addItemToListWidget(HbListWidget* w,
|
|
414 |
const QString& item, const QString& data) const
|
|
415 |
{
|
|
416 |
DPRINT << ": IN";
|
|
417 |
|
|
418 |
HbListWidgetItem* o = new HbListWidgetItem();
|
|
419 |
o->setText(item);
|
|
420 |
o->setData(data);
|
|
421 |
w->addItem(o);
|
|
422 |
|
|
423 |
DPRINT << ": OUT";
|
|
424 |
}
|
|
425 |
|
|
426 |
/*!
|
|
427 |
CpDivertQuery::addItemToListWidget.
|
|
428 |
*/
|
|
429 |
void CpDivertQuery::addItemToListWidget(HbListWidget* w,
|
|
430 |
const QString& item, const int& data) const
|
|
431 |
{
|
|
432 |
DPRINT << ": IN";
|
|
433 |
|
|
434 |
HbListWidgetItem* o = new HbListWidgetItem();
|
|
435 |
o->setText(item);
|
|
436 |
o->setData(data);
|
|
437 |
w->addItem(o);
|
|
438 |
|
|
439 |
DPRINT << ": OUT";
|
|
440 |
}
|
|
441 |
|