2016-08-19 17:26:31 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-08-19 17:26:31 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-08-19 17:26:31 +00:00
|
|
|
*/
|
|
|
|
#include "settings/settings_advanced_widget.h"
|
|
|
|
|
|
|
|
#include "styles/style_settings.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/connection_box.h"
|
|
|
|
#include "boxes/confirm_box.h"
|
|
|
|
#include "boxes/about_box.h"
|
|
|
|
#include "boxes/local_storage_box.h"
|
2016-08-22 17:16:21 +00:00
|
|
|
#include "mainwindow.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2017-09-13 16:57:44 +00:00
|
|
|
#include "ui/wrap/slide_wrap.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2017-02-03 20:07:26 +00:00
|
|
|
#include "window/themes/window_theme.h"
|
2016-08-19 17:26:31 +00:00
|
|
|
|
|
|
|
namespace Settings {
|
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
AdvancedWidget::AdvancedWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, lang(lng_settings_section_advanced_settings)) {
|
|
|
|
createControls();
|
2016-08-27 04:49:18 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_NETWORK_PROXY
|
|
|
|
subscribe(Global::RefConnectionTypeChanged(), [this]() {
|
|
|
|
connectionTypeUpdated();
|
|
|
|
});
|
2016-10-18 07:56:38 +00:00
|
|
|
#endif // !TDESKTOP_DISABLE_NETWORK_PROXY
|
2016-12-21 08:38:36 +00:00
|
|
|
if (!self) {
|
|
|
|
subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &update) {
|
|
|
|
if (update.type == Window::Theme::BackgroundUpdate::Type::ApplyingTheme) {
|
|
|
|
checkNonDefaultTheme();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-08-19 17:26:31 +00:00
|
|
|
}
|
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
void AdvancedWidget::createControls() {
|
|
|
|
style::margins marginSmall(0, 0, 0, st::settingsSmallSkip);
|
|
|
|
style::margins marginLarge(0, 0, 0, st::settingsLargeSkip);
|
|
|
|
|
2018-04-07 08:47:08 +00:00
|
|
|
style::margins marginLocalStorage = [&] {
|
2016-08-28 19:16:23 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_NETWORK_PROXY
|
|
|
|
return marginSmall;
|
2016-10-18 07:56:38 +00:00
|
|
|
#else // !TDESKTOP_DISABLE_NETWORK_PROXY
|
2016-08-28 19:16:23 +00:00
|
|
|
return marginLarge;
|
|
|
|
#endif // TDESKTOP_DISABLE_NETWORK_PROXY
|
2018-04-07 08:47:08 +00:00
|
|
|
}();
|
2016-08-22 17:16:21 +00:00
|
|
|
if (self()) {
|
2017-09-13 16:57:44 +00:00
|
|
|
createChildRow(_manageLocalStorage, marginLocalStorage, lang(lng_settings_manage_local_storage), SLOT(onManageLocalStorage()));
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
2016-08-28 19:16:23 +00:00
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_NETWORK_PROXY
|
2017-09-13 16:57:44 +00:00
|
|
|
createChildRow(_connectionType, marginLarge, lang(lng_connection_type), lang(lng_connection_auto_connecting), LabeledLink::Type::Primary, SLOT(onConnectionType()));
|
2016-08-27 04:49:18 +00:00
|
|
|
connectionTypeUpdated();
|
2016-10-18 07:56:38 +00:00
|
|
|
#endif // !TDESKTOP_DISABLE_NETWORK_PROXY
|
2016-08-28 19:16:23 +00:00
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
if (self()) {
|
2017-09-13 16:57:44 +00:00
|
|
|
createChildRow(_askQuestion, marginSmall, lang(lng_settings_ask_question), SLOT(onAskQuestion()));
|
2016-12-21 08:38:36 +00:00
|
|
|
} else {
|
|
|
|
style::margins slidedPadding(0, marginLarge.bottom() / 2, 0, marginLarge.bottom() - (marginLarge.bottom() / 2));
|
2017-09-13 16:57:44 +00:00
|
|
|
createChildRow(_useDefaultTheme, marginLarge, slidedPadding, lang(lng_settings_bg_use_default), SLOT(onUseDefaultTheme()));
|
2017-06-29 19:09:10 +00:00
|
|
|
if (!Window::Theme::IsNonDefaultUsed()) {
|
2017-10-01 08:15:40 +00:00
|
|
|
_useDefaultTheme->hide(anim::type::instant);
|
2016-12-21 08:38:36 +00:00
|
|
|
}
|
2017-09-13 16:57:44 +00:00
|
|
|
createChildRow(_toggleNightTheme, marginLarge, slidedPadding, getNightThemeToggleText(), SLOT(onToggleNightTheme()));
|
2017-06-29 19:09:10 +00:00
|
|
|
if (Window::Theme::IsNonDefaultUsed()) {
|
2017-10-01 08:15:40 +00:00
|
|
|
_toggleNightTheme->hide(anim::type::instant);
|
2017-06-29 19:09:10 +00:00
|
|
|
}
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
2017-09-13 16:57:44 +00:00
|
|
|
createChildRow(_telegramFAQ, marginLarge, lang(lng_settings_faq), SLOT(onTelegramFAQ()));
|
2016-08-22 17:16:21 +00:00
|
|
|
if (self()) {
|
2016-08-28 20:23:32 +00:00
|
|
|
style::margins marginLogout(0, 0, 0, 2 * st::settingsLargeSkip);
|
2017-09-13 16:57:44 +00:00
|
|
|
createChildRow(_logOut, marginLogout, lang(lng_settings_logout), SLOT(onLogOut()));
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 08:38:36 +00:00
|
|
|
void AdvancedWidget::checkNonDefaultTheme() {
|
|
|
|
if (self()) return;
|
2017-10-01 08:15:40 +00:00
|
|
|
_useDefaultTheme->toggle(
|
|
|
|
Window::Theme::IsNonDefaultUsed(),
|
|
|
|
anim::type::normal);
|
2017-06-29 19:09:10 +00:00
|
|
|
_toggleNightTheme->entity()->setText(getNightThemeToggleText());
|
2017-10-01 08:15:40 +00:00
|
|
|
_toggleNightTheme->toggle(
|
|
|
|
!Window::Theme::IsNonDefaultUsed(),
|
|
|
|
anim::type::normal);
|
2016-12-21 08:38:36 +00:00
|
|
|
}
|
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
void AdvancedWidget::onManageLocalStorage() {
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<LocalStorageBox>());
|
2016-08-19 17:26:31 +00:00
|
|
|
}
|
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_NETWORK_PROXY
|
2016-08-27 04:49:18 +00:00
|
|
|
void AdvancedWidget::connectionTypeUpdated() {
|
2018-04-27 17:26:45 +00:00
|
|
|
const auto connection = [] {
|
|
|
|
const auto transport = MTP::dctransport();
|
|
|
|
if (!Global::UseProxy()) {
|
|
|
|
return transport.isEmpty()
|
|
|
|
? lang(lng_connection_auto_connecting)
|
|
|
|
: lng_connection_auto(lt_transport, transport);
|
|
|
|
} else {
|
|
|
|
return transport.isEmpty()
|
|
|
|
? lang(lng_connection_proxy_connecting)
|
|
|
|
: lng_connection_proxy(lt_transport, transport);
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
2018-04-27 17:26:45 +00:00
|
|
|
}();
|
|
|
|
_connectionType->link()->setText(connection);
|
2016-08-27 04:49:18 +00:00
|
|
|
resizeToWidth(width());
|
|
|
|
}
|
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
void AdvancedWidget::onConnectionType() {
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<ConnectionBox>());
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
2016-10-18 07:56:38 +00:00
|
|
|
#endif // !TDESKTOP_DISABLE_NETWORK_PROXY
|
2016-08-22 17:16:21 +00:00
|
|
|
|
2016-12-21 08:38:36 +00:00
|
|
|
void AdvancedWidget::onUseDefaultTheme() {
|
|
|
|
Window::Theme::ApplyDefault();
|
|
|
|
}
|
|
|
|
|
2017-06-29 19:09:10 +00:00
|
|
|
void AdvancedWidget::onToggleNightTheme() {
|
|
|
|
Window::Theme::SwitchNightTheme(!Window::Theme::IsNightTheme());
|
|
|
|
}
|
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
void AdvancedWidget::onAskQuestion() {
|
2016-12-13 17:07:56 +00:00
|
|
|
auto box = Box<ConfirmBox>(lang(lng_settings_ask_sure), lang(lng_settings_ask_ok), lang(lng_settings_faq_button), base::lambda_guarded(this, [this] {
|
|
|
|
onAskQuestionSure();
|
|
|
|
}), base::lambda_guarded(this, [this] {
|
|
|
|
onTelegramFAQ();
|
|
|
|
}));
|
|
|
|
box->setStrictCancel(true);
|
2017-02-21 13:45:56 +00:00
|
|
|
Ui::show(std::move(box));
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
2016-08-19 17:26:31 +00:00
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
void AdvancedWidget::onAskQuestionSure() {
|
|
|
|
if (_supportGetRequest) return;
|
|
|
|
_supportGetRequest = MTP::send(MTPhelp_GetSupport(), rpcDone(&AdvancedWidget::supportGot));
|
2016-08-19 17:26:31 +00:00
|
|
|
}
|
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
void AdvancedWidget::supportGot(const MTPhelp_Support &support) {
|
|
|
|
if (!App::main()) return;
|
|
|
|
|
|
|
|
if (support.type() == mtpc_help_support) {
|
|
|
|
if (auto user = App::feedUsers(MTP_vector<MTPUser>(1, support.c_help_support().vuser))) {
|
|
|
|
Ui::showPeerHistory(user, ShowAtUnreadMsgId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-29 19:09:10 +00:00
|
|
|
QString AdvancedWidget::getNightThemeToggleText() const {
|
|
|
|
return lang(Window::Theme::IsNightTheme() ? lng_settings_disable_night_theme : lng_settings_enable_night_theme);
|
|
|
|
}
|
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
void AdvancedWidget::onTelegramFAQ() {
|
|
|
|
QDesktopServices::openUrl(telegramFaqLink());
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdvancedWidget::onLogOut() {
|
|
|
|
App::wnd()->onLogout();
|
|
|
|
}
|
|
|
|
|
2016-08-19 17:26:31 +00:00
|
|
|
} // namespace Settings
|