homescreenapp/hsapplication/src/hshomescreen.cpp
changeset 36 cdae8c6c3876
parent 35 f9ce957a272c
child 39 4e8ebe173323
equal deleted inserted replaced
35:f9ce957a272c 36:cdae8c6c3876
    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 
    29 #ifdef Q_OS_SYMBIAN
       
    30 #include "hshomescreenclientserviceprovider.h"
       
    31 #endif
    30 QTM_USE_NAMESPACE
    32 QTM_USE_NAMESPACE
    31 
    33 
    32 /*!
    34 /*!
    33     \class HsHomeScreen
    35     \class HsHomeScreen
    34     \ingroup group_hsapplication
    36     \ingroup group_hsapplication
    42     \a parent Parent object.
    44     \a parent Parent object.
    43 */
    45 */
    44 HsHomeScreen::HsHomeScreen(QObject *parent)
    46 HsHomeScreen::HsHomeScreen(QObject *parent)
    45   : QObject(parent),
    47   : QObject(parent),
    46     mRuntime(0)
    48     mRuntime(0)
       
    49 #ifdef Q_OS_SYMBIAN
       
    50     ,mHomeScreenClientServiceProvider(0)
       
    51 #endif
    47 {
    52 {
    48     HSTEST_FUNC_ENTRY("HS::HsHomeScreen::HsHomeScreen");
    53     HSTEST_FUNC_ENTRY("HS::HsHomeScreen::HsHomeScreen");
    49 
    54 
    50     registerServicePlugins();
    55     QServiceManager serviceManager;
    51 
    56 
    52     QServiceManager manager;
    57     registerServicePlugins(serviceManager);
    53     QServiceFilter filter("com.nokia.homescreen.runtime.HsRuntime");
    58     
    54     QList<QServiceInterfaceDescriptor> interfaces = manager.findInterfaces(filter);
    59     QServiceFilter filter("com.nokia.symbian.IHomeScreenRuntime");
    55     QObject *interface = manager.loadInterface(interfaces.first().interfaceName());
    60     QList<QServiceInterfaceDescriptor> interfaces = serviceManager.findInterfaces(filter);
    56     mRuntime = qobject_cast<QStateMachine*>(interface);
    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 
    57     if (mRuntime) {
    70     if (mRuntime) {
    58         mRuntime->setParent(this);
    71         mRuntime->setParent(this);
    59         connect(mRuntime, SIGNAL(started()), SLOT(onRuntimeStarted()));
    72         connect(mRuntime, SIGNAL(started()), SLOT(onRuntimeStarted()));
    60         connect(mRuntime, SIGNAL(stopped()), SLOT(onRuntimeStopped()));
    73         connect(mRuntime, SIGNAL(stopped()), SLOT(onRuntimeStopped()));
    61         hbInstance->allMainWindows().at(0)->installEventFilter(this);
    74         hbInstance->allMainWindows().first()->installEventFilter(this);
       
    75 #ifdef Q_OS_SYMBIAN
       
    76         mHomeScreenClientServiceProvider = new HsHomeScreenClientServiceProvider;
       
    77         mHomeScreenClientServiceProvider->setParent(this);
       
    78 #endif
    62     } else {
    79     } else {
       
    80         delete object;
    63         emit exit();
    81         emit exit();
    64     }
    82     }
       
    83 
    65     HSTEST_FUNC_EXIT("HS::HsHomeScreen::HsHomeScreen");
    84     HSTEST_FUNC_EXIT("HS::HsHomeScreen::HsHomeScreen");
    66 }
    85 }
    67 
    86 
    68 /*!
    87 /*!
    69     Destructor.
    88     Destructor.
    96     Stops the runtime.
   115     Stops the runtime.
    97 */
   116 */
    98 void HsHomeScreen::stop()
   117 void HsHomeScreen::stop()
    99 {
   118 {
   100 	if (mRuntime && mRuntime->isRunning()) {
   119 	if (mRuntime && mRuntime->isRunning()) {
   101 		QMetaObject::invokeMethod(mRuntime, "event_exit");
   120         QEventLoop eventLoop;
   102 	}
   121         connect(mRuntime, SIGNAL(finished()), &eventLoop, SLOT(quit()));
       
   122         QMetaObject::invokeMethod(mRuntime, "event_exit", Qt::QueuedConnection);
       
   123         eventLoop.exec();
       
   124     }
   103 }
   125 }
   104 
   126 
   105 /*!
   127 /*!
   106     \copydoc QObject::eventFilter(QObject *watched, QEvent *event)
   128     \copydoc QObject::eventFilter(QObject *watched, QEvent *event)
   107 */
   129 */
   130 }
   152 }
   131 
   153 
   132 /*!
   154 /*!
   133     Registers service plugins pre-installed on the device.
   155     Registers service plugins pre-installed on the device.
   134 */
   156 */
   135 void HsHomeScreen::registerServicePlugins()
   157 void HsHomeScreen::registerServicePlugins(QServiceManager &serviceManager)
   136 {
   158 {
   137     HSTEST_FUNC_ENTRY("HS::HsHomeScreen::registerServicePlugins()");
   159     HSTEST_FUNC_ENTRY("HS::HsHomeScreen::registerServicePlugins()");
   138     QStringList pluginPaths;
   160     QStringList pluginPaths;
   139 
   161 
   140     pluginPaths << "hsresources/plugins";
   162     pluginPaths << "hsresources/plugins";
   150         //Check plugin dirs from root of different drives
   172         //Check plugin dirs from root of different drives
   151         foreach(QFileInfo drive, drives) {
   173         foreach(QFileInfo drive, drives) {
   152             QString driveLetter = drive.absolutePath();
   174             QString driveLetter = drive.absolutePath();
   153             QString path = driveLetter + pluginPath;
   175             QString path = driveLetter + pluginPath;
   154             if(QDir(path).exists()) {
   176             if(QDir(path).exists()) {
   155                 registerServicePlugins(path);
   177                 registerServicePlugins(path, serviceManager);
   156             }
   178             }
   157         }
   179         }
   158 #endif
   180 #endif
   159         //Check plugin path relative to current dir
   181         //Check plugin path relative to current dir
   160         if(QDir(pluginPath).exists()) {
   182         if(QDir(pluginPath).exists()) {
   161             registerServicePlugins(pluginPath);
   183             registerServicePlugins(pluginPath, serviceManager);
   162         }
   184         }
   163     }
   185     }
   164     HSTEST_FUNC_EXIT("HS::HsHomeScreen::registerServicePlugins()");
   186     HSTEST_FUNC_EXIT("HS::HsHomeScreen::registerServicePlugins()");
   165 }
   187 }
   166 
   188 
   167 /*!
   189 /*!
   168     Recursively registers service plugins starting from given /a root
   190     Recursively registers service plugins starting from given /a root
   169     directory. All directories containing plugins are added to
   191     directory. All directories containing plugins are added to
   170     application's library paths at the same time.
   192     application's library paths at the same time.
   171 */
   193 */
   172 void HsHomeScreen::registerServicePlugins(const QString &root)
   194 void HsHomeScreen::registerServicePlugins(const QString &root, QServiceManager &serviceManager)
   173 {
   195 {
   174     HSTEST_FUNC_ENTRY("HS::HsHomeScreen::registerServicePlugins(const QString &)");
   196     HSTEST_FUNC_ENTRY("HS::HsHomeScreen::registerServicePlugins(const QString &)");
   175     QDir dir = QDir(root);
   197     QDir dir(root);
   176     QFileInfoList fileInfos = dir.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot);
   198     QFileInfoList fileInfos = dir.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot);
   177 
   199 
   178     foreach (QFileInfo fileInfo, fileInfos) {
   200     foreach (QFileInfo fileInfo, fileInfos) {
   179         registerServicePlugins(fileInfo.absoluteFilePath());
   201         registerServicePlugins(fileInfo.absoluteFilePath(), serviceManager);
   180     }
   202     }
   181 
   203 
   182     fileInfos = dir.entryInfoList(QStringList("*.xml"));
   204     fileInfos = dir.entryInfoList(QStringList("*.xml"));
   183 
   205 
   184     if (!fileInfos.isEmpty()) {
   206     if (!fileInfos.isEmpty()) {
   185         //Plugin dll and xml are in the same directory
   207         //Plugin dll and xml are in the same directory
   186         QApplication::addLibraryPath(root);
   208         QApplication::addLibraryPath(root);
   187         qDebug() << QString("HS::HsHomeScreen::registerServicePlugins - Directory added to application's library paths: ")
   209         qDebug() << QString("HS::HsHomeScreen::registerServicePlugins - Directory added to application's library paths: ")
   188                  << root;
   210                  << root;        
   189         QServiceManager manager;
       
   190         foreach(QFileInfo fileInfo, fileInfos) {
   211         foreach(QFileInfo fileInfo, fileInfos) {
   191             manager.addService(fileInfo.absoluteFilePath());
   212             if (serviceManager.addService(fileInfo.absoluteFilePath())) {
   192             qDebug() << QString("HS::HsHomeScreen::registerServicePlugins - Plugin registered: ") + fileInfo.fileName();
   213                 qDebug() << QString("HS::HsHomeScreen::registerServicePlugins - Plugin registered: ") + fileInfo.fileName();
       
   214             } else {
       
   215                 qDebug() << QString("HS::HsHomeScreen::registerServicePlugins - Plugin FAILED to register: ") + fileInfo.fileName();
       
   216             }
   193         }
   217         }
   194     }
   218     }
   195     HSTEST_FUNC_EXIT("HS::HsHomeScreen::registerServicePlugins(const QString &)");
   219     HSTEST_FUNC_EXIT("HS::HsHomeScreen::registerServicePlugins(const QString &)");
   196 }
   220 }