Add a platform-specific OSD flag for tray-bubble support.
Disable the "native" option on Linux compiled without libnotify. Fixes issue #22
This commit is contained in:
parent
e4a724198a
commit
04fda5badd
|
@ -22,8 +22,10 @@ void OSD::ReloadSettings() {
|
||||||
behaviour_ = OSD::Behaviour(s.value("Behaviour", Native).toInt());
|
behaviour_ = OSD::Behaviour(s.value("Behaviour", Native).toInt());
|
||||||
timeout_ = s.value("Timeout", 5000).toInt();
|
timeout_ = s.value("Timeout", 5000).toInt();
|
||||||
|
|
||||||
if (!CanShowNativeMessages() && behaviour_ == Native)
|
if (!SupportsNativeNotifications() && behaviour_ == Native)
|
||||||
behaviour_ = TrayPopup;
|
behaviour_ = TrayPopup;
|
||||||
|
if (!SupportsTrayPopups() && behaviour_ == TrayPopup)
|
||||||
|
behaviour_ = Disabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSD::SongChanged(const Song &song) {
|
void OSD::SongChanged(const Song &song) {
|
||||||
|
|
|
@ -29,6 +29,10 @@ class OSD : public QObject {
|
||||||
TrayPopup,
|
TrayPopup,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Implemented in the OS-specific files
|
||||||
|
static bool SupportsNativeNotifications();
|
||||||
|
static bool SupportsTrayPopups();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void ReloadSettings();
|
void ReloadSettings();
|
||||||
|
|
||||||
|
@ -45,11 +49,9 @@ class OSD : public QObject {
|
||||||
|
|
||||||
// These are implemented in the OS-specific files
|
// These are implemented in the OS-specific files
|
||||||
void Init();
|
void Init();
|
||||||
bool CanShowNativeMessages() const;
|
|
||||||
void ShowMessageNative(const QString& summary,
|
void ShowMessageNative(const QString& summary,
|
||||||
const QString& message = QString(),
|
const QString& message = QString(),
|
||||||
const QString& icon = QString());
|
const QString& icon = QString());
|
||||||
|
|
||||||
void ShowMessageNative(const QString& summary,
|
void ShowMessageNative(const QString& summary,
|
||||||
const QString& message,
|
const QString& message,
|
||||||
const QImage& image);
|
const QImage& image);
|
||||||
|
|
|
@ -110,10 +110,14 @@ void OSD::Init() {
|
||||||
wrapper_ = new GrowlNotificationWrapper;
|
wrapper_ = new GrowlNotificationWrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OSD::CanShowNativeMessages() const {
|
bool OSD::SupportsNativeNotifications() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool OSD::SupportsTrayPopups() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void OSD::ShowMessageNative(const QString& summary, const QString& message,
|
void OSD::ShowMessageNative(const QString& summary, const QString& message,
|
||||||
const QString& icon) {
|
const QString& icon) {
|
||||||
Q_UNUSED(icon);
|
Q_UNUSED(icon);
|
||||||
|
|
|
@ -5,10 +5,14 @@
|
||||||
void OSD::Init() {
|
void OSD::Init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OSD::CanShowNativeMessages() const {
|
bool OSD::SupportsNativeNotifications() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool OSD::SupportsTrayPopups() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void OSD::ShowMessageNative(const QString&, const QString&,
|
void OSD::ShowMessageNative(const QString&, const QString&,
|
||||||
const QString&) {
|
const QString&) {
|
||||||
qWarning() << __PRETTY_FUNCTION__ << ": NOT IMPLEMENTED";
|
qWarning() << __PRETTY_FUNCTION__ << ": NOT IMPLEMENTED";
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
// Libnotify headers need to go before Qt ones because they use "signals" as
|
// Libnotify headers need to go before Qt ones because they use "signals" as
|
||||||
// a variable name
|
// a variable name
|
||||||
|
#ifndef NOLIBNOTIFY
|
||||||
# include <libnotify/notify.h>
|
# include <libnotify/notify.h>
|
||||||
# include <gdk-pixbuf/gdk-pixbuf.h>
|
# include <gdk-pixbuf/gdk-pixbuf.h>
|
||||||
# include <glib.h>
|
# include <glib.h>
|
||||||
|
#endif // NOLIBNOTIFY
|
||||||
|
|
||||||
#include "osd.h"
|
#include "osd.h"
|
||||||
|
|
||||||
|
@ -13,15 +15,26 @@
|
||||||
void OSD::Init() {
|
void OSD::Init() {
|
||||||
notification_ = NULL;
|
notification_ = NULL;
|
||||||
pixbuf_ = NULL;
|
pixbuf_ = NULL;
|
||||||
|
#ifndef NOLIBNOTIFY
|
||||||
notify_init(QCoreApplication::applicationName().toUtf8().constData());
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSD::ShowMessageNative(const QString& summary, const QString& message,
|
void OSD::ShowMessageNative(const QString& summary, const QString& message,
|
||||||
const QString& icon) {
|
const QString& icon) {
|
||||||
|
#ifndef NOLIBNOTIFY
|
||||||
if (summary.isNull())
|
if (summary.isNull())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -47,10 +60,12 @@ void OSD::ShowMessageNative(const QString& summary, const QString& message,
|
||||||
}
|
}
|
||||||
|
|
||||||
pixbuf_ = NULL;
|
pixbuf_ = NULL;
|
||||||
|
#endif // NOLIBNOTIFY
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSD::ShowMessageNative(const QString& summary, const QString& message,
|
void OSD::ShowMessageNative(const QString& summary, const QString& message,
|
||||||
const QImage& image) {
|
const QImage& image) {
|
||||||
|
#ifndef NOLIBNOTIFY
|
||||||
QImage happy_gdk_image = image.convertToFormat(QImage::Format_RGB888).scaledToHeight(100);
|
QImage happy_gdk_image = image.convertToFormat(QImage::Format_RGB888).scaledToHeight(100);
|
||||||
pixbuf_ = gdk_pixbuf_new_from_data(
|
pixbuf_ = gdk_pixbuf_new_from_data(
|
||||||
happy_gdk_image.bits(),
|
happy_gdk_image.bits(),
|
||||||
|
@ -63,4 +78,5 @@ void OSD::ShowMessageNative(const QString& summary, const QString& message,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
|
|
||||||
ShowMessageNative(summary, message, QString());
|
ShowMessageNative(summary, message, QString());
|
||||||
|
#endif // NOLIBNOTIFY
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,10 +21,10 @@ SettingsDialog::SettingsDialog(QWidget* parent)
|
||||||
connect(ui_.notifications_native, SIGNAL(toggled(bool)), SLOT(NotificationTypeChanged()));
|
connect(ui_.notifications_native, SIGNAL(toggled(bool)), SLOT(NotificationTypeChanged()));
|
||||||
connect(ui_.notifications_tray, SIGNAL(toggled(bool)), SLOT(NotificationTypeChanged()));
|
connect(ui_.notifications_tray, SIGNAL(toggled(bool)), SLOT(NotificationTypeChanged()));
|
||||||
|
|
||||||
#ifdef Q_WS_WIN
|
if (!OSD::SupportsNativeNotifications())
|
||||||
// Sucks to be a windows user
|
|
||||||
ui_.notifications_native->setEnabled(false);
|
ui_.notifications_native->setEnabled(false);
|
||||||
#endif
|
if (!OSD::SupportsTrayPopups())
|
||||||
|
ui_.notifications_tray->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsDialog::CurrentTextChanged(const QString &text) {
|
void SettingsDialog::CurrentTextChanged(const QString &text) {
|
||||||
|
@ -92,10 +92,24 @@ void SettingsDialog::showEvent(QShowEvent*) {
|
||||||
s.beginGroup(OSD::kSettingsGroup);
|
s.beginGroup(OSD::kSettingsGroup);
|
||||||
OSD::Behaviour osd_behaviour = OSD::Behaviour(s.value("Behaviour", OSD::Native).toInt());
|
OSD::Behaviour osd_behaviour = OSD::Behaviour(s.value("Behaviour", OSD::Native).toInt());
|
||||||
switch (osd_behaviour) {
|
switch (osd_behaviour) {
|
||||||
case OSD::Native: ui_.notifications_native->setChecked(true); break;
|
case OSD::Native:
|
||||||
case OSD::TrayPopup: ui_.notifications_tray->setChecked(true); break;
|
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:
|
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);
|
ui_.notifications_duration->setValue(s.value("Timeout", 5000).toInt() / 1000);
|
||||||
s.endGroup();
|
s.endGroup();
|
||||||
|
|
|
@ -178,10 +178,10 @@ win32|fedora-win32-cross:LIBS += -ltag \
|
||||||
-lpthreadGC2
|
-lpthreadGC2
|
||||||
|
|
||||||
# OSD
|
# OSD
|
||||||
unix:!macx:!fedora-win32-cross {
|
unix:!macx {
|
||||||
nolibnotify:SOURCES += osd_win.cpp
|
nolibnotify:DEFINES += NOLIBNOTIFY
|
||||||
!nolibnotify {
|
|
||||||
SOURCES += osd_x11.cpp
|
SOURCES += osd_x11.cpp
|
||||||
|
!nolibnotify {
|
||||||
QMAKE_CXXFLAGS += $$system(pkg-config --cflags libnotify)
|
QMAKE_CXXFLAGS += $$system(pkg-config --cflags libnotify)
|
||||||
LIBS += $$system(pkg-config --libs libnotify)
|
LIBS += $$system(pkg-config --libs libnotify)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue