31 #include "cadefs.h" |
31 #include "cadefs.h" |
32 #include "hsallappsstate.h" |
32 #include "hsallappsstate.h" |
33 #include "hsaddappstocollectionstate.h" |
33 #include "hsaddappstocollectionstate.h" |
34 #include "hsapp_defs.h" |
34 #include "hsapp_defs.h" |
35 #include "hsmenumodetransition.h" |
35 #include "hsmenumodetransition.h" |
36 |
36 #include "caentry.h" |
37 // --------------------------------------------------------------------------- |
37 #include "caservice.h" |
38 // --------------------------------------------------------------------------- |
38 |
39 // |
39 /*! |
|
40 Constructor. |
|
41 \param menuView Menu view. |
|
42 \param parent Owner. |
|
43 */ |
40 HsAllAppsState::HsAllAppsState(HsMenuView &menuView, QState *parent) : |
44 HsAllAppsState::HsAllAppsState(HsMenuView &menuView, QState *parent) : |
41 QState(parent), mSortAttribute(AscendingNameHsSortAttribute), |
45 QState(parent), mSortAttribute(AscendingNameHsSortAttribute), |
42 mCollectionsSortAttribute(LatestOnTopHsSortAttribute), |
46 mCollectionsSortAttribute(LatestOnTopHsSortAttribute), |
43 mMenuView(menuView), mAllAppsModel(0) |
47 mMenuView(menuView), mAllAppsModel(0) |
44 { |
48 { |
45 construct(); |
49 construct(); |
46 } |
50 } |
47 |
51 |
48 // --------------------------------------------------------------------------- |
52 /*! |
49 // --------------------------------------------------------------------------- |
53 Constructs contained objects. |
50 // |
54 */ |
51 void HsAllAppsState::construct() |
55 void HsAllAppsState::construct() |
52 { |
56 { |
53 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::construct"); |
57 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::construct"); |
54 |
58 |
55 QState *initialState = new QState(this); |
59 QState *initialState = new QState(this); |
64 initialState->addTransition(new HsMenuModeTransition( |
68 initialState->addTransition(new HsMenuModeTransition( |
65 mMenuView, NormalHsMenuMode, normalModeState)); |
69 mMenuView, NormalHsMenuMode, normalModeState)); |
66 initialState->addTransition(new HsMenuModeTransition( |
70 initialState->addTransition(new HsMenuModeTransition( |
67 mMenuView, AddHsMenuMode, addModeState)); |
71 mMenuView, AddHsMenuMode, addModeState)); |
68 |
72 |
69 setObjectName(this->parent()->objectName() + "/allappsstate"); |
73 const QString parentName = |
|
74 parent() != 0 ? parent()->objectName() : QString(""); |
|
75 setObjectName(parentName + "/allappsstate"); |
|
76 |
70 connect(this, SIGNAL(entered()),SLOT(stateEntered())); |
77 connect(this, SIGNAL(entered()),SLOT(stateEntered())); |
71 connect(this, SIGNAL(exited()),SLOT(stateExited())); |
78 connect(this, SIGNAL(exited()),SLOT(stateExited())); |
72 mAllAppsModel = HsMenuService::getAllApplicationsModel(mSortAttribute); |
79 mAllAppsModel = HsMenuService::getAllApplicationsModel(mSortAttribute); |
73 HSMENUTEST_FUNC_EXIT("HsAllAppsState::construct"); |
80 HSMENUTEST_FUNC_EXIT("HsAllAppsState::construct"); |
74 } |
81 } |
75 |
82 |
76 // --------------------------------------------------------------------------- |
83 /*! |
77 // --------------------------------------------------------------------------- |
84 Creates and installs menu options for the view |
78 // |
85 */ |
79 void HsAllAppsState::setMenuOptions() |
86 void HsAllAppsState::setMenuOptions() |
80 { |
87 { |
81 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::setMenuOptions"); |
88 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::setMenuOptions"); |
82 HbMenu *const mOptions = new HbMenu(); |
89 HbMenu *const mOptions = new HbMenu(); |
83 mOptions->addAction(hbTrId("txt_applib_opt_task_switcher"), |
90 mOptions->addAction(hbTrId("txt_applib_opt_task_switcher"), |
84 this, |
91 this, SLOT(openTaskSwitcher())); |
85 SLOT(openTaskSwitcher())); |
|
86 mOptions->addAction(hbTrId("txt_applib_opt_add_to_collection"), |
92 mOptions->addAction(hbTrId("txt_applib_opt_add_to_collection"), |
87 this, |
93 this, SLOT(addToCollection())); |
88 SLOT(addToCollection())); |
94 mOptions->addAction(hbTrId("txt_applib_opt_check_software_updates"), |
|
95 this, SLOT(checkSoftwareUpdates())); |
89 |
96 |
90 HbMenu *const sortMenu = mOptions->addMenu(hbTrId( |
97 HbMenu *const sortMenu = mOptions->addMenu(hbTrId( |
91 "txt_applib_opt_sort_by")); |
98 "txt_applib_opt_sort_by")); |
92 //Grouped options are exclusive by default. |
99 //Grouped options are exclusive by default. |
93 QActionGroup *sortGroup = new QActionGroup(mOptions); |
100 QActionGroup *sortGroup = new QActionGroup(mOptions); |
94 |
101 |
95 sortGroup->addAction( |
102 sortGroup->addAction( |
96 sortMenu->addAction(hbTrId("txt_applib_opt_sub_ascending"), |
103 sortMenu->addAction(hbTrId("txt_applib_opt_sub_ascending"), |
97 this, |
104 this, SLOT(ascendingMenuAction()))); |
98 SLOT(ascendingMenuAction()))); |
|
99 sortGroup->addAction( |
105 sortGroup->addAction( |
100 sortMenu->addAction(hbTrId("txt_applib_opt_sub_descending"), |
106 sortMenu->addAction(hbTrId("txt_applib_opt_sub_descending"), |
101 this, |
107 this, SLOT(descendingMenuAction()))); |
102 SLOT(descendingMenuAction()))); |
108 |
|
109 mOptions->addAction(hbTrId("txt_applib_subtitle_installed"), |
|
110 this, SLOT(openInstalledView())); |
|
111 |
103 mOptions->setParent(this); |
112 mOptions->setParent(this); |
104 foreach(QAction *action, sortMenu->actions()) { |
113 foreach(QAction *action, sortMenu->actions()) { |
105 action->setCheckable(true); |
114 action->setCheckable(true); |
106 } |
115 } |
107 int currentSortingPosition(-1); |
116 int currentSortingPosition(-1); |
120 } |
129 } |
121 mMenuView.view()->setMenu(mOptions); |
130 mMenuView.view()->setMenu(mOptions); |
122 HSMENUTEST_FUNC_EXIT("HsAllAppsState::setMenuOptions"); |
131 HSMENUTEST_FUNC_EXIT("HsAllAppsState::setMenuOptions"); |
123 } |
132 } |
124 |
133 |
125 // --------------------------------------------------------------------------- |
134 /*! |
126 // --------------------------------------------------------------------------- |
135 Destructor. |
127 // |
136 */ |
128 HsAllAppsState::~HsAllAppsState() |
137 HsAllAppsState::~HsAllAppsState() |
129 { |
138 { |
130 delete mAllAppsModel; |
139 delete mAllAppsModel; |
131 } |
140 } |
132 |
141 |
133 |
142 /*! |
134 // --------------------------------------------------------------------------- |
143 Populates all applications |
135 // --------------------------------------------------------------------------- |
144 */ |
136 // |
|
137 void HsAllAppsState::scrollToBeginning() |
145 void HsAllAppsState::scrollToBeginning() |
138 { |
146 { |
139 mBookmark = mAllAppsModel->index(0); |
147 mBookmark = mAllAppsModel->index(0); |
140 } |
148 } |
141 |
149 |
142 // --------------------------------------------------------------------------- |
150 /*! |
143 // --------------------------------------------------------------------------- |
151 Slot invoked when a state is entered. |
144 // |
152 */ |
145 void HsAllAppsState::stateEntered() |
153 void HsAllAppsState::stateEntered() |
146 { |
154 { |
147 qDebug("AllAppsState::stateEntered()"); |
155 qDebug("AllAppsState::stateEntered()"); |
148 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::stateEntered"); |
156 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::stateEntered"); |
149 |
157 |
150 mMenuView.setModel(mAllAppsModel); |
158 mMenuView.setModel(mAllAppsModel); |
151 mMenuView.scrollTo(mBookmark, HbAbstractItemView::PositionAtTop); |
159 mMenuView.scrollTo(mBookmark, HbAbstractItemView::PositionAtTop); |
152 HSMENUTEST_FUNC_EXIT("HsAllAppsState::stateEntered"); |
160 HSMENUTEST_FUNC_EXIT("HsAllAppsState::stateEntered"); |
153 } |
161 } |
154 |
162 |
155 // --------------------------------------------------------------------------- |
163 /*! |
156 // --------------------------------------------------------------------------- |
164 Slot invoked when add mode entered. |
157 // |
165 */ |
158 void HsAllAppsState::normalModeEntered() |
166 void HsAllAppsState::normalModeEntered() |
159 { |
167 { |
160 setMenuOptions(); |
168 setMenuOptions(); |
161 |
169 |
162 connect(&mMenuView, SIGNAL(activated(QModelIndex)), |
170 connect(&mMenuView, SIGNAL(activated(QModelIndex)), |
226 mMenuView.setSearchPanelVisible(false); |
246 mMenuView.setSearchPanelVisible(false); |
227 |
247 |
228 HSMENUTEST_FUNC_EXIT("HsAllAppsState::listItemActivated"); |
248 HSMENUTEST_FUNC_EXIT("HsAllAppsState::listItemActivated"); |
229 } |
249 } |
230 |
250 |
231 // --------------------------------------------------------------------------- |
251 /*! |
232 // --------------------------------------------------------------------------- |
252 Slot connected to List widget in add mode. |
233 // |
253 |
|
254 \param index Model index of the activated item. |
|
255 */ |
234 void HsAllAppsState::addActivated(const QModelIndex &index) |
256 void HsAllAppsState::addActivated(const QModelIndex &index) |
235 { |
257 { |
236 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::addActivated"); |
258 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::addActivated"); |
237 mMenuView.setSearchPanelVisible(false); |
|
238 addToHomeScreen(index); |
259 addToHomeScreen(index); |
239 machine()->postEvent( |
260 machine()->postEvent( |
240 HsMenuEventFactory::createOpenHomeScreenEvent()); |
261 HsMenuEventFactory::createOpenHomeScreenEvent()); |
241 HSMENUTEST_FUNC_EXIT("HsAllAppsState::addActivated"); |
262 HSMENUTEST_FUNC_EXIT("HsAllAppsState::addActivated"); |
242 } |
263 } |
243 |
264 |
244 /*! |
265 /*! |
245 Handles long-item-pressed event in all apps view by showing context menu |
266 Handles long-item-pressed event in all apps view by showing context menu |
246 \param item the event pertains to |
267 \param item View item |
247 \param position at which context menu is shown |
268 \param coords Press point coordinates |
248 */ |
269 */ |
249 void HsAllAppsState::listItemLongPressed(HbAbstractViewItem *item, |
270 void HsAllAppsState::listItemLongPressed(HbAbstractViewItem *item, |
250 const QPointF &coords) |
271 const QPointF &coords) |
251 { |
272 { |
252 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::listItemLongPressed"); |
273 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::listItemLongPressed"); |
253 |
274 |
254 mMenuView.setSearchPanelVisible(false); |
|
255 |
275 |
256 // create context menu |
276 // create context menu |
257 HbMenu *menu = new HbMenu(); |
277 HbMenu *menu = new HbMenu(); |
258 |
278 |
259 HbAction *addToHomeScreenAction = menu->addAction(hbTrId( |
279 HbAction *addToHomeScreenAction = menu->addAction(hbTrId( |
262 HbAction *addToCollectionAction = menu->addAction(hbTrId( |
282 HbAction *addToCollectionAction = menu->addAction(hbTrId( |
263 "txt_applib_menu_add_to_collection")); |
283 "txt_applib_menu_add_to_collection")); |
264 |
284 |
265 HbAction *uninstallAction = menu->addAction(hbTrId( |
285 HbAction *uninstallAction = menu->addAction(hbTrId( |
266 "txt_common_menu_delete")); |
286 "txt_common_menu_delete")); |
|
287 HbAction *appSettingsAction(NULL); |
267 |
288 |
268 // check conditions and hide irrelevant menu items |
289 // check conditions and hide irrelevant menu items |
269 |
290 |
|
291 QSharedPointer<const CaEntry> entry = mAllAppsModel->entry(item->modelIndex()); |
|
292 |
|
293 if (!(entry->attribute(appSettingsPlugin()).isEmpty())) { |
|
294 appSettingsAction = menu->addAction(hbTrId( |
|
295 "txt_common_menu_settings")); |
|
296 } |
270 EntryFlags flags = item->modelIndex().data( |
297 EntryFlags flags = item->modelIndex().data( |
271 CaItemModel::FlagsRole).value<EntryFlags> (); |
298 CaItemModel::FlagsRole).value<EntryFlags> (); |
272 |
299 |
273 if (!(flags & RemovableEntryFlag)) { |
300 if (!(flags & RemovableEntryFlag)) { |
274 uninstallAction->setVisible(false); |
301 uninstallAction->setVisible(false); |
275 } |
302 } |
276 // choose proper action |
303 // choose proper action |
277 if (HbAction *selectedAction = menu->exec(coords)) { |
304 if (HbAction *selectedAction = menu->exec(coords)) { |
|
305 |
278 if (selectedAction == addToHomeScreenAction) { |
306 if (selectedAction == addToHomeScreenAction) { |
279 addToHomeScreen(item->modelIndex()); |
307 addToHomeScreen(item->modelIndex()); |
280 } else if (selectedAction == addToCollectionAction) { |
308 } else if (selectedAction == addToCollectionAction) { |
281 // Addding a specific application to |
309 // Addding a specific application to |
282 // an existing collection via item specific menu. |
310 // an existing collection via item specific menu. |
283 const int itemId = |
311 const int itemId = |
284 item->modelIndex().data(CaItemModel::IdRole).toInt(); |
312 item->modelIndex().data(CaItemModel::IdRole).toInt(); |
285 machine()->postEvent( |
313 machine()->postEvent( |
286 HsMenuEventFactory::createAddAppsFromApplicationsViewEvent( |
314 HsMenuEventFactory::createAddAppsFromApplicationsViewEvent( |
287 mSortAttribute, mCollectionsSortAttribute, itemId)); |
315 mSortAttribute, mCollectionsSortAttribute, itemId)); |
288 |
|
289 } else if (selectedAction == uninstallAction) { |
316 } else if (selectedAction == uninstallAction) { |
290 const int itemId = |
317 const int itemId = |
291 item->modelIndex().data(CaItemModel::IdRole).toInt(); |
318 item->modelIndex().data(CaItemModel::IdRole).toInt(); |
292 HsMenuService::executeAction(itemId, removeActionIdentifier()); |
319 HsMenuService::executeAction(itemId, removeActionIdentifier()); |
|
320 } else if (selectedAction == appSettingsAction) { |
|
321 const int itemId = |
|
322 item->modelIndex().data(CaItemModel::IdRole).toInt(); |
|
323 QMap<QString, QString> attributes = entry->attributes(); |
|
324 machine()->postEvent( |
|
325 HsMenuEventFactory::createAppSettingsViewEvent(itemId)); |
293 } |
326 } |
|
327 mMenuView.setSearchPanelVisible(false); |
|
328 |
294 } |
329 } |
295 delete menu; |
330 delete menu; |
296 HSMENUTEST_FUNC_EXIT("HsAllAppsState::listItemLongPressed"); |
331 HSMENUTEST_FUNC_EXIT("HsAllAppsState::listItemLongPressed"); |
297 } |
332 } |
298 |
333 |
299 // --------------------------------------------------------------------------- |
334 /*! |
300 // --------------------------------------------------------------------------- |
335 Slot connected to List widget in add mode. |
301 // |
336 Called when item long pressed. |
|
337 \param item View item. |
|
338 \param coords Press point coordinates. |
|
339 */ |
302 void HsAllAppsState::addLongPressed(HbAbstractViewItem *item, |
340 void HsAllAppsState::addLongPressed(HbAbstractViewItem *item, |
303 const QPointF &coords) |
341 const QPointF &coords) |
304 { |
342 { |
305 Q_UNUSED(coords); |
343 Q_UNUSED(coords); |
306 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::addLongPressed"); |
344 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::addLongPressed"); |
307 mMenuView.setSearchPanelVisible(false); |
|
308 addToHomeScreen(item->modelIndex()); |
345 addToHomeScreen(item->modelIndex()); |
309 machine()->postEvent( |
346 machine()->postEvent( |
310 HsMenuEventFactory::createOpenHomeScreenEvent()); |
347 HsMenuEventFactory::createOpenHomeScreenEvent()); |
311 HSMENUTEST_FUNC_EXIT("HsAllAppsState::addLongPressed"); |
348 HSMENUTEST_FUNC_EXIT("HsAllAppsState::addLongPressed"); |
312 |
349 |
313 } |
350 } |
314 |
351 |
315 // --------------------------------------------------------------------------- |
352 /*! |
316 // --------------------------------------------------------------------------- |
353 Slot called when application is adding to collection. |
317 // |
354 */ |
318 void HsAllAppsState::addToCollection() |
355 void HsAllAppsState::addToCollection() |
319 { |
356 { |
320 // Add one/many applications to |
357 // Add one/many applications to |
321 // a new/an existing collection via the All view |
358 // a new/an existing collection via the All view |
322 machine()->postEvent( |
359 machine()->postEvent( |
323 HsMenuEventFactory::createAddAppsFromApplicationsViewEvent( |
360 HsMenuEventFactory::createAddAppsFromApplicationsViewEvent( |
324 mSortAttribute, mCollectionsSortAttribute)); |
361 mSortAttribute, mCollectionsSortAttribute)); |
325 } |
362 } |
326 |
363 |
327 /*! |
364 /*! |
|
365 Triggers event so that a installed applications state is entered. |
|
366 \retval void |
|
367 */ |
|
368 #ifdef COVERAGE_MEASUREMENT |
|
369 #pragma CTC SKIP |
|
370 #endif //COVERAGE_MEASUREMENT |
|
371 void HsAllAppsState::openInstalledView() |
|
372 { |
|
373 machine()->postEvent(HsMenuEventFactory::createOpenInstalledViewEvent()); |
|
374 } |
|
375 #ifdef COVERAGE_MEASUREMENT |
|
376 #pragma CTC ENDSKIP |
|
377 #endif //COVERAGE_MEASUREMENT |
|
378 |
|
379 /*! |
328 Triggers event so that a state adding to Home Screen is reached |
380 Triggers event so that a state adding to Home Screen is reached |
329 \param index of an item to be added to homescreen |
381 \param index of an item to be added to homescreen |
330 \retval void |
382 \retval void |
331 */ |
383 */ |
332 void HsAllAppsState::addToHomeScreen(const QModelIndex &index) |
384 void HsAllAppsState::addToHomeScreen(const QModelIndex &index) |
333 { |
385 { |
334 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::addToHomeScreen"); |
386 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::addToHomeScreen"); |
335 const CaEntry *entry = mAllAppsModel->entry(index); |
387 QSharedPointer<const CaEntry> entry = mAllAppsModel->entry(index); |
336 |
388 |
337 QMap<QString, QString> attributes = entry->attributes(); |
|
338 |
|
339 machine()-> postEvent(HsMenuEventFactory::createAddToHomeScreenEvent( |
389 machine()-> postEvent(HsMenuEventFactory::createAddToHomeScreenEvent( |
340 entry->id(), |
390 entry->id())); |
341 entry->entryTypeName(), |
|
342 entry->attribute(widgetUriAttributeName()), |
|
343 entry->attribute(widgetLibraryAttributeName()), |
|
344 &attributes)); |
|
345 |
391 |
346 HSMENUTEST_FUNC_EXIT("HsAllAppsState::addToHomeScreen"); |
392 HSMENUTEST_FUNC_EXIT("HsAllAppsState::addToHomeScreen"); |
347 } |
393 } |
348 |
394 |
349 // --------------------------------------------------------------------------- |
395 /*! |
350 // --------------------------------------------------------------------------- |
396 Menu ascending sort action slot. |
351 // |
397 */ |
352 void HsAllAppsState::ascendingMenuAction() |
398 void HsAllAppsState::ascendingMenuAction() |
353 { |
399 { |
354 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::ascendingMenuAction"); |
400 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::ascendingMenuAction"); |
355 mSortAttribute = AscendingNameHsSortAttribute; |
401 mSortAttribute = AscendingNameHsSortAttribute; |
356 mAllAppsModel->setSort(mSortAttribute); |
402 mAllAppsModel->setSort(mSortAttribute); |
357 HSMENUTEST_FUNC_EXIT("HsAllAppsState::ascendingMenuAction"); |
403 HSMENUTEST_FUNC_EXIT("HsAllAppsState::ascendingMenuAction"); |
358 } |
404 } |
359 |
405 |
360 // --------------------------------------------------------------------------- |
406 /** |
361 // --------------------------------------------------------------------------- |
407 * Sets collections sort order |
362 // |
408 * |
|
409 * @since S60 ?S60_version. |
|
410 * @param sortOrder sort order. |
|
411 */ |
363 void HsAllAppsState::collectionsSortOrder( |
412 void HsAllAppsState::collectionsSortOrder( |
364 HsSortAttribute sortOrder) |
413 HsSortAttribute sortOrder) |
365 { |
414 { |
366 mCollectionsSortAttribute = sortOrder; |
415 mCollectionsSortAttribute = sortOrder; |
367 } |
416 } |
368 |
417 |
369 // --------------------------------------------------------------------------- |
418 /*! |
370 // --------------------------------------------------------------------------- |
419 Menu descending sort action slot. |
371 // |
420 */ |
372 void HsAllAppsState::descendingMenuAction() |
421 void HsAllAppsState::descendingMenuAction() |
373 { |
422 { |
374 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::descendingMenuAction"); |
423 HSMENUTEST_FUNC_ENTRY("HsAllAppsState::descendingMenuAction"); |
375 mSortAttribute = DescendingNameHsSortAttribute; |
424 mSortAttribute = DescendingNameHsSortAttribute; |
376 mAllAppsModel->setSort(mSortAttribute); |
425 mAllAppsModel->setSort(mSortAttribute); |