mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-25 04:38:23 +00:00
Allow selecting export folder.
This commit is contained in:
parent
154e5660de
commit
156c3d288c
@ -1696,6 +1696,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
"lng_export_finished" = "Export is finished.";
|
||||
"lng_export_total_files" = "Total files: {count}.";
|
||||
"lng_export_total_size" = "Total size: {size}.";
|
||||
"lng_export_folder" = "Choose export folder";
|
||||
|
||||
// Wnd specific
|
||||
|
||||
|
@ -91,7 +91,7 @@ void DownloadPathBox::onEditPath() {
|
||||
}();
|
||||
const auto handleFolder = [=](const QString &result) {
|
||||
if (!result.isEmpty()) {
|
||||
_path = result + '/';
|
||||
_path = result.endsWith('/') ? result : (result + '/');
|
||||
_pathBookmark = psDownloadPathBookmark(_path);
|
||||
setPathText(QDir::toNativeSeparators(_path));
|
||||
_group->setValue(Directory::Custom);
|
||||
|
@ -76,8 +76,10 @@ QString filedialogDefaultName(
|
||||
if (skipExistance) {
|
||||
name = base + extension;
|
||||
} else {
|
||||
QDir dir(directoryPath);
|
||||
QString nameBase = dir.absolutePath() + '/' + base;
|
||||
QDir directory(directoryPath);
|
||||
const auto dir = directory.absolutePath();
|
||||
const auto nameBase = (dir.endsWith('/') ? dir : (dir + '/'))
|
||||
+ base;
|
||||
name = nameBase + extension;
|
||||
for (int i = 0; QFileInfo(name).exists(); ++i) {
|
||||
name = nameBase + qsl(" (%1)").arg(i + 2) + extension;
|
||||
@ -90,14 +92,16 @@ QString filedialogNextFilename(
|
||||
const QString &name,
|
||||
const QString &cur,
|
||||
const QString &path) {
|
||||
QDir dir(path.isEmpty() ? cDialogLastPath() : path);
|
||||
QDir directory(path.isEmpty() ? cDialogLastPath() : path);
|
||||
int32 extIndex = name.lastIndexOf('.');
|
||||
QString prefix = name, extension;
|
||||
if (extIndex >= 0) {
|
||||
extension = name.mid(extIndex);
|
||||
prefix = name.mid(0, extIndex);
|
||||
}
|
||||
QString nameBase = dir.absolutePath() + '/' + prefix, result = nameBase + extension;
|
||||
const auto dir = directory.absolutePath();
|
||||
const auto nameBase = (dir.endsWith('/') ? dir : (dir + '/')) + prefix;
|
||||
auto result = nameBase + extension;
|
||||
for (int i = 0; result.toLower() != cur.toLower() && QFileInfo(result).exists(); ++i) {
|
||||
result = nameBase + qsl(" (%1)").arg(i + 2) + extension;
|
||||
}
|
||||
|
@ -151,7 +151,8 @@ void Launcher::prepareSettings() {
|
||||
info = info.symLinkTarget();
|
||||
}
|
||||
if (info.exists()) {
|
||||
gExeDir = info.absoluteDir().absolutePath() + '/';
|
||||
const auto dir = info.absoluteDir().absolutePath();
|
||||
gExeDir = (dir.endsWith('/') ? dir : (dir + '/'));
|
||||
gExeName = info.fileName();
|
||||
}
|
||||
}
|
||||
|
@ -232,11 +232,12 @@ bool Controller::normalizePath() {
|
||||
};
|
||||
QDir folder(_settings.path);
|
||||
const auto path = folder.absolutePath();
|
||||
_settings.path = path + '/';
|
||||
_settings.path = path.endsWith('/') ? path : (path + '/');
|
||||
if (!folder.exists()) {
|
||||
return check();
|
||||
}
|
||||
const auto list = folder.entryInfoList();
|
||||
const auto mode = QDir::AllEntries | QDir::NoDotAndDotDot;
|
||||
const auto list = folder.entryInfoList(mode);
|
||||
if (list.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "ui/wrap/slide_wrap.h"
|
||||
#include "ui/wrap/fade_wrap.h"
|
||||
#include "platform/platform_specific.h"
|
||||
#include "core/file_utilities.h"
|
||||
#include "styles/style_widgets.h"
|
||||
#include "styles/style_export.h"
|
||||
#include "styles/style_boxes.h"
|
||||
@ -311,7 +312,7 @@ void SettingsWidget::refreshButtons(not_null<Ui::RpWidget*> container) {
|
||||
: nullptr;
|
||||
if (start) {
|
||||
start->show();
|
||||
_startClicks = start->clicks();
|
||||
start->addClickHandler([=] { chooseFolder(); });
|
||||
|
||||
container->sizeValue(
|
||||
) | rpl::start_with_next([=](QSize size) {
|
||||
@ -339,14 +340,16 @@ void SettingsWidget::refreshButtons(not_null<Ui::RpWidget*> container) {
|
||||
}, cancel->lifetime());
|
||||
}
|
||||
|
||||
void SettingsWidget::chooseFolder() {
|
||||
const auto ready = [=](QString &&result) {
|
||||
_data.path = result;
|
||||
_startClicks.fire(base::duplicate(_data));
|
||||
};
|
||||
FileDialog::GetFolder(this, lang(lng_export_folder), _data.path, ready);
|
||||
}
|
||||
|
||||
rpl::producer<Settings> SettingsWidget::startClicks() const {
|
||||
return _startClicks.value(
|
||||
) | rpl::map([](Wrap &&wrap) {
|
||||
return std::move(wrap.value);
|
||||
}) | rpl::flatten_latest(
|
||||
) | rpl::map([=] {
|
||||
return _data;
|
||||
});
|
||||
return _startClicks.events();
|
||||
}
|
||||
|
||||
rpl::producer<> SettingsWidget::cancelClicks() const {
|
||||
|
@ -31,6 +31,7 @@ private:
|
||||
using MediaTypes = MediaSettings::Types;
|
||||
|
||||
void setupContent();
|
||||
void chooseFolder();
|
||||
void refreshButtons(not_null<Ui::RpWidget*> container);
|
||||
void createSizeSlider(not_null<Ui::VerticalLayout*> container);
|
||||
|
||||
@ -43,7 +44,7 @@ private:
|
||||
rpl::producer<> value;
|
||||
|
||||
};
|
||||
rpl::variable<Wrap> _startClicks;
|
||||
rpl::event_stream<Settings> _startClicks;
|
||||
rpl::variable<Wrap> _cancelClicks;
|
||||
rpl::event_stream<Settings::Types> _dataTypesChanges;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user