• 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
collectionmodel.h
Go to the documentation of this file.
1 /*
2  * collectionmodel.h - Akonadi collection models
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 COLLECTIONMODEL_H
22 #define COLLECTIONMODEL_H
23 
24 #include "akonadimodel.h"
25 
26 #include <kalarmcal/kacalendar.h>
27 
28 #include <akonadi/favoritecollectionsmodel.h>
29 #include <kcheckableproxymodel.h>
30 #include <kdescendantsproxymodel.h>
31 #include <kdeversion.h>
32 
33 #include <QSortFilterProxyModel>
34 #include <QListView>
35 
36 using namespace KAlarmCal;
37 
38 class QEventLoop;
39 namespace Akonadi
40 {
41  class EntityMimeTypeFilterModel;
42 }
43 
44 /*=============================================================================
45 = Class: CollectionListModel
46 = Proxy model converting the AkonadiModel collection tree into a flat list.
47 = The model may be restricted to specified content mime types.
48 = It can optionally be restricted to writable and/or enabled Collections.
49 =============================================================================*/
50 class CollectionListModel : public KDescendantsProxyModel
51 {
52  Q_OBJECT
53  public:
54  explicit CollectionListModel(QObject* parent = 0);
55  void setEventTypeFilter(CalEvent::Type);
56  void setFilterWritable(bool writable);
57  void setFilterEnabled(bool enabled);
58  void useCollectionColour(bool use) { mUseCollectionColour = use; }
59  Akonadi::Collection collection(int row) const;
60  Akonadi::Collection collection(const QModelIndex&) const;
61  QModelIndex collectionIndex(const Akonadi::Collection&) const;
62  virtual bool isDescendantOf(const QModelIndex& ancestor, const QModelIndex& descendant) const;
63  virtual QVariant data(const QModelIndex&, int role = Qt::DisplayRole) const;
64 
65  private:
66  bool mUseCollectionColour;
67 };
68 
69 
70 /*=============================================================================
71 = Class: CollectionCheckListModel
72 = Proxy model providing a checkable list of all Collections. A Collection's
73 = checked status is equivalent to whether it is selected or not.
74 = An alarm type is specified, whereby Collections which are enabled for that
75 = alarm type are checked; Collections which do not contain that alarm type, or
76 = which are disabled for that alarm type, are unchedked.
77 =============================================================================*/
78 class CollectionCheckListModel : public KCheckableProxyModel
79 {
80  Q_OBJECT
81  public:
82  explicit CollectionCheckListModel(CalEvent::Type, QObject* parent = 0);
83  ~CollectionCheckListModel();
84  Akonadi::Collection collection(int row) const;
85  Akonadi::Collection collection(const QModelIndex&) const;
86  virtual QVariant data(const QModelIndex&, int role = Qt::DisplayRole) const;
87  virtual bool setData(const QModelIndex&, const QVariant& value, int role);
88 
89  signals:
90  void collectionTypeChange(CollectionCheckListModel*);
91 
92  private slots:
93  void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
94  void slotRowsInserted(const QModelIndex& parent, int start, int end);
95  void collectionStatusChanged(const Akonadi::Collection&, AkonadiModel::Change, const QVariant& value, bool inserted);
96 
97  private:
98  void setSelectionStatus(const Akonadi::Collection&, const QModelIndex&);
99 
100  static CollectionListModel* mModel;
101  static int mInstanceCount;
102  CalEvent::Type mAlarmType; // alarm type contained in this model
103  QItemSelectionModel* mSelectionModel;
104 };
105 
106 
107 /*=============================================================================
108 = Class: CollectionFilterCheckListModel
109 = Proxy model providing a checkable collection list. The model contains all
110 = alarm types, but returns only one type at any given time. The selected alarm
111 = type may be changed as desired.
112 =============================================================================*/
113 class CollectionFilterCheckListModel : public QSortFilterProxyModel
114 {
115  Q_OBJECT
116  public:
117  explicit CollectionFilterCheckListModel(QObject* parent = 0);
118  void setEventTypeFilter(CalEvent::Type);
119  Akonadi::Collection collection(int row) const;
120  Akonadi::Collection collection(const QModelIndex&) const;
121  virtual QVariant data(const QModelIndex&, int role = Qt::DisplayRole) const;
122 
123  protected:
124  bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const;
125 
126  private slots:
127  void collectionTypeChanged(CollectionCheckListModel*);
128 
129  private:
130  CollectionCheckListModel* mActiveModel;
131  CollectionCheckListModel* mArchivedModel;
132  CollectionCheckListModel* mTemplateModel;
133  CalEvent::Type mAlarmType; // alarm type contained in this model
134 };
135 
136 
137 /*=============================================================================
138 = Class: CollectionView
139 = View for a CollectionFilterCheckListModel.
140 =============================================================================*/
141 class CollectionView : public QListView
142 {
143  Q_OBJECT
144  public:
145  explicit CollectionView(CollectionFilterCheckListModel*, QWidget* parent = 0);
146  CollectionFilterCheckListModel* collectionModel() const { return static_cast<CollectionFilterCheckListModel*>(model()); }
147  Akonadi::Collection collection(int row) const;
148  Akonadi::Collection collection(const QModelIndex&) const;
149 
150  protected:
151  virtual void setModel(QAbstractItemModel*);
152  virtual void mouseReleaseEvent(QMouseEvent*);
153  virtual bool viewportEvent(QEvent*);
154 };
155 
156 
157 /*=============================================================================
158 = Class: CollectionControlModel
159 = Proxy model to select which Collections will be enabled. Disabled Collections
160 = are not populated or monitored; their contents are ignored. The set of
161 = enabled Collections is stored in the config file's "Collections" group.
162 = Note that this model is not used directly for displaying - its purpose is to
163 = allow collections to be disabled, which will remove them from the other
164 = collection models.
165 = This model also controls which collections are standard for their type,
166 = ensuring that there is only one standard collection for any given type.
167 =============================================================================*/
168 class CollectionControlModel : public Akonadi::FavoriteCollectionsModel
169 {
170  Q_OBJECT
171  public:
172  static CollectionControlModel* instance();
173 
175  static bool isEnabled(const Akonadi::Collection&, CalEvent::Type);
176 
181  static CalEvent::Types setEnabled(const Akonadi::Collection&, CalEvent::Types, bool enabled);
182 
193  static int isWritableEnabled(const Akonadi::Collection&, CalEvent::Type);
194 
212  static int isWritableEnabled(const Akonadi::Collection&, CalEvent::Type, KACalendar::Compat& format);
213 
219  static Akonadi::Collection getStandard(CalEvent::Type, bool useDefault = false);
220 
223  static bool isStandard(Akonadi::Collection&, CalEvent::Type);
224 
230  static CalEvent::Types standardTypes(const Akonadi::Collection&, bool useDefault = false);
231 
235  static void setStandard(Akonadi::Collection&, CalEvent::Type, bool standard);
236 
240  static void setStandard(Akonadi::Collection&, CalEvent::Types);
241 
247  static void setAskDestinationPolicy(bool ask) { mAskDestination = ask; }
248 
256  static Akonadi::Collection destination(CalEvent::Type, QWidget* promptParent = 0, bool noPrompt = false, bool* cancelled = 0);
257 
261  static Akonadi::Collection::List enabledCollections(CalEvent::Type, bool writable);
262 
266  static Akonadi::Collection collectionForResource(const QString& resourceId);
267 
268 #if KDE_IS_VERSION(4,9,80)
269 
272  static bool isPopulated(Akonadi::Collection::Id);
273 
280  bool waitUntilPopulated(Akonadi::Collection::Id colId = -1, int timeout = 0);
281 #endif
282 
283  virtual QVariant data(const QModelIndex&, int role = Qt::DisplayRole) const;
284 
286  static QString typeListForDisplay(CalEvent::Types);
287 
288  private slots:
289  void reset();
290  void statusChanged(const Akonadi::Collection&, AkonadiModel::Change, const QVariant& value, bool inserted);
291  void collectionPopulated();
292 
293  private:
294  explicit CollectionControlModel(QObject* parent = 0);
295  void findEnabledCollections(const Akonadi::EntityMimeTypeFilterModel*, const QModelIndex& parent, Akonadi::Collection::List&) const;
296  CalEvent::Types setEnabledStatus(const Akonadi::Collection&, CalEvent::Types, bool inserted);
297  static CalEvent::Types checkTypesToEnable(const Akonadi::Collection&, const Akonadi::Collection::List&, CalEvent::Types);
298 
299  static CollectionControlModel* mInstance;
300  static bool mAskDestination;
301  QEventLoop* mPopulatedCheckLoop;
302 };
303 
304 #endif // COLLECTIONMODEL_H
305 
306 // vim: et sw=4:
QModelIndex
QEvent
QWidget
CollectionControlModel::setAskDestinationPolicy
static void setAskDestinationPolicy(bool ask)
Set whether the user should be prompted for the destination collection to add alarms to...
Definition: collectionmodel.h:247
KCheckableProxyModel
QEventLoop
KDescendantsProxyModel
CollectionCheckListModel
Definition: collectionmodel.h:78
QMouseEvent
akonadimodel.h
QListView
CollectionListModel::useCollectionColour
void useCollectionColour(bool use)
Definition: collectionmodel.h:58
QObject
CollectionControlModel
Definition: collectionmodel.h:168
AkonadiModel::Change
Change
Definition: akonadimodel.h:50
QString
QSortFilterProxyModel
QItemSelection
CollectionFilterCheckListModel
Definition: collectionmodel.h:113
QAbstractItemModel
CollectionListModel
Definition: collectionmodel.h:50
CollectionView::collectionModel
CollectionFilterCheckListModel * collectionModel() const
Definition: collectionmodel.h:146
CollectionView
Definition: collectionmodel.h:141
QItemSelectionModel
QVariant
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