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

KDE's Doxygen guidelines are available online.