From ffc65f7da4904b28a8bbe261aefcb5ce4f7bc6f7 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 18 Mar 2020 14:07:11 +0400 Subject: [PATCH] Add folders menu to Settings. --- Telegram/Resources/icons/settings_folders.png | Bin 0 -> 360 bytes .../Resources/icons/settings_folders@2x.png | Bin 0 -> 633 bytes .../Resources/icons/settings_folders@3x.png | Bin 0 -> 1017 bytes Telegram/Resources/langs/lang.strings | 2 ++ .../boxes/filters/manage_filters_box.cpp | 5 ++++- .../info/settings/info_settings_widget.cpp | 18 ++++++++++++++---- .../info/settings/info_settings_widget.h | 4 ++++ Telegram/SourceFiles/main/main_app_config.cpp | 10 ++++++++++ Telegram/SourceFiles/main/main_app_config.h | 5 +++++ Telegram/SourceFiles/settings/settings.style | 1 + .../SourceFiles/settings/settings_common.h | 1 + .../SourceFiles/settings/settings_main.cpp | 11 +++++++++++ .../window/window_session_controller.cpp | 2 ++ 13 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 Telegram/Resources/icons/settings_folders.png create mode 100644 Telegram/Resources/icons/settings_folders@2x.png create mode 100644 Telegram/Resources/icons/settings_folders@3x.png diff --git a/Telegram/Resources/icons/settings_folders.png b/Telegram/Resources/icons/settings_folders.png new file mode 100644 index 0000000000000000000000000000000000000000..bb941b3e21cf1d7d4cb27d8090f64a614a22bace GIT binary patch literal 360 zcmV-u0hj)XP)A zuj>6D74;(kU~r=FnJ~D3rvM2d5QZU8N`W!9s-|fmNfJ<1^=&BoTAt@I5v6I$zRwEQ zvQZQT$K7tXhXaOTu&(R)9@8}U1BYSYW*Fnmp&$tOp0;gSS(Xng%QEIT&THT}j@%3( zv>duo@bN_mE&9KI@#i<%bDTc{9<2-b4}o=E^QUdwyNu`gs;X9Ni>&i~ zUnnC*HTgXaZ$b!*qDVNLw=~U9K9k?m@IG4CJ^bT90JsA`bjvlvzPkkg0000U)GWCjHQAn?Kb`eZraf*$}EWF0QZI$V%-TnQ?Q0;;Nl zrfEP3d8u?=hr{6j-EJ4+@%USA7jdd&GD#+r3GvJEcqHX=*>S#r%Xz@jXyjY&&h>gF z>2x|gg0)&LFu6PZem^{dv)POar>ZKEW%=a^VzC(MbUM@+mSvG*u^0})^Z87LD-;T@ zClN)F?DuV}rfGsGijQMSlEAVo*WcisL?QvDQpxl6vMfWp-G)pi^Efvg z4x!O#{Pmh2eS$$$rBb0Xold9lJi#EquKwJ8F%RbY6HKlq>_1b_55SJ2pdbj;F|H6; zg0BZzhYPX}Z!)aI1zCp+@+K20n|-^WJ%c@?oqz6= zESF1a|6{#gyV|-Bx^QmH@C;`3ylq&o*8|<=`yXIN&w^Ov@i??{n9bM5FIFm*BGc(K z1UfXB3A6bYyqBUVWV6{2P1D{cg>z#D%<@WR{%=Fp;exEg1zCp+vJMwy8UXkLzKS|U TR`8Kx00000NkvXXu0mjf4G%8< literal 0 HcmV?d00001 diff --git a/Telegram/Resources/icons/settings_folders@3x.png b/Telegram/Resources/icons/settings_folders@3x.png new file mode 100644 index 0000000000000000000000000000000000000000..9300c2dc6a86f1655d66360db14588a6639796e1 GIT binary patch literal 1017 zcmeAS@N?(olHy`uVBq!ia0vp^At21b1|(&&1r9PWFdy)AaSW-L^LCD{_vZkKw)uOu zh3bf|oh*NMiGp6!;%3)h>?NWlg@JSxBR$r3J0JQ_Z_ha?FuOmNYV5ae=eX~M}= zaAId?&&Vew}?kW!lWyv$>aD zSi4sDeyY*=^XIkX`q{lRjAn)`4O*$@G;`|IsR^8O=g+^+_V?GXpwp*MYfbbB30>%+ zvM6ZflwG@aU6NZKpfN+;)WFH#&u@#PxtZAlQE3SY1OG{V&CSgZIQH(|eYx$;`}ghP zdDYdoH@)WP=fA!*;Q05a_wV0d2?R;iCQ?hcZ#RFz|76`dy;EtMuiUv4^YP}{v%IqM z@`wA5imL#1l$4aXq^GBczCC?W^2d)K7q&^r{oZ5on46n>+S)7Hn{KX=l9c?o{Pb^K z6RF-+HFocJholu32e&#Y=C^**S**I69MPu{s-O@G-Yfe_y)xFz&#_00p z%Lj!{rDkNT5YzMh!9OcPC++={>1%H-4bTX%kXiSmOhss6(#D9ZZ+-|bUcC6qrAv=a z?i220>Fw_i_V@4q_Ic$>&8YbJ?OWH!Uv&DbaffSd+qA=no%46qY>ePp6QK99Bx<() z^wX7>pYDuqcUsu>)`sW9{V_@{j$l`UiT|%Yp>=#w>-qBB+|pd zs_b;oLM%(7t<3s9lh~5hL-2&5rfP7>>0n2I0ZiEm9e%ecMDj@qVp7(HngCSQ*Ba$( z$IHw6b?O<_Fv~Z7yZTz~Y;7~Qt4}`p>hcxFFv~SX^~X0}h|ybq*Us2Dc>AO|2~!Vi zZRc}eeOXLgeCz7VKV~jkx^(F(`9G^dA66CrT|2M$(VclZ>2F@Y4xT@MzF2l`Gw1WC zcgp@)y!#|BF1}^^_UDf2tK%*7pKt4aoOkWsy*xdKzw!^}%(>nuU;bFEyz%$%-wxVO zYsz+4U3J=7QdTyLe-oSFxuZYlST*ixo*Dnh$jr=bWk}bq-Mi1GUfs_dw=<^hT5)=M wyPv;*tm=g6QOy&xE8%`e3I=p0r{G`KsLva-mU(WM17>LkPgg&ebxsLQ0Q<+&>;M1& literal 0 HcmV?d00001 diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 7984173cc..df3608e3e 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -344,6 +344,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_settings_send_ctrlenter" = "Send by Ctrl+Enter"; "lng_settings_send_cmdenter" = "Send by Cmd+Enter"; +"lng_settings_section_filters" = "Folders"; + "lng_settings_section_background" = "Chat background"; "lng_settings_bg_use_default" = "Use default color theme"; "lng_settings_bg_from_gallery" = "Choose from gallery"; diff --git a/Telegram/SourceFiles/boxes/filters/manage_filters_box.cpp b/Telegram/SourceFiles/boxes/filters/manage_filters_box.cpp index c12a997dd..debf79a40 100644 --- a/Telegram/SourceFiles/boxes/filters/manage_filters_box.cpp +++ b/Telegram/SourceFiles/boxes/filters/manage_filters_box.cpp @@ -393,6 +393,8 @@ void ManageFiltersPrepare::SetupBox( crl::guard(button, doneCallback))); }); rows->push_back({ button, filter }); + + wrap->resizeToWidth(content->width()); }; const auto &list = session->data().chatsFilters().list(); for (const auto &filter : list) { @@ -466,8 +468,9 @@ void ManageFiltersPrepare::SetupBox( const auto prepareGoodIdsForNewFilters = [=] { const auto &list = session->data().chatsFilters().list(); - auto localId = 2; + auto localId = 1; const auto chooseNextId = [&] { + ++localId; while (ranges::contains(list, localId, &Data::ChatFilter::id)) { ++localId; } diff --git a/Telegram/SourceFiles/info/settings/info_settings_widget.cpp b/Telegram/SourceFiles/info/settings/info_settings_widget.cpp index 689164a8b..76df4330f 100644 --- a/Telegram/SourceFiles/info/settings/info_settings_widget.cpp +++ b/Telegram/SourceFiles/info/settings/info_settings_widget.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/info_memento.h" #include "info/info_controller.h" #include "settings/settings_common.h" +#include "boxes/filters/manage_filters_box.h" #include "ui/ui_utility.h" namespace Info { @@ -44,17 +45,26 @@ Widget::Widget( , _self(controller->key().settingsSelf()) , _type(controller->section().settingsType()) , _inner(setInnerWidget(::Settings::CreateSection( - _type, - this, - controller->parentController()))) { + _type, + this, + controller->parentController()))) +, _manageFilters( + std::make_unique( + controller->parentController())) { _inner->sectionShowOther( ) | rpl::start_with_next([=](Type type) { - controller->showSettings(type); + if (type == Type::Folders) { + _manageFilters->showBox(); + } else { + controller->showSettings(type); + } }, _inner->lifetime()); controller->setCanSaveChanges(_inner->sectionCanSaveChanges()); } +Widget::~Widget() = default; + not_null Widget::self() const { return _self; } diff --git a/Telegram/SourceFiles/info/settings/info_settings_widget.h b/Telegram/SourceFiles/info/settings/info_settings_widget.h index f4c241350..30c636d26 100644 --- a/Telegram/SourceFiles/info/settings/info_settings_widget.h +++ b/Telegram/SourceFiles/info/settings/info_settings_widget.h @@ -10,6 +10,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/info_content_widget.h" #include "info/info_controller.h" +class ManageFiltersPrepare; + namespace Settings { class Section; } // namespace Settings @@ -52,6 +54,7 @@ public: Widget( QWidget *parent, not_null controller); + ~Widget(); not_null self() const; @@ -77,6 +80,7 @@ private: Type _type = Type(); not_null<::Settings::Section*> _inner; + std::unique_ptr _manageFilters; }; diff --git a/Telegram/SourceFiles/main/main_app_config.cpp b/Telegram/SourceFiles/main/main_app_config.cpp index 08254a15a..8518dec00 100644 --- a/Telegram/SourceFiles/main/main_app_config.cpp +++ b/Telegram/SourceFiles/main/main_app_config.cpp @@ -74,6 +74,16 @@ auto AppConfig::getValue(const QString &key, Extractor &&extractor) const { : MTPJSONValue(MTP_jsonNull())); } +bool AppConfig::getBool(const QString &key, bool fallback) const { + return getValue(key, [&](const MTPJSONValue &value) { + return value.match([&](const MTPDjsonBool &data) { + return mtpIsTrue(data.vvalue()); + }, [&](const auto &data) { + return fallback; + }); + }); +} + double AppConfig::getDouble(const QString &key, double fallback) const { return getValue(key, [&](const MTPJSONValue &value) { return value.match([&](const MTPDjsonNumber &data) { diff --git a/Telegram/SourceFiles/main/main_app_config.h b/Telegram/SourceFiles/main/main_app_config.h index 54afb170e..0ab3625a3 100644 --- a/Telegram/SourceFiles/main/main_app_config.h +++ b/Telegram/SourceFiles/main/main_app_config.h @@ -25,6 +25,8 @@ public: return getString(key, fallback); } else if constexpr (std::is_same_v>) { return getStringArray(key, std::move(fallback)); + } else if constexpr (std::is_same_v) { + return getBool(key, fallback); } } @@ -40,6 +42,9 @@ private: const QString &key, Extractor &&extractor) const; + [[nodiscard]] bool getBool( + const QString &key, + bool fallback) const; [[nodiscard]] double getDouble( const QString &key, double fallback) const; diff --git a/Telegram/SourceFiles/settings/settings.style b/Telegram/SourceFiles/settings/settings.style index 0500f2808..fb45aaaf5 100644 --- a/Telegram/SourceFiles/settings/settings.style +++ b/Telegram/SourceFiles/settings/settings.style @@ -52,6 +52,7 @@ settingsDividerLabelPadding: margins(22px, 10px, 22px, 19px); settingsIconInformation: icon {{ "settings_information", menuIconFg }}; settingsIconNotifications: icon {{ "settings_notifications", menuIconFg }}; settingsIconChat: icon {{ "settings_chat", menuIconFg }}; +settingsIconFolders: icon {{ "settings_folders", menuIconFg }}; settingsIconGeneral: icon {{ "settings_advanced", menuIconFg }}; settingsIconPrivacySecurity: icon {{ "settings_privacy_security", menuIconFg }}; settingsIconLanguage: icon {{ "settings_language", menuIconFg }}; diff --git a/Telegram/SourceFiles/settings/settings_common.h b/Telegram/SourceFiles/settings/settings_common.h index ac9f8d88e..c2609c06c 100644 --- a/Telegram/SourceFiles/settings/settings_common.h +++ b/Telegram/SourceFiles/settings/settings_common.h @@ -37,6 +37,7 @@ enum class Type { PrivacySecurity, Advanced, Chat, + Folders, Calls, }; diff --git a/Telegram/SourceFiles/settings/settings_main.cpp b/Telegram/SourceFiles/settings/settings_main.cpp index 05a4d384d..f2d848806 100644 --- a/Telegram/SourceFiles/settings/settings_main.cpp +++ b/Telegram/SourceFiles/settings/settings_main.cpp @@ -21,9 +21,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_user.h" #include "data/data_session.h" #include "data/data_cloud_themes.h" +#include "data/data_chat_filters.h" #include "lang/lang_keys.h" #include "storage/localstorage.h" #include "main/main_session.h" +#include "main/main_account.h" +#include "main/main_app_config.h" #include "apiwrap.h" #include "window/window_session_controller.h" #include "core/file_utilities.h" @@ -101,6 +104,14 @@ void SetupSections( tr::lng_settings_section_chat_settings(), Type::Chat, &st::settingsIconChat); + const auto &appConfig = controller->session().account().appConfig(); + if (!controller->session().data().chatsFilters().list().empty() + || appConfig.get("dialog_filters_enabled", false)) { + addSection( + tr::lng_settings_section_filters(), + Type::Folders, + &st::settingsIconFolders); + } addSection( tr::lng_settings_advanced(), Type::Advanced, diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index 8d8d8e8f1..135bb95de 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -91,6 +91,8 @@ void SessionNavigation::showPeerInfo( void SessionNavigation::showSettings( Settings::Type type, const SectionShow ¶ms) { + Expects(type != Settings::Type::Folders); + showSection( Info::Memento( Info::Settings::Tag{ _session->user() },