From: Manuel Nickschas Date: Sun, 12 Oct 2008 18:37:10 +0000 (+0200) Subject: Add TaskbarNotificationBackend X-Git-Tag: 0.3.1~175 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=c80ab2e825ff9125c1c7e8e829487a4b1c118579 Add TaskbarNotificationBackend This will make the taskbar blink on Wintendo and Linux, and the dock entry bounce on Mac. --- diff --git a/src/qtui/CMakeLists.txt b/src/qtui/CMakeLists.txt index 0bf28eee..84115296 100644 --- a/src/qtui/CMakeLists.txt +++ b/src/qtui/CMakeLists.txt @@ -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 diff --git a/src/qtui/desktopnotificationbackend.cpp b/src/qtui/desktopnotificationbackend.cpp index 45d18b59..d2cf9ed8 100644 --- a/src/qtui/desktopnotificationbackend.cpp +++ b/src/qtui/desktopnotificationbackend.cpp @@ -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(); diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index 9cc1c3e0..480b3316 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -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 index 00000000..9b2e2be1 --- /dev/null +++ b/src/qtui/taskbarnotificationbackend.cpp @@ -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 + +#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 ¬ification) { + 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 index 00000000..e8d08877 --- /dev/null +++ b/src/qtui/taskbarnotificationbackend.h @@ -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