|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <HbDocumentLoader> |
|
19 #include <HbDialog> |
|
20 #include <HbListView> |
|
21 #include <QStandardItemModel> |
|
22 #include <qfinalstate.h> |
|
23 #include <QDebug> |
|
24 #include <hsmenuservice.h> |
|
25 #include <hbnotificationdialog.h> |
|
26 #include <QAbstractTransition> |
|
27 #include <hbaction.h> |
|
28 |
|
29 #include "hsaddappstocollectionstate.h" |
|
30 #include "hsmenuevent.h" |
|
31 #include "hscollectionnamedialog.h" |
|
32 #include "hsappschecklist.h" |
|
33 #include "hsmenuitemmodel.h" |
|
34 |
|
35 /*! |
|
36 \class HsAddAppsToCollectionState |
|
37 \ingroup group_hsmenuworkerstateplugin |
|
38 \brief Manages adding to homescreen state |
|
39 State responsible for adding new applications to collections. |
|
40 \lib ?library |
|
41 \see StateMachine |
|
42 */ |
|
43 |
|
44 /*! |
|
45 \enum HsAddAppsToCollectionState::CollectionActionType |
|
46 Types of collection's related actions. |
|
47 */ |
|
48 |
|
49 /*! \var HsAddAppsToCollectionState::CollectionActionType HsAddAppsToCollectionState::NoActionType |
|
50 No action. |
|
51 */ |
|
52 |
|
53 /*! \var HsAddAppsToCollectionState::CollectionActionType HsAddAppsToCollectionState::ViaItemSpecificMenuType |
|
54 Adding a specific application to an existing collection via item specific menu. |
|
55 */ |
|
56 |
|
57 /*! \var HsAddAppsToCollectionState::CollectionActionType HsAddAppsToCollectionState::ViaAllViewOptionMenuType |
|
58 Add one/many applications to a new/an existing collection via the All view. |
|
59 */ |
|
60 |
|
61 /*! \var HsAddAppsToCollectionState::CollectionActionType HsAddAppsToCollectionState::ViaAllCollectionsViewType |
|
62 Adding a new collection via the Collections view. |
|
63 */ |
|
64 |
|
65 /*! \var HsAddAppsToCollectionState::CollectionActionType HsAddAppsToCollectionState::ViaCollectionsViewOptionsMenuType |
|
66 Add items to a collection via the collection's view options menu. |
|
67 */ |
|
68 |
|
69 /*! \var HsAddAppsToCollectionState::CollectionActionType HsAddAppsToCollectionState::ViaCollectionSpecificMenuType |
|
70 Add a specific item to a collection via collection specific menu. |
|
71 */ |
|
72 |
|
73 /*! |
|
74 \var HsAddAppsToCollectionState::mCollectionName |
|
75 Collection name. |
|
76 */ |
|
77 |
|
78 /*! |
|
79 \var HsAddAppsToCollectionState::mCollectionId |
|
80 Collection id. |
|
81 */ |
|
82 |
|
83 /*! |
|
84 \var HsAddAppsToCollectionState::mAppList |
|
85 Applications list. |
|
86 */ |
|
87 |
|
88 /*! |
|
89 \var HsAddAppsToCollectionState::mShowConfirmation |
|
90 Bool indicating need of confirmation note after saving in content arsenal. |
|
91 */ |
|
92 |
|
93 /*! |
|
94 \var HsAddAppsToCollectionState::mInitialState |
|
95 Initial state. |
|
96 */ |
|
97 |
|
98 /*! |
|
99 \var HsAddAppsToCollectionState::mSelectCollectionState |
|
100 Select collection state. |
|
101 */ |
|
102 |
|
103 /*! |
|
104 \var HsAddAppsToCollectionState::mNewCollectionState |
|
105 Collection name state. |
|
106 */ |
|
107 |
|
108 /*! |
|
109 \var HsAddAppsToCollectionState::mAppsCheckListState |
|
110 Collection name state. |
|
111 */ |
|
112 |
|
113 /*! |
|
114 \var HsAddAppsToCollectionState::mActionType |
|
115 Collection action type. |
|
116 */ |
|
117 |
|
118 /*! |
|
119 \var HsAddAppsToCollectionState::mApplicationsSortAttribute |
|
120 Applications sort order. |
|
121 */ |
|
122 |
|
123 /*! |
|
124 \var HsAddAppsToCollectionState::mCollectionsSortAttribute |
|
125 Collections sort order. |
|
126 */ |
|
127 |
|
128 /*! |
|
129 \var HsAddAppsToCollectionState::mAppsCheckList |
|
130 Applications check list. |
|
131 */ |
|
132 |
|
133 /*! |
|
134 \fn void HsAddAppsToCollectionState::transitToSaveState(const QString &collectionName); |
|
135 Signal emitted when collection name is selected. |
|
136 \param collectionName name of collection. |
|
137 */ |
|
138 |
|
139 /*! |
|
140 \fn void void HsAddAppsToCollectionState::transitToSaveState(int collectionId); |
|
141 Signal emitted when collection id is selected. |
|
142 \param collectionId id of collection. |
|
143 */ |
|
144 |
|
145 /*! |
|
146 \fn void HsAddAppsToCollectionState::transitToSelectCollectionState(); |
|
147 Signal emitted after close multiselection list when CollectionActionType is ViaAllViewOptionMenuType |
|
148 transition to mSelectCollectionState. |
|
149 */ |
|
150 |
|
151 /*! |
|
152 \fn void HsAddAppsToCollectionState::transitToNewCollectionState(); |
|
153 Signal emitted when user selects creating new collection. |
|
154 */ |
|
155 |
|
156 /*! |
|
157 \fn void HsAddAppsToCollectionState::transitToSaveState(const QList<int> &appList); |
|
158 Signal emitted when applications are selected. |
|
159 \param appList application list. |
|
160 */ |
|
161 |
|
162 /*! |
|
163 \fn void HsAddAppsToCollectionState::transitToFinalState(); |
|
164 Signal emitted when user selects cancel. |
|
165 \param collectionName name of collection. |
|
166 */ |
|
167 |
|
168 /*! |
|
169 Constructor. |
|
170 \return \a true on success, \a false otherwise. |
|
171 \param parent Parent state. |
|
172 */ |
|
173 HsAddAppsToCollectionState::HsAddAppsToCollectionState(QState *parent) : |
|
174 QState(parent), mCollectionName(), mCollectionId(0), mAppList(), |
|
175 mShowConfirmation(0), mInitialState(0), mSelectCollectionState(0), |
|
176 mNewCollectionState(0), mAppsCheckListState(0), mActionType( |
|
177 NoActionType), mApplicationsSortAttribute(Hs::NoHsSortAttribute), |
|
178 mAppsCheckList(0), mEditorDialog(0), mListDialog(0), mModel(0) |
|
179 { |
|
180 construct(); |
|
181 } |
|
182 |
|
183 /*! |
|
184 Destructor. |
|
185 */ |
|
186 HsAddAppsToCollectionState::~HsAddAppsToCollectionState() |
|
187 { |
|
188 |
|
189 } |
|
190 |
|
191 /*! |
|
192 Constructor part. |
|
193 */ |
|
194 void HsAddAppsToCollectionState::construct() |
|
195 { |
|
196 HSMENUTEST_FUNC_ENTRY("HsAddAppsToCollectionState::construct"); |
|
197 setObjectName("homescreen.nokia.com/state/addappstocollectionstate"); |
|
198 createStates(); |
|
199 connect(this, SIGNAL(exited()),SLOT(stateExited())); |
|
200 |
|
201 HSMENUTEST_FUNC_EXIT("HsAddAppsToCollectionState::construct"); |
|
202 } |
|
203 |
|
204 /*! |
|
205 Creates behavioural model i.e states |
|
206 */ |
|
207 void HsAddAppsToCollectionState::createStates() |
|
208 { |
|
209 //child states |
|
210 HSMENUTEST_FUNC_ENTRY("HsAddAppsToCollectionState::createStates"); |
|
211 |
|
212 mInitialState = new QState(this); |
|
213 QState *saveState = new QState(this); |
|
214 QFinalState *finalState = new QFinalState(this); |
|
215 |
|
216 mSelectCollectionState = new QState(this); |
|
217 mNewCollectionState = new QState(this); |
|
218 mAppsCheckListState = new QState(this); |
|
219 |
|
220 setInitialState(mInitialState); |
|
221 connect(saveState, SIGNAL(entered()),SLOT(save())); |
|
222 connect(finalState, SIGNAL(entered()),SLOT(cleanData())); |
|
223 connect(mNewCollectionState, SIGNAL(entered()),SLOT(newCollection())); |
|
224 connect(mSelectCollectionState, SIGNAL(entered()), |
|
225 SLOT(selectCollection())); |
|
226 connect(mAppsCheckListState, SIGNAL(entered()), |
|
227 SLOT(appsCheckListState())); |
|
228 |
|
229 //child states will gather needed data in parent sate |
|
230 //with signals and slots communication |
|
231 connect(this, SIGNAL(transitToSaveState(int)), |
|
232 SLOT(setCollectionId(int))); |
|
233 connect(this, SIGNAL(transitToSaveState(QString)), |
|
234 SLOT(setCollectionName(QString))); |
|
235 connect(this, SIGNAL(transitToSaveState(QList<int>)), |
|
236 SLOT(setAppList(QList<int>))); |
|
237 |
|
238 // Add a specific application to an existing collection |
|
239 // via item specific menu. |
|
240 // Add a specific item to a collection via collection specific menu. |
|
241 // Adding a new collection via the Collections view. |
|
242 mSelectCollectionState->addTransition(this, |
|
243 SIGNAL(transitToNewCollectionState()), mNewCollectionState); |
|
244 mSelectCollectionState->addTransition(this, |
|
245 SIGNAL(transitToSaveState(int)), saveState); |
|
246 mNewCollectionState->addTransition(this, |
|
247 SIGNAL(transitToSaveState(QString)), saveState); |
|
248 |
|
249 // Add one/many applications to an existing/a new collection |
|
250 // via the All view options menu. |
|
251 // Add items to a collection via the collection's view options menu. |
|
252 mSelectCollectionState->addTransition(this, |
|
253 SIGNAL(transitToSaveState(int)), saveState); |
|
254 mNewCollectionState->addTransition(this, |
|
255 SIGNAL(transitToSaveState(QString)), saveState); |
|
256 mAppsCheckListState->addTransition(this, |
|
257 SIGNAL(transitToSaveState(QList<int>)), saveState); |
|
258 mSelectCollectionState->addTransition(this, |
|
259 SIGNAL(transitToFinalState()),finalState); |
|
260 mNewCollectionState->addTransition(this, |
|
261 SIGNAL(transitToFinalState()), finalState); |
|
262 mAppsCheckListState->addTransition(this, |
|
263 SIGNAL(transitToSelectCollectionState()), mSelectCollectionState); |
|
264 mAppsCheckListState->addTransition(this, |
|
265 SIGNAL(transitToFinalState()), finalState); |
|
266 |
|
267 //transition to final state after save |
|
268 saveState->addTransition(finalState); |
|
269 HSMENUTEST_FUNC_EXIT("HsAddAppsToCollectionState::createStates"); |
|
270 |
|
271 } |
|
272 |
|
273 /*! |
|
274 Saves data in content arsenal(selected applications in collection). |
|
275 */ |
|
276 void HsAddAppsToCollectionState::save() |
|
277 { |
|
278 qDebug("AddAppsToCollectionState::save() - slot"); |
|
279 HSMENUTEST_FUNC_ENTRY("HsAddAppsToCollectionState::save"); |
|
280 //Adds new collection. |
|
281 if (!mCollectionName.isEmpty()) { |
|
282 mCollectionId = HsMenuService::createCollection(mCollectionName); |
|
283 } |
|
284 //Adds applications to colection. |
|
285 if ((mCollectionId > 0) && mAppList.count()) { |
|
286 HsMenuService::addApplicationsToCollection(mAppList, mCollectionId); |
|
287 HsMenuService::touch(mAppList); |
|
288 if (mShowConfirmation) { |
|
289 showMessageAppsAdded(mCollectionId); |
|
290 } |
|
291 } |
|
292 HSMENUTEST_FUNC_EXIT("HsAddAppsToCollectionState::save"); |
|
293 } |
|
294 |
|
295 /*! |
|
296 Cleans data after cancel() signal. |
|
297 */ |
|
298 void HsAddAppsToCollectionState::cleanData() |
|
299 { |
|
300 qDebug("AddAppsToCollectionState::cleanData() - slot"); |
|
301 HSMENUTEST_FUNC_ENTRY("HsAddAppsToCollectionState::cleanData"); |
|
302 mCollectionId = 0; |
|
303 mAppList.clear(); |
|
304 mCollectionName.clear(); |
|
305 mShowConfirmation = false; |
|
306 mActionType = NoActionType; |
|
307 HSMENUTEST_FUNC_EXIT("HsAddAppsToCollectionState::cleanData"); |
|
308 } |
|
309 |
|
310 /*! |
|
311 Derived from QState. |
|
312 Method invoked when a state is entered. |
|
313 \param event an event causing the entrance the state. |
|
314 */ |
|
315 void HsAddAppsToCollectionState::onEntry(QEvent *event) |
|
316 { |
|
317 qDebug("HsAddAppsToCollectionState::onEntry()"); |
|
318 HSMENUTEST_FUNC_ENTRY("HsAddAppsToCollectionState::onEntry"); |
|
319 QState::onEntry(event); |
|
320 HsMenuEvent *menuEvent = static_cast<HsMenuEvent *>(event); |
|
321 QVariantMap data = menuEvent->data(); |
|
322 |
|
323 mApplicationsSortAttribute = static_cast<Hs::HsSortAttribute>(data.value( |
|
324 Hs::appSortOrderKey).toInt()); |
|
325 |
|
326 const int itemId = data.value(Hs::itemIdKey).toInt(); |
|
327 mCollectionId = data.value(Hs::collectionIdKey).toInt(); |
|
328 |
|
329 if (itemId) { |
|
330 //add selected app item from allAppView or collectionView |
|
331 mAppList.append(itemId); |
|
332 mInitialState->addTransition(mSelectCollectionState); |
|
333 mShowConfirmation = true; |
|
334 } else if (mApplicationsSortAttribute != Hs::NoHsSortAttribute) { |
|
335 //add apps from allAppView options menu |
|
336 mActionType = ViaAllViewOptionMenuType; |
|
337 mInitialState->addTransition(mAppsCheckListState); |
|
338 mShowConfirmation = true; |
|
339 } else if (mCollectionId) { |
|
340 //add apps from collectionView options menu |
|
341 mApplicationsSortAttribute = Hs::AscendingNameHsSortAttribute; |
|
342 mInitialState->addTransition(mAppsCheckListState); |
|
343 } |
|
344 HSMENUTEST_FUNC_EXIT("HsAddAppsToCollectionState::onEntry"); |
|
345 } |
|
346 |
|
347 /*! |
|
348 Slot invoked when a state is exited. |
|
349 */ |
|
350 void HsAddAppsToCollectionState::stateExited() |
|
351 { |
|
352 HSMENUTEST_FUNC_ENTRY("HsAddAppsToCollectionState::stateExited"); |
|
353 QList<QAbstractTransition *> transitionsList = |
|
354 mInitialState->findChildren<QAbstractTransition *> (); |
|
355 if (transitionsList.count()) { |
|
356 mInitialState->removeTransition(transitionsList[0]); |
|
357 } |
|
358 delete mAppsCheckList; |
|
359 mAppsCheckList = NULL; |
|
360 |
|
361 if (mEditorDialog) { |
|
362 disconnect(mEditorDialog, SIGNAL(finished(HbAction*)), |
|
363 this, SLOT(editorDialogFinished(HbAction*))); |
|
364 mEditorDialog->close(); |
|
365 mEditorDialog = NULL; |
|
366 } |
|
367 |
|
368 if (mListDialog) { |
|
369 disconnect(mListDialog, SIGNAL(finished(HbAction*)), |
|
370 this, SLOT(listDialogFinished(HbAction*))); |
|
371 mListDialog->close(); |
|
372 mListDialog = NULL; |
|
373 } |
|
374 |
|
375 HSMENUTEST_FUNC_EXIT("HsAddAppsToCollectionState::stateExited"); |
|
376 qDebug("AddAppsToCollectionState::stateExited()"); |
|
377 } |
|
378 |
|
379 /*! |
|
380 Slot invoked when new collection state is entered.. |
|
381 */ |
|
382 void HsAddAppsToCollectionState::newCollection() |
|
383 { |
|
384 qDebug("HsAddAppsToCollectionState::newCollection"); |
|
385 HSMENUTEST_FUNC_ENTRY("HsAddAppsToCollectionState::newCollection"); |
|
386 mEditorDialog = new HsCollectionNameDialog(); |
|
387 mEditorDialog->open(this, SLOT(editorDialogFinished(HbAction*))); |
|
388 |
|
389 HSMENUTEST_FUNC_EXIT("HsAddAppsToCollectionState::newCollection"); |
|
390 } |
|
391 |
|
392 |
|
393 /*! |
|
394 Slot invoked when editor dialog with name of created collection is finished. |
|
395 */ |
|
396 void HsAddAppsToCollectionState::editorDialogFinished( |
|
397 HbAction* finishedAction) |
|
398 { |
|
399 if (finishedAction == mEditorDialog->actions().value(0)) { |
|
400 QString newName( |
|
401 mEditorDialog->uniqueCollectionName()); |
|
402 qDebug("HsAddAppsToCollectionState::newCollection() " |
|
403 "- emit collectionNameSelectedCl(newName)"); |
|
404 emit transitToSaveState(newName); |
|
405 } else { |
|
406 qDebug( |
|
407 "HsAddAppsToCollectionState::newCollection() - emit cancel()"); |
|
408 emit transitToFinalState(); |
|
409 } |
|
410 mEditorDialog = NULL; // set to null since this will be deleted after close |
|
411 } |
|
412 |
|
413 /*! |
|
414 Slot invoked when select collection state is entered. |
|
415 */ |
|
416 void HsAddAppsToCollectionState::selectCollection() |
|
417 { |
|
418 qDebug("HsAddAppsToCollectionState::selectCollection()"); |
|
419 HSMENUTEST_FUNC_ENTRY("HsAddAppsToCollectionState::selectCollection"); |
|
420 |
|
421 HbDocumentLoader loader; |
|
422 bool loadStatusOk = false; |
|
423 loader.load(HS_COLLECTION_DIALOG_LAYOUT, &loadStatusOk); |
|
424 Q_ASSERT_X(loadStatusOk, HS_COLLECTION_DIALOG_LAYOUT, |
|
425 "Error while loading docml file."); |
|
426 |
|
427 mListDialog = qobject_cast<HbDialog*>( |
|
428 loader.findWidget(HS_COLLECTION_DIALOG_NAME)); |
|
429 |
|
430 HbListView *listView = qobject_cast<HbListView*>( |
|
431 loader.findWidget(HS_COLLECTION_DIALOG_LIST_VIEW)); |
|
432 |
|
433 HbAction* createNewCollection = |
|
434 qobject_cast<HbAction*>(loader.findObject( |
|
435 HS_COLLECTION_DIALOG_CREATE_NEW_ACTION)); |
|
436 |
|
437 HbAction* cancel = qobject_cast<HbAction*>(loader.findObject( |
|
438 HS_COLLECTION_DIALOG_CANCEL_ACTION)); |
|
439 |
|
440 if (mListDialog != NULL) { |
|
441 mListDialog->setTimeout(HbPopup::NoTimeout); |
|
442 mListDialog->setAttribute(Qt::WA_DeleteOnClose, true); |
|
443 |
|
444 createNewCollection->setParent(mListDialog); |
|
445 cancel->setParent(mListDialog); |
|
446 |
|
447 mModel = standardItemModel(mCollectionId); |
|
448 mModel->setParent(mListDialog); |
|
449 listView->setModel(mModel); |
|
450 |
|
451 connect(listView, SIGNAL(activated(const QModelIndex &)), |
|
452 this, SLOT(collectionSelected(const QModelIndex &))); |
|
453 |
|
454 mListDialog->open(this, SLOT(listDialogFinished(HbAction*))); |
|
455 } |
|
456 |
|
457 HSMENUTEST_FUNC_EXIT("HsAddAppsToCollectionState::selectCollection"); |
|
458 } |
|
459 |
|
460 /*! |
|
461 Slot invoked when collection list dialog is finished |
|
462 */ |
|
463 void HsAddAppsToCollectionState::listDialogFinished(HbAction* finishedAction) |
|
464 { |
|
465 if (finishedAction == mListDialog->actions().value(0)) { |
|
466 qDebug("emit createNewCollection()"); |
|
467 emit transitToNewCollectionState(); |
|
468 } else if (finishedAction == mListDialog->actions().value(1)) { |
|
469 qDebug("emit cancel()"); |
|
470 emit transitToFinalState(); |
|
471 } |
|
472 |
|
473 mListDialog = NULL; // set to null since this will be deleted after close |
|
474 mModel = NULL;// set to null since this will be deleted with dialog |
|
475 } |
|
476 |
|
477 /*! |
|
478 Slot invoked when collection is selected |
|
479 \param modelIndex Index of selected item. |
|
480 */ |
|
481 void HsAddAppsToCollectionState::collectionSelected( |
|
482 const QModelIndex &modelIndex) |
|
483 { |
|
484 if (mListDialog) { |
|
485 int selectedCollection = mModel->data( |
|
486 modelIndex, CaItemModel::IdRole).toInt(); |
|
487 mListDialog->close(); |
|
488 qDebug("emit collectionSelected(%d)", selectedCollection); |
|
489 emit transitToSaveState(selectedCollection); |
|
490 } |
|
491 } |
|
492 |
|
493 /*! |
|
494 Slot connected to saving action of state. |
|
495 It is called when new application are addend to collection. |
|
496 \param id Id of collection to which applications were added. |
|
497 */ |
|
498 void HsAddAppsToCollectionState::showMessageAppsAdded(int id) |
|
499 { |
|
500 HSMENUTEST_FUNC_ENTRY("HsAddAppsToCollectionState::showMessageAppsAdded"); |
|
501 HbNotificationDialog *notificationDialog = new HbNotificationDialog(); |
|
502 notificationDialog->setAttribute(Qt::WA_DeleteOnClose); |
|
503 notificationDialog->setTitle( |
|
504 hbTrId("txt_applib_dpophead_added_to_collection_1") .arg( |
|
505 HsMenuService::getName(id))); |
|
506 notificationDialog->show(); |
|
507 mShowConfirmation = false; |
|
508 HSMENUTEST_FUNC_EXIT("HsAddAppsToCollectionState::showMessageAppsAdded"); |
|
509 } |
|
510 |
|
511 /*! |
|
512 Slot setting collection name. |
|
513 \param collectionName name of collection. |
|
514 */ |
|
515 void HsAddAppsToCollectionState::setCollectionName( |
|
516 const QString &collectionName) |
|
517 { |
|
518 qDebug() << "AddAppsToCollectionState::setCollectionName(" |
|
519 << collectionName << ") - slot"; |
|
520 |
|
521 mCollectionName = collectionName; |
|
522 } |
|
523 |
|
524 /*! |
|
525 Slot setting collection id.. |
|
526 \param collectionId id of collection. |
|
527 */ |
|
528 void HsAddAppsToCollectionState::setCollectionId(int collectionId) |
|
529 { |
|
530 qDebug() << "AddAppsToCollectionState::setCollectionId(" |
|
531 << collectionId << ") - slot"; |
|
532 |
|
533 mCollectionId = collectionId; |
|
534 } |
|
535 |
|
536 /*! |
|
537 Slot sets app list. |
|
538 \param appList list of applications ids. |
|
539 */ |
|
540 void HsAddAppsToCollectionState::setAppList(const QList<int> &appList) |
|
541 { |
|
542 qDebug() << "AddAppsToCollectionState::setAppList(" << appList |
|
543 << ") - slot"; |
|
544 |
|
545 mAppList = appList; |
|
546 } |
|
547 |
|
548 /*! |
|
549 Slot invoked when apps checklist state is entered. |
|
550 */ |
|
551 void HsAddAppsToCollectionState::appsCheckListState() |
|
552 { |
|
553 qDebug("HsAddAppsToCollectionState::appsCheckListState()"); |
|
554 HSMENUTEST_FUNC_ENTRY("HsAddAppsToCollectionState::appsCheckListState"); |
|
555 if (!mAppsCheckList) { |
|
556 mAppsCheckList = new HsAppsCheckList(); |
|
557 connect(mAppsCheckList, SIGNAL(commit(QList<int>)), |
|
558 SLOT(selectApplicationsDone(QList<int>))); |
|
559 |
|
560 } |
|
561 mAppsCheckList->setSortOrder(mApplicationsSortAttribute); |
|
562 mAppsCheckList->showAppsCheckboxList(mApplicationsSortAttribute); |
|
563 HSMENUTEST_FUNC_EXIT("HsAddAppsToCollectionState::appsCheckListState"); |
|
564 } |
|
565 /*! |
|
566 Slot connected trrigger action of secondary soft key of check list box. |
|
567 It is called when done button is selected. |
|
568 */ |
|
569 void HsAddAppsToCollectionState::selectApplicationsDone( |
|
570 const QList<int> &appList) |
|
571 { |
|
572 if (appList.count()) { |
|
573 qDebug("AppsCheckListState::selectApplicationsDone() " |
|
574 "- emit appsSelected(mAppList)"); |
|
575 if (mActionType == ViaAllViewOptionMenuType) { |
|
576 setAppList(appList); |
|
577 emit transitToSelectCollectionState(); |
|
578 } else { |
|
579 emit transitToSaveState(appList); |
|
580 } |
|
581 } else { |
|
582 qDebug( |
|
583 "AppsCheckListState::selectApplicationsDone() - emit cancel()"); |
|
584 emit transitToFinalState(); |
|
585 } |
|
586 } |
|
587 /*! |
|
588 Creates standard item model. |
|
589 \param collectionId id of collection to remove from model. |
|
590 \return QStandardItemModel - caller takes ownership. |
|
591 */ |
|
592 QStandardItemModel *HsAddAppsToCollectionState::standardItemModel( |
|
593 int collectionId) |
|
594 { |
|
595 HSMENUTEST_FUNC_ENTRY("HsListDialog::standartItemModel"); |
|
596 QScopedPointer<HsMenuItemModel> caModel( |
|
597 HsMenuService::getAllCollectionsModel()); |
|
598 caModel->setSecondLineVisibility(true); |
|
599 QStandardItemModel *model = new QStandardItemModel(this); |
|
600 QList<QStandardItem *> items; |
|
601 for (int row = 0; row < caModel->rowCount(); row++) { |
|
602 uint flags = caModel->data(caModel->index(row, 0), |
|
603 CaItemModel::FlagsRole).value<EntryFlags> (); |
|
604 int itemId = caModel->data(caModel->index(row, 0), |
|
605 CaItemModel::IdRole).toInt(); |
|
606 if ((flags & RemovableEntryFlag) && (itemId != collectionId)) { |
|
607 QStandardItem *standardItem = new QStandardItem(); |
|
608 standardItem->setData(caModel->data(caModel->index(row, 0), |
|
609 CaItemModel::IdRole), CaItemModel::IdRole); |
|
610 standardItem->setData(caModel->data(caModel->index(row, 0), |
|
611 Qt::DisplayRole), Qt::DisplayRole); |
|
612 standardItem->setData(caModel->data(caModel->index(row, 0), |
|
613 Qt::DecorationRole), Qt::DecorationRole); |
|
614 items << standardItem; |
|
615 } |
|
616 } |
|
617 model->insertColumn(0, items); |
|
618 |
|
619 HSMENUTEST_FUNC_EXIT("HsListDialog::standartItemModel"); |
|
620 return model; |
|
621 } |