Add folders menu to Settings.

This commit is contained in:
John Preston 2020-03-18 14:07:11 +04:00
parent 4881981cf6
commit ffc65f7da4
13 changed files with 54 additions and 5 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 360 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 633 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1017 B

View File

@ -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";

View File

@ -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;
}

View File

@ -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<ManageFiltersPrepare>(
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<UserData*> Widget::self() const {
return _self;
}

View File

@ -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*> controller);
~Widget();
not_null<UserData*> self() const;
@ -77,6 +80,7 @@ private:
Type _type = Type();
not_null<::Settings::Section*> _inner;
std::unique_ptr<ManageFiltersPrepare> _manageFilters;
};

View File

@ -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) {

View File

@ -25,6 +25,8 @@ public:
return getString(key, fallback);
} else if constexpr (std::is_same_v<Type, std::vector<QString>>) {
return getStringArray(key, std::move(fallback));
} else if constexpr (std::is_same_v<Type, bool>) {
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;

View File

@ -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 }};

View File

@ -37,6 +37,7 @@ enum class Type {
PrivacySecurity,
Advanced,
Chat,
Folders,
Calls,
};

View File

@ -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<bool>("dialog_filters_enabled", false)) {
addSection(
tr::lng_settings_section_filters(),
Type::Folders,
&st::settingsIconFolders);
}
addSection(
tr::lng_settings_advanced(),
Type::Advanced,

View File

@ -91,6 +91,8 @@ void SessionNavigation::showPeerInfo(
void SessionNavigation::showSettings(
Settings::Type type,
const SectionShow &params) {
Expects(type != Settings::Type::Folders);
showSection(
Info::Memento(
Info::Settings::Tag{ _session->user() },