• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.11.3 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 <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  explicit Private( CalendarModel *qq )
58  :q( qq )
59  {
60  }
61 
62  private:
63  CalendarModel *const q;
64 };
65 
66 CalendarModel::CalendarModel( Akonadi::ChangeRecorder *monitor, QObject *parent )
67  : EntityTreeModel( monitor, parent ),
68  d( new Private( this ) )
69 {
70  monitor->itemFetchScope().fetchAllAttributes( true );
71 }
72 
73 CalendarModel::~CalendarModel()
74 {
75  delete d;
76 }
77 
78 QVariant CalendarModel::entityData( const Akonadi::Item &item, int column, int role ) const
79 {
80  const KCalCore::Incidence::Ptr inc = incidence( item );
81  if ( !inc ) {
82  return QVariant();
83  }
84 
85  switch( role ) {
86  case Qt::DecorationRole:
87  if ( column != Summary ) {
88  return QVariant();
89  }
90  if ( inc->type() == KCalCore::IncidenceBase::TypeTodo ) {
91  return SmallIcon( QLatin1String( "view-pim-tasks" ) );
92  }
93  if ( inc->type() == KCalCore::IncidenceBase::TypeJournal ) {
94  return SmallIcon( QLatin1String( "view-pim-journal" ) );
95  }
96  if ( inc->type() == KCalCore::IncidenceBase::TypeEvent ) {
97  return SmallIcon( QLatin1String( "view-calendar" ) );
98  }
99  return SmallIcon( QLatin1String( "network-wired" ) );
100 
101  case Qt::DisplayRole:
102  switch( column ) {
103  case Summary:
104  return inc->summary();
105 
106  case DateTimeStart:
107  return inc->dtStart().toString();
108 
109  case DateTimeEnd:
110  return inc->dateTime( KCalCore::Incidence::RoleEndTimeZone ).toString();
111 
112  case DateTimeDue:
113  if ( KCalCore::Todo::Ptr t = todo( item ) ) {
114  return t->dtDue().toString();
115  } else {
116  return QVariant();
117  }
118 
119  case Priority:
120  if ( KCalCore::Todo::Ptr t = todo( item ) ) {
121  return t->priority();
122  } else {
123  return QVariant();
124  }
125 
126  case PercentComplete:
127  if ( KCalCore::Todo::Ptr t = todo( item ) ) {
128  return t->percentComplete();
129  } else {
130  return QVariant();
131  }
132 
133  case Type:
134  return inc->typeStr();
135  default:
136  break;
137  }
138 
139  case SortRole:
140  switch( column ) {
141  case Summary:
142  return inc->summary();
143 
144  case DateTimeStart:
145  return inc->dtStart().toUtc().dateTime();
146 
147  case DateTimeEnd:
148  return inc->dateTime( KCalCore::Incidence::RoleEndTimeZone ).toUtc().dateTime();
149 
150  case DateTimeDue:
151  if ( KCalCore::Todo::Ptr t = todo( item ) ) {
152  return t->dtDue().toUtc().dateTime();
153  } else {
154  return QVariant();
155  }
156 
157  case Priority:
158  if ( KCalCore::Todo::Ptr t = todo( item ) ) {
159  return t->priority();
160  } else {
161  return QVariant();
162  }
163 
164  case PercentComplete:
165  if ( KCalCore::Todo::Ptr t = todo( item ) ) {
166  return t->percentComplete();
167  } else {
168  return QVariant();
169  }
170 
171  case Type:
172  return inc->type();
173 
174  default:
175  break;
176  }
177 
178  return QVariant();
179 
180  case RecursRole:
181  return inc->recurs();
182 
183  default:
184  return QVariant();
185  }
186 
187  return QVariant();
188 }
189 
190 QVariant CalendarModel::entityData( const Akonadi::Collection &collection,
191  int column, int role ) const
192 {
193  return EntityTreeModel::entityData( collection, column, role );
194 }
195 
196 int CalendarModel::entityColumnCount( EntityTreeModel::HeaderGroup headerSet ) const
197 {
198  if ( headerSet == EntityTreeModel::ItemListHeaders ) {
199  return ItemColumnCount;
200  } else {
201  return CollectionColumnCount;
202  }
203 }
204 
205 QVariant CalendarModel::entityHeaderData( int section, Qt::Orientation orientation,
206  int role, EntityTreeModel::HeaderGroup headerSet ) const
207 {
208  if ( role != Qt::DisplayRole || orientation != Qt::Horizontal ) {
209  return QVariant();
210  }
211 
212  if ( headerSet == EntityTreeModel::ItemListHeaders ) {
213  switch( section ) {
214  case Summary:
215  return i18nc( "@title:column calendar event summary", "Summary" );
216  case DateTimeStart:
217  return i18nc( "@title:column calendar event start date and time", "Start Date and Time" );
218  case DateTimeEnd:
219  return i18nc( "@title:column calendar event end date and time", "End Date and Time" );
220  case Type:
221  return i18nc( "@title:column calendar event type", "Type" );
222  case DateTimeDue:
223  return i18nc( "@title:column todo item due date and time", "Due Date and Time" );
224  case Priority:
225  return i18nc( "@title:column todo item priority", "Priority" );
226  case PercentComplete:
227  return i18nc( "@title:column todo item completion in percent", "Complete" );
228  default:
229  return QVariant();
230  }
231  }
232 
233  if ( headerSet == EntityTreeModel::CollectionTreeHeaders ) {
234  switch ( section ) {
235  case CollectionTitle:
236  return i18nc( "@title:column calendar title", "Calendar" );
237  default:
238  return QVariant();
239  }
240  }
241  return QVariant();
242 }
243 
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:138
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:154
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-2013 The KDE developers.
Generated on Tue Nov 26 2013 09:03:16 by doxygen 1.8.5 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.11.3 API Reference

Skip menu "kdepimlibs-4.11.3 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