diff --git a/data/data.qrc b/data/data.qrc
index 02a4e0612..dd91d0c34 100644
--- a/data/data.qrc
+++ b/data/data.qrc
@@ -55,5 +55,6 @@
web.png
library.png
media-playback-start-32.png
+ lightbulb.png
diff --git a/data/lightbulb.png b/data/lightbulb.png
new file mode 100644
index 000000000..209f1d28c
Binary files /dev/null and b/data/lightbulb.png differ
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 445c332dc..eeb320b28 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -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());
diff --git a/src/osd.cpp b/src/osd.cpp
index 71e1b54e9..a7e5593e3 100644
--- a/src/osd.cpp
+++ b/src/osd.cpp
@@ -2,15 +2,30 @@
#include
#include
+#include
+
+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;
+ }
+}
diff --git a/src/osd.h b/src/osd.h
index 0ad941fbb..4619d2404 100644
--- a/src/osd.h
+++ b/src/osd.h
@@ -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_;
diff --git a/src/osd_mac.cpp b/src/osd_mac.cpp
index e85e050ef..e80458546 100644
--- a/src/osd_mac.cpp
+++ b/src/osd_mac.cpp
@@ -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_);
}
diff --git a/src/osd_x11.cpp b/src/osd_x11.cpp
index fa47a368c..cbdbe37c8 100644
--- a/src/osd_x11.cpp
+++ b/src/osd_x11.cpp
@@ -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;
diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp
index e1d523f92..de1efdcd9 100644
--- a/src/settingsdialog.cpp
+++ b/src/settingsdialog.cpp
@@ -1,5 +1,6 @@
#include "settingsdialog.h"
#include "enginebase.h"
+#include "osd.h"
#include
@@ -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());
}
diff --git a/src/settingsdialog.h b/src/settingsdialog.h
index f289b2339..7fe1ad274 100644
--- a/src/settingsdialog.h
+++ b/src/settingsdialog.h
@@ -23,6 +23,7 @@ class SettingsDialog : public QDialog {
private slots:
void CurrentTextChanged(const QString& text);
+ void NotificationTypeChanged();
private:
Ui::SettingsDialog ui_;
diff --git a/src/settingsdialog.ui b/src/settingsdialog.ui
index 84a547391..8ba14d357 100644
--- a/src/settingsdialog.ui
+++ b/src/settingsdialog.ui
@@ -51,16 +51,25 @@
Playback
-
+
:/media-playback-start-32.png:/media-playback-start-32.png
+ -
+
+ Notifications
+
+
+
+ :/lightbulb.png:/lightbulb.png
+
+
-
Music Library
-
+
:/library.png:/library.png
@@ -69,7 +78,7 @@
Last.fm
-
+
:/last.fm/as.png:/last.fm/as.png
@@ -90,7 +99,7 @@
-
- 0
+ 1
@@ -186,6 +195,99 @@
groupBox
verticalSpacer
+
+
+
+ 0
+
+
-
+
+
+ Clementine can show a message when the track changes.
+
+
+
+ -
+
+
+ Don't show notifications
+
+
+
+ -
+
+
+ Show a native desktop notification
+
+
+
+ -
+
+
+ Show a popup from the system tray
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+ QSizePolicy::Fixed
+
+
+
+ 20
+ 4
+
+
+
+
+ -
+
+
+
-
+
+
+ Popup duration
+
+
+
+ -
+
+
+ seconds
+
+
+ 1
+
+
+ 20
+
+
+ 5
+
+
+
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 286
+
+
+
+
+
+
@@ -232,9 +334,7 @@
fadeout_duration
buttonBox
-
-
-
+
list