2018-09-05 22:05:49 +03: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_main.h"
|
|
|
|
|
|
|
|
#include "settings/settings_common.h"
|
|
|
|
#include "boxes/abstract_box.h"
|
2018-09-06 00:01:50 +03:00
|
|
|
#include "boxes/language_box.h"
|
|
|
|
#include "boxes/confirm_box.h"
|
2018-09-06 13:18:49 +03:00
|
|
|
#include "boxes/about_box.h"
|
2018-09-05 22:05:49 +03:00
|
|
|
#include "ui/wrap/vertical_layout.h"
|
2018-09-06 00:01:50 +03:00
|
|
|
#include "ui/wrap/padding_wrap.h"
|
|
|
|
#include "ui/widgets/labels.h"
|
|
|
|
#include "ui/widgets/discrete_sliders.h"
|
2018-09-05 22:05:49 +03:00
|
|
|
#include "info/profile/info_profile_button.h"
|
2018-09-05 22:39:35 +03:00
|
|
|
#include "info/profile/info_profile_cover.h"
|
2018-09-05 22:05:49 +03:00
|
|
|
#include "lang/lang_keys.h"
|
2018-09-06 00:01:50 +03:00
|
|
|
#include "storage/localstorage.h"
|
2018-09-06 13:18:49 +03:00
|
|
|
#include "auth_session.h"
|
|
|
|
#include "apiwrap.h"
|
2018-09-05 22:05:49 +03:00
|
|
|
#include "styles/style_settings.h"
|
|
|
|
|
|
|
|
namespace Settings {
|
2018-09-06 00:01:50 +03:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
void AddSkip(not_null<Ui::VerticalLayout*> container) {
|
|
|
|
container->add(object_ptr<Ui::FixedHeightWidget>(
|
|
|
|
container,
|
|
|
|
st::settingsSectionSkip));
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddDivider(not_null<Ui::VerticalLayout*> container) {
|
|
|
|
container->add(object_ptr<BoxContentDivider>(container));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetupLanguageButton(not_null<Ui::VerticalLayout*> container) {
|
|
|
|
const auto button = container->add(object_ptr<Button>(
|
|
|
|
container,
|
|
|
|
Lang::Viewer(lng_settings_language),
|
|
|
|
st::settingsSectionButton));
|
|
|
|
const auto guard = Ui::AttachAsChild(button, base::binary_guard());
|
|
|
|
button->addClickHandler([=] {
|
|
|
|
*guard = LanguageBox::Show();
|
|
|
|
});
|
|
|
|
const auto name = Ui::CreateChild<Ui::FlatLabel>(
|
|
|
|
button,
|
|
|
|
Lang::Viewer(lng_language_name),
|
|
|
|
st::settingsButtonRight);
|
|
|
|
rpl::combine(
|
|
|
|
name->widthValue(),
|
|
|
|
button->widthValue()
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
name->moveToRight(
|
|
|
|
st::settingsButtonRightPosition.x(),
|
|
|
|
st::settingsButtonRightPosition.y());
|
|
|
|
}, name->lifetime());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetupInterfaceScale(not_null<Ui::VerticalLayout*> container) {
|
|
|
|
if (cRetina()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AddDivider(container);
|
|
|
|
AddSkip(container);
|
|
|
|
|
|
|
|
const auto toggled = Ui::AttachAsChild(
|
|
|
|
container,
|
|
|
|
rpl::event_stream<bool>());
|
|
|
|
|
2018-09-06 13:18:49 +03:00
|
|
|
const auto switched = (cConfigScale() == dbisAuto)
|
|
|
|
|| (cConfigScale() == cScreenScale());
|
2018-09-06 00:01:50 +03:00
|
|
|
const auto button = container->add(object_ptr<Button>(
|
|
|
|
container,
|
|
|
|
Lang::Viewer(lng_settings_default_scale),
|
|
|
|
st::settingsSectionButton)
|
2018-09-06 13:18:49 +03:00
|
|
|
)->toggleOn(toggled->events_starting_with_copy(switched));
|
2018-09-06 00:01:50 +03:00
|
|
|
|
|
|
|
const auto slider = container->add(
|
2018-09-06 13:18:49 +03:00
|
|
|
object_ptr<Ui::SettingsSlider>(container, st::settingsSlider),
|
|
|
|
st::settingsScalePadding);
|
2018-09-06 00:01:50 +03:00
|
|
|
|
|
|
|
const auto inSetScale = Ui::AttachAsChild(container, false);
|
|
|
|
const auto setScale = std::make_shared<Fn<void(DBIScale)>>();
|
|
|
|
*setScale = [=](DBIScale scale) {
|
|
|
|
if (*inSetScale) return;
|
|
|
|
*inSetScale = true;
|
|
|
|
const auto guard = gsl::finally([=] { *inSetScale = false; });
|
|
|
|
|
|
|
|
if (scale == cScreenScale()) {
|
|
|
|
scale = dbisAuto;
|
|
|
|
}
|
|
|
|
toggled->fire(scale == dbisAuto);
|
|
|
|
const auto applying = scale;
|
|
|
|
if (scale == dbisAuto) {
|
|
|
|
scale = cScreenScale();
|
|
|
|
}
|
|
|
|
slider->setActiveSection(scale - 1);
|
|
|
|
|
|
|
|
if (cEvalScale(scale) != cEvalScale(cRealScale())) {
|
|
|
|
const auto confirmed = crl::guard(button, [=] {
|
2018-09-06 13:18:49 +03:00
|
|
|
cSetConfigScale(applying);
|
2018-09-06 00:01:50 +03:00
|
|
|
Local::writeSettings();
|
|
|
|
App::restart();
|
|
|
|
});
|
|
|
|
const auto cancelled = crl::guard(button, [=] {
|
|
|
|
App::CallDelayed(
|
|
|
|
st::defaultSettingsSlider.duration,
|
|
|
|
button,
|
|
|
|
[=] { (*setScale)(cRealScale()); });
|
|
|
|
});
|
|
|
|
Ui::show(Box<ConfirmBox>(
|
|
|
|
lang(lng_settings_need_restart),
|
|
|
|
lang(lng_settings_restart_now),
|
|
|
|
confirmed,
|
|
|
|
cancelled));
|
|
|
|
} else {
|
|
|
|
cSetConfigScale(scale);
|
|
|
|
Local::writeSettings();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
button->toggledValue(
|
|
|
|
) | rpl::start_with_next([=](bool checked) {
|
|
|
|
auto scale = checked ? dbisAuto : cEvalScale(cConfigScale());
|
|
|
|
if (scale == cScreenScale()) {
|
|
|
|
if (scale != cScale()) {
|
|
|
|
scale = cScale();
|
|
|
|
} else {
|
|
|
|
switch (scale) {
|
|
|
|
case dbisOne: scale = dbisOneAndQuarter; break;
|
|
|
|
case dbisOneAndQuarter: scale = dbisOne; break;
|
|
|
|
case dbisOneAndHalf: scale = dbisOneAndQuarter; break;
|
|
|
|
case dbisTwo: scale = dbisOneAndHalf; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(*setScale)(scale);
|
|
|
|
}, button->lifetime());
|
|
|
|
|
|
|
|
const auto label = [](DBIScale scale) {
|
|
|
|
switch (scale) {
|
|
|
|
case dbisOne: return qsl("100%");
|
|
|
|
case dbisOneAndQuarter: return qsl("125%");
|
|
|
|
case dbisOneAndHalf: return qsl("150%");
|
|
|
|
case dbisTwo: return qsl("200%");
|
|
|
|
}
|
|
|
|
Unexpected("Value in scale label.");
|
|
|
|
};
|
|
|
|
const auto scaleByIndex = [](int index) {
|
|
|
|
switch (index) {
|
|
|
|
case 0: return dbisOne;
|
|
|
|
case 1: return dbisOneAndQuarter;
|
|
|
|
case 2: return dbisOneAndHalf;
|
|
|
|
case 3: return dbisTwo;
|
|
|
|
}
|
|
|
|
Unexpected("Index in scaleByIndex.");
|
|
|
|
};
|
|
|
|
|
|
|
|
slider->addSection(label(dbisOne));
|
|
|
|
slider->addSection(label(dbisOneAndQuarter));
|
|
|
|
slider->addSection(label(dbisOneAndHalf));
|
|
|
|
slider->addSection(label(dbisTwo));
|
|
|
|
slider->setActiveSectionFast(cEvalScale(cConfigScale()) - 1);
|
|
|
|
slider->sectionActivated(
|
|
|
|
) | rpl::start_with_next([=](int section) {
|
|
|
|
(*setScale)(scaleByIndex(section));
|
|
|
|
}, slider->lifetime());
|
|
|
|
|
|
|
|
AddSkip(container);
|
|
|
|
}
|
|
|
|
|
2018-09-06 13:18:49 +03:00
|
|
|
void SetupHelp(not_null<Ui::VerticalLayout*> container) {
|
|
|
|
AddDivider(container);
|
|
|
|
AddSkip(container);
|
|
|
|
|
|
|
|
container->add(object_ptr<Button>(
|
|
|
|
container,
|
|
|
|
Lang::Viewer(lng_settings_faq),
|
|
|
|
st::settingsSectionButton)
|
|
|
|
)->addClickHandler([] {
|
|
|
|
QDesktopServices::openUrl(telegramFaqLink());
|
|
|
|
});
|
|
|
|
|
|
|
|
if (AuthSession::Exists()) {
|
|
|
|
const auto button = container->add(object_ptr<Button>(
|
|
|
|
container,
|
|
|
|
Lang::Viewer(lng_settings_ask_question),
|
|
|
|
st::settingsSectionButton));
|
|
|
|
button->addClickHandler([=] {
|
|
|
|
const auto ready = crl::guard(button, [](const MTPUser &data) {
|
|
|
|
const auto users = MTP_vector<MTPUser>(1, data);
|
|
|
|
if (const auto user = App::feedUsers(users)) {
|
|
|
|
Ui::showPeerHistory(user, ShowAtUnreadMsgId);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Auth().api().requestSupportContact(ready);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
AddSkip(container);
|
|
|
|
}
|
|
|
|
|
2018-09-06 00:01:50 +03:00
|
|
|
} // namespace
|
2018-09-05 22:05:49 +03:00
|
|
|
|
2018-09-05 22:39:35 +03:00
|
|
|
Main::Main(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::Controller*> controller,
|
|
|
|
not_null<UserData*> self)
|
2018-09-05 22:05:49 +03:00
|
|
|
: Section(parent)
|
|
|
|
, _self(self) {
|
2018-09-05 22:39:35 +03:00
|
|
|
setupContent(controller);
|
2018-09-05 22:05:49 +03:00
|
|
|
}
|
|
|
|
|
2018-09-05 22:39:35 +03:00
|
|
|
void Main::setupContent(not_null<Window::Controller*> controller) {
|
2018-09-05 22:05:49 +03:00
|
|
|
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
|
|
|
|
2018-09-05 22:39:35 +03:00
|
|
|
const auto cover = content->add(object_ptr<Info::Profile::Cover>(
|
|
|
|
content,
|
|
|
|
_self,
|
|
|
|
controller));
|
|
|
|
cover->setOnlineCount(rpl::single(0));
|
|
|
|
|
2018-09-06 00:01:50 +03:00
|
|
|
setupSections(content);
|
|
|
|
SetupInterfaceScale(content);
|
2018-09-06 13:18:49 +03:00
|
|
|
SetupHelp(content);
|
2018-09-06 00:01:50 +03:00
|
|
|
|
|
|
|
Ui::ResizeFitChild(this, content);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Main::setupSections(not_null<Ui::VerticalLayout*> container) {
|
|
|
|
AddDivider(container);
|
|
|
|
AddSkip(container);
|
2018-09-05 22:05:49 +03:00
|
|
|
|
|
|
|
const auto addSection = [&](LangKey label, Type type) {
|
2018-09-06 00:01:50 +03:00
|
|
|
container->add(object_ptr<Button>(
|
|
|
|
container,
|
2018-09-05 22:05:49 +03:00
|
|
|
Lang::Viewer(label),
|
|
|
|
st::settingsSectionButton)
|
|
|
|
)->addClickHandler([=] {
|
|
|
|
_showOther.fire_copy(type);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
addSection(lng_settings_section_info, Type::Information);
|
|
|
|
addSection(lng_settings_section_notify, Type::Notifications);
|
|
|
|
addSection(lng_settings_section_privacy, Type::PrivacySecurity);
|
|
|
|
addSection(lng_settings_section_general, Type::General);
|
|
|
|
addSection(lng_settings_section_chat_settings, Type::Chat);
|
|
|
|
|
2018-09-06 00:01:50 +03:00
|
|
|
SetupLanguageButton(container);
|
|
|
|
|
|
|
|
AddSkip(container);
|
2018-09-05 22:05:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<Type> Main::sectionShowOther() {
|
|
|
|
return _showOther.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Settings
|