From 8f1a8f909dd632479902d6b4d3effb8bbb254dd4 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sun, 2 Oct 2022 11:07:22 +0400 Subject: [PATCH] Ask download path first time in Linux sandbox This allows to have less sandbox holes in flatpak and allows snap users to specify a normal folder to download to (as opposed to $HOME/snap/$SNAP_NAME/current/Downloads) --- Telegram/SourceFiles/core/file_utilities.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Telegram/SourceFiles/core/file_utilities.cpp b/Telegram/SourceFiles/core/file_utilities.cpp index 28dd826f84..ec556bcdd3 100644 --- a/Telegram/SourceFiles/core/file_utilities.cpp +++ b/Telegram/SourceFiles/core/file_utilities.cpp @@ -24,6 +24,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include +#include + bool filedialogGetSaveFile( QPointer parent, QString &file, @@ -171,6 +173,24 @@ QString DefaultDownloadPathFolder(not_null session) { } QString DefaultDownloadPath(not_null session) { + if (KSandbox::isInside() && Core::App().settings().downloadPath().isEmpty()) { + QStringList files; + QByteArray remoteContent; + const auto success = Platform::FileDialog::Get( + nullptr, + files, + remoteContent, + tr::lng_download_path_choose(tr::now), + QString(), + FileDialog::internal::Type::ReadFolder, + QString()); + if (success && !files.isEmpty() && !files[0].isEmpty()) { + const auto result = files[0].endsWith('/') ? files[0] : (files[0] + '/'); + Core::App().settings().setDownloadPath(result); + Core::App().saveSettings(); + return result; + } + } return QStandardPaths::writableLocation( QStandardPaths::DownloadLocation) + '/'