From 233a87a8bc4f03e30d19ed44976fdf0a0ce84c44 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 19 Sep 2018 15:56:08 +0300 Subject: [PATCH] Always export to subfolder of Downloads. --- Telegram/SourceFiles/export/export_settings.h | 1 + .../export/output/export_output_abstract.cpp | 4 ++-- .../view/export_view_panel_controller.cpp | 23 ++++++++++++++++--- .../view/export_view_panel_controller.h | 2 ++ .../export/view/export_view_settings.cpp | 11 ++++----- 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/Telegram/SourceFiles/export/export_settings.h b/Telegram/SourceFiles/export/export_settings.h index a3f39f5306..8e4f4cdc60 100644 --- a/Telegram/SourceFiles/export/export_settings.h +++ b/Telegram/SourceFiles/export/export_settings.h @@ -70,6 +70,7 @@ struct Settings { friend inline constexpr auto is_flag_type(Type) { return true; }; QString path; + bool forceSubPath = false; Output::Format format = Output::Format(); Types types = DefaultTypes(); diff --git a/Telegram/SourceFiles/export/output/export_output_abstract.cpp b/Telegram/SourceFiles/export/output/export_output_abstract.cpp index f203a1737c..b2f3895147 100644 --- a/Telegram/SourceFiles/export/output/export_output_abstract.cpp +++ b/Telegram/SourceFiles/export/output/export_output_abstract.cpp @@ -23,12 +23,12 @@ QString NormalizePath(const Settings &settings) { QDir folder(settings.path); const auto path = folder.absolutePath(); auto result = path.endsWith('/') ? path : (path + '/'); - if (!folder.exists()) { + if (!folder.exists() && !settings.forceSubPath) { return result; } const auto mode = QDir::AllEntries | QDir::NoDotAndDotDot; const auto list = folder.entryInfoList(mode); - if (list.isEmpty()) { + if (list.isEmpty() && !settings.forceSubPath) { return result; } const auto date = QDate::currentDate(); diff --git a/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp b/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp index d1ca9e96b6..0eb212278b 100644 --- a/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp +++ b/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp @@ -102,13 +102,30 @@ void ClearSuggestStart() { } } +bool IsDefaultPath(const QString &path) { + const auto check = [](const QString &value) { + const auto result = value.endsWith('/') + ? value.mid(0, value.size() - 1) + : value; + return (cPlatform() == dbipWindows) ? result.toLower() : result; + }; + return (check(path) == check(psDownloadPath())); +} + +void ResolveSettings(Settings &settings) { + if (settings.path.isEmpty()) { + settings.path = psDownloadPath(); + settings.forceSubPath = true; + } else { + settings.forceSubPath = IsDefaultPath(settings.path); + } +} + PanelController::PanelController(not_null process) : _process(process) , _settings(std::make_unique(Local::ReadExportSettings())) , _saveSettingsTimer([=] { saveSettings(); }) { - if (_settings->path.isEmpty()) { - _settings->path = psDownloadPath(); - } + ResolveSettings(*_settings); _process->state( ) | rpl::start_with_next([=](State &&state) { diff --git a/Telegram/SourceFiles/export/view/export_view_panel_controller.h b/Telegram/SourceFiles/export/view/export_view_panel_controller.h index 6f56c80347..71a1cfcbac 100644 --- a/Telegram/SourceFiles/export/view/export_view_panel_controller.h +++ b/Telegram/SourceFiles/export/view/export_view_panel_controller.h @@ -27,6 +27,8 @@ namespace View { Environment PrepareEnvironment(); QPointer SuggestStart(); void ClearSuggestStart(); +bool IsDefaultPath(const QString &path); +void ResolveSettings(Settings &settings); class Panel; diff --git a/Telegram/SourceFiles/export/view/export_view_settings.cpp b/Telegram/SourceFiles/export/view/export_view_settings.cpp index f4e5d953c1..a8c26afdd8 100644 --- a/Telegram/SourceFiles/export/view/export_view_settings.cpp +++ b/Telegram/SourceFiles/export/view/export_view_settings.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "export/view/export_view_settings.h" #include "export/output/export_output_abstract.h" +#include "export/view/export_view_panel_controller.h" #include "lang/lang_keys.h" #include "ui/widgets/checkbox.h" #include "ui/widgets/buttons.h" @@ -76,6 +77,7 @@ SettingsWidget::SettingsWidget(QWidget *parent, Settings data) : RpWidget(parent) , _singlePeerId(ReadPeerId(data.singlePeer)) , _internal_data(std::move(data)) { + ResolveSettings(_internal_data); setupContent(); } @@ -240,13 +242,7 @@ void SettingsWidget::addLocationLabel( return data.path; }) | rpl::distinct_until_changed( ) | rpl::map([](const QString &path) { - const auto check = [](const QString &value) { - const auto result = value.endsWith('/') - ? value.mid(0, value.size() - 1) - : value; - return (cPlatform() == dbipWindows) ? result.toLower() : result; - }; - const auto text = (check(path) == check(psDownloadPath())) + const auto text = IsDefaultPath(path) ? QString("Downloads/Telegram Desktop") : path; auto pathLink = TextWithEntities{ @@ -562,6 +558,7 @@ void SettingsWidget::chooseFolder() { const auto callback = [=](QString &&result) { changeData([&](Settings &data) { data.path = std::move(result); + data.forceSubPath = IsDefaultPath(data.path); }); }; FileDialog::GetFolder(