homescreenapp/stateplugins/hsapplibrarystateplugin/src/hsallappsstate.cpp
changeset 62 341166945d65
parent 55 03646e8da489
child 63 52b0f64eeb51
--- a/homescreenapp/stateplugins/hsapplibrarystateplugin/src/hsallappsstate.cpp	Thu Jun 24 13:11:40 2010 +0100
+++ b/homescreenapp/stateplugins/hsapplibrarystateplugin/src/hsallappsstate.cpp	Fri Jun 25 19:19:22 2010 +0300
@@ -25,6 +25,8 @@
 #include <hbinstance.h>
 #include <caentry.h>
 #include <hbsearchpanel.h>
+#include <HbScrollBar>
+#include <HbIndexFeedback>
 
 #include "hsmenuitemmodel.h"
 #include "cadefs.h"
@@ -78,7 +80,7 @@
                                HsMenuModeWrapper &menuMode,
                                HsMainWindow &mainWindow,
                                QState *parent) :
-    QState(parent), mSortAttribute(AscendingNameHsSortAttribute),
+    HsBaseViewState(parent), mSortAttribute(AscendingNameHsSortAttribute),
     mCollectionsSortAttribute(LatestOnTopHsSortAttribute),
     mMenuView(menuViewBuilder, HsAllAppsContext),
     mMenuMode(menuMode),
@@ -128,6 +130,11 @@
     mAllAppsModel = HsMenuService::getAllApplicationsModel(mSortAttribute);
     mMenuView.setModel(mAllAppsModel);
 
+    mMenuView.listView()->verticalScrollBar()->setInteractive(true);
+    HbIndexFeedback *indexFeedback = new HbIndexFeedback(mMenuView.view());
+    indexFeedback->setIndexFeedbackPolicy(HbIndexFeedback::IndexFeedbackSingleCharacter);
+    indexFeedback->setItemView(mMenuView.listView());
+
     HSMENUTEST_FUNC_EXIT("HsAllAppsState::construct");
 }
 
