|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "cpprofilemodel_p.h" |
|
19 #include <e32base.h> |
|
20 #include <QString> |
|
21 #include <MProfileEngineExtended.h> |
|
22 #include <MProfileExtended.h> |
|
23 #include <MProfileName.h> |
|
24 #include <MProfileTones.h> |
|
25 #include <MProfileSetTones.h> |
|
26 #include <MProfileExtraTones.h> |
|
27 #include <MProfileSetExtraTones.h> |
|
28 #include <MProfileExtraSettings.h> |
|
29 #include <MProfileSetExtraSettings.h> |
|
30 #include <MProfileFeedbackSettings.h> |
|
31 #include <MProfileSetFeedbackSettings.h> |
|
32 |
|
33 #include <TProfileToneSettings.h> |
|
34 #include <hwrmvibrasdkcrkeys.h> |
|
35 #include <centralrepository.h> |
|
36 |
|
37 |
|
38 QString stringFromDescriptor(const TDesC& dsp) |
|
39 { |
|
40 return QString::fromUtf16(dsp.Ptr(), dsp.Length()); |
|
41 } |
|
42 |
|
43 HBufC* descriptorFromString(const QString& str) |
|
44 { |
|
45 TPtrC ptr(reinterpret_cast<const TUint16*>(str.utf16())); |
|
46 return ptr.Alloc(); |
|
47 } |
|
48 |
|
49 CpProfileModelPrivate::CpProfileModelPrivate() |
|
50 { |
|
51 TRAPD( err, |
|
52 mEngine = CreateProfileEngineExtendedL(); |
|
53 UpdateProfileL(); |
|
54 mVibraCenRep = CRepository::NewL( KCRUidVibraCtrl ); |
|
55 ); |
|
56 mInitErrFlag = err; |
|
57 } |
|
58 |
|
59 void CpProfileModelPrivate::UpdateProfileL() |
|
60 { |
|
61 mProfileExt = mEngine->ProfileL( mEngine->ActiveProfileId() ); |
|
62 |
|
63 // General tones |
|
64 TProfileToneSettings& toneSettings = mProfileExt->ProfileSetTones().SetToneSettings(); |
|
65 mToneSettings = &toneSettings; |
|
66 |
|
67 // Feedback settings, used to get screen tone |
|
68 const MProfileFeedbackSettings& feedback = |
|
69 mProfileExt->ProfileExtraSettings().ProfileFeedbackSettings(); |
|
70 mFeedbackSettings = &feedback; |
|
71 |
|
72 // Feedback settings, used to set screen tone |
|
73 MProfileSetFeedbackSettings& setFeedback = |
|
74 mProfileExt->ProfileSetExtraSettings().ProfileSetFeedbackSettings(); |
|
75 mSetFeedbackSettings = &setFeedback; |
|
76 } |
|
77 |
|
78 CpProfileModelPrivate::~CpProfileModelPrivate() |
|
79 { |
|
80 delete mVibraCenRep; |
|
81 mVibraCenRep = NULL; |
|
82 } |
|
83 |
|
84 /* |
|
85 * Get the result of the initiation |
|
86 */ |
|
87 int CpProfileModelPrivate::initiationFlag() |
|
88 { |
|
89 return mInitErrFlag; |
|
90 } |
|
91 |
|
92 /* |
|
93 * Get profile name with its id |
|
94 */ |
|
95 QString CpProfileModelPrivate::profileName(int profileId) |
|
96 { |
|
97 if ( profileId > 2 || profileId < 0 ){ |
|
98 return ""; |
|
99 } |
|
100 |
|
101 MProfileName* name = 0; |
|
102 TRAPD( err, |
|
103 *name = mEngine->ProfileL(profileId)->ProfileName(); |
|
104 ); |
|
105 |
|
106 if (name){ |
|
107 return stringFromDescriptor( name->Name() ); |
|
108 } else { |
|
109 return ""; |
|
110 } |
|
111 |
|
112 } |
|
113 |
|
114 /* |
|
115 * Activate a profile with its id, return the operation code. |
|
116 */ |
|
117 int CpProfileModelPrivate::activateProfile(int profileId) |
|
118 { |
|
119 if ( profileId > 2 || profileId < 0 ){ |
|
120 return -1; |
|
121 } |
|
122 |
|
123 TRAPD( err, |
|
124 mEngine->SetActiveProfileL( profileId ); |
|
125 UpdateProfileL(); |
|
126 ); |
|
127 return err; |
|
128 } |
|
129 |
|
130 /* |
|
131 * Get active profile's id |
|
132 */ |
|
133 int CpProfileModelPrivate::activeProfileId() |
|
134 { |
|
135 return mEngine->ActiveProfileId(); |
|
136 } |
|
137 |
|
138 /* |
|
139 * Get path and file name of ring tone file |
|
140 */ |
|
141 QString CpProfileModelPrivate::ringTone() |
|
142 { |
|
143 return stringFromDescriptor( mProfileExt->ProfileTones().RingingTone1() ); |
|
144 } |
|
145 |
|
146 /* |
|
147 * Set path and file to ring tone |
|
148 */ |
|
149 int CpProfileModelPrivate::setRingTone(const QString& filePath) |
|
150 { |
|
151 TRAPD(err, mProfileExt->ProfileSetTones().SetRingingTone1L( *descriptorFromString(filePath) )); |
|
152 commitChange(); |
|
153 return err; |
|
154 } |
|
155 |
|
156 /* |
|
157 * Get path and file name of message tone file |
|
158 */ |
|
159 QString CpProfileModelPrivate::messageTone() |
|
160 { |
|
161 return stringFromDescriptor( mProfileExt->ProfileTones().MessageAlertTone() ); |
|
162 } |
|
163 |
|
164 /* |
|
165 * Set path and file to message tone |
|
166 */ |
|
167 int CpProfileModelPrivate::setMessageTone(const QString& filePath) |
|
168 { |
|
169 TRAPD(err, mProfileExt->ProfileSetTones().SetMessageAlertToneL( *descriptorFromString(filePath) )); |
|
170 commitChange(); |
|
171 return err; |
|
172 } |
|
173 |
|
174 /* |
|
175 * Get path and file name of email tone file |
|
176 */ |
|
177 QString CpProfileModelPrivate::emailTone() |
|
178 { |
|
179 return stringFromDescriptor( mProfileExt->ProfileExtraTones().EmailAlertTone() ); |
|
180 } |
|
181 |
|
182 /* |
|
183 * Set path and file to email tone |
|
184 */ |
|
185 int CpProfileModelPrivate::setEmailTone(const QString& filePath) |
|
186 { |
|
187 TRAPD(err, mProfileExt->ProfileSetExtraTones().SetEmailAlertToneL( *descriptorFromString(filePath) )); |
|
188 commitChange(); |
|
189 return err; |
|
190 } |
|
191 |
|
192 /* |
|
193 * Get path and file name of calendar event tone file |
|
194 */ |
|
195 QString CpProfileModelPrivate::calendarTone() |
|
196 { |
|
197 return ""; |
|
198 } |
|
199 |
|
200 /* |
|
201 * Set path and file to calendar event tone |
|
202 */ |
|
203 void CpProfileModelPrivate::setCalendarTone(const QString& filePath) |
|
204 { |
|
205 Q_UNUSED(filePath); |
|
206 } |
|
207 |
|
208 /* |
|
209 * Get path and file name of clock alarm tone file |
|
210 */ |
|
211 QString CpProfileModelPrivate::alarmTone() |
|
212 { |
|
213 return ""; |
|
214 } |
|
215 |
|
216 /* |
|
217 * Set path and file to clock alarm tone |
|
218 */ |
|
219 void CpProfileModelPrivate::setAlarmTone(const QString& filePath) |
|
220 { |
|
221 Q_UNUSED(filePath); |
|
222 } |
|
223 |
|
224 /* |
|
225 * Get the value of master volume |
|
226 */ |
|
227 int CpProfileModelPrivate::ringVolume() |
|
228 { |
|
229 return mToneSettings->iRingingVolume; |
|
230 } |
|
231 |
|
232 /* |
|
233 * Set master volume, the value should be between 1-10 |
|
234 */ |
|
235 void CpProfileModelPrivate::setRingVolume(int volume) |
|
236 { |
|
237 if (volume < 0 || volume >10) |
|
238 { |
|
239 return; |
|
240 } |
|
241 |
|
242 mToneSettings->iRingingType = EProfileRingingTypeRinging; |
|
243 mToneSettings->iRingingVolume = volume; |
|
244 commitChange(); |
|
245 } |
|
246 |
|
247 /* |
|
248 * Activate master volume to beep |
|
249 */ |
|
250 void CpProfileModelPrivate::activateBeep() |
|
251 { |
|
252 mToneSettings->iRingingType = EProfileRingingTypeBeepOnce; |
|
253 commitChange(); |
|
254 } |
|
255 |
|
256 /* |
|
257 * Get beep status in master volume |
|
258 */ |
|
259 bool CpProfileModelPrivate::isBeep() |
|
260 { |
|
261 return (EProfileRingingTypeBeepOnce == mToneSettings->iRingingType) ? true : false; |
|
262 } |
|
263 |
|
264 /* |
|
265 * Activate master volume to silent |
|
266 */ |
|
267 void CpProfileModelPrivate::activateSilent() |
|
268 { |
|
269 mToneSettings->iRingingType = EProfileRingingTypeSilent; |
|
270 commitChange(); |
|
271 } |
|
272 |
|
273 /* |
|
274 * Get silent status in master volume |
|
275 */ |
|
276 bool CpProfileModelPrivate::isSilent() |
|
277 { |
|
278 return (EProfileRingingTypeSilent == mToneSettings->iRingingType) ? true : false; |
|
279 } |
|
280 |
|
281 /* |
|
282 * Get master vibra's status |
|
283 */ |
|
284 bool CpProfileModelPrivate::vibraStatus() |
|
285 { |
|
286 return mToneSettings->iVibratingAlert; |
|
287 } |
|
288 |
|
289 /* |
|
290 * Set master vibra's status |
|
291 */ |
|
292 void CpProfileModelPrivate::setVibraStatus(bool status) |
|
293 { |
|
294 mVibraCenRep->Set(KVibraCtrlProfileVibraEnabled, status ); |
|
295 mToneSettings->iVibratingAlert = status; |
|
296 commitChange(); |
|
297 } |
|
298 |
|
299 /* |
|
300 * Get keypad' volume |
|
301 */ |
|
302 int CpProfileModelPrivate::keyVolume() |
|
303 { |
|
304 return mToneSettings->iKeypadVolume; |
|
305 } |
|
306 |
|
307 /* |
|
308 * Set keypad's volume, |
|
309 * the value of the volume should be between 0-3 |
|
310 */ |
|
311 void CpProfileModelPrivate::setKeyVolume(int volume) |
|
312 { |
|
313 if (volume < 0 || volume > 3) |
|
314 { |
|
315 return; |
|
316 } |
|
317 |
|
318 mToneSettings->iKeypadVolume = (TProfileKeypadVolume)volume; |
|
319 commitChange(); |
|
320 } |
|
321 |
|
322 /* |
|
323 * Get screen tone's volume |
|
324 */ |
|
325 int CpProfileModelPrivate::screenVolume() |
|
326 { |
|
327 return mFeedbackSettings->AudioFeedback(); |
|
328 } |
|
329 |
|
330 /* |
|
331 * Set screen tone's volume, |
|
332 * the value of the volume should be between 0-3 |
|
333 */ |
|
334 void CpProfileModelPrivate::setScreenVolume(int volume) |
|
335 { |
|
336 if (volume < 0 || volume > 3) |
|
337 { |
|
338 return; |
|
339 } |
|
340 |
|
341 mSetFeedbackSettings->SetAudioFeedback( (TProfileAudioFeedback)volume ); |
|
342 commitChange(); |
|
343 } |
|
344 |
|
345 /* |
|
346 * Get screen vibra's level |
|
347 */ |
|
348 int CpProfileModelPrivate::screenVibra() |
|
349 { |
|
350 return mFeedbackSettings->TactileFeedback(); |
|
351 } |
|
352 |
|
353 /* |
|
354 * Set screen vibra's level, |
|
355 * the value of the level should be between 0-3 |
|
356 */ |
|
357 void CpProfileModelPrivate::setScreenVibra(int volume) |
|
358 { |
|
359 if (volume < 0 || volume > 3) |
|
360 { |
|
361 return; |
|
362 } |
|
363 |
|
364 mSetFeedbackSettings->SetTactileFeedback( (TProfileTactileFeedback)volume ); |
|
365 commitChange(); |
|
366 } |
|
367 |
|
368 /* |
|
369 * Commit changes when change settings value in profile. |
|
370 */ |
|
371 int CpProfileModelPrivate::commitChange() |
|
372 { |
|
373 TRAPD( err, mEngine->CommitChangeL(*mProfileExt) ); |
|
374 return err; |
|
375 } |
|
376 |
|
377 // End of file |
|
378 |