|
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 "cpprofilesettingform.h" |
|
19 #include "cppersonalizationentryitemdata.h" |
|
20 #include <QStringList> |
|
21 #include <hbdataformmodel.h> |
|
22 #include <hbabstractviewitem.h> |
|
23 #include <cpitemdatahelper.h> |
|
24 #include <cpprofilemodel.h> |
|
25 #include <hbslider.h> |
|
26 |
|
27 #include <QFileInfo> |
|
28 #include <QFileIconProvider> |
|
29 #include <QAbstractItemModel> |
|
30 #include <QModelIndex> |
|
31 #include <QMap> |
|
32 |
|
33 #include <xqsettingsmanager.h> |
|
34 #include <ProfileEngineInternalCRKeys.h> |
|
35 |
|
36 CpProfileSettingForm::CpProfileSettingForm() |
|
37 : mModel(0), mItemDataHelper(new CpItemDataHelper( this )), |
|
38 mProfileModel(new CpProfileModel()), mFileIconProvider(new QFileIconProvider), |
|
39 mGeneralPage(0),mMeetingPage(0),mCurrentPage( 0 ), mSettingManager(0) |
|
40 { |
|
41 this->setHeading(hbTrId("txt_cp_button_advanced_settings")); |
|
42 this->setDescription(hbTrId("txt_cp_info_select_tones_that_play_when_you_select")); |
|
43 |
|
44 initModel(); |
|
45 } |
|
46 |
|
47 CpProfileSettingForm::~CpProfileSettingForm() |
|
48 { |
|
49 delete mModel; |
|
50 delete mProfileModel; |
|
51 delete mFileIconProvider; |
|
52 delete mSettingManager; |
|
53 } |
|
54 |
|
55 void CpProfileSettingForm::initModel() |
|
56 { |
|
57 mModel = new HbDataFormModel(); |
|
58 |
|
59 QString generalString( mProfileModel->profileName( EProfileWrapperGeneralId ) ); |
|
60 if( generalString.isEmpty() ) { |
|
61 qDebug( "warning: general profile name is empty"); |
|
62 generalString = hbTrId("txt_cp_list_general"); |
|
63 } |
|
64 QString meetingString( mProfileModel->profileName( EProfileWrapperMeetingId ) ); |
|
65 if( meetingString.isEmpty() ) { |
|
66 qDebug( "warning: meeting profile name is empty"); |
|
67 meetingString = hbTrId("txt_cp_list_meeting"); |
|
68 } |
|
69 |
|
70 mSettingManager = new XQSettingsManager(); |
|
71 |
|
72 XQCentralRepositorySettingsKey key(KCRUidProfileEngine.iUid,KProEngSilenceMode); |
|
73 |
|
74 QVariant silenceMode = mSettingManager->readItemValue(key,XQSettingsManager::TypeInt); |
|
75 |
|
76 mSettingManager->startMonitoring(key,XQSettingsManager::TypeInt); |
|
77 connect(mSettingManager, SIGNAL(valueChanged (XQSettingsKey, QVariant)), |
|
78 this, SLOT(settingValueChanged(XQSettingsKey, QVariant))); |
|
79 |
|
80 mGeneralPage = mModel->appendDataFormPage( generalString ); |
|
81 initProfileItems(EProfileWrapperGeneralId,mGeneralPage); |
|
82 |
|
83 //initGeneralTonesGroup(); |
|
84 |
|
85 //initGeneralVibraGroup(); |
|
86 |
|
87 mMeetingPage = mModel->appendDataFormPage( meetingString ); |
|
88 initProfileItems(EProfileWrapperMeetingId,mMeetingPage); |
|
89 //initMeetingTonesGroup(); |
|
90 //initMeetingVibraGroup(); |
|
91 setModel(mModel); |
|
92 settingValueChanged(key,silenceMode); |
|
93 } |
|
94 |
|
95 void CpProfileSettingForm::initProfileItems(int profileId,HbDataFormModelItem *parent) |
|
96 { |
|
97 CpProfileSettings profileSettings; |
|
98 mProfileModel->profileSettings( profileId, profileSettings ); |
|
99 |
|
100 QHash<int,HbDataFormModelItem*> modelItems; |
|
101 |
|
102 //ring tone item |
|
103 QFileInfo ringToneFileInfo( profileSettings.mRingTone ); |
|
104 HbDataFormModelItem *modelItem = new CpPersonalizationEntryItemData( *mItemDataHelper, |
|
105 hbTrId("txt_cp_dblist_ringtone"), ringToneFileInfo.fileName(), "qtg_large_ring_tone", |
|
106 CpPersonalizationEntryItemData::TONE_Ring, profileId ); |
|
107 mModel->appendDataFormItem(modelItem, parent); |
|
108 modelItems.insert(ProfileItemRingTone,modelItem); |
|
109 |
|
110 //message tone item |
|
111 QFileInfo messageToneFileInfo( profileSettings.mMessageTone ); |
|
112 modelItem = new CpPersonalizationEntryItemData( *mItemDataHelper, |
|
113 hbTrId("txt_cp_dblist_message_tone"), messageToneFileInfo.fileName(), "qtg_large_message", |
|
114 CpPersonalizationEntryItemData::TONE_Message, |
|
115 profileId ); |
|
116 mModel->appendDataFormItem(modelItem , parent); |
|
117 modelItems.insert(ProfileItemMessageTone,modelItem); |
|
118 |
|
119 //email tone item |
|
120 QFileInfo emailToneFileInfo( profileSettings.mEmailTone ); |
|
121 modelItem = new CpPersonalizationEntryItemData( *mItemDataHelper, |
|
122 hbTrId("txt_cp_dblist_email_tone"), emailToneFileInfo.fileName(), "qtg_large_email", |
|
123 CpPersonalizationEntryItemData::TONE_Email, |
|
124 profileId ); |
|
125 mModel->appendDataFormItem(modelItem , parent); |
|
126 modelItems.insert(ProfileItemEmailTone,modelItem); |
|
127 |
|
128 //reminder tone item |
|
129 QFileInfo reminderToneFileInfo( profileSettings.mReminderTone ); |
|
130 modelItem = new CpPersonalizationEntryItemData( *mItemDataHelper, |
|
131 hbTrId("txt_cp_dblist_reminder_tone"), reminderToneFileInfo.fileName(), "qtg_large_calendar", |
|
132 CpPersonalizationEntryItemData::TONE_Reminder, |
|
133 profileId ); |
|
134 mModel->appendDataFormItem(modelItem , parent); |
|
135 modelItems.insert(ProfileItemReminderTone,modelItem); |
|
136 |
|
137 //notification tones item |
|
138 modelItem= mModel->appendDataFormItem(HbDataFormModelItem::CheckBoxItem,QString(),parent); |
|
139 modelItem->setContentWidgetData("text", hbTrId("txt_cp_list_notification_tones")); |
|
140 modelItem->setContentWidgetData("checkState", profileSettings.mNotificationTone ? 2 : 0); |
|
141 modelItem->setContentWidgetData("objectName", "notificationTonesCheckBox" + QString::number(profileId)); |
|
142 if (profileId == EProfileWrapperGeneralId) { |
|
143 addConnection( modelItem, SIGNAL( stateChanged( int )), this, SLOT( on_general_notificationTones_stateChanged( int ))); |
|
144 } |
|
145 else if (profileId == EProfileWrapperMeetingId) { |
|
146 addConnection( modelItem, SIGNAL( stateChanged( int )), this, SLOT( on_meeting_notificationTones_stateChanged( int ))); |
|
147 } |
|
148 modelItems.insert(ProfileItemNotificationTones,modelItem); |
|
149 |
|
150 |
|
151 //Key and Touch Screen Tones item |
|
152 modelItem = |
|
153 mModel->appendDataFormItem(HbDataFormModelItem::SliderItem ,QString(hbTrId("txt_cp_setlabel_key_and_touchscreen_tones")),parent); |
|
154 |
|
155 QList<QVariant> sliderElements; |
|
156 sliderElements << QVariant(HbSlider::IncreaseElement) << QVariant(HbSlider::TrackElement) |
|
157 << QVariant(HbSlider::DecreaseElement) << QVariant(HbSlider::IconElement) |
|
158 << QVariant(HbSlider::TextElement); |
|
159 modelItem->setContentWidgetData("sliderElements",sliderElements); |
|
160 modelItem->setContentWidgetData("objectName", "keyTonesSlider" + QString::number(profileId)); |
|
161 |
|
162 |
|
163 //TODO: profileModel need provide Max and Min value( 0-5 ), current max value from profileModel is 3 |
|
164 modelItem->setContentWidgetData( QString( "minimum" ), 0 ); |
|
165 modelItem->setContentWidgetData( QString( "maximum" ), 5 ); |
|
166 modelItem->setContentWidgetData( QString("value"), profileSettings.mKeyTouchScreenTone ); |
|
167 QMap< QString, QVariant > elements; |
|
168 elements.insert(QString("IncreaseElement") , QVariant(":/icon/hb_vol_slider_increment.svg")); |
|
169 elements.insert(QString("DecreaseElement"), QVariant(":/icon/hb_vol_slider_decrement.svg") ); |
|
170 if (profileSettings.mKeyTouchScreenTone != 0) { |
|
171 elements.insert(QString("IconElement"), QVariant(":/icon/hb_vol_slider_unmuted.svg") ); |
|
172 } |
|
173 else { |
|
174 elements.insert(QString("IconElement"), QVariant(":/icon/hb_vol_slider_muted.svg") ); |
|
175 } |
|
176 |
|
177 modelItem->setContentWidgetData( QString( "elementIcons" ), elements ); |
|
178 |
|
179 if (profileId == EProfileWrapperGeneralId) { |
|
180 addConnection( modelItem, SIGNAL( valueChanged( int )), this, SLOT( on_general_keysAndScreenToneSlider_ValueChanged( int ))); |
|
181 } |
|
182 else if (profileId == EProfileWrapperMeetingId) { |
|
183 addConnection( modelItem, SIGNAL( valueChanged( int )), this, SLOT( on_meeting_keysAndScreenToneSlider_ValueChanged( int ))); |
|
184 } |
|
185 |
|
186 modelItems.insert(ProfileItemKeyandTouchScreenTones,modelItem); |
|
187 |
|
188 |
|
189 //Touch Screen Vibra item |
|
190 modelItem = mModel->appendDataFormItem( HbDataFormModelItem::SliderItem, QString( hbTrId( "txt_cp_setlabel_touch_screen_vibra" ) ), parent ); |
|
191 //TODO: profileModel need provide Max and Min value( 0-5 ), current max value from profileModel is 3 |
|
192 sliderElements.clear(); |
|
193 sliderElements << QVariant(HbSlider::IncreaseElement) << QVariant(HbSlider::TrackElement) |
|
194 << QVariant(HbSlider::DecreaseElement); |
|
195 modelItem->setContentWidgetData("sliderElements",sliderElements); |
|
196 modelItem->setContentWidgetData("objectName", "vibrationSlider" + QString::number(profileId)); |
|
197 modelItem->setContentWidgetData( QString( "minimum" ), 0 ); |
|
198 modelItem->setContentWidgetData( QString( "maximum" ), 5 ); |
|
199 modelItem->setContentWidgetData( QString("value"), profileSettings.mKeyTouchScreenVibra ); |
|
200 QMap< QString, QVariant > iconElements; |
|
201 iconElements.insert(QString("IncreaseElement") , QVariant(":/icon/hb_vol_slider_increment.svg")); |
|
202 iconElements.insert(QString("DecreaseElement"), QVariant(":/icon/hb_vol_slider_decrement.svg") ); |
|
203 modelItem->setContentWidgetData( QString( "elementIcons" ), iconElements ); |
|
204 |
|
205 if (profileId == EProfileWrapperGeneralId) { |
|
206 addConnection( modelItem, SIGNAL( valueChanged( int )), this, SLOT( on_general_screenVibra_ValueChanged( int ))); |
|
207 } |
|
208 else if (profileId == EProfileWrapperMeetingId) { |
|
209 addConnection( modelItem, SIGNAL( valueChanged( int )), this, SLOT( on_meeting_screenVibra_ValueChanged( int ))); |
|
210 } |
|
211 |
|
212 modelItems.insert(ProfileItemTouchScreenVibra,modelItem); |
|
213 |
|
214 mProfileModelItems.insert(profileId,modelItems); |
|
215 |
|
216 } |
|
217 |
|
218 |
|
219 |
|
220 //////////////////////////////////////////////////// |
|
221 //general tones |
|
222 void CpProfileSettingForm::on_general_notificationTones_stateChanged(int state) |
|
223 { |
|
224 mProfileModel->setNotificationTone( EProfileWrapperGeneralId, checkBoxStateToBool( state ) ); |
|
225 } |
|
226 |
|
227 void CpProfileSettingForm::on_general_keysAndScreenToneSlider_ValueChanged( int value ) |
|
228 { |
|
229 mProfileModel->setKeyTouchScreenTone( EProfileWrapperGeneralId, value ); |
|
230 HbDataFormModelItem *modelItem = profileItem(EProfileWrapperGeneralId,ProfileItemKeyandTouchScreenTones); |
|
231 if (modelItem) { |
|
232 modelItem->setContentWidgetData( QString("value"), value ); |
|
233 setMuteIcon(modelItem, (value == 0) ); |
|
234 } |
|
235 } |
|
236 |
|
237 |
|
238 //general vibra |
|
239 void CpProfileSettingForm::on_general_screenVibra_ValueChanged( int value ) |
|
240 { |
|
241 mProfileModel->setKeyTouchScreenVibra( EProfileWrapperGeneralId, value ); |
|
242 |
|
243 HbDataFormModelItem *modelItem = profileItem(EProfileWrapperGeneralId,ProfileItemTouchScreenVibra); |
|
244 if (modelItem) { |
|
245 modelItem->setContentWidgetData( QString("value"), value ); |
|
246 } |
|
247 |
|
248 } |
|
249 |
|
250 //////////////////////////////////////////////////// |
|
251 //meeting Tones |
|
252 void CpProfileSettingForm::on_meeting_notificationTones_stateChanged(int state) |
|
253 { |
|
254 mProfileModel->setNotificationTone( EProfileWrapperMeetingId, checkBoxStateToBool( state ) ); |
|
255 } |
|
256 |
|
257 void CpProfileSettingForm::on_meeting_keysAndScreenToneSlider_ValueChanged( int value ) |
|
258 { |
|
259 mProfileModel->setKeyTouchScreenTone( EProfileWrapperMeetingId, value ); |
|
260 |
|
261 HbDataFormModelItem *modelItem = profileItem(EProfileWrapperMeetingId,ProfileItemKeyandTouchScreenTones); |
|
262 if (modelItem) { |
|
263 modelItem->setContentWidgetData( QString("value"), value ); |
|
264 setMuteIcon(modelItem, (value == 0) ); |
|
265 } |
|
266 } |
|
267 |
|
268 void CpProfileSettingForm::on_meeting_screenVibra_ValueChanged( int value ) |
|
269 { |
|
270 mProfileModel->setKeyTouchScreenVibra( EProfileWrapperMeetingId, value ); |
|
271 |
|
272 HbDataFormModelItem *modelItem = profileItem(EProfileWrapperMeetingId,ProfileItemTouchScreenVibra); |
|
273 if (modelItem) { |
|
274 modelItem->setContentWidgetData( QString("value"), value ); |
|
275 } |
|
276 } |
|
277 |
|
278 bool CpProfileSettingForm::checkBoxStateToBool( int state ) |
|
279 { |
|
280 if( state == Qt::Checked ) { |
|
281 return true; |
|
282 } else { |
|
283 return false; |
|
284 } |
|
285 } |
|
286 |
|
287 |
|
288 void CpProfileSettingForm::settingValueChanged(const XQSettingsKey &key, const QVariant &value) |
|
289 { |
|
290 if (key.uid() == KCRUidProfileEngine.iUid && key.key() == KProEngSilenceMode && value.isValid()) { |
|
291 |
|
292 static const int silenceSensitiveModelItemIds[] = |
|
293 { |
|
294 CpProfileSettingForm::ProfileItemRingTone, |
|
295 CpProfileSettingForm::ProfileItemMessageTone, |
|
296 CpProfileSettingForm::ProfileItemEmailTone, |
|
297 CpProfileSettingForm::ProfileItemReminderTone, |
|
298 CpProfileSettingForm::ProfileItemNotificationTones, |
|
299 CpProfileSettingForm::ProfileItemKeyandTouchScreenTones |
|
300 }; |
|
301 |
|
302 QHash< int,QHash<int,HbDataFormModelItem*> >::const_iterator it (mProfileModelItems.begin()); |
|
303 for(; it != mProfileModelItems.end(); ++it ) { |
|
304 for (int i = 0; i < sizeof(silenceSensitiveModelItemIds)/sizeof(silenceSensitiveModelItemIds[0]);++i) { |
|
305 QHash<int,HbDataFormModelItem*>::const_iterator found = it.value().find(silenceSensitiveModelItemIds[i]); |
|
306 if (found != it.value().end()) { |
|
307 if (found.key() == CpProfileSettingForm::ProfileItemKeyandTouchScreenTones) { |
|
308 int currentValue = found.value()->contentWidgetData("value").toInt(); |
|
309 // change the mute icon when the silence mode is changed |
|
310 bool isMute = value.toBool() || (currentValue == 0); |
|
311 setMuteIcon(found.value(), isMute); |
|
312 } |
|
313 found.value()->setEnabled(!value.toBool()); |
|
314 } |
|
315 } |
|
316 } |
|
317 } |
|
318 } |
|
319 |
|
320 HbDataFormModelItem *CpProfileSettingForm::profileItem(int profileId,int profileItemId) |
|
321 { |
|
322 return mProfileModelItems.value(profileId).value(profileItemId); |
|
323 } |
|
324 |
|
325 /*! |
|
326 * Set the slider icon to mute or unmute |
|
327 * @param isMute: identified the icon of slider, mute or unmute |
|
328 * @param profileId: identified which slider should be changed |
|
329 */ |
|
330 |
|
331 void CpProfileSettingForm::setMuteIcon(HbDataFormModelItem *sliderItem, bool isMute) |
|
332 { |
|
333 if (sliderItem == 0) { |
|
334 return; |
|
335 } |
|
336 //VolumeSliderItem will be depreacted, so ignore the assert about it |
|
337 if (sliderItem->type() != HbDataFormModelItem::SliderItem) { |
|
338 return; |
|
339 } |
|
340 |
|
341 QMap<QString, QVariant> elements = sliderItem->contentWidgetData("elementIcons").toMap(); |
|
342 |
|
343 if (isMute) { |
|
344 elements.insert(QString("IconElement"), QVariant(":/icon/hb_vol_slider_muted.svg")); |
|
345 } |
|
346 else { |
|
347 elements.insert(QString("IconElement"), QVariant(":/icon/hb_vol_slider_unmuted.svg")); |
|
348 } |
|
349 sliderItem->setContentWidgetData( QString( "elementIcons" ), elements ); |
|
350 } |
|
351 //End of File |