From 759ede3c5770a6abf896e7acc8e95be590c3d069 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 5 Feb 2016 17:32:19 +0300 Subject: [PATCH] fixed linux launch with static linking --- README.md | 15 -- Telegram/FixMake.sh | 4 +- Telegram/SourceFiles/app.cpp | 3 +- Telegram/SourceFiles/pspecific_linux.cpp | 295 +++++++++++------------ Telegram/Telegram.pro | 2 +- 5 files changed, 143 insertions(+), 176 deletions(-) diff --git a/README.md b/README.md index df84d73516..be9a159774 100644 --- a/README.md +++ b/README.md @@ -48,21 +48,6 @@ The source code is published under GPLv3 with OpenSSL exception, the license is Compiles given files to single update file, compresses it with lzma and signs with a private key. It is not built in **Debug** and **Release** configurations of Telegram solution, because private key is inaccessible. -* ### Prepare - - Prepares a release for deployment, puts all current files to deploy/{version} folder. - - **Windows**: - * tsetup{version}.exe installer - * Telegram.exe - * Telegram.pdb (debug info for crash minidumps view) - * tupdate{updversion} binary lzma update archive - - **Mac**: - * tsetup{version}.dmg - * Telegram.app - * tmacupd{updversion} binary lzma update archive - * ### MetaEmoji Creates four sprites and text2emoji replace code diff --git a/Telegram/FixMake.sh b/Telegram/FixMake.sh index 21abada2b2..b2b180b135 100755 --- a/Telegram/FixMake.sh +++ b/Telegram/FixMake.sh @@ -11,11 +11,9 @@ Replace () { } Replace '\-llzma' '\/usr\/lib\/x86_64\-linux\-gnu\/liblzma\.a' -Replace '\-lz' '\/usr\/lib\/x86_64\-linux\-gnu\/libz\.a' Replace '\-lssl' '\/usr\/lib\/x86_64\-linux\-gnu\/libssl\.a' Replace '\-lcrypto' '\/usr\/lib\/x86_64\-linux\-gnu\/libcrypto\.a' -Replace '\-lexif' '\/usr\/lib\/x86_64\-linux\-gnu\/libexif\.a' -Replace '\-lgobject\-2\.0' '\/usr\/lib\/x86_64\-linux\-gnu\/libgobject\-2\.0\.a \/usr\/lib\/x86_64\-linux\-gnu\/libffi\.a' +#Replace '\-lgobject\-2\.0' '\/usr\/lib\/x86_64\-linux\-gnu\/libgobject\-2\.0\.a \/usr\/lib\/x86_64\-linux\-gnu\/libffi\.a' Replace '\-lXi' '\/usr\/lib\/x86_64\-linux\-gnu\/libXi\.a' Replace '\-lSM' '\/usr\/lib\/x86_64\-linux\-gnu\/libSM\.a' Replace '\-lICE' '\/usr\/lib\/x86_64\-linux\-gnu\/libICE\.a' diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index 3a992e7065..fae83e4597 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -25,8 +25,9 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org #include "application.h" #include "fileuploader.h" #include "mainwidget.h" +#if QT_VERSION < QT_VERSION_CHECK(5, 5, 0) #include - +#endif #include "localstorage.h" #include "numbers.h" diff --git a/Telegram/SourceFiles/pspecific_linux.cpp b/Telegram/SourceFiles/pspecific_linux.cpp index 47429e862e..6eec662957 100644 --- a/Telegram/SourceFiles/pspecific_linux.cpp +++ b/Telegram/SourceFiles/pspecific_linux.cpp @@ -346,156 +346,141 @@ namespace { return FALSE; } - class _PsInitializer { - public: - _PsInitializer() { - static bool inited = false; - if (inited) return; - inited = true; - - QString cdesktop = QString(getenv("XDG_CURRENT_DESKTOP")).toLower(); - noQtTrayIcon = (cdesktop == qstr("pantheon")) || (cdesktop == qstr("gnome")); - tryAppIndicator = (cdesktop == qstr("xfce")); - noTryUnity = (cdesktop != qstr("unity")); - - if (noQtTrayIcon) cSetSupportTray(false); - - DEBUG_LOG(("Loading libraries")); - setupGtk(); - setupUnity(); + bool loadLibrary(QLibrary &lib, const char *name, int version) { + DEBUG_LOG(("Loading '%1' with version %2..").arg(QLatin1String(name)).arg(version)); + lib.setFileNameAndVersion(QLatin1String(name), version); + if (lib.load()) { + DEBUG_LOG(("Loaded '%1' with version %2!").arg(QLatin1String(name)).arg(version)); + return true; } - - bool loadLibrary(QLibrary &lib, const char *name, int version) { - DEBUG_LOG(("Loading '%1' with version %2..").arg(QLatin1String(name)).arg(version)); - lib.setFileNameAndVersion(QLatin1String(name), version); - if (lib.load()) { - DEBUG_LOG(("Loaded '%1' with version %2!").arg(QLatin1String(name)).arg(version)); - return true; - } - lib.setFileNameAndVersion(QLatin1String(name), QString()); - if (lib.load()) { - DEBUG_LOG(("Loaded '%1' without version!").arg(QLatin1String(name))); - return true; - } - LOG(("Could not load '%1' with version %2 :(").arg(QLatin1String(name)).arg(version)); - return false; + lib.setFileNameAndVersion(QLatin1String(name), QString()); + if (lib.load()) { + DEBUG_LOG(("Loaded '%1' without version!").arg(QLatin1String(name))); + return true; } + LOG(("Could not load '%1' with version %2 :(").arg(QLatin1String(name)).arg(version)); + return false; + } - void setupGtkBase(QLibrary &lib_gtk) { - if (!loadFunction(lib_gtk, "gtk_init_check", ps_gtk_init_check)) return; - if (!loadFunction(lib_gtk, "gtk_menu_new", ps_gtk_menu_new)) return; - if (!loadFunction(lib_gtk, "gtk_menu_get_type", ps_gtk_menu_get_type)) return; + void setupGtkBase(QLibrary &lib_gtk) { + if (!loadFunction(lib_gtk, "gtk_init_check", ps_gtk_init_check)) return; + if (!loadFunction(lib_gtk, "gtk_menu_new", ps_gtk_menu_new)) return; + if (!loadFunction(lib_gtk, "gtk_menu_get_type", ps_gtk_menu_get_type)) return; - if (!loadFunction(lib_gtk, "gtk_menu_item_new_with_label", ps_gtk_menu_item_new_with_label)) return; - if (!loadFunction(lib_gtk, "gtk_menu_item_set_label", ps_gtk_menu_item_set_label)) return; - if (!loadFunction(lib_gtk, "gtk_menu_shell_append", ps_gtk_menu_shell_append)) return; - if (!loadFunction(lib_gtk, "gtk_menu_shell_get_type", ps_gtk_menu_shell_get_type)) return; - if (!loadFunction(lib_gtk, "gtk_widget_show", ps_gtk_widget_show)) return; - if (!loadFunction(lib_gtk, "gtk_widget_get_toplevel", ps_gtk_widget_get_toplevel)) return; - if (!loadFunction(lib_gtk, "gtk_widget_get_visible", ps_gtk_widget_get_visible)) return; - if (!loadFunction(lib_gtk, "gtk_widget_set_sensitive", ps_gtk_widget_set_sensitive)) return; + if (!loadFunction(lib_gtk, "gtk_menu_item_new_with_label", ps_gtk_menu_item_new_with_label)) return; + if (!loadFunction(lib_gtk, "gtk_menu_item_set_label", ps_gtk_menu_item_set_label)) return; + if (!loadFunction(lib_gtk, "gtk_menu_shell_append", ps_gtk_menu_shell_append)) return; + if (!loadFunction(lib_gtk, "gtk_menu_shell_get_type", ps_gtk_menu_shell_get_type)) return; + if (!loadFunction(lib_gtk, "gtk_widget_show", ps_gtk_widget_show)) return; + if (!loadFunction(lib_gtk, "gtk_widget_get_toplevel", ps_gtk_widget_get_toplevel)) return; + if (!loadFunction(lib_gtk, "gtk_widget_get_visible", ps_gtk_widget_get_visible)) return; + if (!loadFunction(lib_gtk, "gtk_widget_set_sensitive", ps_gtk_widget_set_sensitive)) return; - if (!loadFunction(lib_gtk, "g_type_check_instance_cast", ps_g_type_check_instance_cast)) return; - if (!loadFunction(lib_gtk, "g_signal_connect_data", ps_g_signal_connect_data)) return; + if (!loadFunction(lib_gtk, "g_type_check_instance_cast", ps_g_type_check_instance_cast)) return; + if (!loadFunction(lib_gtk, "g_signal_connect_data", ps_g_signal_connect_data)) return; - if (!loadFunction(lib_gtk, "g_object_ref_sink", ps_g_object_ref_sink)) return; - if (!loadFunction(lib_gtk, "g_object_unref", ps_g_object_unref)) return; + if (!loadFunction(lib_gtk, "g_object_ref_sink", ps_g_object_ref_sink)) return; + if (!loadFunction(lib_gtk, "g_object_unref", ps_g_object_unref)) return; + DEBUG_LOG(("Library gtk functions loaded!")); + if (ps_gtk_init_check(0, 0)) { + DEBUG_LOG(("Checked gtk with gtk_init_check!")); useGtkBase = true; - DEBUG_LOG(("Library gtk functions loaded!")); + } else { + DEBUG_LOG(("Failed to gtk_init_check(0, 0)!")); } + } - void setupAppIndicator(QLibrary &lib_indicator) { - if (!loadFunction(lib_indicator, "app_indicator_new", ps_app_indicator_new)) return; - if (!loadFunction(lib_indicator, "app_indicator_set_status", ps_app_indicator_set_status)) return; - if (!loadFunction(lib_indicator, "app_indicator_set_menu", ps_app_indicator_set_menu)) return; - if (!loadFunction(lib_indicator, "app_indicator_set_icon_full", ps_app_indicator_set_icon_full)) return; - useAppIndicator = true; - DEBUG_LOG(("Library appindicator functions loaded!")); - } + void setupAppIndicator(QLibrary &lib_indicator) { + if (!loadFunction(lib_indicator, "app_indicator_new", ps_app_indicator_new)) return; + if (!loadFunction(lib_indicator, "app_indicator_set_status", ps_app_indicator_set_status)) return; + if (!loadFunction(lib_indicator, "app_indicator_set_menu", ps_app_indicator_set_menu)) return; + if (!loadFunction(lib_indicator, "app_indicator_set_icon_full", ps_app_indicator_set_icon_full)) return; + useAppIndicator = true; + DEBUG_LOG(("Library appindicator functions loaded!")); + } - void setupGtk() { - QLibrary lib_gtk, lib_indicator; - if (!noQtTrayIcon && !tryAppIndicator) { - if (!noTryUnity) { - if (loadLibrary(lib_gtk, "gtk-3", 0)) { + void setupGtk() { + QLibrary lib_gtk, lib_indicator; + if (!noQtTrayIcon && !tryAppIndicator) { + if (!noTryUnity) { + if (loadLibrary(lib_gtk, "gtk-3", 0)) { + setupGtkBase(lib_gtk); + } + if (!useGtkBase) { + if (loadLibrary(lib_gtk, "gtk-x11-2.0", 0)) { setupGtkBase(lib_gtk); } - if (!useGtkBase) { - if (loadLibrary(lib_gtk, "gtk-x11-2.0", 0)) { - setupGtkBase(lib_gtk); - } - } - if (!useGtkBase) { - noTryUnity = true; - } } - return; + if (!useGtkBase) { + noTryUnity = true; + } } + return; + } - if (loadLibrary(lib_indicator, "appindicator3", 1)) { - if (loadLibrary(lib_gtk, "gtk-3", 0)) { + if (loadLibrary(lib_indicator, "appindicator3", 1)) { + if (loadLibrary(lib_gtk, "gtk-3", 0)) { + setupGtkBase(lib_gtk); + setupAppIndicator(lib_indicator); + } + } + if (!useGtkBase || !useAppIndicator) { + if (loadLibrary(lib_indicator, "appindicator", 1)) { + if (loadLibrary(lib_gtk, "gtk-x11-2.0", 0)) { + useGtkBase = useAppIndicator = false; setupGtkBase(lib_gtk); setupAppIndicator(lib_indicator); } } - if (!useGtkBase || !useAppIndicator) { - if (loadLibrary(lib_indicator, "appindicator", 1)) { - if (loadLibrary(lib_gtk, "gtk-x11-2.0", 0)) { - useGtkBase = useAppIndicator = false; - setupGtkBase(lib_gtk); - setupAppIndicator(lib_indicator); - } - } - } - if (tryAppIndicator) { - if (useGtkBase && useAppIndicator) { - noQtTrayIcon = true; - cSetSupportTray(false); - } - return; - } - - if (!useGtkBase && lib_gtk.isLoaded()) { - LOG(("Could not load appindicator, trying to load gtk..")); - setupGtkBase(lib_gtk); - } - if (!useGtkBase) { - useAppIndicator = false; - LOG(("Could not load gtk-x11-2.0!")); - return; - } - - if (!loadFunction(lib_gtk, "gdk_init_check", ps_gdk_init_check)) return; - if (!loadFunction(lib_gtk, "gdk_pixbuf_new_from_data", ps_gdk_pixbuf_new_from_data)) return; - if (!loadFunction(lib_gtk, "gtk_status_icon_new_from_pixbuf", ps_gtk_status_icon_new_from_pixbuf)) return; - if (!loadFunction(lib_gtk, "gtk_status_icon_set_from_pixbuf", ps_gtk_status_icon_set_from_pixbuf)) return; - if (!loadFunction(lib_gtk, "gtk_status_icon_set_title", ps_gtk_status_icon_set_title)) return; - if (!loadFunction(lib_gtk, "gtk_status_icon_set_tooltip_text", ps_gtk_status_icon_set_tooltip_text)) return; - if (!loadFunction(lib_gtk, "gtk_status_icon_set_visible", ps_gtk_status_icon_set_visible)) return; - if (!loadFunction(lib_gtk, "gtk_status_icon_is_embedded", ps_gtk_status_icon_is_embedded)) return; - if (!loadFunction(lib_gtk, "gtk_status_icon_get_geometry", ps_gtk_status_icon_get_geometry)) return; - if (!loadFunction(lib_gtk, "gtk_status_icon_position_menu", ps_gtk_status_icon_position_menu)) return; - if (!loadFunction(lib_gtk, "gtk_menu_popup", ps_gtk_menu_popup)) return; - if (!loadFunction(lib_gtk, "gtk_get_current_event_time", ps_gtk_get_current_event_time)) return; - if (!loadFunction(lib_gtk, "g_idle_add", ps_g_idle_add)) return; - useStatusIcon = true; - DEBUG_LOG(("Status icon api loaded!")); - } - - void setupUnity() { - if (noTryUnity) return; - - QLibrary lib_unity(qstr("unity"), 9, 0); - if (!loadLibrary(lib_unity, "unity", 9)) return; - - if (!loadFunction(lib_unity, "unity_launcher_entry_get_for_desktop_id", ps_unity_launcher_entry_get_for_desktop_id)) return; - if (!loadFunction(lib_unity, "unity_launcher_entry_set_count", ps_unity_launcher_entry_set_count)) return; - if (!loadFunction(lib_unity, "unity_launcher_entry_set_count_visible", ps_unity_launcher_entry_set_count_visible)) return; - useUnityCount = true; - DEBUG_LOG(("Unity count api loaded!")); } - }; + if (tryAppIndicator) { + if (useGtkBase && useAppIndicator) { + noQtTrayIcon = true; + cSetSupportTray(false); + } + return; + } + + if (!useGtkBase && lib_gtk.isLoaded()) { + LOG(("Could not load appindicator, trying to load gtk..")); + setupGtkBase(lib_gtk); + } + if (!useGtkBase) { + useAppIndicator = false; + LOG(("Could not load gtk-x11-2.0!")); + return; + } + + if (!loadFunction(lib_gtk, "gdk_init_check", ps_gdk_init_check)) return; + if (!loadFunction(lib_gtk, "gdk_pixbuf_new_from_data", ps_gdk_pixbuf_new_from_data)) return; + if (!loadFunction(lib_gtk, "gtk_status_icon_new_from_pixbuf", ps_gtk_status_icon_new_from_pixbuf)) return; + if (!loadFunction(lib_gtk, "gtk_status_icon_set_from_pixbuf", ps_gtk_status_icon_set_from_pixbuf)) return; + if (!loadFunction(lib_gtk, "gtk_status_icon_set_title", ps_gtk_status_icon_set_title)) return; + if (!loadFunction(lib_gtk, "gtk_status_icon_set_tooltip_text", ps_gtk_status_icon_set_tooltip_text)) return; + if (!loadFunction(lib_gtk, "gtk_status_icon_set_visible", ps_gtk_status_icon_set_visible)) return; + if (!loadFunction(lib_gtk, "gtk_status_icon_is_embedded", ps_gtk_status_icon_is_embedded)) return; + if (!loadFunction(lib_gtk, "gtk_status_icon_get_geometry", ps_gtk_status_icon_get_geometry)) return; + if (!loadFunction(lib_gtk, "gtk_status_icon_position_menu", ps_gtk_status_icon_position_menu)) return; + if (!loadFunction(lib_gtk, "gtk_menu_popup", ps_gtk_menu_popup)) return; + if (!loadFunction(lib_gtk, "gtk_get_current_event_time", ps_gtk_get_current_event_time)) return; + if (!loadFunction(lib_gtk, "g_idle_add", ps_g_idle_add)) return; + useStatusIcon = true; + DEBUG_LOG(("Status icon api loaded!")); + } + + void setupUnity() { + if (noTryUnity) return; + + QLibrary lib_unity(qstr("unity"), 9, 0); + if (!loadLibrary(lib_unity, "unity", 9)) return; + + if (!loadFunction(lib_unity, "unity_launcher_entry_get_for_desktop_id", ps_unity_launcher_entry_get_for_desktop_id)) return; + if (!loadFunction(lib_unity, "unity_launcher_entry_set_count", ps_unity_launcher_entry_set_count)) return; + if (!loadFunction(lib_unity, "unity_launcher_entry_set_count_visible", ps_unity_launcher_entry_set_count_visible)) return; + useUnityCount = true; + DEBUG_LOG(("Unity count api loaded!")); + } class _PsEventFilter : public QAbstractNativeEventFilter { public: @@ -516,8 +501,6 @@ namespace { PsMainWindow::PsMainWindow(QWidget *parent) : QMainWindow(parent), posInited(false), trayIcon(0), trayIconMenu(0), icon256(qsl(":/gui/art/icon256.png")), iconbig256(icon256), wndIcon(QIcon::fromTheme("telegram", QIcon(QPixmap::fromImage(icon256, Qt::ColorOnly)))), _psCheckStatusIconLeft(100), _psLastIndicatorUpdate(0) { - _PsInitializer initializer; - connect(&_psCheckStatusIconTimer, SIGNAL(timeout()), this, SLOT(psStatusIconCheck())); _psCheckStatusIconTimer.setSingleShot(false); @@ -770,41 +753,31 @@ void PsMainWindow::psCreateTrayIcon() { if (!noQtTrayIcon) { cSetSupportTray(QSystemTrayIcon::isSystemTrayAvailable()); if (!noTryUnity) { - if (ps_gtk_init_check(0, 0)) { - DEBUG_LOG(("Checked gtk with gtk_init_check!")); - } else { - DEBUG_LOG(("Failed to gtk_init_check(0, 0)!")); - useUnityCount = false; - } + useUnityCount = false; } return; } if (useAppIndicator) { DEBUG_LOG(("Trying to create AppIndicator")); - if (ps_gtk_init_check(0, 0)) { - DEBUG_LOG(("Checked gtk with gtk_init_check!")); - _trayMenu = ps_gtk_menu_new(); - if (_trayMenu) { - DEBUG_LOG(("Created gtk menu for appindicator!")); - QFileInfo f(_trayIconImageFile()); - if (f.exists()) { - QByteArray path = QFile::encodeName(f.absoluteFilePath()); - _trayIndicator = ps_app_indicator_new("Telegram Desktop", path.constData(), APP_INDICATOR_CATEGORY_APPLICATION_STATUS); - if (_trayIndicator) { - DEBUG_LOG(("Created appindicator!")); - } else { - DEBUG_LOG(("Failed to app_indicator_new()!")); - } + _trayMenu = ps_gtk_menu_new(); + if (_trayMenu) { + DEBUG_LOG(("Created gtk menu for appindicator!")); + QFileInfo f(_trayIconImageFile()); + if (f.exists()) { + QByteArray path = QFile::encodeName(f.absoluteFilePath()); + _trayIndicator = ps_app_indicator_new("Telegram Desktop", path.constData(), APP_INDICATOR_CATEGORY_APPLICATION_STATUS); + if (_trayIndicator) { + DEBUG_LOG(("Created appindicator!")); } else { - useAppIndicator = false; - DEBUG_LOG(("Failed to create image file!")); + DEBUG_LOG(("Failed to app_indicator_new()!")); } } else { - DEBUG_LOG(("Failed to gtk_menu_new()!")); + useAppIndicator = false; + DEBUG_LOG(("Failed to create image file!")); } } else { - DEBUG_LOG(("Failed to gtk_init_check(0, 0)!")); + DEBUG_LOG(("Failed to gtk_menu_new()!")); } if (_trayMenu && _trayIndicator) { ps_app_indicator_set_status(_trayIndicator, APP_INDICATOR_STATUS_ACTIVE); @@ -816,7 +789,7 @@ void PsMainWindow::psCreateTrayIcon() { } } if (useStatusIcon) { - if (ps_gtk_init_check(0, 0) && ps_gdk_init_check(0, 0)) { + if (ps_gdk_init_check(0, 0)) { if (!_trayMenu) _trayMenu = ps_gtk_menu_new(); if (_trayMenu) { loadPixbuf(_trayIconImageGen()); @@ -1269,6 +1242,16 @@ void psShowInFolder(const QString &name) { namespace PlatformSpecific { Initializer::Initializer() { + QString cdesktop = QString(getenv("XDG_CURRENT_DESKTOP")).toLower(); + noQtTrayIcon = (cdesktop == qstr("pantheon")) || (cdesktop == qstr("gnome")); + tryAppIndicator = (cdesktop == qstr("xfce")); + noTryUnity = (cdesktop != qstr("unity")); + + if (noQtTrayIcon) cSetSupportTray(false); + + DEBUG_LOG(("Loading libraries")); + setupGtk(); + setupUnity(); } Initializer::~Initializer() { diff --git a/Telegram/Telegram.pro b/Telegram/Telegram.pro index b0ea1e9d8c..1ba6d852ec 100644 --- a/Telegram/Telegram.pro +++ b/Telegram/Telegram.pro @@ -318,7 +318,7 @@ INCLUDEPATH += "/usr/include/atk-1.0" INCLUDEPATH += "/usr/include/dee-1.0" INCLUDEPATH += "/usr/include/libdbusmenu-glib-0.4" -LIBS += -lcrypto -lssl -ldl -llzma -lexif -lopenal -lavformat -lavcodec -lswresample -lswscale -lavutil -lopus -lva +LIBS += -lcrypto -lssl -ldl -llzma -lopenal -lavformat -lavcodec -lswresample -lswscale -lavutil -lopus -lva LIBS += ./../../../Libraries/QtStatic/qtbase/plugins/platforminputcontexts/libcomposeplatforminputcontextplugin.a \ ./../../../Libraries/QtStatic/qtbase/plugins/platforminputcontexts/libibusplatforminputcontextplugin.a \ ./../../../Libraries/QtStatic/qtbase/plugins/platforminputcontexts/libfcitxplatforminputcontextplugin.a