Add TaskbarNotificationBackend
authorManuel Nickschas <sputnick@quassel-irc.org>
Sun, 12 Oct 2008 18:37:10 +0000 (20:37 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sun, 12 Oct 2008 18:38:44 +0000 (20:38 +0200)
This will make the taskbar blink on Wintendo and Linux, and the dock entry bounce on Mac.

src/qtui/CMakeLists.txt
src/qtui/desktopnotificationbackend.cpp
src/qtui/mainwin.cpp
src/qtui/taskbarnotificationbackend.cpp [new file with mode: 0644]
src/qtui/taskbarnotificationbackend.h [new file with mode: 0644]

index 0bf28ee..8411529 100644 (file)
@@ -39,6 +39,7 @@ set(SOURCES
     settingsdlg.cpp
     settingspagedlg.cpp
     systraynotificationbackend.cpp
+    taskbarnotificationbackend.cpp
     titlesetter.cpp
     topiclabel.cpp
     topicwidget.cpp
@@ -72,6 +73,7 @@ set(MOC_HDRS
     settingsdlg.h
     settingspagedlg.h
     systraynotificationbackend.h
+    taskbarnotificationbackend.h
     titlesetter.h
     topiclabel.h
     topicwidget.h
index 45d18b5..d2cf9ed 100644 (file)
@@ -203,7 +203,7 @@ void DesktopNotificationBackend::ConfigWidget::load() {
   NotificationSettings s;
   enabled = s.value("DesktopNotification/Enabled", false).toBool();
   useTimeout = s.value("DesktopNotification/UseTimeout", true).toBool();
-  timeout = s.value("DesktopNotification/Timeout", 10).toInt();
+  timeout = s.value("DesktopNotification/Timeout", 10000).toInt();
   useHints = s.value("DesktopNotification/UseHints", false).toBool();
   xHint = s.value("DesktopNotification/XHint", 0).toInt();
   yHint = s.value("DesktopNotification/YHint", 0).toInt();
index 9cc1c3e..480b331 100644 (file)
@@ -50,6 +50,7 @@
 
 #include "desktopnotificationbackend.h"
 #include "systraynotificationbackend.h"
+#include "taskbarnotificationbackend.h"
 
 #include "settingspages/aliasessettingspage.h"
 #include "settingspages/appearancesettingspage.h"
@@ -87,6 +88,7 @@ MainWin::MainWin(QWidget *parent)
 
   installEventFilter(new JumpKeyHandler(this));
 
+  QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
   QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
 #ifdef HAVE_DBUS
   QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
diff --git a/src/qtui/taskbarnotificationbackend.cpp b/src/qtui/taskbarnotificationbackend.cpp
new file mode 100644 (file)
index 0000000..9b2e2be
--- /dev/null
@@ -0,0 +1,119 @@
+/***************************************************************************
+*   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 "taskbarnotificationbackend.h"
+
+#include <QtGui>
+
+#include "clientsettings.h"
+#include "mainwin.h"
+#include "qtui.h"
+
+TaskbarNotificationBackend::TaskbarNotificationBackend(QObject *parent) : AbstractNotificationBackend(parent) {
+  NotificationSettings notificationSettings;
+  _enabled = notificationSettings.value("Taskbar/Enabled", true).toBool();
+  _timeout = notificationSettings.value("Taskbar/Timeout", 0).toBool();
+
+  notificationSettings.notify("Taskbar/Enabled", this, SLOT(enabledChanged(const QVariant &)));
+  notificationSettings.notify("Taskbar/Timeout", this, SLOT(timeoutChanged(const QVariant &)));
+
+  _configWidget = new ConfigWidget();
+}
+
+TaskbarNotificationBackend::~TaskbarNotificationBackend() {
+  delete _configWidget;
+}
+
+void TaskbarNotificationBackend::notify(const Notification &notification) {
+  Q_UNUSED(notification)
+  if(_enabled) {
+    QApplication::alert(QtUi::mainWindow(), _timeout);
+  }
+}
+
+void TaskbarNotificationBackend::close(uint notificationId) {
+  Q_UNUSED(notificationId);
+}
+
+void TaskbarNotificationBackend::enabledChanged(const QVariant &v) {
+  _enabled = v.toBool();
+}
+
+void TaskbarNotificationBackend::timeoutChanged(const QVariant &v) {
+  _timeout = v.toInt();
+}
+
+SettingsPage *TaskbarNotificationBackend::configWidget() const {
+  return _configWidget;
+}
+
+/***************************************************************************/
+
+TaskbarNotificationBackend::ConfigWidget::ConfigWidget(QWidget *parent) : SettingsPage("Internal", "TaskbarNotification", parent) {
+  QHBoxLayout *layout = new QHBoxLayout(this);
+#ifdef Q_WS_MAC
+  layout->addWidget(enabledBox = new QCheckBox(tr("Activate dock entry, timeout:"), this));
+#else
+  layout->addWidget(enabledBox = new QCheckBox(tr("Mark taskbar entry, timeout:"), this));
+#endif
+  timeoutBox = new QSpinBox(this);
+  timeoutBox->setMinimum(0);
+  timeoutBox->setMaximum(99);
+  timeoutBox->setSpecialValueText(tr("Unlimited"));
+  timeoutBox->setSuffix(tr(" s"));
+  layout->addWidget(timeoutBox);
+  layout->addStretch(1);
+
+  connect(enabledBox, SIGNAL(toggled(bool)), SLOT(widgetChanged()));
+  connect(timeoutBox, SIGNAL(valueChanged(int)), SLOT(widgetChanged()));
+}
+
+void TaskbarNotificationBackend::ConfigWidget::widgetChanged() {
+  bool changed = (enabled != enabledBox->isChecked() || timeout/1000 != timeoutBox->value());
+  if(changed != hasChanged()) setChangedState(changed);
+}
+
+bool TaskbarNotificationBackend::ConfigWidget::hasDefaults() const {
+  return true;
+}
+
+void TaskbarNotificationBackend::ConfigWidget::defaults() {
+  enabledBox->setChecked(true);
+  timeoutBox->setValue(0);
+  widgetChanged();
+}
+
+void TaskbarNotificationBackend::ConfigWidget::load() {
+  NotificationSettings s;
+  enabled = s.value("Taskbar/Enabled", true).toBool();
+  timeout = s.value("Taskbar/Timeout", 0).toInt();
+
+  enabledBox->setChecked(enabled);
+  timeoutBox->setValue(timeout/1000);
+
+  setChangedState(false);
+}
+
+void TaskbarNotificationBackend::ConfigWidget::save() {
+  NotificationSettings s;
+  s.setValue("Taskbar/Enabled", enabledBox->isChecked());
+  s.setValue("Taskbar/Timeout", timeoutBox->value() * 1000);
+  load();
+}
diff --git a/src/qtui/taskbarnotificationbackend.h b/src/qtui/taskbarnotificationbackend.h
new file mode 100644 (file)
index 0000000..e8d0887
--- /dev/null
@@ -0,0 +1,75 @@
+/***************************************************************************
+*   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 TASKBARNOTIFICATIONBACKEND_H_
+#define TASKBARNOTIFICATIONBACKEND_H_
+
+#include "abstractnotificationbackend.h"
+
+#include "settingspage.h"
+
+class QCheckBox;
+class QSpinBox;
+
+class TaskbarNotificationBackend : public AbstractNotificationBackend {
+  Q_OBJECT
+
+public:
+  TaskbarNotificationBackend(QObject *parent = 0);
+  ~TaskbarNotificationBackend();
+
+  void notify(const Notification &);
+  void close(uint notificationId);
+  SettingsPage *configWidget() const;
+
+private slots:
+  void enabledChanged(const QVariant &);
+  void timeoutChanged(const QVariant &);
+
+private:
+  class ConfigWidget;
+
+  SettingsPage *_configWidget;
+  bool _enabled;
+  int _timeout;
+};
+
+class TaskbarNotificationBackend::ConfigWidget : public SettingsPage {
+  Q_OBJECT
+
+public:
+  ConfigWidget(QWidget *parent = 0);
+  void save();
+  void load();
+  bool hasDefaults() const;
+  void defaults();
+
+private slots:
+  void widgetChanged();
+
+private:
+  QCheckBox *enabledBox;
+  QSpinBox *timeoutBox;
+
+  bool enabled;
+  int timeout;
+};
+
+#endif