85
|
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 |
|
|
26 |
const char POSTERURI[] = "homescreen.nokia.com/widget/poster/";
|
|
27 |
const char POSTERWIDGETNAME[] = "name";
|
|
28 |
const char POSTERWIDGETID[] = "posterwidgetid";
|
|
29 |
const char PUBLISHER[] = "publisher";
|
|
30 |
const char TEMPLATETYPE[] = "templatetype";
|
|
31 |
const char CONTENTID[] = "contentid";
|
|
32 |
const char CONTENTTYPE[] = "contenttype";
|
|
33 |
|
|
34 |
/*!
|
|
35 |
?Qt_style_documentation
|
|
36 |
*/
|
|
37 |
HsWidgetRegistryServicePrivate::HsWidgetRegistryServicePrivate(
|
87
|
38 |
const QString &installationPath, HsWidgetRegistryService *ptrToPublic,
|
|
39 |
QObject *parent) : QObject(parent)
|
85
|
40 |
{
|
|
41 |
Q_UNUSED(ptrToPublic);
|
|
42 |
QStringList manifestPaths;
|
87
|
43 |
|
85
|
44 |
this->mInstallationPath = installationPath;
|
|
45 |
QDir currentDir = QDir::current();
|
|
46 |
QString currentPath = currentDir.absolutePath();
|
87
|
47 |
|
85
|
48 |
//Check widget installation dirs from root of different drives
|
|
49 |
QFileInfoList drives = QDir::drives();
|
87
|
50 |
|
85
|
51 |
// ?
|
87
|
52 |
for (int i=0; i < drives.count(); i++) {
|
85
|
53 |
QFileInfo drive = drives.at(i);
|
|
54 |
QString driveLetter = drive.absolutePath();
|
|
55 |
QString path = currentPath + "/" + mInstallationPath;
|
|
56 |
QDir registryDir(path);
|
|
57 |
|
87
|
58 |
if (registryDir.exists()) {
|
85
|
59 |
// ?
|
|
60 |
mManifestDirectories[path] = readManifestDirectories(path);
|
|
61 |
}
|
|
62 |
}
|
|
63 |
}
|
|
64 |
|
|
65 |
/*!
|
|
66 |
?Qt_style_documentation
|
|
67 |
*/
|
|
68 |
HsWidgetRegistryServicePrivate::~HsWidgetRegistryServicePrivate()
|
|
69 |
{
|
|
70 |
|
|
71 |
}
|
|
72 |
|
|
73 |
/*!
|
|
74 |
?Qt_style_documentation
|
|
75 |
*/
|
87
|
76 |
QList<HsWidgetToken> HsWidgetRegistryServicePrivate::widgets()
|
|
77 |
{
|
|
78 |
QList<HsWidgetToken> widgets;
|
|
79 |
QMapIterator<QString, QStringList> i(mManifestDirectories);
|
85
|
80 |
|
87
|
81 |
while (i.hasNext()) {
|
85
|
82 |
i.next();
|
|
83 |
QStringList manifestFileList = i.value();
|
|
84 |
QDir manifestDir(i.key());
|
|
85 |
|
87
|
86 |
// ?
|
|
87 |
for (int h=0; h < manifestFileList.count(); h++) {
|
85
|
88 |
widgets << readManifestFile(manifestDir.absoluteFilePath(manifestFileList.at(h)));
|
|
89 |
}
|
|
90 |
}
|
|
91 |
return widgets;
|
|
92 |
}
|
|
93 |
|
|
94 |
/*!
|
|
95 |
?Qt_style_documentation
|
|
96 |
*/
|
87
|
97 |
IHsWidgetProvider *HsWidgetRegistryServicePrivate::loadProviderFromPlugin(
|
|
98 |
const QString &pluginName)
|
|
99 |
{
|
85
|
100 |
QPluginLoader loader(pluginName);
|
|
101 |
QObject *plugin = loader.instance();
|
|
102 |
IHsWidgetProvider *provider = qobject_cast<IHsWidgetProvider *>(plugin);
|
87
|
103 |
|
85
|
104 |
if (provider) {
|
87
|
105 |
// ?
|
85
|
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 |
}
|
87
|
114 |
|
85
|
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);
|
87
|
126 |
QStringList widgetDirs = registryDir.entryList(QDir::AllDirs);
|
|
127 |
|
|
128 |
// ?
|
|
129 |
for (int i=0; i < widgetDirs.count(); ++i) {
|
85
|
130 |
widgetDirPaths << registryDir.absoluteFilePath(widgetDirs.at(i));
|
|
131 |
}
|
|
132 |
return widgetDirPaths;
|
|
133 |
}
|
|
134 |
|
|
135 |
/*!
|
|
136 |
?Qt_style_documentation
|
|
137 |
*/
|
87
|
138 |
void HsWidgetRegistryServicePrivate::doWidgetRemove(const QString &path,
|
|
139 |
const QStringList &originalList, const QStringList ¤tList)
|
85
|
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()) {
|
87
|
170 |
// ?
|
85
|
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 |
|
87
|
180 |
// ?
|
|
181 |
for (int i=0; i<widgets.count(); i++) {
|
85
|
182 |
widgets[i].mUid = widgetUid;
|
|
183 |
widgets[i].mLibrary = manifestFilePath + "/" + widgets[i].mLibrary;
|
|
184 |
if (widgets[i].mIconUri != "") {
|
87
|
185 |
// ?
|
85
|
186 |
widgets[i].mIconUri = manifestFilePath + "/" + widgets[i].mIconUri;
|
|
187 |
}
|
|
188 |
}
|
|
189 |
|
|
190 |
qDebug() << "HsWidgetRegistryServicePrivate::readManifestFile - " \
|
87
|
191 |
"widget added: " << fileName;
|
85
|
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 |
|
87
|
206 |
// ?
|
85
|
207 |
for(int i=0; i < pathList.count(); i++) {
|
|
208 |
QDir registryDir(pathList.at(i));
|
87
|
209 |
|
|
210 |
if(!registryDir.exists()) {
|
|
211 |
// ?
|
85
|
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 |
/*
|
87
|
229 |
int installationStatus = mInstallerObserver.value();
|
85
|
230 |
|
|
231 |
if ((installationStatus & KSASwisOperationMask) == ESASwisNone) {
|
87
|
232 |
// ?
|
85
|
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 {
|
87
|
240 |
// ?
|
85
|
241 |
mFileSystemWatcher.disconnect();
|
|
242 |
connect(&mInstallerObserver,SIGNAL(valueChanged(int)),SLOT(installerStateChanged(int)));
|
|
243 |
mInstallerObserver.subscribe();
|
|
244 |
mLatestChangedDirectory = path;
|
|
245 |
}
|
87
|
246 |
*/
|
85
|
247 |
}
|
|
248 |
|
|
249 |
/*!
|
|
250 |
?Qt_style_documentation
|
|
251 |
*/
|
|
252 |
void HsWidgetRegistryServicePrivate::installerStateChanged(int newValue)
|
|
253 |
{
|
|
254 |
Q_UNUSED(newValue);
|
87
|
255 |
/*
|
85
|
256 |
if ((newValue & KSASwisOperationMask) == ESASwisNone) {
|
87
|
257 |
// ?
|
85
|
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 |
}
|
87
|
268 |
*/
|
85
|
269 |
}
|
|
270 |
|
|
271 |
|
|
272 |
/*!
|
|
273 |
\class HsWidgetRegistryService
|
|
274 |
\ingroup group_hsruntimeservices
|
|
275 |
\brief Manages installed widgets information
|
|
276 |
|
87
|
277 |
Manages information on available widgets and inform observers on
|
85
|
278 |
registry modifications, i.e installing and uninstalling widgets.
|
87
|
279 |
|
85
|
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.
|
87
|
286 |
*/
|
85
|
287 |
HsWidgetRegistryService::HsWidgetRegistryService(
|
87
|
288 |
const QString &installationPath,
|
|
289 |
QObject *parent)
|
85
|
290 |
:QObject(parent),
|
87
|
291 |
mPrivate(new HsWidgetRegistryServicePrivate(installationPath, this, this))
|
85
|
292 |
{
|
87
|
293 |
|
85
|
294 |
}
|
|
295 |
|
|
296 |
/*!
|
|
297 |
Destructor.
|
87
|
298 |
*/
|
85
|
299 |
HsWidgetRegistryService::~HsWidgetRegistryService()
|
|
300 |
{
|
|
301 |
|
|
302 |
}
|
|
303 |
|
|
304 |
/*!
|
|
305 |
Fetch available widgets information
|
|
306 |
Return List of widget tokens.
|
87
|
307 |
*/
|
85
|
308 |
QList<HsWidgetToken> HsWidgetRegistryService::widgets()
|
|
309 |
{
|
87
|
310 |
return mPrivate->widgets();
|
85
|
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.
|
87
|
317 |
*/
|
85
|
318 |
|
|
319 |
/*!
|
|
320 |
\fn HsWidgetRegistryService::widgetRemovedFromRegistry(int uid)
|
87
|
321 |
Emitted when a widget is removed from registry
|
85
|
322 |
|
87
|
323 |
*/
|
|
324 |
|
|
325 |
|
85
|
326 |
/*!
|
|
327 |
\fn HsWidgetRegistryService::posterWidgetRemovedFromRegistry(int posterWidgetId)
|
87
|
328 |
Emitted when a poster widget publisher is removed from cps
|
85
|
329 |
\a posterWidgetId Poster widget id.
|
87
|
330 |
*/
|
85
|
331 |
|
|
332 |
/*!
|
|
333 |
Emits the widgetAddedToRegistry() signal
|
|
334 |
\a widgetsAdded Identifies the added widgets.
|
87
|
335 |
*/
|
85
|
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.
|
87
|
345 |
*/
|
85
|
346 |
void HsWidgetRegistryService::emitWidgetRemovedFromRegistry(int uid)
|
|
347 |
{
|
|
348 |
emit widgetRemovedFromRegistry(uid);
|
|
349 |
}
|