1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-18 12:28:31 +01:00

Notifications settings

This commit is contained in:
David Sansome 2010-02-03 17:21:25 +00:00
parent b0cad6cee9
commit 4aa1cdfa52
10 changed files with 218 additions and 16 deletions

View File

@ -55,5 +55,6 @@
<file>web.png</file>
<file>library.png</file>
<file>media-playback-start-32.png</file>
<file>lightbulb.png</file>
</qresource>
</RCC>

BIN
data/lightbulb.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -228,6 +228,7 @@ MainWindow::MainWindow(QWidget *parent)
// Settings
connect(settings_dialog_, SIGNAL(accepted()), player_, SLOT(ReloadSettings()));
connect(settings_dialog_, SIGNAL(accepted()), osd_, SLOT(ReloadSettings()));
// Analyzer
ui_.analyzer->set_engine(player_->GetEngine());

View File

@ -2,15 +2,30 @@
#include <QCoreApplication>
#include <QtDebug>
#include <QSettings>
const char* OSD::kSettingsGroup = "OSD";
OSD::OSD(QSystemTrayIcon* tray_icon, QObject* parent)
: QObject(parent),
tray_icon_(tray_icon),
timeout_(5000)
timeout_(5000),
behaviour_(Native)
{
ReloadSettings();
Init();
}
void OSD::ReloadSettings() {
QSettings s;
s.beginGroup(kSettingsGroup);
behaviour_ = OSD::Behaviour(s.value("Behaviour", Native).toInt());
timeout_ = s.value("Timeout", 5000).toInt();
if (!CanShowNativeMessages() && behaviour_ == Native)
behaviour_ = TrayPopup;
}
void OSD::SongChanged(const Song &song) {
QString summary(song.PrettyTitle());
if (!song.artist().isNull())
@ -38,3 +53,21 @@ void OSD::Stopped() {
void OSD::VolumeChanged(int value) {
ShowMessage(QCoreApplication::applicationName(), QString("Volume %1%").arg(value));
}
void OSD::ShowMessage(const QString& summary,
const QString& message,
const QString& icon) {
switch (behaviour_) {
case Native:
ShowMessageNative(summary, message, icon);
break;
case TrayPopup:
tray_icon_->showMessage(summary, message, QSystemTrayIcon::NoIcon, timeout_);
break;
case Disabled:
default:
break;
}
}

View File

@ -19,20 +19,38 @@ class OSD : public QObject {
public:
OSD(QSystemTrayIcon* tray_icon, QObject* parent = 0);
void Init();
void ShowMessage(const QString& summary,
const QString& message = QString::null,
const QString& icon = QString::null);
static const char* kSettingsGroup;
enum Behaviour {
Disabled = 0,
Native,
TrayPopup,
};
public slots:
void ReloadSettings();
void SongChanged(const Song& song);
void Paused();
void Stopped();
void VolumeChanged(int value);
private:
void ShowMessage(const QString& summary,
const QString& message = QString::null,
const QString& icon = QString::null);
// These are implemented in the OS-specific files
void Init();
bool CanShowNativeMessages() const;
void ShowMessageNative(const QString& summary,
const QString& message = QString::null,
const QString& icon = QString::null);
private:
QSystemTrayIcon* tray_icon_;
int timeout_;
Behaviour behaviour_;
#ifdef Q_WS_X11
NotifyNotification* notification_;

View File

@ -5,7 +5,12 @@
void OSD::Init() {
}
void OSD::ShowMessage(const QString& summary, const QString& message,
const QString& icon) {
bool OSD::CanShowNativeMessages() const {
return true;
}
void OSD::ShowMessageNative(const QString& summary, const QString& message,
const QString& icon) {
// This should use growl
tray_icon_->showMessage(summary, message, QSystemTrayIcon::NoIcon, timeout_);
}

View File

@ -14,8 +14,12 @@ void OSD::Init() {
notify_init(QCoreApplication::applicationName().toUtf8().constData());
}
void OSD::ShowMessage(const QString& summary, const QString& message,
const QString& icon) {
bool OSD::CanShowNativeMessages() const {
return true;
}
void OSD::ShowMessageNative(const QString& summary, const QString& message,
const QString& icon) {
if (summary.isNull())
return;

View File

@ -1,5 +1,6 @@
#include "settingsdialog.h"
#include "enginebase.h"
#include "osd.h"
#include <QSettings>
@ -8,8 +9,19 @@ SettingsDialog::SettingsDialog(QWidget* parent)
{
ui_.setupUi(this);
// List box
connect(ui_.list, SIGNAL(currentTextChanged(QString)), SLOT(CurrentTextChanged(QString)));
ui_.list->setCurrentRow(0);
// Notifications
connect(ui_.notifications_none, SIGNAL(toggled(bool)), SLOT(NotificationTypeChanged()));
connect(ui_.notifications_native, SIGNAL(toggled(bool)), SLOT(NotificationTypeChanged()));
connect(ui_.notifications_tray, SIGNAL(toggled(bool)), SLOT(NotificationTypeChanged()));
#ifdef Q_WS_WIN
// Sucks to be a windows user
ui_.notifications_native->setEnabled(false);
#endif
}
void SettingsDialog::CurrentTextChanged(const QString &text) {
@ -29,6 +41,17 @@ void SettingsDialog::accept() {
s.setValue("FadeoutDuration", ui_.fadeout_duration->value());
s.endGroup();
// Notifications
OSD::Behaviour osd_behaviour;
if (ui_.notifications_none->isChecked()) osd_behaviour = OSD::Disabled;
else if (ui_.notifications_native->isChecked()) osd_behaviour = OSD::Native;
else if (ui_.notifications_tray->isChecked()) osd_behaviour = OSD::TrayPopup;
s.beginGroup(OSD::kSettingsGroup);
s.setValue("Behaviour", int(osd_behaviour));
s.setValue("Timeout", ui_.notifications_duration->value() * 1000);
s.endGroup();
QDialog::accept();
}
@ -43,4 +66,20 @@ void SettingsDialog::showEvent(QShowEvent*) {
ui_.no_fadeout->setChecked(true);
ui_.fadeout_duration->setValue(s.value("FadeoutDuration", 2000).toInt());
s.endGroup();
// Notifications
s.beginGroup(OSD::kSettingsGroup);
OSD::Behaviour osd_behaviour = OSD::Behaviour(s.value("Behaviour", OSD::Native).toInt());
switch (osd_behaviour) {
case OSD::Native: ui_.notifications_native->setChecked(true); break;
case OSD::TrayPopup: ui_.notifications_tray->setChecked(true); break;
case OSD::Disabled:
default: ui_.notifications_none->setChecked(true); break;
}
ui_.notifications_duration->setValue(s.value("Timeout", 5000).toInt() / 1000);
s.endGroup();
}
void SettingsDialog::NotificationTypeChanged() {
ui_.notifications_options->setEnabled(!ui_.notifications_none->isChecked());
}

View File

@ -23,6 +23,7 @@ class SettingsDialog : public QDialog {
private slots:
void CurrentTextChanged(const QString& text);
void NotificationTypeChanged();
private:
Ui::SettingsDialog ui_;

View File

@ -51,16 +51,25 @@
<string>Playback</string>
</property>
<property name="icon">
<iconset resource="../data/data.qrc">
<iconset>
<normaloff>:/media-playback-start-32.png</normaloff>:/media-playback-start-32.png</iconset>
</property>
</item>
<item>
<property name="text">
<string>Notifications</string>
</property>
<property name="icon">
<iconset>
<normaloff>:/lightbulb.png</normaloff>:/lightbulb.png</iconset>
</property>
</item>
<item>
<property name="text">
<string>Music Library</string>
</property>
<property name="icon">
<iconset resource="../data/data.qrc">
<iconset>
<normaloff>:/library.png</normaloff>:/library.png</iconset>
</property>
</item>
@ -69,7 +78,7 @@
<string>Last.fm</string>
</property>
<property name="icon">
<iconset resource="../data/data.qrc">
<iconset>
<normaloff>:/last.fm/as.png</normaloff>:/last.fm/as.png</iconset>
</property>
</item>
@ -90,7 +99,7 @@
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="page">
<layout class="QVBoxLayout" name="verticalLayout_2">
@ -186,6 +195,99 @@
<zorder>groupBox</zorder>
<zorder>verticalSpacer</zorder>
</widget>
<widget class="QWidget" name="page_4">
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Clementine can show a message when the track changes.</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="notifications_none">
<property name="text">
<string>Don't show notifications</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="notifications_native">
<property name="text">
<string>Show a native desktop notification</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="notifications_tray">
<property name="text">
<string>Show a popup from the system tray</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>4</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QWidget" name="notifications_options" native="true">
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Popup duration</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="notifications_duration">
<property name="suffix">
<string> seconds</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>20</number>
</property>
<property name="value">
<number>5</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>286</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_2">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="margin">
@ -232,9 +334,7 @@
<tabstop>fadeout_duration</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources>
<include location="../data/data.qrc"/>
</resources>
<resources/>
<connections>
<connection>
<sender>list</sender>