MauiKit Controls

notify.h
1/*
2 * <one line to give the program's name and a brief idea of what it does.>
3 * Copyright (C) 2021 <copyright holder> <email>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#pragma once
20
21#include <QObject>
22#include <QList>
23#include <QQmlListProperty>
24#include <QUrl>
25#include <QQmlEngine>
26
27class Notify;
28class NotifyAction : public QObject
29{
31 QML_ELEMENT
32 Q_DISABLE_COPY(NotifyAction)
33
34 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
35
36public:
37 NotifyAction(QObject *parent = nullptr);
38 void setText(const QString &text);
39 QString text() const;
40
41private:
42 QString m_text;
43
45 void triggered(Notify* notify);
46 void textChanged();
47};
48
49class KNotification;
50/**
51 * @todo write docs
52 */
53class Notify : public QObject
54{
56 QML_ELEMENT
57 Q_DISABLE_COPY(Notify)
58
59 Q_PROPERTY(QString componentName READ componentName WRITE setComponentName NOTIFY componentNameChanged)
60 Q_PROPERTY(QString eventId READ eventId WRITE setEventId REQUIRED)
61 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
62 Q_PROPERTY(QString message READ message WRITE setMessage NOTIFY messageChanged)
63 Q_PROPERTY(QString iconName READ iconName WRITE setIconName NOTIFY iconNameChanged)
64
65 Q_PROPERTY(QUrl imageSource READ imageSource WRITE setImageSource NOTIFY imageSourceChanged)
66 Q_PROPERTY(QQmlListProperty<NotifyAction> actions READ actions)
67 Q_PROPERTY(NotifyAction * defaultAction READ defaultAction WRITE setDefaultAction NOTIFY defaulActionChanged)
68 Q_PROPERTY(QList<QUrl> urls READ urls WRITE setUrls NOTIFY urlsChanged)
69
70public:
71 Notify(QObject * parent = nullptr);
72
74
75 void appendAction(NotifyAction*);
76 int actionsCount() const;
77 NotifyAction *action(int) const;
78 void clearActions();
79 void replaceAction(int, NotifyAction*);
80 void removeLastAction();
81
82 const QString &componentName() const;
83 void setComponentName(const QString &newComponentName);
84
85 const QString &eventId() const;
86 void setEventId(const QString &newEventId);
87
88 const QString &title() const;
89 void setTitle(const QString &newTitle);
90
91 const QString &message() const;
92 void setMessage(const QString &newMessage);
93
94 const QString &iconName() const;
95 void setIconName(const QString &newIconName);
96
97 const QUrl &imageSource() const;
98 void setImageSource(const QUrl &newImageSource);
99
100 NotifyAction *defaultAction() const;
101 void setDefaultAction(NotifyAction *newDefaultAction);
102
103 const QList<QUrl> &urls() const;
104 void setUrls(const QList<QUrl> &newUrls);
105
106private Q_SLOTS:
107 void actionActivated(int index);
108
109public Q_SLOTS:
110 void send();
111// void send(const QString &title, const QString &message, const QString &iconName);
112
114 void componentNameChanged(QString);
115
116 void titleChanged(QString);
117
118 void messageChanged(QString);
119
120 void iconNameChanged(QString);
121
122 void imageSourceChanged(QUrl);
123
124 void defaulActionChanged();
125
126 void urlsChanged(QList<QUrl>);
127
128private:
129 static void appendAction(QQmlListProperty<NotifyAction>*, NotifyAction*);
130 static int actionsCount(QQmlListProperty<NotifyAction>*);
131 static NotifyAction* action(QQmlListProperty<NotifyAction>*, int);
132 static void clearActions(QQmlListProperty<NotifyAction>*);
133 static void replaceAction(QQmlListProperty<NotifyAction>*, int, NotifyAction*);
134 static void removeLastAction(QQmlListProperty<NotifyAction>*);
135
136 QList<NotifyAction*> m_actions;
137
138 NotifyAction * m_defaultAction;
139 QString m_eventId;
140 QString m_title;
141 QString m_message;
142 QString m_iconName;
143 QString m_componentName;
144 QUrl m_imageSource;
145 QList<QUrl> m_urls;
146};
147
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 19 2024 12:00:22 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.