use QSystemTrayIcon on not-Unity, Semibold Open Sans fixed by Qt patch

This commit is contained in:
John Preston 2015-02-16 17:51:50 +03:00
parent 394170bd4c
commit 871231c5cf
7 changed files with 78 additions and 75 deletions

View File

@ -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)

View File

@ -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"));

View File

@ -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<QAction*> &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)) {

View File

@ -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;

View File

@ -18,8 +18,6 @@
<file>art/emoji_200x.png</file>
<file>art/blank.gif</file>
<file>art/icon256.png</file>
<file>art/fonts/DejaVuSans.ttf</file>
<file>art/fonts/NanumMyeongjo-Regular.ttf</file>
</qresource>
<qresource prefix="/ava">
<file>art/chatcolor1.png</file>
@ -47,6 +45,6 @@
<file alias="lang_de.strings">langs/lang_de.strings</file>
<file alias="lang_nl.strings">langs/lang_nl.strings</file>
<file alias="lang_pt_BR.strings">langs/lang_pt_BR.strings</file>
<file alias="lang_ko.strings">langs/lang_ko.strings</file>
<file alias="lang_ko.strings">langs/lang_ko.strings</file>
</qresource>
</RCC>

View File

@ -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();
}

View File

@ -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);