Adding KNotify support to Quassel
authorManuel Nickschas <sputnick@quassel-irc.org>
Thu, 25 Dec 2008 19:48:16 +0000 (20:48 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Fri, 26 Dec 2008 00:08:42 +0000 (01:08 +0100)
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
data/CMakeLists.txt
data/quassel.notifyrc [new file with mode: 0644]
src/qtui/CMakeLists.txt
src/qtui/knotificationbackend.cpp [new file with mode: 0644]
src/qtui/knotificationbackend.h [new file with mode: 0644]
src/qtui/mainwin.cpp
src/uisupport/abstractnotificationbackend.h

index c473282..ea108c4 100644 (file)
@@ -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)
index df560cf..4513ca1 100644 (file)
@@ -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 (file)
index 0000000..ac742de
--- /dev/null
@@ -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
index a9e98e6..2e0d3cf 100644 (file)
@@ -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 (file)
index 0000000..c55bf31
--- /dev/null
@@ -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 <QVBoxLayout>
+
+#include <KNotification>
+#include <KNotifyConfigWidget>
+
+#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("<b>&lt;%1&gt;</b> %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 (file)
index 0000000..706478e
--- /dev/null
@@ -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
index 4ebb003..7d3b45d 100644 (file)
@@ -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<QtUiApplication*> qApp;
   connect(app, SIGNAL(saveStateToSession(const QString&)), SLOT(saveStateToSession(const QString&)));
index cc9941b..982855f 100644 (file)
@@ -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;
 };