|
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 <QModelIndex> |
|
19 #include <hbdataform.h> |
|
20 #include <hbdataformmodel.h> |
|
21 #include <hbdataformmodelitem.h> |
|
22 #include <hbdataformviewitem.h> |
|
23 #include <hbabstractbutton.h> |
|
24 #include <xqsettingsmanager.h> |
|
25 #include <xqsettingskey.h> |
|
26 #include <HbExtendedLocale.h> |
|
27 |
|
28 #include "calensettings.h" |
|
29 #include "calenservices.h" |
|
30 #include "calendarprivatecrkeys.h" |
|
31 |
|
32 // Constants |
|
33 const int KValueZero( 0 ); |
|
34 const int KValueOne( 1 ); |
|
35 |
|
36 |
|
37 CalenSettings::CalenSettings(MCalenServices& services, HbDataForm *form, QObject *parent) |
|
38 :QObject(parent), |
|
39 mServices(services), |
|
40 mSettingsForm(form), |
|
41 mSettingsModel(NULL), |
|
42 mAlarmSnoozeTimeItem(NULL), |
|
43 mShowWeekNumberItem(NULL), |
|
44 mShowRegionalInfoItem(NULL), |
|
45 mShowWeekStartOnInfoItem(NULL), |
|
46 mStartOfWeekItem(NULL), |
|
47 mWeekNumberItemAdded(false), |
|
48 mRegionalpluginActive(false) |
|
49 { |
|
50 mSettingsManager = new XQSettingsManager(this); |
|
51 mAlarmSnoozeCenrepKey = new XQSettingsKey( |
|
52 XQSettingsKey::TargetCentralRepository, |
|
53 KCRUidCalendar, KCalendarSnoozeTime); |
|
54 mWeekNumberCenrepKey = new XQSettingsKey( |
|
55 XQSettingsKey::TargetCentralRepository, |
|
56 KCRUidCalendar, KCalendarShowWeekNum); |
|
57 mShowRegionalInfoKey = new XQSettingsKey( |
|
58 XQSettingsKey::TargetCentralRepository, |
|
59 KCRUidCalendar, KCalendarShowRegionalInfo); |
|
60 } |
|
61 |
|
62 /*! |
|
63 Destructor |
|
64 */ |
|
65 CalenSettings::~CalenSettings() |
|
66 { |
|
67 if (mSettingsManager) { |
|
68 delete mSettingsManager; |
|
69 } |
|
70 // Delete the cenrep keys |
|
71 delete mAlarmSnoozeCenrepKey; |
|
72 delete mWeekNumberCenrepKey; |
|
73 delete mShowRegionalInfoKey; |
|
74 |
|
75 if (mSettingsModel) { |
|
76 delete mSettingsModel; |
|
77 } |
|
78 if (mAlarmSnoozeTimeHash.count()) { |
|
79 // Clear the contents |
|
80 mAlarmSnoozeTimeHash.clear(); |
|
81 } |
|
82 } |
|
83 |
|
84 /*! |
|
85 Creates the settings model |
|
86 */ |
|
87 void CalenSettings::createModel() |
|
88 { |
|
89 // Remove the model. |
|
90 if (mSettingsForm->model()) { |
|
91 delete mSettingsForm->model(); |
|
92 mSettingsForm->setModel(0); |
|
93 mSettingsModel = 0; |
|
94 } |
|
95 |
|
96 // Create a model and set it. |
|
97 mSettingsModel = new HbDataFormModel(mSettingsForm); |
|
98 |
|
99 // Create the alarm snooze choices |
|
100 QStringList alarmSnoozeChoices; |
|
101 alarmSnoozeChoices << hbTrId( |
|
102 "txt_calendar_setlabel_reminder_snooze_time_val_5_m") |
|
103 << hbTrId("txt_calendar_setlabel_reminder_snooze_time_val_10") |
|
104 << hbTrId("txt_calendar_setlabel_reminder_snooze_time_val_15") |
|
105 << hbTrId("txt_calendar_setlabel_reminder_snooze_time_val_30"); |
|
106 // Build the hash map for the alarm snooze time. |
|
107 // The values are five, ten, fifteen and thirty minutes |
|
108 mAlarmSnoozeTimeHash[0] = 5; |
|
109 mAlarmSnoozeTimeHash[1] = 10; |
|
110 mAlarmSnoozeTimeHash[2] = 15; |
|
111 mAlarmSnoozeTimeHash[3] = 30; |
|
112 |
|
113 // Append Alarm Snooze Time Setting item |
|
114 mAlarmSnoozeTimeItem = new HbDataFormModelItem(); |
|
115 mAlarmSnoozeTimeItem->setType(HbDataFormModelItem::ComboBoxItem); |
|
116 mAlarmSnoozeTimeItem->setData(HbDataFormModelItem::LabelRole, |
|
117 QString(hbTrId("txt_calendar_setlabel_reminder_snooze_time"))); |
|
118 |
|
119 mAlarmSnoozeTimeItem->setContentWidgetData(QString("items"), |
|
120 alarmSnoozeChoices); |
|
121 mAlarmSnoozeTimeItem->setContentWidgetData(QString("currentIndex"), 0); |
|
122 mSettingsForm->addConnection(mAlarmSnoozeTimeItem, |
|
123 SIGNAL(currentIndexChanged(int)), |
|
124 this, SLOT(handleAlarmSnoozeTimeChange(int))); |
|
125 mAlarmSnoozeTimeItem->setContentWidgetData("objectName", "alarmSnoozeTime"); |
|
126 mSettingsModel->appendDataFormItem(mAlarmSnoozeTimeItem); |
|
127 |
|
128 // Create the weekday list based on start of week. |
|
129 QStringList weekdaysList; |
|
130 weekdaysList |
|
131 << hbTrId("txt_calendar_setlabel_week_starts_on_val_monday") |
|
132 << hbTrId("txt_calendar_setlabel_week_starts_on_val_tuesday") |
|
133 << hbTrId("txt_calendar_setlabel_week_starts_on_val_wednesday") |
|
134 << hbTrId("txt_calendar_setlabel_week_starts_on_val_thursday") |
|
135 << hbTrId("txt_calendar_setlabel_week_starts_on_val_friday") |
|
136 << hbTrId("txt_calendar_setlabel_week_starts_on_val_saturday") |
|
137 << hbTrId("txt_calendar_setlabel_week_starts_on_val_sunday"); |
|
138 // Start of week item. |
|
139 mShowWeekStartOnInfoItem = mSettingsModel->appendDataFormItem( |
|
140 HbDataFormModelItem::ComboBoxItem, |
|
141 hbTrId("txt_calendar_setlabel_week_starts_on")); |
|
142 |
|
143 // Get start of week from the locale. |
|
144 HbExtendedLocale locale = HbExtendedLocale::system(); |
|
145 mStartOfWeek = locale.startOfWeek(); |
|
146 mShowWeekStartOnInfoItem->setContentWidgetData("items", weekdaysList); |
|
147 mShowWeekStartOnInfoItem->setContentWidgetData( |
|
148 "currentIndex", mStartOfWeek); |
|
149 mShowWeekStartOnInfoItem->setContentWidgetData("objectName", "startOfWeek"); |
|
150 mSettingsForm->addConnection(mShowWeekStartOnInfoItem, |
|
151 SIGNAL(currentIndexChanged(int)), |
|
152 this, SLOT(setStartDayOfWeek(int))); |
|
153 // Add the show week number item in the model |
|
154 addWeekNumberItem(); |
|
155 |
|
156 if (isPluginEnabled()) { |
|
157 addRegionalInfoItem(); |
|
158 } |
|
159 } |
|
160 |
|
161 /*! |
|
162 Adds the regional info item to the model |
|
163 */ |
|
164 void CalenSettings::addRegionalInfoItem() |
|
165 { |
|
166 mRegionalpluginActive = true; |
|
167 mShowRegionalInfoItem = new HbDataFormModelItem(); |
|
168 mShowRegionalInfoItem->setType(HbDataFormModelItem::ToggleValueItem); |
|
169 mShowRegionalInfoItem->setData(HbDataFormModelItem::LabelRole, |
|
170 QString(hbTrId("txt_calendar_setlabel_show_lunar_calendar"))); |
|
171 |
|
172 // For HbPushButton type properties -- to be used for toggle value item |
|
173 mShowRegionalInfoItem->setContentWidgetData(QString("text"), |
|
174 QString(hbTrId("txt_calendar_button_no"))); |
|
175 mShowRegionalInfoItem->setContentWidgetData(QString("additionalText"), |
|
176 QString(hbTrId("txt_calendar_button_yes"))); |
|
177 mShowRegionalInfoItem->setContentWidgetData( |
|
178 "objectName", "showRegionalInfo"); |
|
179 mSettingsForm->addConnection(mShowRegionalInfoItem, SIGNAL(clicked()), |
|
180 this, SLOT(handleRegionalInfoChange())); |
|
181 mSettingsModel->appendDataFormItem(mShowRegionalInfoItem); |
|
182 } |
|
183 |
|
184 /*! |
|
185 Removes the regional info item from the model |
|
186 */ |
|
187 void CalenSettings::removeRegionalInfoItem() |
|
188 { |
|
189 mSettingsForm->removeConnection(mShowRegionalInfoItem, SIGNAL(clicked()), |
|
190 this, SLOT(handleRegionalInfoChange())); |
|
191 mSettingsModel->removeItem(mShowRegionalInfoItem); |
|
192 mRegionalpluginActive = false; |
|
193 } |
|
194 |
|
195 /*! |
|
196 Handles the alarm snooze time change |
|
197 */ |
|
198 void CalenSettings::handleAlarmSnoozeTimeChange(int index) |
|
199 { |
|
200 if(mAlarmSnoozeTimeHash.value(index) > KValueZero) { |
|
201 mSettingsManager->writeItemValue(*mAlarmSnoozeCenrepKey, mAlarmSnoozeTimeHash[index]); |
|
202 } |
|
203 } |
|
204 |
|
205 /*! |
|
206 Handles the week number change |
|
207 */ |
|
208 void CalenSettings::handleWeekNumberChange() |
|
209 { |
|
210 QVariant data = mShowWeekNumberItem->contentWidgetData(QString("text")); |
|
211 QString value = data.toString(); |
|
212 if (!value.compare(hbTrId("txt_calendar_button_no"))) { |
|
213 // User has made it OFF. |
|
214 mSettingsManager->writeItemValue(*mWeekNumberCenrepKey, KValueZero); |
|
215 } else if (!value.compare(hbTrId("txt_calendar_button_yes"))) { |
|
216 // User has made it ON. |
|
217 mSettingsManager->writeItemValue(*mWeekNumberCenrepKey, KValueOne); |
|
218 } |
|
219 } |
|
220 |
|
221 /*! |
|
222 Handles the regional info option change |
|
223 */ |
|
224 void CalenSettings::handleRegionalInfoChange() |
|
225 { |
|
226 QVariant data = mShowRegionalInfoItem->contentWidgetData(QString("text")); |
|
227 QString value = data.toString(); |
|
228 if (!value.compare(hbTrId("txt_calendar_button_no"))) { |
|
229 // User has made it OFF |
|
230 mSettingsManager->writeItemValue(*mShowRegionalInfoKey, KValueZero); |
|
231 } else if (!value.compare(hbTrId("txt_calendar_button_yes"))) { |
|
232 // User has made it ON. |
|
233 mSettingsManager->writeItemValue(*mShowRegionalInfoKey, KValueOne); |
|
234 } |
|
235 } |
|
236 |
|
237 /*! |
|
238 Populates the settings model |
|
239 */ |
|
240 void CalenSettings::populateSettingList() |
|
241 { |
|
242 // Read the values from cenrep |
|
243 // Read the initial values from the cenrep |
|
244 QVariant value = mSettingsManager->readItemValue(*mAlarmSnoozeCenrepKey); |
|
245 uint alarmSnoozeTime = value.toUInt(); |
|
246 |
|
247 // Get the value from the hash and set the value to the form |
|
248 int choiceIndex = mAlarmSnoozeTimeHash.key(alarmSnoozeTime); |
|
249 mAlarmSnoozeTimeItem->setContentWidgetData(QString("currentIndex"), |
|
250 choiceIndex); |
|
251 // Get start of week from the locale. |
|
252 HbExtendedLocale locale = HbExtendedLocale::system(); |
|
253 mStartOfWeek = locale.startOfWeek(); |
|
254 |
|
255 mShowWeekStartOnInfoItem->setContentWidgetData("currentIndex", mStartOfWeek); |
|
256 //update the show week number option |
|
257 updateShowWeekItem(); |
|
258 // Check the the regional info plugin is loaded now or not |
|
259 if (isPluginEnabled()) { |
|
260 // If the plugin was already there just populate the item |
|
261 // else add the regional info item and then populate |
|
262 if (mRegionalpluginActive) { |
|
263 populateRegionalInfo(); |
|
264 }else { |
|
265 addRegionalInfoItem(); |
|
266 populateRegionalInfo(); |
|
267 } |
|
268 }else { |
|
269 // If the plugin is removed now and if it was loaded before |
|
270 // remove the item |
|
271 if (mRegionalpluginActive) { |
|
272 removeRegionalInfoItem(); |
|
273 } |
|
274 } |
|
275 mSettingsForm->setModel(mSettingsModel); |
|
276 } |
|
277 |
|
278 /*! |
|
279 Populates the regional info item |
|
280 */ |
|
281 void CalenSettings::populateRegionalInfo() |
|
282 { |
|
283 QVariant value = mSettingsManager->readItemValue(*mShowRegionalInfoKey); |
|
284 uint showRegionalInfo = value.toUInt(); |
|
285 |
|
286 if (showRegionalInfo) { |
|
287 mShowRegionalInfoItem->setContentWidgetData( |
|
288 QString("text"), QString(hbTrId("txt_calendar_button_yes"))); |
|
289 mShowRegionalInfoItem->setContentWidgetData( |
|
290 QString("additionalText"), QString( |
|
291 hbTrId("txt_calendar_button_no"))); |
|
292 } else { |
|
293 mShowRegionalInfoItem->setContentWidgetData( |
|
294 QString("text"), QString(hbTrId("txt_calendar_button_no"))); |
|
295 mShowRegionalInfoItem->setContentWidgetData( |
|
296 QString("additionalText"), QString( |
|
297 hbTrId("txt_calendar_button_yes"))); |
|
298 } |
|
299 } |
|
300 |
|
301 /*! |
|
302 Adds the week number item in the model |
|
303 */ |
|
304 void CalenSettings::addWeekNumberItem() |
|
305 { |
|
306 mWeekNumberItemAdded = true; |
|
307 // Append Show Week Number settings item |
|
308 mShowWeekNumberItem = new HbDataFormModelItem(); |
|
309 mShowWeekNumberItem->setType(HbDataFormModelItem::ToggleValueItem); |
|
310 |
|
311 QStringList values; |
|
312 values << hbTrId("txt_calendar_button_no") |
|
313 << hbTrId("txt_calendar_button_yes"); |
|
314 mShowWeekNumberItem->setData(HbDataFormModelItem::LabelRole, |
|
315 QString(hbTrId("txt_calendar_setlabel_show_week_numbers"))); |
|
316 mShowWeekNumberItem->setContentWidgetData("objectName", "showWeekNumber"); |
|
317 |
|
318 mSettingsModel->appendDataFormItem(mShowWeekNumberItem); |
|
319 mSettingsForm->addConnection(mShowWeekNumberItem, SIGNAL(clicked()), |
|
320 this, SLOT(handleWeekNumberChange())); |
|
321 } |
|
322 |
|
323 /*! |
|
324 Returns true if the regional plugin is loaded |
|
325 */ |
|
326 bool CalenSettings::isPluginEnabled() |
|
327 { |
|
328 QString *pluginInfo = mServices.InfobarTextL(); |
|
329 if (!pluginInfo) { |
|
330 return false; |
|
331 } else { |
|
332 return true; |
|
333 } |
|
334 } |
|
335 |
|
336 /*! |
|
337 Sets the start day of the week to the locale |
|
338 Is called when user selects week day |
|
339 */ |
|
340 void CalenSettings::setStartDayOfWeek(const int index) |
|
341 { |
|
342 TLocale locale; |
|
343 TDay day = (TDay)index; |
|
344 //set the start day of the week to locale |
|
345 locale.SetStartOfWeek(day); |
|
346 locale.Set(); |
|
347 updateShowWeekItem(); |
|
348 } |
|
349 |
|
350 /*! |
|
351 Updates the show week number option |
|
352 */ |
|
353 void CalenSettings::updateShowWeekItem() |
|
354 { |
|
355 // Get start of week from the locale. |
|
356 HbExtendedLocale locale = HbExtendedLocale::system(); |
|
357 mStartOfWeek = locale.startOfWeek(); |
|
358 mShowWeekStartOnInfoItem->setContentWidgetData("currentIndex", mStartOfWeek); |
|
359 |
|
360 // Read the value form cenrep |
|
361 QVariant value = mSettingsManager->readItemValue(*mWeekNumberCenrepKey); |
|
362 uint showWeekNumber = value.toUInt(); |
|
363 |
|
364 //if start day is not Monday |
|
365 //set the show week number option dimmed , |
|
366 //else set to proper status |
|
367 if(mStartOfWeek != HbExtendedLocale::Monday) { |
|
368 mShowWeekNumberItem->setContentWidgetData(QString("text"), |
|
369 QString(hbTrId("txt_calendar_button_no"))); |
|
370 mShowWeekNumberItem->setContentWidgetData(QString("additionalText"), |
|
371 QString(hbTrId("txt_calendar_button_yes"))); |
|
372 mShowWeekNumberItem->setEnabled(false); |
|
373 } else { |
|
374 if(showWeekNumber) { |
|
375 mShowWeekNumberItem->setContentWidgetData(QString("text"), |
|
376 QString(hbTrId("txt_calendar_button_yes"))); |
|
377 mShowWeekNumberItem->setContentWidgetData(QString("additionalText"), |
|
378 QString(hbTrId("txt_calendar_button_no"))); |
|
379 } else { |
|
380 mShowWeekNumberItem->setContentWidgetData(QString("text"), |
|
381 QString(hbTrId("txt_calendar_button_no"))); |
|
382 mShowWeekNumberItem->setContentWidgetData(QString("additionalText"), |
|
383 QString(hbTrId("txt_calendar_button_yes"))); |
|
384 } |
|
385 mShowWeekNumberItem->setEnabled(true); |
|
386 } |
|
387 } |
|
388 // End of file |