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
|
|
|
|
2023-08-01 16:04:25 +04:00
|
|
|
#include <gio/gio.hpp>
|
|
|
|
|
|
|
|
using namespace gi::repository;
|
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) {
|
2023-08-01 16:04:25 +04:00
|
|
|
{
|
|
|
|
const auto result = Gio::AppInfo::launch_default_for_uri(
|
2022-08-02 19:25:48 +04:00
|
|
|
url.toStdString(),
|
2023-08-01 16:04:25 +04:00
|
|
|
base::Platform::AppLaunchContext());
|
|
|
|
|
|
|
|
if (!result) {
|
2023-09-19 17:10:53 +04:00
|
|
|
LOG(("App Error: %1").arg(result.error().what()));
|
2023-08-01 16:04:25 +04:00
|
|
|
} else if (*result) {
|
2021-02-28 06:34:41 +04:00
|
|
|
return;
|
|
|
|
}
|
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) {
|
2023-08-01 16:04:25 +04:00
|
|
|
if ([&] {
|
|
|
|
const auto filename = GLib::filename_to_uri(filepath.toStdString());
|
|
|
|
if (!filename) {
|
2023-09-19 17:10:53 +04:00
|
|
|
LOG(("App Error: %1").arg(filename.error().what()));
|
2023-08-01 16:04:25 +04:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto result = Gio::AppInfo::launch_default_for_uri(
|
|
|
|
*filename,
|
|
|
|
base::Platform::AppLaunchContext());
|
|
|
|
|
|
|
|
if (!result) {
|
2023-09-19 17:10:53 +04:00
|
|
|
LOG(("App Error: %1").arg(result.error().what()));
|
2023-08-01 16:04:25 +04:00
|
|
|
|
|
|
|
return false;
|
2020-11-08 01:28:24 +04:00
|
|
|
}
|
2023-08-01 16:04:25 +04:00
|
|
|
|
|
|
|
return *result;
|
|
|
|
}()) {
|
|
|
|
return;
|
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();
|
|
|
|
}
|
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
|