homescreenapp/stateplugins/hsapplibrarystateplugin/src/hsinstalledappsstate.cpp
changeset 39 4e8ebe173323
child 46 23b5d6a29cce
equal deleted inserted replaced
36:cdae8c6c3876 39:4e8ebe173323
       
     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.h>
       
    19 #include <hbview.h>
       
    20 #include <hblistview.h>
       
    21 #include <hbaction.h>
       
    22 #include <hbmenu.h>
       
    23 #include <hbabstractviewitem.h>
       
    24 #include <hsmenueventfactory.h>
       
    25 #include <hbinstance.h>
       
    26 #include <caentry.h>
       
    27 #include <hbsearchpanel.h>
       
    28 
       
    29 #include "hsmenuitemmodel.h"
       
    30 #include "hsmenuview.h"
       
    31 #include "cadefs.h"
       
    32 #include "hsinstalledappsstate.h"
       
    33 #include "hsaddappstocollectionstate.h"
       
    34 #include "hsapp_defs.h"
       
    35 #include "hsmenumodetransition.h"
       
    36 
       
    37 /*!
       
    38  \class HsInstalledAppsState
       
    39  \ingroup group_hsapplibrarystateplugin
       
    40  \brief Manages displaying installed applications
       
    41  */
       
    42 
       
    43 /*!
       
    44  Constructor.
       
    45  \param menuView menu view.
       
    46  \param parent Pwner.
       
    47  */
       
    48 HsInstalledAppsState::HsInstalledAppsState(HsMenuView &menuView, QState *parent) :
       
    49     QState(parent), mMenuView(menuView), mInstalledAppsModel(0)
       
    50 {
       
    51     construct();
       
    52 }
       
    53 
       
    54 /*!
       
    55  Constructor part.
       
    56  */
       
    57 void HsInstalledAppsState::construct()
       
    58 {
       
    59     HSMENUTEST_FUNC_ENTRY("HsInstalledAppsState::construct");
       
    60 
       
    61     const QString parentName =
       
    62         parent() != 0 ? parent()->objectName() : QString("");
       
    63     setObjectName(parentName + "/installedappsstate");
       
    64     connect(this, SIGNAL(entered()),SLOT(stateEntered()));
       
    65     connect(this, SIGNAL(exited()),SLOT(stateExited()));
       
    66 
       
    67     mSecondarySoftkeyAction = new HbAction(Hb::BackAction, this);
       
    68 
       
    69     HSMENUTEST_FUNC_EXIT("HsInstalledAppsState::construct");
       
    70 }
       
    71 
       
    72 /*!
       
    73  Method seting menu options.
       
    74  */
       
    75 void HsInstalledAppsState::setMenuOptions()
       
    76 {
       
    77     HSMENUTEST_FUNC_ENTRY("HsInstalledAppsState::setMenuOptions");
       
    78     HbMenu *const mOptions = new HbMenu();
       
    79     mOptions->setParent(this);
       
    80 
       
    81     mOptions->addAction(hbTrId("txt_applib_opt_task_switcher"),
       
    82                         this, SLOT(openTaskSwitcher()));
       
    83 
       
    84     mMenuView.view()->setMenu(mOptions);
       
    85     HSMENUTEST_FUNC_EXIT("HsInstalledAppsState::setMenuOptions");
       
    86 }
       
    87 
       
    88 /*!
       
    89  Destructor.
       
    90  */
       
    91 HsInstalledAppsState::~HsInstalledAppsState()
       
    92 {
       
    93     delete mInstalledAppsModel;
       
    94 }
       
    95 
       
    96 /*!
       
    97  Slot connected to entered() signal.
       
    98  Invoked when a state is entered.
       
    99  */
       
   100 void HsInstalledAppsState::stateEntered()
       
   101 {
       
   102     qDebug("AllAppsState::stateEntered()");
       
   103     HSMENUTEST_FUNC_ENTRY("HsInstalledAppsState::stateEntered");
       
   104 
       
   105     if (!mInstalledAppsModel) {
       
   106         mInstalledAppsModel
       
   107         = HsMenuService::getInstalledModel(AscendingNameHsSortAttribute);
       
   108     }
       
   109     mMenuView.setModel(mInstalledAppsModel);
       
   110     mMenuView.scrollTo(mInstalledAppsModel->index(0));
       
   111     setMenuOptions();
       
   112 
       
   113     connect(&mMenuView, SIGNAL(activated(QModelIndex)),
       
   114             SLOT(listItemActivated(QModelIndex)));
       
   115     connect(&mMenuView, SIGNAL(longPressed(HbAbstractViewItem *, QPointF)),
       
   116             SLOT(listItemLongPressed(HbAbstractViewItem *, QPointF)));
       
   117     connect(mSecondarySoftkeyAction, SIGNAL(triggered()),
       
   118             SLOT(backAction()));
       
   119     mMenuView.hideToolBar();
       
   120     mOldNavigationAction = mMenuView.view()->navigationAction();
       
   121     mMenuView.view()->setNavigationAction(mSecondarySoftkeyAction);
       
   122     mMenuView.setLabelVisible(true);
       
   123     mMenuView.setLabel(hbTrId("txt_applib_subtitle_installed"));
       
   124     HSMENUTEST_FUNC_EXIT("HsInstalledAppsState::stateEntered");
       
   125 }
       
   126 
       
   127 /*!
       
   128  Slot invoked when a state is exited.
       
   129  */
       
   130 void HsInstalledAppsState::stateExited()
       
   131 {
       
   132     HSMENUTEST_FUNC_ENTRY("HsInstalledAppsState::stateExited");
       
   133     mMenuView.setSearchPanelVisible(false);
       
   134     // revert navigation action
       
   135     mMenuView.view()->setNavigationAction(mOldNavigationAction);
       
   136     mMenuView.showToolBar();
       
   137     mMenuView.setLabelVisible(false);
       
   138     mMenuView.disconnect(this);
       
   139     mMenuView.view()->setMenu(NULL);
       
   140 
       
   141     disconnect(mSecondarySoftkeyAction, SIGNAL(triggered()),
       
   142                this, SLOT(backAction()));
       
   143 
       
   144     HSMENUTEST_FUNC_EXIT("HsInstalledAppsState::stateExited");
       
   145     qDebug("AllAppsState::stateExited()");
       
   146 }
       
   147 
       
   148 /*!
       
   149  Open task switcher.
       
   150  \retval true if operation is successful.
       
   151  */
       
   152 bool HsInstalledAppsState::openTaskSwitcher()
       
   153 {
       
   154     return HsMenuService::launchTaskSwitcher();
       
   155 }
       
   156 
       
   157 /*!
       
   158  Method invoked when a list item is activated.
       
   159  \param index indec of activated item.
       
   160  */
       
   161 #ifdef COVERAGE_MEASUREMENT
       
   162 #pragma CTC SKIP
       
   163 #endif //COVERAGE_MEASUREMENT
       
   164 void HsInstalledAppsState::listItemActivated(const QModelIndex &/*index*/)
       
   165 {
       
   166     //no implementation yet
       
   167 }
       
   168 #ifdef COVERAGE_MEASUREMENT
       
   169 #pragma CTC ENDSKIP
       
   170 #endif //COVERAGE_MEASUREMENT
       
   171 
       
   172 /*!
       
   173  Handles long-item-pressed event in all apps view by showing context menu
       
   174  \param item the event pertains to
       
   175  \param coords press point coordinates.
       
   176  */
       
   177 #ifdef COVERAGE_MEASUREMENT
       
   178 #pragma CTC SKIP
       
   179 #endif //COVERAGE_MEASUREMENT
       
   180 void HsInstalledAppsState::listItemLongPressed(HbAbstractViewItem *item,
       
   181         const QPointF &coords)
       
   182 {
       
   183     HSMENUTEST_FUNC_ENTRY("HsInstalledAppsState::listItemLongPressed");
       
   184 
       
   185     // create context menu
       
   186     HbMenu *menu = new HbMenu();
       
   187 
       
   188     HbAction *uninstallAction = menu->addAction(
       
   189                                     hbTrId("txt_common_menu_delete"));
       
   190 
       
   191     // choose proper action
       
   192     if (HbAction *selectedAction = menu->exec(coords)) {
       
   193         if (selectedAction == uninstallAction) {
       
   194             const int itemId = item->modelIndex().data(
       
   195                                    CaItemModel::IdRole).toInt();
       
   196             HsMenuService::executeAction(itemId, removeActionIdentifier());
       
   197         }
       
   198         mMenuView.setSearchPanelVisible(false);
       
   199     }
       
   200     delete menu;
       
   201     HSMENUTEST_FUNC_EXIT("HsInstalledAppsState::listItemLongPressed");
       
   202 }
       
   203 #ifdef COVERAGE_MEASUREMENT
       
   204 #pragma CTC ENDSKIP
       
   205 #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