From b66b1d455e0a6c8c438cf2b8ceecdd738cbfcb04 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Thu, 25 Dec 2008 20:48:16 +0100 Subject: [PATCH] Adding KNotify support to Quassel If KDE support is enabled, all notification backends are replaced by standard KNotify events. NOTE: To make this work, you'll need a real installation (i.e. make install) into a standard location KDE can find, because some external files are req'd! --- CMakeLists.txt | 6 +- data/CMakeLists.txt | 4 ++ data/quassel.notifyrc | 9 +++ src/qtui/CMakeLists.txt | 29 ++++---- src/qtui/knotificationbackend.cpp | 76 +++++++++++++++++++++ src/qtui/knotificationbackend.h | 60 ++++++++++++++++ src/qtui/mainwin.cpp | 24 ++++--- src/uisupport/abstractnotificationbackend.h | 6 +- 8 files changed, 189 insertions(+), 25 deletions(-) create mode 100644 data/quassel.notifyrc create mode 100644 src/qtui/knotificationbackend.cpp create mode 100644 src/qtui/knotificationbackend.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c473282e..ea108c40 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,7 @@ if(STATIC) set(CMAKE_BUILD_TYPE Release) set(OXYGEN_ICONS "Builtin") set(QUASSEL_ICONS "Builtin") + set(WITH_KDE OFF) endif(STATIC) # RPATH needs to be set correctly @@ -62,7 +63,7 @@ set(CMAKE_BUILD_WITH_INSTALL_RPATH 1) # Define install locations. Using variables will allow overriding this by the KDE macros later. set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin) -set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/apps/quassel) +set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/apps) set(ICON_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/icons) set(XDG_APPS_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/applications) @@ -178,8 +179,9 @@ if(WITH_KDE) add_definitions(-DHAVE_KDE ${KDE4_DEFINITIONS}) set(HAVE_KDE 1) set(MOC_DEFINES ${MOC_DEFINES} -DHAVE_KDE) - set(QUASSEL_KDE_LIBRARIES ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBRARY}) + set(QUASSEL_KDE_LIBRARIES ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBRARY} knotifyconfig) set(OXYGEN_ICONS "External") + set(QUASSEL_ICONS "External") else(KDE4_FOUND) message(STATUS "KDE4 not found, disabling KDE integration") endif(KDE4_FOUND) diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt index df560cfc..4513ca1e 100644 --- a/data/CMakeLists.txt +++ b/data/CMakeLists.txt @@ -5,3 +5,7 @@ endif(WANT_QTCLIENT) if(WANT_MONO) install(FILES quassel.desktop DESTINATION ${XDG_APPS_INSTALL_DIR}) endif(WANT_MONO) + +if(WANT_MONO OR WANT_QTCLIENT) + install(FILES quassel.notifyrc DESTINATION ${DATA_INSTALL_DIR}/quassel) +endif(WANT_MONO OR WANT_QTCLIENT) diff --git a/data/quassel.notifyrc b/data/quassel.notifyrc new file mode 100644 index 00000000..ac742def --- /dev/null +++ b/data/quassel.notifyrc @@ -0,0 +1,9 @@ +[Global] +IconName=quassel +Comment=Quassel IRC + +[Event/Highlight] +Name=Highlight +Comment=A highlighted message has arrived +Sound=KDE-Im-Highlight-Msg.ogg +Action=Sound|Popup diff --git a/src/qtui/CMakeLists.txt b/src/qtui/CMakeLists.txt index a9e98e62..2e0d3cf1 100644 --- a/src/qtui/CMakeLists.txt +++ b/src/qtui/CMakeLists.txt @@ -114,19 +114,24 @@ set(FORMS settingspagedlg.ui topicwidget.ui) -IF(HAVE_DBUS) - set(SOURCES ${SOURCES} desktopnotificationbackend.cpp) - set(MOC_HDRS ${MOC_HDRS} desktopnotificationbackend.h) - set(FORMS ${FORMS} desktopnotificationconfigwidget.ui) - qt4_add_dbus_interface(DBUS ../../interfaces/org.freedesktop.Notifications.xml desktopnotificationinterface) -ENDIF(HAVE_DBUS) +if(HAVE_KDE) + set(SOURCES ${SOURCES} knotificationbackend.cpp) + set(MOC_HDRS ${MOC_HDRS} knotificationbackend.h) +else(HAVE_KDE) + if(HAVE_DBUS) + set(SOURCES ${SOURCES} desktopnotificationbackend.cpp) + set(MOC_HDRS ${MOC_HDRS} desktopnotificationbackend.h) + set(FORMS ${FORMS} desktopnotificationconfigwidget.ui) + qt4_add_dbus_interface(DBUS ../../interfaces/org.freedesktop.Notifications.xml desktopnotificationinterface) + endif(HAVE_DBUS) -IF(HAVE_PHONON) - set(SOURCES ${SOURCES} phononnotificationbackend.cpp) - set(MOC_HDRS ${MOC_HDRS} phononnotificationbackend.h) - set(FORMS ${FORMS} phononnotificationconfigwidget.ui) - include_directories(${PHONON_INCLUDES}) -ENDIF(HAVE_PHONON) + if(HAVE_PHONON) + set(SOURCES ${SOURCES} phononnotificationbackend.cpp) + set(MOC_HDRS ${MOC_HDRS} phononnotificationbackend.h) + set(FORMS ${FORMS} phononnotificationconfigwidget.ui) + include_directories(${PHONON_INCLUDES}) + endif(HAVE_PHONON) +endif(HAVE_KDE) foreach(FORM ${FORMS}) set(FORMPATH ${FORMPATH} ui/${FORM}) diff --git a/src/qtui/knotificationbackend.cpp b/src/qtui/knotificationbackend.cpp new file mode 100644 index 00000000..c55bf31c --- /dev/null +++ b/src/qtui/knotificationbackend.cpp @@ -0,0 +1,76 @@ +/*************************************************************************** +* Copyright (C) 2005-08 by the Quassel Project * +* devel@quassel-irc.org * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) version 3. * +* * +* This program 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 General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ + +#include + +#include +#include + +#include "knotificationbackend.h" + +#include "client.h" +#include "icon.h" +#include "iconloader.h" +#include "networkmodel.h" +#include "qtui.h" + +KNotificationBackend::KNotificationBackend(QObject *parent) : AbstractNotificationBackend(parent) { + +} + +void KNotificationBackend::notify(const Notification &n) { + //QString title = Client::networkModel()->networkName(n.bufferId) + " - " + Client::networkModel()->bufferName(n.bufferId); + QString message = QString("<%1> %2").arg(n.sender, n.message); + KNotification::event("Highlight", message, DesktopIcon("dialog-information"), QtUi::mainWindow(), + KNotification::Persistent|KNotification::RaiseWidgetOnActivation|KNotification::CloseWhenWidgetActivated); +} + +void KNotificationBackend::close(uint notificationId) { + Q_UNUSED(notificationId); +} + +SettingsPage *KNotificationBackend::createConfigWidget() const { + return new ConfigWidget(); +} + +/***************************************************************************/ + +KNotificationBackend::ConfigWidget::ConfigWidget(QWidget *parent) : SettingsPage("Internal", "KNotification", parent) { + _widget = new KNotifyConfigWidget(this); + _widget->setApplication("quassel"); + + QVBoxLayout *layout = new QVBoxLayout(this); + layout->addWidget(_widget); + + connect(_widget, SIGNAL(changed(bool)), SLOT(widgetChanged(bool))); +} + +void KNotificationBackend::ConfigWidget::widgetChanged(bool changed) { + setChangedState(changed); +} + +void KNotificationBackend::ConfigWidget::load() { + setChangedState(false); +} + +void KNotificationBackend::ConfigWidget::save() { + _widget->save(); + load(); +} diff --git a/src/qtui/knotificationbackend.h b/src/qtui/knotificationbackend.h new file mode 100644 index 00000000..706478e6 --- /dev/null +++ b/src/qtui/knotificationbackend.h @@ -0,0 +1,60 @@ +/*************************************************************************** +* Copyright (C) 2005-08 by the Quassel Project * +* devel@quassel-irc.org * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) version 3. * +* * +* This program 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 General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ + +#ifndef KNOTIFICATIONBACKEND_H_ +#define KNOTIFICATIONBACKEND_H_ + +#include "abstractnotificationbackend.h" +#include "settingspage.h" + +class KNotification; +class KNotifyConfigWidget; + +class KNotificationBackend : public AbstractNotificationBackend { + Q_OBJECT + +public: + KNotificationBackend(QObject *parent = 0); + + void notify(const Notification &); + void close(uint notificationId); + virtual SettingsPage *createConfigWidget() const; + +private: + class ConfigWidget; +}; + +class KNotificationBackend::ConfigWidget : public SettingsPage { + Q_OBJECT + +public: + ConfigWidget(QWidget *parent = 0); + + void save(); + void load(); + +private slots: + void widgetChanged(bool); + +private: + KNotifyConfigWidget *_widget; +}; + +#endif diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index 4ebb0035..7d3b45d2 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -67,6 +67,9 @@ #ifdef HAVE_PHONON # include "phononnotificationbackend.h" #endif +#ifdef HAVE_KDE +# include "knotificationbackend.h" +#endif #include "systraynotificationbackend.h" #include "taskbarnotificationbackend.h" @@ -110,14 +113,19 @@ MainWin::MainWin(QWidget *parent) installEventFilter(new JumpKeyHandler(this)); - QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this)); - QtUi::registerNotificationBackend(new SystrayNotificationBackend(this)); -#ifdef HAVE_PHONON - QtUi::registerNotificationBackend(new PhononNotificationBackend(this)); -#endif -#ifdef HAVE_DBUS - QtUi::registerNotificationBackend(new DesktopNotificationBackend(this)); -#endif +#ifndef HAVE_KDE + QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this)); + QtUi::registerNotificationBackend(new SystrayNotificationBackend(this)); +# ifdef HAVE_PHONON + QtUi::registerNotificationBackend(new PhononNotificationBackend(this)); +# endif +# ifdef HAVE_DBUS + QtUi::registerNotificationBackend(new DesktopNotificationBackend(this)); +# endif + +#else /* HAVE_KDE */ + QtUi::registerNotificationBackend(new KNotificationBackend(this)); +#endif /* HAVE_KDE */ QtUiApplication* app = qobject_cast qApp; connect(app, SIGNAL(saveStateToSession(const QString&)), SLOT(saveStateToSession(const QString&))); diff --git a/src/uisupport/abstractnotificationbackend.h b/src/uisupport/abstractnotificationbackend.h index cc9941b0..982855ff 100644 --- a/src/uisupport/abstractnotificationbackend.h +++ b/src/uisupport/abstractnotificationbackend.h @@ -48,10 +48,10 @@ public: virtual void notify(const Notification &) = 0; virtual void close(uint notificationId) { Q_UNUSED(notificationId); } - //! factory to create a configuration widget suitable for a specific notification backend + //! Factory to create a configuration widget suitable for a specific notification backend /** - * AbstractNotification will not take owner ship of that configWidget! - * in case you need to communicate with the configWidget directly, make your connections here + * AbstractNotification will not take ownership of that configWidget! + * In case you need to communicate with the configWidget directly, make your connections here */ virtual SettingsPage *createConfigWidget() const = 0; }; -- 2.20.1