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); });
_pathLink->addClickHandler([=] { editPath(); });
if (!_path.isEmpty() && _path != u"tmp"_q) {
if (!_path.isEmpty() && _path != FileDialog::Tmp()) {
setPathText(QDir::toNativeSeparators(_path));
}
updateControlsVisibility();
@ -73,14 +73,14 @@ void DownloadPathBox::resizeEvent(QResizeEvent *e) {
void DownloadPathBox::radioChanged(Directory value) {
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);
editPath();
} else {
setPathText(QDir::toNativeSeparators(_path));
}
} else if (value == Directory::Temp) {
_path = u"tmp"_q;
_path = FileDialog::Tmp();
} else {
_path = QString();
}
@ -91,7 +91,7 @@ void DownloadPathBox::radioChanged(Directory value) {
void DownloadPathBox::editPath() {
const auto initialPath = [] {
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 QString();
@ -118,7 +118,7 @@ void DownloadPathBox::save() {
if (value == Directory::Custom) {
return _path;
} else if (value == Directory::Temp) {
return qsl("tmp");
return FileDialog::Tmp();
}
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();
_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,
};
void radioChanged(Directory value);
Directory typeFromPath(const QString &path) {
if (path.isEmpty()) {
return Directory::Downloads;
} else if (path == u"tmp"_q) {
return Directory::Temp;
}
return Directory::Custom;
}
Directory typeFromPath(const QString &path);
void save();
void updateControlsVisibility();

View file

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

View file

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

View file

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

View file

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

View file

@ -1745,7 +1745,7 @@ void OverlayWidget::downloadMedia() {
const auto session = _photo ? &_photo->session() : &_document->session();
if (Core::App().settings().downloadPath().isEmpty()) {
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();
} else {
path = Core::App().settings().downloadPath();

View file

@ -83,7 +83,7 @@ void AddAction(
: folderPath;
const auto path = downloadPath.isEmpty()
? File::DefaultDownloadPath(session)
: (downloadPath == u"tmp"_q)
: (downloadPath == FileDialog::Tmp())
? session->local().tempDirectory()
: downloadPath;
if (path.isEmpty()) {
@ -144,7 +144,7 @@ void AddAction(
if (Core::App().settings().askDownloadPath()) {
const auto initialPath = [] {
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));
}

View file

@ -1056,7 +1056,7 @@ void SetupDataStorage(
) | rpl::map([](const QString &text) {
if (text.isEmpty()) {
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 QDir::toNativeSeparators(text);

View file

@ -936,7 +936,9 @@ bool ReadSetting(
stream >> v;
if (!CheckStreamStatus(stream)) return false;
#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().setDownloadPath(v);
#endif // OS_WIN_STORE
@ -950,7 +952,9 @@ bool ReadSetting(
if (!CheckStreamStatus(stream)) return false;
#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().setDownloadPath(v);
psDownloadPathEnableAccess();