Use glib to open files & urls
This commit is contained in:
parent
9ab221d4c9
commit
41e0e4fba7
|
@ -18,6 +18,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include <QtCore/QProcess>
|
#include <QtCore/QProcess>
|
||||||
#include <QtGui/QDesktopServices>
|
#include <QtGui/QDesktopServices>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#undef signals
|
||||||
|
#include <gio/gio.h>
|
||||||
|
#define signals public
|
||||||
|
} // extern "C"
|
||||||
|
|
||||||
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
|
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
|
||||||
#include <private/qguiapplication_p.h>
|
#include <private/qguiapplication_p.h>
|
||||||
|
|
||||||
|
@ -63,38 +69,30 @@ QByteArray EscapeShell(const QByteArray &content) {
|
||||||
|
|
||||||
void UnsafeOpenUrl(const QString &url) {
|
void UnsafeOpenUrl(const QString &url) {
|
||||||
if (InSnap()) {
|
if (InSnap()) {
|
||||||
const QStringList arguments{
|
|
||||||
url
|
|
||||||
};
|
|
||||||
QProcess process;
|
QProcess process;
|
||||||
process.startDetached(qsl("xdg-open"), arguments);
|
process.startDetached(qsl("xdg-open"), {url});
|
||||||
} else {
|
} else if (!g_app_info_launch_default_for_uri(
|
||||||
|
url.toUtf8(),
|
||||||
|
nullptr,
|
||||||
|
nullptr)) {
|
||||||
QDesktopServices::openUrl(url);
|
QDesktopServices::openUrl(url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnsafeOpenEmailLink(const QString &email) {
|
void UnsafeOpenEmailLink(const QString &email) {
|
||||||
const auto url = qstr("mailto:") + email;
|
UnsafeOpenUrl(qstr("mailto:") + email);
|
||||||
|
|
||||||
if (InSnap()) {
|
|
||||||
const QStringList arguments{
|
|
||||||
url
|
|
||||||
};
|
|
||||||
QProcess process;
|
|
||||||
process.startDetached(qsl("xdg-open"), arguments);
|
|
||||||
} else {
|
|
||||||
QDesktopServices::openUrl(QUrl(url));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnsafeLaunch(const QString &filepath) {
|
void UnsafeLaunch(const QString &filepath) {
|
||||||
|
const auto absolutePath = QFileInfo(filepath).absoluteFilePath();
|
||||||
|
|
||||||
if (InSnap()) {
|
if (InSnap()) {
|
||||||
const QStringList arguments{
|
|
||||||
QFileInfo(filepath).absoluteFilePath()
|
|
||||||
};
|
|
||||||
QProcess process;
|
QProcess process;
|
||||||
process.startDetached(qsl("xdg-open"), arguments);
|
process.startDetached(qsl("xdg-open"), {absolutePath});
|
||||||
} else {
|
} else if (!g_app_info_launch_default_for_uri(
|
||||||
|
("file://" + absolutePath).toUtf8(),
|
||||||
|
nullptr,
|
||||||
|
nullptr)) {
|
||||||
QDesktopServices::openUrl(QUrl::fromLocalFile(filepath));
|
QDesktopServices::openUrl(QUrl::fromLocalFile(filepath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue