homescreenapp/stateplugins/hsapplibrarystateplugin/src/hsinstalledappsstate.cpp
branchRCL_3
changeset 82 5f0182e07bfb
equal deleted inserted replaced
79:f00a6757af32 82:5f0182e07bfb
       
     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: Menu All Applications state.
       
    15  *
       
    16  */
       
    17 
       
    18 #include <QStateMachine>
       
    19 #include <HbView>
       
    20 #include <HbGroupBox>
       
    21 #include <HbListView>
       
    22 #include <HbAction>
       
    23 #include <HbMenu>
       
    24 #include <HbAbstractViewItem>
       
    25 
       
    26 #include <cadefs.h>
       
    27 #include <caentry.h>
       
    28 
       
    29 #include "hsapp_defs.h"
       
    30 #include "hsmenueventfactory.h"
       
    31 #include "hsmenuitemmodel.h"
       
    32 #include "hsinstalledappsstate.h"
       
    33 #include "hsaddappstocollectionstate.h"
       
    34 #include "hsmenumodetransition.h"
       
    35 
       
    36 /*!
       
    37  \class HsInstalledAppsState
       
    38  \ingroup group_hsapplibrarystateplugin
       
    39  \brief Manages displaying installed applications
       
    40  Displays all installed packages present on the device.
       
    41  \see StateMachine
       
    42  \lib ?library
       
    43  */
       
    44 
       
    45 /*!
       
    46  Constructor.
       
    47  \param menuViewBuilder Menu view builder.
       
    48  \param mainWindow main window wrapper.
       
    49  \param parent Owner.
       
    50  */
       
    51 HsInstalledAppsState::HsInstalledAppsState(HsMenuViewBuilder &menuViewBuilder,
       
    52         HsMainWindow &mainWindow,
       
    53         QState *parent):
       
    54     HsBaseViewState(mainWindow, parent),
       
    55             mSortAttribute(Hs::OldestOnTopHsSortAttribute)
       
    56 {
       
    57     initialize(menuViewBuilder, HsInstalledAppsContext);
       
    58     construct();
       
    59 }
       
    60 
       
    61 /*!
       
    62  Constructor part.
       
    63  */
       
    64 void HsInstalledAppsState::construct()
       
    65 {
       
    66     HSMENUTEST_FUNC_ENTRY("HsInstalledAppsState::construct");
       
    67 
       
    68     const QString parentName =
       
    69         parent() != 0 ? parent()->objectName() : QString("");
       
    70     setObjectName(parentName + "/installedappsstate");
       
    71 
       
    72     connect(mBackKeyAction, SIGNAL(triggered()), SLOT(openAppLibrary()));
       
    73 
       
    74     HSMENUTEST_FUNC_EXIT("HsInstalledAppsState::construct");
       
    75 }
       
    76 
       
    77 /*!
       
    78  Method seting menu options.
       
    79  */
       
    80 void HsInstalledAppsState::setMenuOptions()
       
    81 {
       
    82     HSMENUTEST_FUNC_ENTRY("HsInstalledAppsState::setMenuOptions");
       
    83 
       
    84     mViewOptions->clearActions();
       
    85 
       
    86     mViewOptions->addAction(hbTrId("txt_applib_opt_task_switcher"),
       
    87                         this, SLOT(openTaskSwitcher()));
       
    88     mViewOptions->addAction(hbTrId("txt_applib_opt_installation_log"),
       
    89                         this, SLOT(openInstallationLog()));
       
    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     }
       
   117     mMenuView->view()->setMenu(mViewOptions);
       
   118     HSMENUTEST_FUNC_EXIT("HsInstalledAppsState::setMenuOptions");
       
   119 }
       
   120 
       
   121 /*!
       
   122  Method seting context menu options.
       
   123  \param item the context menu is built for.
       
   124  \param flags of the \item.
       
   125  */
       
   126 void HsInstalledAppsState::setContextMenuOptions(HbAbstractViewItem *item, EntryFlags flags)
       
   127 {
       
   128     HbAction *uninstallAction = mContextMenu->addAction(
       
   129                                 hbTrId("txt_common_menu_delete"));
       
   130     HbAction *appDetailsAction(NULL);
       
   131     uninstallAction->setData(Hs::UninstallContextAction);
       
   132 
       
   133     QSharedPointer<const CaEntry> entry = mModel->entry(item->modelIndex());
       
   134 
       
   135     if (!(entry->attribute(Hs::componentIdAttributeName).isEmpty()) &&
       
   136             (flags & RemovableEntryFlag) ) {
       
   137         appDetailsAction = mContextMenu->addAction(hbTrId(
       
   138                                                 "txt_common_menu_details"));
       
   139         appDetailsAction->setData(Hs::AppDetailsContextAction);
       
   140     }
       
   141 }
       
   142 
       
   143 
       
   144 /*!
       
   145  Destructor.
       
   146  */
       
   147 HsInstalledAppsState::~HsInstalledAppsState()
       
   148 {
       
   149     mMenuView->inactivate();
       
   150     mMenuView->view()->setNavigationAction(NULL);
       
   151 }
       
   152 
       
   153 /*!
       
   154  Slot connected to entered() signal.
       
   155  Invoked when a state is entered.
       
   156  */
       
   157 void HsInstalledAppsState::stateEntered()
       
   158 {
       
   159     qDebug("AllAppsState::stateEntered()");
       
   160     HSMENUTEST_FUNC_ENTRY("HsInstalledAppsState::stateEntered");
       
   161 
       
   162     mMenuView->viewLabel()->setHeading(
       
   163             hbTrId("txt_applib_subtitle_installed"));
       
   164 
       
   165     if (!mModel) {
       
   166         mModel
       
   167             = HsMenuService::getInstalledModel(mSortAttribute);
       
   168     }
       
   169 
       
   170     if (mModel->rowCount() == 0) {
       
   171         mMenuView->reset(HsEmptyLabelContext);
       
   172     }
       
   173     else {
       
   174 		mMenuView->reset(HsItemViewContext);
       
   175         mMenuView->setModel(mModel);
       
   176         mMenuView->listView()->scrollTo(
       
   177             mModel->index(0));
       
   178     }
       
   179     
       
   180     setMenuOptions();
       
   181 
       
   182     connect(mMenuView.data(),
       
   183             SIGNAL(longPressed(HbAbstractViewItem *, QPointF)),
       
   184             SLOT(showContextMenu(HbAbstractViewItem *, QPointF)));
       
   185 
       
   186     connect(mModel, SIGNAL(empty(bool)),this,
       
   187             SLOT(setEmptyLabelVisibility(bool)));
       
   188 
       
   189     HsBaseViewState::stateEntered();
       
   190 
       
   191     HSMENUTEST_FUNC_EXIT("HsInstalledAppsState::stateEntered");
       
   192 }
       
   193 
       
   194 /*!
       
   195  Slot invoked when a state is exited.
       
   196  */
       
   197 void HsInstalledAppsState::stateExited()
       
   198 {
       
   199     HSMENUTEST_FUNC_ENTRY("HsInstalledAppsState::stateExited");
       
   200 
       
   201     disconnect(mModel, SIGNAL(empty(bool)),this,
       
   202                SLOT(setEmptyLabelVisibility(bool)));
       
   203 
       
   204     disconnect(mMenuView.data(),
       
   205             SIGNAL(longPressed(HbAbstractViewItem *, QPointF)), this,
       
   206             SLOT(showContextMenu(HbAbstractViewItem *, QPointF)));
       
   207 
       
   208     HsBaseViewState::stateExited();
       
   209 
       
   210     HSMENUTEST_FUNC_EXIT("HsInstalledAppsState::stateExited");
       
   211     qDebug("AllAppsState::stateExited()");
       
   212 }
       
   213 
       
   214 /*!
       
   215  Handles button visibility.
       
   216  \param visibility indicates whether show or not to show 'empty' label.
       
   217  */
       
   218 void HsInstalledAppsState::setEmptyLabelVisibility(bool visibility)
       
   219 {
       
   220     if(visibility){
       
   221         mMenuView->reset(HsEmptyLabelContext);
       
   222     } else {
       
   223         mMenuView->reset(HsItemViewContext);
       
   224         mMenuView->setModel(mModel);
       
   225     }
       
   226     setMenuOptions();
       
   227     mMenuView->activate();
       
   228 }
       
   229 
       
   230 /*!
       
   231  Open installation log.
       
   232  */
       
   233 void HsInstalledAppsState::openInstallationLog()
       
   234 {
       
   235     machine()->postEvent(
       
   236         HsMenuEventFactory::createInstallationLogEvent());
       
   237 }
       
   238 
       
   239 /*!
       
   240   A Slot called when an action for sorting (latest
       
   241   on top) is invoked for Installed.
       
   242  */
       
   243 void HsInstalledAppsState::latestOnTopMenuAction()
       
   244 {
       
   245     // as we geting already reversed list from query
       
   246     // we set it to OldestOnTopHsSortAttribute
       
   247     mSortAttribute = Hs::OldestOnTopHsSortAttribute;
       
   248     mModel->setSort(mSortAttribute);
       
   249 }
       
   250 
       
   251 /*!
       
   252   A Slot called when an action for sorting (oldest
       
   253   on top) is invoked for Installed.
       
   254  */
       
   255 void HsInstalledAppsState::oldestOnTopMenuAction()
       
   256 {
       
   257     // as we geting already reversed list from query
       
   258     // we set it to LatestOnTopHsSortAttribute
       
   259     mSortAttribute = Hs::LatestOnTopHsSortAttribute;
       
   260     mModel->setSort(mSortAttribute);
       
   261 }