settings_experimental.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #include "settings/settings_experimental.h"
  8. #include "ui/boxes/confirm_box.h"
  9. #include "ui/wrap/vertical_layout.h"
  10. #include "ui/wrap/slide_wrap.h"
  11. #include "ui/widgets/buttons.h"
  12. #include "ui/widgets/labels.h"
  13. #include "ui/vertical_list.h"
  14. #include "ui/gl/gl_detection.h"
  15. #include "ui/chat/chat_style_radius.h"
  16. #include "base/options.h"
  17. #include "core/application.h"
  18. #include "core/launcher.h"
  19. #include "chat_helpers/tabbed_panel.h"
  20. #include "dialogs/dialogs_widget.h"
  21. #include "history/history_item_components.h"
  22. #include "info/profile/info_profile_actions.h"
  23. #include "lang/lang_keys.h"
  24. #include "mainwindow.h"
  25. #include "media/player/media_player_instance.h"
  26. #include "mtproto/session_private.h"
  27. #include "webview/webview_embed.h"
  28. #include "window/main_window.h"
  29. #include "window/window_peer_menu.h"
  30. #include "window/window_session_controller.h"
  31. #include "window/window_controller.h"
  32. #include "window/notifications_manager.h"
  33. #include "storage/localimageloader.h"
  34. #include "data/data_document_resolver.h"
  35. #include "styles/style_settings.h"
  36. #include "styles/style_layers.h"
  37. namespace Settings {
  38. namespace {
  39. void AddOption(
  40. not_null<Window::Controller*> window,
  41. not_null<Ui::VerticalLayout*> container,
  42. base::options::option<bool> &option,
  43. rpl::producer<> resetClicks) {
  44. auto &lifetime = container->lifetime();
  45. const auto name = option.name().isEmpty() ? option.id() : option.name();
  46. const auto toggles = lifetime.make_state<rpl::event_stream<bool>>();
  47. std::move(
  48. resetClicks
  49. ) | rpl::map_to(
  50. option.defaultValue()
  51. ) | rpl::start_to_stream(*toggles, lifetime);
  52. const auto button = container->add(object_ptr<Button>(
  53. container,
  54. rpl::single(name),
  55. (option.relevant()
  56. ? st::settingsButtonNoIcon
  57. : st::settingsOptionDisabled)
  58. ))->toggleOn(toggles->events_starting_with(option.value()));
  59. const auto restarter = (option.relevant() && option.restartRequired())
  60. ? button->lifetime().make_state<base::Timer>()
  61. : nullptr;
  62. if (restarter) {
  63. restarter->setCallback([=] {
  64. window->show(Ui::MakeConfirmBox({
  65. .text = tr::lng_settings_need_restart(),
  66. .confirmed = [] { Core::Restart(); },
  67. .confirmText = tr::lng_settings_restart_now(),
  68. .cancelText = tr::lng_settings_restart_later(),
  69. }));
  70. });
  71. }
  72. button->toggledChanges(
  73. ) | rpl::start_with_next([=, &option](bool toggled) {
  74. if (!option.relevant() && toggled != option.defaultValue()) {
  75. toggles->fire_copy(option.defaultValue());
  76. window->showToast(
  77. tr::lng_settings_experimental_irrelevant(tr::now));
  78. return;
  79. }
  80. option.set(toggled);
  81. if (restarter) {
  82. restarter->callOnce(st::settingsButtonNoIcon.toggle.duration);
  83. }
  84. }, container->lifetime());
  85. const auto &description = option.description();
  86. if (!description.isEmpty()) {
  87. Ui::AddSkip(container, st::settingsCheckboxesSkip);
  88. Ui::AddDividerText(container, rpl::single(description));
  89. Ui::AddSkip(container, st::settingsCheckboxesSkip);
  90. }
  91. }
  92. void SetupExperimental(
  93. not_null<Window::Controller*> window,
  94. not_null<Ui::VerticalLayout*> container) {
  95. Ui::AddSkip(container, st::settingsCheckboxesSkip);
  96. container->add(
  97. object_ptr<Ui::FlatLabel>(
  98. container,
  99. tr::lng_settings_experimental_about(),
  100. st::boxLabel),
  101. st::defaultBoxDividerLabelPadding);
  102. auto reset = (Button*)nullptr;
  103. if (base::options::changed()) {
  104. const auto wrap = container->add(
  105. object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
  106. container,
  107. object_ptr<Ui::VerticalLayout>(container)));
  108. const auto inner = wrap->entity();
  109. Ui::AddDivider(inner);
  110. Ui::AddSkip(inner, st::settingsCheckboxesSkip);
  111. reset = inner->add(object_ptr<Button>(
  112. inner,
  113. tr::lng_settings_experimental_restore(),
  114. st::settingsButtonNoIcon));
  115. reset->addClickHandler([=] {
  116. base::options::reset();
  117. wrap->hide(anim::type::normal);
  118. });
  119. Ui::AddSkip(inner, st::settingsCheckboxesSkip);
  120. }
  121. Ui::AddDivider(container);
  122. Ui::AddSkip(container, st::settingsCheckboxesSkip);
  123. const auto addToggle = [&](const char name[]) {
  124. AddOption(
  125. window,
  126. container,
  127. base::options::lookup<bool>(name),
  128. (reset
  129. ? (reset->clicks() | rpl::to_empty)
  130. : rpl::producer<>()));
  131. };
  132. addToggle(ChatHelpers::kOptionTabbedPanelShowOnClick);
  133. addToggle(Dialogs::kOptionForumHideChatsList);
  134. addToggle(Core::kOptionFractionalScalingEnabled);
  135. addToggle(Window::kOptionViewProfileInChatsListContextMenu);
  136. addToggle(Info::Profile::kOptionShowPeerIdBelowAbout);
  137. addToggle(Ui::kOptionUseSmallMsgBubbleRadius);
  138. addToggle(Media::Player::kOptionDisableAutoplayNext);
  139. addToggle(kOptionSendLargePhotos);
  140. addToggle(Webview::kOptionWebviewDebugEnabled);
  141. addToggle(Webview::kOptionWebviewLegacyEdge);
  142. addToggle(kOptionAutoScrollInactiveChat);
  143. addToggle(Window::Notifications::kOptionGNotification);
  144. addToggle(Core::kOptionFreeType);
  145. addToggle(Core::kOptionSkipUrlSchemeRegister);
  146. addToggle(Data::kOptionExternalVideoPlayer);
  147. addToggle(Window::kOptionNewWindowsSizeAsFirst);
  148. addToggle(MTP::details::kOptionPreferIPv6);
  149. if (base::options::lookup<bool>(kOptionFastButtonsMode).value()) {
  150. addToggle(kOptionFastButtonsMode);
  151. }
  152. addToggle(Window::kOptionDisableTouchbar);
  153. }
  154. } // namespace
  155. Experimental::Experimental(
  156. QWidget *parent,
  157. not_null<Window::SessionController*> controller)
  158. : Section(parent) {
  159. setupContent(controller);
  160. }
  161. rpl::producer<QString> Experimental::title() {
  162. return tr::lng_settings_experimental();
  163. }
  164. void Experimental::setupContent(
  165. not_null<Window::SessionController*> controller) {
  166. const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
  167. SetupExperimental(&controller->window(), content);
  168. Ui::ResizeFitChild(this, content);
  169. }
  170. } // namespace Settings