french -> French
[kdepim.git] / kalarm / itemlistmodel.h
blobb46f782bfa643ccc8b5298673523b0498c04a820
1 /*
2 * itemlistmodel.h - Akonadi item models
3 * Program: kalarm
4 * Copyright © 2010,2011 by David Jarvie <djarvie@kde.org>
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.
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.
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.
21 #ifndef ITEMLISTMODEL_H
22 #define ITEMLISTMODEL_H
24 #include "akonadimodel.h"
26 #include <kalarmcal/kacalendar.h>
27 #include <kalarmcal/kaevent.h>
29 #include <akonadi/entitymimetypefiltermodel.h>
31 using namespace KAlarmCal;
33 /*=============================================================================
34 = Class: ItemListModel
35 = Filter proxy model containing all items (alarms/templates) of specified mime
36 = types in enabled collections.
37 =============================================================================*/
38 class ItemListModel : public Akonadi::EntityMimeTypeFilterModel
40 Q_OBJECT
41 public:
42 /** Constructor.
43 * @param allowed the alarm types (active/archived/template) included in this model
45 explicit ItemListModel(CalEvent::Types allowed, QObject* parent = 0);
47 CalEvent::Types includedTypes() const { return mAllowedTypes; }
48 KAEvent event(int row) const;
49 KAEvent event(const QModelIndex&) const;
50 using QObject::event; // prevent warning about hidden virtual method
51 QModelIndex eventIndex(Akonadi::Item::Id) const;
53 /** Determine whether the model contains any items. */
54 bool haveEvents() const;
56 virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
57 virtual Qt::ItemFlags flags(const QModelIndex&) const;
59 static int iconWidth() { return AkonadiModel::iconSize().width(); }
61 signals:
62 /** Signal emitted when either the first item is added to the model,
63 * or when the last item is deleted from the model.
65 void haveEventsStatus(bool have);
67 protected:
68 virtual bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const;
70 private slots:
71 void slotRowsInserted();
72 void slotRowsRemoved();
73 void collectionStatusChanged(const Akonadi::Collection& collection, AkonadiModel::Change change, const QVariant&, bool inserted);
75 private:
76 CalEvent::Types mAllowedTypes; // types of events allowed in this model
77 bool mHaveEvents; // there are events in this model
81 /*=============================================================================
82 = Class: AlarmListModel
83 = Filter proxy model containing all alarms of specified mime types in enabled
84 = collections.
85 Equivalent to AlarmListFilterModel
86 =============================================================================*/
87 class AlarmListModel : public ItemListModel
89 Q_OBJECT
90 public:
91 enum { // data columns
92 TimeColumn = 0, TimeToColumn, RepeatColumn, ColourColumn, TypeColumn, TextColumn,
93 ColumnCount
96 explicit AlarmListModel(QObject* parent = 0);
97 ~AlarmListModel();
99 /** Return the model containing all active and archived alarms. */
100 static AlarmListModel* all();
102 /** Set a filter to restrict the event types to a subset of those
103 * specified in the constructor.
104 * @param types the event types to be included in the model
106 void setEventTypeFilter(CalEvent::Types types);
108 /** Return the filter set by setEventTypeFilter().
109 * @return all event types included in the model
111 CalEvent::Types eventTypeFilter() const { return mFilterTypes; }
113 virtual int columnCount(const QModelIndex& = QModelIndex()) const { return ColumnCount; }
114 virtual QVariant headerData(int section, Qt::Orientation, int role = Qt::DisplayRole) const;
116 protected:
117 virtual bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const;
118 virtual bool filterAcceptsColumn(int sourceCol, const QModelIndex& sourceParent) const;
120 private:
121 static AlarmListModel* mAllInstance;
123 CalEvent::Types mFilterTypes; // types of events contained in this model
127 /*=============================================================================
128 = Class: TemplateListModel
129 = Filter proxy model containing all alarm templates for specified alarm types
130 = in enabled collections.
131 Equivalent to TemplateListFilterModel
132 =============================================================================*/
133 class TemplateListModel : public ItemListModel
135 Q_OBJECT
136 public:
137 enum { // data columns
138 TypeColumn, TemplateNameColumn,
139 ColumnCount
142 explicit TemplateListModel(QObject* parent = 0);
143 ~TemplateListModel();
145 /** Return the model containing all alarm templates. */
146 static TemplateListModel* all();
148 /** Set which alarm action types should be included in the model. */
149 void setAlarmActionFilter(KAEvent::Actions);
151 /** Return which alarm action types are included in the model. */
152 KAEvent::Actions alarmActionFilter() const { return mActionsFilter; }
154 /** Set which alarm types should be shown as disabled in the model. */
155 void setAlarmActionsEnabled(KAEvent::Actions);
157 /** Set which alarm types should be shown as disabled in the model. */
158 KAEvent::Actions setAlarmActionsEnabled() const { return mActionsEnabled; }
160 virtual int columnCount(const QModelIndex& = QModelIndex()) const { return ColumnCount; }
161 virtual QVariant headerData(int section, Qt::Orientation, int role = Qt::DisplayRole) const;
162 virtual Qt::ItemFlags flags(const QModelIndex&) const;
164 protected:
165 virtual bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const;
166 virtual bool filterAcceptsColumn(int sourceCol, const QModelIndex& sourceParent) const;
168 private:
169 static TemplateListModel* mAllInstance;
171 KAEvent::Actions mActionsEnabled; // disable types not in this mask
172 KAEvent::Actions mActionsFilter; // hide types not in this mask
175 #endif // ITEMLISTMODEL_H
177 // vim: et sw=4: