13 * |
13 * |
14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
|
18 #include <HbDocumentLoader> |
|
19 #include <HbDialog> |
|
20 #include <HbListView> |
|
21 #include <QStandardItemModel> |
18 #include <qfinalstate.h> |
22 #include <qfinalstate.h> |
19 #include <QDebug> |
23 #include <QDebug> |
20 #include <hsmenuservice.h> |
24 #include <hsmenuservice.h> |
21 #include <hbnotificationdialog.h> |
25 #include <hbnotificationdialog.h> |
22 #include <QAbstractTransition> |
26 #include <QAbstractTransition> |
23 #include <hbaction.h> |
27 #include <hbaction.h> |
24 |
28 |
25 #include "hsaddappstocollectionstate.h" |
29 #include "hsaddappstocollectionstate.h" |
26 #include "hsmenuevent.h" |
30 #include "hsmenuevent.h" |
27 #include "hscollectionnamedialog.h" |
31 #include "hscollectionnamedialog.h" |
28 #include "hscollectionslistdialog.h" |
|
29 #include "hsappschecklist.h" |
32 #include "hsappschecklist.h" |
|
33 #include "hsmenuitemmodel.h" |
30 |
34 |
31 /*! |
35 /*! |
32 \class HsAddAppsToCollectionState |
36 \class HsAddAppsToCollectionState |
33 \ingroup group_hsmenuworkerstateplugin |
37 \ingroup group_hsmenuworkerstateplugin |
34 \brief Manages adding to homescreen state |
38 \brief Manages adding to homescreen state |
131 Signal emitted when collection name is selected. |
135 Signal emitted when collection name is selected. |
132 \param collectionName name of collection. |
136 \param collectionName name of collection. |
133 */ |
137 */ |
134 |
138 |
135 /*! |
139 /*! |
136 \fn void HsAddAppsToCollectionState::transitToAppsCheckListState(const QString &collectionName); |
|
137 Signal emitted when collection name is selected - version to trigger |
|
138 transition to mAppCheckListState. |
|
139 \param collectionName name of collection. |
|
140 */ |
|
141 |
|
142 /*! |
|
143 \fn void void HsAddAppsToCollectionState::transitToSaveState(int collectionId); |
140 \fn void void HsAddAppsToCollectionState::transitToSaveState(int collectionId); |
144 Signal emitted when collection id is selected. |
141 Signal emitted when collection id is selected. |
145 \param collectionId id of collection. |
142 \param collectionId id of collection. |
146 */ |
143 */ |
147 |
144 |
148 /*! |
145 /*! |
149 \fn void HsAddAppsToCollectionState::transitToAppsCheckListState(int collectionId); |
146 \fn void HsAddAppsToCollectionState::transitToSelectCollectionState(); |
150 Signal emitted when collection name is selected - version to trigger |
147 Signal emitted after close multiselection list when CollectionActionType is ViaAllViewOptionMenuType |
151 transition to mAppCheckListState. |
148 transition to mSelectCollectionState. |
152 \param collectionId id of collection. |
149 */ |
153 */ |
|
154 |
150 |
155 /*! |
151 /*! |
156 \fn void HsAddAppsToCollectionState::transitToNewCollectionState(); |
152 \fn void HsAddAppsToCollectionState::transitToNewCollectionState(); |
157 Signal emitted when user selects creating new collection. |
153 Signal emitted when user selects creating new collection. |
158 */ |
154 */ |
177 HsAddAppsToCollectionState::HsAddAppsToCollectionState(QState *parent) : |
173 HsAddAppsToCollectionState::HsAddAppsToCollectionState(QState *parent) : |
178 QState(parent), mCollectionName(), mCollectionId(0), mAppList(), |
174 QState(parent), mCollectionName(), mCollectionId(0), mAppList(), |
179 mShowConfirmation(0), mInitialState(0), mSelectCollectionState(0), |
175 mShowConfirmation(0), mInitialState(0), mSelectCollectionState(0), |
180 mNewCollectionState(0), mAppsCheckListState(0), mActionType( |
176 mNewCollectionState(0), mAppsCheckListState(0), mActionType( |
181 NoActionType), mApplicationsSortAttribute(NoHsSortAttribute), |
177 NoActionType), mApplicationsSortAttribute(NoHsSortAttribute), |
182 mAppsCheckList(0), mEditorDialog(0), mListDialog(0) |
178 mAppsCheckList(0), mEditorDialog(0), mListDialog(0), mModel(0) |
183 { |
179 { |
184 construct(); |
180 construct(); |
185 } |
181 } |
186 |
182 |
187 /*! |
183 /*! |
188 Destructor. |
184 Destructor. |
189 |
|
190 */ |
185 */ |
191 HsAddAppsToCollectionState::~HsAddAppsToCollectionState() |
186 HsAddAppsToCollectionState::~HsAddAppsToCollectionState() |
192 { |
187 { |
193 |
188 |
194 } |
189 } |
235 //with signals and slots communication |
230 //with signals and slots communication |
236 connect(this, SIGNAL(transitToSaveState(int)), |
231 connect(this, SIGNAL(transitToSaveState(int)), |
237 SLOT(setCollectionId(int))); |
232 SLOT(setCollectionId(int))); |
238 connect(this, SIGNAL(transitToSaveState(QString)), |
233 connect(this, SIGNAL(transitToSaveState(QString)), |
239 SLOT(setCollectionName(QString))); |
234 SLOT(setCollectionName(QString))); |
240 connect(this, SIGNAL(transitToAppsCheckListState(int)), |
|
241 SLOT(setCollectionId(int))); |
|
242 connect(this, SIGNAL(transitToAppsCheckListState(QString)), |
|
243 SLOT(setCollectionName(QString))); |
|
244 connect(this, SIGNAL(transitToSaveState(QList<int>)), |
235 connect(this, SIGNAL(transitToSaveState(QList<int>)), |
245 SLOT(setAppList(QList<int>))); |
236 SLOT(setAppList(QList<int>))); |
246 |
237 |
247 // Add a specific application to an existing collection |
238 // Add a specific application to an existing collection |
248 // via item specific menu. |
239 // via item specific menu. |
249 // Add a specific item to a collection via collection specific menu. |
240 // Add a specific item to a collection via collection specific menu. |
250 // Adding a new collection via the Collections view. |
241 // Adding a new collection via the Collections view. |
251 mSelectCollectionState->addTransition(this, |
242 mSelectCollectionState->addTransition(this, |
252 SIGNAL(transitToNewCollectionState()), mNewCollectionState); |
243 SIGNAL(transitToNewCollectionState()), mNewCollectionState); |
253 mSelectCollectionState->addTransition(this, |
244 mSelectCollectionState->addTransition(this, |
254 SIGNAL(transitToSaveState(int)), saveState); |
245 SIGNAL(transitToSaveState(int)), saveState); |
255 mNewCollectionState->addTransition(this, |
246 mNewCollectionState->addTransition(this, |
256 SIGNAL(transitToSaveState(QString)), saveState); |
247 SIGNAL(transitToSaveState(QString)), saveState); |
257 |
248 |
258 // Add one/many applications to an existing/a new collection |
249 // Add one/many applications to an existing/a new collection |
259 // via the All view options menu. |
250 // via the All view options menu. |
260 // Add items to a collection via the collection's view options menu. |
251 // Add items to a collection via the collection's view options menu. |
261 mSelectCollectionState->addTransition(this, |
252 mSelectCollectionState->addTransition(this, |
262 SIGNAL(transitToAppsCheckListState(int)), mAppsCheckListState); |
253 SIGNAL(transitToSaveState(int)), saveState); |
263 mNewCollectionState->addTransition(this, |
254 mNewCollectionState->addTransition(this, |
264 SIGNAL(transitToAppsCheckListState(QString)), mAppsCheckListState); |
255 SIGNAL(transitToSaveState(QString)), saveState); |
265 mAppsCheckListState->addTransition(this, |
256 mAppsCheckListState->addTransition(this, |
266 SIGNAL(transitToSaveState(QList<int>)), saveState); |
257 SIGNAL(transitToSaveState(QList<int>)), saveState); |
267 |
|
268 mSelectCollectionState->addTransition(this, |
258 mSelectCollectionState->addTransition(this, |
269 SIGNAL(transitToFinalState()),finalState); |
259 SIGNAL(transitToFinalState()),finalState); |
270 mNewCollectionState->addTransition(this, |
260 mNewCollectionState->addTransition(this, |
271 SIGNAL(transitToFinalState()), finalState); |
261 SIGNAL(transitToFinalState()), finalState); |
272 mAppsCheckListState->addTransition(this, |
262 mAppsCheckListState->addTransition(this, |
273 SIGNAL(transitToFinalState()), finalState); |
263 SIGNAL(transitToSelectCollectionState()), mSelectCollectionState); |
|
264 mAppsCheckListState->addTransition(this, |
|
265 SIGNAL(transitToFinalState()), finalState); |
274 |
266 |
275 //transition to final state after save |
267 //transition to final state after save |
276 saveState->addTransition(finalState); |
268 saveState->addTransition(finalState); |
277 HSMENUTEST_FUNC_EXIT("HsAddAppsToCollectionState::createStates"); |
269 HSMENUTEST_FUNC_EXIT("HsAddAppsToCollectionState::createStates"); |
278 |
270 |
339 mInitialState->addTransition(mSelectCollectionState); |
331 mInitialState->addTransition(mSelectCollectionState); |
340 mShowConfirmation = true; |
332 mShowConfirmation = true; |
341 } else if (mApplicationsSortAttribute != NoHsSortAttribute) { |
333 } else if (mApplicationsSortAttribute != NoHsSortAttribute) { |
342 //add apps from allAppView options menu |
334 //add apps from allAppView options menu |
343 mActionType = ViaAllViewOptionMenuType; |
335 mActionType = ViaAllViewOptionMenuType; |
344 mInitialState->addTransition(mSelectCollectionState); |
336 mInitialState->addTransition(mAppsCheckListState); |
345 mShowConfirmation = true; |
337 mShowConfirmation = true; |
346 } else if (mCollectionId) { |
338 } else if (mCollectionId) { |
347 //add apps from collectionView options menu |
339 //add apps from collectionView options menu |
348 mApplicationsSortAttribute = AscendingNameHsSortAttribute; |
340 mApplicationsSortAttribute = AscendingNameHsSortAttribute; |
349 mInitialState->addTransition(mAppsCheckListState); |
341 mInitialState->addTransition(mAppsCheckListState); |
395 |
387 |
396 HSMENUTEST_FUNC_EXIT("HsAddAppsToCollectionState::newCollection"); |
388 HSMENUTEST_FUNC_EXIT("HsAddAppsToCollectionState::newCollection"); |
397 } |
389 } |
398 |
390 |
399 |
391 |
400 // --------------------------------------------------------------------------- |
392 /*! |
401 // --------------------------------------------------------------------------- |
393 Slot invoked when editor dialog with name of created collection is finished. |
402 // |
394 */ |
403 void HsAddAppsToCollectionState::editorDialogFinished(HbAction* finishedAction) |
395 void HsAddAppsToCollectionState::editorDialogFinished( |
|
396 HbAction* finishedAction) |
404 { |
397 { |
405 if (finishedAction == mEditorDialog->actions().value(0)) { |
398 if (finishedAction == mEditorDialog->actions().value(0)) { |
406 QString newName(mEditorDialog->newName(mEditorDialog->value().toString(), true)); |
399 QString newName(mEditorDialog->newName( |
407 if (mActionType == ViaAllViewOptionMenuType) { |
400 mEditorDialog->value().toString(), true)); |
408 qDebug("HsAddAppsToCollectionState::newCollection() " |
401 qDebug("HsAddAppsToCollectionState::newCollection() " |
409 "- emit collectionNameSelectedCl(newName)"); |
402 "- emit collectionNameSelectedCl(newName)"); |
410 emit transitToAppsCheckListState(newName); |
403 emit transitToSaveState(newName); |
411 } else { |
|
412 qDebug("HsAddAppsToCollectionState::newCollection() " |
|
413 "- emit collectionNameSelected(newName)"); |
|
414 emit transitToSaveState(newName); |
|
415 } |
|
416 } else { |
404 } else { |
417 qDebug( |
405 qDebug( |
418 "HsAddAppsToCollectionState::newCollection() - emit cancel()"); |
406 "HsAddAppsToCollectionState::newCollection() - emit cancel()"); |
419 emit transitToFinalState(); |
407 emit transitToFinalState(); |
420 } |
408 } |
426 */ |
414 */ |
427 void HsAddAppsToCollectionState::selectCollection() |
415 void HsAddAppsToCollectionState::selectCollection() |
428 { |
416 { |
429 qDebug("HsAddAppsToCollectionState::selectCollection()"); |
417 qDebug("HsAddAppsToCollectionState::selectCollection()"); |
430 HSMENUTEST_FUNC_ENTRY("HsAddAppsToCollectionState::selectCollection"); |
418 HSMENUTEST_FUNC_ENTRY("HsAddAppsToCollectionState::selectCollection"); |
431 mListDialog = new HsCollectionsListDialog(mCollectionId); |
419 |
432 mListDialog->open(this, SLOT(listDialogFinished(HbAction*))); |
420 HbDocumentLoader loader; |
|
421 bool loadStatusOk = false; |
|
422 loader.load(HS_COLLECTION_DIALOG_LAYOUT, &loadStatusOk); |
|
423 Q_ASSERT_X(loadStatusOk, HS_COLLECTION_DIALOG_LAYOUT, |
|
424 "Error while loading docml file."); |
|
425 |
|
426 mListDialog = qobject_cast<HbDialog*>( |
|
427 loader.findWidget(HS_COLLECTION_DIALOG_NAME)); |
|
428 |
|
429 HbListView *listView = qobject_cast<HbListView*>( |
|
430 loader.findWidget(HS_COLLECTION_DIALOG_LIST_VIEW)); |
|
431 |
|
432 HbAction* createNewCollection = |
|
433 qobject_cast<HbAction*>(loader.findObject( |
|
434 HS_COLLECTION_DIALOG_CREATE_NEW_ACTION)); |
|
435 |
|
436 HbAction* cancel = qobject_cast<HbAction*>(loader.findObject( |
|
437 HS_COLLECTION_DIALOG_CANCEL_ACTION)); |
|
438 |
|
439 if (mListDialog != NULL) { |
|
440 mListDialog->setTimeout(HbPopup::NoTimeout); |
|
441 mListDialog->setAttribute(Qt::WA_DeleteOnClose, true); |
|
442 |
|
443 createNewCollection->setParent(mListDialog); |
|
444 cancel->setParent(mListDialog); |
|
445 |
|
446 mModel = standardItemModel(mCollectionId); |
|
447 mModel->setParent(mListDialog); |
|
448 listView->setModel(mModel); |
|
449 |
|
450 connect(listView, SIGNAL(activated(const QModelIndex &)), |
|
451 this, SLOT(collectionSelected(const QModelIndex &))); |
|
452 |
|
453 mListDialog->open(this, SLOT(listDialogFinished(HbAction*))); |
|
454 } |
|
455 |
433 HSMENUTEST_FUNC_EXIT("HsAddAppsToCollectionState::selectCollection"); |
456 HSMENUTEST_FUNC_EXIT("HsAddAppsToCollectionState::selectCollection"); |
434 } |
457 } |
435 |
458 |
436 // --------------------------------------------------------------------------- |
459 /*! |
437 // --------------------------------------------------------------------------- |
460 Slot invoked when collection list dialog is finished |
438 // |
461 */ |
439 void HsAddAppsToCollectionState::listDialogFinished(HbAction* finishedAction) |
462 void HsAddAppsToCollectionState::listDialogFinished(HbAction* finishedAction) |
440 { |
463 { |
441 if (finishedAction != mListDialog->actions().value(0)) { |
464 if (finishedAction == mListDialog->actions().value(0)) { |
442 int itemId = mListDialog->getItemId(); |
465 qDebug("emit createNewCollection()"); |
443 if (itemId) { |
466 emit transitToNewCollectionState(); |
444 if (mActionType == ViaAllViewOptionMenuType) { |
467 } else if (finishedAction == mListDialog->actions().value(1)) { |
445 qDebug("emit collectionSelectedCl(%d)", itemId); |
|
446 emit transitToAppsCheckListState(itemId); |
|
447 } else { |
|
448 qDebug("emit collectionSelected(%d)", itemId); |
|
449 emit transitToSaveState(itemId); |
|
450 } |
|
451 } else { |
|
452 qDebug("emit createNewCollection()"); |
|
453 emit transitToNewCollectionState(); |
|
454 } |
|
455 } else { |
|
456 qDebug("emit cancel()"); |
468 qDebug("emit cancel()"); |
457 emit transitToFinalState(); |
469 emit transitToFinalState(); |
458 } |
470 } |
|
471 |
459 mListDialog = NULL; // set to null since this will be deleted after close |
472 mListDialog = NULL; // set to null since this will be deleted after close |
|
473 mModel = NULL;// set to null since this will be deleted with dialog |
|
474 } |
|
475 |
|
476 /*! |
|
477 Slot invoked when collection is selected |
|
478 \param modelIndex Index of selected item. |
|
479 */ |
|
480 void HsAddAppsToCollectionState::collectionSelected( |
|
481 const QModelIndex &modelIndex) |
|
482 { |
|
483 int selectedCollection = mModel->data( |
|
484 modelIndex, CaItemModel::IdRole).toInt(); |
|
485 mListDialog->close(); |
|
486 |
|
487 qDebug("emit collectionSelected(%d)", selectedCollection); |
|
488 emit transitToSaveState(selectedCollection); |
460 } |
489 } |
461 |
490 |
462 /*! |
491 /*! |
463 Slot connected to saving action of state. |
492 Slot connected to saving action of state. |
464 It is called when new application are addend to collection. |
493 It is called when new application are addend to collection. |
467 void HsAddAppsToCollectionState::showMessageAppsAdded(int id) |
496 void HsAddAppsToCollectionState::showMessageAppsAdded(int id) |
468 { |
497 { |
469 HSMENUTEST_FUNC_ENTRY("HsAddAppsToCollectionState::showMessageAppsAdded"); |
498 HSMENUTEST_FUNC_ENTRY("HsAddAppsToCollectionState::showMessageAppsAdded"); |
470 HbNotificationDialog *notificationDialog = new HbNotificationDialog(); |
499 HbNotificationDialog *notificationDialog = new HbNotificationDialog(); |
471 notificationDialog->setAttribute(Qt::WA_DeleteOnClose); |
500 notificationDialog->setAttribute(Qt::WA_DeleteOnClose); |
472 notificationDialog->setTitle(hbTrId( |
501 notificationDialog->setTitle( |
473 "txt_applib_dpopinfo_added_to_collection_1") .arg( |
502 hbTrId("txt_applib_dpopinfo_added_to_collection_1") .arg( |
474 HsMenuService::getName(id))); |
503 HsMenuService::getName(id))); |
475 notificationDialog->show(); |
504 notificationDialog->show(); |
476 mShowConfirmation = false; |
505 mShowConfirmation = false; |
477 HSMENUTEST_FUNC_EXIT("HsAddAppsToCollectionState::showMessageAppsAdded"); |
506 HSMENUTEST_FUNC_EXIT("HsAddAppsToCollectionState::showMessageAppsAdded"); |
478 } |
507 } |
479 |
508 |
532 } |
558 } |
533 mAppsCheckList->setSortOrder(mApplicationsSortAttribute); |
559 mAppsCheckList->setSortOrder(mApplicationsSortAttribute); |
534 mAppsCheckList->showAppsCheckboxList(mApplicationsSortAttribute); |
560 mAppsCheckList->showAppsCheckboxList(mApplicationsSortAttribute); |
535 HSMENUTEST_FUNC_EXIT("HsAddAppsToCollectionState::appsCheckListState"); |
561 HSMENUTEST_FUNC_EXIT("HsAddAppsToCollectionState::appsCheckListState"); |
536 } |
562 } |
537 #ifdef COVERAGE_MEASUREMENT |
|
538 #pragma CTC ENDSKIP |
|
539 #endif //COVERAGE_MEASUREMENT |
|
540 /*! |
563 /*! |
541 Slot connected trrigger action of secondary soft key of check list box. |
564 Slot connected trrigger action of secondary soft key of check list box. |
542 It is called when done button is selected. |
565 It is called when done button is selected. |
543 */ |
566 */ |
544 #ifdef COVERAGE_MEASUREMENT |
|
545 #pragma CTC SKIP |
|
546 #endif //COVERAGE_MEASUREMENT |
|
547 void HsAddAppsToCollectionState::selectApplicationsDone( |
567 void HsAddAppsToCollectionState::selectApplicationsDone( |
548 const QList<int> &appList) |
568 const QList<int> &appList) |
549 { |
569 { |
550 if (appList.count()) { |
570 if (appList.count()) { |
551 qDebug("AppsCheckListState::selectApplicationsDone() " |
571 qDebug("AppsCheckListState::selectApplicationsDone() " |
552 "- emit appsSelected(mAppList)"); |
572 "- emit appsSelected(mAppList)"); |
553 emit transitToSaveState(appList); |
573 if (mActionType == ViaAllViewOptionMenuType) { |
|
574 setAppList(appList); |
|
575 emit transitToSelectCollectionState(); |
|
576 } else { |
|
577 emit transitToSaveState(appList); |
|
578 } |
554 } else { |
579 } else { |
555 qDebug( |
580 qDebug( |
556 "AppsCheckListState::selectApplicationsDone() - emit cancel()"); |
581 "AppsCheckListState::selectApplicationsDone() - emit cancel()"); |
557 emit transitToFinalState(); |
582 emit transitToFinalState(); |
558 } |
583 } |
559 } |
584 } |
560 #ifdef COVERAGE_MEASUREMENT |
585 /*! |
561 #pragma CTC ENDSKIP |
586 Creates standard item model. |
562 #endif //COVERAGE_MEASUREMENT |
587 \param collectionId id of collection to remove from model. |
|
588 \return QStandardItemModel - caller takes ownership. |
|
589 */ |
|
590 QStandardItemModel *HsAddAppsToCollectionState::standardItemModel( |
|
591 int collectionId) |
|
592 { |
|
593 HSMENUTEST_FUNC_ENTRY("HsListDialog::standartItemModel"); |
|
594 QScopedPointer<HsMenuItemModel> caModel( |
|
595 HsMenuService::getAllCollectionsModel()); |
|
596 caModel->setSecondLineVisibility(true); |
|
597 QStandardItemModel *model = new QStandardItemModel(this); |
|
598 QList<QStandardItem *> items; |
|
599 for (int row = 0; row < caModel->rowCount(); row++) { |
|
600 uint flags = caModel->data(caModel->index(row, 0), |
|
601 CaItemModel::FlagsRole).value<EntryFlags> (); |
|
602 int itemId = caModel->data(caModel->index(row, 0), |
|
603 CaItemModel::IdRole).toInt(); |
|
604 if ((flags & RemovableEntryFlag) && (itemId != collectionId)) { |
|
605 QStandardItem *standardItem = new QStandardItem(); |
|
606 standardItem->setData(caModel->data(caModel->index(row, 0), |
|
607 CaItemModel::IdRole), CaItemModel::IdRole); |
|
608 standardItem->setData(caModel->data(caModel->index(row, 0), |
|
609 Qt::DisplayRole), Qt::DisplayRole); |
|
610 standardItem->setData(caModel->data(caModel->index(row, 0), |
|
611 Qt::DecorationRole), Qt::DecorationRole); |
|
612 items << standardItem; |
|
613 } |
|
614 } |
|
615 model->insertColumn(0, items); |
|
616 |
|
617 HSMENUTEST_FUNC_EXIT("HsListDialog::standartItemModel"); |
|
618 return model; |
|
619 } |