homescreenapp/stateplugins/hsapplibrarystateplugin/src/hsinstalledappsstate.cpp
changeset 46 23b5d6a29cce
parent 39 4e8ebe173323
child 51 4785f57bf3d4
equal deleted inserted replaced
39:4e8ebe173323 46:23b5d6a29cce
    14  * Description: Menu All Applications state.
    14  * Description: Menu All Applications state.
    15  *
    15  *
    16  */
    16  */
    17 
    17 
    18 #include <qstatemachine.h>
    18 #include <qstatemachine.h>
       
    19 #include <HbGroupBox>
    19 #include <hbview.h>
    20 #include <hbview.h>
    20 #include <hblistview.h>
    21 #include <hblistview.h>
    21 #include <hbaction.h>
    22 #include <hbaction.h>
    22 #include <hbmenu.h>
    23 #include <hbmenu.h>
    23 #include <hbabstractviewitem.h>
    24 #include <hbabstractviewitem.h>
    25 #include <hbinstance.h>
    26 #include <hbinstance.h>
    26 #include <caentry.h>
    27 #include <caentry.h>
    27 #include <hbsearchpanel.h>
    28 #include <hbsearchpanel.h>
    28 
    29 
    29 #include "hsmenuitemmodel.h"
    30 #include "hsmenuitemmodel.h"
    30 #include "hsmenuview.h"
    31 #include "hsmenuviewbuilder.h"
    31 #include "cadefs.h"
    32 #include "cadefs.h"
    32 #include "hsinstalledappsstate.h"
    33 #include "hsinstalledappsstate.h"
    33 #include "hsaddappstocollectionstate.h"
    34 #include "hsaddappstocollectionstate.h"
    34 #include "hsapp_defs.h"
    35 #include "hsapp_defs.h"
    35 #include "hsmenumodetransition.h"
    36 #include "hsmenumodetransition.h"
    36 
    37 
    37 /*!
    38 /*!
    38  \class HsInstalledAppsState
    39  \class HsInstalledAppsState
    39  \ingroup group_hsapplibrarystateplugin
    40  \ingroup group_hsapplibrarystateplugin
    40  \brief Manages displaying installed applications
    41  \brief Manages displaying installed applications
       
    42  Displays all installed packages present on the device.
       
    43  \see StateMachine
       
    44  \lib ?library
       
    45  */
       
    46 
       
    47 /*!
       
    48  \var HsInstalledAppsState::mMenuView
       
    49  The View widget.
       
    50  Own.
       
    51  */
       
    52 
       
    53 /*!
       
    54  \var HsInstalledAppsState::mInstalledAppsModel
       
    55  Item Model for the List.
       
    56  Own.
       
    57  */
       
    58 
       
    59 /*!
       
    60  \var HsInstalledAppsState::mSecondarySoftkeyAction
       
    61  Secondary Softkey action.
       
    62  Backstepping functionality.
       
    63  Own.
       
    64  */
       
    65 
       
    66 /*!
       
    67  \var HsInstalledAppsState::mOldNavigationAction
       
    68  Old navigation icon.
       
    69  Not own.
    41  */
    70  */
    42 
    71 
    43 /*!
    72 /*!
    44  Constructor.
    73  Constructor.
    45  \param menuView menu view.
    74  \param menuViewBuilder Menu view builder.
    46  \param parent Pwner.
    75  \param parent Owner.
    47  */
    76  */
    48 HsInstalledAppsState::HsInstalledAppsState(HsMenuView &menuView, QState *parent) :
    77 HsInstalledAppsState::HsInstalledAppsState(HsMenuViewBuilder &menuViewBuilder,
    49     QState(parent), mMenuView(menuView), mInstalledAppsModel(0)
    78         QState *parent):
       
    79     QState(parent),
       
    80     mMenuView(menuViewBuilder, HsInstalledAppsContext),
       
    81     mInstalledAppsModel(0),
       
    82     mSecondarySoftkeyAction(new HbAction(Hb::BackNaviAction, this)),
       
    83     mContextModelIndex(),mContextMenu(0)
    50 {
    84 {
    51     construct();
    85     construct();
    52 }
    86 }
    53 
    87 
    54 /*!
    88 /*!
    62         parent() != 0 ? parent()->objectName() : QString("");
    96         parent() != 0 ? parent()->objectName() : QString("");
    63     setObjectName(parentName + "/installedappsstate");
    97     setObjectName(parentName + "/installedappsstate");
    64     connect(this, SIGNAL(entered()),SLOT(stateEntered()));
    98     connect(this, SIGNAL(entered()),SLOT(stateEntered()));
    65     connect(this, SIGNAL(exited()),SLOT(stateExited()));
    99     connect(this, SIGNAL(exited()),SLOT(stateExited()));
    66 
   100 
    67     mSecondarySoftkeyAction = new HbAction(Hb::BackAction, this);
   101     connect(mSecondarySoftkeyAction, SIGNAL(triggered()),
       
   102             SLOT(backAction()));
       
   103     mMenuView.view()->
       
   104     setNavigationAction(mSecondarySoftkeyAction);
       
   105 
       
   106 
       
   107     setMenuOptions();
    68 
   108 
    69     HSMENUTEST_FUNC_EXIT("HsInstalledAppsState::construct");
   109     HSMENUTEST_FUNC_EXIT("HsInstalledAppsState::construct");
    70 }
   110 }
    71 
   111 
    72 /*!
   112 /*!
    88 /*!
   128 /*!
    89  Destructor.
   129  Destructor.
    90  */
   130  */
    91 HsInstalledAppsState::~HsInstalledAppsState()
   131 HsInstalledAppsState::~HsInstalledAppsState()
    92 {
   132 {
       
   133     mMenuView.inactivate();
       
   134     mMenuView.setModel(NULL);
       
   135     mMenuView.view()->setNavigationAction(NULL);
       
   136 
    93     delete mInstalledAppsModel;
   137     delete mInstalledAppsModel;
    94 }
   138 }
    95 
   139 
    96 /*!
   140 /*!
    97  Slot connected to entered() signal.
   141  Slot connected to entered() signal.
    99  */
   143  */
   100 void HsInstalledAppsState::stateEntered()
   144 void HsInstalledAppsState::stateEntered()
   101 {
   145 {
   102     qDebug("AllAppsState::stateEntered()");
   146     qDebug("AllAppsState::stateEntered()");
   103     HSMENUTEST_FUNC_ENTRY("HsInstalledAppsState::stateEntered");
   147     HSMENUTEST_FUNC_ENTRY("HsInstalledAppsState::stateEntered");
       
   148 
       
   149     mMenuView.activate();
   104 
   150 
   105     if (!mInstalledAppsModel) {
   151     if (!mInstalledAppsModel) {
   106         mInstalledAppsModel
   152         mInstalledAppsModel
   107         = HsMenuService::getInstalledModel(AscendingNameHsSortAttribute);
   153         = HsMenuService::getInstalledModel(AscendingNameHsSortAttribute);
       
   154         mMenuView.setModel(mInstalledAppsModel);
   108     }
   155     }
   109     mMenuView.setModel(mInstalledAppsModel);
   156 
   110     mMenuView.scrollTo(mInstalledAppsModel->index(0));
   157     mMenuView.listView()->scrollTo(
   111     setMenuOptions();
   158         mInstalledAppsModel->index(0));
   112 
   159 
   113     connect(&mMenuView, SIGNAL(activated(QModelIndex)),
   160     connect(&mMenuView,
       
   161             SIGNAL(activated(QModelIndex)),
   114             SLOT(listItemActivated(QModelIndex)));
   162             SLOT(listItemActivated(QModelIndex)));
   115     connect(&mMenuView, SIGNAL(longPressed(HbAbstractViewItem *, QPointF)),
   163     connect(&mMenuView,
       
   164             SIGNAL(longPressed(HbAbstractViewItem *, QPointF)),
   116             SLOT(listItemLongPressed(HbAbstractViewItem *, QPointF)));
   165             SLOT(listItemLongPressed(HbAbstractViewItem *, QPointF)));
   117     connect(mSecondarySoftkeyAction, SIGNAL(triggered()),
   166 
   118             SLOT(backAction()));
   167     mMenuView.viewLabel()->setHeading(
   119     mMenuView.hideToolBar();
   168         hbTrId("txt_applib_subtitle_installed"));
   120     mOldNavigationAction = mMenuView.view()->navigationAction();
   169 
   121     mMenuView.view()->setNavigationAction(mSecondarySoftkeyAction);
       
   122     mMenuView.setLabelVisible(true);
       
   123     mMenuView.setLabel(hbTrId("txt_applib_subtitle_installed"));
       
   124     HSMENUTEST_FUNC_EXIT("HsInstalledAppsState::stateEntered");
   170     HSMENUTEST_FUNC_EXIT("HsInstalledAppsState::stateEntered");
   125 }
   171 }
   126 
   172 
   127 /*!
   173 /*!
   128  Slot invoked when a state is exited.
   174  Slot invoked when a state is exited.
   129  */
   175  */
   130 void HsInstalledAppsState::stateExited()
   176 void HsInstalledAppsState::stateExited()
   131 {
   177 {
   132     HSMENUTEST_FUNC_ENTRY("HsInstalledAppsState::stateExited");
   178     HSMENUTEST_FUNC_ENTRY("HsInstalledAppsState::stateExited");
       
   179 
   133     mMenuView.setSearchPanelVisible(false);
   180     mMenuView.setSearchPanelVisible(false);
   134     // revert navigation action
   181     mMenuView.inactivate();
   135     mMenuView.view()->setNavigationAction(mOldNavigationAction);
   182 
   136     mMenuView.showToolBar();
   183     if (mContextMenu)
   137     mMenuView.setLabelVisible(false);
   184         mContextMenu->close();
   138     mMenuView.disconnect(this);
   185     
   139     mMenuView.view()->setMenu(NULL);
       
   140 
       
   141     disconnect(mSecondarySoftkeyAction, SIGNAL(triggered()),
       
   142                this, SLOT(backAction()));
       
   143 
       
   144     HSMENUTEST_FUNC_EXIT("HsInstalledAppsState::stateExited");
   186     HSMENUTEST_FUNC_EXIT("HsInstalledAppsState::stateExited");
   145     qDebug("AllAppsState::stateExited()");
   187     qDebug("AllAppsState::stateExited()");
   146 }
   188 }
   147 
   189 
   148 /*!
   190 /*!
   181         const QPointF &coords)
   223         const QPointF &coords)
   182 {
   224 {
   183     HSMENUTEST_FUNC_ENTRY("HsInstalledAppsState::listItemLongPressed");
   225     HSMENUTEST_FUNC_ENTRY("HsInstalledAppsState::listItemLongPressed");
   184 
   226 
   185     // create context menu
   227     // create context menu
   186     HbMenu *menu = new HbMenu();
   228     mContextMenu = new HbMenu();
   187 
   229 
   188     HbAction *uninstallAction = menu->addAction(
   230     HbAction *uninstallAction = mContextMenu->addAction(
   189                                     hbTrId("txt_common_menu_delete"));
   231                                     hbTrId("txt_common_menu_delete"));
   190 
   232     uninstallAction->setData(UninstallContextAction);
   191     // choose proper action
   233 
   192     if (HbAction *selectedAction = menu->exec(coords)) {
   234     mContextModelIndex = item->modelIndex();
   193         if (selectedAction == uninstallAction) {
   235     mContextMenu->setPreferredPos(coords);
   194             const int itemId = item->modelIndex().data(
   236     mContextMenu->setAttribute(Qt::WA_DeleteOnClose);
       
   237     mContextMenu->open(this, SLOT(contextMenuAction(HbAction*)));
       
   238     
       
   239     
       
   240     HSMENUTEST_FUNC_EXIT("HsInstalledAppsState::listItemLongPressed");
       
   241 }
       
   242 #ifdef COVERAGE_MEASUREMENT
       
   243 #pragma CTC ENDSKIP
       
   244 #endif //COVERAGE_MEASUREMENT
       
   245 
       
   246 /*!
       
   247  Handles context menu actions
       
   248  */
       
   249 void HsInstalledAppsState::contextMenuAction(HbAction *action)
       
   250 {
       
   251     HsContextAction command = static_cast<HsContextAction>(action->data().toInt());
       
   252     if (command == UninstallContextAction) {
       
   253         const int itemId = mContextModelIndex.data(
   195                                    CaItemModel::IdRole).toInt();
   254                                    CaItemModel::IdRole).toInt();
   196             HsMenuService::executeAction(itemId, removeActionIdentifier());
   255         HsMenuService::executeAction(itemId, removeActionIdentifier());
   197         }
   256     }   
   198         mMenuView.setSearchPanelVisible(false);
   257     mMenuView.setSearchPanelVisible(false);
   199     }
   258 }
   200     delete menu;
   259 
   201     HSMENUTEST_FUNC_EXIT("HsInstalledAppsState::listItemLongPressed");
   260 /*!
       
   261  Slot invoked when a back action is triggered.
       
   262  */
       
   263 #ifdef COVERAGE_MEASUREMENT
       
   264 #pragma CTC SKIP
       
   265 #endif //COVERAGE_MEASUREMENT
       
   266 void HsInstalledAppsState::backAction()
       
   267 {
       
   268     machine()->postEvent(HsMenuEventFactory::createOpenAppLibraryEvent());
   202 }
   269 }
   203 #ifdef COVERAGE_MEASUREMENT
   270 #ifdef COVERAGE_MEASUREMENT
   204 #pragma CTC ENDSKIP
   271 #pragma CTC ENDSKIP
   205 #endif //COVERAGE_MEASUREMENT
   272 #endif //COVERAGE_MEASUREMENT
   206 
       
   207 /*!
       
   208  Slot invoked when a back action is triggered.
       
   209  */
       
   210 #ifdef COVERAGE_MEASUREMENT
       
   211 #pragma CTC SKIP
       
   212 #endif //COVERAGE_MEASUREMENT
       
   213 void HsInstalledAppsState::backAction()
       
   214 {
       
   215     machine()->postEvent(HsMenuEventFactory::createOpenAppLibraryEvent());
       
   216 }
       
   217 #ifdef COVERAGE_MEASUREMENT
       
   218 #pragma CTC ENDSKIP
       
   219 #endif //COVERAGE_MEASUREMENT