homescreenapp/stateplugins/hsapplibrarystateplugin/src/hsinstalledappsstate.cpp
changeset 77 4b195f3bea29
parent 61 2b1b11a301d2
child 85 35368b604b28
equal deleted inserted replaced
61:2b1b11a301d2 77:4b195f3bea29
    13  *
    13  *
    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>
       
    19 #include <HbView>
    19 #include <HbGroupBox>
    20 #include <HbGroupBox>
    20 #include <hbview.h>
    21 #include <HbListView>
    21 #include <hblistview.h>
    22 #include <HbAction>
    22 #include <hbaction.h>
    23 #include <HbMenu>
    23 #include <hbmenu.h>
    24 #include <HbAbstractViewItem>
    24 #include <hbabstractviewitem.h>
    25 
    25 #include <hsmenueventfactory.h>
    26 #include <cadefs.h>
    26 #include <hbinstance.h>
       
    27 #include <caentry.h>
    27 #include <caentry.h>
    28 #include <hbsearchpanel.h>
    28 
    29 
    29 #include "hsapp_defs.h"
       
    30 #include "hsmenueventfactory.h"
    30 #include "hsmenuitemmodel.h"
    31 #include "hsmenuitemmodel.h"
    31 #include "hsmenuviewbuilder.h"
       
    32 #include "cadefs.h"
       
    33 #include "hsinstalledappsstate.h"
    32 #include "hsinstalledappsstate.h"
    34 #include "hsaddappstocollectionstate.h"
    33 #include "hsaddappstocollectionstate.h"
    35 #include "hsapp_defs.h"
       
    36 #include "hsmenumodetransition.h"
    34 #include "hsmenumodetransition.h"
    37 #include "hsmainwindow.h"
       
    38 
    35 
    39 /*!
    36 /*!
    40  \class HsInstalledAppsState
    37  \class HsInstalledAppsState
    41  \ingroup group_hsapplibrarystateplugin
    38  \ingroup group_hsapplibrarystateplugin
    42  \brief Manages displaying installed applications
    39  \brief Manages displaying installed applications
    44  \see StateMachine
    41  \see StateMachine
    45  \lib ?library
    42  \lib ?library
    46  */
    43  */
    47 
    44 
    48 /*!
    45 /*!
    49  \var HsInstalledAppsState::mMenuView
       
    50  The View widget.
       
    51  Own.
       
    52  */
       
    53 
       
    54 /*!
       
    55  \var HsInstalledAppsState::mInstalledAppsModel
       
    56  Item Model for the List.
       
    57  Own.
       
    58  */
       
    59 
       
    60 /*!
       
    61  \var HsInstalledAppsState::mSecondarySoftkeyAction
       
    62  Secondary Softkey action.
       
    63  Backstepping functionality.
       
    64  Own.
       
    65  */
       
    66 
       
    67 /*!
       
    68  \var HsInstalledAppsState::mOldNavigationAction
       
    69  Old navigation icon.
       
    70  Not own.
       
    71  */
       
    72 
       
    73 /*!
       
    74  Constructor.
    46  Constructor.
    75  \param menuViewBuilder Menu view builder.
    47  \param menuViewBuilder Menu view builder.
       
    48  \param mainWindow main window wrapper.
    76  \param parent Owner.
    49  \param parent Owner.
    77  */
    50  */
    78 HsInstalledAppsState::HsInstalledAppsState(HsMenuViewBuilder &menuViewBuilder,
    51 HsInstalledAppsState::HsInstalledAppsState(HsMenuViewBuilder &menuViewBuilder,
    79         HsMainWindow &mainWindow,
    52         HsMainWindow &mainWindow,
    80         QState *parent):
    53         QState *parent):
    81     HsBaseViewState(parent),
    54     HsBaseViewState(mainWindow, parent)
    82     mMenuView(menuViewBuilder, HsInstalledAppsContext),
    55 {
    83     mInstalledAppsModel(0),
    56     initialize(menuViewBuilder, HsInstalledAppsContext);
    84     mSecondarySoftkeyAction(new HbAction(Hb::BackNaviAction, this)),
       
    85     mMainWindow(mainWindow),
       
    86     mContextModelIndex(),mContextMenu(0)
       
    87 {
       
    88     construct();
    57     construct();
    89 }
    58 }
    90 
    59 
    91 /*!
    60 /*!
    92  Constructor part.
    61  Constructor part.
    96     HSMENUTEST_FUNC_ENTRY("HsInstalledAppsState::construct");
    65     HSMENUTEST_FUNC_ENTRY("HsInstalledAppsState::construct");
    97 
    66 
    98     const QString parentName =
    67     const QString parentName =
    99         parent() != 0 ? parent()->objectName() : QString("");
    68         parent() != 0 ? parent()->objectName() : QString("");
   100     setObjectName(parentName + "/installedappsstate");
    69     setObjectName(parentName + "/installedappsstate");
   101     connect(this, SIGNAL(entered()),SLOT(stateEntered()));
    70 
   102     connect(this, SIGNAL(exited()),SLOT(stateExited()));
    71     connect(mBackKeyAction, SIGNAL(triggered()), SLOT(openAppLibrary()));
   103 
       
   104     connect(mSecondarySoftkeyAction, SIGNAL(triggered()),
       
   105             SLOT(backAction()));
       
   106     mMenuView.view()->
       
   107     setNavigationAction(mSecondarySoftkeyAction);
       
   108 
       
   109 
       
   110     setMenuOptions();
       
   111 
    72 
   112     HSMENUTEST_FUNC_EXIT("HsInstalledAppsState::construct");
    73     HSMENUTEST_FUNC_EXIT("HsInstalledAppsState::construct");
   113 }
    74 }
   114 
    75 
   115 /*!
    76 /*!
   116  Method seting menu options.
    77  Method seting menu options.
   117  */
    78  */
   118 void HsInstalledAppsState::setMenuOptions()
    79 void HsInstalledAppsState::setMenuOptions()
   119 {
    80 {
   120     HSMENUTEST_FUNC_ENTRY("HsInstalledAppsState::setMenuOptions");
    81     HSMENUTEST_FUNC_ENTRY("HsInstalledAppsState::setMenuOptions");
   121     HbMenu *const mOptions = new HbMenu();
    82 
   122     mOptions->setParent(this);
    83     mViewOptions->clearActions();
   123 
    84 
   124     mOptions->addAction(hbTrId("txt_applib_opt_task_switcher"),
    85     mViewOptions->addAction(hbTrId("txt_applib_opt_task_switcher"),
   125                         this, SLOT(openTaskSwitcher()));
    86                         this, SLOT(openTaskSwitcher()));
   126 
    87     mViewOptions->addAction(hbTrId("txt_applib_opt_installation_log"),
   127     mMenuView.view()->setMenu(mOptions);
    88                         this, SLOT(openInstallationLog()));
       
    89 
       
    90     mMenuView->view()->setMenu(mViewOptions);
   128     HSMENUTEST_FUNC_EXIT("HsInstalledAppsState::setMenuOptions");
    91     HSMENUTEST_FUNC_EXIT("HsInstalledAppsState::setMenuOptions");
   129 }
    92 }
   130 
    93 
   131 /*!
    94 /*!
       
    95  Method seting context menu options.
       
    96  \param item the context menu is built for.
       
    97  \param flags of the \item.
       
    98  */
       
    99 void HsInstalledAppsState::setContextMenuOptions(HbAbstractViewItem *item, EntryFlags flags)
       
   100 {
       
   101     HbAction *uninstallAction = mContextMenu->addAction(
       
   102                                 hbTrId("txt_common_menu_delete"));
       
   103     HbAction *appDetailsAction(NULL);
       
   104     uninstallAction->setData(UninstallContextAction);
       
   105 
       
   106     QSharedPointer<const CaEntry> entry = mModel->entry(item->modelIndex());
       
   107 
       
   108     if (!(entry->attribute(componentIdAttributeName()).isEmpty()) &&
       
   109             (flags & RemovableEntryFlag) ) {
       
   110         appDetailsAction = mContextMenu->addAction(hbTrId(
       
   111                                                 "txt_common_menu_details"));
       
   112         appDetailsAction->setData(AppDetailsContextAction);
       
   113     }
       
   114 }
       
   115 
       
   116 
       
   117 /*!
   132  Destructor.
   118  Destructor.
   133  */
   119  */
   134 HsInstalledAppsState::~HsInstalledAppsState()
   120 HsInstalledAppsState::~HsInstalledAppsState()
   135 {
   121 {
   136     mMenuView.inactivate();
   122     mMenuView->inactivate();
   137     mMenuView.setModel(NULL);
   123     mMenuView->view()->setNavigationAction(NULL);
   138     mMenuView.view()->setNavigationAction(NULL);
       
   139 
       
   140     delete mInstalledAppsModel;
       
   141 }
   124 }
   142 
   125 
   143 /*!
   126 /*!
   144  Slot connected to entered() signal.
   127  Slot connected to entered() signal.
   145  Invoked when a state is entered.
   128  Invoked when a state is entered.
   147 void HsInstalledAppsState::stateEntered()
   130 void HsInstalledAppsState::stateEntered()
   148 {
   131 {
   149     qDebug("AllAppsState::stateEntered()");
   132     qDebug("AllAppsState::stateEntered()");
   150     HSMENUTEST_FUNC_ENTRY("HsInstalledAppsState::stateEntered");
   133     HSMENUTEST_FUNC_ENTRY("HsInstalledAppsState::stateEntered");
   151 
   134 
   152     mMainWindow.setCurrentView(mMenuView);
   135     mMenuView->viewLabel()->setHeading(
   153     mMenuView.activate();
   136             hbTrId("txt_applib_subtitle_installed"));
   154 
   137 
   155     if (!mInstalledAppsModel) {
   138     if (!mModel) {
   156         mInstalledAppsModel
   139         mModel
   157         = HsMenuService::getInstalledModel(AscendingNameHsSortAttribute);
   140             = HsMenuService::getInstalledModel(AscendingNameHsSortAttribute);
   158         mMenuView.setModel(mInstalledAppsModel);
   141     }
   159     }
   142 
   160 
   143     if (mModel->rowCount() == 0) {
   161     if (mInstalledAppsModel->rowCount() == 0){
   144         mMenuView->reset(HsEmptyLabelContext);
   162         mMenuView.setContext(HsInstalledAppsContext,HsEmptyLabelContext);
   145     }
   163         }
   146     else {
   164 
   147 		mMenuView->reset(HsItemViewContext);
   165     mMenuView.listView()->scrollTo(
   148         mMenuView->setModel(mModel);
   166         mInstalledAppsModel->index(0));
   149         mMenuView->listView()->scrollTo(
   167 
   150             mModel->index(0));
   168     connect(&mMenuView,
   151     }
   169             SIGNAL(activated(QModelIndex)),
   152     
   170             SLOT(listItemActivated(QModelIndex)));
   153     setMenuOptions();
   171     connect(&mMenuView,
   154 
       
   155     connect(mMenuView.data(),
   172             SIGNAL(longPressed(HbAbstractViewItem *, QPointF)),
   156             SIGNAL(longPressed(HbAbstractViewItem *, QPointF)),
   173             SLOT(listItemLongPressed(HbAbstractViewItem *, QPointF)));
   157             SLOT(showContextMenu(HbAbstractViewItem *, QPointF)));
   174 
   158 
   175     connect(mInstalledAppsModel, SIGNAL(empty(bool)),this,
   159     connect(mModel, SIGNAL(empty(bool)),this,
   176             SLOT(setEmptyLabelVisibility(bool)));
   160             SLOT(setEmptyLabelVisibility(bool)));
   177 
   161 
       
   162     HsBaseViewState::stateEntered();
       
   163 
   178     HSMENUTEST_FUNC_EXIT("HsInstalledAppsState::stateEntered");
   164     HSMENUTEST_FUNC_EXIT("HsInstalledAppsState::stateEntered");
   179 }
   165 }
   180 
   166 
   181 /*!
   167 /*!
   182  Slot invoked when a state is exited.
   168  Slot invoked when a state is exited.
   183  */
   169  */
   184 void HsInstalledAppsState::stateExited()
   170 void HsInstalledAppsState::stateExited()
   185 {
   171 {
   186     HSMENUTEST_FUNC_ENTRY("HsInstalledAppsState::stateExited");
   172     HSMENUTEST_FUNC_ENTRY("HsInstalledAppsState::stateExited");
   187 
   173 
   188     disconnect(mInstalledAppsModel, SIGNAL(empty(bool)),this,
   174     disconnect(mModel, SIGNAL(empty(bool)),this,
   189                SLOT(setEmptyLabelVisibility(bool)));
   175                SLOT(setEmptyLabelVisibility(bool)));
   190 
   176 
   191     mMenuView.setSearchPanelVisible(false);
   177     disconnect(mMenuView.data(),
   192 
       
   193     disconnect(&mMenuView,
       
   194             SIGNAL(activated(QModelIndex)), this,
       
   195             SLOT(listItemActivated(QModelIndex)));
       
   196     disconnect(&mMenuView,
       
   197             SIGNAL(longPressed(HbAbstractViewItem *, QPointF)), this,
   178             SIGNAL(longPressed(HbAbstractViewItem *, QPointF)), this,
   198             SLOT(listItemLongPressed(HbAbstractViewItem *, QPointF)));
   179             SLOT(showContextMenu(HbAbstractViewItem *, QPointF)));
   199 
   180 
   200     mMenuView.inactivate();
       
   201 
       
   202     if (mContextMenu)
       
   203         mContextMenu->close();
       
   204     
       
   205     HsBaseViewState::stateExited();
   181     HsBaseViewState::stateExited();
   206     
   182 
   207     HSMENUTEST_FUNC_EXIT("HsInstalledAppsState::stateExited");
   183     HSMENUTEST_FUNC_EXIT("HsInstalledAppsState::stateExited");
   208     qDebug("AllAppsState::stateExited()");
   184     qDebug("AllAppsState::stateExited()");
   209 }
   185 }
   210 
   186 
   211 /*!
   187 /*!
   212  Handles button visibility
   188  Handles button visibility.
       
   189  \param visibility indicates whether show or not to show 'empty' label.
   213  */
   190  */
   214 void HsInstalledAppsState::setEmptyLabelVisibility(bool visibility)
   191 void HsInstalledAppsState::setEmptyLabelVisibility(bool visibility)
   215 {
   192 {
   216     if(visibility){
   193     if(visibility){
   217         mMenuView.setContext(HsInstalledAppsContext,HsEmptyLabelContext);
   194         mMenuView->reset(HsEmptyLabelContext);
   218     } else {
   195     } else {
   219         mMenuView.setContext(HsInstalledAppsContext,HsItemViewContext);
   196         mMenuView->reset(HsItemViewContext);
   220     }
   197         mMenuView->setModel(mModel);
   221 }
   198     }
   222 
   199     mMenuView->activate();
   223 /*!
   200 }
   224  Open task switcher.
   201 
   225  \retval true if operation is successful.
   202 /*!
   226  */
   203  Open installation log.
   227 bool HsInstalledAppsState::openTaskSwitcher()
   204  */
   228 {
   205 void HsInstalledAppsState::openInstallationLog()
   229     return HsMenuService::launchTaskSwitcher();
   206 {
   230 }
   207     machine()->postEvent(
   231 
   208         HsMenuEventFactory::createInstallationLogEvent());
   232 /*!
   209 }
   233  Method invoked when a list item is activated.
   210 
   234  \param index indec of activated item.
   211 /*!
   235  */
   212  Handles context menu actions.
   236 #ifdef COVERAGE_MEASUREMENT
   213  \param action to handle.
   237 #pragma CTC SKIP
       
   238 #endif //COVERAGE_MEASUREMENT
       
   239 void HsInstalledAppsState::listItemActivated(const QModelIndex &/*index*/)
       
   240 {
       
   241     //no implementation yet
       
   242 }
       
   243 #ifdef COVERAGE_MEASUREMENT
       
   244 #pragma CTC ENDSKIP
       
   245 #endif //COVERAGE_MEASUREMENT
       
   246 
       
   247 /*!
       
   248  Handles long-item-pressed event in all apps view by showing context menu
       
   249  \param item the event pertains to
       
   250  \param coords press point coordinates.
       
   251  */
       
   252 #ifdef COVERAGE_MEASUREMENT
       
   253 #pragma CTC SKIP
       
   254 #endif //COVERAGE_MEASUREMENT
       
   255 void HsInstalledAppsState::listItemLongPressed(HbAbstractViewItem *item,
       
   256         const QPointF &coords)
       
   257 {
       
   258     HSMENUTEST_FUNC_ENTRY("HsInstalledAppsState::listItemLongPressed");
       
   259 
       
   260     EntryFlags flags = item->modelIndex().data(
       
   261                            CaItemModel::FlagsRole).value<EntryFlags> ();
       
   262     if (!(flags & UninstallEntryFlag)) {
       
   263         // create context menu
       
   264         mContextMenu = new HbMenu();
       
   265 
       
   266         HbAction *uninstallAction = mContextMenu->addAction(
       
   267                                     hbTrId("txt_common_menu_delete"));
       
   268         HbAction *appDetailsAction(NULL);
       
   269         uninstallAction->setData(UninstallContextAction);
       
   270     
       
   271         QSharedPointer<const CaEntry> entry = mInstalledAppsModel->entry(item->modelIndex());
       
   272     
       
   273         if (!(entry->attribute(componentIdAttributeName()).isEmpty()) &&
       
   274                 (flags & RemovableEntryFlag) ) {
       
   275             appDetailsAction = mContextMenu->addAction(hbTrId(
       
   276                                                     "txt_common_menu_details"));
       
   277             appDetailsAction->setData(AppDetailsContextAction);
       
   278         }
       
   279 
       
   280         mContextModelIndex = item->modelIndex();
       
   281         mContextMenu->setPreferredPos(coords);
       
   282         mContextMenu->setAttribute(Qt::WA_DeleteOnClose);
       
   283         mContextMenu->open(this, SLOT(contextMenuAction(HbAction*)));
       
   284     }
       
   285     
       
   286     
       
   287     HSMENUTEST_FUNC_EXIT("HsInstalledAppsState::listItemLongPressed");
       
   288 }
       
   289 #ifdef COVERAGE_MEASUREMENT
       
   290 #pragma CTC ENDSKIP
       
   291 #endif //COVERAGE_MEASUREMENT
       
   292 
       
   293 /*!
       
   294  Handles context menu actions
       
   295  */
   214  */
   296 void HsInstalledAppsState::contextMenuAction(HbAction *action)
   215 void HsInstalledAppsState::contextMenuAction(HbAction *action)
   297 {    
   216 {
   298     HsContextAction command = 
   217     HsContextAction command =
   299             static_cast<HsContextAction>(action->data().toInt());
   218             static_cast<HsContextAction>(action->data().toInt());
   300     
   219 
   301     const int itemId = mContextModelIndex.data(CaItemModel::IdRole).toInt();
   220     const int itemId = mContextModelIndex.data(CaItemModel::IdRole).toInt();
   302     
   221 
   303     switch (command) {
   222     switch (command) {
   304         case UninstallContextAction:
   223         case UninstallContextAction:
   305             machine()->postEvent(
   224             machine()->postEvent(
   306                 HsMenuEventFactory::createUninstallApplicationEvent(
   225                 HsMenuEventFactory::createUninstallApplicationEvent(
   307                     itemId));
   226                     itemId));
   308             break;
   227             break;
   309         case AppDetailsContextAction: 
   228         case AppDetailsContextAction:
   310             machine()->postEvent(
   229             machine()->postEvent(
   311                 HsMenuEventFactory::createAppDetailsViewEvent(itemId));
   230                 HsMenuEventFactory::createAppDetailsViewEvent(itemId));
   312             break;            
   231             break;
   313         default:
   232         default:
   314             break;            
   233             break;
   315     }
   234     }
   316     mMenuView.setSearchPanelVisible(false);
   235     mMenuView->hideSearchPanel();
   317 }
   236 }
   318 
       
   319 /*!
       
   320  Slot invoked when a back action is triggered.
       
   321  */
       
   322 #ifdef COVERAGE_MEASUREMENT
       
   323 #pragma CTC SKIP
       
   324 #endif //COVERAGE_MEASUREMENT
       
   325 void HsInstalledAppsState::backAction()
       
   326 {
       
   327     machine()->postEvent(HsMenuEventFactory::createOpenAppLibraryEvent());
       
   328 }
       
   329 #ifdef COVERAGE_MEASUREMENT
       
   330 #pragma CTC ENDSKIP
       
   331 #endif //COVERAGE_MEASUREMENT