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

kalarm

  • sources
  • kde-4.14
  • 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-2014 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 }
40 class QPixmap;
41 class KJob;
42 
43 using namespace KAlarmCal;
44 
45 
46 class AkonadiModel : public Akonadi::EntityTreeModel
47 {
48  Q_OBJECT
49  public:
50  enum Change { Added, Deleted, Invalidated, Enabled, ReadOnly, AlarmTypes, WrongType, Location, Colour };
51  enum { // data columns
52  // Item columns
53  TimeColumn = 0, TimeToColumn, RepeatColumn, ColourColumn, TypeColumn, TextColumn,
54  TemplateNameColumn,
55  ColumnCount
56  };
57  enum { // additional data roles
58  // Collection roles
59  EnabledTypesRole = UserRole, // alarm types which are enabled for the collection
60  BaseColourRole, // background colour ignoring collection colour
61  AlarmTypeRole, // OR of event types which collection contains
62  IsStandardRole, // OR of event types which collection is standard for
63  KeepFormatRole, // user has chosen not to update collection's calendar storage format
64  // Item roles
65  EnabledRole, // true for enabled alarm, false for disabled
66  StatusRole, // KAEvent::ACTIVE/ARCHIVED/TEMPLATE
67  AlarmActionsRole, // KAEvent::Actions
68  AlarmSubActionRole, // KAEvent::Action
69  ValueRole, // numeric value
70  SortRole, // the value to use for sorting
71  CommandErrorRole // last command execution error for alarm (per user)
72  };
73 
75  struct Event
76  {
77  Event(const KAEvent& e, const Akonadi::Collection& c) : event(e), collection(c) {}
78  EventId eventId() const { return EventId(collection.id(), event.id()); }
79  bool isConsistent() const { return event.collectionId() == collection.id(); }
80  KAEvent event;
81  Akonadi::Collection collection;
82  };
83  typedef QList<Event> EventList;
84 
85  static AkonadiModel* instance();
86 
87  ~AkonadiModel();
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 
156  QModelIndex eventIndex(const KAEvent&);
160  Akonadi::Item::Id findItemId(const KAEvent&);
161 
162 #if 0
163 
164  KAEvent::List events(Akonadi::Collection&, CalEvent::Type = CalEvent::EMPTY) const;
165 #endif
166 
167  bool addEvent(KAEvent&, Akonadi::Collection&);
168  bool addEvents(const KAEvent::List&, Akonadi::Collection&);
169  bool updateEvent(KAEvent& event);
170  bool updateEvent(Akonadi::Item::Id oldId, KAEvent& newEvent);
171  bool deleteEvent(const KAEvent& event);
172  bool deleteEvent(Akonadi::Item::Id itemId);
173 
175  static bool isCompatible(const Akonadi::Collection&);
176 
185  static int isWritable(const Akonadi::Collection&);
186 
200  static int isWritable(const Akonadi::Collection&, KACalendar::Compat& format);
201 
202  static CalEvent::Types types(const Akonadi::Collection&);
203 
204  static QSize iconSize() { return mIconSize; }
205 
206  signals:
208  void collectionAdded(const Akonadi::Collection&);
209 
214  void collectionStatusChanged(const Akonadi::Collection&, AkonadiModel::Change, const QVariant& newValue, bool inserted);
215 
217  void eventsAdded(const AkonadiModel::EventList&);
218 
220  void eventsToBeRemoved(const AkonadiModel::EventList&);
221 
223  void eventChanged(const AkonadiModel::Event&);
224 
229  void collectionModified(Akonadi::Collection::Id, bool status = true);
230 
235  void collectionDeleted(Akonadi::Collection::Id, bool status = true);
236 
242  void itemDone(Akonadi::Item::Id, bool status = true);
243 
245  void migrationCompleted();
246 
248  void serverStopped();
249 
250  protected:
251  virtual QVariant entityHeaderData(int section, Qt::Orientation, int role, HeaderGroup) const;
252  virtual int entityColumnCount(HeaderGroup) const;
253 
254  private slots:
255  void checkResources(Akonadi::ServerManager::State);
256  void slotMigrationCompleted();
257  void slotCollectionChanged(const Akonadi::Collection& c, const QSet<QByteArray>& attrNames)
258  { setCollectionChanged(c, attrNames, false); }
259  void slotCollectionRemoved(const Akonadi::Collection&);
260  void slotCollectionBeingCreated(const QString& path, Akonadi::Collection::Id, bool finished);
261  void slotUpdateTimeTo();
262  void slotUpdateArchivedColour(const QColor&);
263  void slotUpdateDisabledColour(const QColor&);
264  void slotUpdateHolidays();
265  void slotUpdateWorkingHours();
266  void slotRowsInserted(const QModelIndex& parent, int start, int end);
267  void slotRowsAboutToBeRemoved(const QModelIndex& parent, int start, int end);
268  void slotMonitoredItemChanged(const Akonadi::Item&, const QSet<QByteArray>&);
269  void slotEmitEventChanged();
270  void modifyCollectionJobDone(KJob*);
271  void itemJobDone(KJob*);
272 
273  private:
274  struct CalData // data per collection
275  {
276  CalData() : enabled(false) { }
277  CalData(bool e, const QColor& c) : colour(c), enabled(e) { }
278  QColor colour; // user selected color for the calendar
279  bool enabled; // whether the collection is enabled
280  };
281  struct CollJobData // collection data for jobs in progress
282  {
283  CollJobData() : id(-1) {}
284  CollJobData(Akonadi::Collection::Id i, const QString& d) : id(i), displayName(d) {}
285  Akonadi::Collection::Id id;
286  QString displayName;
287  };
288  struct CollTypeData // data for configuration dialog for collection creation job
289  {
290  CollTypeData() : parent(0), alarmType(CalEvent::EMPTY) {}
291  CollTypeData(CalEvent::Type t, QWidget* p) : parent(p), alarmType(t) {}
292  QWidget* parent;
293  CalEvent::Type alarmType;
294  };
295 
296  AkonadiModel(Akonadi::ChangeRecorder*, QObject* parent);
297  void initCalendarMigrator();
298  KAEvent event(const Akonadi::Item&, const QModelIndex&, Akonadi::Collection*) const;
299  void signalDataChanged(bool (*checkFunc)(const Akonadi::Item&), int startColumn, int endColumn, const QModelIndex& parent);
300  void setCollectionChanged(const Akonadi::Collection&, const QSet<QByteArray>&, bool rowInserted);
301  void queueItemModifyJob(const Akonadi::Item&);
302  void checkQueuedItemModifyJob(const Akonadi::Item&);
303 #if 0
304  void getChildEvents(const QModelIndex& parent, CalEvent::Type, KAEvent::List&) const;
305 #endif
306  QColor backgroundColor_p(const Akonadi::Collection&) const;
307  QString repeatText(const KAEvent&) const;
308  QString repeatOrder(const KAEvent&) const;
309  QPixmap* eventIcon(const KAEvent&) const;
310  QString whatsThisText(int column) const;
311  EventList eventList(const QModelIndex& parent, int start, int end);
312 
313  static AkonadiModel* mInstance;
314  static QPixmap* mTextIcon;
315  static QPixmap* mFileIcon;
316  static QPixmap* mCommandIcon;
317  static QPixmap* mEmailIcon;
318  static QPixmap* mAudioIcon;
319  static QSize mIconSize;
320  static int mTimeHourPos; // position of hour within time string, or -1 if leading zeroes included
321 
322  Akonadi::ChangeRecorder* mMonitor;
323  QMap<Akonadi::Collection::Id, CalEvent::Types> mCollectionAlarmTypes; // last content mime types of each collection
324  QMap<Akonadi::Collection::Id, Akonadi::Collection::Rights> mCollectionRights; // last writable status of each collection
325  QMap<Akonadi::Collection::Id, CalEvent::Types> mCollectionEnabled; // last enabled mime types of each collection
326  QMap<KJob*, CollJobData> mPendingCollectionJobs; // pending collection creation/deletion jobs, with collection ID & name
327  QMap<KJob*, CollTypeData> mPendingColCreateJobs; // default alarm type for pending collection creation jobs
328  QMap<KJob*, Akonadi::Item::Id> mPendingItemJobs; // pending item creation/deletion jobs, with event ID
329  QMap<Akonadi::Item::Id, Akonadi::Item> mItemModifyJobQueue; // pending item modification jobs, invalid item = queue empty but job active
330  QList<QString> mCollectionsBeingCreated; // path names of new collections being created by migrator
331  QList<Akonadi::Collection::Id> mCollectionIdsBeingCreated; // ids of new collections being created by migrator
332  QList<Akonadi::Item::Id> mItemsBeingCreated; // new items not fully initialised yet
333  QList<Akonadi::Collection::Id> mCollectionsDeleting; // collections currently being removed
334  QList<Akonadi::Collection::Id> mCollectionsDeleted; // collections recently removed
335  QQueue<Event> mPendingEventChanges; // changed events with changedEvent() signal pending
336  bool mResourcesChecked; // whether resource existence has been checked yet
337  bool mMigrating; // currently migrating calendars
338 };
339 
340 #endif // AKONADIMODEL_H
341 
342 // vim: et sw=4:
QModelIndex
AkonadiModel::StatusRole
Definition: akonadimodel.h:66
QWidget
QQueue
AkonadiModel::IsStandardRole
Definition: akonadimodel.h:62
QMap< Akonadi::Collection::Id, CalEvent::Types >
eventid.h
AkonadiModel::collectionIndex
QModelIndex collectionIndex(Akonadi::Collection::Id id) const
Definition: akonadimodel.h:119
AkonadiModel::AlarmSubActionRole
Definition: akonadimodel.h:68
AkonadiModel::event
KAEvent event(const Akonadi::Item &item) const
Return the alarm with the specified unique identifier.
Definition: akonadimodel.h:150
QObject::event
virtual bool event(QEvent *e)
AkonadiModel::EventList
QList< Event > EventList
Definition: akonadimodel.h:83
AkonadiModel::Event
Struct containing a KAEvent and its parent Collection.
Definition: akonadimodel.h:75
AkonadiModel::TemplateNameColumn
Definition: akonadimodel.h:54
AkonadiModel::Event::event
KAEvent event
Definition: akonadimodel.h:80
QObject
AkonadiModel::ValueRole
Definition: akonadimodel.h:69
AkonadiModel::Event::collection
Akonadi::Collection collection
Definition: akonadimodel.h:81
AkonadiModel::SortRole
Definition: akonadimodel.h:70
AkonadiModel::Change
Change
Definition: akonadimodel.h:50
QSet
QString
QList< Event >
QColor
QStringList
QPixmap
AkonadiModel::EnabledRole
Definition: akonadimodel.h:65
AkonadiModel::Event::Event
Event(const KAEvent &e, const Akonadi::Collection &c)
Definition: akonadimodel.h:77
QSize
EventId
Unique event identifier for Akonadi.
Definition: eventid.h:38
AkonadiModel::Event::eventId
EventId eventId() const
Definition: akonadimodel.h:78
AkonadiModel::Event::isConsistent
bool isConsistent() const
Definition: akonadimodel.h:79
AkonadiModel::BaseColourRole
Definition: akonadimodel.h:60
AkonadiModel::collection
Akonadi::Collection collection(const KAEvent &e) const
Definition: akonadimodel.h:124
AkonadiModel::iconSize
static QSize iconSize()
Definition: akonadimodel.h:204
AkonadiModel::AlarmActionsRole
Definition: akonadimodel.h:67
AkonadiModel::WrongType
Definition: akonadimodel.h:50
KJob
AkonadiModel
Definition: akonadimodel.h:46
AkonadiModel::KeepFormatRole
Definition: akonadimodel.h:63
AkonadiModel::AlarmTypeRole
Definition: akonadimodel.h:61
AkonadiModel::TypeColumn
Definition: akonadimodel.h:53
QVariant
AkonadiModel::itemIndex
QModelIndex itemIndex(Akonadi::Item::Id id) const
Definition: akonadimodel.h:142
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:51 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
  • pimprint

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