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:
David Sansome 2010-02-26 22:37:48 +00:00
parent e4a724198a
commit 04fda5badd
7 changed files with 62 additions and 20 deletions

View File

@ -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) {

View File

@ -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);

View File

@ -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);

View File

@ -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";

View File

@ -1,8 +1,10 @@
// Libnotify headers need to go before Qt ones because they use "signals" as
// a variable name
#include <libnotify/notify.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <glib.h>
#ifndef NOLIBNOTIFY
# include <libnotify/notify.h>
# include <gdk-pixbuf/gdk-pixbuf.h>
# include <glib.h>
#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
}

View File

@ -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();

View File

@ -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)
}