From 871231c5cfe862806216baa47bfabbb565e9396f Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 16 Feb 2015 17:51:50 +0300 Subject: [PATCH] use QSystemTrayIcon on not-Unity, Semibold Open Sans fixed by Qt patch --- README.md | 2 - Telegram/SourceFiles/application.cpp | 4 - Telegram/SourceFiles/pspecific_linux.cpp | 91 +++++++++++++++---- Telegram/SourceFiles/settings.cpp | 4 - Telegram/SourceFiles/telegram_linux.qrc | 4 +- Telegram/SourceFiles/window.cpp | 10 +- .../fontconfig/qfontconfigdatabase.cpp | 38 +------- 7 files changed, 78 insertions(+), 75 deletions(-) diff --git a/README.md b/README.md index 8f8a95956..ff35ac7ab 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,6 @@ Source code is published under GPL v3, license is available [here](https://githu * Opus codec, opusfile ([BSD license](http://www.opus-codec.org/license/)) * libogg ([BSD license](http://www.xiph.org/downloads/)) * Open Sans font ([Apache License](http://www.apache.org/licenses/LICENSE-2.0.html)) -* DejaVu Sans font ([Free license](http://dejavu-fonts.org/wiki/License)) -* Nanum Myeongjo font ([SIL Open Font License](http://fonts.gstatic.com/ea/nanummyeongjo/v4/OFL.txt)) ###[Build instructions for Visual Studio 2013](https://github.com/telegramdesktop/tdesktop/blob/master/MSVC.md) diff --git a/Telegram/SourceFiles/application.cpp b/Telegram/SourceFiles/application.cpp index 0a6a9cacc..03adc0074 100644 --- a/Telegram/SourceFiles/application.cpp +++ b/Telegram/SourceFiles/application.cpp @@ -104,10 +104,6 @@ Application::Application(int &argc, char **argv) : PsApplication(argc, argv), installEventFilter(new _DebugWaiter(this)); -#if defined Q_OS_LINUX || defined Q_OS_LINUX64 - QFontDatabase::addApplicationFont(qsl(":/gui/art/fonts/DejaVuSans.ttf")); - QFontDatabase::addApplicationFont(qsl(":/gui/art/fonts/NanumMyeongjo-Regular.ttf")); -#endif QFontDatabase::addApplicationFont(qsl(":/gui/art/fonts/OpenSans-Regular.ttf")); QFontDatabase::addApplicationFont(qsl(":/gui/art/fonts/OpenSans-Bold.ttf")); QFontDatabase::addApplicationFont(qsl(":/gui/art/fonts/OpenSans-Semibold.ttf")); diff --git a/Telegram/SourceFiles/pspecific_linux.cpp b/Telegram/SourceFiles/pspecific_linux.cpp index c5e153f89..01aea56c4 100644 --- a/Telegram/SourceFiles/pspecific_linux.cpp +++ b/Telegram/SourceFiles/pspecific_linux.cpp @@ -43,6 +43,7 @@ extern "C" { namespace { bool frameless = true; bool finished = true; + bool isUnity = false; bool useGtkBase = false, useAppIndicator = false, useStatusIcon = false, trayIconChecked = false, useUnityCount = false; AppIndicator *_trayIndicator = 0; @@ -325,6 +326,9 @@ namespace { class _PsInitializer { public: _PsInitializer() { + isUnity = (QString(getenv("XDG_CURRENT_DESKTOP")).toLower() == QLatin1String("unity")); + + if (isUnity) cSetSupportTray(false); std::cout << "libs init..\n"; setupGtk(); setupUnity(); @@ -379,6 +383,8 @@ namespace { } void setupGtk() { + if (!isUnity) return; + QLibrary lib_gtk, lib_indicator; if (loadLibrary(lib_indicator, "appindicator3", 1)) { if (loadLibrary(lib_gtk, "gtk-3", 0)) { @@ -426,6 +432,8 @@ namespace { } void setupUnity() { + if (!useGtkBase || !isUnity) return; + QLibrary lib_unity(QLatin1String("unity"), 9, 0); if (!loadLibrary(lib_unity, "unity", 9)) return; @@ -483,7 +491,7 @@ void PsMainWindow::psRefreshTaskbarIcon() { } void PsMainWindow::psTrayMenuUpdated() { - if (useAppIndicator || useStatusIcon) { + if (isUnity && (useAppIndicator || useStatusIcon)) { const QList &actions = trayIconMenu->actions(); if (_trayItems.isEmpty()) { DEBUG_LOG(("Creating tray menu!")); @@ -509,27 +517,56 @@ void PsMainWindow::psTrayMenuUpdated() { } void PsMainWindow::psSetupTrayIcon() { - if (!cSupportTray()) return; - psUpdateCounter(); + if (isUnity) { + if (!cSupportTray()) return; + psUpdateCounter(); + } else { + if (!trayIcon) { + trayIcon = new QSystemTrayIcon(this); + + QIcon icon(QPixmap::fromImage(App::wnd()->iconLarge(), Qt::ColorOnly)); + + trayIcon->setIcon(icon); + trayIcon->setToolTip(QString::fromStdWString(AppName)); + connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(toggleTray(QSystemTrayIcon::ActivationReason)), Qt::UniqueConnection); + connect(trayIcon, SIGNAL(messageClicked()), this, SLOT(showFromTray())); + App::wnd()->updateTrayMenu(); + } + psUpdateCounter(); + + trayIcon->show(); + psUpdateDelegate(); + } } void PsMainWindow::psUpdateWorkmode() { if (!cSupportTray()) return; if (cWorkMode() == dbiwmWindowOnly) { - if (useAppIndicator) { - ps_app_indicator_set_status(_trayIndicator, APP_INDICATOR_STATUS_PASSIVE); - } else if (useStatusIcon) { - ps_gtk_status_icon_set_visible(_trayIcon, false); + if (isUnity) { + if (useAppIndicator) { + ps_app_indicator_set_status(_trayIndicator, APP_INDICATOR_STATUS_PASSIVE); + } else if (useStatusIcon) { + ps_gtk_status_icon_set_visible(_trayIcon, false); + } + } else { + if (trayIcon) { + trayIcon->setContextMenu(0); + trayIcon->deleteLater(); + } + trayIcon = 0; } } else { - if (useAppIndicator) { - ps_app_indicator_set_status(_trayIndicator, APP_INDICATOR_STATUS_ACTIVE); - } else if (useStatusIcon) { - ps_gtk_status_icon_set_visible(_trayIcon, true); + if (isUnity) { + if (useAppIndicator) { + ps_app_indicator_set_status(_trayIndicator, APP_INDICATOR_STATUS_ACTIVE); + } else if (useStatusIcon) { + ps_gtk_status_icon_set_visible(_trayIcon, true); + } + } else { + psSetupTrayIcon(); } } - setWindowIcon(wndIcon); } void PsMainWindow::psUpdateIndicator() { @@ -560,15 +597,24 @@ void PsMainWindow::psUpdateCounter() { } } - if (useAppIndicator) { - if (getms() > _psLastIndicatorUpdate + 1000) { - psUpdateIndicator(); - } else if (!_psUpdateIndicatorTimer.isActive()) { - _psUpdateIndicatorTimer.start(100); + if (isUnity) { + if (useAppIndicator) { + if (getms() > _psLastIndicatorUpdate + 1000) { + psUpdateIndicator(); + } else if (!_psUpdateIndicatorTimer.isActive()) { + _psUpdateIndicatorTimer.start(100); + } + } else if (useStatusIcon && trayIconChecked) { + loadPixbuf(_trayIconImageGen()); + ps_gtk_status_icon_set_from_pixbuf(_trayIcon, _trayPixbuf); } - } else if (useStatusIcon && trayIconChecked) { - loadPixbuf(_trayIconImageGen()); - ps_gtk_status_icon_set_from_pixbuf(_trayIcon, _trayPixbuf); + } else if (trayIcon) { + int32 counter = App::histories().unreadFull; + style::color bg = (App::histories().unreadMuted < counter) ? st::counterBG : st::counterMuteBG; + QIcon iconSmall; + iconSmall.addPixmap(QPixmap::fromImage(iconWithCounter(16, counter, bg, true), Qt::ColorOnly)); + iconSmall.addPixmap(QPixmap::fromImage(iconWithCounter(32, counter, bg, true), Qt::ColorOnly)); + trayIcon->setIcon(iconSmall); } } @@ -666,6 +712,11 @@ void PsMainWindow::psUpdatedPosition() { } void PsMainWindow::psCreateTrayIcon() { + if (!isUnity) { + cSetSupportTray(QSystemTrayIcon::isSystemTrayAvailable()); + return; + } + if (useAppIndicator) { DEBUG_LOG(("Trying to create AppIndicator")); if (ps_gtk_init_check(0, 0)) { diff --git a/Telegram/SourceFiles/settings.cpp b/Telegram/SourceFiles/settings.cpp index b3402eadc..3d1733569 100644 --- a/Telegram/SourceFiles/settings.cpp +++ b/Telegram/SourceFiles/settings.cpp @@ -43,11 +43,7 @@ bool gSendToMenu = false; bool gAutoUpdate = true; TWindowPos gWindowPos; bool gFromAutoStart = false; -#if defined Q_OS_WIN || defined Q_OS_MAC bool gSupportTray = true; -#else -bool gSupportTray = false; -#endif DBIWorkMode gWorkMode = dbiwmWindowAndTray; DBIConnectionType gConnectionType = dbictAuto; ConnectionProxy gConnectionProxy; diff --git a/Telegram/SourceFiles/telegram_linux.qrc b/Telegram/SourceFiles/telegram_linux.qrc index 5e977d964..0b83dd091 100644 --- a/Telegram/SourceFiles/telegram_linux.qrc +++ b/Telegram/SourceFiles/telegram_linux.qrc @@ -18,8 +18,6 @@ art/emoji_200x.png art/blank.gif art/icon256.png - art/fonts/DejaVuSans.ttf - art/fonts/NanumMyeongjo-Regular.ttf art/chatcolor1.png @@ -47,6 +45,6 @@ langs/lang_de.strings langs/lang_nl.strings langs/lang_pt_BR.strings - langs/lang_ko.strings + langs/lang_ko.strings diff --git a/Telegram/SourceFiles/window.cpp b/Telegram/SourceFiles/window.cpp index 8ae4f1397..622b09c6e 100644 --- a/Telegram/SourceFiles/window.cpp +++ b/Telegram/SourceFiles/window.cpp @@ -889,15 +889,15 @@ void Window::updateTrayMenu(bool force) { first->setText(lang(active ? lng_minimize_to_tray : lng_open_from_tray)); disconnect(first, SIGNAL(triggered(bool)), 0, 0); connect(first, SIGNAL(triggered(bool)), this, active ? SLOT(minimizeToTray()) : SLOT(showFromTray())); -#ifndef Q_OS_WIN - if (trayIcon) { - trayIcon->setContextMenu((active || cPlatform() != dbipMac) ? trayIconMenu : 0); - } -#endif } else { QAction *second = trayIconMenu->actions().at(1); second->setDisabled(!isVisible()); } +#ifndef Q_OS_WIN + if (trayIcon) { + trayIcon->setContextMenu((active || cPlatform() != dbipMac) ? trayIconMenu : 0); + } +#endif psTrayMenuUpdated(); } diff --git a/Telegram/_qt_5_4_0_patch/qtbase/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp b/Telegram/_qt_5_4_0_patch/qtbase/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp index 1683ac87a..f4d6fcd13 100644 --- a/Telegram/_qt_5_4_0_patch/qtbase/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp +++ b/Telegram/_qt_5_4_0_patch/qtbase/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp @@ -699,42 +699,6 @@ QStringList QFontconfigDatabase::fallbacksForFamily(const QString &family, QFont return fallbackFamilies; } -// copied from freetype with some modifications - -#ifndef FT_PARAM_TAG_IGNORE_PREFERRED_FAMILY -#define FT_PARAM_TAG_IGNORE_PREFERRED_FAMILY FT_MAKE_TAG('i', 'g', 'p', 'f') -#endif - -#ifndef FT_PARAM_TAG_IGNORE_PREFERRED_SUBFAMILY -#define FT_PARAM_TAG_IGNORE_PREFERRED_SUBFAMILY FT_MAKE_TAG('i', 'g', 'p', 's') -#endif - -/* documentation is in freetype.h */ - -FT_Error ___ft_New_Memory_Face(FT_Library library, const FT_Byte* file_base, FT_Long file_size, FT_Long face_index, FT_Face *aface) { - FT_Open_Args args; - - /* test for valid `library' and `face' delayed to FT_Open_Face() */ - if (!file_base) - return FT_Err_Invalid_Argument; - - FT_Parameter params[2]; - params[0].tag = FT_PARAM_TAG_IGNORE_PREFERRED_FAMILY; - params[0].data = 0; - params[1].tag = FT_PARAM_TAG_IGNORE_PREFERRED_SUBFAMILY; - params[1].data = 0; - args.flags = FT_OPEN_MEMORY | FT_OPEN_PARAMS; - args.memory_base = file_base; - args.memory_size = file_size; - args.stream = NULL; - args.num_params = 2; - args.params = params; - - return FT_Open_Face(library, &args, face_index, aface); -} - -// end - static FcPattern *queryFont(const FcChar8 *file, const QByteArray &data, int id, FcBlanks *blanks, int *count) { #if FC_VERSION < 20402 @@ -749,7 +713,7 @@ static FcPattern *queryFont(const FcChar8 *file, const QByteArray &data, int id, FcPattern *pattern = 0; FT_Face face; - if (!___ft_New_Memory_Face(lib, (const FT_Byte *)data.constData(), data.size(), id, &face)) { + if (!FT_New_Memory_Face(lib, (const FT_Byte *)data.constData(), data.size(), id, &face)) { *count = face->num_faces; pattern = FcFreeTypeQueryFace(face, file, id, blanks);