tdesktop/Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp

105 lines
2.2 KiB
C++
Raw Normal View History

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "platform/linux/file_utilities_linux.h"
2021-01-10 03:51:38 +00:00
#include "platform/linux/linux_gtk_integration.h"
#include "platform/linux/specific_linux.h"
#include <QtGui/QDesktopServices>
2019-11-18 07:52:08 +00:00
2020-10-27 05:03:50 +00:00
extern "C" {
#undef signals
#include <gio/gio.h>
#define signals public
} // extern "C"
2021-01-10 03:51:38 +00:00
using Platform::internal::GtkIntegration;
namespace Platform {
namespace File {
void UnsafeOpenUrl(const QString &url) {
if (!g_app_info_launch_default_for_uri(
2020-10-27 05:03:50 +00:00
url.toUtf8(),
nullptr,
nullptr)) {
QDesktopServices::openUrl(url);
}
}
void UnsafeOpenEmailLink(const QString &email) {
2020-10-27 05:03:50 +00:00
UnsafeOpenUrl(qstr("mailto:") + email);
}
2020-11-07 21:28:24 +00:00
bool UnsafeShowOpenWith(const QString &filepath) {
2021-01-10 03:51:38 +00:00
if (InFlatpak() || InSnap()) {
2020-11-07 21:28:24 +00:00
return false;
}
2021-01-10 03:51:38 +00:00
if (const auto integration = GtkIntegration::Instance()) {
const auto absolutePath = QFileInfo(filepath).absoluteFilePath();
return integration->showOpenWithDialog(absolutePath);
}
2020-11-07 21:28:24 +00:00
return false;
}
void UnsafeLaunch(const QString &filepath) {
2020-10-27 05:03:50 +00:00
const auto absolutePath = QFileInfo(filepath).absoluteFilePath();
if (!g_app_info_launch_default_for_uri(
2020-11-07 20:29:58 +00:00
g_filename_to_uri(absolutePath.toUtf8(), nullptr, nullptr),
2020-10-27 05:03:50 +00:00
nullptr,
nullptr)) {
2020-11-07 21:28:24 +00:00
if (!UnsafeShowOpenWith(filepath)) {
QDesktopServices::openUrl(QUrl::fromLocalFile(filepath));
}
}
}
} // namespace File
namespace FileDialog {
bool Get(
QPointer<QWidget> parent,
QStringList &files,
QByteArray &remoteContent,
const QString &caption,
const QString &filter,
2021-01-10 03:51:38 +00:00
::FileDialog::internal::Type type,
QString startFile) {
if (parent) {
parent = parent->window();
}
2021-01-10 03:51:38 +00:00
if (const auto integration = GtkIntegration::Instance()) {
if (integration->fileDialogSupported()
&& integration->useFileDialog(type)) {
return integration->getFileDialog(
parent,
files,
remoteContent,
caption,
filter,
type,
startFile);
}
}
return ::FileDialog::internal::GetDefault(
parent,
files,
remoteContent,
caption,
filter,
type,
startFile);
}
} // namespace FileDialog
} // namespace Platform