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 * |
|
15 * Description: |
|
16 * The source file of the query sdialog utility of file manager |
|
17 */ |
|
18 |
|
19 #include "fmdlgutils.h" |
|
20 #include "fmcombinedquery.h" |
|
21 #include "fmtimequery.h" |
|
22 #include "fmsingletextquery.h" |
|
23 #include "fmmultitextquery.h" |
|
24 #include "fmutils.h" |
|
25 #include "fmviewmanager.h" |
|
26 #include "fmmessagebox.h" |
|
27 #include "fmdrivequery.h" |
|
28 |
|
29 #include <QString> |
|
30 #include <QStringList> |
|
31 #include <QMap> |
|
32 |
|
33 #include <hblabel.h> |
|
34 #include <hbaction.h> |
|
35 |
|
36 /* |
|
37 Private Constructor |
|
38 */ |
|
39 FmDlgUtils::FmDlgUtils() |
|
40 { |
|
41 } |
|
42 |
|
43 /*! |
|
44 Destructor |
|
45 */ |
|
46 FmDlgUtils::~FmDlgUtils() |
|
47 { |
|
48 } |
|
49 |
|
50 /*! |
|
51 Shows single select setting query dialog |
|
52 \a title used for title text |
|
53 \a textList used for text list for available settings |
|
54 \a selectedIndex used for storing selected index |
|
55 Dialog will be closed as canceled while drive in \a associatedDrives is removed |
|
56 return true if selection made, otherwise false |
|
57 */ |
|
58 bool FmDlgUtils::showSingleSettingQuery( |
|
59 const QString &title, |
|
60 const QStringList &textList, |
|
61 int &selectedIndex, const QString &associatedDrives ) |
|
62 { |
|
63 bool ret( false ); |
|
64 |
|
65 int i = 0; |
|
66 QMap< int, QString > items; // Maps list item with corresponding text in viewer |
|
67 for( QStringList::const_iterator it = textList.begin(); it!= textList.end(); ++it ){ |
|
68 items.insert( i, *it ); |
|
69 ++i; |
|
70 } |
|
71 bool ok ( false ); // SK return (out parameter) |
|
72 |
|
73 FmCombinedQuery *cQuery=new FmCombinedQuery; |
|
74 cQuery->setSelectMode( FmCombinedQuery::SingleSelectMode ); |
|
75 cQuery->setHeadingWidget( new HbLabel( title ) ); |
|
76 cQuery->setListItems( items ); |
|
77 |
|
78 if( selectedIndex != -1 ){ |
|
79 cQuery->setMarkedListItem( selectedIndex ); |
|
80 } |
|
81 |
|
82 QString sk1 ( hbTrId( "txt_common_button_ok" ) ); |
|
83 QString sk2 ( hbTrId("txt_common_button_cancel" ) ); |
|
84 |
|
85 if( !sk1.isEmpty() ) { |
|
86 HbAction *primary = new HbAction( sk1 ); |
|
87 cQuery->setPrimaryAction( primary ); |
|
88 } |
|
89 |
|
90 if( !sk2.isEmpty() ) { |
|
91 HbAction *secondary = new HbAction( sk2 ); |
|
92 cQuery->setSecondaryAction( secondary ); |
|
93 } |
|
94 |
|
95 //HbAction* action = cQuery->exec(); |
|
96 HbAction* action = executeDialog( cQuery, associatedDrives ); |
|
97 if( action == cQuery->primaryAction() ){ |
|
98 ok = true; |
|
99 } |
|
100 else{ |
|
101 ok = false; |
|
102 } |
|
103 if( ok ){ |
|
104 //get selected key list. |
|
105 QList<int> selectedKeyList = cQuery->selectedKeys(); |
|
106 |
|
107 // Get new selection and notify changes |
|
108 int selectionResult( 0 ); |
|
109 int i = 0; |
|
110 for ( QMap< int, QString >::const_iterator it = items.begin(); it != items.end(); ++it ){ |
|
111 // if one item has been selected( judge if the key is in the selected key list) |
|
112 if ( selectedKeyList.indexOf( it.key() ) >= 0 ) { |
|
113 selectionResult = i; |
|
114 break; |
|
115 } |
|
116 ++i; |
|
117 } |
|
118 if ( selectionResult != selectedIndex ){ |
|
119 selectedIndex = selectionResult; |
|
120 ret = true; |
|
121 } |
|
122 } |
|
123 delete cQuery; |
|
124 return ret; |
|
125 } |
|
126 |
|
127 /*! |
|
128 Shows multi select setting query dialog |
|
129 \a title used for title text |
|
130 \a textList used for text list for available settings |
|
131 \a selection used for storing selected indexes as bitmask |
|
132 \a dominantIndex used for dominant index for select all behaviour |
|
133 Dialog will be closed as canceled while drive in \a associatedDrives is removed |
|
134 return true if selection made, otherwise false |
|
135 */ |
|
136 bool FmDlgUtils::showMultiSettingQuery( |
|
137 const QString &title, |
|
138 const QStringList &textList, |
|
139 quint32 &selection, |
|
140 int dominantIndex, const QString &associatedDrives ) |
|
141 { |
|
142 bool ret( false ); |
|
143 |
|
144 int i = 0; |
|
145 QMap<int, QString> items; // Maps list item with corresponding text in viewer |
|
146 for( QStringList::const_iterator it = textList.begin(); it!= textList.end(); ++it){ |
|
147 items.insert( i, *it ); |
|
148 ++i; |
|
149 } |
|
150 bool ok ( false ); // SK return (out parameter) |
|
151 |
|
152 FmCombinedQuery *cQuery=new FmCombinedQuery; |
|
153 cQuery->setSelectMode( FmCombinedQuery::MultiSelectMode ); |
|
154 cQuery->setHeadingWidget( new HbLabel( title ) ); |
|
155 cQuery->setListItems( items ); |
|
156 cQuery->setDominantIndex( dominantIndex ); |
|
157 |
|
158 // Create selection array |
|
159 int count( textList.count() ); |
|
160 for ( int i( 0 ); i < count; ++i ){ |
|
161 if ( selection & ( 1 << i ) ){ |
|
162 cQuery->setMarkedListItem( i ); |
|
163 } |
|
164 } |
|
165 |
|
166 |
|
167 QString sk1 ( hbTrId( "txt_common_button_ok" ) ); |
|
168 QString sk2 ( hbTrId( "txt_common_button_cancel" ) ); |
|
169 |
|
170 if( !sk1.isEmpty() ) { |
|
171 HbAction *primary = new HbAction( sk1 ); |
|
172 cQuery->setPrimaryAction( primary ); |
|
173 } |
|
174 |
|
175 if( !sk2.isEmpty() ) { |
|
176 HbAction *secondary = new HbAction( sk2 ); |
|
177 cQuery->setSecondaryAction( secondary ); |
|
178 } |
|
179 |
|
180 HbAction* action = executeDialog( cQuery, associatedDrives ); |
|
181 if( action == cQuery->primaryAction() ){ |
|
182 ok = true; |
|
183 } |
|
184 else{ |
|
185 ok = false; |
|
186 } |
|
187 if( ok ) |
|
188 { |
|
189 //get selected key list. |
|
190 QList<int> selectedKeyList = cQuery->selectedKeys(); |
|
191 |
|
192 // Get new selection and notify changes |
|
193 quint32 selectionResult( 0 ); |
|
194 int i = 0; |
|
195 for ( QMap< int, QString >::const_iterator it = items.begin(); it != items.end(); ++it ){ |
|
196 // if one item has been selected( judge if the key is in the selected key list) |
|
197 if ( selectedKeyList.indexOf( it.key() ) >= 0 ) { |
|
198 selectionResult |= 1 << i; |
|
199 } |
|
200 ++i; |
|
201 } |
|
202 if ( selectionResult != selection ){ |
|
203 selection = selectionResult; |
|
204 ret = true; |
|
205 } |
|
206 } |
|
207 delete cQuery; |
|
208 return ret; |
|
209 } |
|
210 |
|
211 /*! |
|
212 Shows time setting query dialog |
|
213 \a title used for title text |
|
214 \a time used for selected time |
|
215 Dialog will be closed as canceled while drive in \a associatedDrives is removed |
|
216 return true if selection made, otherwise false |
|
217 */ |
|
218 bool FmDlgUtils::showTimeSettingQuery( |
|
219 const QString &title, QTime &time, const QString &associatedDrives ) |
|
220 { |
|
221 bool ret( false ); |
|
222 bool ok ( false ); // SK return (out parameter) |
|
223 |
|
224 FmTimeQuery *cQuery=new FmTimeQuery; |
|
225 cQuery->setHeadingWidget( new HbLabel( title ) ); |
|
226 cQuery->setTime( time ); |
|
227 |
|
228 QString sk1 ( hbTrId( "txt_common_button_ok" ) ); |
|
229 QString sk2 ( hbTrId( "txt_common_button_cancel" ) ); |
|
230 |
|
231 if( !sk1.isEmpty() ) { |
|
232 HbAction *primary = new HbAction( sk1 ); |
|
233 cQuery->setPrimaryAction( primary ); |
|
234 } |
|
235 |
|
236 if( !sk2.isEmpty() ) { |
|
237 HbAction *secondary = new HbAction( sk2 ); |
|
238 cQuery->setSecondaryAction( secondary ); |
|
239 } |
|
240 |
|
241 HbAction* action = executeDialog( cQuery, associatedDrives ); |
|
242 if( action == cQuery->primaryAction() ){ |
|
243 ok = true; |
|
244 } |
|
245 else{ |
|
246 ok = false; |
|
247 } |
|
248 if( ok ) |
|
249 { |
|
250 QTime resultTime = cQuery->getTime(); |
|
251 if ( resultTime != time ){ |
|
252 time = resultTime; |
|
253 ret = true; |
|
254 } |
|
255 } |
|
256 delete cQuery; |
|
257 return ret; |
|
258 } |
|
259 |
|
260 /*! |
|
261 Shows text query dialog |
|
262 \a title used for title text |
|
263 \a text used for receiving user input text |
|
264 \a validRegExpStringList used for set valid regExp string list |
|
265 \a maxLength used for setting max length of input text |
|
266 Dialog will be closed as canceled while drive in \a associatedDrives is removed |
|
267 Set \a isReturnFalseWhenNoTextChanged true if need make return value as true while no text changed |
|
268 return true if text change is made, otherwise false |
|
269 */ |
|
270 bool FmDlgUtils::showTextQuery( |
|
271 const QString& title, QString& text, QStringList validRegExpStringList, |
|
272 int maxLength, const QString &associatedDrives, bool isReturnFalseWhenNoTextChanged ) |
|
273 { |
|
274 bool ret( false ); |
|
275 bool ok ( true ); // SK return (out parameter) |
|
276 |
|
277 FmSingleTextQuery *cQuery = new FmSingleTextQuery(); |
|
278 if( maxLength != -1 ){ |
|
279 cQuery->setLineEditMaxLength( maxLength ); |
|
280 } |
|
281 cQuery->setHeadingWidget( new HbLabel( title ) ); |
|
282 |
|
283 cQuery->setRegExpStringList( validRegExpStringList ); |
|
284 |
|
285 QString sk1 ( hbTrId ( "txt_common_button_ok" ) ); |
|
286 QString sk2 ( hbTrId ( "txt_common_button_cancel" ) ); |
|
287 |
|
288 if( !sk1.isEmpty() ) { |
|
289 HbAction *primary = new HbAction( sk1 ); |
|
290 cQuery->setPrimaryAction( primary ); |
|
291 } |
|
292 |
|
293 if( !sk2.isEmpty() ) { |
|
294 HbAction *secondary = new HbAction( sk2 ); |
|
295 cQuery->setSecondaryAction( secondary ); |
|
296 } |
|
297 cQuery->setLineEditText( text ); |
|
298 cQuery->checkActions(); |
|
299 |
|
300 HbAction* action = executeDialog( cQuery, associatedDrives ); |
|
301 if( action == cQuery->primaryAction() ){ |
|
302 ok = true; |
|
303 } |
|
304 else{ |
|
305 ok = false; |
|
306 } |
|
307 |
|
308 if( ok ){ |
|
309 QString newName = cQuery->getLineEditText(); |
|
310 if ( newName == text ){ |
|
311 if( isReturnFalseWhenNoTextChanged ) { |
|
312 ret = false; |
|
313 } |
|
314 else { |
|
315 ret = true; |
|
316 } |
|
317 } else { |
|
318 text = newName; |
|
319 ret = true; |
|
320 } |
|
321 } |
|
322 delete cQuery; |
|
323 return ret; |
|
324 } |
|
325 |
|
326 /*! |
|
327 Shows single-line password query dialog |
|
328 \a title used for title text |
|
329 \a pwd used for receiving user input password |
|
330 \a maxLength used for setting max length of input password |
|
331 Dialog will be closed as canceled while drive in \a associatedDrives is removed |
|
332 return true if password text is inputted, otherwise false |
|
333 */ |
|
334 bool FmDlgUtils::showSinglePasswordQuery( const QString &title, QString &pwd, int maxLength, const QString &associatedDrives ) |
|
335 { |
|
336 bool ret( false ); |
|
337 |
|
338 FmSingleTextQuery *cQuery = new FmSingleTextQuery( HbLineEdit::Password ); |
|
339 if( maxLength != -1 ){ |
|
340 cQuery->setLineEditMaxLength( maxLength ); |
|
341 } |
|
342 cQuery->setHeadingWidget( new HbLabel( title ) ); |
|
343 |
|
344 // validate that length is not zero. space is acceptable character. |
|
345 cQuery->setRegExpStringList( QStringList( Regex_ValidUnZeroLength ) ); |
|
346 QString sk1 ( hbTrId("txt_common_button_ok" ) ); |
|
347 QString sk2 ( hbTrId("txt_common_button_cancel" ) ); |
|
348 |
|
349 if( !sk1.isEmpty() ) { |
|
350 HbAction *primary = new HbAction( sk1 ); |
|
351 cQuery->setPrimaryAction( primary ); |
|
352 } |
|
353 |
|
354 if( !sk2.isEmpty() ) { |
|
355 HbAction *secondary = new HbAction( sk2 ); |
|
356 cQuery->setSecondaryAction( secondary ); |
|
357 } |
|
358 cQuery->checkActions(); |
|
359 |
|
360 HbAction* action = executeDialog( cQuery, associatedDrives ); |
|
361 if( action == cQuery->primaryAction() ){ |
|
362 ret = true; |
|
363 pwd = cQuery->getLineEditText(); |
|
364 } |
|
365 else{ |
|
366 ret = false; |
|
367 } |
|
368 |
|
369 delete cQuery; |
|
370 return ret; |
|
371 } |
|
372 |
|
373 /*! |
|
374 Shows mulit-line password query dialog. If two password is not equal, primary action is dimmed |
|
375 \a firstLabel used for first line title text |
|
376 \a secondLabel used for second line title text |
|
377 \a pwd used for receiving user input password |
|
378 \a maxLength used for setting max length of input password |
|
379 Dialog will be closed as canceled while drive in \a associatedDrives is removed |
|
380 return true if password text is inputted, otherwise false |
|
381 */ |
|
382 bool FmDlgUtils::showMultiPasswordQuery( |
|
383 const QString &firstLabel, const QString &secondLabel, QString &pwd, int maxLength, const QString &associatedDrives ) |
|
384 { |
|
385 bool ret( false ); |
|
386 |
|
387 FmMultiTextQuery *cQuery = new FmMultiTextQuery( HbLineEdit::Password ); |
|
388 if( maxLength != -1 ){ |
|
389 cQuery->setLineEditMaxLength( maxLength ); |
|
390 } |
|
391 cQuery->setFirstLabelText( firstLabel ); |
|
392 cQuery->setSecondLabelText( secondLabel ); |
|
393 |
|
394 QString sk1 = ( hbTrId( "txt_common_button_ok" ) ); |
|
395 QString sk2 = ( hbTrId( "txt_common_button_cancel" ) ); |
|
396 |
|
397 if( !sk1.isEmpty() ) { |
|
398 HbAction *primary = new HbAction( sk1 ); |
|
399 cQuery->setPrimaryAction( primary ); |
|
400 } |
|
401 |
|
402 if( !sk2.isEmpty() ) { |
|
403 HbAction *secondary = new HbAction( sk2 ); |
|
404 cQuery->setSecondaryAction( secondary ); |
|
405 } |
|
406 cQuery->checkActions(); |
|
407 |
|
408 HbAction* action = executeDialog( cQuery, associatedDrives ); |
|
409 if( action == cQuery->primaryAction() ){ |
|
410 QString firstPwd = cQuery->getFirstEditText(); |
|
411 QString secondPwd = cQuery->getSecondEditText(); |
|
412 if ( firstPwd == secondPwd ){ |
|
413 pwd = secondPwd; |
|
414 ret = true; |
|
415 } |
|
416 } |
|
417 else{ |
|
418 ret = false; |
|
419 } |
|
420 |
|
421 delete cQuery; |
|
422 return ret; |
|
423 } |
|
424 |
|
425 /*! |
|
426 This is a convenience function for showing a question dialog with \a questionText |
|
427 Default buttons are Yes and No. |
|
428 */ |
|
429 bool FmDlgUtils::question( const QString &questionText, |
|
430 HbMessageBox::StandardButtons buttons ) |
|
431 { |
|
432 FmMessageBox msgBox; |
|
433 return msgBox.question( questionText, buttons ); |
|
434 } |
|
435 |
|
436 /*! |
|
437 This is a convenience function for showing an information dialog with \a informationText |
|
438 Default button is OK. |
|
439 */ |
|
440 void FmDlgUtils::information( const QString &informationText, |
|
441 HbMessageBox::StandardButtons buttons ) |
|
442 { |
|
443 FmMessageBox msgBox; |
|
444 return msgBox.information( informationText, buttons ); |
|
445 } |
|
446 |
|
447 /*! |
|
448 Shows query dialog for select backup drive |
|
449 \a title used for title text |
|
450 only backup target drives will be shown. |
|
451 return selected drive, and empty string for cancel. |
|
452 */ |
|
453 QString FmDlgUtils::showBackupDriveQuery( const QString& title ) |
|
454 { |
|
455 QString ret; |
|
456 |
|
457 FmDriveQuery *cQuery = new FmDriveQuery(); |
|
458 cQuery->setHeadingWidget( new HbLabel( title ) ); |
|
459 |
|
460 QString sk = ( hbTrId( "txt_common_button_cancel" ) ); |
|
461 |
|
462 HbAction *primary = new HbAction( sk ); |
|
463 cQuery->setPrimaryAction( primary ); |
|
464 |
|
465 executeDialog( cQuery, QString() ); |
|
466 ret = cQuery->selectedDrive(); |
|
467 |
|
468 delete cQuery; |
|
469 return ret; |
|
470 } |
|
471 |
|
472 /* |
|
473 Private function used to popup \a dialog |
|
474 If want popup dialog in class FmDlgUtils, please call this function. |
|
475 Dialog will be closed as canceled while drive in \a associatedDrives is removed |
|
476 return selected action. |
|
477 */ |
|
478 HbAction *FmDlgUtils::executeDialog( FmDialog *dialog, const QString &associatedDrives ) |
|
479 { |
|
480 for( int i = 0; i < associatedDrives.length(); i++ ) { |
|
481 QString drive( associatedDrives[i] + QString( ":/" ) ); |
|
482 if( !FmUtils::isDriveAvailable( drive ) ) { |
|
483 FM_LOG( "executeDialog return 0_ " + associatedDrives ); |
|
484 return 0; |
|
485 } |
|
486 } |
|
487 |
|
488 FmDlgCloseUnit dlgCloseUnit( dialog ); |
|
489 dlgCloseUnit.addAssociatedDrives( associatedDrives ); |
|
490 |
|
491 FmViewManager::viewManager()->addDlgCloseUnit( &dlgCloseUnit ); |
|
492 HbAction* action = dialog->exec(); |
|
493 FmViewManager::viewManager()->removeDlgCloseUnit( &dlgCloseUnit ); |
|
494 return action; |
|
495 } |
|