File indexing completed on 2024-05-05 04:46:59
0001 /* 0002 * <one line to give the program's name and a brief idea of what it does.> 0003 * Copyright (C) 2021 <copyright holder> <email> 0004 * 0005 * This program is free software: you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation, either version 3 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 */ 0018 0019 #pragma once 0020 0021 #include <QObject> 0022 #include <QList> 0023 #include <QQmlListProperty> 0024 #include <QUrl> 0025 0026 class Notify; 0027 class NotifyAction : public QObject 0028 { 0029 Q_OBJECT 0030 Q_DISABLE_COPY(NotifyAction) 0031 0032 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) 0033 0034 public: 0035 NotifyAction(QObject *parent = nullptr); 0036 void setText(const QString &text); 0037 QString text() const; 0038 0039 private: 0040 QString m_text; 0041 0042 Q_SIGNALS: 0043 void triggered(Notify* notify); 0044 void textChanged(); 0045 }; 0046 0047 class KNotification; 0048 /** 0049 * @todo write docs 0050 */ 0051 class Notify : public QObject 0052 { 0053 Q_OBJECT 0054 Q_DISABLE_COPY(Notify) 0055 0056 Q_PROPERTY(QString componentName READ componentName WRITE setComponentName NOTIFY componentNameChanged) 0057 Q_PROPERTY(QString eventId READ eventId WRITE setEventId REQUIRED) 0058 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) 0059 Q_PROPERTY(QString message READ message WRITE setMessage NOTIFY messageChanged) 0060 Q_PROPERTY(QString iconName READ iconName WRITE setIconName NOTIFY iconNameChanged) 0061 0062 Q_PROPERTY(QUrl imageSource READ imageSource WRITE setImageSource NOTIFY imageSourceChanged) 0063 Q_PROPERTY(QQmlListProperty<NotifyAction> actions READ actions) 0064 Q_PROPERTY(NotifyAction * defaultAction READ defaultAction WRITE setDefaultAction NOTIFY defaulActionChanged) 0065 Q_PROPERTY(QList<QUrl> urls READ urls WRITE setUrls NOTIFY urlsChanged) 0066 0067 public: 0068 Notify(QObject * parent = nullptr); 0069 0070 QQmlListProperty<NotifyAction> actions(); 0071 0072 void appendAction(NotifyAction*); 0073 int actionsCount() const; 0074 NotifyAction *action(int) const; 0075 void clearActions(); 0076 void replaceAction(int, NotifyAction*); 0077 void removeLastAction(); 0078 0079 const QString &componentName() const; 0080 void setComponentName(const QString &newComponentName); 0081 0082 const QString &eventId() const; 0083 void setEventId(const QString &newEventId); 0084 0085 const QString &title() const; 0086 void setTitle(const QString &newTitle); 0087 0088 const QString &message() const; 0089 void setMessage(const QString &newMessage); 0090 0091 const QString &iconName() const; 0092 void setIconName(const QString &newIconName); 0093 0094 const QUrl &imageSource() const; 0095 void setImageSource(const QUrl &newImageSource); 0096 0097 NotifyAction *defaultAction() const; 0098 void setDefaultAction(NotifyAction *newDefaultAction); 0099 0100 const QList<QUrl> &urls() const; 0101 void setUrls(const QList<QUrl> &newUrls); 0102 0103 private Q_SLOTS: 0104 void actionActivated(int index); 0105 0106 public Q_SLOTS: 0107 void send(); 0108 // void send(const QString &title, const QString &message, const QString &iconName); 0109 0110 Q_SIGNALS: 0111 void componentNameChanged(QString); 0112 0113 void titleChanged(QString); 0114 0115 void messageChanged(QString); 0116 0117 void iconNameChanged(QString); 0118 0119 void imageSourceChanged(QUrl); 0120 0121 void defaulActionChanged(); 0122 0123 void urlsChanged(QList<QUrl>); 0124 0125 private: 0126 static void appendAction(QQmlListProperty<NotifyAction>*, NotifyAction*); 0127 static int actionsCount(QQmlListProperty<NotifyAction>*); 0128 static NotifyAction* action(QQmlListProperty<NotifyAction>*, int); 0129 static void clearActions(QQmlListProperty<NotifyAction>*); 0130 static void replaceAction(QQmlListProperty<NotifyAction>*, int, NotifyAction*); 0131 static void removeLastAction(QQmlListProperty<NotifyAction>*); 0132 0133 QList<NotifyAction*> m_actions; 0134 0135 NotifyAction * m_defaultAction; 0136 QString m_eventId; 0137 QString m_title; 0138 QString m_message; 0139 QString m_iconName; 0140 QString m_componentName; 0141 QUrl m_imageSource; 0142 QList<QUrl> m_urls; 0143 }; 0144