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

84 lines
2.1 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
#ifdef HAVE_LIBNOTIFY
# include <libnotify/notify.h>
# include <gdk-pixbuf/gdk-pixbuf.h>
# include <glib.h>
#endif // HAVE_LIBNOTIFY
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;
#ifdef HAVE_LIBNOTIFY
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 HAVE_LIBNOTIFY
return true;
#else
return false;
#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) {
#ifdef HAVE_LIBNOTIFY
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 // HAVE_LIBNOTIFY
2010-01-08 15:52:05 +01:00
}
void OSD::ShowMessageNative(const QString& summary, const QString& message,
const QImage& image) {
#ifdef HAVE_LIBNOTIFY
QImage happy_gdk_image = image.scaledToHeight(100, Qt::SmoothTransformation)
.convertToFormat(QImage::Format_RGB888);
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 // HAVE_LIBNOTIFY
}