|
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 * Definition of CalenEditorRepeatField class. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // System Includes |
|
21 #include <QDate> |
|
22 #include <hbdataformmodelitem.h> |
|
23 #include <hbdataformviewitem.h> |
|
24 #include <hbdataformmodel.h> |
|
25 #include <hbdataform.h> |
|
26 #include <hbcombobox.h> |
|
27 #include <hblabel.h> |
|
28 #include <hbdatetimepicker.h> |
|
29 #include <hbaction.h> |
|
30 #include <agendautil.h> |
|
31 |
|
32 // User Included |
|
33 #include "caleneditorrepeatfield.h" |
|
34 #include "caleneditorcustomitem.h" |
|
35 #include "caleneditorreminderfield.h" |
|
36 #include "calendateutils.h" |
|
37 #include "OstTraceDefinitions.h" |
|
38 #ifdef OST_TRACE_COMPILER_IN_USE |
|
39 #include "caleneditorrepeatfieldTraces.h" |
|
40 #endif |
|
41 |
|
42 |
|
43 // Constants |
|
44 const int userRole = Qt::UserRole + 100; |
|
45 |
|
46 /*! |
|
47 \class CalenEditorRepeatField |
|
48 */ |
|
49 /*! |
|
50 \enum CalenEditorRepeatField::RepeatTypes |
|
51 This enum defines the different repeat types of an entry |
|
52 */ |
|
53 /*! |
|
54 \var CalenEditorRepeatField::RepeatTypes CalenEditorRepeatField::RepeatOnce |
|
55 No repeating type. |
|
56 */ |
|
57 /*! |
|
58 \var CalenEditorRepeatField::RepeatTypes CalenEditorRepeatField::RepeatDaily |
|
59 Daily repeating type. |
|
60 */ |
|
61 /*! |
|
62 \var CalenEditorRepeatField::RepeatTypes CalenEditorRepeatField::RepeatWorkdays |
|
63 Workdays repeating type. |
|
64 */ |
|
65 /*! |
|
66 \var CalenEditorRepeatField::RepeatTypes CalenEditorRepeatField::RepeatWeekly |
|
67 Weekly repeating type. |
|
68 */ |
|
69 /*! |
|
70 \var CalenEditorRepeatField::RepeatTypes CalenEditorRepeatField::RepeatBiWeekly |
|
71 Fortnightly repeating type. |
|
72 */ |
|
73 /*! |
|
74 \var CalenEditorRepeatField::RepeatTypes CalenEditorRepeatField::RepeatMonthly |
|
75 Monthly repeating type. |
|
76 */ |
|
77 /*! |
|
78 \var CalenEditorRepeatField::RepeatTypes CalenEditorRepeatField::RepeatYearly |
|
79 Yearly repeating type. |
|
80 */ |
|
81 |
|
82 /*! |
|
83 Constructor. |
|
84 |
|
85 \param parent QObject pointer |
|
86 */ |
|
87 |
|
88 CalenEditorRepeatField::CalenEditorRepeatField(CalenEditorPrivate* calenEditor, |
|
89 HbDataForm* form, |
|
90 HbDataFormModel* model, |
|
91 QObject *parent) |
|
92 :QObject(parent), |
|
93 mCalenEditor(calenEditor), |
|
94 mEditorForm(form), |
|
95 mCalenEditorModel(model), |
|
96 mRepeatItem(0), |
|
97 mRepeatComboBox(0), |
|
98 mCustomRepeatUntilItem(0), |
|
99 mRepeatRoleValue(0), |
|
100 mIsBiWeekly(false), |
|
101 mIsWorkdays(false), |
|
102 mRepeatUntilItemAdded(false) |
|
103 { |
|
104 OstTraceFunctionEntry0( CALENEDITORREPEATFIELD_CALENEDITORREPEATFIELD_ENTRY ); |
|
105 if (!mCalenEditor->editedEntry()->repeatRule().isNull()) { |
|
106 mRepeatRuleType = mCalenEditor->editedEntry()->repeatRule().type(); |
|
107 mRepeatUntilDate = mCalenEditor->editedEntry()->repeatRule().until().date(); |
|
108 } |
|
109 |
|
110 mRepeatItem = new HbDataFormModelItem(); |
|
111 mRepeatItem->setType(HbDataFormModelItem::ComboBoxItem); |
|
112 mRepeatItem->setData(HbDataFormModelItem::LabelRole, |
|
113 hbTrId("txt_calendar_setlabel_repeat")); |
|
114 |
|
115 // Create the repeat choices |
|
116 QStringList repeatChoices; |
|
117 repeatChoices << hbTrId("txt_calendar_setlabel_repeat_val_only_once") |
|
118 << hbTrId("txt_calendar_setlabel_repeat_val_daily") |
|
119 << hbTrId("txt_calendar_setlabel_repeat_val_workdays") |
|
120 << hbTrId("txt_calendar_setlabel_repeat_val_weekly") |
|
121 << hbTrId("txt_calendar_setlabel_repeat_val_fortnightly") |
|
122 << hbTrId("txt_calendar_setlabel_repeat_val_monthly") |
|
123 << hbTrId("txt_calendar_setlabel_repeat_val_yearly"); |
|
124 |
|
125 mRepeatItem->setContentWidgetData("items", repeatChoices); |
|
126 mRepeatItem->setContentWidgetData("objectName", "repeatItem"); |
|
127 mCalenEditorModel->appendDataFormItem( mRepeatItem, |
|
128 mCalenEditorModel->invisibleRootItem()); |
|
129 OstTraceFunctionExit0( CALENEDITORREPEATFIELD_CALENEDITORREPEATFIELD_EXIT ); |
|
130 } |
|
131 |
|
132 /*! |
|
133 Destructor |
|
134 */ |
|
135 CalenEditorRepeatField::~CalenEditorRepeatField() |
|
136 { |
|
137 OstTraceFunctionEntry0( DUP1_CALENEDITORREPEATFIELD_CALENEDITORREPEATFIELD_ENTRY ); |
|
138 // Nothing Yet |
|
139 OstTraceFunctionExit0( DUP1_CALENEDITORREPEATFIELD_CALENEDITORREPEATFIELD_EXIT ); |
|
140 } |
|
141 |
|
142 /*! |
|
143 Adds repeat item to the model |
|
144 */ |
|
145 void CalenEditorRepeatField::addItemToModel() |
|
146 { |
|
147 OstTraceFunctionEntry0( CALENEDITORREPEATFIELD_ADDITEMTOMODEL_ENTRY ); |
|
148 // Add reminder to the model |
|
149 mCalenEditorModel->appendDataFormItem( mRepeatItem, |
|
150 mCalenEditorModel->invisibleRootItem()); |
|
151 OstTraceFunctionExit0( CALENEDITORREPEATFIELD_ADDITEMTOMODEL_EXIT ); |
|
152 } |
|
153 |
|
154 /*! |
|
155 Removes the repeat item from the model |
|
156 */ |
|
157 void CalenEditorRepeatField::removeItemFromModel() |
|
158 { |
|
159 OstTraceFunctionEntry0( CALENEDITORREPEATFIELD_REMOVEITEMFROMMODEL_ENTRY ); |
|
160 mCalenEditorModel->removeItem(modelIndex()); |
|
161 OstTraceFunctionExit0( CALENEDITORREPEATFIELD_REMOVEITEMFROMMODEL_EXIT ); |
|
162 } |
|
163 |
|
164 /*! |
|
165 Populates repeat item with the options available |
|
166 \param index index at which repeat item needs to be added |
|
167 */ |
|
168 void CalenEditorRepeatField::populateRepeatItem(int index) |
|
169 { |
|
170 OstTraceFunctionEntry0( CALENEDITORREPEATFIELD_POPULATEREPEATITEM_ENTRY ); |
|
171 HbDataFormViewItem |
|
172 *item = |
|
173 qobject_cast<HbDataFormViewItem *> ( |
|
174 mEditorForm->itemByIndex( |
|
175 mCalenEditorModel->index( index, 0))); |
|
176 mRepeatComboBox |
|
177 = qobject_cast<HbComboBox *> (item->dataItemContentWidget()); |
|
178 |
|
179 // Set the user roles for the combobox items so that we depend on these |
|
180 // roles to identify the correct repeat type when repeat choices are |
|
181 // dynamically removed or added |
|
182 mRepeatComboBox->setItemData(RepeatOnce, RepeatOnce, userRole); |
|
183 mRepeatComboBox->setItemData(RepeatDaily, RepeatDaily, userRole); |
|
184 mRepeatComboBox->setItemData(RepeatWorkdays, |
|
185 RepeatWorkdays, userRole); |
|
186 mRepeatComboBox->setItemData(RepeatWeekly, RepeatWeekly, userRole); |
|
187 mRepeatComboBox->setItemData(RepeatBiWeekly, |
|
188 RepeatBiWeekly, userRole); |
|
189 mRepeatComboBox->setItemData(RepeatMonthly, |
|
190 RepeatMonthly, userRole); |
|
191 mRepeatComboBox->setItemData(RepeatYearly, RepeatYearly, userRole); |
|
192 |
|
193 if (mCalenEditor->editedEntry()->isRepeating()) { |
|
194 switch (mCalenEditor->editedEntry()->repeatRule().type()) { |
|
195 case AgendaRepeatRule::DailyRule: { |
|
196 mRepeatComboBox->setCurrentIndex(DailyRole); |
|
197 } |
|
198 break; |
|
199 case AgendaRepeatRule::WeeklyRule: { |
|
200 bool isWorkdays = AgendaUtil::isWorkdaysRepeatingEntry( |
|
201 mCalenEditor->editedEntry()->repeatRule()); |
|
202 if (isWorkdays) { |
|
203 mRepeatComboBox->setCurrentIndex(WorkdaysRole); |
|
204 mIsWorkdays = true; |
|
205 } else { |
|
206 if (mCalenEditor->editedEntry()->repeatRule().interval() == 1) { |
|
207 mRepeatComboBox->setCurrentIndex(WeeklyRole); |
|
208 } else { |
|
209 mRepeatComboBox->setCurrentIndex(BiWeeklyRole); |
|
210 mIsBiWeekly = true; |
|
211 } |
|
212 } |
|
213 } |
|
214 break; |
|
215 case AgendaRepeatRule::MonthlyRule: { |
|
216 mRepeatComboBox->setCurrentIndex(MonthlyRole); |
|
217 } |
|
218 break; |
|
219 case AgendaRepeatRule::YearlyRule: { |
|
220 mRepeatComboBox->setCurrentIndex(YearlyRole); |
|
221 } |
|
222 break; |
|
223 default: |
|
224 break; |
|
225 } |
|
226 // If entry is repeating type then insert the repeatuntil item. |
|
227 insertRepeatUntilItem(); |
|
228 } else { |
|
229 mRepeatComboBox->setCurrentIndex(0); |
|
230 // Set the Original entry value also. |
|
231 mCalenEditor->originalEntry()->setRepeatRule( |
|
232 AgendaRepeatRule( |
|
233 AgendaRepeatRule::InvalidRule)); |
|
234 } |
|
235 // Connect the slot once the updation of mRepeatComboBox is done |
|
236 connect(mRepeatComboBox, SIGNAL(currentIndexChanged(int)), this, |
|
237 SLOT(handleRepeatIndexChanged(int))); |
|
238 // Update the repeat choices depending upon the duration |
|
239 updateRepeatChoices(); |
|
240 OstTraceFunctionExit0( CALENEDITORREPEATFIELD_POPULATEREPEATITEM_EXIT ); |
|
241 } |
|
242 |
|
243 /*! |
|
244 Removes the repeat until item from the model |
|
245 and removed the connection for date picker launch too. |
|
246 */ |
|
247 void CalenEditorRepeatField::removeRepeatUntilItem() |
|
248 { |
|
249 mRepeatRuleType = AgendaRepeatRule::InvalidRule; |
|
250 if (mRepeatUntilItemAdded) { |
|
251 mEditorForm->removeConnection(mCustomRepeatUntilItem, SIGNAL(clicked()), |
|
252 this, SLOT(launchRepeatUntilDatePicker())); |
|
253 QModelIndex repeatIndex = |
|
254 mCalenEditorModel->indexFromItem(mRepeatItem); |
|
255 mCalenEditorModel->removeItem( |
|
256 mCalenEditorModel->index( |
|
257 repeatIndex.row()+ 1, 0)); |
|
258 mRepeatUntilItemAdded = false; |
|
259 mCustomRepeatUntilItem = 0; |
|
260 } |
|
261 } |
|
262 |
|
263 /*! |
|
264 Triggerd from tapping on reminder item. |
|
265 Handles the reminder time change and updates the same in the event. |
|
266 \param index The new index chosen in the reminder list. |
|
267 */ |
|
268 void CalenEditorRepeatField::handleRepeatIndexChanged(int index) |
|
269 { |
|
270 OstTraceFunctionEntry0( CALENEDITORREPEATFIELD_HANDLEREPEATINDEXCHANGED_ENTRY ); |
|
271 mIsBiWeekly = false; |
|
272 mIsWorkdays = false; |
|
273 |
|
274 HbExtendedLocale locale = HbExtendedLocale::system(); |
|
275 // Get the user role we have set for this index |
|
276 QVariant role = mRepeatComboBox->itemData(index, userRole); |
|
277 int value = role.toInt(); |
|
278 |
|
279 // Boolean to check if the repeating property of the entry is changed. |
|
280 // based on the value and mRepeatUntilItemAdded |
|
281 // ie. From repeating to non repeating OR vice versa OR No change |
|
282 bool repeatPropertyChange = false; |
|
283 if (value > 0 && value <= 6 && !mRepeatUntilItemAdded) { |
|
284 // Non repeating to repeating |
|
285 repeatPropertyChange = true; |
|
286 }else if(mRepeatUntilItemAdded && value == 0) { |
|
287 // Repeating to non repeating |
|
288 repeatPropertyChange = true; |
|
289 }else { |
|
290 // No change in repeat value |
|
291 repeatPropertyChange = false; |
|
292 } |
|
293 QDate repeatUntilDate = mRepeatUntilDate; |
|
294 // Update the repeat type only if its has been changed |
|
295 // ie. if the previous repeatrole is different from the current repeat role |
|
296 if (value != mRepeatRoleValue) { |
|
297 mRepeatRoleValue = value; |
|
298 switch (value) { |
|
299 case DailyRole: { |
|
300 if (!mRepeatUntilItemAdded) { |
|
301 insertRepeatUntilItem(); |
|
302 } |
|
303 if (mCustomRepeatUntilItem) { |
|
304 // Show default repeat until date till one year for daily rule |
|
305 mRepeatUntilDate = |
|
306 mCalenEditor->editedEntry()->startTime().date().addYears(1); |
|
307 mCustomRepeatUntilItem->setContentWidgetData( "text", |
|
308 locale.format( |
|
309 mRepeatUntilDate, r_qtn_date_usual_with_zero)); |
|
310 } |
|
311 mRepeatRuleType = AgendaRepeatRule::DailyRule; |
|
312 } |
|
313 break; |
|
314 case WorkdaysRole: { |
|
315 if (!mRepeatUntilItemAdded) { |
|
316 insertRepeatUntilItem(); |
|
317 } |
|
318 if (mCustomRepeatUntilItem) { |
|
319 // Show default repeat until date till one year for workdays rule |
|
320 mRepeatUntilDate = |
|
321 mCalenEditor->editedEntry()->startTime().date().addYears(1); |
|
322 mCustomRepeatUntilItem->setContentWidgetData( "text", |
|
323 locale.format( |
|
324 mRepeatUntilDate, r_qtn_date_usual_with_zero)); |
|
325 } |
|
326 mRepeatRuleType = AgendaRepeatRule::WeeklyRule; |
|
327 mIsWorkdays = true; |
|
328 } |
|
329 break; |
|
330 case WeeklyRole: { |
|
331 if (!mRepeatUntilItemAdded) { |
|
332 insertRepeatUntilItem(); |
|
333 } |
|
334 if (mCustomRepeatUntilItem) { |
|
335 // Show default repeat until date till one year for weekly rule |
|
336 mRepeatUntilDate = |
|
337 mCalenEditor->editedEntry()->startTime().date().addYears(1); |
|
338 mCustomRepeatUntilItem->setContentWidgetData( "text", |
|
339 locale.format( |
|
340 mRepeatUntilDate, r_qtn_date_usual_with_zero)); |
|
341 } |
|
342 mRepeatRuleType = AgendaRepeatRule::WeeklyRule; |
|
343 } |
|
344 break; |
|
345 case BiWeeklyRole: { |
|
346 if (!mRepeatUntilItemAdded) { |
|
347 insertRepeatUntilItem(); |
|
348 } |
|
349 if (mCustomRepeatUntilItem) { |
|
350 // Show default repeat until date till one year for bi-weekly rule |
|
351 mRepeatUntilDate = |
|
352 mCalenEditor->editedEntry()->startTime().date().addYears(1); |
|
353 mCustomRepeatUntilItem->setContentWidgetData( "text", |
|
354 locale.format( |
|
355 mRepeatUntilDate, r_qtn_date_usual_with_zero)); |
|
356 } |
|
357 mRepeatRuleType = AgendaRepeatRule::WeeklyRule; |
|
358 mIsBiWeekly = true; |
|
359 } |
|
360 break; |
|
361 case MonthlyRole: { |
|
362 if (!mRepeatUntilItemAdded) { |
|
363 insertRepeatUntilItem(); |
|
364 } |
|
365 if (mCustomRepeatUntilItem) { |
|
366 // Show default repeat until date till one year for monthly rule |
|
367 mRepeatUntilDate = |
|
368 mCalenEditor->editedEntry()->startTime().date().addYears(1); |
|
369 mCustomRepeatUntilItem->setContentWidgetData( "text", |
|
370 locale.format( |
|
371 mRepeatUntilDate, r_qtn_date_usual_with_zero)); |
|
372 } |
|
373 mRepeatRuleType = AgendaRepeatRule::MonthlyRule; |
|
374 } |
|
375 break; |
|
376 case YearlyRole: { |
|
377 if (!mRepeatUntilItemAdded) { |
|
378 insertRepeatUntilItem(); |
|
379 } |
|
380 if (mCustomRepeatUntilItem) { |
|
381 // Show default repeat until date till ten years for yearly rule |
|
382 mRepeatUntilDate = |
|
383 mCalenEditor->editedEntry()->startTime().date().addYears(10); |
|
384 mCustomRepeatUntilItem->setContentWidgetData( "text", |
|
385 locale.format( |
|
386 mRepeatUntilDate, r_qtn_date_usual_with_zero)); |
|
387 } |
|
388 mRepeatRuleType = AgendaRepeatRule::YearlyRule; |
|
389 } |
|
390 break; |
|
391 default: { |
|
392 removeRepeatUntilItem(); |
|
393 } |
|
394 break; |
|
395 } |
|
396 } |
|
397 if(!mCalenEditor->isNewEntry()) { |
|
398 mCalenEditor->addDiscardAction(); |
|
399 } |
|
400 // Depending on repeatPropertyChange value and the repeatuntil date change |
|
401 // the reminder choices are updated |
|
402 if(repeatPropertyChange || repeatUntilDate != mRepeatUntilDate) { |
|
403 mCalenEditor->updateReminderChoices(); |
|
404 // Once the entry is changed from non repeating to repeating |
|
405 // and if the alarm set is off |
|
406 // Then change the reminder option to the default 'one day before' |
|
407 // if the option is valid |
|
408 if (mCalenEditor->isAllDayEvent() && |
|
409 repeatPropertyChange && mRepeatUntilItemAdded) { |
|
410 if(!mCalenEditor->isReminderTimeForAllDayAdded() && |
|
411 mCalenEditor->getReminderCount() >= 3) { |
|
412 mCalenEditor->setCurrentIndexOfReminderField( |
|
413 CalenEditorReminderField::ReminderOneDayBefore); |
|
414 } |
|
415 } |
|
416 } |
|
417 OstTraceFunctionExit0( CALENEDITORREPEATFIELD_HANDLEREPEATINDEXCHANGED_EXIT ); |
|
418 } |
|
419 |
|
420 /*! |
|
421 Returns model index of the repeat item |
|
422 \return Model index of the repeat item |
|
423 */ |
|
424 QModelIndex CalenEditorRepeatField::modelIndex() |
|
425 { |
|
426 OstTraceFunctionEntry0( CALENEDITORREPEATFIELD_MODELINDEX_ENTRY ); |
|
427 return mCalenEditorModel->indexFromItem(mRepeatItem); |
|
428 } |
|
429 |
|
430 /*! |
|
431 Inserts the repeat until item to the dataform model |
|
432 */ |
|
433 void CalenEditorRepeatField::insertRepeatUntilItem() |
|
434 { |
|
435 OstTraceFunctionEntry0( CALENEDITORREPEATFIELD_INSERTREPEATUNTILITEM_ENTRY ); |
|
436 HbDataFormModelItem::DataItemType itemType = |
|
437 static_cast<HbDataFormModelItem::DataItemType> (RepeatUntilOffset); |
|
438 |
|
439 int index = CalenEditorPrivate::RepeatUntilItem; |
|
440 if (!mCalenEditor->isReminderTimeForAllDayAdded()) { |
|
441 index -= 1; |
|
442 } |
|
443 mCustomRepeatUntilItem = mCalenEditorModel->insertDataFormItem( |
|
444 index, |
|
445 itemType, |
|
446 QString( |
|
447 hbTrId( |
|
448 "txt_calendar_setlabel_repeat_until")), |
|
449 mCalenEditorModel->invisibleRootItem()); |
|
450 mRepeatUntilItemAdded = true; |
|
451 |
|
452 mEditorForm->addConnection(mCustomRepeatUntilItem, SIGNAL(clicked()), |
|
453 this, SLOT(launchRepeatUntilDatePicker())); |
|
454 if (!mCalenEditor->isNewEntry() && mRepeatRuleType != AgendaRepeatRule::InvalidRule) { |
|
455 HbExtendedLocale locale = HbExtendedLocale::system(); |
|
456 QString dateString = locale.format( |
|
457 mCalenEditor->editedEntry()->repeatRule().until().date(), |
|
458 r_qtn_date_usual_with_zero); |
|
459 mCustomRepeatUntilItem->setContentWidgetData("text", dateString); |
|
460 } |
|
461 //Scroll to repeat until item added |
|
462 mEditorForm->scrollTo(mCalenEditorModel->index(index, 0), HbAbstractItemView::EnsureVisible); |
|
463 OstTraceFunctionExit0( CALENEDITORREPEATFIELD_INSERTREPEATUNTILITEM_EXIT ); |
|
464 } |
|
465 |
|
466 /*! |
|
467 Informs if repeat until item has been added or not |
|
468 \return true if repeat until item is added else false |
|
469 */ |
|
470 bool CalenEditorRepeatField::isRepeatUntilItemAdded() |
|
471 { |
|
472 OstTraceFunctionEntry0( CALENEDITORREPEATFIELD_ISREPEATUNTILITEMADDED_ENTRY ); |
|
473 OstTraceFunctionExit0( CALENEDITORREPEATFIELD_ISREPEATUNTILITEMADDED_EXIT ); |
|
474 return mRepeatUntilItemAdded; |
|
475 } |
|
476 |
|
477 /*! |
|
478 Launches the date picker by tapping on the repaet until pushbutton |
|
479 */ |
|
480 void CalenEditorRepeatField::launchRepeatUntilDatePicker() |
|
481 { |
|
482 OstTraceFunctionEntry0( CALENEDITORREPEATFIELD_LAUNCHREPEATUNTILDATEPICKER_ENTRY ); |
|
483 HbDialog *popUp = new HbDialog(); |
|
484 popUp->setDismissPolicy(HbDialog::NoDismiss); |
|
485 popUp->setTimeout(HbDialog::NoTimeout); |
|
486 popUp->setHeadingWidget( new HbLabel( |
|
487 hbTrId("txt_calendar_title_repeat_until"))); |
|
488 popUp->setAttribute( Qt::WA_DeleteOnClose, true ); |
|
489 |
|
490 if (mDatePicker) { |
|
491 mDatePicker = 0; |
|
492 } |
|
493 if (mRepeatRuleType == AgendaRepeatRule::DailyRule) { |
|
494 QDate minDate = mCalenEditor->editedEntry()->endTime().date().addDays(1); |
|
495 mDatePicker = new HbDateTimePicker(mRepeatUntilDate, popUp); |
|
496 mDatePicker->setMinimumDate(minDate); |
|
497 mDatePicker->setMaximumDate(CalenDateUtils::maxTime().date()); |
|
498 mDatePicker->setDate(mRepeatUntilDate); |
|
499 } else if (mRepeatRuleType == AgendaRepeatRule::WeeklyRule) { |
|
500 QDate minDate; |
|
501 if (!mIsBiWeekly || mIsWorkdays) { |
|
502 minDate = mCalenEditor->editedEntry()->endTime().date().addDays(7); |
|
503 } else { |
|
504 minDate = mCalenEditor->editedEntry()->endTime().date().addDays(14); |
|
505 } |
|
506 mDatePicker = new HbDateTimePicker(mRepeatUntilDate, popUp); |
|
507 mDatePicker->setMinimumDate(minDate); |
|
508 mDatePicker->setMaximumDate(CalenDateUtils::maxTime().date()); |
|
509 mDatePicker->setDate(mRepeatUntilDate); |
|
510 } else if (mRepeatRuleType == AgendaRepeatRule::MonthlyRule) { |
|
511 QDate minDate = mCalenEditor->editedEntry()->endTime().date().addMonths(1); |
|
512 mDatePicker = new HbDateTimePicker(mRepeatUntilDate, popUp); |
|
513 mDatePicker->setMinimumDate(minDate); |
|
514 mDatePicker->setMaximumDate(CalenDateUtils::maxTime().date()); |
|
515 mDatePicker->setDate(mRepeatUntilDate); |
|
516 } else if (mRepeatRuleType == AgendaRepeatRule::YearlyRule) { |
|
517 QDate minDate = mCalenEditor->editedEntry()->endTime().date().addYears(1); |
|
518 mDatePicker = new HbDateTimePicker(mRepeatUntilDate, popUp); |
|
519 mDatePicker->setMinimumDate(minDate); |
|
520 mDatePicker->setMaximumDate(CalenDateUtils::maxTime().date()); |
|
521 mDatePicker->setDate(mRepeatUntilDate); |
|
522 } |
|
523 popUp->setContentWidget(mDatePicker); |
|
524 |
|
525 HbAction *okAction = new HbAction(hbTrId("txt_common_button_ok")); |
|
526 popUp->addAction(okAction); |
|
527 connect(okAction, SIGNAL(triggered()), this, SLOT(setRepeatUntilDate())); |
|
528 popUp->addAction(new HbAction(hbTrId("txt_common_button_cancel"), popUp)); |
|
529 popUp->open(); |
|
530 OstTraceFunctionExit0( CALENEDITORREPEATFIELD_LAUNCHREPEATUNTILDATEPICKER_EXIT ); |
|
531 } |
|
532 |
|
533 /*! |
|
534 Sets the repeat until date on the repeat until item |
|
535 */ |
|
536 void CalenEditorRepeatField::setRepeatUntilDate() |
|
537 { |
|
538 OstTraceFunctionEntry0( CALENEDITORREPEATFIELD_SETREPEATUNTILDATE_ENTRY ); |
|
539 //Get the previous date which was set |
|
540 QDate previousDate = mRepeatUntilDate; |
|
541 mRepeatUntilDate = mDatePicker->date(); |
|
542 if (mRepeatUntilDate.isValid()) { |
|
543 HbExtendedLocale locale = HbExtendedLocale::system(); |
|
544 QString dateString = locale.format(mRepeatUntilDate, |
|
545 r_qtn_date_usual_with_zero); |
|
546 mCustomRepeatUntilItem->setContentWidgetData("text", dateString); |
|
547 } |
|
548 mCalenEditor->updateReminderChoices(); |
|
549 // If the entry's repeatuntil date is changed from past to a future date |
|
550 // And if the alarm set set is off |
|
551 // Then change the reminder option to the default 'one day before' |
|
552 // if the option is valid |
|
553 if (mCalenEditor->isAllDayEvent() && previousDate <= QDate::currentDate()) { |
|
554 if(mRepeatUntilDate > QDate::currentDate() && |
|
555 !mCalenEditor->isReminderTimeForAllDayAdded() && |
|
556 mCalenEditor->getReminderCount() >= 3) { |
|
557 mCalenEditor->setCurrentIndexOfReminderField( |
|
558 CalenEditorReminderField::ReminderOneDayBefore); |
|
559 } |
|
560 } |
|
561 OstTraceFunctionExit0( CALENEDITORREPEATFIELD_SETREPEATUNTILDATE_EXIT ); |
|
562 } |
|
563 |
|
564 /*! |
|
565 Returns the repeatuntildate displayed. |
|
566 */ |
|
567 QDate CalenEditorRepeatField::repeatUntilDate() |
|
568 { |
|
569 OstTraceFunctionEntry0( CALENEDITORREPEATFIELD_REPEATUNTILDATE_ENTRY ); |
|
570 OstTraceFunctionExit0( CALENEDITORREPEATFIELD_REPEATUNTILDATE_EXIT ); |
|
571 return mRepeatUntilDate; |
|
572 } |
|
573 |
|
574 /*! |
|
575 Updates the repeat choices depending on the meeting duration |
|
576 */ |
|
577 void CalenEditorRepeatField::updateRepeatChoices() |
|
578 { |
|
579 OstTraceFunctionEntry0( CALENEDITORREPEATFIELD_UPDATEREPEATCHOICES_ENTRY ); |
|
580 if (!mRepeatComboBox) { |
|
581 OstTraceFunctionExit0( CALENEDITORREPEATFIELD_UPDATEREPEATCHOICES_EXIT ); |
|
582 return; |
|
583 } |
|
584 // Disconnect the slot and connect it back again at end to avoid unnecessary |
|
585 // calls to handleRepeatIndexChanged slot. Or else the slot gets called |
|
586 // when we add all of items to the repeat combobox. |
|
587 disconnect(mRepeatComboBox, SIGNAL(currentIndexChanged(int)), this, |
|
588 SLOT(handleRepeatIndexChanged(int))); |
|
589 // Clear all the choices and add it again. If we dont do it |
|
590 // as user would have changed the end times many times and we would have |
|
591 // deleted repeat options depending upon that |
|
592 // Get the current choice |
|
593 int choice = mRepeatComboBox->currentIndex(); |
|
594 |
|
595 QVariant role = mRepeatComboBox->itemData(choice, userRole); |
|
596 mRepeatRoleValue = role.toInt(); |
|
597 |
|
598 int previousCount = mRepeatComboBox->count(); |
|
599 mRepeatComboBox->clear(); |
|
600 QStringList repeatChoices; |
|
601 repeatChoices << hbTrId("txt_calendar_setlabel_repeat_val_only_once") |
|
602 << hbTrId("txt_calendar_setlabel_repeat_val_daily") |
|
603 << hbTrId("txt_calendar_setlabel_repeat_val_workdays") |
|
604 << hbTrId("txt_calendar_setlabel_repeat_val_weekly") |
|
605 << hbTrId("txt_calendar_setlabel_repeat_val_fortnightly") |
|
606 << hbTrId("txt_calendar_setlabel_repeat_val_monthly") |
|
607 << hbTrId("txt_calendar_setlabel_repeat_val_yearly"); |
|
608 mRepeatComboBox->addItems(repeatChoices); |
|
609 // Set the user roles for the combobox items so that we depend on these |
|
610 // roles to identify the correct repeat type when repeat choices are |
|
611 // dynamically removed or added |
|
612 mRepeatComboBox->setItemData(RepeatOnce, RepeatOnce, userRole); |
|
613 mRepeatComboBox->setItemData(RepeatDaily, RepeatDaily, |
|
614 userRole); |
|
615 mRepeatComboBox->setItemData(RepeatWorkdays, |
|
616 RepeatWorkdays, userRole); |
|
617 mRepeatComboBox->setItemData(RepeatWeekly, RepeatWeekly, |
|
618 userRole); |
|
619 mRepeatComboBox->setItemData(RepeatBiWeekly, RepeatBiWeekly, |
|
620 userRole); |
|
621 mRepeatComboBox->setItemData(RepeatMonthly, RepeatMonthly, |
|
622 userRole); |
|
623 mRepeatComboBox->setItemData(RepeatYearly, RepeatYearly, |
|
624 userRole); |
|
625 |
|
626 int totalCount = mRepeatComboBox->count(); |
|
627 |
|
628 if (previousCount < totalCount && choice > 0) { |
|
629 choice += (totalCount - previousCount); |
|
630 } |
|
631 // Now check if the duration of the meeting and remove the repeat choices |
|
632 // if necessary |
|
633 int duration = |
|
634 mCalenEditor->editedEntry()->startTime().daysTo( |
|
635 mCalenEditor->editedEntry()->endTime()); |
|
636 |
|
637 bool isRemovedItem = false; |
|
638 int numberOfItemRemoved = 0; |
|
639 |
|
640 if (mCalenEditor->editedEntry()->endTime() >= (mCalenEditor->editedEntry()->startTime().addYears(1))) { |
|
641 |
|
642 isRemovedItem = true; |
|
643 numberOfItemRemoved = 6; |
|
644 // Remove all options except "RepeatOnce" |
|
645 // Should be deletd in the descending order only |
|
646 mRepeatComboBox->removeItem(RepeatYearly); |
|
647 mRepeatComboBox->removeItem(RepeatMonthly); |
|
648 mRepeatComboBox->removeItem(RepeatBiWeekly); |
|
649 mRepeatComboBox->removeItem(RepeatWeekly); |
|
650 mRepeatComboBox->removeItem(RepeatWorkdays); |
|
651 mRepeatComboBox->removeItem(RepeatDaily); |
|
652 //Remove the repeat until item too. |
|
653 removeRepeatUntilItem(); |
|
654 } else if (mCalenEditor->editedEntry()->endTime() |
|
655 >= (mCalenEditor->editedEntry()->startTime().addMonths(1))) { |
|
656 isRemovedItem = true; |
|
657 numberOfItemRemoved = 5; |
|
658 // Remove all the options except "Repeat Once" |
|
659 // and "Repeat Yearly" options |
|
660 // Should be deletd in the descending order only |
|
661 mRepeatComboBox->removeItem(RepeatMonthly); |
|
662 mRepeatComboBox->removeItem(RepeatBiWeekly); |
|
663 mRepeatComboBox->removeItem(RepeatWeekly); |
|
664 mRepeatComboBox->removeItem(RepeatWorkdays); |
|
665 mRepeatComboBox->removeItem(RepeatDaily); |
|
666 } else if (duration >= 14) { |
|
667 isRemovedItem = true; |
|
668 numberOfItemRemoved = 4; |
|
669 // Remove daily, workdays, weekly and biweekly options |
|
670 // Should be deletd in the descending order only |
|
671 mRepeatComboBox->removeItem(RepeatBiWeekly); |
|
672 mRepeatComboBox->removeItem(RepeatWeekly); |
|
673 mRepeatComboBox->removeItem(RepeatWorkdays); |
|
674 mRepeatComboBox->removeItem(RepeatDaily); |
|
675 } else if (duration >= 7) { |
|
676 isRemovedItem = true; |
|
677 numberOfItemRemoved = 3; |
|
678 // Remove daily, workdays and weekly options |
|
679 // Should be deletd in the descending order only |
|
680 mRepeatComboBox->removeItem(RepeatWeekly); |
|
681 mRepeatComboBox->removeItem(RepeatWorkdays); |
|
682 mRepeatComboBox->removeItem(RepeatDaily); |
|
683 } else if (duration >= 1) { |
|
684 isRemovedItem = true; |
|
685 numberOfItemRemoved = 2; |
|
686 // Remove daily and workdays option |
|
687 mRepeatComboBox->removeItem(RepeatWorkdays); |
|
688 mRepeatComboBox->removeItem(RepeatDaily); |
|
689 } |
|
690 |
|
691 if (isRemovedItem && choice > 0) { |
|
692 choice -= numberOfItemRemoved; |
|
693 if (choice <= 0) |
|
694 choice = 1; |
|
695 } |
|
696 int count = mRepeatComboBox->count(); |
|
697 if (choice >= count) { |
|
698 choice = count - 1; |
|
699 } |
|
700 |
|
701 //Connecting back the slot for repeat index change before setting index. |
|
702 connect(mRepeatComboBox, SIGNAL(currentIndexChanged(int)), this, |
|
703 SLOT(handleRepeatIndexChanged(int))); |
|
704 // By default the repeat combobox index will be 0 |
|
705 // Set the previous user's choice |
|
706 mRepeatComboBox->setCurrentIndex(choice); |
|
707 // If the previous user's choice is also zero, then slot |
|
708 // handleRepeatIndexChanged will not be called as |
|
709 // there is no change in current index |
|
710 // So explicitly call updateReminderChoices to update the reminder choices |
|
711 // for choice : 0 (Not repeated) |
|
712 if(choice == 0) { |
|
713 mCalenEditor->updateReminderChoices(); |
|
714 } |
|
715 OstTraceFunctionExit0( DUP1_CALENEDITORREPEATFIELD_UPDATEREPEATCHOICES_EXIT ); |
|
716 } |
|
717 |
|
718 /*! |
|
719 Save RepeatRule to the edited entry |
|
720 */ |
|
721 void CalenEditorRepeatField::saveRepeatRule() |
|
722 { |
|
723 OstTraceFunctionEntry0( CALENEDITORREPEATFIELD_SAVEREPEATRULE_ENTRY ); |
|
724 // saves repeat type of entry. |
|
725 if (mRepeatRuleType != AgendaRepeatRule::InvalidRule) { |
|
726 AgendaRepeatRule repeatRule(mRepeatRuleType); |
|
727 |
|
728 //TODO : Set the repeat from and to dates |
|
729 QVariant dateVariant = |
|
730 mCustomRepeatUntilItem->contentWidgetData("text"); |
|
731 QString dateString = dateVariant.toString(); |
|
732 QDate untilDate = QDate::fromString(dateString, "dd/MM/yyyy"); |
|
733 repeatRule.setRepeatRuleStart(mCalenEditor->editedEntry()->startTime()); |
|
734 repeatRule.setInterval(1); |
|
735 QDateTime repeatUntil(mRepeatUntilDate, |
|
736 QTime(mCalenEditor->editedEntry()->endTime().time())); |
|
737 repeatRule.setUntil(repeatUntil); |
|
738 |
|
739 // need to set the day for weekly & monthly repeat rule. |
|
740 if (mRepeatRuleType == AgendaRepeatRule::WeeklyRule) { |
|
741 if (mIsWorkdays) { |
|
742 mIsWorkdays = false; |
|
743 HbExtendedLocale locale = HbExtendedLocale::system(); |
|
744 // 0(Sun)0(sat)1(Fri)1(Thu)1(Wed)1(Tue)1(Mon) |
|
745 QString workDaysString = locale.workDays(); |
|
746 bool ok; |
|
747 int fixedNum = 1; |
|
748 int ruleday = 0; |
|
749 uint workDays = workDaysString.toUInt(&ok, 2); |
|
750 if (ok) { |
|
751 QList<AgendaRepeatRule::Day> weekDaysFromLocale; |
|
752 |
|
753 // "workDays" is a bit mask of seven bits indicating |
|
754 // (by being set) which days are workdays. |
|
755 // The least significant bit corresponds to Monday, |
|
756 // the next bit to Tuesday and so on. |
|
757 for (TInt i = 0; i < KNoOfDaysInWeek; i++) { |
|
758 ruleday = fixedNum << i; |
|
759 if (workDays & ruleday) { |
|
760 weekDaysFromLocale.append( |
|
761 (AgendaRepeatRule::Day) i); |
|
762 repeatRule.setByDay(weekDaysFromLocale); |
|
763 } |
|
764 |
|
765 } |
|
766 |
|
767 } else { |
|
768 mCalenEditor->editedEntry()->setRepeatRule(AgendaRepeatRule( |
|
769 AgendaRepeatRule::InvalidRule)); |
|
770 } |
|
771 } else { |
|
772 QList<AgendaRepeatRule::Day> days; |
|
773 if (mIsBiWeekly) { |
|
774 repeatRule.setInterval(2); |
|
775 mIsBiWeekly = false; |
|
776 } |
|
777 int dayOfWeek = |
|
778 mCalenEditor->editedEntry()->startTime().date().dayOfWeek(); |
|
779 days.append(AgendaRepeatRule::Day(dayOfWeek - 1)); |
|
780 repeatRule.setByDay(days); |
|
781 } |
|
782 } else if (mRepeatRuleType == AgendaRepeatRule::MonthlyRule) { |
|
783 QList<int> monthDays; |
|
784 int dayNoInMonth = mCalenEditor->editedEntry()->startTime().date().day(); |
|
785 monthDays.append(dayNoInMonth); |
|
786 repeatRule.setByMonthDay(monthDays); |
|
787 } else if (mRepeatRuleType == AgendaRepeatRule::YearlyRule) { |
|
788 } |
|
789 mCalenEditor->editedEntry()->setRepeatRule(repeatRule); |
|
790 } else { |
|
791 mCalenEditor->editedEntry()->setRepeatRule( AgendaRepeatRule( |
|
792 AgendaRepeatRule::InvalidRule)); |
|
793 } |
|
794 // TODO: Need to update rDates here for 10.2 if required |
|
795 OstTraceFunctionExit0( CALENEDITORREPEATFIELD_SAVEREPEATRULE_EXIT ); |
|
796 } |
|
797 |
|
798 // End of file --Don't remove this. |