• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • sources
  • kde-4.12
  • kdepimlibs
  • akonadi
  • calendar
calendarmodel.cpp
1 /*
2  Copyright (c) 2008 Bruno Virlet <bvirlet@kdemail.net>
3  2009 KDAB; Author: Frank Osterfeld <osterfeld@kde.org>
4 
5  This library is free software; you can redistribute it and/or modify it
6  under the terms of the GNU Library General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or (at your
8  option) any later version.
9 
10  This library is distributed in the hope that it will be useful, but WITHOUT
11  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13  License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to the
17  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  02110-1301, USA.
19 */
20 
21 #include "calendarmodel_p.h"
22 
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>
28 
29 #include <KDateTime>
30 #include <KIconLoader>
31 #include <KLocalizedString>
32 
33 #include <QPixmap>
34 #include <QDateTime>
35 
36 using namespace Akonadi;
37 
38 static KCalCore::Incidence::Ptr incidence(const Akonadi::Item &item)
39 {
40  return
41  item.hasPayload<KCalCore::Incidence::Ptr>() ?
42  item.payload<KCalCore::Incidence::Ptr>() :
43  KCalCore::Incidence::Ptr();
44 }
45 
46 static KCalCore::Todo::Ptr todo(const Akonadi::Item &item)
47 {
48  return
49  item.hasPayload<KCalCore::Todo::Ptr>() ?
50  item.payload<KCalCore::Todo::Ptr>() :
51  KCalCore::Todo::Ptr();
52 }
53 
54 class CalendarModel::Private
55 {
56 public:
57  Private()
58  {
59  }
60 };
61 
62 CalendarModel::CalendarModel(Akonadi::ChangeRecorder *monitor, QObject *parent)
63  : EntityTreeModel(monitor, parent),
64  d(new Private())
65 {
66  monitor->itemFetchScope().fetchAllAttributes(true);
67 }
68 
69 CalendarModel::~CalendarModel()
70 {
71  delete d;
72 }
73 
74 QVariant CalendarModel::entityData(const Akonadi::Item &item, int column, int role) const
75 {
76  const KCalCore::Incidence::Ptr inc = incidence(item);
77  if (!inc) {
78  return QVariant();
79  }
80 
81  switch (role) {
82  case Qt::DecorationRole:
83  if (column != Summary) {
84  return QVariant();
85  }
86  if (inc->type() == KCalCore::IncidenceBase::TypeTodo) {
87  return SmallIcon(QLatin1String("view-pim-tasks"));
88  }
89  if (inc->type() == KCalCore::IncidenceBase::TypeJournal) {
90  return SmallIcon(QLatin1String("view-pim-journal"));
91  }
92  if (inc->type() == KCalCore::IncidenceBase::TypeEvent) {
93  return SmallIcon(QLatin1String("view-calendar"));
94  }
95  return SmallIcon(QLatin1String("network-wired"));
96 
97  case Qt::DisplayRole:
98  switch (column) {
99  case Summary:
100  return inc->summary();
101 
102  case DateTimeStart:
103  return inc->dtStart().toString();
104 
105  case DateTimeEnd:
106  return inc->dateTime(KCalCore::Incidence::RoleEndTimeZone).toString();
107 
108  case DateTimeDue:
109  if (KCalCore::Todo::Ptr t = todo(item)) {
110  return t->dtDue().toString();
111  } else {
112  return QVariant();
113  }
114 
115  case Priority:
116  if (KCalCore::Todo::Ptr t = todo(item)) {
117  return t->priority();
118  } else {
119  return QVariant();
120  }
121 
122  case PercentComplete:
123  if (KCalCore::Todo::Ptr t = todo(item)) {
124  return t->percentComplete();
125  } else {
126  return QVariant();
127  }
128 
129  case Type:
130  return inc->typeStr();
131  default:
132  break;
133  }
134 
135  case SortRole:
136  switch (column) {
137  case Summary:
138  return inc->summary();
139 
140  case DateTimeStart:
141  return inc->dtStart().toUtc().dateTime();
142 
143  case DateTimeEnd:
144  return inc->dateTime(KCalCore::Incidence::RoleEndTimeZone).toUtc().dateTime();
145 
146  case DateTimeDue:
147  if (KCalCore::Todo::Ptr t = todo(item)) {
148  return t->dtDue().toUtc().dateTime();
149  } else {
150  return QVariant();
151  }
152 
153  case Priority:
154  if (KCalCore::Todo::Ptr t = todo(item)) {
155  return t->priority();
156  } else {
157  return QVariant();
158  }
159 
160  case PercentComplete:
161  if (KCalCore::Todo::Ptr t = todo(item)) {
162  return t->percentComplete();
163  } else {
164  return QVariant();
165  }
166 
167  case Type:
168  return inc->type();
169 
170  default:
171  break;
172  }
173 
174  return QVariant();
175 
176  case RecursRole:
177  return inc->recurs();
178 
179  default:
180  return QVariant();
181  }
182 
183  return QVariant();
184 }
185 
186 QVariant CalendarModel::entityData(const Akonadi::Collection &collection,
187  int column, int role) const
188 {
189  return EntityTreeModel::entityData(collection, column, role);
190 }
191 
192 int CalendarModel::entityColumnCount(EntityTreeModel::HeaderGroup headerSet) const
193 {
194  if (headerSet == EntityTreeModel::ItemListHeaders) {
195  return ItemColumnCount;
196  } else {
197  return CollectionColumnCount;
198  }
199 }
200 
201 QVariant CalendarModel::entityHeaderData(int section, Qt::Orientation orientation,
202  int role, EntityTreeModel::HeaderGroup headerSet) const
203 {
204  if (role != Qt::DisplayRole || orientation != Qt::Horizontal) {
205  return QVariant();
206  }
207 
208  if (headerSet == EntityTreeModel::ItemListHeaders) {
209  switch (section) {
210  case Summary:
211  return i18nc("@title:column calendar event summary", "Summary");
212  case DateTimeStart:
213  return i18nc("@title:column calendar event start date and time", "Start Date and Time");
214  case DateTimeEnd:
215  return i18nc("@title:column calendar event end date and time", "End Date and Time");
216  case Type:
217  return i18nc("@title:column calendar event type", "Type");
218  case DateTimeDue:
219  return i18nc("@title:column todo item due date and time", "Due Date and Time");
220  case Priority:
221  return i18nc("@title:column todo item priority", "Priority");
222  case PercentComplete:
223  return i18nc("@title:column todo item completion in percent", "Complete");
224  default:
225  return QVariant();
226  }
227  }
228 
229  if (headerSet == EntityTreeModel::CollectionTreeHeaders) {
230  switch (section) {
231  case CollectionTitle:
232  return i18nc("@title:column calendar title", "Calendar");
233  default:
234  return QVariant();
235  }
236  }
237  return QVariant();
238 }
239 
Akonadi::ItemFetchScope::fetchAllAttributes
void fetchAllAttributes(bool fetch=true)
Sets whether all available attributes should be fetched.
Definition: itemfetchscope.cpp:91
Akonadi::EntityTreeModel::entityData
virtual QVariant entityData(const Item &item, int column, int role=Qt::DisplayRole) const
Provided for convenience of subclasses.
Definition: entitytreemodel.cpp:136
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
Akonadi::EntityTreeModel::CollectionTreeHeaders
Header information for a collection-only tree.
Definition: entitytreemodel.h:383
Akonadi::EntityTreeModel::HeaderGroup
HeaderGroup
Describes what header information the model shall return.
Definition: entitytreemodel.h:381
Akonadi::Monitor::itemFetchScope
ItemFetchScope & itemFetchScope()
Returns the item fetch scope.
Definition: monitor.cpp:197
Akonadi::EntityTreeModel::ItemListHeaders
Header information for a list of items.
Definition: entitytreemodel.h:384
Akonadi::EntityTreeModel
A model for collections and items together.
Definition: entitytreemodel.h:317
Akonadi::ChangeRecorder
Records and replays change notification.
Definition: changerecorder.h:47
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:26 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal