From 41e0e4fba703eddfe599ab8935cf0b64549a933f Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Tue, 27 Oct 2020 09:03:50 +0400 Subject: [PATCH] Use glib to open files & urls --- .../platform/linux/file_utilities_linux.cpp | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp b/Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp index a1b7db22b86faa..dfecc5b7994616 100644 --- a/Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp @@ -18,6 +18,12 @@ For license and copyright information please follow this link: #include #include +extern "C" { +#undef signals +#include +#define signals public +} // extern "C" + #ifndef TDESKTOP_DISABLE_GTK_INTEGRATION #include @@ -63,38 +69,30 @@ QByteArray EscapeShell(const QByteArray &content) { void UnsafeOpenUrl(const QString &url) { if (InSnap()) { - const QStringList arguments{ - url - }; QProcess process; - process.startDetached(qsl("xdg-open"), arguments); - } else { + process.startDetached(qsl("xdg-open"), {url}); + } else if (!g_app_info_launch_default_for_uri( + url.toUtf8(), + nullptr, + nullptr)) { QDesktopServices::openUrl(url); } } void UnsafeOpenEmailLink(const QString &email) { - const auto url = qstr("mailto:") + email; - - if (InSnap()) { - const QStringList arguments{ - url - }; - QProcess process; - process.startDetached(qsl("xdg-open"), arguments); - } else { - QDesktopServices::openUrl(QUrl(url)); - } + UnsafeOpenUrl(qstr("mailto:") + email); } void UnsafeLaunch(const QString &filepath) { + const auto absolutePath = QFileInfo(filepath).absoluteFilePath(); + if (InSnap()) { - const QStringList arguments{ - QFileInfo(filepath).absoluteFilePath() - }; QProcess process; - process.startDetached(qsl("xdg-open"), arguments); - } else { + process.startDetached(qsl("xdg-open"), {absolutePath}); + } else if (!g_app_info_launch_default_for_uri( + ("file://" + absolutePath).toUtf8(), + nullptr, + nullptr)) { QDesktopServices::openUrl(QUrl::fromLocalFile(filepath)); } }