KNotifications

knotificationqmlplugin.cpp
1 /*
2  SPDX-FileCopyrightText: 2021 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "knotificationqmlplugin.h"
8 
9 #include <KNotification>
10 #include <KNotificationReplyAction>
11 
12 class NotificationWrapper : public KNotification
13 {
14  Q_OBJECT
15  Q_PROPERTY(KNotificationReplyAction *replyAction READ replyActionFactory CONSTANT)
16 public:
17  explicit NotificationWrapper(QObject *parent = nullptr)
19  {
20  setAutoDelete(false);
21  }
22 
23  KNotificationReplyAction *replyActionFactory()
24  {
25  if (!replyAction()) {
26  setReplyAction(std::make_unique<KNotificationReplyAction>(QString()));
27  }
28  return replyAction();
29  }
30 };
31 
32 void KNotificationQmlPlugin::registerTypes(const char *uri)
33 {
34  Q_ASSERT(QLatin1String(uri) == QLatin1String("org.kde.notification"));
35  qmlRegisterType<NotificationWrapper>(uri, 1, 0, "Notification");
36  qmlRegisterUncreatableType<KNotificationReplyAction>(uri, 1, 0, "NotificationReplyAction", {});
37 }
38 
39 #include "knotificationqmlplugin.moc"
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
KNotificationReplyAction * replyAction() const
void setReplyAction(std::unique_ptr< KNotificationReplyAction > replyAction)
Add an inline reply action to the notification.
@ CloseOnTimeout
The notification will be automatically closed after a timeout.
QObject * parent() const const
void setAutoDelete(bool autoDelete)
Sets whether this notification object will be automatically deleted after closing.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon May 8 2023 03:49:15 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.