|
|
@ -1,15 +1,14 @@ |
|
|
|
#include "notifications/Manager.h" |
|
|
|
#include "notifications/Manager.h" |
|
|
|
|
|
|
|
|
|
|
|
#include <QImage> |
|
|
|
|
|
|
|
#include <QDebug> |
|
|
|
#include <QDebug> |
|
|
|
|
|
|
|
#include <QImage> |
|
|
|
|
|
|
|
#include <QtDBus/QDBusConnection> |
|
|
|
#include <QtDBus/QDBusMessage> |
|
|
|
#include <QtDBus/QDBusMessage> |
|
|
|
#include <QtDBus/QDBusMetaType> |
|
|
|
#include <QtDBus/QDBusMetaType> |
|
|
|
#include <QtDBus/QDBusConnection> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NotificationsManager::NotificationsManager(QObject *parent) : |
|
|
|
NotificationsManager::NotificationsManager(QObject *parent) |
|
|
|
QObject(parent), |
|
|
|
: QObject(parent) |
|
|
|
dbus( |
|
|
|
, dbus("org.freedesktop.Notifications", |
|
|
|
"org.freedesktop.Notifications", |
|
|
|
|
|
|
|
"/org/freedesktop/Notifications", |
|
|
|
"/org/freedesktop/Notifications", |
|
|
|
"org.freedesktop.Notifications", |
|
|
|
"org.freedesktop.Notifications", |
|
|
|
QDBusConnection::sessionBus(), |
|
|
|
QDBusConnection::sessionBus(), |
|
|
@ -17,17 +16,13 @@ NotificationsManager::NotificationsManager(QObject *parent) : |
|
|
|
{ |
|
|
|
{ |
|
|
|
qDBusRegisterMetaType<QImage>(); |
|
|
|
qDBusRegisterMetaType<QImage>(); |
|
|
|
|
|
|
|
|
|
|
|
//connectSlot("ActionInvoked", SLOT(actionInvoked(uint, QString)));
|
|
|
|
QDBusConnection::sessionBus().connect("org.freedesktop.Notifications", |
|
|
|
//connectSlot("NotificationClosed", SLOT(notificationClosed(uint, uint)));
|
|
|
|
|
|
|
|
QDBusConnection::sessionBus().connect( |
|
|
|
|
|
|
|
"org.freedesktop.Notifications", |
|
|
|
|
|
|
|
"/org/freedesktop/Notifications", |
|
|
|
"/org/freedesktop/Notifications", |
|
|
|
"org.freedesktop.Notifications", |
|
|
|
"org.freedesktop.Notifications", |
|
|
|
"ActionInvoked", |
|
|
|
"ActionInvoked", |
|
|
|
this, |
|
|
|
this, |
|
|
|
SLOT(actionInvoked(uint, QString))); |
|
|
|
SLOT(actionInvoked(uint, QString))); |
|
|
|
QDBusConnection::sessionBus().connect( |
|
|
|
QDBusConnection::sessionBus().connect("org.freedesktop.Notifications", |
|
|
|
"org.freedesktop.Notifications", |
|
|
|
|
|
|
|
"/org/freedesktop/Notifications", |
|
|
|
"/org/freedesktop/Notifications", |
|
|
|
"org.freedesktop.Notifications", |
|
|
|
"org.freedesktop.Notifications", |
|
|
|
"NotificationClosed", |
|
|
|
"NotificationClosed", |
|
|
@ -43,8 +38,8 @@ NotificationsManager::postNotification(const QString &roomid, |
|
|
|
const QString &text, |
|
|
|
const QString &text, |
|
|
|
const QImage &icon) |
|
|
|
const QImage &icon) |
|
|
|
{ |
|
|
|
{ |
|
|
|
uint id = showNotification(roomname, sender+": "+text, icon); |
|
|
|
uint id = showNotification(roomname, sender + ": " + text, icon); |
|
|
|
notificationIds[id] = roomEventId{roomid,eventid}; |
|
|
|
notificationIds[id] = roomEventId{roomid, eventid}; |
|
|
|
} |
|
|
|
} |
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* This function is based on code from |
|
|
|
* This function is based on code from |
|
|
@ -53,29 +48,28 @@ NotificationsManager::postNotification(const QString &roomid, |
|
|
|
* Licensed under the GNU General Public License, version 3 |
|
|
|
* Licensed under the GNU General Public License, version 3 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
uint |
|
|
|
uint |
|
|
|
NotificationsManager::showNotification(const QString summary, const QString text, const QImage image) |
|
|
|
NotificationsManager::showNotification(const QString summary, |
|
|
|
|
|
|
|
const QString text, |
|
|
|
|
|
|
|
const QImage image) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QVariantMap hints; |
|
|
|
QVariantMap hints; |
|
|
|
hints["image_data"] = image; |
|
|
|
hints["image_data"] = image; |
|
|
|
QList<QVariant> argumentList; |
|
|
|
QList<QVariant> argumentList; |
|
|
|
argumentList << "nheko"; //app_name
|
|
|
|
argumentList << "nheko"; // app_name
|
|
|
|
argumentList << (uint)0; // replace_id
|
|
|
|
argumentList << (uint)0; // replace_id
|
|
|
|
argumentList << ""; // app_icon
|
|
|
|
argumentList << ""; // app_icon
|
|
|
|
argumentList << summary; // summary
|
|
|
|
argumentList << summary; // summary
|
|
|
|
argumentList << text; // body
|
|
|
|
argumentList << text; // body
|
|
|
|
argumentList << (QStringList("default")<<"reply"); // actions
|
|
|
|
argumentList << (QStringList("default") << "reply"); // actions
|
|
|
|
argumentList << hints; // hints
|
|
|
|
argumentList << hints; // hints
|
|
|
|
argumentList << (int)0; // timeout in ms
|
|
|
|
argumentList << (int)0; // timeout in ms
|
|
|
|
|
|
|
|
|
|
|
|
static QDBusInterface notifyApp( |
|
|
|
static QDBusInterface notifyApp("org.freedesktop.Notifications", |
|
|
|
"org.freedesktop.Notifications", |
|
|
|
|
|
|
|
"/org/freedesktop/Notifications", |
|
|
|
"/org/freedesktop/Notifications", |
|
|
|
"org.freedesktop.Notifications"); |
|
|
|
"org.freedesktop.Notifications"); |
|
|
|
QDBusMessage reply = notifyApp.callWithArgumentList( |
|
|
|
QDBusMessage reply = |
|
|
|
QDBus::AutoDetect, |
|
|
|
notifyApp.callWithArgumentList(QDBus::AutoDetect, "Notify", argumentList); |
|
|
|
"Notify", |
|
|
|
if (reply.type() == QDBusMessage::ErrorMessage) { |
|
|
|
argumentList); |
|
|
|
|
|
|
|
if(reply.type() == QDBusMessage::ErrorMessage) { |
|
|
|
|
|
|
|
qDebug() << "D-Bus Error:" << reply.errorMessage(); |
|
|
|
qDebug() << "D-Bus Error:" << reply.errorMessage(); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -109,8 +103,10 @@ NotificationsManager::notificationClosed(uint id, uint reason) |
|
|
|
* |
|
|
|
* |
|
|
|
* Copyright 2010, David Sansome <me@davidsansome.com> |
|
|
|
* Copyright 2010, David Sansome <me@davidsansome.com> |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
QDBusArgument& operator<<(QDBusArgument& arg, const QImage& image) { |
|
|
|
QDBusArgument & |
|
|
|
if(image.isNull()) { |
|
|
|
operator<<(QDBusArgument &arg, const QImage &image) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (image.isNull()) { |
|
|
|
arg.beginStructure(); |
|
|
|
arg.beginStructure(); |
|
|
|
arg << 0 << 0 << 0 << false << 0 << 0 << QByteArray(); |
|
|
|
arg << 0 << 0 << 0 << false << 0 << 0 << QByteArray(); |
|
|
|
arg.endStructure(); |
|
|
|
arg.endStructure(); |
|
|
@ -127,9 +123,9 @@ QDBusArgument& operator<<(QDBusArgument& arg, const QImage& image) { |
|
|
|
// ABGR -> GBAR
|
|
|
|
// ABGR -> GBAR
|
|
|
|
QImage i(scaled.size(), scaled.format()); |
|
|
|
QImage i(scaled.size(), scaled.format()); |
|
|
|
for (int y = 0; y < i.height(); ++y) { |
|
|
|
for (int y = 0; y < i.height(); ++y) { |
|
|
|
QRgb* p = (QRgb*) scaled.scanLine(y); |
|
|
|
QRgb *p = (QRgb *)scaled.scanLine(y); |
|
|
|
QRgb* q = (QRgb*) i.scanLine(y); |
|
|
|
QRgb *q = (QRgb *)i.scanLine(y); |
|
|
|
QRgb* end = p + scaled.width(); |
|
|
|
QRgb *end = p + scaled.width(); |
|
|
|
while (p < end) { |
|
|
|
while (p < end) { |
|
|
|
*q = qRgba(qGreen(*p), qBlue(*p), qAlpha(*p), qRed(*p)); |
|
|
|
*q = qRgba(qGreen(*p), qBlue(*p), qAlpha(*p), qRed(*p)); |
|
|
|
p++; |
|
|
|
p++; |
|
|
@ -146,12 +142,14 @@ QDBusArgument& operator<<(QDBusArgument& arg, const QImage& image) { |
|
|
|
int channels = i.isGrayscale() ? 1 : (i.hasAlphaChannel() ? 4 : 3); |
|
|
|
int channels = i.isGrayscale() ? 1 : (i.hasAlphaChannel() ? 4 : 3); |
|
|
|
arg << i.depth() / channels; |
|
|
|
arg << i.depth() / channels; |
|
|
|
arg << channels; |
|
|
|
arg << channels; |
|
|
|
arg << QByteArray(reinterpret_cast<const char*>(i.bits()), i.byteCount()); |
|
|
|
arg << QByteArray(reinterpret_cast<const char *>(i.bits()), i.byteCount()); |
|
|
|
arg.endStructure(); |
|
|
|
arg.endStructure(); |
|
|
|
return arg; |
|
|
|
return arg; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const QDBusArgument& operator>>(const QDBusArgument& arg, QImage&) { |
|
|
|
const QDBusArgument & |
|
|
|
|
|
|
|
operator>>(const QDBusArgument &arg, QImage &) |
|
|
|
|
|
|
|
{ |
|
|
|
// This is needed to link but shouldn't be called.
|
|
|
|
// This is needed to link but shouldn't be called.
|
|
|
|
Q_ASSERT(0); |
|
|
|
Q_ASSERT(0); |
|
|
|
return arg; |
|
|
|
return arg; |
|
|
|