diff --git a/CMakeLists.txt b/CMakeLists.txt index 35a5ca7e..9903364e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -467,7 +467,6 @@ add_subdirectory( kimgio ) add_subdirectory( kinit ) add_subdirectory( kio ) add_subdirectory( kioslave ) -add_subdirectory( knotify ) add_subdirectory( kparts ) add_subdirectory( kpty ) add_subdirectory( kutils ) diff --git a/includes/CMakeLists.txt b/includes/CMakeLists.txt index c6c0439a..5b3e40a2 100644 --- a/includes/CMakeLists.txt +++ b/includes/CMakeLists.txt @@ -189,7 +189,7 @@ install( KNewPasswordDialog KNotification KNotificationRestrictions - KNotifyConfigWidget + KNotificationConfigWidget KNumInput KOpenWithDialog KPageDialog diff --git a/includes/KNotificationConfigWidget b/includes/KNotificationConfigWidget new file mode 100644 index 00000000..581ab013 --- /dev/null +++ b/includes/KNotificationConfigWidget @@ -0,0 +1 @@ +#include "../knotificationconfigwidget.h" diff --git a/includes/KNotifyConfigWidget b/includes/KNotifyConfigWidget deleted file mode 100644 index 4174ad92..00000000 --- a/includes/KNotifyConfigWidget +++ /dev/null @@ -1 +0,0 @@ -#include "../knotifyconfigwidget.h" diff --git a/kdecore/kdebug.areas b/kdecore/kdebug.areas index 0cbe46c4..9fce9f55 100644 --- a/kdecore/kdebug.areas +++ b/kdecore/kdebug.areas @@ -79,7 +79,6 @@ # kde-workspace 101 kioclient 900 kdesudo -901 knotify 1203 libkonq 1204 plasma 1207 krunner diff --git a/kdecore/kernel/kauthorization.cpp b/kdecore/kernel/kauthorization.cpp index 4f99d307..2162fb0b 100644 --- a/kdecore/kernel/kauthorization.cpp +++ b/kdecore/kernel/kauthorization.cpp @@ -17,6 +17,7 @@ */ #include "kauthorization.h" +#include "kdbusconnectionpool.h" #include "klocale.h" #include "kdebug.h" @@ -58,21 +59,6 @@ void kAuthMessageHandler(QtMsgType type, const char *msg) } } -static bool isDBusServiceRegistered(const QString &helper) -{ - QDBusConnectionInterface* dbusinterface = QDBusConnection::systemBus().interface(); - if (!dbusinterface) { - kDebug(s_kauthorizationarea) << "Null D-Bus interface" << helper; - return false; - } - QDBusReply reply = dbusinterface->isServiceRegistered(helper); - if (reply.value() == false) { - kDebug(s_kauthorizationarea) << "Service not registered" << helper; - return false; - } - return true; -} - class KAuthorizationAdaptor: public QDBusAbstractAdaptor { Q_OBJECT @@ -159,7 +145,7 @@ int KAuthorization::execute(const QString &helper, const QString &method, const { kDebug(s_kauthorizationarea) << "Executing" << helper << "method" << method; - while (isDBusServiceRegistered(helper)) { + while (KDBusConnectionPool::isServiceRegistered(helper, QDBusConnection::systemBus())) { kDebug(s_kauthorizationarea) << "Waiting for service to unregister" << helper; QCoreApplication::processEvents(QEventLoop::AllEvents, KAUTHORIZATION_TIMEOUT); QThread::msleep(KAUTHORIZATION_SLEEPTIME); diff --git a/kdecore/kernel/kdbusconnectionpool.cpp b/kdecore/kernel/kdbusconnectionpool.cpp index 0edc7271..ffd01356 100644 --- a/kdecore/kernel/kdbusconnectionpool.cpp +++ b/kdecore/kernel/kdbusconnectionpool.cpp @@ -20,10 +20,15 @@ */ #include "kdbusconnectionpool.h" +#include "kdebug.h" + #include #include +#include +#include namespace { + QAtomicInt s_connectionCounter(0); class KDBusConnectionPoolPrivate @@ -70,3 +75,18 @@ QDBusConnection KDBusConnectionPool::threadConnection() return s_perThreadConnection->connection(); } +bool KDBusConnectionPool::isServiceRegistered(const QString &service, const QDBusConnection &connection) +{ + QDBusConnectionInterface* dbusinterface = connection.interface(); + if (!dbusinterface) { + kDebug() << "Null D-Bus interface" << service; + return false; + } + QDBusReply reply = dbusinterface->isServiceRegistered(service); + if (reply.value() == false) { + kDebug() << "Service not registered" << service; + return false; + } + return true; +} + diff --git a/kdecore/kernel/kdbusconnectionpool.h b/kdecore/kernel/kdbusconnectionpool.h index 4f348daa..4e80336b 100644 --- a/kdecore/kernel/kdbusconnectionpool.h +++ b/kdecore/kernel/kdbusconnectionpool.h @@ -22,19 +22,24 @@ #define KDBUSCONNECTIONPOOL_H #include + #include namespace KDBusConnectionPool { + /** - * The KDBusConnectionPool works around the problem - * of QDBusConnection not being thread-safe. As soon as that - * has been fixed (either directly in libdbus or with a work- - * around in Qt) this method can be dropped in favor of - * QDBusConnection::sessionBus(). + * The KDBusConnectionPool works around the problem of QDBusConnection not being thread-safe. * @since 4.10.4 */ KDECORE_EXPORT QDBusConnection threadConnection(); + +/** + * Checks if service is registered on the give connection. + * @since 4.24.0 + */ +KDECORE_EXPORT bool isServiceRegistered(const QString &service, const QDBusConnection &connection); + } #endif diff --git a/kdeui/CMakeLists.txt b/kdeui/CMakeLists.txt index b7cfc6ce..effba48d 100644 --- a/kdeui/CMakeLists.txt +++ b/kdeui/CMakeLists.txt @@ -152,7 +152,7 @@ set(kdeui_LIB_SRCS kernel/ktoolinvocation.cpp kernel/ktoolinvocation_x11.cpp notifications/knotification.cpp - notifications/knotificationmanager.cpp + notifications/knotificationconfigwidget.cpp notifications/knotificationrestrictions.cpp notifications/kdbusmenuexporter.cpp notifications/kdbusmenuimporter.cpp @@ -290,9 +290,6 @@ set_source_files_properties(${kglobalaccel_component_xml} PROPERTIES INCLUDE "kg qt4_add_dbus_interface(kdeui_LIB_SRCS ${kglobalaccel_component_xml} kglobalaccel_component_interface ) install(FILES ${kglobalaccel_component_xml} DESTINATION ${KDE4_DBUS_INTERFACES_INSTALL_DIR}) -set(knotify_xml notifications/org.kde.KNotify.xml) -qt4_add_dbus_interface(kdeui_LIB_SRCS ${knotify_xml} knotify_interface) - set_source_files_properties( ${CMAKE_SOURCE_DIR}/kdeui/colors/kcolordialog.cpp ${CMAKE_SOURCE_DIR}/kdeui/kernel/kapplication.cpp @@ -460,6 +457,7 @@ install( notifications/kstatusnotifieritem.h notifications/ksystemtrayicon.h notifications/knotification.h + notifications/knotificationconfigwidget.h notifications/knotificationrestrictions.h notifications/kdbusmenuexporter.h notifications/kdbusmenuimporter.h diff --git a/kdeui/dialogs/kmessagebox.cpp b/kdeui/dialogs/kmessagebox.cpp index 438522f2..5303d111 100644 --- a/kdeui/dialogs/kmessagebox.cpp +++ b/kdeui/dialogs/kmessagebox.cpp @@ -117,16 +117,16 @@ static void sendNotification( QString message, //krazy:exclude=passbyvalue QString messageType; switch (icon) { case QMessageBox::Warning: - messageType = "messageWarning"; + messageType = "kde/messageWarning"; break; case QMessageBox::Critical: - messageType = "messageCritical"; + messageType = "kde/messageCritical"; break; case QMessageBox::Question: - messageType = "messageQuestion"; + messageType = "kde/messageQuestion"; break; default: - messageType = "messageInformation"; + messageType = "kde/messageInformation"; break; } @@ -137,8 +137,9 @@ static void sendNotification( QString message, //krazy:exclude=passbyvalue } if ( !message.isEmpty() ) { - KNotification::event( messageType, message, QPixmap(), QWidget::find( parent_id ), - KNotification::DefaultEvent | KNotification::CloseOnTimeout ); + KNotification::event( + messageType, QString(), message, QString(), QWidget::find( parent_id ) + ); } } diff --git a/kdeui/notifications/knotification.cpp b/kdeui/notifications/knotification.cpp index 844fc1c2..f47f2385 100644 --- a/kdeui/notifications/knotification.cpp +++ b/kdeui/notifications/knotification.cpp @@ -1,109 +1,293 @@ -/* This file is part of the KDE libraries - Copyright (C) 2005-2006 Olivier Goffart +/* This file is part of the KDE libraries + Copyright (C) 2023 Ivailo Monev - code from KNotify/KNotifyClient - Copyright (c) 1997 Christian Esken (esken@kde.org) - 2000 Charles Samuels (charles@kde.org) - 2000 Stefan Schimanski (1Stein@gmx.de) - 2000 Matthias Ettrich (ettrich@kde.org) - 2000 Waldo Bastian - 2000-2003 Carsten Pfeiffer - 2005 Allan Sandfeld Jensen + 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 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. - 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. + 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. */ #include "knotification.h" -#include "knotificationmanager_p.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include +#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 +#include +#include #include -#include -#include -struct KNotification::Private +// 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 { - QString eventId; - int id; - int ref; + Q_OBJECT +public: + KNotificationManager(); - QWidget *widget; + 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 m_notifications; +}; +K_GLOBAL_STATIC(KNotificationManager, kNotificationManager); + +KNotificationManager::KNotificationManager() + : m_config(KGlobal::mainComponent().componentName() + ".notifyrc", KConfig::NoGlobals), + m_notificationsiface(nullptr), + m_kaudioplayeriface(nullptr) +{ + const QStringList notifyconfigs = KGlobal::dirs()->findAllResources("config", "notifications/*.notifyrc"); + m_config.addConfigSources(notifyconfigs); +} + +void KNotificationManager::send(KNotification *notification, const bool persistent) +{ + 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"); + } + + QString eventtext = notification->text(); + if (eventtext.isEmpty()) { + eventtext = eventgroup.readEntry("Name"); + } + if (eventtext.isEmpty()) { + eventtext = globalgroup.readEntry("Name"); + } + + QString eventicon = notification->icon(); + if (eventicon.isEmpty()) { + eventicon = eventgroup.readEntry("IconName"); + } + if (eventicon.isEmpty()) { + eventicon = globalgroup.readEntry("IconName"); + } + + 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 { + const uint eventid = m_notifications.value(notification); + // 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 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()); + } + } + } + + if (eventactions.contains(QString::fromLatin1("Sound"))) { + QString eventsound = notification->icon(); + if (eventsound.isEmpty()) { + eventsound = eventgroup.readEntry("Sound"); + } + if (eventsound.isEmpty()) { + eventsound = globalgroup.readEntry("Sound"); + } + const QString eventsoundfile = KStandardDirs::locate("sound", eventsound); + if (eventsoundfile.isEmpty()) { + 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 + ); + } + // TODO: configurable player + QDBusReply playreply = m_kaudioplayeriface->call( + QString::fromLatin1("play"), eventsoundfile, QString::fromLatin1("knotification") + ); + if (!playreply.isValid()) { + kWarning(s_knotificationarea) << "invalid play reply" << playreply.error().message(); + } + } + } + + 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); + } + } +} + +void KNotificationManager::close(KNotification *notification) +{ + QMutableMapIterator iter(m_notifications); + while (iter.hasNext()) { + iter.next(); + if (iter.key() == notification) { + iter.remove(); + QDBusReply closereply = m_notificationsiface->call( + QString::fromLatin1("CloseNotification"), + iter.value() + ); + if (!closereply.isValid()) { + kWarning(s_knotificationarea) << "invalid close reply" << closereply.error().message(); + } + } + } +} + +void KNotificationManager::slotNotificationClosed(uint eventid, uint reason) +{ + kDebug(s_knotificationarea) << "closing notifications due to interface" << reason; + QMutableMapIterator iter(m_notifications); + while (iter.hasNext()) { + iter.next(); + if (iter.value() == eventid) { + KNotification* notification = iter.key(); + notification->close(); + } + } +} + +void KNotificationManager::slotActionInvoked(uint eventid, const QString &action) +{ + kDebug(s_knotificationarea) << "notification action invoked" << action; + QMutableMapIterator iter(m_notifications); + while (iter.hasNext()) { + iter.next(); + if (iter.value() == eventid) { + KNotification* notification = iter.key(); + notification->activate(action.toUInt()); + } + } +} + +class KNotificationPrivate +{ +public: + KNotificationPrivate(); + + QString eventid; QString title; QString text; + QString icon; + QWidget *widget; QStringList actions; - QPixmap pixmap; - ContextList contexts; - NotificationFlags flags; - KComponentData componentData; - - QTimer updateTimer; - bool needUpdate; - - Private() : id(0), ref(1), widget(0l), needUpdate(false) {} - /** - * recursive function that raise the widget. @p w - * - * @see raiseWidget() - */ - static void raiseWidget(QWidget *w); + KNotification::NotificationFlags flags; }; -KNotification::KNotification(const QString &eventId, QWidget *parent, const NotificationFlags &flags) - : QObject(parent), - d(new Private()) +KNotificationPrivate::KNotificationPrivate() + : widget(nullptr) { - d->eventId = eventId; - d->flags = flags; - setWidget(parent); - connect(&d->updateTimer,SIGNAL(timeout()), this, SLOT(update())); - d->updateTimer.setSingleShot(true); - d->updateTimer.setInterval(100); } -KNotification::KNotification(const QString &eventId, const NotificationFlags &flags, QObject *parent) - : QObject(parent), - d(new Private()) -{ - d->eventId = eventId; - d->flags = flags; - connect(&d->updateTimer,SIGNAL(timeout()), this, SLOT(update())); - d->updateTimer.setSingleShot(true); - d->updateTimer.setInterval(100); -} +KNotification::KNotification(QObject *parent) + : QObject(parent), + d(new KNotificationPrivate()) +{ +} KNotification::~KNotification() { - if (d->id > 0) { - KNotificationManager::self()->close(d->id); - } + close(); delete d; } -QString KNotification::eventId() const +QString KNotification::eventID() const { - return d->eventId; + return d->eventid; +} + +void KNotification::setEventID(const QString &eventid) +{ + d->eventid = eventid; } QString KNotification::title() const @@ -111,54 +295,42 @@ QString KNotification::title() const return d->title; } +void KNotification::setTitle(const QString &title) +{ + d->title = title; +} + QString KNotification::text() const { return d->text; } -QWidget *KNotification::widget() const +void KNotification::setText(const QString &text) +{ + d->text = text; +} + +QString KNotification::icon() const +{ + return d->icon; +} + +void KNotification::setIcon(const QString &icon) +{ + d->icon = icon; +} + +QWidget* KNotification::widget() const { return d->widget; } -void KNotification::setWidget(QWidget *wid) +void KNotification::setWidget(QWidget *widget) { - d->widget = wid; - setParent(wid); - if (wid && (d->flags & CloseWhenWidgetActivated)) { - wid->installEventFilter(this); - } -} - -void KNotification::setTitle(const QString &title) -{ - d->needUpdate = true; - d->title = title; - if (d->id > 0) { - d->updateTimer.start(); - } -} - -void KNotification::setText(const QString &text) -{ - d->needUpdate = true; - d->text = text; - if (d->id > 0) { - d->updateTimer.start(); - } -} - -QPixmap KNotification::pixmap() const -{ - return d->pixmap; -} - -void KNotification::setPixmap(const QPixmap &pix) -{ - d->needUpdate = true; - d->pixmap = pix; - if (d->id > 0) { - d->updateTimer.start(); + d->widget = widget; + setParent(widget); + if (widget && (d->flags & KNotification::CloseWhenWidgetActivated)) { + widget->installEventFilter(this); } } @@ -167,33 +339,9 @@ QStringList KNotification::actions() const return d->actions; } -void KNotification::setActions(const QStringList &as) +void KNotification::setActions(const QStringList &actions) { - d->needUpdate = true; - d->actions = as; - if (d->id > 0) { - d->updateTimer.start(); - } -} - -KNotification::ContextList KNotification::contexts() const -{ - return d->contexts; -} - -void KNotification::setContexts(const KNotification::ContextList &contexts) -{ - d->contexts = contexts; -} - -void KNotification::addContext(const KNotification::Context &context) -{ - d->contexts << context; -} - -void KNotification::addContext(const QString &context_key, const QString &context_value) -{ - d->contexts << qMakePair(context_key , context_value); + d->actions = actions; } KNotification::NotificationFlags KNotification::flags() const @@ -206,18 +354,20 @@ void KNotification::setFlags(const NotificationFlags &flags) d->flags = flags; } -void KNotification::setComponentData(const KComponentData &c) +void KNotification::send() { - d->componentData = c; + kDebug(s_knotificationarea) << "sending notification" << d->eventid; + const bool persistent = (flags() & KNotification::Persistent); + kNotificationManager->send(this, persistent); + if (!persistent) { + close(); + } } void KNotification::activate(unsigned int action) { + kDebug(s_knotificationarea) << "activating notification action" << d->eventid << action; switch (action) { - case 0: { - emit activated(); - break; - } case 1: { emit action1Activated(); break; @@ -230,197 +380,56 @@ void KNotification::activate(unsigned int action) emit action3Activated(); break; } + default: { + kWarning(s_knotificationarea) << "invalid action" << action; + break; + } } - emit activated(action); - if (d->id != -1) { - deleteLater(); - } - d->id = -2; + close(); } - void KNotification::close() { - if (d->id >= 0) { - KNotificationManager::self()->close(d->id); - } - if (d->id != -1) { - // still waiting for receiving the id - deleteLater(); - } - d->id = -2; + kDebug(s_knotificationarea) << "closing notification" << d->eventid; + kNotificationManager->close(this); emit closed(); -} - - -void KNotification::raiseWidget() -{ - if (!d->widget) { - return; - } - Private::raiseWidget(d->widget); -} - -//TODO this function is far from finished. -void KNotification::Private::raiseWidget(QWidget *w) -{ - if (w->isTopLevel()) { - w->raise(); - KWindowSystem::activateWindow(w->winId()); - } else { - QWidget *pw = w->parentWidget(); - raiseWidget(pw); - - if (QTabWidget *tab_widget = qobject_cast(pw)) { - tab_widget->setCurrentIndex(tab_widget->indexOf(w)); - } - } -} - -KNotification* KNotification::event(const QString &eventid , const QString &title, const QString &text, - const QPixmap &pixmap, QWidget *widget, const NotificationFlags &flags, - const KComponentData &componentData) -{ - KNotification *notify = new KNotification(eventid, widget, flags); - notify->setTitle(title); - notify->setText(text); - notify->setPixmap(pixmap); - notify->setComponentData(componentData); - QTimer::singleShot(0, notify, SLOT(sendEvent())); - return notify; -} - -KNotification* KNotification::event(const QString &eventid, const QString &text, - const QPixmap &pixmap, QWidget *widget, const NotificationFlags &flags, - const KComponentData &componentData) -{ - return event(eventid, QString(), text, pixmap, widget, flags, componentData); -} - - -KNotification* KNotification::event(StandardEvent eventid , const QString &title, const QString &text, - const QPixmap &pixmap, QWidget *widget, const NotificationFlags &flags) -{ - QString message; - switch (eventid) { - case Warning: { - message = QLatin1String("warning"); - break; - } - case Error: { - message = QLatin1String("fatalerror"); - break; - } - case Catastrophe: { - message = QLatin1String("catastrophe"); - break; - } - case Notification: // fall through - default: { - message = QLatin1String("notification"); - break; - } - } - return event(message, title, text, pixmap, widget, flags | DefaultEvent); -} - -KNotification *KNotification::event(StandardEvent eventid, const QString &text, - const QPixmap &pixmap, QWidget *widget, const NotificationFlags &flags) -{ - return event(eventid, QString(), text, pixmap, widget , flags); -} - -void KNotification::ref() -{ - d->ref++; -} - -void KNotification::deref() -{ - d->ref--; - if (d->ref == 0) { - close(); - } -} - -void KNotification::beep(const QString &reason, QWidget *widget) -{ - event(QLatin1String("beep"), reason, QPixmap(), widget, CloseOnTimeout | DefaultEvent); -} - -void KNotification::sendEvent() -{ - d->needUpdate = false; - if (d->id == 0) { - QString appname; - if (d->flags & DefaultEvent) { - appname = QLatin1String("kde"); - } else if(d->componentData.isValid()) { - appname = d->componentData.componentName(); - } else { - appname = KGlobal::mainComponent().componentName(); - } - - if (KNotificationManager::self()->notify(this, d->pixmap, d->actions, d->contexts, appname)) { - d->id = -1; - } - } else if (d->id > 0) { - KNotificationManager::self()->reemit(this, d->id); - } else if (d->id == -1) { - // schedule an update. - d->needUpdate = true; - } -} - -void KNotification::slotReceivedId(int id) -{ - if (d->id == -2) { //we are already closed - KNotificationManager::self()->close(id, /*force=*/ true); - deleteLater(); - return; - } - d->id = id; - if (d->id > 0) { - KNotificationManager::self()->insert(this, d->id); - if (d->needUpdate) { - sendEvent(); - } - } else { - //if there is no presentation, delete the object - QTimer::singleShot(0, this, SLOT(deref())); - } -} - -void KNotification::slotReceivedIdError(const QDBusError &error) -{ - if (d->id == -2) { //we are already closed - deleteLater(); - return; - } - kWarning(299) << "Error while contacting notify daemon" << error.message(); - d->id = -3; - QTimer::singleShot(0, this, SLOT(deref())); -} - - -void KNotification::update() -{ - KNotificationManager::self()->update(this, d->id); + deleteLater(); } bool KNotification::eventFilter(QObject *watched, QEvent *event) { if (watched == d->widget) { - if (event->type() == QEvent::WindowActivate) { - if (d->flags & CloseWhenWidgetActivated) { - QTimer::singleShot(500, this, SLOT(close())); - } + 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())); } - // kDebug(299) << event->type(); } - return false; } +KNotification* KNotification::event(const QString &eventid, const QString &title, const QString &text, + const QString &icon, QWidget *widget, + const NotificationFlags &flags) +{ + 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; +} + +void KNotification::beep(const QString &reason, QWidget *widget) +{ + event( + QString::fromLatin1("kde/beep"), QString(), reason, QString(), widget, + KNotification::CloseOnTimeout + ); +} #include "moc_knotification.cpp" +#include "knotification.moc" diff --git a/kdeui/notifications/knotification.h b/kdeui/notifications/knotification.h index b4dee8c1..ac10cccd 100644 --- a/kdeui/notifications/knotification.h +++ b/kdeui/notifications/knotification.h @@ -1,214 +1,73 @@ -/* This file is part of the KDE libraries - Copyright (C) 2005-2006 Olivier Goffart +/* This file is part of the KDE libraries + Copyright (C) 2023 Ivailo Monev - 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 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. + 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. + 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. */ - #ifndef KNOTIFICATION_H #define KNOTIFICATION_H #include -#include - -#include -#include -#include #include -#include +#include -/** - * KNotification is used to notify the user of an event. - * - * \section introduction - * - * There are two main kinds of notifications: - * - * @li Feedback events: - * For notifying the user that he/she just performed an operation, like maximizing a window. This - * allows to play sounds when a dialog appears. This is an instant notification. It ends - * automatically after a small timeout. - * - * @li persistent notifications: - * Notify when the user received a new message, or when something else important happened the user - * has to know about. This notification has a start and a end. It begins when the event actually - * occurs, and finishes when the message is acknowledged or read. - * - * Example of a persistent notification in an instant messaging application: - * The application emits the notification when the message is actually received, and closes it only - * when the user has read the message (when the message window has received the focus) using the - * close() slot. Persistent notifications must have the Persistent flag. - * - * By default a notification will use the application name as title, but you can also provide a - * brief text in the title and a more precise description in the body text. This is especially - * useful for notifications coming from applications which should be considered "part of the - * system", like a battery monitor or a network connection manager. For example a battery indicator - * could use "Low Battery" as a title and "Only 12 minutes left." as a body text. - * - * In order to perform a notification, you need to create a description file, which contains - * default parameters of the notification, and use KNotification::event at the place in the - * application code where the notification occurs. The returned KNotification pointer may be used - * to connect signals or slots - * - * \section file The global config file - * Your application should install a file called: - * $KDEDIR/share/appname/appname.notifyrc - * - * You can do this with the following CMake command: - * install(FILES appname.notifyrc DESTINATION ${KDE4_DATA_INSTALL_DIR}/appname)) - * - * This file contains mainly 3 parts - *
  1. \ref global "Global information"
  2. - *
  3. \ref context "Context information"
  4. - *
  5. \ref events "Definition of individual events"
- * - * \subsection global Global information - * The global part looks like that - *
-        [Global]
-        IconName=Filename
-        Comment=Friendly Name of app
-        Name=Name of app
- * 
- * The icon filename is just the name, without extension, it's found with the KIconLoader. The - * Comment field will be used in KControl to describe the application. The Name field is optional - * and may be used as the application name for popup, if Name is not present, Comment is used - * instead - * - * \subsection context Context information - * - * This part consists of hints for the configuration widget - *
-        [Context/group]
-        Name=Group name
-        Comment=The name of the group for contacts
+class KNotificationPrivate;
 
-        [Context/folder]
-        Name=Group name
- *  
- * The second part of the groupname is the context identifier. It should not contain special - * characters. The Name field is the one the user will see (and which is translated) - * - * \subsection events Definition of Events - * - * The definition of the events forms the most important part of the config file - *
-        [Event/newmail]
-        Name=New email
-        Comment=You have got a new email
-        Contexts=folder,group
-        Action=Sound|Popup
+/*!
+    Class to notify the user of an event.
 
-        [Event/contactOnline]
-        Name=Contact goes online
-        Comment=One of your contact has been connected
-        Contexts=group
-        Sound=filetoplay.ogg
-        Action=None
- *  
- * These are the default settings for each notifiable event. Action is the string representing the - * action. Actions can be added to the KNotify daemon as plugins, by deriving from KNotifyPlugin. - * At the time of writing, the following actions are available: Taskbar, Sound, Popup, Logfile - * and Execute. Actions can be combined by seperating them with '|'. - * - * Contexts is a comma separated list of possible context for this event. - * - * \section userfile The user's config file - * - * This is an implementation detail, and is described here for your information. - * - * In the config file, there are two parts: the event configuration, and the context information - * \subsection context Context information - * These are hints for the configuration dialog. They contain both the internal id of the context, - * and the user visible string. - *
-        [Context/group]
-        Values=1:Friends,2:Work,3:Family
- *  
- * \subsection event Events configuration - * This contains the configuration of events for the user. It contains the same fields as the - * description file. The key of groups is in the form - * Event/<EventName>/<ContextName>/<ContextValue> - *
-        [Event/contactOnline]
-        Action=Sound
-        Sound=/usr/share/sounds/super.ogg
+    Notification configuration file consist of main group and a group for each event, for example:
+    @code
+    [mynotification]
+    Name=My name
+    Comment=My comment
+    IconName=my-icon
 
-        [Event/contactOnline/group/1]
-        Action=Popup|Sound
- * 
- * - * \section example Example of code - * - * This portion of code will fire the event for the "contactOnline" event - * - * @code - KNotification *notification= new KNotification ("contactOnline", widget); - notification->setText(i18n("The contact %1 has gone online", contact->name()); - notification->setPixmap(contact->pixmap()); - notification->setActions(QStringList(i18n("Open chat"))); + [mynotification/myevent] + Name=My event name + Actions=Sound,Popup,Taskbar + Sound=KDE-Im-Contact-Out.ogg + @endcode - foreach(const QString &group , contact->groups()) { - notification->addContext("group", group); - } + The main configuration group ("mynotification" in this case) is used as fallback for key that + is not set in the event group ("mynotification/myevent" in this case). The "Name" key specifies + the event text while the "Comment" key specifies the event title. The "Actions" key speicifes + what the notification event will do: + @li Sound - play the sound from the "Sound" key + @li Popup - show a passive popup + @li Taskbar - mark the event widget as requiring attention - connect(notification, SIGNAL(activated(unsigned int)), contact , SLOT(slotOpenChat())); + Notification configuration files should be installed from the build system like this: + @code + install(FILES foo.notifyrc DESTINATION ${KDE4_CONFIG_INSTALL_DIR}/notifications) + @endcode - notification->sendEvent(); - * @endcode - * - * @author Olivier Goffart \ - */ + @since 4.24 + @warning the API is subject to change +*/ class KDEUI_EXPORT KNotification : public QObject { Q_OBJECT public: - /** - * Sometimes the user may want different notifications for the same event, depending the source - * of the event. Example, you want to be notified for mails that arrive in your folder - * "personal inbox" but not for those in "spam" folder - * - * A notification context is a pair of two strings. The first string is a key from what the - * context is. example "group" or "filter" (not translated). The second is the id of the - * context. In our example, the group id or the filter id in the applications. These strings - * are the ones present in the config file, and are in theory not shown in the user interface. - * - * The order of contexts in the list is is important, the most important context should be - * placed first. They are processed in that order when the notification occurs. - * - * @see event - */ - typedef QPair Context; - typedef QList< Context > ContextList; - - enum NotificationFlag - { + enum NotificationFlag { /** * The notification will be automatically closed after a timeout. (this is the default) */ CloseOnTimeout = 0x00, - /** - * When the notification is activated, raise the notification's widget. - * - * This will change the desktop, raise the window, and switch to the tab. - * @todo doesn't work yet - */ - RaiseWidgetOnActivation = 0x01, - /** * The notification will NOT be automatically closed after a timeout. You will have to * track the notification, and close it with the close function manually when the event is @@ -221,365 +80,98 @@ public: * * If the widget is already activated when the notification occurs, the notification will * be closed after a small timeout. This only works if the widget is the toplevel widget - * @todo make it work with tabulated widget */ CloseWhenWidgetActivated = 0x03, - - /** - * @internal - * The event is a standard kde event, and not an event of the application - */ - DefaultEvent= 0xF000 }; Q_DECLARE_FLAGS(NotificationFlags , NotificationFlag) - /** - * default events you can use in the event function - */ - enum StandardEvent { Notification , Warning , Error , Catastrophe }; - - /** - * Create a new notification. - * - * You have to use sendEvent to show the notification. - * - * The pointer is automatically deleted when the event is closed. - * - * Make sure you use one of the NotificationFlags CloseOnTimeOut or CloseWhenWidgetActivated, - * if not, you have to close the notification yourself. - * - * @param eventId is the name of the event - * @param widget is a widget where the notification reports to - * @param flags is a bitmask of NotificationFlag - */ - explicit KNotification(const QString &eventId , QWidget *widget = nullptr, const NotificationFlags &flags = CloseOnTimeout); - - /** - * Create a new notification. - * - * You have to use sendEvent to show the notification. - * - * The pointer is automatically deleted when the event is closed. - * - * Make sure you use one of the NotificationFlags CloseOnTimeOut or - * CloseWhenWidgetActivated, if not, - * you have to close the notification yourself. - * - * @since 4.4 - * - * @param eventId is the name of the event - * @param flags is a bitmask of NotificationFlag - * @param parent parent object - */ - explicit KNotification(const QString &eventId, const NotificationFlags &flags, QObject *parent = NULL); - + KNotification(QObject *parent = nullptr); ~KNotification(); - /** - * @brief the widget associated to the notification - * - * If the widget is destroyed, the notification will be automatically cancelled. If the widget - * is activated, the notification will be automatically closed if the NotificationFlags specify - * that - * - * When the notification is activated, the widget might be raised. Depending on the - * configuration, the taskbar entry of the window containing the widget may blink. - */ - QWidget *widget() const; - /** - * Set the widget associated to the notification. The notification is reparented to the new - * widget. - * - * \see widget() - * @param widget the new widget - */ - void setWidget(QWidget *widget); + QString eventID() const; + void setEventID(const QString &eventid); - /** - * @return the name of the event - */ - QString eventId() const; - - /** - * @return the notification title - * @see setTitle - * @since 4.3 - */ QString title() const; - /** - * Set the title of the notification popup. If no title is set, the application name will be - * used. - * - * @param title the title - * @since 4.3 - */ void setTitle(const QString &title); - /** - * @return the notification text - * @see setText - */ QString text() const; - /** - * Set the notification text that will appear in the popup. - * - * The text is shown in a QLabel, you should make sure to escape any html that is needed. You - * can use some of the Katie basic html tags. - * - * @param text the text - */ void setText(const QString &text); - /** - * \return the pixmap shown in the popup - * \see setPixmap - */ - QPixmap pixmap() const; - /** - * Set the pixmap that will be shown in the popup. - * @param pix the pixmap - */ - void setPixmap(const QPixmap &pix); + QString icon() const; + void setIcon(const QString &icon); + + QWidget *widget() const; + void setWidget(QWidget *widget); - /** - * @return the list of actions - */ QStringList actions() const; - /** - * Set the list of actions link shown in the popup. - * @param actions the list of actions - */ void setActions(const QStringList &actions); - /** - * @return the list of contexts, see KNotification::Context - */ - ContextList contexts() const; - /** - * Set the list of contexts, see KNotification::Context - * - * The list of contexts must be set before calling sendEvent; - */ - void setContexts(const ContextList &contexts); - /** - * Append a context at the list of contexts, see KNotificaiton::Context - * @param context the context which is added - */ - void addContext(const Context &context); - /** - * @overload - * @param context_key is the key of the context - * @param context_value is the value of the context - */ - void addContext(const QString &context_key, const QString &context_value); - - /** - * @return the notification flags. - */ NotificationFlags flags() const; - /** - * Set the notification flags. Should be called before sendEvent(). - */ void setFlags(const NotificationFlags &flags); /** - * The componentData is used to determine the location of the config file. By default, kapp is - * used - * @param componentData the new componentData + * Convenience method - creates KNotification, sets it up and automatically sends the event. + * + * @warning Do not use this method if additional setup, such as signals connection, is + * required. */ - void setComponentData(const KComponentData &componentData); + static KNotification* event(const QString &eventid, + const QString &title = QString(), const QString &text = QString(), + const QString &icon = QString(), QWidget *widget = nullptr, + const NotificationFlags &flags = CloseOnTimeout); + + /** + * This is a simple substitution for QApplication::beep(). + */ + static void beep(const QString &reason = QString(), QWidget *widget = nullptr); + + // prevent warning + using QObject::event; + +public Q_SLOTS: + /** + * Sends the event. + */ + void send(); + + /** + * Activate the specified @p action. + */ + void activate(unsigned int action); + /** + * Closes the notification and deletes it. + */ + void close(); Q_SIGNALS: /** - * Emit only when the default activation has occurred - */ - void activated(); - /** - * Emit when an action has been activated. - * @param action will be 0 is the default aciton was activated, or any action id - */ - void activated(unsigned int action); - /** - * Convenience signal that is emitted when the first action is activated. + * Signal that the first action is activated. */ void action1Activated(); /** - * \overload + * Signal that the second action is activated. */ void action2Activated(); /** - * \overload + * Signal that the third action is activated. */ void action3Activated(); /** - * Emitted when the notification is closed. Both when it is activated or if it is just ignored. + * Signals that the notification is closed. */ void closed(); - /** - * The notification has been ignored - */ - void ignored(); - -public Q_SLOTS: - /** - * @brief Activate the action specified action - * If the action is zero, then the default action is activated - */ - void activate(unsigned int action = 0); - - /** - * Close the notification without activating it. - * - * This will delete the notification. - */ - void close(); - - /** - * @brief Raise the widget. - * This will change the desktop, activate the window, and the tab if needed. - */ - void raiseWidget(); - - /** - * The notification will automatically be closed if all presentations are finished. if you want - * to show your own presentation in your application, you should use this function, so it will - * not be automatically closed when there is nothing to show. - * - * Don't forgot to deref, or the notification may be never closed if there is no timeout. - * @see ref - */ - void ref(); - /** - * remove a reference made with ref() - * the notification may be closed when calling this. - * @see ref - */ - void deref(); - - /** - * Emit or re-emit the event. - */ - void sendEvent(); - - /** - * @internal - * update the texts, the icon, and the actions of one existing notification - */ - void update(); - -private Q_SLOTS: - void slotReceivedId(int); - void slotReceivedIdError(const QDBusError &); - -private: - struct Private; - Private *const d; - protected: /** * reimplemented for internal reasons */ virtual bool eventFilter(QObject *watched, QEvent *event); -public: - /** - * @brief emit an event - * - * This method creates the KNotification, setting every parameter, and fire the event. You - * don't need to call sendEvent - * - * A popup may be displayed or a sound may be played, depending the config. - * - * @return a KNotification. You may use that pointer to connect some signals or slot. The - * pointer is automatically deleted when the event is closed. - * - * Make sure you use one of the CloseOnTimeOut or CloseWhenWidgetActivated, if not, you have - * to close yourself the notification. - * - * @note the text is shown in a QLabel, you should escape HTML, if needed. - * - * @param eventId is the name of the event - * @param title is title of the notification to show in the popup. - * @param text is the text of the notification to show in the popup. - * @param pixmap is a picture which may be shown in the popup. - * @param widget is a widget where the notification reports to - * @param flags is a bitmask of NotificationFlag - * @param componentData used to determine the location of the config file. by default, kapp is used - * @since 4.4 - */ - static KNotification* event(const QString &eventId, const QString &title, const QString &text, - const QPixmap &pixmap = QPixmap(), QWidget *widget = nullptr, - const NotificationFlags &flags = CloseOnTimeout, - const KComponentData &componentData = KComponentData()); - - /** - * @brief emit a standard event - * - * @overload - * - * This will emit a standard event - * - * @param eventId is the name of the event - * @param text is the text of the notification to show in the popup. - * @param pixmap is a picture which may be shown in the popup. - * @param widget is a widget where the notification reports to - * @param flags is a bitmask of NotificationFlag - * @param componentData used to determine the location of the config file. by default, kapp is used - */ - static KNotification* event(const QString &eventId, const QString &text = QString(), - const QPixmap &pixmap = QPixmap(), QWidget *widget = nullptr, - const NotificationFlags &flags = CloseOnTimeout, - const KComponentData &componentData = KComponentData()); - - /** - * @brief emit a standard event - * - * @overload - * - * This will emit a standard event - * - * @param eventId is the name of the event - * @param text is the text of the notification to show in the popup - * @param pixmap is a picture which may be shown in the popup - * @param widget is a widget where the notification reports to - * @param flags is a bitmask of NotificationFlag - */ - static KNotification* event(StandardEvent eventId, const QString &text = QString(), - const QPixmap &pixmap = QPixmap(), QWidget *widget = nullptr, - const NotificationFlags &flags = CloseOnTimeout); - - /** - * @brief emit a standard event - * - * @overload - * - * This will emit a standard event - * - * @param eventId is the name of the event - * @param title is title of the notification to show in the popup. - * @param text is the text of the notification to show in the popup - * @param pixmap is a picture which may be shown in the popup - * @param widget is a widget where the notification reports to - * @param flags is a bitmask of NotificationFlag - * @since 4.4 - */ - static KNotification* event(StandardEvent eventId, const QString &title, const QString &text, - const QPixmap &pixmap = QPixmap(), QWidget *widget = nullptr, - const NotificationFlags &flags = CloseOnTimeout); - - /** - * This is a simple substitution for QApplication::beep() - * - * @param reason a short text explaining what has happened (may be empty) - * @param widget the widget the notification refers to - */ - static void beep(const QString &reason = QString() , QWidget *widget = nullptr); - - // prevent warning - using QObject::event; +private: + Q_DISABLE_COPY(KNotification); + KNotificationPrivate *d; }; Q_DECLARE_OPERATORS_FOR_FLAGS(KNotification::NotificationFlags) diff --git a/kdeui/notifications/knotificationconfigwidget.cpp b/kdeui/notifications/knotificationconfigwidget.cpp new file mode 100644 index 00000000..24586f80 --- /dev/null +++ b/kdeui/notifications/knotificationconfigwidget.cpp @@ -0,0 +1,60 @@ +/* This file is part of the KDE libraries + Copyright (C) 2023 Ivailo Monev + + 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. +*/ + +#include "knotificationconfigwidget.h" +#include "kdialog.h" +#include "klocale.h" + +class KNotificationConfigWidgetPrivate +{ +public: + KNotificationConfigWidgetPrivate(); +}; + +KNotificationConfigWidgetPrivate::KNotificationConfigWidgetPrivate() +{ +} + +KNotificationConfigWidget::KNotificationConfigWidget(const QString &app, QWidget *parent) + : QWidget(parent), + d(new KNotificationConfigWidgetPrivate()) +{ + // TODO: +} + +KNotificationConfigWidget::~KNotificationConfigWidget() +{ + delete d; +} + +void KNotificationConfigWidget::configure(const QString &app, QWidget *parent) +{ + KDialog *dialog = new KDialog(parent); + dialog->setCaption(i18n("Configure Notifications")); + KNotificationConfigWidget *widget = new KNotificationConfigWidget(app, dialog); + dialog->setMainWidget(widget); + + connect(dialog, SIGNAL(applyClicked()), widget, SLOT(save())); + connect(dialog, SIGNAL(okClicked()), widget, SLOT(save())); + connect(widget, SIGNAL(changed(bool)), dialog , SLOT(enableButtonApply(bool))); + + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); +} + +#include "moc_knotificationconfigwidget.cpp" diff --git a/kdeui/notifications/knotificationconfigwidget.h b/kdeui/notifications/knotificationconfigwidget.h new file mode 100644 index 00000000..6e48d8a2 --- /dev/null +++ b/kdeui/notifications/knotificationconfigwidget.h @@ -0,0 +1,48 @@ +/* This file is part of the KDE libraries + Copyright (C) 2023 Ivailo Monev + + 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. +*/ + +#ifndef KNOTIFICATIONCONFIGWIDGET_H +#define KNOTIFICATIONCONFIGWIDGET_H + +#include + +#include + +class KNotificationConfigWidgetPrivate; + +/*! + Class to configure user notification events. + + @since 4.24 + @warning the API is subject to change +*/ +class KDEUI_EXPORT KNotificationConfigWidget : public QWidget +{ + Q_OBJECT +public: + KNotificationConfigWidget(const QString &app, QWidget *parent = nullptr); + ~KNotificationConfigWidget(); + + static void configure(const QString &app, QWidget *parent = nullptr); + +private: + Q_DISABLE_COPY(KNotificationConfigWidget); + KNotificationConfigWidgetPrivate *d; +}; + +#endif // KNOTIFICATIONCONFIGWIDGET_H diff --git a/kdeui/notifications/knotificationmanager.cpp b/kdeui/notifications/knotificationmanager.cpp deleted file mode 100644 index f6b7baf9..00000000 --- a/kdeui/notifications/knotificationmanager.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2005 Olivier Goffart - - 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. -*/ - -#include -#include -#include - -#include "knotificationmanager_p.h" -#include -#include "knotification.h" -#include -#include -#include -#include -#include - -static const QByteArray imageFormat = QImageWriter::defaultImageFormat(); - -KNotificationManager * KNotificationManager::self() -{ - K_GLOBAL_STATIC(KNotificationManager, s_self) - return s_self; -} - -KNotificationManager::KNotificationManager() -{ - QDBusConnectionInterface* sessionIface = QDBusConnection::sessionBus().interface(); - if (!sessionIface->isServiceRegistered("org.kde.knotify")) { - QDBusReply sessionReply = sessionIface->startService("org.kde.knotify"); - if (!sessionReply.isValid()) { - kError() << "Couldn't start knotify service" << sessionReply.error(); - } - } - - m_knotify = new org::kde::KNotify( - QLatin1String("org.kde.knotify"), QLatin1String("/Notify"), QDBusConnection::sessionBus(), this - ); - - connect( - m_knotify, SIGNAL(notificationClosed(int)), - this, SLOT(notificationClosed(int)) - ); - connect( - m_knotify, SIGNAL(notificationActivated(int,int)), - this, SLOT(notificationActivated(int,int)) - ); -} - - -KNotificationManager::~KNotificationManager() -{ - delete m_knotify; -} - -void KNotificationManager::notificationActivated(int id, int action) -{ - if (m_notifications.contains(id)) { - kDebug(299) << id << " " << action; - KNotification *n = m_notifications[id]; - m_notifications.remove(id); - n->activate( action ); - } -} - -void KNotificationManager::notificationClosed(int id) -{ - if (m_notifications.contains(id)) { - kDebug(299) << id; - KNotification *n = m_notifications[id]; - m_notifications.remove(id); - n->close(); - } -} - - -void KNotificationManager::close(int id, bool force) -{ - if (force || m_notifications.contains(id)) { - m_notifications.remove(id); - kDebug(299) << id; - m_knotify->closeNotification(id); - } -} - -bool KNotificationManager::notify(KNotification* n, const QPixmap &pix, - const QStringList &actions, - const KNotification::ContextList & contexts, - const QString &appname) -{ - WId winId = n->widget() ? n->widget()->window()->winId() : 0; - - QByteArray pixmapData; - QBuffer buffer(&pixmapData); - buffer.open(QIODevice::WriteOnly); - pix.save(&buffer, imageFormat); - - QVariantList contextList; - foreach (const KNotification::Context &ctx, contexts) { - QVariantList vl; - vl << ctx.first << ctx.second; - contextList << vl; - } - - // Persistent => 0 == infinite timeout - // CloseOnTimeout => -1 == let the server decide - int timeout = (n->flags() & KNotification::Persistent) ? 0 : -1; - - QList args; - args << n->eventId() << (appname.isEmpty() ? KGlobal::mainComponent().componentName() : appname); - args.append(QVariant(contextList)); - args << n->title() << n->text() << pixmapData << QVariant(actions) << timeout << qlonglong(winId) ; - return m_knotify->callWithCallback("event", args, n, SLOT(slotReceivedId(int)), SLOT(slotReceivedIdError(QDBusError))); -} - -void KNotificationManager::insert(KNotification *n, int id) -{ - m_notifications.insert(id, n); -} - -void KNotificationManager::update(KNotification * n, int id) -{ - if (id <= 0) { - return; - } - - QByteArray pixmapData; - if (!n->pixmap().isNull()) { - QBuffer buffer(&pixmapData); - buffer.open(QIODevice::WriteOnly); - n->pixmap().save(&buffer, imageFormat); - } - - m_knotify->update(id, n->title(), n->text(), pixmapData , n->actions() ); -} - -void KNotificationManager::reemit(KNotification * n, int id) -{ - QVariantList contextList; - foreach (const KNotification::Context &ctx, n->contexts()) { - // kDebug(299) << "add context " << ctx.first << "-" << ctx.second; - QVariantList vl; - vl << ctx.first << ctx.second; - contextList << vl; - } - - m_knotify->reemit(id, contextList); -} - - -#include "moc_knotificationmanager_p.cpp" diff --git a/kdeui/notifications/knotificationmanager_p.h b/kdeui/notifications/knotificationmanager_p.h deleted file mode 100644 index 3d98759c..00000000 --- a/kdeui/notifications/knotificationmanager_p.h +++ /dev/null @@ -1,80 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2005 Olivier Goffart - Copyright (C) 2006 Thiago Macieira - - 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. -*/ - -#ifndef KNOTIFICATIONMANAGER_H -#define KNOTIFICATIONMANAGER_H - -#include -#include "knotify_interface.h" - -#include -#include - -/** - * @internal - * @author Olivier Goffart - */ -class KNotificationManager : public QObject -{ - Q_OBJECT -public: - static KNotificationManager* self(); - ~KNotificationManager(); - - /** - * send the dbus call to the knotify server - */ - bool notify(KNotification *n, const QPixmap &pix, const QStringList &action, - const KNotification::ContextList &contexts, const QString &appname); - - /** - * send the close dcop call to the knotify server for the notification with the identifier @p id . - * And remove the notification from the internal map - * @param id the id of the notification - * @param force if false, only close registered notification - */ - void close(int id, bool force = false); - - /** - * Insert the notification and its id in the internal map - */ - void insert(KNotification *n, int id); - - /** - * update one notification text and pixmap and actions - */ - void update(KNotification *n, int id); - - /** - * re-emit the notification, eventually with new contexts - */ - void reemit(KNotification *n, int id); - -private Q_SLOTS: - void notificationClosed(int id); - void notificationActivated(int id, int action); - -private: - KNotificationManager(); - - QHash m_notifications; - org::kde::KNotify *m_knotify; -}; - -#endif // KNOTIFICATIONMANAGER_H diff --git a/kdeui/notifications/org.kde.KNotify.xml b/kdeui/notifications/org.kde.KNotify.xml deleted file mode 100644 index 62d6d41b..00000000 --- a/kdeui/notifications/org.kde.KNotify.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/kdeui/util/kcompletion.cpp b/kdeui/util/kcompletion.cpp index ddb38ce7..33def8b8 100644 --- a/kdeui/util/kcompletion.cpp +++ b/kdeui/util/kcompletion.cpp @@ -688,19 +688,19 @@ void KCompletion::doBeep( BeepMode mode ) const switch ( mode ) { case Rotation: - event = QLatin1String("Textcompletion: rotation"); + event = QLatin1String("kde/TextcompletionRotation"); text = i18n("You reached the end of the list\nof matching items.\n"); break; case PartialMatch: if ( d->myCompletionMode == KGlobalSettings::CompletionShell || d->myCompletionMode == KGlobalSettings::CompletionMan ) { - event = QLatin1String("Textcompletion: partial match"); + event = QLatin1String("kde/TextcompletionPartialMatch"); text = i18n("The completion is ambiguous, more than one\nmatch is available.\n"); } break; case NoMatch: if ( d->myCompletionMode == KGlobalSettings::CompletionShell ) { - event = QLatin1String("Textcompletion: no match"); + event = QLatin1String("kde/TextcompletionNoMatch"); text = i18n("There is no matching item available.\n"); } break; @@ -708,7 +708,7 @@ void KCompletion::doBeep( BeepMode mode ) const if ( !text.isEmpty() ) { - KNotification::event( event, text , QPixmap() , 0L , KNotification::DefaultEvent ); + KNotification::event( event, QString(), text ); } } diff --git a/kdeui/util/kcompletion.h b/kdeui/util/kcompletion.h index 3f984104..6338818f 100644 --- a/kdeui/util/kcompletion.h +++ b/kdeui/util/kcompletion.h @@ -353,7 +353,7 @@ public: * @li nextMatch() or previousMatch() hit the last possible * match -> rotation * - * For playing the sounds, KNotifyClient() is used. + * For playing the sounds, KNotification is used. * * @param enable true to enable sounds * @see soundsEnabled diff --git a/kdeui/util/kpassivepopup.cpp b/kdeui/util/kpassivepopup.cpp index a5d561d9..4dd336b0 100644 --- a/kdeui/util/kpassivepopup.cpp +++ b/kdeui/util/kpassivepopup.cpp @@ -36,7 +36,6 @@ #include #include #include -#include #include #include @@ -519,25 +518,6 @@ KPassivePopup *KPassivePopup::message(const QString &caption, const QString &tex return message(DEFAULT_POPUP_TYPE, caption, text, icon, parent, timeout); } -KPassivePopup *KPassivePopup::message(const QString &caption, const QString &text, - const QPixmap &icon, - QSystemTrayIcon *parent, int timeout) -{ - return message(DEFAULT_POPUP_TYPE, caption, text, icon, parent, timeout); -} - -KPassivePopup *KPassivePopup::message(const QString &text, QSystemTrayIcon *parent) -{ - return message(DEFAULT_POPUP_TYPE, QString(), text, QPixmap(), parent); -} - -KPassivePopup *KPassivePopup::message(const QString &caption, const QString &text, - QSystemTrayIcon *parent) -{ - return message(DEFAULT_POPUP_TYPE, caption, text, QPixmap(), parent); -} - - KPassivePopup *KPassivePopup::message(int popupStyle, const QString &caption, const QString &text, const QPixmap &icon, QWidget *parent, int timeout) @@ -574,30 +554,4 @@ KPassivePopup *KPassivePopup::message(int popupStyle, const QString &caption, co return pop; } -KPassivePopup *KPassivePopup::message(int popupStyle, const QString &caption, const QString &text, - const QPixmap &icon, - QSystemTrayIcon *parent, int timeout) -{ - KPassivePopup *pop = new KPassivePopup(); - pop->setPopupStyle(popupStyle); - pop->setAutoDelete(true); - pop->setView(caption, text, icon); - pop->d->hideDelay = timeout; - QPoint pos = pop->calculateNearbyPoint(parent->geometry()); - pop->show(pos); - pop->moveNear(parent->geometry()); - return pop; -} - -KPassivePopup *KPassivePopup::message(int popupStyle, const QString &text, QSystemTrayIcon *parent) -{ - return message(popupStyle, QString(), text, QPixmap(), parent); -} - -KPassivePopup *KPassivePopup::message(int popupStyle, const QString &caption, const QString &text, - QSystemTrayIcon *parent) -{ - return message(popupStyle, caption, text, QPixmap(), parent); -} - #include "moc_kpassivepopup.cpp" diff --git a/kdeui/util/kpassivepopup.h b/kdeui/util/kpassivepopup.h index c990d11e..312f43c6 100644 --- a/kdeui/util/kpassivepopup.h +++ b/kdeui/util/kpassivepopup.h @@ -23,7 +23,6 @@ #include #include -#include class KVBox; @@ -201,14 +200,6 @@ public: */ static KPassivePopup* message(const QString &text, QWidget *parent); - /** - * Convenience method that displays popup with the specified message beside the - * icon of the specified QSystemTrayIcon. - * Note that the returned object is destroyed when it is hidden. - * @see setAutoDelete - */ - static KPassivePopup* message(const QString &text, QSystemTrayIcon *parent); - /** * Convenience method that displays popup with the specified caption and message * beside the icon of the specified widget. @@ -218,15 +209,6 @@ public: static KPassivePopup* message(const QString &caption, const QString &text, QWidget *parent); - /** - * Convenience method that displays popup with the specified caption and message - * beside the icon of the specified QSystemTrayIcon. - * Note that the returned object is destroyed when it is hidden. - * @see setAutoDelete - */ - static KPassivePopup* message(const QString &caption, const QString &text, - QSystemTrayIcon *parent); - /** * Convenience method that displays popup with the specified icon, caption and * message beside the icon of the specified widget. @@ -237,16 +219,6 @@ public: const QPixmap &icon, QWidget *parent, int timeout = -1); - /** - * Convenience method that displays popup with the specified icon, caption and - * message beside the icon of the specified QSystemTrayIcon. - * Note that the returned object is destroyed when it is hidden. - * @see setAutoDelete - */ - static KPassivePopup* message(const QString &caption, const QString &text, - const QPixmap &icon, - QSystemTrayIcon *parent, int timeout = -1); - /** * Convenience method that displays popup with the specified icon, caption and * message beside the icon of the specified window. @@ -265,23 +237,6 @@ public: */ static KPassivePopup* message(int popupStyle, const QString &text, QWidget *parent); - /** - * Convenience method that displays popup with the specified popup-style and message beside the - * icon of the specified QSystemTrayIcon. - * Note that the returned object is destroyed when it is hidden. - * @see setAutoDelete - */ - static KPassivePopup* message(int popupStyle, const QString &text, QSystemTrayIcon *parent); - - /** - * Convenience method that displays popup with the specified popup-style, caption and message - * beside the icon of the specified QSystemTrayIcon. - * Note that the returned object is destroyed when it is hidden. - * @see setAutoDelete - */ - static KPassivePopup* message(int popupStyle, const QString &caption, const QString &text, - QSystemTrayIcon *parent); - /** * Convenience method that displays popup with the specified popup-style, caption and message * beside the icon of the specified widget. @@ -301,16 +256,6 @@ public: const QPixmap &icon, QWidget *parent, int timeout = -1); - /** - * Convenience method that displays popup with the specified popup-style, icon, caption and - * message beside the icon of the specified QSystemTrayIcon. - * Note that the returned object is destroyed when it is hidden. - * @see setAutoDelete - */ - static KPassivePopup* message(int popupStyle, const QString &caption, const QString &text, - const QPixmap &icon, - QSystemTrayIcon *parent, int timeout = -1); - /** * Convenience method that displays popup with the specified popup-style, icon, caption and * message beside the icon of the specified window. diff --git a/kdeui/widgets/khistorycombobox.cpp b/kdeui/widgets/khistorycombobox.cpp index 1473b3f0..c2e157a3 100644 --- a/kdeui/widgets/khistorycombobox.cpp +++ b/kdeui/widgets/khistorycombobox.cpp @@ -320,9 +320,8 @@ void KHistoryComboBox::rotateDown() } else { // bottom of history if ( d->myIterateIndex == -2 ) { - KNotification::event( "Textcompletion: No Match" , - i18n("No further items in the history."), - QPixmap() , this, KNotification::DefaultEvent); + KNotification::event( "kde/TextcompletionNoMatch" , QString(), + i18n("No further items in the history.")); } d->myIterateIndex = -1; diff --git a/kdeui/windowmanagement/kwindowsystem.h b/kdeui/windowmanagement/kwindowsystem.h index 52714460..035ab4df 100644 --- a/kdeui/windowmanagement/kwindowsystem.h +++ b/kdeui/windowmanagement/kwindowsystem.h @@ -164,8 +164,6 @@ public: * of activating the window, which could be obtrusive, the window * will be marked specially as demanding user's attention. * See also explanation in description of activateWindow(). - * - * Note that it's usually better to use KNotifyClient. */ static void demandAttention( WId win, bool set = true ); diff --git a/kfile/kfileplacesview.cpp b/kfile/kfileplacesview.cpp index 15323286..40985391 100644 --- a/kfile/kfileplacesview.cpp +++ b/kfile/kfileplacesview.cpp @@ -649,7 +649,7 @@ void KFilePlacesView::contextMenuEvent(QContextMenuEvent *event) QDataStream stream(&packedArgs, QIODevice::WriteOnly); stream << int(1); KIO::Job *job = KIO::special(KUrl("trash:/"), packedArgs); - KNotification::event("Trash: emptied", QString() , QPixmap() , 0, KNotification::DefaultEvent); + KNotification::event("kde/TrashEmptied"); job->ui()->setWindow(parentWidget()); connect(job, SIGNAL(result(KJob*)), SLOT(_k_trashUpdated(KJob*))); } diff --git a/knotify/CMakeLists.txt b/knotify/CMakeLists.txt deleted file mode 100644 index 63c9f63d..00000000 --- a/knotify/CMakeLists.txt +++ /dev/null @@ -1,47 +0,0 @@ -project(knotify) - -include_directories( - ${KDE4_KIO_INCLUDES} - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_BINARY_DIR} -) - -########### next target ############### - -set(knotifyconfig_LIB_SRCS - knotifyconfigactionswidget.cpp - knotifyconfigelement.cpp - knotifyeventlist.cpp - knotifyconfigwidget.cpp -) - -add_library(knotifyconfig SHARED ${knotifyconfig_LIB_SRCS}) - -# Needs KIO for KUrlRequester -target_link_libraries(knotifyconfig PUBLIC - ${QT_QTGUI_LIBRARY} - ${QT_QTDBUS_LIBRARY} - kdecore - kio -) - -set_target_properties(knotifyconfig PROPERTIES - VERSION ${GENERIC_LIB_VERSION} - SOVERSION ${GENERIC_LIB_SOVERSION} -) -install( - TARGETS knotifyconfig - EXPORT kdelibsTargets - DESTINATION ${KDE4_LIB_INSTALL_DIR} -) - -########### install files ############### - -generate_export_header(knotifyconfig) - -install( - FILES - ${CMAKE_CURRENT_BINARY_DIR}/knotifyconfig_export.h - knotifyconfigwidget.h - DESTINATION ${KDE4_INCLUDE_INSTALL_DIR} -) diff --git a/knotify/knotifyconfigactionswidget.cpp b/knotify/knotifyconfigactionswidget.cpp deleted file mode 100644 index d704efc1..00000000 --- a/knotify/knotifyconfigactionswidget.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2005-2007 Olivier Goffart - - 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. -*/ -#include "knotifyconfigactionswidget.h" -#include "knotifyconfigelement.h" - -#include - -#include -#include - -KNotifyConfigActionsWidget::KNotifyConfigActionsWidget( QWidget * parent ) - : QWidget(parent) -{ - m_ui.setupUi(this); - - //Show sounds directory by default - QStringList soundDirs = KGlobal::dirs()->resourceDirs( "sound" ); - if ( !soundDirs.isEmpty() ) - m_ui.Sound_select->setStartDir( KUrl( soundDirs.last() ) ); - - m_ui.Sound_play->setIcon(KIcon("media-playback-start")); - m_ui.Sound_check->setIcon(KIcon("media-playback-start")); - m_ui.Popup_check->setIcon(KIcon("dialog-information")); - m_ui.Logfile_check->setIcon(KIcon("text-x-generic")); - m_ui.Execute_check->setIcon(KIcon("system-run")); - m_ui.Taskbar_check->setIcon(KIcon("services")); - - connect(m_ui.Execute_check,SIGNAL(toggled(bool)), this, SIGNAL(changed())); - connect(m_ui.Sound_check,SIGNAL(toggled(bool)), this, SIGNAL(changed())); - connect(m_ui.Popup_check,SIGNAL(toggled(bool)), this, SIGNAL(changed())); - connect(m_ui.Logfile_check,SIGNAL(toggled(bool)), this, SIGNAL(changed())); - connect(m_ui.Taskbar_check,SIGNAL(toggled(bool)), this, SIGNAL(changed())); - connect(m_ui.Execute_select,SIGNAL(textChanged(QString)), this, SIGNAL(changed())); - connect(m_ui.Sound_select,SIGNAL(textChanged(QString)), this, SIGNAL(changed())); - connect(m_ui.Logfile_select,SIGNAL(textChanged(QString)), this, SIGNAL(changed())); - connect(m_ui.Sound_play,SIGNAL(clicked()), this, SLOT(slotPlay())); - -} - -KNotifyConfigActionsWidget::~KNotifyConfigActionsWidget() -{ -} - -void KNotifyConfigActionsWidget::setConfigElement( KNotifyConfigElement * config ) -{ - bool blocked = blockSignals(true); //to block the changed() signal - QString prstring=config->readEntry( "Action" ); - QStringList actions=prstring.split ('|'); - - m_ui.Sound_check->setChecked( actions.contains("Sound") ); - m_ui.Popup_check->setChecked( actions.contains("Popup") ); - m_ui.Logfile_check->setChecked( actions.contains("Logfile") ); - m_ui.Execute_check->setChecked( actions.contains("Execute") ); - m_ui.Taskbar_check->setChecked( actions.contains("Taskbar") ); - - m_ui.Sound_select->setUrl( KUrl( config->readEntry( "Sound" , true ) ) ); - m_ui.Logfile_select->setUrl( KUrl( config->readEntry( "Logfile" , true ) ) ); - m_ui.Execute_select->setUrl( KUrl( config->readEntry( "Execute" ) ) ); - blockSignals(blocked); -} - -void KNotifyConfigActionsWidget::save( KNotifyConfigElement * config ) -{ - QStringList actions; - if(m_ui.Sound_check->isChecked()) - actions << "Sound"; - if(m_ui.Popup_check->isChecked()) - actions << "Popup"; - if(m_ui.Logfile_check->isChecked()) - actions << "Logfile"; - if(m_ui.Execute_check->isChecked()) - actions << "Execute"; - if(m_ui.Taskbar_check->isChecked()) - actions << "Taskbar"; - - config->writeEntry( "Action" , actions.join("|") ); - - config->writeEntry( "Sound" , m_ui.Sound_select->url().url() ); - config->writeEntry( "Logfile" , m_ui.Logfile_select->url().url() ); - config->writeEntry( "Execute" , m_ui.Execute_select->url().path() ); -} - -void KNotifyConfigActionsWidget::slotPlay( ) -{ - KUrl soundURL = m_ui.Sound_select->url(); - if ( soundURL.isRelative() ) - { - QString soundString = soundURL.toLocalFile(); - // we need a way to get the application name in order to ba able to do this : - /*QString search = QString("%1/sounds/%2").arg(config->appname).arg(soundFile); - search = KGlobal::mainComponent().dirs()->findResource("data", search); - if ( search.isEmpty() )*/ - soundURL = KUrl::fromPath( KStandardDirs::locate( "sound", soundString ) ); - } - // same ID as the one used in kde-workspace/knotify/notifybysound.cpp - QDBusInterface kaudioplayer("org.kde.kded", "/modules/kaudioplayer", "org.kde.kaudioplayer"); - kaudioplayer.call("play", soundURL.prettyUrl(), QString::fromLatin1("knotify")); -} - -#include "moc_knotifyconfigactionswidget.cpp" diff --git a/knotify/knotifyconfigactionswidget.h b/knotify/knotifyconfigactionswidget.h deleted file mode 100644 index 7f38f20e..00000000 --- a/knotify/knotifyconfigactionswidget.h +++ /dev/null @@ -1,51 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2005-2007 by Olivier Goffart - - 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. - - */ - -#ifndef KNOTIFYCONFIGACTIONSWIDGET_H -#define KNOTIFYCONFIGACTIONSWIDGET_H - -#include - -#include "ui_knotifyconfigactionswidgetbase.h" - -class KNotifyConfigElement; - -/** - * Represent the config for an event - * @internal - * @author Olivier Goffart - */ -class KNotifyConfigActionsWidget : public QWidget -{ - Q_OBJECT - public: - KNotifyConfigActionsWidget( QWidget *parent); - ~KNotifyConfigActionsWidget(); - - void setConfigElement( KNotifyConfigElement *config ); - void save( KNotifyConfigElement *config ); - Q_SIGNALS: - void changed(); - private Q_SLOTS: - void slotPlay(); - private: - Ui::KNotifyConfigActionsWidgetBase m_ui; -}; - -#endif // KNOTIFYCONFIGACTIONSWIDGET_H diff --git a/knotify/knotifyconfigactionswidgetbase.ui b/knotify/knotifyconfigactionswidgetbase.ui deleted file mode 100644 index 514ea042..00000000 --- a/knotify/knotifyconfigactionswidgetbase.ui +++ /dev/null @@ -1,184 +0,0 @@ - - KNotifyConfigActionsWidgetBase - - - - 0 - 0 - 433 - 190 - - - - - - - Play a &sound - - - - - - - false - - - - - - - - - - false - - - - 0 - 0 - - - - Select the sound to play - - - - - - - Show a message in a &popup - - - - - - - Log to a file - - - - - - - false - - - - 0 - 0 - - - - - - - - Mark &taskbar entry - - - - - - - Run &command - - - - - - - false - - - - 0 - 0 - - - - Select the command to run - - - - - - - - KUrlRequester - QFrame -
kurlrequester.h
- 1 -
- - KComboBox - QComboBox -
kcombobox.h
-
-
- - - Sound_check - toggled(bool) - Sound_play - setEnabled(bool) - - - 59 - 23 - - - 118 - 20 - - - - - Sound_check - toggled(bool) - Sound_select - setEnabled(bool) - - - 18 - 16 - - - 254 - 8 - - - - - Logfile_check - toggled(bool) - Logfile_select - setEnabled(bool) - - - 48 - 74 - - - 238 - 69 - - - - - Execute_check - toggled(bool) - Execute_select - setEnabled(bool) - - - 92 - 138 - - - 244 - 127 - - - - -
diff --git a/knotify/knotifyconfigelement.cpp b/knotify/knotifyconfigelement.cpp deleted file mode 100644 index 7e60596b..00000000 --- a/knotify/knotifyconfigelement.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2005-2006 by Olivier Goffart - - - 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. - - */ - -#include "knotifyconfigelement.h" - -#include -#include -#include -#include -#include - -KNotifyConfigElement::KNotifyConfigElement(const QString &eventid, KConfig *config) - : m_config( new KConfigGroup(config , "Event/" + eventid) ) -{ -} - -KNotifyConfigElement::~KNotifyConfigElement() -{ - delete m_config; -} - -QString KNotifyConfigElement::readEntry( const QString & entry, bool path ) -{ - if(m_cache.contains(entry)) - return m_cache[entry]; - return path ? m_config->readPathEntry(entry, QString()) : - m_config->readEntry(entry, QString()); -} - -void KNotifyConfigElement::writeEntry( const QString & entry, const QString &data ) -{ - m_cache[entry]=data; -} - -void KNotifyConfigElement::save( ) -{ - QMapIterator it(m_cache); - while(it.hasNext()) - { - it.next(); - m_config->writeEntry(it.key() , it.value() ); - } - m_config->sync(); -} diff --git a/knotify/knotifyconfigelement.h b/knotify/knotifyconfigelement.h deleted file mode 100644 index b3ecbf4c..00000000 --- a/knotify/knotifyconfigelement.h +++ /dev/null @@ -1,49 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2005-2006 by Olivier Goffart - - - 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. - - */ - -#ifndef KNOTIFYCONFIGELEMENT_H -#define KNOTIFYCONFIGELEMENT_H - -#include - -class KConfig; -class KConfigGroup; - -/** - * Represent the config for an event - @author Olivier Goffart - */ -class KNotifyConfigElement -{ - public: - KNotifyConfigElement( const QString &eventid, KConfig *config); - ~KNotifyConfigElement(); - - QString readEntry(const QString& entry, bool path=false); - void writeEntry(const QString& entry, const QString & data); - - void save(); - - private: - QMap m_cache; - KConfigGroup* m_config; -}; - -#endif diff --git a/knotify/knotifyconfigwidget.cpp b/knotify/knotifyconfigwidget.cpp deleted file mode 100644 index d3254ad1..00000000 --- a/knotify/knotifyconfigwidget.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2005 Olivier Goffart - - 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. -*/ - -#include "knotifyconfigwidget.h" -#include "knotifyconfigactionswidget.h" -#include "knotifyeventlist.h" -#include "knotifyconfigelement.h" - -#include -#include -#include - -#include -#include -#include - -struct KNotifyConfigWidget::Private -{ - KNotifyEventList *eventList; - KNotifyConfigActionsWidget *actionsconfig; - KNotifyConfigElement *currentElement; -}; - - -KNotifyConfigWidget::KNotifyConfigWidget( QWidget * parent ) - : QWidget(parent) , d(new Private) -{ - d->currentElement=0l; - d->eventList=new KNotifyEventList( this ); - d->eventList->setFocus(); - d->actionsconfig=new KNotifyConfigActionsWidget(this); - d->actionsconfig->setEnabled(false); - connect(d->eventList , SIGNAL(eventSelected(KNotifyConfigElement*)) , - this , SLOT(slotEventSelected(KNotifyConfigElement*))); - connect(d->actionsconfig,SIGNAL(changed()),this,SLOT(slotActionChanged())); - - QVBoxLayout *layout = new QVBoxLayout(this); - layout->setMargin(0); - layout->addWidget(d->eventList,1); - layout->addWidget(d->actionsconfig); -} - - -KNotifyConfigWidget::~KNotifyConfigWidget() -{ - delete d; -} - - -void KNotifyConfigWidget::setApplication (const QString & app, const QString & context_name, const QString & context_value ) -{ - d->currentElement=0l; - d->eventList->fill( app.isEmpty() ? KGlobal::mainComponent().componentName() : app , context_name , context_value ); -} - - -void KNotifyConfigWidget::slotEventSelected( KNotifyConfigElement * e ) -{ - if(d->currentElement) - { - d->actionsconfig->save( d->currentElement ); - } - d->currentElement=e; - if(e) - { - d->actionsconfig->setConfigElement( e); - d->actionsconfig->setEnabled(true); - } - else - d->actionsconfig->setEnabled(false); - -} - -void KNotifyConfigWidget::save( ) -{ - if(d->currentElement) - d->actionsconfig->save( d->currentElement ); - - - d->eventList->save(); - emit changed(false); - - //ask the notify daemon to reload the config - if (QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.knotify")) - { - QDBusInterface( QLatin1String("org.kde.knotify"), QLatin1String("/Notify"), - QLatin1String("org.kde.KNotify")).call( "reconfigure" ); - } -} - -KNotifyConfigWidget * KNotifyConfigWidget::configure( QWidget * parent, const QString & appname ) -{ - KDialog *dialog=new KDialog(parent); - dialog->setCaption(i18n("Configure Notifications")); - KNotifyConfigWidget *w=new KNotifyConfigWidget(dialog); - dialog->setMainWidget(w); - - connect(dialog,SIGNAL(applyClicked()),w,SLOT(save())); - connect(dialog,SIGNAL(okClicked()),w,SLOT(save())); - connect(w,SIGNAL(changed(bool)) , dialog , SLOT(enableButtonApply(bool))); - - w->setApplication(appname); - dialog->setAttribute( Qt::WA_DeleteOnClose ); - dialog->show(); - return w; -} - -void KNotifyConfigWidget::slotActionChanged() -{ - emit changed( true ); //TODO - if(d->currentElement) - { - d->actionsconfig->save( d->currentElement ); - d->eventList->updateCurrentItem(); - } -} - - -#include "moc_knotifyconfigwidget.cpp" diff --git a/knotify/knotifyconfigwidget.h b/knotify/knotifyconfigwidget.h deleted file mode 100644 index e4b9c692..00000000 --- a/knotify/knotifyconfigwidget.h +++ /dev/null @@ -1,86 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2005 Olivier Goffart - - 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. -*/ - -#ifndef KNOTIFYCONFIGWIDGET_H -#define KNOTIFYCONFIGWIDGET_H - -#include -#include -#include - -class KNotifyConfigElement; - -/** - * Configure the notification for a given application / context - * - * You probably will want to use the static function configure - * - * If you create the widget yourself, you must call setApplication before showing it - * - * @author Olivier Goffart - */ -class KNOTIFYCONFIG_EXPORT KNotifyConfigWidget : public QWidget -{ - Q_OBJECT -public: - KNotifyConfigWidget( QWidget *parent); - ~KNotifyConfigWidget(); - - /** - * Show a dialog with the widget. - * @param parent the parent widget of the dialog - * @param appname the application name, if null, it is autodetected - * @return the widget itself the topLevelWidget of it is probably a KDialog - */ - static KNotifyConfigWidget *configure(QWidget *parent = 0l, const QString &appname=QString()); - - /** - * Change the application and the context - * - * @param appname name of the application. if null KGlobal::mainComponent().componentName() is used - * @param context_name the name of the context, if null , avery context are considered - * @param context_value the context value - */ - void setApplication( const QString & appname = QString() , - const QString & context_name = QString(), - const QString & context_value = QString()); - -public Q_SLOTS: - /** - * save to the config file - */ - void save(); - -Q_SIGNALS: - /** - * Indicate that the state of the modules contents has changed. - * This signal is emitted whenever the state of the configuration changes. - * @see KCModule::changed - */ - void changed(bool state); - -private: - struct Private; - Private* const d; -private Q_SLOTS: - void slotEventSelected( KNotifyConfigElement *e); - void slotActionChanged(); - -}; - -#endif diff --git a/knotify/knotifyeventlist.cpp b/knotify/knotifyeventlist.cpp deleted file mode 100644 index 3bf7f9bc..00000000 --- a/knotify/knotifyeventlist.cpp +++ /dev/null @@ -1,215 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2005 Olivier Goffart - - 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. -*/ -#include "knotifyeventlist.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -//BEGIN KNotifyEventListDelegate - -class KNotifyEventList::KNotifyEventListDelegate : public QStyledItemDelegate -{ - public: - KNotifyEventListDelegate(QObject *parent = 0); - - virtual void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; - private: -}; - -KNotifyEventList::KNotifyEventListDelegate::KNotifyEventListDelegate(QObject *parent) - : QStyledItemDelegate(parent) -{ -} - -void KNotifyEventList::KNotifyEventListDelegate::paint( QPainter* painter, - const QStyleOptionViewItem& option, const QModelIndex& index ) const -{ - if (index.column() != 0) - return QStyledItemDelegate::paint(painter, option, index); - - QVariant displayData = index.data(Qt::UserRole); - QString prstring=displayData.toString(); - - QStyledItemDelegate::paint(painter, option, index); - -// kDebug() << prstring; - - QRect rect=option.rect; - - QStringList optionsList = prstring.split ('|'); - QList iconList; - iconList << ( optionsList.contains("Sound") ? KIcon("media-playback-start") : KIcon() ); - iconList << ( optionsList.contains("Popup") ? KIcon("dialog-information") : KIcon() ); - iconList << ( optionsList.contains("Logfile") ? KIcon("text-x-generic") : KIcon() ); - iconList << ( optionsList.contains("Taskbar") ? KIcon("services") : KIcon() ); - iconList << ( optionsList.contains("Execute") ? KIcon("system-run") : KIcon() ); - - int mc_x=0; - - int iconWidth = option.decorationSize.width(); - int iconHeight = option.decorationSize.height(); - foreach(const KIcon &icon, iconList) - { - icon.paint(painter, rect.left() + mc_x + 4, rect.top() + (rect.height() - iconHeight) / 2, iconWidth, iconHeight); - mc_x += iconWidth + 4; - } -} - -//END KNotifyEventListDelegate - -KNotifyEventList::KNotifyEventList(QWidget *parent) - : QTreeWidget(parent) , config(0) -{ - QStringList headerLabels; - headerLabels << i18nc( "State of the notified event", "State" ) << i18nc( "Title of the notified event", "Title" ) << i18nc( "Description of the notified event", "Description" ); - setHeaderLabels( headerLabels ); - - setItemDelegate(new KNotifyEventListDelegate(this)); - setRootIsDecorated(false); - setAlternatingRowColors(true); - - //Extract icon size as the font height (as h=w on icons) - QStyleOptionViewItem iconOption; - iconOption.initFrom( this ); - int iconWidth = iconOption.fontMetrics.height() -2 ; //1px margin top & bottom - setIconSize( QSize(iconWidth, iconWidth) ); - - header()->setResizeMode( 0, QHeaderView::Fixed ); - header()->resizeSection( 0, (iconWidth + 4) * 5 ); - header()->setResizeMode( 1, QHeaderView::ResizeToContents ); - - connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)) , this , SLOT(slotSelectionChanged(QTreeWidgetItem*,QTreeWidgetItem*))); -} - - -KNotifyEventList::~KNotifyEventList() -{ - delete config; -} - -void KNotifyEventList::fill( const QString & appname , const QString & context_name ,const QString & context_value ) -{ - m_elements.clear(); - clear(); - delete config; - config = new KConfig(appname + ".notifyrc" , KConfig::NoGlobals); - config->addConfigSources(KGlobal::dirs()->findAllResources("data", - appname + '/' + appname + ".notifyrc")); - - QStringList conflist = config->groupList(); - QRegExp rx("^Event/([^/]*)$"); - conflist=conflist.filter( rx ); - - foreach (const QString& group , conflist ) - { - KConfigGroup cg(config, group); - rx.indexIn(group); - QString id=rx.cap(1); - - if(!context_name.isEmpty()) - { - QStringList contexts = cg.readEntry("Contexts", QStringList()); - if(!contexts.contains(context_name)) - continue; - - id=id+'/'+context_name+'/'+context_value; - } - QString name = cg.readEntry("Name"); - QString description = cg.readEntry("Comment"); - - m_elements << new KNotifyEventListItem(this, id, name, description, config ); - } - - resizeColumnToContents(2); -} - -void KNotifyEventList::save( ) -{ - foreach( KNotifyEventListItem *it , m_elements ) - { - it->save(); - } -} - -void KNotifyEventList::slotSelectionChanged( QTreeWidgetItem *current , QTreeWidgetItem *previous) -{ - Q_UNUSED( current ); - - KNotifyEventListItem *it=dynamic_cast(currentItem()); - if(it) - emit eventSelected( it->configElement() ); - else - emit eventSelected( 0l ); - - it=dynamic_cast(previous); - if(it) - it->update(); -} - -void KNotifyEventList::updateCurrentItem() -{ - KNotifyEventListItem *it=dynamic_cast(currentItem()); - if(it) - it->update(); -} - -QSize KNotifyEventList::sizeHint() const -{ - int fontSize = fontMetrics().height(); - return QSize(48 * fontSize, 12 * fontSize); -} - - -KNotifyEventListItem::KNotifyEventListItem( QTreeWidget * parent, const QString & eventName, - const QString & name, const QString & description , KConfig *config) - : QTreeWidgetItem(parent) , - m_config(eventName, config ) -{ - setText( 1, name ); - setToolTip( 1, description ); - setText( 2, description ); - setToolTip( 2, description ); - update(); -} - -KNotifyEventListItem::~KNotifyEventListItem() -{ -} - -void KNotifyEventListItem::save() -{ - m_config.save(); -} - -void KNotifyEventListItem::update() -{ - setData(0 , Qt::UserRole , m_config.readEntry( "Action" )); -} - -#include "moc_knotifyeventlist.cpp" diff --git a/knotify/knotifyeventlist.h b/knotify/knotifyeventlist.h deleted file mode 100644 index 1b75f0bc..00000000 --- a/knotify/knotifyeventlist.h +++ /dev/null @@ -1,77 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2005 Olivier Goffart - - 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. -*/ - - -#ifndef KNOTIFYEVENTLIST_H -#define KNOTIFYEVENTLIST_H - -#include "knotifyconfigelement.h" - - -#include - -class KNotifyConfigElement; -class KNotifyEventListItem; -class KConfig; - -/** - @author Olivier Goffart -*/ -class KNotifyEventList : public QTreeWidget -{ - Q_OBJECT -public: - KNotifyEventList(QWidget *parent); - ~KNotifyEventList(); - void fill( const QString & appname , const QString & context_name=QString() , - const QString & context_value=QString()); - void save(); - void updateCurrentItem(); - QSize sizeHint() const; -private: - KConfig *config; - QList m_elements; - - class KNotifyEventListDelegate; - -private Q_SLOTS: - void slotSelectionChanged(QTreeWidgetItem *current , QTreeWidgetItem *previous); - -Q_SIGNALS: - void eventSelected(KNotifyConfigElement *); - -}; - -class KNotifyEventListItem : public QTreeWidgetItem -{ - public: - KNotifyEventListItem(QTreeWidget *parent , const QString & eventName , const QString & name , - const QString & description , KConfig* confir); - ~KNotifyEventListItem(); - void save(); - - KNotifyConfigElement *configElement() { return &m_config; } - - void update(); - - private: - KNotifyConfigElement m_config; - -}; - -#endif diff --git a/kutils/knetworkmanager/kded/CMakeLists.txt b/kutils/knetworkmanager/kded/CMakeLists.txt index 07af5f22..66dce1b2 100644 --- a/kutils/knetworkmanager/kded/CMakeLists.txt +++ b/kutils/knetworkmanager/kded/CMakeLists.txt @@ -32,5 +32,5 @@ install( install( FILES knetworkmanager.notifyrc - DESTINATION ${KDE4_DATA_INSTALL_DIR}/knetworkmanager + DESTINATION ${KDE4_CONFIG_INSTALL_DIR}/notifications ) diff --git a/kutils/knetworkmanager/kded/kded_knetworkmanager.cpp b/kutils/knetworkmanager/kded/kded_knetworkmanager.cpp index b665baa2..2880c06e 100644 --- a/kutils/knetworkmanager/kded/kded_knetworkmanager.cpp +++ b/kutils/knetworkmanager/kded/kded_knetworkmanager.cpp @@ -55,35 +55,24 @@ bool KNetworkManagerModule::enable(const bool enable) void KNetworkManagerModule::slotStatusChanged(const KNetworkManager::KNetworkStatus status) { - KNotification *knotification = nullptr; switch (status) { case KNetworkManager::UnknownStatus: { - knotification = new KNotification("Unknown"); - knotification->setComponentData(KComponentData("knetworkmanager")); - knotification->setTitle(i18n("Network status changed")); - knotification->setText(i18n("Network status is unknown")); + KNotification::event("knetworkmanager/Unknown"); break; } case KNetworkManager::ConnectedStatus: { - knotification = new KNotification("Connected"); - knotification->setComponentData(KComponentData("knetworkmanager")); - knotification->setTitle(i18n("Network status changed")); - knotification->setText(i18n("Network status is connected")); + KNotification::event("knetworkmanager/Connected"); break; } case KNetworkManager::DisconnectedStatus: { - knotification = new KNotification("Disconnected"); - knotification->setComponentData(KComponentData("knetworkmanager")); - knotification->setTitle(i18n("Network status changed")); - knotification->setText(i18n("Network status is disconnected")); + KNotification::event("knetworkmanager/Disconnected"); break; } case KNetworkManager::IntermediateStatus: { // no notification for intermediate status changes - return; + break; } } - knotification->sendEvent(); } #include "moc_kded_knetworkmanager.cpp" diff --git a/kutils/knetworkmanager/kded/knetworkmanager.notifyrc b/kutils/knetworkmanager/kded/knetworkmanager.notifyrc index 8111a660..fd4ec9bf 100644 --- a/kutils/knetworkmanager/kded/knetworkmanager.notifyrc +++ b/kutils/knetworkmanager/kded/knetworkmanager.notifyrc @@ -1,22 +1,22 @@ -[Global] +[knetworkmanager] Name=knetworkmanager Comment=Network manager IconName=network-workgroup -[Event/Unknown] +[knetworkmanager/kUnknown] Name=Network status is unknown -Action=Sound|Popup +Actions=Sound|Popup Sound=KDE-Im-Cant-Connect.ogg IconName=dialog-warning -[Event/Disconnected] +[knetworkmanager/Disconnected] Name=Network status is disconnected -Action=Sound|Popup +Actions=Sound,Popup Sound=KDE-Im-Contact-Out.ogg IconName=network-disconnect -[Event/Connected] +[knetworkmanager/Connected] Name=Network status is connected -Action=Sound|Popup +Actions=Sound,Popup Sound=KDE-Im-Contact-In.ogg IconName=network-connect \ No newline at end of file