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
57 explicit Private( CalendarModel *qq )
63 CalendarModel *
const q;
68 d( new Private( this ) )
73 CalendarModel::~CalendarModel()
78 QVariant CalendarModel::entityData(
const Akonadi::Item &item,
int column,
int role )
const
80 const KCalCore::Incidence::Ptr inc = incidence( item );
86 case Qt::DecorationRole:
87 if ( column != Summary ) {
90 if ( inc->type() == KCalCore::IncidenceBase::TypeTodo ) {
91 return SmallIcon( QLatin1String(
"view-pim-tasks" ) );
93 if ( inc->type() == KCalCore::IncidenceBase::TypeJournal ) {
94 return SmallIcon( QLatin1String(
"view-pim-journal" ) );
96 if ( inc->type() == KCalCore::IncidenceBase::TypeEvent ) {
97 return SmallIcon( QLatin1String(
"view-calendar" ) );
99 return SmallIcon( QLatin1String(
"network-wired" ) );
101 case Qt::DisplayRole:
104 return inc->summary();
107 return inc->dtStart().toString();
110 return inc->dateTime( KCalCore::Incidence::RoleEndTimeZone ).toString();
113 if ( KCalCore::Todo::Ptr t = todo( item ) ) {
114 return t->dtDue().toString();
120 if ( KCalCore::Todo::Ptr t = todo( item ) ) {
121 return t->priority();
126 case PercentComplete:
127 if ( KCalCore::Todo::Ptr t = todo( item ) ) {
128 return t->percentComplete();
134 return inc->typeStr();
142 return inc->summary();
145 return inc->dtStart().toUtc().dateTime();
148 return inc->dateTime( KCalCore::Incidence::RoleEndTimeZone ).toUtc().dateTime();
151 if ( KCalCore::Todo::Ptr t = todo( item ) ) {
152 return t->dtDue().toUtc().dateTime();
158 if ( KCalCore::Todo::Ptr t = todo( item ) ) {
159 return t->priority();
164 case PercentComplete:
165 if ( KCalCore::Todo::Ptr t = todo( item ) ) {
166 return t->percentComplete();
181 return inc->recurs();
191 int column,
int role )
const
199 return ItemColumnCount;
201 return CollectionColumnCount;
205 QVariant CalendarModel::entityHeaderData(
int section, Qt::Orientation orientation,
208 if ( role != Qt::DisplayRole || orientation != Qt::Horizontal ) {
215 return i18nc(
"@title:column calendar event summary",
"Summary" );
217 return i18nc(
"@title:column calendar event start date and time",
"Start Date and Time" );
219 return i18nc(
"@title:column calendar event end date and time",
"End Date and Time" );
221 return i18nc(
"@title:column calendar event type",
"Type" );
223 return i18nc(
"@title:column todo item due date and time",
"Due Date and Time" );
225 return i18nc(
"@title:column todo item priority",
"Priority" );
226 case PercentComplete:
227 return i18nc(
"@title:column todo item completion in percent",
"Complete" );
235 case CollectionTitle:
236 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.