Moved tmp string for temporary folder to single place.

This commit is contained in:
23rd 2022-11-30 03:05:55 +03:00
parent 47bb04b019
commit f8a17bd9c9
10 changed files with 34 additions and 21 deletions

View file

@ -40,7 +40,7 @@ void DownloadPathBox::prepare() {
_group->setChangedCallback([this](Directory value) { radioChanged(value); }); _group->setChangedCallback([this](Directory value) { radioChanged(value); });
_pathLink->addClickHandler([=] { editPath(); }); _pathLink->addClickHandler([=] { editPath(); });
if (!_path.isEmpty() && _path != u"tmp"_q) { if (!_path.isEmpty() && _path != FileDialog::Tmp()) {
setPathText(QDir::toNativeSeparators(_path)); setPathText(QDir::toNativeSeparators(_path));
} }
updateControlsVisibility(); updateControlsVisibility();
@ -73,14 +73,14 @@ void DownloadPathBox::resizeEvent(QResizeEvent *e) {
void DownloadPathBox::radioChanged(Directory value) { void DownloadPathBox::radioChanged(Directory value) {
if (value == Directory::Custom) { if (value == Directory::Custom) {
if (_path.isEmpty() || _path == u"tmp"_q) { if (_path.isEmpty() || _path == FileDialog::Tmp()) {
_group->setValue(_path.isEmpty() ? Directory::Downloads : Directory::Temp); _group->setValue(_path.isEmpty() ? Directory::Downloads : Directory::Temp);
editPath(); editPath();
} else { } else {
setPathText(QDir::toNativeSeparators(_path)); setPathText(QDir::toNativeSeparators(_path));
} }
} else if (value == Directory::Temp) { } else if (value == Directory::Temp) {
_path = u"tmp"_q; _path = FileDialog::Tmp();
} else { } else {
_path = QString(); _path = QString();
} }
@ -91,7 +91,7 @@ void DownloadPathBox::radioChanged(Directory value) {
void DownloadPathBox::editPath() { void DownloadPathBox::editPath() {
const auto initialPath = [] { const auto initialPath = [] {
const auto path = Core::App().settings().downloadPath(); const auto path = Core::App().settings().downloadPath();
if (!path.isEmpty() && path != u"tmp"_q) { if (!path.isEmpty() && path != FileDialog::Tmp()) {
return path.left(path.size() - (path.endsWith('/') ? 1 : 0)); return path.left(path.size() - (path.endsWith('/') ? 1 : 0));
} }
return QString(); return QString();
@ -118,7 +118,7 @@ void DownloadPathBox::save() {
if (value == Directory::Custom) { if (value == Directory::Custom) {
return _path; return _path;
} else if (value == Directory::Temp) { } else if (value == Directory::Temp) {
return qsl("tmp"); return FileDialog::Tmp();
} }
return QString(); return QString();
}; };
@ -134,3 +134,13 @@ void DownloadPathBox::setPathText(const QString &text) {
auto availw = st::boxWideWidth - st::boxPadding.left() - st::defaultCheck.diameter - st::defaultBoxCheckbox.textPosition.x() - st::boxPadding.right(); auto availw = st::boxWideWidth - st::boxPadding.left() - st::defaultCheck.diameter - st::defaultBoxCheckbox.textPosition.x() - st::boxPadding.right();
_pathLink->setText(st::boxTextFont->elided(text, availw)); _pathLink->setText(st::boxTextFont->elided(text, availw));
} }
DownloadPathBox::Directory DownloadPathBox::typeFromPath(
const QString &path) {
if (path.isEmpty()) {
return Directory::Downloads;
} else if (path == FileDialog::Tmp()) {
return Directory::Temp;
}
return Directory::Custom;
}

View file

@ -39,14 +39,7 @@ private:
Custom, Custom,
}; };
void radioChanged(Directory value); void radioChanged(Directory value);
Directory typeFromPath(const QString &path) { Directory typeFromPath(const QString &path);
if (path.isEmpty()) {
return Directory::Downloads;
} else if (path == u"tmp"_q) {
return Directory::Temp;
}
return Directory::Custom;
}
void save(); void save();
void updateControlsVisibility(); void updateControlsVisibility();

View file

@ -255,7 +255,7 @@ void Application::run() {
if (KSandbox::isInside()) { if (KSandbox::isInside()) {
const auto path = settings().downloadPath(); const auto path = settings().downloadPath();
if (!path.isEmpty() if (!path.isEmpty()
&& path != qstr("tmp") && path != FileDialog::Tmp()
&& !base::CanReadDirectory(path)) { && !base::CanReadDirectory(path)) {
settings().setDownloadPath(QString()); settings().setDownloadPath(QString());
} }

View file

@ -359,6 +359,11 @@ QString PhotoVideoFilesFilter() {
+ AllFilesFilter(); + AllFilesFilter();
} }
const QString &Tmp() {
static const auto tmp = u"tmp"_q;
return tmp;
}
namespace internal { namespace internal {
void InitLastPathDefault() { void InitLastPathDefault() {

View file

@ -92,6 +92,7 @@ void GetFolder(
[[nodiscard]] QString AllOrImagesFilter(); [[nodiscard]] QString AllOrImagesFilter();
[[nodiscard]] QString ImagesOrAllFilter(); [[nodiscard]] QString ImagesOrAllFilter();
[[nodiscard]] QString PhotoVideoFilesFilter(); [[nodiscard]] QString PhotoVideoFilesFilter();
[[nodiscard]] const QString &Tmp();
namespace internal { namespace internal {

View file

@ -149,7 +149,7 @@ QString FileNameUnsafe(
const auto path = Core::App().settings().downloadPath(); const auto path = Core::App().settings().downloadPath();
if (path.isEmpty()) { if (path.isEmpty()) {
return File::DefaultDownloadPath(session); return File::DefaultDownloadPath(session);
} else if (path == u"tmp"_q) { } else if (path == FileDialog::Tmp()) {
return session->local().tempDirectory(); return session->local().tempDirectory();
} else { } else {
return path; return path;

View file

@ -1745,7 +1745,7 @@ void OverlayWidget::downloadMedia() {
const auto session = _photo ? &_photo->session() : &_document->session(); const auto session = _photo ? &_photo->session() : &_document->session();
if (Core::App().settings().downloadPath().isEmpty()) { if (Core::App().settings().downloadPath().isEmpty()) {
path = File::DefaultDownloadPath(session); path = File::DefaultDownloadPath(session);
} else if (Core::App().settings().downloadPath() == u"tmp"_q) { } else if (Core::App().settings().downloadPath() == FileDialog::Tmp()) {
path = session->local().tempDirectory(); path = session->local().tempDirectory();
} else { } else {
path = Core::App().settings().downloadPath(); path = Core::App().settings().downloadPath();

View file

@ -83,7 +83,7 @@ void AddAction(
: folderPath; : folderPath;
const auto path = downloadPath.isEmpty() const auto path = downloadPath.isEmpty()
? File::DefaultDownloadPath(session) ? File::DefaultDownloadPath(session)
: (downloadPath == u"tmp"_q) : (downloadPath == FileDialog::Tmp())
? session->local().tempDirectory() ? session->local().tempDirectory()
: downloadPath; : downloadPath;
if (path.isEmpty()) { if (path.isEmpty()) {
@ -144,7 +144,7 @@ void AddAction(
if (Core::App().settings().askDownloadPath()) { if (Core::App().settings().askDownloadPath()) {
const auto initialPath = [] { const auto initialPath = [] {
const auto path = Core::App().settings().downloadPath(); const auto path = Core::App().settings().downloadPath();
if (!path.isEmpty() && path != u"tmp"_q) { if (!path.isEmpty() && path != FileDialog::Tmp()) {
return path.left(path.size() return path.left(path.size()
- (path.endsWith('/') ? 1 : 0)); - (path.endsWith('/') ? 1 : 0));
} }

View file

@ -1056,7 +1056,7 @@ void SetupDataStorage(
) | rpl::map([](const QString &text) { ) | rpl::map([](const QString &text) {
if (text.isEmpty()) { if (text.isEmpty()) {
return tr::lng_download_path_default(tr::now); return tr::lng_download_path_default(tr::now);
} else if (text == u"tmp"_q) { } else if (text == FileDialog::Tmp()) {
return tr::lng_download_path_temp(tr::now); return tr::lng_download_path_temp(tr::now);
} }
return QDir::toNativeSeparators(text); return QDir::toNativeSeparators(text);

View file

@ -936,7 +936,9 @@ bool ReadSetting(
stream >> v; stream >> v;
if (!CheckStreamStatus(stream)) return false; if (!CheckStreamStatus(stream)) return false;
#ifndef OS_WIN_STORE #ifndef OS_WIN_STORE
if (!v.isEmpty() && v != u"tmp"_q && !v.endsWith('/')) v += '/'; if (!v.isEmpty() && v != FileDialog::Tmp() && !v.endsWith('/')) {
v += '/';
}
Core::App().settings().setDownloadPathBookmark(QByteArray()); Core::App().settings().setDownloadPathBookmark(QByteArray());
Core::App().settings().setDownloadPath(v); Core::App().settings().setDownloadPath(v);
#endif // OS_WIN_STORE #endif // OS_WIN_STORE
@ -950,7 +952,9 @@ bool ReadSetting(
if (!CheckStreamStatus(stream)) return false; if (!CheckStreamStatus(stream)) return false;
#ifndef OS_WIN_STORE #ifndef OS_WIN_STORE
if (!v.isEmpty() && v != u"tmp"_q && !v.endsWith('/')) v += '/'; if (!v.isEmpty() && v != FileDialog::Tmp() && !v.endsWith('/')) {
v += '/';
}
Core::App().settings().setDownloadPathBookmark(bookmark); Core::App().settings().setDownloadPathBookmark(bookmark);
Core::App().settings().setDownloadPath(v); Core::App().settings().setDownloadPath(v);
psDownloadPathEnableAccess(); psDownloadPathEnableAccess();