2023-08-24 19:53:51 +03:00
|
|
|
/* This file is part of the KDE libraries
|
|
|
|
Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License version 2, as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public License
|
|
|
|
along with this library; see the file COPYING.LIB. If not, write to
|
|
|
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
2014-11-13 01:04:59 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "knotification.h"
|
2023-08-24 19:53:51 +03:00
|
|
|
#include "kglobal.h"
|
|
|
|
#include "kcomponentdata.h"
|
|
|
|
#include "kconfig.h"
|
|
|
|
#include "kconfiggroup.h"
|
|
|
|
#include "kstandarddirs.h"
|
|
|
|
#include "kwindowsystem.h"
|
|
|
|
#include "kdbusconnectionpool.h"
|
|
|
|
#include "kiconloader.h"
|
|
|
|
#include "kpassivepopup.h"
|
|
|
|
#include "kdebug.h"
|
|
|
|
|
|
|
|
#include <QDBusConnectionInterface>
|
|
|
|
#include <QDBusInterface>
|
|
|
|
#include <QDBusReply>
|
2014-11-13 01:04:59 +02:00
|
|
|
#include <QTimer>
|
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
// for reference:
|
|
|
|
// https://specifications.freedesktop.org/notification-spec/notification-spec-latest.html
|
|
|
|
|
|
|
|
// see kdebug.areas
|
|
|
|
static const int s_knotificationarea = 299;
|
|
|
|
static const QString s_notifications = QString::fromLatin1("org.freedesktop.Notifications");
|
|
|
|
|
|
|
|
class KNotificationManager : public QObject
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-08-24 19:53:51 +03:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
KNotificationManager();
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
void send(KNotification *notification, const bool persistent);
|
|
|
|
void close(KNotification *notification);
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void slotNotificationClosed(uint eventid, uint reason);
|
|
|
|
void slotActionInvoked(uint eventid, const QString &action);
|
|
|
|
|
|
|
|
private:
|
|
|
|
KConfig m_config;
|
|
|
|
QDBusInterface* m_notificationsiface;
|
|
|
|
QDBusInterface* m_kaudioplayeriface;
|
|
|
|
QMap<KNotification*,uint> m_notifications;
|
2014-11-13 01:04:59 +02:00
|
|
|
};
|
2023-08-24 19:53:51 +03:00
|
|
|
K_GLOBAL_STATIC(KNotificationManager, kNotificationManager);
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
KNotificationManager::KNotificationManager()
|
2023-08-25 23:12:14 +03:00
|
|
|
: m_config("knotificationrc", KConfig::NoGlobals),
|
2023-08-24 19:53:51 +03:00
|
|
|
m_notificationsiface(nullptr),
|
|
|
|
m_kaudioplayeriface(nullptr)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-08-25 23:12:14 +03:00
|
|
|
// TODO: config watch
|
2023-08-24 19:53:51 +03:00
|
|
|
const QStringList notifyconfigs = KGlobal::dirs()->findAllResources("config", "notifications/*.notifyrc");
|
2023-08-25 23:12:14 +03:00
|
|
|
if (!notifyconfigs.isEmpty()) {
|
|
|
|
m_config.addConfigSources(notifyconfigs);
|
|
|
|
}
|
2023-08-25 19:11:07 +03:00
|
|
|
// qDebug() << Q_FUNC_INFO << notifyconfigs;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
void KNotificationManager::send(KNotification *notification, const bool persistent)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-08-24 19:53:51 +03:00
|
|
|
const QString eventid = notification->eventID();
|
|
|
|
const QStringList spliteventid = eventid.split(QLatin1Char('/'));
|
|
|
|
// qDebug() << Q_FUNC_INFO << spliteventid;
|
|
|
|
if (spliteventid.size() != 2) {
|
|
|
|
kWarning(s_knotificationarea) << "invalid notification ID" << eventid;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
KConfigGroup globalgroup(&m_config, spliteventid.at(0));
|
|
|
|
KConfigGroup eventgroup(&m_config, eventid);
|
|
|
|
QString eventtitle = notification->title();
|
|
|
|
if (eventtitle.isEmpty()) {
|
|
|
|
eventtitle = eventgroup.readEntry("Comment");
|
|
|
|
}
|
|
|
|
if (eventtitle.isEmpty()) {
|
|
|
|
eventtitle = globalgroup.readEntry("Comment");
|
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
QString eventtext = notification->text();
|
|
|
|
if (eventtext.isEmpty()) {
|
|
|
|
eventtext = eventgroup.readEntry("Name");
|
|
|
|
}
|
|
|
|
if (eventtext.isEmpty()) {
|
|
|
|
eventtext = globalgroup.readEntry("Name");
|
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
QString eventicon = notification->icon();
|
|
|
|
if (eventicon.isEmpty()) {
|
|
|
|
eventicon = eventgroup.readEntry("IconName");
|
|
|
|
}
|
|
|
|
if (eventicon.isEmpty()) {
|
|
|
|
eventicon = globalgroup.readEntry("IconName");
|
2022-09-27 09:49:21 +03:00
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
QStringList eventactions = eventgroup.readEntry("Actions", QStringList());
|
|
|
|
if (eventactions.isEmpty()) {
|
|
|
|
eventactions = globalgroup.readEntry("Actions", QStringList());
|
|
|
|
}
|
|
|
|
// qDebug() << Q_FUNC_INFO << eventactions << notification->actions();
|
|
|
|
if (eventactions.contains(QString::fromLatin1("Popup"))) {
|
|
|
|
if (!m_notificationsiface
|
|
|
|
&& KDBusConnectionPool::isServiceRegistered(s_notifications, QDBusConnection::sessionBus())) {
|
|
|
|
m_notificationsiface = new QDBusInterface(
|
|
|
|
s_notifications, "/org/freedesktop/Notifications", s_notifications,
|
|
|
|
QDBusConnection::sessionBus(), this
|
|
|
|
);
|
|
|
|
connect(m_notificationsiface, SIGNAL(NotificationClosed(uint,uint)), this, SLOT(slotNotificationClosed(uint,uint)));
|
|
|
|
connect(m_notificationsiface, SIGNAL(ActionInvoked(uint,QString)), this, SLOT(slotActionInvoked(uint,QString)));
|
|
|
|
}
|
|
|
|
const int eventtimeout = (persistent ? 0 : -1);
|
|
|
|
if (!m_notificationsiface || !m_notificationsiface->isValid()) {
|
|
|
|
kWarning(s_knotificationarea) << "notifications interface is not valid";
|
|
|
|
const QPixmap eventpixmap = KIconLoader::global()->loadIcon(eventicon, KIconLoader::Small);
|
|
|
|
KPassivePopup* kpassivepopup = new KPassivePopup(notification->widget());
|
|
|
|
kpassivepopup->setTimeout(eventtimeout);
|
|
|
|
kpassivepopup->setView(eventtitle, eventtext, eventpixmap);
|
|
|
|
kpassivepopup->setAutoDelete(true);
|
|
|
|
// NOTE: KPassivePopup positions itself depending on the windows
|
|
|
|
kpassivepopup->show();
|
|
|
|
} else {
|
2023-08-26 03:20:28 +03:00
|
|
|
const uint eventid = m_notifications.value(notification, 0);
|
2023-08-24 19:53:51 +03:00
|
|
|
// NOTE: there has to be id for each action, starting from 1
|
|
|
|
int actionscounter = 1;
|
|
|
|
QStringList eventactions;
|
|
|
|
foreach (const QString &eventaction, notification->actions()) {
|
|
|
|
eventactions.append(QString::number(actionscounter));
|
|
|
|
eventactions.append(eventaction);
|
|
|
|
actionscounter++;
|
|
|
|
}
|
|
|
|
const QString eventapp = KGlobal::mainComponent().componentName();
|
|
|
|
QVariantMap eventhints;
|
|
|
|
// NOTE: has to be set to be configurable via plasma notifications applet
|
|
|
|
eventhints.insert("x-kde-appname", eventapp);
|
|
|
|
QDBusReply<uint> notifyreply = m_notificationsiface->call(
|
|
|
|
QString::fromLatin1("Notify"),
|
|
|
|
eventapp,
|
|
|
|
eventid,
|
|
|
|
eventicon,
|
|
|
|
eventtitle,
|
|
|
|
eventtext,
|
|
|
|
eventactions,
|
|
|
|
eventhints,
|
|
|
|
eventtimeout
|
|
|
|
);
|
|
|
|
if (!notifyreply.isValid()) {
|
|
|
|
kWarning(s_knotificationarea) << "invalid notify reply" << notifyreply.error().message();
|
|
|
|
} else {
|
|
|
|
m_notifications.insert(notification, notifyreply.value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
if (eventactions.contains(QString::fromLatin1("Sound"))) {
|
|
|
|
QString eventsound = notification->icon();
|
|
|
|
if (eventsound.isEmpty()) {
|
|
|
|
eventsound = eventgroup.readEntry("Sound");
|
|
|
|
}
|
|
|
|
if (eventsound.isEmpty()) {
|
|
|
|
eventsound = globalgroup.readEntry("Sound");
|
|
|
|
}
|
2023-08-26 07:55:22 +03:00
|
|
|
const QStringList eventsoundfiles = KGlobal::dirs()->findAllResources("sound", eventsound, KStandardDirs::Recursive);
|
|
|
|
if (eventsoundfiles.isEmpty()) {
|
2023-08-24 19:53:51 +03:00
|
|
|
kWarning(s_knotificationarea) << "sound not found" << eventsound;
|
|
|
|
} else {
|
|
|
|
kDebug(s_knotificationarea) << "playing notification sound" << eventsound;
|
|
|
|
if (!m_kaudioplayeriface) {
|
|
|
|
m_kaudioplayeriface = new QDBusInterface(
|
|
|
|
"org.kde.kded", "/modules/kaudioplayer", "org.kde.kaudioplayer",
|
|
|
|
QDBusConnection::sessionBus(), this
|
|
|
|
);
|
|
|
|
}
|
2023-08-25 22:10:53 +03:00
|
|
|
// the sound player is configurable and is used by the bball plasma applet for example
|
2023-08-26 07:55:22 +03:00
|
|
|
QDBusReply<void> playreply = m_kaudioplayeriface->call(QString::fromLatin1("play"), eventsoundfiles.first());
|
2023-08-24 19:53:51 +03:00
|
|
|
if (!playreply.isValid()) {
|
|
|
|
kWarning(s_knotificationarea) << "invalid play reply" << playreply.error().message();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
if (eventactions.contains(QString::fromLatin1("Taskbar"))) {
|
|
|
|
const QWidget* eventwidget = notification->widget();
|
|
|
|
if (!eventwidget) {
|
|
|
|
kWarning(s_knotificationarea) << "taskbar event with no widget set" << eventid;
|
|
|
|
} else {
|
|
|
|
const WId eventwidgetid = eventwidget->winId();
|
|
|
|
kDebug(s_knotificationarea) << "marking notification task" << eventid << eventwidgetid;
|
|
|
|
KWindowSystem::demandAttention(eventwidgetid);
|
|
|
|
}
|
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
void KNotificationManager::close(KNotification *notification)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-08-24 19:53:51 +03:00
|
|
|
QMutableMapIterator<KNotification*,uint> iter(m_notifications);
|
|
|
|
while (iter.hasNext()) {
|
|
|
|
iter.next();
|
|
|
|
if (iter.key() == notification) {
|
|
|
|
iter.remove();
|
|
|
|
QDBusReply<void> closereply = m_notificationsiface->call(
|
|
|
|
QString::fromLatin1("CloseNotification"),
|
|
|
|
iter.value()
|
|
|
|
);
|
|
|
|
if (!closereply.isValid()) {
|
|
|
|
kWarning(s_knotificationarea) << "invalid close reply" << closereply.error().message();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
void KNotificationManager::slotNotificationClosed(uint eventid, uint reason)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-08-24 19:53:51 +03:00
|
|
|
kDebug(s_knotificationarea) << "closing notifications due to interface" << reason;
|
|
|
|
QMutableMapIterator<KNotification*,uint> iter(m_notifications);
|
|
|
|
while (iter.hasNext()) {
|
|
|
|
iter.next();
|
|
|
|
if (iter.value() == eventid) {
|
|
|
|
KNotification* notification = iter.key();
|
|
|
|
notification->close();
|
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
void KNotificationManager::slotActionInvoked(uint eventid, const QString &action)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-08-24 19:53:51 +03:00
|
|
|
kDebug(s_knotificationarea) << "notification action invoked" << action;
|
|
|
|
QMutableMapIterator<KNotification*,uint> iter(m_notifications);
|
|
|
|
while (iter.hasNext()) {
|
|
|
|
iter.next();
|
|
|
|
if (iter.value() == eventid) {
|
|
|
|
KNotification* notification = iter.key();
|
|
|
|
notification->activate(action.toUInt());
|
|
|
|
}
|
2022-09-27 09:49:21 +03:00
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
class KNotificationPrivate
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-08-24 19:53:51 +03:00
|
|
|
public:
|
|
|
|
KNotificationPrivate();
|
|
|
|
|
|
|
|
QString eventid;
|
|
|
|
QString title;
|
|
|
|
QString text;
|
|
|
|
QString icon;
|
|
|
|
QWidget *widget;
|
|
|
|
QStringList actions;
|
|
|
|
KNotification::NotificationFlags flags;
|
|
|
|
};
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
KNotificationPrivate::KNotificationPrivate()
|
|
|
|
: widget(nullptr)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
|
|
|
|
KNotification::KNotification(QObject *parent)
|
|
|
|
: QObject(parent),
|
|
|
|
d(new KNotificationPrivate())
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
KNotification::~KNotification()
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-08-24 19:53:51 +03:00
|
|
|
close();
|
|
|
|
delete d;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
QString KNotification::eventID() const
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-08-24 19:53:51 +03:00
|
|
|
return d->eventid;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
void KNotification::setEventID(const QString &eventid)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-08-24 19:53:51 +03:00
|
|
|
d->eventid = eventid;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
QString KNotification::title() const
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-08-24 19:53:51 +03:00
|
|
|
return d->title;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
void KNotification::setTitle(const QString &title)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-08-24 19:53:51 +03:00
|
|
|
d->title = title;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
QString KNotification::text() const
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-08-24 19:53:51 +03:00
|
|
|
return d->text;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
void KNotification::setText(const QString &text)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-08-24 19:53:51 +03:00
|
|
|
d->text = text;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
QString KNotification::icon() const
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-08-24 19:53:51 +03:00
|
|
|
return d->icon;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
void KNotification::setIcon(const QString &icon)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-08-24 19:53:51 +03:00
|
|
|
d->icon = icon;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
QWidget* KNotification::widget() const
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-08-24 19:53:51 +03:00
|
|
|
return d->widget;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
void KNotification::setWidget(QWidget *widget)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-08-24 19:53:51 +03:00
|
|
|
d->widget = widget;
|
|
|
|
setParent(widget);
|
|
|
|
if (widget && (d->flags & KNotification::CloseWhenWidgetActivated)) {
|
|
|
|
widget->installEventFilter(this);
|
2022-09-27 09:49:21 +03:00
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
QStringList KNotification::actions() const
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-08-24 19:53:51 +03:00
|
|
|
return d->actions;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
void KNotification::setActions(const QStringList &actions)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-08-24 19:53:51 +03:00
|
|
|
d->actions = actions;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
KNotification::NotificationFlags KNotification::flags() const
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-08-24 19:53:51 +03:00
|
|
|
return d->flags;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
void KNotification::setFlags(const NotificationFlags &flags)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-08-24 19:53:51 +03:00
|
|
|
d->flags = flags;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
void KNotification::send()
|
|
|
|
{
|
|
|
|
kDebug(s_knotificationarea) << "sending notification" << d->eventid;
|
|
|
|
const bool persistent = (flags() & KNotification::Persistent);
|
|
|
|
kNotificationManager->send(this, persistent);
|
|
|
|
if (!persistent) {
|
2023-08-26 20:41:03 +03:00
|
|
|
QTimer::singleShot(500, this, SLOT(close()));
|
2023-08-24 19:53:51 +03:00
|
|
|
}
|
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
void KNotification::activate(unsigned int action)
|
2015-09-22 10:34:04 +00:00
|
|
|
{
|
2023-08-24 19:53:51 +03:00
|
|
|
kDebug(s_knotificationarea) << "activating notification action" << d->eventid << action;
|
|
|
|
switch (action) {
|
|
|
|
case 1: {
|
|
|
|
emit action1Activated();
|
2015-09-22 10:34:04 +00:00
|
|
|
break;
|
2022-09-27 09:49:21 +03:00
|
|
|
}
|
2023-08-24 19:53:51 +03:00
|
|
|
case 2: {
|
|
|
|
emit action2Activated();
|
2015-09-22 10:34:04 +00:00
|
|
|
break;
|
2022-09-27 09:49:21 +03:00
|
|
|
}
|
2023-08-24 19:53:51 +03:00
|
|
|
case 3: {
|
|
|
|
emit action3Activated();
|
2015-09-22 10:34:04 +00:00
|
|
|
break;
|
2022-09-27 09:49:21 +03:00
|
|
|
}
|
2023-08-23 16:02:24 +03:00
|
|
|
default: {
|
2023-08-24 19:53:51 +03:00
|
|
|
kWarning(s_knotificationarea) << "invalid action" << action;
|
2015-09-22 10:34:04 +00:00
|
|
|
break;
|
2022-09-27 09:49:21 +03:00
|
|
|
}
|
2015-09-22 10:34:04 +00:00
|
|
|
}
|
2023-08-24 19:53:51 +03:00
|
|
|
close();
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
void KNotification::close()
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-08-24 19:53:51 +03:00
|
|
|
kDebug(s_knotificationarea) << "closing notification" << d->eventid;
|
|
|
|
kNotificationManager->close(this);
|
|
|
|
emit closed();
|
|
|
|
deleteLater();
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
bool KNotification::eventFilter(QObject *watched, QEvent *event)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-08-24 19:53:51 +03:00
|
|
|
if (watched == d->widget) {
|
|
|
|
if (event->type() == QEvent::WindowActivate
|
|
|
|
&& d->flags & KNotification::CloseWhenWidgetActivated) {
|
|
|
|
kDebug(s_knotificationarea) << "closing due to widget activation" << d->eventid;
|
|
|
|
QTimer::singleShot(500, this, SLOT(close()));
|
2022-09-27 10:10:44 +03:00
|
|
|
}
|
2015-09-22 10:34:04 +00:00
|
|
|
}
|
2023-08-24 19:53:51 +03:00
|
|
|
return false;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
KNotification* KNotification::event(const QString &eventid, const QString &title, const QString &text,
|
|
|
|
const QString &icon, QWidget *widget,
|
|
|
|
const NotificationFlags &flags)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-08-24 19:53:51 +03:00
|
|
|
KNotification* knotification = new KNotification(widget);
|
|
|
|
knotification->setEventID(eventid);
|
|
|
|
knotification->setTitle(title);
|
|
|
|
knotification->setText(text);
|
|
|
|
knotification->setIcon(icon);
|
|
|
|
knotification->setWidget(widget);
|
|
|
|
knotification->setFlags(flags);
|
|
|
|
QTimer::singleShot(0, knotification, SLOT(send()));
|
|
|
|
return knotification;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
void KNotification::beep(const QString &reason, QWidget *widget)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2023-08-24 19:53:51 +03:00
|
|
|
event(
|
|
|
|
QString::fromLatin1("kde/beep"), QString(), reason, QString(), widget,
|
|
|
|
KNotification::CloseOnTimeout
|
|
|
|
);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2015-02-27 07:40:26 +00:00
|
|
|
#include "moc_knotification.cpp"
|
2023-08-24 19:53:51 +03:00
|
|
|
#include "knotification.moc"
|