From fdf16d0aea614e585d8618883191b840feded4ff Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Mon, 2 Mar 2020 19:55:29 +0400 Subject: [PATCH] Fix notification daemon detection on KDE Minimize usage of QDBusInterface Log the whole notification daemon information --- .../linux/notifications_manager_linux.cpp | 96 +++++++++---------- .../linux/notifications_manager_linux.h | 8 +- 2 files changed, 51 insertions(+), 53 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp index 4f094e591a..0a50d2c2ca 100644 --- a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp @@ -14,7 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "facades.h" #include -#include +#include #include #include #include @@ -113,10 +113,7 @@ QVersionNumber ParseSpecificationVersion( return QVersionNumber(); } -QString GetImageKey() { - const auto specificationVersion = ParseSpecificationVersion( - GetServerInformation()); - +QString GetImageKey(const QVersionNumber &specificationVersion) { if (!specificationVersion.isNull()) { const auto majorVersion = specificationVersion.majorVersion(); const auto minorVersion = specificationVersion.minorVersion(); @@ -141,7 +138,6 @@ QString GetImageKey() { } NotificationData::NotificationData( - not_null notificationInterface, const base::weak_ptr &manager, const QString &title, const QString &subtitle, @@ -149,10 +145,11 @@ NotificationData::NotificationData( PeerId peerId, MsgId msgId, bool hideReplyButton) -: _notificationInterface(notificationInterface) +: _dbusConnection(QDBusConnection::sessionBus()) , _manager(manager) , _title(title) -, _imageKey(GetImageKey()) +, _imageKey(GetImageKey(ParseSpecificationVersion( + GetServerInformation()))) , _peerId(peerId) , _msgId(msgId) { const auto capabilities = GetCapabilities(); @@ -172,7 +169,7 @@ NotificationData::NotificationData( if (capabilities.contains(qsl("actions"))) { _actions << qsl("default") << QString(); - _notificationInterface->connection().connect( + _dbusConnection.connect( kService.utf16(), kObjectPath.utf16(), kInterface.utf16(), @@ -181,10 +178,11 @@ NotificationData::NotificationData( SLOT(notificationClicked(uint,QString))); if (capabilities.contains(qsl("inline-reply")) && !hideReplyButton) { - _actions << qsl("inline-reply") + _actions + << qsl("inline-reply") << tr::lng_notification_reply(tr::now); - _notificationInterface->connection().connect( + _dbusConnection.connect( kService.utf16(), kObjectPath.utf16(), kInterface.utf16(), @@ -193,7 +191,8 @@ NotificationData::NotificationData( SLOT(notificationReplied(uint,QString))); } else { // icon name according to https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html - _actions << qsl("mail-reply-sender") + _actions + << qsl("mail-reply-sender") << tr::lng_notification_reply(tr::now); } } @@ -219,7 +218,7 @@ NotificationData::NotificationData( _hints["category"] = qsl("im.received"); _hints["desktop-entry"] = GetLauncherBasename(); - _notificationInterface->connection().connect( + _dbusConnection.connect( kService.utf16(), kObjectPath.utf16(), kInterface.utf16(), @@ -233,8 +232,13 @@ bool NotificationData::show() { ? GetIconName() : QString(); - const QDBusReply reply = _notificationInterface->call( - qsl("Notify"), + auto message = QDBusMessage::createMethodCall( + kService.utf16(), + kObjectPath.utf16(), + kInterface.utf16(), + qsl("Notify")); + + message.setArguments({ AppName.utf16(), uint(0), iconName, @@ -242,7 +246,11 @@ bool NotificationData::show() { _body, _actions, _hints, - -1); + -1 + }); + + const QDBusReply reply = _dbusConnection.call( + message); if (reply.isValid()) { _notificationId = reply.value(); @@ -253,16 +261,18 @@ bool NotificationData::show() { return reply.isValid(); } -bool NotificationData::close() { - const QDBusReply reply = _notificationInterface->call( - qsl("CloseNotification"), - _notificationId); +void NotificationData::close() { + auto message = QDBusMessage::createMethodCall( + kService.utf16(), + kObjectPath.utf16(), + kInterface.utf16(), + qsl("CloseNotification")); - if (!reply.isValid()) { - LOG(("Native notification error: %1").arg(reply.error().message())); - } + message.setArguments({ + _notificationId + }); - return reply.isValid(); + _dbusConnection.send(message); } void NotificationData::setImage(const QString &imagePath) { @@ -331,7 +341,8 @@ QDBusArgument &operator<<( QDBusArgument &argument, const NotificationData::ImageData &imageData) { argument.beginStructure(); - argument << imageData.width + argument + << imageData.width << imageData.height << imageData.rowStride << imageData.hasAlpha @@ -346,7 +357,8 @@ const QDBusArgument &operator>>( const QDBusArgument &argument, NotificationData::ImageData &imageData) { argument.beginStructure(); - argument >> imageData.width + argument + >> imageData.width >> imageData.height >> imageData.rowStride >> imageData.hasAlpha @@ -380,12 +392,7 @@ bool SkipToast() { bool Supported() { #ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION - static const auto Available = QDBusInterface( - kService.utf16(), - kObjectPath.utf16(), - kInterface.utf16() - ).isValid(); - + static const auto Available = !GetServerInformation().empty(); return Available; #else // !TDESKTOP_DISABLE_DBUS_INTEGRATION return false; @@ -405,27 +412,21 @@ std::unique_ptr Create( #ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION Manager::Private::Private(not_null manager, Type type) : _cachedUserpics(type) -, _manager(manager) -, _notificationInterface( - std::make_shared( - kService.utf16(), - kObjectPath.utf16(), - kInterface.utf16())) { +, _manager(manager) { qDBusRegisterMetaType(); - const auto specificationVersion = ParseSpecificationVersion( - GetServerInformation()); - + const auto serverInformation = GetServerInformation(); const auto capabilities = GetCapabilities(); - if (!specificationVersion.isNull()) { - LOG(("Notification daemon specification version: %1") - .arg(specificationVersion.toString())); + if (!serverInformation.empty()) { + LOG(("Notification daemon product name: %1").arg(serverInformation[0])); + LOG(("Notification daemon vendor name: %1").arg(serverInformation[1])); + LOG(("Notification daemon version: %1").arg(serverInformation[2])); + LOG(("Notification daemon specification version: %1").arg(serverInformation[3])); } - if (!capabilities.empty()) { - const auto capabilitiesString = capabilities.join(", "); - LOG(("Notification daemon capabilities: %1").arg(capabilitiesString)); + if (!capabilities.isEmpty()) { + LOG(("Notification daemon capabilities: %1").arg(capabilities.join(", "))); } } @@ -438,7 +439,6 @@ void Manager::Private::showNotification( bool hideNameAndPhoto, bool hideReplyButton) { auto notification = std::make_shared( - _notificationInterface.get(), _manager, title, subtitle, diff --git a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.h b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.h index 2cd5ba9534..d22a02f117 100644 --- a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.h +++ b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.h @@ -12,7 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/weak_ptr.h" #ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION -#include +#include #include #endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION @@ -28,7 +28,6 @@ class NotificationData : public QObject { public: NotificationData( - not_null notificationInterface, const base::weak_ptr &manager, const QString &title, const QString &subtitle, @@ -43,7 +42,7 @@ public: NotificationData &operator=(NotificationData &&other) = delete; bool show(); - bool close(); + void close(); void setImage(const QString &imagePath); struct ImageData { @@ -54,7 +53,7 @@ public: }; private: - const not_null _notificationInterface; + QDBusConnection _dbusConnection; base::weak_ptr _manager; QString _title; @@ -134,7 +133,6 @@ private: Window::Notifications::CachedUserpics _cachedUserpics; base::weak_ptr _manager; - std::shared_ptr _notificationInterface; }; #endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION