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

akonadi

  • 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 <KLocale>
32 
33 #include <QPixmap>
34 
35 using namespace Akonadi;
36 
37 static KCalCore::Incidence::Ptr incidence( const Akonadi::Item &item )
38 {
39  return
40  item.hasPayload<KCalCore::Incidence::Ptr>() ?
41  item.payload<KCalCore::Incidence::Ptr>() :
42  KCalCore::Incidence::Ptr();
43 }
44 
45 static KCalCore::Event::Ptr event( const Akonadi::Item &item )
46 {
47  return
48  item.hasPayload<KCalCore::Event::Ptr>() ?
49  item.payload<KCalCore::Event::Ptr>() :
50  KCalCore::Event::Ptr();
51 }
52 
53 static KCalCore::Todo::Ptr todo( const Akonadi::Item &item )
54 {
55  return
56  item.hasPayload<KCalCore::Todo::Ptr>() ?
57  item.payload<KCalCore::Todo::Ptr>() :
58  KCalCore::Todo::Ptr();
59 }
60 
61 static KCalCore::Journal::Ptr journal( const Akonadi::Item &item )
62 {
63  return
64  item.hasPayload<KCalCore::Journal::Ptr>() ?
65  item.payload<KCalCore::Journal::Ptr>() :
66  KCalCore::Journal::Ptr();
67 }
68 
69 class CalendarModel::Private
70 {
71  public:
72  explicit Private( CalendarModel *qq )
73  :q( qq )
74  {
75  }
76 
77  private:
78  CalendarModel *const q;
79 };
80 
81 CalendarModel::CalendarModel( Akonadi::ChangeRecorder *monitor, QObject *parent )
82  : EntityTreeModel( monitor, parent ),
83  d( new Private( this ) )
84 {
85  monitor->itemFetchScope().fetchAllAttributes( true );
86 }
87 
88 CalendarModel::~CalendarModel()
89 {
90  delete d;
91 }
92 
93 static KDateTime primaryDateForIncidence( const Akonadi::Item &item )
94 {
95  if ( const KCalCore::Todo::Ptr t = todo( item ) ) {
96  return t->hasDueDate() ? t->dtDue() : KDateTime();
97  }
98 
99  if ( const KCalCore::Event::Ptr e = event( item ) ) {
100  return ( !e->recurs() && !e->isMultiDay() ) ? e->dtStart() : KDateTime();
101  }
102 
103  if ( const KCalCore::Journal::Ptr j = journal( item ) ) {
104  return j->dtStart();
105  }
106 
107  return KDateTime();
108 }
109 
110 QVariant CalendarModel::entityData( const Akonadi::Item &item, int column, int role ) const
111 {
112  const KCalCore::Incidence::Ptr inc = incidence( item );
113  if ( !inc ) {
114  return QVariant();
115  }
116 
117  switch( role ) {
118  case Qt::DecorationRole:
119  if ( column != Summary ) {
120  return QVariant();
121  }
122  if ( inc->type() == KCalCore::IncidenceBase::TypeTodo ) {
123  return SmallIcon( QLatin1String( "view-pim-tasks" ) );
124  }
125  if ( inc->type() == KCalCore::IncidenceBase::TypeJournal ) {
126  return SmallIcon( QLatin1String( "view-pim-journal" ) );
127  }
128  if ( inc->type() == KCalCore::IncidenceBase::TypeEvent ) {
129  return SmallIcon( QLatin1String( "view-calendar" ) );
130  }
131  return SmallIcon( QLatin1String( "network-wired" ) );
132 
133  case Qt::DisplayRole:
134  switch( column ) {
135  case Summary:
136  return inc->summary();
137 
138  case DateTimeStart:
139  return inc->dtStart().toString();
140 
141  case DateTimeEnd:
142  return inc->dateTime( KCalCore::Incidence::RoleEndTimeZone ).toString();
143 
144  case DateTimeDue:
145  if ( KCalCore::Todo::Ptr t = todo( item ) ) {
146  return t->dtDue().toString();
147  } else {
148  return QVariant();
149  }
150 
151  case Priority:
152  if ( KCalCore::Todo::Ptr t = todo( item ) ) {
153  return t->priority();
154  } else {
155  return QVariant();
156  }
157 
158  case PercentComplete:
159  if ( KCalCore::Todo::Ptr t = todo( item ) ) {
160  return t->percentComplete();
161  } else {
162  return QVariant();
163  }
164 
165  case PrimaryDate:
166  return primaryDateForIncidence( item ).toString();
167 
168  case Type:
169 
170  return inc->type();
171  default:
172  break;
173  }
174 
175  case SortRole:
176  switch( column ) {
177  case Summary:
178  return inc->summary();
179 
180  case DateTimeStart:
181  return inc->dtStart().toUtc().dateTime();
182 
183  case DateTimeEnd:
184  return inc->dateTime( KCalCore::Incidence::RoleEndTimeZone ).toUtc().dateTime();
185 
186  case DateTimeDue:
187  if ( KCalCore::Todo::Ptr t = todo( item ) ) {
188  return t->dtDue().toUtc().dateTime();
189  } else {
190  return QVariant();
191  }
192 
193  case PrimaryDate:
194  return primaryDateForIncidence( item ).toUtc().dateTime();
195 
196  case Priority:
197  if ( KCalCore::Todo::Ptr t = todo( item ) ) {
198  return t->priority();
199  } else {
200  return QVariant();
201  }
202 
203  case PercentComplete:
204  if ( KCalCore::Todo::Ptr t = todo( item ) ) {
205  return t->percentComplete();
206  } else {
207  return QVariant();
208  }
209 
210  case Type:
211  return inc->type();
212 
213  default:
214  break;
215  }
216 
217  return QVariant();
218 
219  case RecursRole:
220  return inc->recurs();
221 
222  default:
223  return QVariant();
224  }
225 
226  return QVariant();
227 }
228 
229 QVariant CalendarModel::entityData( const Akonadi::Collection &collection,
230  int column, int role ) const
231 {
232  return EntityTreeModel::entityData( collection, column, role );
233 }
234 
235 int CalendarModel::entityColumnCount( EntityTreeModel::HeaderGroup headerSet ) const
236 {
237  if ( headerSet == EntityTreeModel::ItemListHeaders ) {
238  return ItemColumnCount;
239  } else {
240  return CollectionColumnCount;
241  }
242 }
243 
244 QVariant CalendarModel::entityHeaderData( int section, Qt::Orientation orientation,
245  int role, EntityTreeModel::HeaderGroup headerSet ) const
246 {
247  if ( role != Qt::DisplayRole || orientation != Qt::Horizontal ) {
248  return QVariant();
249  }
250 
251  if ( headerSet == EntityTreeModel::ItemListHeaders ) {
252  switch( section ) {
253  case Summary:
254  return i18nc( "@title:column calendar event summary", "Summary" );
255  case DateTimeStart:
256  return i18nc( "@title:column calendar event start date and time", "Start Date and Time" );
257  case DateTimeEnd:
258  return i18nc( "@title:column calendar event end date and time", "End Date and Time" );
259  case Type:
260  return i18nc( "@title:column calendar event type", "Type" );
261  case DateTimeDue:
262  return i18nc( "@title:column todo item due date and time", "Due Date and Time" );
263  case Priority:
264  return i18nc( "@title:column todo item priority", "Priority" );
265  case PercentComplete:
266  return i18nc( "@title:column todo item completion in percent", "Complete" );
267  default:
268  return QVariant();
269  }
270  }
271 
272  if ( headerSet == EntityTreeModel::CollectionTreeHeaders ) {
273  switch ( section ) {
274  case CollectionTitle:
275  return i18nc( "@title:column calendar title", "Calendar" );
276  default:
277  return QVariant();
278  }
279  }
280  return QVariant();
281 }
282 
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:27:32 by doxygen 1.8.3.1 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-4.10.5 API Reference

Skip menu "kdepimlibs-4.10.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
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