summaryrefslogtreecommitdiff
path: root/libsowatch/notificationsmodel.h
blob: 86ed2af0bde84eba49d4fb891f53f19725f00e3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef SOWATCH_NOTIFICATIONSMODEL_H
#define SOWATCH_NOTIFICATIONSMODEL_H

#include <QtCore/QAbstractListModel>

#include "notification.h"

namespace sowatch
{

class NotificationsModel : public QAbstractListModel
{
	Q_OBJECT

public:
	explicit NotificationsModel(QObject *parent = 0);

	enum DataRoles {
		ObjectRole = Qt::UserRole,
		BodyRole,
		CountRole
	};

	int rowCount(const QModelIndex &parent) const;
	QVariant data(const QModelIndex &index, int role) const;

	int size() const;
	int size(const QList<Notification::Type>& types) const;
	Notification* at(int position) const;
	Notification* at(Notification::Type type, int position) const;
	Notification* at(const QList<Notification::Type>& types, int position) const;

	void add(Notification *n);
	void remove(Notification *n);
	void remove(Notification::Type type, Notification *n);

	Q_INVOKABLE int countByType(Notification::Type type) const;

	Q_INVOKABLE int fullCount() const;
	Q_INVOKABLE int fullCountByType(Notification::Type type) const;
	Q_INVOKABLE int fullCountByType(int type) const; // See QTBUG-26415

	Q_INVOKABLE Notification* getMostRecentByType(Notification::Type type) const;
	Q_INVOKABLE QObject* getMostRecentByType(int type) const; // QML version

	Notification::Type getTypeOfDeletedNotification(Notification *n) const;

signals:
	void modelChanged();

private:
	int getOffsetForType(Notification::Type type) const;
	int getAppendOffsetForType(Notification::Type type) const;
	int getIndexForNotification(Notification *n) const;

private slots:
	void handleNotificationChanged();

private:
	QList<Notification*> _list[Notification::TypeCount];
};

}

QML_DECLARE_TYPE(sowatch::NotificationsModel)

#endif // SOWATCH_NOTIFICATIONSMODEL_H