|
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: Manages installed widgets information |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QDir> |
|
19 #include <QPluginLoader> |
|
20 #include <QDebug> |
|
21 |
|
22 #include "hswidgetregistryservice.h" |
|
23 #include "hswidgetregistryservice_p.h" |
|
24 #include "hswidgetprovidermanifest.h" |
|
25 #include "servicefinder.h" |
|
26 |
|
27 const char POSTERURI[] = "homescreen.nokia.com/widget/poster/"; |
|
28 const char POSTERWIDGETNAME[] = "name"; |
|
29 const char POSTERWIDGETID[] = "posterwidgetid"; |
|
30 const char PUBLISHER[] = "publisher"; |
|
31 const char TEMPLATETYPE[] = "templatetype"; |
|
32 const char CONTENTID[] = "contentid"; |
|
33 const char CONTENTTYPE[] = "contenttype"; |
|
34 |
|
35 /*! |
|
36 ?Qt_style_documentation |
|
37 */ |
|
38 HsWidgetRegistryServicePrivate::HsWidgetRegistryServicePrivate( |
|
39 const QString& installationPath, HsWidgetRegistryService* ptrToPublic, |
|
40 QObject* parent) : QObject(parent) |
|
41 { |
|
42 Q_UNUSED(ptrToPublic); |
|
43 QStringList manifestPaths; |
|
44 |
|
45 this->mInstallationPath = installationPath; |
|
46 QDir currentDir = QDir::current(); |
|
47 QString currentPath = currentDir.absolutePath(); |
|
48 |
|
49 //Check widget installation dirs from root of different drives |
|
50 QFileInfoList drives = QDir::drives(); |
|
51 |
|
52 // ? |
|
53 for(int i=0; i < drives.count(); i++) { |
|
54 QFileInfo drive = drives.at(i); |
|
55 QString driveLetter = drive.absolutePath(); |
|
56 QString path = currentPath + "/" + mInstallationPath; |
|
57 QDir registryDir(path); |
|
58 |
|
59 if(registryDir.exists()) { |
|
60 // ? |
|
61 mManifestDirectories[path] = readManifestDirectories(path); |
|
62 } |
|
63 } |
|
64 } |
|
65 |
|
66 /*! |
|
67 ?Qt_style_documentation |
|
68 */ |
|
69 HsWidgetRegistryServicePrivate::~HsWidgetRegistryServicePrivate() |
|
70 { |
|
71 |
|
72 } |
|
73 |
|
74 /*! |
|
75 ?Qt_style_documentation |
|
76 */ |
|
77 QList<HsWidgetToken> HsWidgetRegistryServicePrivate::widgets() { |
|
78 QList<HsWidgetToken> widgets; |
|
79 QMapIterator<QString, QStringList> i(mManifestDirectories); |
|
80 |
|
81 while (i.hasNext()) { |
|
82 i.next(); |
|
83 QStringList manifestFileList = i.value(); |
|
84 QDir manifestDir(i.key()); |
|
85 |
|
86 // ? |
|
87 for(int h=0; h < manifestFileList.count(); h++) { |
|
88 widgets << readManifestFile(manifestDir.absoluteFilePath(manifestFileList.at(h))); |
|
89 } |
|
90 } |
|
91 return widgets; |
|
92 } |
|
93 |
|
94 /*! |
|
95 ?Qt_style_documentation |
|
96 */ |
|
97 IHsWidgetProvider* HsWidgetRegistryServicePrivate::loadProviderFromPlugin( |
|
98 const QString& pluginName) |
|
99 { |
|
100 QPluginLoader loader(pluginName); |
|
101 QObject *plugin = loader.instance(); |
|
102 IHsWidgetProvider *provider = qobject_cast<IHsWidgetProvider *>(plugin); |
|
103 |
|
104 if (provider) { |
|
105 // ? |
|
106 return provider; |
|
107 } |
|
108 |
|
109 // Don't leak memory if provider not IHsWidgetProvider |
|
110 if (plugin) { |
|
111 //qDebug("Widget provider load - !provider, deleting plugin.") |
|
112 delete plugin; |
|
113 } |
|
114 |
|
115 // qDebug("Widget provider load failed - Not found.") |
|
116 return 0; |
|
117 } |
|
118 |
|
119 /*! |
|
120 ?Qt_style_documentation |
|
121 */ |
|
122 QStringList HsWidgetRegistryServicePrivate::readManifestDirectories(const QString &path) |
|
123 { |
|
124 QStringList widgetDirPaths; |
|
125 QDir registryDir(path); |
|
126 QStringList widgetDirs = registryDir.entryList(QDir::AllDirs); |
|
127 |
|
128 // ? |
|
129 for (int i=0; i < widgetDirs.count(); ++i) { |
|
130 widgetDirPaths << registryDir.absoluteFilePath(widgetDirs.at(i)); |
|
131 } |
|
132 return widgetDirPaths; |
|
133 } |
|
134 |
|
135 /*! |
|
136 ?Qt_style_documentation |
|
137 */ |
|
138 void HsWidgetRegistryServicePrivate::doWidgetRemove(const QString &path, |
|
139 const QStringList &originalList, const QStringList ¤tList) |
|
140 { |
|
141 Q_UNUSED(path); |
|
142 const int originalCount = originalList.count(); |
|
143 |
|
144 // ? |
|
145 for (int i=0; i<originalCount; i++) { |
|
146 QString widgetDir = originalList.at(i); |
|
147 |
|
148 if (!currentList.contains(widgetDir)) { |
|
149 // ? |
|
150 QDir dir(widgetDir); |
|
151 int widgetUid = dir.dirName().toUInt(0, 16); |
|
152 mPublic->emitWidgetRemovedFromRegistry(widgetUid); |
|
153 } |
|
154 } |
|
155 } |
|
156 |
|
157 /*! |
|
158 ?Qt_style_documentation |
|
159 */ |
|
160 QList<HsWidgetToken> HsWidgetRegistryServicePrivate::readManifestFile( |
|
161 const QString &manifestFilePath) |
|
162 { |
|
163 QList<HsWidgetToken> widgets; |
|
164 HsWidgetProviderManifest manifest; |
|
165 QStringList filters("*.manifest"); |
|
166 QDir dir(manifestFilePath); |
|
167 QStringList manifestDir = dir.entryList(filters, QDir::Files); |
|
168 |
|
169 if (!manifestDir.isEmpty()) { |
|
170 // ? |
|
171 QString fileName = manifestDir.first(); |
|
172 |
|
173 if (fileName != "hsposterwidgetprovider.manifest") { |
|
174 // Directory differs from the poster widget's directory |
|
175 // which is not supported for the time being. |
|
176 manifest.loadFromXml(dir.absoluteFilePath(fileName)); |
|
177 widgets = manifest.widgets(); |
|
178 int widgetUid = dir.dirName().toUInt(0, 16); |
|
179 |
|
180 // ? |
|
181 for (int i=0; i<widgets.count();i++) { |
|
182 widgets[i].mUid = widgetUid; |
|
183 widgets[i].mLibrary = manifestFilePath + "/" + widgets[i].mLibrary; |
|
184 if (widgets[i].mIconUri != "") { |
|
185 // ? |
|
186 widgets[i].mIconUri = manifestFilePath + "/" + widgets[i].mIconUri; |
|
187 } |
|
188 } |
|
189 |
|
190 qDebug() << "HsWidgetRegistryServicePrivate::readManifestFile - " \ |
|
191 "widget added: " << fileName; |
|
192 } |
|
193 } |
|
194 return widgets; |
|
195 } |
|
196 |
|
197 /*! |
|
198 ?Qt_style_documentation |
|
199 */ |
|
200 void HsWidgetRegistryServicePrivate::ensureWidgetRegistryPaths() |
|
201 { |
|
202 /* |
|
203 mFileSystemWatcher.disconnect(); |
|
204 QStringList pathList = mManifestDirectories.keys(); |
|
205 |
|
206 // ? |
|
207 for(int i=0; i < pathList.count(); i++) { |
|
208 QDir registryDir(pathList.at(i)); |
|
209 |
|
210 if(!registryDir.exists()) { |
|
211 // ? |
|
212 registryDir.mkpath(pathList.at(i)); |
|
213 } |
|
214 } |
|
215 |
|
216 mFileSystemWatcher.removePaths(QStringList(mManifestDirectories.keys())); |
|
217 mFileSystemWatcher.addPaths(QStringList(mManifestDirectories.keys())); |
|
218 connect(&mFileSystemWatcher,SIGNAL(directoryChanged(const QString&)),SLOT(directoryChanged(const QString&))); |
|
219 */ |
|
220 } |
|
221 |
|
222 /*! |
|
223 ?Qt_style_documentation |
|
224 */ |
|
225 void HsWidgetRegistryServicePrivate::directoryChanged(const QString &path) |
|
226 { |
|
227 Q_UNUSED(path); |
|
228 /* |
|
229 int installationStatus = mInstallerObserver.value(); |
|
230 |
|
231 if ((installationStatus & KSASwisOperationMask) == ESASwisNone) { |
|
232 // ? |
|
233 QStringList originalList = mManifestDirectories.value(path); |
|
234 QStringList currentList = readManifestDirectories(path); |
|
235 doWidgetAdd(path, originalList, currentList); |
|
236 doWidgetRemove(path, originalList, currentList); |
|
237 mManifestDirectories[path] = currentList; |
|
238 ensureWidgetRegistryPaths(); |
|
239 } else { |
|
240 // ? |
|
241 mFileSystemWatcher.disconnect(); |
|
242 connect(&mInstallerObserver,SIGNAL(valueChanged(int)),SLOT(installerStateChanged(int))); |
|
243 mInstallerObserver.subscribe(); |
|
244 mLatestChangedDirectory = path; |
|
245 } |
|
246 */ |
|
247 } |
|
248 |
|
249 /*! |
|
250 ?Qt_style_documentation |
|
251 */ |
|
252 void HsWidgetRegistryServicePrivate::installerStateChanged(int newValue) |
|
253 { |
|
254 Q_UNUSED(newValue); |
|
255 /* |
|
256 if ((newValue & KSASwisOperationMask) == ESASwisNone) { |
|
257 // ? |
|
258 mInstallerObserver.unSubscribe(); |
|
259 mInstallerObserver.disconnect(); |
|
260 QStringList originalList = mManifestDirectories.value(mLatestChangedDirectory); |
|
261 QStringList currentList = readManifestDirectories(mLatestChangedDirectory); |
|
262 doWidgetAdd(mLatestChangedDirectory, originalList, currentList); |
|
263 doWidgetRemove(mLatestChangedDirectory, originalList, currentList); |
|
264 connect(&mFileSystemWatcher,SIGNAL(directoryChanged(const QString&)),SLOT(directoryChanged(const QString&))); |
|
265 mManifestDirectories[mLatestChangedDirectory] = currentList; |
|
266 ensureWidgetRegistryPaths(); |
|
267 } |
|
268 */ |
|
269 } |
|
270 |
|
271 |
|
272 /*! |
|
273 \class HsWidgetRegistryService |
|
274 \ingroup group_hsruntimeservices |
|
275 \brief Manages installed widgets information |
|
276 |
|
277 Manages information on available widgets and inform observers on |
|
278 registry modifications, i.e installing and uninstalling widgets. |
|
279 |
|
280 */ |
|
281 |
|
282 /*! |
|
283 Constructor. |
|
284 \a installationPath is the path where the widget is installed |
|
285 and the \a parent is the parent object. |
|
286 */ |
|
287 HsWidgetRegistryService::HsWidgetRegistryService( |
|
288 const QString& installationPath, |
|
289 QObject* parent) |
|
290 :QObject(parent), |
|
291 mPrivate(new HsWidgetRegistryServicePrivate(installationPath, this, this)) |
|
292 { |
|
293 |
|
294 } |
|
295 |
|
296 /*! |
|
297 Destructor. |
|
298 */ |
|
299 HsWidgetRegistryService::~HsWidgetRegistryService() |
|
300 { |
|
301 |
|
302 } |
|
303 |
|
304 /*! |
|
305 Fetch available widgets information |
|
306 Return List of widget tokens. |
|
307 */ |
|
308 QList<HsWidgetToken> HsWidgetRegistryService::widgets() |
|
309 { |
|
310 return mPrivate->widgets(); |
|
311 } |
|
312 |
|
313 /*! |
|
314 \fn HsWidgetRegistryService::widgetAddedToRegistry(const QList<HsWidgetToken> &widgetTokenList); |
|
315 Emitted when new widgets are added to registry. \a widgetTokenList |
|
316 contains list of widget tokens. |
|
317 */ |
|
318 |
|
319 /*! |
|
320 \fn HsWidgetRegistryService::widgetRemovedFromRegistry(int uid) |
|
321 Emitted when a widget is removed from registry |
|
322 |
|
323 */ |
|
324 |
|
325 |
|
326 /*! |
|
327 \fn HsWidgetRegistryService::posterWidgetRemovedFromRegistry(int posterWidgetId) |
|
328 Emitted when a poster widget publisher is removed from cps |
|
329 \a posterWidgetId Poster widget id. |
|
330 */ |
|
331 |
|
332 /*! |
|
333 Emits the widgetAddedToRegistry() signal |
|
334 \a widgetsAdded Identifies the added widgets. |
|
335 */ |
|
336 void HsWidgetRegistryService::emitWidgetAddedToRegistry(const QList<HsWidgetToken> &widgetsAdded) |
|
337 { |
|
338 emit widgetAddedToRegistry(widgetsAdded); |
|
339 } |
|
340 |
|
341 |
|
342 /*! |
|
343 Emits the widgetRemovedFromRegistry() signal |
|
344 \a uid HsWidget uid. |
|
345 */ |
|
346 void HsWidgetRegistryService::emitWidgetRemovedFromRegistry(int uid) |
|
347 { |
|
348 emit widgetRemovedFromRegistry(uid); |
|
349 } |