Skip to content

Commit

Permalink
Allow selecting export folder.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Jun 20, 2018
1 parent 154e566 commit 156c3d2
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 17 deletions.
1 change: 1 addition & 0 deletions Telegram/Resources/langs/lang.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/boxes/download_path_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 8 additions & 4 deletions Telegram/SourceFiles/core/file_utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion Telegram/SourceFiles/core/launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
5 changes: 3 additions & 2 deletions Telegram/SourceFiles/export/export_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
19 changes: 11 additions & 8 deletions Telegram/SourceFiles/export/view/export_view_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ For license and copyright information please follow this link:
#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"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion Telegram/SourceFiles/export/view/export_view_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class SettingsWidget : public Ui::RpWidget {
using MediaTypes = MediaSettings::Types;

void setupContent();
void chooseFolder();
void refreshButtons(not_null<Ui::RpWidget*> container);
void createSizeSlider(not_null<Ui::VerticalLayout*> container);

Expand All @@ -43,7 +44,7 @@ class SettingsWidget : public Ui::RpWidget {
rpl::producer<> value;

};
rpl::variable<Wrap> _startClicks;
rpl::event_stream<Settings> _startClicks;
rpl::variable<Wrap> _cancelClicks;
rpl::event_stream<Settings::Types> _dataTypesChanges;

Expand Down

0 comments on commit 156c3d2

Please sign in to comment.