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