screensaverapp/runtimeproviders/snsrdefaultruntimeprovider/src/snsrdefaultruntime.cpp
changeset 39 4e8ebe173323
parent 36 cdae8c6c3876
child 42 517f4fb5ec74
child 46 23b5d6a29cce
equal deleted inserted replaced
36:cdae8c6c3876 39:4e8ebe173323
     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: Default Screensaver runtime.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "snsrdefaultruntime.h"
       
    19 
       
    20 #include <QStateMachine>
       
    21 #include <QState>
       
    22 
       
    23 #include <hbmainwindow.h>
       
    24 
       
    25 #include <hsistateprovider.h>
       
    26 #include <hsstatefactory.h>
       
    27 
       
    28 /*!
       
    29     \class SnsrDefaultRuntime
       
    30     \ingroup group_snsrdefaultruntimeprovider
       
    31     \brief Default implementation of the screensaver runtime.
       
    32 */
       
    33 
       
    34 const char factoryManifestDir [] = "snsrresources/plugins/stateproviders";
       
    35 const char factoryPluginDir [] = "snsrresources/plugins/stateproviders";
       
    36 const char stateLibrary[] = "snsrdefaultstateprovider.dll";
       
    37 
       
    38 const char rootStateUri [] = "screensaver.nokia.com/state/root";
       
    39 
       
    40 /*!
       
    41     Constructs a new SnsrDefaultRuntime with parent.
       
    42 */
       
    43 SnsrDefaultRuntime::SnsrDefaultRuntime(QObject *parent) :
       
    44     HsRuntime(parent),
       
    45     mStateMachine(0),
       
    46     mWindow(0)
       
    47 {
       
    48     initializeUserInterface();
       
    49     initializeStateMachine();
       
    50 }
       
    51 
       
    52 /*!
       
    53     Destructs the class.
       
    54 */
       
    55 SnsrDefaultRuntime::~SnsrDefaultRuntime()
       
    56 {
       
    57     delete mWindow;
       
    58 }
       
    59 
       
    60 /*!
       
    61     Starts the runtime.
       
    62 */
       
    63 void SnsrDefaultRuntime::start()
       
    64 {
       
    65     mStateMachine->start();
       
    66 }
       
    67 
       
    68 /*!
       
    69     Stops the runtime.
       
    70 */
       
    71 void SnsrDefaultRuntime::stop()
       
    72 {
       
    73     mStateMachine->stop();
       
    74 }
       
    75 
       
    76 /*!
       
    77     Function initializes objects required to UI creation.
       
    78 */
       
    79 void SnsrDefaultRuntime::initializeUserInterface()
       
    80 {
       
    81     mWindow = new HbMainWindow();
       
    82     mWindow->show();
       
    83 }
       
    84 
       
    85 /*!
       
    86     Function initialize state machine.
       
    87 */
       
    88 void SnsrDefaultRuntime::initializeStateMachine()
       
    89 {
       
    90     // Ownership transfered to application.
       
    91     // State machine instance will be removed after runtime destruction.
       
    92     mStateMachine = new QStateMachine(this);
       
    93 
       
    94     // Forward signals emited by statemachine.
       
    95     connect(mStateMachine, SIGNAL(started()), SIGNAL(started()));
       
    96     connect(mStateMachine, SIGNAL(stopped()), SIGNAL(stopped()));
       
    97 
       
    98     createStates();
       
    99 }
       
   100 
       
   101 /*!
       
   102     Function creates and initializes UI states. 
       
   103 */
       
   104 void SnsrDefaultRuntime::createStates()
       
   105 {
       
   106     HsStateToken token;
       
   107     HsStateFactory factory(factoryManifestDir, factoryPluginDir);
       
   108 
       
   109     token.mLibrary = stateLibrary;
       
   110     token.mUri = rootStateUri;
       
   111     QState *snsrRootState = factory.createState(token);
       
   112     snsrRootState->setParent(mStateMachine);
       
   113     snsrRootState->setObjectName(token.mUri);
       
   114 
       
   115     mStateMachine->setInitialState(snsrRootState);
       
   116 }