86 HsMenuModeWrapper &menuMode, |
86 HsMenuModeWrapper &menuMode, |
87 HsMainWindow &mainWindow, |
87 HsMainWindow &mainWindow, |
88 QState *parent) : |
88 QState *parent) : |
89 HsBaseViewState(mainWindow, menuMode, parent), |
89 HsBaseViewState(mainWindow, menuMode, parent), |
90 mSortAttribute(Hs::LatestOnTopHsSortAttribute), |
90 mSortAttribute(Hs::LatestOnTopHsSortAttribute), |
91 mCollectionId(-1) |
91 mCollectionId(-1), |
|
92 mLatestOnTopMenuAction(0), |
|
93 mOldestOnTopMenuAction(0) |
92 { |
94 { |
93 initialize(menuViewBuilder, HsCollectionContext); |
95 initialize(menuViewBuilder, HsCollectionContext); |
94 construct(); |
96 construct(); |
95 } |
97 } |
96 |
98 |
199 mViewOptions->addAction( |
201 mViewOptions->addAction( |
200 hbTrId("txt_common_opt_delete"), |
202 hbTrId("txt_common_opt_delete"), |
201 this, |
203 this, |
202 SLOT(deleteAction())); |
204 SLOT(deleteAction())); |
203 } |
205 } |
204 if (mCollectionType == Hs::collectionDownloadedTypeName && |
206 if (mCollectionType == Hs::collectionDownloadedTypeName && |
205 mModel->rowCount() > 0) { |
207 mModel->rowCount() > 0) { |
206 HbMenu *sortMenu = mViewOptions->addMenu( |
208 mLatestOnTopMenuAction = mViewOptions->addAction( |
207 hbTrId("txt_applib_opt_sort_by")); |
209 hbTrId("txt_applib_menu_sort_by_latest_on_top"), |
208 //Grouped options are exclusive by default. |
210 this, SLOT(latestOnTopMenuAction())); |
209 QActionGroup *sortGroup = new QActionGroup(this); |
211 mOldestOnTopMenuAction = mViewOptions->addAction( |
210 sortGroup->addAction( |
212 hbTrId("txt_applib_menu_sort_by_oldest_on_top"), |
211 sortMenu->addAction( |
213 this, SLOT(oldestOnTopMenuAction())); |
212 hbTrId("txt_applib_opt_sub_latest_on_top"), |
214 |
213 this, |
215 if(mSortAttribute == Hs::LatestOnTopHsSortAttribute) |
214 SLOT(latestOnTopMenuAction()))); |
216 { |
215 sortGroup->addAction( |
217 mLatestOnTopMenuAction->setVisible(false); |
216 sortMenu->addAction( |
218 } else { |
217 hbTrId("txt_applib_opt_sub_oldest_on_top"), |
219 mOldestOnTopMenuAction->setVisible(false); |
218 this, |
|
219 SLOT(oldestOnTopMenuAction()))); |
|
220 foreach(QAction *action, sortMenu->actions()) { |
|
221 action->setCheckable(true); |
|
222 } |
220 } |
223 static const int defaultSortingPosition = 0; |
221 |
224 sortGroup->actions().at(defaultSortingPosition)->setChecked(true); |
222 } |
225 } |
223 |
|
224 |
226 mMenuView->view()->setMenu(mViewOptions); |
225 mMenuView->view()->setMenu(mViewOptions); |
227 HSMENUTEST_FUNC_EXIT("HsAllCollectionsState::setMenuOptions"); |
226 HSMENUTEST_FUNC_EXIT("HsAllCollectionsState::setMenuOptions"); |
228 } |
227 } |
229 |
228 |
230 /*! |
229 /*! |
297 /*! |
296 /*! |
298 Handles context menu actions |
297 Handles context menu actions |
299 \param action action taken in context menu |
298 \param action action taken in context menu |
300 */ |
299 */ |
301 void HsCollectionState::contextMenuAction(HbAction *action) |
300 void HsCollectionState::contextMenuAction(HbAction *action) |
302 { |
301 { |
303 HsBaseViewState::contextMenuAction(action); |
302 Hs::HsContextAction command = static_cast<Hs::HsContextAction> (action->data().toInt()); |
304 Hs::HsContextAction command = |
303 |
305 static_cast<Hs::HsContextAction>(action->data().toInt()); |
304 if (command == Hs::RemoveFromCollectionContextAction) { |
306 if (command == Hs::RemoveFromCollectionContextAction ) { |
305 const int itemId = mContextModelIndex.data( |
307 const int itemId = mContextModelIndex.data(CaItemModel::IdRole).toInt(); |
306 CaItemModel::IdRole).toInt(); |
308 machine()->postEvent( |
307 machine()->postEvent( |
309 HsMenuEventFactory::createRemoveAppFromCollectionEvent( |
308 HsMenuEventFactory::createRemoveAppFromCollectionEvent(itemId, |
310 itemId, mCollectionId)); |
309 mCollectionId)); |
|
310 HsMenuService::touch(itemId); |
|
311 } else if ( |
|
312 command == Hs::AddToCollectionFromCollectionViewContextAction) { |
|
313 const int itemId = mContextModelIndex.data( |
|
314 CaItemModel::IdRole).toInt(); |
|
315 machine()->postEvent( |
|
316 HsMenuEventFactory::createAddAppsFromCollectionViewEvent( |
|
317 mCollectionId, itemId)); |
|
318 HsMenuService::touch(itemId); |
|
319 } else { |
|
320 HsBaseViewState::contextMenuAction(action); |
311 } |
321 } |
312 } |
322 } |
313 |
323 |
314 /*! |
324 /*! |
315 Handler to be called when model becomes not empty or model becomes empty. |
325 Handler to be called when model becomes not empty or model becomes empty. |
316 \param empty \a true when model becomes empty \a false otherwise. |
326 \param empty \a true when model becomes empty \a false otherwise. |
317 */ |
327 */ |
318 void HsCollectionState::handleEmptyChange(bool empty) |
328 void HsCollectionState::handleEmptyChange(bool empty) |
319 { |
329 { |
320 |
330 EntryFlags flags = mModel->root().data( |
321 EntryFlags flags = |
331 CaItemModel::FlagsRole).value<EntryFlags> (); |
322 mModel->root().data(CaItemModel::FlagsRole).value< |
|
323 EntryFlags> (); |
|
324 |
332 |
325 if (empty){ |
333 if (empty){ |
326 if (flags & RemovableEntryFlag){ |
334 mMenuView->reset(HsEmptyLabelContext); |
327 mMenuView->reset(HsButtonContext); |
|
328 connect(mMenuView->contentButton(), |
|
329 SIGNAL(clicked()), this, SLOT(addAppsAction()), |
|
330 Qt::UniqueConnection); |
|
331 } else { |
|
332 mMenuView->reset(HsEmptyLabelContext); |
|
333 } |
|
334 |
|
335 } else { |
335 } else { |
336 mMenuView->reset(HsItemViewContext); |
336 mMenuView->reset(HsItemViewContext); |
337 mMenuView->setModel(mModel); |
337 mMenuView->setModel(mModel); |
338 mMenuView->listView()->scrollTo( |
338 mMenuView->listView()->scrollTo( |
339 mModel->index(0), HbAbstractItemView::PositionAtTop); |
339 mModel->index(0), HbAbstractItemView::PositionAtTop); |
340 } |
340 } |
341 |
|
342 mMenuView->disableSearch(empty); |
341 mMenuView->disableSearch(empty); |
343 |
|
344 mMenuView->activate(); |
342 mMenuView->activate(); |
345 |
|
346 setMenuOptions(); |
343 setMenuOptions(); |
347 } |
344 } |
348 |
345 |
349 |
346 |
350 /*! |
347 /*! |
468 */ |
465 */ |
469 void HsCollectionState::latestOnTopMenuAction() |
466 void HsCollectionState::latestOnTopMenuAction() |
470 { |
467 { |
471 mSortAttribute = Hs::LatestOnTopHsSortAttribute; |
468 mSortAttribute = Hs::LatestOnTopHsSortAttribute; |
472 mModel->setSort(mSortAttribute); |
469 mModel->setSort(mSortAttribute); |
473 emit sortOrderChanged(mSortAttribute); |
470 mLatestOnTopMenuAction->setVisible(false); |
|
471 mOldestOnTopMenuAction->setVisible(true); |
474 } |
472 } |
475 |
473 |
476 /*! |
474 /*! |
477 A Slot called when an action for sorting (oldest |
475 A Slot called when an action for sorting (oldest |
478 on top) is invoked for Downloaded collection. |
476 on top) is invoked for Downloaded collection. |
479 */ |
477 */ |
480 void HsCollectionState::oldestOnTopMenuAction() |
478 void HsCollectionState::oldestOnTopMenuAction() |
481 { |
479 { |
482 mSortAttribute = Hs::OldestOnTopHsSortAttribute; |
480 mSortAttribute = Hs::OldestOnTopHsSortAttribute; |
483 mModel->setSort(mSortAttribute); |
481 mModel->setSort(mSortAttribute); |
484 emit sortOrderChanged(mSortAttribute); |
482 mLatestOnTopMenuAction->setVisible(true); |
|
483 mOldestOnTopMenuAction->setVisible(false); |
485 } |
484 } |
486 |
485 |
487 /*! |
486 /*! |
488 A Slot called when an arrange operation |
487 A Slot called when an arrange operation |
489 is invoked for a static collection. |
488 is invoked for a static collection. |