21 #include "calendarmodel_p.h"
23 #include <akonadi/changerecorder.h>
24 #include <akonadi/itemfetchscope.h>
25 #include <kcalcore/event.h>
26 #include <kcalcore/todo.h>
27 #include <kcalcore/journal.h>
30 #include <KIconLoader>
31 #include <KLocalizedString>
36 using namespace Akonadi;
38 static KCalCore::Incidence::Ptr incidence(
const Akonadi::Item &item)
41 item.hasPayload<KCalCore::Incidence::Ptr>() ?
42 item.payload<KCalCore::Incidence::Ptr>() :
43 KCalCore::Incidence::Ptr();
46 static KCalCore::Todo::Ptr todo(
const Akonadi::Item &item)
49 item.hasPayload<KCalCore::Todo::Ptr>() ?
50 item.payload<KCalCore::Todo::Ptr>() :
51 KCalCore::Todo::Ptr();
54 class CalendarModel::Private
69 CalendarModel::~CalendarModel()
74 QVariant CalendarModel::entityData(
const Akonadi::Item &item,
int column,
int role)
const
76 const KCalCore::Incidence::Ptr inc = incidence(item);
82 case Qt::DecorationRole:
83 if (column != Summary) {
86 if (inc->type() == KCalCore::IncidenceBase::TypeTodo) {
87 return SmallIcon(QLatin1String(
"view-pim-tasks"));
89 if (inc->type() == KCalCore::IncidenceBase::TypeJournal) {
90 return SmallIcon(QLatin1String(
"view-pim-journal"));
92 if (inc->type() == KCalCore::IncidenceBase::TypeEvent) {
93 return SmallIcon(QLatin1String(
"view-calendar"));
95 return SmallIcon(QLatin1String(
"network-wired"));
100 return inc->summary();
103 return inc->dtStart().toString();
106 return inc->dateTime(KCalCore::Incidence::RoleEndTimeZone).toString();
109 if (KCalCore::Todo::Ptr t = todo(item)) {
110 return t->dtDue().toString();
116 if (KCalCore::Todo::Ptr t = todo(item)) {
117 return t->priority();
122 case PercentComplete:
123 if (KCalCore::Todo::Ptr t = todo(item)) {
124 return t->percentComplete();
130 return inc->typeStr();
138 return inc->summary();
141 return inc->dtStart().toUtc().dateTime();
144 return inc->dateTime(KCalCore::Incidence::RoleEndTimeZone).toUtc().dateTime();
147 if (KCalCore::Todo::Ptr t = todo(item)) {
148 return t->dtDue().toUtc().dateTime();
154 if (KCalCore::Todo::Ptr t = todo(item)) {
155 return t->priority();
160 case PercentComplete:
161 if (KCalCore::Todo::Ptr t = todo(item)) {
162 return t->percentComplete();
177 return inc->recurs();
187 int column,
int role)
const
195 return ItemColumnCount;
197 return CollectionColumnCount;
201 QVariant CalendarModel::entityHeaderData(
int section, Qt::Orientation orientation,
204 if (role != Qt::DisplayRole || orientation != Qt::Horizontal) {
211 return i18nc(
"@title:column calendar event summary",
"Summary");
213 return i18nc(
"@title:column calendar event start date and time",
"Start Date and Time");
215 return i18nc(
"@title:column calendar event end date and time",
"End Date and Time");
217 return i18nc(
"@title:column calendar event type",
"Type");
219 return i18nc(
"@title:column todo item due date and time",
"Due Date and Time");
221 return i18nc(
"@title:column todo item priority",
"Priority");
222 case PercentComplete:
223 return i18nc(
"@title:column todo item completion in percent",
"Complete");
231 case CollectionTitle:
232 return i18nc(
"@title:column calendar title",
"Calendar");
void fetchAllAttributes(bool fetch=true)
Sets whether all available attributes should be fetched.
virtual QVariant entityData(const Item &item, int column, int role=Qt::DisplayRole) const
Provided for convenience of subclasses.
Represents a collection of PIM items.
Header information for a collection-only tree.
HeaderGroup
Describes what header information the model shall return.
ItemFetchScope & itemFetchScope()
Returns the item fetch scope.
Header information for a list of items.
A model for collections and items together.
Records and replays change notification.