homescreenapp/stateplugins/hsapplibrarystateplugin/src/hsallappsstate.cpp
changeset 62 341166945d65
parent 55 03646e8da489
child 63 52b0f64eeb51
equal deleted inserted replaced
57:2e2dc3d30ca8 62:341166945d65
    23 #include <hbabstractviewitem.h>
    23 #include <hbabstractviewitem.h>
    24 #include <hsmenueventfactory.h>
    24 #include <hsmenueventfactory.h>
    25 #include <hbinstance.h>
    25 #include <hbinstance.h>
    26 #include <caentry.h>
    26 #include <caentry.h>
    27 #include <hbsearchpanel.h>
    27 #include <hbsearchpanel.h>
       
    28 #include <HbScrollBar>
       
    29 #include <HbIndexFeedback>
    28 
    30 
    29 #include "hsmenuitemmodel.h"
    31 #include "hsmenuitemmodel.h"
    30 #include "cadefs.h"
    32 #include "cadefs.h"
    31 #include "hsallappsstate.h"
    33 #include "hsallappsstate.h"
    32 #include "hsaddappstocollectionstate.h"
    34 #include "hsaddappstocollectionstate.h"
    76  */
    78  */
    77 HsAllAppsState::HsAllAppsState(HsMenuViewBuilder &menuViewBuilder,
    79 HsAllAppsState::HsAllAppsState(HsMenuViewBuilder &menuViewBuilder,
    78                                HsMenuModeWrapper &menuMode,
    80                                HsMenuModeWrapper &menuMode,
    79                                HsMainWindow &mainWindow,
    81                                HsMainWindow &mainWindow,
    80                                QState *parent) :
    82                                QState *parent) :
    81     QState(parent), mSortAttribute(AscendingNameHsSortAttribute),
    83     HsBaseViewState(parent), mSortAttribute(AscendingNameHsSortAttribute),
    82     mCollectionsSortAttribute(LatestOnTopHsSortAttribute),
    84     mCollectionsSortAttribute(LatestOnTopHsSortAttribute),
    83     mMenuView(menuViewBuilder, HsAllAppsContext),
    85     mMenuView(menuViewBuilder, HsAllAppsContext),
    84     mMenuMode(menuMode),
    86     mMenuMode(menuMode),
    85     mAllAppsModel(0),
    87     mAllAppsModel(0),
    86     mMainWindow(mainWindow),
    88     mMainWindow(mainWindow),
   125     connect(mSecondarySoftkeyAction, SIGNAL(triggered()),
   127     connect(mSecondarySoftkeyAction, SIGNAL(triggered()),
   126             SIGNAL(toAppLibraryState()));
   128             SIGNAL(toAppLibraryState()));
   127 
   129 
   128     mAllAppsModel = HsMenuService::getAllApplicationsModel(mSortAttribute);
   130     mAllAppsModel = HsMenuService::getAllApplicationsModel(mSortAttribute);
   129     mMenuView.setModel(mAllAppsModel);
   131     mMenuView.setModel(mAllAppsModel);
       
   132 
       
   133     mMenuView.listView()->verticalScrollBar()->setInteractive(true);
       
   134     HbIndexFeedback *indexFeedback = new HbIndexFeedback(mMenuView.view());
       
   135     indexFeedback->setIndexFeedbackPolicy(HbIndexFeedback::IndexFeedbackSingleCharacter);
       
   136     indexFeedback->setItemView(mMenuView.listView());
   130 
   137 
   131     HSMENUTEST_FUNC_EXIT("HsAllAppsState::construct");
   138     HSMENUTEST_FUNC_EXIT("HsAllAppsState::construct");
   132 }
   139 }
   133 
   140 
   134 /*!
   141 /*!
   208 
   215 
   209 void HsAllAppsState::stateEntered()
   216 void HsAllAppsState::stateEntered()
   210 {
   217 {
   211     qDebug("AllAppsState::stateEntered()");
   218     qDebug("AllAppsState::stateEntered()");
   212     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::stateEntered");
   219     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::stateEntered");
   213 
   220     
   214     mMainWindow.setCurrentView(mMenuView);
   221     mMainWindow.setCurrentView(mMenuView);
   215     mMenuView.activate();
   222     mMenuView.activate();
   216 
   223 
   217     HSMENUTEST_FUNC_EXIT("HsAllAppsState::stateEntered");
   224     HSMENUTEST_FUNC_EXIT("HsAllAppsState::stateEntered");
   218 }
   225 }
   219 
   226 
   220 /*!
   227 /*!
   221  Slot invoked when add mode entered.
   228  Slot invoked when add mode entered.
   222  */
   229  */
   223 void HsAllAppsState::normalModeEntered()
   230 void HsAllAppsState::normalModeEntered()
   224 {
   231 {    
   225     setMenuOptions();
   232     setMenuOptions();
   226 
   233     connect(&mMainWindow, SIGNAL(viewIsReady()),
       
   234         &mMainWindow, SLOT(saveActivity()),
       
   235         Qt::UniqueConnection);
   227     connect(&mMenuView,
   236     connect(&mMenuView,
   228             SIGNAL(activated(QModelIndex)),
   237             SIGNAL(activated(QModelIndex)),
   229             SLOT(listItemActivated(QModelIndex)));
   238             SLOT(listItemActivated(QModelIndex)));
   230     connect(&mMenuView,
   239     connect(&mMenuView,
   231             SIGNAL(longPressed(HbAbstractViewItem *, QPointF)),
   240             SIGNAL(longPressed(HbAbstractViewItem *, QPointF)),
   249  Slot invoked when a state is exited.
   258  Slot invoked when a state is exited.
   250  */
   259  */
   251 void HsAllAppsState::stateExited()
   260 void HsAllAppsState::stateExited()
   252 {
   261 {
   253     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::stateExited");
   262     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::stateExited");
       
   263 
       
   264     disconnect(&mMainWindow, SIGNAL(viewIsReady()),
       
   265                &mMainWindow, SLOT(saveActivity()));
       
   266        
   254     mMenuView.setSearchPanelVisible(false);
   267     mMenuView.setSearchPanelVisible(false);
   255 
   268 
   256     mMenuView.disconnect(this);
   269     mMenuView.disconnect(this);
   257 
   270 
   258     mMenuView.view()->setMenu(NULL);
   271     mMenuView.view()->setMenu(NULL);
   260     mMenuView.inactivate();
   273     mMenuView.inactivate();
   261 
   274 
   262     if (mContextMenu)
   275     if (mContextMenu)
   263         mContextMenu->close();
   276         mContextMenu->close();
   264 
   277 
       
   278     HsBaseViewState::stateExited();
       
   279     
   265     HSMENUTEST_FUNC_EXIT("HsAllAppsState::stateExited");
   280     HSMENUTEST_FUNC_EXIT("HsAllAppsState::stateExited");
   266     qDebug("AllAppsState::stateExited()");
   281     qDebug("AllAppsState::stateExited()");
   267 }
   282 }
   268 
   283 
   269 /*!
   284 /*!
   275     return HsMenuService::launchTaskSwitcher();
   290     return HsMenuService::launchTaskSwitcher();
   276 }
   291 }
   277 
   292 
   278 /*!
   293 /*!
   279  Check software updates.
   294  Check software updates.
   280  \retval true if operation is successful.
   295  \retval 0 if operation is successful.
   281  */
   296  */
   282 bool HsAllAppsState::checkSoftwareUpdates()
   297 int HsAllAppsState::checkSoftwareUpdates()
   283 {
   298 {
   284     return HsMenuService::launchSoftwareUpdate();
   299     int errCode = HsMenuService::launchSoftwareUpdate();
       
   300     if (errCode != 0){
       
   301         createApplicationLaunchFailMessage(errCode,0);
       
   302     }
       
   303     return errCode;
   285 }
   304 }
   286 
   305 
   287 /*!
   306 /*!
   288  Slot connected to List widget in normal mode.
   307  Slot connected to List widget in normal mode.
   289  \param index Model index of the activated item.
   308  \param index Model index of the activated item.
   291 void HsAllAppsState::listItemActivated(const QModelIndex &index)
   310 void HsAllAppsState::listItemActivated(const QModelIndex &index)
   292 {
   311 {
   293     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::listItemActivated");
   312     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::listItemActivated");
   294 
   313 
   295     QSharedPointer<const CaEntry> entry = mAllAppsModel->entry(index);
   314     QSharedPointer<const CaEntry> entry = mAllAppsModel->entry(index);
   296 
   315     
   297     if (entry->entryTypeName() == widgetTypeName()) {
   316     if (entry->entryTypeName() == widgetTypeName()) {
   298         machine()->postEvent(
   317         EntryFlags flags = index.data(CaItemModel::FlagsRole).value<
   299             HsMenuEventFactory::createPreviewHSWidgetEvent(
   318                                EntryFlags> ();
   300                 entry->id(), entry->entryTypeName(), entry->attribute(
   319         if (!(flags & UninstallEntryFlag)) {
   301                     widgetUriAttributeName()), entry->attribute(
   320             machine()->postEvent(
   302                     widgetLibraryAttributeName())));
   321                 HsMenuEventFactory::createPreviewHSWidgetEvent(
   303 
   322                     entry->id(), entry->entryTypeName(), entry->attribute(
   304         const int itemId = index.data(CaItemModel::IdRole).toInt();
   323                         widgetUriAttributeName()), entry->attribute(
   305         HsMenuService::touch(itemId);
   324                         widgetLibraryAttributeName())));
       
   325 
       
   326             const int itemId = index.data(CaItemModel::IdRole).toInt();
       
   327             HsMenuService::touch(itemId);
       
   328         }
   306     } else {
   329     } else {
   307         QVariant data = mAllAppsModel->data(index, CaItemModel::IdRole);
   330         QVariant data = mAllAppsModel->data(index, CaItemModel::IdRole);
   308         HsMenuService::executeAction(data.toInt());
   331         int errCode = HsMenuService::executeAction(data.toInt());
   309     }
   332         if (errCode != 0) {
   310 
   333             createApplicationLaunchFailMessage(errCode,index.data(CaItemModel::IdRole).toInt());
       
   334         }
       
   335     }
       
   336     
   311     mMenuView.setSearchPanelVisible(false);
   337     mMenuView.setSearchPanelVisible(false);
   312 
   338 
   313     HSMENUTEST_FUNC_EXIT("HsAllAppsState::listItemActivated");
   339     HSMENUTEST_FUNC_EXIT("HsAllAppsState::listItemActivated");
   314 }
   340 }
   315 
   341 
   332 void HsAllAppsState::listItemLongPressed(HbAbstractViewItem *item,
   358 void HsAllAppsState::listItemLongPressed(HbAbstractViewItem *item,
   333         const QPointF &coords)
   359         const QPointF &coords)
   334 {
   360 {
   335     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::listItemLongPressed");
   361     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::listItemLongPressed");
   336 
   362 
   337 
       
   338     // create context menu
       
   339     mContextMenu = new HbMenu;
       
   340 
       
   341     HbAction *addToHomeScreenAction = mContextMenu->addAction(hbTrId(
       
   342                                           "txt_applib_menu_add_to_home_screen"));
       
   343     addToHomeScreenAction->setData(AddToHomeScreenContextAction);
       
   344 
       
   345     HbAction *addToCollectionAction = mContextMenu->addAction(hbTrId(
       
   346                                           "txt_applib_menu_add_to_collection"));
       
   347     addToCollectionAction->setData(AddToCollectionContextAction);
       
   348 
       
   349     HbAction *uninstallAction = mContextMenu->addAction(hbTrId(
       
   350                                     "txt_common_menu_delete"));
       
   351     uninstallAction->setData(UninstallContextAction);
       
   352     HbAction *appSettingsAction(NULL);
       
   353     HbAction *appDetailsAction(NULL);
       
   354 
       
   355     // check conditions and hide irrelevant menu items
       
   356 
       
   357     QSharedPointer<const CaEntry> entry = mAllAppsModel->entry(item->modelIndex());
       
   358     EntryFlags flags = item->modelIndex().data(
   363     EntryFlags flags = item->modelIndex().data(
   359                            CaItemModel::FlagsRole).value<EntryFlags> ();
   364                            CaItemModel::FlagsRole).value<EntryFlags> ();
   360 
   365 
   361     if (!(entry->attribute(appSettingsPlugin()).isEmpty())) {
   366     if (!(flags & UninstallEntryFlag)) {
   362         appSettingsAction = mContextMenu->addAction(hbTrId(
   367         // create context menu
   363                                                 "txt_common_menu_settings"));
   368         mContextMenu = new HbMenu;
   364         appSettingsAction->setData(AppSettingContextAction);
   369 
   365     }
   370         HbAction *addToHomeScreenAction = mContextMenu->addAction(
   366     if (!(entry->attribute(componentIdAttributeName()).isEmpty()) && 
   371             hbTrId("txt_applib_menu_add_to_home_screen"));
   367             (flags & RemovableEntryFlag) ) {
   372         addToHomeScreenAction->setData(AddToHomeScreenContextAction);
   368         appDetailsAction = mContextMenu->addAction(hbTrId(
   373 
   369                                                 "txt_common_menu_details"));
   374         HbAction *addToCollectionAction = mContextMenu->addAction(
   370         appDetailsAction->setData(AppDetailsContextAction);
   375             hbTrId("txt_applib_menu_add_to_collection"));
   371     }        
   376         addToCollectionAction->setData(AddToCollectionContextAction);
   372 
   377 
   373     if (!(flags & RemovableEntryFlag)) {
   378         HbAction *uninstallAction = mContextMenu->addAction(
   374         uninstallAction->setVisible(false);
   379             hbTrId("txt_common_menu_delete"));
   375     }
   380         uninstallAction->setData(UninstallContextAction);
   376 
   381         HbAction *appSettingsAction(NULL);
   377     mContextModelIndex = item->modelIndex();
   382         HbAction *appDetailsAction(NULL);
   378     mContextMenu->setPreferredPos(coords);
   383 
   379     mContextMenu->setAttribute(Qt::WA_DeleteOnClose);
   384         // check conditions and hide irrelevant menu items
   380     mContextMenu->open(this, SLOT(contextMenuAction(HbAction*)));
   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     }
   381 
   408 
   382 
   409 
   383     HSMENUTEST_FUNC_EXIT("HsAllAppsState::listItemLongPressed");
   410     HSMENUTEST_FUNC_EXIT("HsAllAppsState::listItemLongPressed");
   384 }
   411 }
   385 
   412 
   404                 HsMenuEventFactory::createAddAppsFromApplicationsViewEvent(
   431                 HsMenuEventFactory::createAddAppsFromApplicationsViewEvent(
   405                     mSortAttribute, mCollectionsSortAttribute, itemId));
   432                     mSortAttribute, mCollectionsSortAttribute, itemId));
   406             break;
   433             break;
   407         case UninstallContextAction:
   434         case UninstallContextAction:
   408             machine()->postEvent(
   435             machine()->postEvent(
   409                 HsMenuEventFactory::createUninstallApplicationEvent(
   436                 HsMenuEventFactory::createUninstallApplicationEvent(itemId));
   410                     itemId));
       
   411             break;
   437             break;
   412         case AppSettingContextAction: 
   438         case AppSettingContextAction: 
   413             machine()->postEvent(
   439             machine()->postEvent(
   414                 HsMenuEventFactory::createAppSettingsViewEvent(itemId));
   440                 HsMenuEventFactory::createAppSettingsViewEvent(itemId));
   415             break;
   441             break;
   476 {
   502 {
   477     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::addToHomeScreen");
   503     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::addToHomeScreen");
   478     QSharedPointer<const CaEntry> entry = mAllAppsModel->entry(index);
   504     QSharedPointer<const CaEntry> entry = mAllAppsModel->entry(index);
   479 
   505 
   480     machine()-> postEvent(HsMenuEventFactory::createAddToHomeScreenEvent(
   506     machine()-> postEvent(HsMenuEventFactory::createAddToHomeScreenEvent(
   481                               entry->id(), mMenuMode.getHsMenuMode()));
   507                               entry->id(), mMenuMode.getHsMenuMode(), 
       
   508                               mMenuMode.getHsToken()));
   482 
   509 
   483     HSMENUTEST_FUNC_EXIT("HsAllAppsState::addToHomeScreen");
   510     HSMENUTEST_FUNC_EXIT("HsAllAppsState::addToHomeScreen");
   484 }
   511 }
   485 
   512 
   486 /*!
   513 /*!