homescreenapp/hsapplication/src/hshomescreen.cpp
changeset 77 4b195f3bea29
parent 39 4e8ebe173323
child 92 6727c5d0afc7
equal deleted inserted replaced
61:2b1b11a301d2 77:4b195f3bea29
    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 
    56     
    57     registerServicePlugins(serviceManager);
    57     mRuntime = new HsStateMachine(this);
    58     
    58 
    59     QServiceFilter filter("com.nokia.symbian.IHomeScreenRuntime");
    59     connect(mRuntime, SIGNAL(started()), SLOT(onRuntimeStarted()));
    60     QList<QServiceInterfaceDescriptor> interfaces = serviceManager.findInterfaces(filter);
    60     connect(mRuntime, SIGNAL(stopped()), SLOT(onRuntimeStopped()));
    61 
    61     hbInstance->allMainWindows().first()->installEventFilter(this);
    62     if (interfaces.isEmpty()) {
    62 #ifdef Q_OS_SYMBIAN
    63         emit exit();
    63     mHomeScreenClientServiceProvider = new HsHomeScreenClientServiceProvider;
    64         return;
    64     mHomeScreenClientServiceProvider->setParent(this);
    65     }
    65 #endif
    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
       
    76         mHomeScreenClientServiceProvider = new HsHomeScreenClientServiceProvider;
       
    77         mHomeScreenClientServiceProvider->setParent(this);
       
    78 #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";
       
   164 
   144 
   165     QFileInfoList drives = QDir::drives();
   145     QFileInfoList drives = QDir::drives();
   166     foreach(const QString pluginPath, pluginPaths) {
   146     foreach(const QString pluginPath, pluginPaths) {
   167 #ifdef Q_OS_SYMBIAN
   147 #ifdef Q_OS_SYMBIAN
   168         //Check plugin dirs from root of different drives
   148         //Check plugin dirs from root of different drives
   179             registerServicePlugins(pluginPath, serviceManager);
   159             registerServicePlugins(pluginPath, serviceManager);
   180         }
   160         }
   181     }
   161     }
   182     HSTEST_FUNC_EXIT("HS::HsHomeScreen::registerServicePlugins()");
   162     HSTEST_FUNC_EXIT("HS::HsHomeScreen::registerServicePlugins()");
   183 }
   163 }
       
   164 
       
   165 #ifdef COVERAGE_MEASUREMENT 
       
   166 #ifndef Q_OS_SYMBIAN 
       
   167 #pragma CTC SKIP
       
   168 #endif // Q_OS_SYMBIAN
       
   169 #endif //COVERAGE_MEASUREMENT
   184 
   170 
   185 /*!
   171 /*!
   186     Recursively registers service plugins starting from given /a root
   172     Recursively registers service plugins starting from given /a root
   187     directory. All directories containing plugins are added to
   173     directory. All directories containing plugins are added to
   188     application's library paths at the same time.
   174     application's library paths at the same time.
   212             }
   198             }
   213         }
   199         }
   214     }
   200     }
   215     HSTEST_FUNC_EXIT("HS::HsHomeScreen::registerServicePlugins(const QString &)");
   201     HSTEST_FUNC_EXIT("HS::HsHomeScreen::registerServicePlugins(const QString &)");
   216 }
   202 }
       
   203 
       
   204 #ifdef COVERAGE_MEASUREMENT
       
   205 #ifndef Q_OS_SYMBIAN 
       
   206 #pragma CTC ENDSKIP
       
   207 #endif // Q_OS_SYMBIAN
       
   208 #endif //COVERAGE_MEASUREMENT