Skip to content

Commit

Permalink
Use glib to open files & urls
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-fedin authored and john-preston committed Oct 27, 2020
1 parent 9ab221d commit 41e0e4f
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ For license and copyright information please follow this link:
#include <QtCore/QProcess>
#include <QtGui/QDesktopServices>

extern "C" {
#undef signals
#include <gio/gio.h>
#define signals public
} // extern "C"

#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
#include <private/qguiapplication_p.h>

Expand Down Expand Up @@ -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));
}
}
Expand Down

0 comments on commit 41e0e4f

Please sign in to comment.