mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-21 18:57:48 +00:00
Always export to subfolder of Downloads.
This commit is contained in:
parent
00e4cfc345
commit
233a87a8bc
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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<ControllerWrap*> process)
|
||||
: _process(process)
|
||||
, _settings(std::make_unique<Settings>(Local::ReadExportSettings()))
|
||||
, _saveSettingsTimer([=] { saveSettings(); }) {
|
||||
if (_settings->path.isEmpty()) {
|
||||
_settings->path = psDownloadPath();
|
||||
}
|
||||
ResolveSettings(*_settings);
|
||||
|
||||
_process->state(
|
||||
) | rpl::start_with_next([=](State &&state) {
|
||||
|
@ -27,6 +27,8 @@ namespace View {
|
||||
Environment PrepareEnvironment();
|
||||
QPointer<BoxContent> SuggestStart();
|
||||
void ClearSuggestStart();
|
||||
bool IsDefaultPath(const QString &path);
|
||||
void ResolveSettings(Settings &settings);
|
||||
|
||||
class Panel;
|
||||
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user