|
1 /* |
|
2 * Copyright (c) 2010 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 * Definition of CalenEditorReminderField class. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // System Includes |
|
21 #include <QDate> |
|
22 |
|
23 #include <hbdataformmodelitem.h> |
|
24 #include <hbdataformmodel.h> |
|
25 #include <hbdataform.h> |
|
26 #include <hbdatetimepicker.h> |
|
27 #include <hbextendedlocale.h> |
|
28 #include <hbi18ndef.h> |
|
29 #include <hbdialog.h> |
|
30 #include <hblabel.h> |
|
31 #include <hbaction.h> |
|
32 |
|
33 // User Includes |
|
34 #include "calenagendautils.h" |
|
35 #include "caleneditorreminderfield.h" |
|
36 #include "OstTraceDefinitions.h" |
|
37 #ifdef OST_TRACE_COMPILER_IN_USE |
|
38 #include "caleneditorreminderfieldTraces.h" |
|
39 #endif |
|
40 |
|
41 |
|
42 #define numberOfMinutesInADay 1440 |
|
43 /*! |
|
44 \class CalenEditorReminderField |
|
45 */ |
|
46 /*! |
|
47 Constructor. |
|
48 |
|
49 \param parent QObject pointer |
|
50 */ |
|
51 |
|
52 CalenEditorReminderField::CalenEditorReminderField( |
|
53 CalenEditorPrivate* calenEditor, |
|
54 HbDataForm* form, |
|
55 HbDataFormModel* model, |
|
56 QObject *parent) |
|
57 :QObject(parent), |
|
58 mCalenEditor(calenEditor), |
|
59 mEditorForm(form), |
|
60 mCalenEditorModel(model), |
|
61 mCustomReminderTimeItem(0), |
|
62 mReminderTimeAdded(false) |
|
63 { |
|
64 OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_CALENEDITORREMINDERFIELD_ENTRY ); |
|
65 mReminderItem = new HbDataFormModelItem(); |
|
66 mReminderItem->setType(HbDataFormModelItem::ComboBoxItem); |
|
67 mReminderItem->setData(HbDataFormModelItem::LabelRole, |
|
68 hbTrId("txt_calendar_setlabel_reminder")); |
|
69 // Add it to the model |
|
70 mCalenEditorModel->appendDataFormItem(mReminderItem, |
|
71 mCalenEditorModel->invisibleRootItem()); |
|
72 OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_CALENEDITORREMINDERFIELD_EXIT ); |
|
73 } |
|
74 |
|
75 /*! |
|
76 Destructor |
|
77 */ |
|
78 CalenEditorReminderField::~CalenEditorReminderField() |
|
79 { |
|
80 OstTraceFunctionEntry0( DUP1_CALENEDITORREMINDERFIELD_CALENEDITORREMINDERFIELD_ENTRY ); |
|
81 if(mReminderHash.count()) { |
|
82 mReminderHash.clear(); |
|
83 } |
|
84 OstTraceFunctionExit0( DUP1_CALENEDITORREMINDERFIELD_CALENEDITORREMINDERFIELD_EXIT ); |
|
85 } |
|
86 |
|
87 /*! |
|
88 Set the reminder choices. |
|
89 */ |
|
90 void CalenEditorReminderField::setReminderChoices() |
|
91 { |
|
92 OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_SETREMINDERCHOICES_ENTRY ); |
|
93 |
|
94 // Disconnect the slot and connect it back again at end to avoid unnecessary |
|
95 // calls to handleReminderIndexChanged slot. Or else the slot gets called |
|
96 // when we add all of items to the repeat combobox. |
|
97 mEditorForm->removeConnection(mReminderItem, |
|
98 SIGNAL(currentIndexChanged(int)), this, |
|
99 SLOT(handleReminderIndexChanged(int))); |
|
100 // Create the reminder choices |
|
101 QStringList reminderChoices; |
|
102 reminderChoices << hbTrId("txt_calendar_setlabel_reminder_val_off") |
|
103 << hbTrId("txt_calendar_setlabel_reminder_val_at_the_start") |
|
104 << hbTrId("txt_calendar_setlabel_reminder_val_15_minutes_befo") |
|
105 << hbTrId("txt_calendar_setlabel_reminder_val_30_minutes_befo") |
|
106 << hbTrId("txt_calendar_setlabel_reminder_val_1_hour_before"); |
|
107 |
|
108 mReminderItem->setContentWidgetData("items", reminderChoices); |
|
109 mReminderItem->setEnabled(true); |
|
110 |
|
111 mEditorForm->addConnection(mReminderItem, |
|
112 SIGNAL(currentIndexChanged(int)), this, |
|
113 SLOT(handleReminderIndexChanged(int))); |
|
114 OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_SETREMINDERCHOICES_EXIT ); |
|
115 } |
|
116 |
|
117 /*! |
|
118 Adds reminder item to the model |
|
119 */ |
|
120 void CalenEditorReminderField::addItemToModel() |
|
121 { |
|
122 OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_ADDITEMTOMODEL_ENTRY ); |
|
123 // Add reminder to the model |
|
124 mCalenEditorModel->appendDataFormItem( mReminderItem, |
|
125 mCalenEditorModel->invisibleRootItem()); |
|
126 OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_ADDITEMTOMODEL_EXIT ); |
|
127 } |
|
128 |
|
129 /*! |
|
130 Removes reminder item from the model |
|
131 */ |
|
132 void CalenEditorReminderField::removeItemFromModel() |
|
133 { |
|
134 OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_REMOVEITEMFROMMODEL_ENTRY ); |
|
135 mCalenEditorModel->removeItem(modelIndex()); |
|
136 OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_REMOVEITEMFROMMODEL_EXIT ); |
|
137 } |
|
138 |
|
139 /*! |
|
140 Set the current reminder index with the value which was saved |
|
141 before, if it is valid or else default the value to 15MinsBefore |
|
142 or AtTheStart whichever is appropriate |
|
143 */ |
|
144 void CalenEditorReminderField::setSavedMeetingReminderIndex() |
|
145 { |
|
146 // Get the reminder offset value. |
|
147 int reminderOffset = |
|
148 mCalenEditor->editedEntry()->alarm().timeOffset(); |
|
149 // Get the index value for the reminder combo box from the hash |
|
150 // table. 2nd argument is defaultKey if the hash contains no item mapped to value |
|
151 //TODO: Need to confirm the default reminder to set if none of the choices are met like in case of synch from outlook. |
|
152 int index = mReminderHash.key(reminderOffset, Reminder15MinsBefore); |
|
153 |
|
154 if (index < reminderItemsCount()) |
|
155 setCurrentIndex(index); |
|
156 else if (reminderItemsCount() == (ReminderAtStart + 1)) //+1 because enum starts from 0. |
|
157 setCurrentIndex(ReminderAtStart); |
|
158 else |
|
159 setCurrentIndex(Reminder15MinsBefore); |
|
160 } |
|
161 |
|
162 /*! |
|
163 Populates reminder item with available choices to the user |
|
164 \param newEntry bool value to indicate if its a new entry |
|
165 */ |
|
166 void CalenEditorReminderField::populateReminderItem(bool newEntry) |
|
167 { |
|
168 OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_POPULATEREMINDERITEM_ENTRY ); |
|
169 AgendaAlarm reminder; |
|
170 bool pastEvent = false; |
|
171 bool repeatingEntry = false; |
|
172 bool sameDay = false; |
|
173 |
|
174 mReminderItem->setContentWidgetData("objectName", "remainderItem"); |
|
175 // Build the hash map for the reminder. |
|
176 mReminderHash[ReminderOff] = -1; // OFF. |
|
177 mReminderHash[ReminderAtStart] = 0; |
|
178 mReminderHash[Reminder15MinsBefore] = 15; |
|
179 mReminderHash[Reminder30MinsBefore] = 30; |
|
180 mReminderHash[Reminder1HourBefore] = 60; |
|
181 |
|
182 // Set reference date to start date or repeat until date accordingly to |
|
183 // decide whether its a past event or not. |
|
184 QDate referenceDate; |
|
185 if (!mCalenEditor->editedEntry()->isRepeating() || |
|
186 (mCalenEditor->isEditRangeThisOnly())) { |
|
187 referenceDate = mCalenEditor->editedEntry()->startTime().date(); |
|
188 } else { |
|
189 referenceDate = mCalenEditor->editedEntry()->repeatRule().until().date(); |
|
190 repeatingEntry = true; |
|
191 } |
|
192 |
|
193 if ((referenceDate < QDate::currentDate()) || |
|
194 (referenceDate == QDate::currentDate() |
|
195 && (mCalenEditor->editedEntry()->startTime().time() < |
|
196 QTime::currentTime()))) { |
|
197 pastEvent = true; |
|
198 } |
|
199 |
|
200 if (mCalenEditor->isAllDayEvent()) { |
|
201 updateReminderChoicesForAllDay(referenceDate); |
|
202 } else { |
|
203 if((referenceDate == QDate::currentDate()) |
|
204 && !pastEvent) { |
|
205 UpdateReminderChoicesForSameDay(mCalenEditor->editedEntry()->startTime().time()); |
|
206 sameDay = true; |
|
207 } |
|
208 else { |
|
209 setReminderChoices(); |
|
210 } |
|
211 } |
|
212 // Set the default reminder value to 15 minutes |
|
213 if (newEntry) { |
|
214 if (!pastEvent) { |
|
215 int defaultIndex = Reminder15MinsBefore; |
|
216 if (reminderItemsCount() == (ReminderAtStart + 1)) //If 15MinsBefore option is not available |
|
217 defaultIndex = ReminderAtStart; |
|
218 |
|
219 setCurrentIndex(defaultIndex); |
|
220 // Save the reminder alarm for the entry |
|
221 reminder.setTimeOffset(mReminderHash.value(defaultIndex)); |
|
222 reminder.setAlarmSoundName(QString(" ")); |
|
223 // Set the reminder to the entry as well as original entry. |
|
224 mCalenEditor->editedEntry()->setAlarm(reminder); |
|
225 mCalenEditor->originalEntry()->setAlarm(reminder); |
|
226 } else { |
|
227 setReminderOff(); |
|
228 } |
|
229 } else { |
|
230 int offsetInMins = mCalenEditor->editedEntry()->alarm().timeOffset(); |
|
231 // If the alarm is not null, |
|
232 // Check if all day event or not and then set the choices accordingly. |
|
233 if (mCalenEditor->editedEntry()->alarm().isNull()) { |
|
234 // Alarm is set off |
|
235 setCurrentIndex(ReminderOff); |
|
236 if(mReminderTimeAdded) { |
|
237 removeReminderTimeField(); |
|
238 } |
|
239 } else if (!mCalenEditor->isAllDayEvent()) { |
|
240 QTime currentTime = QTime::currentTime(); |
|
241 |
|
242 //TODO: Still need confirmation for proper behaviour when entry is edited after alarm has expired. |
|
243 if (!repeatingEntry && sameDay && (currentTime.addSecs(offsetInMins * 60) >= mCalenEditor->editedEntry()->startTime().time())) { |
|
244 setCurrentIndex(ReminderOff); //Alarm has expired already, so making it off. |
|
245 //The slot for index 0 is not called, since after UpdateReminderChoicesForSameDay() |
|
246 //index is 0 itself and there is no change. So explicitly calling it here. |
|
247 handleReminderIndexChanged(0); |
|
248 } |
|
249 else { |
|
250 setSavedMeetingReminderIndex(); |
|
251 } |
|
252 } else { |
|
253 // Insert reminder time field and display entry's reminder time. |
|
254 // If past then disable the field. |
|
255 if (!mReminderTimeAdded) { |
|
256 insertReminderTimeField(); |
|
257 } |
|
258 if (pastEvent && mReminderTimeAdded) { |
|
259 mCustomReminderTimeItem->setEnabled(false); |
|
260 } |
|
261 // Get the appropriate reminder index depending on the value of time offset. |
|
262 int index = getReminderIndexBasedOnEntryAlarm(); |
|
263 mReminderItem->setContentWidgetData("currentIndex", index); |
|
264 setDisplayTime(); |
|
265 } |
|
266 if (pastEvent) { |
|
267 mReminderItem->setEnabled(false); |
|
268 } |
|
269 } |
|
270 mEditorForm->addConnection(mReminderItem, |
|
271 SIGNAL(currentIndexChanged(int)), this, |
|
272 SLOT(handleReminderIndexChanged(int))); |
|
273 OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_POPULATEREMINDERITEM_EXIT ); |
|
274 } |
|
275 |
|
276 /*! |
|
277 Triggered from tapping on reminder item. |
|
278 Handles the reminder time change and updates the same in the event. |
|
279 \param index The new index chosen in the reminder list. |
|
280 */ |
|
281 void CalenEditorReminderField::handleReminderIndexChanged(int index) |
|
282 { |
|
283 OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_HANDLEREMINDERINDEXCHANGED_ENTRY ); |
|
284 AgendaAlarm reminder; |
|
285 if (!mCalenEditor->editedEntry()->alarm().isNull()) { |
|
286 reminder = mCalenEditor->editedEntry()->alarm(); |
|
287 } |
|
288 // Check whether all day event or not and store appropriately. |
|
289 if (!mCalenEditor->isAllDayEvent()) { |
|
290 // If value for the index in hash table is -1 i.e reminder is "OFF", |
|
291 // then set the default constructed reminder to |
|
292 // the entry which is Null. |
|
293 if (mReminderHash.value(index) < 0) { |
|
294 // Construct the default alarm which is NULL |
|
295 reminder = AgendaAlarm(); |
|
296 } else { |
|
297 // If not zero then set the reminder offset |
|
298 // value to the entry. |
|
299 reminder.setTimeOffset(mReminderHash.value(index)); |
|
300 reminder.setAlarmSoundName(QString(" ")); |
|
301 } |
|
302 } else { |
|
303 QDateTime reminderDateTimeForAllDay; |
|
304 QDateTime |
|
305 startDateTimeForAllDay( |
|
306 mCalenEditor->editedEntry()->startTime().date(), |
|
307 QTime(0, 0, 0)); |
|
308 if (mReminderItem->contentWidgetData("currentIndex") == ReminderOff) { |
|
309 reminder = AgendaAlarm(); |
|
310 removeReminderTimeField(); |
|
311 } else { |
|
312 int offset = 0; |
|
313 if (mReminderItem->contentWidgetData("currentIndex") == ReminderOneDayBefore) { |
|
314 offset = 1; |
|
315 } else if (mReminderItem->contentWidgetData("currentIndex") == ReminderTwoDaysBefore) { |
|
316 offset = 2; |
|
317 } |
|
318 if(!mReminderTimeAdded) { |
|
319 insertReminderTimeField(); |
|
320 } |
|
321 // If on same day as that of the event then check if time has been |
|
322 // changed , if changed retain that else set default time. |
|
323 if (offset == 0) { |
|
324 if(mReminderTimeForAllDay == QTime(18, 0, 0, 0)) { |
|
325 mReminderTimeForAllDay.setHMS(8, 0, 0); |
|
326 } |
|
327 }else { |
|
328 // For the reminder options other than ReminderOnEventDay |
|
329 // reset the default values since the time set for one option |
|
330 // may not be valid for the other option |
|
331 mReminderTimeForAllDay.setHMS(18, 0, 0, 0); |
|
332 } |
|
333 setDisplayTime(); |
|
334 reminderDateTimeForAllDay.setDate( |
|
335 mCalenEditor->editedEntry()->startTime().date().addDays( |
|
336 -offset)); |
|
337 reminderDateTimeForAllDay.setTime(mReminderTimeForAllDay); |
|
338 int seconds = |
|
339 reminderDateTimeForAllDay.secsTo(startDateTimeForAllDay); |
|
340 int timeOffset = seconds / 60; |
|
341 mCustomReminderTimeItem->setEnabled(true); |
|
342 reminder.setTimeOffset(timeOffset); |
|
343 reminder.setAlarmSoundName(QString(" ")); |
|
344 } |
|
345 } |
|
346 // Set the reminder to the entry. |
|
347 mCalenEditor->editedEntry()->setAlarm(reminder); |
|
348 if(!mCalenEditor->isNewEntry()) { |
|
349 mCalenEditor->addDiscardAction(); |
|
350 } |
|
351 OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_HANDLEREMINDERINDEXCHANGED_EXIT ); |
|
352 } |
|
353 |
|
354 /*! |
|
355 Returns the mode index of the reminder item |
|
356 \return Mode index of the reminder item |
|
357 */ |
|
358 QModelIndex CalenEditorReminderField::modelIndex() |
|
359 { |
|
360 OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_MODELINDEX_ENTRY ); |
|
361 return mCalenEditorModel->indexFromItem(mReminderItem); |
|
362 } |
|
363 |
|
364 /*! |
|
365 Set reminder off. |
|
366 */ |
|
367 void CalenEditorReminderField::setReminderOff() |
|
368 { |
|
369 OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_SETREMINDEROFF_ENTRY ); |
|
370 // Create the remindar choices |
|
371 QStringList reminderChoices; |
|
372 reminderChoices << hbTrId("txt_calendar_setlabel_reminder_val_off"); |
|
373 mReminderItem->setContentWidgetData(QString("items"), reminderChoices); |
|
374 mReminderItem->setEnabled(false); |
|
375 OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_SETREMINDEROFF_EXIT ); |
|
376 } |
|
377 |
|
378 /*! |
|
379 Set the default alarm for a new all day event. |
|
380 */ |
|
381 void CalenEditorReminderField::setDefaultAlarmForAllDay() |
|
382 { |
|
383 OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_SETDEFAULTALARMFORALLDAY_ENTRY ); |
|
384 // Set default alarm if its a new entry. |
|
385 if (mCalenEditor->isNewEntry()) { |
|
386 AgendaAlarm reminder; |
|
387 QDate defaultDate |
|
388 (mCalenEditor->editedEntry()->startTime().date().addDays(-1)); |
|
389 // Set default time as 6pm of the previous day. |
|
390 mReminderTimeForAllDay.setHMS(18, 0, 0, 0); |
|
391 setDisplayTime(); |
|
392 QDateTime startDateTimeForAllDay( |
|
393 mCalenEditor->editedEntry()->startTime().date(), QTime(0, 0)); |
|
394 QDateTime defaultReminderDateTimeForAllDay |
|
395 (defaultDate, mReminderTimeForAllDay); |
|
396 int offsetInSecs = |
|
397 defaultReminderDateTimeForAllDay.secsTo(startDateTimeForAllDay); |
|
398 int offsetInMins = offsetInSecs/60; |
|
399 reminder.setTimeOffset(offsetInMins); |
|
400 reminder.setAlarmSoundName(QString(" ")); |
|
401 // Set the reminder to the entry as well as original entry. |
|
402 mCalenEditor->editedEntry()->setAlarm(reminder); |
|
403 mCalenEditor->originalEntry()->setAlarm(reminder); |
|
404 } |
|
405 OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_SETDEFAULTALARMFORALLDAY_EXIT ); |
|
406 } |
|
407 |
|
408 /*! |
|
409 Update the reminder choices when the meeting is on same day, |
|
410 based on the time available from current time to start time of the event. |
|
411 */ |
|
412 void CalenEditorReminderField::UpdateReminderChoicesForSameDay(QTime startTime) |
|
413 { |
|
414 QTime currentTime = QTime::currentTime(); |
|
415 int offset = currentTime.secsTo(startTime); |
|
416 |
|
417 // Disconnect the slot and connect it back again at end to avoid unnecessary |
|
418 // calls to handleReminderIndexChanged slot. Or else the slot gets called |
|
419 // when we add all of items to the repeat combobox. |
|
420 mEditorForm->removeConnection(mReminderItem, |
|
421 SIGNAL(currentIndexChanged(int)), this, |
|
422 SLOT(handleReminderIndexChanged(int))); |
|
423 |
|
424 //The event start time is within 15mins from current time of today, |
|
425 //then we cannot have alarms "15 mins before", "30mins before" and "1 hour before" |
|
426 if (offset <= SecsIn15Mins) |
|
427 { |
|
428 QStringList reminderChoices; |
|
429 //First to clear all items, we just set items with empty list. |
|
430 mReminderItem->setContentWidgetData("items", reminderChoices); |
|
431 reminderChoices << hbTrId("txt_calendar_setlabel_reminder_val_off") |
|
432 << hbTrId("txt_calendar_setlabel_reminder_val_at_the_start"); |
|
433 mReminderItem->setContentWidgetData("items", reminderChoices); |
|
434 } |
|
435 //The event start time is within half and hour from current time of today |
|
436 //then we cannot have alarms "30mins before" and "1 hour before" |
|
437 else if (offset <= SecsIn30Mins) |
|
438 { |
|
439 QStringList reminderChoices; |
|
440 //First to clear all items, we just set items with empty list. |
|
441 mReminderItem->setContentWidgetData("items", reminderChoices); |
|
442 reminderChoices << hbTrId("txt_calendar_setlabel_reminder_val_off") |
|
443 << hbTrId("txt_calendar_setlabel_reminder_val_at_the_start") |
|
444 << hbTrId("txt_calendar_setlabel_reminder_val_15_minutes_befo"); |
|
445 mReminderItem->setContentWidgetData("items", reminderChoices); |
|
446 } |
|
447 //The event start time is within an hour of the current time of today, |
|
448 //then cannot have alarm "1 hour before". |
|
449 else if (offset <= SecsInOneHour) |
|
450 { |
|
451 QStringList reminderChoices; |
|
452 //First to clear all items, we just set items with empty list. |
|
453 mReminderItem->setContentWidgetData("items", reminderChoices); |
|
454 reminderChoices << hbTrId("txt_calendar_setlabel_reminder_val_off") |
|
455 << hbTrId("txt_calendar_setlabel_reminder_val_at_the_start") |
|
456 << hbTrId("txt_calendar_setlabel_reminder_val_15_minutes_befo") |
|
457 << hbTrId("txt_calendar_setlabel_reminder_val_30_minutes_befo"); |
|
458 mReminderItem->setContentWidgetData("items", reminderChoices); |
|
459 } |
|
460 // The event start time is more than one hour from current time |
|
461 // then we can have all choices for alarm. |
|
462 else |
|
463 { |
|
464 QStringList reminderChoices; |
|
465 //First to clear all items, we just set items with empty list. |
|
466 mReminderItem->setContentWidgetData("items", reminderChoices); |
|
467 reminderChoices << hbTrId("txt_calendar_setlabel_reminder_val_off") |
|
468 << hbTrId("txt_calendar_setlabel_reminder_val_at_the_start") |
|
469 << hbTrId("txt_calendar_setlabel_reminder_val_15_minutes_befo") |
|
470 << hbTrId("txt_calendar_setlabel_reminder_val_30_minutes_befo") |
|
471 << hbTrId("txt_calendar_setlabel_reminder_val_1_hour_before"); |
|
472 mReminderItem->setContentWidgetData("items", reminderChoices); |
|
473 } |
|
474 mReminderItem->setEnabled(true); |
|
475 mEditorForm->addConnection(mReminderItem, |
|
476 SIGNAL(currentIndexChanged(int)), this, |
|
477 SLOT(handleReminderIndexChanged(int))); |
|
478 } |
|
479 |
|
480 /*! |
|
481 Updates the reminder choices for an all day event. |
|
482 \param referenceDate to indicate past or not. |
|
483 */ |
|
484 void CalenEditorReminderField::updateReminderChoicesForAllDay(QDate referenceDate) |
|
485 { |
|
486 OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_UPDATEREMINDERCHOICESFORALLDAY_ENTRY ); |
|
487 if (!mReminderTimeAdded){ |
|
488 insertReminderTimeField(); |
|
489 } |
|
490 // This functions rearranges the reminder options based on the date and time |
|
491 // To avoid the unecessary call to handleReminderIndexChanged |
|
492 // the connection is removed. |
|
493 mEditorForm->removeConnection(mReminderItem, |
|
494 SIGNAL(currentIndexChanged(int)), this, |
|
495 SLOT(handleReminderIndexChanged(int))); |
|
496 |
|
497 // Since the combox box is not updated as per the current datetime |
|
498 // there can be a conflict between the previousIndex set on the combobox |
|
499 // and the actual index. This comes while populating an existing entry. |
|
500 // So the index has to be taken from the entry alarm |
|
501 |
|
502 AgendaAlarm actualAlarm = mCalenEditor->editedEntry()->alarm(); |
|
503 // Get the actual alarm index from the entry alarm which is been set |
|
504 int actualIndex = getReminderIndexBasedOnEntryAlarm(); |
|
505 int offsetInMins = actualAlarm.timeOffset(); |
|
506 |
|
507 // Calculate the alarm time |
|
508 QDateTime alarmDateTime; |
|
509 alarmDateTime.setDate(referenceDate); |
|
510 alarmDateTime.setTime(mCalenEditor->editedEntry()->startTime().time()); |
|
511 QTime checkTime = alarmDateTime.time().addSecs(-(offsetInMins * 60)); |
|
512 alarmDateTime.setTime(checkTime); |
|
513 |
|
514 // The combox is updated based on the reference date which is beed passed. |
|
515 // And the reminder time has to be set acoordingly |
|
516 QStringList reminderChoicesForAllDay; |
|
517 QDate tomorrow = QDate::currentDate().addDays(1); |
|
518 QDate theDayAfterTomorrow = QDate::currentDate().addDays(2); |
|
519 |
|
520 // If the event is on a past date the default alarm will be off. |
|
521 if (referenceDate < QDate::currentDate() || |
|
522 referenceDate == QDate::currentDate()) { |
|
523 // Set reminder off for past event. |
|
524 reminderChoicesForAllDay << hbTrId("txt_calendar_setlabel_reminder_val_off"); |
|
525 mReminderItem->setContentWidgetData(QString("items"), |
|
526 reminderChoicesForAllDay); |
|
527 mReminderItem->setEnabled(false); |
|
528 // Remove the reminder field if it was added |
|
529 if(mReminderTimeAdded) { |
|
530 removeReminderTimeField(); |
|
531 } |
|
532 } else if (theDayAfterTomorrow < referenceDate) { |
|
533 // If the event is on a future date which is two days after the current date |
|
534 // The options are off, on event day, 1 day before and 2 days before |
|
535 reminderChoicesForAllDay |
|
536 << hbTrId("txt_calendar_setlabel_reminder_val_off") |
|
537 << hbTrId("txt_calendar_setlabel_reminder_val_on_event_day") |
|
538 << hbTrId("txt_calendar_setlabel_reminder_val_1_day_before") |
|
539 << hbTrId("txt_calendar_setlabel_reminder_val_2_days_before"); |
|
540 mReminderItem->setEnabled(true); |
|
541 mCustomReminderTimeItem->setEnabled(true); |
|
542 mReminderItem->setContentWidgetData(QString("items"), |
|
543 reminderChoicesForAllDay); |
|
544 } else if (theDayAfterTomorrow == referenceDate) { |
|
545 // If the event is on a future date which is two days after the current date |
|
546 // If the current time is before 6.00 pm (default for 2 days before) |
|
547 // The options are off, on event day, 1 day before and 2 days before |
|
548 if (QTime::currentTime() < QTime(18, 0, 0, 0)) { |
|
549 reminderChoicesForAllDay |
|
550 << hbTrId("txt_calendar_setlabel_reminder_val_off") |
|
551 << hbTrId("txt_calendar_setlabel_reminder_val_on_event_day") |
|
552 << hbTrId("txt_calendar_setlabel_reminder_val_1_day_before") |
|
553 << hbTrId("txt_calendar_setlabel_reminder_val_2_days_before"); |
|
554 }else { |
|
555 // If the event is on a future date which is two days after the current date |
|
556 // the current time is after 6.00 pm (default for 2 days before) |
|
557 // If its after the default time don't show the 2 days before option |
|
558 reminderChoicesForAllDay |
|
559 << hbTrId("txt_calendar_setlabel_reminder_val_off") |
|
560 << hbTrId("txt_calendar_setlabel_reminder_val_on_event_day") |
|
561 << hbTrId("txt_calendar_setlabel_reminder_val_1_day_before"); |
|
562 } |
|
563 mReminderItem->setEnabled(true); |
|
564 mCustomReminderTimeItem->setEnabled(true); |
|
565 mReminderItem->setContentWidgetData(QString("items"), |
|
566 reminderChoicesForAllDay); |
|
567 }else if (QTime::currentTime() < QTime(18, 0, 0, 0)) { |
|
568 // If the event is on a future date which is one day after the current date |
|
569 // and current time is before 6.00 pm. |
|
570 // The options are off, on event day and 1 day before |
|
571 reminderChoicesForAllDay |
|
572 << hbTrId("txt_calendar_setlabel_reminder_val_off") |
|
573 << hbTrId("txt_calendar_setlabel_reminder_val_on_event_day") |
|
574 << hbTrId("txt_calendar_setlabel_reminder_val_1_day_before"); |
|
575 mReminderItem->setEnabled(true); |
|
576 mCustomReminderTimeItem->setEnabled(true); |
|
577 mReminderItem->setContentWidgetData(QString("items"), |
|
578 reminderChoicesForAllDay); |
|
579 }else { |
|
580 // If the event is on a future date which is one day after the current date |
|
581 // and current time is after 6.00 pm. |
|
582 // The options are off and on event day |
|
583 reminderChoicesForAllDay |
|
584 << hbTrId("txt_calendar_setlabel_reminder_val_off") |
|
585 << hbTrId("txt_calendar_setlabel_reminder_val_on_event_day"); |
|
586 mReminderItem->setEnabled(true); |
|
587 mCustomReminderTimeItem->setEnabled(true); |
|
588 mReminderItem->setContentWidgetData(QString("items"), |
|
589 reminderChoicesForAllDay); |
|
590 } |
|
591 // Get the count of the reminder options after the rearrangement |
|
592 // based on the date and time |
|
593 int count = reminderItemsCount(); |
|
594 // Set the reminder index |
|
595 |
|
596 if (count <= actualIndex || |
|
597 alarmDateTime < QDateTime::currentDateTime() || |
|
598 actualIndex == ReminderOff) { |
|
599 // This will be executed when the actual index is not |
|
600 // available in the combobox or the alarm time is already passed |
|
601 // or the actual alarm is off |
|
602 // So set it as off |
|
603 mReminderItem->setContentWidgetData("currentIndex", ReminderOff); |
|
604 actualAlarm = AgendaAlarm(); |
|
605 mCalenEditor->editedEntry()->setAlarm(actualAlarm); |
|
606 removeReminderTimeField(); |
|
607 }else { |
|
608 // Set the actual reminder index |
|
609 mReminderItem->setContentWidgetData("currentIndex", actualIndex); |
|
610 if( actualIndex != ReminderOff) { |
|
611 if(!mReminderTimeAdded) { |
|
612 insertReminderTimeField(); |
|
613 } |
|
614 mCalenEditor->editedEntry()->setAlarm(actualAlarm); |
|
615 // Get the alarm time from the offset |
|
616 QTime alarmTime = alarmDateTime.time(); |
|
617 // Set the alarm time and display it on the button |
|
618 mReminderTimeForAllDay.setHMS( |
|
619 alarmTime.hour(),alarmTime.minute(),alarmTime.second()); |
|
620 setDisplayTime(); |
|
621 }else { |
|
622 actualAlarm = AgendaAlarm(); |
|
623 removeReminderTimeField(); |
|
624 } |
|
625 } |
|
626 // Connect the slot for the index change |
|
627 mEditorForm->addConnection(mReminderItem, |
|
628 SIGNAL(currentIndexChanged(int)), this, |
|
629 SLOT(handleReminderIndexChanged(int))); |
|
630 |
|
631 OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_UPDATEREMINDERCHOICESFORALLDAY_EXIT ); |
|
632 } |
|
633 |
|
634 /*! |
|
635 Gets the reminder index for all day events based on the alarm |
|
636 which is saved for the entry |
|
637 */ |
|
638 int CalenEditorReminderField::getReminderIndexBasedOnEntryAlarm() |
|
639 { |
|
640 // Get the appropriate reminder index depending on the value of time offset. |
|
641 AgendaAlarm actualAlarm = mCalenEditor->editedEntry()->alarm(); |
|
642 QTime referenceTime(0, 0, 0); |
|
643 int index = ReminderOff; |
|
644 int offsetInMins = actualAlarm.timeOffset(); |
|
645 if(offsetInMins == -1) { |
|
646 index = ReminderOff; |
|
647 }else if (offsetInMins < 0 || offsetInMins == 0) { |
|
648 index = ReminderOnEventDay; |
|
649 mReminderTimeForAllDay = referenceTime.addSecs(-(offsetInMins |
|
650 * 60)); |
|
651 } else if (offsetInMins <= numberOfMinutesInADay) { |
|
652 index = ReminderOneDayBefore; |
|
653 mReminderTimeForAllDay = referenceTime.addSecs(-(offsetInMins |
|
654 * 60)); |
|
655 } else { |
|
656 index = ReminderTwoDaysBefore; |
|
657 offsetInMins %= (24 * 60); |
|
658 mReminderTimeForAllDay = referenceTime.addSecs(-(offsetInMins |
|
659 * 60)); |
|
660 } |
|
661 return index; |
|
662 } |
|
663 |
|
664 /*! |
|
665 Insert the reminder time field for an all day event. |
|
666 */ |
|
667 void CalenEditorReminderField::insertReminderTimeField() |
|
668 { |
|
669 OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_INSERTREMINDERTIMEFIELD_ENTRY ); |
|
670 HbDataFormModelItem::DataItemType itemType = |
|
671 static_cast<HbDataFormModelItem::DataItemType> (ReminderTimeOffset); |
|
672 |
|
673 // If all day item is not added then insert at one level before. |
|
674 int index = CalenEditorPrivate::ReminderTimeForAllDayItem; |
|
675 if(!mCalenEditor->isAllDayFieldAdded()) { |
|
676 index = CalenEditorPrivate::ReminderTimeForAllDayItem - 1; |
|
677 } |
|
678 mCustomReminderTimeItem = mCalenEditorModel->insertDataFormItem( |
|
679 index, |
|
680 itemType, |
|
681 QString(hbTrId("txt_calendar_setlabel_reminder_time")), |
|
682 mCalenEditorModel->invisibleRootItem()); |
|
683 if (currentReminderIndex() != 1){ |
|
684 mReminderTimeForAllDay.setHMS(18,0,0,0); |
|
685 } else { |
|
686 mReminderTimeForAllDay.setHMS(8,0,0,0); |
|
687 } |
|
688 |
|
689 mEditorForm->addConnection(mCustomReminderTimeItem, SIGNAL(clicked()), |
|
690 this, SLOT(launchReminderTimePicker())); |
|
691 setDisplayTime(); |
|
692 mReminderTimeAdded = true; |
|
693 OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_INSERTREMINDERTIMEFIELD_EXIT ); |
|
694 } |
|
695 |
|
696 /*! |
|
697 Set the reminder time selected by the user. |
|
698 */ |
|
699 void CalenEditorReminderField::setDisplayTime() |
|
700 { |
|
701 OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_SETDISPLAYTIME_ENTRY ); |
|
702 HbExtendedLocale locale = HbExtendedLocale::system(); |
|
703 QString timeString = locale.format( |
|
704 mReminderTimeForAllDay, |
|
705 r_qtn_time_usual_with_zero); |
|
706 mCustomReminderTimeItem->setContentWidgetData("text", timeString); |
|
707 OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_SETDISPLAYTIME_EXIT ); |
|
708 } |
|
709 |
|
710 /*! |
|
711 Remove the reminder time field if its not an all day event. |
|
712 */ |
|
713 void CalenEditorReminderField::removeReminderTimeField() |
|
714 { |
|
715 OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_REMOVEREMINDERTIMEFIELD_ENTRY ); |
|
716 mReminderTimeAdded = false; |
|
717 mEditorForm->removeConnection(mCustomReminderTimeItem, SIGNAL(clicked()), |
|
718 this, SLOT(launchReminderTimePicker())); |
|
719 if (mCustomReminderTimeItem) { |
|
720 QModelIndex reminderIndex = |
|
721 mCalenEditorModel->indexFromItem(mCustomReminderTimeItem); |
|
722 mCalenEditorModel->removeItem( |
|
723 mCalenEditorModel->index( |
|
724 reminderIndex.row(), 0)); |
|
725 mCustomReminderTimeItem = 0; |
|
726 } |
|
727 OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_REMOVEREMINDERTIMEFIELD_EXIT ); |
|
728 } |
|
729 |
|
730 /*! |
|
731 Launches time picker to select time. |
|
732 */ |
|
733 void CalenEditorReminderField::launchReminderTimePicker() |
|
734 { |
|
735 OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_LAUNCHREMINDERTIMEPICKER_ENTRY ); |
|
736 |
|
737 HbDialog *popUp = new HbDialog(); |
|
738 popUp->setDismissPolicy(HbDialog::NoDismiss); |
|
739 popUp->setTimeout(HbDialog::NoTimeout); |
|
740 popUp->setAttribute( Qt::WA_DeleteOnClose, true ); |
|
741 popUp->setHeadingWidget( new HbLabel( |
|
742 hbTrId("Reminder Time"))); |
|
743 |
|
744 HbExtendedLocale locale = HbExtendedLocale::system(); |
|
745 mTimePicker = new HbDateTimePicker(mReminderTimeForAllDay); |
|
746 // Set the display format |
|
747 if(locale.timeStyle() == HbExtendedLocale::Time12) { |
|
748 mTimePicker->setDisplayFormat("hh:mm ap"); |
|
749 }else { |
|
750 mTimePicker->setDisplayFormat("hh:mm"); |
|
751 } |
|
752 |
|
753 // Check if the entry is repeating based on the repeatuntil item |
|
754 if(!mCalenEditor->isRepeatUntilItemAdded()) { |
|
755 int index = currentReminderIndex(); |
|
756 QDate checkDate = mCalenEditor->editedEntry()->startTime().date(); |
|
757 // Restrict the time picker to show the valid time |
|
758 // depending on the reminder options |
|
759 // Take an offset of 5 mins |
|
760 QTime minTime = QTime::currentTime().addSecs(5 * 60); |
|
761 if(index == ReminderTwoDaysBefore && checkDate.addDays(-2) == QDate::currentDate()) { |
|
762 mTimePicker->setMinimumTime(minTime); |
|
763 }else if(index == ReminderOneDayBefore && checkDate.addDays(-1) == QDate::currentDate()) { |
|
764 mTimePicker->setMinimumTime(minTime); |
|
765 }else if(index == ReminderOnEventDay && checkDate == QDate::currentDate()) { |
|
766 mTimePicker->setMinimumTime(minTime); |
|
767 } |
|
768 } |
|
769 mTimePicker->setTime(mReminderTimeForAllDay); |
|
770 popUp->setContentWidget(mTimePicker); |
|
771 |
|
772 HbAction *okAction = new HbAction(hbTrId("txt_common_button_ok"), popUp); |
|
773 popUp->addAction(okAction); |
|
774 connect(okAction, SIGNAL(triggered()), this, SLOT(setReminderTimeForAllDay())); |
|
775 popUp->addAction(new HbAction(hbTrId("txt_common_button_cancel"), |
|
776 popUp)); |
|
777 popUp->open(); |
|
778 OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_LAUNCHREMINDERTIMEPICKER_EXIT ); |
|
779 } |
|
780 |
|
781 /*! |
|
782 Set the reminder time chosen. |
|
783 */ |
|
784 void CalenEditorReminderField::setReminderTimeForAllDay() |
|
785 { |
|
786 OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_SETREMINDERTIMEFORALLDAY_ENTRY ); |
|
787 mReminderTimeForAllDay = mTimePicker->time(); |
|
788 if (mReminderTimeForAllDay.isValid()) { |
|
789 // Change the time displayed to that selected by the user. |
|
790 setDisplayTime(); |
|
791 int offset = 0; |
|
792 if (currentReminderIndex() == ReminderOneDayBefore) { |
|
793 offset = 1; |
|
794 } else if (currentReminderIndex() == ReminderTwoDaysBefore) { |
|
795 offset = 2; |
|
796 } |
|
797 QDateTime startDateTimeForAllDay( |
|
798 mCalenEditor->editedEntry()->startTime().date(), QTime(0, 0, 0)); |
|
799 QDateTime reminderDateTimeForAllDay; |
|
800 reminderDateTimeForAllDay.setDate( |
|
801 mCalenEditor->editedEntry()->startTime().date().addDays( |
|
802 -offset)); |
|
803 reminderDateTimeForAllDay.setTime(mReminderTimeForAllDay); |
|
804 int seconds = |
|
805 reminderDateTimeForAllDay.secsTo(startDateTimeForAllDay); |
|
806 int timeOffset = seconds / 60; |
|
807 mCustomReminderTimeItem->setEnabled(true); |
|
808 AgendaAlarm reminder; |
|
809 reminder.setTimeOffset(timeOffset); |
|
810 reminder.setAlarmSoundName(QString(" ")); |
|
811 // Set the reminder to the entry. |
|
812 mCalenEditor->editedEntry()->setAlarm(reminder); |
|
813 } |
|
814 OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_SETREMINDERTIMEFORALLDAY_EXIT ); |
|
815 } |
|
816 |
|
817 /*! |
|
818 Checks if reminder field is enabled or not. |
|
819 */ |
|
820 bool CalenEditorReminderField::isReminderFieldEnabled() |
|
821 { |
|
822 OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_ISREMINDERFIELDENABLED_ENTRY ); |
|
823 return mReminderItem->isEnabled(); |
|
824 } |
|
825 |
|
826 /*! |
|
827 Returns the number of items present in the reminder option. |
|
828 */ |
|
829 int CalenEditorReminderField::reminderItemsCount() |
|
830 { |
|
831 OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_REMINDERITEMSCOUNT_ENTRY ); |
|
832 QVariant strings = mReminderItem->contentWidgetData("items"); |
|
833 QStringList stringList(strings.toStringList()); |
|
834 int count = stringList.count(); |
|
835 OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_REMINDERITEMSCOUNT_EXIT ); |
|
836 return count; |
|
837 } |
|
838 |
|
839 /*! |
|
840 Returns the current chosen index. |
|
841 */ |
|
842 int CalenEditorReminderField::currentReminderIndex() |
|
843 { |
|
844 OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_CURRENTREMINDERINDEX_ENTRY ); |
|
845 QVariant countVariant = mReminderItem->contentWidgetData("currentIndex"); |
|
846 int index = countVariant.toInt(); |
|
847 OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_CURRENTREMINDERINDEX_EXIT ); |
|
848 return index; |
|
849 } |
|
850 |
|
851 /*! |
|
852 Sets the chosen index as current index. |
|
853 /param index indicates the idex value to be set. |
|
854 */ |
|
855 void CalenEditorReminderField::setCurrentIndex(int index) |
|
856 { |
|
857 OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_SETCURRENTINDEX_ENTRY ); |
|
858 mReminderItem->setContentWidgetData("currentIndex", index); |
|
859 OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_SETCURRENTINDEX_EXIT ); |
|
860 } |
|
861 |
|
862 /*! |
|
863 Disables the reminder time field. |
|
864 */ |
|
865 void CalenEditorReminderField::disableReminderTimeField() |
|
866 { |
|
867 OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_DISABLEREMINDERTIMEFIELD_ENTRY ); |
|
868 if (mReminderTimeAdded) { |
|
869 mCustomReminderTimeItem->setEnabled(false); |
|
870 } |
|
871 OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_DISABLEREMINDERTIMEFIELD_EXIT ); |
|
872 } |
|
873 |
|
874 /*! |
|
875 Checks if reminder time field is added or not. |
|
876 */ |
|
877 bool CalenEditorReminderField::isReminderTimeForAllDayAdded() |
|
878 { |
|
879 OstTraceFunctionEntry0( CALENEDITORREMINDERFIELD_ISREMINDERTIMEFORALLDAYADDED_ENTRY ); |
|
880 OstTraceFunctionExit0( CALENEDITORREMINDERFIELD_ISREMINDERTIMEFORALLDAYADDED_EXIT ); |
|
881 return mReminderTimeAdded; |
|
882 } |
|
883 |
|
884 // End of file --Don't remove this. |