homescreenapp/stateplugins/hsapplibrarystateplugin/src/hsallappsstate.cpp
changeset 39 4e8ebe173323
parent 36 cdae8c6c3876
child 46 23b5d6a29cce
--- a/homescreenapp/stateplugins/hsapplibrarystateplugin/src/hsallappsstate.cpp	Fri Apr 16 14:54:01 2010 +0300
+++ b/homescreenapp/stateplugins/hsapplibrarystateplugin/src/hsallappsstate.cpp	Mon May 03 12:24:59 2010 +0300
@@ -33,10 +33,14 @@
 #include "hsaddappstocollectionstate.h"
 #include "hsapp_defs.h"
 #include "hsmenumodetransition.h"
+#include "caentry.h"
+#include "caservice.h"
 
-// ---------------------------------------------------------------------------
-// ---------------------------------------------------------------------------
-//
+/*!
+ Constructor.
+ \param menuView Menu view.
+ \param parent Owner.
+ */
 HsAllAppsState::HsAllAppsState(HsMenuView &menuView, QState *parent) :
     QState(parent), mSortAttribute(AscendingNameHsSortAttribute),
     mCollectionsSortAttribute(LatestOnTopHsSortAttribute),
@@ -45,9 +49,9 @@
     construct();
 }
 
-// ---------------------------------------------------------------------------
-// ---------------------------------------------------------------------------
-//
+/*!
+ Constructs contained objects.
+ */
 void HsAllAppsState::construct()
 {
     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::construct");
@@ -66,26 +70,29 @@
     initialState->addTransition(new HsMenuModeTransition(
                                     mMenuView, AddHsMenuMode, addModeState));
 
-    setObjectName(this->parent()->objectName() + "/allappsstate");
+    const QString parentName =
+        parent() != 0 ? parent()->objectName() : QString("");
+    setObjectName(parentName + "/allappsstate");
+
     connect(this, SIGNAL(entered()),SLOT(stateEntered()));
     connect(this, SIGNAL(exited()),SLOT(stateExited()));
     mAllAppsModel = HsMenuService::getAllApplicationsModel(mSortAttribute);
     HSMENUTEST_FUNC_EXIT("HsAllAppsState::construct");
 }
 
-// ---------------------------------------------------------------------------
-// ---------------------------------------------------------------------------
-//
+/*!
+ Creates and installs menu options for the view
+ */
 void HsAllAppsState::setMenuOptions()
 {
     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::setMenuOptions");
     HbMenu *const mOptions = new HbMenu();
     mOptions->addAction(hbTrId("txt_applib_opt_task_switcher"),
-                        this,
-                        SLOT(openTaskSwitcher()));
+                        this, SLOT(openTaskSwitcher()));
     mOptions->addAction(hbTrId("txt_applib_opt_add_to_collection"),
-                        this,
-                        SLOT(addToCollection()));
+                        this, SLOT(addToCollection()));
+    mOptions->addAction(hbTrId("txt_applib_opt_check_software_updates"),
+                        this, SLOT(checkSoftwareUpdates()));
 
     HbMenu *const sortMenu = mOptions->addMenu(hbTrId(
                                  "txt_applib_opt_sort_by"));
@@ -94,12 +101,14 @@
 
     sortGroup->addAction(
         sortMenu->addAction(hbTrId("txt_applib_opt_sub_ascending"),
-                            this,
-                            SLOT(ascendingMenuAction())));
+                            this, SLOT(ascendingMenuAction())));
     sortGroup->addAction(
         sortMenu->addAction(hbTrId("txt_applib_opt_sub_descending"),
-                            this,
-                            SLOT(descendingMenuAction())));
+                            this, SLOT(descendingMenuAction())));
+
+    mOptions->addAction(hbTrId("txt_applib_subtitle_installed"),
+                        this, SLOT(openInstalledView()));
+
     mOptions->setParent(this);
     foreach(QAction *action, sortMenu->actions()) {
         action->setCheckable(true);
@@ -122,26 +131,25 @@
     HSMENUTEST_FUNC_EXIT("HsAllAppsState::setMenuOptions");
 }
 
-// ---------------------------------------------------------------------------
-// ---------------------------------------------------------------------------
-//
+/*!
+ Destructor.
+ */
 HsAllAppsState::~HsAllAppsState()
 {
     delete mAllAppsModel;
 }
 
-
-// ---------------------------------------------------------------------------
-// ---------------------------------------------------------------------------
-//
+/*!
+ Populates all applications
+ */
 void HsAllAppsState::scrollToBeginning()
 {
     mBookmark = mAllAppsModel->index(0);
 }
 
-// ---------------------------------------------------------------------------
-// ---------------------------------------------------------------------------
-//
+/*!
+ Slot invoked when a state is entered.
+ */
 void HsAllAppsState::stateEntered()
 {
     qDebug("AllAppsState::stateEntered()");
@@ -152,9 +160,9 @@
     HSMENUTEST_FUNC_EXIT("HsAllAppsState::stateEntered");
 }
 
-// ---------------------------------------------------------------------------
-// ---------------------------------------------------------------------------
-//
+/*!
+ Slot invoked when add mode entered.
+ */
 void HsAllAppsState::normalModeEntered()
 {
     setMenuOptions();
@@ -176,12 +184,14 @@
             SLOT(addLongPressed(HbAbstractViewItem *, QPointF)));
 }
 
-// ---------------------------------------------------------------------------
-// ---------------------------------------------------------------------------
-//
+/*!
+ Slot invoked when a state is exited.
+ */
 void HsAllAppsState::stateExited()
 {
     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::stateExited");
+    mMenuView.setSearchPanelVisible(false);
+
     mBookmark = mMenuView.firstVisibleItemIndex();
 
     mMenuView.disconnect(this);
@@ -200,14 +210,24 @@
     return HsMenuService::launchTaskSwitcher();
 }
 
