runtimeproviders/ftudefaultruntimeprovider/src/ftudefaultruntime.cpp
changeset 0 c464cd7e2753
child 2 66c26770985f
equal deleted inserted replaced
-1:000000000000 0:c464cd7e2753
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of the FTU default runtime.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ftudefaultruntime.h"
       
    20 #include "ftutest_global.h"
       
    21 #include "ftucontentservice.h"
       
    22 
       
    23 #include "ftustateprovider.h"
       
    24 
       
    25 #include <QStateMachine>
       
    26 #include <QState>
       
    27 #include <QFinalState>
       
    28 #include <QDebug>
       
    29 
       
    30 #include <hbmainwindow.h>
       
    31 
       
    32 
       
    33 
       
    34 // plugin factory const
       
    35 
       
    36 // states
       
    37 const char wizardMenuStateUri []        = "ftu.nokia.com/state/wizardmenustate";
       
    38 const char wizardLoaderStateUri []      = "ftu.nokia.com/state/wizardloaderstate";
       
    39 const char wizardActivatedStateUri []   = "ftu.nokia.com/state/wizardactivatedstate";
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // FtuDefaultRuntime::FtuDefaultRuntime
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 FtuDefaultRuntime::FtuDefaultRuntime( QObject* aParent)
       
    46     : 
       
    47     QStateMachine(aParent),
       
    48     mFtuContentService(0),
       
    49     mWindow(0)    
       
    50 {
       
    51     createContentServiceParts();
       
    52     createGuiServiceParts();
       
    53     initializeRuntimeServices();
       
    54     createStates();
       
    55     assignServices();
       
    56 }
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // FtuDefaultRuntime::~FtuDefaultRuntime()
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 FtuDefaultRuntime::~FtuDefaultRuntime()
       
    63 {
       
    64     delete mWindow;
       
    65     delete mFtuContentService;
       
    66 }
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // FtuDefaultRuntime::handleStateMachineStarted()
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 void FtuDefaultRuntime::handleStateMachineStarted()
       
    73 {
       
    74     
       
    75 }
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // FtuDefaultRuntime::handleStateMachineStopped()
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 void FtuDefaultRuntime::handleStateMachineStopped()
       
    82 {
       
    83     emit stopped();
       
    84 }
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 //createContentServiceParts() - implementation
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 void FtuDefaultRuntime::createContentServiceParts()
       
    91 {
       
    92     mFtuContentService = new FtuContentService(this);
       
    93 }
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // FtuDefaultRuntime::createGuiServiceParts()
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 void FtuDefaultRuntime::createGuiServiceParts()
       
   100 {
       
   101     mWindow = new HbMainWindow();
       
   102     mWindow->show();
       
   103 }
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // FtuDefaultRuntime::createStates()
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 void FtuDefaultRuntime::createStates()
       
   110 {    
       
   111     
       
   112     FtuStateProvider stateProvider;
       
   113     
       
   114     QFinalState* finalState = new QFinalState();
       
   115     this->addState(finalState);
       
   116     
       
   117     // parallel state activates all children states
       
   118     QState* parallel = new QState(QState::ParallelStates);
       
   119     this->addState(parallel);
       
   120     parallel->addTransition(this, SIGNAL(stopStateMachine()), finalState);
       
   121     
       
   122     // root GUI state
       
   123     QState* guiRootState = new QState(parallel);
       
   124     
       
   125     // root FTU state
       
   126     QState* ftuRootState = new QState(guiRootState);
       
   127     
       
   128     // create state based on token
       
   129     QState* wizardMenuState = stateProvider.createState(wizardMenuStateUri);
       
   130     // set state specific data
       
   131     wizardMenuState->setParent(ftuRootState);
       
   132     wizardMenuState->setObjectName(wizardMenuStateUri);
       
   133     wizardMenuState->setProperty(FTU_SERVICES_REGISTRATION_KEY, 
       
   134                                  QList<QVariant>() << FTU_CONTENT_SERVICE_KEY);
       
   135     
       
   136     connect(mFtuContentService, SIGNAL(wizardAdded(int)), wizardMenuState, 
       
   137             SLOT(addWizardToListModel(int)));
       
   138     
       
   139     QState *wizardLoadingState = stateProvider.createState(wizardLoaderStateUri);
       
   140     wizardLoadingState->setParent(parallel);
       
   141     wizardLoadingState->setObjectName(wizardLoaderStateUri);
       
   142     wizardLoadingState->setProperty(FTU_SERVICES_REGISTRATION_KEY, 
       
   143             QList<QVariant>() << FTU_CONTENT_SERVICE_KEY);
       
   144     
       
   145     // Create activated state
       
   146 
       
   147     
       
   148     QState* wizardActivatedState = stateProvider.createState(wizardActivatedStateUri);
       
   149     wizardActivatedState->setParent(ftuRootState);
       
   150     wizardActivatedState->setObjectName(wizardActivatedStateUri);
       
   151     wizardActivatedState->setProperty(FTU_SERVICES_REGISTRATION_KEY, 
       
   152             QList<QVariant>() << FTU_CONTENT_SERVICE_KEY);
       
   153     
       
   154     
       
   155     // Setup state transitions menu state <-> activated state
       
   156     // From menu to activated
       
   157     wizardMenuState->addTransition(wizardMenuState, SIGNAL(wizardSelected()),
       
   158                                    wizardActivatedState);
       
   159     
       
   160     // From activated back to menu
       
   161     wizardActivatedState->addTransition(wizardActivatedState, 
       
   162                                         SIGNAL(backEventTriggered()), 
       
   163                                         wizardMenuState);
       
   164     
       
   165     // set initial state for statemachine
       
   166     ftuRootState->setInitialState(wizardMenuState);
       
   167     guiRootState->setInitialState(ftuRootState);
       
   168     this->setInitialState(parallel);
       
   169 
       
   170     connect(this, SIGNAL(started()), SLOT(handleStateMachineStarted()));
       
   171     connect(this, SIGNAL(stopped()), SLOT(handleStateMachineStopped()));
       
   172     connect(this, SIGNAL(finished()), SLOT(handleStateMachineStopped()));
       
   173    
       
   174 }
       
   175 
       
   176 // ---------------------------------------------------------------------------
       
   177 // FtuDefaultRuntime::assignServices()
       
   178 // ---------------------------------------------------------------------------
       
   179 //
       
   180 void FtuDefaultRuntime::assignServices()
       
   181 {
       
   182     QList<QState*> children = this->findChildren<QState*>();
       
   183     foreach (QState* state, children)
       
   184     {
       
   185         QList<QVariant> services = state->property(FTU_SERVICES_REGISTRATION_KEY).toList();
       
   186 
       
   187         foreach (const QVariant& service, services)
       
   188         {           
       
   189             QString name = service.toString();
       
   190             qDebug() << "Assign service:" << name << "\n to " << state->objectName();
       
   191             if (name == FTU_CONTENT_SERVICE_KEY) 
       
   192             {
       
   193                 state->setProperty(name.toAscii().data(), qVariantFromValue(mFtuContentService));
       
   194             }
       
   195             else 
       
   196             {
       
   197                 qWarning() << "WARNING: Service " << name << " is unknown";
       
   198             }
       
   199         }
       
   200     }
       
   201 }
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 //void initializeRuntimeServices() - implementation
       
   205 // ---------------------------------------------------------------------------
       
   206 //
       
   207 void FtuDefaultRuntime::initializeRuntimeServices()
       
   208 {
       
   209     mServices[ FTU_CONTENT_SERVICE_KEY ] = mFtuContentService;     
       
   210 }