searchui/runtimeproviders/searchruntimeprovider/src/searchruntime.cpp
changeset 0 ccd0fd43f247
child 2 208a4ba3894c
equal deleted inserted replaced
-1:000000000000 0:ccd0fd43f247
       
     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 SEARCH default runtime.
       
    15  *
       
    16  */
       
    17 
       
    18 #include "searchruntime.h"
       
    19 #include "Search_global.h"
       
    20 #include "hsstatefactory.h"
       
    21 
       
    22 #include <qstatemachine.h>
       
    23 #include <qstate.h>
       
    24 #include <qfinalstate.h>
       
    25 #include <qdebug.h>
       
    26 
       
    27 #include <hbmainwindow.h>
       
    28 
       
    29 // plugin factory const
       
    30 const char factoryManifestDir[] = "searchresources/plugins/stateproviders";
       
    31 const char factoryPluginDir[] = "searchresources/plugins/stateproviders";
       
    32 const char stateLibrary[] = "searchstateprovider.dll";
       
    33 
       
    34 // states
       
    35 const char wizardProgressiveStateUri[] =
       
    36         "search.nokia.com/state/wizardprogressivestate";
       
    37 const char wizardSettingStateUri[] =
       
    38         "search.nokia.com/state/wizardsettingstate";
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // searchRuntime::SearchRuntime
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 SearchRuntime::SearchRuntime(QObject* aParent) :
       
    45     HsRuntime(aParent), mStateMachine(0), mWindow(0)
       
    46     {
       
    47     mStateMachine = new QStateMachine(this);
       
    48     createGuiServiceParts();
       
    49     createStates();
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // SearchRuntime::~SearchRuntime()
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 SearchRuntime::~SearchRuntime()
       
    57     {
       
    58     delete mWindow;
       
    59     delete mStateMachine;
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // SearchRuntime::start()
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 void SearchRuntime::start()
       
    67     {
       
    68     mStateMachine->start();
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // SearchRuntime::stop()
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 void SearchRuntime::stop()
       
    76     {
       
    77     mStateMachine->stop();
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // SearchRuntime::handleStateMachineStarted()
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 void SearchRuntime::handleStateMachineStarted()
       
    85     {
       
    86     emit started();
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // SearchRuntime::handleStateMachineStopped()
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 void SearchRuntime::handleStateMachineStopped()
       
    94     {
       
    95     emit stopped();
       
    96     }
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // SearchRuntime::createGuiServiceParts()
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 void SearchRuntime::createGuiServiceParts()
       
   103     {
       
   104     mWindow = new HbMainWindow();
       
   105     mWindow->show();
       
   106     }
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 // SearchRuntime::createStates()
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 void SearchRuntime::createStates()
       
   113     {
       
   114     HsStateFactory factory(factoryManifestDir, factoryPluginDir);
       
   115     HsStateToken token;
       
   116 
       
   117     QFinalState* finalState = new QFinalState();
       
   118     mStateMachine->addState(finalState);
       
   119 
       
   120     // parallel state activates all children states
       
   121     QState* parallel = new QState(QState::ParallelStates);
       
   122     mStateMachine->addState(parallel);
       
   123     parallel->addTransition(this, SIGNAL(stopStateMachine()), finalState);
       
   124 
       
   125     // root GUI state
       
   126     QState* guiRootState = new QState(parallel);
       
   127 
       
   128     QState* searchRootState = new QState(guiRootState);
       
   129 
       
   130     // create state based on token
       
   131     token.mLibrary = stateLibrary;
       
   132     token.mUri = wizardProgressiveStateUri;
       
   133     QState* wizardProgressiveState = factory.createState(token);
       
   134     // set state specific data
       
   135     wizardProgressiveState->setParent(searchRootState);
       
   136     wizardProgressiveState->setObjectName(token.mUri);
       
   137     token.mUri = wizardSettingStateUri;
       
   138 
       
   139     QState* wizardSettingState = factory.createState(token);
       
   140     wizardSettingState->setParent(searchRootState);
       
   141     wizardSettingState->setObjectName(token.mUri);
       
   142 
       
   143     wizardProgressiveState->addTransition(wizardProgressiveState,
       
   144             SIGNAL(settingsState()), wizardSettingState);
       
   145 
       
   146     // From activated back to menu
       
   147     wizardSettingState->addTransition(wizardSettingState,
       
   148             SIGNAL(backEventTriggered()), wizardProgressiveState);
       
   149     
       
   150     connect(wizardSettingState, SIGNAL(clickstatus(bool)),
       
   151                 wizardProgressiveState, SLOT(settingsaction(bool)));
       
   152 
       
   153     connect(wizardSettingState, SIGNAL(publishSelectedCategory(int,bool)),
       
   154             wizardProgressiveState, SLOT(getSettingCategory(int,bool)));
       
   155 
       
   156     connect(wizardSettingState, SIGNAL(customizeGoButton(bool)),
       
   157             wizardProgressiveState, SLOT(_customizeGoButton(bool)));
       
   158 
       
   159     // set initial state for statemachine
       
   160     searchRootState->setInitialState(wizardProgressiveState);
       
   161     guiRootState->setInitialState(searchRootState);
       
   162     mStateMachine->setInitialState(parallel);
       
   163 
       
   164     connect(mStateMachine, SIGNAL(started()),
       
   165             SLOT(handleStateMachineStarted()));
       
   166     connect(mStateMachine, SIGNAL(stopped()),
       
   167             SLOT(handleStateMachineStopped()));
       
   168     connect(mStateMachine, SIGNAL(finished()),
       
   169             SLOT(handleStateMachineStopped()));
       
   170 
       
   171     }