2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-30 06:07:45 +00:00

[Option][GUI] Folder options

This commit is contained in:
RadRussianRus 2022-09-05 15:31:25 +03:00 committed by Eric Kotato
parent 729f452393
commit 62f73f51f7
11 changed files with 112 additions and 18 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@ -62,8 +62,13 @@
"other": "Recent stickers: show {count} stickers"
},
"ktg_settings_recent_stickers_limit_none": "Recent stickers: hide all",
"ktg_filters_context_edit_all": "Edit folders",
"ktg_settings_filters": "Folders",
"ktg_settings_filters_only_unmuted_counter": "Do not count muted chats",
"ktg_settings_filters_hide_edit": "Hide Edit button",
"ktg_settings_filters_hide_folder_names": "Compact folders",
"ktg_settings_messages": "Messages",
"ktg_settings_filters_hide_all": "Hide \"All chats\" folder",
"ktg_settings_tray_icon": "Tray icon",
"ktg_settings_tray_icon_default": "Default",
"ktg_settings_tray_icon_blue": "Blue",
@ -86,6 +91,10 @@
"ktg_supergroup_id_copied": "Supergroup ID copied to clipboard.",
"ktg_channel_id_copied": "Channel ID copied to clipboard.",
"ktg_settings_forward": "Forward",
"ktg_filters_hide_folder": "Hide folder",
"ktg_filters_hide_button": "Hide button",
"ktg_filters_hide_all_chats_toast": "\"All Chats\" folder is hidden.\nYou can enable it back in Kotatogram Settings.",
"ktg_filters_hide_edit_toast": "Edit button is hidden.\nYou can enable it back in Kotatogram Settings.",
"ktg_in_app_update_disabled": "In-app updater is disabled.",
"dummy_last_string": ""
}

View File

@ -306,6 +306,18 @@ const std::map<QString, Definition, std::greater<QString>> DefinitionMap {
.type = SettingType::IntSetting,
.defaultValue = 0,
.limitHandler = IntLimit(0, 5), }},
{ "folders/count_unmuted_only", {
.type = SettingType::BoolSetting,
.defaultValue = false, }},
{ "folders/hide_edit_button", {
.type = SettingType::BoolSetting,
.defaultValue = false, }},
{ "folders/hide_names", {
.type = SettingType::BoolSetting,
.defaultValue = false, }},
{ "folders/hide_all_chats", {
.type = SettingType::BoolSetting,
.defaultValue = false, }},
};
using OldOptionKey = QString;

View File

