diff --git a/src/osd.cpp b/src/osd.cpp index 92bc3309a..faf6cedd8 100644 --- a/src/osd.cpp +++ b/src/osd.cpp @@ -22,8 +22,10 @@ void OSD::ReloadSettings() { behaviour_ = OSD::Behaviour(s.value("Behaviour", Native).toInt()); timeout_ = s.value("Timeout", 5000).toInt(); - if (!CanShowNativeMessages() && behaviour_ == Native) + if (!SupportsNativeNotifications() && behaviour_ == Native) behaviour_ = TrayPopup; + if (!SupportsTrayPopups() && behaviour_ == TrayPopup) + behaviour_ = Disabled; } void OSD::SongChanged(const Song &song) { diff --git a/src/osd.h b/src/osd.h index 1549da398..9975c7d59 100644 --- a/src/osd.h +++ b/src/osd.h @@ -29,6 +29,10 @@ class OSD : public QObject { TrayPopup, }; + // Implemented in the OS-specific files + static bool SupportsNativeNotifications(); + static bool SupportsTrayPopups(); + public slots: void ReloadSettings(); @@ -45,11 +49,9 @@ class OSD : public QObject { // These are implemented in the OS-specific files void Init(); - bool CanShowNativeMessages() const; void ShowMessageNative(const QString& summary, const QString& message = QString(), const QString& icon = QString()); - void ShowMessageNative(const QString& summary, const QString& message, const QImage& image); diff --git a/src/osd_mac.mm b/src/osd_mac.mm index 7d7b70a13..53b1e59ac 100644 --- a/src/osd_mac.mm +++ b/src/osd_mac.mm @@ -110,10 +110,14 @@ void OSD::Init() { wrapper_ = new GrowlNotificationWrapper; } -bool OSD::CanShowNativeMessages() const { +bool OSD::SupportsNativeNotifications() { return true; } +bool OSD::SupportsTrayPopups() { + return false; +} + void OSD::ShowMessageNative(const QString& summary, const QString& message, const QString& icon) { Q_UNUSED(icon); diff --git a/src/osd_win.cpp b/src/osd_win.cpp index 89e33bd38..2b0ce90b0 100644 --- a/src/osd_win.cpp +++ b/src/osd_win.cpp @@ -5,10 +5,14 @@ void OSD::Init() { } -bool OSD::CanShowNativeMessages() const { +bool OSD::SupportsNativeNotifications() { return false; } +bool OSD::SupportsTrayPopups() { + return true; +} + void OSD::ShowMessageNative(const QString&, const QString&, const QString&) { qWarning() << __PRETTY_FUNCTION__ << ": NOT IMPLEMENTED"; diff --git a/src/osd_x11.cpp b/src/osd_x11.cpp index eae7fb06f..a23ec3431 100644 --- a/src/osd_x11.cpp +++ b/src/osd_x11.cpp @@ -1,8 +1,10 @@ // Libnotify headers need to go before Qt ones because they use "signals" as // a variable name -#include -#include -#include +#ifndef NOLIBNOTIFY +# include +# include +# include +#endif // NOLIBNOTIFY #include "osd.h" @@ -13,15 +15,26 @@ void OSD::Init() { notification_ = NULL; pixbuf_ = NULL; +#ifndef NOLIBNOTIFY notify_init(QCoreApplication::applicationName().toUtf8().constData()); +#endif } -bool OSD::CanShowNativeMessages() const { +bool OSD::SupportsNativeNotifications() { +#ifdef NOLIBNOTIFY + return false; +#else + return true; +#endif +} + +bool OSD::SupportsTrayPopups() { return true; } void OSD::ShowMessageNative(const QString& summary, const QString& message, const QString& icon) { +#ifndef NOLIBNOTIFY if (summary.isNull()) return; @@ -47,10 +60,12 @@ void OSD::ShowMessageNative(const QString& summary, const QString& message, } pixbuf_ = NULL; +#endif // NOLIBNOTIFY } void OSD::ShowMessageNative(const QString& summary, const QString& message, const QImage& image) { +#ifndef NOLIBNOTIFY QImage happy_gdk_image = image.convertToFormat(QImage::Format_RGB888).scaledToHeight(100); pixbuf_ = gdk_pixbuf_new_from_data( happy_gdk_image.bits(), @@ -63,4 +78,5 @@ void OSD::ShowMessageNative(const QString& summary, const QString& message, NULL, NULL); ShowMessageNative(summary, message, QString()); +#endif // NOLIBNOTIFY } diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index ef57317ec..b09868e21 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -21,10 +21,10 @@ SettingsDialog::SettingsDialog(QWidget* parent) 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 + if (!OSD::SupportsNativeNotifications()) + ui_.notifications_native->setEnabled(false); + if (!OSD::SupportsTrayPopups()) + ui_.notifications_tray->setEnabled(false); } void SettingsDialog::CurrentTextChanged(const QString &text) { @@ -92,10 +92,24 @@ void SettingsDialog::showEvent(QShowEvent*) { 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::Native: + if (OSD::SupportsNativeNotifications()) { + ui_.notifications_native->setChecked(true); + break; + } + // Fallthrough + + case OSD::TrayPopup: + if (OSD::SupportsTrayPopups()) { + ui_.notifications_tray->setChecked(true); + break; + } + // Fallthrough + case OSD::Disabled: - default: ui_.notifications_none->setChecked(true); break; + default: + ui_.notifications_none->setChecked(true); + break; } ui_.notifications_duration->setValue(s.value("Timeout", 5000).toInt() / 1000); s.endGroup(); diff --git a/src/src.pro b/src/src.pro index 7397366e0..03300b226 100644 --- a/src/src.pro +++ b/src/src.pro @@ -178,10 +178,10 @@ win32|fedora-win32-cross:LIBS += -ltag \ -lpthreadGC2 # OSD -unix:!macx:!fedora-win32-cross { - nolibnotify:SOURCES += osd_win.cpp - !nolibnotify { - SOURCES += osd_x11.cpp +unix:!macx { + nolibnotify:DEFINES += NOLIBNOTIFY + SOURCES += osd_x11.cpp + !nolibnotify { QMAKE_CXXFLAGS += $$system(pkg-config --cflags libnotify) LIBS += $$system(pkg-config --libs libnotify) }