From 1ca86a239060ebec1026e9f0a00e4a5cdf2e38e9 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 16 Jan 2015 19:46:01 +0300 Subject: [PATCH 1/5] removing telegram.desktop when adding telegramdesktop.desktop, fixed libappindicator and libunity usage --- Telegram/SourceFiles/main.cpp | 6 +- Telegram/SourceFiles/pspecific_linux.cpp | 86 +++++++++++++++++++----- Telegram/SourceFiles/pspecific_linux.h | 2 + Telegram/SourceFiles/pspecific_mac.cpp | 5 ++ Telegram/SourceFiles/pspecific_mac.h | 2 + Telegram/SourceFiles/pspecific_wnd.cpp | 4 ++ Telegram/SourceFiles/pspecific_wnd.h | 2 + 7 files changed, 90 insertions(+), 17 deletions(-) diff --git a/Telegram/SourceFiles/main.cpp b/Telegram/SourceFiles/main.cpp index 7fe9471ff5..114729217d 100644 --- a/Telegram/SourceFiles/main.cpp +++ b/Telegram/SourceFiles/main.cpp @@ -46,7 +46,11 @@ int main(int argc, char *argv[]) { for (int32 i = 0; i < argc; ++i) { LOG(("Argument: %1").arg(QString::fromLocal8Bit(argv[i]))); } - } + QStringList errs = psInitErrors(); + for (int32 i = 0, l = errs.size(); i < l; ++i) { + LOG(("Init Error: %1").arg(errs.at(i))); + } + } DEBUG_LOG(("Application Info: ideal thread count: %1, using %2 connections per session").arg(QThread::idealThreadCount()).arg(cConnectionsInSession())); diff --git a/Telegram/SourceFiles/pspecific_linux.cpp b/Telegram/SourceFiles/pspecific_linux.cpp index e6866b777e..6e738bbad4 100644 --- a/Telegram/SourceFiles/pspecific_linux.cpp +++ b/Telegram/SourceFiles/pspecific_linux.cpp @@ -171,12 +171,19 @@ namespace { typedef UnityLauncherEntry* (*f_unity_launcher_entry_get_for_desktop_id)(const gchar* desktop_id); f_unity_launcher_entry_get_for_desktop_id ps_unity_launcher_entry_get_for_desktop_id = 0; + QStringList _initErrors; + template bool loadFunction(QLibrary &lib, const char *name, TFunction &func) { if (!lib.isLoaded()) return false; func = (TFunction)lib.resolve(name); - return !!func; + if (func) { + return true; + } else { + _initErrors.push_back(QString("Failed to load '%1' function!").arg(name)); + return false; + } } void _trayIconPopup(GtkStatusIcon *status_icon, guint button, guint32 activate_time, gpointer popup_menu) { @@ -322,8 +329,11 @@ namespace { setupUnity(); } void setupGTK() { - QLibrary lib_gtk(QLatin1String("gtk-x11-2.0"), 0, 0), lib_indicator(QLatin1String("appindicator")); - if (!lib_gtk.load()) return; + QLibrary lib_gtk(QLatin1String("gtk-x11-2.0"), 0, 0), lib_indicator(QLatin1String("appindicator"), 1, 0); + if (!lib_gtk.load()) { + _initErrors.push_back(QString("Failed to load 'gtk-x11-2.0' library!")); + return; + } if (!loadFunction(lib_gtk, "gtk_init_check", ps_gtk_init_check)) return; if (!loadFunction(lib_gtk, "gtk_menu_new", ps_gtk_menu_new)) return; @@ -341,7 +351,12 @@ namespace { 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 (lib_indicator.load()) setupAppIndicator(lib_indicator); + if (lib_indicator.load()) { + setupAppIndicator(lib_indicator); + } else { + _initErrors.push_back(QString("Failed to load 'appindicator' library!")); + 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; @@ -368,8 +383,11 @@ namespace { useAppIndicator = true; } void setupUnity() { - QLibrary lib_unity("unity"); - if (!lib_unity.load()) return; + QLibrary lib_unity("unity", 9, 0); + if (!lib_unity.load()) { + _initErrors.push_back(QString("Failed to load 'unity' library!")); + 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; @@ -393,7 +411,7 @@ namespace { }; _PsEventFilter *_psEventFilter = 0; - UnityLauncherEntry *_psUnityLauncherEntry = 0; + UnityLauncherEntry *_psUnityLauncherEntryOld = 0, *_psUnityLauncherEntry = 0; }; PsMainWindow::PsMainWindow(QWidget *parent) : QMainWindow(parent), @@ -529,7 +547,7 @@ void PsMainWindow::psUpdateIndicator() { _psLastIndicatorUpdate = getms(); QFileInfo f(_trayIconImageFile()); if (f.exists()) { - QByteArray path = f.absoluteFilePath().toUtf8(), name = f.fileName().toUtf8(); + QByteArray path = QFile::encodeName(f.absoluteFilePath()), name = QFile::encodeName(f.fileName()); name = name.mid(0, name.size() - 4); ps_app_indicator_set_icon_full(_trayIndicator, path.constData(), name); } else { @@ -543,6 +561,14 @@ void PsMainWindow::psUpdateCounter() { int32 counter = App::histories().unreadFull; setWindowTitle((counter > 0) ? qsl("Telegram (%1)").arg(counter) : qsl("Telegram")); + if (_psUnityLauncherEntryOld) { + if (counter > 0) { + ps_unity_launcher_entry_set_count(_psUnityLauncherEntryOld, (counter > 9999) ? 9999 : counter); + ps_unity_launcher_entry_set_count_visible(_psUnityLauncherEntryOld, TRUE); + } else { + ps_unity_launcher_entry_set_count_visible(_psUnityLauncherEntryOld, FALSE); + } + } if (_psUnityLauncherEntry) { if (counter > 0) { ps_unity_launcher_entry_set_count(_psUnityLauncherEntry, (counter > 9999) ? 9999 : counter); @@ -667,23 +693,33 @@ void PsMainWindow::psStateChanged(Qt::WindowState state) { void PsMainWindow::psCreateTrayIcon() { if (useAppIndicator) { + DEBUG_LOG(("Trying to create AppIndicator")); if (ps_gtk_init_check(0, 0)) { _trayMenu = ps_gtk_menu_new(); if (_trayMenu) { QFileInfo f(_trayIconImageFile()); if (f.exists()) { - QByteArray path = f.absoluteFilePath().toUtf8(); + QByteArray path = QFile::encodeName(f.absoluteFilePath()); _trayIndicator = ps_app_indicator_new("Telegram Desktop", path.constData(), APP_INDICATOR_CATEGORY_APPLICATION_STATUS); + if (!_trayIndicator) { + DEBUG_LOG(("Failed to app_indicator_new()!")); + } } else { useAppIndicator = false; + DEBUG_LOG(("Failed to create image file!")); } + } else { + DEBUG_LOG(("Failed to gtk_menu_new()!")); } + } else { + DEBUG_LOG(("Failed to gtk_init_check(0, 0)!")); } if (_trayMenu && _trayIndicator) { ps_app_indicator_set_status(_trayIndicator, APP_INDICATOR_STATUS_ACTIVE); ps_app_indicator_set_menu(_trayIndicator, PS_GTK_MENU(_trayMenu)); useStatusIcon = false; } else { + DEBUG_LOG(("AppIndicator failed!")); useAppIndicator = false; } } @@ -732,7 +768,17 @@ void PsMainWindow::psFirstShow() { if (useUnityCount) { _psUnityLauncherEntry = ps_unity_launcher_entry_get_for_desktop_id("telegramdesktop.desktop"); - if (!_psUnityLauncherEntry) _psUnityLauncherEntry = ps_unity_launcher_entry_get_for_desktop_id("Telegram.desktop"); + if (_psUnityLauncherEntry) { + LOG(("Found Unity Launcher entry telegramdesktop.desktop!")); + } + _psUnityLauncherEntryOld = ps_unity_launcher_entry_get_for_desktop_id("Telegram.desktop"); + if (_psUnityLauncherEntryOld) { + LOG(("Found Unity Launcher entry Telegram.desktop!")); + } else if (_psUnityLauncherEntry) { + LOG(("Could not get Unity Launcher entry!")); + } + } else { + LOG(("Not using Unity Launcher count.")); } finished = false; @@ -1025,7 +1071,7 @@ void PsUpdateDownloader::partFailed(QNetworkReply::NetworkError e) { } bool _removeDirectory(const QString &path) { // from http://stackoverflow.com/questions/2256945/removing-a-non-empty-directory-programmatically-in-c-or-c - QByteArray pathRaw = path.toUtf8(); + QByteArray pathRaw = QFile::encodeName(path); DIR *d = opendir(pathRaw.constData()); if (!d) return false; @@ -1034,7 +1080,7 @@ bool _removeDirectory(const QString &path) { // from http://stackoverflow.com/qu if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, "..")) continue; QString fname = path + '/' + p->d_name; - QByteArray fnameRaw = fname.toUtf8(); + QByteArray fnameRaw = QFile::encodeName(fname); struct stat statbuf; if (!stat(fnameRaw.constData(), &statbuf)) { if (S_ISDIR(statbuf.st_mode)) { @@ -1287,6 +1333,11 @@ PsUpdateDownloader::~PsUpdateDownloader() { reply = 0; } + +QStringList psInitErrors() { + return _initErrors; +} + void psActivateProcess(uint64 pid) { // objc_activateProgram(); } @@ -1481,7 +1532,7 @@ bool psCheckReadyUpdate() { return false; } #elif defined Q_OS_LINUX - if (!moveFile(updater.absoluteFilePath().toUtf8().constData(), curUpdater.toUtf8().constData())) { + if (!moveFile(QFile::encodeName(updater.absoluteFilePath()).constData(), QFile::encodeName(curUpdater).constData())) { PsUpdateDownloader::clearAll(); return false; } @@ -1498,7 +1549,7 @@ void psOpenFile(const QString &name, bool openWith) { void psShowInFolder(const QString &name) { App::wnd()->layerHidden(); - system(("nautilus \"" + QFileInfo(name).absoluteDir().absolutePath() + "\"").toUtf8().constData()); + system(("nautilus \"" + QFileInfo(name).absoluteDir().absolutePath() + "\"").toLocal8Bit().constData()); } void psStart() { @@ -1556,6 +1607,9 @@ void psRegisterCustomScheme() { f.close(); if (_psRunCommand(qsl("desktop-file-install --dir=%1.local/share/applications --delete-original \"%2\"").arg(home).arg(file))) { + DEBUG_LOG(("App Info: removing old .desktop file")); + QFile(qsl("%1.local/share/applications/telegram.desktop").arg(home)).remove(); + _psRunCommand(qsl("update-desktop-database %1.local/share/applications").arg(home)); _psRunCommand(qsl("xdg-mime default telegramdesktop.desktop x-scheme-handler/tg")); } @@ -1607,7 +1661,7 @@ bool _execUpdater(bool update = true) { static const int MaxLen = 65536, MaxArgsCount = 128; char path[MaxLen] = {0}; - QByteArray data((cExeDir() + "Updater").toUtf8()); + QByteArray data(QFile::encodeName(cExeDir() + "Updater")); memcpy(path, data.constData(), data.size()); char *args[MaxArgsCount] = {0}, p_noupdate[] = "-noupdate", p_autostart[] = "-autostart", p_debug[] = "-debug", p_tosettings[] = "-tosettings", p_key[] = "-key", p_path[] = "-workpath"; @@ -1621,7 +1675,7 @@ bool _execUpdater(bool update = true) { if (cFromAutoStart()) args[argIndex++] = p_autostart; if (cDebug()) args[argIndex++] = p_debug; if (cDataFile() != (cTestMode() ? qsl("data_test") : qsl("data"))) { - QByteArray dataf = cDataFile().toUtf8(); + QByteArray dataf = QFile::encodeName(cDataFile()); if (dataf.size() < MaxLen) { memcpy(p_datafile, dataf.constData(), dataf.size()); args[argIndex++] = p_key; diff --git a/Telegram/SourceFiles/pspecific_linux.h b/Telegram/SourceFiles/pspecific_linux.h index 37326e5a6c..121b227fbe 100644 --- a/Telegram/SourceFiles/pspecific_linux.h +++ b/Telegram/SourceFiles/pspecific_linux.h @@ -175,6 +175,8 @@ private: }; +QStringList psInitErrors(); + void psActivateProcess(uint64 pid = 0); QString psLocalServerPrefix(); QString psCurrentCountry(); diff --git a/Telegram/SourceFiles/pspecific_mac.cpp b/Telegram/SourceFiles/pspecific_mac.cpp index e381e73747..fe2612a8c3 100644 --- a/Telegram/SourceFiles/pspecific_mac.cpp +++ b/Telegram/SourceFiles/pspecific_mac.cpp @@ -978,6 +978,11 @@ PsUpdateDownloader::~PsUpdateDownloader() { reply = 0; } + +QStringList psInitErrors() { + return QStringList(); +} + void psActivateProcess(uint64 pid) { objc_activateProgram(); } diff --git a/Telegram/SourceFiles/pspecific_mac.h b/Telegram/SourceFiles/pspecific_mac.h index bdc402fc7b..b6890d1d48 100644 --- a/Telegram/SourceFiles/pspecific_mac.h +++ b/Telegram/SourceFiles/pspecific_mac.h @@ -199,6 +199,8 @@ private: }; +QStringList psInitErrors(); + void psActivateProcess(uint64 pid = 0); QString psLocalServerPrefix(); QString psCurrentCountry(); diff --git a/Telegram/SourceFiles/pspecific_wnd.cpp b/Telegram/SourceFiles/pspecific_wnd.cpp index cc0f6b4ff1..7a76d3ad47 100644 --- a/Telegram/SourceFiles/pspecific_wnd.cpp +++ b/Telegram/SourceFiles/pspecific_wnd.cpp @@ -1778,6 +1778,10 @@ namespace { } } +QStringList psInitErrors() { + return QStringList(); +} + void psActivateProcess(uint64 pid) { if (pid) { ::EnumWindows((WNDENUMPROC)_ActivateProcess, (LPARAM)&pid); diff --git a/Telegram/SourceFiles/pspecific_wnd.h b/Telegram/SourceFiles/pspecific_wnd.h index 4ec4d0269f..43b6d6182f 100644 --- a/Telegram/SourceFiles/pspecific_wnd.h +++ b/Telegram/SourceFiles/pspecific_wnd.h @@ -176,6 +176,8 @@ private: }; +QStringList psInitErrors(); + void psActivateProcess(uint64 pid = 0); QString psLocalServerPrefix(); QString psCurrentCountry(); From 9e43f1b5de3d44041264ad670ec7456cd419c268 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 16 Jan 2015 20:00:35 +0300 Subject: [PATCH 2/5] trying to load specific versions of libs on linux, otherwise - just libs --- Telegram/SourceFiles/pspecific_linux.cpp | 25 +++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/Telegram/SourceFiles/pspecific_linux.cpp b/Telegram/SourceFiles/pspecific_linux.cpp index 6e738bbad4..34204f5212 100644 --- a/Telegram/SourceFiles/pspecific_linux.cpp +++ b/Telegram/SourceFiles/pspecific_linux.cpp @@ -331,8 +331,11 @@ namespace { void setupGTK() { QLibrary lib_gtk(QLatin1String("gtk-x11-2.0"), 0, 0), lib_indicator(QLatin1String("appindicator"), 1, 0); if (!lib_gtk.load()) { - _initErrors.push_back(QString("Failed to load 'gtk-x11-2.0' library!")); - return; + lib_gtk.setFileNameAndVersion(QLatin1String("gtk-x11-2.0"), QString()); + if (!lib_gtk.load()) { + _initErrors.push_back(QString("Failed to load 'gtk-x11-2.0' library!")); + return; + } } if (!loadFunction(lib_gtk, "gtk_init_check", ps_gtk_init_check)) return; @@ -354,8 +357,13 @@ namespace { if (lib_indicator.load()) { setupAppIndicator(lib_indicator); } else { - _initErrors.push_back(QString("Failed to load 'appindicator' library!")); - return; + lib_indicator.setFileNameAndVersion(QLatin1String("appindicator"), QString()); + if (lib_indicator.load()) { + setupAppIndicator(lib_indicator); + } else { + _initErrors.push_back(QString("Failed to load 'appindicator' library!")); + return; + } } if (!loadFunction(lib_gtk, "gdk_init_check", ps_gdk_init_check)) return; @@ -383,10 +391,13 @@ namespace { useAppIndicator = true; } void setupUnity() { - QLibrary lib_unity("unity", 9, 0); + QLibrary lib_unity(QLatin1String("unity"), 9, 0); if (!lib_unity.load()) { - _initErrors.push_back(QString("Failed to load 'unity' library!")); - return; + lib_unity.setFileNameAndVersion(QLatin1String("unity"), QString()); + if (!lib_unity.load()) { + _initErrors.push_back(QString("Failed to load 'unity' library!")); + return; + } } if (!loadFunction(lib_unity, "unity_launcher_entry_get_for_desktop_id", ps_unity_launcher_entry_get_for_desktop_id)) return; From 2f9b64fdd76f663d3d7a0f0d61249f6912e8a632 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 18 Jan 2015 11:37:02 +0300 Subject: [PATCH 3/5] fixed libappindicator load:q --- Telegram/SourceFiles/pspecific_linux.cpp | 65 ++++++++++++++++-------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/Telegram/SourceFiles/pspecific_linux.cpp b/Telegram/SourceFiles/pspecific_linux.cpp index 34204f5212..6de68e292b 100644 --- a/Telegram/SourceFiles/pspecific_linux.cpp +++ b/Telegram/SourceFiles/pspecific_linux.cpp @@ -330,9 +330,13 @@ namespace { } void setupGTK() { QLibrary lib_gtk(QLatin1String("gtk-x11-2.0"), 0, 0), lib_indicator(QLatin1String("appindicator"), 1, 0); - if (!lib_gtk.load()) { + if (lib_gtk.load()) { + _initErrors.push_back(QString("Loaded 'gtk-x11-2.0' version 0 library")); + } else { lib_gtk.setFileNameAndVersion(QLatin1String("gtk-x11-2.0"), QString()); - if (!lib_gtk.load()) { + if (lib_gtk.load()) { + _initErrors.push_back(QString("Loaded 'gtk-x11-2.0' withou version library")); + } else { _initErrors.push_back(QString("Failed to load 'gtk-x11-2.0' library!")); return; } @@ -355,14 +359,28 @@ namespace { if (!loadFunction(lib_gtk, "g_signal_connect_data", ps_g_signal_connect_data)) return; if (lib_indicator.load()) { + _initErrors.push_back(QString("Loaded 'appindicator' version 1 library")); setupAppIndicator(lib_indicator); } else { lib_indicator.setFileNameAndVersion(QLatin1String("appindicator"), QString()); if (lib_indicator.load()) { + _initErrors.push_back(QString("Loaded 'appindicator' without version library")); setupAppIndicator(lib_indicator); } else { - _initErrors.push_back(QString("Failed to load 'appindicator' library!")); - return; + lib_indicator.setFileNameAndVersion(QLatin1String("appindicator3"), 1); + if (lib_indicator.load()) { + _initErrors.push_back(QString("Loaded 'appindicator3' version 1 library")); + setupAppIndicator(lib_indicator); + } else { + lib_indicator.setFileNameAndVersion(QLatin1String("appindicator3"), QString()); + if (lib_indicator.load()) { + _initErrors.push_back(QString("Loaded 'appindicator3' without version library")); + setupAppIndicator(lib_indicator); + } else { + _initErrors.push_back(QString("Failed to load 'appindicator' library!")); + return; + } + } } } @@ -392,9 +410,13 @@ namespace { } void setupUnity() { QLibrary lib_unity(QLatin1String("unity"), 9, 0); - if (!lib_unity.load()) { + if (lib_unity.load()) { + _initErrors.push_back(QString("Loaded 'unity' version 9 library")); + } else { lib_unity.setFileNameAndVersion(QLatin1String("unity"), QString()); - if (!lib_unity.load()) { + if (lib_unity.load()) { + _initErrors.push_back(QString("Loaded 'unity' without version library")); + } else { _initErrors.push_back(QString("Failed to load 'unity' library!")); return; } @@ -422,7 +444,7 @@ namespace { }; _PsEventFilter *_psEventFilter = 0; - UnityLauncherEntry *_psUnityLauncherEntryOld = 0, *_psUnityLauncherEntry = 0; + UnityLauncherEntry *_psUnityLauncherEntry = 0; }; PsMainWindow::PsMainWindow(QWidget *parent) : QMainWindow(parent), @@ -509,6 +531,7 @@ void PsMainWindow::psTrayMenuUpdated() { if (useAppIndicator || useStatusIcon) { const QList &actions = trayIconMenu->actions(); if (_trayItems.isEmpty()) { + DEBUG_LOG(("Creating tray menu!")); for (int32 i = 0, l = actions.size(); i != l; ++i) { GtkWidget *item = ps_gtk_menu_item_new_with_label(actions.at(i)->text().toUtf8()); ps_gtk_menu_shell_append(PS_GTK_MENU_SHELL(_trayMenu), item); @@ -519,6 +542,7 @@ void PsMainWindow::psTrayMenuUpdated() { _trayItems.push_back(qMakePair(item, actions.at(i))); } } else { + DEBUG_LOG(("Updating tray menu!")); for (int32 i = 0, l = actions.size(); i != l; ++i) { if (i < _trayItems.size()) { ps_gtk_menu_item_set_label(reinterpret_cast(_trayItems.at(i).first), actions.at(i)->text().toUtf8()); @@ -572,14 +596,6 @@ void PsMainWindow::psUpdateCounter() { int32 counter = App::histories().unreadFull; setWindowTitle((counter > 0) ? qsl("Telegram (%1)").arg(counter) : qsl("Telegram")); - if (_psUnityLauncherEntryOld) { - if (counter > 0) { - ps_unity_launcher_entry_set_count(_psUnityLauncherEntryOld, (counter > 9999) ? 9999 : counter); - ps_unity_launcher_entry_set_count_visible(_psUnityLauncherEntryOld, TRUE); - } else { - ps_unity_launcher_entry_set_count_visible(_psUnityLauncherEntryOld, FALSE); - } - } if (_psUnityLauncherEntry) { if (counter > 0) { ps_unity_launcher_entry_set_count(_psUnityLauncherEntry, (counter > 9999) ? 9999 : counter); @@ -706,13 +722,17 @@ void PsMainWindow::psCreateTrayIcon() { 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) { + if (_trayIndicator) { + DEBUG_LOG(("Created appindicator!")); + } else { DEBUG_LOG(("Failed to app_indicator_new()!")); } } else { @@ -781,12 +801,13 @@ void PsMainWindow::psFirstShow() { _psUnityLauncherEntry = ps_unity_launcher_entry_get_for_desktop_id("telegramdesktop.desktop"); if (_psUnityLauncherEntry) { LOG(("Found Unity Launcher entry telegramdesktop.desktop!")); - } - _psUnityLauncherEntryOld = ps_unity_launcher_entry_get_for_desktop_id("Telegram.desktop"); - if (_psUnityLauncherEntryOld) { - LOG(("Found Unity Launcher entry Telegram.desktop!")); - } else if (_psUnityLauncherEntry) { - LOG(("Could not get Unity Launcher entry!")); + } else { + _psUnityLauncherEntry = ps_unity_launcher_entry_get_for_desktop_id("Telegram.desktop"); + if (_psUnityLauncherEntry) { + LOG(("Found Unity Launcher entry Telegram.desktop!")); + } else { + LOG(("Could not get Unity Launcher entry!")); + } } } else { LOG(("Not using Unity Launcher count.")); From ea5b82497759fbb8c1eeaff21233d117876e63cb Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 18 Jan 2015 12:23:03 +0300 Subject: [PATCH 4/5] trying to use gtk-3 and appindicator3, if failed use gtk-x11-2.0 and appindicator1, improved init logs --- Telegram/SourceFiles/main.cpp | 6 +-- Telegram/SourceFiles/pspecific_linux.cpp | 66 +++++++++++++++--------- Telegram/SourceFiles/pspecific_linux.h | 3 +- Telegram/SourceFiles/pspecific_mac.cpp | 12 +++-- Telegram/SourceFiles/pspecific_mac.h | 3 +- Telegram/SourceFiles/pspecific_wnd.cpp | 10 +++- Telegram/SourceFiles/pspecific_wnd.h | 3 +- 7 files changed, 67 insertions(+), 36 deletions(-) diff --git a/Telegram/SourceFiles/main.cpp b/Telegram/SourceFiles/main.cpp index 114729217d..bc2faedb19 100644 --- a/Telegram/SourceFiles/main.cpp +++ b/Telegram/SourceFiles/main.cpp @@ -46,9 +46,9 @@ int main(int argc, char *argv[]) { for (int32 i = 0; i < argc; ++i) { LOG(("Argument: %1").arg(QString::fromLocal8Bit(argv[i]))); } - QStringList errs = psInitErrors(); - for (int32 i = 0, l = errs.size(); i < l; ++i) { - LOG(("Init Error: %1").arg(errs.at(i))); + QStringList logs = psInitLogs(); + for (int32 i = 0, l = logs.size(); i < l; ++i) { + LOG(("Init Log: %1").arg(logs.at(i))); } } diff --git a/Telegram/SourceFiles/pspecific_linux.cpp b/Telegram/SourceFiles/pspecific_linux.cpp index 6de68e292b..b1b104a642 100644 --- a/Telegram/SourceFiles/pspecific_linux.cpp +++ b/Telegram/SourceFiles/pspecific_linux.cpp @@ -171,7 +171,7 @@ namespace { typedef UnityLauncherEntry* (*f_unity_launcher_entry_get_for_desktop_id)(const gchar* desktop_id); f_unity_launcher_entry_get_for_desktop_id ps_unity_launcher_entry_get_for_desktop_id = 0; - QStringList _initErrors; + QStringList _initLogs; template bool loadFunction(QLibrary &lib, const char *name, TFunction &func) { @@ -181,7 +181,7 @@ namespace { if (func) { return true; } else { - _initErrors.push_back(QString("Failed to load '%1' function!").arg(name)); + _initLogs.push_back(QString("Init Error: Failed to load '%1' function!").arg(name)); return false; } } @@ -329,16 +329,28 @@ namespace { setupUnity(); } void setupGTK() { - QLibrary lib_gtk(QLatin1String("gtk-x11-2.0"), 0, 0), lib_indicator(QLatin1String("appindicator"), 1, 0); + int useversion = 3; + QLibrary lib_gtk(QLatin1String("gtk-3"), 0, 0), lib_indicator(QLatin1String("appindicator3"), 1, 0); if (lib_gtk.load()) { - _initErrors.push_back(QString("Loaded 'gtk-x11-2.0' version 0 library")); + _initLogs.push_back(QString("Loaded 'gtk-3' version 0 library, will try appindicator3 lib")); } else { - lib_gtk.setFileNameAndVersion(QLatin1String("gtk-x11-2.0"), QString()); + lib_gtk.setFileNameAndVersion(QLatin1String("gtk-3"), QString()); if (lib_gtk.load()) { - _initErrors.push_back(QString("Loaded 'gtk-x11-2.0' withou version library")); + _initLogs.push_back(QString("Loaded 'gtk-3' without version library, will try appindicator3 lib")); } else { - _initErrors.push_back(QString("Failed to load 'gtk-x11-2.0' library!")); - return; + useversion = 2; + lib_gtk.setFileNameAndVersion(QLatin1String("gtk-x11-2.0"), 0); + if (lib_gtk.load()) { + _initLogs.push_back(QString("Loaded 'gtk-x11-2.0' version 0 library, will try appindicator lib")); + } else { + lib_gtk.setFileNameAndVersion(QLatin1String("gtk-x11-2.0"), QString()); + if (lib_gtk.load()) { + _initLogs.push_back(QString("Loaded 'gtk-x11-2.0' without version library, will try appindicator lib")); + } else { + _initLogs.push_back(QString("Init Error: Failed to load 'gtk-x11-2.0' library!")); + return; + } + } } } @@ -358,26 +370,26 @@ namespace { 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 (lib_indicator.load()) { - _initErrors.push_back(QString("Loaded 'appindicator' version 1 library")); + if (useversion == 3 && lib_indicator.load()) { + _initLogs.push_back(QString("Loaded 'appindicator3' version 1 library")); setupAppIndicator(lib_indicator); } else { - lib_indicator.setFileNameAndVersion(QLatin1String("appindicator"), QString()); - if (lib_indicator.load()) { - _initErrors.push_back(QString("Loaded 'appindicator' without version library")); + lib_indicator.setFileNameAndVersion(QLatin1String("appindicator3"), QString()); + if (useversion == 3 && lib_indicator.load()) { + _initLogs.push_back(QString("Loaded 'appindicator3' without version library")); setupAppIndicator(lib_indicator); } else { - lib_indicator.setFileNameAndVersion(QLatin1String("appindicator3"), 1); - if (lib_indicator.load()) { - _initErrors.push_back(QString("Loaded 'appindicator3' version 1 library")); + lib_indicator.setFileNameAndVersion(QLatin1String("appindicator"), 1); + if (useversion == 2 && lib_indicator.load()) { + _initLogs.push_back(QString("Loaded 'appindicator' version 1 library")); setupAppIndicator(lib_indicator); } else { - lib_indicator.setFileNameAndVersion(QLatin1String("appindicator3"), QString()); - if (lib_indicator.load()) { - _initErrors.push_back(QString("Loaded 'appindicator3' without version library")); + lib_indicator.setFileNameAndVersion(QLatin1String("appindicator"), QString()); + if (useversion == 2 && lib_indicator.load()) { + _initLogs.push_back(QString("Loaded 'appindicator' without version library")); setupAppIndicator(lib_indicator); } else { - _initErrors.push_back(QString("Failed to load 'appindicator' library!")); + _initLogs.push_back(QString("Failed to load 'appindicator' library!")); return; } } @@ -411,13 +423,13 @@ namespace { void setupUnity() { QLibrary lib_unity(QLatin1String("unity"), 9, 0); if (lib_unity.load()) { - _initErrors.push_back(QString("Loaded 'unity' version 9 library")); + _initLogs.push_back(QString("Loaded 'unity' version 9 library")); } else { lib_unity.setFileNameAndVersion(QLatin1String("unity"), QString()); if (lib_unity.load()) { - _initErrors.push_back(QString("Loaded 'unity' without version library")); + _initLogs.push_back(QString("Loaded 'unity' without version library")); } else { - _initErrors.push_back(QString("Failed to load 'unity' library!")); + _initLogs.push_back(QString("Init Error: Failed to load 'unity' library!")); return; } } @@ -1366,8 +1378,12 @@ PsUpdateDownloader::~PsUpdateDownloader() { } -QStringList psInitErrors() { - return _initErrors; +QStringList psInitLogs() { + return _initLogs; +} + +void psClearInitLogs() { + _initLogs = QStringList(); } void psActivateProcess(uint64 pid) { diff --git a/Telegram/SourceFiles/pspecific_linux.h b/Telegram/SourceFiles/pspecific_linux.h index 121b227fbe..3f61b624ce 100644 --- a/Telegram/SourceFiles/pspecific_linux.h +++ b/Telegram/SourceFiles/pspecific_linux.h @@ -175,7 +175,8 @@ private: }; -QStringList psInitErrors(); +QStringList psInitLogs(); +void psClearInitLogs(); void psActivateProcess(uint64 pid = 0); QString psLocalServerPrefix(); diff --git a/Telegram/SourceFiles/pspecific_mac.cpp b/Telegram/SourceFiles/pspecific_mac.cpp index fe2612a8c3..3229c5212a 100644 --- a/Telegram/SourceFiles/pspecific_mac.cpp +++ b/Telegram/SourceFiles/pspecific_mac.cpp @@ -24,7 +24,9 @@ Copyright (c) 2014 John Preston, https://desktop.telegram.org #include "historywidget.h" namespace { - bool frameless = true; + QStringList _initLogs; + + bool frameless = true; bool finished = true; class _PsEventFilter : public QAbstractNativeEventFilter { @@ -979,8 +981,12 @@ PsUpdateDownloader::~PsUpdateDownloader() { } -QStringList psInitErrors() { - return QStringList(); +QStringList psInitLogs() { + return _initLogs; +} + +void psClearInitLogs() { + _initLogs = QStringList(); } void psActivateProcess(uint64 pid) { diff --git a/Telegram/SourceFiles/pspecific_mac.h b/Telegram/SourceFiles/pspecific_mac.h index b6890d1d48..99cb839245 100644 --- a/Telegram/SourceFiles/pspecific_mac.h +++ b/Telegram/SourceFiles/pspecific_mac.h @@ -199,7 +199,8 @@ private: }; -QStringList psInitErrors(); +QStringList psInitLogs(); +void psClearInitLogs(); void psActivateProcess(uint64 pid = 0); QString psLocalServerPrefix(); diff --git a/Telegram/SourceFiles/pspecific_wnd.cpp b/Telegram/SourceFiles/pspecific_wnd.cpp index 7a76d3ad47..8ea2e8a468 100644 --- a/Telegram/SourceFiles/pspecific_wnd.cpp +++ b/Telegram/SourceFiles/pspecific_wnd.cpp @@ -51,6 +51,8 @@ Copyright (c) 2014 John Preston, https://desktop.telegram.org #pragma comment (lib,"Msimg32.lib") namespace { + QStringList _initLogs; + bool frameless = true; bool useDWM = false; bool useTheme = false; @@ -1778,8 +1780,12 @@ namespace { } } -QStringList psInitErrors() { - return QStringList(); +QStringList psInitLogs() { + return _initLogs; +} + +void psClearInitLogs() { + _initLogs = QStringList(); } void psActivateProcess(uint64 pid) { diff --git a/Telegram/SourceFiles/pspecific_wnd.h b/Telegram/SourceFiles/pspecific_wnd.h index 43b6d6182f..955ca01474 100644 --- a/Telegram/SourceFiles/pspecific_wnd.h +++ b/Telegram/SourceFiles/pspecific_wnd.h @@ -176,7 +176,8 @@ private: }; -QStringList psInitErrors(); +QStringList psInitLogs(); +void psClearInitLogs(); void psActivateProcess(uint64 pid = 0); QString psLocalServerPrefix(); From 12f6b340e5b09b7506ffcf37f9bcc5e433c74058 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 18 Jan 2015 15:52:14 +0300 Subject: [PATCH 5/5] clearing init logs --- Telegram/FixMake.sh | 40 ++++++++++++++++++----------------- Telegram/FixMake32.sh | 40 ++++++++++++++++++----------------- Telegram/SourceFiles/main.cpp | 1 + 3 files changed, 43 insertions(+), 38 deletions(-) diff --git a/Telegram/FixMake.sh b/Telegram/FixMake.sh index 693d69c163..1e14d64f72 100755 --- a/Telegram/FixMake.sh +++ b/Telegram/FixMake.sh @@ -1,19 +1,21 @@ -sed -i 's/\-lxcb\-render\-util/\/usr\/lib\/x86_64\-linux\-gnu\/libxcb\-render\-util\.a/g' Makefile -sed -i 's/\-lxcb\-render/\/usr\/lib\/x86_64\-linux\-gnu\/libxcb\-render\.a/g' Makefile -sed -i 's/\-lxcb\-sync/\/usr\/lib\/x86_64\-linux\-gnu\/libxcb\-sync\.a/g' Makefile -sed -i 's/\-lxcb\-keysyms/\/usr\/lib\/x86_64\-linux\-gnu\/libxcb\-keysyms\.a/g' Makefile -sed -i 's/\-lxcb\-icccm/\/usr\/lib\/x86_64\-linux\-gnu\/libxcb\-icccm\.a/g' Makefile -sed -i 's/\-lxcb\-xfixes/\/usr\/lib\/x86_64\-linux\-gnu\/libxcb\-xfixes\.a/g' Makefile -sed -i 's/\-lxcb\-shm/\/usr\/lib\/x86_64\-linux\-gnu\/libxcb\-shm\.a/g' Makefile -sed -i 's/\-lxcb\-randr/\/usr\/lib\/x86_64\-linux\-gnu\/libxcb\-randr\.a/g' Makefile -sed -i 's/\-lxcb\-shape/\/usr\/lib\/x86_64\-linux\-gnu\/libxcb\-shape\.a/g' Makefile -sed -i 's/\-lxcb\-image/\/usr\/lib\/x86_64\-linux\-gnu\/libxcb\-image\.a \/usr\/lib\/x86_64\-linux\-gnu\/libxcb\-util\.a/g' Makefile -sed -i 's/\-llzma/\/usr\/lib\/x86_64\-linux\-gnu\/liblzma\.a/g' Makefile -sed -i 's/\-lz/\/usr\/lib\/x86_64\-linux\-gnu\/libz\.a/g' Makefile -sed -i 's/\-lssl/\/usr\/lib\/x86_64\-linux\-gnu\/libssl\.a/g' Makefile -sed -i 's/\-lcrypto/\/usr\/lib\/x86_64\-linux\-gnu\/libcrypto\.a/g' Makefile -sed -i 's/\-lexif/\/usr\/lib\/x86_64\-linux\-gnu\/libexif\.a/g' Makefile -sed -i 's/\-lopusfile/\/usr\/local\/lib\/libopusfile\.a/g' Makefile -sed -i 's/\-lopus/\/usr\/local\/lib\/libopus\.a/g' Makefile -sed -i 's/\-lopenal/\/usr\/local\/lib\/libopenal\.a/g' Makefile -sed -i 's/\-logg/\/usr\/local\/lib\/libogg\.a/g' Makefile +Replace () { + CheckCommand="grep -ci '$1' Makefile" + CheckCount=$(eval $CheckCommand) + if [ "$CheckCount" -gt 0 ]; then + echo "Requested '$1' to '$2', found - replacing.." + ReplaceCommand="sed -i 's/$1/$2/g' Makefile" + eval $ReplaceCommand + else + echo "Skipping '$1' to '$2'" + fi +} + +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 '\-lopusfile' '\/usr\/local\/lib\/libopusfile\.a' +Replace '\-lopus' '\/usr\/local\/lib\/libopus\.a' +Replace '\-lopenal' '\/usr\/local\/lib\/libopenal\.a' +Replace '\-logg' '\/usr\/local\/lib\/libogg\.a' diff --git a/Telegram/FixMake32.sh b/Telegram/FixMake32.sh index 10492cc067..936b8de2b4 100755 --- a/Telegram/FixMake32.sh +++ b/Telegram/FixMake32.sh @@ -1,19 +1,21 @@ -sed -i 's/\-lxcb\-render\-util/\/usr\/lib\/i386\-linux\-gnu\/libxcb\-render\-util\.a/g' Makefile -sed -i 's/\-lxcb\-render/\/usr\/lib\/i386\-linux\-gnu\/libxcb\-render\.a/g' Makefile -sed -i 's/\-lxcb\-sync/\/usr\/lib\/i386\-linux\-gnu\/libxcb\-sync\.a/g' Makefile -sed -i 's/\-lxcb\-keysyms/\/usr\/lib\/i386\-linux\-gnu\/libxcb\-keysyms\.a/g' Makefile -sed -i 's/\-lxcb\-icccm/\/usr\/lib\/i386\-linux\-gnu\/libxcb\-icccm\.a/g' Makefile -sed -i 's/\-lxcb\-xfixes/\/usr\/lib\/i386\-linux\-gnu\/libxcb\-xfixes\.a/g' Makefile -sed -i 's/\-lxcb\-shm/\/usr\/lib\/i386\-linux\-gnu\/libxcb\-shm\.a/g' Makefile -sed -i 's/\-lxcb\-randr/\/usr\/lib\/i386\-linux\-gnu\/libxcb\-randr\.a/g' Makefile -sed -i 's/\-lxcb\-shape/\/usr\/lib\/i386\-linux\-gnu\/libxcb\-shape\.a/g' Makefile -sed -i 's/\-lxcb\-image/\/usr\/lib\/i386\-linux\-gnu\/libxcb\-image\.a \/usr\/lib\/i386\-linux\-gnu\/libxcb\-util\.a/g' Makefile -sed -i 's/\-llzma/\/usr\/lib\/i386\-linux\-gnu\/liblzma\.a/g' Makefile -sed -i 's/\-lz/\/usr\/lib\/i386\-linux\-gnu\/libz\.a/g' Makefile -sed -i 's/\-lssl/\/usr\/lib\/i386\-linux\-gnu\/libssl\.a/g' Makefile -sed -i 's/\-lcrypto/\/usr\/lib\/i386\-linux\-gnu\/libcrypto\.a/g' Makefile -sed -i 's/\-lexif/\/usr\/lib\/i386\-linux\-gnu\/libexif\.a/g' Makefile -sed -i 's/\-lopusfile/\/usr\/local\/lib\/libopusfile\.a/g' Makefile -sed -i 's/\-lopus/\/usr\/local\/lib\/libopus\.a/g' Makefile -sed -i 's/\-lopenal/\/usr\/local\/lib\/libopenal\.a/g' Makefile -sed -i 's/\-logg/\/usr\/local\/lib\/libogg\.a/g' Makefile +Replace () { + CheckCommand="grep -ci '$1' Makefile" + CheckCount=$(eval $CheckCommand) + if [ "$CheckCount" -gt 0 ]; then + echo "Requested '$1' to '$2', found - replacing.." + ReplaceCommand="sed -i 's/$1/$2/g' Makefile" + eval $ReplaceCommand + else + echo "Skipping '$1' to '$2'" + fi +} + +Replace '\-llzma' '\/usr\/lib\/i386\-linux\-gnu\/liblzma\.a' +Replace '\-lz' '\/usr\/lib\/i386\-linux\-gnu\/libz\.a' +Replace '\-lssl' '\/usr\/lib\/i386\-linux\-gnu\/libssl\.a' +Replace '\-lcrypto' '\/usr\/lib\/i386\-linux\-gnu\/libcrypto\.a' +Replace '\-lexif' '\/usr\/lib\/i386\-linux\-gnu\/libexif\.a' +Replace '\-lopusfile' '\/usr\/local\/lib\/libopusfile\.a' +Replace '\-lopus' '\/usr\/local\/lib\/libopus\.a' +Replace '\-lopenal' '\/usr\/local\/lib\/libopenal\.a' +Replace '\-logg' '\/usr\/local\/lib\/libogg\.a' diff --git a/Telegram/SourceFiles/main.cpp b/Telegram/SourceFiles/main.cpp index bc2faedb19..68e15b3d1d 100644 --- a/Telegram/SourceFiles/main.cpp +++ b/Telegram/SourceFiles/main.cpp @@ -51,6 +51,7 @@ int main(int argc, char *argv[]) { LOG(("Init Log: %1").arg(logs.at(i))); } } + psClearInitLogs(); DEBUG_LOG(("Application Info: ideal thread count: %1, using %2 connections per session").arg(QThread::idealThreadCount()).arg(cConnectionsInSession()));