2022-01-25 13:25:51 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "settings/settings_experimental.h"
|
|
|
|
|
2022-02-02 12:33:41 +00:00
|
|
|
#include "ui/boxes/confirm_box.h"
|
2022-01-25 13:25:51 +00:00
|
|
|
#include "ui/wrap/vertical_layout.h"
|
2022-02-02 12:33:41 +00:00
|
|
|
#include "ui/wrap/slide_wrap.h"
|
2022-01-25 13:25:51 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
|
|
|
#include "ui/widgets/labels.h"
|
2022-02-02 12:33:41 +00:00
|
|
|
#include "ui/gl/gl_detection.h"
|
2022-01-25 15:40:22 +00:00
|
|
|
#include "base/options.h"
|
2022-02-02 12:33:41 +00:00
|
|
|
#include "core/application.h"
|
2022-01-25 13:25:51 +00:00
|
|
|
#include "chat_helpers/tabbed_panel.h"
|
2022-06-07 18:05:37 +00:00
|
|
|
#include "dialogs/dialogs_inner_widget.h"
|
2022-06-04 06:59:48 +00:00
|
|
|
#include "history/history_widget.h"
|
2022-01-25 13:25:51 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2022-03-05 09:40:49 +00:00
|
|
|
#include "media/player/media_player_instance.h"
|
2022-05-02 09:10:03 +00:00
|
|
|
#include "webview/webview_embed.h"
|
2022-02-01 15:19:47 +00:00
|
|
|
#include "window/window_peer_menu.h"
|
2022-02-02 12:33:41 +00:00
|
|
|
#include "window/window_session_controller.h"
|
|
|
|
#include "window/window_controller.h"
|
2022-03-14 06:20:36 +00:00
|
|
|
#include "settings/settings_common.h"
|
2022-01-25 13:25:51 +00:00
|
|
|
#include "styles/style_settings.h"
|
|
|
|
#include "styles/style_layers.h"
|
|
|
|
|
|
|
|
namespace Settings {
|
|
|
|
namespace {
|
|
|
|
|
2022-01-25 15:40:22 +00:00
|
|
|
void AddOption(
|
2022-02-02 12:33:41 +00:00
|
|
|
not_null<Window::Controller*> window,
|
2022-01-25 15:40:22 +00:00
|
|
|
not_null<Ui::VerticalLayout*> container,
|
2022-02-02 12:33:41 +00:00
|
|
|
base::options::option<bool> &option,
|
|
|
|
rpl::producer<> resetClicks) {
|
|
|
|
auto &lifetime = container->lifetime();
|
2022-01-25 15:40:22 +00:00
|
|
|
const auto name = option.name().isEmpty() ? option.id() : option.name();
|
2022-02-02 12:33:41 +00:00
|
|
|
const auto toggles = lifetime.make_state<rpl::event_stream<bool>>();
|
|
|
|
std::move(
|
|
|
|
resetClicks
|
|
|
|
) | rpl::map_to(
|
|
|
|
option.defaultValue()
|
|
|
|
) | rpl::start_to_stream(*toggles, lifetime);
|
|
|
|
|
|
|
|
const auto button = AddButton(
|
2022-01-25 15:40:22 +00:00
|
|
|
container,
|
|
|
|
rpl::single(name),
|
2022-02-13 13:30:43 +00:00
|
|
|
(option.relevant()
|
|
|
|
? st::settingsButtonNoIcon
|
|
|
|
: st::settingsOptionDisabled)
|
2022-02-02 12:33:41 +00:00
|
|
|
)->toggleOn(toggles->events_starting_with(option.value()));
|
|
|
|
|
|
|
|
const auto restarter = (option.relevant() && option.restartRequired())
|
|
|
|
? button->lifetime().make_state<base::Timer>()
|
|
|
|
: nullptr;
|
|
|
|
if (restarter) {
|
|
|
|
restarter->setCallback([=] {
|
2022-02-27 08:23:20 +00:00
|
|
|
window->show(Ui::MakeConfirmBox({
|
|
|
|
.text = tr::lng_settings_need_restart(),
|
|
|
|
.confirmed = [] { Core::Restart(); },
|
|
|
|
.confirmText = tr::lng_settings_restart_now(),
|
|
|
|
.cancelText = tr::lng_settings_restart_later(),
|
|
|
|
}));
|
2022-02-02 12:33:41 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
button->toggledChanges(
|
2022-01-25 15:40:22 +00:00
|
|
|
) | rpl::start_with_next([=, &option](bool toggled) {
|
2022-02-02 12:33:41 +00:00
|
|
|
if (!option.relevant() && toggled != option.defaultValue()) {
|
|
|
|
toggles->fire_copy(option.defaultValue());
|
|
|
|
window->showToast(
|
|
|
|
tr::lng_settings_experimental_irrelevant(tr::now));
|
|
|
|
return;
|
|
|
|
}
|
2022-01-25 15:40:22 +00:00
|
|
|
option.set(toggled);
|
2022-02-02 12:33:41 +00:00
|
|
|
if (restarter) {
|
2022-02-13 13:30:43 +00:00
|
|
|
restarter->callOnce(st::settingsButtonNoIcon.toggle.duration);
|
2022-02-02 12:33:41 +00:00
|
|
|
}
|
2022-01-25 15:40:22 +00:00
|
|
|
}, container->lifetime());
|
|
|
|
|
|
|
|
const auto &description = option.description();
|
|
|
|
if (!description.isEmpty()) {
|
|
|
|
AddSkip(container, st::settingsCheckboxesSkip);
|
|
|
|
AddDividerText(container, rpl::single(description));
|
2022-02-02 12:33:41 +00:00
|
|
|
AddSkip(container, st::settingsCheckboxesSkip);
|
2022-01-25 15:40:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-25 13:25:51 +00:00
|
|
|
void SetupExperimental(
|
2022-02-02 12:33:41 +00:00
|
|
|
not_null<Window::Controller*> window,
|
2022-01-25 13:25:51 +00:00
|
|
|
not_null<Ui::VerticalLayout*> container) {
|
|
|
|
AddSkip(container, st::settingsCheckboxesSkip);
|
|
|
|
|
|
|
|
container->add(
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
container,
|
|
|
|
tr::lng_settings_experimental_about(),
|
|
|
|
st::boxLabel),
|
|
|
|
st::settingsDividerLabelPadding);
|
|
|
|
|
2022-02-02 12:33:41 +00:00
|
|
|
auto reset = (Button*)nullptr;
|
|
|
|
if (base::options::changed()) {
|
|
|
|
const auto wrap = container->add(
|
|
|
|
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
|
|
|
container,
|
|
|
|
object_ptr<Ui::VerticalLayout>(container)));
|
|
|
|
const auto inner = wrap->entity();
|
|
|
|
AddDivider(inner);
|
|
|
|
AddSkip(inner, st::settingsCheckboxesSkip);
|
|
|
|
reset = AddButton(
|
|
|
|
inner,
|
|
|
|
tr::lng_settings_experimental_restore(),
|
2022-02-13 13:30:43 +00:00
|
|
|
st::settingsButtonNoIcon);
|
2022-02-02 12:33:41 +00:00
|
|
|
reset->addClickHandler([=] {
|
|
|
|
base::options::reset();
|
|
|
|
wrap->hide(anim::type::normal);
|
|
|
|
});
|
|
|
|
AddSkip(inner, st::settingsCheckboxesSkip);
|
|
|
|
}
|
2022-01-25 13:25:51 +00:00
|
|
|
|
2022-02-02 12:33:41 +00:00
|
|
|
AddDivider(container);
|
2022-01-25 13:25:51 +00:00
|
|
|
AddSkip(container, st::settingsCheckboxesSkip);
|
2022-01-25 15:40:22 +00:00
|
|
|
|
|
|
|
const auto addToggle = [&](const char name[]) {
|
2022-02-02 12:33:41 +00:00
|
|
|
AddOption(
|
|
|
|
window,
|
|
|
|
container,
|
|
|
|
base::options::lookup<bool>(name),
|
|
|
|
(reset
|
|
|
|
? (reset->clicks() | rpl::to_empty)
|
|
|
|
: rpl::producer<>()));
|
2022-01-25 15:40:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
addToggle(ChatHelpers::kOptionTabbedPanelShowOnClick);
|
2022-02-01 15:19:47 +00:00
|
|
|
addToggle(Window::kOptionViewProfileInChatsListContextMenu);
|
2022-06-07 18:05:37 +00:00
|
|
|
addToggle(Dialogs::kOptionCtrlClickChatNewWindow);
|
2022-02-02 12:33:41 +00:00
|
|
|
addToggle(Ui::GL::kOptionAllowLinuxNvidiaOpenGL);
|
2022-03-05 09:40:49 +00:00
|
|
|
addToggle(Media::Player::kOptionDisableAutoplayNext);
|
2022-03-14 06:20:36 +00:00
|
|
|
addToggle(Settings::kOptionMonoSettingsIcons);
|
2022-05-02 09:10:03 +00:00
|
|
|
addToggle(Webview::kOptionWebviewDebugEnabled);
|
2022-06-04 06:59:48 +00:00
|
|
|
addToggle(kOptionAutoScrollInactiveChat);
|
2022-01-25 13:25:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
Experimental::Experimental(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::SessionController*> controller)
|
|
|
|
: Section(parent) {
|
|
|
|
setupContent(controller);
|
|
|
|
}
|
|
|
|
|
2022-04-13 08:05:10 +00:00
|
|
|
rpl::producer<QString> Experimental::title() {
|
2022-04-01 11:53:23 +00:00
|
|
|
return tr::lng_settings_experimental();
|
|
|
|
}
|
|
|
|
|
2022-01-25 13:25:51 +00:00
|
|
|
void Experimental::setupContent(
|
|
|
|
not_null<Window::SessionController*> controller) {
|
|
|
|
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
|
|
|
|
2022-02-02 12:33:41 +00:00
|
|
|
SetupExperimental(&controller->window(), content);
|
2022-01-25 13:25:51 +00:00
|
|
|
|
|
|
|
Ui::ResizeFitChild(this, content);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Settings
|