mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 10:22:48 +00:00
kdeui: reimplement KNotification
cleaning up the mess, everything but KNotificationConfigWidget is implemented. not only does it not require additional D-Bus service (knotify) to function but also does not transmit pixmaps over D-Bus, the features to execute command or log to file are dropped and will not be implemented. also about markup support in notifications - if the server does not support markup then it is supposed to strip it, see the spec: https://specifications.freedesktop.org/notification-spec/notification-spec-latest.html#backwards-compat meaning nothing should be done by KNotification itself because it is not a server, it is just a proxy. Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
80d185a980
commit
450120097d
37 changed files with 594 additions and 2297 deletions
|
@ -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 )
|
||||
|
|
|
@ -189,7 +189,7 @@ install(
|
|||
KNewPasswordDialog
|
||||
KNotification
|
||||
KNotificationRestrictions
|
||||
KNotifyConfigWidget
|
||||
KNotificationConfigWidget
|
||||
KNumInput
|
||||
KOpenWithDialog
|
||||
KPageDialog
|
||||
|
|
1
includes/KNotificationConfigWidget
Normal file
1
includes/KNotificationConfigWidget
Normal file
|
@ -0,0 +1 @@
|
|||
#include "../knotificationconfigwidget.h"
|
|
@ -1 +0,0 @@
|
|||
#include "../knotifyconfigwidget.h"
|
|
@ -79,7 +79,6 @@
|
|||
# kde-workspace
|
||||
101 kioclient
|
||||
900 kdesudo
|
||||
901 knotify
|
||||
1203 libkonq
|
||||
1204 plasma
|
||||
1207 krunner
|
||||
|
|
|
@ -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<bool> 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);
|
||||
|
|
|
@ -20,10 +20,15 @@
|
|||
*/
|
||||
|
||||
#include "kdbusconnectionpool.h"
|
||||
#include "kdebug.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QThread>
|
||||
#include <QDBusConnectionInterface>
|
||||
#include <QDBusReply>
|
||||
|
||||
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<bool> reply = dbusinterface->isServiceRegistered(service);
|
||||
if (reply.value() == false) {
|
||||
kDebug() << "Service not registered" << service;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,19 +22,24 @@
|
|||
#define KDBUSCONNECTIONPOOL_H
|
||||
|
||||
#include <kdecore_export.h>
|
||||
|
||||
#include <QtDBus/qdbusconnection.h>
|
||||
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,18 +1,9 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2005-2006 Olivier Goffart <ogoffart at kde.org>
|
||||
|
||||
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 <bastian@kde.org>
|
||||
2000-2003 Carsten Pfeiffer <pfeiffer@kde.org>
|
||||
2005 Allan Sandfeld Jensen <kde@carewolf.com>
|
||||
Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2 as published by the Free Software Foundation.
|
||||
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
|
||||
|
@ -26,84 +17,277 @@
|
|||
*/
|
||||
|
||||
#include "knotification.h"
|
||||
#include "knotificationmanager_p.h"
|
||||
|
||||
#include <kmessagebox.h>
|
||||
#include <klocale.h>
|
||||
#include <kiconloader.h>
|
||||
#include <kconfig.h>
|
||||
#include <kpassivepopup.h>
|
||||
#include <kdialog.h>
|
||||
#include <kwindowsystem.h>
|
||||
#include <kdebug.h>
|
||||
#include <kapplication.h>
|
||||
#include "kglobal.h"
|
||||
#include "kcomponentdata.h"
|
||||
#include "kconfig.h"
|
||||
#include "kconfiggroup.h"
|
||||
#include "kstandarddirs.h"
|
||||
#include "kwindowsystem.h"
|
||||
#include "kdbusconnectionpool.h"
|
||||
#include "kiconloader.h"
|
||||
#include "kpassivepopup.h"
|
||||
#include "kdebug.h"
|
||||
|
||||
#include <QDBusConnectionInterface>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusReply>
|
||||
#include <QTimer>
|
||||
#include <QTabWidget>
|
||||
#include <QDBusError>
|
||||
|
||||
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<KNotification*,uint> 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<uint> notifyreply = m_notificationsiface->call(
|
||||
QString::fromLatin1("Notify"),
|
||||
eventapp,
|
||||
eventid,
|
||||
eventicon,
|
||||
eventtitle,
|
||||
eventtext,
|
||||
eventactions,
|
||||
eventhints,
|
||||
eventtimeout
|
||||
);
|
||||
if (!notifyreply.isValid()) {
|
||||
kWarning(s_knotificationarea) << "invalid notify reply" << notifyreply.error().message();
|
||||
} else {
|
||||
m_notifications.insert(notification, notifyreply.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<void> 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<KNotification*,uint> iter(m_notifications);
|
||||
while (iter.hasNext()) {
|
||||
iter.next();
|
||||
if (iter.key() == notification) {
|
||||
iter.remove();
|
||||
QDBusReply<void> closereply = m_notificationsiface->call(
|
||||
QString::fromLatin1("CloseNotification"),
|
||||
iter.value()
|
||||
);
|
||||
if (!closereply.isValid()) {
|
||||
kWarning(s_knotificationarea) << "invalid close reply" << closereply.error().message();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KNotificationManager::slotNotificationClosed(uint eventid, uint reason)
|
||||
{
|
||||
kDebug(s_knotificationarea) << "closing notifications due to interface" << reason;
|
||||
QMutableMapIterator<KNotification*,uint> iter(m_notifications);
|
||||
while (iter.hasNext()) {
|
||||
iter.next();
|
||||
if (iter.value() == eventid) {
|
||||
KNotification* notification = iter.key();
|
||||
notification->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KNotificationManager::slotActionInvoked(uint eventid, const QString &action)
|
||||
{
|
||||
kDebug(s_knotificationarea) << "notification action invoked" << action;
|
||||
QMutableMapIterator<KNotification*,uint> iter(m_notifications);
|
||||
while (iter.hasNext()) {
|
||||
iter.next();
|
||||
if (iter.value() == eventid) {
|
||||
KNotification* notification = iter.key();
|
||||
notification->activate(action.toUInt());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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<QTabWidget*>(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);
|
||||
}
|
||||
|
||||
bool KNotification::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (watched == d->widget) {
|
||||
if (event->type() == QEvent::WindowActivate) {
|
||||
if (d->flags & CloseWhenWidgetActivated) {
|
||||
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"
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2005-2006 Olivier Goffart <ogoffart at kde.org>
|
||||
Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2 as published by the Free Software Foundation.
|
||||
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
|
||||
|
@ -16,199 +16,58 @@
|
|||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef KNOTIFICATION_H
|
||||
#define KNOTIFICATION_H
|
||||
|
||||
#include <kdeui_export.h>
|
||||
#include <kcomponentdata.h>
|
||||
|
||||
#include <QtGui/QPixmap>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QPair>
|
||||
|
||||
#include <QWidget>
|
||||
#include <QDBusError>
|
||||
#include <QEvent>
|
||||
|
||||
/**
|
||||
* 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:
|
||||
* <em>$KDEDIR/share/appname/appname.notifyrc</em>
|
||||
*
|
||||
* 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
|
||||
* <ol><li>\ref global "Global information"</li>
|
||||
* <li>\ref context "Context information"</li>
|
||||
* <li>\ref events "Definition of individual events"</li></ol>
|
||||
*
|
||||
* \subsection global Global information
|
||||
* The global part looks like that
|
||||
* <pre>
|
||||
[Global]
|
||||
IconName=Filename
|
||||
Comment=Friendly Name of app
|
||||
Name=Name of app
|
||||
* </pre>
|
||||
* 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
|
||||
* <pre>
|
||||
[Context/group]
|
||||
Name=Group name
|
||||
Comment=The name of the group for contacts
|
||||
class KNotificationPrivate;
|
||||
|
||||
[Context/folder]
|
||||
Name=Group name
|
||||
* </pre>
|
||||
* 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
|
||||
* <pre>
|
||||
[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
|
||||
* </pre>
|
||||
* 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.
|
||||
* <pre>
|
||||
[Context/group]
|
||||
Values=1:Friends,2:Work,3:Family
|
||||
* </pre>
|
||||
* \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
|
||||
* <em>Event/<EventName>/<ContextName>/<ContextValue></em>
|
||||
* <pre>
|
||||
[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
|
||||
* </pre>
|
||||
*
|
||||
* \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 <i>%1</i> 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 \<ogoffart at kde.org\>
|
||||
*/
|
||||
@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<QString,QString> 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)
|
||||
|
|
60
kdeui/notifications/knotificationconfigwidget.cpp
Normal file
60
kdeui/notifications/knotificationconfigwidget.cpp
Normal file
|
@ -0,0 +1,60 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2, as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#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"
|
48
kdeui/notifications/knotificationconfigwidget.h
Normal file
48
kdeui/notifications/knotificationconfigwidget.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2, as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef KNOTIFICATIONCONFIGWIDGET_H
|
||||
#define KNOTIFICATIONCONFIGWIDGET_H
|
||||
|
||||
#include <kdeui_export.h>
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
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
|
|
@ -1,165 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2005 Olivier Goffart <ogoffart at kde.org>
|
||||
|
||||
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 <QWidget>
|
||||
#include <QImageWriter>
|
||||
#include <QBuffer>
|
||||
|
||||
#include "knotificationmanager_p.h"
|
||||
#include <ktoolinvocation.h>
|
||||
#include "knotification.h"
|
||||
#include <kdebug.h>
|
||||
#include <kapplication.h>
|
||||
#include <kiconloader.h>
|
||||
#include <kconfig.h>
|
||||
#include <klocale.h>
|
||||
|
||||
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<void> 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<QVariant> 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"
|
|
@ -1,80 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2005 Olivier Goffart <ogoffart at kde.org>
|
||||
Copyright (C) 2006 Thiago Macieira <thiago@kde.org>
|
||||
|
||||
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 <knotification.h>
|
||||
#include "knotify_interface.h"
|
||||
|
||||
#include <QPixmap>
|
||||
#include <QStringList>
|
||||
|
||||
/**
|
||||
* @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<int , KNotification*> m_notifications;
|
||||
org::kde::KNotify *m_knotify;
|
||||
};
|
||||
|
||||
#endif // KNOTIFICATIONMANAGER_H
|
|
@ -1,41 +0,0 @@
|
|||
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
|
||||
<node>
|
||||
<interface name="org.kde.KNotify">
|
||||
<signal name="notificationClosed">
|
||||
<arg name="id" type="i" direction="out"/>
|
||||
</signal>
|
||||
<signal name="notificationActivated">
|
||||
<arg name="id" type="i" direction="out"/>
|
||||
<arg name="action" type="i" direction="out"/>
|
||||
</signal>
|
||||
<method name="reconfigure">
|
||||
</method>
|
||||
<method name="closeNotification">
|
||||
<arg name="id" type="i" direction="in"/>
|
||||
</method>
|
||||
<method name="event">
|
||||
<arg type="i" direction="out"/>
|
||||
<arg name="event" type="s" direction="in"/>
|
||||
<arg name="fromApp" type="s" direction="in"/>
|
||||
<arg name="contexts" type="av" direction="in"/>
|
||||
<arg name="title" type="s" direction="in"/>
|
||||
<arg name="text" type="s" direction="in"/>
|
||||
<arg name="pixmap" type="ay" direction="in"/>
|
||||
<arg name="actions" type="as" direction="in"/>
|
||||
<arg name="timeout" type="i" direction="in"/>
|
||||
<arg name="winId" type="x" direction="in"/>
|
||||
</method>
|
||||
<method name="update">
|
||||
<arg name="id" type="i" direction="in"/>
|
||||
<arg name="title" type="s" direction="in"/>
|
||||
<arg name="text" type="s" direction="in"/>
|
||||
<arg name="pixmap" type="ay" direction="in"/>
|
||||
<arg name="actions" type="as" direction="in"/>
|
||||
</method>
|
||||
<method name="reemit">
|
||||
<arg name="id" type="i" direction="in"/>
|
||||
<arg name="contexts" type="av" direction="in"/>
|
||||
</method>
|
||||
</interface>
|
||||
</node>
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -36,7 +36,6 @@
|
|||
#include <QPolygon>
|
||||
#include <QTimer>
|
||||
#include <QToolTip>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QDesktopWidget>
|
||||
#include <QX11Info>
|
||||
|
||||
|
@ -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"
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include <kdeui_export.h>
|
||||
|
||||
#include <QFrame>
|
||||
#include <QSystemTrayIcon>
|
||||
|
||||
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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 );
|
||||
|
||||
|
|
|
@ -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*)));
|
||||
}
|
||||
|
|
|
@ -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}
|
||||
)
|
|
@ -1,115 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2005-2007 Olivier Goffart <ogoffart at kde.org>
|
||||
|
||||
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 <QtDBus/QDBusInterface>
|
||||
|
||||
#include <kstandarddirs.h>
|
||||
#include <kiconloader.h>
|
||||
|
||||
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"
|
|
@ -1,51 +0,0 @@
|
|||
/* This file is part of the KDE project
|
||||
Copyright (C) 2005-2007 by Olivier Goffart <ogoffart at kde.org>
|
||||
|
||||
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 <QtGui/QWidget>
|
||||
|
||||
#include "ui_knotifyconfigactionswidgetbase.h"
|
||||
|
||||
class KNotifyConfigElement;
|
||||
|
||||
/**
|
||||
* Represent the config for an event
|
||||
* @internal
|
||||
* @author Olivier Goffart <ogoffart @ kde.org>
|
||||
*/
|
||||
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
|
|
@ -1,184 +0,0 @@
|
|||
<ui version="4.0" >
|
||||
<class>KNotifyConfigActionsWidgetBase</class>
|
||||
<widget class="QWidget" name="KNotifyConfigActionsWidgetBase" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>433</width>
|
||||
<height>190</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" >
|
||||
<item row="0" column="0" >
|
||||
<widget class="QCheckBox" name="Sound_check" >
|
||||
<property name="text" >
|
||||
<string>Play a &sound</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" >
|
||||
<widget class="QToolButton" name="Sound_play" >
|
||||
<property name="enabled" >
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2" colspan="2" >
|
||||
<widget class="KUrlRequester" name="Sound_select" >
|
||||
<property name="enabled" >
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip" >
|
||||
<string>Select the sound to play</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="4" >
|
||||
<widget class="QCheckBox" name="Popup_check" >
|
||||
<property name="text" >
|
||||
<string>Show a message in a &popup</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" >
|
||||
<widget class="QCheckBox" name="Logfile_check" >
|
||||
<property name="text" >
|
||||
<string>Log to a file</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1" colspan="3" >
|
||||
<widget class="KUrlRequester" name="Logfile_select" >
|
||||
<property name="enabled" >
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="4" >
|
||||
<widget class="QCheckBox" name="Taskbar_check" >
|
||||
<property name="text" >
|
||||
<string>Mark &taskbar entry</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0" >
|
||||
<widget class="QCheckBox" name="Execute_check" >
|
||||
<property name="text" >
|
||||
<string>Run &command</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1" colspan="3" >
|
||||
<widget class="KUrlRequester" name="Execute_select" >
|
||||
<property name="enabled" >
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip" >
|
||||
<string>Select the command to run</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>KUrlRequester</class>
|
||||
<extends>QFrame</extends>
|
||||
<header>kurlrequester.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>KComboBox</class>
|
||||
<extends>QComboBox</extends>
|
||||
<header>kcombobox.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>Sound_check</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>Sound_play</receiver>
|
||||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<x>59</x>
|
||||
<y>23</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<x>118</x>
|
||||
<y>20</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>Sound_check</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>Sound_select</receiver>
|
||||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<x>18</x>
|
||||
<y>16</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<x>254</x>
|
||||
<y>8</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>Logfile_check</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>Logfile_select</receiver>
|
||||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<x>48</x>
|
||||
<y>74</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<x>238</x>
|
||||
<y>69</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>Execute_check</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>Execute_select</receiver>
|
||||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<x>92</x>
|
||||
<y>138</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<x>244</x>
|
||||
<y>127</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
|
@ -1,61 +0,0 @@
|
|||
/* This file is part of the KDE project
|
||||
Copyright (C) 2005-2006 by Olivier Goffart <ogoffart at kde.org>
|
||||
|
||||
|
||||
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 <kconfiggroup.h>
|
||||
#include <kconfig.h>
|
||||
#include <kdebug.h>
|
||||
#include <kstandarddirs.h>
|
||||
#include <kservice.h>
|
||||
|
||||
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<QString, QString> it(m_cache);
|
||||
while(it.hasNext())
|
||||
{
|
||||
it.next();
|
||||
m_config->writeEntry(it.key() , it.value() );
|
||||
}
|
||||
m_config->sync();
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
/* This file is part of the KDE project
|
||||
Copyright (C) 2005-2006 by Olivier Goffart <ogoffart at kde.org>
|
||||
|
||||
|
||||
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 <QtCore/QMap>
|
||||
|
||||
class KConfig;
|
||||
class KConfigGroup;
|
||||
|
||||
/**
|
||||
* Represent the config for an event
|
||||
@author Olivier Goffart <ogoffart@kde.org>
|
||||
*/
|
||||
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<QString,QString> m_cache;
|
||||
KConfigGroup* m_config;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,134 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2005 Olivier Goffart <ogoffart at kde.org>
|
||||
|
||||
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 <kapplication.h>
|
||||
#include <kdialog.h>
|
||||
#include <klocale.h>
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusConnectionInterface>
|
||||
|
||||
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"
|
|
@ -1,86 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2005 Olivier Goffart <ogoffart at kde.org>
|
||||
|
||||
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 <knotifyconfig_export.h>
|
||||
#include <QtGui/QWidget>
|
||||
#include <QtCore/QString>
|
||||
|
||||
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 <ogoffart @ kde.org>
|
||||
*/
|
||||
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
|
|
@ -1,215 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2005 Olivier Goffart <ogoffart at kde.org>
|
||||
|
||||
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 <kdebug.h>
|
||||
#include <klocale.h>
|
||||
#include <kicon.h>
|
||||
#include <kiconloader.h>
|
||||
#include <kconfig.h>
|
||||
#include <kconfiggroup.h>
|
||||
#include <kglobal.h>
|
||||
#include <kstandarddirs.h>
|
||||
|
||||
#include <QtGui/QStyledItemDelegate>
|
||||
#include <QtGui/QPainter>
|
||||
#include <QtGui/QHeaderView>
|
||||
#include <QtGui/QFontMetrics>
|
||||
|
||||
//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<KIcon> 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<KNotifyEventListItem *>(currentItem());
|
||||
if(it)
|
||||
emit eventSelected( it->configElement() );
|
||||
else
|
||||
emit eventSelected( 0l );
|
||||
|
||||
it=dynamic_cast<KNotifyEventListItem *>(previous);
|
||||
if(it)
|
||||
it->update();
|
||||
}
|
||||
|
||||
void KNotifyEventList::updateCurrentItem()
|
||||
{
|
||||
KNotifyEventListItem *it=dynamic_cast<KNotifyEventListItem *>(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"
|
|
@ -1,77 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2005 Olivier Goffart <ogoffart at kde.org>
|
||||
|
||||
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 <QtGui/QTreeWidget>
|
||||
|
||||
class KNotifyConfigElement;
|
||||
class KNotifyEventListItem;
|
||||
class KConfig;
|
||||
|
||||
/**
|
||||
@author Olivier Goffart <ogoffart at kde.org>
|
||||
*/
|
||||
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<KNotifyEventListItem*> 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
|
|
@ -32,5 +32,5 @@ install(
|
|||
|
||||
install(
|
||||
FILES knetworkmanager.notifyrc
|
||||
DESTINATION ${KDE4_DATA_INSTALL_DIR}/knetworkmanager
|
||||
DESTINATION ${KDE4_CONFIG_INSTALL_DIR}/notifications
|
||||
)
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
Loading…
Add table
Reference in a new issue