homescreenapp/hsapplication/src/hshomescreen.cpp
changeset 63 52b0f64eeb51
parent 39 4e8ebe173323
child 71 1db7cc813a4e
equal deleted inserted replaced
62:341166945d65 63:52b0f64eeb51
    24 
    24 
    25 #include <HbInstance>
    25 #include <HbInstance>
    26 
    26 
    27 #include "hshomescreen.h"
    27 #include "hshomescreen.h"
    28 #include "hstest_global.h"
    28 #include "hstest_global.h"
       
    29 #include "hsstatemachine.h"
    29 #ifdef Q_OS_SYMBIAN
    30 #ifdef Q_OS_SYMBIAN
    30 #include "hshomescreenclientserviceprovider.h"
    31 #include "hshomescreenclientserviceprovider.h"
    31 #endif
    32 #endif
    32 QTM_USE_NAMESPACE
    33 QTM_USE_NAMESPACE
    33 
    34 
    34 /*!
    35 /*!
    35     \class HsHomeScreen
    36     \class HsHomeScreen
    36     \ingroup group_hsapplication
    37     \ingroup group_hsapplication
    37     \brief Homescreen application main class.
    38     \brief Homescreen application main class.
    38     Loads a runtime from a runtime provider plugin. Manages
    39     Manages the state machine execution.
    39     the state machine execution.
       
    40 */
    40 */
    41 
    41 
    42 /*!
    42 /*!
    43     Constructor.
    43     Constructor.
    44     \a parent Parent object.
    44     \a parent Parent object.
    50     ,mHomeScreenClientServiceProvider(0)
    50     ,mHomeScreenClientServiceProvider(0)
    51 #endif
    51 #endif
    52 {
    52 {
    53     HSTEST_FUNC_ENTRY("HS::HsHomeScreen::HsHomeScreen");
    53     HSTEST_FUNC_ENTRY("HS::HsHomeScreen::HsHomeScreen");
    54 
    54 
    55     QServiceManager serviceManager;
    55     registerServicePlugins();
       
    56     
       
    57     mRuntime = new HsStateMachine(this);
    56 
    58 
    57     registerServicePlugins(serviceManager);
    59     connect(mRuntime, SIGNAL(started()), SLOT(onRuntimeStarted()));
    58     
    60     connect(mRuntime, SIGNAL(stopped()), SLOT(onRuntimeStopped()));
    59     QServiceFilter filter("com.nokia.symbian.IHomeScreenRuntime");
    61     hbInstance->allMainWindows().first()->installEventFilter(this);
    60     QList<QServiceInterfaceDescriptor> interfaces = serviceManager.findInterfaces(filter);
       
    61 
       
    62     if (interfaces.isEmpty()) {
       
    63         emit exit();
       
    64         return;
       
    65     }
       
    66 
       
    67     QObject *object = serviceManager.loadInterface(interfaces.first().interfaceName());
       
    68     mRuntime = qobject_cast<QStateMachine *>(object);
       
    69 
       
    70     if (mRuntime) {
       
    71         mRuntime->setParent(this);
       
    72         connect(mRuntime, SIGNAL(started()), SLOT(onRuntimeStarted()));
       
    73         connect(mRuntime, SIGNAL(stopped()), SLOT(onRuntimeStopped()));
       
    74         hbInstance->allMainWindows().first()->installEventFilter(this);
       
    75 #ifdef Q_OS_SYMBIAN
    62 #ifdef Q_OS_SYMBIAN
    76         mHomeScreenClientServiceProvider = new HsHomeScreenClientServiceProvider;
    63     mHomeScreenClientServiceProvider = new HsHomeScreenClientServiceProvider;
    77         mHomeScreenClientServiceProvider->setParent(this);
    64     mHomeScreenClientServiceProvider->setParent(this);
    78 #endif
    65 #endif
    79     } else {
       
    80         delete object;
       
    81         emit exit();
       
    82     }
       
    83 
    66 
    84     HSTEST_FUNC_EXIT("HS::HsHomeScreen::HsHomeScreen");
    67     HSTEST_FUNC_EXIT("HS::HsHomeScreen::HsHomeScreen");
    85 }
    68 }
    86 
    69 
    87 /*!
    70 /*!
    95     \fn void HsHomeScreen::exit()
    78     \fn void HsHomeScreen::exit()
    96     Emitted when the home screen application needs to exit.
    79     Emitted when the home screen application needs to exit.
    97 */
    80 */
    98 
    81 
    99 /*!
    82 /*!
   100     Starts the runtime.
    83     Starts the state machine.
   101 */
    84 */
   102 void HsHomeScreen::start()
    85 void HsHomeScreen::start()
   103 {
    86 {
   104     HSTEST_FUNC_ENTRY("HS::HsHomeScreen::start");
    87     HSTEST_FUNC_ENTRY("HS::HsHomeScreen::start");
   105     if (mRuntime) {
    88     mRuntime->start();
   106         mRuntime->start();
       
   107     } else {
       
   108         HSTEST_FUNC_EXIT("HS::HsHomeScreen::start, mRuntime not created, exit application");
       
   109         emit exit();
       
   110     }
       
   111     HSTEST_FUNC_EXIT("HS::HsHomeScreen::start");
    89     HSTEST_FUNC_EXIT("HS::HsHomeScreen::start");
   112 }
    90 }
   113 
    91 
   114 /*!
    92 /*!
   115     Stops the runtime.
    93     Stops the state machine.
   116 */
    94 */
   117 void HsHomeScreen::stop()
    95 void HsHomeScreen::stop()
   118 {
    96 {
   119 	if (mRuntime && mRuntime->isRunning()) {
    97 	if (mRuntime->isRunning()) {
   120         QEventLoop eventLoop;
    98         QEventLoop eventLoop;
   121         connect(mRuntime, SIGNAL(finished()), &eventLoop, SLOT(quit()));
    99         connect(mRuntime, SIGNAL(finished()), &eventLoop, SLOT(quit()));
   122         QMetaObject::invokeMethod(mRuntime, "event_exit", Qt::QueuedConnection);
   100         QMetaObject::invokeMethod(mRuntime, "event_exit", Qt::QueuedConnection);
   123         eventLoop.exec();
   101         eventLoop.exec();
   124     }
   102     }
   135     }
   113     }
   136     return false;
   114     return false;
   137 }
   115 }
   138 
   116 
   139 /*!
   117 /*!
   140     Called after the runtime has started.
   118     Called after the state machine has started.
   141 */
   119 */
   142 void HsHomeScreen::onRuntimeStarted()
   120 void HsHomeScreen::onRuntimeStarted()
   143 {
   121 {
   144 }
   122 }
   145 
   123 
   146 /*!
   124 /*!
   147     Called after the runtime has stopped.
   125     Called after the state machine has stopped.
   148 */
   126 */
   149 void HsHomeScreen::onRuntimeStopped()
   127 void HsHomeScreen::onRuntimeStopped()
   150 {
   128 {
   151     emit exit();
   129     emit exit();
   152 }
   130 }
   153 
   131 
   154 /*!
   132 /*!
   155     Registers service plugins pre-installed on the device.
   133     Registers service plugins pre-installed on the device.
   156 */
   134 */
   157 void HsHomeScreen::registerServicePlugins(QServiceManager &serviceManager)
   135 void HsHomeScreen::registerServicePlugins()
   158 {
   136 {    
   159     HSTEST_FUNC_ENTRY("HS::HsHomeScreen::registerServicePlugins()");
   137     HSTEST_FUNC_ENTRY("HS::HsHomeScreen::registerServicePlugins()");
       
   138     
       
   139     QServiceManager serviceManager;
       
   140     
   160     QStringList pluginPaths;
   141     QStringList pluginPaths;
   161     
   142     
   162     pluginPaths << "private/20022F35";    
   143     pluginPaths << "private/20022F35";    
   163     pluginPaths << "hsresources/plugins";
   144     pluginPaths << "hsresources/plugins";
   164 
   145