From a0c6104fae7d425284cb263ee518d9bccfc688ff Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 6 Dec 2018 19:47:28 +0400 Subject: [PATCH] Redesign auto download box. --- Telegram/Resources/langs/lang.strings | 14 +- .../SourceFiles/boxes/auto_download_box.cpp | 167 ++++++++++++++++++ .../SourceFiles/boxes/auto_download_box.h | 30 ++++ Telegram/SourceFiles/boxes/boxes.style | 4 + Telegram/SourceFiles/boxes/connection_box.cpp | 144 +-------------- Telegram/SourceFiles/boxes/connection_box.h | 12 -- Telegram/SourceFiles/data/data_session.cpp | 14 +- Telegram/SourceFiles/data/data_session.h | 3 +- .../export/view/export_view_settings.cpp | 59 +++---- .../export/view/export_view_settings.h | 3 + .../info/profile/info_profile_button.cpp | 15 +- .../info/profile/info_profile_button.h | 3 +- Telegram/SourceFiles/settings/settings.style | 4 + .../settings/settings_advanced.cpp | 1 + .../SourceFiles/settings/settings_chat.cpp | 32 +++- Telegram/SourceFiles/settings/settings_chat.h | 1 + .../settings/settings_privacy_security.cpp | 2 +- Telegram/SourceFiles/ui/widgets/checkbox.h | 3 + Telegram/gyp/telegram_sources.txt | 6 +- 19 files changed, 298 insertions(+), 219 deletions(-) create mode 100644 Telegram/SourceFiles/boxes/auto_download_box.cpp create mode 100644 Telegram/SourceFiles/boxes/auto_download_box.h diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index f15b225a1b..22c5a07e6d 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -998,13 +998,19 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_media_audio" = "Voice message"; "lng_media_auto_settings" = "Automatic media download"; +"lng_media_auto_in_private" = "In private chats"; +"lng_media_auto_in_groups" = "In groups"; +"lng_media_auto_in_channels" = "In channels"; "lng_media_auto_title" = "Automatically download"; "lng_media_photo_title" = "Photos"; +"lng_media_video_title" = "Video files"; "lng_media_audio_title" = "Voice messages"; -"lng_media_gif_title" = "GIFs and animations"; -"lng_media_auto_private_chats" = "Private chats"; -"lng_media_auto_groups" = "Groups and channels"; -"lng_media_auto_play" = "Autoplay"; +"lng_media_video_messages_title" = "Round video messages"; +"lng_media_file_title" = "Files"; +"lng_media_music_title" = "Music"; +"lng_media_animation_title" = "Animated GIFs"; +"lng_media_size_limit" = "Limit by size"; +"lng_media_size_up_to" = "up to {size}"; "lng_emoji_category1" = "People"; "lng_emoji_category2" = "Nature"; diff --git a/Telegram/SourceFiles/boxes/auto_download_box.cpp b/Telegram/SourceFiles/boxes/auto_download_box.cpp new file mode 100644 index 0000000000..bb27db5933 --- /dev/null +++ b/Telegram/SourceFiles/boxes/auto_download_box.cpp @@ -0,0 +1,167 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "boxes/auto_download_box.h" + +#include "lang/lang_keys.h" +#include "auth_session.h" +#include "data/data_session.h" +#include "info/profile/info_profile_button.h" +#include "ui/widgets/continuous_sliders.h" +#include "ui/wrap/vertical_layout.h" +#include "ui/wrap/wrap.h" +#include "storage/localstorage.h" +#include "settings/settings_common.h" +#include "export/view/export_view_settings.h" +#include "styles/style_boxes.h" +#include "styles/style_settings.h" + +namespace { + +constexpr auto kMegabyte = 1024 * 1024; +constexpr auto kDefaultLimit = 10 * kMegabyte; + +} // namespace + +AutoDownloadBox::AutoDownloadBox( + QWidget*, + Data::AutoDownload::Source source) +: _source(source) { +} + +void AutoDownloadBox::prepare() { + setupContent(); +} + +void AutoDownloadBox::setupContent() { + using namespace Settings; + using namespace Data::AutoDownload; + using namespace rpl::mappers; + using Type = Data::AutoDownload::Type; + + constexpr auto kLegacyLimit = 10 * 1024 * 1024; + + setTitle(langFactory(lng_media_auto_title)); + + const auto settings = &Auth().settings().autoDownload(); + const auto checked = [=](Source source, Type type) { + return (settings->bytesLimit(source, type) > 0); + }; + + auto wrap = object_ptr(this); + const auto content = wrap.data(); + setInnerWidget(object_ptr( + this, + std::move(wrap))); + + const auto values = Ui::CreateChild>(content); + const auto add = [&](Type type, LangKey label) { + const auto value = settings->bytesLimit(_source, type); + AddButton( + content, + label, + st::settingsButton + )->toggleOn( + rpl::single(value > 0) + )->toggledChanges( + ) | rpl::start_with_next([=](bool enabled) { + (*values)[type] = enabled ? 1 : 0; + }, content->lifetime()); + values->emplace(type, value); + }; + add(Type::Photo, lng_media_photo_title); + add(Type::VoiceMessage, lng_media_audio_title); + add(Type::VideoMessage, lng_media_video_messages_title); + add(Type::Video, lng_media_video_title); + add(Type::File, lng_media_file_title); + add(Type::Music, lng_media_music_title); + add(Type::GIF, lng_media_animation_title); + + const auto limits = Ui::CreateChild>(content); + using Pair = base::flat_map::value_type; + const auto settingsLimit = ranges::max_element( + *values, + std::less<>(), + [](Pair pair) { return pair.second; })->second; + const auto initialLimit = settingsLimit ? settingsLimit : kDefaultLimit; + const auto limit = Ui::CreateChild(content, initialLimit); + AddButtonWithLabel( + content, + lng_media_size_limit, + limits->events_starting_with_copy( + initialLimit + ) | rpl::map([](int value) { + return lng_media_size_up_to( + lt_size, + QString::number(value / kMegabyte) + " MB"); + }), + st::autoDownloadLimitButton + )->setAttribute(Qt::WA_TransparentForMouseEvents); + const auto slider = content->add( + object_ptr(content, st::autoDownloadLimitSlider), + st::autoDownloadLimitPadding); + slider->resize(st::autoDownloadLimitSlider.seekSize); + slider->setPseudoDiscrete( + Export::View::kSizeValueCount, + Export::View::SizeLimitByIndex, + *limit, + [=](int value) { + *limit = value; + limits->fire_copy(value); + }); + const auto save = [=]( + Type type, + std::pair pair) { + const auto limit = [](bool checked) { + return checked ? kMaxBytesLimit : 0; + }; + settings->setBytesLimit(Source::User, type, limit(pair.first)); + settings->setBytesLimit(Source::Group, type, limit(pair.second)); + settings->setBytesLimit(Source::Channel, type, limit(pair.second)); + }; + + addButton(langFactory(lng_connection_save), [=] { + auto allowMore = ranges::view::all( + *values + ) | ranges::view::filter([&](Pair pair) { + const auto [type, enabled] = pair; + const auto value = enabled ? *limit : 0; + const auto old = settings->bytesLimit(_source, type); + return (old < value); + }) | ranges::view::transform([](Pair pair) { + return pair.first; + }); + const auto allowMoreTypes = base::flat_set( + allowMore.begin(), + allowMore.end()); + + const auto changed = ranges::find_if(*values, [&](Pair pair) { + const auto [type, enabled] = pair; + const auto value = enabled ? *limit : 0; + return settings->bytesLimit(_source, type) != value; + }) != end(*values); + + if (changed) { + for (const auto [type, enabled] : *values) { + const auto value = enabled ? *limit : 0; + settings->setBytesLimit(_source, type, value); + } + Local::writeUserSettings(); + } + if (allowMoreTypes.contains(Type::Photo)) { + Auth().data().photoLoadSettingsChanged(); + } + if (ranges::find_if(allowMoreTypes, _1 != Type::Photo) + != allowMoreTypes.end()) { + Auth().data().documentLoadSettingsChanged(); + } + closeBox(); + }); + addButton(langFactory(lng_cancel), [=] { closeBox(); }); + + setDimensionsToContent(st::boxWidth, content); +} diff --git a/Telegram/SourceFiles/boxes/auto_download_box.h b/Telegram/SourceFiles/boxes/auto_download_box.h new file mode 100644 index 0000000000..a3485ef4ea --- /dev/null +++ b/Telegram/SourceFiles/boxes/auto_download_box.h @@ -0,0 +1,30 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +#include "boxes/abstract_box.h" + +namespace Data { +namespace AutoDownload { +enum class Source; +} // namespace AutoDownload +} // namespace Data + +class AutoDownloadBox : public BoxContent { +public: + AutoDownloadBox(QWidget*, Data::AutoDownload::Source source); + +protected: + void prepare() override; + +private: + void setupContent(); + + Data::AutoDownload::Source _source; + +}; diff --git a/Telegram/SourceFiles/boxes/boxes.style b/Telegram/SourceFiles/boxes/boxes.style index 7ec24cee1a..7959a122b8 100644 --- a/Telegram/SourceFiles/boxes/boxes.style +++ b/Telegram/SourceFiles/boxes/boxes.style @@ -533,6 +533,10 @@ aboutLabel: FlatLabel(defaultFlatLabel) { autoDownloadTopDelta: 10px; autoDownloadTitlePosition: point(23px, 18px); autoDownloadTitleFont: font(15px semibold); +autoDownloadLimitSlider: MediaSlider(defaultContinuousSlider) { + seekSize: size(15px, 15px); +} +autoDownloadLimitPadding: margins(22px, 8px, 22px, 8px); confirmCaptionArea: InputField(defaultInputField) { textMargins: margins(1px, 26px, 31px, 4px); diff --git a/Telegram/SourceFiles/boxes/connection_box.cpp b/Telegram/SourceFiles/boxes/connection_box.cpp index ab5917f562..fb545d0504 100644 --- a/Telegram/SourceFiles/boxes/connection_box.cpp +++ b/Telegram/SourceFiles/boxes/connection_box.cpp @@ -7,37 +7,24 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "boxes/connection_box.h" -#include "data/data_photo.h" -#include "data/data_document.h" #include "boxes/confirm_box.h" #include "lang/lang_keys.h" #include "storage/localstorage.h" #include "base/qthelp_url.h" -#include "mainwidget.h" #include "messenger.h" -#include "mainwindow.h" -#include "auth_session.h" -#include "data/data_session.h" -#include "mtproto/connection.h" #include "ui/widgets/checkbox.h" #include "ui/widgets/buttons.h" #include "ui/widgets/input_fields.h" #include "ui/widgets/labels.h" #include "ui/widgets/dropdown_menu.h" -#include "ui/wrap/fade_wrap.h" -#include "ui/wrap/padding_wrap.h" #include "ui/wrap/slide_wrap.h" #include "ui/wrap/vertical_layout.h" #include "ui/toast/toast.h" #include "ui/effects/radial_animation.h" #include "ui/text_options.h" -#include "history/history_location_manager.h" -#include "settings/settings_common.h" -#include "application.h" #include "styles/style_boxes.h" #include "styles/style_chat_helpers.h" #include "styles/style_info.h" -#include "styles/style_settings.h" namespace { @@ -936,135 +923,6 @@ void ProxyBox::addLabel( } // namespace -AutoDownloadBox::AutoDownloadBox(QWidget *parent) { -} - -void AutoDownloadBox::prepare() { - setupContent(); -} - -void AutoDownloadBox::setupContent() { - using namespace Settings; - using namespace Data::AutoDownload; - using Type = Data::AutoDownload::Type; - - constexpr auto kLegacyLimit = 10 * 1024 * 1024; - - setTitle(langFactory(lng_media_auto_title)); - - const auto settings = &Auth().settings().autoDownload(); - const auto checked = [=](Source source, Type type) { - return (settings->bytesLimit(source, type) > 0); - }; - - auto wrap = object_ptr(this); - const auto content = wrap.data(); - setInnerWidget(object_ptr( - this, - std::move(wrap))); - - using pair = std::pair; - const auto pairChecked = [](pair checkboxes) { - return std::make_pair( - checkboxes.first->checked(), - checkboxes.second->checked()); - }; - const auto enabledSomething = [=]( - Type type, - std::pair pair) { - return (!checked(Source::User, type) && pair.first) - || (!checked(Source::Group, type) && pair.second); - }; - const auto changedSomething = [=]( - Type type, - std::pair pair) { - return (checked(Source::User, type) != pair.first) - || (checked(Source::Group, type) != pair.second); - }; - const auto save = [=]( - Type type, - std::pair pair) { - const auto limit = [](bool checked) { - return checked ? kMaxBytesLimit : 0; - }; - settings->setBytesLimit(Source::User, type, limit(pair.first)); - settings->setBytesLimit(Source::Group, type, limit(pair.second)); - settings->setBytesLimit(Source::Channel, type, limit(pair.second)); - }; - const auto addCheckbox = [&](Type type, Source source) { - const auto label = (source == Source::User) - ? lng_media_auto_private_chats - : lng_media_auto_groups; - return content->add( - object_ptr( - content, - lang(label), - checked(source, type), - st::settingsSendType), - st::settingsSendTypePadding); - }; - const auto addPair = [&](Type type) { - const auto first = addCheckbox(type, Source::User); - const auto second = addCheckbox(type, Source::Group); - return pair(first, second); - }; - - AddSubsectionTitle(content, lng_media_photo_title); - const auto photo = addPair(Type::Photo); - AddSkip(content); - - AddSkip(content); - AddSubsectionTitle(content, lng_media_audio_title); - const auto audio = addPair(Type::VoiceMessage); - AddSkip(content); - - AddSkip(content); - AddSubsectionTitle(content, lng_media_gif_title); - const auto gif = addPair(Type::GIF); - AddSkip(content); - - addButton(langFactory(lng_connection_save), [=] { - const auto photoChecked = pairChecked(photo); - const auto audioChecked = pairChecked(audio); - const auto gifChecked = pairChecked(gif); - const auto photosEnabled = enabledSomething( - Type::Photo, - photoChecked); - const auto audioEnabled = enabledSomething( - Type::VoiceMessage, - audioChecked); - const auto gifEnabled = enabledSomething( - Type::GIF, - gifChecked); - const auto photosChanged = changedSomething( - Type::Photo, - photoChecked); - const auto documentsChanged = changedSomething( - Type::VoiceMessage, - audioChecked) || changedSomething(Type::GIF, gifChecked); - if (photosChanged || documentsChanged) { - save(Type::Photo, photoChecked); - save(Type::VoiceMessage, audioChecked); - save(Type::GIF, gifChecked); - save(Type::VideoMessage, gifChecked); - Local::writeUserSettings(); - } - if (photosEnabled) { - Auth().data().photoLoadSettingsChanged(); - } - if (audioEnabled) { - Auth().data().voiceLoadSettingsChanged(); - } - if (gifEnabled) { - Auth().data().animationLoadSettingsChanged(); - } - closeBox(); - }); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); - - setDimensionsToContent(st::boxWideWidth, content); -} - ProxiesBoxController::ProxiesBoxController() : _saveTimer([] { Local::writeSettings(); }) { _list = ranges::view::all( @@ -1524,7 +1382,7 @@ void ProxiesBoxController::share(const ProxyData &proxy) { ? "&pass=" + qthelp::url_encode(proxy.password) : "") + ((proxy.type == Type::Mtproto && !proxy.password.isEmpty()) ? "&secret=" + proxy.password : ""); - Application::clipboard()->setText(link); + QApplication::clipboard()->setText(link); Ui::Toast::Show(lang(lng_username_copied)); } diff --git a/Telegram/SourceFiles/boxes/connection_box.h b/Telegram/SourceFiles/boxes/connection_box.h index 6958ded70a..66b0eaa80d 100644 --- a/Telegram/SourceFiles/boxes/connection_box.h +++ b/Telegram/SourceFiles/boxes/connection_box.h @@ -22,18 +22,6 @@ template class Radioenum; } // namespace Ui -class AutoDownloadBox : public BoxContent { -public: - AutoDownloadBox(QWidget *parent); - -protected: - void prepare() override; - -private: - void setupContent(); - -}; - class ProxiesBoxController : public base::Subscriber { public: using Type = ProxyData::Type; diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index ad83cf42a2..a7cf6b6526 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -247,19 +247,9 @@ void Session::photoLoadSettingsChanged() { } } -void Session::voiceLoadSettingsChanged() { +void Session::documentLoadSettingsChanged() { for (const auto &[id, document] : _documents) { - if (document->isVoiceMessage()) { - document->automaticLoadSettingsChanged(); - } - } -} - -void Session::animationLoadSettingsChanged() { - for (const auto &[id, document] : _documents) { - if (document->isAnimation()) { - document->automaticLoadSettingsChanged(); - } + document->automaticLoadSettingsChanged(); } } diff --git a/Telegram/SourceFiles/data/data_session.h b/Telegram/SourceFiles/data/data_session.h index 44076a24ff..e559e9ec7f 100644 --- a/Telegram/SourceFiles/data/data_session.h +++ b/Telegram/SourceFiles/data/data_session.h @@ -238,8 +238,7 @@ public: const Dialogs::Key &key2); void photoLoadSettingsChanged(); - void voiceLoadSettingsChanged(); - void animationLoadSettingsChanged(); + void documentLoadSettingsChanged(); void notifyPhotoLayoutChanged(not_null photo); void notifyDocumentLayoutChanged( diff --git a/Telegram/SourceFiles/export/view/export_view_settings.cpp b/Telegram/SourceFiles/export/view/export_view_settings.cpp index 8cff8f13d3..191791c878 100644 --- a/Telegram/SourceFiles/export/view/export_view_settings.cpp +++ b/Telegram/SourceFiles/export/view/export_view_settings.cpp @@ -31,33 +31,8 @@ namespace Export { namespace View { namespace { -constexpr auto kSizeValueCount = 80; constexpr auto kMegabyte = 1024 * 1024; -int SizeLimitByIndex(int index) { - Expects(index >= 0 && index <= kSizeValueCount); - - const auto megabytes = [&] { - if (index <= 10) { - return index; - } else if (index <= 30) { - return 10 + (index - 10) * 2; - } else if (index <= 40) { - return 50 + (index - 30) * 5; - } else if (index <= 60) { - return 100 + (index - 40) * 10; - } else if (index <= 70) { - return 300 + (index - 60) * 20; - } else { - return 500 + (index - 70) * 100; - } - }; - if (!index) { - return kMegabyte / 2; - } - return megabytes() * kMegabyte; -} - PeerId ReadPeerId(const MTPInputPeer &data) { return data.match([](const MTPDinputPeerUser &data) { return peerFromUser(data.vuser_id.v); @@ -74,6 +49,33 @@ PeerId ReadPeerId(const MTPInputPeer &data) { } // namespace +int SizeLimitByIndex(int index) { + Expects(index >= 0 && index < kSizeValueCount); + + index += 1; + const auto megabytes = [&] { + if (index <= 10) { + return index; + } + else if (index <= 30) { + return 10 + (index - 10) * 2; + } + else if (index <= 40) { + return 50 + (index - 30) * 5; + } + else if (index <= 60) { + return 100 + (index - 40) * 10; + } + else if (index <= 70) { + return 300 + (index - 60) * 20; + } + else { + return 500 + (index - 70) * 100; + } + }(); + return megabytes * kMegabyte; +} + SettingsWidget::SettingsWidget(QWidget *parent, Settings data) : RpWidget(parent) , _singlePeerId(ReadPeerId(data.singlePeer)) @@ -583,7 +585,7 @@ void SettingsWidget::addSizeSlider( st::exportFileSizePadding); slider->resize(st::exportFileSizeSlider.seekSize); slider->setPseudoDiscrete( - kSizeValueCount + 1, + kSizeValueCount, SizeLimitByIndex, readData().media.sizeLimit, [=](int limit) { @@ -599,10 +601,7 @@ void SettingsWidget::addSizeSlider( return data.media.sizeLimit; }) | rpl::start_with_next([=](int sizeLimit) { const auto limit = sizeLimit / kMegabyte; - const auto size = ((limit > 0) - ? QString::number(limit) - : QString::number(float64(sizeLimit) / kMegabyte)) - + " MB"; + const auto size = QString::number(limit) + " MB"; const auto text = lng_export_option_size_limit(lt_size, size); label->setText(text); }, slider->lifetime()); diff --git a/Telegram/SourceFiles/export/view/export_view_settings.h b/Telegram/SourceFiles/export/view/export_view_settings.h index da68694a6e..66325ce40f 100644 --- a/Telegram/SourceFiles/export/view/export_view_settings.h +++ b/Telegram/SourceFiles/export/view/export_view_settings.h @@ -21,6 +21,9 @@ class ScrollArea; namespace Export { namespace View { +constexpr auto kSizeValueCount = 80; +int SizeLimitByIndex(int index); + class SettingsWidget : public Ui::RpWidget { public: SettingsWidget(QWidget *parent, Settings data); diff --git a/Telegram/SourceFiles/info/profile/info_profile_button.cpp b/Telegram/SourceFiles/info/profile/info_profile_button.cpp index 1a924d3233..184f0e665f 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_button.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_button.cpp @@ -51,6 +51,17 @@ Button *Button::toggleOn(rpl::producer &&toggled) { return this; } +bool Button::toggled() const { + return _toggle ? _toggle->checked() : false; +} + +rpl::producer Button::toggledChanges() const { + if (_toggle) { + return _toggle->checkedChanges(); + } + return rpl::never(); +} + rpl::producer Button::toggledValue() const { if (_toggle) { return _toggle->checkedValue(); @@ -58,10 +69,6 @@ rpl::producer Button::toggledValue() const { return rpl::never(); } -bool Button::toggled() const { - return _toggle ? _toggle->checked() : false; -} - void Button::setColorOverride(std::optional textColorOverride) { _textColorOverride = textColorOverride; update(); diff --git a/Telegram/SourceFiles/info/profile/info_profile_button.h b/Telegram/SourceFiles/info/profile/info_profile_button.h index ee7239a67c..9ea4983e12 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_button.h +++ b/Telegram/SourceFiles/info/profile/info_profile_button.h @@ -27,8 +27,9 @@ public: const style::InfoProfileButton &st); Button *toggleOn(rpl::producer &&toggled); - rpl::producer toggledValue() const; bool toggled() const; + rpl::producer toggledChanges() const; + rpl::producer toggledValue() const; void setColorOverride(std::optional textColorOverride); diff --git a/Telegram/SourceFiles/settings/settings.style b/Telegram/SourceFiles/settings/settings.style index 1e7948c88d..4f760c3f27 100644 --- a/Telegram/SourceFiles/settings/settings.style +++ b/Telegram/SourceFiles/settings/settings.style @@ -187,3 +187,7 @@ settingsThemeBubblePosition: point(6px, 8px); settingsThemeBubbleSkip: 4px; settingsThemeRadioBottom: 8px; settingsThemeMinSkip: 4px; + +autoDownloadLimitButton: InfoProfileButton(settingsButton) { + padding: margins(22px, 10px, 22px, 0px); +} diff --git a/Telegram/SourceFiles/settings/settings_advanced.cpp b/Telegram/SourceFiles/settings/settings_advanced.cpp index 6040e5eba7..41d176c97e 100644 --- a/Telegram/SourceFiles/settings/settings_advanced.cpp +++ b/Telegram/SourceFiles/settings/settings_advanced.cpp @@ -472,6 +472,7 @@ void Advanced::setupContent() { AddSkip(content); } SetupDataStorage(content); + SetupAutoDownload(content); if (HasTray()) { addDivider(); AddSkip(content); diff --git a/Telegram/SourceFiles/settings/settings_chat.cpp b/Telegram/SourceFiles/settings/settings_chat.cpp index d2941ab9ec..899ae7071b 100644 --- a/Telegram/SourceFiles/settings/settings_chat.cpp +++ b/Telegram/SourceFiles/settings/settings_chat.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "settings/settings_common.h" #include "boxes/connection_box.h" +#include "boxes/auto_download_box.h" #include "boxes/stickers_box.h" #include "boxes/background_box.h" #include "boxes/download_path_box.h" @@ -616,20 +617,35 @@ void SetupDataStorage(not_null container) { }, ask->lifetime()); - AddButton( - container, - lng_media_auto_settings, - st::settingsButton - )->addClickHandler([] { - Ui::show(Box()); - }); - SetupLocalStorage(container); SetupExport(container); AddSkip(container, st::settingsCheckboxesSkip); } +void SetupAutoDownload(not_null container) { + AddDivider(container); + AddSkip(container); + + AddSubsectionTitle(container, lng_media_auto_settings); + + using Source = Data::AutoDownload::Source; + const auto add = [&](LangKey label, Source source) { + AddButton( + container, + label, + st::settingsButton + )->addClickHandler([=] { + Ui::show(Box(source)); + }); + }; + add(lng_media_auto_in_private, Source::User); + add(lng_media_auto_in_groups, Source::Group); + add(lng_media_auto_in_channels, Source::Channel); + + AddSkip(container, st::settingsCheckboxesSkip); +} + void SetupChatBackground(not_null container) { AddDivider(container); AddSkip(container); diff --git a/Telegram/SourceFiles/settings/settings_chat.h b/Telegram/SourceFiles/settings/settings_chat.h index f2d1d16b6c..f9f2f98186 100644 --- a/Telegram/SourceFiles/settings/settings_chat.h +++ b/Telegram/SourceFiles/settings/settings_chat.h @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Settings { void SetupDataStorage(not_null container); +void SetupAutoDownload(not_null container); void SetupDefaultThemes(not_null container); void SetupSupport(not_null container); diff --git a/Telegram/SourceFiles/settings/settings_privacy_security.cpp b/Telegram/SourceFiles/settings/settings_privacy_security.cpp index 7df986a73e..f65d1c8182 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_security.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_security.cpp @@ -12,7 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/peer_list_box.h" #include "boxes/edit_privacy_box.h" #include "boxes/passcode_box.h" -#include "boxes/autolock_box.h" +#include "boxes/auto_lock_box.h" #include "boxes/sessions_box.h" #include "boxes/confirm_box.h" #include "boxes/self_destruction_box.h" diff --git a/Telegram/SourceFiles/ui/widgets/checkbox.h b/Telegram/SourceFiles/ui/widgets/checkbox.h index a41ca38147..0f2bf00c91 100644 --- a/Telegram/SourceFiles/ui/widgets/checkbox.h +++ b/Telegram/SourceFiles/ui/widgets/checkbox.h @@ -27,6 +27,9 @@ public: float64 currentAnimationValue(TimeMs ms); bool animating() const; + auto checkedChanges() const { + return _checks.events(); + } auto checkedValue() const { return _checks.events_starting_with(checked()); } diff --git a/Telegram/gyp/telegram_sources.txt b/Telegram/gyp/telegram_sources.txt index be4c7d0e81..621bc0b8b3 100644 --- a/Telegram/gyp/telegram_sources.txt +++ b/Telegram/gyp/telegram_sources.txt @@ -8,8 +8,10 @@ <(src_loc)/boxes/abstract_box.h <(src_loc)/boxes/add_contact_box.cpp <(src_loc)/boxes/add_contact_box.h -<(src_loc)/boxes/autolock_box.cpp -<(src_loc)/boxes/autolock_box.h +<(src_loc)/boxes/auto_lock_box.cpp +<(src_loc)/boxes/auto_lock_box.h +<(src_loc)/boxes/auto_download_box.cpp +<(src_loc)/boxes/auto_download_box.h <(src_loc)/boxes/background_box.cpp <(src_loc)/boxes/background_box.h <(src_loc)/boxes/calendar_box.cpp