From 22bfbab8322258df6891a8f00deb75c98e441cc4 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sun, 4 Oct 2020 04:38:46 +0200 Subject: [PATCH] Add check for desktop notifications service version --- src/osd/osddbus.cpp | 25 +++++++++++++++++++++---- src/osd/osddbus.h | 2 ++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/osd/osddbus.cpp b/src/osd/osddbus.cpp index c413d6a06..5b6fd8af4 100644 --- a/src/osd/osddbus.cpp +++ b/src/osd/osddbus.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -107,7 +108,7 @@ const QDBusArgument &operator>>(const QDBusArgument &arg, QImage &image) { } -OSDDBus::OSDDBus(SystemTrayIcon *tray_icon, Application *app, QObject *parent) : OSDBase(tray_icon, app, parent) { +OSDDBus::OSDDBus(SystemTrayIcon *tray_icon, Application *app, QObject *parent) : OSDBase(tray_icon, app, parent), version_(1, 1), notification_id_(0) { Init(); } @@ -115,13 +116,20 @@ OSDDBus::~OSDDBus() = default; void OSDDBus::Init() { - notification_id_ = 0; - interface_.reset(new OrgFreedesktopNotificationsInterface(OrgFreedesktopNotificationsInterface::staticInterfaceName(), "/org/freedesktop/Notifications", QDBusConnection::sessionBus())); if (!interface_->isValid()) { qLog(Warning) << "Error connecting to notifications service."; } + QString vendor, version, spec_version; + QDBusReply reply = interface_->GetServerInformation(vendor, version, spec_version); + if (reply.isValid()) { + version_ = QVersionNumber::fromString(spec_version); + } + else { + qLog(Error) << "Could not retrieve notification server information." << reply.error(); + } + } bool OSDDBus::SupportsNativeNotifications() { return true; } @@ -133,8 +141,17 @@ void OSDDBus::ShowMessageNative(const QString &summary, const QString &message, if (!interface_) return; QVariantMap hints; + if (!image.isNull()) { - hints["image_data"] = QVariant(image); + if (version_ >= QVersionNumber(1, 2)) { + hints["image-data"] = QVariant(image); + } + else if (version_ >= QVersionNumber(1, 1)) { + hints["image_data"] = QVariant(image); + } + else { + hints["icon_data"] = QVariant(image); + } } hints["transient"] = QVariant(true); diff --git a/src/osd/osddbus.h b/src/osd/osddbus.h index d9da2d370..ac03dc2f9 100644 --- a/src/osd/osddbus.h +++ b/src/osd/osddbus.h @@ -33,6 +33,7 @@ #include #include #include +#include #include "osdbase.h" @@ -63,6 +64,7 @@ class OSDDBus : public OSDBase { private: std::unique_ptr interface_; + QVersionNumber version_; uint notification_id_; QDateTime last_notification_time_;