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 |
*/
|
99
|
70 |
QList<HsWidgetComponentDescriptor> HsWidgetRegistryServicePrivate::widgets()
|
87
|
71 |
{
|
99
|
72 |
QList<HsWidgetComponentDescriptor> widgets;
|
87
|
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 |
*/
|
99
|
91 |
/*
|
87
|
92 |
IHsWidgetProvider *HsWidgetRegistryServicePrivate::loadProviderFromPlugin(
|
|
93 |
const QString &pluginName)
|
|
94 |
{
|
85
|
95 |
QPluginLoader loader(pluginName);
|
|
96 |
QObject *plugin = loader.instance();
|
|
97 |
IHsWidgetProvider *provider = qobject_cast<IHsWidgetProvider *>(plugin);
|
87
|
98 |
|
85
|
99 |
if (provider) {
|
87
|
100 |
// ?
|
85
|
101 |
return provider;
|
|
102 |
}
|
|
103 |
|
|
104 |
// Don't leak memory if provider not IHsWidgetProvider
|
|
105 |
if (plugin) {
|
|
106 |
//qDebug("Widget provider load - !provider, deleting plugin.")
|
|
107 |
delete plugin;
|
|
108 |
}
|
87
|
109 |
|
85
|
110 |
// qDebug("Widget provider load failed - Not found.")
|
|
111 |
return 0;
|
|
112 |
}
|
99
|
113 |
*/
|
85
|
114 |
|
|
115 |
/*!
|
|
116 |
?Qt_style_documentation
|
|
117 |
*/
|
|
118 |
QStringList HsWidgetRegistryServicePrivate::readManifestDirectories(const QString &path)
|
|
119 |
{
|
|
120 |
QStringList widgetDirPaths;
|
|
121 |
QDir registryDir(path);
|
87
|
122 |
QStringList widgetDirs = registryDir.entryList(QDir::AllDirs);
|
|
123 |
|
|
124 |
// ?
|
|
125 |
for (int i=0; i < widgetDirs.count(); ++i) {
|
85
|
126 |
widgetDirPaths << registryDir.absoluteFilePath(widgetDirs.at(i));
|
|
127 |
}
|
|
128 |
return widgetDirPaths;
|
|
129 |
}
|
|
130 |
|
|
131 |
/*!
|
|
132 |
?Qt_style_documentation
|
|
133 |
*/
|
87
|
134 |
void HsWidgetRegistryServicePrivate::doWidgetRemove(const QString &path,
|
|
135 |
const QStringList &originalList, const QStringList ¤tList)
|
85
|
136 |
{
|
|
137 |
Q_UNUSED(path);
|
|
138 |
const int originalCount = originalList.count();
|
|
139 |
|
|
140 |
// ?
|
|
141 |
for (int i=0; i<originalCount; i++) {
|
|
142 |
QString widgetDir = originalList.at(i);
|
|
143 |
|
|
144 |
if (!currentList.contains(widgetDir)) {
|
|
145 |
// ?
|
|
146 |
QDir dir(widgetDir);
|
|
147 |
int widgetUid = dir.dirName().toUInt(0, 16);
|
|
148 |
mPublic->emitWidgetRemovedFromRegistry(widgetUid);
|
|
149 |
}
|
|
150 |
}
|
|
151 |
}
|
|
152 |
|
|
153 |
/*!
|
|
154 |
?Qt_style_documentation
|
|
155 |
*/
|
99
|
156 |
QList<HsWidgetComponentDescriptor> HsWidgetRegistryServicePrivate::readManifestFile(
|
85
|
157 |
const QString &manifestFilePath)
|
|
158 |
{
|
99
|
159 |
QList<HsWidgetComponentDescriptor> widgets;
|
85
|
160 |
QStringList filters("*.manifest");
|
|
161 |
QDir dir(manifestFilePath);
|
|
162 |
QStringList manifestDir = dir.entryList(filters, QDir::Files);
|
|
163 |
|
|
164 |
if (!manifestDir.isEmpty()) {
|
87
|
165 |
// ?
|
85
|
166 |
QString fileName = manifestDir.first();
|
93
|
167 |
HsWidgetComponentParser componentParser(dir.absoluteFilePath(fileName));
|
|
168 |
if ( !componentParser.error() ) {
|
99
|
169 |
|
|
170 |
HsWidgetComponentDescriptor widgetDescriptor = componentParser.widgetComponentDescriptor();
|
|
171 |
widgetDescriptor.library = manifestFilePath + "/" + widgetDescriptor.uri + ".dll";
|
93
|
172 |
if (widgetDescriptor.iconUri.length() > 0 ) {
|
99
|
173 |
widgetDescriptor.iconUri = manifestFilePath + "/" + widgetDescriptor.iconUri;
|
|
174 |
}
|
|
175 |
if (widgetDescriptor.previewImage.length() > 0 ) {
|
|
176 |
widgetDescriptor.previewImage = manifestFilePath + "/" + widgetDescriptor.previewImage;
|
|
177 |
}
|
|
178 |
|
93
|
179 |
int widgetUid = dir.dirName().toUInt(0, 16);
|
99
|
180 |
widgetDescriptor.uid = widgetUid;
|
|
181 |
widgets << widgetDescriptor;
|
93
|
182 |
qDebug() << "HsWidgetRegistryServicePrivate::readManifestFile - " \
|
|
183 |
"widget added: " << fileName;
|
|
184 |
}
|
85
|
185 |
}
|
|
186 |
return widgets;
|
|
187 |
}
|
|
188 |
|
|
189 |
/*!
|
|
190 |
?Qt_style_documentation
|
|
191 |
*/
|
|
192 |
void HsWidgetRegistryServicePrivate::ensureWidgetRegistryPaths()
|
|
193 |
{
|
|
194 |
/*
|
|
195 |
mFileSystemWatcher.disconnect();
|
|
196 |
QStringList pathList = mManifestDirectories.keys();
|
|
197 |
|
87
|
198 |
// ?
|
85
|
199 |
for(int i=0; i < pathList.count(); i++) {
|
|
200 |
QDir registryDir(pathList.at(i));
|
87
|
201 |
|
99
|
202 |
if(!registryDir.exists()) {
|
|
203 |
// ?
|
85
|
204 |
registryDir.mkpath(pathList.at(i));
|
|
205 |
}
|
|
206 |
}
|
|
207 |
|
|
208 |
mFileSystemWatcher.removePaths(QStringList(mManifestDirectories.keys()));
|
|
209 |
mFileSystemWatcher.addPaths(QStringList(mManifestDirectories.keys()));
|
|
210 |
connect(&mFileSystemWatcher,SIGNAL(directoryChanged(const QString&)),SLOT(directoryChanged(const QString&)));
|
|
211 |
*/
|
|
212 |
}
|
|
213 |
|
|
214 |
/*!
|
|
215 |
?Qt_style_documentation
|
|
216 |
*/
|
|
217 |
void HsWidgetRegistryServicePrivate::directoryChanged(const QString &path)
|
|
218 |
{
|
|
219 |
Q_UNUSED(path);
|
|
220 |
/*
|
87
|
221 |
int installationStatus = mInstallerObserver.value();
|
85
|
222 |
|
|
223 |
if ((installationStatus & KSASwisOperationMask) == ESASwisNone) {
|
87
|
224 |
// ?
|
85
|
225 |
QStringList originalList = mManifestDirectories.value(path);
|
|
226 |
QStringList currentList = readManifestDirectories(path);
|
|
227 |
doWidgetAdd(path, originalList, currentList);
|
|
228 |
doWidgetRemove(path, originalList, currentList);
|
|
229 |
mManifestDirectories[path] = currentList;
|
|
230 |
ensureWidgetRegistryPaths();
|
|
231 |
} else {
|
87
|
232 |
// ?
|
85
|
233 |
mFileSystemWatcher.disconnect();
|
|
234 |
connect(&mInstallerObserver,SIGNAL(valueChanged(int)),SLOT(installerStateChanged(int)));
|
|
235 |
mInstallerObserver.subscribe();
|
|
236 |
mLatestChangedDirectory = path;
|
|
237 |
}
|
87
|
238 |
*/
|
85
|
239 |
}
|
|
240 |
|
|
241 |
/*!
|
|
242 |
?Qt_style_documentation
|
|
243 |
*/
|
|
244 |
void HsWidgetRegistryServicePrivate::installerStateChanged(int newValue)
|
|
245 |
{
|
|
246 |
Q_UNUSED(newValue);
|
87
|
247 |
/*
|
85
|
248 |
if ((newValue & KSASwisOperationMask) == ESASwisNone) {
|
99
|
249 |
// ?
|
85
|
250 |
mInstallerObserver.unSubscribe();
|
|
251 |
mInstallerObserver.disconnect();
|
|
252 |
QStringList originalList = mManifestDirectories.value(mLatestChangedDirectory);
|
|
253 |
QStringList currentList = readManifestDirectories(mLatestChangedDirectory);
|
|
254 |
doWidgetAdd(mLatestChangedDirectory, originalList, currentList);
|
|
255 |
doWidgetRemove(mLatestChangedDirectory, originalList, currentList);
|
|
256 |
connect(&mFileSystemWatcher,SIGNAL(directoryChanged(const QString&)),SLOT(directoryChanged(const QString&)));
|
|
257 |
mManifestDirectories[mLatestChangedDirectory] = currentList;
|
|
258 |
ensureWidgetRegistryPaths();
|
|
259 |
}
|
87
|
260 |
*/
|
85
|
261 |
}
|
|
262 |
|
|
263 |
|
|
264 |
/*!
|
|
265 |
\class HsWidgetRegistryService
|
|
266 |
\ingroup group_hsruntimeservices
|
|
267 |
\brief Manages installed widgets information
|
|
268 |
|
87
|
269 |
Manages information on available widgets and inform observers on
|
85
|
270 |
registry modifications, i.e installing and uninstalling widgets.
|
87
|
271 |
|
85
|
272 |
*/
|
|
273 |
|
|
274 |
/*!
|
|
275 |
Constructor.
|
|
276 |
\a installationPath is the path where the widget is installed
|
|
277 |
and the \a parent is the parent object.
|
87
|
278 |
*/
|
85
|
279 |
HsWidgetRegistryService::HsWidgetRegistryService(
|
87
|
280 |
const QString &installationPath,
|
|
281 |
QObject *parent)
|
85
|
282 |
:QObject(parent),
|
87
|
283 |
mPrivate(new HsWidgetRegistryServicePrivate(installationPath, this, this))
|
85
|
284 |
{
|
87
|
285 |
|
85
|
286 |
}
|
|
287 |
|
|
288 |
/*!
|
|
289 |
Destructor.
|
87
|
290 |
*/
|
85
|
291 |
HsWidgetRegistryService::~HsWidgetRegistryService()
|
|
292 |
{
|
|
293 |
|
|
294 |
}
|
|
295 |
|
|
296 |
/*!
|
|
297 |
Fetch available widgets information
|
|
298 |
Return List of widget tokens.
|
87
|
299 |
*/
|
99
|
300 |
QList<HsWidgetComponentDescriptor> HsWidgetRegistryService::widgets()
|
85
|
301 |
{
|
87
|
302 |
return mPrivate->widgets();
|
85
|
303 |
}
|
|
304 |
|
|
305 |
/*!
|
|
306 |
\fn HsWidgetRegistryService::widgetAddedToRegistry(const QList<HsWidgetToken> &widgetTokenList);
|
|
307 |
Emitted when new widgets are added to registry. \a widgetTokenList
|
|
308 |
contains list of widget tokens.
|
87
|
309 |
*/
|
85
|
310 |
|
|
311 |
/*!
|
|
312 |
\fn HsWidgetRegistryService::widgetRemovedFromRegistry(int uid)
|
87
|
313 |
Emitted when a widget is removed from registry
|
85
|
314 |
|
87
|
315 |
*/
|
|
316 |
|
|
317 |
|
85
|
318 |
/*!
|
|
319 |
\fn HsWidgetRegistryService::posterWidgetRemovedFromRegistry(int posterWidgetId)
|
87
|
320 |
Emitted when a poster widget publisher is removed from cps
|
85
|
321 |
\a posterWidgetId Poster widget id.
|
87
|
322 |
*/
|
85
|
323 |
|
|
324 |
/*!
|
|
325 |
Emits the widgetAddedToRegistry() signal
|
|
326 |
\a widgetsAdded Identifies the added widgets.
|
87
|
327 |
*/
|
99
|
328 |
void HsWidgetRegistryService::emitWidgetAddedToRegistry(const QList<HsWidgetComponentDescriptor> &widgetsAdded)
|
85
|
329 |
{
|
|
330 |
emit widgetAddedToRegistry(widgetsAdded);
|
|
331 |
}
|
|
332 |
|
|
333 |
|
|
334 |
/*!
|
|
335 |
Emits the widgetRemovedFromRegistry() signal
|
|
336 |
\a uid HsWidget uid.
|
87
|
337 |
*/
|
85
|
338 |
void HsWidgetRegistryService::emitWidgetRemovedFromRegistry(int uid)
|
|
339 |
{
|
|
340 |
emit widgetRemovedFromRegistry(uid);
|
|
341 |
}
|