14 * Description: Menu collection state. |
14 * Description: Menu collection state. |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include <qstatemachine.h> |
18 #include <qstatemachine.h> |
|
19 |
|
20 #include <HbGroupBox> |
|
21 #include <HbListView> |
19 #include <hbview.h> |
22 #include <hbview.h> |
20 #include <hbaction.h> |
23 #include <hbaction.h> |
21 #include <hbabstractviewitem.h> |
24 #include <hbabstractviewitem.h> |
22 #include <hsmenueventfactory.h> |
25 #include <hsmenueventfactory.h> |
23 #include <hbmenu.h> |
26 #include <hbmenu.h> |
24 #include <hbinstance.h> |
27 #include <hbinstance.h> |
25 #include <hbsearchpanel.h> |
28 #include <hbsearchpanel.h> |
26 |
29 |
27 #include "hsmenuevent.h" |
30 #include "hsmenuevent.h" |
28 #include "hsmenuservice.h" |
31 #include "hsmenuservice.h" |
|
32 #include "hsmenumodewrapper.h" |
29 #include "hsmenuitemmodel.h" |
33 #include "hsmenuitemmodel.h" |
30 #include "hsmenuview.h" |
34 #include "hsmenuviewbuilder.h" |
31 #include "cadefs.h" |
35 #include "cadefs.h" |
32 #include "caentry.h" |
36 #include "caentry.h" |
33 #include "hscollectionstate.h" |
37 #include "hscollectionstate.h" |
34 #include "hsaddappstocollectionstate.h" |
38 #include "hsaddappstocollectionstate.h" |
35 #include "hsapp_defs.h" |
39 #include "hsapp_defs.h" |
36 |
40 |
|
41 |
|
42 /*! |
|
43 \class HsCollectionState |
|
44 \ingroup group_hsmenustateplugin |
|
45 \brief Collection State. |
|
46 Displays a concrete collection. |
|
47 \lib ?library |
|
48 \see StateMachine |
|
49 */ |
|
50 |
|
51 /*! |
|
52 \var HsCollectionState::mSortAttribute |
|
53 Sort order. |
|
54 */ |
|
55 |
|
56 /*! |
|
57 \var HsCollectionState::mCollectionsSortAttribute |
|
58 All collections sort order. |
|
59 */ |
|
60 |
|
61 /*! |
|
62 \var HsCollectionState::mCollectionId |
|
63 The id of the current collection. |
|
64 */ |
|
65 |
|
66 /*! |
|
67 \var HsCollectionState::mCollectionType |
|
68 The type of the current collection. |
|
69 */ |
|
70 |
|
71 /*! |
|
72 \var HsCollectionState::mMenuView |
|
73 The List View widget. |
|
74 */ |
|
75 |
|
76 /*! |
|
77 \var HsCollectionState::mSecondarySoftkeyAction |
|
78 Secondary Softkey action. |
|
79 Backstepping functionality. |
|
80 Own. |
|
81 */ |
|
82 |
|
83 /*! |
|
84 \var HsCollectionState::mOldNavigationAction |
|
85 Old navigation icon. |
|
86 Not own. |
|
87 */ |
|
88 |
|
89 /*! |
|
90 \var HsCollectionState::mCollectionModel |
|
91 Item Model for the List. |
|
92 Own. |
|
93 */ |
|
94 |
|
95 /*! |
|
96 \var HsCollectionState::mOptions |
|
97 Options menu. |
|
98 Own. |
|
99 */ |
|
100 |
|
101 /*! |
|
102 \fn void HsCollectionState::sortOrderChanged(SHsSortAttribute sortOrder); |
|
103 This signal is emitted when sort order is changed to \a sortOrder. |
|
104 \param sortAttribute sort attribute |
|
105 */ |
|
106 |
|
107 /*! |
|
108 \fn void HsCollectionState::constructMenu(bool isDynamic); |
|
109 Set up Menu. |
|
110 \param isDynamic Decides which options should be added to menu. |
|
111 */ |
|
112 |
37 /*! |
113 /*! |
38 Constructor. |
114 Constructor. |
39 \param menuView Menu view. |
115 \param menuViewBuilder Menu view builder. |
|
116 \param menuMode reference to object representing menu mode (add mode on/add mode off). |
40 \param parent Owner. |
117 \param parent Owner. |
41 */ |
118 */ |
42 HsCollectionState::HsCollectionState(HsMenuView &menuView, QState *parent) : |
119 HsCollectionState::HsCollectionState(HsMenuViewBuilder &menuViewBuilder, |
|
120 HsMenuModeWrapper &menuMode, |
|
121 QState *parent) : |
43 QState(parent), |
122 QState(parent), |
44 mSortAttribute(LatestOnTopHsSortAttribute), |
123 mSortAttribute(LatestOnTopHsSortAttribute), |
45 mCollectionsSortAttribute(CustomHsSortAttribute), |
124 mCollectionsSortAttribute(CustomHsSortAttribute), |
46 mCollectionId(-1), mMenuView(menuView), |
125 mCollectionId(-1), |
47 mCollectionModel(0), mOptions(0) |
126 mMenuView(menuViewBuilder, HsCollectionContext), |
|
127 mMenuMode(menuMode), |
|
128 mSecondarySoftkeyAction(new HbAction(Hb::BackNaviAction, this)), |
|
129 mCollectionModel(0), |
|
130 mOptions(0), mContextModelIndex(), mContextMenu(0) |
48 { |
131 { |
49 construct(); |
132 construct(); |
50 } |
133 } |
51 |
134 |
52 /*! |
135 /*! |
57 HSMENUTEST_FUNC_ENTRY("HsCollectionState::construct"); |
140 HSMENUTEST_FUNC_ENTRY("HsCollectionState::construct"); |
58 const QString parentName = |
141 const QString parentName = |
59 parent() != 0 ? parent()->objectName() : QString(""); |
142 parent() != 0 ? parent()->objectName() : QString(""); |
60 setObjectName(parentName + "/collectionstate"); |
143 setObjectName(parentName + "/collectionstate"); |
61 |
144 |
62 //new action for backstepping |
145 |
63 mSecondarySoftkeyAction = new HbAction(Hb::BackAction, this); |
|
64 connect(this, SIGNAL(entered()),SLOT(stateEntered())); |
146 connect(this, SIGNAL(entered()),SLOT(stateEntered())); |
65 connect(this, SIGNAL(exited()),SLOT(stateExited())); |
147 connect(this, SIGNAL(exited()),SLOT(stateExited())); |
|
148 |
|
149 makeConnect(); |
|
150 mMenuView.view()-> |
|
151 setNavigationAction(mSecondarySoftkeyAction); |
|
152 |
66 HSMENUTEST_FUNC_EXIT("HsCollectionState::construct"); |
153 HSMENUTEST_FUNC_EXIT("HsCollectionState::construct"); |
67 } |
154 } |
68 |
155 |
69 /*! |
156 /*! |
70 Destructor. |
157 Destructor. |
71 */ |
158 */ |
72 HsCollectionState::~HsCollectionState() |
159 HsCollectionState::~HsCollectionState() |
73 { |
160 { |
|
161 makeDisconnect(); |
|
162 mMenuView.inactivate(); |
|
163 mMenuView.setModel(NULL); |
|
164 mMenuView.view()-> |
|
165 setNavigationAction(NULL); |
74 delete mCollectionModel; |
166 delete mCollectionModel; |
75 } |
167 } |
76 |
168 |
77 |
169 |
78 /*! |
170 /*! |
96 } |
188 } |
97 |
189 |
98 /*! |
190 /*! |
99 Slot invoked when a state is entered. |
191 Slot invoked when a state is entered. |
100 */ |
192 */ |
|
193 |
|
194 |
101 void HsCollectionState::stateEntered() |
195 void HsCollectionState::stateEntered() |
102 { |
196 { |
103 HSMENUTEST_FUNC_ENTRY("HsCollectionState::stateEntered"); |
197 HSMENUTEST_FUNC_ENTRY("HsCollectionState::stateEntered"); |
|
198 |
|
199 mMenuView.activate(); |
|
200 |
104 if (!mCollectionModel) { |
201 if (!mCollectionModel) { |
105 mCollectionModel = HsMenuService::getCollectionModel(mCollectionId, |
202 mCollectionModel = |
106 mSortAttribute, mCollectionType); |
203 HsMenuService::getCollectionModel( |
|
204 mCollectionId, mSortAttribute, mCollectionType); |
107 } else { |
205 } else { |
108 if (mCollectionType == collectionDownloadedTypeName()) { |
206 if (mCollectionType == collectionDownloadedTypeName()) { |
109 mCollectionModel->setFlagsOn(RemovableEntryFlag | VisibleEntryFlag); |
207 mCollectionModel->setFlagsOn(RemovableEntryFlag | VisibleEntryFlag); |
110 } else { |
208 } else { |
111 mCollectionModel->setFlagsOn(VisibleEntryFlag); |
209 mCollectionModel->setFlagsOn(VisibleEntryFlag); |
112 } |
210 } |
113 |
|
114 mCollectionModel->setParentId(mCollectionId); |
211 mCollectionModel->setParentId(mCollectionId); |
115 mCollectionModel->setSort( |
212 mCollectionModel->setSort(LatestOnTopHsSortAttribute); |
116 LatestOnTopHsSortAttribute); |
|
117 } |
213 } |
118 |
214 |
119 mMenuView.setModel(mCollectionModel); |
215 mMenuView.setModel(mCollectionModel); |
120 mMenuView.scrollTo(mCollectionModel->index(0), |
216 |
121 HbAbstractItemView::PositionAtTop); |
217 mMenuView.listView()->scrollTo( |
122 |
218 mCollectionModel->index(0), HbAbstractItemView::PositionAtTop); |
123 mMenuView.setLabelVisible(true); |
219 |
124 mMenuView.setLabel( |
220 mMenuView.viewLabel()->setHeading( |
125 mCollectionModel->root().data(Qt::DisplayRole).toString()); |
221 mCollectionModel->root().data(Qt::DisplayRole).toString()); |
126 |
|
127 |
222 |
128 if (!mOptions) { |
223 if (!mOptions) { |
129 mOptions = new HbMenu(); |
224 mOptions = new HbMenu(); |
130 mOptions->addAction(hbTrId("txt_applib_opt_task_switcher"), |
225 mOptions->addAction(hbTrId("txt_applib_opt_task_switcher"), |
131 this, |
226 this, |
176 } |
271 } |
177 |
272 |
178 mOptions->setParent(this); |
273 mOptions->setParent(this); |
179 mMenuView.view()->setMenu(mOptions); |
274 mMenuView.view()->setMenu(mOptions); |
180 } |
275 } |
181 mOldNavigationAction = mMenuView.view()->navigationAction(); |
|
182 mMenuView.view()->setNavigationAction(mSecondarySoftkeyAction); |
|
183 |
|
184 makeConnect(); |
|
185 HSMENUTEST_FUNC_EXIT("HsCollectionState::stateEntered"); |
276 HSMENUTEST_FUNC_EXIT("HsCollectionState::stateEntered"); |
186 } |
277 } |
187 |
278 |
188 /*! |
279 /*! |
189 Slot invoked when a state is exited. |
280 Slot invoked when a state is exited. |
190 */ |
281 */ |
191 void HsCollectionState::stateExited() |
282 void HsCollectionState::stateExited() |
192 { |
283 { |
193 HSMENUTEST_FUNC_ENTRY("HsCollectionState::stateExited"); |
284 HSMENUTEST_FUNC_ENTRY("HsCollectionState::stateExited"); |
|
285 |
194 mMenuView.setSearchPanelVisible(false); |
286 mMenuView.setSearchPanelVisible(false); |
195 |
287 mMenuView.inactivate(); |
196 makeDisconnect(); |
288 delete mCollectionModel; |
197 |
289 mCollectionModel = NULL; |
|
290 delete mOptions; |
198 mOptions = NULL; |
291 mOptions = NULL; |
199 |
292 if (mContextMenu) |
200 mMenuView.view()->setMenu(NULL); |
293 mContextMenu->close(); |
201 mMenuView.setLabelVisible(false); |
|
202 |
|
203 // revert navigation action |
|
204 mMenuView.view()->setNavigationAction(mOldNavigationAction); |
|
205 |
|
206 HSMENUTEST_FUNC_EXIT("HsCollectionState::stateExited"); |
294 HSMENUTEST_FUNC_EXIT("HsCollectionState::stateExited"); |
207 qDebug("CollectionState::stateExited()"); |
295 qDebug("CollectionState::stateExited()"); |
208 } |
296 } |
209 |
297 |
210 /*! |
298 /*! |
212 */ |
300 */ |
213 void HsCollectionState::makeConnect() |
301 void HsCollectionState::makeConnect() |
214 { |
302 { |
215 connect(mSecondarySoftkeyAction, SIGNAL(triggered()), |
303 connect(mSecondarySoftkeyAction, SIGNAL(triggered()), |
216 SLOT(backSteppingAction())); |
304 SLOT(backSteppingAction())); |
217 connect(&mMenuView, SIGNAL(activated(QModelIndex)), |
305 connect(&mMenuView, |
|
306 SIGNAL(activated(QModelIndex)), |
218 SLOT(listItemActivated(QModelIndex))); |
307 SLOT(listItemActivated(QModelIndex))); |
219 connect(&mMenuView, SIGNAL(longPressed(HbAbstractViewItem *, QPointF)), |
308 connect(&mMenuView, |
|
309 SIGNAL(longPressed(HbAbstractViewItem *, QPointF)), |
220 SLOT(listItemLongPressed(HbAbstractViewItem *, QPointF))); |
310 SLOT(listItemLongPressed(HbAbstractViewItem *, QPointF))); |
221 connect(mCollectionModel, SIGNAL(modelReset()),SLOT(updateLabel())); |
311 connect(mCollectionModel, SIGNAL(modelReset()),SLOT(updateLabel())); |
222 } |
312 } |
223 |
313 |
224 /*! |
314 /*! |
230 this, SLOT(backSteppingAction())); |
320 this, SLOT(backSteppingAction())); |
231 |
321 |
232 disconnect(mCollectionModel, SIGNAL(modelReset()), |
322 disconnect(mCollectionModel, SIGNAL(modelReset()), |
233 this, SLOT(updateLabel())); |
323 this, SLOT(updateLabel())); |
234 |
324 |
235 disconnect(&mMenuView, SIGNAL(activated(QModelIndex)), |
325 disconnect(&mMenuView, |
|
326 SIGNAL(activated(QModelIndex)), |
236 this, SLOT(listItemActivated(QModelIndex))); |
327 this, SLOT(listItemActivated(QModelIndex))); |
237 |
328 |
238 disconnect(&mMenuView, SIGNAL(longPressed(HbAbstractViewItem *, QPointF)), |
329 disconnect(&mMenuView, |
|
330 SIGNAL(longPressed(HbAbstractViewItem *, QPointF)), |
239 this, SLOT(listItemLongPressed(HbAbstractViewItem *, QPointF))); |
331 this, SLOT(listItemLongPressed(HbAbstractViewItem *, QPointF))); |
240 } |
332 } |
241 |
333 |
242 /*! |
334 /*! |
243 Open task switcher. |
335 Open task switcher. |
285 void HsCollectionState::listItemLongPressed(HbAbstractViewItem *item, |
377 void HsCollectionState::listItemLongPressed(HbAbstractViewItem *item, |
286 const QPointF &coords) |
378 const QPointF &coords) |
287 { |
379 { |
288 Q_UNUSED(item); |
380 Q_UNUSED(item); |
289 HSMENUTEST_FUNC_ENTRY("HsCollectionState::listItemLongPressed"); |
381 HSMENUTEST_FUNC_ENTRY("HsCollectionState::listItemLongPressed"); |
290 int itemId = item->modelIndex().data(CaItemModel::IdRole).toInt(); |
|
291 // create context menu |
382 // create context menu |
292 HbMenu *menu = new HbMenu(); |
383 mContextMenu = new HbMenu(); |
293 |
384 |
294 HbAction *addShortcutAction = menu->addAction(hbTrId( |
385 HbAction *addShortcutAction = mContextMenu->addAction(hbTrId( |
295 "txt_applib_menu_add_to_home_screen")); |
386 "txt_applib_menu_add_to_home_screen")); |
296 HbAction *addToCollection = menu->addAction(hbTrId( |
387 addShortcutAction->setData(AddToHomeScreenContextAction); |
|
388 HbAction *addToCollection = mContextMenu->addAction(hbTrId( |
297 "txt_applib_menu_add_to_collection")); |
389 "txt_applib_menu_add_to_collection")); |
|
390 addToCollection->setData(AddToCollectionContextAction); |
298 HbAction *removeAction(NULL); |
391 HbAction *removeAction(NULL); |
299 HbAction *uninstallAction(NULL); |
392 HbAction *uninstallAction(NULL); |
300 HbAction *appSettingsAction(NULL); |
393 HbAction *appSettingsAction(NULL); |
301 // we do not add remove option in collection download menu |
394 // we do not add remove option in locked collection |
302 // check conditions and hide irrelevant menu items |
395 // check conditions and hide irrelevant menu items |
303 if (mCollectionType != collectionDownloadedTypeName()) { |
396 EntryFlags rootFlags = |
304 removeAction = menu->addAction( |
397 mCollectionModel->root().data(CaItemModel::FlagsRole).value< |
|
398 EntryFlags> (); |
|
399 |
|
400 if (rootFlags & RemovableEntryFlag) { |
|
401 removeAction = mContextMenu->addAction( |
305 hbTrId("txt_applib_menu_remove_from_collection")); |
402 hbTrId("txt_applib_menu_remove_from_collection")); |
|
403 removeAction->setData(RemoveFromCollectionContextAction); |
306 } |
404 } |
307 |
405 |
308 EntryFlags flags = item->modelIndex().data(CaItemModel::FlagsRole).value< |
406 EntryFlags flags = item->modelIndex().data(CaItemModel::FlagsRole).value< |
309 EntryFlags> (); |
407 EntryFlags> (); |
310 |
408 |
311 if ((flags & RemovableEntryFlag)) { |
409 if ((flags & RemovableEntryFlag)) { |
312 uninstallAction = menu->addAction(hbTrId("txt_common_menu_delete")); |
410 uninstallAction = mContextMenu->addAction(hbTrId("txt_common_menu_delete")); |
|
411 uninstallAction->setData(UninstallContextAction); |
313 } |
412 } |
314 QSharedPointer<const CaEntry> entry = mCollectionModel->entry(item->modelIndex()); |
413 QSharedPointer<const CaEntry> entry = mCollectionModel->entry(item->modelIndex()); |
315 |
414 |
316 if (!(entry->attribute(appSettingsPlugin()).isEmpty())) { |
415 if (!(entry->attribute(appSettingsPlugin()).isEmpty())) { |
317 appSettingsAction = menu->addAction(hbTrId( |
416 appSettingsAction = mContextMenu->addAction(hbTrId( |
318 "txt_common_menu_settings")); |
417 "txt_common_menu_settings")); |
319 } |
418 appSettingsAction->setData(AppSettingContextAction); |
320 // choose proper action |
419 } |
321 if (HbAction *selectedAction = menu->exec(coords)) { |
420 |
322 |
421 mContextModelIndex = item->modelIndex(); |
323 if (selectedAction == addShortcutAction) { |
422 mContextMenu->setPreferredPos(coords); |
324 addElementToHomeScreen(item->modelIndex()); |
423 mContextMenu->setAttribute(Qt::WA_DeleteOnClose); |
325 } else if (selectedAction == addToCollection) { |
424 mContextMenu->open(this, SLOT(contextMenuAction(HbAction*))); |
|
425 |
|
426 |
|
427 HSMENUTEST_FUNC_EXIT("HsCollectionState::listItemLongPressed"); |
|
428 } |
|
429 |
|
430 /*! |
|
431 Handles context menu actions |
|
432 */ |
|
433 void HsCollectionState::contextMenuAction(HbAction *action) |
|
434 { |
|
435 HsContextAction command = |
|
436 static_cast<HsContextAction>(action->data().toInt()); |
|
437 |
|
438 const int itemId = mContextModelIndex.data(CaItemModel::IdRole).toInt(); |
|
439 |
|
440 switch (command) { |
|
441 case AddToHomeScreenContextAction: |
|
442 addElementToHomeScreen(mContextModelIndex); |
|
443 break; |
|
444 case AddToCollectionContextAction: |
326 machine()->postEvent( |
445 machine()->postEvent( |
327 HsMenuEventFactory::createAddAppsFromCallectionViewEvent( |
446 HsMenuEventFactory::createAddAppsFromCallectionViewEvent( |
328 mCollectionId, itemId, mCollectionsSortAttribute)); |
447 mCollectionId, itemId, mCollectionsSortAttribute)); |
329 } else if (selectedAction == uninstallAction) { |
448 break; |
|
449 case UninstallContextAction: |
330 HsMenuService::executeAction(itemId, removeActionIdentifier()); |
450 HsMenuService::executeAction(itemId, removeActionIdentifier()); |
331 } else if (selectedAction == removeAction) { |
451 break; |
|
452 case RemoveFromCollectionContextAction: |
332 machine()->postEvent( |
453 machine()->postEvent( |
333 HsMenuEventFactory::createRemoveAppFromCollectionEvent( |
454 HsMenuEventFactory::createRemoveAppFromCollectionEvent( |
334 itemId, mCollectionId)); |
455 itemId, mCollectionId)); |
335 } else if (selectedAction == appSettingsAction) { |
456 break; |
336 const int itemId = |
457 case AppSettingContextAction: |
337 item->modelIndex().data(CaItemModel::IdRole).toInt(); |
|
338 QMap<QString, QString> attributes = entry->attributes(); |
|
339 machine()->postEvent( |
458 machine()->postEvent( |
340 HsMenuEventFactory::createAppSettingsViewEvent(itemId)); |
459 HsMenuEventFactory::createAppSettingsViewEvent(itemId)); |
341 } |
460 break; |
342 |
461 default: |
343 mMenuView.setSearchPanelVisible(false); |
462 break; |
344 } |
463 } |
345 delete menu; |
464 |
346 HSMENUTEST_FUNC_EXIT("HsCollectionState::listItemLongPressed"); |
465 mMenuView.setSearchPanelVisible(false); |
347 } |
466 } |
348 |
467 |
349 /*! |
468 /*! |
350 Menu add applications action slot |
469 Menu add applications action slot |
351 */ |
470 */ |