From 74942cd06ea5caaa925e15ad0c6939e871d706ca Mon Sep 17 00:00:00 2001
From: Ilya Fedin <fedin-ilja2010@ya.ru>
Date: Fri, 24 Jan 2020 23:55:01 +0400
Subject: [PATCH] Use QDBusConnection::connect to fix signal connection on old
 distributions

---
 .../linux/notifications_manager_linux.cpp     | 67 ++++++++++++-------
 1 file changed, 44 insertions(+), 23 deletions(-)

diff --git a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp
index 794b205ef..a10314e75 100644
--- a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp
+++ b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp
@@ -13,7 +13,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 
 #ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
 #include <QtCore/QVersionNumber>
-#include <QtDBus/QDBusConnection>
 #include <QtDBus/QDBusReply>
 #include <QtDBus/QDBusMetaType>
 #endif
@@ -31,7 +30,7 @@ constexpr auto kInterface = kService;
 std::vector<QString> GetServerInformation(
 		const std::shared_ptr<QDBusInterface> &notificationInterface) {
 	std::vector<QString> serverInformation;
-	auto serverInformationReply = notificationInterface
+	const auto serverInformationReply = notificationInterface
 		->call(qsl("GetServerInformation"));
 
 	if (serverInformationReply.type() == QDBusMessage::ReplyMessage) {
@@ -58,7 +57,7 @@ std::vector<QString> GetServerInformation(
 
 QStringList GetCapabilities(
 		const std::shared_ptr<QDBusInterface> &notificationInterface) {
-	QDBusReply<QStringList> capabilitiesReply = notificationInterface
+	const QDBusReply<QStringList> capabilitiesReply = notificationInterface
 		->call(qsl("GetCapabilities"));
 
 	if (capabilitiesReply.isValid()) {
@@ -95,7 +94,7 @@ NotificationData::NotificationData(
 , _title(title)
 , _peerId(peerId)
 , _msgId(msgId) {
-	auto capabilities = GetCapabilities(_notificationInterface);
+	const auto capabilities = GetCapabilities(_notificationInterface);
 
 	if (capabilities.contains(qsl("body-markup"))) {
 		_body = subtitle.isEmpty()
@@ -112,17 +111,25 @@ NotificationData::NotificationData(
 	if (capabilities.contains(qsl("actions"))) {
 		_actions << qsl("default") << QString();
 
-		connect(_notificationInterface.get(),
-			SIGNAL(ActionInvoked(uint, QString)),
-			this, SLOT(notificationClicked(uint)));
+		_notificationInterface->connection().connect(
+			str_const_toString(kService),
+			str_const_toString(kObjectPath),
+			str_const_toString(kInterface),
+			qsl("ActionInvoked"),
+			this,
+			SLOT(notificationClicked(uint)));
 
 		if (capabilities.contains(qsl("inline-reply"))) {
 			_actions << qsl("inline-reply")
 				<< tr::lng_notification_reply(tr::now);
 
-			connect(_notificationInterface.get(),
-				SIGNAL(NotificationReplied(uint,QString)),
-				this, SLOT(notificationReplied(uint,QString)));
+			_notificationInterface->connection().connect(
+				str_const_toString(kService),
+				str_const_toString(kObjectPath),
+				str_const_toString(kInterface),
+				qsl("NotificationReplied"),
+				this,
+				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")
@@ -153,15 +160,26 @@ NotificationData::NotificationData(
 	_hints["desktop-entry"] =
 		qsl(MACRO_TO_STRING(TDESKTOP_LAUNCHER_BASENAME));
 
-	connect(_notificationInterface.get(),
-		SIGNAL(NotificationClosed(uint, uint)),
-		this, SLOT(notificationClosed(uint)));
+	_notificationInterface->connection().connect(
+		str_const_toString(kService),
+		str_const_toString(kObjectPath),
+		str_const_toString(kInterface),
+		qsl("NotificationClosed"),
+		this,
+		SLOT(notificationClosed(uint)));
 }
 
 bool NotificationData::show() {
-	QDBusReply<uint> notifyReply = _notificationInterface->call(qsl("Notify"),
-		str_const_toString(AppName), uint(0), QString(), _title, _body,
-		_actions, _hints, -1);
+	const QDBusReply<uint> notifyReply = _notificationInterface->call(
+		qsl("Notify"),
+		str_const_toString(AppName),
+		uint(0),
+		QString(),
+		_title,
+		_body,
+		_actions,
+		_hints,
+		-1);
 
 	if (notifyReply.isValid()) {
 		_notificationId = notifyReply.value();
@@ -174,7 +192,7 @@ bool NotificationData::show() {
 }
 
 bool NotificationData::close() {
-	QDBusReply<void> closeReply = _notificationInterface
+	const QDBusReply<void> closeReply = _notificationInterface
 		->call(qsl("CloseNotification"), _notificationId);
 
 	if (!closeReply.isValid()) {
@@ -186,7 +204,7 @@ bool NotificationData::close() {
 }
 
 void NotificationData::setImage(const QString &imagePath) {
-	auto specificationVersion = ParseSpecificationVersion(
+	const auto specificationVersion = ParseSpecificationVersion(
 		GetServerInformation(_notificationInterface));
 
 	QString imageKey;
@@ -211,8 +229,11 @@ void NotificationData::setImage(const QString &imagePath) {
 		return;
 	}
 
-	auto image = QImage(imagePath).convertToFormat(QImage::Format_RGBA8888);
-	QByteArray imageBytes((const char*)image.constBits(),
+	const auto image = QImage(imagePath)
+		.convertToFormat(QImage::Format_RGBA8888);
+
+	const QByteArray imageBytes(
+		(const char*)image.constBits(),
 		image.sizeInBytes());
 
 	ImageData imageData;
@@ -285,7 +306,7 @@ const QDBusArgument &operator>>(const QDBusArgument &argument,
 
 bool Supported() {
 #ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
-	static auto Available = QDBusInterface(
+	static const auto Available = QDBusInterface(
 		str_const_toString(kService),
 		str_const_toString(kObjectPath),
 		str_const_toString(kInterface)).isValid();
@@ -316,10 +337,10 @@ Manager::Private::Private(Manager *manager, Type type)
 		str_const_toString(kInterface))) {
 	qDBusRegisterMetaType<NotificationData::ImageData>();
 
-	auto specificationVersion = ParseSpecificationVersion(
+	const auto specificationVersion = ParseSpecificationVersion(
 		GetServerInformation(_notificationInterface));
 
-	auto capabilities = GetCapabilities(_notificationInterface);
+	const auto capabilities = GetCapabilities(_notificationInterface);
 
 	if (!specificationVersion.isNull()) {
 		LOG(("Notification daemon specification version: %1")