From 7307f0b1a5b4716595e4d8985304649d45151e0e Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Mon, 2 Jan 2023 17:22:21 +0400 Subject: [PATCH] Use temp directory for downloads in Linux sandbox by default --- Telegram/Resources/langs/lang.strings | 1 - .../SourceFiles/boxes/download_path_box.cpp | 4 ++- Telegram/SourceFiles/core/application.cpp | 12 +-------- Telegram/SourceFiles/core/file_utilities.cpp | 26 ++++--------------- .../SourceFiles/settings/settings_chat.cpp | 2 +- 5 files changed, 10 insertions(+), 35 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 5776e1373..a4b642b26 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -755,7 +755,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_download_path" = "Download path"; "lng_download_path_temp" = "Temp folder"; "lng_download_path_default" = "Default folder"; -"lng_download_path_unset" = "Unset"; "lng_download_path_clear" = "Clear all"; "lng_download_path_header" = "Choose download path"; "lng_download_path_default_radio" = "Telegram folder in system «Downloads»"; diff --git a/Telegram/SourceFiles/boxes/download_path_box.cpp b/Telegram/SourceFiles/boxes/download_path_box.cpp index efbd96899..69179e9f4 100644 --- a/Telegram/SourceFiles/boxes/download_path_box.cpp +++ b/Telegram/SourceFiles/boxes/download_path_box.cpp @@ -147,7 +147,9 @@ void DownloadPathBox::setPathText(const QString &text) { DownloadPathBox::Directory DownloadPathBox::typeFromPath( const QString &path) { if (path.isEmpty()) { - return Directory::Downloads; + return Core::App().canReadDefaultDownloadPath(true) + ? Directory::Downloads + : Directory::Temp; } else if (path == FileDialog::Tmp()) { return Directory::Temp; } diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index b1d194ca5..16eb0cf0f 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -252,15 +252,6 @@ void Application::run() { return; } - if (KSandbox::isInside()) { - const auto path = settings().downloadPath(); - if (!path.isEmpty() - && path != FileDialog::Tmp() - && !base::CanReadDirectory(path)) { - settings().setDownloadPath(QString()); - } - } - _translator = std::make_unique(); QCoreApplication::instance()->installTranslator(_translator.get()); @@ -606,8 +597,7 @@ bool Application::canReadDefaultDownloadPath(bool always) const { } bool Application::canSaveFileWithoutAskingForPath() const { - return !Core::App().settings().askDownloadPath() - && canReadDefaultDownloadPath(); + return !Core::App().settings().askDownloadPath(); } MTP::Config &Application::fallbackProductionConfig() const { diff --git a/Telegram/SourceFiles/core/file_utilities.cpp b/Telegram/SourceFiles/core/file_utilities.cpp index 7b8d03cd9..5821bddd4 100644 --- a/Telegram/SourceFiles/core/file_utilities.cpp +++ b/Telegram/SourceFiles/core/file_utilities.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/abstract_box.h" #include "storage/localstorage.h" +#include "storage/storage_account.h" #include "base/platform/base_platform_info.h" #include "base/platform/base_platform_file_utilities.h" #include "platform/platform_file_utilities.h" @@ -171,31 +172,14 @@ QString DefaultDownloadPathFolder(not_null session) { } QString DefaultDownloadPath(not_null session) { - const auto realDefaultPath = QStandardPaths::writableLocation( + if (!Core::App().canReadDefaultDownloadPath()) { + return session->local().tempDirectory(); + } + return QStandardPaths::writableLocation( QStandardPaths::DownloadLocation) + '/' + DefaultDownloadPathFolder(session) + '/'; - if (!Core::App().canReadDefaultDownloadPath()) { - 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, - realDefaultPath); - 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 QString(); - } - return realDefaultPath; } namespace internal { diff --git a/Telegram/SourceFiles/settings/settings_chat.cpp b/Telegram/SourceFiles/settings/settings_chat.cpp index 904bfed94..875676c53 100644 --- a/Telegram/SourceFiles/settings/settings_chat.cpp +++ b/Telegram/SourceFiles/settings/settings_chat.cpp @@ -1057,7 +1057,7 @@ void SetupDataStorage( if (text.isEmpty()) { return Core::App().canReadDefaultDownloadPath(true) ? tr::lng_download_path_default(tr::now) - : tr::lng_download_path_unset(tr::now); + : tr::lng_download_path_temp(tr::now); } else if (text == FileDialog::Tmp()) { return tr::lng_download_path_temp(tr::now); }