2010-01-08 15:52:05 +01:00
|
|
|
// Libnotify headers need to go before Qt ones because they use "signals" as
|
|
|
|
// a variable name
|
2010-02-27 01:39:46 +01:00
|
|
|
#ifdef HAVE_LIBNOTIFY
|
2010-02-26 23:37:48 +01:00
|
|
|
# include <libnotify/notify.h>
|
|
|
|
# include <gdk-pixbuf/gdk-pixbuf.h>
|
|
|
|
# include <glib.h>
|
2010-02-27 01:39:46 +01:00
|
|
|
#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>
|
2010-01-08 20:50:29 +01:00
|
|
|
#include <QTextDocument>
|
2010-01-08 15:52:05 +01:00
|
|
|
|
|
|
|
void OSD::Init() {
|
2010-01-08 16:16:59 +01:00
|
|
|
notification_ = NULL;
|
2010-02-24 23:38:35 +01:00
|
|
|
pixbuf_ = NULL;
|
2010-02-27 01:39:46 +01:00
|
|
|
#ifdef HAVE_LIBNOTIFY
|
2010-01-08 17:21:22 +01:00
|
|
|
notify_init(QCoreApplication::applicationName().toUtf8().constData());
|
2010-02-26 23:37:48 +01:00
|
|
|
#endif
|
2010-01-08 15:52:05 +01:00
|
|
|
}
|
|
|
|
|
2010-02-26 23:37:48 +01:00
|
|
|
bool OSD::SupportsNativeNotifications() {
|
2010-02-27 01:39:46 +01:00
|
|
|
#ifdef HAVE_LIBNOTIFY
|
2010-02-26 23:37:48 +01:00
|
|
|
return true;
|
2010-02-27 01:39:46 +01:00
|
|
|
#else
|
|
|
|
return false;
|
2010-02-26 23:37:48 +01:00
|
|
|
#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) {
|
2010-02-27 01:39:46 +01:00
|
|
|
#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
|
|
|
|
2010-02-24 23:38:35 +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
|
|
|
|
2010-02-24 23:38:35 +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);
|
|
|
|
}
|
2010-02-24 23:38:35 +01:00
|
|
|
|
|
|
|
pixbuf_ = NULL;
|
2010-02-27 01:39:46 +01:00
|
|
|
#endif // HAVE_LIBNOTIFY
|
2010-01-08 15:52:05 +01:00
|
|
|
}
|
2010-02-24 22:44:14 +01:00
|
|
|
|
|
|
|
void OSD::ShowMessageNative(const QString& summary, const QString& message,
|
|
|
|
const QImage& image) {
|
2010-02-27 01:39:46 +01:00
|
|
|
#ifdef HAVE_LIBNOTIFY
|
2010-02-28 02:03:13 +01:00
|
|
|
QImage happy_gdk_image = image.scaledToHeight(100, Qt::SmoothTransformation)
|
|
|
|
.convertToFormat(QImage::Format_RGB888);
|
2010-02-24 23:38:35 +01:00
|
|
|
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());
|
2010-02-27 01:39:46 +01:00
|
|
|
#endif // HAVE_LIBNOTIFY
|
2010-02-24 22:44:14 +01:00
|
|
|
}
|