From 2daaf3f40286ae68ebd75ff4ca29487e894175a8 Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Mon, 20 Sep 2021 15:36:21 +0300 Subject: [PATCH] Options to remember forward mode and set default --- Telegram/Resources/langs/rewrites/en.json | 10 ++ Telegram/Resources/langs/rewrites/ru.json | 10 ++ Telegram/SourceFiles/boxes/share_box.cpp | 29 +++-- .../SourceFiles/history/history_widget.cpp | 27 +++-- Telegram/SourceFiles/kotato/json_settings.cpp | 16 +++ Telegram/SourceFiles/kotato/settings.cpp | 30 ++++++ Telegram/SourceFiles/kotato/settings.h | 10 ++ Telegram/SourceFiles/kotato/settings_menu.cpp | 102 ++++++++++++++++++ .../SourceFiles/window/window_peer_menu.cpp | 23 +++- 9 files changed, 237 insertions(+), 20 deletions(-) diff --git a/Telegram/Resources/langs/rewrites/en.json b/Telegram/Resources/langs/rewrites/en.json index 95916a2fd..1d869f35d 100644 --- a/Telegram/Resources/langs/rewrites/en.json +++ b/Telegram/Resources/langs/rewrites/en.json @@ -243,5 +243,15 @@ "other": "days" }, "ktg_forward_sender_names_and_captions_removed": "Sender names and captions removed", + "ktg_forward_remember_mode": "Remember forward mode", + "ktg_forward_mode": "Forward mode", + "ktg_forward_mode_quoted": "Quoted", + "ktg_forward_mode_unquoted": "Unquoted", + "ktg_forward_mode_uncaptioned": "Uncaptioned", + "ktg_forward_grouping_mode": "Grouping mode", + "ktg_forward_grouping_mode_preserve_albums": "Same as original", + "ktg_forward_grouping_mode_regroup": "Regroup media", + "ktg_forward_grouping_mode_regroup_desc": "Unquoted and uncaptioned only", + "ktg_forward_grouping_mode_separate": "Separate", "dummy_last_string": "" } diff --git a/Telegram/Resources/langs/rewrites/ru.json b/Telegram/Resources/langs/rewrites/ru.json index f42cd1b40..018f72dcb 100644 --- a/Telegram/Resources/langs/rewrites/ru.json +++ b/Telegram/Resources/langs/rewrites/ru.json @@ -261,5 +261,15 @@ "other": "дня" }, "ktg_forward_sender_names_and_captions_removed": "Имена отправителей и подписи скрыты", + "ktg_forward_remember_mode": "Запоминать режим пересылки", + "ktg_forward_mode": "Режим пересылки", + "ktg_forward_mode_quoted": "С автором", + "ktg_forward_mode_unquoted": "Без автора", + "ktg_forward_mode_uncaptioned": "Без подписей", + "ktg_forward_grouping_mode": "Режим группировки", + "ktg_forward_grouping_mode_preserve_albums": "Как в оригинале", + "ktg_forward_grouping_mode_regroup": "Объединить медиа", + "ktg_forward_grouping_mode_regroup_desc": "Только без автора и без подписей", + "ktg_forward_grouping_mode_separate": "По отдельности", "dummy_last_string": "" } diff --git a/Telegram/SourceFiles/boxes/share_box.cpp b/Telegram/SourceFiles/boxes/share_box.cpp index 704e05cf1..207167ed2 100644 --- a/Telegram/SourceFiles/boxes/share_box.cpp +++ b/Telegram/SourceFiles/boxes/share_box.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "dialogs/dialogs_indexed_list.h" #include "kotato/kotato_lang.h" +#include "kotato/json_settings.h" #include "lang/lang_keys.h" #include "mainwindow.h" #include "mainwidget.h" @@ -527,34 +528,42 @@ bool ShareBox::showMenu(not_null button) { }); button->installEventFilter(_menu); - const auto addForwardOption = [this] (Data::ForwardOptions option, const QString &langKey) { + const auto addForwardOption = [this] (Data::ForwardOptions option, const QString &langKey, int settingsKey) { if (_descriptor.draft->options != option) { - _menu->addAction(ktr(langKey), [this, option] { + _menu->addAction(ktr(langKey), [this, option, settingsKey] { _descriptor.draft->options = option; updateAdditionalTitle(); + if (cForwardRememberMode()) { + SetForwardMode(settingsKey); + Kotato::JsonSettings::Write(); + } }); } }; - addForwardOption(Data::ForwardOptions::PreserveInfo, "ktg_forward_menu_quoted"); - addForwardOption(Data::ForwardOptions::NoSenderNames, "ktg_forward_menu_unquoted"); - addForwardOption(Data::ForwardOptions::NoNamesAndCaptions, "ktg_forward_menu_uncaptioned"); + addForwardOption(Data::ForwardOptions::PreserveInfo, "ktg_forward_menu_quoted", 0); + addForwardOption(Data::ForwardOptions::NoSenderNames, "ktg_forward_menu_unquoted", 1); + addForwardOption(Data::ForwardOptions::NoNamesAndCaptions, "ktg_forward_menu_uncaptioned", 2); if (_descriptor.hasMedia) { _menu->addSeparator(); - const auto addGroupingOption = [this] (Data::GroupingOptions option, const QString &langKey) { + const auto addGroupingOption = [this] (Data::GroupingOptions option, const QString &langKey, int settingsKey) { if (_descriptor.draft->groupOptions != option) { - _menu->addAction(ktr(langKey), [this, option] { + _menu->addAction(ktr(langKey), [this, option, settingsKey] { _descriptor.draft->groupOptions = option; updateAdditionalTitle(); + if (cForwardRememberMode()) { + SetForwardGroupingMode(settingsKey); + Kotato::JsonSettings::Write(); + } }); } }; - addGroupingOption(Data::GroupingOptions::GroupAsIs, "ktg_forward_menu_default_albums"); - addGroupingOption(Data::GroupingOptions::RegroupAll, "ktg_forward_menu_group_all_media"); - addGroupingOption(Data::GroupingOptions::Separate, "ktg_forward_menu_separate_messages"); + addGroupingOption(Data::GroupingOptions::GroupAsIs, "ktg_forward_menu_default_albums", 0); + addGroupingOption(Data::GroupingOptions::RegroupAll, "ktg_forward_menu_group_all_media", 1); + addGroupingOption(Data::GroupingOptions::Separate, "ktg_forward_menu_separate_messages", 2); } const auto parentTopLeft = window()->mapToGlobal({ 0, 0 }); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 3afe0e8cb..4324c7edc 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_widget.h" #include "kotato/kotato_lang.h" +#include "kotato/json_settings.h" #include "api/api_editing.h" #include "api/api_bot.h" #include "api/api_sending.h" @@ -5718,7 +5719,8 @@ void HistoryWidget::contextMenuEvent(QContextMenuEvent *e) { }(); const auto addForwardOption = [=]( Options newOptions, - const QString &langKey) { + const QString &langKey, + int settingsKey) { if (_history && _toForward.options != newOptions) { _menu->addAction(ktr(langKey), [=] { _toForward.options = newOptions; @@ -5728,22 +5730,27 @@ void HistoryWidget::contextMenuEvent(QContextMenuEvent *e) { .groupOptions = _toForward.groupOptions, }); updateField(); + if (cForwardRememberMode()) { + SetForwardMode(settingsKey); + Kotato::JsonSettings::Write(); + } }); } }; _menu = base::make_unique_q(this); - addForwardOption(Options::PreserveInfo, "ktg_forward_menu_quoted"); - addForwardOption(Options::NoSenderNames, "ktg_forward_menu_unquoted"); + addForwardOption(Options::PreserveInfo, "ktg_forward_menu_quoted", 0); + addForwardOption(Options::NoSenderNames, "ktg_forward_menu_unquoted", 1); if (hasCaptions) { - addForwardOption(Options::NoNamesAndCaptions, "ktg_forward_menu_uncaptioned"); + addForwardOption(Options::NoNamesAndCaptions, "ktg_forward_menu_uncaptioned", 2); } if (hasMediaToGroup && count > 1) { const auto addGroupingOption = [=]( GroupingOptions newOptions, - const QString &langKey) { + const QString &langKey, + int settingsKey) { if (_history && _toForward.groupOptions != newOptions) { _menu->addAction(ktr(langKey), [=] { _toForward.groupOptions = newOptions; @@ -5754,14 +5761,18 @@ void HistoryWidget::contextMenuEvent(QContextMenuEvent *e) { }); updateForwardingTexts(); updateField(); + if (cForwardRememberMode()) { + SetForwardGroupingMode(settingsKey); + Kotato::JsonSettings::Write(); + } }); } }; _menu->addSeparator(); - addGroupingOption(GroupingOptions::GroupAsIs, "ktg_forward_menu_default_albums"); - addGroupingOption(GroupingOptions::RegroupAll, "ktg_forward_menu_group_all_media"); - addGroupingOption(GroupingOptions::Separate, "ktg_forward_menu_separate_messages"); + addGroupingOption(GroupingOptions::GroupAsIs, "ktg_forward_menu_default_albums", 0); + addGroupingOption(GroupingOptions::RegroupAll, "ktg_forward_menu_group_all_media", 1); + addGroupingOption(GroupingOptions::Separate, "ktg_forward_menu_separate_messages", 2); } _menu->popup(QCursor::pos()); diff --git a/Telegram/SourceFiles/kotato/json_settings.cpp b/Telegram/SourceFiles/kotato/json_settings.cpp index 300721b38..479ae83e8 100644 --- a/Telegram/SourceFiles/kotato/json_settings.cpp +++ b/Telegram/SourceFiles/kotato/json_settings.cpp @@ -391,6 +391,9 @@ QByteArray GenerateSettingsJson(bool areDefault = false) { settings.insert(qsl("forward_retain_selection"), cForwardRetainSelection()); settings.insert(qsl("forward_on_click"), cForwardChatOnClick()); settings.insert(qsl("telegram_sites_autologin"), cTelegramSitesAutologin()); + settings.insert(qsl("forward_remember_mode"), cForwardRememberMode()); + settings.insert(qsl("forward_mode"), ForwardMode()); + settings.insert(qsl("forward_grouping_mode"), ForwardGroupingMode()); settingsFonts.insert(qsl("size"), cFontSize()); settingsFonts.insert(qsl("use_system_font"), cUseSystemFont()); @@ -972,6 +975,19 @@ bool Manager::readCustomFile() { ReadBoolOption(settings, "telegram_sites_autologin", [&](auto v) { cSetTelegramSitesAutologin(v); }); + ReadBoolOption(settings, "forward_remember_mode", [&](auto v) { + cSetForwardRememberMode(v); + }); + ReadIntOption(settings, "forward_mode", [&](auto v) { + if (v >= 0 && v <= 2) { + SetForwardMode(v); + } + }); + ReadIntOption(settings, "forward_grouping_mode", [&](auto v) { + if (v >= 0 && v <= 2) { + SetForwardGroupingMode(v); + } + }); return true; } diff --git a/Telegram/SourceFiles/kotato/settings.cpp b/Telegram/SourceFiles/kotato/settings.cpp index 524f7ca60..5bb2895a7 100644 --- a/Telegram/SourceFiles/kotato/settings.cpp +++ b/Telegram/SourceFiles/kotato/settings.cpp @@ -262,3 +262,33 @@ bool gAutoScrollUnfocused = false; LocalFolderVector gLocalFolders; bool gTelegramSitesAutologin = true; + +bool gForwardRememberMode = true; + +// 0 - quoted +// 1 - unquoted +// 2 - uncaptioned +rpl::variable gForwardMode = 0; +void SetForwardMode(int mode) { + gForwardMode = mode; +} +int ForwardMode() { + return gForwardMode.current(); +} +rpl::producer ForwardModeChanges() { + return gForwardMode.changes(); +} + +// 0 - preserve albums +// 1 - group all media +// 2 - separate messages +rpl::variable gForwardGroupingMode = 0; +void SetForwardGroupingMode(int mode) { + gForwardGroupingMode = mode; +} +int ForwardGroupingMode() { + return gForwardGroupingMode.current(); +} +rpl::producer ForwardGroupingModeChanges() { + return gForwardGroupingMode.changes(); +} diff --git a/Telegram/SourceFiles/kotato/settings.h b/Telegram/SourceFiles/kotato/settings.h index a3eca2017..bff6feb71 100644 --- a/Telegram/SourceFiles/kotato/settings.h +++ b/Telegram/SourceFiles/kotato/settings.h @@ -174,3 +174,13 @@ using LocalFolderVector = std::vector; DeclareRefSetting(LocalFolderVector, LocalFolders); DeclareSetting(bool, TelegramSitesAutologin); + +DeclareSetting(bool, ForwardRememberMode); + +void SetForwardMode(int mode); +[[nodiscard]] int ForwardMode(); +[[nodiscard]] rpl::producer ForwardModeChanges(); + +void SetForwardGroupingMode(int mode); +[[nodiscard]] int ForwardGroupingMode(); +[[nodiscard]] rpl::producer ForwardGroupingModeChanges(); diff --git a/Telegram/SourceFiles/kotato/settings_menu.cpp b/Telegram/SourceFiles/kotato/settings_menu.cpp index 21cf96920..753a66960 100644 --- a/Telegram/SourceFiles/kotato/settings_menu.cpp +++ b/Telegram/SourceFiles/kotato/settings_menu.cpp @@ -56,6 +56,55 @@ QString FileDialogTypeDescription(int value) { return Platform::FileDialog::ImplementationTypeDescription(typedValue); } +QString ForwardModeLabel(int mode) { + switch (mode) { + case 0: + return ktr("ktg_forward_mode_quoted"); + + case 1: + return ktr("ktg_forward_mode_unquoted"); + + case 2: + return ktr("ktg_forward_mode_uncaptioned"); + + default: + Unexpected("Boost in Settings::ForwardModeLabel."); + } + return QString(); +} + +QString GroupingModeLabel(int mode) { + switch (mode) { + case 0: + return ktr("ktg_forward_grouping_mode_preserve_albums"); + + case 1: + return ktr("ktg_forward_grouping_mode_regroup"); + + case 2: + return ktr("ktg_forward_grouping_mode_separate"); + + default: + Unexpected("Boost in Settings::GroupingModeLabel."); + } + return QString(); +} + +QString GroupingModeDescription(int mode) { + switch (mode) { + case 0: + case 2: + return QString(); + + case 1: + return ktr("ktg_forward_grouping_mode_regroup_desc"); + + default: + Unexpected("Boost in Settings::GroupingModeLabel."); + } + return QString(); +} + QString NetBoostLabel(int boost) { switch (boost) { case 0: @@ -388,6 +437,59 @@ void SetupKotatoForward(not_null container) { AddSkip(container); AddSubsectionTitle(container, rktr("ktg_settings_forward")); + SettingsMenuCSwitch(ktg_forward_remember_mode, ForwardRememberMode); + + auto forwardModeText = rpl::single( + ForwardMode() + ) | rpl::then( + ForwardModeChanges() + ) | rpl::map([] { + return ForwardModeLabel(ForwardMode()); + }); + + AddButtonWithLabel( + container, + rktr("ktg_forward_mode"), + forwardModeText, + st::settingsButton + )->addClickHandler([=] { + Ui::show(Box<::Kotato::RadioBox>( + ktr("ktg_forward_mode"), + ForwardMode(), + 3, + ForwardModeLabel, + [=] (int value) { + SetForwardMode(value); + ::Kotato::JsonSettings::Write(); + }, false)); + }); + + auto forwardGroupingModeText = rpl::single( + ForwardGroupingMode() + ) | rpl::then( + ForwardGroupingModeChanges() + ) | rpl::map([] { + return GroupingModeLabel(ForwardGroupingMode()); + }); + + AddButtonWithLabel( + container, + rktr("ktg_forward_grouping_mode"), + forwardGroupingModeText, + st::settingsButton + )->addClickHandler([=] { + Ui::show(Box<::Kotato::RadioBox>( + ktr("ktg_forward_grouping_mode"), + ForwardGroupingMode(), + 3, + GroupingModeLabel, + GroupingModeDescription, + [=] (int value) { + SetForwardGroupingMode(value); + ::Kotato::JsonSettings::Write(); + }, false)); + }); + SettingsMenuCSwitch(ktg_settings_forward_retain_selection, ForwardRetainSelection); SettingsMenuCSwitch(ktg_settings_forward_chat_on_click, ForwardChatOnClick); diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 7e22fe1ae..f710e7fee 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -1272,10 +1272,29 @@ QPointer ShowForwardMessagesBox( not_null navigation, MessageIdsList &&items, FnMut &&successCallback) { + const auto options = [] { + switch (ForwardMode()) { + case 1: return Data::ForwardOptions::NoSenderNames; + case 2: return Data::ForwardOptions::NoNamesAndCaptions; + default: return Data::ForwardOptions::PreserveInfo; + } + }(); + + const auto groupOptions = [] { + switch (ForwardGroupingMode()) { + case 1: return Data::GroupingOptions::RegroupAll; + case 2: return Data::GroupingOptions::Separate; + default: return Data::GroupingOptions::GroupAsIs; + } + }(); + return ShowForwardMessagesBox( navigation, - Data::ForwardDraft{ .ids = std::move(items) }, - std::move(successCallback)); + Data::ForwardDraft{ + .ids = std::move(items), + .options = options, + .groupOptions = groupOptions, + }, std::move(successCallback)); } QPointer ShowSendNowMessagesBox(