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