Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default export directory in flatpak #28268

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Telegram/SourceFiles/boxes/download_path_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ DownloadPathBox::DownloadPathBox(
, _path(Core::App().settings().downloadPath())
, _pathBookmark(Core::App().settings().downloadPathBookmark())
, _group(std::make_shared<Ui::RadioenumGroup<Directory>>(typeFromPath(_path)))
, _default(Core::App().canReadDefaultDownloadPath(true)
, _default(Core::App().canReadDefaultDownloadPath()
? object_ptr<Ui::Radioenum<Directory>>(
this,
_group,
Expand Down Expand Up @@ -149,7 +149,7 @@ void DownloadPathBox::setPathText(const QString &text) {
DownloadPathBox::Directory DownloadPathBox::typeFromPath(
const QString &path) {
if (path.isEmpty()) {
return Core::App().canReadDefaultDownloadPath(true)
return Core::App().canReadDefaultDownloadPath()
? Directory::Downloads
: Directory::Temp;
} else if (path == FileDialog::Tmp()) {
Expand Down
14 changes: 6 additions & 8 deletions Telegram/SourceFiles/core/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,14 +737,12 @@ void Application::saveSettings() {
Local::writeSettings();
}

bool Application::canReadDefaultDownloadPath(bool always) const {
if (KSandbox::isInside()
&& (always || settings().downloadPath().isEmpty())) {
const auto path = QStandardPaths::writableLocation(
QStandardPaths::DownloadLocation);
return base::CanReadDirectory(path);
}
return true;
bool Application::canReadDefaultDownloadPath() const {
return KSandbox::isInside()
? base::CanReadDirectory(
QStandardPaths::writableLocation(
QStandardPaths::DownloadLocation))
: true;
}

bool Application::canSaveFileWithoutAskingForPath() const {
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/core/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class Application final : public QObject {
void saveSettingsDelayed(crl::time delay = kDefaultSaveDelay);
void saveSettings();

[[nodiscard]] bool canReadDefaultDownloadPath(bool always = false) const;
[[nodiscard]] bool canReadDefaultDownloadPath() const;
[[nodiscard]] bool canSaveFileWithoutAskingForPath() const;

// Fallback config and proxy.
Expand Down
4 changes: 4 additions & 0 deletions Telegram/SourceFiles/export/view/export_view_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ void SettingsWidget::addLocationLabel(
}) | rpl::distinct_until_changed(
) | rpl::map([=](const QString &path) {
const auto text = IsDefaultPath(_session, path)
? Core::App().canReadDefaultDownloadPath()
? u"Downloads/"_q + File::DefaultDownloadPathFolder(_session)
: tr::lng_download_path_temp(tr::now)
: path;
return Ui::Text::Link(
QDir::toNativeSeparators(text),
Expand Down Expand Up @@ -341,7 +343,9 @@ void SettingsWidget::addFormatAndLocationLabel(
}) | rpl::distinct_until_changed(
) | rpl::map([=](const QString &path) {
const auto text = IsDefaultPath(_session, path)
? Core::App().canReadDefaultDownloadPath()
? u"Downloads/"_q + File::DefaultDownloadPathFolder(_session)
: tr::lng_download_path_temp(tr::now)
: path;
return Ui::Text::Link(
QDir::toNativeSeparators(text),
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/settings/settings_chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ void SetupDataStorage(
auto pathtext = Core::App().settings().downloadPathValue(
) | rpl::map([](const QString &text) {
if (text.isEmpty()) {
return Core::App().canReadDefaultDownloadPath(true)
return Core::App().canReadDefaultDownloadPath()
? tr::lng_download_path_default(tr::now)
: tr::lng_download_path_temp(tr::now);
} else if (text == FileDialog::Tmp()) {
Expand Down
Loading