@@ -210,7 +217,7 @@
 {
     qDebug("AllAppsState::stateEntered()");
     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::stateEntered");
-
+    
     mMainWindow.setCurrentView(mMenuView);
     mMenuView.activate();
 
@@ -221,9 +228,11 @@
  Slot invoked when add mode entered.
  */
 void HsAllAppsState::normalModeEntered()
-{
+{    
     setMenuOptions();
-
+    connect(&mMainWindow, SIGNAL(viewIsReady()),
+        &mMainWindow, SLOT(saveActivity()),
+        Qt::UniqueConnection);
     connect(&mMenuView,
             SIGNAL(activated(QModelIndex)),
             SLOT(listItemActivated(QModelIndex)));
@@ -251,6 +260,10 @@
 void HsAllAppsState::stateExited()
 {
     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::stateExited");
+
+    disconnect(&mMainWindow, SIGNAL(viewIsReady()),
+               &mMainWindow, SLOT(saveActivity()));
+       
     mMenuView.setSearchPanelVisible(false);
 
     mMenuView.disconnect(this);
@@ -262,6 +275,8 @@
     if (mContextMenu)
         mContextMenu->close();
 
+    HsBaseViewState::stateExited();
+    
     HSMENUTEST_FUNC_EXIT("HsAllAppsState::stateExited");
     qDebug("AllAppsState::stateExited()");
 }
@@ -277,11 +292,15 @@
 
 /*!
  Check software updates.
- \retval true if operation is successful.
+ \retval 0 if operation is successful.
  */
-bool HsAllAppsState::checkSoftwareUpdates()
+int HsAllAppsState::checkSoftwareUpdates()
 {
-    return HsMenuService::launchSoftwareUpdate();
+    int errCode = HsMenuService::launchSoftwareUpdate();
+    if (errCode != 0){
+        createApplicationLaunchFailMessage(errCode,0);
+    }
+    return errCode;
 }
 
 /*!
@@ -293,21 +312,28 @@
     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::listItemActivated");
 
     QSharedPointer<const CaEntry> entry = mAllAppsModel->entry(index);
-
+    
     if (entry->entryTypeName() == widgetTypeName()) {
-        machine()->postEvent(
-            HsMenuEventFactory::createPreviewHSWidgetEvent(
-                entry->id(), entry->entryTypeName(), entry->attribute(
-                    widgetUriAttributeName()), entry->attribute(
-                    widgetLibraryAttributeName())));
+        EntryFlags flags = index.data(CaItemModel::FlagsRole).value<
+                               EntryFlags> ();
+        if (!(flags & UninstallEntryFlag)) {
+            machine()->postEvent(
+                HsMenuEventFactory::createPreviewHSWidgetEvent(
+                    entry->id(), entry->entryTypeName(), entry->attribute(
+                        widgetUriAttributeName()), entry->attribute(
+                        widgetLibraryAttributeName())));
 
-        const int itemId = index.data(CaItemModel::IdRole).toInt();
-        HsMenuService::touch(itemId);
+            const int itemId = index.data(CaItemModel::IdRole).toInt();
+            HsMenuService::touch(itemId);
+        }
     } else {
         QVariant data = mAllAppsModel->data(index, CaItemModel::IdRole);
-        HsMenuService::executeAction(data.toInt());
+        int errCode = HsMenuService::executeAction(data.toInt());
+        if (errCode != 0) {
+            createApplicationLaunchFailMessage(errCode,index.data(CaItemModel::IdRole).toInt());
+        }
     }
-
+    
     mMenuView.setSearchPanelVisible(false);
 
     HSMENUTEST_FUNC_EXIT("HsAllAppsState::listItemActivated");
@@ -334,50 +360,51 @@
 {
     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::listItemLongPressed");
 
-
-    // create context menu
-    mContextMenu = new HbMenu;
-
-    HbAction *addToHomeScreenAction = mContextMenu->addAction(hbTrId(
-                                          "txt_applib_menu_add_to_home_screen"));
-    addToHomeScreenAction->setData(AddToHomeScreenContextAction);
-
-    HbAction *addToCollectionAction = mContextMenu->addAction(hbTrId(
-                                          "txt_applib_menu_add_to_collection"));
-    addToCollectionAction->setData(AddToCollectionContextAction);
-
-    HbAction *uninstallAction = mContextMenu->addAction(hbTrId(
-                                    "txt_common_menu_delete"));
-    uninstallAction->setData(UninstallContextAction);
-    HbAction *appSettingsAction(NULL);
-    HbAction *appDetailsAction(NULL);
-
-    // check conditions and hide irrelevant menu items
-
-    QSharedPointer<const CaEntry> entry = mAllAppsModel->entry(item->modelIndex());
     EntryFlags flags = item->modelIndex().data(
                            CaItemModel::FlagsRole).value<EntryFlags> ();
 
-    if (!(entry->attribute(appSettingsPlugin()).isEmpty())) {
-        appSettingsAction = mContextMenu->addAction(hbTrId(
-                                                "txt_common_menu_settings"));
-        appSettingsAction->setData(AppSettingContextAction);
+    if (!(flags & UninstallEntryFlag)) {
+        // create context menu
+        mContextMenu = new HbMenu;
+
+        HbAction *addToHomeScreenAction = mContextMenu->addAction(
+            hbTrId("txt_applib_menu_add_to_home_screen"));
+        addToHomeScreenAction->setData(AddToHomeScreenContextAction);
+
+        HbAction *addToCollectionAction = mContextMenu->addAction(
+            hbTrId("txt_applib_menu_add_to_collection"));
+        addToCollectionAction->setData(AddToCollectionContextAction);
+
+        HbAction *uninstallAction = mContextMenu->addAction(
+            hbTrId("txt_common_menu_delete"));
+        uninstallAction->setData(UninstallContextAction);
+        HbAction *appSettingsAction(NULL);
+        HbAction *appDetailsAction(NULL);
+
+        // check conditions and hide irrelevant menu items
+        QSharedPointer<const CaEntry> entry = mAllAppsModel->entry(item->modelIndex());
+
+        if (!(entry->attribute(appSettingsPlugin()).isEmpty())) {
+            appSettingsAction = mContextMenu->addAction(
+                hbTrId("txt_common_menu_settings"));
+            appSettingsAction->setData(AppSettingContextAction);
+        }
+        if (!(entry->attribute(componentIdAttributeName()).isEmpty()) &&
+                (flags & RemovableEntryFlag) ) {
+            appDetailsAction = mContextMenu->addAction(
+                hbTrId("txt_common_menu_details"));
+            appDetailsAction->setData(AppDetailsContextAction);
+        }
+
+        if (!(flags & RemovableEntryFlag)) {
+            uninstallAction->setVisible(false);
+        }
+
+        mContextModelIndex = item->modelIndex();
+        mContextMenu->setPreferredPos(coords);
+        mContextMenu->setAttribute(Qt::WA_DeleteOnClose);
+        mContextMenu->open(this, SLOT(contextMenuAction(HbAction*)));
     }
-    if (!(entry->attribute(componentIdAttributeName()).isEmpty()) && 
-            (flags & RemovableEntryFlag) ) {
-        appDetailsAction = mContextMenu->addAction(hbTrId(
-                                                "txt_common_menu_details"));
-        appDetailsAction->setData(AppDetailsContextAction);
-    }        
-
-    if (!(flags & RemovableEntryFlag)) {
-        uninstallAction->setVisible(false);
-    }
-
-    mContextModelIndex = item->modelIndex();
-    mContextMenu->setPreferredPos(coords);
-    mContextMenu->setAttribute(Qt::WA_DeleteOnClose);
-    mContextMenu->open(this, SLOT(contextMenuAction(HbAction*)));
 
 
     HSMENUTEST_FUNC_EXIT("HsAllAppsState::listItemLongPressed");
@@ -406,8 +433,7 @@
             break;
         case UninstallContextAction:
             machine()->postEvent(
-                HsMenuEventFactory::createUninstallApplicationEvent(
-                    itemId));
+                HsMenuEventFactory::createUninstallApplicationEvent(itemId));
             break;
         case AppSettingContextAction: 
             machine()->postEvent(
@@ -478,7 +504,8 @@
     QSharedPointer<const CaEntry> entry = mAllAppsModel->entry(index);
 
     machine()-> postEvent(HsMenuEventFactory::createAddToHomeScreenEvent(
-                              entry->id(), mMenuMode.getHsMenuMode()));
+                              entry->id(), mMenuMode.getHsMenuMode(), 
+                              mMenuMode.getHsToken()));
 
     HSMENUTEST_FUNC_EXIT("HsAllAppsState::addToHomeScreen");
 }