|
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 "hbfeedbackmanager.h" |
|
28 #include "hbfeedbackplugingroup.h" |
|
29 #include "hbfeedbackengine.h" |
|
30 #include "hbinstantinteractionevent_p.h" |
|
31 #include "hbcontinuousinteractionevent_p.h" |
|
32 #include "hbwidget.h" |
|
33 |
|
34 // Qt related |
|
35 #include <QtDebug> |
|
36 #include <QList> |
|
37 #include <QCoreApplication> |
|
38 |
|
39 static int instantRunningIndex; |
|
40 static int continuousRunningIndex; |
|
41 |
|
42 /*! |
|
43 @beta |
|
44 @hbcore |
|
45 |
|
46 \class HbFeedbackManager |
|
47 |
|
48 \brief Feedback manager forwards interaction information from the widgets to feedback engine plugins. |
|
49 Feedback engine plugins decide what kind of feedback effects will be played. Widgets don't use |
|
50 HbFeedbackManager directly but through HbWidgetFeedback convenience class. |
|
51 */ |
|
52 |
|
53 Q_GLOBAL_STATIC(HbFeedbackManager, feedbackManagerGlobal); |
|
54 |
|
55 class HbFeedbackManagerPrivate : public QObject |
|
56 { |
|
57 |
|
58 public: |
|
59 HbFeedbackManagerPrivate(); |
|
60 ~HbFeedbackManagerPrivate(); |
|
61 public: |
|
62 HbFeedbackPluginGroup* pluginGroup; |
|
63 QList <HbFeedbackEngine*> engines; |
|
64 }; |
|
65 |
|
66 HbFeedbackManagerPrivate::HbFeedbackManagerPrivate() |
|
67 { |
|
68 } |
|
69 |
|
70 |
|
71 HbFeedbackManagerPrivate::~HbFeedbackManagerPrivate() |
|
72 { |
|
73 delete pluginGroup; |
|
74 engines.clear(); |
|
75 } |
|
76 |
|
77 void removePlugins() { |
|
78 HbFeedbackManager* manager = HbFeedbackManager::instance(); |
|
79 if (manager) { |
|
80 manager->plugins().removePlugins(); |
|
81 } |
|
82 } |
|
83 |
|
84 /*! |
|
85 Constructor. |
|
86 */ |
|
87 HbFeedbackManager::HbFeedbackManager(QObject *parent) : QObject(parent), |
|
88 d(new HbFeedbackManagerPrivate) |
|
89 { |
|
90 d->pluginGroup = new HbFeedbackPluginGroup(*this); |
|
91 d->pluginGroup->loadPlugins(); |
|
92 instantRunningIndex = Hb::InstantUser; |
|
93 continuousRunningIndex = Hb::ContinuousUser; |
|
94 // delete the plugins before the application and widgets are destroyed |
|
95 qAddPostRoutine(removePlugins); |
|
96 } |
|
97 |
|
98 /*! |
|
99 Destructor. |
|
100 */ |
|
101 HbFeedbackManager::~HbFeedbackManager() |
|
102 { |
|
103 delete d; |
|
104 } |
|
105 |
|
106 /*! |
|
107 Returns feedback manager singleton object responsible for initiating feedback effects. |
|
108 |
|
109 \return HbFeedbackManager returns feedback manager singleton object |
|
110 */ |
|
111 HbFeedbackManager* HbFeedbackManager::instance() |
|
112 { |
|
113 return feedbackManagerGlobal(); |
|
114 } |
|
115 |
|
116 /*! |
|
117 Mediates interaction triggers from widgets to all active feedback engine plugins. |
|
118 |
|
119 \param widget the widget being interacted with |
|
120 \param interaction the interaction |
|
121 \param modifiers extra specifiers to the interaction |
|
122 */ |
|
123 void HbFeedbackManager::triggered(const HbWidget *widget, Hb::InstantInteraction interaction, Hb::InteractionModifiers modifiers) |
|
124 { |
|
125 if (widget) { |
|
126 if (!widget->testAttribute(Hb::InteractionDisabled)) { |
|
127 HbInstantInteractionEvent event(widget, interaction, modifiers); |
|
128 foreach (HbFeedbackEngine* engine, d->engines) { |
|
129 QCoreApplication::sendEvent(engine, &event); |
|
130 } |
|
131 } |
|
132 } else { |
|
133 qWarning("HbFeedbackManager::triggered: Attempt to report an interaction trigger with null widget pointer"); |
|
134 } |
|
135 } |
|
136 |
|
137 /*! |
|
138 Mediates continuous interaction triggers to all active feedback plugins. |
|
139 |
|
140 \param widget the widget being interacted with |
|
141 \param interaction the continuous interaction in progress |
|
142 \param delta the direction and distance of the continuous interaction |
|
143 */ |
|
144 void HbFeedbackManager::continuousTriggered(const HbWidget *widget, Hb::ContinuousInteraction interaction, QPointF delta) |
|
145 { |
|
146 if (widget) { |
|
147 if (!widget->testAttribute(Hb::InteractionDisabled)) { |
|
148 HbContinuousInteractionEvent event(HbContinuousInteractionEvent::ContinuousInteraction, widget, interaction, delta); |
|
149 foreach (HbFeedbackEngine* engine, d->engines) { |
|
150 QCoreApplication::sendEvent(engine, &event); |
|
151 } |
|
152 } |
|
153 } else { |
|
154 qWarning("HbFeedbackManager::continuousTriggered: Attempt to stop a continuous interaction trigger with null widget pointer"); |
|
155 } |
|
156 } |
|
157 |
|
158 /*! |
|
159 Mediates a "continuous interaction stop" triggers to all active feedback engine plugins. |
|
160 This methods is needed for knowing when to stop continuous feedback effects started by |
|
161 the continuous interaction. |
|
162 |
|
163 \param widget the widget being interacted with |
|
164 \param interaction the continuous interaction in progress |
|
165 */ |
|
166 void HbFeedbackManager::continuousStopped(const HbWidget *widget, Hb::ContinuousInteraction interaction) |
|
167 { |
|
168 if (widget) { |
|
169 if (!widget->testAttribute(Hb::InteractionDisabled)) { |
|
170 HbContinuousInteractionEvent event(HbContinuousInteractionEvent::ContinuousInteractionStop, widget, interaction); |
|
171 foreach (HbFeedbackEngine* engine, d->engines) { |
|
172 QCoreApplication::sendEvent(engine, &event); |
|
173 } |
|
174 } |
|
175 } else { |
|
176 qWarning("HbFeedbackManager::continuousStopped: Attempt to stop a c trigger with \ |
|
177 null widget pointer"); |
|
178 } |
|
179 } |
|
180 |
|
181 /*! |
|
182 Registers and returns a unique value (between Hb::InstantUser and Hb::InstantMaxUser) for custom |
|
183 interactions that cannot be covered with standard ones defined in namepace Hb. Returns -1 if all |
|
184 custom interactions have been reserved. |
|
185 */ |
|
186 int HbFeedbackManager::registerInstantInteraction() |
|
187 { |
|
188 if (instantRunningIndex < Hb::InstantMaxUser) { |
|
189 instantRunningIndex++; |
|
190 return instantRunningIndex; |
|
191 } |
|
192 else { |
|
193 return -1; |
|
194 } |
|
195 } |
|
196 |
|
197 /*! |
|
198 Registers and returns an unique value (between Hb::ContinuousUser and Hb::ContinuousMaxUser) for custom |
|
199 continuous interactions that cannot be covered with standard ones defined in namepace Hb. Returns -1 if |
|
200 all custom interactions have been reserved. |
|
201 */ |
|
202 int HbFeedbackManager::registerContinuousInteraction() |
|
203 { |
|
204 if (continuousRunningIndex < Hb::ContinuousMaxUser) { |
|
205 continuousRunningIndex++; |
|
206 return continuousRunningIndex; |
|
207 } |
|
208 else { |
|
209 return -1; |
|
210 } |
|
211 } |
|
212 |
|
213 /*! |
|
214 Adds or removes HbFeedbackEngine from the list of feedback engines that receive |
|
215 interaction events from the feedback manager. |
|
216 |
|
217 \param engine the feedback engine to be added or removed |
|
218 \param enabled the flag indicating whether the feedback engine is to be added or removed |
|
219 */ |
|
220 |
|
221 void HbFeedbackManager::setReceivesInteractions(HbFeedbackEngine* engine, bool enabled) |
|
222 { |
|
223 if (engine) { |
|
224 if (enabled) { |
|
225 if (!d->engines.contains(engine)) { |
|
226 d->engines.append(engine); |
|
227 } |
|
228 } else { |
|
229 int index = d->engines.indexOf(engine); |
|
230 if (index != -1) { |
|
231 d->engines.removeAt(index); |
|
232 } |
|
233 } |
|
234 } else { |
|
235 if (enabled) { |
|
236 qWarning("HbFeedbackManager::setReceivesInteractions: Attempt to register engine by passing a null pointer"); |
|
237 } else { |
|
238 qWarning("HbFeedbackManager::setReceivesInteractions: Attempt to unregister engine using a null pointer"); |
|
239 } |
|
240 } |
|
241 } |
|
242 |
|
243 /*! |
|
244 Returns true if HbFeedbackEngine has already been registered to the manager. |
|
245 |
|
246 \param engine the feedback engine |
|
247 */ |
|
248 bool HbFeedbackManager::receivesInteractions(HbFeedbackEngine* engine) |
|
249 { |
|
250 bool contains(false); |
|
251 if (engine) { |
|
252 if (d->engines.contains(engine)) { |
|
253 contains = true; |
|
254 } |
|
255 } |
|
256 return contains; |
|
257 } |
|
258 |
|
259 /*! |
|
260 Returns the group of feedback engine plugins. |
|
261 |
|
262 \sa HbFeedbackPluginGroup |
|
263 */ |
|
264 HbFeedbackPluginGroup& HbFeedbackManager::plugins() |
|
265 { |
|
266 return *d->pluginGroup; |
|
267 } |
|
268 |