aboutsummaryrefslogtreecommitdiffstats
path: root/net-im
diff options
context:
space:
mode:
authoryuri <yuri@FreeBSD.org>2017-12-19 07:35:45 +0800
committeryuri <yuri@FreeBSD.org>2017-12-19 07:35:45 +0800
commita3cd1e1db9594dadc32652ac4590399b171beed4 (patch)
tree72cefbd5c06404a45785e358f3436341ed918381 /net-im
parentaa40b77e93db6faab748862392eafb0fff483d4e (diff)
downloadfreebsd-ports-gnome-a3cd1e1db9594dadc32652ac4590399b171beed4.tar.gz
freebsd-ports-gnome-a3cd1e1db9594dadc32652ac4590399b171beed4.tar.zst
freebsd-ports-gnome-a3cd1e1db9594dadc32652ac4590399b171beed4.zip
New port: net-im/telegram-desktop: Telegram Desktop messaging app
PR: 224193 Submitted by: Henry Hu <henry.hu.sh@gmail.com> Approved by: adamw (mentor) Differential Revision: https://reviews.freebsd.org/D13434
Diffstat (limited to 'net-im')
-rw-r--r--net-im/Makefile1
-rw-r--r--net-im/telegram-desktop/Makefile88
-rw-r--r--net-im/telegram-desktop/distinfo11
-rw-r--r--net-im/telegram-desktop/files/CMakeLists.inj14
-rw-r--r--net-im/telegram-desktop/files/gyp-patches375
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_SourceFiles___other_packer.cpp11
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_SourceFiles_base_build__config.h11
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_SourceFiles_base_lambda.h73
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_SourceFiles_config.h20
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_SourceFiles_layout.cpp22
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_SourceFiles_logs.cpp35
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_SourceFiles_main.cpp30
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_SourceFiles_mainwindow.cpp19
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_linux_linux__libs.cpp47
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_linux_linux__libs.h36
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_linux_main__window__linux.cpp87
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_platform__audio.h20
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_platform__file__utilities.h14
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_platform__main__window.h14
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_platform__notifications__manager.h14
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_platform__specific.h14
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_platform__window__title.h17
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_SourceFiles_qt__functions.cpp97
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_SourceFiles_qt__static__plugins.cpp19
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_SourceFiles_structs.cpp11
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_SourceFiles_ui_text_text.cpp17
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_SourceFiles_ui_text_text__block.cpp11
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_SourceFiles_ui_twidget.cpp14
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_ThirdParty_libtgvoip_audio_AudioInput.cpp11
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_ThirdParty_libtgvoip_audio_AudioOutput.cpp11
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_ThirdParty_libtgvoip_os_posix_NetworkSocketPosix.cpp10
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_ThirdParty_libtgvoip_threading.h11
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_ThirdParty_libtgvoip_webrtc__dsp_webrtc_base_stringutils.h11
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_gyp_PrecompiledHeader.cmake36
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_gyp_common.gypi11
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_gyp_settings__linux.gypi18
-rw-r--r--net-im/telegram-desktop/files/patch-Telegram_gyp_telegram__sources.txt18
-rw-r--r--net-im/telegram-desktop/files/patch-lib_xdg_tg.protocol9
-rw-r--r--net-im/telegram-desktop/pkg-descr13
-rw-r--r--net-im/telegram-desktop/pkg-plist11
40 files changed, 1312 insertions, 0 deletions
diff --git a/net-im/Makefile b/net-im/Makefile
index 599a5ae1ba74..10fbccf087b2 100644
--- a/net-im/Makefile
+++ b/net-im/Makefile
@@ -167,6 +167,7 @@
SUBDIR += skype4
SUBDIR += teamwords
SUBDIR += telegram
+ SUBDIR += telegram-desktop
SUBDIR += telegram-purple
SUBDIR += telegramqml
SUBDIR += telepathy-accounts-signon
diff --git a/net-im/telegram-desktop/Makefile b/net-im/telegram-desktop/Makefile
new file mode 100644
index 000000000000..384e7c047411
--- /dev/null
+++ b/net-im/telegram-desktop/Makefile
@@ -0,0 +1,88 @@
+# $FreeBSD$
+
+PORTNAME= telegram-desktop
+DISTVERSIONPREFIX= v
+DISTVERSION= 1.1.23
+CATEGORIES= net-im
+
+MAINTAINER= henry.hu.sh@gmail.com
+COMMENT= Telegram Desktop messaging app
+
+LICENSE= GPLv3
+LICENSE_FILE= ${WRKSRC}/LICENSE
+
+BUILD_DEPENDS= dee>0:devel/dee \
+ gyp:devel/py-gyp@${PY_FLAVOR}
+LIB_DEPENDS= libasound.so:audio/alsa-lib \
+ libavformat.so:multimedia/ffmpeg \
+ libdbus-1.so:devel/dbus \
+ libminizip.so:archivers/minizip \
+ libopenal.so:audio/openal-soft \
+ libopus.so:audio/opus \
+ libpulse.so:audio/pulseaudio
+
+USES= cmake:noninja,outsource desktop-file-utils gmake pkgconfig python:build ssl
+USE_GITHUB= yes
+GH_ACCOUNT= telegramdesktop
+GH_PROJECT= tdesktop
+GH_TUPLE= catchorg:Catch2:5ca44b68:catch/Telegram/ThirdParty/Catch \
+ mapbox:variant:550ac2f:variant/Telegram/ThirdParty/variant \
+ Microsoft:GSL:c5851a8:gsl/Telegram/ThirdParty/GSL \
+ telegramdesktop:libtgvoip:757a5d8e:libtgvoip/Telegram/ThirdParty/libtgvoip
+USE_GNOME= glib20 gtk30
+USE_QT5= core gui imageformats network widgets buildtools_build qmake_build
+USE_XORG= x11 xcb
+
+CMAKE_SOURCE_PATH= ${WRKSRC}/out/Release
+
+GYP_DEFINES= TDESKTOP_DISABLE_CRASH_REPORTS,TDESKTOP_DISABLE_AUTOUPDATE,TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME
+
+.include <bsd.port.pre.mk>
+
+.if ${OPSYS} == FreeBSD && ${OSVERSION} < 1100000
+CC= clang40
+CXX= clang++40
+BUILD_DEPENDS+= clang++40:devel/llvm40
+RUN_DEPENDS+= clang++40:devel/llvm40
+.endif
+
+post-patch:
+ @cd ${WRKSRC} && \
+ (${SED} -e " \
+ s|%%QT_VERSION%%|${QT5_VERSION}| ; \
+ s|%%LOCALBASE%%|${LOCALBASE}| ; \
+ s|%%CFLAGS%%|${CFLAGS:C/(.*)/'\1',/}| ; \
+ s|%%CXXFLAGS%%|${CXXFLAGS:C/(.*)/'\1',/}| ; \
+ s|%%LDFLAGS%%|${LDFLAGS:C/(.*)/'\1',/}| ; \
+ s|%%QT_BINDIR%%|${QT_BINDIR}| ; \
+ s|%%QT_INCDIR%%|${QT_INCDIR}| ; \
+ s|%%QT_LIBDIR%%|${QT_LIBDIR}| ; \
+ s|%%QMAKESPEC%%|${QMAKESPEC}| ; \
+ s|%%PYTHON_CMD%%|${PYTHON_CMD}|" \
+ ${FILESDIR}/gyp-patches | \
+ ${PATCH} -z .bak -s)
+ @${ECHO} "#define FREEBSD_QT_PLUGINDIR \"${QT_PLUGINDIR}\"" > ${WRKSRC}/Telegram/SourceFiles/FREEBSD_QT_PLUGINDIR.h
+
+pre-configure:
+ @cd ${WRKSRC} && gyp \
+ -Dbuild_defines=${GYP_DEFINES} \
+ -Gconfig=Release \
+ --depth=Telegram/gyp --generator-output=../.. -Goutput_dir=out Telegram/gyp/Telegram.gyp --format=cmake
+ @TOT=`wc -l < ${WRKSRC}/out/Release/CMakeLists.txt` && NUM=`expr $$TOT - 2` && \
+ ${SED} -i -e "$$NUM r ${FILESDIR}/CMakeLists.inj" ${WRKSRC}/out/Release/CMakeLists.txt
+
+do-install:
+ ${INSTALL_PROGRAM} ${BUILD_WRKSRC}/Telegram ${STAGEDIR}${PREFIX}/bin/${PORTNAME}
+ ${INSTALL_DATA} ${WRKSRC}/lib/xdg/telegramdesktop.desktop ${STAGEDIR}${PREFIX}/share/applications/${PORTNAME}.desktop
+ @${MKDIR} ${STAGEDIR}${PREFIX}/share/kservices5
+ ${INSTALL_DATA} ${WRKSRC}/lib/xdg/tg.protocol ${STAGEDIR}${PREFIX}/share/kservices5
+ @${MKDIR} ${STAGEDIR}${PREFIX}/share/appdata
+ ${INSTALL_DATA} ${WRKSRC}/lib/xdg/telegramdesktop.appdata.xml ${STAGEDIR}${PREFIX}/share/appdata/${PORTNAME}.appdata.xml
+.for icon_size in 16 32 48 64 128 256 512
+ @${MKDIR} ${STAGEDIR}${PREFIX}/share/icons/hicolor/${icon_size}x${icon_size}/apps
+ ${INSTALL_DATA} \
+ ${WRKSRC}/Telegram/Resources/art/icon${icon_size}.png \
+ ${STAGEDIR}${PREFIX}/share/icons/hicolor/${icon_size}x${icon_size}/apps/${PORTNAME}.png
+.endfor
+
+.include <bsd.port.post.mk>
diff --git a/net-im/telegram-desktop/distinfo b/net-im/telegram-desktop/distinfo
new file mode 100644
index 000000000000..d28acf319b8b
--- /dev/null
+++ b/net-im/telegram-desktop/distinfo
@@ -0,0 +1,11 @@
+TIMESTAMP = 1512711381
+SHA256 (telegramdesktop-tdesktop-v1.1.23_GH0.tar.gz) = 56b7fce84adf85a4af1c3174353169f32d0b0c052a4e7a284fc741fa96b04030
+SIZE (telegramdesktop-tdesktop-v1.1.23_GH0.tar.gz) = 16863984
+SHA256 (Microsoft-GSL-c5851a8_GH0.tar.gz) = 32fae541af0bc21cdf83922740db6a3a00fbb9cb9ace323fbc038b608ac36956
+SIZE (Microsoft-GSL-c5851a8_GH0.tar.gz) = 54462
+SHA256 (mapbox-variant-550ac2f_GH0.tar.gz) = 7ab3aa7c9fa672027f13721584df5f7ec09c0ecca499d374c6ac76e147ef7354
+SIZE (mapbox-variant-550ac2f_GH0.tar.gz) = 108686
+SHA256 (catchorg-Catch2-5ca44b68_GH0.tar.gz) = 8cdf2a345897bda1aaabffd4496dffe263768cef3e4254e74ae63545c8e12cc2
+SIZE (catchorg-Catch2-5ca44b68_GH0.tar.gz) = 375264
+SHA256 (telegramdesktop-libtgvoip-757a5d8e_GH0.tar.gz) = a745c2c097f6a98bf9443d0cee9e375f279571a18dcb51bf06684eccf82eb9c6
+SIZE (telegramdesktop-libtgvoip-757a5d8e_GH0.tar.gz) = 408328
diff --git a/net-im/telegram-desktop/files/CMakeLists.inj b/net-im/telegram-desktop/files/CMakeLists.inj
new file mode 100644
index 000000000000..e039cb1585af
--- /dev/null
+++ b/net-im/telegram-desktop/files/CMakeLists.inj
@@ -0,0 +1,14 @@
+# ------------- debian/CMakeLists.inj begin -------------
+# The text will be putted into the appropriate CMakeLists by debian/rules script
+
+# Avoid rpath compiler parameter
+set_target_properties(Telegram PROPERTIES SKIP_BUILD_RPATH TRUE)
+
+# This makes up for patch of gyp utility, supporting precompiled headers. If
+# Telegram/Patches/gyp.diff file will be changed in future, please check these
+# lines.
+include(../../Telegram/gyp/PrecompiledHeader.cmake)
+add_precompiled_header(Telegram ../../Telegram/SourceFiles/stdafx.h)
+
+# vim: ft=cmake
+# -------------- debian/CMakeLists.inj end --------------
diff --git a/net-im/telegram-desktop/files/gyp-patches b/net-im/telegram-desktop/files/gyp-patches
new file mode 100644
index 000000000000..379607eebba0
--- /dev/null
+++ b/net-im/telegram-desktop/files/gyp-patches
@@ -0,0 +1,375 @@
+--- Telegram/gyp/qt_rcc.gypi.orig 2017-09-05 17:38:38 UTC
++++ Telegram/gyp/qt_rcc.gypi
+@@ -28,7 +28,7 @@
+ '<(SHARED_INTERMEDIATE_DIR)/<(_target_name)/qrc/qrc_<(RULE_INPUT_ROOT).cpp',
+ ],
+ 'action': [
+- '<(qt_loc)/bin/rcc<(exe_ext)',
++ '%%QT_BINDIR%%/rcc',
+ '-name', '<(RULE_INPUT_ROOT)',
+ '-no-compress',
+ '<(RULE_INPUT_PATH)',
+--- Telegram/gyp/qt.gypi.orig 2017-09-05 17:38:38 UTC
++++ Telegram/gyp/qt.gypi
+@@ -27,25 +27,21 @@
+ [ 'build_macold', {
+ 'qt_version%': '5.3.2',
+ }, {
+- 'qt_version%': '5.6.2',
++ 'qt_version%': '%%QT_VERSION%%',
+ }]
+ ],
+ },
+ 'qt_libs': [
+- 'qwebp',
+- 'Qt5PrintSupport',
+- 'Qt5PlatformSupport',
+ 'Qt5Network',
+ 'Qt5Widgets',
+ 'Qt5Gui',
+- 'qtharfbuzzng',
+ ],
+ 'qt_version%': '<(qt_version)',
+ 'conditions': [
+ [ 'build_macold', {
+ 'linux_path_qt%': '/usr/local/macold/Qt-<(qt_version)',
+ }, {
+- 'linux_path_qt%': '/usr/local/tdesktop/Qt-<(qt_version)',
++ 'linux_path_qt%': '%%LOCALBASE%%/lib/qt',
+ }]
+ ]
+ },
+@@ -85,44 +81,24 @@
+ ],
+ }],
+ [ 'build_linux', {
+- 'qt_lib_prefix': 'lib',
+- 'qt_lib_debug_postfix': '.a',
+- 'qt_lib_release_postfix': '.a',
++ 'qt_lib_prefix': '',
++ 'qt_lib_debug_postfix': '',
++ 'qt_lib_release_postfix': '',
+ 'qt_libs': [
+- 'qxcb',
+- 'Qt5XcbQpa',
+- 'qconnmanbearer',
+- 'qgenericbearer',
+- 'qnmbearer',
+ '<@(qt_libs)',
+- 'Qt5DBus',
+ 'Qt5Core',
+- 'qtpcre',
+- 'Xi',
+- 'Xext',
+- 'Xfixes',
+- 'SM',
+- 'ICE',
+- 'fontconfig',
+- 'expat',
+- 'freetype',
+- 'z',
+- 'xcb-shm',
+- 'xcb-xfixes',
+- 'xcb-render',
+- 'xcb-static',
+ ],
+ }],
+ ],
+ },
+ 'qt_version%': '<(qt_version)',
+ 'qt_loc_unix': '<(qt_loc_unix)',
+- 'qt_version_loc': '<!(python -c "print(\'<(qt_version)\'.replace(\'.\', \'_\'))")',
++ 'qt_version_loc': '<!(%%PYTHON_CMD%% -c "print(\'<(qt_version)\'.replace(\'.\', \'_\'))")',
+ 'qt_libs_debug': [
+- '<!@(python -c "for s in \'<@(qt_libs)\'.split(\' \'): print(\'<(qt_lib_prefix)\' + s + \'<(qt_lib_debug_postfix)\')")',
++ '<!@(%%PYTHON_CMD%% -c "for s in \'<@(qt_libs)\'.split(\' \'): print(\'<(qt_lib_prefix)\' + s + \'<(qt_lib_debug_postfix)\')")',
+ ],
+ 'qt_libs_release': [
+- '<!@(python -c "for s in \'<@(qt_libs)\'.split(\' \'): print(\'<(qt_lib_prefix)\' + s + \'<(qt_lib_release_postfix)\')")',
++ '<!@(%%PYTHON_CMD%% -c "for s in \'<@(qt_libs)\'.split(\' \'): print(\'<(qt_lib_prefix)\' + s + \'<(qt_lib_release_postfix)\')")',
+ ],
+ },
+ 'qt_libs_debug': [ '<@(qt_libs_debug)' ],
+@@ -140,11 +116,6 @@
+ # '<!@(python <(DEPTH)/list_sources.py [sources] <(qt_moc_list_sources_arg))'
+ # where [sources] contains all your source files
+ 'qt_moc_list_sources_arg': '--moc-prefix SHARED_INTERMEDIATE_DIR/<(_target_name)/moc/moc_',
+-
+- 'linux_path_xkbcommon%': '/usr/local',
+- 'linux_lib_ssl%': '/usr/local/ssl/lib/libssl.a',
+- 'linux_lib_crypto%': '/usr/local/ssl/lib/libcrypto.a',
+- 'linux_lib_icu%': '/usr/lib/libicutu.a /usr/lib/libicui18n.a /usr/lib/libicuuc.a /usr/lib/libicudata.a',
+ },
+
+ 'configurations': {
+@@ -193,15 +164,17 @@
+ },
+
+ 'include_dirs': [
+- '<(qt_loc)/include',
+- '<(qt_loc)/include/QtCore',
+- '<(qt_loc)/include/QtGui',
+- '<(qt_loc)/include/QtCore/<(qt_version)',
+- '<(qt_loc)/include/QtGui/<(qt_version)',
+- '<(qt_loc)/include/QtCore/<(qt_version)/QtCore',
+- '<(qt_loc)/include/QtGui/<(qt_version)/QtGui',
++ '%%QT_INCDIR%%',
++ '%%QT_INCDIR%%/QtCore',
++ '%%QT_INCDIR%%/QtGui',
++ '%%QT_INCDIR%%/QtCore/<(qt_version)',
++ '%%QT_INCDIR%%/QtGui/<(qt_version)',
++ '%%QT_INCDIR%%/QtCore/<(qt_version)/QtCore',
++ '%%QT_INCDIR%%/QtGui/<(qt_version)/QtGui',
+ ],
+ 'library_dirs': [
++ '%%LOCALBASE%%/lib',
++ '%%QT_LIBDIR%%/',
+ '<(qt_loc)/lib',
+ '<(qt_loc)/plugins',
+ '<(qt_loc)/plugins/bearer',
+@@ -220,25 +193,20 @@
+ '<(qt_loc)/plugins/platforminputcontexts',
+ ],
+ 'libraries': [
+- '<(linux_path_xkbcommon)/lib/libxkbcommon.a',
+ '<@(qt_libs_release)',
+- '<(linux_lib_ssl)',
+- '<(linux_lib_crypto)',
+- '<!@(python -c "for s in \'<(linux_lib_icu)\'.split(\' \'): print(s)")',
++ '-lcrypto',
+ '-lxcb',
+ '-lX11',
+ '-lX11-xcb',
+ '-ldbus-1',
+- '-ldl',
+ '-lgthread-2.0',
+ '-lglib-2.0',
+ '-lpthread',
+ ],
+ 'include_dirs': [
+- '<(qt_loc)/mkspecs/linux-g++',
++ '%%QMAKESPEC%%',
+ ],
+ 'ldflags': [
+- '-static-libstdc++',
+ '-pthread',
+ '-g',
+ '-rdynamic',
+@@ -260,12 +228,12 @@
+ '<(SHARED_INTERMEDIATE_DIR)/<(_target_name)/moc/moc_<(RULE_INPUT_ROOT).cpp',
+ ],
+ 'action': [
+- '<(qt_loc)/bin/moc<(exe_ext)',
++ '%%QT_BINDIR%%/moc',
+
+ # Silence "Note: No relevant classes found. No output generated."
+ '--no-notes',
+
+- '<!@(python -c "for s in \'<@(_defines)\'.split(\' \'): print(\'-D\' + s)")',
++ '<!@(%%PYTHON_CMD%% -c "for s in \'<@(_defines)\'.split(\' \'): print(\'-D\' + s)")',
+ # '<!@(python -c "for s in \'<@(_include_dirs)\'.split(\' \'): print(\'-I\' + s)")',
+ '<(RULE_INPUT_PATH)',
+ '-o', '<(SHARED_INTERMEDIATE_DIR)/<(_target_name)/moc/moc_<(RULE_INPUT_ROOT).cpp',
+--- Telegram/gyp/telegram_linux.gypi.orig 2017-09-05 17:38:38 UTC
++++ Telegram/gyp/telegram_linux.gypi
+@@ -33,7 +33,7 @@
+ 'linux_path_va%': '/usr/local',
+ 'linux_path_vdpau%': '/usr/local',
+ 'linux_path_breakpad%': '<(libs_loc)/breakpad',
+- 'linux_path_opus_include%': '<(libs_loc)/opus/include',
++ 'linux_path_opus_include%': '%%LOCALBASE%%/include/opus',
+ },
+ 'include_dirs': [
+ '/usr/local/include',
+@@ -52,48 +52,34 @@
+ '<(linux_path_breakpad)/lib',
+ ],
+ 'libraries': [
+- 'breakpad_client',
+- 'composeplatforminputcontextplugin',
+- 'ibusplatforminputcontextplugin',
+- 'fcitxplatforminputcontextplugin',
+- 'himeplatforminputcontextplugin',
+- 'liblzma.a',
+- 'libopenal.a',
+- 'libavformat.a',
+- 'libavcodec.a',
+- 'libswresample.a',
+- 'libswscale.a',
+- 'libavutil.a',
+- 'libopus.a',
+- 'libva-x11.a',
+- 'libva-drm.a',
+- 'libva.a',
+- 'libvdpau.a',
+- 'libdrm.a',
+- 'libz.a',
++ 'openal',
++ 'avformat',
++ 'avcodec',
++ 'swresample',
++ 'swscale',
++ 'avutil',
++ 'minizip',
++ 'opus',
++ 'z',
+ # '<!(pkg-config 2> /dev/null --libs <@(pkgconfig_libs))',
+ ],
+ 'cflags_cc': [
+- '<!(pkg-config 2> /dev/null --cflags appindicator-0.1)',
+- '<!(pkg-config 2> /dev/null --cflags gtk+-2.0)',
+- '<!(pkg-config 2> /dev/null --cflags glib-2.0)',
++# '<!(pkg-config 2> /dev/null --cflags appindicator-0.1)',
++ '<!(pkg-config 2> /dev/null --cflags gtk+-3.0)',
+ '<!(pkg-config 2> /dev/null --cflags dee-1.0)',
+ ],
+ 'configurations': {
+ 'Release': {
+ 'cflags': [
+- '-Ofast',
+- '-flto',
++ %%CFLAGS%%
+ '-fno-strict-aliasing',
+ ],
+ 'cflags_cc': [
+- '-Ofast',
+- '-flto',
++ %%CXXFLAGS%%
+ '-fno-strict-aliasing',
+ ],
+ 'ldflags': [
+- '-Ofast',
+- '-flto',
++ %%LDFLAGS%%
+ ],
+ },
+ },
+--- Telegram/gyp/Telegram.gyp.orig 2017-09-05 17:38:38 UTC
++++ Telegram/gyp/Telegram.gyp
+@@ -61,7 +61,7 @@
+ 'pt-BR',
+ ],
+ 'build_defines%': '',
+- 'list_sources_command': 'python <(DEPTH)/list_sources.py --input <(DEPTH)/telegram_sources.txt --replace src_loc=<(src_loc)',
++ 'list_sources_command': '%%PYTHON_CMD%% <(DEPTH)/list_sources.py --input <(DEPTH)/telegram_sources.txt --replace src_loc=<(src_loc)',
+ },
+ 'includes': [
+ 'common_executable.gypi',
+@@ -80,28 +80,19 @@
+ 'codegen.gyp:codegen_numbers',
+ 'codegen.gyp:codegen_style',
+ 'tests/tests.gyp:tests',
+- 'utils.gyp:Updater',
+ '../ThirdParty/libtgvoip/libtgvoip.gyp:libtgvoip',
+ ],
+
+ 'defines': [
+- 'AL_LIBTYPE_STATIC',
+ 'AL_ALEXT_PROTOTYPES',
+ 'TGVOIP_USE_CXX11_LIB',
+- '<!@(python -c "for s in \'<(build_defines)\'.split(\',\'): print(s)")',
++ '<!@(%%PYTHON_CMD%% -c "for s in \'<(build_defines)\'.split(\',\'): print(s)")',
+ ],
+
+ 'include_dirs': [
+ '<(src_loc)',
+ '<(SHARED_INTERMEDIATE_DIR)',
+- '<(libs_loc)/breakpad/src',
+- '<(libs_loc)/lzma/C',
+- '<(libs_loc)/libexif-0.6.20',
+- '<(libs_loc)/zlib-1.2.8',
+- '<(libs_loc)/ffmpeg',
+- '<(libs_loc)/openal-soft/include',
+- '<(libs_loc)/opus/include',
+- '<(minizip_loc)',
++ '%%LOCALBASE%%/include/minizip',
+ '<(sp_media_key_tap_loc)',
+ '<(emoji_suggestions_loc)',
+ '<(submodules_loc)/GSL/include',
+@@ -113,7 +104,7 @@
+ '<!@(<(list_sources_command) <(qt_moc_list_sources_arg))',
+ ],
+ 'sources!': [
+- '<!@(<(list_sources_command) <(qt_moc_list_sources_arg) --exclude_for <(build_os))',
++ '<!@(<(list_sources_command) <(qt_moc_list_sources_arg) --exclude_for linux)',
+ ],
+ 'conditions': [
+ [ '"<(official_build_target)" != ""', {
+--- Telegram/ThirdParty/libtgvoip/libtgvoip.gyp.orig 2017-07-06 17:16:18 UTC
++++ Telegram/ThirdParty/libtgvoip/libtgvoip.gyp
+@@ -13,11 +13,12 @@
+ 'variables': {
+ 'tgvoip_src_loc': '.',
+ 'official_build_target%': '',
+- 'linux_path_opus_include%': '<(DEPTH)/../../../Libraries/opus/include',
++ 'linux_path_opus_include%': '%%LOCALBASE%%/include/opus',
+ },
+ 'include_dirs': [
+ '<(tgvoip_src_loc)/webrtc_dsp',
+ '<(linux_path_opus_include)',
++ '%%LOCALBASE%%/include/',
+ ],
+ 'direct_dependent_settings': {
+ 'include_dirs': [
+@@ -371,12 +372,13 @@
+ },
+ ],
+ [
+- '"<(OS)" == "linux"', {
++ '"<(OS)" == "freebsd"', {
+ 'defines': [
+ 'WEBRTC_POSIX',
+ ],
+ 'cflags_cc': [
+ '-msse2',
++ '-std=c++11',
+ ],
+ 'direct_dependent_settings': {
+ 'libraries': [
+--- Telegram/gyp/codegen_rules.gypi.orig 2017-12-11 17:08:58 UTC
++++ Telegram/gyp/codegen_rules.gypi
+@@ -28,7 +28,7 @@
+ '<(SHARED_INTERMEDIATE_DIR)/update_dependent_styles.timestamp',
+ ],
+ 'action': [
+- 'python', '<(DEPTH)/update_dependent.py', '--styles',
++ '%%PYTHON_CMD%%', '<(DEPTH)/update_dependent.py', '--styles',
+ '-I', '<(res_loc)', '-I', '<(src_loc)',
+ '-o', '<(SHARED_INTERMEDIATE_DIR)/update_dependent_styles.timestamp',
+ '<@(style_files)',
+@@ -39,13 +39,13 @@
+ 'inputs': [
+ '<(DEPTH)/update_dependent.py',
+ '<@(qrc_files)',
+- '<!@(python <(DEPTH)/update_dependent.py --qrc_list <@(qrc_files))',
++ '<!@(%%PYTHON_CMD%% <(DEPTH)/update_dependent.py --qrc_list <@(qrc_files))',
+ ],
+ 'outputs': [
+ '<(SHARED_INTERMEDIATE_DIR)/update_dependent_qrc.timestamp',
+ ],
+ 'action': [
+- 'python', '<(DEPTH)/update_dependent.py', '--qrc',
++ '%%PYTHON_CMD%%', '<(DEPTH)/update_dependent.py', '--qrc',
+ '-o', '<(SHARED_INTERMEDIATE_DIR)/update_dependent_qrc.timestamp',
+ '<@(qrc_files)',
+ ],
+@@ -122,7 +122,7 @@
+ '<(SHARED_INTERMEDIATE_DIR)/scheme.h',
+ ],
+ 'action': [
+- 'python', '<(src_loc)/codegen/scheme/codegen_scheme.py',
++ '%%PYTHON_CMD%%', '<(src_loc)/codegen/scheme/codegen_scheme.py',
+ '-o', '<(SHARED_INTERMEDIATE_DIR)', '<(res_loc)/scheme.tl',
+ ],
+ 'message': 'codegen_scheme-ing scheme.tl..',
+--- Telegram/gyp/tests/tests.gyp.orig 2017-12-11 17:12:35 UTC
++++ Telegram/gyp/tests/tests.gyp
+@@ -26,7 +26,7 @@
+ 'src_loc': '../../SourceFiles',
+ 'submodules_loc': '../../ThirdParty',
+ 'mac_target': '10.10',
+- 'list_tests_command': 'python <(DEPTH)/tests/list_tests.py --input <(DEPTH)/tests/tests_list.txt',
++ 'list_tests_command': '%%PYTHON_CMD%% <(DEPTH)/tests/list_tests.py --input <(DEPTH)/tests/tests_list.txt',
+ },
+ 'targets': [{
+ 'target_name': 'tests',
diff --git a/net-im/telegram-desktop/files/patch-Telegram_SourceFiles___other_packer.cpp b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles___other_packer.cpp
new file mode 100644
index 000000000000..6edc49a306f8
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles___other_packer.cpp
@@ -0,0 +1,11 @@
+--- Telegram/SourceFiles/_other/packer.cpp.orig 2017-09-05 17:38:38 UTC
++++ Telegram/SourceFiles/_other/packer.cpp
+@@ -246,7 +246,7 @@ int main(int argc, char *argv[])
+ }
+ QByteArray inner = f.readAll();
+ stream << name << quint32(inner.size()) << inner;
+-#if defined Q_OS_MAC || defined Q_OS_LINUX
++#if defined Q_OS_MAC || defined Q_OS_LINUX || defined Q_OS_FREEBSD
+ stream << (QFileInfo(fullName).isExecutable() ? true : false);
+ #endif
+ }
diff --git a/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_base_build__config.h b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_base_build__config.h
new file mode 100644
index 000000000000..6138f504dfca
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_base_build__config.h
@@ -0,0 +1,11 @@
+--- Telegram/SourceFiles/base/build_config.h.orig 2017-09-05 17:38:38 UTC
++++ Telegram/SourceFiles/base/build_config.h
+@@ -26,7 +26,7 @@ Copyright (c) 2014-2017 John Preston, ht
+
+ #if defined(__APPLE__)
+ #define OS_MAC 1
+-#elif defined(__linux__) // __APPLE__
++#elif defined(__linux__) || defined(__FreeBSD__)// __APPLE__
+ #define OS_LINUX 1
+ #elif defined(_WIN32) // __APPLE__ || __linux__
+ #define OS_WIN 1
diff --git a/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_base_lambda.h b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_base_lambda.h
new file mode 100644
index 000000000000..560cfdbc36d1
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_base_lambda.h
@@ -0,0 +1,73 @@
+--- Telegram/SourceFiles/base/lambda.h.orig 2017-09-05 17:38:38 UTC
++++ Telegram/SourceFiles/base/lambda.h
+@@ -212,11 +212,14 @@ protected:
+
+ template <typename Lambda, typename Return, typename ...Args>
+ struct vtable_once : public vtable_once_impl<Lambda, is_large<Lambda>, Return, Args...> {
+- static const vtable_once instance;
++ static const vtable_once* get_instance();
+ };
+
+ template <typename Lambda, typename Return, typename ...Args>
+-const vtable_once<Lambda, Return, Args...> vtable_once<Lambda, Return, Args...>::instance = {};
++const vtable_once<Lambda, Return, Args...>* vtable_once<Lambda, Return, Args...>::get_instance() {
++ static vtable_once<Lambda, Return, Args...> instance;
++ return &instance;
++}
+
+ template <typename Lambda, bool IsLarge, typename Return, typename ...Args> struct vtable_impl;
+
+@@ -262,12 +265,14 @@ struct vtable_impl<Lambda, false, Return
+
+ template <typename Lambda, typename Return, typename ...Args>
+ struct vtable : public vtable_impl<Lambda, is_large<Lambda>, Return, Args...> {
+- static const vtable instance;
++ static const vtable* get_instance();
+ };
+
+ template <typename Lambda, typename Return, typename ...Args>
+-const vtable<Lambda, Return, Args...> vtable<Lambda, Return, Args...>::instance = {};
+-
++const vtable<Lambda, Return, Args...>* vtable<Lambda, Return, Args...>::get_instance() {
++ static vtable<Lambda, Return, Args...> instance;
++ return &instance;
++}
+ } // namespace lambda_internal
+
+ template <typename Return, typename ...Args>
+@@ -346,7 +351,7 @@ public:
+ // Copy / move construct / assign from an arbitrary type.
+ template <typename Lambda, typename = std::enable_if_t<std::is_convertible<decltype(std::declval<Lambda>()(std::declval<Args>()...)),Return>::value>>
+ lambda_once(Lambda other) {
+- data_.vtable = &lambda_internal::vtable_once<Lambda, Return, Args...>::instance;
++ data_.vtable = lambda_internal::vtable_once<Lambda, Return, Args...>::get_instance();
+ lambda_internal::vtable_once<Lambda, Return, Args...>::construct_move_lambda_method(data_.storage, &other);
+ }
+ template <typename Lambda, typename = std::enable_if_t<std::is_convertible<decltype(std::declval<Lambda>()(std::declval<Args>()...)),Return>::value>>
+@@ -354,7 +359,7 @@ public:
+ if (data_.vtable) {
+ data_.vtable->destruct(data_.storage);
+ }
+- data_.vtable = &lambda_internal::vtable_once<Lambda, Return, Args...>::instance;
++ data_.vtable = lambda_internal::vtable_once<Lambda, Return, Args...>::get_instance();
+ lambda_internal::vtable_once<Lambda, Return, Args...>::construct_move_lambda_method(data_.storage, &other);
+ return *this;
+ }
+@@ -424,7 +429,7 @@ public:
+
+ // Copy / move construct / assign from an arbitrary type.
+ template <typename Lambda, typename = std::enable_if_t<std::is_convertible<decltype(std::declval<Lambda>()(std::declval<Args>()...)),Return>::value>>
+- lambda(Lambda other) : Parent(&lambda_internal::vtable<Lambda, Return, Args...>::instance, typename Parent::Private()) {
++ lambda(Lambda other) : Parent(lambda_internal::vtable<Lambda, Return, Args...>::get_instance(), typename Parent::Private()) {
+ lambda_internal::vtable<Lambda, Return, Args...>::construct_move_lambda_method(this->data_.storage, &other);
+ }
+ template <typename Lambda, typename = std::enable_if_t<std::is_convertible<decltype(std::declval<Lambda>()(std::declval<Args>()...)),Return>::value>>
+@@ -432,7 +437,7 @@ public:
+ if (this->data_.vtable) {
+ this->data_.vtable->destruct(this->data_.storage);
+ }
+- this->data_.vtable = &lambda_internal::vtable<Lambda, Return, Args...>::instance;
++ this->data_.vtable = lambda_internal::vtable<Lambda, Return, Args...>::get_instance();
+ lambda_internal::vtable<Lambda, Return, Args...>::construct_move_lambda_method(this->data_.storage, &other);
+ return *this;
+ }
diff --git a/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_config.h b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_config.h
new file mode 100644
index 000000000000..3b596bd1068c
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_config.h
@@ -0,0 +1,20 @@
+--- Telegram/SourceFiles/config.h.orig 2017-09-05 17:38:38 UTC
++++ Telegram/SourceFiles/config.h
+@@ -270,7 +270,7 @@ inline const char *cApiDeviceModel() {
+ return "PC";
+ #elif defined Q_OS_MAC
+ return "Mac";
+-#elif defined Q_OS_LINUX
++#elif defined Q_OS_LINUX || defined Q_OS_FREEBSD
+ return "PC";
+ #endif
+ }
+@@ -281,6 +281,8 @@ inline const char *cApiSystemVersion() {
+ return "OS X";
+ #elif defined Q_OS_LINUX
+ return "Linux";
++#elif defined Q_OS_FREEBSD
++ return "FreeBSD";
+ #endif
+ }
+
diff --git a/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_layout.cpp b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_layout.cpp
new file mode 100644
index 000000000000..22545c6e01a0
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_layout.cpp
@@ -0,0 +1,22 @@
+--- Telegram/SourceFiles/layout.cpp.orig 2017-09-05 17:38:38 UTC
++++ Telegram/SourceFiles/layout.cpp
+@@ -264,16 +264,16 @@ bool documentIsExecutableName(const QStr
+ *result = qsl("\
+ action app bin command csh osx workflow\
+ ").split(' ');
+-#elif defined Q_OS_LINUX // Q_OS_MAC
++#elif defined Q_OS_LINUX || defined Q_OS_FREEBSD // Q_OS_MAC
+ *result = qsl("\
+ bin csh ksh out run\
+ ").split(' ');
+-#else // Q_OS_MAC || Q_OS_LINUX
++#else // Q_OS_MAC || Q_OS_LINUX || Q_OS_FREEBSD
+ *result = qsl("\
+ bat bin cmd com cpl exe gadget inf ins inx isu job jse lnk msc msi \
+ msp mst paf pif ps1 reg rgs sct shb shs u3p vb vbe vbs vbscript ws wsf\
+ ").split(' ');
+-#endif // !Q_OS_MAC && !Q_OS_LINUX
++#endif // !Q_OS_MAC && !Q_OS_LINUX && ! Q_OS_FREEBSD
+ return result.release();
+ })());
+
diff --git a/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_logs.cpp b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_logs.cpp
new file mode 100644
index 000000000000..2155b99fee85
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_logs.cpp
@@ -0,0 +1,35 @@
+--- Telegram/SourceFiles/logs.cpp.orig 2017-09-05 17:38:38 UTC
++++ Telegram/SourceFiles/logs.cpp
+@@ -311,7 +311,7 @@ namespace Logs {
+ QString initialWorkingDir = QDir(cWorkingDir()).absolutePath() + '/', moveOldDataFrom;
+ if (cBetaVersion()) {
+ cSetDebug(true);
+-#if defined Q_OS_MAC || defined Q_OS_LINUX
++#if defined Q_OS_MAC || defined Q_OS_LINUX || defined Q_OS_FREEBSD
+ } else {
+ #ifdef _DEBUG
+ cForceWorkingDir(cExeDir());
+@@ -322,11 +322,11 @@ namespace Logs {
+ #endif // else for _DEBUG
+ workingDirChosen = true;
+
+-#if defined Q_OS_LINUX && !defined _DEBUG // fix first version
++#if (defined Q_OS_LINUX || defined Q_OS_FREEBSD) && !defined _DEBUG // fix first version
+ moveOldDataFrom = initialWorkingDir;
+-#endif // Q_OS_LINUX && !_DEBUG
++#endif // (Q_OS_LINUX || Q_OS_FREEBSD) && !_DEBUG
+
+-#elif defined Q_OS_WINRT // Q_OS_MAC || Q_OS_LINUX
++#elif defined Q_OS_WINRT // Q_OS_MAC || Q_OS_LINUX || Q_OS_FREEBSD
+ } else {
+ cForceWorkingDir(psAppDataPath());
+ workingDirChosen = true;
+@@ -502,7 +502,7 @@ namespace Logs {
+ //OutputDebugString(reinterpret_cast<const wchar_t *>(msg.utf16()));
+ #elif defined Q_OS_MAC
+ //objc_outputDebugString(msg);
+-#elif defined Q_OS_LINUX && defined _DEBUG
++#elif (defined Q_OS_LINUX || defined Q_OS_FREEBSD) && defined _DEBUG
+ //std::cout << msg.toUtf8().constData();
+ #endif
+ }
diff --git a/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_main.cpp b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_main.cpp
new file mode 100644
index 000000000000..4835ff0b7fca
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_main.cpp
@@ -0,0 +1,30 @@
+--- Telegram/SourceFiles/main.cpp.orig 2017-09-05 17:38:38 UTC
++++ Telegram/SourceFiles/main.cpp
+@@ -22,10 +22,13 @@ Copyright (c) 2014-2017 John Preston, ht
+ #include "platform/platform_specific.h"
+ #include "storage/localstorage.h"
+
++#include "FREEBSD_QT_PLUGINDIR.h"
++
+ int main(int argc, char *argv[]) {
+-#ifndef Q_OS_MAC // Retina display support is working fine, others are not.
++#if !defined(Q_OS_MAC) && QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
++ // Retina display support is working fine, others are not.
+ QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling, true);
+-#endif // Q_OS_MAC
++#endif // not defined Q_OS_MAC and QT_VERSION >= 5.6.0
+ QCoreApplication::setApplicationName(qsl("TelegramDesktop"));
+
+ InitFromCommandLine(argc, argv);
+@@ -39,6 +42,11 @@ int main(int argc, char *argv[]) {
+ Logs::start(); // must be started before Platform is started
+ Platform::start(); // must be started before QApplication is created
+
++ // I don't know why path is not in QT_PLUGIN_PATH by default
++ QCoreApplication::addLibraryPath(FREEBSD_QT_PLUGINDIR);
++ // without this Telegram doesn't start on Ubuntu 17.04 due GTK errors
++ setenv("QT_STYLE_OVERRIDE", "qwerty", false);
++
+ int result = 0;
+ {
+ Application app(argc, argv);
diff --git a/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_mainwindow.cpp b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_mainwindow.cpp
new file mode 100644
index 000000000000..9a3fdcf3bc7e
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_mainwindow.cpp
@@ -0,0 +1,19 @@
+--- Telegram/SourceFiles/mainwindow.cpp.orig 2017-09-05 17:38:38 UTC
++++ Telegram/SourceFiles/mainwindow.cpp
+@@ -460,6 +460,7 @@ void MainWindow::ui_hideMediaPreview() {
+ void MainWindow::showConnecting(const QString &text, const QString &reconnect) {
+ if (_connecting) {
+ _connecting->set(text, reconnect);
++ _connecting->show();
+ } else {
+ _connecting.create(bodyWidget(), text, reconnect);
+ _connecting->show();
+@@ -470,7 +471,7 @@ void MainWindow::showConnecting(const QS
+
+ void MainWindow::hideConnecting() {
+ if (_connecting) {
+- _connecting.destroyDelayed();
++ _connecting->hide();
+ }
+ }
+
diff --git a/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_linux_linux__libs.cpp b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_linux_linux__libs.cpp
new file mode 100644
index 000000000000..32152264bcd0
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_linux_linux__libs.cpp
@@ -0,0 +1,47 @@
+--- Telegram/SourceFiles/platform/linux/linux_libs.cpp.orig 2017-09-05 17:38:38 UTC
++++ Telegram/SourceFiles/platform/linux/linux_libs.cpp
+@@ -133,6 +133,7 @@ bool setupGtkBase(QLibrary &lib_gtk) {
+ return true;
+ }
+
++#ifdef HAVE_APPINDICATOR
+ bool setupAppIndicator(QLibrary &lib_indicator) {
+ if (!load(lib_indicator, "app_indicator_new", app_indicator_new)) return false;
+ if (!load(lib_indicator, "app_indicator_set_status", app_indicator_set_status)) return false;
+@@ -142,6 +143,7 @@ bool setupAppIndicator(QLibrary &lib_ind
+ DEBUG_LOG(("Library appindicator functions loaded!"));
+ return true;
+ }
++#endif
+
+ } // namespace
+
+@@ -201,10 +203,12 @@ f_g_type_check_instance_cast g_type_chec
+ f_g_type_check_instance_is_a g_type_check_instance_is_a = nullptr;
+ f_g_signal_connect_data g_signal_connect_data = nullptr;
+ f_g_signal_handler_disconnect g_signal_handler_disconnect = nullptr;
++#ifdef HAVE_APPINDICATOR
+ f_app_indicator_new app_indicator_new = nullptr;
+ f_app_indicator_set_status app_indicator_set_status = nullptr;
+ f_app_indicator_set_menu app_indicator_set_menu = nullptr;
+ f_app_indicator_set_icon_full app_indicator_set_icon_full = nullptr;
++#endif
+ f_gdk_init_check gdk_init_check = nullptr;
+ f_gdk_pixbuf_new_from_data gdk_pixbuf_new_from_data = nullptr;
+ f_gdk_pixbuf_new_from_file gdk_pixbuf_new_from_file = nullptr;
+@@ -242,6 +246,7 @@ void start() {
+ bool gtkLoaded = false;
+ bool indicatorLoaded = false;
+ QLibrary lib_gtk, lib_indicator;
++#ifdef HAVE_APPINDICATOR
+ if (loadLibrary(lib_indicator, "appindicator3", 1)) {
+ if (loadLibrary(lib_gtk, "gtk-3", 0)) {
+ gtkLoaded = setupGtkBase(lib_gtk);
+@@ -257,6 +262,7 @@ void start() {
+ }
+ }
+ }
++#endif
+
+ // If no appindicator, try at least load gtk.
+ if (!gtkLoaded && !indicatorLoaded) {
diff --git a/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_linux_linux__libs.h b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_linux_linux__libs.h
new file mode 100644
index 000000000000..53ce0217b9ea
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_linux_linux__libs.h
@@ -0,0 +1,36 @@
+--- Telegram/SourceFiles/platform/linux/linux_libs.h.orig 2017-09-05 17:38:38 UTC
++++ Telegram/SourceFiles/platform/linux/linux_libs.h
+@@ -22,14 +22,16 @@ Copyright (c) 2014-2017 John Preston, ht
+
+ extern "C" {
+ #undef signals
++#ifdef HAVE_APPINDICATOR
+ #include <libappindicator/app-indicator.h>
++#endif
+ #include <gtk/gtk.h>
+ #include <gdk/gdk.h>
+ #define signals public
+ } // extern "C"
+
+ #ifndef TDESKTOP_DISABLE_UNITY_INTEGRATION
+-#include <unity/unity/unity.h>
++typedef void UnityLauncherEntry;
+ #endif // !TDESKTOP_DISABLE_UNITY_INTEGRATION
+
+ namespace Platform {
+@@ -284,6 +286,7 @@ inline gulong g_signal_connect_swapped_h
+ typedef void (*f_g_signal_handler_disconnect)(gpointer instance, gulong handler_id);
+ extern f_g_signal_handler_disconnect g_signal_handler_disconnect;
+
++#ifdef HAVE_APPINDICATOR
+ typedef AppIndicator* (*f_app_indicator_new)(const gchar *id, const gchar *icon_name, AppIndicatorCategory category);
+ extern f_app_indicator_new app_indicator_new;
+
+@@ -295,6 +298,7 @@ extern f_app_indicator_set_menu app_indi
+
+ typedef void (*f_app_indicator_set_icon_full)(AppIndicator *self, const gchar *icon_name, const gchar *icon_desc);
+ extern f_app_indicator_set_icon_full app_indicator_set_icon_full;
++#endif
+
+ typedef gboolean (*f_gdk_init_check)(gint *argc, gchar ***argv);
+ extern f_gdk_init_check gdk_init_check;
diff --git a/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_linux_main__window__linux.cpp b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_linux_main__window__linux.cpp
new file mode 100644
index 000000000000..d31a2a5ba2d1
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_linux_main__window__linux.cpp
@@ -0,0 +1,87 @@
+--- Telegram/SourceFiles/platform/linux/main_window_linux.cpp.orig 2017-09-05 17:38:38 UTC
++++ Telegram/SourceFiles/platform/linux/main_window_linux.cpp
+@@ -36,7 +36,9 @@ namespace {
+ bool noQtTrayIcon = false, tryAppIndicator = false;
+ bool useGtkBase = false, useAppIndicator = false, useStatusIcon = false, trayIconChecked = false, useUnityCount = false;
+
++#ifdef HAVE_APPINDICATOR
+ AppIndicator *_trayIndicator = 0;
++#endif
+ GtkStatusIcon *_trayIcon = 0;
+ GtkWidget *_trayMenu = 0;
+ GdkPixbuf *_trayPixbuf = 0;
+@@ -274,7 +276,9 @@ void MainWindow::workmodeUpdated(DBIWork
+ if (mode == dbiwmWindowOnly) {
+ if (noQtTrayIcon) {
+ if (useAppIndicator) {
++#ifdef HAVE_APPINDICATOR
+ Libs::app_indicator_set_status(_trayIndicator, APP_INDICATOR_STATUS_PASSIVE);
++#endif
+ } else if (useStatusIcon) {
+ Libs::gtk_status_icon_set_visible(_trayIcon, false);
+ }
+@@ -288,7 +292,9 @@ void MainWindow::workmodeUpdated(DBIWork
+ } else {
+ if (noQtTrayIcon) {
+ if (useAppIndicator) {
++#ifdef HAVE_APPINDICATOR
+ Libs::app_indicator_set_status(_trayIndicator, APP_INDICATOR_STATUS_ACTIVE);
++#endif
+ } else if (useStatusIcon) {
+ Libs::gtk_status_icon_set_visible(_trayIcon, true);
+ }
+@@ -305,7 +311,9 @@ void MainWindow::psUpdateIndicator() {
+ if (iconFile.exists()) {
+ QByteArray path = QFile::encodeName(iconFile.absoluteFilePath()), name = QFile::encodeName(iconFile.fileName());
+ name = name.mid(0, name.size() - 4);
++#ifdef HAVE_APPINDICATOR
+ Libs::app_indicator_set_icon_full(_trayIndicator, path.constData(), name);
++#endif
+ } else {
+ useAppIndicator = false;
+ }
+@@ -392,11 +400,15 @@ void MainWindow::LibsLoaded() {
+ && (Libs::g_object_ref_sink != nullptr)
+ && (Libs::g_object_unref != nullptr);
+
++#ifdef HAVE_APPINDICATOR
+ useAppIndicator = useGtkBase
+ && (Libs::app_indicator_new != nullptr)
+ && (Libs::app_indicator_set_status != nullptr)
+ && (Libs::app_indicator_set_menu != nullptr)
+ && (Libs::app_indicator_set_icon_full != nullptr);
++#else
++ useAppIndicator = false;
++#endif
+
+ if (tryAppIndicator && useGtkBase && useAppIndicator) {
+ noQtTrayIcon = true;
+@@ -439,6 +451,7 @@ void MainWindow::psCreateTrayIcon() {
+ return;
+ }
+
++#ifdef HAVE_APPINDICATOR
+ if (useAppIndicator) {
+ DEBUG_LOG(("Trying to create AppIndicator"));
+ _trayMenu = Libs::gtk_menu_new();
+@@ -469,6 +482,7 @@ void MainWindow::psCreateTrayIcon() {
+ useAppIndicator = false;
+ }
+ }
++#endif
+ if (useStatusIcon) {
+ if (Libs::gdk_init_check(0, 0)) {
+ if (!_trayMenu) _trayMenu = Libs::gtk_menu_new();
+@@ -585,10 +599,12 @@ MainWindow::~MainWindow() {
+ Libs::g_object_unref(_trayMenu);
+ _trayMenu = nullptr;
+ }
++#ifdef HAVE_APPINDICATOR
+ if (_trayIndicator) {
+ Libs::g_object_unref(_trayIndicator);
+ _trayIndicator = nullptr;
+ }
++#endif
+ #ifndef TDESKTOP_DISABLE_UNITY_INTEGRATION
+ if (_psUnityLauncherEntry) {
+ Libs::g_object_unref(_psUnityLauncherEntry);
diff --git a/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_platform__audio.h b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_platform__audio.h
new file mode 100644
index 000000000000..302480d688c1
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_platform__audio.h
@@ -0,0 +1,20 @@
+--- Telegram/SourceFiles/platform/platform_audio.h.orig 2017-09-05 17:38:38 UTC
++++ Telegram/SourceFiles/platform/platform_audio.h
+@@ -32,7 +32,7 @@ void DeInit();
+
+ // Platform dependent implementations.
+
+-#if defined Q_OS_MAC || defined Q_OS_LINUX
++#if defined Q_OS_MAC || defined Q_OS_LINUX || defined Q_OS_FREEBSD
+ namespace Platform {
+ namespace Audio {
+
+@@ -44,6 +44,6 @@ inline void DeInit() {
+
+ } // namespace Audio
+ } // namespace Platform
+-#elif defined Q_OS_WINRT || defined Q_OS_WIN // Q_OS_MAC || Q_OS_LINUX
++#elif defined Q_OS_WINRT || defined Q_OS_WIN // Q_OS_MAC || Q_OS_LINUX || Q_OS_FREEBSD
+ #include "platform/win/audio_win.h"
+-#endif // Q_OS_MAC || Q_OS_LINUX || Q_OS_WINRT || Q_OS_WIN
++#endif // Q_OS_MAC || Q_OS_LINUX || Q_OS_WINRT || Q_OS_WIN || Q_OS_FREEBSD
diff --git a/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_platform__file__utilities.h b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_platform__file__utilities.h
new file mode 100644
index 000000000000..98ebbb8aa247
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_platform__file__utilities.h
@@ -0,0 +1,14 @@
+--- Telegram/SourceFiles/platform/platform_file_utilities.h.orig 2017-09-05 17:38:38 UTC
++++ Telegram/SourceFiles/platform/platform_file_utilities.h
+@@ -51,8 +51,8 @@ bool Get(QStringList &files, QByteArray
+
+ #ifdef Q_OS_MAC
+ #include "platform/mac/file_utilities_mac.h"
+-#elif defined Q_OS_LINUX // Q_OS_MAC
++#elif defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) // Q_OS_MAC
+ #include "platform/linux/file_utilities_linux.h"
+-#elif defined Q_OS_WINRT || defined Q_OS_WIN // Q_OS_MAC || Q_OS_LINUX
++#elif defined Q_OS_WINRT || defined Q_OS_WIN // Q_OS_MAC || Q_OS_LINUX || Q_OS_FREEBSD
+ #include "platform/win/file_utilities_win.h"
+-#endif // Q_OS_MAC || Q_OS_LINUX || Q_OS_WINRT || Q_OS_WIN
++#endif // Q_OS_MAC || Q_OS_LINUX || Q_OS_WINRT || Q_OS_WIN || Q_OS_FREEBSD
diff --git a/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_platform__main__window.h b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_platform__main__window.h
new file mode 100644
index 000000000000..34c08df18f21
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_platform__main__window.h
@@ -0,0 +1,14 @@
+--- Telegram/SourceFiles/platform/platform_main_window.h.orig 2017-09-05 17:38:38 UTC
++++ Telegram/SourceFiles/platform/platform_main_window.h
+@@ -32,8 +32,8 @@ class MainWindow;
+
+ #ifdef Q_OS_MAC
+ #include "platform/mac/main_window_mac.h"
+-#elif defined Q_OS_LINUX // Q_OS_MAC
++#elif defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) // Q_OS_MAC
+ #include "platform/linux/main_window_linux.h"
+-#elif defined Q_OS_WIN // Q_OS_MAC || Q_OS_LINUX
++#elif defined Q_OS_WIN // Q_OS_MAC || Q_OS_LINUX || Q_OS_FREEBSD
+ #include "platform/win/main_window_win.h"
+-#endif // Q_OS_MAC || Q_OS_LINUX || Q_OS_WIN
++#endif // Q_OS_MAC || Q_OS_LINUX || Q_OS_WIN || Q_OS_FREEBSD
diff --git a/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_platform__notifications__manager.h b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_platform__notifications__manager.h
new file mode 100644
index 000000000000..8f3699b92875
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_platform__notifications__manager.h
@@ -0,0 +1,14 @@
+--- Telegram/SourceFiles/platform/platform_notifications_manager.h.orig 2017-09-05 17:38:38 UTC
++++ Telegram/SourceFiles/platform/platform_notifications_manager.h
+@@ -39,8 +39,8 @@ void FlashBounce();
+
+ #ifdef Q_OS_MAC
+ #include "platform/mac/notifications_manager_mac.h"
+-#elif defined Q_OS_LINUX // Q_OS_MAC
++#elif defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) // Q_OS_MAC
+ #include "platform/linux/notifications_manager_linux.h"
+-#elif defined Q_OS_WIN // Q_OS_MAC || Q_OS_LINUX
++#elif defined Q_OS_WIN // Q_OS_MAC || Q_OS_LINUX || Q_OS_FREEBSD
+ #include "platform/win/notifications_manager_win.h"
+-#endif // Q_OS_MAC || Q_OS_LINUX || Q_OS_WIN
++#endif // Q_OS_MAC || Q_OS_LINUX || Q_OS_WIN || Q_OS_FREEBSD
diff --git a/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_platform__specific.h b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_platform__specific.h
new file mode 100644
index 000000000000..debe306c7aac
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_platform__specific.h
@@ -0,0 +1,14 @@
+--- Telegram/SourceFiles/platform/platform_specific.h.orig 2017-09-05 17:38:38 UTC
++++ Telegram/SourceFiles/platform/platform_specific.h
+@@ -45,8 +45,8 @@ void finish();
+
+ #ifdef Q_OS_MAC
+ #include "platform/mac/specific_mac.h"
+-#elif defined Q_OS_LINUX // Q_OS_MAC
++#elif defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) // Q_OS_MAC
+ #include "platform/linux/specific_linux.h"
+-#elif defined Q_OS_WIN // Q_OS_MAC || Q_OS_LINUX
++#elif defined Q_OS_WIN // Q_OS_MAC || Q_OS_LINUX || Q_OS_FREEBSD
+ #include "platform/win/specific_win.h"
+-#endif // Q_OS_MAC || Q_OS_LINUX || Q_OS_WIN
++#endif // Q_OS_MAC || Q_OS_LINUX || Q_OS_WIN || Q_OS_FREEBSD
diff --git a/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_platform__window__title.h b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_platform__window__title.h
new file mode 100644
index 000000000000..5216166bd822
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_platform_platform__window__title.h
@@ -0,0 +1,17 @@
+--- Telegram/SourceFiles/platform/platform_window_title.h.orig 2017-09-05 17:38:38 UTC
++++ Telegram/SourceFiles/platform/platform_window_title.h
+@@ -38,7 +38,7 @@ void PreviewWindowFramePaint(QImage &pre
+ #include "platform/mac/window_title_mac.h"
+ #elif defined Q_OS_WIN // Q_OS_MAC
+ #include "platform/win/window_title_win.h"
+-#elif defined Q_OS_WINRT || defined Q_OS_LINUX // Q_OS_MAC || Q_OS_WIN
++#elif defined Q_OS_WINRT || defined Q_OS_LINUX || defined Q_OS_FREEBSD // Q_OS_MAC || Q_OS_WIN
+
+ namespace Platform {
+
+@@ -56,4 +56,4 @@ inline void PreviewWindowFramePaint(QIma
+
+ } // namespace Platform
+
+-#endif // Q_OS_MAC || Q_OS_WIN || Q_OS_WINRT || Q_OS_LINUX
++#endif // Q_OS_MAC || Q_OS_WIN || Q_OS_WINRT || Q_OS_LINUX || Q_OS_FREEBSD
diff --git a/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_qt__functions.cpp b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_qt__functions.cpp
new file mode 100644
index 000000000000..8d76c04ea7ea
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_qt__functions.cpp
@@ -0,0 +1,97 @@
+--- Telegram/SourceFiles/qt_functions.cpp.orig 2017-12-11 10:10:37 UTC
++++ Telegram/SourceFiles/qt_functions.cpp
+@@ -0,0 +1,94 @@
++/****************************************************************************
++**
++** Copyright (C) 2015 The Qt Company Ltd.
++** Contact: http://www.qt.io/licensing/
++**
++** This file contains some parts of the Qt Toolkit.
++**
++** $QT_BEGIN_LICENSE:LGPL21$
++** Commercial License Usage
++** Licensees holding valid commercial Qt licenses may use this file in
++** accordance with the commercial license agreement provided with the
++** Software or, alternatively, in accordance with the terms contained in
++** a written agreement between you and The Qt Company. For licensing terms
++** and conditions see http://www.qt.io/terms-conditions. For further
++** information use the contact form at http://www.qt.io/contact-us.
++**
++** GNU Lesser General Public License Usage
++** Alternatively, this file may be used under the terms of the GNU Lesser
++** General Public License version 2.1 or version 3 as published by the Free
++** Software Foundation and appearing in the file LICENSE.LGPLv21 and
++** LICENSE.LGPLv3 included in the packaging of this file. Please review the
++** following information to ensure the GNU Lesser General Public License
++** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
++** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
++**
++** As a special exception, The Qt Company gives you certain additional
++** rights. These rights are described in The Qt Company LGPL Exception
++** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
++**
++** $QT_END_LICENSE$
++**
++****************************************************************************/
++
++/* TODO: find a dynamic library with these symbols. */
++
++/* Debian maintainer: this function is taken from qfiledialog.cpp */
++/*
++ Makes a list of filters from ;;-separated text.
++ Used by the mac and windows implementations
++*/
++QStringList qt_make_filter_list(const QString &filter)
++{
++ QString f(filter);
++
++ if (f.isEmpty())
++ return QStringList();
++
++ QString sep(QLatin1String(";;"));
++ int i = f.indexOf(sep, 0);
++ if (i == -1) {
++ if (f.indexOf(QLatin1Char('\n'), 0) != -1) {
++ sep = QLatin1Char('\n');
++ i = f.indexOf(sep, 0);
++ }
++ }
++
++ return f.split(sep);
++}
++
++/* Debian maintainer: this constructor is taken from qtextengine.cpp for TextPainter::drawLine */
++QTextItemInt::QTextItemInt(const QGlyphLayout &g, QFont *font, const QChar *chars_, int numChars, QFontEngine *fe, const QTextCharFormat &format)
++ : flags(0), justified(false), underlineStyle(QTextCharFormat::NoUnderline), charFormat(format),
++ num_chars(numChars), chars(chars_), logClusters(0), f(font), glyphs(g), fontEngine(fe)
++{
++}
++
++/* Debian maintainer: this method is also taken from qtextengine.cpp */
++// Fix up flags and underlineStyle with given info
++void QTextItemInt::initWithScriptItem(const QScriptItem &si)
++{
++ // explicitly initialize flags so that initFontAttributes can be called
++ // multiple times on the same TextItem
++ flags = 0;
++ if (si.analysis.bidiLevel %2)
++ flags |= QTextItem::RightToLeft;
++ ascent = si.ascent;
++ descent = si.descent;
++
++ if (charFormat.hasProperty(QTextFormat::TextUnderlineStyle)) {
++ underlineStyle = charFormat.underlineStyle();
++ } else if (charFormat.boolProperty(QTextFormat::FontUnderline)
++ || f->d->underline) {
++ underlineStyle = QTextCharFormat::SingleUnderline;
++ }
++
++ // compat
++ if (underlineStyle == QTextCharFormat::SingleUnderline)
++ flags |= QTextItem::Underline;
++
++ if (f->d->overline || charFormat.fontOverline())
++ flags |= QTextItem::Overline;
++ if (f->d->strikeOut || charFormat.fontStrikeOut())
++ flags |= QTextItem::StrikeOut;
++}
diff --git a/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_qt__static__plugins.cpp b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_qt__static__plugins.cpp
new file mode 100644
index 000000000000..550a22dfa278
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_qt__static__plugins.cpp
@@ -0,0 +1,19 @@
+--- Telegram/SourceFiles/qt_static_plugins.cpp.orig 2017-09-05 17:38:38 UTC
++++ Telegram/SourceFiles/qt_static_plugins.cpp
+@@ -27,14 +27,5 @@ Q_IMPORT_PLUGIN(QWindowsIntegrationPlugi
+ Q_IMPORT_PLUGIN(QWebpPlugin)
+ Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin)
+ Q_IMPORT_PLUGIN(QGenericEnginePlugin)
+-#elif defined Q_OS_LINUX // Q_OS_WIN | Q_OS_MAC
+-Q_IMPORT_PLUGIN(QWebpPlugin)
+-Q_IMPORT_PLUGIN(QXcbIntegrationPlugin)
+-Q_IMPORT_PLUGIN(QConnmanEnginePlugin)
+-Q_IMPORT_PLUGIN(QGenericEnginePlugin)
+-Q_IMPORT_PLUGIN(QNetworkManagerEnginePlugin)
+-Q_IMPORT_PLUGIN(QComposePlatformInputContextPlugin)
+-Q_IMPORT_PLUGIN(QIbusPlatformInputContextPlugin)
+-Q_IMPORT_PLUGIN(QFcitxPlatformInputContextPlugin)
+-Q_IMPORT_PLUGIN(QHimePlatformInputContextPlugin)
+-#endif // Q_OS_WIN | Q_OS_MAC | Q_OS_LINUX
++#elif defined Q_OS_LINUX || defined Q_OS_FREEBSD // Q_OS_WIN | Q_OS_MAC
++#endif // Q_OS_WIN | Q_OS_MAC | Q_OS_LINUX | Q_OS_FREEBSD
diff --git a/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_structs.cpp b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_structs.cpp
new file mode 100644
index 000000000000..ed3c4bd68037
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_structs.cpp
@@ -0,0 +1,11 @@
+--- Telegram/SourceFiles/structs.cpp.orig 2017-09-05 17:38:38 UTC
++++ Telegram/SourceFiles/structs.cpp
+@@ -1280,7 +1280,7 @@ QString saveFileName(const QString &titl
+ name = name.replace(QRegularExpression(qsl("[\\\\\\/\\:\\*\\?\\\"\\<\\>\\|]")), qsl("_"));
+ #elif defined Q_OS_MAC
+ name = name.replace(QRegularExpression(qsl("[\\:]")), qsl("_"));
+-#elif defined Q_OS_LINUX
++#elif defined Q_OS_LINUX || defined Q_OS_FREEBSD
+ name = name.replace(QRegularExpression(qsl("[\\/]")), qsl("_"));
+ #endif
+ if (Global::AskDownloadPath() || savingAs) {
diff --git a/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_ui_text_text.cpp b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_ui_text_text.cpp
new file mode 100644
index 000000000000..9fa8cbaf66c9
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_ui_text_text.cpp
@@ -0,0 +1,17 @@
+--- Telegram/SourceFiles/ui/text/text.cpp.orig 2017-09-05 17:38:38 UTC
++++ Telegram/SourceFiles/ui/text/text.cpp
+@@ -1689,11 +1689,11 @@ private:
+ if (item == -1)
+ return;
+
+-#ifdef OS_MAC_OLD
++#if defined(OS_MAC_OLD) || QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
+ auto end = _e->findItem(line.from + line.length - 1);
+-#else // OS_MAC_OLD
++#else
+ auto end = _e->findItem(line.from + line.length - 1, item);
+-#endif // OS_MAC_OLD
++#endif
+
+ auto blockIndex = _lineStartBlock;
+ auto currentBlock = _t->_blocks[blockIndex].get();
diff --git a/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_ui_text_text__block.cpp b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_ui_text_text__block.cpp
new file mode 100644
index 000000000000..670103853f9f
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_ui_text_text__block.cpp
@@ -0,0 +1,11 @@
+--- Telegram/SourceFiles/ui/text/text_block.cpp.orig 2017-09-05 17:38:38 UTC
++++ Telegram/SourceFiles/ui/text/text_block.cpp
+@@ -330,7 +330,7 @@ TextBlock::TextBlock(const style::font &
+ SignalHandlers::setCrashAnnotationRef("CrashString", &part);
+
+ QStackTextEngine engine(part, blockFont->f);
+- QTextLayout layout(&engine);
++ QTextLayout layout(part, blockFont->f);
+ layout.beginLayout();
+ layout.createLine();
+
diff --git a/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_ui_twidget.cpp b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_ui_twidget.cpp
new file mode 100644
index 000000000000..8b440118311e
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_SourceFiles_ui_twidget.cpp
@@ -0,0 +1,14 @@
+--- Telegram/SourceFiles/ui/twidget.cpp.orig 2017-09-05 17:38:38 UTC
++++ Telegram/SourceFiles/ui/twidget.cpp
+@@ -191,9 +191,9 @@ void sendSynteticMouseEvent(QWidget *wid
+ , button
+ , QGuiApplication::mouseButtons() | button
+ , QGuiApplication::keyboardModifiers()
+-#ifndef OS_MAC_OLD
++#if !defined(OS_MAC_OLD) && QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
+ , Qt::MouseEventSynthesizedByApplication
+-#endif // OS_MAC_OLD
++#endif
+ );
+ ev.setTimestamp(getms());
+ QGuiApplication::sendEvent(windowHandle, &ev);
diff --git a/net-im/telegram-desktop/files/patch-Telegram_ThirdParty_libtgvoip_audio_AudioInput.cpp b/net-im/telegram-desktop/files/patch-Telegram_ThirdParty_libtgvoip_audio_AudioInput.cpp
new file mode 100644
index 000000000000..90ad3a66c0d5
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_ThirdParty_libtgvoip_audio_AudioInput.cpp
@@ -0,0 +1,11 @@
+--- Telegram/ThirdParty/libtgvoip/audio/AudioInput.cpp.orig 2017-07-06 17:16:18 UTC
++++ Telegram/ThirdParty/libtgvoip/audio/AudioInput.cpp
+@@ -20,7 +20,7 @@
+ #include "../os/windows/AudioInputWave.h"
+ #endif
+ #include "../os/windows/AudioInputWASAPI.h"
+-#elif defined(__linux__)
++#elif defined(__linux__) || defined(__FreeBSD__)
+ #include "../os/linux/AudioInputALSA.h"
+ #include "../os/linux/AudioInputPulse.h"
+ #else
diff --git a/net-im/telegram-desktop/files/patch-Telegram_ThirdParty_libtgvoip_audio_AudioOutput.cpp b/net-im/telegram-desktop/files/patch-Telegram_ThirdParty_libtgvoip_audio_AudioOutput.cpp
new file mode 100644
index 000000000000..c2240c21deca
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_ThirdParty_libtgvoip_audio_AudioOutput.cpp
@@ -0,0 +1,11 @@
+--- Telegram/ThirdParty/libtgvoip/audio/AudioOutput.cpp.orig 2017-07-06 17:16:18 UTC
++++ Telegram/ThirdParty/libtgvoip/audio/AudioOutput.cpp
+@@ -21,7 +21,7 @@
+ #include "../os/windows/AudioOutputWave.h"
+ #endif
+ #include "../os/windows/AudioOutputWASAPI.h"
+-#elif defined(__linux__)
++#elif defined(__linux__) || defined(__FreeBSD__)
+ #include "../os/linux/AudioOutputALSA.h"
+ #include "../os/linux/AudioOutputPulse.h"
+ #else
diff --git a/net-im/telegram-desktop/files/patch-Telegram_ThirdParty_libtgvoip_os_posix_NetworkSocketPosix.cpp b/net-im/telegram-desktop/files/patch-Telegram_ThirdParty_libtgvoip_os_posix_NetworkSocketPosix.cpp
new file mode 100644
index 000000000000..4fb1713ccabb
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_ThirdParty_libtgvoip_os_posix_NetworkSocketPosix.cpp
@@ -0,0 +1,10 @@
+--- Telegram/ThirdParty/libtgvoip/os/posix/NetworkSocketPosix.cpp.orig 2017-07-06 17:16:18 UTC
++++ Telegram/ThirdParty/libtgvoip/os/posix/NetworkSocketPosix.cpp
+@@ -45,6 +45,7 @@ void NetworkSocketPosix::SetMaxPriority(
+ if(res<0){
+ LOGE("error setting darwin-specific net priority: %d / %s", errno, strerror(errno));
+ }
++#elif defined(__FreeBSD__)
+ #else
+ int prio=5;
+ int res=setsockopt(fd, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(prio));
diff --git a/net-im/telegram-desktop/files/patch-Telegram_ThirdParty_libtgvoip_threading.h b/net-im/telegram-desktop/files/patch-Telegram_ThirdParty_libtgvoip_threading.h
new file mode 100644
index 000000000000..3be3f1b7461f
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_ThirdParty_libtgvoip_threading.h
@@ -0,0 +1,11 @@
+--- Telegram/ThirdParty/libtgvoip/threading.h.orig 2017-07-06 17:16:18 UTC
++++ Telegram/ThirdParty/libtgvoip/threading.h
+@@ -20,7 +20,7 @@ typedef pthread_cond_t tgvoip_lock_t;
+ #define start_thread(ref, entry, arg) pthread_create(&ref, NULL, entry, arg)
+ #define join_thread(thread) pthread_join(thread, NULL)
+ #ifndef __APPLE__
+-#define set_thread_name(thread, name) pthread_setname_np(thread, name)
++#define set_thread_name(thread, name)
+ #else
+ #define set_thread_name(thread, name)
+ #endif
diff --git a/net-im/telegram-desktop/files/patch-Telegram_ThirdParty_libtgvoip_webrtc__dsp_webrtc_base_stringutils.h b/net-im/telegram-desktop/files/patch-Telegram_ThirdParty_libtgvoip_webrtc__dsp_webrtc_base_stringutils.h
new file mode 100644
index 000000000000..a04402d23a5b
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_ThirdParty_libtgvoip_webrtc__dsp_webrtc_base_stringutils.h
@@ -0,0 +1,11 @@
+--- Telegram/ThirdParty/libtgvoip/webrtc_dsp/webrtc/base/stringutils.h.orig 2017-07-06 17:16:18 UTC
++++ Telegram/ThirdParty/libtgvoip/webrtc_dsp/webrtc/base/stringutils.h
+@@ -23,7 +23,7 @@
+ #endif // WEBRTC_WIN
+
+ #if defined(WEBRTC_POSIX)
+-#ifdef BSD
++#if defined BSD || defined __FreeBSD__
+ #include <stdlib.h>
+ #else // BSD
+ #include <alloca.h>
diff --git a/net-im/telegram-desktop/files/patch-Telegram_gyp_PrecompiledHeader.cmake b/net-im/telegram-desktop/files/patch-Telegram_gyp_PrecompiledHeader.cmake
new file mode 100644
index 000000000000..7d458e9b6846
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_gyp_PrecompiledHeader.cmake
@@ -0,0 +1,36 @@
+--- Telegram/gyp/PrecompiledHeader.cmake.orig 2017-09-05 17:38:38 UTC
++++ Telegram/gyp/PrecompiledHeader.cmake
+@@ -79,7 +79,7 @@ function(export_all_flags _filename _sou
+ endfunction()
+
+ function(add_precompiled_header _target _input)
+- if(CMAKE_COMPILER_IS_GNUCXX)
++ if(CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
+ get_filename_component(_name ${_input} NAME)
+ set(_pch_header "${CMAKE_CURRENT_SOURCE_DIR}/${_input}")
+ set(_pch_binary_dir "${CMAKE_CURRENT_BINARY_DIR}/${_target}_pch")
+@@ -112,7 +112,7 @@ function(add_precompiled_header _target
+ set(_compiler_FLAGS "@${_pch_c_flags_file}")
+ add_custom_command(
+ OUTPUT "${_output_c}"
+- COMMAND "${CMAKE_C_COMPILER}" ${_compiler_FLAGS} -x c-header -o "${_output_c}" -c "${_pchfile}"
++ COMMAND "${CMAKE_C_COMPILER}" "$(C_DEFINES)" "$(C_INCLUDES)" "$(C_FLAGS)" -x c-header -o "${_output_c}" -c "${_pchfile}"
+ DEPENDS "${_pchfile}" "${_pch_c_flags_file}"
+ IMPLICIT_DEPENDS C "${_pch_header}"
+ COMMENT "Precompiling ${_name} for ${_target} (C)")
+@@ -123,7 +123,7 @@ function(add_precompiled_header _target
+ set(_compiler_FLAGS "@${_pch_cpp_flags_file}")
+ add_custom_command(
+ OUTPUT "${_output_cxx}"
+- COMMAND "${CMAKE_CXX_COMPILER}" ${_compiler_FLAGS} -x c++-header -o "${_output_cxx}" -c "${_pchfile}"
++ COMMAND "${CMAKE_CXX_COMPILER}" "$(CXX_DEFINES)" "$(CXX_INCLUDES)" "$(CXX_FLAGS)" -x c++-header -o "${_output_cxx}" -c "${_pchfile}"
+ DEPENDS "${_pchfile}" "${_pch_cpp_flags_file}"
+ IMPLICIT_DEPENDS CXX "${_pch_header}"
+ COMMENT "Precompiling ${_name} for ${_target} (C++)")
+@@ -161,5 +161,5 @@ function(add_precompiled_header _target
+ OBJECT_DEPENDS "${_object_depends}")
+ endif()
+ endforeach()
+- endif(CMAKE_COMPILER_IS_GNUCXX)
++ endif(CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
+ endfunction()
diff --git a/net-im/telegram-desktop/files/patch-Telegram_gyp_common.gypi b/net-im/telegram-desktop/files/patch-Telegram_gyp_common.gypi
new file mode 100644
index 000000000000..76bf82b970e7
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_gyp_common.gypi
@@ -0,0 +1,11 @@
+--- Telegram/gyp/common.gypi.orig 2017-09-05 17:38:38 UTC
++++ Telegram/gyp/common.gypi
+@@ -42,7 +42,7 @@
+ }, {
+ 'build_mac': 0,
+ }],
+- [ 'build_os == "linux"', {
++ [ 'build_os == "freebsd"', {
+ 'build_linux': 1,
+ }, {
+ 'build_linux': 0,
diff --git a/net-im/telegram-desktop/files/patch-Telegram_gyp_settings__linux.gypi b/net-im/telegram-desktop/files/patch-Telegram_gyp_settings__linux.gypi
new file mode 100644
index 000000000000..a42d3b652c75
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_gyp_settings__linux.gypi
@@ -0,0 +1,18 @@
+--- Telegram/gyp/settings_linux.gypi.orig 2017-09-05 17:38:38 UTC
++++ Telegram/gyp/settings_linux.gypi
+@@ -25,7 +25,6 @@
+ '-pipe',
+ '-g',
+ '-Wall',
+- '-Werror',
+ '-W',
+ '-fPIC',
+ '-Wno-unused-variable',
+@@ -61,7 +60,6 @@
+ ],
+ 'defines': [
+ '_REENTRANT',
+- 'QT_STATICPLUGIN',
+ 'QT_PLUGIN',
+ ],
+ 'cflags_c': [
diff --git a/net-im/telegram-desktop/files/patch-Telegram_gyp_telegram__sources.txt b/net-im/telegram-desktop/files/patch-Telegram_gyp_telegram__sources.txt
new file mode 100644
index 000000000000..bfaf5a316c99
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-Telegram_gyp_telegram__sources.txt
@@ -0,0 +1,18 @@
+--- Telegram/gyp/telegram_sources.txt.orig 2017-09-05 17:38:38 UTC
++++ Telegram/gyp/telegram_sources.txt
+@@ -598,14 +598,7 @@
+ <(emoji_suggestions_loc)/emoji_suggestions.cpp
+ <(emoji_suggestions_loc)/emoji_suggestions.h
+
+-platforms: !win
+-<(minizip_loc)/crypt.h
+-<(minizip_loc)/ioapi.c
+-<(minizip_loc)/ioapi.h
+-<(minizip_loc)/zip.c
+-<(minizip_loc)/zip.h
+-<(minizip_loc)/unzip.c
+-<(minizip_loc)/unzip.h
++<(src_loc)/qt_functions.cpp
+
+ platforms: mac
+ <(sp_media_key_tap_loc)/SPMediaKeyTap.m
diff --git a/net-im/telegram-desktop/files/patch-lib_xdg_tg.protocol b/net-im/telegram-desktop/files/patch-lib_xdg_tg.protocol
new file mode 100644
index 000000000000..f2eff6d5b318
--- /dev/null
+++ b/net-im/telegram-desktop/files/patch-lib_xdg_tg.protocol
@@ -0,0 +1,9 @@
+--- lib/xdg/tg.protocol.orig 2017-09-05 17:38:38 UTC
++++ lib/xdg/tg.protocol
+@@ -1,5 +1,5 @@
+ [Protocol]
+-exec=/usr/bin/telegram-desktop -- %u
++exec=telegram-desktop -- %u
+ protocol=tg
+ input=none
+ output=none
diff --git a/net-im/telegram-desktop/pkg-descr b/net-im/telegram-desktop/pkg-descr
new file mode 100644
index 000000000000..7575e44a1e7e
--- /dev/null
+++ b/net-im/telegram-desktop/pkg-descr
@@ -0,0 +1,13 @@
+Telegram Desktop is a messaging app. It is the fast and functional open source
+desktop app connected to the closed source Telegram server.
+
+Features:
+* accounts tied to telephone numbers
+* cloud-based messaging
+* bots for third party developers
+* channels
+* secret chats featuring with client-to-client encryption
+* stickers
+* voice calls
+
+WWW: https://desktop.telegram.org/
diff --git a/net-im/telegram-desktop/pkg-plist b/net-im/telegram-desktop/pkg-plist
new file mode 100644
index 000000000000..03c555f04629
--- /dev/null
+++ b/net-im/telegram-desktop/pkg-plist
@@ -0,0 +1,11 @@
+bin/telegram-desktop
+share/appdata/telegram-desktop.appdata.xml
+share/applications/telegram-desktop.desktop
+share/kservices5/tg.protocol
+share/icons/hicolor/128x128/apps/telegram-desktop.png
+share/icons/hicolor/16x16/apps/telegram-desktop.png
+share/icons/hicolor/256x256/apps/telegram-desktop.png
+share/icons/hicolor/32x32/apps/telegram-desktop.png
+share/icons/hicolor/48x48/apps/telegram-desktop.png
+share/icons/hicolor/512x512/apps/telegram-desktop.png
+share/icons/hicolor/64x64/apps/telegram-desktop.png