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: CalenDayViewWidget implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <QStandardItemModel> |
|
20 #include <QGraphicsSceneEvent> |
|
21 #include <QDir> |
|
22 #include <QPluginLoader> |
|
23 #include <hbi18ndef.h> |
|
24 #include <hbextendedlocale.h> |
|
25 #include <hbgroupbox.h> |
|
26 #include <hbmenu.h> |
|
27 #include <hbaction.h> |
|
28 #include <hbmainwindow.h> |
|
29 #include <hbstyleloader.h> |
|
30 #include <hbdatetimepicker.h> |
|
31 #include <hbdialog.h> |
|
32 #include <xqsettingsmanager.h> |
|
33 #include <agendautil.h> |
|
34 #include <NotesEditorInterface> |
|
35 |
|
36 // User includes |
|
37 #include "calendayviewwidget.h" |
|
38 #include "calencommon.h" |
|
39 #include "calendayview.h" |
|
40 #include "calendocloader.h" |
|
41 #include "calenservices.h" |
|
42 #include "calencontext.h" |
|
43 #include "calendateutils.h" |
|
44 #include "CalenUid.h" |
|
45 #include "caleneventlistviewitem.h" |
|
46 #include "calenpluginlabel.h" |
|
47 #include "calendarprivatecrkeys.h" |
|
48 |
|
49 // Constants |
|
50 static const QString singleSpace(" "); |
|
51 static const QString newLine("\n"); |
|
52 static const QString customLayout("custom"); |
|
53 static const char *stretchLayout("stretchItem"); |
|
54 // TODO: Replace with actual image names later |
|
55 static const QString toDoIcon("qtg_small_todo"); |
|
56 static const QString reminderIcon("qtg_mono_alarm"); |
|
57 static const QString locationIcon("qtg_mono_location"); |
|
58 static const QString repeatIcon("qtg_mono_repeat"); |
|
59 static const QString allDayIcon(":/qgn_indi_cdr_meeting_layer0.svg"); |
|
60 static const QString exceptionIcon(":/qtg_mono_exception.png"); |
|
61 static const int singleColumn(1); |
|
62 |
|
63 // ---------------------------------------------------------------------------- |
|
64 // CalenDayViewWidget::CalenDayViewWidget |
|
65 // Rest of the details are commented in the header |
|
66 // ---------------------------------------------------------------------------- |
|
67 // |
|
68 EXPORT_C CalenDayViewWidget::CalenDayViewWidget(MCalenServices &services, |
|
69 CalenDocLoader *docLoader) : |
|
70 mServices(services), |
|
71 mDocLoader(docLoader), |
|
72 mRegionalInfoGroupBox(NULL), |
|
73 mLongTapEventFlag(false), |
|
74 mNotesPluginLoaded(false) |
|
75 { |
|
76 // Construct the list view prototype |
|
77 mListViewPrototype = new CalenEventListViewItem(this); |
|
78 |
|
79 // Create the list model |
|
80 mListModel = new QStandardItemModel(this); |
|
81 |
|
82 // Register the custom docml and css to provide our own style to the list items |
|
83 HbStyleLoader::registerFilePath(":/"); |
|
84 |
|
85 //Create the setting manager |
|
86 mSettingsManager = new XQSettingsManager(this); |
|
87 } |
|
88 |
|
89 // ---------------------------------------------------------------------------- |
|
90 // CalenDayViewWidget::~CalenDayViewWidget |
|
91 // Rest of the details are commented in the header |
|
92 // ---------------------------------------------------------------------------- |
|
93 // |
|
94 EXPORT_C CalenDayViewWidget::~CalenDayViewWidget() |
|
95 { |
|
96 // Unload notes editor if loaded. |
|
97 if (mNotesEditorPluginLoader) { |
|
98 mNotesEditorPluginLoader->unload(); |
|
99 delete mNotesEditorPluginLoader; |
|
100 mNotesEditorPluginLoader = 0; |
|
101 } |
|
102 |
|
103 if (mListViewPrototype) { |
|
104 delete mListViewPrototype; |
|
105 mListViewPrototype = NULL; |
|
106 } |
|
107 if (mListModel) { |
|
108 // Do not delete the model since its owned by the view |
|
109 mListModel->clear(); |
|
110 } |
|
111 } |
|
112 |
|
113 // ---------------------------------------------------------------------------- |
|
114 // CalenDayViewWidget::setupWidget |
|
115 // Rest of the details are commented in the header |
|
116 // ---------------------------------------------------------------------------- |
|
117 // |
|
118 void CalenDayViewWidget::setupWidget(CalenDayView *view) |
|
119 { |
|
120 // Store the view for future reference |
|
121 mView = view; |
|
122 |
|
123 if (!mDocLoader) { |
|
124 // Nothing much can be done. Simply return |
|
125 return; |
|
126 } |
|
127 |
|
128 // Initialize the child widgets |
|
129 initChildWidgets(); |
|
130 } |
|
131 |
|
132 // ---------------------------------------------------------------------------- |
|
133 // CalenDayViewWidget::showWidget |
|
134 // Rest of the details are commented in the header |
|
135 // ---------------------------------------------------------------------------- |
|
136 // |
|
137 void CalenDayViewWidget::showWidget() |
|
138 { |
|
139 // Get the date for which this view has been launched |
|
140 mDate = mServices.Context().focusDateAndTimeL(); |
|
141 |
|
142 // Set the heading text |
|
143 setHeadingText(); |
|
144 |
|
145 // Get the instance list |
|
146 getInstanceList(); |
|
147 |
|
148 // Check if regional information needs to be shown |
|
149 // and add it or remove it |
|
150 showHideRegionalInformation(); |
|
151 |
|
152 // Load the appropriate section based on the number of events for the day |
|
153 if (0 == mInstanceArray.count()) { |
|
154 // There are no entries for the day |
|
155 // Load and show the empty list section |
|
156 bool loadSuccess = false; |
|
157 |
|
158 // Hide the list which shows the events |
|
159 mEventsList->hide(); |
|
160 |
|
161 // Show the empty list text |
|
162 mEmptyListLabel->show(); |
|
163 |
|
164 // Get the current device orientation |
|
165 int orientation = mServices.MainWindow().orientation(); |
|
166 if (Qt::Vertical == orientation) { |
|
167 mDocLoader->load(CALEN_DAYVIEW_XML_FILE, "emptyList", &loadSuccess); |
|
168 } else { |
|
169 mDocLoader->load(CALEN_DAYVIEW_XML_FILE, "emptyLandscape", &loadSuccess); |
|
170 } |
|
171 if (!loadSuccess) { |
|
172 qFatal("calendayviewwidget.cpp : Unable to load empty list section"); |
|
173 } |
|
174 } else { |
|
175 // Hide the empty view label |
|
176 mEmptyListLabel->hide(); |
|
177 |
|
178 // Show the events list |
|
179 mEventsList->show(); |
|
180 |
|
181 // There are one or more events. Load the non-empty section |
|
182 bool loadSuccess = false; |
|
183 mDocLoader->load(CALEN_DAYVIEW_XML_FILE, "nonEmptyList", &loadSuccess); |
|
184 if (!loadSuccess) { |
|
185 qFatal("calendayviewwidget.cpp : Unable to load non-empty list section"); |
|
186 } |
|
187 // Now populate the list with the events |
|
188 populateListWidget(); |
|
189 } |
|
190 } |
|
191 |
|
192 // ---------------------------------------------------------------------------- |
|
193 // CalenDayViewWidget::orientationChanged |
|
194 // Rest of the details are commented in the header |
|
195 // ---------------------------------------------------------------------------- |
|
196 // |
|
197 void CalenDayViewWidget::orientationChanged(Qt::Orientation orientation) |
|
198 { |
|
199 // Load the appropriate section based on the number of events for the day |
|
200 if (0 == mInstanceArray.count()) { |
|
201 // There are no entries for the day |
|
202 // Load and show the empty list section |
|
203 bool loadSuccess = false; |
|
204 |
|
205 // Hide the list which shows the events |
|
206 mEventsList->hide(); |
|
207 |
|
208 // Show the empty list text |
|
209 mEmptyListLabel->show(); |
|
210 |
|
211 if (Qt::Vertical == orientation) { |
|
212 mDocLoader->load(CALEN_DAYVIEW_XML_FILE, "emptyList", &loadSuccess); |
|
213 } else { |
|
214 mDocLoader->load(CALEN_DAYVIEW_XML_FILE, "emptyLandscape", &loadSuccess); |
|
215 } |
|
216 if (!loadSuccess) { |
|
217 qFatal("calendayviewwidget.cpp : Unable to load empty list section"); |
|
218 } |
|
219 } else { |
|
220 // Hide the empty view label |
|
221 mEmptyListLabel->hide(); |
|
222 |
|
223 // Show the events list |
|
224 mEventsList->show(); |
|
225 |
|
226 // There are one or more events. Load the non-empty section |
|
227 bool loadSuccess = false; |
|
228 mDocLoader->load(CALEN_DAYVIEW_XML_FILE, "nonEmptyList", &loadSuccess); |
|
229 if (!loadSuccess) { |
|
230 qFatal("calendayviewwidget.cpp : Unable to load non-empty list section"); |
|
231 } |
|
232 handleListItemStretching(orientation); |
|
233 } |
|
234 } |
|
235 |
|
236 // ---------------------------------------------------------------------------- |
|
237 // CalenDayViewWidget::handleLocaleChange |
|
238 // Rest of the details are commented in the header |
|
239 // ---------------------------------------------------------------------------- |
|
240 // |
|
241 void CalenDayViewWidget::handleLocaleChange() |
|
242 { |
|
243 |
|
244 } |
|
245 |
|
246 // ---------------------------------------------------------------------------- |
|
247 // CalenDayViewWidget::setContextFromHighlight |
|
248 // Rest of the details are commented in the header |
|
249 // ---------------------------------------------------------------------------- |
|
250 // |
|
251 void CalenDayViewWidget::setContextFromHighlight(AgendaEntry entry) |
|
252 { |
|
253 if (entry.isTimedEntry()) { |
|
254 // Timed entry. |
|
255 QDateTime start = entry.startTime(); |
|
256 // start.setDate(mDate.date()); |
|
257 mServices.Context().setFocusDateAndTimeAndInstanceL(start, |
|
258 TCalenInstanceId::create(entry), |
|
259 KCalenDayViewUidValue); |
|
260 } else { |
|
261 // Untimed entry. |
|
262 if (CalenDateUtils::onSameDay(TCalenInstanceId::create(entry).mInstanceTime, |
|
263 mDate)) { |
|
264 mServices.Context().setInstanceIdL(TCalenInstanceId::create(entry), |
|
265 KCalenDayViewUidValue); |
|
266 } else { |
|
267 // Multi-day untimed note (either multi-day day note or weird todo). |
|
268 // Focus on the instance and set the focus time to the highlighted day. |
|
269 mServices.Context().setFocusDateAndTimeAndInstanceL(mDate, |
|
270 TCalenInstanceId::create(entry), |
|
271 KCalenDayViewUidValue); |
|
272 } |
|
273 } |
|
274 } |
|
275 |
|
276 // ---------------------------------------------------------------------------- |
|
277 // CalenDayViewWidget::initChildWidgets |
|
278 // Rest of the details are commented in the header |
|
279 // ---------------------------------------------------------------------------- |
|
280 // |
|
281 void CalenDayViewWidget::initChildWidgets() |
|
282 { |
|
283 // Get the pointer to the events list |
|
284 mEventsList = static_cast<HbListView*> (mDocLoader->findWidget(CALEN_DAYVIEW_LISTWIDGET)); |
|
285 if (!mEventsList) { |
|
286 qFatal("calendayviewwidget.cpp : Unable to find the events list"); |
|
287 } |
|
288 // NOTE: Layout name MUST be same as the name mentioned in the css |
|
289 mEventsList->setLayoutName(customLayout); |
|
290 |
|
291 // TODO : remove this line after gestures are available |
|
292 mEventsList->installEventFilter(mView); |
|
293 |
|
294 // Connect to the long press and activation signals |
|
295 connect(mEventsList, SIGNAL(longPressed(HbAbstractViewItem*, const QPointF&)), |
|
296 this, SLOT(itemLongPressed(HbAbstractViewItem*, const QPointF&))); |
|
297 connect(mEventsList, SIGNAL(activated(const QModelIndex&)), this, |
|
298 SLOT(itemActivated(const QModelIndex&))); |
|
299 |
|
300 // Get the pointer to label from the loader. |
|
301 mHeadingLabel = qobject_cast<HbGroupBox*> (mDocLoader->findWidget(CALEN_DAYVIEW_HEADING)); |
|
302 if (!mHeadingLabel) { |
|
303 qFatal("calendayviewwidget.cpp : Unable to find heading widget"); |
|
304 } |
|
305 |
|
306 // Get the pointer to the empty view label |
|
307 mEmptyListLabel = qobject_cast<HbLabel*> (mDocLoader->findWidget("noEventsLabel")); |
|
308 if (!mEmptyListLabel) { |
|
309 qFatal("calendayviewwidget.cpp : Unable to find empty list label"); |
|
310 } |
|
311 HbWidget *headingPluginWidget = |
|
312 qobject_cast<HbWidget*> (mDocLoader->findWidget(CALEN_DAYVIEW_HEADING_REGIONALPLUGIN_WIDGET)); |
|
313 |
|
314 mRegionalPluginLayout = static_cast<QGraphicsLinearLayout*>(headingPluginWidget->layout()); |
|
315 |
|
316 } |
|
317 |
|
318 // ---------------------------------------------------------------------------- |
|
319 // CalenDayViewWidget::populateListWidget |
|
320 // Rest of the details are commented in the header |
|
321 // ---------------------------------------------------------------------------- |
|
322 // |
|
323 void CalenDayViewWidget::populateListWidget() |
|
324 { |
|
325 // Recycle the list items so that only needed rows |
|
326 // are added or removed |
|
327 if (mInstanceArray.count() == 0) { |
|
328 // Reset the list |
|
329 mEventsList->reset(); |
|
330 // Clear the model to ensure it does not have any old items |
|
331 mListModel->clear(); |
|
332 return; |
|
333 } else if (mInstanceArray.count() > mListModel->rowCount()) { |
|
334 // There are more events than the number of items |
|
335 // in the list. Add more rows |
|
336 mListModel->insertRows(0, mInstanceArray.count() - mListModel->rowCount()); |
|
337 } else if (mInstanceArray.count() < mListModel->rowCount()) { |
|
338 // There are less number of events than the number |
|
339 // of items in the list. Remove the extra rows |
|
340 mListModel->removeRows(0, mListModel->rowCount() - mInstanceArray.count()); |
|
341 } |
|
342 mListModel->setColumnCount(singleColumn); |
|
343 |
|
344 // Add all the events to the list |
|
345 for (int index = 0; index < mInstanceArray.count(); index++) { |
|
346 // Get each of the entry details |
|
347 AgendaEntry entry = mInstanceArray[index]; |
|
348 // Create a list item for each entry |
|
349 createListItem(index, entry); |
|
350 } |
|
351 // Add the item on to the list widget |
|
352 mEventsList->setModel(mListModel, mListViewPrototype); |
|
353 |
|
354 // Now get the item to scroll to |
|
355 int scrollToIndex = getIndexToScrollTo(); |
|
356 if (mListModel->rowCount() > 0) { |
|
357 // Scroll to the index only if index is valid |
|
358 mEventsList->scrollTo(mListModel->index(scrollToIndex, 0)); |
|
359 } |
|
360 } |
|
361 |
|
362 // ---------------------------------------------------------------------------- |
|
363 // CalenDayViewWidget::getInstanceList |
|
364 // Rest of the details are commented in the header |
|
365 // ---------------------------------------------------------------------------- |
|
366 // |
|
367 void CalenDayViewWidget::getInstanceList() |
|
368 { |
|
369 // Clear the previous instance list |
|
370 mInstanceArray.clear(); |
|
371 |
|
372 // Check if the date is valid |
|
373 if (!CalenDateUtils::isValidDay(mDate)) { |
|
374 mDate = CalenDateUtils::today(); |
|
375 } |
|
376 |
|
377 // Set the filter flags to fetch all relevant entries |
|
378 AgendaUtil::FilterFlags filter = AgendaUtil::FilterFlags(AgendaUtil::IncludeAnniversaries | |
|
379 AgendaUtil::IncludeAppointments | |
|
380 AgendaUtil::IncludeEvents | |
|
381 AgendaUtil::IncludeReminders | |
|
382 AgendaUtil::IncludeIncompletedTodos); |
|
383 |
|
384 // Fetch the instance list from the agenda interface |
|
385 mInstanceArray = mServices.agendaInterface()->createEntryIdListForDay(mDate, filter); |
|
386 |
|
387 if (0 == mInstanceArray.count()) { |
|
388 // There are no events to populate |
|
389 // Hide the events list |
|
390 mEventsList->hide(); |
|
391 // Show the empty list text |
|
392 mEmptyListLabel->show(); |
|
393 return; |
|
394 } |
|
395 } |
|
396 |
|
397 // ---------------------------------------------------------------------------- |
|
398 // CalenDayViewWidget::setDateToLabel |
|
399 // Rest of the details are commented in the header |
|
400 // ---------------------------------------------------------------------------- |
|
401 // |
|
402 void CalenDayViewWidget::setHeadingText() |
|
403 { |
|
404 // Format the date as per the device locale settings |
|
405 HbExtendedLocale systemLocale = HbExtendedLocale::system(); |
|
406 |
|
407 // Get localised name of the day from locale |
|
408 QString dayString = systemLocale.dayName(mDate.date().dayOfWeek()); |
|
409 // Append a single space |
|
410 dayString.append(singleSpace); |
|
411 // Set the heading |
|
412 // Append the date which is formatted as per the locale |
|
413 mHeadingLabel->setHeading(hbTrId( |
|
414 "txt_calendar_subhead_1_2").arg(dayString).arg( |
|
415 systemLocale.format(mDate.date(), r_qtn_date_usual_with_zero))); |
|
416 } |
|
417 |
|
418 // ---------------------------------------------------------------------------- |
|
419 // CalenDayViewWidget::createListItem |
|
420 // Rest of the details are commented in the header |
|
421 // ---------------------------------------------------------------------------- |
|
422 // |
|
423 void CalenDayViewWidget::createListItem(int index, AgendaEntry entry) |
|
424 { |
|
425 if (index < 0 || entry.isNull()) { |
|
426 // Not a valid index or entry. Dont do anything |
|
427 return; |
|
428 } |
|
429 // Check if the entry is a timed entry |
|
430 // TODO: Right now, only appointment/meeting type is being handled |
|
431 // Handle other timed entry types like reminder etc |
|
432 if (entry.isTimedEntry()) { |
|
433 // Get the text and icon data for the entry |
|
434 addTimedEventToList(index, entry); |
|
435 } else { |
|
436 addNonTimedEventToList(index, entry); |
|
437 } |
|
438 } |
|
439 |
|
440 // ---------------------------------------------------------------------------- |
|
441 // CalenDayViewWidget::addTimedEventToList |
|
442 // Rest of the details are commented in the header |
|
443 // ---------------------------------------------------------------------------- |
|
444 // |
|
445 void CalenDayViewWidget::addTimedEventToList(int index, AgendaEntry entry) |
|
446 { |
|
447 // Create text and icon list to set to the model |
|
448 QVariantList textData; |
|
449 QVariantList iconData; |
|
450 bool twoLines = false; |
|
451 |
|
452 /** |
|
453 * IMPORTANT NOTE: All the text and icon items must be |
|
454 * inserted into the variant list in a specific order. |
|
455 * If not, chaos will set it!!! |
|
456 * On a more serious note, the mesh layout depends on the |
|
457 * fact that the icons and text data will be added in a |
|
458 * particular order. If one of the items go missing, the |
|
459 * layout might get messed up. Also in case a particular item |
|
460 * is not required to be added in the middle of the list, an |
|
461 * empty QVariant must be added to indicate to the list view |
|
462 * that the item must be removed from the layout. |
|
463 * Do not mess with the order in case you are not sure what |
|
464 * you are exactly doing. |
|
465 */ |
|
466 |
|
467 // The first icon to show to-do or all day should not be shown |
|
468 // Append empty data to the icons list |
|
469 iconData << QVariant(); |
|
470 |
|
471 // Check if alarm is enabled for the entry |
|
472 if (entry.alarm().isNull()) { |
|
473 // Insert a blank icon. Else the next icon |
|
474 // will get replaced in this icon's position |
|
475 iconData << QVariant(); |
|
476 } else { |
|
477 iconData << HbIcon(reminderIcon); |
|
478 } |
|
479 |
|
480 // Check if the entry is recurring |
|
481 if (entry.isRepeating()) { |
|
482 iconData << HbIcon(repeatIcon); |
|
483 } else if (!entry.recurrenceId().isNull()) { |
|
484 // This is an exceptional entry |
|
485 iconData << HbIcon(exceptionIcon); |
|
486 } else { |
|
487 // Insert a blank icon. Else the next icon |
|
488 // will get replaced in this icon's position |
|
489 iconData << QVariant(); |
|
490 } |
|
491 |
|
492 HbExtendedLocale locale = HbExtendedLocale::system(); |
|
493 // Get the start time and format as per the locale |
|
494 QDateTime startTime = entry.startTime(); |
|
495 QTime eventStartTime; |
|
496 |
|
497 if (CalenDateUtils::beginningOfDay(startTime) |
|
498 < CalenDateUtils::beginningOfDay(mDate)) { |
|
499 // event is started previous day, show StarTime as 12:00 am in Agendaview, |
|
500 eventStartTime.setHMS(00, 00, 00); |
|
501 } else { |
|
502 eventStartTime = entry.startTime().time(); |
|
503 } |
|
504 QString eventTime = locale.format(eventStartTime, r_qtn_time_usual_with_zero); |
|
505 |
|
506 // Get the event end time |
|
507 QDateTime endTime = entry.endTime(); |
|
508 QTime eventEndTime; |
|
509 |
|
510 if (CalenDateUtils::beginningOfDay(endTime) |
|
511 > CalenDateUtils::beginningOfDay(mDate)) { |
|
512 // event has MidNight crossover, show EndTime as 11:59pm in Agendaview, |
|
513 eventEndTime.setHMS(23, 59, 59); |
|
514 } else { |
|
515 eventEndTime = entry.endTime().time(); |
|
516 } |
|
517 |
|
518 if (eventStartTime < eventEndTime) { |
|
519 // Raise the flag to indicate that the list item |
|
520 // would wrap to two lines |
|
521 twoLines = true; |
|
522 // Append '-' to indicate an end time is present |
|
523 eventTime.append("-"); |
|
524 } else { |
|
525 // To align the subject properly if the start and endtime are same |
|
526 eventTime.append(" "); |
|
527 } |
|
528 |
|
529 // Add the event time to the text list |
|
530 // This MUST be the first item to be added to the list |
|
531 textData << eventTime; |
|
532 |
|
533 // Get the entry subject |
|
534 QString subject = entry.summary(); |
|
535 if (subject.isEmpty() || subject.isNull()) { |
|
536 // No subject. Add "(No subject)" text |
|
537 subject.append(hbTrId("txt_calendar_dblist_unnamed")); |
|
538 } |
|
539 // Add the subject to the text list |
|
540 // This MUST be the second item in the list |
|
541 textData << subject; |
|
542 |
|
543 // Check if the entry has location |
|
544 // TODO: This must change to check for geo-location |
|
545 // This MUST be the third item in the list |
|
546 if (entry.location().isEmpty()) { |
|
547 // Insert a blank icon. Else the next icon |
|
548 // will get replaced in this icon's position |
|
549 iconData << QVariant(); |
|
550 if (twoLines) { |
|
551 /** |
|
552 * NOTE: If the primary text is wrapping to two |
|
553 * lines, then the location must be set as blank |
|
554 * since the bottom of the list item is anchored to |
|
555 * the bottom of the secondary text. Else the bottom |
|
556 * of the list will overlap on the primary text |
|
557 */ |
|
558 textData << singleSpace; |
|
559 } else { |
|
560 /** |
|
561 * Else, set the secondary text to empty to indicate |
|
562 * to the list view to remove the item itself and |
|
563 * shrink its size to a single line size |
|
564 */ |
|
565 textData << QVariant(); |
|
566 } |
|
567 } else { |
|
568 // TODO: Location icon must be shown |
|
569 // only if valid geo-coordinates are present |
|
570 // iconData << HbIcon(locationIcon); |
|
571 textData << entry.location(); |
|
572 } |
|
573 // Add the end time to the list item |
|
574 if (eventStartTime < eventEndTime) { |
|
575 QString endtime = locale.format(eventEndTime, r_qtn_time_usual_with_zero); |
|
576 endtime.append(" "); |
|
577 textData << endtime; |
|
578 }else { |
|
579 textData<<QString(" "); |
|
580 } |
|
581 // Get the list model index and set the text and icon data |
|
582 QModelIndex listIndex = mListModel->index(index, 0); |
|
583 mListModel->setData(listIndex, textData, Qt::DisplayRole); |
|
584 mListModel->setData(listIndex, iconData, Qt::DecorationRole); |
|
585 |
|
586 // Disable item stretching by removing the dynamic property |
|
587 HbListViewItem *listViewItem = static_cast<HbListViewItem*> |
|
588 (mEventsList->itemByIndex(mListModel->index(index, 0))); |
|
589 if (listViewItem) { |
|
590 listViewItem->setProperty(stretchLayout, false); |
|
591 } |
|
592 } |
|
593 |
|
594 // ---------------------------------------------------------------------------- |
|
595 // CalenDayViewWidget::addNonTimedEventToList |
|
596 // Rest of the details are commented in the header |
|
597 // ---------------------------------------------------------------------------- |
|
598 // |
|
599 void CalenDayViewWidget::addNonTimedEventToList(int index, AgendaEntry entry) |
|
600 { |
|
601 QVariantList textData; |
|
602 QVariantList iconData; |
|
603 |
|
604 /** |
|
605 * IMPORTANT NOTE: All the text and icon items must be |
|
606 * inserted into the variant list in a specific order. |
|
607 * If not, chaos will set it!!! |
|
608 * On a more serious note, the mesh layout depends on the |
|
609 * fact that the icons and text data will be added in a |
|
610 * particular order. If one of the items go missing, the |
|
611 * layout might get messed up. Also in case a particular item |
|
612 * is not required to be added in the middle of the list, an |
|
613 * empty QVariant must be added to indicate to the list view |
|
614 * that the item must be removed from the layout. |
|
615 * Do not mess with the order in case you are not sure what |
|
616 * you are exactly doing. |
|
617 */ |
|
618 |
|
619 // The first column text has to be empty |
|
620 textData << QVariant(); |
|
621 |
|
622 // Get the entry subject |
|
623 QString subject = entry.summary(); |
|
624 if (subject.isEmpty() || subject.isNull()) { |
|
625 // No subject. Add "(No subject)" text |
|
626 subject.append(hbTrId("txt_calendar_dblist_unnamed")); |
|
627 } |
|
628 // Add the subject to the text list |
|
629 // This MUST be the second item in the list |
|
630 textData << subject; |
|
631 |
|
632 // Get the entry type |
|
633 AgendaEntry::Type entryType = entry.type(); |
|
634 |
|
635 if (entryType == AgendaEntry::TypeAnniversary) { |
|
636 // Nothing to do as of now as anniversary events |
|
637 // cannot be created |
|
638 // TODO: To be handled in case of sync |
|
639 } else if (entryType == AgendaEntry::TypeEvent) { |
|
640 // This is an all day event |
|
641 // Append the all-day icon |
|
642 iconData << HbIcon(allDayIcon); |
|
643 |
|
644 // Check if alarm is enabled for the entry |
|
645 if (entry.alarm().isNull()) { |
|
646 // Insert a blank icon. Else next text item will get shifted to left |
|
647 iconData << HbIcon(); |
|
648 } else { |
|
649 // if entry is not repeating in place of reminder icon put a blank |
|
650 // icon and move reminder icon to the place of repeating icon |
|
651 if (!entry.isRepeating()) { |
|
652 iconData << HbIcon(); |
|
653 } |
|
654 iconData << HbIcon(reminderIcon); |
|
655 } |
|
656 |
|
657 // Check if the entry is recurring |
|
658 if (entry.isRepeating()) { |
|
659 iconData << HbIcon(repeatIcon); |
|
660 } else { |
|
661 // put the blank icon only when both reminder and repeating icons |
|
662 // are not there |
|
663 if (entry.alarm().isNull()) { |
|
664 iconData << HbIcon(); |
|
665 } |
|
666 } |
|
667 |
|
668 // Append the location |
|
669 if (!entry.location().isEmpty()) { |
|
670 textData << entry.location(); |
|
671 // TODO: Location icon must be shown |
|
672 // only if valid geo-coordinates are present |
|
673 // iconData << HbIcon(locationIcon); |
|
674 } else { |
|
675 textData << QVariant(); |
|
676 } |
|
677 // The fourth text item has to be empty |
|
678 textData << QVariant(); |
|
679 |
|
680 } else if (entryType == AgendaEntry::TypeTodo) { |
|
681 // Append the to-do icon |
|
682 iconData << HbIcon(toDoIcon); |
|
683 |
|
684 // Get the due date |
|
685 QDateTime dueDate = entry.endTime(); |
|
686 |
|
687 // Append the date first |
|
688 QString dueDateString(hbTrId("txt_calendar_dblist_val_due_on_1")); |
|
689 QString dueText; |
|
690 dueText.setNum(dueDate.date().day()); |
|
691 dueText.append(singleSpace); |
|
692 |
|
693 // Append the month name next |
|
694 HbExtendedLocale locale = HbExtendedLocale::system(); |
|
695 QString month = locale.monthName(dueDate.date().month()); |
|
696 dueText.append(month); |
|
697 dueText.append(singleSpace); |
|
698 |
|
699 // Append the year |
|
700 QString year; |
|
701 year.setNum(dueDate.date().year()); |
|
702 dueText.append(year); |
|
703 |
|
704 textData << dueDateString.arg(dueText); |
|
705 |
|
706 // The fourth text item has to be empty |
|
707 textData << QVariant(); |
|
708 |
|
709 // Check if alarm is enabled for the entry |
|
710 if (entry.alarm().isNull()) { |
|
711 // Insert a blank icon. Else next text item will get shifted to left |
|
712 iconData << HbIcon(); |
|
713 } else { |
|
714 // if entry is not repeating in place of reminder icon put a blank |
|
715 // icon and move reminder icon to the place of repeating icon |
|
716 if (!entry.isRepeating()) { |
|
717 iconData << HbIcon(); |
|
718 } |
|
719 iconData << HbIcon(reminderIcon); |
|
720 } |
|
721 |
|
722 // Check if the entry is recurring |
|
723 if (entry.isRepeating()) { |
|
724 iconData << HbIcon(repeatIcon); |
|
725 } else { |
|
726 // Insert the blank icon only when both reminder and repeating icons |
|
727 // are not there |
|
728 if (entry.alarm().isNull()) { |
|
729 iconData << HbIcon(); |
|
730 } |
|
731 } |
|
732 } |
|
733 |
|
734 // Get the list model index and set the text and icon data |
|
735 QModelIndex listIndex = mListModel->index(index, 0); |
|
736 mListModel->setData(listIndex, textData, Qt::DisplayRole); |
|
737 mListModel->setData(listIndex, iconData, Qt::DecorationRole); |
|
738 |
|
739 // Enable item stretching by adding the dynamic property |
|
740 HbListViewItem *listViewItem = static_cast<HbListViewItem*> |
|
741 (mEventsList->itemByIndex(mListModel->index(index, 0))); |
|
742 Qt::Orientation orientation = mServices.MainWindow().orientation(); |
|
743 // Apply stretch only for landscape orientation |
|
744 if (listViewItem) { |
|
745 if (Qt::Horizontal == orientation) { |
|
746 listViewItem->setProperty(stretchLayout, true); |
|
747 } else { |
|
748 listViewItem->setProperty(stretchLayout, false); |
|
749 } |
|
750 } |
|
751 } |
|
752 |
|
753 // ---------------------------------------------------------------------------- |
|
754 // CalenDayViewWidget::handleListItemStretching |
|
755 // Rest of the details are commented in the header |
|
756 // ---------------------------------------------------------------------------- |
|
757 // |
|
758 void CalenDayViewWidget::handleListItemStretching(Qt::Orientation orientation) |
|
759 { |
|
760 if (mInstanceArray.count() == 0) { |
|
761 // Nothing much to do. Simply return |
|
762 return; |
|
763 } |
|
764 for(int index = 0; index < mInstanceArray.count() ; index ++) { |
|
765 AgendaEntry entry = mInstanceArray[index]; |
|
766 if (!entry.isNull()) { |
|
767 AgendaEntry::Type eventType = entry.type(); |
|
768 switch(eventType) { |
|
769 // Apply the stretching to only to-do's, |
|
770 // anniversary and all-day event types |
|
771 case AgendaEntry::TypeTodo: |
|
772 case AgendaEntry::TypeEvent: |
|
773 case AgendaEntry::TypeAnniversary: |
|
774 { |
|
775 // Get the list view item corresponding to the index |
|
776 HbListViewItem *listItem = static_cast<HbListViewItem*> |
|
777 (mEventsList->itemByIndex(mListModel->index(index, 0))); |
|
778 if (listItem) { |
|
779 if (orientation == Qt::Horizontal) { |
|
780 // Set a dynamic property to indicate that this list item |
|
781 // must be stretched in landscape. |
|
782 // NOTE: Property name MUST match the name specified in |
|
783 // css file, else wierd things might happen |
|
784 listItem->setProperty(stretchLayout, true); |
|
785 } |
|
786 } |
|
787 } |
|
788 break; |
|
789 default: |
|
790 { |
|
791 HbListViewItem *listItem = static_cast<HbListViewItem*> |
|
792 (mEventsList->itemByIndex(mListModel->index(index, 0))); |
|
793 if (listItem) { |
|
794 listItem->setProperty(stretchLayout, false); |
|
795 } |
|
796 break; |
|
797 } |
|
798 } |
|
799 } |
|
800 } |
|
801 } |
|
802 |
|
803 // ---------------------------------------------------------------------------- |
|
804 // CalenDayViewWidget::getIndexToScrollTo |
|
805 // Rest of the details are commented in the header |
|
806 // ---------------------------------------------------------------------------- |
|
807 // |
|
808 int CalenDayViewWidget::getIndexToScrollTo() |
|
809 { |
|
810 int scrollIndex = 0; |
|
811 TCalenInstanceId instanceId = mServices.Context().instanceId(); |
|
812 if (instanceId == TCalenInstanceId::nullInstanceId()) { |
|
813 // If the instance is not set, then scroll to zero index |
|
814 return scrollIndex; |
|
815 } |
|
816 |
|
817 for (int index = 0 ; index < mInstanceArray.count() ; index++) { |
|
818 AgendaEntry entry = mInstanceArray[index]; |
|
819 if (entry.id() == instanceId.mEntryLocalUid) { |
|
820 // Match found. |
|
821 scrollIndex = index; |
|
822 break; |
|
823 } |
|
824 } |
|
825 return scrollIndex; |
|
826 } |
|
827 |
|
828 // ---------------------------------------------------------------------------- |
|
829 // CalenDayViewWidget::showHideRegionalInformation |
|
830 // To Show and hide regional plugin label depends upon settings |
|
831 // ---------------------------------------------------------------------------- |
|
832 // |
|
833 void CalenDayViewWidget::showHideRegionalInformation() |
|
834 { |
|
835 if (mView->pluginEnabled()) { |
|
836 XQSettingsKey regionalInfo(XQSettingsKey::TargetCentralRepository, |
|
837 KCRUidCalendar, KCalendarShowRegionalInfo); |
|
838 |
|
839 int showRegionalInfo = |
|
840 mSettingsManager->readItemValue(regionalInfo).toUInt(); |
|
841 if (showRegionalInfo) { |
|
842 |
|
843 if (!mRegionalInfoGroupBox) { |
|
844 mRegionalInfoGroupBox = new HbGroupBox(); |
|
845 CalenPluginLabel *regionalInfo = new CalenPluginLabel( |
|
846 mServices, this); |
|
847 regionalInfo->setFontSpec(HbFontSpec(HbFontSpec::Primary)); |
|
848 mRegionalInfoGroupBox->setContentWidget(regionalInfo); |
|
849 mRegionalPluginLayout->insertItem(1, mRegionalInfoGroupBox); |
|
850 } |
|
851 QString *pluginString = mView->pluginText(); |
|
852 HbLabel *pluginInfoLabel = qobject_cast <HbLabel *> |
|
853 (mRegionalInfoGroupBox->contentWidget()); |
|
854 pluginInfoLabel->setPlainText(*pluginString); |
|
855 } |
|
856 } else { |
|
857 if (mRegionalInfoGroupBox) { |
|
858 mRegionalPluginLayout->removeItem(mRegionalInfoGroupBox); |
|
859 delete mRegionalInfoGroupBox; |
|
860 mRegionalInfoGroupBox = NULL; |
|
861 } |
|
862 } |
|
863 } |
|
864 |
|
865 // ---------------------------------------------------------------------------- |
|
866 // CalenDayViewWidget::createNewEvent |
|
867 // Rest of the details are commented in the header |
|
868 // ---------------------------------------------------------------------------- |
|
869 // |
|
870 void CalenDayViewWidget::createNewEvent() |
|
871 { |
|
872 // Issue a command to launch editor to create |
|
873 // a new event |
|
874 mServices.IssueCommandL(ECalenNewMeeting); |
|
875 } |
|
876 |
|
877 // ---------------------------------------------------------------------------- |
|
878 // CalenDayViewWidget::editEntry |
|
879 // Rest of the details are commented in the header |
|
880 // ---------------------------------------------------------------------------- |
|
881 // |
|
882 void CalenDayViewWidget::editEntry() |
|
883 { |
|
884 // Check if the selected index is valid |
|
885 if (mSelectedIndex < 0 || mSelectedIndex > mInstanceArray.count()) { |
|
886 return; |
|
887 } |
|
888 |
|
889 // Get the entry details first |
|
890 AgendaEntry entry = mInstanceArray[mSelectedIndex]; |
|
891 if (AgendaEntry::TypeTodo == entry.type()) { |
|
892 // Load the notes editor plugin if not loaded. |
|
893 if (!mNotesPluginLoaded) { |
|
894 // Launch the to-do editor using notes editor plugin api |
|
895 QDir dir(NOTES_EDITOR_PLUGIN_PATH); |
|
896 QString pluginName = dir.absoluteFilePath(NOTES_EDITOR_PLUGIN_NAME); |
|
897 |
|
898 // Create NotesEditor plugin loader object. |
|
899 mNotesEditorPluginLoader = new QPluginLoader(pluginName); |
|
900 |
|
901 // Load the plugin |
|
902 mNotesPluginLoaded = mNotesEditorPluginLoader->load(); |
|
903 } |
|
904 |
|
905 QObject *plugin = qobject_cast<QObject*> ( |
|
906 mNotesEditorPluginLoader->instance()); |
|
907 |
|
908 NotesEditorInterface* interface = |
|
909 qobject_cast<NotesEditorInterface*>(plugin); |
|
910 |
|
911 interface->edit(entry, mServices.agendaInterface()); |
|
912 |
|
913 connect( |
|
914 interface, SIGNAL(editingCompleted(bool)), |
|
915 this, SLOT(noteEditingCompleted(bool))); |
|
916 } else { |
|
917 // Set the context |
|
918 setContextFromHighlight(entry); |
|
919 // Issue a command to launch the editor to edit this entry |
|
920 mServices.IssueCommandL(ECalenEditCurrentEntry); |
|
921 } |
|
922 } |
|
923 |
|
924 // ---------------------------------------------------------------------------- |
|
925 // CalenDayViewWidget::viewEntry |
|
926 // Rest of the details are commented in the header |
|
927 // ---------------------------------------------------------------------------- |
|
928 // |
|
929 void CalenDayViewWidget::viewEntry() |
|
930 { |
|
931 // Get the entry details first |
|
932 AgendaEntry entry = mInstanceArray[mSelectedIndex]; |
|
933 |
|
934 // Set the context |
|
935 setContextFromHighlight(entry); |
|
936 |
|
937 // Launch the event viewer. |
|
938 mServices.IssueCommandL(ECalenEventView); |
|
939 } |
|
940 |
|
941 |
|
942 // ---------------------------------------------------------------------------- |
|
943 // CalenDayViewWidget::deleteEntry |
|
944 // Rest of the details are commented in the header |
|
945 // ---------------------------------------------------------------------------- |
|
946 // |
|
947 void CalenDayViewWidget::deleteEntry() |
|
948 { |
|
949 // Check if the selected index is valid |
|
950 if (mSelectedIndex < 0 || mSelectedIndex > mInstanceArray.count()) { |
|
951 return; |
|
952 } |
|
953 |
|
954 // Get the entry details |
|
955 AgendaEntry entry = mInstanceArray[mSelectedIndex]; |
|
956 // Set the context |
|
957 setContextFromHighlight(entry); |
|
958 // Issue the command to delete the entry |
|
959 mServices.IssueCommandL(ECalenDeleteCurrentEntry); |
|
960 } |
|
961 |
|
962 // ---------------------------------------------------------------------------- |
|
963 // CalenDayViewWidget::markAsDone |
|
964 // Rest of the details are commented in the header |
|
965 // ---------------------------------------------------------------------------- |
|
966 // |
|
967 void CalenDayViewWidget::markAsDone() |
|
968 { |
|
969 // Check if the selected index is valid |
|
970 if (mSelectedIndex < 0 || mSelectedIndex > mInstanceArray.count()) { |
|
971 return; |
|
972 } |
|
973 |
|
974 // Get the entry details |
|
975 AgendaEntry entry = mInstanceArray[mSelectedIndex]; |
|
976 |
|
977 // Check again if the event is of type to-to |
|
978 if (AgendaEntry::TypeTodo == entry.type()) { |
|
979 // Set the status of the to-do as completed |
|
980 entry.setStatus(AgendaEntry::TodoCompleted); |
|
981 // Update the completed date and time |
|
982 entry.setCompletedDateTime(mDate); |
|
983 |
|
984 // Update the entry in the database |
|
985 mServices.agendaInterface()->setCompleted(entry, true, mDate); |
|
986 mServices.IssueCommandL(ECalenStartActiveStep); |
|
987 } |
|
988 } |
|
989 |
|
990 // ---------------------------------------------------------------------------- |
|
991 // CalenDayViewWidget::itemLongPressed |
|
992 // Rest of the details are commented in the header |
|
993 // ---------------------------------------------------------------------------- |
|
994 // |
|
995 void CalenDayViewWidget::itemLongPressed(HbAbstractViewItem* listViewItem, |
|
996 const QPointF& coords) |
|
997 { |
|
998 mLongTapEventFlag = true; |
|
999 // Update the selection index first |
|
1000 mSelectedIndex = listViewItem->modelIndex().row(); |
|
1001 |
|
1002 if (mSelectedIndex < 0 || mSelectedIndex > mInstanceArray.count()) { |
|
1003 // Invalid index |
|
1004 return; |
|
1005 } |
|
1006 |
|
1007 AgendaEntry entry = mInstanceArray[mSelectedIndex]; |
|
1008 |
|
1009 // Create new menu. |
|
1010 HbMenu *contextMenu = new HbMenu(); |
|
1011 |
|
1012 // Add the open option |
|
1013 HbAction *openAction = contextMenu->addAction( |
|
1014 hbTrId("txt_common_menu_open")); |
|
1015 |
|
1016 // Check the type of event |
|
1017 if (AgendaEntry::TypeTodo == entry.type()) { |
|
1018 // Add an option to mark the note as complete |
|
1019 HbAction *completeAction = contextMenu->addAction( |
|
1020 hbTrId("txt_calendar_menu_mark_as_done")); |
|
1021 } |
|
1022 |
|
1023 // Add the edit option |
|
1024 HbAction *editAction = contextMenu->addAction( |
|
1025 hbTrId("txt_common_menu_edit")); |
|
1026 |
|
1027 // Add the delete option |
|
1028 HbAction *deleteAction = contextMenu->addAction( |
|
1029 hbTrId("txt_common_menu_delete")); |
|
1030 |
|
1031 contextMenu->setDismissPolicy(HbMenu::TapAnywhere); |
|
1032 |
|
1033 // Show context sensitive menu. |
|
1034 // Param const QPointF& coordinate - is a longpress position. |
|
1035 contextMenu->setPreferredPos(coords); |
|
1036 connect(contextMenu, SIGNAL(aboutToClose()), |
|
1037 this, |
|
1038 SLOT(contextMenuClosed())); |
|
1039 |
|
1040 contextMenu->open(this, SLOT(contextManuTriggered(HbAction *))); |
|
1041 } |
|
1042 |
|
1043 // ---------------------------------------------------------------------------- |
|
1044 // CalenDayViewWidget::itemActivated |
|
1045 // Rest of the details are commented in the header |
|
1046 // ---------------------------------------------------------------------------- |
|
1047 // |
|
1048 void CalenDayViewWidget::itemActivated(const QModelIndex &index) |
|
1049 { |
|
1050 // Update the selection index first |
|
1051 mSelectedIndex = index.row(); |
|
1052 |
|
1053 // Check if the selected index is valid |
|
1054 if (mSelectedIndex < 0 || mSelectedIndex > mInstanceArray.count()) { |
|
1055 return; |
|
1056 } |
|
1057 if( !mLongTapEventFlag ) { |
|
1058 // Open the event for viewing |
|
1059 viewEntry(); |
|
1060 } |
|
1061 } |
|
1062 |
|
1063 // ---------------------------------------------------------------------------- |
|
1064 // CalenDayViewWidget::itemActivated |
|
1065 // Rest of the details are commented in the header |
|
1066 // ---------------------------------------------------------------------------- |
|
1067 // |
|
1068 void CalenDayViewWidget::noteEditingCompleted(bool status) |
|
1069 { |
|
1070 // We need to refresh the list since user |
|
1071 // might have marked the to-do as complete or |
|
1072 // edited it or deleted it. So get the instance |
|
1073 // list again |
|
1074 if (status) { |
|
1075 mServices.IssueCommandL(ECalenStartActiveStep); |
|
1076 } |
|
1077 } |
|
1078 |
|
1079 // ---------------------------------------------------------------------------- |
|
1080 // CalenDayViewWidget::goToToday |
|
1081 // Rest of the details are commented in the header |
|
1082 // ---------------------------------------------------------------------------- |
|
1083 // |
|
1084 void CalenDayViewWidget::goToToday() |
|
1085 { |
|
1086 // First check if we are not already |
|
1087 // showing today's agenda |
|
1088 if (mDate == CalenDateUtils::today()) { |
|
1089 return; |
|
1090 } |
|
1091 |
|
1092 // Set the context for the current day |
|
1093 mServices.Context().setFocusDateL(CalenDateUtils::today(), KCalenDayViewUidValue); |
|
1094 |
|
1095 mView->refreshViewOnGoToDate(); |
|
1096 } |
|
1097 |
|
1098 // ---------------------------------------------------------------------------- |
|
1099 // CalenDayViewWidget::contextMenuClosed |
|
1100 // Rest of the details are commented in the header |
|
1101 // ---------------------------------------------------------------------------- |
|
1102 // |
|
1103 void CalenDayViewWidget::contextMenuClosed() |
|
1104 { |
|
1105 mLongTapEventFlag = false; |
|
1106 } |
|
1107 |
|
1108 // ---------------------------------------------------------------------------- |
|
1109 // CalenDayViewWidget::contextManuTriggered |
|
1110 // Rest of the details are commented in the header |
|
1111 // ---------------------------------------------------------------------------- |
|
1112 // |
|
1113 void CalenDayViewWidget::contextManuTriggered(HbAction *action) |
|
1114 { |
|
1115 if (action->text() == hbTrId("txt_common_menu_open")) { |
|
1116 viewEntry(); |
|
1117 } else if (action->text() == hbTrId("txt_calendar_menu_mark_as_done")) { |
|
1118 markAsDone(); |
|
1119 } else if (action->text() == hbTrId("txt_common_menu_edit")) { |
|
1120 editEntry(); |
|
1121 } else { |
|
1122 if (action->text() == hbTrId("txt_common_menu_delete")) { |
|
1123 deleteEntry(); |
|
1124 } |
|
1125 } |
|
1126 } |
|
1127 // ---------------------------------------------------------------------------- |
|
1128 // CalenDayViewWidget::clearListModel |
|
1129 // clears the list model |
|
1130 // ---------------------------------------------------------------------------- |
|
1131 // |
|
1132 void CalenDayViewWidget::clearListModel() |
|
1133 { |
|
1134 mListModel->clear(); |
|
1135 } |
|
1136 // End of file --Don't remove this. |
|