From add2356c8ae714cfa48b79b468bf083fa730b7a5 Mon Sep 17 00:00:00 2001 From: John Zimmermann Date: Fri, 7 Dec 2018 18:59:14 +0100 Subject: [PATCH] Generalize Unity Integration to not depend on libunity --- .appveyor/install.bat | 4 -- .travis.yml | 3 +- .travis/build.sh | 4 -- .../SourceFiles/platform/linux/linux_libs.cpp | 16 ----- .../SourceFiles/platform/linux/linux_libs.h | 14 ---- .../platform/linux/main_window_linux.cpp | 72 ++++++++++--------- docs/building-cmake.md | 2 +- snap/snapcraft.yaml | 3 +- 8 files changed, 41 insertions(+), 77 deletions(-) diff --git a/.appveyor/install.bat b/.appveyor/install.bat index cde8967f3..a74f8da63 100644 --- a/.appveyor/install.bat +++ b/.appveyor/install.bat @@ -72,10 +72,6 @@ GOTO:EOF set TDESKTOP_BUILD_DEFINES=%TDESKTOP_BUILD_DEFINES%,TDESKTOP_DISABLE_DESKTOP_FILE_GENERATION ) - echo %BUILD_VERSION% | findstr /C:"disable_unity_integration">nul && ( - set TDESKTOP_BUILD_DEFINES=%TDESKTOP_BUILD_DEFINES%,TDESKTOP_DISABLE_UNITY_INTEGRATION - ) - echo %BUILD_VERSION% | findstr /C:"disable_gtk_integration">nul && ( set TDESKTOP_BUILD_DEFINES=%TDESKTOP_BUILD_DEFINES%,TDESKTOP_DISABLE_GTK_INTEGRATION ) diff --git a/.travis.yml b/.travis.yml index 7d3f36b6f..8bf5c82ec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,6 @@ env: - BUILD_VERSION="disable_crash_reports" - BUILD_VERSION="disable_network_proxy" - BUILD_VERSION="disable_desktop_file_generation" - - BUILD_VERSION="disable_unity_integration" - BUILD_VERSION="disable_gtk_integration" matrix: @@ -45,7 +44,7 @@ addons: - libopus-dev - libpulse-dev - libssl-dev - - libunity-dev + - libdee-dev - libva-dev - libvdpau-dev - libxcb-xkb-dev diff --git a/.travis/build.sh b/.travis/build.sh index bcb0a85ef..e27ddebb1 100755 --- a/.travis/build.sh +++ b/.travis/build.sh @@ -116,10 +116,6 @@ build() { GYP_DEFINES+=",TDESKTOP_DISABLE_DESKTOP_FILE_GENERATION" fi - if [[ $BUILD_VERSION == *"disable_unity_integration"* ]]; then - GYP_DEFINES+=",TDESKTOP_DISABLE_UNITY_INTEGRATION" - fi - if [[ $BUILD_VERSION == *"disable_gtk_integration"* ]]; then GYP_DEFINES+=",TDESKTOP_DISABLE_GTK_INTEGRATION" fi diff --git a/Telegram/SourceFiles/platform/linux/linux_libs.cpp b/Telegram/SourceFiles/platform/linux/linux_libs.cpp index f8d74fee1..d1ff24303 100644 --- a/Telegram/SourceFiles/platform/linux/linux_libs.cpp +++ b/Telegram/SourceFiles/platform/linux/linux_libs.cpp @@ -220,11 +220,6 @@ f_g_list_free g_list_free = nullptr; f_g_list_free_full g_list_free_full = nullptr; f_g_error_free g_error_free = nullptr; f_g_slist_free g_slist_free = nullptr; -#ifndef TDESKTOP_DISABLE_UNITY_INTEGRATION -f_unity_launcher_entry_set_count unity_launcher_entry_set_count = nullptr; -f_unity_launcher_entry_set_count_visible unity_launcher_entry_set_count_visible = nullptr; -f_unity_launcher_entry_get_for_desktop_id unity_launcher_entry_get_for_desktop_id = nullptr; -#endif // !TDESKTOP_DISABLE_UNITY_INTEGRATION #endif // !TDESKTOP_DISABLE_GTK_INTEGRATION void start() { @@ -288,17 +283,6 @@ void start() { LOG(("Could not load gtk-x11-2.0!")); } -#ifndef TDESKTOP_DISABLE_UNITY_INTEGRATION - if (DesktopEnvironment::TryUnityCounter()) { - QLibrary lib_unity(qstr("unity"), 9, 0); - loadLibrary(lib_unity, "unity", 9); - - load(lib_unity, "unity_launcher_entry_get_for_desktop_id", unity_launcher_entry_get_for_desktop_id); - load(lib_unity, "unity_launcher_entry_set_count", unity_launcher_entry_set_count); - load(lib_unity, "unity_launcher_entry_set_count_visible", unity_launcher_entry_set_count_visible); - } -#endif // !TDESKTOP_DISABLE_UNITY_INTEGRATION - if (gtkLoaded) { startLibNotify(); } diff --git a/Telegram/SourceFiles/platform/linux/linux_libs.h b/Telegram/SourceFiles/platform/linux/linux_libs.h index 4834fee11..8f9a241e7 100644 --- a/Telegram/SourceFiles/platform/linux/linux_libs.h +++ b/Telegram/SourceFiles/platform/linux/linux_libs.h @@ -20,9 +20,6 @@ extern "C" { #define signals public } // extern "C" -#ifndef TDESKTOP_DISABLE_UNITY_INTEGRATION -#include -#endif // !TDESKTOP_DISABLE_UNITY_INTEGRATION #endif // !TDESKTOP_DISABLE_GTK_INTEGRATION namespace Platform { @@ -364,17 +361,6 @@ extern f_g_error_free g_error_free; typedef void (*f_g_slist_free)(GSList *list); extern f_g_slist_free g_slist_free; - -#ifndef TDESKTOP_DISABLE_UNITY_INTEGRATION -typedef void (*f_unity_launcher_entry_set_count)(UnityLauncherEntry* self, gint64 value); -extern f_unity_launcher_entry_set_count unity_launcher_entry_set_count; - -typedef void (*f_unity_launcher_entry_set_count_visible)(UnityLauncherEntry* self, gboolean value); -extern f_unity_launcher_entry_set_count_visible unity_launcher_entry_set_count_visible; - -typedef UnityLauncherEntry* (*f_unity_launcher_entry_get_for_desktop_id)(const gchar* desktop_id); -extern f_unity_launcher_entry_get_for_desktop_id unity_launcher_entry_get_for_desktop_id; -#endif // !TDESKTOP_DISABLE_UNITY_INTEGRATION #endif // !TDESKTOP_DISABLE_GTK_INTEGRATION } // namespace Libs diff --git a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp index 52b819f8c..536969165 100644 --- a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp @@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/application.h" #include "lang/lang_keys.h" #include "storage/localstorage.h" +#include namespace Platform { namespace { @@ -36,6 +37,8 @@ int32 _trayIconSize = 22; bool _trayIconMuted = true; int32 _trayIconCount = 0; QImage _trayIconImageBack, _trayIconImage; +QString _desktopFile; +QString _dbusPath = "/"; #ifndef TDESKTOP_DISABLE_GTK_INTEGRATION void _trayIconPopup(GtkStatusIcon *status_icon, guint button, guint32 activate_time, gpointer popup_menu) { @@ -177,11 +180,17 @@ static gboolean _trayIconCheck(gpointer/* pIn*/) { return FALSE; } -#ifndef TDESKTOP_DISABLE_UNITY_INTEGRATION -UnityLauncherEntry *_psUnityLauncherEntry = nullptr; -#endif // !TDESKTOP_DISABLE_UNITY_INTEGRATION #endif // !TDESKTOP_DISABLE_GTK_INTEGRATION +quint32 djbStringHash(QString string) { + quint32 hash = 5381; + QByteArray chars = string.toLatin1(); + for(int i = 0; i < chars.length(); i++){ + hash = (hash << 5) + hash + chars[i]; + } + return hash; +} + } // namespace MainWindow::MainWindow() { @@ -336,16 +345,20 @@ void MainWindow::updateIconCounters() { const auto counter = Core::App().unreadBadge(); -#if !defined(TDESKTOP_DISABLE_GTK_INTEGRATION) && !defined(TDESKTOP_DISABLE_UNITY_INTEGRATION) - if (_psUnityLauncherEntry) { + if (useUnityCount) { + QVariantMap dbusUnityProperties; if (counter > 0) { - Libs::unity_launcher_entry_set_count(_psUnityLauncherEntry, (counter > 9999) ? 9999 : counter); - Libs::unity_launcher_entry_set_count_visible(_psUnityLauncherEntry, TRUE); + // Gnome requires that count is a 64bit integer + dbusUnityProperties.insert("count", (qint64) ((counter > 9999) ? 9999 : (counter))); + dbusUnityProperties.insert("count-visible", true); } else { - Libs::unity_launcher_entry_set_count_visible(_psUnityLauncherEntry, FALSE); + dbusUnityProperties.insert("count-visible", false); } + QDBusMessage signal = QDBusMessage::createSignal(_dbusPath, "com.canonical.Unity.LauncherEntry", "Update"); + signal << "application://" + _desktopFile; + signal << dbusUnityProperties; + QDBusConnection::sessionBus().send(signal); } -#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION && !TDESKTOP_DISABLE_UNITY_INTEGRATION if (noQtTrayIcon) { #ifndef TDESKTOP_DISABLE_GTK_INTEGRATION @@ -441,15 +454,6 @@ void MainWindow::LibsLoaded() { if (useStatusIcon) { DEBUG_LOG(("Status icon api loaded!")); } - -#ifndef TDESKTOP_DISABLE_UNITY_INTEGRATION - useUnityCount = (Libs::unity_launcher_entry_get_for_desktop_id != nullptr) - && (Libs::unity_launcher_entry_set_count != nullptr) - && (Libs::unity_launcher_entry_set_count_visible != nullptr); - if (useUnityCount) { - DEBUG_LOG(("Unity count api loaded!")); - } -#endif // !TDESKTOP_DISABLE_UNITY_INTEGRATION #endif // !TDESKTOP_DISABLE_GTK_INTEGRATION } @@ -544,23 +548,29 @@ void MainWindow::psCreateTrayIcon() { void MainWindow::psFirstShow() { psCreateTrayIcon(); -#if !defined(TDESKTOP_DISABLE_GTK_INTEGRATION) && !defined(TDESKTOP_DISABLE_UNITY_INTEGRATION) - if (useUnityCount) { - _psUnityLauncherEntry = Libs::unity_launcher_entry_get_for_desktop_id("telegramdesktop.desktop"); - if (_psUnityLauncherEntry) { - LOG(("Found Unity Launcher entry telegramdesktop.desktop!")); - } else { - _psUnityLauncherEntry = Libs::unity_launcher_entry_get_for_desktop_id("Telegram.desktop"); - if (_psUnityLauncherEntry) { - LOG(("Found Unity Launcher entry Telegram.desktop!")); + if (QDBusInterface("com.canonical.Unity", "/").isValid()) { + auto snapName = QString::fromLatin1(qgetenv("SNAP_NAME")); + if(snapName.isEmpty()) { + if(!QStandardPaths::locate(QStandardPaths::ApplicationsLocation, "telegramdesktop.desktop").isEmpty()) { + _desktopFile = "telegramdesktop.desktop"; + LOG(("Found Unity Launcher entry telegramdesktop.desktop!")); + useUnityCount=true; + } else if(!QStandardPaths::locate(QStandardPaths::ApplicationsLocation, "Telegram.desktop").isEmpty()) { + _desktopFile = "telegramdesktop.desktop"; + LOG(("Found Unity Launcher entry telegramdesktop.desktop!")); + useUnityCount=true; } else { LOG(("Could not get Unity Launcher entry!")); } + } else { + LOG(("SNAP Enviroment detected, setting Launcher entry to %1-telegramdesktop.desktop!").arg(snapName)); + _desktopFile = snapName + "_telegramdesktop.desktop"; + useUnityCount=true; } + _dbusPath = "/com/canonical/unity/launcherentry/" + QString::number(djbStringHash("application://" + _desktopFile)); } else { LOG(("Not using Unity Launcher count.")); } -#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION && !TDESKTOP_DISABLE_GTK_INTEGRATION psUpdateMargins(); @@ -613,12 +623,6 @@ MainWindow::~MainWindow() { Libs::g_object_unref(_trayIndicator); _trayIndicator = nullptr; } -#ifndef TDESKTOP_DISABLE_UNITY_INTEGRATION - if (_psUnityLauncherEntry) { - Libs::g_object_unref(_psUnityLauncherEntry); - _psUnityLauncherEntry = nullptr; - } -#endif // ! TDESKTOP_DISABLE_UNITY_INTEGRATION #endif // !TDESKTOP_DISABLE_GTK_INTEGRATION } diff --git a/docs/building-cmake.md b/docs/building-cmake.md index e0ed92737..849586477 100644 --- a/docs/building-cmake.md +++ b/docs/building-cmake.md @@ -22,7 +22,7 @@ You will need GCC 7.2 and CMake 3.2 installed. To install them and all the requi sudo add-apt-repository --remove ppa:ubuntu-toolchain-r/test sudo add-apt-repository --remove ppa:george-edison55/cmake-3.x - sudo apt-get install git libexif-dev liblzma-dev libz-dev libssl-dev libappindicator-dev libunity-dev libicu-dev libdee-dev libdrm-dev dh-autoreconf autoconf automake build-essential libass-dev libfreetype6-dev libgpac-dev libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-image0-dev libxcb-shm0-dev libxcb-xfixes0-dev libxcb-keysyms1-dev libxcb-icccm4-dev libxcb-render-util0-dev libxcb-util0-dev libxrender-dev libasound-dev libpulse-dev libxcb-sync0-dev libxcb-randr0-dev libx11-xcb-dev libffi-dev libncurses5-dev pkg-config texi2html zlib1g-dev yasm cmake xutils-dev bison python-xcbgen + sudo apt-get install git libexif-dev liblzma-dev libz-dev libssl-dev libappindicator-dev libicu-dev libdee-dev libdrm-dev dh-autoreconf autoconf automake build-essential libass-dev libfreetype6-dev libgpac-dev libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-image0-dev libxcb-shm0-dev libxcb-xfixes0-dev libxcb-keysyms1-dev libxcb-icccm4-dev libxcb-render-util0-dev libxcb-util0-dev libxrender-dev libasound-dev libpulse-dev libxcb-sync0-dev libxcb-randr0-dev libx11-xcb-dev libffi-dev libncurses5-dev pkg-config texi2html zlib1g-dev yasm cmake xutils-dev bison python-xcbgen You can set the multithreaded make parameter by running diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 1977e3cd9..dddba3c41 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -72,7 +72,7 @@ parts: - libicu-dev - liblzma-dev - libssl-dev - - libunity-dev + - libdee-dev - zlib1g-dev gyp-file: Telegram/gyp/Telegram.gyp build-type: 'Release' @@ -133,7 +133,6 @@ parts: - libappindicator3-1 - libnotify4 - libpulse0 - - libunity9 after: [desktop-gtk3] stage: - -./usr/share/fonts/**