2016-07-06 21:30:14 +03:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 13:23:14 +03:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-07-06 21:30:14 +03:00
|
|
|
|
2018-01-03 13:23:14 +03:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-07-06 21:30:14 +03:00
|
|
|
*/
|
2017-02-28 13:51:00 +03:00
|
|
|
#include "platform/linux/file_utilities_linux.h"
|
2016-07-06 21:30:14 +03:00
|
|
|
|
2022-08-02 19:25:48 +04:00
|
|
|
#include "base/platform/linux/base_linux_app_launch_context.h"
|
2021-03-07 02:29:13 +04:00
|
|
|
#include "platform/linux/linux_xdp_open_with_dialog.h"
|
2021-02-05 02:06:21 +04:00
|
|
|
|
2020-04-28 12:26:12 +04:00
|
|
|
#include <QtGui/QDesktopServices>
|
2019-11-18 10:52:08 +03:00
|
|
|
|
2021-02-28 06:34:41 +04:00
|
|
|
#include <glibmm.h>
|
|
|
|
#include <giomm.h>
|
2020-10-27 09:03:50 +04:00
|
|
|
|
2016-07-06 21:30:14 +03:00
|
|
|
namespace Platform {
|
2017-02-28 17:05:30 +03:00
|
|
|
namespace File {
|
|
|
|
|
2020-04-28 12:26:12 +04:00
|
|
|
void UnsafeOpenUrl(const QString &url) {
|
2021-02-28 06:34:41 +04:00
|
|
|
try {
|
2022-08-02 19:25:48 +04:00
|
|
|
if (Gio::AppInfo::launch_default_for_uri(
|
|
|
|
url.toStdString(),
|
|
|
|
base::Platform::AppLaunchContext())) {
|
2021-02-28 06:34:41 +04:00
|
|
|
return;
|
|
|
|
}
|
2022-11-03 13:41:18 +04:00
|
|
|
} catch (const std::exception &e) {
|
2021-02-28 06:34:41 +04:00
|
|
|
LOG(("App Error: %1").arg(QString::fromStdString(e.what())));
|
2020-04-28 12:26:12 +04:00
|
|
|
}
|
2021-02-28 06:34:41 +04:00
|
|
|
|
2022-04-12 18:31:25 +04:00
|
|
|
QDesktopServices::openUrl(url);
|
2020-04-28 12:26:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void UnsafeOpenEmailLink(const QString &email) {
|
2022-11-27 00:20:17 +03:00
|
|
|
UnsafeOpenUrl(u"mailto:"_q + email);
|
2020-04-28 12:26:12 +04:00
|
|
|
}
|
|
|
|
|
2020-11-08 01:28:24 +04:00
|
|
|
bool UnsafeShowOpenWith(const QString &filepath) {
|
2021-03-07 02:29:13 +04:00
|
|
|
if (internal::ShowXDPOpenWithDialog(filepath)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-11-08 01:28:24 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-28 12:26:12 +04:00
|
|
|
void UnsafeLaunch(const QString &filepath) {
|
2021-02-28 06:34:41 +04:00
|
|
|
try {
|
|
|
|
if (Gio::AppInfo::launch_default_for_uri(
|
2022-08-02 19:25:48 +04:00
|
|
|
Glib::filename_to_uri(filepath.toStdString()),
|
|
|
|
base::Platform::AppLaunchContext())) {
|
2021-02-28 06:34:41 +04:00
|
|
|
return;
|
2020-11-08 01:28:24 +04:00
|
|
|
}
|
2022-11-03 13:41:18 +04:00
|
|
|
} catch (const std::exception &e) {
|
2021-02-28 06:34:41 +04:00
|
|
|
LOG(("App Error: %1").arg(QString::fromStdString(e.what())));
|
2020-04-28 12:26:12 +04:00
|
|
|
}
|
2021-02-28 06:34:41 +04:00
|
|
|
|
|
|
|
if (UnsafeShowOpenWith(filepath)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-12 18:31:25 +04:00
|
|
|
QDesktopServices::openUrl(QUrl::fromLocalFile(filepath));
|
2020-04-28 12:26:12 +04:00
|
|
|
}
|
|
|
|
|
2017-02-28 17:05:30 +03:00
|
|
|
} // namespace File
|
|
|
|
|
2016-07-06 21:30:14 +03:00
|
|
|
namespace FileDialog {
|
2017-02-28 17:05:30 +03:00
|
|
|
|
2018-04-17 19:19:34 +04:00
|
|
|
bool Get(
|
|
|
|
QPointer<QWidget> parent,
|
|
|
|
QStringList &files,
|
|
|
|
QByteArray &remoteContent,
|
|
|
|
const QString &caption,
|
|
|
|
const QString &filter,
|
2021-01-10 07:51:38 +04:00
|
|
|
::FileDialog::internal::Type type,
|
2018-04-17 19:19:34 +04:00
|
|
|
QString startFile) {
|
2018-06-11 23:39:33 +03:00
|
|
|
if (parent) {
|
|
|
|
parent = parent->window();
|
|
|
|
}
|
2022-05-31 11:16:25 +04:00
|
|
|
// Workaround for sandboxed paths
|
|
|
|
static const auto docRegExp = QRegularExpression("^/run/user/\\d+/doc");
|
|
|
|
if (cDialogLastPath().contains(docRegExp)) {
|
|
|
|
InitLastPath();
|
2021-02-05 02:06:21 +04:00
|
|
|
}
|
2018-04-17 19:19:34 +04:00
|
|
|
return ::FileDialog::internal::GetDefault(
|
|
|
|
parent,
|
|
|
|
files,
|
|
|
|
remoteContent,
|
|
|
|
caption,
|
|
|
|
filter,
|
|
|
|
type,
|
|
|
|
startFile);
|
2017-02-28 17:05:30 +03:00
|
|
|
}
|
|
|
|
|
2016-07-06 21:30:14 +03:00
|
|
|
} // namespace FileDialog
|
|
|
|
} // namespace Platform
|