MauiKit Controls

notify.cpp
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#include "notify.h"
20#include <KNotification>
21#include <QPixmap>
22#include <QDebug>
23
24NotifyAction::NotifyAction(QObject* parent) : QObject(parent)
25{
26}
27
28void NotifyAction::setText(const QString& text)
29{
30 if(text == m_text)
31 {
32 return;
33 }
34
35 m_text = text;
36 Q_EMIT textChanged();
37}
38
39QString NotifyAction::text() const
40{
41 return m_text;
42}
43
44Notify::Notify(QObject* parent) : QObject(parent)
45,m_defaultAction(nullptr)
46{
47}
48
49QQmlListProperty<NotifyAction> Notify::actions()
50{
51 return { };
52}
53
54void Notify::appendAction(NotifyAction* action)
55{
56 m_actions.append(action);
57}
58
59int Notify::actionsCount() const
60{
61 return m_actions.count();
62}
63
64NotifyAction * Notify::action(int index) const
65{
66 return m_actions.at(index);
67}
68
69void Notify::clearActions()
70{
71 m_actions.clear();
72}
73
74void Notify::replaceAction(int index, NotifyAction* action)
75{
76 m_actions[index] = action;
77}
78
79void Notify::removeLastAction()
80{
81 m_actions.removeLast();
82}
83
84void Notify::appendAction(QQmlListProperty<NotifyAction>* list, NotifyAction* action)
85{
86 reinterpret_cast< Notify* >(list->data)->appendAction(action);
87}
88
89int Notify::actionsCount(QQmlListProperty<NotifyAction>* list)
90{
91 return reinterpret_cast< Notify* >(list->data)->actionsCount();
92}
93
94NotifyAction * Notify::action(QQmlListProperty<NotifyAction>* list, int index)
95{
96 return reinterpret_cast< Notify* >(list->data)->action(index);
97}
98
99void Notify::clearActions(QQmlListProperty<NotifyAction>* list)
100{
101 reinterpret_cast< Notify* >(list->data)->clearActions();
102}
103
104void Notify::replaceAction(QQmlListProperty<NotifyAction>* list, int index, NotifyAction* action)
105{
106 reinterpret_cast< Notify* >(list->data)->replaceAction(index, action);
107}
108
109void Notify::removeLastAction(QQmlListProperty<NotifyAction>* list)
110{
111 reinterpret_cast< Notify* >(list->data)->removeLastAction();
112}
113
114void Notify::send()
115{
116
117 //const auto groups = contact->groups();
118 //for (const QString &group : groups) {
119 // m_notification->addContext("group", group);
120 //}
121
122
123 auto notification = new KNotification(m_eventId);
124
125
126 QStringList actionsLabels;
127 // for(const auto &action : qAsConst(m_actions))
128 // {
129 // actionsLabels << action->text ();
130 // qDebug() << "Setting notify actions first" << actionsLabels;
131 // }
132 // notification->setActions (actionsLabels);
133 //
134 // if(m_defaultAction)
135 // {
136 // notification->setDefaultAction (m_defaultAction->text ());
137 // }
138
139 notification->setComponentName (m_componentName);
140 notification->setText (m_message);
141 notification->setTitle (m_title);
142 notification->setIconName (m_iconName);
143 notification->setPixmap (QPixmap(m_imageSource.toString()));
144 notification->setUrls (m_urls);
145
146 qDebug() << notification->eventId ();
147
148
149 // connect(notification, QOverload<unsigned int>::of(&KNotification::activated), this, &Notify::actionActivated);
150 //
151 // connect(notification, &KNotification::defaultActivated,[this]()
152 // {
153 // if(m_defaultAction)
154 // Q_EMIT m_defaultAction->triggered (this);
155 // });
156
157 notification->sendEvent();
158}
159
160const QString &Notify::componentName() const
161{
162 return m_componentName;
163}
164
165void Notify::setComponentName(const QString &newComponentName)
166{
167 if (m_componentName == newComponentName)
168 return;
169 m_componentName = newComponentName;
170 Q_EMIT componentNameChanged(m_componentName);
171}
172
173void Notify::actionActivated(int index)
174{
175 qDebug() << "notify action was activated at <<" << index;
176if(index == 0)
177{
178 return;
179 }
180
181 if(index >= 1 && index-1 < m_actions.count ())
182 {
183 Q_EMIT m_actions.at (index-1)->triggered (this);
184 }
185}
186
187const QString &Notify::eventId() const
188{
189 return m_eventId;
190}
191
192void Notify::setEventId(const QString &newEventId)
193{
194 m_eventId = newEventId;
195}
196
197const QString &Notify::title() const
198{
199 return m_title;
200}
201
202void Notify::setTitle(const QString &newTitle)
203{
204 if (m_title == newTitle)
205 return;
206 m_title = newTitle;
207 Q_EMIT titleChanged(m_title);
208}
209
210const QString &Notify::message() const
211{
212 return m_message;
213}
214
215void Notify::setMessage(const QString &newMessage)
216{
217 if (m_message == newMessage)
218 return;
219 m_message = newMessage;
220 Q_EMIT messageChanged(m_message);
221}
222
223const QString &Notify::iconName() const
224{
225 return m_iconName;
226}
227
228void Notify::setIconName(const QString &newIconName)
229{
230 if (m_iconName == newIconName)
231 return;
232 m_iconName = newIconName;
233 Q_EMIT iconNameChanged(m_iconName);
234}
235
236const QUrl &Notify::imageSource() const
237{
238 return m_imageSource;
239}
240
241void Notify::setImageSource(const QUrl &newImageSource)
242{
243 if (m_imageSource == newImageSource)
244 return;
245 m_imageSource = newImageSource;
246 Q_EMIT imageSourceChanged(m_imageSource);
247}
248
249NotifyAction *Notify::defaultAction() const
250{
251 return m_defaultAction;
252}
253
254void Notify::setDefaultAction(NotifyAction *newDefaultAction)
255{
256 if (m_defaultAction == newDefaultAction)
257 return;
258 m_defaultAction = newDefaultAction;
259 Q_EMIT defaulActionChanged();
260}
261
262const QList<QUrl> &Notify::urls() const
263{
264 return m_urls;
265}
266
267void Notify::setUrls(const QList<QUrl> &newUrls)
268{
269 if (m_urls == newUrls)
270 return;
271 m_urls = newUrls;
272 Q_EMIT urlsChanged(m_urls);
273}
KIOCORE_EXPORT QStringList list(const QString &fileClass)
pointer data()
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Mar 21 2025 12:01:42 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.