70 mAgendaUtil, SIGNAL(entryUpdated(ulong)), |
68 mAgendaUtil, SIGNAL(entryUpdated(ulong)), |
71 this, SLOT(updateSourceModel(ulong))); |
69 this, SLOT(updateSourceModel(ulong))); |
72 |
70 |
73 // Populate the model in a different thread. |
71 // Populate the model in a different thread. |
74 QTimer::singleShot(1, this, SLOT(populateSourceModel())); |
72 QTimer::singleShot(1, this, SLOT(populateSourceModel())); |
75 |
|
76 qDebug() << "notes: NotesModel::NotesModel <--"; |
|
77 } |
73 } |
78 |
74 |
79 /*! |
75 /*! |
80 Destructor. |
76 Destructor. |
81 */ |
77 */ |
82 NotesModel::~NotesModel() |
78 NotesModel::~NotesModel() |
83 { |
79 { |
84 qDebug() << "notes: NotesModel::~NotesModel -->"; |
|
85 |
|
86 // Nothing yet. |
80 // Nothing yet. |
87 |
|
88 qDebug() << "notes: NotesModel::~NotesModel <--"; |
|
89 } |
81 } |
90 |
82 |
91 /*! |
83 /*! |
92 Returns the source model to be used with a view. |
84 Returns the source model to be used with a view. |
93 |
85 |
94 \return QAbstractItemModel |
86 \return QAbstractItemModel |
95 \sa QAbstractItemModel, HbListView. |
87 \sa QAbstractItemModel, HbListView. |
96 */ |
88 */ |
97 QAbstractItemModel *NotesModel::sourceModel() |
89 QAbstractItemModel *NotesModel::sourceModel() |
98 { |
90 { |
99 qDebug() << "notes: NotesModel::sourceModel -->"; |
|
100 |
|
101 Q_ASSERT(mSourceModel); |
91 Q_ASSERT(mSourceModel); |
102 |
|
103 qDebug() << "notes: NotesModel::sourceModel <--"; |
|
104 |
|
105 return mSourceModel; |
92 return mSourceModel; |
106 } |
93 } |
107 |
94 |
108 /*! |
95 /*! |
109 Populates the source model. |
96 Populates the source model. |
110 */ |
97 */ |
111 void NotesModel::populateSourceModel() |
98 void NotesModel::populateSourceModel() |
112 { |
99 { |
113 qDebug() << "notes: NotesModel::populateSourceModel -->"; |
|
114 |
|
115 // Clear the model if it has any data already |
100 // Clear the model if it has any data already |
116 mSourceModel->clear(); |
101 mSourceModel->clear(); |
117 mSourceModel->setColumnCount(1); |
102 mSourceModel->setColumnCount(1); |
118 mNotesCount = mInCompTodoCount = mCompTodoCount = 0; |
103 mNotesCount = mInCompTodoCount = mCompTodoCount = 0; |
119 |
104 |
120 // The order of appending the items to the model is: |
105 // The order of appending the items to the model is: |
121 // 1. Notes, 2. Incompleted to-dos, 3. Completed to-dos. |
106 // 1. Notes, 2. Incompleted to-dos, 3. Completed to-dos. |
122 // First get only the notes and populate the model. |
107 // First get only the notes and populate the model. |
123 QList<ulong> entryIds = mAgendaUtil->entryIds( |
108 QList<AgendaEntry> agendaEntyList = mAgendaUtil->fetchAllEntries( |
124 (AgendaUtil::FilterFlags) (AgendaUtil::IncludeNotes)); |
109 (AgendaUtil::FilterFlags) (AgendaUtil::IncludeNotes)); |
125 |
110 |
126 // Add the notes to the model. |
111 // Add the notes to the model. |
127 appendNotesToModel(entryIds); |
112 appendNotesToModel(agendaEntyList); |
128 |
113 |
129 // Get the incompleted to-dos. |
114 // Get the incompleted to-dos. |
130 entryIds.clear(); |
115 agendaEntyList.clear(); |
131 entryIds = mAgendaUtil->entryIds( |
116 agendaEntyList = mAgendaUtil->fetchAllEntries( |
132 (AgendaUtil::FilterFlags) (AgendaUtil::IncludeIncompletedTodos)); |
117 (AgendaUtil::FilterFlags) (AgendaUtil::IncludeIncompletedTodos)); |
133 |
118 |
134 // Add the incompleted to-dos to the model. |
119 // Add the incompleted to-dos to the model. |
135 appendInCompTodosToModel(entryIds); |
120 appendInCompTodosToModel(agendaEntyList); |
136 |
121 |
137 // Get the completed to-dos. |
122 // Get the completed to-dos. |
138 entryIds.clear(); |
123 agendaEntyList.clear(); |
139 entryIds = mAgendaUtil->entryIds( |
124 agendaEntyList = mAgendaUtil->fetchAllEntries( |
140 (AgendaUtil::FilterFlags) (AgendaUtil::IncludeCompletedTodos)); |
125 (AgendaUtil::FilterFlags) (AgendaUtil::IncludeCompletedTodos)); |
141 |
126 |
142 // Add the completed to-dos to the model. |
127 // Add the completed to-dos to the model. |
143 appendCompTodosToModel(entryIds); |
128 appendCompTodosToModel(agendaEntyList); |
144 |
|
145 qDebug() << "notes: NotesModel::populateSourceModel <--"; |
|
146 } |
129 } |
147 |
130 |
148 /*! |
131 /*! |
149 Updates the source model with the given entry `id'. |
132 Updates the source model with the given entry `id'. |
150 The entry could be either have undergone a status change or have just been |
133 The entry could be either have undergone a status change or have just been |
378 mSourceModel->setData( |
348 mSourceModel->setData( |
379 modelIndex, entry.type(), NotesNamespace::TypeRole); |
349 modelIndex, entry.type(), NotesNamespace::TypeRole); |
380 |
350 |
381 // Set the display data to the index. |
351 // Set the display data to the index. |
382 if (AgendaEntry::TypeNote == entry.type()) { |
352 if (AgendaEntry::TypeNote == entry.type()) { |
|
353 QString displayText; |
|
354 QString dateTimeText; |
|
355 QString modifiedText; |
|
356 |
383 // Read modification time from agenda entry |
357 // Read modification time from agenda entry |
384 QString displayText; |
358 QDateTime entryStartDateTime = entry.startTime(); |
385 QString timeText(qtTrId("txt_notes_dblist_val_modified_on_1_2")); |
359 |
386 QString modifiedDateText = |
360 // If modified on today,show only modified time otherwise show the |
387 entry.startTime().date().toString("dd/MM/yyyy"); |
361 // modified date. |
388 QString modifiedTimeText = |
362 if ((QDate::currentDate()) == entryStartDateTime.date() ) { |
389 entry.startTime().time().toString("hh:mm ap"); |
363 dateTimeText = |
390 displayText = timeText.arg(modifiedDateText,modifiedTimeText); |
364 hbTrId("txt_notes_dblist_note_modified_at_time"); |
|
365 modifiedText = |
|
366 entryStartDateTime.time().toString(timeFormatString()); |
|
367 } else { |
|
368 dateTimeText = |
|
369 hbTrId("txt_notes_dblist_note_modified_on_date"); |
|
370 modifiedText = |
|
371 entryStartDateTime.date().toString(dateFormatString()); |
|
372 } |
|
373 |
|
374 displayText = dateTimeText.arg(modifiedText); |
391 |
375 |
392 QStringList stringList; |
376 QStringList stringList; |
393 stringList << entry.description().left(15) << displayText; |
377 stringList << entry.description().left(15) << displayText; |
394 // Set the data. |
378 // Set the data. |
395 mSourceModel->setData( |
379 mSourceModel->setData( |
396 modelIndex, stringList, Qt::DisplayRole); |
380 modelIndex, stringList, Qt::DisplayRole); |
397 // Set the favourite icon. |
381 // Set the favourite icon. |
398 if (entry.favourite()) { |
382 if (entry.favourite()) { |
399 QList<QVariant> iconList; |
383 QList<QVariant> iconList; |
400 iconList.append(QVariant(QVariant::Invalid)); |
384 iconList.append(HbIcon("qtg_small_note")); |
401 iconList.append(HbIcon("qtg_mono_favourites")); |
385 iconList.append(HbIcon("qtg_mono_favourites")); |
402 mSourceModel->setData(modelIndex, iconList, Qt::DecorationRole); |
386 mSourceModel->setData(modelIndex, iconList, Qt::DecorationRole); |
403 } else { |
387 } else { |
404 QList<QVariant> iconList; |
388 QList<QVariant> iconList; |
405 iconList.append(QVariant(QVariant::Invalid)); |
389 iconList.append(HbIcon("qtg_small_note")); |
406 iconList.append(QVariant(QVariant::Invalid)); |
390 iconList.append(QVariant(QVariant::Invalid)); |
407 mSourceModel->setData(modelIndex, iconList, Qt::DecorationRole); |
391 mSourceModel->setData(modelIndex, iconList, Qt::DecorationRole); |
408 } |
392 } |
409 } else if (AgendaEntry::TypeTodo == entry.type()) { |
393 } else if (AgendaEntry::TypeTodo == entry.type()) { |
410 QStringList stringList; |
394 QStringList stringList; |
411 stringList << entry.summary(); |
395 if (entry.summary().isEmpty()) { |
|
396 // If empty set unnamed text |
|
397 stringList<<hbTrId("txt_notes_dblist_unnamed"); |
|
398 } else { |
|
399 stringList << entry.summary(); |
|
400 } |
412 if (AgendaEntry::TodoNeedsAction == entry.status()) { |
401 if (AgendaEntry::TodoNeedsAction == entry.status()) { |
413 // Read due date from agenda entry |
402 // Read due date from agenda entry |
414 QString displayText; |
403 QString displayText; |
415 QString timeText(hbTrId("txt_notes_dblist_val_due_on_1")); |
404 QString timeText(hbTrId("txt_notes_dblist_val_due_on_1")); |
416 QString dueDateText = |
405 QString dueDateText = |
417 entry.startTime().toString("dd/MM/yyyy"); |
406 entry.startTime().toString(dateFormatString()); |
418 displayText = timeText.arg(dueDateText); |
407 displayText = timeText.arg(dueDateText); |
419 stringList << displayText; |
408 stringList << displayText; |
420 } |
409 } |
421 // Set the data. |
410 // Set the data. |
422 mSourceModel->setData( |
411 mSourceModel->setData( |
428 iconList.append(HbIcon("qtg_small_todo_done")); |
417 iconList.append(HbIcon("qtg_small_todo_done")); |
429 } else { |
418 } else { |
430 iconList.append(HbIcon("qtg_small_todo")); |
419 iconList.append(HbIcon("qtg_small_todo")); |
431 } |
420 } |
432 |
421 |
433 // Set the alarm icon if reminder is set. |
422 if (1 == entry.priority()) { |
434 if (!entry.alarm().isNull()) { |
423 // Set the High Priority icon if priority is high. |
|
424 iconList.append(HbIcon("qtg_small_priority_high")); |
|
425 } else if (!entry.alarm().isNull()) { |
|
426 // Set the alarm if set. |
435 iconList.append(HbIcon("qtg_mono_alarm")); |
427 iconList.append(HbIcon("qtg_mono_alarm")); |
436 } else { |
428 } else { |
437 iconList.append(QVariant(QVariant::Invalid)); |
429 iconList.append(QVariant(QVariant::Invalid)); |
438 } |
430 } |
|
431 |
439 // Set the icons. |
432 // Set the icons. |
440 mSourceModel->setData(modelIndex, iconList, Qt::DecorationRole); |
433 mSourceModel->setData(modelIndex, iconList, Qt::DecorationRole); |
441 } |
434 } |
442 |
|
443 qDebug() << "notes: NotesModel::modifyEntryInModel <--"; |
|
444 } |
435 } |
445 |
436 |
446 /*! |
437 /*! |
447 Appends notes to the model. |
438 Appends notes to the model. |
448 |
439 |
449 \param ids QList of uids containing the notes. |
440 \param ids QList of uids containing the notes. |
450 */ |
441 */ |
451 void NotesModel::appendNotesToModel(QList<ulong> &ids) |
442 void NotesModel::appendNotesToModel(QList<AgendaEntry> &agendaEntryList) |
452 { |
443 { |
453 qDebug() << "notes: NotesModel::appendNotesToModel -->"; |
444 int entriesCount = agendaEntryList.count(); |
454 |
|
455 // Iterate and add notes to the model. |
445 // Iterate and add notes to the model. |
456 mSourceModel->insertRows(mSourceModel->rowCount(), ids.count()); |
446 mSourceModel->insertRows(mSourceModel->rowCount(), entriesCount); |
457 int rowCount = mSourceModel->rowCount(); |
447 int rowCount = mSourceModel->rowCount(); |
458 for (int idIter = 0, modelIter = rowCount - ids.count(); |
448 for (int idIter = 0, modelIter = rowCount - entriesCount; |
459 idIter < ids.count(); idIter++, modelIter++) { |
449 idIter < entriesCount; idIter++, modelIter++) { |
460 // Fetch the note details. |
450 |
461 ulong id = ids[rowCount - 1 - idIter]; |
451 // Read the note details. |
462 AgendaEntry entry = mAgendaUtil->fetchById(id); |
452 AgendaEntry entry = agendaEntryList[rowCount - 1 - idIter]; |
463 |
453 |
464 if (AgendaEntry::TypeNote != entry.type()) { |
454 if (AgendaEntry::TypeNote != entry.type()) { |
465 continue; |
455 continue; |
466 } |
456 } |
467 |
457 |
468 // Create a model index. |
458 // Create a model index. |
469 QModelIndex mdlIndex = mSourceModel->index(qAbs(modelIter), 0); |
459 QModelIndex mdlIndex = mSourceModel->index(qAbs(modelIter), 0); |
470 |
460 |
471 // Set the note id. |
461 // Set the note id. |
472 mSourceModel->setData( |
462 mSourceModel->setData( |
473 mdlIndex, (qulonglong) id, NotesNamespace::IdRole); |
463 mdlIndex, (qulonglong) entry.id(), NotesNamespace::IdRole); |
474 // Set the type of the note. |
464 // Set the type of the note. |
475 mSourceModel->setData( |
465 mSourceModel->setData( |
476 mdlIndex, entry.type(), NotesNamespace::TypeRole); |
466 mdlIndex, entry.type(), NotesNamespace::TypeRole); |
477 // Set the favourite property. |
467 // Set the favourite property. |
478 mSourceModel->setData( |
468 mSourceModel->setData( |
479 mdlIndex, entry.favourite(), NotesNamespace::FavouriteRole); |
469 mdlIndex, entry.favourite(), NotesNamespace::FavouriteRole); |
480 |
470 |
481 // Set the display data now. |
471 // Set the display data now. |
482 // Read modification time from agenda entry |
472 // Read modification time from agenda entry |
483 QString displayText; |
473 QString displayText; |
484 QString timeText(hbTrId("txt_notes_dblist_val_modified_on_1_2")); |
474 QString dateTimeText; |
485 QString modifiedDateText = |
475 QString modifiedText; |
486 entry.lastModifiedDateTime().date().toString("dd/MM/yyyy"); |
476 |
487 QString modifiedTimeText = |
477 // Show the creation time if entry is not modified. |
488 entry.lastModifiedDateTime().time().toString("hh:mm ap"); |
478 if (entry.dtStamp().isValid()) { |
489 displayText = timeText.arg(modifiedDateText,modifiedTimeText); |
479 QDateTime creationDateTime = entry.dtStamp(); |
|
480 |
|
481 // If created on today,show only creation time otherwise show the |
|
482 // creation date. |
|
483 if ((QDate::currentDate()) == creationDateTime.date()) { |
|
484 dateTimeText = |
|
485 hbTrId("txt_notes_dblist_note_created_at_time"); |
|
486 modifiedText = |
|
487 creationDateTime.time().toString(timeFormatString()); |
|
488 } else { |
|
489 dateTimeText = |
|
490 hbTrId("txt_notes_dblist_note_created_on_date"); |
|
491 modifiedText = |
|
492 creationDateTime.date().toString(dateFormatString()); |
|
493 } |
|
494 } else { |
|
495 QDateTime modifiedDateTime = entry.lastModifiedDateTime(); |
|
496 |
|
497 // If modified on today,show only modified time otherwise show the |
|
498 // modified date. |
|
499 if ((QDate::currentDate()) == modifiedDateTime.date() ) { |
|
500 dateTimeText = |
|
501 hbTrId("txt_notes_dblist_note_modified_at_time"); |
|
502 modifiedText = |
|
503 modifiedDateTime.time().toString(timeFormatString()); |
|
504 } else { |
|
505 dateTimeText = |
|
506 hbTrId("txt_notes_dblist_note_modified_on_date"); |
|
507 modifiedText = |
|
508 modifiedDateTime.date().toString(dateFormatString()); |
|
509 } |
|
510 } |
|
511 |
|
512 displayText = dateTimeText.arg(modifiedText); |
490 |
513 |
491 QStringList stringList; |
514 QStringList stringList; |
492 stringList << entry.description().left(100) << displayText; |
515 stringList << entry.description().left(100) << displayText; |
493 // Set the data. |
516 // Set the data. |
494 mSourceModel->setData( |
517 mSourceModel->setData( |
495 mdlIndex, stringList, Qt::DisplayRole); |
518 mdlIndex, stringList, Qt::DisplayRole); |
496 |
519 |
497 if (entry.favourite()) { |
520 if (entry.favourite()) { |
498 // Set the favourite icon. |
521 // Set the favourite icon. |
499 QList<QVariant> iconList; |
522 QList<QVariant> iconList; |
500 iconList.append(QVariant(QVariant::Invalid)); |
523 iconList.append(HbIcon("qtg_small_note")); |
501 iconList.append(HbIcon("qtg_mono_favourites")); |
524 iconList.append(HbIcon("qtg_mono_favourites")); |
502 mSourceModel->setData(mdlIndex, iconList, Qt::DecorationRole); |
525 mSourceModel->setData(mdlIndex, iconList, Qt::DecorationRole); |
503 } else { |
526 } else { |
504 QList<QVariant> iconList; |
527 QList<QVariant> iconList; |
505 iconList.append(QVariant(QVariant::Invalid)); |
528 iconList.append(HbIcon("qtg_small_note")); |
506 iconList.append(QVariant(QVariant::Invalid)); |
529 iconList.append(QVariant(QVariant::Invalid)); |
507 mSourceModel->setData(mdlIndex, iconList, Qt::DecorationRole); |
530 mSourceModel->setData(mdlIndex, iconList, Qt::DecorationRole); |
508 } |
531 } |
509 |
532 |
510 // Update the notes count. |
533 // Update the notes count. |
511 mNotesCount++; |
534 mNotesCount++; |
512 } |
535 } |
513 |
|
514 qDebug() << "notes: NotesModel::appendNotesToModel <--"; |
|
515 } |
536 } |
516 |
537 |
517 /*! |
538 /*! |
518 Appends incompleted to-dos to the model. |
539 Appends incompleted to-dos to the model. |
519 |
540 |
520 \param ids QList of uids containing the incompleted to-dos. |
541 \param ids QList of uids containing the incompleted to-dos. |
521 */ |
542 */ |
522 void NotesModel::appendInCompTodosToModel(QList<ulong> &ids) |
543 void NotesModel::appendInCompTodosToModel(QList<AgendaEntry> &agendaEntryList) |
523 { |
544 { |
524 qDebug() << "notes: NotesModel::appendInCompTodosToModel -->"; |
545 int entriesCount = agendaEntryList.count(); |
525 |
|
526 // Iterate and add incomplete to-do to the model. |
546 // Iterate and add incomplete to-do to the model. |
527 mSourceModel->insertRows(mSourceModel->rowCount(), ids.count()); |
547 mSourceModel->insertRows(mSourceModel->rowCount(), entriesCount); |
528 int rowCount = mSourceModel->rowCount(); |
548 int rowCount = mSourceModel->rowCount(); |
529 for (int idIter = 0, modelIter = rowCount - ids.count(); |
549 for (int idIter = 0, modelIter = rowCount - entriesCount; |
530 idIter < ids.count(); idIter++, modelIter++) { |
550 idIter < entriesCount; idIter++, modelIter++) { |
531 // Fetch the to-do details. |
551 |
532 ulong id = ids[idIter]; |
552 // Read the to-do details. |
533 AgendaEntry entry = mAgendaUtil->fetchById(id); |
553 AgendaEntry entry = agendaEntryList[idIter]; |
534 |
554 |
535 if (AgendaEntry::TypeTodo != entry.type()) { |
555 if (AgendaEntry::TypeTodo != entry.type()) { |
536 continue; |
556 continue; |
537 } |
557 } |
538 |
558 |
543 // Create a model index. |
563 // Create a model index. |
544 QModelIndex mdlIndex = mSourceModel->index(modelIter, 0); |
564 QModelIndex mdlIndex = mSourceModel->index(modelIter, 0); |
545 |
565 |
546 // Set the to-do id. |
566 // Set the to-do id. |
547 mSourceModel->setData( |
567 mSourceModel->setData( |
548 mdlIndex, (qulonglong) id, NotesNamespace::IdRole); |
568 mdlIndex, (qulonglong) entry.id(), NotesNamespace::IdRole); |
549 // Set the type of the to-do. |
569 // Set the type of the to-do. |
550 mSourceModel->setData( |
570 mSourceModel->setData( |
551 mdlIndex, entry.type(), NotesNamespace::TypeRole); |
571 mdlIndex, entry.type(), NotesNamespace::TypeRole); |
552 // Set the status of the to-do. |
572 // Set the status of the to-do. |
553 mSourceModel->setData( |
573 mSourceModel->setData( |
554 mdlIndex, (int) entry.status(), NotesNamespace::StatusRole); |
574 mdlIndex, (int) entry.status(), NotesNamespace::StatusRole); |
555 |
575 |
556 // Set the display data now. |
576 // Set the display data now. |
557 QStringList stringList; |
577 QStringList stringList; |
558 stringList << entry.summary(); |
578 if (entry.summary().isEmpty()) { |
|
579 // If empty set unnamed text |
|
580 stringList<<hbTrId("txt_notes_dblist_unnamed"); |
|
581 } else { |
|
582 stringList << entry.summary(); |
|
583 } |
|
584 |
559 if (AgendaEntry::TodoNeedsAction == entry.status()) { |
585 if (AgendaEntry::TodoNeedsAction == entry.status()) { |
560 // Read due date from agenda entry |
586 // Read due date from agenda entry |
561 QString displayText; |
587 QString displayText; |
562 QString timeText(hbTrId("txt_notes_dblist_val_due_on_1")); |
588 QString timeText(hbTrId("txt_notes_dblist_val_due_on_1")); |
563 QString dueDateText = |
589 QString dueDateText = |
564 entry.startTime().toString("dd/MM/yyyy"); |
590 entry.startTime().toString(dateFormatString()); |
565 displayText = timeText.arg(dueDateText); |
591 displayText = timeText.arg(dueDateText); |
566 stringList << displayText; |
592 stringList << displayText; |
567 } |
593 } |
568 // Set the data. |
594 // Set the data. |
569 mSourceModel->setData(mdlIndex, stringList, Qt::DisplayRole); |
595 mSourceModel->setData(mdlIndex, stringList, Qt::DisplayRole); |
570 // Set the to-do done/undone icon based on the status. |
596 // Set the to-do done/undone icon based on the status. |
571 QList<QVariant> iconList; |
597 QList<QVariant> iconList; |
572 iconList.append(HbIcon("qtg_small_todo")); |
598 iconList.append(HbIcon("qtg_small_todo")); |
573 |
599 |
574 // Set the alarm icon if reminder is set. |
600 if (1 == entry.priority()) { |
575 if (!entry.alarm().isNull()) { |
601 // Set the High Priority icon if priority is high. |
|
602 iconList.append(HbIcon("qtg_small_priority_high")); |
|
603 } else if (!entry.alarm().isNull()) { |
|
604 // Set the alarm if set. |
576 iconList.append(HbIcon("qtg_mono_alarm")); |
605 iconList.append(HbIcon("qtg_mono_alarm")); |
577 } else { |
606 } else { |
578 iconList.append(QVariant(QVariant::Invalid)); |
607 iconList.append(QVariant(QVariant::Invalid)); |
579 } |
608 } |
580 |
609 |
582 mSourceModel->setData(mdlIndex, iconList, Qt::DecorationRole); |
611 mSourceModel->setData(mdlIndex, iconList, Qt::DecorationRole); |
583 |
612 |
584 // Update the incompleted to-do count. |
613 // Update the incompleted to-do count. |
585 mInCompTodoCount++; |
614 mInCompTodoCount++; |
586 } |
615 } |
587 |
|
588 qDebug() << "notes: NotesModel::appendInCompTodosToModel <--"; |
|
589 } |
616 } |
590 |
617 |
591 /*! |
618 /*! |
592 Appends incompleted to-dos to the model. |
619 Appends incompleted to-dos to the model. |
593 |
620 |
594 \param ids QList of uids containing the completed to-dos. |
621 \param ids QList of uids containing the completed to-dos. |
595 */ |
622 */ |
596 void NotesModel::appendCompTodosToModel(QList<ulong> &ids) |
623 void NotesModel::appendCompTodosToModel(QList<AgendaEntry> &agendaEntryList) |
597 { |
624 { |
598 qDebug() << "notes: NotesModel::appendCompTodosToModel -->"; |
625 int entriesCount = agendaEntryList.count(); |
599 |
|
600 // Iterate and add complete to-do to the model. |
626 // Iterate and add complete to-do to the model. |
601 mSourceModel->insertRows(mSourceModel->rowCount(), ids.count()); |
627 mSourceModel->insertRows(mSourceModel->rowCount(), entriesCount); |
602 int rowCount = mSourceModel->rowCount(); |
628 int rowCount = mSourceModel->rowCount(); |
603 for (int idIter = 0, modelIter = rowCount - ids.count(); |
629 for (int idIter = 0, modelIter = rowCount - entriesCount; |
604 idIter < ids.count(); idIter++, modelIter++) { |
630 idIter < entriesCount; idIter++, modelIter++) { |
605 // Fetch the to-do details. |
631 |
606 ulong id = ids[idIter]; |
632 // Read the completed to-do details. |
607 AgendaEntry entry = mAgendaUtil->fetchById(id); |
633 AgendaEntry entry = agendaEntryList[idIter]; |
608 |
634 |
609 if (AgendaEntry::TypeTodo != entry.type()) { |
635 if (AgendaEntry::TypeTodo != entry.type()) { |
610 continue; |
636 continue; |
611 } |
637 } |
612 |
638 |
617 // Create a model index. |
643 // Create a model index. |
618 QModelIndex mdlIndex = mSourceModel->index(modelIter, 0); |
644 QModelIndex mdlIndex = mSourceModel->index(modelIter, 0); |
619 |
645 |
620 // Set the to-do id. |
646 // Set the to-do id. |
621 mSourceModel->setData( |
647 mSourceModel->setData( |
622 mdlIndex, (qulonglong) id, NotesNamespace::IdRole); |
648 mdlIndex, (qulonglong) entry.id(), NotesNamespace::IdRole); |
623 // Set the type of the to-do. |
649 // Set the type of the to-do. |
624 mSourceModel->setData( |
650 mSourceModel->setData( |
625 mdlIndex, entry.type(), NotesNamespace::TypeRole); |
651 mdlIndex, entry.type(), NotesNamespace::TypeRole); |
626 // Set the status of the to-do. |
652 // Set the status of the to-do. |
627 mSourceModel->setData( |
653 mSourceModel->setData( |
628 mdlIndex, (int) entry.status(), NotesNamespace::StatusRole); |
654 mdlIndex, (int) entry.status(), NotesNamespace::StatusRole); |
629 |
655 |
630 // Set the display data now. |
656 // Set the display data now. |
631 QStringList stringList; |
657 QStringList stringList; |
632 stringList << entry.summary(); |
658 if (entry.summary().isEmpty()) { |
|
659 // If empty set unnamed text |
|
660 stringList<<hbTrId("txt_notes_dblist_unnamed"); |
|
661 } else { |
|
662 stringList << entry.summary(); |
|
663 } |
633 if (AgendaEntry::TodoCompleted == entry.status()) { |
664 if (AgendaEntry::TodoCompleted == entry.status()) { |
634 // Read completed date from agenda entry |
665 // Read completed date from agenda entry |
635 QString displayText; |
666 QString displayText; |
636 QString timeText(hbTrId("txt_notes_dblist_val_completed_on_1")); |
667 QString timeText(hbTrId("txt_notes_dblist_val_completed_on_1")); |
637 QString completedTimeText = |
668 QString completedTimeText = |
638 entry.completedDateTime().toString("dd/MM/yyyy"); |
669 entry.completedDateTime().toString(dateFormatString()); |
639 displayText = timeText.arg(completedTimeText); |
670 displayText = timeText.arg(completedTimeText); |
640 stringList << displayText; |
671 stringList << displayText; |
641 } |
672 } |
642 // Set the data. |
673 // Set the data. |
643 mSourceModel->setData(mdlIndex, stringList, Qt::DisplayRole); |
674 mSourceModel->setData(mdlIndex, stringList, Qt::DisplayRole); |
689 mdlIndex, entry.favourite(), NotesNamespace::FavouriteRole); |
716 mdlIndex, entry.favourite(), NotesNamespace::FavouriteRole); |
690 |
717 |
691 // Set the display data now. |
718 // Set the display data now. |
692 // Read modification time from agenda entry |
719 // Read modification time from agenda entry |
693 QString displayText; |
720 QString displayText; |
694 QString timeText(hbTrId("txt_notes_dblist_val_modified_on_1_2")); |
721 QString dateTimeText; |
695 QString modifiedDateText = |
722 QString modifiedText; |
696 entry.lastModifiedDateTime().date().toString("dd/MM/yyyy"); |
723 |
697 QString modifiedTimeText = |
724 // Show the creation time if entry is not modified. |
698 entry.lastModifiedDateTime().time().toString("hh:mm ap"); |
725 if (entry.dtStamp().isValid()) { |
699 displayText = timeText.arg(modifiedDateText,modifiedTimeText); |
726 QDateTime creationDateTime = entry.dtStamp(); |
|
727 |
|
728 // If created on today,show only creation time otherwise show the |
|
729 // creation date. |
|
730 if ((QDate::currentDate()) == creationDateTime.date()) { |
|
731 dateTimeText = |
|
732 hbTrId("txt_notes_dblist_note_created_at_time"); |
|
733 modifiedText = |
|
734 creationDateTime.time().toString(timeFormatString()); |
|
735 } else { |
|
736 dateTimeText = |
|
737 hbTrId("txt_notes_dblist_note_created_on_date"); |
|
738 modifiedText = |
|
739 creationDateTime.date().toString(dateFormatString()); |
|
740 } |
|
741 } else { |
|
742 QDateTime modifiedDateTime = entry.lastModifiedDateTime(); |
|
743 |
|
744 // If modified on today,show only modified time otherwise show the |
|
745 // modified date. |
|
746 if ((QDate::currentDate()) == modifiedDateTime.date() ) { |
|
747 dateTimeText = |
|
748 hbTrId("txt_notes_dblist_note_modified_at_time"); |
|
749 modifiedText = |
|
750 modifiedDateTime.time().toString(timeFormatString()); |
|
751 } else { |
|
752 dateTimeText = |
|
753 hbTrId("txt_notes_dblist_note_modified_on_date"); |
|
754 modifiedText = |
|
755 modifiedDateTime.date().toString(dateFormatString()); |
|
756 } |
|
757 } |
|
758 displayText = dateTimeText.arg(modifiedText); |
700 |
759 |
701 QStringList stringList; |
760 QStringList stringList; |
702 stringList << entry.description().left(100) << displayText; |
761 stringList << entry.description().left(100) << displayText; |
703 // Set the data. |
762 // Set the data. |
704 mSourceModel->setData( |
763 mSourceModel->setData( |
705 mdlIndex, stringList, Qt::DisplayRole); |
764 mdlIndex, stringList, Qt::DisplayRole); |
706 |
765 |
707 // Set the favourite icon. |
766 // Set the favourite icon. |
708 if (entry.favourite()) { |
767 if (entry.favourite()) { |
709 QList<QVariant> iconList; |
768 QList<QVariant> iconList; |
710 iconList.append(QVariant(QVariant::Invalid)); |
769 iconList.append(HbIcon("qtg_small_note")); |
711 iconList.append(HbIcon("qtg_mono_favourites")); |
770 iconList.append(HbIcon("qtg_mono_favourites")); |
712 mSourceModel->setData(mdlIndex, iconList, Qt::DecorationRole); |
771 mSourceModel->setData(mdlIndex, iconList, Qt::DecorationRole); |
713 } else { |
772 } else { |
714 QList<QVariant> iconList; |
773 QList<QVariant> iconList; |
715 iconList.append(QVariant(QVariant::Invalid)); |
774 iconList.append(HbIcon("qtg_small_note")); |
716 iconList.append(QVariant(QVariant::Invalid)); |
775 iconList.append(QVariant(QVariant::Invalid)); |
717 mSourceModel->setData(mdlIndex, iconList, Qt::DecorationRole); |
776 mSourceModel->setData(mdlIndex, iconList, Qt::DecorationRole); |
718 } |
777 } |
719 // Update the notes count. |
778 // Update the notes count. |
720 mNotesCount++; |
779 mNotesCount++; |
721 |
780 |
722 index = mdlIndex; |
781 index = mdlIndex; |
723 |
|
724 qDebug() << "notes: NotesModel::insertNoteToModel <--"; |
|
725 |
782 |
726 return true; |
783 return true; |
727 } |
784 } |
728 |
785 |
729 /*! |
786 /*! |
784 newModelIndex, (int) entry.status(), |
839 newModelIndex, (int) entry.status(), |
785 NotesNamespace::StatusRole); |
840 NotesNamespace::StatusRole); |
786 |
841 |
787 // Set the display data now. |
842 // Set the display data now. |
788 QStringList stringList; |
843 QStringList stringList; |
789 stringList << entry.summary(); |
844 if (entry.summary().isEmpty()) { |
|
845 // If empty set unnamed text |
|
846 stringList<<hbTrId("txt_notes_dblist_unnamed"); |
|
847 } else { |
|
848 stringList << entry.summary(); |
|
849 } |
790 if (AgendaEntry::TodoNeedsAction == entry.status()) { |
850 if (AgendaEntry::TodoNeedsAction == entry.status()) { |
791 // Read due date from agenda entry |
851 // Read due date from agenda entry |
792 QString displayText; |
852 QString displayText; |
793 QString timeText(hbTrId("txt_notes_dblist_val_due_on_1")); |
853 QString timeText(hbTrId("txt_notes_dblist_val_due_on_1")); |
794 QString dueDateText = |
854 QString dueDateText = |
795 entry.startTime().toString("dd/MM/yyyy"); |
855 entry.startTime().toString(dateFormatString()); |
796 displayText = timeText.arg(dueDateText); |
856 displayText = timeText.arg(dueDateText); |
797 stringList << displayText; |
857 stringList << displayText; |
798 } |
858 } |
799 // Set the data. |
859 // Set the data. |
800 mSourceModel->setData( |
860 mSourceModel->setData( |
801 newModelIndex, stringList, Qt::DisplayRole); |
861 newModelIndex, stringList, Qt::DisplayRole); |
802 // Set the to-do done/undone icon based on the status. |
862 // Set the to-do done/undone icon based on the status. |
803 QList<QVariant> iconList; |
863 QList<QVariant> iconList; |
804 iconList.append(HbIcon("qtg_small_todo")); |
864 iconList.append(HbIcon("qtg_small_todo")); |
805 |
865 |
806 // Set the alarm icon if reminder is set. |
866 if (1 == entry.priority()) { |
807 if (!entry.alarm().isNull()) { |
867 // Set the High Priority icon if priority is high. |
|
868 iconList.append(HbIcon("qtg_small_priority_high")); |
|
869 } else if (!entry.alarm().isNull()) { |
|
870 // Set the alarm if set. |
808 iconList.append(HbIcon("qtg_mono_alarm")); |
871 iconList.append(HbIcon("qtg_mono_alarm")); |
809 } else { |
872 } else { |
810 iconList.append(QVariant(QVariant::Invalid)); |
873 iconList.append(QVariant(QVariant::Invalid)); |
811 } |
874 } |
|
875 |
812 // Set the icons. |
876 // Set the icons. |
813 mSourceModel->setData( |
877 mSourceModel->setData( |
814 newModelIndex, iconList, Qt::DecorationRole); |
878 newModelIndex, iconList, Qt::DecorationRole); |
815 |
879 |
816 // Update the incompleted to-do count. |
880 // Update the incompleted to-do count. |
918 success = true; |
983 success = true; |
919 index = newModelIndex; |
984 index = newModelIndex; |
920 } |
985 } |
921 } |
986 } |
922 |
987 |
923 qDebug() << "notes: NotesModel::insertCompTodoToModel <--"; |
|
924 |
|
925 return success; |
988 return success; |
926 } |
989 } |
927 |
990 |
|
991 /*! |
|
992 Retruns the dateformat based current locale settings. |
|
993 Common method can be used by any class. |
|
994 Can be removed once format strings are defined in hb. |
|
995 */ |
|
996 QString NotesModel::dateFormatString() |
|
997 { |
|
998 HbExtendedLocale locale = HbExtendedLocale::system(); |
|
999 |
|
1000 QString dateFormat; |
|
1001 switch (locale.dateStyle()) { |
|
1002 case HbExtendedLocale::American: |
|
1003 dateFormat.append("MM"); |
|
1004 dateFormat.append(locale.dateSeparator(1)); |
|
1005 dateFormat.append("dd"); |
|
1006 dateFormat.append(locale.dateSeparator(1)); |
|
1007 dateFormat.append("yyyy"); |
|
1008 break; |
|
1009 |
|
1010 case HbExtendedLocale::European: |
|
1011 dateFormat.append("dd"); |
|
1012 dateFormat.append(locale.dateSeparator(1)); |
|
1013 dateFormat.append("MM"); |
|
1014 dateFormat.append(locale.dateSeparator(1)); |
|
1015 dateFormat.append("yyyy"); |
|
1016 break; |
|
1017 |
|
1018 case HbExtendedLocale::Japanese: |
|
1019 dateFormat.append("yyyy"); |
|
1020 dateFormat.append(locale.dateSeparator(1)); |
|
1021 dateFormat.append("MM"); |
|
1022 dateFormat.append(locale.dateSeparator(1)); |
|
1023 dateFormat.append("dd"); |
|
1024 break; |
|
1025 } |
|
1026 |
|
1027 return dateFormat; |
|
1028 } |
|
1029 |
|
1030 /*! |
|
1031 Retruns the timeformat string based on current locale settings |
|
1032 Common method can be used by any class. |
|
1033 Can be removed once format strings are defined in hb. |
|
1034 */ |
|
1035 QString NotesModel::timeFormatString() |
|
1036 { |
|
1037 QString timeFormat; |
|
1038 |
|
1039 HbExtendedLocale locale = HbExtendedLocale::system(); |
|
1040 |
|
1041 if (locale.timeStyle() == HbExtendedLocale::Time12) { |
|
1042 timeFormat.append("h"); |
|
1043 timeFormat.append(locale.timeSeparator(1)); |
|
1044 timeFormat.append("mm"); |
|
1045 timeFormat.append(" ap"); |
|
1046 } else { |
|
1047 timeFormat.append("hh"); |
|
1048 timeFormat.append(locale.timeSeparator(1)); |
|
1049 timeFormat.append("mm"); |
|
1050 } |
|
1051 |
|
1052 return timeFormat; |
|
1053 } |
|
1054 |
|
1055 |
928 // End of file --Don't remove this. |
1056 // End of file --Don't remove this. |