|
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 HbFeedback 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 #include "hbfeedbackplayer.h" |
|
27 #include "hbfeedbackplayer_p.h" |
|
28 |
|
29 #include "hbinstantfeedback.h" |
|
30 #include "hbcontinuousfeedback.h" |
|
31 #include "hbtacticonfeedback.h" |
|
32 #include "hbhitareafeedback.h" |
|
33 #include "hbfeedbackplayer_stub_p.h" |
|
34 |
|
35 #ifdef FEEDBACK_TEST_EVENT |
|
36 #include "hbfeedbacktestevent_p.h" |
|
37 #endif |
|
38 |
|
39 #include <QApplication> |
|
40 |
|
41 #ifdef Q_OS_SYMBIAN |
|
42 #include "hbfeedbackplayer_symbian_p.h" |
|
43 #else |
|
44 #include "hbfeedbackplayer_stub_p.h" |
|
45 #endif |
|
46 |
|
47 HbFeedbackPlayerPrivate::HbFeedbackPlayerPrivate(HbFeedbackPlayer* parent) : parent(parent), basePlayer(0) |
|
48 { |
|
49 } |
|
50 |
|
51 HbFeedbackPlayerPrivate::~HbFeedbackPlayerPrivate() |
|
52 { |
|
53 if (basePlayer) { |
|
54 delete basePlayer; |
|
55 } |
|
56 if (feedbackSettings) { |
|
57 delete feedbackSettings; |
|
58 } |
|
59 } |
|
60 |
|
61 void HbFeedbackPlayerPrivate::init() |
|
62 { |
|
63 feedbackSettings = new HbFeedbackSettings(); |
|
64 connect(feedbackSettings, SIGNAL(feedbackDisabled()), |
|
65 this, SLOT(feedbackDisabled())); |
|
66 connect(feedbackSettings, SIGNAL(feedbackTypeDisabled(HbFeedback::Type)), |
|
67 this, SLOT(feedbackTypeDisabled(HbFeedback::Type))); |
|
68 |
|
69 basePlayer = new HbFeedbackBasePlayer(); |
|
70 } |
|
71 |
|
72 void HbFeedbackPlayerPrivate::feedbackDisabled() |
|
73 { |
|
74 if (basePlayer) { |
|
75 basePlayer->cancelContinuousFeedbacks(); |
|
76 basePlayer->removeHitAreas(); |
|
77 } |
|
78 } |
|
79 |
|
80 void HbFeedbackPlayerPrivate::feedbackTypeDisabled(HbFeedback::Type type) |
|
81 { |
|
82 if (basePlayer) { |
|
83 switch (type) { |
|
84 case HbFeedback::TypeContinuous: |
|
85 basePlayer->cancelContinuousFeedbacks(); |
|
86 break; |
|
87 |
|
88 case HbFeedback::TypeHitArea: |
|
89 basePlayer->removeHitAreas(); |
|
90 break; |
|
91 case HbFeedback::TypeInstant: |
|
92 case HbFeedback::TypeTacticon: |
|
93 default: |
|
94 break; |
|
95 } |
|
96 } |
|
97 } |
|
98 |
|
99 /*! |
|
100 @beta |
|
101 @hbfeedback |
|
102 \class HbFeedbackPlayer |
|
103 |
|
104 \brief Feedback player is used to initiate various haptic and sound feedback effects for the device. |
|
105 |
|
106 Current player supports four kinds of effects: instant feedback, continuous feedback, tacticon feedback |
|
107 and hit area feedback effects. Separate HbFeedbackSettings interface is reserved for applications wanting |
|
108 to limit or disable feedback effects emitted by the interface. See \ref feedback "Feedback Player" for |
|
109 more information on the design of the player. |
|
110 |
|
111 \sa HbInstantFeedback, HbContinuousFeedback, HbTacticonFeedback, HbHitAreaFeedback, HbFeedbackSettings. |
|
112 */ |
|
113 |
|
114 |
|
115 Q_GLOBAL_STATIC(HbFeedbackPlayer, feedbackPlayerGlobal); |
|
116 |
|
117 /*! |
|
118 Constructor. |
|
119 */ |
|
120 HbFeedbackPlayer::HbFeedbackPlayer() : d(new HbFeedbackPlayerPrivate(this)) |
|
121 { |
|
122 d->init(); |
|
123 } |
|
124 |
|
125 /*! |
|
126 Destructor. |
|
127 */ |
|
128 HbFeedbackPlayer::~HbFeedbackPlayer() |
|
129 { |
|
130 delete d; |
|
131 } |
|
132 |
|
133 /*! |
|
134 Returns the handle to the global instance. |
|
135 */ |
|
136 HbFeedbackPlayer* HbFeedbackPlayer::instance() |
|
137 { |
|
138 return feedbackPlayerGlobal(); |
|
139 } |
|
140 |
|
141 /*! |
|
142 Returns a reference to the feedback settings interface. |
|
143 */ |
|
144 HbFeedbackSettings& HbFeedbackPlayer::settings() |
|
145 { |
|
146 return *d->feedbackSettings; |
|
147 } |
|
148 |
|
149 /*! |
|
150 Triggers instant feedback effects. |
|
151 |
|
152 \param feedback instant feedback object |
|
153 \sa HbInstantFeedback |
|
154 */ |
|
155 void HbFeedbackPlayer::playInstantFeedback(const HbInstantFeedback& feedback) |
|
156 { |
|
157 if (feedback.isValid() && d->feedbackSettings->isFeedbackAllowed(HbFeedback::TypeInstant)) { |
|
158 if (d->basePlayer) { |
|
159 d->basePlayer->playInstantFeedback(feedback); |
|
160 } |
|
161 #ifdef FEEDBACK_TEST_EVENT |
|
162 HbFeedbackTestEvent te(feedback); |
|
163 qApp->sendEvent(this, &te); |
|
164 #endif |
|
165 } |
|
166 } |
|
167 |
|
168 /*! |
|
169 Triggers tacticon feedback effects. |
|
170 |
|
171 \param feedback tacticon feedback object |
|
172 \sa HbTacticonFeedback |
|
173 |
|
174 \deprecated HbFeedbackPlayer::playTacticonFeedback(const HbTacticonFeedback&) |
|
175 is deprecated. Please use HbInstantFeedback instead. |
|
176 |
|
177 \sa HbInstantFeedback |
|
178 */ |
|
179 void HbFeedbackPlayer::playTacticonFeedback(const HbTacticonFeedback& feedback) |
|
180 { |
|
181 if (feedback.isValid() && d->feedbackSettings->isFeedbackAllowed(HbFeedback::TypeTacticon)) { |
|
182 if (d->basePlayer) { |
|
183 d->basePlayer->playTacticonFeedback(feedback); |
|
184 #ifdef FEEDBACK_TEST_EVENT |
|
185 HbFeedbackTestEvent te(feedback); |
|
186 qApp->sendEvent(this, &te); |
|
187 #endif |
|
188 } |
|
189 } |
|
190 } |
|
191 |
|
192 /*! |
|
193 Starts a continuous feedback effect. |
|
194 |
|
195 \param feedback continuous feedback object |
|
196 \return identifier The identifier for the started effect. |
|
197 |
|
198 \sa HbContinuousFeedback |
|
199 */ |
|
200 int HbFeedbackPlayer::startContinuousFeedback(const HbContinuousFeedback& feedback) |
|
201 { |
|
202 int identifier(-1); |
|
203 if (feedback.isValid() && d->feedbackSettings->isFeedbackAllowed(HbFeedback::TypeContinuous)) { |
|
204 if (d->basePlayer) { |
|
205 identifier = d->basePlayer->startContinuousFeedback(feedback); |
|
206 #ifdef FEEDBACK_TEST_EVENT |
|
207 HbFeedbackTestEvent te(feedback, HbFeedbackTestEvent::Start, identifier); |
|
208 qApp->sendEvent(this, &te); |
|
209 #endif |
|
210 } |
|
211 } else if (!feedback.window()) { |
|
212 qWarning("HbFeedbackPlayer::startContinuousFeedback: no window defined for the feedback."); |
|
213 |
|
214 } |
|
215 |
|
216 return identifier; |
|
217 } |
|
218 |
|
219 /*! |
|
220 Updates an ongoing continuous feedback effect. |
|
221 |
|
222 \param identifier The identifier for the ongoing effect. |
|
223 \param feedback continuous feedback object |
|
224 |
|
225 \sa HbContinuousFeedback |
|
226 */ |
|
227 void HbFeedbackPlayer::updateContinuousFeedback(int identifier, const HbContinuousFeedback& feedback) |
|
228 { |
|
229 if (feedback.isValid() && d->feedbackSettings->isFeedbackAllowed(HbFeedback::TypeContinuous)) { |
|
230 if (d->basePlayer) { |
|
231 d->basePlayer->updateContinuousFeedback(identifier, feedback); |
|
232 #ifdef FEEDBACK_TEST_EVENT |
|
233 HbFeedbackTestEvent te(feedback, HbFeedbackTestEvent::Update, identifier); |
|
234 qApp->sendEvent(this, &te); |
|
235 #endif |
|
236 } |
|
237 |
|
238 } else if (!feedback.window()) { |
|
239 qWarning("HbFeedbackPlayer::updateContinuousFeedback: no window defined for the feedback."); |
|
240 } |
|
241 } |
|
242 |
|
243 /*! |
|
244 Cancels an ongoing continuous feedback effect. |
|
245 |
|
246 \param identifier The identifier for the ongoing effect. |
|
247 */ |
|
248 void HbFeedbackPlayer::cancelContinuousFeedback(int identifier) |
|
249 { |
|
250 if (d->basePlayer) { |
|
251 #ifdef FEEDBACK_TEST_EVENT |
|
252 if (d->basePlayer->continuousFeedbackOngoing(identifier)) { |
|
253 HbContinuousFeedback feedback; |
|
254 HbFeedbackTestEvent te(feedback, HbFeedbackTestEvent::Stop, identifier); |
|
255 qApp->sendEvent(this, &te); |
|
256 } |
|
257 #endif |
|
258 d->basePlayer->cancelContinuousFeedback(identifier); |
|
259 } |
|
260 } |
|
261 |
|
262 /*! |
|
263 Cancels all ongoing continuous feedback effects. |
|
264 */ |
|
265 void HbFeedbackPlayer::cancelContinuousFeedbacks() |
|
266 { |
|
267 if (d->basePlayer) { |
|
268 d->basePlayer->cancelContinuousFeedbacks(); |
|
269 } |
|
270 } |
|
271 |
|
272 /*! |
|
273 Checks if the given continuous feedback effect is currently running. |
|
274 |
|
275 \param identifier The identifier for the ongoing effect. |
|
276 |
|
277 \return true, if the effect is ongoing. |
|
278 */ |
|
279 bool HbFeedbackPlayer::continuousFeedbackOngoing(int identifier) |
|
280 { |
|
281 bool feedbackOngoing(false); |
|
282 if (d->basePlayer) { |
|
283 feedbackOngoing = d->basePlayer->continuousFeedbackOngoing(identifier); |
|
284 } |
|
285 return feedbackOngoing; |
|
286 } |
|
287 |
|
288 /*! |
|
289 Inserts a hit area to the specified window. |
|
290 |
|
291 \param feedback hit area feedback object |
|
292 \return The identifier for the inserted hit area. |
|
293 \sa HbHitAreaFeedback |
|
294 |
|
295 \deprecated HbFeedbackPlayer::insertHitArea(const HbHitAreaFeedback&) |
|
296 is deprecated. Please use HbInstantFeedback instead. |
|
297 |
|
298 \sa HbInstantFeedback |
|
299 */ |
|
300 int HbFeedbackPlayer::insertHitArea(const HbHitAreaFeedback& feedback) |
|
301 { |
|
302 int identifier(-1); |
|
303 |
|
304 if (feedback.isValid() && d->feedbackSettings->isFeedbackAllowed(HbFeedback::TypeHitArea)) { |
|
305 if (d->basePlayer) { |
|
306 identifier = d->basePlayer->insertHitArea(feedback); |
|
307 #ifdef FEEDBACK_TEST_EVENT |
|
308 HbFeedbackTestEvent te(feedback, HbFeedbackTestEvent::Start, identifier); |
|
309 qApp->sendEvent(this, &te); |
|
310 #endif |
|
311 } |
|
312 } else if (!feedback.isLocated()) { |
|
313 qWarning("HbFeedbackPlayer::insertHitArea: Hit area missing required parameters parent window and/or rectangle."); |
|
314 } |
|
315 |
|
316 return identifier; |
|
317 } |
|
318 |
|
319 /*! |
|
320 Update the specified hit area. |
|
321 |
|
322 \param identifier Identifier for the hit area. |
|
323 \param feedback hit area feedback object |
|
324 \sa HbHitAreaFeedback |
|
325 |
|
326 \deprecated HbFeedbackPlayer::updateHitArea(int, const HbHitAreaFeedback&) |
|
327 is deprecated. Please use HbInstantFeedback instead. |
|
328 |
|
329 \sa HbInstantFeedback |
|
330 */ |
|
331 void HbFeedbackPlayer::updateHitArea(int identifier, const HbHitAreaFeedback& feedback) |
|
332 { |
|
333 if (feedback.isValid() && d->feedbackSettings->isFeedbackAllowed(HbFeedback::TypeHitArea)) { |
|
334 if (d->basePlayer) { |
|
335 d->basePlayer->updateHitArea(identifier, feedback); |
|
336 #ifdef FEEDBACK_TEST_EVENT |
|
337 HbFeedbackTestEvent te(feedback, HbFeedbackTestEvent::Update, identifier); |
|
338 qApp->sendEvent(this, &te); |
|
339 #endif |
|
340 } |
|
341 } else if (!feedback.isLocated()) { |
|
342 qWarning("HbFeedbackPlayer::updateHitArea: Hit area missing required parameters parent window and/or rectangle."); |
|
343 } |
|
344 } |
|
345 |
|
346 /*! |
|
347 Remove the specified hit area. |
|
348 \param identifier The identifer for the hit area to be removed. |
|
349 \sa HbHitAreaFeedback |
|
350 |
|
351 \deprecated HbFeedbackPlayer::removeHitArea(int) |
|
352 is deprecated. Please use HbInstantFeedback instead. |
|
353 |
|
354 \sa HbInstantFeedback |
|
355 */ |
|
356 void HbFeedbackPlayer::removeHitArea(int identifier) |
|
357 { |
|
358 if (d->basePlayer) { |
|
359 d->basePlayer->removeHitArea(identifier); |
|
360 #ifdef FEEDBACK_TEST_EVENT |
|
361 HbHitAreaFeedback feedback; |
|
362 HbFeedbackTestEvent te(feedback, HbFeedbackTestEvent::Stop, identifier); |
|
363 qApp->sendEvent(this, &te); |
|
364 #endif |
|
365 } |
|
366 } |
|
367 |
|
368 /*! |
|
369 Remove all registered hit areas. |
|
370 |
|
371 \deprecated HbFeedbackPlayer::removeHitAreas() |
|
372 is deprecated. Please use HbInstantFeedback instead. |
|
373 |
|
374 \sa HbInstantFeedback |
|
375 */ |
|
376 void HbFeedbackPlayer::removeHitAreas() |
|
377 { |
|
378 if (d->basePlayer) { |
|
379 d->basePlayer->removeHitAreas(); |
|
380 } |
|
381 } |
|
382 |
|
383 /*! |
|
384 Check if the specified hit area still exists. |
|
385 |
|
386 \param identifier The identifier for the hit area. |
|
387 \return True, if the hit area exists. |
|
388 |
|
389 \deprecated HbFeedbackPlayer::hitAreaExists(int) |
|
390 is deprecated. Please use HbInstantFeedback instead. |
|
391 |
|
392 \sa HbInstantFeedback |
|
393 */ |
|
394 bool HbFeedbackPlayer::hitAreaExists(int identifier) |
|
395 { |
|
396 bool hitAreaExists = false; |
|
397 |
|
398 if (d->feedbackSettings->isFeedbackAllowed(HbFeedback::TypeHitArea)) { |
|
399 if (d->basePlayer) { |
|
400 hitAreaExists = d->basePlayer->hitAreaExists(identifier); |
|
401 } |
|
402 } |
|
403 |
|
404 return hitAreaExists; |
|
405 } |
|
406 |