|
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: Homescreen application main class. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QStateMachine> |
|
19 #include <QDir> |
|
20 |
|
21 #include <qservicemanager.h> |
|
22 #include <qservicefilter.h> |
|
23 #include <qserviceinterfacedescriptor.h> |
|
24 |
|
25 #include <HbInstance> |
|
26 |
|
27 #include "hshomescreen.h" |
|
28 #include "hstest_global.h" |
|
29 #include "hsstatemachine.h" |
|
30 #ifdef Q_OS_SYMBIAN |
|
31 #include "hshomescreenclientserviceprovider.h" |
|
32 #endif |
|
33 QTM_USE_NAMESPACE |
|
34 |
|
35 /*! |
|
36 \class HsHomeScreen |
|
37 \ingroup group_hsapplication |
|
38 \brief Homescreen application main class. |
|
39 Manages the state machine execution. |
|
40 */ |
|
41 |
|
42 /*! |
|
43 Constructor. |
|
44 \a parent Parent object. |
|
45 */ |
|
46 HsHomeScreen::HsHomeScreen(QObject *parent) |
|
47 : QObject(parent), |
|
48 mRuntime(0) |
|
49 #ifdef Q_OS_SYMBIAN |
|
50 ,mHomeScreenClientServiceProvider(0) |
|
51 #endif |
|
52 { |
|
53 HSTEST_FUNC_ENTRY("HS::HsHomeScreen::HsHomeScreen"); |
|
54 |
|
55 registerServicePlugins(); |
|
56 |
|
57 mRuntime = new HsStateMachine(this); |
|
58 |
|
59 connect(mRuntime, SIGNAL(started()), SLOT(onRuntimeStarted())); |
|
60 connect(mRuntime, SIGNAL(stopped()), SLOT(onRuntimeStopped())); |
|
61 hbInstance->allMainWindows().first()->installEventFilter(this); |
|
62 #ifdef Q_OS_SYMBIAN |
|
63 mHomeScreenClientServiceProvider = new HsHomeScreenClientServiceProvider; |
|
64 mHomeScreenClientServiceProvider->setParent(this); |
|
65 #endif |
|
66 |
|
67 HSTEST_FUNC_EXIT("HS::HsHomeScreen::HsHomeScreen"); |
|
68 } |
|
69 |
|
70 /*! |
|
71 Destructor. |
|
72 */ |
|
73 HsHomeScreen::~HsHomeScreen() |
|
74 { |
|
75 } |
|
76 |
|
77 /*! |
|
78 \fn void HsHomeScreen::exit() |
|
79 Emitted when the home screen application needs to exit. |
|
80 */ |
|
81 |
|
82 /*! |
|
83 Starts the state machine. |
|
84 */ |
|
85 void HsHomeScreen::start() |
|
86 { |
|
87 HSTEST_FUNC_ENTRY("HS::HsHomeScreen::start"); |
|
88 mRuntime->start(); |
|
89 HSTEST_FUNC_EXIT("HS::HsHomeScreen::start"); |
|
90 } |
|
91 |
|
92 /*! |
|
93 Stops the state machine. |
|
94 */ |
|
95 void HsHomeScreen::stop() |
|
96 { |
|
97 if (mRuntime->isRunning()) { |
|
98 QEventLoop eventLoop; |
|
99 connect(mRuntime, SIGNAL(finished()), &eventLoop, SLOT(quit())); |
|
100 QMetaObject::invokeMethod(mRuntime, "event_exit", Qt::QueuedConnection); |
|
101 eventLoop.exec(); |
|
102 } |
|
103 } |
|
104 |
|
105 /*! |
|
106 \copydoc QObject::eventFilter(QObject *watched, QEvent *event) |
|
107 */ |
|
108 bool HsHomeScreen::eventFilter(QObject *watched, QEvent *event) |
|
109 { |
|
110 Q_UNUSED(watched); |
|
111 if (event->type() == QEvent::Close) { |
|
112 return true; |
|
113 } |
|
114 return false; |
|
115 } |
|
116 |
|
117 /*! |
|
118 Called after the state machine has started. |
|
119 */ |
|
120 void HsHomeScreen::onRuntimeStarted() |
|
121 { |
|
122 } |
|
123 |
|
124 /*! |
|
125 Called after the state machine has stopped. |
|
126 */ |
|
127 void HsHomeScreen::onRuntimeStopped() |
|
128 { |
|
129 emit exit(); |
|
130 } |
|
131 |
|
132 /*! |
|
133 Registers service plugins pre-installed on the device. |
|
134 */ |
|
135 void HsHomeScreen::registerServicePlugins() |
|
136 { |
|
137 HSTEST_FUNC_ENTRY("HS::HsHomeScreen::registerServicePlugins()"); |
|
138 |
|
139 QServiceManager serviceManager; |
|
140 |
|
141 QStringList pluginPaths; |
|
142 |
|
143 pluginPaths << "private/20022F35"; |
|
144 |
|
145 QFileInfoList drives = QDir::drives(); |
|
146 foreach(const QString pluginPath, pluginPaths) { |
|
147 #ifdef Q_OS_SYMBIAN |
|
148 //Check plugin dirs from root of different drives |
|
149 foreach(QFileInfo drive, drives) { |
|
150 QString driveLetter = drive.absolutePath(); |
|
151 QString path = driveLetter + pluginPath; |
|
152 if(QDir(path).exists()) { |
|
153 registerServicePlugins(path, serviceManager); |
|
154 } |
|
155 } |
|
156 #endif |
|
157 //Check plugin path relative to current dir |
|
158 if(QDir(pluginPath).exists()) { |
|
159 registerServicePlugins(pluginPath, serviceManager); |
|
160 } |
|
161 } |
|
162 HSTEST_FUNC_EXIT("HS::HsHomeScreen::registerServicePlugins()"); |
|
163 } |
|
164 |
|
165 #ifdef COVERAGE_MEASUREMENT |
|
166 #ifndef Q_OS_SYMBIAN |
|
167 #pragma CTC SKIP |
|
168 #endif // Q_OS_SYMBIAN |
|
169 #endif //COVERAGE_MEASUREMENT |
|
170 |
|
171 /*! |
|
172 Recursively registers service plugins starting from given /a root |
|
173 directory. All directories containing plugins are added to |
|
174 application's library paths at the same time. |
|
175 */ |
|
176 void HsHomeScreen::registerServicePlugins(const QString &root, QServiceManager &serviceManager) |
|
177 { |
|
178 HSTEST_FUNC_ENTRY("HS::HsHomeScreen::registerServicePlugins(const QString &)"); |
|
179 QDir dir(root); |
|
180 QFileInfoList fileInfos = dir.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot); |
|
181 |
|
182 foreach (QFileInfo fileInfo, fileInfos) { |
|
183 registerServicePlugins(fileInfo.absoluteFilePath(), serviceManager); |
|
184 } |
|
185 |
|
186 fileInfos = dir.entryInfoList(QStringList("*.xml")); |
|
187 |
|
188 if (!fileInfos.isEmpty()) { |
|
189 //Plugin dll and xml are in the same directory |
|
190 QApplication::addLibraryPath(root); |
|
191 qDebug() << QString("HS::HsHomeScreen::registerServicePlugins - Directory added to application's library paths: ") |
|
192 << root; |
|
193 foreach(QFileInfo fileInfo, fileInfos) { |
|
194 if (serviceManager.addService(fileInfo.absoluteFilePath())) { |
|
195 qDebug() << QString("HS::HsHomeScreen::registerServicePlugins - Plugin registered: ") + fileInfo.fileName(); |
|
196 } else { |
|
197 qDebug() << QString("HS::HsHomeScreen::registerServicePlugins - Plugin FAILED to register: ") + fileInfo.fileName(); |
|
198 } |
|
199 } |
|
200 } |
|
201 HSTEST_FUNC_EXIT("HS::HsHomeScreen::registerServicePlugins(const QString &)"); |
|
202 } |
|
203 |
|
204 #ifdef COVERAGE_MEASUREMENT |
|
205 #ifndef Q_OS_SYMBIAN |
|
206 #pragma CTC ENDSKIP |
|
207 #endif // Q_OS_SYMBIAN |
|
208 #endif //COVERAGE_MEASUREMENT |