mirror of
https://github.com/strawberrymusicplayer/strawberry
synced 2025-01-20 21:00:46 +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 <QImage>
|
||||
#include <QCoreApplication>
|
||||
#include <QVersionNumber>
|
||||
#include <QDBusArgument>
|
||||
#include <QDBusConnection>
|
||||
#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();
|
||||
}
|
||||
|
||||
@ -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<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; }
|
||||
@ -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);
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include <QImage>
|
||||
#include <QDBusPendingCall>
|
||||
#include <QDBusArgument>
|
||||
#include <QVersionNumber>
|
||||
|
||||
#include "osdbase.h"
|
||||
|
||||
@ -63,6 +64,7 @@ class OSDDBus : public OSDBase {
|
||||
|
||||
private:
|
||||
std::unique_ptr<OrgFreedesktopNotificationsInterface> interface_;
|
||||
QVersionNumber version_;
|
||||
uint notification_id_;
|
||||
QDateTime last_notification_time_;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user