|
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 "hbfeedbacksettings.h" |
|
27 |
|
28 #ifdef Q_OS_SYMBIAN |
|
29 #include <touchfeedback.h> |
|
30 #endif |
|
31 |
|
32 /*! |
|
33 @beta |
|
34 @hbfeedback |
|
35 |
|
36 \class HbFeedbackSettings |
|
37 |
|
38 \brief %Feedback Settings API for Qt application development. |
|
39 |
|
40 Application can choose to disable feedback effects for the application, for example |
|
41 phone application may want to disable vibration and sound feedback effects during a phone call. |
|
42 |
|
43 Feedback effects can also be disabled based on the type of feedback. There are currently four |
|
44 supported types of feedback: instant fire&forget feedback, continuous feedback that needs to |
|
45 be started and ended separately, hit area feedback that uses pre-registered feedback areas and |
|
46 finally tacticon feedback. |
|
47 */ |
|
48 |
|
49 class HbFeedbackSettingsPrivate |
|
50 { |
|
51 |
|
52 public: |
|
53 HbFeedbackSettingsPrivate(HbFeedbackSettings* parent); |
|
54 ~HbFeedbackSettingsPrivate(); |
|
55 void init(); |
|
56 |
|
57 public: |
|
58 bool feedbackEnabled; |
|
59 HbFeedback::Types enabledTypes; |
|
60 HbFeedbackSettings* parent; |
|
61 }; |
|
62 |
|
63 HbFeedbackSettingsPrivate::HbFeedbackSettingsPrivate(HbFeedbackSettings* parent) : parent(parent) |
|
64 { |
|
65 } |
|
66 |
|
67 HbFeedbackSettingsPrivate::~HbFeedbackSettingsPrivate() |
|
68 { |
|
69 } |
|
70 |
|
71 void HbFeedbackSettingsPrivate::init() |
|
72 { |
|
73 feedbackEnabled = true; |
|
74 #ifdef Q_OS_SYMBIAN |
|
75 MTouchFeedback* touchFeedbackPlayer = MTouchFeedback::Instance(); |
|
76 |
|
77 if (touchFeedbackPlayer) { |
|
78 feedbackEnabled = touchFeedbackPlayer->FeedbackEnabledForThisApp(); |
|
79 } |
|
80 |
|
81 #endif |
|
82 // all types are enabled by default |
|
83 enabledTypes = HbFeedback::TypeInstant |
|
84 | HbFeedback::TypeContinuous |
|
85 | HbFeedback::TypeHitArea |
|
86 | HbFeedback::TypeTacticon; |
|
87 } |
|
88 |
|
89 /*! |
|
90 Constructor. |
|
91 */ |
|
92 HbFeedbackSettings::HbFeedbackSettings(QObject* parent) : QObject(parent), |
|
93 d(new HbFeedbackSettingsPrivate(this)) |
|
94 { |
|
95 d->init(); |
|
96 } |
|
97 |
|
98 /*! |
|
99 Destructor. |
|
100 */ |
|
101 HbFeedbackSettings::~HbFeedbackSettings() |
|
102 { |
|
103 delete d; |
|
104 } |
|
105 |
|
106 /*! |
|
107 True if the device supports feedback effects. |
|
108 */ |
|
109 bool HbFeedbackSettings::feedbackSupported() |
|
110 { |
|
111 bool feedbackSupported = false; |
|
112 #ifdef Q_OS_SYMBIAN |
|
113 MTouchFeedback* touchFeedbackPlayer = MTouchFeedback::Instance(); |
|
114 |
|
115 if (touchFeedbackPlayer) { |
|
116 feedbackSupported = touchFeedbackPlayer->TouchFeedbackSupported(); |
|
117 } |
|
118 |
|
119 #else |
|
120 feedbackSupported = true; |
|
121 |
|
122 #endif |
|
123 return feedbackSupported; |
|
124 } |
|
125 |
|
126 /*! |
|
127 Enables haptic and sound feedback effects for the application. |
|
128 */ |
|
129 void HbFeedbackSettings::enableFeedback() |
|
130 { |
|
131 if (!d->feedbackEnabled) { |
|
132 #ifdef Q_OS_SYMBIAN |
|
133 MTouchFeedback* touchFeedbackPlayer = MTouchFeedback::Instance(); |
|
134 |
|
135 if (touchFeedbackPlayer) { |
|
136 touchFeedbackPlayer->SetFeedbackEnabledForThisApp(ETrue); |
|
137 } |
|
138 |
|
139 d->feedbackEnabled = touchFeedbackPlayer->FeedbackEnabledForThisApp(); |
|
140 |
|
141 #else |
|
142 d->feedbackEnabled = true; |
|
143 #endif |
|
144 emit feedbackEnabled(); |
|
145 } |
|
146 } |
|
147 |
|
148 /*! |
|
149 Disables feedback effects for the application. |
|
150 */ |
|
151 void HbFeedbackSettings::disableFeedback() |
|
152 { |
|
153 if (d->feedbackEnabled) { |
|
154 #ifdef Q_OS_SYMBIAN |
|
155 MTouchFeedback* touchFeedbackPlayer = MTouchFeedback::Instance(); |
|
156 |
|
157 if (touchFeedbackPlayer) { |
|
158 touchFeedbackPlayer->SetFeedbackEnabledForThisApp(EFalse); |
|
159 } |
|
160 |
|
161 d->feedbackEnabled = touchFeedbackPlayer->FeedbackEnabledForThisApp(); |
|
162 |
|
163 #else |
|
164 d->feedbackEnabled = false; |
|
165 #endif |
|
166 |
|
167 if (!d->feedbackEnabled) { |
|
168 emit feedbackDisabled(); |
|
169 } |
|
170 } |
|
171 } |
|
172 |
|
173 /*! |
|
174 Returns true if haptic and sound feedback effects has been enabled in the application. |
|
175 */ |
|
176 bool HbFeedbackSettings::isFeedbackEnabled() |
|
177 { |
|
178 #ifdef Q_OS_SYMBIAN |
|
179 MTouchFeedback* touchFeedbackPlayer = MTouchFeedback::Instance(); |
|
180 |
|
181 if (touchFeedbackPlayer) { |
|
182 d->feedbackEnabled = touchFeedbackPlayer->FeedbackEnabledForThisApp(); |
|
183 } |
|
184 |
|
185 #endif |
|
186 return d->feedbackEnabled; |
|
187 } |
|
188 |
|
189 /*! |
|
190 Enables given type of feedback effects in the application. |
|
191 All feedback types are enabled by default. |
|
192 Emits signal typeEnabled(HbFeedback::Type type) if |
|
193 previously disabled feedback type has been enabled. |
|
194 */ |
|
195 void HbFeedbackSettings::enableType(HbFeedback::Type type) |
|
196 { |
|
197 if (!isTypeEnabled(type)) { |
|
198 d->enabledTypes |= type; |
|
199 emit feedbackTypeEnabled(type); |
|
200 } |
|
201 } |
|
202 |
|
203 /*! |
|
204 Disables given type of feedback effect mechanism in the application. |
|
205 |
|
206 Emits signal typeDisabled(HbFeedback::Type type) if |
|
207 previously enabled feedback type has been disabled. |
|
208 |
|
209 \param type type of feedback effect |
|
210 */ |
|
211 void HbFeedbackSettings::disableType(HbFeedback::Type type) |
|
212 { |
|
213 if (isTypeEnabled(type)) { |
|
214 d->enabledTypes &= ~type; |
|
215 emit feedbackTypeDisabled(type); |
|
216 } |
|
217 } |
|
218 |
|
219 /*! |
|
220 Returns true if a particular type of feedback effect mechanism has been |
|
221 enabled for the application. |
|
222 */ |
|
223 bool HbFeedbackSettings::isTypeEnabled(HbFeedback::Type type) |
|
224 { |
|
225 return d->enabledTypes & type; |
|
226 } |
|
227 |
|
228 /*! |
|
229 True if feedback effects and the particular feedback type of feedback |
|
230 effect mechanism is enabled, false if not. |
|
231 */ |
|
232 bool HbFeedbackSettings::isFeedbackAllowed(HbFeedback::Type type) |
|
233 { |
|
234 return d->feedbackEnabled && isTypeEnabled(type); |
|
235 } |