|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbCore module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 |
|
26 // internal |
|
27 #include "hbfeedbackplugingroup.h" |
|
28 #include "hbfeedbackmanager.h" |
|
29 #include "hbfeedbackplugin.h" |
|
30 |
|
31 // Qt related |
|
32 #include <QtDebug> |
|
33 #include <QPluginLoader> |
|
34 #include <QDir> |
|
35 |
|
36 class HbFeedbackPluginGroupPrivate |
|
37 { |
|
38 |
|
39 public: |
|
40 HbFeedbackPluginGroupPrivate(HbFeedbackManager& manager); |
|
41 ~HbFeedbackPluginGroupPrivate(); |
|
42 |
|
43 public: |
|
44 HbFeedbackManager& manager; |
|
45 QList< QPointer< HbFeedbackPlugin> > feedbackPlugins; |
|
46 }; |
|
47 |
|
48 HbFeedbackPluginGroupPrivate::HbFeedbackPluginGroupPrivate(HbFeedbackManager& manager) |
|
49 : manager(manager) |
|
50 { |
|
51 } |
|
52 |
|
53 HbFeedbackPluginGroupPrivate::~HbFeedbackPluginGroupPrivate() |
|
54 { |
|
55 } |
|
56 |
|
57 void HbFeedbackPluginGroup::removePlugins() |
|
58 { |
|
59 foreach(HbFeedbackPlugin* plugin, d->feedbackPlugins) { |
|
60 // we cannot trust that dynamically |
|
61 // loaded plugins haven't been destroyed somewhere else |
|
62 if (plugin) { |
|
63 delete plugin; |
|
64 } |
|
65 } |
|
66 |
|
67 d->feedbackPlugins.clear(); |
|
68 } |
|
69 |
|
70 /*! |
|
71 @beta |
|
72 @hbcore |
|
73 |
|
74 \class HbFeedbackPluginGroup |
|
75 |
|
76 \brief Container class that loads and manages all feedback plugins. |
|
77 |
|
78 Feedback plugins are used for implementing various feedback features. |
|
79 |
|
80 HbFeedbackPluginGroup handles feedback plugins |
|
81 \li loadPlugins() loads plugins |
|
82 \li plugins() returns the list of plugins |
|
83 \li supportedFeatures() lists supported features |
|
84 \li isFeatureSupported() returns \c true if the feature is supported |
|
85 \li enableFeature() enables feedback feature |
|
86 \li disableFeature() disables feedback feature |
|
87 \li isFeatureEnabled() returns \c true if the features is enabled |
|
88 |
|
89 See \ref arcFeedback "Feedback Manager Framework" for more information about the plugins. |
|
90 |
|
91 \sa feedbackPluginInterface |
|
92 */ |
|
93 |
|
94 |
|
95 /*! |
|
96 Constructor. |
|
97 */ |
|
98 HbFeedbackPluginGroup::HbFeedbackPluginGroup(HbFeedbackManager& manager) : |
|
99 d(new HbFeedbackPluginGroupPrivate(manager)) |
|
100 { |
|
101 } |
|
102 |
|
103 /*! |
|
104 Destructor. |
|
105 */ |
|
106 HbFeedbackPluginGroup::~HbFeedbackPluginGroup() |
|
107 { |
|
108 removePlugins(); |
|
109 delete d; |
|
110 } |
|
111 |
|
112 |
|
113 /*! |
|
114 Loads platform's featureName plugins. |
|
115 */ |
|
116 void HbFeedbackPluginGroup::loadPlugins() |
|
117 { |
|
118 QStringList pluginPathList; |
|
119 #if defined(Q_OS_SYMBIAN) |
|
120 const QString pluginRelativePath("resource/plugins/feedback/"); |
|
121 |
|
122 QFileInfoList driveInfoList = QDir::drives(); |
|
123 |
|
124 foreach (const QFileInfo &driveInfo, driveInfoList) { |
|
125 const QString drive = driveInfo.absolutePath(); |
|
126 if (drive.startsWith("z:", Qt::CaseInsensitive) || |
|
127 drive.startsWith("c:", Qt::CaseInsensitive)) { |
|
128 QString path(drive + pluginRelativePath); |
|
129 pluginPathList << path; |
|
130 } |
|
131 } |
|
132 #elif defined(Q_OS_WIN32) || defined(Q_OS_UNIX) |
|
133 pluginPathList << HB_PLUGINS_DIR"/feedback/"; |
|
134 #endif |
|
135 |
|
136 loadPlugins(pluginPathList); |
|
137 } |
|
138 |
|
139 /*! |
|
140 Loads plugins from specified directories. |
|
141 |
|
142 \param pluginPathList list of directories in which the plugins are located |
|
143 */ |
|
144 void HbFeedbackPluginGroup::loadPlugins(QStringList pluginPathList) |
|
145 { |
|
146 // remove old feedbackPlugins before loading new ones |
|
147 removePlugins(); |
|
148 QString nameFilter; |
|
149 |
|
150 foreach (const QString &path, pluginPathList) { |
|
151 QDir pluginDir(path, nameFilter, QDir::NoSort, QDir::Files | QDir::Readable); |
|
152 foreach(const QString& fileName, pluginDir.entryList(QDir::Files)) { |
|
153 QPluginLoader loader(pluginDir.absoluteFilePath(fileName)); |
|
154 QObject *plugin = loader.instance(); |
|
155 if (plugin) { |
|
156 if (HbFeedbackPlugin *feedbackPlugin = qobject_cast<HbFeedbackPlugin *>(plugin)) { |
|
157 addPlugin(feedbackPlugin); |
|
158 } |
|
159 } |
|
160 } |
|
161 } |
|
162 } |
|
163 |
|
164 //! Adds a plugin to the plugin group. |
|
165 /*! |
|
166 You don't need to call this. Plugins are loaded by the loadPlugins() method. |
|
167 |
|
168 \param feedbackPlugin the plugin to be added |
|
169 */ |
|
170 void HbFeedbackPluginGroup::addPlugin(HbFeedbackPlugin* feedbackPlugin) |
|
171 { |
|
172 if (feedbackPlugin |
|
173 && !d->feedbackPlugins.contains(feedbackPlugin)) { |
|
174 d->feedbackPlugins.append(feedbackPlugin); |
|
175 feedbackPlugin->engine().setManager(&d->manager); |
|
176 } |
|
177 } |
|
178 |
|
179 /*! |
|
180 List supported feedback features |
|
181 */ |
|
182 QStringList HbFeedbackPluginGroup::supportedFeatures() const |
|
183 { |
|
184 QStringList supportedFeatures; |
|
185 foreach(HbFeedbackPlugin *plugin, d->feedbackPlugins) { |
|
186 // sadly we cannot trust that dynamically |
|
187 // loaded plugins aren't destroyed somewhere else |
|
188 if (plugin) { |
|
189 if (!supportedFeatures.contains(plugin->featureName())) { |
|
190 supportedFeatures.append(plugin->featureName()); |
|
191 } |
|
192 } |
|
193 } |
|
194 return supportedFeatures; |
|
195 } |
|
196 |
|
197 /*! |
|
198 To check whether feedback feature is supported or not. |
|
199 |
|
200 \param featureName the name of the feature |
|
201 */ |
|
202 bool HbFeedbackPluginGroup::isFeatureSupported(QString featureName) |
|
203 { |
|
204 if (featureName.isEmpty()) { |
|
205 qWarning("HbFeedbackPluginGroup::isFeatureSupported: Attempt to give empty string \ |
|
206 as the parameter"); |
|
207 } |
|
208 |
|
209 bool supported(false); |
|
210 foreach(HbFeedbackPlugin *plugin, d->feedbackPlugins) { |
|
211 // There's a small risk, that dynamically |
|
212 // loaded plugins aren't destroyed somewhere else |
|
213 if (plugin) { |
|
214 if (plugin->featureName() == featureName) { |
|
215 supported = true; |
|
216 break; |
|
217 } |
|
218 } |
|
219 } |
|
220 return supported; |
|
221 } |
|
222 |
|
223 /*! |
|
224 To check whether \a featureName is enabled or not. |
|
225 |
|
226 \param featureName the name of the feature |
|
227 */ |
|
228 bool HbFeedbackPluginGroup::isFeatureEnabled(QString featureName) |
|
229 { |
|
230 if (featureName.isEmpty()) { |
|
231 qWarning("HbFeedbackPluginGroup::isFeatureEnabled: Attempt to give empty string \ |
|
232 as the parameter"); |
|
233 } |
|
234 |
|
235 bool enabled(false); |
|
236 foreach(HbFeedbackPlugin *plugin, d->feedbackPlugins) { |
|
237 // There's a small risk, that dynamically |
|
238 // loaded plugins aren't destroyed somewhere else |
|
239 if (plugin) { |
|
240 if (plugin->featureName() == featureName) { |
|
241 enabled = plugin->engine().receivesInteractions(); |
|
242 break; |
|
243 } |
|
244 } |
|
245 } |
|
246 return enabled; |
|
247 } |
|
248 |
|
249 /*! |
|
250 Enables feedback feature |
|
251 |
|
252 \param featureName the name of the feature |
|
253 */ |
|
254 bool HbFeedbackPluginGroup::enableFeature(QString featureName) |
|
255 { |
|
256 if (featureName.isEmpty()) { |
|
257 qWarning("HbFeedbackPluginGroup::enableFeature: Attempt to give empty string \ |
|
258 as the parameter"); |
|
259 } |
|
260 bool succeeded(false); |
|
261 foreach(HbFeedbackPlugin *plugin, d->feedbackPlugins) { |
|
262 // There's a small risk, that dynamically |
|
263 // loaded plugins aren't destroyed somewhere else |
|
264 if (plugin) { |
|
265 if (plugin->featureName() == featureName) { |
|
266 plugin->engine().setReceivesInteractions(true); |
|
267 succeeded = plugin->engine().receivesInteractions(); |
|
268 if (!succeeded) { |
|
269 break; |
|
270 } |
|
271 } |
|
272 } |
|
273 } |
|
274 return succeeded; |
|
275 } |
|
276 |
|
277 /*! |
|
278 Disables feedback feature |
|
279 |
|
280 \param featureName the name of the feature |
|
281 */ |
|
282 bool HbFeedbackPluginGroup::disableFeature(QString featureName) |
|
283 { |
|
284 if (featureName.isEmpty()) { |
|
285 qWarning("HbFeedbackPluginGroup::disableFeature: Attempt to give empty string \ |
|
286 as the parameter"); |
|
287 } |
|
288 |
|
289 bool succeeded(false); |
|
290 foreach(HbFeedbackPlugin *plugin, d->feedbackPlugins) { |
|
291 if (plugin) { |
|
292 if (plugin->featureName() == featureName) { |
|
293 plugin->engine().setReceivesInteractions(false); |
|
294 succeeded = !plugin->engine().receivesInteractions(); |
|
295 if (!succeeded) { |
|
296 break; |
|
297 } |
|
298 } |
|
299 } |
|
300 } |
|
301 return succeeded; |
|
302 } |
|
303 |
|
304 /*! |
|
305 Returns the list of plugins |
|
306 |
|
307 \return Reference to the plugin list. |
|
308 */ |
|
309 QList< QPointer< HbFeedbackPlugin> >& HbFeedbackPluginGroup::plugins() const |
|
310 { |
|
311 return d->feedbackPlugins; |
|
312 } |