mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-21 16:47:07 +02:00
Use glib to open files & urls
This commit is contained in:
parent
9ab221d4c9
commit
41e0e4fba7
1 changed files with 19 additions and 21 deletions
|
@ -18,6 +18,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#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>
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue