mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Hide default download folder option if it's not available
This commit is contained in:
parent
7a64725045
commit
0eec470387
6 changed files with 30 additions and 18 deletions
|
@ -755,6 +755,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_download_path" = "Download path";
|
"lng_download_path" = "Download path";
|
||||||
"lng_download_path_temp" = "Temp folder";
|
"lng_download_path_temp" = "Temp folder";
|
||||||
"lng_download_path_default" = "Default folder";
|
"lng_download_path_default" = "Default folder";
|
||||||
|
"lng_download_path_unset" = "Unset";
|
||||||
"lng_download_path_clear" = "Clear all";
|
"lng_download_path_clear" = "Clear all";
|
||||||
"lng_download_path_header" = "Choose download path";
|
"lng_download_path_header" = "Choose download path";
|
||||||
"lng_download_path_default_radio" = "Telegram folder in system «Downloads»";
|
"lng_download_path_default_radio" = "Telegram folder in system «Downloads»";
|
||||||
|
|
|
@ -25,7 +25,14 @@ DownloadPathBox::DownloadPathBox(
|
||||||
, _path(Core::App().settings().downloadPath())
|
, _path(Core::App().settings().downloadPath())
|
||||||
, _pathBookmark(Core::App().settings().downloadPathBookmark())
|
, _pathBookmark(Core::App().settings().downloadPathBookmark())
|
||||||
, _group(std::make_shared<Ui::RadioenumGroup<Directory>>(typeFromPath(_path)))
|
, _group(std::make_shared<Ui::RadioenumGroup<Directory>>(typeFromPath(_path)))
|
||||||
, _default(this, _group, Directory::Downloads, tr::lng_download_path_default_radio(tr::now), st::defaultBoxCheckbox)
|
, _default(Core::App().canReadDefaultDownloadPath(true)
|
||||||
|
? object_ptr<Ui::Radioenum<Directory>>(
|
||||||
|
this,
|
||||||
|
_group,
|
||||||
|
Directory::Downloads,
|
||||||
|
tr::lng_download_path_default_radio(tr::now),
|
||||||
|
st::defaultBoxCheckbox)
|
||||||
|
: nullptr)
|
||||||
, _temp(this, _group, Directory::Temp, tr::lng_download_path_temp_radio(tr::now), st::defaultBoxCheckbox)
|
, _temp(this, _group, Directory::Temp, tr::lng_download_path_temp_radio(tr::now), st::defaultBoxCheckbox)
|
||||||
, _dir(this, _group, Directory::Custom, tr::lng_download_path_dir_radio(tr::now), st::defaultBoxCheckbox)
|
, _dir(this, _group, Directory::Custom, tr::lng_download_path_dir_radio(tr::now), st::defaultBoxCheckbox)
|
||||||
, _pathLink(this, QString(), st::boxLinkButton) {
|
, _pathLink(this, QString(), st::boxLinkButton) {
|
||||||
|
@ -50,7 +57,7 @@ void DownloadPathBox::updateControlsVisibility() {
|
||||||
auto custom = (_group->value() == Directory::Custom);
|
auto custom = (_group->value() == Directory::Custom);
|
||||||
_pathLink->setVisible(custom);
|
_pathLink->setVisible(custom);
|
||||||
|
|
||||||
auto newHeight = st::boxOptionListPadding.top() + _default->getMargins().top() + _default->heightNoMargins() + st::boxOptionListSkip + _temp->heightNoMargins() + st::boxOptionListSkip + _dir->heightNoMargins();
|
auto newHeight = st::boxOptionListPadding.top() + (_default ? _default->getMargins().top() + _default->heightNoMargins() : 0) + st::boxOptionListSkip + _temp->heightNoMargins() + st::boxOptionListSkip + _dir->heightNoMargins();
|
||||||
if (custom) {
|
if (custom) {
|
||||||
newHeight += st::downloadPathSkip + _pathLink->height();
|
newHeight += st::downloadPathSkip + _pathLink->height();
|
||||||
}
|
}
|
||||||
|
@ -62,8 +69,10 @@ void DownloadPathBox::updateControlsVisibility() {
|
||||||
void DownloadPathBox::resizeEvent(QResizeEvent *e) {
|
void DownloadPathBox::resizeEvent(QResizeEvent *e) {
|
||||||
BoxContent::resizeEvent(e);
|
BoxContent::resizeEvent(e);
|
||||||
|
|
||||||
_default->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), st::boxOptionListPadding.top() + _default->getMargins().top());
|
if (_default) {
|
||||||
_temp->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), _default->bottomNoMargins() + st::boxOptionListSkip);
|
_default->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), st::boxOptionListPadding.top() + _default->getMargins().top());
|
||||||
|
}
|
||||||
|
_temp->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), (_default ? _default->bottomNoMargins() : 0) + st::boxOptionListSkip);
|
||||||
_dir->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), _temp->bottomNoMargins() + st::boxOptionListSkip);
|
_dir->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), _temp->bottomNoMargins() + st::boxOptionListSkip);
|
||||||
auto inputx = st::boxPadding.left() + st::boxOptionListPadding.left() + st::defaultCheck.diameter + st::defaultBoxCheckbox.textPosition.x();
|
auto inputx = st::boxPadding.left() + st::boxOptionListPadding.left() + st::defaultCheck.diameter + st::defaultBoxCheckbox.textPosition.x();
|
||||||
auto inputy = _dir->bottomNoMargins() + st::downloadPathSkip;
|
auto inputy = _dir->bottomNoMargins() + st::downloadPathSkip;
|
||||||
|
|
|
@ -595,11 +595,9 @@ void Application::saveSettings() {
|
||||||
Local::writeSettings();
|
Local::writeSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Application::canSaveFileWithoutAskingForPath() const {
|
bool Application::canReadDefaultDownloadPath(bool always) const {
|
||||||
if (Core::App().settings().askDownloadPath()) {
|
if (KSandbox::isInside()
|
||||||
return false;
|
&& (always || Core::App().settings().downloadPath().isEmpty())) {
|
||||||
} else if (KSandbox::isInside()
|
|
||||||
&& Core::App().settings().downloadPath().isEmpty()) {
|
|
||||||
const auto path = QStandardPaths::writableLocation(
|
const auto path = QStandardPaths::writableLocation(
|
||||||
QStandardPaths::DownloadLocation);
|
QStandardPaths::DownloadLocation);
|
||||||
return base::CanReadDirectory(path);
|
return base::CanReadDirectory(path);
|
||||||
|
@ -607,6 +605,11 @@ bool Application::canSaveFileWithoutAskingForPath() const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Application::canSaveFileWithoutAskingForPath() const {
|
||||||
|
return !Core::App().settings().askDownloadPath()
|
||||||
|
&& canReadDefaultDownloadPath();
|
||||||
|
}
|
||||||
|
|
||||||
MTP::Config &Application::fallbackProductionConfig() const {
|
MTP::Config &Application::fallbackProductionConfig() const {
|
||||||
if (!_fallbackProductionConfig) {
|
if (!_fallbackProductionConfig) {
|
||||||
_fallbackProductionConfig = std::make_unique<MTP::Config>(
|
_fallbackProductionConfig = std::make_unique<MTP::Config>(
|
||||||
|
|
|
@ -178,6 +178,8 @@ public:
|
||||||
[[nodiscard]] Settings &settings();
|
[[nodiscard]] Settings &settings();
|
||||||
void saveSettingsDelayed(crl::time delay = kDefaultSaveDelay);
|
void saveSettingsDelayed(crl::time delay = kDefaultSaveDelay);
|
||||||
void saveSettings();
|
void saveSettings();
|
||||||
|
|
||||||
|
[[nodiscard]] bool canReadDefaultDownloadPath(bool always = false) const;
|
||||||
[[nodiscard]] bool canSaveFileWithoutAskingForPath() const;
|
[[nodiscard]] bool canSaveFileWithoutAskingForPath() const;
|
||||||
|
|
||||||
// Fallback config and proxy.
|
// Fallback config and proxy.
|
||||||
|
|
|
@ -24,8 +24,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include <QtCore/QStandardPaths>
|
#include <QtCore/QStandardPaths>
|
||||||
#include <QtGui/QDesktopServices>
|
#include <QtGui/QDesktopServices>
|
||||||
|
|
||||||
#include <ksandbox.h>
|
|
||||||
|
|
||||||
bool filedialogGetSaveFile(
|
bool filedialogGetSaveFile(
|
||||||
QPointer<QWidget> parent,
|
QPointer<QWidget> parent,
|
||||||
QString &file,
|
QString &file,
|
||||||
|
@ -173,15 +171,12 @@ QString DefaultDownloadPathFolder(not_null<Main::Session*> session) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DefaultDownloadPath(not_null<Main::Session*> session) {
|
QString DefaultDownloadPath(not_null<Main::Session*> session) {
|
||||||
const auto standardLocation = QStandardPaths::writableLocation(
|
const auto realDefaultPath = QStandardPaths::writableLocation(
|
||||||
QStandardPaths::DownloadLocation);
|
QStandardPaths::DownloadLocation)
|
||||||
const auto realDefaultPath = standardLocation
|
|
||||||
+ '/'
|
+ '/'
|
||||||
+ DefaultDownloadPathFolder(session)
|
+ DefaultDownloadPathFolder(session)
|
||||||
+ '/';
|
+ '/';
|
||||||
if (KSandbox::isInside()
|
if (!Core::App().canReadDefaultDownloadPath()) {
|
||||||
&& Core::App().settings().downloadPath().isEmpty()
|
|
||||||
&& !base::CanReadDirectory(standardLocation)) {
|
|
||||||
QStringList files;
|
QStringList files;
|
||||||
QByteArray remoteContent;
|
QByteArray remoteContent;
|
||||||
const auto success = Platform::FileDialog::Get(
|
const auto success = Platform::FileDialog::Get(
|
||||||
|
|
|
@ -1055,7 +1055,9 @@ void SetupDataStorage(
|
||||||
auto pathtext = Core::App().settings().downloadPathValue(
|
auto pathtext = Core::App().settings().downloadPathValue(
|
||||||
) | 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 Core::App().canReadDefaultDownloadPath(true)
|
||||||
|
? tr::lng_download_path_default(tr::now)
|
||||||
|
: tr::lng_download_path_unset(tr::now);
|
||||||
} else if (text == FileDialog::Tmp()) {
|
} else if (text == FileDialog::Tmp()) {
|
||||||
return tr::lng_download_path_temp(tr::now);
|
return tr::lng_download_path_temp(tr::now);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue