Basic implementation of indicators.
authorAurelien Gateau <aurelien.gateau@canonical.com>
Wed, 26 Aug 2009 13:51:46 +0000 (15:51 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Mon, 14 Sep 2009 21:37:08 +0000 (23:37 +0200)
CMakeLists.txt
src/CMakeLists.txt
src/qtui/CMakeLists.txt
src/qtui/indicatornotificationbackend.cpp [new file with mode: 0644]
src/qtui/indicatornotificationbackend.h [new file with mode: 0644]
src/qtui/mainwin.cpp
src/qtui/ui/indicatornotificationconfigwidget.ui [new file with mode: 0644]

index 0b1f39b..2bdea50 100644 (file)
@@ -231,6 +231,13 @@ if(NOT HAVE_KDE)
   endif(WITH_PHONON)
 endif(NOT HAVE_KDE)
 
   endif(WITH_PHONON)
 endif(NOT HAVE_KDE)
 
+# Setup libindicate-qt support
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(INDICATEQT indicate-qt)
+if(INDICATEQT_FOUND)
+  add_definitions(-DHAVE_INDICATEQT)
+endif(INDICATEQT_FOUND)
+
 # Now set up install locations; those are set by KDE if integration is enabled
 if(NOT HAVE_KDE)
   if(WIN32)
 # Now set up install locations; those are set by KDE if integration is enabled
 if(NOT HAVE_KDE)
   if(WIN32)
@@ -276,6 +283,16 @@ if(WIN32)
   endif(HAVE_SSL)
 endif(WIN32)
 
   endif(HAVE_SSL)
 endif(WIN32)
 
+if(INDICATEQT_FOUND)
+  if(WANT_QTCLIENT)
+    set(DESKTOP_FILE ${XDG_APPS_INSTALL_DIR}/quasselclient.desktop)
+  endif(WANT_QTCLIENT)
+  if(WANT_MONO)
+    set(DESKTOP_FILE ${XDG_APPS_INSTALL_DIR}/quassel.desktop)
+  endif(WANT_MONO)
+  add_definitions(-DDESKTOP_FILE=\"${DESKTOP_FILE}\")
+endif(INDICATEQT_FOUND)
+
 # We need to create a version.gen
 # For this, we create our genversion binary and make sure it is run every time.
 add_executable(genversion ${CMAKE_SOURCE_DIR}/src/common/genversion.cpp)
 # We need to create a version.gen
 # For this, we create our genversion binary and make sure it is run every time.
 add_executable(genversion ${CMAKE_SOURCE_DIR}/src/common/genversion.cpp)
index 5160445..01eb0ca 100644 (file)
@@ -54,7 +54,7 @@ if(WANT_QTCLIENT)
                                       COMPILE_FLAGS "-DQT_GUI_LIB -DQT_NETWORK_LIB -DBUILD_QTUI"
                                       OUTPUT_NAME ../quasselclient)
   target_link_libraries(quasselclient ${LINK_KDE} mod_qtui mod_uisupport mod_client mod_common ${CLIENT_LIBS}
                                       COMPILE_FLAGS "-DQT_GUI_LIB -DQT_NETWORK_LIB -DBUILD_QTUI"
                                       OUTPUT_NAME ../quasselclient)
   target_link_libraries(quasselclient ${LINK_KDE} mod_qtui mod_uisupport mod_client mod_common ${CLIENT_LIBS}
-                                      ${QUASSEL_QT_LIBRARIES} ${QUASSEL_KDE_LIBRARIES} ${QUASSEL_SSL_LIBRARIES} ${PHONON_LIBS})
+                                      ${QUASSEL_QT_LIBRARIES} ${QUASSEL_KDE_LIBRARIES} ${QUASSEL_SSL_LIBRARIES} ${PHONON_LIBS} ${INDICATEQT_LIBRARIES})
   install(TARGETS quasselclient RUNTIME DESTINATION ${BIN_INSTALL_DIR})
 endif(WANT_QTCLIENT)
 
   install(TARGETS quasselclient RUNTIME DESTINATION ${BIN_INSTALL_DIR})
 endif(WANT_QTCLIENT)
 
