mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Merge pull request #388 from LorenDB/fixBorkedDbus
Keep DBUS from blocking
This commit is contained in:
commit
f47bedff23
2 changed files with 36 additions and 41 deletions
|
@ -47,7 +47,6 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QDBusInterface dbus;
|
QDBusInterface dbus;
|
||||||
uint showNotification(const QString summary, const QString text, const QImage image);
|
|
||||||
void closeNotification(uint id);
|
void closeNotification(uint id);
|
||||||
|
|
||||||
// notification ID to (room ID, event ID)
|
// notification ID to (room ID, event ID)
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
#include "notifications/Manager.h"
|
#include "notifications/Manager.h"
|
||||||
|
|
||||||
|
#include <QDBusConnection>
|
||||||
|
#include <QDBusMessage>
|
||||||
|
#include <QDBusMetaType>
|
||||||
|
#include <QDBusPendingCallWatcher>
|
||||||
|
#include <QDBusPendingReply>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QtDBus/QDBusConnection>
|
|
||||||
#include <QtDBus/QDBusMessage>
|
|
||||||
#include <QtDBus/QDBusMetaType>
|
|
||||||
|
|
||||||
NotificationsManager::NotificationsManager(QObject *parent)
|
NotificationsManager::NotificationsManager(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
|
@ -36,6 +38,12 @@ NotificationsManager::NotificationsManager(QObject *parent)
|
||||||
SLOT(notificationReplied(uint, QString)));
|
SLOT(notificationReplied(uint, QString)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function is based on code from
|
||||||
|
* https://github.com/rohieb/StratumsphereTrayIcon
|
||||||
|
* Copyright (C) 2012 Roland Hieber <rohieb@rohieb.name>
|
||||||
|
* Licensed under the GNU General Public License, version 3
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
NotificationsManager::postNotification(const QString &roomid,
|
NotificationsManager::postNotification(const QString &roomid,
|
||||||
const QString &eventid,
|
const QString &eventid,
|
||||||
|
@ -43,30 +51,16 @@ NotificationsManager::postNotification(const QString &roomid,
|
||||||
const QString &sender,
|
const QString &sender,
|
||||||
const QString &text,
|
const QString &text,
|
||||||
const QImage &icon)
|
const QImage &icon)
|
||||||
{
|
|
||||||
uint id = showNotification(roomname, sender + ": " + text, icon);
|
|
||||||
notificationIds[id] = roomEventId{roomid, eventid};
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* This function is based on code from
|
|
||||||
* https://github.com/rohieb/StratumsphereTrayIcon
|
|
||||||
* Copyright (C) 2012 Roland Hieber <rohieb@rohieb.name>
|
|
||||||
* Licensed under the GNU General Public License, version 3
|
|
||||||
*/
|
|
||||||
uint
|
|
||||||
NotificationsManager::showNotification(const QString summary,
|
|
||||||
const QString text,
|
|
||||||
const QImage image)
|
|
||||||
{
|
{
|
||||||
QVariantMap hints;
|
QVariantMap hints;
|
||||||
hints["image-data"] = image;
|
hints["image-data"] = icon;
|
||||||
hints["sound-name"] = "message-new-instant";
|
hints["sound-name"] = "message-new-instant";
|
||||||
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 << roomname; // summary
|
||||||
argumentList << text; // body
|
argumentList << sender + ": " + text; // body
|
||||||
// The list of actions has always the action name and then a localized version of that
|
// The list of actions has always the action name and then a localized version of that
|
||||||
// action. Currently we just use an empty string for that.
|
// action. Currently we just use an empty string for that.
|
||||||
// TODO(Nico): Look into what to actually put there.
|
// TODO(Nico): Look into what to actually put there.
|
||||||
|
@ -79,31 +73,33 @@ NotificationsManager::showNotification(const QString summary,
|
||||||
static QDBusInterface notifyApp("org.freedesktop.Notifications",
|
static QDBusInterface notifyApp("org.freedesktop.Notifications",
|
||||||
"/org/freedesktop/Notifications",
|
"/org/freedesktop/Notifications",
|
||||||
"org.freedesktop.Notifications");
|
"org.freedesktop.Notifications");
|
||||||
QDBusMessage reply =
|
QDBusPendingCall call = notifyApp.asyncCallWithArgumentList("Notify", argumentList);
|
||||||
notifyApp.callWithArgumentList(QDBus::AutoDetect, "Notify", argumentList);
|
auto watcher = new QDBusPendingCallWatcher{call, this};
|
||||||
if (reply.type() == QDBusMessage::ErrorMessage) {
|
connect(
|
||||||
qDebug() << "D-Bus Error:" << reply.errorMessage();
|
watcher, &QDBusPendingCallWatcher::finished, this, [watcher, this, roomid, eventid]() {
|
||||||
return 0;
|
if (watcher->reply().type() == QDBusMessage::ErrorMessage)
|
||||||
} else {
|
qDebug() << "D-Bus Error:" << watcher->reply().errorMessage();
|
||||||
return reply.arguments().first().toUInt();
|
else
|
||||||
}
|
notificationIds[watcher->reply().arguments().first().toUInt()] =
|
||||||
return true;
|
roomEventId{roomid, eventid};
|
||||||
|
watcher->deleteLater();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
NotificationsManager::closeNotification(uint id)
|
NotificationsManager::closeNotification(uint id)
|
||||||
{
|
{
|
||||||
QList<QVariant> argumentList;
|
|
||||||
argumentList << (uint)id; // replace_id
|
|
||||||
|
|
||||||
static QDBusInterface closeCall("org.freedesktop.Notifications",
|
static QDBusInterface closeCall("org.freedesktop.Notifications",
|
||||||
"/org/freedesktop/Notifications",
|
"/org/freedesktop/Notifications",
|
||||||
"org.freedesktop.Notifications");
|
"org.freedesktop.Notifications");
|
||||||
QDBusMessage reply =
|
auto call = closeCall.asyncCall("CloseNotification", (uint)id); // replace_id
|
||||||
closeCall.callWithArgumentList(QDBus::AutoDetect, "CloseNotification", argumentList);
|
auto watcher = new QDBusPendingCallWatcher{call, this};
|
||||||
if (reply.type() == QDBusMessage::ErrorMessage) {
|
connect(watcher, &QDBusPendingCallWatcher::finished, this, [watcher, this]() {
|
||||||
qDebug() << "D-Bus Error:" << reply.errorMessage();
|
if (watcher->reply().type() == QDBusMessage::ErrorMessage) {
|
||||||
}
|
qDebug() << "D-Bus Error:" << watcher->reply().errorMessage();
|
||||||
|
};
|
||||||
|
watcher->deleteLater();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in a new issue