Clementine-audio-player-Mac.../src/osd_x11.cpp

83 lines
2.0 KiB
C++
Raw Normal View History

2010-01-08 15:52:05 +01:00
// Libnotify headers need to go before Qt ones because they use "signals" as
// a variable name
#ifndef NOLIBNOTIFY
# include <libnotify/notify.h>
# include <gdk-pixbuf/gdk-pixbuf.h>
# include <glib.h>
#endif // NOLIBNOTIFY
2010-01-08 15:52:05 +01:00
#include "osd.h"
2010-01-08 17:21:22 +01:00
#include <QCoreApplication>
2010-01-08 15:52:05 +01:00
#include <QtDebug>
#include <QTextDocument>
2010-01-08 15:52:05 +01:00
void OSD::Init() {
2010-01-08 16:16:59 +01:00
notification_ = NULL;
pixbuf_ = NULL;
#ifndef NOLIBNOTIFY
2010-01-08 17:21:22 +01:00
notify_init(QCoreApplication::applicationName().toUtf8().constData());
#endif
2010-01-08 15:52:05 +01:00
}
bool OSD::SupportsNativeNotifications() {
#ifdef NOLIBNOTIFY
return false;
#else
return true;
#endif
}
bool OSD::SupportsTrayPopups() {
2010-02-03 18:21:25 +01:00
return true;
}
void OSD::ShowMessageNative(const QString& summary, const QString& message,
const QString& icon) {
#ifndef NOLIBNOTIFY
2010-01-08 15:52:05 +01:00
if (summary.isNull())
return;
2010-01-08 16:16:59 +01:00
#define STR(x) (x.isNull() ? NULL : x.toUtf8().constData())
2010-01-08 15:52:05 +01:00
notification_ = notify_notification_new(
STR(summary), STR(Qt::escape(message)), STR(icon), NULL);
2010-01-08 16:16:59 +01:00
2010-01-08 17:21:22 +01:00
#undef STR
2010-01-08 16:16:59 +01:00
notify_notification_set_urgency(notification_, NOTIFY_URGENCY_LOW);
2010-01-08 16:37:35 +01:00
notify_notification_set_timeout(notification_, timeout_);
2010-01-08 15:52:05 +01:00
if (pixbuf_) {
notify_notification_set_icon_from_pixbuf(notification_, pixbuf_);
}
2010-01-08 15:52:05 +01:00
GError* error = NULL;
2010-01-08 16:16:59 +01:00
notify_notification_show(notification_, &error);
2010-01-08 15:52:05 +01:00
if (error) {
qDebug() << "Error from notify_notification_show:" << error->message;
g_error_free(error);
}
pixbuf_ = NULL;
#endif // NOLIBNOTIFY
2010-01-08 15:52:05 +01:00
}
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(),
GDK_COLORSPACE_RGB,
false, // has_alpha
8, // bits_per_sample
happy_gdk_image.width(),
happy_gdk_image.height(),
happy_gdk_image.bytesPerLine(),
NULL, NULL);
ShowMessageNative(summary, message, QString());
#endif // NOLIBNOTIFY
}