@@ -67,7 +67,7 @@ if(WANT_MONO)
                                 COMPILE_FLAGS "-DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_SCRIPT_LIB -DQT_SQL_LIB -DBUILD_MONO"
                                 OUTPUT_NAME ../quassel)
   target_link_libraries(quassel mod_qtui mod_uisupport mod_client mod_core mod_common ${CLIENT_LIBS}
                                 COMPILE_FLAGS "-DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_SCRIPT_LIB -DQT_SQL_LIB -DBUILD_MONO"
                                 OUTPUT_NAME ../quassel)
   target_link_libraries(quassel mod_qtui mod_uisupport mod_client mod_core mod_common ${CLIENT_LIBS}
-                                ${QUASSEL_QT_LIBRARIES} ${QUASSEL_KDE_LIBRARIES} ${QUASSEL_SSL_LIBRARIES} ${PHONON_LIBS})
+                                ${QUASSEL_QT_LIBRARIES} ${QUASSEL_KDE_LIBRARIES} ${QUASSEL_SSL_LIBRARIES} ${PHONON_LIBS} ${INDICATEQT_LIBRARIES})
   install(TARGETS quassel RUNTIME DESTINATION ${BIN_INSTALL_DIR})
 endif(WANT_MONO)
 
   install(TARGETS quassel RUNTIME DESTINATION ${BIN_INSTALL_DIR})
 endif(WANT_MONO)
 
index 642c84e..801d8ee 100644 (file)
@@ -5,6 +5,11 @@ set(QT_USE_QTNETWORK 1)
 set(QT_USE_QTDBUS 1)
 include(${QT_USE_FILE})
 
 set(QT_USE_QTDBUS 1)
 include(${QT_USE_FILE})
 
+if(INDICATEQT_FOUND)
+  include_directories(${INDICATEQT_INCLUDE_DIRS})
+  link_directories(${INDICATEQT_LIBRARY_DIRS})
+endif(INDICATEQT_FOUND)
+
 set(SOURCES
     aboutdlg.cpp
     awaylogfilter.cpp
 set(SOURCES
     aboutdlg.cpp
     awaylogfilter.cpp
@@ -146,6 +151,12 @@ else(HAVE_KDE)
   endif(HAVE_PHONON)
 endif(HAVE_KDE)
 
   endif(HAVE_PHONON)
 endif(HAVE_KDE)
 
+if(INDICATEQT_FOUND)
+  set(SOURCES ${SOURCES} indicatornotificationbackend.cpp)
+  set(MOC_HDRS ${MOC_HDRS} indicatornotificationbackend.h)
+  set(FORMS ${FORMS} indicatornotificationconfigwidget.ui)
+endif(INDICATEQT_FOUND)
+
 foreach(FORM ${FORMS})
   set(FORMPATH ${FORMPATH} ui/${FORM})
 endforeach(FORM ${FORMS})
 foreach(FORM ${FORMS})
   set(FORMPATH ${FORMPATH} ui/${FORM})
 endforeach(FORM ${FORMS})
diff --git a/src/qtui/indicatornotificationbackend.cpp b/src/qtui/indicatornotificationbackend.cpp
new file mode 100644 (file)
index 0000000..0637004
--- /dev/null
@@ -0,0 +1,150 @@
+/***************************************************************************
+*   Copyright (C) 2005-09 Canonical Ltd                                   *
+*   author: aurelien.gateau@canonical.com                                 *
+*                                                                         *
+*   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 "indicatornotificationbackend.h"
+
+#include <qindicateserver.h>
+#include <qindicateindicatormessage.h>
+
+#include "clientsettings.h"
+#include "mainwin.h"
+#include "qtui.h"
+
+class Indicator : public QIndicate::IndicatorMessage {
+public:
+  uint lastNotificationId;
+};
+
+IndicatorNotificationBackend::IndicatorNotificationBackend(QObject *parent)
+  : AbstractNotificationBackend(parent)
+{
+  NotificationSettings notificationSettings;
+  _enabled = notificationSettings.value("Indicator/Enabled", true).toBool();
+
+  notificationSettings.notify("Indicator/Enabled", this, SLOT(enabledChanged(const QVariant &)));
+
+  _server = QIndicate::Server::defaultInstance();
+  _server->setType("message.im");
+  _server->setDesktopFile(DESKTOP_FILE);
+  if (_enabled) {
+    _server->show();
+  }
+}
+
+IndicatorNotificationBackend::~IndicatorNotificationBackend() {
+  qDeleteAll(_indicatorHash);
+}
+
+void IndicatorNotificationBackend::notify(const Notification &notification) {
+  if(!_enabled) {
+    return;
+  }
+  if (notification.type != Highlight && notification.type != PrivMsg) {
+    return;
+  }
+  Indicator *indicator = _indicatorHash.value(notification.bufferId);
+  if(!indicator) {
+    indicator = new Indicator;
+    _indicatorHash.insert(notification.bufferId, indicator);
+  }
+  indicator->lastNotificationId = notification.notificationId;
+  indicator->setProperty("sender", notification.sender);
+  indicator->setProperty("time", QTime::currentTime());
+  qDebug() << "FIXME icon";
+  indicator->show();
+}
+
+void IndicatorNotificationBackend::close(uint notificationId) {
+  // If we find an indicator whose lastNotificationId is notificationId, we
+  // delete it
+
+  IndicatorHash::Iterator
+    it = _indicatorHash.begin(),
+    end = _indicatorHash.end();
+  for (; it != end; ++it) {
+    if (it.value()->lastNotificationId == notificationId) {
+      break;
+    }
+  }
+  if (it == end) {
+    // Not found, maybe there was no indicator for this notification or another
+    // notification happened after
+    return;
+  }
+  _indicatorHash.erase(it);
+  delete it.value();
+}
+
+void IndicatorNotificationBackend::enabledChanged(const QVariant &v) {
+  _enabled = v.toBool();
+  if (_enabled) {
+    _server->show();
+    // TODO: Create indicators for existing highlighted buffers?
+  } else {
+    _server->hide();
+    qDeleteAll(_indicatorHash);
+  }
+}
+
+SettingsPage *IndicatorNotificationBackend::createConfigWidget() const {
+  return new ConfigWidget();
+}
+
+/***************************************************************************/
+
+IndicatorNotificationBackend::ConfigWidget::ConfigWidget(QWidget *parent)
+: SettingsPage("Internal", "IndicatorNotification", parent)
+{
+  ui.setupUi(this);
+
+  connect(ui.enabled, SIGNAL(toggled(bool)), SLOT(widgetChanged()));
+}
+
+IndicatorNotificationBackend::ConfigWidget::~ConfigWidget() {
+}
+
+void IndicatorNotificationBackend::ConfigWidget::widgetChanged() {
+  bool changed = enabled != ui.enabled->isChecked();
+
+  if(changed != hasChanged()) setChangedState(changed);
+}
+
+bool IndicatorNotificationBackend::ConfigWidget::hasDefaults() const {
+  return true;
+}
+
+void IndicatorNotificationBackend::ConfigWidget::defaults() {
+  ui.enabled->setChecked(false);
+  widgetChanged();
+}
+
+void IndicatorNotificationBackend::ConfigWidget::load() {
+  NotificationSettings s;
+  enabled = s.value("Indicator/Enabled", false).toBool();
+
+  ui.enabled->setChecked(enabled);
+  setChangedState(false);
+}
+
+void IndicatorNotificationBackend::ConfigWidget::save() {
+  NotificationSettings s;
+  s.setValue("Indicator/Enabled", ui.enabled->isChecked());
+  load();
+}
diff --git a/src/qtui/indicatornotificationbackend.h b/src/qtui/indicatornotificationbackend.h
new file mode 100644 (file)
index 0000000..f4ed7b7
--- /dev/null
@@ -0,0 +1,83 @@
+/***************************************************************************
+*   Copyright (C) 2009 Canonical Ltd                                      *
+*   author: aurelien.gateau@canonical.com                                 *
+*                                                                         *
+*   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 INDICATORNOTIFICATIONBACKEND_H_
+#define INDICATORNOTIFICATIONBACKEND_H_
+
+#include <QHash>
+
+#include "abstractnotificationbackend.h"
+#include "settingspage.h"
+
+#include "ui_indicatornotificationconfigwidget.h"
+
+namespace QIndicate {
+class Server;
+}
+
+class Indicator;
+
+typedef QHash<BufferId, Indicator *> IndicatorHash;
+
+class IndicatorNotificationBackend : public AbstractNotificationBackend {
+  Q_OBJECT
+
+public:
+  IndicatorNotificationBackend(QObject *parent = 0);
+  ~IndicatorNotificationBackend();
+
+  void notify(const Notification &);
+  void close(uint notificationId);
+  virtual SettingsPage *createConfigWidget() const;
+
+private slots:
+  void enabledChanged(const QVariant &);
+
+private:
+  class ConfigWidget;
+
+  bool _enabled;
+
+  QIndicate::Server *_server;
+  IndicatorHash _indicatorHash;
+};
+
+class IndicatorNotificationBackend::ConfigWidget : public SettingsPage {
+  Q_OBJECT
+
+public:
+  ConfigWidget(QWidget *parent = 0);
+  ~ConfigWidget();
+
+  void save();
+  void load();
+  bool hasDefaults() const;
+  void defaults();
+
+private slots:
+  void widgetChanged();
+
+private:
+  Ui::IndicatorNotificationConfigWidget ui;
+
+  bool enabled;
+};
+
+#endif
index 98ecdd3..963f7a2 100644 (file)
 #  include "knotificationbackend.h"
 #endif /* HAVE_KDE */
 
 #  include "knotificationbackend.h"
 #endif /* HAVE_KDE */
 
+#ifdef HAVE_INDICATEQT
+  #include "indicatornotificationbackend.h"
+#endif
+
 #include "settingspages/aliasessettingspage.h"
 #include "settingspages/appearancesettingspage.h"
 #include "settingspages/backlogsettingspage.h"
 #include "settingspages/aliasessettingspage.h"
 #include "settingspages/appearancesettingspage.h"
 #include "settingspages/backlogsettingspage.h"
@@ -185,6 +189,10 @@ void MainWin::init() {
   QtUi::registerNotificationBackend(new KNotificationBackend(this));
 #endif /* HAVE_KDE */
 
   QtUi::registerNotificationBackend(new KNotificationBackend(this));
 #endif /* HAVE_KDE */
 
+#ifdef HAVE_INDICATEQT
+  QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
+#endif
+
   connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
 
   setDisconnectedState();  // Disable menus and stuff
   connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
 
   setDisconnectedState();  // Disable menus and stuff
diff --git a/src/qtui/ui/indicatornotificationconfigwidget.ui b/src/qtui/ui/indicatornotificationconfigwidget.ui
new file mode 100644 (file)
index 0000000..69f2778
--- /dev/null
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>IndicatorNotificationConfigWidget</class>
+ <widget class="QWidget" name="IndicatorNotificationConfigWidget">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>435</width>
+    <height>35</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout_2">
+   <item>
+    <widget class="QCheckBox" name="enabled">
+     <property name="text">
+      <string>Show messages in indicator</string>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <spacer name="verticalSpacer">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>20</width>
+       <height>40</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>