From 7bd05985551aa1be634f9e2027e3b9b72c776efb Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Wed, 26 Feb 2020 15:38:31 +0400 Subject: [PATCH] Unified function to detect icon name on Linux --- .../SourceFiles/platform/linux/main_window_linux.cpp | 12 +++--------- .../platform/linux/notifications_manager_linux.cpp | 2 +- .../SourceFiles/platform/linux/specific_linux.cpp | 8 ++++++++ Telegram/SourceFiles/platform/linux/specific_linux.h | 2 ++ Telegram/SourceFiles/window/main_window.cpp | 6 +++--- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp index bd3f656ffe..da77c191a6 100644 --- a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp @@ -31,7 +31,6 @@ namespace Platform { namespace { constexpr auto kDisableTrayCounter = "TDESKTOP_DISABLE_TRAY_COUNTER"_cs; -constexpr auto kTrayIconName = "telegram"_cs; constexpr auto kPanelTrayIconName = "telegram-panel"_cs; constexpr auto kMutePanelTrayIconName = "telegram-mute-panel"_cs; constexpr auto kAttentionPanelTrayIconName = "telegram-attention-panel"_cs; @@ -56,18 +55,13 @@ QString GetPanelIconName() { } QString GetTrayIconName() { + const auto iconName = GetIconName(); const auto panelIconName = GetPanelIconName(); if (QIcon::hasThemeIcon(panelIconName)) { return panelIconName; - } else if (InSandbox()) { - const auto launcherBasename = GetLauncherBasename(); - - if (QIcon::hasThemeIcon(launcherBasename)) { - return launcherBasename; - } - } else if (QIcon::hasThemeIcon(kTrayIconName.utf16())) { - return kTrayIconName.utf16(); + } else if (QIcon::hasThemeIcon(iconName)) { + return iconName; } return QString(); diff --git a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp index 00803863b1..71e785d59a 100644 --- a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp @@ -200,7 +200,7 @@ NotificationData::NotificationData( bool NotificationData::show() { const auto iconName = _imageKey.isEmpty() || !_hints.contains(_imageKey) - ? qsl("telegram") + ? GetIconName() : QString(); const QDBusReply notifyReply = _notificationInterface->call( diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index 0bacb65d4d..4e6ee35c88 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -44,6 +44,7 @@ namespace { constexpr auto kDesktopFile = ":/misc/telegramdesktop.desktop"_cs; constexpr auto kSnapLauncherDir = "/var/lib/snapd/desktop/applications/"_cs; +constexpr auto kIconName = "telegram"_cs; #ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION void SandboxAutostart(bool autostart, bool silent = false) { @@ -333,6 +334,13 @@ QString GetLauncherFilename() { return LauncherFilename; } +QString GetIconName() { + static const auto IconName = InSandbox() + ? GetLauncherBasename() + : kIconName.utf16(); + return IconName; +} + } // namespace Platform namespace { diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.h b/Telegram/SourceFiles/platform/linux/specific_linux.h index f878dac711..526a2aec58 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.h +++ b/Telegram/SourceFiles/platform/linux/specific_linux.h @@ -35,6 +35,8 @@ QString SingleInstanceLocalServerName(const QString &hash); QString GetLauncherBasename(); QString GetLauncherFilename(); +QString GetIconName(); + inline std::optional LastUserInputTime() { return std::nullopt; } diff --git a/Telegram/SourceFiles/window/main_window.cpp b/Telegram/SourceFiles/window/main_window.cpp index 50b9564979..a220b03693 100644 --- a/Telegram/SourceFiles/window/main_window.cpp +++ b/Telegram/SourceFiles/window/main_window.cpp @@ -117,9 +117,9 @@ QIcon CreateOfficialIcon(Main::Account *account) { QIcon CreateIcon(Main::Account *account) { auto result = CreateOfficialIcon(account); - if (Platform::IsLinux()) { - return QIcon::fromTheme("telegram", result); - } +#ifdef Q_OS_LINUX + return QIcon::fromTheme(Platform::GetIconName(), result); +#endif return result; }