homescreenapp/stateplugins/hsapplibrarystateplugin/src/hsapplibrarystate.cpp
changeset 46 23b5d6a29cce
parent 39 4e8ebe173323
child 51 4785f57bf3d4
equal deleted inserted replaced
39:4e8ebe173323 46:23b5d6a29cce
    12  * Contributors:
    12  * Contributors:
    13  *
    13  *
    14  * Description: Menu Application Library state.
    14  * Description: Menu Application Library state.
    15  *
    15  *
    16  */
    16  */
    17 #include <qsignaltransition.h>
       
    18 #include <qhistorystate.h>
       
    19 
       
    20 #include <hbmainwindow.h>
    17 #include <hbmainwindow.h>
    21 #include <hbview.h>
    18 #include <hbview.h>
    22 #include <hbaction.h>
    19 #include <hbaction.h>
    23 #include <hbtoolbar.h>
    20 #include <HbToolBar>
       
    21 #include <HbIcon>
    24 #include <hbinstance.h>
    22 #include <hbinstance.h>
    25 #include <hblistview.h>
    23 #include <hblistview.h>
    26 #include <hbsearchpanel.h>
    24 #include <hbsearchpanel.h>
       
    25 #include <HbToolBarExtension>
       
    26 #include <HbStyleLoader>
    27 #include <hsmenueventtransition.h>
    27 #include <hsmenueventtransition.h>
    28 
    28 
    29 #include "hstest_global.h"
    29 #include "hstest_global.h"
    30 #include "hsapplibrarystate.h"
    30 #include "hsapplibrarystate.h"
    31 #include "hsallappsstate.h"
    31 #include "hsallappsstate.h"
    32 #include "hsallcollectionsstate.h"
    32 #include "hsallcollectionsstate.h"
    33 #include "hscollectionstate.h"
    33 #include "hscollectionstate.h"
    34 #include "hsinstalledappsstate.h"
    34 #include "hsinstalledappsstate.h"
    35 #include "hsovistorehandler.h"
    35 #include "hsoperatorhandler.h"
    36 #include "hsmenuview.h"
    36 #include "hsmenuview.h"
    37 #include "hsmenumodetransition.h"
    37 #include "hsmenumodetransition.h"
    38 
    38 
    39 /*!
    39 /*!
       
    40  \class HsAppLibraryState
       
    41  \ingroup group_hsmenustateplugin
       
    42  \brief Application Library State.
       
    43  Parent state for Application Library functionality
       
    44  (browsing applications and collections)
       
    45  \lib ?library
       
    46  \see StateMachine
       
    47  */
       
    48 
       
    49 /*!
       
    50  \var HsAppLibraryState::mSecondarySoftkeyAction
       
    51  Secondary Softkey action.
       
    52  Usually backstepping functionality.
       
    53  Own.
       
    54  */
       
    55 
       
    56 /*!
       
    57  \var HsAppLibraryState::mAllAppsState
       
    58  All Applications state.
       
    59  Own.
       
    60  */
       
    61 
       
    62 /*!
       
    63  \var HsAppLibraryState::mHistoryTransaction
       
    64  Transition to remember last visited child state in Application Library.
       
    65  Own.
       
    66  */
       
    67 
       
    68 /*!
       
    69  \var HsAppLibraryState::mAllCollectionsState
       
    70  All Collections state.
       
    71  Own.
       
    72  */
       
    73 
       
    74 /*!
       
    75  \var HsAppLibraryState::mCollectionState
       
    76  Collection state.
       
    77  Own.
       
    78  */
       
    79 
       
    80 /*!
       
    81  \fn void HsAppLibraryState::toHomescreenState();
       
    82  Signal emitted when leaving the state,
       
    83  i.e when the back softkey is pressed.
       
    84  */
       
    85 
       
    86 /*!
       
    87  \fn void HsAppLibraryState::initialize();
       
    88  Signal emitted when entering the state
       
    89  */
       
    90 
       
    91 /*!
    40  Constructor.
    92  Constructor.
    41  \param parent Owner.
    93  \param parent Owner.
    42  */
    94  */
    43 HsAppLibraryState::HsAppLibraryState(QState *parent) :
    95 HsAppLibraryState::HsAppLibraryState(QState *parent) :
    44     QState(parent), mSecondarySoftkeyAction(0), mAllAppsState(0),
    96     QState(parent), mAllAppsState(0),
    45     mHistoryTransaction(0), mAllCollectionsState(0), mCollectionState(0)
    97     mHistoryTransaction(0), mAllCollectionsState(0), mCollectionState(0)
    46 {
    98 {
    47     construct();
    99     construct();
    48 }
   100 }
    49 
   101 
    50 /*!
   102 /*!
    51  Destructor.
   103  Destructor.
    52  */
   104  */
    53 HsAppLibraryState::~HsAppLibraryState()
   105 HsAppLibraryState::~HsAppLibraryState()
    54 {
   106 {
    55     HbMainWindow *const hbW =
   107     delete mAllAppsState;
    56         HbInstance::instance()->allMainWindows().value(0);
   108     delete mAllCollectionsState;
    57 
   109     delete mCollectionState;
    58     if (hbW) {
   110     delete mInstalledAppsState;
    59         mMenuView.view()->setNavigationAction(NULL);
   111 
    60         hbW->removeView(mMenuView.view());
       
    61     }
       
    62 }
   112 }
    63 
   113 
    64 /*!
   114 /*!
    65  Constructs contained objects.
   115  Constructs contained objects.
    66  */
   116  */
    67 void HsAppLibraryState::construct()
   117 void HsAppLibraryState::construct()
    68 {
   118 {
    69     HSMENUTEST_FUNC_ENTRY("HsAppLibraryState::construct");
   119     HSMENUTEST_FUNC_ENTRY("HsAppLibraryState::construct");
    70     setObjectName("homescreen.nokia.com/state/applibrarystate");
   120     setObjectName("homescreen.nokia.com/state/applibrarystate");
    71 
   121 
    72     mSecondarySoftkeyAction = new HbAction(Hb::BackAction, this);
   122     mAllAppsState = new HsAllAppsState(mMenuViewBuilder, mMenuMode, this);
    73     connect(mSecondarySoftkeyAction, SIGNAL(triggered()),
       
    74             SIGNAL(toHomescreenState()));
       
    75 
       
    76     mAllAppsState = new HsAllAppsState(mMenuView, this);
       
    77     connect(this, SIGNAL(entered()),mAllAppsState, SLOT(scrollToBeginning()));
   123     connect(this, SIGNAL(entered()),mAllAppsState, SLOT(scrollToBeginning()));
    78 
   124 
    79     mAllCollectionsState = new HsAllCollectionsState(mMenuView, this);
   125     mAllCollectionsState = new HsAllCollectionsState(mMenuViewBuilder, mMenuMode, this);
    80     connect(this, SIGNAL(entered()),
   126     connect(this, SIGNAL(entered()),
    81             mAllCollectionsState, SLOT(scrollToBeginning()));
   127             mAllCollectionsState, SLOT(scrollToBeginning()));
    82 
   128 
    83     QState *initialState = new QState(this);
   129     QState *initialState = new QState(this);
    84     setInitialState(initialState);
   130     setInitialState(initialState);
    85 
   131 
    86     mHistoryTransaction =  new HsMenuModeTransition(
   132     mHistoryTransaction =  new HsMenuModeTransition(
    87         mMenuView, NormalHsMenuMode, mAllAppsState);
   133         mMenuMode, NormalHsMenuMode, mAllAppsState);
       
   134 
    88     initialState->addTransition(mHistoryTransaction);
   135     initialState->addTransition(mHistoryTransaction);
    89     initialState->addTransition(new HsMenuModeTransition(
   136     initialState->addTransition(new HsMenuModeTransition(
    90                                     mMenuView, AddHsMenuMode, mAllAppsState));
   137                                     mMenuMode, AddHsMenuMode, mAllAppsState));
    91 
   138 
    92     mCollectionState = new HsCollectionState(mMenuView, this);
   139     mCollectionState = new HsCollectionState(mMenuViewBuilder,
       
   140             mMenuMode,
       
   141             this);
       
   142 
    93     connect(mCollectionState, SIGNAL(entered()),SLOT(clearToolbarLatch()));
   143     connect(mCollectionState, SIGNAL(entered()),SLOT(clearToolbarLatch()));
    94 
   144 
    95     HsMenuEventTransition *eventTransition =
   145     HsMenuEventTransition *eventTransition =
    96         new HsMenuEventTransition(HsMenuEvent::OpenCollection,
   146         new HsMenuEventTransition(HsMenuEvent::OpenCollection,
    97                                   mAllCollectionsState, mCollectionState);
   147                                   mAllCollectionsState, mCollectionState);
   106     HsMenuEventTransition *collectionToAppLibTransition =
   156     HsMenuEventTransition *collectionToAppLibTransition =
   107         new HsMenuEventTransition(HsMenuEvent::OpenApplicationLibrary,
   157         new HsMenuEventTransition(HsMenuEvent::OpenApplicationLibrary,
   108                                   mCollectionState, mAllCollectionsState);
   158                                   mCollectionState, mAllCollectionsState);
   109     mCollectionState->addTransition(collectionToAppLibTransition);
   159     mCollectionState->addTransition(collectionToAppLibTransition);
   110 
   160 
   111     HsInstalledAppsState *installedAppsState = new HsInstalledAppsState(
   161     mInstalledAppsState = new HsInstalledAppsState(
   112         mMenuView, this);
   162         mMenuViewBuilder, this);
   113 
   163 
   114     HsMenuEventTransition *installedToAppLibTransition =
   164     HsMenuEventTransition *installedToAppLibTransition =
   115         new HsMenuEventTransition(HsMenuEvent::OpenApplicationLibrary,
   165         new HsMenuEventTransition(HsMenuEvent::OpenApplicationLibrary,
   116                                   installedAppsState, mAllAppsState);
   166                                   mInstalledAppsState, mAllAppsState);
   117     installedAppsState->addTransition(installedToAppLibTransition);
   167     mInstalledAppsState->addTransition(installedToAppLibTransition);
   118 
   168 
   119     HsMenuEventTransition *allViewToInstalledTransition =
   169     HsMenuEventTransition *allViewToInstalledTransition =
   120         new HsMenuEventTransition(HsMenuEvent::OpenInstalledView,
   170         new HsMenuEventTransition(HsMenuEvent::OpenInstalledView,
   121                                   mAllAppsState, installedAppsState);
   171                                   mAllAppsState, mInstalledAppsState);
   122     mAllAppsState->addTransition(allViewToInstalledTransition);
   172     mAllAppsState->addTransition(allViewToInstalledTransition);
   123 
   173 
   124     constructToolbar();
   174     constructToolbar();
   125 
   175 
   126     connect(this, SIGNAL(entered()),SLOT(stateEntered()));
       
   127     connect(this, SIGNAL(exited()),SLOT(stateExited()));
       
   128     connect(mAllCollectionsState, SIGNAL(sortOrderChanged(HsSortAttribute)),
   176     connect(mAllCollectionsState, SIGNAL(sortOrderChanged(HsSortAttribute)),
   129             mAllAppsState, SLOT(collectionsSortOrder(HsSortAttribute)));
   177             mAllAppsState, SLOT(collectionsSortOrder(HsSortAttribute)));
   130     connect(mAllCollectionsState, SIGNAL(sortOrderChanged(HsSortAttribute)),
   178     connect(mAllCollectionsState, SIGNAL(sortOrderChanged(HsSortAttribute)),
   131             mCollectionState, SLOT(collectionsSortOrder(HsSortAttribute)));
   179             mCollectionState, SLOT(collectionsSortOrder(HsSortAttribute)));
   132 
   180 
   133     connect(mAllAppsState, SIGNAL(entered()),
   181     connect(mAllAppsState, SIGNAL(entered()),
   134             this, SLOT(allAppsStateEntered()));
   182             this, SLOT(allAppsStateEntered()));
       
   183 
       
   184     connect(mAllAppsState, SIGNAL(toAppLibraryState()),
       
   185             this, SIGNAL(toHomescreenState()));
       
   186     connect(mAllCollectionsState, SIGNAL(toAppLibraryState()),
       
   187             this, SIGNAL(toHomescreenState()));
       
   188 
   135     connect(mAllCollectionsState, SIGNAL(entered()),
   189     connect(mAllCollectionsState, SIGNAL(entered()),
   136             this, SLOT(allCollectionsStateEntered()));
   190             this, SLOT(allCollectionsStateEntered()));
   137 
   191 
   138     HSMENUTEST_FUNC_EXIT("HsAppLibraryState::construct");
   192     HSMENUTEST_FUNC_EXIT("HsAppLibraryState::construct");
   139 }
   193 }
   149     QState::onEntry(event);
   203     QState::onEntry(event);
   150 
   204 
   151     if (event->type() == HsMenuEvent::eventType()) {
   205     if (event->type() == HsMenuEvent::eventType()) {
   152         HsMenuEvent *menuEvent = static_cast<HsMenuEvent *>(event);
   206         HsMenuEvent *menuEvent = static_cast<HsMenuEvent *>(event);
   153         QVariantMap data = menuEvent->data();
   207         QVariantMap data = menuEvent->data();
   154         mMenuView.setHsMenuMode(
   208         mMenuMode.setHsMenuMode(
   155             static_cast<HsMenuMode>(data.value(menuModeType()).toInt()));
   209             static_cast<HsMenuMode>(data.value(menuModeType()).toInt()));
   156     } else {
   210     } else {
   157         mMenuView.setHsMenuMode(NormalHsMenuMode);
   211         mMenuMode.setHsMenuMode(NormalHsMenuMode);
   158     }
   212     }
   159 
   213 
   160     HSMENUTEST_FUNC_EXIT("HsAppLibraryState::onEntry");
   214     HSMENUTEST_FUNC_EXIT("HsAppLibraryState::onEntry");
   161 }
   215 }
   162 
   216 
   163 /*!
   217 /*!
   164  Slot invoked when a state is entered.
       
   165  */
       
   166 void HsAppLibraryState::stateEntered()
       
   167 {
       
   168     HSTEST_FUNC_ENTRY("AppLibraryState::stateEntered");
       
   169     HbMainWindow *hbW = HbInstance::instance()->allMainWindows().value(0);
       
   170     if (!hbW->views().contains(mMenuView.view())) {
       
   171         hbW->addView(mMenuView.view());
       
   172         mMenuView.view()->setNavigationAction(mSecondarySoftkeyAction);
       
   173     }
       
   174     hbW->setCurrentView(mMenuView.view());
       
   175     HSTEST_FUNC_EXIT("AppLibraryState::stateEntered");
       
   176 }
       
   177 
       
   178 /*!
       
   179  Slot invoked when a state is exited.
       
   180  */
       
   181 void HsAppLibraryState::stateExited()
       
   182 {
       
   183     HSTEST_FUNC_ENTRY("AppLibraryState::stateExited");
       
   184     HSTEST_FUNC_EXIT("AppLibraryState::stateExited");
       
   185 }
       
   186 
       
   187 /*!
       
   188  Sets up Toolbar.
   218  Sets up Toolbar.
   189  */
   219  */
   190 void HsAppLibraryState::constructToolbar()
   220 void HsAppLibraryState::constructToolbar()
   191 {
   221 {
   192     HSMENUTEST_FUNC_ENTRY("HsAppLibraryState::constructToolbar");
   222     HSMENUTEST_FUNC_ENTRY("HsAppLibraryState::constructToolbar");
   193 
   223 
   194     HsOviStoreHandler *const oviStoreHandler = new HsOviStoreHandler(this);
   224     connect(mMenuViewBuilder.oviStoreAction(), SIGNAL(triggered()),
   195 
   225             this, SLOT(oviStoreAction()));
   196     HbAction *const oviStoreAction(mMenuView.oviStoreAction());
   226 
   197 
   227     HsOperatorHandler *const operatorHandler = new HsOperatorHandler(this);
   198     oviStoreAction->setIcon(HbIcon(oviStoreHandler->icon()));
   228 
   199     connect(mMenuView.oviStoreAction(), SIGNAL(triggered()),
   229     const bool operatorActionAvailable = !operatorHandler->icon().isNull();
   200             oviStoreHandler, SLOT(action()));
   230 
   201 
   231     if (operatorActionAvailable) {
   202     HbAction *const allCollectionsAction(mMenuView.allCollectionsAction());
   232 
   203 
   233         //TODO HbToolBarExtension is not supported in docml currently
   204     mAllAppsState->addTransition(allCollectionsAction, SIGNAL(triggered()),
   234         //should be changed in future
   205                                  mAllCollectionsState);
   235         bool loaded = HbStyleLoader::registerFilePath(
   206     mCollectionState->addTransition(allCollectionsAction,
   236                      ":/css/hsapplibrarystateplugin.css");
   207                                     SIGNAL(triggered()), mAllCollectionsState);
   237         Q_ASSERT(loaded);
   208 
   238         HbAction *const operatorAction(mMenuViewBuilder.operatorAction());
   209     HbAction *const allAppsAction(mMenuView.allAppsAction());
   239 
   210 
   240         HbToolBarExtension *const extension(
   211     mAllCollectionsState->addTransition(allAppsAction,
   241             mMenuViewBuilder.toolBarExtension());
   212                                         SIGNAL(triggered()), mAllAppsState);
   242         HbAction *const extensionAction(
   213     mCollectionState->addTransition(allAppsAction, SIGNAL(triggered()),
   243             mMenuViewBuilder.toolBar()->addExtension(extension));
   214                                     mAllAppsState);
   244 
   215 
   245         extensionAction->setIcon(HbIcon("qtg_mono_store"));
   216     mAllAppsState->assignProperty(
   246 
   217         allAppsAction, "checked", true);
   247         operatorAction->setIcon(operatorHandler->icon());
       
   248         operatorAction->setText(hbTrId(operatorHandler->text().toLatin1()));
       
   249 
       
   250         //TODO: no locstring for ovi store currently
       
   251         mMenuViewBuilder.oviStoreAction()->setText("Ovi Store");
       
   252 
       
   253         connect(mMenuViewBuilder.operatorAction(), SIGNAL(triggered()),
       
   254                 operatorHandler, SLOT(action()));
       
   255 
       
   256         extension->addAction(mMenuViewBuilder.oviStoreAction());
       
   257         extension->addAction(operatorAction);
       
   258 
       
   259     } else {
       
   260         mMenuViewBuilder.toolBar()->addAction(
       
   261             mMenuViewBuilder.oviStoreAction());
       
   262     }
       
   263 
       
   264 
       
   265     HbAction *const allCollectionsAction(mMenuViewBuilder.allCollectionsAction());
       
   266 
       
   267     mAllAppsState->addTransition(
       
   268         allCollectionsAction, SIGNAL(triggered()), mAllCollectionsState);
       
   269     mCollectionState->addTransition(
       
   270         allCollectionsAction, SIGNAL(triggered()), mAllCollectionsState);
       
   271 
       
   272     HbAction *const allAppsAction(mMenuViewBuilder.allAppsAction());
       
   273 
       
   274     mAllCollectionsState->addTransition(
       
   275         allAppsAction, SIGNAL(triggered()), mAllAppsState);
       
   276     mCollectionState->addTransition(
       
   277         allAppsAction, SIGNAL(triggered()), mAllAppsState);
       
   278 
       
   279     mAllAppsState->assignProperty(allAppsAction, "checked", true);
   218     mAllCollectionsState->assignProperty(
   280     mAllCollectionsState->assignProperty(
   219         allCollectionsAction, "checked", true);
   281         allCollectionsAction, "checked", true);
   220     HSMENUTEST_FUNC_EXIT("HsAppLibraryState::constructToolbar");
   282     HSMENUTEST_FUNC_EXIT("HsAppLibraryState::constructToolbar");
   221 }
   283 }
   222 
   284 
   225 */
   287 */
   226 void HsAppLibraryState::clearToolbarLatch()
   288 void HsAppLibraryState::clearToolbarLatch()
   227 {
   289 {
   228     HSMENUTEST_FUNC_ENTRY("HsAppLibraryState::clearToolbarLatch");
   290     HSMENUTEST_FUNC_ENTRY("HsAppLibraryState::clearToolbarLatch");
   229     QAction *const checkedAction =
   291     QAction *const checkedAction =
   230         mMenuView.toolBarActionGroup()->checkedAction();
   292         mMenuViewBuilder.toolBarActionGroup()->checkedAction();
   231 
   293 
   232     if (checkedAction != NULL) {
   294     if (checkedAction != NULL) {
   233         checkedAction->setChecked(false);
   295         checkedAction->setChecked(false);
   234     }
   296     }
   235     HSMENUTEST_FUNC_EXIT("HsAppLibraryState::clearToolbarLatch");
   297     HSMENUTEST_FUNC_EXIT("HsAppLibraryState::clearToolbarLatch");
   236 }
   298 }
   237 
   299 
   238 /*!
   300 /*!
       
   301  Ovi Store Action slot
       
   302 */
       
   303 bool HsAppLibraryState::oviStoreAction()
       
   304 {
       
   305     HSMENUTEST_FUNC_ENTRY("HsAppLibraryState::oviStoreAction");
       
   306     CaEntry oviEntry;
       
   307     oviEntry.setEntryTypeName(urlTypeName());
       
   308     oviEntry.setAttribute(urlEntryKey(),
       
   309                           QString("https://store.ovi.com/applications/"));
       
   310 
       
   311     bool result = CaService::instance()->executeCommand(oviEntry);
       
   312     HSMENUTEST_FUNC_EXIT("HsAppLibraryState::oviStoreAction");
       
   313     return result;
       
   314 }
       
   315 
       
   316 /*!
   239  All apps stete entered.
   317  All apps stete entered.
   240  */
   318  */
   241 void HsAppLibraryState::allAppsStateEntered()
   319 void HsAppLibraryState::allAppsStateEntered()
   242 {
   320 {
   243     if (mMenuView.getHsMenuMode() == NormalHsMenuMode) {
   321     if (mMenuMode.getHsMenuMode() == NormalHsMenuMode) {
   244         mHistoryTransaction->setTargetState(mAllAppsState);
   322         mHistoryTransaction->setTargetState(mAllAppsState);
   245     }
   323     }
   246 }
   324 }
   247 
   325 
   248 /*!
   326 /*!
   249  All collections state entered.
   327  All collections state entered.
   250  */
   328  */
   251 void HsAppLibraryState::allCollectionsStateEntered()
   329 void HsAppLibraryState::allCollectionsStateEntered()
   252 {
   330 {
   253     if (mMenuView.getHsMenuMode() == NormalHsMenuMode) {
   331     if (mMenuMode.getHsMenuMode() == NormalHsMenuMode) {
   254         mHistoryTransaction->setTargetState(mAllCollectionsState);
   332         mHistoryTransaction->setTargetState(mAllCollectionsState);
   255     }
   333     }
   256 }
   334 }
       
   335