2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-09-05 17:15:16 +00:00
Files
kotatogram-desktop/Telegram/SourceFiles/kotato/settings_menu.cpp

580 lines
16 KiB
C++
Raw Normal View History

2019-10-10 19:57:03 +03:00
/*
This file is part of Kotatogram Desktop,
the unofficial app based on Telegram Desktop.
For license and copyright information please follow this link:
https://github.com/kotatogram/kotatogram-desktop/blob/dev/LEGAL
*/
2020-04-21 06:26:36 +03:00
#include "kotato/settings_menu.h"
2019-10-10 19:57:03 +03:00
#include "settings/settings_common.h"
#include "settings/settings_chat.h"
#include "ui/wrap/vertical_layout.h"
#include "ui/wrap/slide_wrap.h"
2019-11-06 16:22:25 +03:00
#include "ui/widgets/buttons.h"
2019-10-10 19:57:03 +03:00
#include "ui/widgets/labels.h"
#include "ui/widgets/checkbox.h"
#include "ui/widgets/continuous_sliders.h"
#include "ui/text/text_utilities.h" // Ui::Text::ToUpper
#include "boxes/connection_box.h"
#include "kotato/customboxes/fonts_box.h"
#include "kotato/customboxes/radio_box.h"
2019-10-10 19:57:03 +03:00
#include "boxes/about_box.h"
#include "boxes/confirm_box.h"
#include "platform/platform_specific.h"
#include "window/window_session_controller.h"
#include "lang/lang_keys.h"
#include "core/update_checker.h"
2020-04-21 06:20:14 +03:00
#include "kotato/json_settings.h"
2019-10-10 19:57:03 +03:00
#include "core/application.h"
#include "storage/localstorage.h"
#include "data/data_session.h"
#include "main/main_session.h"
#include "layout.h"
2020-03-30 19:36:59 +03:00
#include "mainwindow.h"
2019-10-10 19:57:03 +03:00
#include "facades.h"
#include "app.h"
#include "styles/style_settings.h"
namespace Settings {
2020-04-23 17:38:15 +03:00
namespace {
QString NetBoostLabel(int boost) {
switch (boost) {
case 0:
return tr::ktg_net_speed_boost_default(tr::now);
case 1:
return tr::ktg_net_speed_boost_slight(tr::now);
case 2:
return tr::ktg_net_speed_boost_medium(tr::now);
case 3:
return tr::ktg_net_speed_boost_big(tr::now);
default:
Unexpected("Boost in Settings::NetBoostLabel.");
}
return QString();
}
2020-04-23 19:56:49 +03:00
QString UserpicRoundingLabel(int rounding) {
switch (rounding) {
case 0:
return tr::ktg_settings_userpic_rounding_none(tr::now);
case 1:
return tr::ktg_settings_userpic_rounding_small(tr::now);
case 2:
return tr::ktg_settings_userpic_rounding_big(tr::now);
case 3:
return tr::ktg_settings_userpic_rounding_full(tr::now);
default:
Unexpected("Rounding in Settings::UserpicRoundingLabel.");
}
return QString();
}
QString TrayIconLabel(int icon) {
switch (icon) {
case 0:
return tr::ktg_settings_tray_icon_default(tr::now);
case 1:
return tr::ktg_settings_tray_icon_blue(tr::now);
case 2:
return tr::ktg_settings_tray_icon_green(tr::now);
case 3:
return tr::ktg_settings_tray_icon_orange(tr::now);
case 4:
return tr::ktg_settings_tray_icon_red(tr::now);
case 5:
return tr::ktg_settings_tray_icon_legacy(tr::now);
default:
Unexpected("Icon in Settings::TrayIconLabel.");
}
return QString();
}
2020-05-05 06:46:11 +03:00
QString ChatIdLabel(int option) {
switch (option) {
case 0:
return tr::ktg_settings_chat_id_disable(tr::now);
case 1:
return tr::ktg_settings_chat_id_telegram(tr::now);
case 2:
return tr::ktg_settings_chat_id_bot(tr::now);
default:
Unexpected("Option in Settings::ChatIdLabel.");
}
return QString();
}
2020-04-23 17:38:15 +03:00
} // namespace
2020-04-24 20:38:11 +03:00
#define SettingsMenuCSwitch(LangKey, Option) AddButton( \
2020-04-23 13:00:53 +03:00
container, \
tr::LangKey(), \
st::settingsButton \
)->toggleOn( \
rpl::single(c##Option()) \
)->toggledValue( \
) | rpl::filter([](bool enabled) { \
return (enabled != c##Option()); \
}) | rpl::start_with_next([](bool enabled) { \
cSet##Option(enabled); \
::Kotato::JsonSettings::Write(); \
}, container->lifetime());
2020-04-24 20:38:11 +03:00
#define SettingsMenuCFilterSwitch(LangKey, Option) AddButton( \
2020-04-23 13:00:53 +03:00
container, \
tr::LangKey(), \
st::settingsButton \
)->toggleOn( \
rpl::single(c##Option()) \
)->toggledValue( \
) | rpl::filter([](bool enabled) { \
return (enabled != c##Option()); \
}) | rpl::start_with_next([controller](bool enabled) { \
cSet##Option(enabled); \
::Kotato::JsonSettings::Write(); \
controller->reloadFiltersMenu(); \
App::wnd()->fixOrder(); \
}, container->lifetime());
#define SettingsMenuSwitch(LangKey, Option) AddButton( \
container, \
tr::LangKey(), \
st::settingsButton \
)->toggleOn( \
rpl::single(Option()) \
)->toggledValue( \
) | rpl::filter([](bool enabled) { \
return (enabled != Option()); \
}) | rpl::start_with_next([](bool enabled) { \
Set##Option(enabled); \
::Kotato::JsonSettings::Write(); \
}, container->lifetime());
2019-10-10 19:57:03 +03:00
void SetupKotatoChats(not_null<Ui::VerticalLayout*> container) {
AddSkip(container);
AddSubsectionTitle(container, tr::ktg_settings_chats());
2020-02-23 04:53:24 +03:00
const auto recentStickersLimitLabel = container->add(
object_ptr<Ui::LabelSimple>(
container,
st::settingsAudioVolumeLabel),
st::settingsAudioVolumeLabelPadding);
const auto recentStickersLimitSlider = container->add(
object_ptr<Ui::MediaSlider>(
container,
st::settingsAudioVolumeSlider),
st::settingsAudioVolumeSliderPadding);
const auto updateRecentStickersLimitLabel = [=](int value) {
if (value == 0) {
recentStickersLimitLabel->setText(
tr::ktg_settings_recent_stickers_limit_none(tr::now));
} else {
recentStickersLimitLabel->setText(
tr::ktg_settings_recent_stickers_limit(tr::now, lt_count_decimal, value));
}
};
const auto updateRecentStickersLimitHeight = [=](int value) {
updateRecentStickersLimitLabel(value);
SetRecentStickersLimit(value);
2020-04-21 06:26:36 +03:00
::Kotato::JsonSettings::Write();
2020-02-23 04:53:24 +03:00
};
recentStickersLimitSlider->resize(st::settingsAudioVolumeSlider.seekSize);
recentStickersLimitSlider->setPseudoDiscrete(
201,
[](int val) { return val; },
RecentStickersLimit(),
updateRecentStickersLimitHeight);
updateRecentStickersLimitLabel(RecentStickersLimit());
2020-04-24 20:38:11 +03:00
SettingsMenuCSwitch(ktg_settings_top_bar_mute, ProfileTopBarNotifications);
SettingsMenuCSwitch(ktg_settings_disable_up_edit, DisableUpEdit);
2019-10-10 19:57:03 +03:00
AddButton(
container,
tr::ktg_settings_chat_list_compact(),
st::settingsButton
)->toggleOn(
rpl::single(DialogListLines() == 1)
)->toggledValue(
) | rpl::filter([](bool enabled) {
return (enabled != (DialogListLines() == 1));
}) | rpl::start_with_next([](bool enabled) {
SetDialogListLines(enabled ? 1 : 2);
2020-04-21 06:26:36 +03:00
::Kotato::JsonSettings::Write();
}, container->lifetime());
2020-04-26 17:22:11 +03:00
SettingsMenuCSwitch(ktg_settings_always_show_scheduled, AlwaysShowScheduled);
2020-05-15 20:20:12 +03:00
SettingsMenuSwitch(ktg_emoji_panel_hover, HoverEmojiPanel);
2019-10-14 02:17:53 +03:00
AddButton(
container,
tr::ktg_settings_fonts(),
st::settingsButton
)->addClickHandler([=] {
Ui::show(Box<FontsBox>());
});
2020-04-23 19:56:49 +03:00
const QMap<int, QString> userpicRoundOptions = {
{ 0, UserpicRoundingLabel(0) },
{ 1, UserpicRoundingLabel(1) },
{ 2, UserpicRoundingLabel(2) },
{ 3, UserpicRoundingLabel(3) }
};
AddButtonWithLabel(
container,
tr::ktg_settings_userpic_rounding(),
rpl::single(UserpicRoundingLabel(cUserpicCornersType())),
st::settingsButton
)->addClickHandler([=] {
Ui::show(Box<::Kotato::RadioBox>(
tr::ktg_settings_userpic_rounding(tr::now),
tr::ktg_settings_userpic_rounding_desc(tr::now),
cUserpicCornersType(),
userpicRoundOptions,
[=] (int value) {
cSetUserpicCornersType(value);
::Kotato::JsonSettings::Write();
}, true));
});
AddSkip(container);
}
void SetupKotatoMessages(not_null<Ui::VerticalLayout*> container) {
AddDivider(container);
AddSkip(container);
AddSubsectionTitle(container, tr::ktg_settings_messages());
const auto stickerHeightLabel = container->add(
object_ptr<Ui::LabelSimple>(
container,
st::settingsAudioVolumeLabel),
st::settingsAudioVolumeLabelPadding);
const auto stickerHeightSlider = container->add(
object_ptr<Ui::MediaSlider>(
container,
st::settingsAudioVolumeSlider),
st::settingsAudioVolumeSliderPadding);
const auto updateStickerHeightLabel = [=](int value) {
const auto pixels = QString::number(value);
stickerHeightLabel->setText(
tr::ktg_settings_sticker_height(tr::now, lt_pixels, pixels));
};
const auto updateStickerHeight = [=](int value) {
updateStickerHeightLabel(value);
SetStickerHeight(value);
2020-04-21 06:26:36 +03:00
::Kotato::JsonSettings::Write();
};
stickerHeightSlider->resize(st::settingsAudioVolumeSlider.seekSize);
stickerHeightSlider->setPseudoDiscrete(
193,
[](int val) { return val + 64; },
StickerHeight(),
updateStickerHeight);
updateStickerHeightLabel(StickerHeight());
2020-05-06 02:27:04 +03:00
container->add(
object_ptr<Ui::Checkbox>(
container,
tr::ktg_settings_sticker_scale_both(tr::now),
StickerScaleBoth(),
st::settingsCheckbox),
st::settingsCheckboxPadding
)->checkedChanges(
) | rpl::filter([](bool checked) {
return (checked != StickerScaleBoth());
}) | rpl::start_with_next([](bool checked) {
SetStickerScaleBoth(checked);
::Kotato::JsonSettings::Write();
}, container->lifetime());
AddSkip(container);
AddDividerText(container, tr::ktg_settings_sticker_scale_both_about());
AddSkip(container);
auto adaptiveBubblesButton = AddButton(
container,
tr::ktg_settings_adaptive_bubbles(),
st::settingsButton
);
auto monospaceLargeBubblesButton = container->add(
object_ptr<Ui::SlideWrap<Button>>(
container,
CreateButton(
container,
tr::ktg_settings_monospace_large_bubbles(),
st::settingsButton)));
adaptiveBubblesButton->toggleOn(
rpl::single(AdaptiveBubbles())
)->toggledValue(
) | rpl::filter([](bool enabled) {
return (enabled != AdaptiveBubbles());
}) | rpl::start_with_next([monospaceLargeBubblesButton](bool enabled) {
monospaceLargeBubblesButton->toggle(!enabled, anim::type::normal);
SetAdaptiveBubbles(enabled);
::Kotato::JsonSettings::Write();
}, container->lifetime());
monospaceLargeBubblesButton->entity()->toggleOn(
rpl::single(MonospaceLargeBubbles())
)->toggledValue(
) | rpl::filter([](bool enabled) {
return (enabled != MonospaceLargeBubbles());
}) | rpl::start_with_next([](bool enabled) {
SetMonospaceLargeBubbles(enabled);
::Kotato::JsonSettings::Write();
}, container->lifetime());
if (adaptiveBubblesButton->toggled()) {
monospaceLargeBubblesButton->hide(anim::type::instant);
}
2020-04-23 13:00:53 +03:00
SettingsMenuSwitch(ktg_settings_emoji_outline, BigEmojiOutline);
2020-03-30 19:56:08 +03:00
2019-10-18 20:32:18 +03:00
AddSkip(container);
}
void SetupKotatoNetwork(not_null<Ui::VerticalLayout*> container) {
AddDivider(container);
AddSkip(container);
AddSubsectionTitle(container, tr::ktg_settings_network());
2020-04-23 17:38:15 +03:00
const QMap<int, QString> netBoostOptions = {
{ 0, NetBoostLabel(0) },
{ 1, NetBoostLabel(1) },
{ 2, NetBoostLabel(2) },
{ 3, NetBoostLabel(3) }
};
2019-10-18 20:32:18 +03:00
AddButtonWithLabel(
container,
tr::ktg_settings_net_speed_boost(),
2020-04-23 17:38:15 +03:00
rpl::single(NetBoostLabel(cNetSpeedBoost())),
2019-10-18 20:32:18 +03:00
st::settingsButton
)->addClickHandler([=] {
2020-04-23 17:38:15 +03:00
Ui::show(Box<::Kotato::RadioBox>(
tr::ktg_net_speed_boost_title(tr::now),
tr::ktg_net_speed_boost_desc(tr::now),
cNetSpeedBoost(),
netBoostOptions,
[=] (int value) {
SetNetworkBoost(value);
::Kotato::JsonSettings::Write();
}, true));
});
2019-10-10 19:57:03 +03:00
AddSkip(container);
}
2020-03-30 19:36:59 +03:00
void SetupKotatoFolders(
not_null<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> container) {
AddDivider(container);
AddSkip(container);
AddSubsectionTitle(container, tr::ktg_settings_filters());
2020-04-24 20:38:11 +03:00
SettingsMenuCFilterSwitch(ktg_settings_filters_only_unmuted_counter, UnmutedFilterCounterOnly);
SettingsMenuCFilterSwitch(ktg_settings_filters_hide_all, HideFilterAllChats);
SettingsMenuCFilterSwitch(ktg_settings_filters_hide_edit, HideFilterEditButton);
SettingsMenuCFilterSwitch(ktg_settings_filters_hide_folder_names, HideFilterNames);
2020-03-30 19:36:59 +03:00
AddSkip(container);
}
2020-02-23 05:30:39 +03:00
void SetupKotatoSystem(not_null<Ui::VerticalLayout*> container) {
AddDivider(container);
AddSkip(container);
AddSubsectionTitle(container, tr::ktg_settings_system());
#if defined Q_OS_WIN || defined Q_OS_MAC
const auto useNativeDecorationsToggled = Ui::CreateChild<rpl::event_stream<bool>>(
container.get());
AddButton(
container,
tr::ktg_settings_use_native_decorations(),
st::settingsButton
)->toggleOn(
useNativeDecorationsToggled->events_starting_with_copy(cUseNativeDecorations())
)->toggledValue(
) | rpl::filter([](bool enabled) {
return (enabled != cUseNativeDecorations());
}) | rpl::start_with_next([=](bool enabled) {
const auto confirmed = [=] {
cSetUseNativeDecorations(enabled);
::Kotato::JsonSettings::Write();
App::restart();
};
const auto cancelled = [=] {
useNativeDecorationsToggled->fire(cUseNativeDecorations() == true);
};
Ui::show(Box<ConfirmBox>(
tr::lng_settings_need_restart(tr::now),
tr::lng_settings_restart_now(tr::now),
confirmed,
cancelled));
}, container->lifetime());
#endif // Q_OS_WIN || Q_OS_MAC
AddButton(
container,
tr::ktg_settings_disable_tray_counter(),
st::settingsButton
)->toggleOn(
rpl::single(cDisableTrayCounter())
)->toggledValue(
) | rpl::filter([](bool enabled) {
return (enabled != cDisableTrayCounter());
}) | rpl::start_with_next([](bool enabled) {
cSetDisableTrayCounter(enabled);
Notify::unreadCounterUpdated();
::Kotato::JsonSettings::Write();
}, container->lifetime());
#if defined Q_OS_UNIX && !defined Q_OS_MAC
AddButton(
container,
tr::ktg_settings_use_telegram_panel_icon(),
st::settingsButton
)->toggleOn(
rpl::single(cUseTelegramPanelIcon())
)->toggledValue(
) | rpl::filter([](bool enabled) {
return (enabled != cUseTelegramPanelIcon());
}) | rpl::start_with_next([](bool enabled) {
cSetUseTelegramPanelIcon(enabled);
Notify::unreadCounterUpdated();
::Kotato::JsonSettings::Write();
}, container->lifetime());
#endif // Q_OS_UNIX && !Q_OS_MAC
2020-04-23 19:56:49 +03:00
const QMap<int, QString> trayIconOptions = {
{ 0, TrayIconLabel(0) },
{ 1, TrayIconLabel(1) },
{ 2, TrayIconLabel(2) },
{ 3, TrayIconLabel(3) },
{ 4, TrayIconLabel(4) },
{ 5, TrayIconLabel(5) },
};
auto trayIconText = rpl::single(
rpl::empty_value()
) | rpl::then(base::ObservableViewer(
Global::RefUnreadCounterUpdate()
)) | rpl::map([] {
return TrayIconLabel(cCustomAppIcon());
});
2020-04-23 19:56:49 +03:00
AddButtonWithLabel(
container,
tr::ktg_settings_tray_icon(),
trayIconText,
2020-04-23 19:56:49 +03:00
st::settingsButton
)->addClickHandler([=] {
Ui::show(Box<::Kotato::RadioBox>(
tr::ktg_settings_tray_icon(tr::now),
tr::ktg_settings_tray_icon_desc(tr::now),
cCustomAppIcon(),
trayIconOptions,
[=] (int value) {
cSetCustomAppIcon(value);
Notify::unreadCounterUpdated();
2020-04-23 19:56:49 +03:00
::Kotato::JsonSettings::Write();
}, false));
2020-04-23 19:56:49 +03:00
});
2020-02-23 05:30:39 +03:00
AddSkip(container);
}
2019-10-18 22:29:21 +03:00
void SetupKotatoOther(not_null<Ui::VerticalLayout*> container) {
AddDivider(container);
AddSkip(container);
AddSubsectionTitle(container, tr::ktg_settings_other());
2020-04-24 20:38:11 +03:00
SettingsMenuCSwitch(ktg_settings_show_phone_number, ShowPhoneInDrawer);
2020-05-05 06:46:11 +03:00
const QMap<int, QString> chatIdOptions = {
{ 0, ChatIdLabel(0) },
{ 1, ChatIdLabel(1) },
{ 2, ChatIdLabel(2) },
};
const auto chatIdButton = container->add(
object_ptr<Button>(
container,
tr::ktg_settings_chat_id(),
st::settingsButton));
auto chatIdText = rpl::single(
rpl::empty_value()
) | rpl::then(base::ObservableViewer(
Global::RefChatIDFormatChanged()
)) | rpl::map([] {
return ChatIdLabel(cShowChatId());
});
CreateRightLabel(
chatIdButton,
std::move(chatIdText),
st::settingsButton,
tr::ktg_settings_chat_id());
chatIdButton->addClickHandler([=] {
Ui::show(Box<::Kotato::RadioBox>(
tr::ktg_settings_chat_id(tr::now),
tr::ktg_settings_chat_id_desc(tr::now),
cShowChatId(),
chatIdOptions,
[=] (int value) {
cSetShowChatId(value);
::Kotato::JsonSettings::Write();
Global::RefChatIDFormatChanged().notify();
}));
});
2020-04-24 20:38:11 +03:00
SettingsMenuCSwitch(ktg_settings_call_confirm, ConfirmBeforeCall);
2020-02-03 05:51:15 +03:00
2019-10-18 22:29:21 +03:00
AddSkip(container);
}
2019-10-10 19:57:03 +03:00
Kotato::Kotato(
QWidget *parent,
not_null<Window::SessionController*> controller)
: Section(parent) {
setupContent(controller);
}
void Kotato::setupContent(not_null<Window::SessionController*> controller) {
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
SetupKotatoChats(content);
SetupKotatoMessages(content);
2019-10-18 20:32:18 +03:00
SetupKotatoNetwork(content);
2020-03-30 19:36:59 +03:00
SetupKotatoFolders(controller, content);
2020-02-23 05:30:39 +03:00
SetupKotatoSystem(content);
2019-10-18 22:29:21 +03:00
SetupKotatoOther(content);
2019-10-10 19:57:03 +03:00
Ui::ResizeFitChild(this, content);
}
} // namespace Settings
2019-10-14 02:17:53 +03:00