mirror of
https://github.com/strawberrymusicplayer/strawberry
synced 2025-02-01 10:06:43 +01:00
Add check for desktop notifications service version
This commit is contained in:
parent
28d0cc8795
commit
22bfbab832
@ -35,6 +35,7 @@
|
|||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
#include <QVersionNumber>
|
||||||
#include <QDBusArgument>
|
#include <QDBusArgument>
|
||||||
#include <QDBusConnection>
|
#include <QDBusConnection>
|
||||||
#include <QDBusError>
|
#include <QDBusError>
|
||||||
@ -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();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,13 +116,20 @@ OSDDBus::~OSDDBus() = default;
|
|||||||
|
|
||||||
void OSDDBus::Init() {
|
void OSDDBus::Init() {
|
||||||
|
|
||||||
notification_id_ = 0;
|
|
||||||
|
|
||||||
interface_.reset(new OrgFreedesktopNotificationsInterface(OrgFreedesktopNotificationsInterface::staticInterfaceName(), "/org/freedesktop/Notifications", QDBusConnection::sessionBus()));
|
interface_.reset(new OrgFreedesktopNotificationsInterface(OrgFreedesktopNotificationsInterface::staticInterfaceName(), "/org/freedesktop/Notifications", QDBusConnection::sessionBus()));
|
||||||
if (!interface_->isValid()) {
|
if (!interface_->isValid()) {
|
||||||
qLog(Warning) << "Error connecting to notifications service.";
|
qLog(Warning) << "Error connecting to notifications service.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString vendor, version, spec_version;
|
||||||
|
QDBusReply<QString> 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; }
|
bool OSDDBus::SupportsNativeNotifications() { return true; }
|
||||||
@ -133,8 +141,17 @@ void OSDDBus::ShowMessageNative(const QString &summary, const QString &message,
|
|||||||
if (!interface_) return;
|
if (!interface_) return;
|
||||||
|
|
||||||
QVariantMap hints;
|
QVariantMap hints;
|
||||||
|
|
||||||
if (!image.isNull()) {
|
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);
|
hints["transient"] = QVariant(true);
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QDBusPendingCall>
|
#include <QDBusPendingCall>
|
||||||
#include <QDBusArgument>
|
#include <QDBusArgument>
|
||||||
|
#include <QVersionNumber>
|
||||||
|
|
||||||
#include "osdbase.h"
|
#include "osdbase.h"
|
||||||
|
|
||||||
@ -63,6 +64,7 @@ class OSDDBus : public OSDBase {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<OrgFreedesktopNotificationsInterface> interface_;
|
std::unique_ptr<OrgFreedesktopNotificationsInterface> interface_;
|
||||||
|
QVersionNumber version_;
|
||||||
uint notification_id_;
|
uint notification_id_;
|
||||||
QDateTime last_notification_time_;
|
QDateTime last_notification_time_;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user