-// ---------------------------------------------------------------------------
-// ---------------------------------------------------------------------------
-//
+/*!
+ Check software updates.
+ \retval true if operation is successful.
+ */
+bool HsAllAppsState::checkSoftwareUpdates()
+{
+    return HsMenuService::launchSoftwareUpdate();
+}
+
+/*!
+ Slot connected to List widget in normal mode.
+ \param index Model index of the activated item.
+ */
 void HsAllAppsState::listItemActivated(const QModelIndex &index)
 {
     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::listItemActivated");
 
-    const CaEntry *entry = mAllAppsModel->entry(index);
+    QSharedPointer<const CaEntry> entry = mAllAppsModel->entry(index);
 
     if (entry->entryTypeName() == widgetTypeName()) {
         machine()->postEvent(
@@ -228,13 +248,14 @@
     HSMENUTEST_FUNC_EXIT("HsAllAppsState::listItemActivated");
 }
 
-// ---------------------------------------------------------------------------
-// ---------------------------------------------------------------------------
-//
+/*!
+ Slot connected to List widget in add mode.
+ 
+ \param index Model index of the activated item.
+ */
 void HsAllAppsState::addActivated(const QModelIndex &index)
 {
     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::addActivated");
-    mMenuView.setSearchPanelVisible(false);
     addToHomeScreen(index);
     machine()->postEvent(
         HsMenuEventFactory::createOpenHomeScreenEvent());
@@ -243,15 +264,14 @@
 
 /*!
  Handles long-item-pressed event in all apps view by showing context menu
- \param item the event pertains to
- \param position at which context menu is shown
+ \param item View item
+ \param coords Press point coordinates
  */
 void HsAllAppsState::listItemLongPressed(HbAbstractViewItem *item,
         const QPointF &coords)
 {
     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::listItemLongPressed");
 
-    mMenuView.setSearchPanelVisible(false);
 
     // create context menu
     HbMenu *menu = new HbMenu();
@@ -264,9 +284,16 @@
 
     HbAction *uninstallAction = menu->addAction(hbTrId(
                                     "txt_common_menu_delete"));
+    HbAction *appSettingsAction(NULL);
 
     // check conditions and hide irrelevant menu items
 
+    QSharedPointer<const CaEntry> entry = mAllAppsModel->entry(item->modelIndex());
+
+    if (!(entry->attribute(appSettingsPlugin()).isEmpty())) {
+        appSettingsAction = menu->addAction(hbTrId(
+                                                "txt_common_menu_settings"));
+    }
     EntryFlags flags = item->modelIndex().data(
                            CaItemModel::FlagsRole).value<EntryFlags> ();
 
@@ -275,6 +302,7 @@
     }
     // choose proper action
     if (HbAction *selectedAction = menu->exec(coords)) {
+
         if (selectedAction == addToHomeScreenAction) {
             addToHomeScreen(item->modelIndex());
         } else if (selectedAction == addToCollectionAction) {
@@ -285,26 +313,35 @@
             machine()->postEvent(
                 HsMenuEventFactory::createAddAppsFromApplicationsViewEvent(
                     mSortAttribute, mCollectionsSortAttribute, itemId));
-
         } else if (selectedAction == uninstallAction) {
             const int itemId =
                 item->modelIndex().data(CaItemModel::IdRole).toInt();
             HsMenuService::executeAction(itemId, removeActionIdentifier());
+        } else if (selectedAction == appSettingsAction) {
+            const int itemId =
+                item->modelIndex().data(CaItemModel::IdRole).toInt();
+            QMap<QString, QString> attributes = entry->attributes();
+            machine()->postEvent(
+                HsMenuEventFactory::createAppSettingsViewEvent(itemId));
         }
+        mMenuView.setSearchPanelVisible(false);
+
     }
     delete menu;
     HSMENUTEST_FUNC_EXIT("HsAllAppsState::listItemLongPressed");
 }
 
-// ---------------------------------------------------------------------------
-// ---------------------------------------------------------------------------
-//
+/*!
+ Slot connected to List widget in add mode.
+ Called when item long pressed.
+ \param item View item.
+ \param coords Press point coordinates.
+ */
 void HsAllAppsState::addLongPressed(HbAbstractViewItem *item,
                                     const QPointF &coords)
 {
     Q_UNUSED(coords);
     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::addLongPressed");
-    mMenuView.setSearchPanelVisible(false);
     addToHomeScreen(item->modelIndex());
     machine()->postEvent(
         HsMenuEventFactory::createOpenHomeScreenEvent());
@@ -312,9 +349,9 @@
 
 }
 
-// ---------------------------------------------------------------------------
-// ---------------------------------------------------------------------------
-//
+/*!
+  Slot called when application is adding to collection.
+ */
 void HsAllAppsState::addToCollection()
 {
     // Add one/many applications to
@@ -325,6 +362,21 @@
 }
 
 /*!
+ Triggers event so that a installed applications state is entered.
+ \retval void
+ */
+#ifdef COVERAGE_MEASUREMENT
+#pragma CTC SKIP
+#endif //COVERAGE_MEASUREMENT
+void HsAllAppsState::openInstalledView()
+{
+    machine()->postEvent(HsMenuEventFactory::createOpenInstalledViewEvent());
+}
+#ifdef COVERAGE_MEASUREMENT
+#pragma CTC ENDSKIP
+#endif //COVERAGE_MEASUREMENT
+
+/*!
  Triggers event so that a state adding to Home Screen is reached
  \param index of an item to be added to homescreen
  \retval void
@@ -332,23 +384,17 @@
 void HsAllAppsState::addToHomeScreen(const QModelIndex &index)
 {
     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::addToHomeScreen");
-    const CaEntry *entry = mAllAppsModel->entry(index);
-    
-    QMap<QString, QString> attributes = entry->attributes();
-    
+    QSharedPointer<const CaEntry> entry = mAllAppsModel->entry(index);
+
     machine()-> postEvent(HsMenuEventFactory::createAddToHomeScreenEvent(
-                              entry->id(),
-                              entry->entryTypeName(),
-                              entry->attribute(widgetUriAttributeName()),
-                              entry->attribute(widgetLibraryAttributeName()),
-                              &attributes));
+                              entry->id()));
 
     HSMENUTEST_FUNC_EXIT("HsAllAppsState::addToHomeScreen");
 }
 
-// ---------------------------------------------------------------------------
-// ---------------------------------------------------------------------------
-//
+/*!
+  Menu ascending sort action slot.
+ */
 void HsAllAppsState::ascendingMenuAction()
 {
     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::ascendingMenuAction");
@@ -357,18 +403,21 @@
     HSMENUTEST_FUNC_EXIT("HsAllAppsState::ascendingMenuAction");
 }
 
-// ---------------------------------------------------------------------------
-// ---------------------------------------------------------------------------
-//
+/**
+ * Sets collections sort order
+ *
+ * @since S60 ?S60_version.
+ * @param sortOrder sort order.
+ */
 void HsAllAppsState::collectionsSortOrder(
     HsSortAttribute sortOrder)
 {
     mCollectionsSortAttribute = sortOrder;
 }
 
-// ---------------------------------------------------------------------------
-// ---------------------------------------------------------------------------
-//
+/*!
+ Menu descending sort action slot.
+ */
 void HsAllAppsState::descendingMenuAction()
 {
     HSMENUTEST_FUNC_ENTRY("HsAllAppsState::descendingMenuAction");