2016-07-06 18:30:14 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-07-06 18:30:14 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-07-06 18:30:14 +00:00
|
|
|
*/
|
2017-02-28 10:51:00 +00:00
|
|
|
#include "platform/linux/file_utilities_linux.h"
|
2016-07-06 18:30:14 +00:00
|
|
|
|
2021-02-04 22:06:21 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
|
|
|
#include "platform/linux/linux_xdp_file_dialog.h"
|
2021-03-06 22:29:13 +00:00
|
|
|
#include "platform/linux/linux_xdp_open_with_dialog.h"
|
2021-02-04 22:06:21 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
|
|
|
|
2021-03-10 10:26:44 +00:00
|
|
|
#include <QtCore/QProcess>
|
2020-04-28 08:26:12 +00:00
|
|
|
#include <QtGui/QDesktopServices>
|
2019-11-18 07:52:08 +00:00
|
|
|
|
2021-02-28 02:34:41 +00:00
|
|
|
#include <glibmm.h>
|
|
|
|
#include <giomm.h>
|
2020-10-27 05:03:50 +00:00
|
|
|
|
2016-07-06 18:30:14 +00:00
|
|
|
namespace Platform {
|
2017-02-28 14:05:30 +00:00
|
|
|
namespace File {
|
|
|
|
|
2020-04-28 08:26:12 +00:00
|
|
|
void UnsafeOpenUrl(const QString &url) {
|
2021-02-28 02:34:41 +00:00
|
|
|
try {
|
|
|
|
if (Gio::AppInfo::launch_default_for_uri(url.toStdString())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} catch (const Glib::Error &e) {
|
|
|
|
LOG(("App Error: %1").arg(QString::fromStdString(e.what())));
|
2020-04-28 08:26:12 +00:00
|
|
|
}
|
2021-02-28 02:34:41 +00:00
|
|
|
|
2021-03-10 10:26:44 +00:00
|
|
|
if (QDesktopServices::openUrl(url)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-17 00:02:06 +00:00
|
|
|
QProcess::startDetached(qsl("xdg-open"), { url });
|
2020-04-28 08:26:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UnsafeOpenEmailLink(const QString &email) {
|
2020-10-27 05:03:50 +00:00
|
|
|
UnsafeOpenUrl(qstr("mailto:") + email);
|
2020-04-28 08:26:12 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 21:28:24 +00:00
|
|
|
bool UnsafeShowOpenWith(const QString &filepath) {
|
2021-03-06 22:29:13 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
|
|
|
if (internal::ShowXDPOpenWithDialog(filepath)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
|
|
|
|
2020-11-07 21:28:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-28 08:26:12 +00:00
|
|
|
void UnsafeLaunch(const QString &filepath) {
|
2021-02-28 02:34:41 +00:00
|
|
|
try {
|
|
|
|
if (Gio::AppInfo::launch_default_for_uri(
|
|
|
|
Glib::filename_to_uri(filepath.toStdString()))) {
|
|
|
|
return;
|
2020-11-07 21:28:24 +00:00
|
|
|
}
|
2021-02-28 02:34:41 +00:00
|
|
|
} catch (const Glib::Error &e) {
|
|
|
|
LOG(("App Error: %1").arg(QString::fromStdString(e.what())));
|
2020-04-28 08:26:12 +00:00
|
|
|
}
|
2021-02-28 02:34:41 +00:00
|
|
|
|
|
|
|
if (UnsafeShowOpenWith(filepath)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-10 10:26:44 +00:00
|
|
|
const auto qUrlPath = QUrl::fromLocalFile(filepath);
|
|
|
|
if (QDesktopServices::openUrl(qUrlPath)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-17 00:02:06 +00:00
|
|
|
QProcess::startDetached(qsl("xdg-open"), { qUrlPath.toEncoded() });
|
2020-04-28 08:26:12 +00:00
|
|
|
}
|
|
|
|
|
2017-02-28 14:05:30 +00:00
|
|
|
} // namespace File
|
|
|
|
|
2016-07-06 18:30:14 +00:00
|
|
|
namespace FileDialog {
|
2017-02-28 14:05:30 +00:00
|
|
|
|
2018-04-17 15:19:34 +00:00
|
|
|
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,
|
2018-04-17 15:19:34 +00:00
|
|
|
QString startFile) {
|
2018-06-11 20:39:33 +00:00
|
|
|
if (parent) {
|
|
|
|
parent = parent->window();
|
|
|
|
}
|
2021-02-04 22:06:21 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2021-06-22 23:20:40 +00:00
|
|
|
{
|
2021-04-30 02:56:19 +00:00
|
|
|
const auto result = XDP::Get(
|
2021-02-04 22:06:21 +00:00
|
|
|
parent,
|
|
|
|
files,
|
|
|
|
remoteContent,
|
|
|
|
caption,
|
|
|
|
filter,
|
|
|
|
type,
|
|
|
|
startFile);
|
2021-04-30 02:56:19 +00:00
|
|
|
|
|
|
|
if (result.has_value()) {
|
|
|
|
return *result;
|
|
|
|
}
|
2021-02-04 22:06:21 +00:00
|
|
|
}
|
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2018-04-17 15:19:34 +00:00
|
|
|
return ::FileDialog::internal::GetDefault(
|
|
|
|
parent,
|
|
|
|
files,
|
|
|
|
remoteContent,
|
|
|
|
caption,
|
|
|
|
filter,
|
|
|
|
type,
|
|
|
|
startFile);
|
2017-02-28 14:05:30 +00:00
|
|
|
}
|
|
|
|
|
2016-07-06 18:30:14 +00:00
|
|
|
} // namespace FileDialog
|
|
|
|
} // namespace Platform
|