2 * eventlistmodel.h - model class for lists of alarms or templates
4 * Copyright © 2007-2012 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 EVENTLISTMODEL_H
22 #define EVENTLISTMODEL_H
26 #include "alarmresources.h"
28 #include <kalarmcal/kacalendar.h>
29 #include <kalarmcal/kaevent.h>
31 #include <QAbstractTableModel>
32 #include <QSortFilterProxyModel>
37 namespace KCal
{ class Event
; }
39 using namespace KAlarmCal
;
42 class EventListModel
: public QAbstractTableModel
46 enum { // data columns
47 TimeColumn
, TimeToColumn
, RepeatColumn
, ColourColumn
, TypeColumn
, TextColumn
,
51 enum { // additional roles
52 StatusRole
= Qt::UserRole
, // return ACTIVE/ARCHIVED
53 ValueRole
, // return numeric value
54 SortRole
, // return the value to use for sorting
55 EnabledRole
// return true for enabled alarm, false for disabled
58 static EventListModel
* alarms();
59 static EventListModel
* templates();
61 virtual int rowCount(const QModelIndex
& parent
= QModelIndex()) const;
62 virtual int columnCount(const QModelIndex
& parent
= QModelIndex()) const;
63 virtual QModelIndex
index(int row
, int column
= 0, const QModelIndex
& parent
= QModelIndex()) const;
64 virtual QVariant
data(const QModelIndex
&, int role
= Qt::DisplayRole
) const;
65 virtual bool setData(const QModelIndex
&, const QVariant
& value
, int role
= Qt::EditRole
);
66 virtual QVariant
headerData(int section
, Qt::Orientation
, int role
= Qt::DisplayRole
) const;
67 virtual Qt::ItemFlags
flags(const QModelIndex
&) const;
68 static int iconWidth() { return mIconSize
.width(); }
69 QModelIndex
eventIndex(const KAEvent
*) const;
70 QModelIndex
eventIndex(const QString
& eventId
) const;
71 void addEvent(KAEvent
*);
72 void addEvents(const KAEvent::List
&);
73 bool updateEvent(KAEvent
* event
) { return updateEvent(mEvents
.indexOf(event
)); }
74 bool updateEvent(const QString
& eventId
) { return updateEvent(findEvent(eventId
)); }
75 bool updateEvent(const QString
& oldId
, KAEvent
* newEvent
);
76 void removeEvent(const KAEvent
* event
) { removeEvent(mEvents
.indexOf(const_cast<KAEvent
*>(event
))); }
77 void removeEvent(const QString
& eventId
) { removeEvent(findEvent(eventId
)); }
78 void removeResource(AlarmResource
*);
79 KAEvent
* event(int row
) const;
80 static KAEvent
* event(const QModelIndex
&);
81 void updateCommandError(const QString
& eventId
);
82 bool haveEvents() const { return mHaveEvents
; }
83 static void resourceStatusChanged(AlarmResource
*, AlarmResources::Change
);
89 void haveEventsStatus(bool have
);
92 void slotUpdateTimeTo();
93 void slotUpdateArchivedColour(const QColor
&);
94 void slotUpdateDisabledColour(const QColor
&);
95 void slotUpdateHolidays();
96 void slotUpdateWorkingHours();
97 void slotResourceLoaded(AlarmResource
*, bool active
);
98 void slotResourceStatusChanged(AlarmResource
*, AlarmResources::Change
);
101 explicit EventListModel(CalEvent::Types
, QObject
* parent
= 0);
102 bool updateEvent(int row
);
103 void removeEvent(int row
);
104 int findEvent(const QString
& eventId
) const;
105 void updateHaveEvents(bool have
) { mHaveEvents
= have
; emit
haveEventsStatus(have
); }
106 QString
repeatText(const KAEvent
*) const;
107 QString
repeatOrder(const KAEvent
*) const;
108 QPixmap
* eventIcon(const KAEvent
*) const;
109 QString
whatsThisText(int column
) const;
111 static EventListModel
* mAlarmInstance
; // the instance containing all alarms
112 static EventListModel
* mTemplateInstance
; // the instance containing all templates
113 static QPixmap
* mTextIcon
;
114 static QPixmap
* mFileIcon
;
115 static QPixmap
* mCommandIcon
;
116 static QPixmap
* mEmailIcon
;
117 static QPixmap
* mAudioIcon
;
118 static QSize mIconSize
; // maximum size of any icon
119 static int mTimeHourPos
; // position of hour within time string, or -1 if leading zeroes included
121 KAEvent::List mEvents
;
122 CalEvent::Types mStatus
; // types of events contained in this model
123 bool mHaveEvents
;// there are events in this model
125 using QObject::event
; // prevent "hidden" warning
129 class EventListFilterModel
: public QSortFilterProxyModel
133 explicit EventListFilterModel(EventListModel
* baseModel
, QObject
* parent
= 0);
134 KAEvent
* event(int row
) const;
135 KAEvent
* event(const QModelIndex
&) const;
136 QModelIndex
eventIndex(const KAEvent
*) const;
137 QModelIndex
eventIndex(const QString
& eventId
) const;
140 void slotDataChanged(const QModelIndex
&, const QModelIndex
&);
143 using QObject::event
; // prevent "hidden" warning
146 #endif // EVENTLISTMODEL_H