homescreenapp/stateplugins/hsapplibrarystateplugin/src/hsallappsstate.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.h>
    19 #include <HbMenu>
    20 #include <hblistview.h>
    20 #include <HbAction>
    21 #include <hbaction.h>
    21 #include <HbAbstractViewItem>
    22 #include <hbmenu.h>
    22 #include <HbIndexFeedback>
    23 #include <hbabstractviewitem.h>
    23 #include <HbListView>
    24 #include <hsmenueventfactory.h>
    24 #include <HbScrollBar>
    25 #include <hbinstance.h>
    25 #include <HbView>
       
    26 
       
    27 #include <cadefs.h>
    26 #include <caentry.h>
    28 #include <caentry.h>
    27 #include <hbsearchpanel.h>
    29 #include <caitemmodel.h>
    28 #include <HbScrollBar>
    30 #include <caservice.h>
    29 #include <HbIndexFeedback>
    31 
    30 
    32 #include "hsapp_defs.h"
       
    33 #include "hsmenueventfactory.h"
    31 #include "hsmenuitemmodel.h"
    34 #include "hsmenuitemmodel.h"
    32 #include "cadefs.h"
       
    33 #include "hsallappsstate.h"
    35 #include "hsallappsstate.h"
    34 #include "hsaddappstocollectionstate.h"
       
    35 #include "hsapp_defs.h"
       
    36 #include "hsmenumodewrapper.h"
    36 #include "hsmenumodewrapper.h"
    37 #include "hsmenuviewbuilder.h"
    37 #include "hsmenuviewbuilder.h"
    38 #include "hsmenumodetransition.h"
       
    39 #include "caentry.h"
       
    40 #include "caservice.h"
       
    41 #include "hsmainwindow.h"
    38 #include "hsmainwindow.h"
       
    39 #include "hsaddmodeproxymodel.h"
       
    40 #include "hsapplibstateutils.h"
    42 
    41 
    43 /*!
    42 /*!
    44  \class HsAllAppsState
    43  \class HsAllAppsState
    45  \ingroup group_hsmenustateplugin
    44  \ingroup group_hsmenustateplugin
    46  \brief All Applications State.
    45  \brief All Applications State.
    53  \var HsAllAppsState::mSortAttribute
    52  \var HsAllAppsState::mSortAttribute
    54  Sort order
    53  Sort order
    55  */
    54  */
    56 
    55 
    57 /*!
    56 /*!
    58  \var HsAllAppsState::mCollectionsSortAttribute
       
    59  Collections sort order
       
    60  */
       
    61 
       
    62 /*!
       
    63  \var HsAllAppsState::mMenuView
       
    64  Wrapper for All Applications View.
       
    65  */
       
    66 
       
    67 /*!
       
    68  \var HsAllAppsState::mMenuMode
       
    69  Menu view mode wrapper.
       
    70  Not Own.
       
    71  */
       
    72 
       
    73 /*!
       
    74  Constructor.
    57  Constructor.
    75  \param menuViewBuilder Menu view builder.
    58  \param menuViewBuilder Menu view builder.
    76  \param menuMode reference to object representing menu mode (add mode on/add mode off).
    59  \param menuMode Menu mode object(add mode on/add mode off).
       
    60  \param mainWindow Main window wrapper.
    77  \param parent Owner.
    61  \param parent Owner.
    78  */
    62  */
    79 HsAllAppsState::HsAllAppsState(HsMenuViewBuilder &menuViewBuilder,
    63 HsAllAppsState::HsAllAppsState(HsMenuViewBuilder &menuViewBuilder,
    80                                HsMenuModeWrapper &menuMode,
    64                                HsMenuModeWrapper &menuMode,
    81                                HsMainWindow &mainWindow,
    65                                HsMainWindow &mainWindow,
    82                                QState *parent) :
    66                                QState *parent) :
    83     HsBaseViewState(parent), mSortAttribute(AscendingNameHsSortAttribute),
    67     HsBaseViewState(mainWindow, menuMode, parent),
    84     mCollectionsSortAttribute(LatestOnTopHsSortAttribute),
    68     mAddModeProxyModel(0),
    85     mMenuView(menuViewBuilder, HsAllAppsContext),
    69     mSortAttribute(AscendingNameHsSortAttribute)
    86     mMenuMode(menuMode),
    70 {
    87     mAllAppsModel(0),
    71     initialize(menuViewBuilder, HsAllAppsContext);
    88     mMainWindow(mainWindow),
       
    89     mContextModelIndex(), mContextMenu(0)
       
    90 {
       
    91     construct();
    72     construct();
       
    73 	mAddModeProxyModel = new HsAddModeProxyModel(this);
       
    74     mAddModeProxyModel->setSourceModel(mModel);
    92 }
    75 }
    93 
    76 
    94 /*!
    77 /*!
    95  Constructs contained objects.
    78  Constructs contained objects.
    96  */
    79  */
    97 void HsAllAppsState::construct()
    80 void HsAllAppsState::construct()
    98 {
    81 {
    99     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::construct");
    82     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::construct");
   100 
    83 
   101     QState *initialState = new QState(this);
    84     defineTransitions();
   102     setInitialState(initialState);
       
   103 
       
   104     QState *addModeState = new QState(this);
       
   105     connect(addModeState, SIGNAL(entered()),SLOT(addModeEntered()));
       
   106 
       
   107     QState *normalModeState = new QState(this);
       
   108     connect(normalModeState, SIGNAL(entered()),SLOT(normalModeEntered()));
       
   109 
       
   110     initialState->addTransition(new HsMenuModeTransition(
       
   111                                     mMenuMode, NormalHsMenuMode, normalModeState));
       
   112     initialState->addTransition(new HsMenuModeTransition(
       
   113                                     mMenuMode, AddHsMenuMode, addModeState));
       
   114 
    85 
   115     const QString parentName =
    86     const QString parentName =
   116         parent() != 0 ? parent()->objectName() : QString("");
    87         parent() != 0 ? parent()->objectName() : QString("");
   117     setObjectName(parentName + "/allappsstate");
    88     setObjectName(parentName + "/allappsstate");
   118 
    89 
   119     connect(this, SIGNAL(entered()),SLOT(stateEntered()));
    90     connect(mBackKeyAction, SIGNAL(triggered()), SIGNAL(toAppLibraryState()));
   120     connect(this, SIGNAL(exited()),SLOT(stateExited()));
    91 
   121 
    92     mModel = HsMenuService::getAllApplicationsModel(mSortAttribute);
   122     mSecondarySoftkeyAction = new HbAction(Hb::BackNaviAction, this);
    93     mMenuView->setModel(mModel);
   123 
    94 
   124     mMenuView.view()->setNavigationAction(
    95     mModel->preloadIcons();
   125         mSecondarySoftkeyAction);
    96 
   126 
    97     mMenuView->listView()->verticalScrollBar()->setInteractive(true);
   127     connect(mSecondarySoftkeyAction, SIGNAL(triggered()),
    98     HbIndexFeedback *indexFeedback = new HbIndexFeedback(mMenuView->view());
   128             SIGNAL(toAppLibraryState()));
       
   129 
       
   130     mAllAppsModel = HsMenuService::getAllApplicationsModel(mSortAttribute);
       
   131     mMenuView.setModel(mAllAppsModel);
       
   132 
       
   133     mMenuView.listView()->verticalScrollBar()->setInteractive(true);
       
   134     HbIndexFeedback *indexFeedback = new HbIndexFeedback(mMenuView.view());
       
   135     indexFeedback->setIndexFeedbackPolicy(HbIndexFeedback::IndexFeedbackSingleCharacter);
    99     indexFeedback->setIndexFeedbackPolicy(HbIndexFeedback::IndexFeedbackSingleCharacter);
   136     indexFeedback->setItemView(mMenuView.listView());
   100     indexFeedback->setItemView(mMenuView->listView());
   137 
   101 
   138     HSMENUTEST_FUNC_EXIT("HsAllAppsState::construct");
   102     HSMENUTEST_FUNC_EXIT("HsAllAppsState::construct");
   139 }
   103 }
   140 
   104 
       
   105 
   141 /*!
   106 /*!
   142  Creates and installs menu options for the view
   107  Creates and installs menu options for the view
   143  */
   108  */
   144 void HsAllAppsState::setMenuOptions()
   109 void HsAllAppsState::setMenuOptions()
   145 {
   110 {
   146     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::setMenuOptions");
   111     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::setMenuOptions");
   147     QScopedPointer<HbMenu> viewOptions(new HbMenu);
   112     mViewOptions->clearActions();
   148     viewOptions->addAction(hbTrId("txt_applib_opt_task_switcher"),
   113     mViewOptions->addAction(hbTrId("txt_applib_opt_task_switcher"),
   149                            this, SLOT(openTaskSwitcher()));
   114                            static_cast<HsBaseViewState*>(this), SLOT(openTaskSwitcher()));
   150     viewOptions->addAction(hbTrId("txt_applib_opt_add_to_collection"),
   115     mViewOptions->addAction(hbTrId("txt_applib_opt_add_to_collection"),
   151                            this, SLOT(addToCollection()));
   116                            this, SLOT(addToCollection()));
   152     viewOptions->addAction(hbTrId("txt_applib_opt_check_software_updates"),
   117     mViewOptions->addAction(hbTrId("txt_applib_opt_check_software_updates"),
   153                            this, SLOT(checkSoftwareUpdates()));
   118                            static_cast<HsBaseViewState*>(this), SLOT(checkSoftwareUpdates()));
   154 
   119 
   155     HbMenu *const sortMenu = viewOptions->addMenu(hbTrId(
   120     HbMenu *const sortMenu = mViewOptions->addMenu(hbTrId(
   156                                  "txt_applib_opt_sort_by"));
   121                                  "txt_applib_opt_sort_by"));
   157     //Grouped options are exclusive by default.
   122     //Grouped options are exclusive by default.
   158     QActionGroup *sortGroup = new QActionGroup(viewOptions.data());
   123     QActionGroup *sortGroup = new QActionGroup(this);
   159 
   124 
   160     sortGroup->addAction(
   125     sortGroup->addAction(
   161         sortMenu->addAction(hbTrId("txt_applib_opt_sub_ascending"),
   126         sortMenu->addAction(hbTrId("txt_applib_opt_sub_ascending"),
   162                             this, SLOT(ascendingMenuAction())));
   127                             this, SLOT(ascendingMenuAction())));
   163     sortGroup->addAction(
   128     sortGroup->addAction(
   164         sortMenu->addAction(hbTrId("txt_applib_opt_sub_descending"),
   129         sortMenu->addAction(hbTrId("txt_applib_opt_sub_descending"),
   165                             this, SLOT(descendingMenuAction())));
   130                             this, SLOT(descendingMenuAction())));
   166 
   131 
   167     viewOptions->addAction(hbTrId("txt_applib_subtitle_installed"),
   132     mViewOptions->addAction(hbTrId("txt_applib_opt_view_installed_applications"),
   168                            this, SLOT(openInstalledView()));
   133                            this, SLOT(openInstalledView()));
   169 
   134 
   170     foreach(QAction *action, sortMenu->actions()) {
   135     foreach(QAction *action, sortMenu->actions()) {
   171         action->setCheckable(true);
   136         action->setCheckable(true);
   172     }
   137     }
   182         break;
   147         break;
   183     }
   148     }
   184     if (currentSortingPosition >= 0) {
   149     if (currentSortingPosition >= 0) {
   185         sortGroup->actions().at(currentSortingPosition)->setChecked(true);
   150         sortGroup->actions().at(currentSortingPosition)->setChecked(true);
   186     }
   151     }
   187     mMenuView.view()->setMenu(viewOptions.take());
       
   188 
   152 
   189     HSMENUTEST_FUNC_EXIT("HsAllAppsState::setMenuOptions");
   153     HSMENUTEST_FUNC_EXIT("HsAllAppsState::setMenuOptions");
   190 }
   154 }
   191 
   155 
   192 /*!
   156 /*!
   193  Destructor.
   157  Destructor.
   194  */
   158  */
   195 
   159 
   196 HsAllAppsState::~HsAllAppsState()
   160 HsAllAppsState::~HsAllAppsState()
   197 {
   161 {
   198     mMenuView.setModel(NULL);
   162 }
   199     delete mAllAppsModel;
   163 
   200 }
   164 
   201 
   165 /*!
   202 /*!
   166  Slot invoked when normal mode entered.
   203  Scrolls view to first item at top
   167  */
   204  */
   168 void HsAllAppsState::normalModeEntered()
   205 void HsAllAppsState::scrollToBeginning()
   169 {
   206 {
   170     HsBaseViewState::normalModeEntered();
   207     mMenuView.listView()->scrollTo(
   171     if (mMenuView->model() != mModel) {
   208         mAllAppsModel->index(0), HbAbstractItemView::PositionAtTop);
   172         mMenuView->setModel(mModel);
   209 }
   173     }
   210 
   174     connect(mMenuView.data(),
   211 /*!
   175             SIGNAL(activated(QModelIndex)),
   212  Slot invoked when a state is entered.
   176             static_cast<HsBaseViewState*>(this), SLOT(launchItem(QModelIndex)));
   213  */
       
   214 
       
   215 
       
   216 void HsAllAppsState::stateEntered()
       
   217 {
       
   218     qDebug("AllAppsState::stateEntered()");
       
   219     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::stateEntered");
       
   220     
       
   221     mMainWindow.setCurrentView(mMenuView);
       
   222     mMenuView.activate();
       
   223 
       
   224     HSMENUTEST_FUNC_EXIT("HsAllAppsState::stateEntered");
       
   225 }
   177 }
   226 
   178 
   227 /*!
   179 /*!
   228  Slot invoked when add mode entered.
   180  Slot invoked when add mode entered.
   229  */
   181  */
   230 void HsAllAppsState::normalModeEntered()
       
   231 {    
       
   232     setMenuOptions();
       
   233     connect(&mMainWindow, SIGNAL(viewIsReady()),
       
   234         &mMainWindow, SLOT(saveActivity()),
       
   235         Qt::UniqueConnection);
       
   236     connect(&mMenuView,
       
   237             SIGNAL(activated(QModelIndex)),
       
   238             SLOT(listItemActivated(QModelIndex)));
       
   239     connect(&mMenuView,
       
   240             SIGNAL(longPressed(HbAbstractViewItem *, QPointF)),
       
   241             SLOT(listItemLongPressed(HbAbstractViewItem *, QPointF)));
       
   242 }
       
   243 
       
   244 /*!
       
   245  Add mode entered.
       
   246  */
       
   247 void HsAllAppsState::addModeEntered()
   182 void HsAllAppsState::addModeEntered()
   248 {
   183 {
   249     connect(&mMenuView,
   184     HsBaseViewState::addModeEntered();
   250             SIGNAL(activated(QModelIndex)),
   185     if (mMenuView->model() != mAddModeProxyModel) {
   251             SLOT(addActivated(QModelIndex)));
   186         mMenuView->setModel(mAddModeProxyModel);
   252     connect(&mMenuView,
   187     }
   253             SIGNAL(longPressed(HbAbstractViewItem *, QPointF)),
       
   254             SLOT(addLongPressed(HbAbstractViewItem *, QPointF)));
       
   255 }
   188 }
   256 
   189 
   257 /*!
   190 /*!
   258  Slot invoked when a state is exited.
   191  Slot invoked when a state is exited.
   259  */
   192  */
   260 void HsAllAppsState::stateExited()
   193 void HsAllAppsState::stateExited()
   261 {
   194 {
   262     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::stateExited");
   195     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::stateExited");
   263 
   196 
   264     disconnect(&mMainWindow, SIGNAL(viewIsReady()),
       
   265                &mMainWindow, SLOT(saveActivity()));
       
   266        
       
   267     mMenuView.setSearchPanelVisible(false);
       
   268 
       
   269     mMenuView.disconnect(this);
       
   270 
       
   271     mMenuView.view()->setMenu(NULL);
       
   272 
       
   273     mMenuView.inactivate();
       
   274 
       
   275     if (mContextMenu)
       
   276         mContextMenu->close();
       
   277 
       
   278     HsBaseViewState::stateExited();
   197     HsBaseViewState::stateExited();
   279     
   198 
   280     HSMENUTEST_FUNC_EXIT("HsAllAppsState::stateExited");
   199     HSMENUTEST_FUNC_EXIT("HsAllAppsState::stateExited");
   281     qDebug("AllAppsState::stateExited()");
   200     qDebug("AllAppsState::stateExited()");
   282 }
   201 }
   283 
   202 
   284 /*!
   203 /*!
   285  Open task switcher.
       
   286  \retval true if operation is successful.
       
   287  */
       
   288 bool HsAllAppsState::openTaskSwitcher()
       
   289 {
       
   290     return HsMenuService::launchTaskSwitcher();
       
   291 }
       
   292 
       
   293 /*!
       
   294  Check software updates.
       
   295  \retval 0 if operation is successful.
       
   296  */
       
   297 int HsAllAppsState::checkSoftwareUpdates()
       
   298 {
       
   299     int errCode = HsMenuService::launchSoftwareUpdate();
       
   300     if (errCode != 0){
       
   301         createApplicationLaunchFailMessage(errCode,0);
       
   302     }
       
   303     return errCode;
       
   304 }
       
   305 
       
   306 /*!
       
   307  Slot connected to List widget in normal mode.
       
   308  \param index Model index of the activated item.
       
   309  */
       
   310 void HsAllAppsState::listItemActivated(const QModelIndex &index)
       
   311 {
       
   312     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::listItemActivated");
       
   313 
       
   314     QSharedPointer<const CaEntry> entry = mAllAppsModel->entry(index);
       
   315     
       
   316     if (entry->entryTypeName() == widgetTypeName()) {
       
   317         EntryFlags flags = index.data(CaItemModel::FlagsRole).value<
       
   318                                EntryFlags> ();
       
   319         if (!(flags & UninstallEntryFlag)) {
       
   320             machine()->postEvent(
       
   321                 HsMenuEventFactory::createPreviewHSWidgetEvent(
       
   322                     entry->id(), entry->entryTypeName(), entry->attribute(
       
   323                         widgetUriAttributeName()), entry->attribute(
       
   324                         widgetLibraryAttributeName())));
       
   325 
       
   326             const int itemId = index.data(CaItemModel::IdRole).toInt();
       
   327             HsMenuService::touch(itemId);
       
   328         }
       
   329     } else {
       
   330         QVariant data = mAllAppsModel->data(index, CaItemModel::IdRole);
       
   331         int errCode = HsMenuService::executeAction(data.toInt());
       
   332         if (errCode != 0) {
       
   333             createApplicationLaunchFailMessage(errCode,index.data(CaItemModel::IdRole).toInt());
       
   334         }
       
   335     }
       
   336     
       
   337     mMenuView.setSearchPanelVisible(false);
       
   338 
       
   339     HSMENUTEST_FUNC_EXIT("HsAllAppsState::listItemActivated");
       
   340 }
       
   341 
       
   342 /*!
       
   343  Slot connected to List widget in add mode.
   204  Slot connected to List widget in add mode.
   344  \param index Model index of the activated item.
   205  \param index Model index of the activated item.
   345  */
   206  */
   346 void HsAllAppsState::addActivated(const QModelIndex &index)
   207 void HsAllAppsState::addActivated(const QModelIndex &index)
   347 {
   208 {
       
   209     mMenuView->disconnect(this);
   348     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::addActivated");
   210     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::addActivated");
   349     addToHomeScreen(index);
   211     addToHomeScreen(index);
   350     HSMENUTEST_FUNC_EXIT("HsAllAppsState::addActivated");
   212     HSMENUTEST_FUNC_EXIT("HsAllAppsState::addActivated");
   351 }
   213 }
   352 
   214 
   353 /*!
       
   354  Handles long-item-pressed event in all apps view by showing context menu
       
   355  \param item View item
       
   356  \param coords Press point coordinates
       
   357  */
       
   358 void HsAllAppsState::listItemLongPressed(HbAbstractViewItem *item,
       
   359         const QPointF &coords)
       
   360 {
       
   361     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::listItemLongPressed");
       
   362 
       
   363     EntryFlags flags = item->modelIndex().data(
       
   364                            CaItemModel::FlagsRole).value<EntryFlags> ();
       
   365 
       
   366     if (!(flags & UninstallEntryFlag)) {
       
   367         // create context menu
       
   368         mContextMenu = new HbMenu;
       
   369 
       
   370         HbAction *addToHomeScreenAction = mContextMenu->addAction(
       
   371             hbTrId("txt_applib_menu_add_to_home_screen"));
       
   372         addToHomeScreenAction->setData(AddToHomeScreenContextAction);
       
   373 
       
   374         HbAction *addToCollectionAction = mContextMenu->addAction(
       
   375             hbTrId("txt_applib_menu_add_to_collection"));
       
   376         addToCollectionAction->setData(AddToCollectionContextAction);
       
   377 
       
   378         HbAction *uninstallAction = mContextMenu->addAction(
       
   379             hbTrId("txt_common_menu_delete"));
       
   380         uninstallAction->setData(UninstallContextAction);
       
   381         HbAction *appSettingsAction(NULL);
       
   382         HbAction *appDetailsAction(NULL);
       
   383 
       
   384         // check conditions and hide irrelevant menu items
       
   385         QSharedPointer<const CaEntry> entry = mAllAppsModel->entry(item->modelIndex());
       
   386 
       
   387         if (!(entry->attribute(appSettingsPlugin()).isEmpty())) {
       
   388             appSettingsAction = mContextMenu->addAction(
       
   389                 hbTrId("txt_common_menu_settings"));
       
   390             appSettingsAction->setData(AppSettingContextAction);
       
   391         }
       
   392         if (!(entry->attribute(componentIdAttributeName()).isEmpty()) &&
       
   393                 (flags & RemovableEntryFlag) ) {
       
   394             appDetailsAction = mContextMenu->addAction(
       
   395                 hbTrId("txt_common_menu_details"));
       
   396             appDetailsAction->setData(AppDetailsContextAction);
       
   397         }
       
   398 
       
   399         if (!(flags & RemovableEntryFlag)) {
       
   400             uninstallAction->setVisible(false);
       
   401         }
       
   402 
       
   403         mContextModelIndex = item->modelIndex();
       
   404         mContextMenu->setPreferredPos(coords);
       
   405         mContextMenu->setAttribute(Qt::WA_DeleteOnClose);
       
   406         mContextMenu->open(this, SLOT(contextMenuAction(HbAction*)));
       
   407     }
       
   408 
       
   409 
       
   410     HSMENUTEST_FUNC_EXIT("HsAllAppsState::listItemLongPressed");
       
   411 }
       
   412 
   215 
   413 /*!
   216 /*!
   414  Handles context menu actions
   217  Handles context menu actions
   415  */
   218  */
   416 void HsAllAppsState::contextMenuAction(HbAction *action)
   219 void HsAllAppsState::contextMenuAction(HbAction *action)
   417 {
   220 {
   418     HsContextAction command = 
   221     HsContextAction command =
   419         static_cast<HsContextAction>(action->data().toInt());
   222         static_cast<HsContextAction>(action->data().toInt());
   420 
   223 
   421     const int itemId = mContextModelIndex.data(CaItemModel::IdRole).toInt();
   224     const int itemId = mContextModelIndex.data(CaItemModel::IdRole).toInt();
   422 
   225 
   423     switch (command) {
   226     switch (command) {
   427         case AddToCollectionContextAction:
   230         case AddToCollectionContextAction:
   428             // Addding a specific application to
   231             // Addding a specific application to
   429             // an existing collection via item specific menu.
   232             // an existing collection via item specific menu.
   430             machine()->postEvent(
   233             machine()->postEvent(
   431                 HsMenuEventFactory::createAddAppsFromApplicationsViewEvent(
   234                 HsMenuEventFactory::createAddAppsFromApplicationsViewEvent(
   432                     mSortAttribute, mCollectionsSortAttribute, itemId));
   235                     mSortAttribute, itemId));
   433             break;
   236             break;
   434         case UninstallContextAction:
   237         case UninstallContextAction:
   435             machine()->postEvent(
   238             machine()->postEvent(
   436                 HsMenuEventFactory::createUninstallApplicationEvent(itemId));
   239                 HsMenuEventFactory::createUninstallApplicationEvent(itemId));
   437             break;
   240             break;
   438         case AppSettingContextAction: 
   241         case AppSettingContextAction:
   439             machine()->postEvent(
   242             machine()->postEvent(
   440                 HsMenuEventFactory::createAppSettingsViewEvent(itemId));
   243                 HsMenuEventFactory::createAppSettingsViewEvent(itemId));
   441             break;
   244             break;
   442         case AppDetailsContextAction: 
   245         case AppDetailsContextAction:
   443             machine()->postEvent(
   246             machine()->postEvent(
   444                 HsMenuEventFactory::createAppDetailsViewEvent(itemId));
   247                 HsMenuEventFactory::createAppDetailsViewEvent(itemId));
   445             break;            
   248             break;
       
   249         case OpenContextAction:
       
   250             launchItem(mContextModelIndex);
       
   251             break;
   446         default:
   252         default:
   447             break;
   253             break;
   448     }
   254     }
   449                                     
   255     mMenuView->hideSearchPanel();
   450     mMenuView.setSearchPanelVisible(false);
       
   451 }
   256 }
   452 
   257 
   453 /*!
   258 /*!
   454  Slot connected to List widget in add mode.
   259  Slot connected to List widget in add mode.
   455  Called when item long pressed.
   260  Called when item long pressed.
   458  */
   263  */
   459 void HsAllAppsState::addLongPressed(HbAbstractViewItem *item,
   264 void HsAllAppsState::addLongPressed(HbAbstractViewItem *item,
   460                                     const QPointF &coords)
   265                                     const QPointF &coords)
   461 {
   266 {
   462     Q_UNUSED(coords);
   267     Q_UNUSED(coords);
       
   268     mMenuView->disconnect(this);
   463     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::addLongPressed");
   269     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::addLongPressed");
   464     addToHomeScreen(item->modelIndex());
   270     addToHomeScreen(item->modelIndex());
   465     HSMENUTEST_FUNC_EXIT("HsAllAppsState::addLongPressed");
   271     HSMENUTEST_FUNC_EXIT("HsAllAppsState::addLongPressed");
   466 
   272 
   467 }
   273 }
   473 {
   279 {
   474     // Add one/many applications to
   280     // Add one/many applications to
   475     // a new/an existing collection via the All view
   281     // a new/an existing collection via the All view
   476     machine()->postEvent(
   282     machine()->postEvent(
   477         HsMenuEventFactory::createAddAppsFromApplicationsViewEvent(
   283         HsMenuEventFactory::createAddAppsFromApplicationsViewEvent(
   478             mSortAttribute, mCollectionsSortAttribute));
   284             mSortAttribute));
   479 }
   285 }
   480 
   286 
   481 /*!
   287 /*!
   482  Triggers event so that a installed applications state is entered.
   288  Triggers event so that a installed applications state is entered.
   483  \retval void
   289  \retval void
   493 #pragma CTC ENDSKIP
   299 #pragma CTC ENDSKIP
   494 #endif //COVERAGE_MEASUREMENT
   300 #endif //COVERAGE_MEASUREMENT
   495 
   301 
   496 /*!
   302 /*!
   497  Triggers event so that a state adding to Home Screen is reached
   303  Triggers event so that a state adding to Home Screen is reached
   498  \param index of an item to be added to homescreen
   304  \param index of an item to be added to homescreen.
   499  \retval void
   305  \retval void
   500  */
   306  */
   501 void HsAllAppsState::addToHomeScreen(const QModelIndex &index)
   307 void HsAllAppsState::addToHomeScreen(const QModelIndex &index)
   502 {
   308 {
   503     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::addToHomeScreen");
   309     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::addToHomeScreen");
   504     QSharedPointer<const CaEntry> entry = mAllAppsModel->entry(index);
   310     QSharedPointer<const CaEntry> entry = mModel->entry(index);
   505 
   311 
   506     machine()-> postEvent(HsMenuEventFactory::createAddToHomeScreenEvent(
   312     machine()-> postEvent(HsMenuEventFactory::createAddToHomeScreenEvent(
   507                               entry->id(), mMenuMode.getHsMenuMode(), 
   313                               entry->id(), mMenuMode->getHsMenuMode(),
   508                               mMenuMode.getHsToken()));
   314                               mMenuMode->getHsToken()));
   509 
   315 
   510     HSMENUTEST_FUNC_EXIT("HsAllAppsState::addToHomeScreen");
   316     HSMENUTEST_FUNC_EXIT("HsAllAppsState::addToHomeScreen");
       
   317 }
       
   318 
       
   319 /*!
       
   320  Method seting context menu options.
       
   321  */
       
   322 void HsAllAppsState::setContextMenuOptions(HbAbstractViewItem *item, EntryFlags flags)
       
   323 {
       
   324     HbAction *openAction = mContextMenu->addAction(hbTrId(
       
   325         "txt_common_menu_open"));
       
   326     openAction->setData(OpenContextAction);
       
   327 
       
   328     HbAction *addToHomeScreenAction = mContextMenu->addAction(
       
   329         hbTrId("txt_applib_menu_add_to_home_screen"));
       
   330     addToHomeScreenAction->setData(AddToHomeScreenContextAction);
       
   331 
       
   332     HbAction *addToCollectionAction = mContextMenu->addAction(
       
   333         hbTrId("txt_applib_menu_add_to_collection"));
       
   334     addToCollectionAction->setData(AddToCollectionContextAction);
       
   335 
       
   336     HbAction *uninstallAction = mContextMenu->addAction(
       
   337         hbTrId("txt_common_menu_delete"));
       
   338     uninstallAction->setData(UninstallContextAction);
       
   339     HbAction *appSettingsAction(NULL);
       
   340     HbAction *appDetailsAction(NULL);
       
   341 
       
   342     // check conditions and hide irrelevant menu items
       
   343     QSharedPointer<const CaEntry> entry = mModel->entry(item->modelIndex());
       
   344 
       
   345     if (!(entry->attribute(appSettingsPlugin()).isEmpty())) {
       
   346         appSettingsAction = mContextMenu->addAction(
       
   347             hbTrId("txt_common_menu_settings"));
       
   348         appSettingsAction->setData(AppSettingContextAction);
       
   349     }
       
   350     if (!(entry->attribute(componentIdAttributeName()).isEmpty()) &&
       
   351             (flags & RemovableEntryFlag) ) {
       
   352         appDetailsAction = mContextMenu->addAction(
       
   353             hbTrId("txt_common_menu_details"));
       
   354         appDetailsAction->setData(AppDetailsContextAction);
       
   355     }
       
   356 
       
   357     if (!(flags & RemovableEntryFlag)) {
       
   358         uninstallAction->setVisible(false);
       
   359     }
       
   360 
       
   361     addToHomeScreenAction->setVisible(
       
   362         !HsAppLibStateUtils::isCWRTWidgetOnHomeScreen(entry.data()));
   511 }
   363 }
   512 
   364 
   513 /*!
   365 /*!
   514   Menu ascending sort action slot.
   366   Menu ascending sort action slot.
   515  */
   367  */
   516 void HsAllAppsState::ascendingMenuAction()
   368 void HsAllAppsState::ascendingMenuAction()
   517 {
   369 {
   518     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::ascendingMenuAction");
   370     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::ascendingMenuAction");
   519     mSortAttribute = AscendingNameHsSortAttribute;
   371     mSortAttribute = AscendingNameHsSortAttribute;
   520     mAllAppsModel->setSort(mSortAttribute);
   372     mModel->setSort(mSortAttribute);
   521     HSMENUTEST_FUNC_EXIT("HsAllAppsState::ascendingMenuAction");
   373     HSMENUTEST_FUNC_EXIT("HsAllAppsState::ascendingMenuAction");
   522 }
       
   523 
       
   524 /*!
       
   525  Sets collections sort order
       
   526  /param sortOrder sort order.
       
   527  */
       
   528 void HsAllAppsState::collectionsSortOrder(
       
   529     HsSortAttribute sortOrder)
       
   530 {
       
   531     mCollectionsSortAttribute = sortOrder;
       
   532 }
   374 }
   533 
   375 
   534 /*!
   376 /*!
   535  Menu descending sort action slot.
   377  Menu descending sort action slot.
   536  */
   378  */
   537 void HsAllAppsState::descendingMenuAction()
   379 void HsAllAppsState::descendingMenuAction()
   538 {
   380 {
   539     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::descendingMenuAction");
   381     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::descendingMenuAction");
   540     mSortAttribute = DescendingNameHsSortAttribute;
   382     mSortAttribute = DescendingNameHsSortAttribute;
   541     mAllAppsModel->setSort(mSortAttribute);
   383     mModel->setSort(mSortAttribute);
   542     HSMENUTEST_FUNC_EXIT("HsAllAppsState::descendingMenuAction");
   384     HSMENUTEST_FUNC_EXIT("HsAllAppsState::descendingMenuAction");
   543 
   385 
   544 }
   386 }