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

kalarm

  • sources
  • kde-4.12
  • kdepim
  • kalarm
akonadimodel.h
Go to the documentation of this file.
1 /*
2  * akonadimodel.h - KAlarm calendar file access using Akonadi
3  * Program: kalarm
4  * Copyright © 2010-2012 by David Jarvie <djarvie@kde.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef AKONADIMODEL_H
22 #define AKONADIMODEL_H
23 
24 #include "eventid.h"
25 
26 #include <kalarmcal/kacalendar.h>
27 #include <kalarmcal/kaevent.h>
28 
29 #include <akonadi/entitytreemodel.h>
30 #include <akonadi/servermanager.h>
31 
32 #include <QSize>
33 #include <QColor>
34 #include <QMap>
35 #include <QQueue>
36 
37 namespace Akonadi {
38  class AgentInstance;
39  class AgentInstanceCreateJob;
40 }
41 class QPixmap;
42 class KJob;
43 class CalendarMigrator;
44 
45 using namespace KAlarmCal;
46 
47 
48 class AkonadiModel : public Akonadi::EntityTreeModel
49 {
50  Q_OBJECT
51  public:
52  enum Change { Added, Deleted, Invalidated, Enabled, ReadOnly, AlarmTypes, WrongType, Location, Colour };
53  enum { // data columns
54  // Item columns
55  TimeColumn = 0, TimeToColumn, RepeatColumn, ColourColumn, TypeColumn, TextColumn,
56  TemplateNameColumn,
57  ColumnCount
58  };
59  enum { // additional data roles
60  // Collection roles
61  EnabledTypesRole = UserRole, // alarm types which are enabled for the collection
62  BaseColourRole, // background colour ignoring collection colour
63  AlarmTypeRole, // OR of event types which collection contains
64  IsStandardRole, // OR of event types which collection is standard for
65  KeepFormatRole, // user has chosen not to update collection's calendar storage format
66  // Item roles
67  EnabledRole, // true for enabled alarm, false for disabled
68  StatusRole, // KAEvent::ACTIVE/ARCHIVED/TEMPLATE
69  AlarmActionsRole, // KAEvent::Actions
70  AlarmSubActionRole, // KAEvent::Action
71  ValueRole, // numeric value
72  SortRole, // the value to use for sorting
73  CommandErrorRole // last command execution error for alarm (per user)
74  };
75 
77  struct Event
78  {
79  Event(const KAEvent& e, const Akonadi::Collection& c) : event(e), collection(c) {}
80  EventId eventId() const { return EventId(collection.id(), event.id()); }
81  bool isConsistent() const { return event.collectionId() == collection.id(); }
82  KAEvent event;
83  Akonadi::Collection collection;
84  };
85  typedef QList<Event> EventList;
86 
87  static AkonadiModel* instance();
88 
90  QString displayName(Akonadi::Collection&) const;
92  QString storageType(const Akonadi::Collection&) const;
94  static QColor foregroundColor(const Akonadi::Collection&, const QStringList& mimeTypes);
96  void setBackgroundColor(Akonadi::Collection&, const QColor&);
98  QColor backgroundColor(Akonadi::Collection&) const;
101  QString tooltip(const Akonadi::Collection&, CalEvent::Types) const;
104  static QString readOnlyTooltip(const Akonadi::Collection&);
105 
109  void updateCommandError(const KAEvent&);
110 
111  virtual QVariant data(const QModelIndex&, int role = Qt::DisplayRole) const;
112  virtual bool setData(const QModelIndex&, const QVariant& value, int role);
113 
115  bool refresh(Akonadi::Collection&) const;
117  bool refresh(Akonadi::Item&) const;
118 
119  QModelIndex collectionIndex(Akonadi::Collection::Id id) const
120  { return collectionIndex(Akonadi::Collection(id)); }
121  QModelIndex collectionIndex(const Akonadi::Collection&) const;
122  Akonadi::Collection collectionById(Akonadi::Collection::Id) const;
123  Akonadi::Collection collectionForItem(Akonadi::Item::Id) const;
124  Akonadi::Collection collection(const KAEvent& e) const { return collectionForItem(e.itemId()); }
125 
129  bool removeCollection(const Akonadi::Collection&);
130 
132  bool reloadCollection(const Akonadi::Collection&);
133 
135  void reload();
136 
138  bool isMigrationCompleted() const;
139 
140  bool isCollectionBeingDeleted(Akonadi::Collection::Id) const;
141 
142  QModelIndex itemIndex(Akonadi::Item::Id id) const
143  { return itemIndex(Akonadi::Item(id)); }
144  QModelIndex itemIndex(const Akonadi::Item&) const;
145  Akonadi::Item itemById(Akonadi::Item::Id) const;
146 
150  KAEvent event(const Akonadi::Item& item) const { return event(item, QModelIndex(), 0); }
151  KAEvent event(Akonadi::Item::Id) const;
152  KAEvent event(const QModelIndex&) const;
153  using QObject::event; // prevent warning about hidden virtual method
154 
155  QModelIndex eventIndex(const KAEvent&);
156 
157 #if 0
158 
159  KAEvent::List events(Akonadi::Collection&, CalEvent::Type = CalEvent::EMPTY) const;
160 #endif
161 
162  bool addEvent(KAEvent&, Akonadi::Collection&);
163  bool addEvents(const KAEvent::List&, Akonadi::Collection&);
164  bool updateEvent(KAEvent& event);
165  bool updateEvent(Akonadi::Item::Id oldId, KAEvent& newEvent);
166  bool deleteEvent(const KAEvent& event);
167  bool deleteEvent(Akonadi::Item::Id itemId);
168 
170  static bool isCompatible(const Akonadi::Collection&);
171 
180  static int isWritable(const Akonadi::Collection&);
181 
195  static int isWritable(const Akonadi::Collection&, KACalendar::Compat& format);
196 
197  static CalEvent::Types types(const Akonadi::Collection&);
198 
199  static QSize iconSize() { return mIconSize; }
200 
201  signals:
203  void collectionAdded(const Akonadi::Collection&);
204 
209  void collectionStatusChanged(const Akonadi::Collection&, AkonadiModel::Change, const QVariant& newValue, bool inserted);
210 
212  void eventsAdded(const AkonadiModel::EventList&);
213 
215  void eventsToBeRemoved(const AkonadiModel::EventList&);
216 
218  void eventChanged(const AkonadiModel::Event&);
219 
224  void collectionModified(Akonadi::Collection::Id, bool status = true);
225 
230  void collectionDeleted(Akonadi::Collection::Id, bool status = true);
231 
237  void itemDone(Akonadi::Item::Id, bool status = true);
238 
240  void migrationCompleted();
241 
242  protected:
243  virtual QVariant entityHeaderData(int section, Qt::Orientation, int role, HeaderGroup) const;
244  virtual int entityColumnCount(HeaderGroup) const;
245 
246  private slots:
247  void checkResources(Akonadi::ServerManager::State);
248  void slotMigrationCompleted();
249  void slotCollectionChanged(const Akonadi::Collection& c, const QSet<QByteArray>& attrNames)
250  { setCollectionChanged(c, attrNames, false); }
251  void slotCollectionRemoved(const Akonadi::Collection&);
252  void slotCollectionBeingCreated(const QString& path, Akonadi::Collection::Id, bool finished);
253  void slotUpdateTimeTo();
254  void slotUpdateArchivedColour(const QColor&);
255  void slotUpdateDisabledColour(const QColor&);
256  void slotUpdateHolidays();
257  void slotUpdateWorkingHours();
258  void slotRowsInserted(const QModelIndex& parent, int start, int end);
259  void slotRowsAboutToBeRemoved(const QModelIndex& parent, int start, int end);
260  void slotMonitoredItemChanged(const Akonadi::Item&, const QSet<QByteArray>&);
261  void slotEmitEventChanged();
262  void modifyCollectionJobDone(KJob*);
263  void itemJobDone(KJob*);
264 
265  private:
266  struct CalData // data per collection
267  {
268  CalData() : enabled(false) { }
269  CalData(bool e, const QColor& c) : colour(c), enabled(e) { }
270  QColor colour; // user selected color for the calendar
271  bool enabled; // whether the collection is enabled
272  };
273  struct CollJobData // collection data for jobs in progress
274  {
275  CollJobData() : id(-1) {}
276  CollJobData(Akonadi::Collection::Id i, const QString& d) : id(i), displayName(d) {}
277  Akonadi::Collection::Id id;
278  QString displayName;
279  };
280  struct CollTypeData // data for configuration dialog for collection creation job
281  {
282  CollTypeData() : parent(0), alarmType(CalEvent::EMPTY) {}
283  CollTypeData(CalEvent::Type t, QWidget* p) : parent(p), alarmType(t) {}
284  QWidget* parent;
285  CalEvent::Type alarmType;
286  };
287 
288  AkonadiModel(Akonadi::ChangeRecorder*, QObject* parent);
289  KAEvent event(const Akonadi::Item&, const QModelIndex&, Akonadi::Collection*) const;
290  void signalDataChanged(bool (*checkFunc)(const Akonadi::Item&), int startColumn, int endColumn, const QModelIndex& parent);
291  void setCollectionChanged(const Akonadi::Collection&, const QSet<QByteArray>&, bool rowInserted);
292  void queueItemModifyJob(const Akonadi::Item&);
293  void checkQueuedItemModifyJob(const Akonadi::Item&);
294 #if 0
295  void getChildEvents(const QModelIndex& parent, CalEvent::Type, KAEvent::List&) const;
296 #endif
297  QColor backgroundColor_p(const Akonadi::Collection&) const;
298  QString repeatText(const KAEvent&) const;
299  QString repeatOrder(const KAEvent&) const;
300  QPixmap* eventIcon(const KAEvent&) const;
301  QString whatsThisText(int column) const;
302  EventList eventList(const QModelIndex& parent, int start, int end);
303 
304  static AkonadiModel* mInstance;
305  static QPixmap* mTextIcon;
306  static QPixmap* mFileIcon;
307  static QPixmap* mCommandIcon;
308  static QPixmap* mEmailIcon;
309  static QPixmap* mAudioIcon;
310  static QSize mIconSize;
311  static int mTimeHourPos; // position of hour within time string, or -1 if leading zeroes included
312 
313  Akonadi::ChangeRecorder* mMonitor;
314  QMap<Akonadi::Collection::Id, CalEvent::Types> mCollectionAlarmTypes; // last content mime types of each collection
315  QMap<Akonadi::Collection::Id, Akonadi::Collection::Rights> mCollectionRights; // last writable status of each collection
316  QMap<Akonadi::Collection::Id, CalEvent::Types> mCollectionEnabled; // last enabled mime types of each collection
317  QMap<KJob*, CollJobData> mPendingCollectionJobs; // pending collection creation/deletion jobs, with collection ID & name
318  QMap<KJob*, CollTypeData> mPendingColCreateJobs; // default alarm type for pending collection creation jobs
319  QMap<KJob*, Akonadi::Item::Id> mPendingItemJobs; // pending item creation/deletion jobs, with event ID
320  QMap<Akonadi::Item::Id, Akonadi::Item> mItemModifyJobQueue; // pending item modification jobs, invalid item = queue empty but job active
321  QList<QString> mCollectionsBeingCreated; // path names of new collections being created by migrator
322  QList<Akonadi::Collection::Id> mCollectionIdsBeingCreated; // ids of new collections being created by migrator
323  QList<Akonadi::Item::Id> mItemsBeingCreated; // new items not fully initialised yet
324  QList<Akonadi::Collection::Id> mCollectionsDeleting; // collections currently being removed
325  QList<Akonadi::Collection::Id> mCollectionsDeleted; // collections recently removed
326  QQueue<Event> mPendingEventChanges; // changed events with changedEvent() signal pending
327  bool mResourcesChecked; // whether resource existence has been checked yet
328  bool mMigrating; // currently migrating calendars
329 };
330 
331 #endif // AKONADIMODEL_H
332 
333 // vim: et sw=4:
AkonadiModel::StatusRole
Definition: akonadimodel.h:68
AkonadiModel::IsStandardRole
Definition: akonadimodel.h:64
QWidget
eventid.h
AkonadiModel::collectionIndex
QModelIndex collectionIndex(Akonadi::Collection::Id id) const
Definition: akonadimodel.h:119
AkonadiModel::AlarmSubActionRole
Definition: akonadimodel.h:70
QObject
AkonadiModel::event
KAEvent event(const Akonadi::Item &item) const
Return the alarm with the specified unique identifier.
Definition: akonadimodel.h:150
AkonadiModel::EventList
QList< Event > EventList
Definition: akonadimodel.h:85
AkonadiModel::Event
Struct containing a KAEvent and its parent Collection.
Definition: akonadimodel.h:77
AkonadiModel::TemplateNameColumn
Definition: akonadimodel.h:56
AkonadiModel::Event::event
KAEvent event
Definition: akonadimodel.h:82
AkonadiModel::ValueRole
Definition: akonadimodel.h:71
AkonadiModel::Event::collection
Akonadi::Collection collection
Definition: akonadimodel.h:83
AkonadiModel::SortRole
Definition: akonadimodel.h:72
AkonadiModel::Change
Change
Definition: akonadimodel.h:52
AkonadiModel::EnabledRole
Definition: akonadimodel.h:67
AkonadiModel::Event::Event
Event(const KAEvent &e, const Akonadi::Collection &c)
Definition: akonadimodel.h:79
EventId
Unique event identifier for Akonadi.
Definition: eventid.h:38
AkonadiModel::Event::eventId
EventId eventId() const
Definition: akonadimodel.h:80
AkonadiModel::Event::isConsistent
bool isConsistent() const
Definition: akonadimodel.h:81
AkonadiModel::BaseColourRole
Definition: akonadimodel.h:62
AkonadiModel::collection
Akonadi::Collection collection(const KAEvent &e) const
Definition: akonadimodel.h:124
AkonadiModel::iconSize
static QSize iconSize()
Definition: akonadimodel.h:199
AkonadiModel::AlarmActionsRole
Definition: akonadimodel.h:69
AkonadiModel::WrongType
Definition: akonadimodel.h:52
KJob
AkonadiModel
Definition: akonadimodel.h:48
AkonadiModel::KeepFormatRole
Definition: akonadimodel.h:65
CalendarMigrator
Class to migrate KResources alarm calendars from pre-Akonadi versions of KAlarm, and to create defaul...
Definition: calendarmigrator.h:45
AkonadiModel::AlarmTypeRole
Definition: akonadimodel.h:63
AkonadiModel::TypeColumn
Definition: akonadimodel.h:55
QList< Event >
AkonadiModel::itemIndex
QModelIndex itemIndex(Akonadi::Item::Id id) const
Definition: akonadimodel.h:142
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:59:09 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kalarm

Skip menu "kalarm"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

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