From 4aa1cdfa52c2a1e6aefa34e3707f5bd7b2bb91a1 Mon Sep 17 00:00:00 2001 From: David Sansome Date: Wed, 3 Feb 2010 17:21:25 +0000 Subject: [PATCH] Notifications settings --- data/data.qrc | 1 + data/lightbulb.png | Bin 0 -> 1641 bytes src/mainwindow.cpp | 1 + src/osd.cpp | 35 ++++++++++++- src/osd.h | 26 ++++++++-- src/osd_mac.cpp | 9 +++- src/osd_x11.cpp | 8 ++- src/settingsdialog.cpp | 39 ++++++++++++++ src/settingsdialog.h | 1 + src/settingsdialog.ui | 114 ++++++++++++++++++++++++++++++++++++++--- 10 files changed, 218 insertions(+), 16 deletions(-) create mode 100644 data/lightbulb.png 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 0000000000000000000000000000000000000000..209f1d28c8ce13db65dd975598913501cb1bbd97 GIT binary patch literal 1641 zcmV-v2A27WP)Eyh)6Gs@ zkuH#=l-3Vj=tBr?aOgrIebHNKUeXuSHqbT@2!=vwFqBgK(n6XND2+?n*xB65R%I!c zEJasWSJK>V*7JR3lvk7V-devo-{C9+^W$SU3yBE&Vs>1~WBzdl`_>`vO$=Yn(FeT= zTsd0J!|*geF-0XPEei}QHlu!5D9h>f=D5v z(44pM#t%qrb6Gzad>#WUj1NHJL*Tz1JS*Mkk!$0hJIInfzkBttS zdJ%2*E3JI;%NrEMC-N)#Pw*jVd;s$1kuli`pUJAjYvNilnRO;600g4jyf3>o*mFAh zz_8I_bL6Si&y&+;EkR0#wn#V@pUoT^|qBR5R|W=2m+GZC_qdsEK8x9cvQ*C ztAnVo{RY4TeF-20K!n6}44Xzq#cc3^ zi>Z53di$9p`1hobkG>oA^bg1zN5{x;nFc>)LpHmFj4ki5Me-G>qO_+PjU5^us5ONg6~|;bbhArT)*wwNO)$d0-raKsNLlkBkZHZr zAUp1Y1X|{sjmA)ExY~(a2n?$yCv-fqN z;#{FDbC4{gVzzT42q}PIgpe~4bESfGtHXLAh>~Ki-PN|ETPX;DbaRR4nrK}ISv1$P z0NuN|NLtmcxa$)$2m%6Ru+oZ_*Tg3haXsR4+0Bb~HxlL8#sGq%k8C63)t{|X_^*sC z{GqRvkV^iq)z;RS%2OMF6h#pWGj_XFJZg7b-rLCCeU&5uiJ-uwO6}B!;M;%3$(6J} zfvofk%9EU0VHKP!K%|HRqa4pKMqbe-Frt)|w!j1yD#XNqI;}vp!U_fcZ2x<~=Wb+F z9hg;H^@EheE`)a-JXd(Vx!=FB>X)vrx}|IHmdcZdR3su0VMr1?s$M$?-+uuoS8D(F zZYVDgy~IIqfIo8As&bqhMAGVNT`6-;AT&a44^^`ag+OK$)oY_v-zd>cc8|5G|He%AQutjm?QM0*^v^9rME;sf>;PvH^i{onJTUg$_*OL|*TO%Ms znSsunfh65L_9ven1+XUqKYnqdwswo1r=I*OMu$AiUw#$L2FFj#;ERtwj>pdaP=Dd! zGnb#(D*-lUrPYb~?S&mRIdvHM{)a#yln$N5%9g@*GeHzZx6lI$y+Fw0Bte>{@IAjU zf~7U?zyAbU%_i#gI@;~FgT2ZCfl`wjilP`vnqYZ(8QS#$0!l#uOQ|9Q_MT;+I0AW| zmz9DN3LgLV6R7SR0yAT2X$g(3h7eJ6&+di=r$2q_*iP7d>DaMj<3TBa6k=KdfiySY ns8$E)H%9 literal 0 HcmV?d00001 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