@ -107,6 +107,21 @@ QString ChatIdLabel(int option) {
::Kotato::JsonSettings::Write(); \
}, container->lifetime());
#define SettingsMenuJsonFilterSwitch(LangKey, Option) container->add(object_ptr<Button>( \
container, \
rktr(#LangKey), \
st::settingsButtonNoIcon \
))->toggleOn( \
rpl::single(::Kotato::JsonSettings::GetBool(#Option)) \
)->toggledValue( \
) | rpl::filter([](bool enabled) { \
return (enabled != ::Kotato::JsonSettings::GetBool(#Option)); \
}) | rpl::start_with_next([controller](bool enabled) { \
::Kotato::JsonSettings::Set(#Option, enabled); \
::Kotato::JsonSettings::Write(); \
controller->reloadFiltersMenu(); \
}, container->lifetime());
void SetupKotatoChats(
not_null<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> container) {
@ -281,6 +296,10 @@ void SetupKotatoFolders(
Ui::AddSkip(container);
Ui::AddSubsectionTitle(container, rktr("ktg_settings_filters"));
SettingsMenuJsonFilterSwitch(ktg_settings_filters_only_unmuted_counter, folders/count_unmuted_only);
SettingsMenuJsonFilterSwitch(ktg_settings_filters_hide_all, folders/hide_all_chats);
SettingsMenuJsonFilterSwitch(ktg_settings_filters_hide_edit, folders/hide_edit_button);
SettingsMenuJsonFilterSwitch(ktg_settings_filters_hide_folder_names, folders/hide_names);
Ui::AddSkip(container);
}

View File

@ -79,6 +79,7 @@ menuIconFake: icon {{ "menu/fake", menuIconColor }};
menuIconPersonal: icon {{ "menu/personal", menuIconColor }};
menuIconPorn: icon {{ "menu/porn", menuIconColor }};
menuIconViolence: icon {{ "menu/violence", menuIconColor }};
menuIconHide: icon {{ "menu/hide", menuIconColor }};
menuIconMuteFor: icon {{ "menu/mute_for", menuIconColor }};
menuIconSilent: icon {{ "menu/silent", menuIconColor }};
menuIconCustomize: icon {{ "menu/customize", menuIconColor }};

View File

@ -240,10 +240,11 @@ createThemeLink: InputField(defaultInputField) {
}
windowFiltersWidth: 72px;
windowFiltersWidthNoText: 50px;
windowFiltersButton: SideBarButton(defaultSideBarButton) {
textTop: 40px;
textSkip: 6px;
minHeight: 62px;
minHeight: 48px;
minTextWidth: 48px;
style: TextStyle(defaultTextStyle) {
font: font(11px semibold);

View File

@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "window/window_filters_menu.h"
#include "kotato/kotato_settings.h"
#include "kotato/kotato_lang.h"
#include "mainwindow.h"
#include "window/window_session_controller.h"
#include "window/window_controller.h"
@ -24,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/wrap/vertical_layout.h"
#include "ui/wrap/vertical_layout_reorder.h"
#include "ui/widgets/popup_menu.h"
#include "ui/toast/toast.h"
#include "ui/boxes/confirm_box.h"
#include "boxes/filters/edit_filter_box.h"
#include "boxes/premium_limits_box.h"
@ -110,7 +113,9 @@ void FiltersMenu::setup() {
_parent->heightValue(
) | rpl::start_with_next([=](int height) {
const auto width = st::windowFiltersWidth;
const auto width = (::Kotato::JsonSettings::GetBool("folders/hide_names")
? st::windowFiltersWidthNoText
: st::windowFiltersWidth);
_outer.setGeometry({ 0, 0, width, height });
_menu.resizeToWidth(width);
_menu.move(0, 0);
@ -245,11 +250,13 @@ void FiltersMenu::refresh() {
void FiltersMenu::setupList() {
_list = _container->add(object_ptr<Ui::VerticalLayout>(_container));
_setup = prepareButton(
_container,
-1,
tr::lng_filters_setup(tr::now),
Ui::FilterIcon::Edit);
if (!::Kotato::JsonSettings::GetBool("folders/hide_edit_button")) {
_setup = prepareButton(
_container,
-1,
tr::lng_filters_setup(tr::now),
Ui::FilterIcon::Edit);
}
_reorder = std::make_unique<Ui::VerticalLayoutReorder>(_list, &_scroll);
_reorder->updates(
@ -284,7 +291,9 @@ base::unique_qptr<Ui::SideBarButton> FiltersMenu::prepareButton(
bool toBeginning) {
auto prepared = object_ptr<Ui::SideBarButton>(
container,
id ? title : tr::lng_filters_all(tr::now),
(::Kotato::JsonSettings::GetBool("folders/hide_names")
? QString()
: id ? title : tr::lng_filters_all(tr::now)),
st::windowFiltersButton);
auto added = toBeginning
? container->insert(0, std::move(prepared))
@ -302,12 +311,22 @@ base::unique_qptr<Ui::SideBarButton> FiltersMenu::prepareButton(
) | rpl::start_with_next([=](const Dialogs::UnreadState &state) {
const auto count = (state.chats + state.marks);
const auto muted = (state.chatsMuted + state.marksMuted);
const auto string = !count
? QString()
: (count > 99)
? "99+"
: QString::number(count);
raw->setBadge(string, count == muted);
if (::Kotato::JsonSettings::GetBool("folders/count_unmuted_only")) {
const auto unmuted = count - muted;
const auto string = !unmuted
? QString()
: (unmuted > 99)
? "99+"
: QString::number(unmuted);
raw->setBadge(string, false);
} else {
const auto string = !count
? QString()
: (count > 99)
? "99+"
: QString::number(count);
raw->setBadge(string, count == muted);
}
}, raw->lifetime());
}
raw->setActive(_session->activeChatsFilterCurrent() == id);
@ -325,11 +344,11 @@ base::unique_qptr<Ui::SideBarButton> FiltersMenu::prepareButton(
openFiltersSettings();
}
});
if (id >= 0) {
if (id >= -1) {
raw->setAcceptDrops(true);
raw->events(
) | rpl::filter([=](not_null<QEvent*> e) {
return ((e->type() == QEvent::ContextMenu) && (id >= 0))
return ((e->type() == QEvent::ContextMenu) && (id >= -1))
|| e->type() == QEvent::DragEnter
|| e->type() == QEvent::DragMove
|| e->type() == QEvent::DragLeave;
@ -338,7 +357,11 @@ base::unique_qptr<Ui::SideBarButton> FiltersMenu::prepareButton(
return;
}
if (e->type() == QEvent::ContextMenu) {
showMenu(QCursor::pos(), id);
if (id == -1) {
showEditMenu(QCursor::pos());
} else if (id > 0) {
showMenu(QCursor::pos(), id);
}
} else if (e->type() == QEvent::DragEnter) {
using namespace Storage;
const auto d = static_cast<QDragEnterEvent*>(e.get());
@ -437,6 +460,30 @@ void FiltersMenu::showMenu(QPoint position, FilterId id) {
_popupMenu->popup(position);
}
void FiltersMenu::showEditMenu(QPoint position) {
if (_popupMenu) {
_popupMenu = nullptr;
return;
}
_popupMenu = base::make_unique_q<Ui::PopupMenu>(
_setup,
st::popupMenuWithIcons);
_popupMenu->addAction(
ktr("ktg_filters_hide_button"),
crl::guard(&_outer, [=] {
::Kotato::JsonSettings::Set("folders/hide_edit_button", true);
::Kotato::JsonSettings::Write();
_setup = nullptr;
Ui::Toast::Show(Ui::Toast::Config{
.text = { ktr("ktg_filters_hide_edit_toast") },
.st = &st::windowArchiveToast,
.multiline = true,
});
}), &st::menuIconHide);
_popupMenu->popup(position);
}
void FiltersMenu::showEditBox(FilterId id) {
EditExistingFilter(_session, id);
}

View File

@ -48,6 +48,7 @@ private:
bool toBeginning = false);
void setupMainMenuIcon();
void showMenu(QPoint position, FilterId id);
void showEditMenu(QPoint position);
void showEditBox(FilterId id);
void showRemoveBox(FilterId id);
void remove(FilterId id, std::vector<not_null<PeerData*>> leave = {});

View File

@ -2469,7 +2469,11 @@ not_null<MainWidget*> SessionController::content() const {
}
int SessionController::filtersWidth() const {
return _filters ? st::windowFiltersWidth : 0;
return _filters
? (::Kotato::JsonSettings::GetBool("folders/hide_names")
? st::windowFiltersWidthNoText
: st::windowFiltersWidth)
: 0;
}
rpl::producer<FilterId> SessionController::activeChatsFilter() const {