homescreenapp/stateplugins/hsmenuworkerstateplugin/src/hsmenuworkerstate.cpp
changeset 92 6727c5d0afc7
parent 77 4b195f3bea29
equal deleted inserted replaced
85:35368b604b28 92:6727c5d0afc7
    27 #include "hsarrangestate.h"
    27 #include "hsarrangestate.h"
    28 #include "hspreviewhswidgetstate.h"
    28 #include "hspreviewhswidgetstate.h"
    29 #include "hsviewappsettingsstate.h"
    29 #include "hsviewappsettingsstate.h"
    30 #include "hsviewappdetailsstate.h"
    30 #include "hsviewappdetailsstate.h"
    31 #include "hsinstallationlogstate.h"
    31 #include "hsinstallationlogstate.h"
       
    32 #include "hsuinstallfailedstate.h"
    32 
    33 
    33 /*!
    34 /*!
    34  \class HsMenuWorkerState
    35  \class HsMenuWorkerState
    35  \ingroup group_hsworkerstateplugin
    36  \ingroup group_hsworkerstateplugin
    36  \brief Menu Worker State.
    37  \brief Menu Worker State.
    45 /*!
    46 /*!
    46  Constructor.
    47  Constructor.
    47  \param parent Parent state. 
    48  \param parent Parent state. 
    48  */
    49  */
    49 HsMenuWorkerState::HsMenuWorkerState(QState *parent) :
    50 HsMenuWorkerState::HsMenuWorkerState(QState *parent) :
    50     QState(parent), mInitialState(0)
    51     QState(parent)
    51 {
    52 {
    52     construct();
    53     construct();
    53 }
    54 }
    54 
    55 
    55 /*!
    56 /*!
    65  */
    66  */
    66 void HsMenuWorkerState::construct()
    67 void HsMenuWorkerState::construct()
    67 {
    68 {
    68     HSMENUTEST_FUNC_ENTRY("HsMenuWorkerState::construct");
    69     HSMENUTEST_FUNC_ENTRY("HsMenuWorkerState::construct");
    69     setObjectName("homescreen.nokia.com/state/MenuWorkerState");
    70     setObjectName("homescreen.nokia.com/state/MenuWorkerState");
       
    71     
       
    72     QState *menuWorkerParallelState = new QState(
       
    73             QState::ParallelStates, this);
       
    74     setInitialState(menuWorkerParallelState);
       
    75     
       
    76     QState *menuWorkerCommonState = new QState(menuWorkerParallelState);
       
    77     QState *menuWorkerFailedMessageState = new QState(menuWorkerParallelState);
       
    78     
    70 
    79 
    71     mInitialState = new QState(this);
    80     QState *initialCommonState = new QState(menuWorkerCommonState);
    72     setInitialState(mInitialState);
    81     menuWorkerCommonState->setInitialState(initialCommonState);
       
    82     QState *initialFailedMessageState = new QState(menuWorkerFailedMessageState);
       
    83     menuWorkerFailedMessageState->setInitialState(initialFailedMessageState);
    73 
    84 
    74     // use templated creation method - less boilerplate code
    85     // use templated creation method - less boilerplate code
    75     createChildState<HsAddToHomeScreenState> (HsMenuEvent::AddToHomeScreen);
    86     createChildState<HsAddToHomeScreenState> (
       
    87             HsMenuEvent::AddToHomeScreen, 
       
    88             menuWorkerCommonState, initialCommonState);
    76     createChildState<HsDeleteCollectionState> (
    89     createChildState<HsDeleteCollectionState> (
    77         HsMenuEvent::DeleteCollection);
    90             HsMenuEvent::DeleteCollection,
       
    91             menuWorkerCommonState, initialCommonState);
    78     createChildState<HsDeleteCollectionItemState> (
    92     createChildState<HsDeleteCollectionItemState> (
    79         HsMenuEvent::RemoveAppFromCollection);
    93             HsMenuEvent::RemoveAppFromCollection,
       
    94             menuWorkerCommonState, initialCommonState);
    80     createChildState<HsUninstallItemState> (
    95     createChildState<HsUninstallItemState> (
    81         HsMenuEvent::UninstallApplication);
    96             HsMenuEvent::UninstallApplication, 
    82     createChildState<HsArrangeState> (HsMenuEvent::ArrangeCollection);
    97             menuWorkerCommonState, initialCommonState);
    83     createChildState<HsArrangeState> (HsMenuEvent::ArrangeAllCollections);
    98     createChildState<HsArrangeState> (
       
    99             HsMenuEvent::ArrangeCollection, 
       
   100             menuWorkerCommonState, initialCommonState);
       
   101     createChildState<HsArrangeState> (
       
   102             HsMenuEvent::ArrangeAllCollections, 
       
   103             menuWorkerCommonState, initialCommonState);
    84 
   104 
    85     
   105     
    86     // create a new child state based on the template
   106     // create a new child state based on the template
    87     HsCollectionNameState *newChildState = new HsCollectionNameState(this);
   107     HsCollectionNameState *newChildState = new HsCollectionNameState(this);
    88     // create a transition to the new child state which will be triggered by
   108     // create a transition to the new child state which will be triggered by
    89     // an event with specified operation type
   109     // an event with specified operation type
    90     HsMenuEventTransition *renameCollectionTransition =
   110     HsMenuEventTransition *renameCollectionTransition =
    91         new HsMenuEventTransition(HsMenuEvent::RenameCollection,
   111         new HsMenuEventTransition(HsMenuEvent::RenameCollection,
    92                                   mInitialState, newChildState);
   112                                   initialCommonState, newChildState);
    93     mInitialState->addTransition(renameCollectionTransition);
   113     initialCommonState->addTransition(renameCollectionTransition);
    94 
   114 
    95     HsMenuEventTransition *createCollectionTransition =
   115     HsMenuEventTransition *createCollectionTransition =
    96         new HsMenuEventTransition(HsMenuEvent::CreateCollection,
   116         new HsMenuEventTransition(HsMenuEvent::CreateCollection,
    97                                   mInitialState, newChildState);
   117                                   initialCommonState, newChildState);
    98     mInitialState->addTransition(createCollectionTransition);
   118     initialCommonState->addTransition(createCollectionTransition);
    99     // set a transition to the initial state after child processing finished
   119     // set a transition to the initial state after child processing finished
   100     newChildState->addTransition(newChildState, SIGNAL(exit()), mInitialState);
   120     newChildState->addTransition(newChildState, SIGNAL(exit()), initialCommonState);
   101     connect(this, SIGNAL(reset()), newChildState, SIGNAL(exit()));
   121     connect(this, SIGNAL(reset()), newChildState, SIGNAL(exit()));
   102     
   122     
   103     HsAddAppsToCollectionState *addAppsToCollectionState =
   123     HsAddAppsToCollectionState *addAppsToCollectionState =
   104         new HsAddAppsToCollectionState(this);
   124         new HsAddAppsToCollectionState(this);
   105     // create a transition to the new child state which will be triggered by
   125     // create a transition to the new child state which will be triggered by
   106     // an event with specified operation type
   126     // an event with specified operation type
   107     HsMenuEventTransition *addAppsToCollectionTransition =
   127     HsMenuEventTransition *addAppsToCollectionTransition =
   108         new HsMenuEventTransition(HsMenuEvent::AddAppsToCollection,
   128         new HsMenuEventTransition(HsMenuEvent::AddAppsToCollection,
   109                                   mInitialState, addAppsToCollectionState);
   129                                   initialCommonState, addAppsToCollectionState);
   110     mInitialState->addTransition(addAppsToCollectionTransition);
   130     initialCommonState->addTransition(addAppsToCollectionTransition);
   111     // set a transition to the initial state after child processing finished
   131     // set a transition to the initial state after child processing finished
   112     addAppsToCollectionState->addTransition(addAppsToCollectionState,
   132     addAppsToCollectionState->addTransition(addAppsToCollectionState,
   113                                             SIGNAL(finished()), mInitialState);
   133                                             SIGNAL(finished()), initialCommonState);
   114     connect(this, SIGNAL(reset()), addAppsToCollectionState, SIGNAL(finished()));
   134     connect(this, SIGNAL(reset()), addAppsToCollectionState, SIGNAL(finished()));
   115     
   135     
   116     
   136     
   117     createChildState<HsPreviewHSWidgetState> (HsMenuEvent::PreviewHSWidget);
   137     createChildState<HsPreviewHSWidgetState> (
   118     createChildState<HsViewAppSettingsState> (HsMenuEvent::ShowAppSettings);
   138             HsMenuEvent::PreviewHSWidget, 
   119     createChildState<HsViewAppDetailsState> (HsMenuEvent::ShowAppDetails);
   139             menuWorkerCommonState, initialCommonState);
   120     createChildState<HsInstallationLogState> (HsMenuEvent::ShowInstallationLog);
   140     createChildState<HsViewAppSettingsState> (
       
   141             HsMenuEvent::ShowAppSettings, 
       
   142             menuWorkerCommonState, initialCommonState);
       
   143     createChildState<HsViewAppDetailsState> (
       
   144             HsMenuEvent::ShowAppDetails, 
       
   145             menuWorkerCommonState, initialCommonState);
       
   146     createChildState<HsInstallationLogState> (
       
   147             HsMenuEvent::ShowInstallationLog,
       
   148             menuWorkerCommonState, initialCommonState);
       
   149     createChildState<HsUninstallFailedState> (
       
   150             HsMenuEvent::UninstallationFailed, 
       
   151             menuWorkerFailedMessageState, initialFailedMessageState);
   121 
   152 
   122     HSMENUTEST_FUNC_EXIT("HsMenuWorkerState::construct");
   153     HSMENUTEST_FUNC_EXIT("HsMenuWorkerState::construct");
   123 }
   154 }
   124 
   155 
   125 /*!
   156 /*!
   126  Template method for constructing child states.
   157  Template method for constructing child states.
   127  \param operation Operation type triggering transition to the
   158  \param operation Operation type triggering transition to the
   128  newely created state.
   159  newely created state.
       
   160  \param parentState Parent state for new state.
       
   161  \param initialState Initial state.
   129  \return newely created state.
   162  \return newely created state.
   130  */
   163  */
   131 template<class T>
   164 template<class T>
   132 T *HsMenuWorkerState::createChildState(
   165 T *HsMenuWorkerState::createChildState(
   133     HsMenuEvent::OperationType operation)
   166     HsMenuEvent::OperationType operation,
       
   167     QState* parentState,
       
   168     QState* initialState)
   134 {
   169 {
   135     HSMENUTEST_FUNC_ENTRY("HsMenuWorkerState::createChildState");
   170     HSMENUTEST_FUNC_ENTRY("HsMenuWorkerState::createChildState");
       
   171     
   136     // create a new child state based on the template
   172     // create a new child state based on the template
   137     T *newChildState = new T(this);
   173     T *newChildState = new T(parentState);
       
   174     
   138     // create a transition to the new child state which will be triggered by
   175     // create a transition to the new child state which will be triggered by
   139     // an event with specified operation type
   176     // an event with specified operation type
   140     HsMenuEventTransition *newChildStateTransition =
   177     HsMenuEventTransition *newChildStateTransition =
   141         new HsMenuEventTransition(operation, mInitialState, newChildState);
   178         new HsMenuEventTransition(operation, initialState, newChildState);
   142     mInitialState->addTransition(newChildStateTransition);
   179     initialState->addTransition(newChildStateTransition);
       
   180     
   143     // set a transition to the initial state after child processing finished
   181     // set a transition to the initial state after child processing finished
   144     newChildState->addTransition(newChildState, SIGNAL(exit()), mInitialState);
   182     newChildState->addTransition(newChildState, SIGNAL(exit()), initialState);
   145     connect(this, SIGNAL(reset()), newChildState, SIGNAL(exit()));
   183     connect(this, SIGNAL(reset()), newChildState, SIGNAL(exit()));
       
   184     
   146     HSMENUTEST_FUNC_EXIT("HsMenuWorkerState::createChildState");
   185     HSMENUTEST_FUNC_EXIT("HsMenuWorkerState::createChildState");
   147 
   186 
   148     return newChildState;
   187     return newChildState;
   149 }
   188 }
       
   189