homescreenapp/stateplugins/hsapplibrarystateplugin/src/hsinstalledappsstate.cpp
changeset 85 35368b604b28
parent 77 4b195f3bea29
child 92 6727c5d0afc7
equal deleted inserted replaced
77:4b195f3bea29 85:35368b604b28
    49  \param parent Owner.
    49  \param parent Owner.
    50  */
    50  */
    51 HsInstalledAppsState::HsInstalledAppsState(HsMenuViewBuilder &menuViewBuilder,
    51 HsInstalledAppsState::HsInstalledAppsState(HsMenuViewBuilder &menuViewBuilder,
    52         HsMainWindow &mainWindow,
    52         HsMainWindow &mainWindow,
    53         QState *parent):
    53         QState *parent):
    54     HsBaseViewState(mainWindow, parent)
    54     HsBaseViewState(mainWindow, parent),
       
    55             mSortAttribute(Hs::OldestOnTopHsSortAttribute)
    55 {
    56 {
    56     initialize(menuViewBuilder, HsInstalledAppsContext);
    57     initialize(menuViewBuilder, HsInstalledAppsContext);
    57     construct();
    58     construct();
    58 }
    59 }
    59 
    60 
    84 
    85 
    85     mViewOptions->addAction(hbTrId("txt_applib_opt_task_switcher"),
    86     mViewOptions->addAction(hbTrId("txt_applib_opt_task_switcher"),
    86                         this, SLOT(openTaskSwitcher()));
    87                         this, SLOT(openTaskSwitcher()));
    87     mViewOptions->addAction(hbTrId("txt_applib_opt_installation_log"),
    88     mViewOptions->addAction(hbTrId("txt_applib_opt_installation_log"),
    88                         this, SLOT(openInstallationLog()));
    89                         this, SLOT(openInstallationLog()));
    89 
    90     if (mModel->rowCount() > 0) {
       
    91         HbMenu *sortMenu = mViewOptions->addMenu(
       
    92                                hbTrId("txt_applib_opt_sort_by"));
       
    93         //Grouped options are exclusive by default.
       
    94         QActionGroup *sortGroup = new QActionGroup(this);
       
    95         sortGroup->addAction(
       
    96             sortMenu->addAction(
       
    97                 hbTrId("txt_applib_opt_sort_by_sub_latest_on_top"),
       
    98                 this,
       
    99                 SLOT(latestOnTopMenuAction())));
       
   100         sortGroup->addAction(
       
   101             sortMenu->addAction(
       
   102                 hbTrId("txt_applib_opt_sort_by_sub_oldest_on_top"),
       
   103                 this,
       
   104                 SLOT(oldestOnTopMenuAction())));
       
   105         foreach(QAction *action, sortMenu->actions()) {
       
   106             action->setCheckable(true);
       
   107         }
       
   108         static const int defaultSortingPosition = 0;
       
   109         if(mSortAttribute == Hs::LatestOnTopHsSortAttribute)
       
   110             {
       
   111             sortGroup->actions().at(defaultSortingPosition + 1)->setChecked(true);
       
   112             }
       
   113         else {
       
   114             sortGroup->actions().at(defaultSortingPosition)->setChecked(true);
       
   115         }
       
   116     }
    90     mMenuView->view()->setMenu(mViewOptions);
   117     mMenuView->view()->setMenu(mViewOptions);
    91     HSMENUTEST_FUNC_EXIT("HsInstalledAppsState::setMenuOptions");
   118     HSMENUTEST_FUNC_EXIT("HsInstalledAppsState::setMenuOptions");
    92 }
   119 }
    93 
   120 
    94 /*!
   121 /*!
    99 void HsInstalledAppsState::setContextMenuOptions(HbAbstractViewItem *item, EntryFlags flags)
   126 void HsInstalledAppsState::setContextMenuOptions(HbAbstractViewItem *item, EntryFlags flags)
   100 {
   127 {
   101     HbAction *uninstallAction = mContextMenu->addAction(
   128     HbAction *uninstallAction = mContextMenu->addAction(
   102                                 hbTrId("txt_common_menu_delete"));
   129                                 hbTrId("txt_common_menu_delete"));
   103     HbAction *appDetailsAction(NULL);
   130     HbAction *appDetailsAction(NULL);
   104     uninstallAction->setData(UninstallContextAction);
   131     uninstallAction->setData(Hs::UninstallContextAction);
   105 
   132 
   106     QSharedPointer<const CaEntry> entry = mModel->entry(item->modelIndex());
   133     QSharedPointer<const CaEntry> entry = mModel->entry(item->modelIndex());
   107 
   134 
   108     if (!(entry->attribute(componentIdAttributeName()).isEmpty()) &&
   135     if (!(entry->attribute(Hs::componentIdAttributeName).isEmpty()) &&
   109             (flags & RemovableEntryFlag) ) {
   136             (flags & RemovableEntryFlag) ) {
   110         appDetailsAction = mContextMenu->addAction(hbTrId(
   137         appDetailsAction = mContextMenu->addAction(hbTrId(
   111                                                 "txt_common_menu_details"));
   138                                                 "txt_common_menu_details"));
   112         appDetailsAction->setData(AppDetailsContextAction);
   139         appDetailsAction->setData(Hs::AppDetailsContextAction);
   113     }
   140     }
   114 }
   141 }
   115 
   142 
   116 
   143 
   117 /*!
   144 /*!
   135     mMenuView->viewLabel()->setHeading(
   162     mMenuView->viewLabel()->setHeading(
   136             hbTrId("txt_applib_subtitle_installed"));
   163             hbTrId("txt_applib_subtitle_installed"));
   137 
   164 
   138     if (!mModel) {
   165     if (!mModel) {
   139         mModel
   166         mModel
   140             = HsMenuService::getInstalledModel(AscendingNameHsSortAttribute);
   167             = HsMenuService::getInstalledModel(mSortAttribute);
   141     }
   168     }
   142 
   169 
   143     if (mModel->rowCount() == 0) {
   170     if (mModel->rowCount() == 0) {
   144         mMenuView->reset(HsEmptyLabelContext);
   171         mMenuView->reset(HsEmptyLabelContext);
   145     }
   172     }
   194         mMenuView->reset(HsEmptyLabelContext);
   221         mMenuView->reset(HsEmptyLabelContext);
   195     } else {
   222     } else {
   196         mMenuView->reset(HsItemViewContext);
   223         mMenuView->reset(HsItemViewContext);
   197         mMenuView->setModel(mModel);
   224         mMenuView->setModel(mModel);
   198     }
   225     }
       
   226     setMenuOptions();
   199     mMenuView->activate();
   227     mMenuView->activate();
   200 }
   228 }
   201 
   229 
   202 /*!
   230 /*!
   203  Open installation log.
   231  Open installation log.
   207     machine()->postEvent(
   235     machine()->postEvent(
   208         HsMenuEventFactory::createInstallationLogEvent());
   236         HsMenuEventFactory::createInstallationLogEvent());
   209 }
   237 }
   210 
   238 
   211 /*!
   239 /*!
   212  Handles context menu actions.
   240   A Slot called when an action for sorting (latest
   213  \param action to handle.
   241   on top) is invoked for Installed.
   214  */
   242  */
   215 void HsInstalledAppsState::contextMenuAction(HbAction *action)
   243 void HsInstalledAppsState::latestOnTopMenuAction()
   216 {
   244 {
   217     HsContextAction command =
   245     // as we geting already reversed list from query
   218             static_cast<HsContextAction>(action->data().toInt());
   246     // we set it to OldestOnTopHsSortAttribute
   219 
   247     mSortAttribute = Hs::OldestOnTopHsSortAttribute;
   220     const int itemId = mContextModelIndex.data(CaItemModel::IdRole).toInt();
   248     mModel->setSort(mSortAttribute);
   221 
   249 }
   222     switch (command) {
   250 
   223         case UninstallContextAction:
   251 /*!
   224             machine()->postEvent(
   252   A Slot called when an action for sorting (oldest
   225                 HsMenuEventFactory::createUninstallApplicationEvent(
   253   on top) is invoked for Installed.
   226                     itemId));
   254  */
   227             break;
   255 void HsInstalledAppsState::oldestOnTopMenuAction()
   228         case AppDetailsContextAction:
   256 {
   229             machine()->postEvent(
   257     // as we geting already reversed list from query
   230                 HsMenuEventFactory::createAppDetailsViewEvent(itemId));
   258     // we set it to LatestOnTopHsSortAttribute
   231             break;
   259     mSortAttribute = Hs::LatestOnTopHsSortAttribute;
   232         default:
   260     mModel->setSort(mSortAttribute);
   233             break;
   261 }
   234     }
       
   235     mMenuView->hideSearchPanel();
       
   236 }