2016-08-19 17:26:31 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2016-08-19 17:26:31 +00:00
|
|
|
*/
|
|
|
|
#include "settings/settings_privacy_widget.h"
|
|
|
|
|
2017-09-13 16:57:44 +00:00
|
|
|
#include "ui/wrap/slide_wrap.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2016-08-19 17:26:31 +00:00
|
|
|
#include "styles/style_settings.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2016-08-28 19:16:23 +00:00
|
|
|
#include "application.h"
|
2017-03-16 15:15:07 +00:00
|
|
|
#include "platform/platform_specific.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/sessions_box.h"
|
|
|
|
#include "boxes/passcode_box.h"
|
|
|
|
#include "boxes/autolock_box.h"
|
2017-03-13 15:40:21 +00:00
|
|
|
#include "boxes/peer_list_box.h"
|
2017-03-16 15:15:07 +00:00
|
|
|
#include "boxes/edit_privacy_box.h"
|
2017-03-20 15:41:17 +00:00
|
|
|
#include "boxes/self_destruction_box.h"
|
2017-03-16 15:15:07 +00:00
|
|
|
#include "settings/settings_privacy_controllers.h"
|
2016-08-19 17:26:31 +00:00
|
|
|
|
|
|
|
namespace Settings {
|
|
|
|
|
2017-09-13 16:57:44 +00:00
|
|
|
LocalPasscodeState::LocalPasscodeState(QWidget *parent) : RpWidget(parent)
|
2017-04-18 17:37:14 +00:00
|
|
|
, _edit(this, GetEditPasscodeText(), st::boxLinkButton)
|
2016-11-11 13:46:04 +00:00
|
|
|
, _turnOff(this, lang(lng_passcode_turn_off), st::boxLinkButton) {
|
2016-08-28 19:16:23 +00:00
|
|
|
updateControls();
|
|
|
|
connect(_edit, SIGNAL(clicked()), this, SLOT(onEdit()));
|
|
|
|
connect(_turnOff, SIGNAL(clicked()), this, SLOT(onTurnOff()));
|
|
|
|
subscribe(Global::RefLocalPasscodeChanged(), [this]() { updateControls(); });
|
|
|
|
}
|
|
|
|
|
|
|
|
int LocalPasscodeState::resizeGetHeight(int newWidth) {
|
|
|
|
_edit->moveToLeft(0, 0, newWidth);
|
|
|
|
_turnOff->moveToRight(0, 0, newWidth);
|
|
|
|
return _edit->height();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalPasscodeState::onEdit() {
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<PasscodeBox>(false));
|
2016-08-28 19:16:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LocalPasscodeState::onTurnOff() {
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<PasscodeBox>(true));
|
2016-08-28 19:16:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LocalPasscodeState::updateControls() {
|
2017-04-18 17:37:14 +00:00
|
|
|
_edit->setText(GetEditPasscodeText());
|
2016-08-28 19:16:23 +00:00
|
|
|
_edit->moveToLeft(0, 0);
|
|
|
|
_turnOff->setVisible(Global::LocalPasscode());
|
|
|
|
}
|
|
|
|
|
2017-04-18 17:37:14 +00:00
|
|
|
QString LocalPasscodeState::GetEditPasscodeText() {
|
|
|
|
return lang(Global::LocalPasscode() ? lng_passcode_change : lng_passcode_turn_on);
|
|
|
|
}
|
|
|
|
|
2017-09-13 16:57:44 +00:00
|
|
|
CloudPasswordState::CloudPasswordState(QWidget *parent) : RpWidget(parent)
|
2016-11-11 13:46:04 +00:00
|
|
|
, _edit(this, lang(lng_cloud_password_set), st::boxLinkButton)
|
|
|
|
, _turnOff(this, lang(lng_passcode_turn_off), st::boxLinkButton) {
|
2016-08-28 19:16:23 +00:00
|
|
|
_turnOff->hide();
|
|
|
|
connect(_edit, SIGNAL(clicked()), this, SLOT(onEdit()));
|
|
|
|
connect(_turnOff, SIGNAL(clicked()), this, SLOT(onTurnOff()));
|
|
|
|
Sandbox::connect(SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(onReloadPassword(Qt::ApplicationState)));
|
|
|
|
onReloadPassword();
|
|
|
|
}
|
|
|
|
|
|
|
|
int CloudPasswordState::resizeGetHeight(int newWidth) {
|
|
|
|
_edit->moveToLeft(0, 0, newWidth);
|
|
|
|
_turnOff->moveToRight(0, 0, newWidth);
|
|
|
|
return _edit->height();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CloudPasswordState::onEdit() {
|
2016-12-13 17:07:56 +00:00
|
|
|
auto box = Ui::show(Box<PasscodeBox>(_newPasswordSalt, _curPasswordSalt, _hasPasswordRecovery, _curPasswordHint));
|
2016-08-28 19:16:23 +00:00
|
|
|
connect(box, SIGNAL(reloadPassword()), this, SLOT(onReloadPassword()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CloudPasswordState::onTurnOff() {
|
|
|
|
if (_curPasswordSalt.isEmpty()) {
|
|
|
|
_turnOff->hide();
|
|
|
|
|
2017-03-25 15:42:01 +00:00
|
|
|
auto flags = MTPDaccount_passwordInputSettings::Flag::f_email;
|
2016-08-28 19:16:23 +00:00
|
|
|
MTPaccount_PasswordInputSettings settings(MTP_account_passwordInputSettings(MTP_flags(flags), MTP_bytes(QByteArray()), MTP_bytes(QByteArray()), MTP_string(QString()), MTP_string(QString())));
|
|
|
|
MTP::send(MTPaccount_UpdatePasswordSettings(MTP_bytes(QByteArray()), settings), rpcDone(&CloudPasswordState::offPasswordDone), rpcFail(&CloudPasswordState::offPasswordFail));
|
|
|
|
} else {
|
2016-12-13 17:07:56 +00:00
|
|
|
auto box = Ui::show(Box<PasscodeBox>(_newPasswordSalt, _curPasswordSalt, _hasPasswordRecovery, _curPasswordHint, true));
|
2016-08-28 19:16:23 +00:00
|
|
|
connect(box, SIGNAL(reloadPassword()), this, SLOT(onReloadPassword()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CloudPasswordState::onReloadPassword(Qt::ApplicationState state) {
|
|
|
|
if (state == Qt::ApplicationActive) {
|
|
|
|
MTP::send(MTPaccount_GetPassword(), rpcDone(&CloudPasswordState::getPasswordDone));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CloudPasswordState::getPasswordDone(const MTPaccount_Password &result) {
|
|
|
|
_waitingConfirm = QString();
|
|
|
|
|
|
|
|
switch (result.type()) {
|
|
|
|
case mtpc_account_noPassword: {
|
|
|
|
auto &d = result.c_account_noPassword();
|
|
|
|
_curPasswordSalt = QByteArray();
|
|
|
|
_hasPasswordRecovery = false;
|
|
|
|
_curPasswordHint = QString();
|
|
|
|
_newPasswordSalt = qba(d.vnew_salt);
|
|
|
|
auto pattern = qs(d.vemail_unconfirmed_pattern);
|
|
|
|
if (!pattern.isEmpty()) {
|
|
|
|
_waitingConfirm = lng_cloud_password_waiting(lt_email, pattern);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case mtpc_account_password: {
|
|
|
|
auto &d = result.c_account_password();
|
|
|
|
_curPasswordSalt = qba(d.vcurrent_salt);
|
|
|
|
_hasPasswordRecovery = mtpIsTrue(d.vhas_recovery);
|
|
|
|
_curPasswordHint = qs(d.vhint);
|
|
|
|
_newPasswordSalt = qba(d.vnew_salt);
|
|
|
|
auto pattern = qs(d.vemail_unconfirmed_pattern);
|
|
|
|
if (!pattern.isEmpty()) {
|
|
|
|
_waitingConfirm = lng_cloud_password_waiting(lt_email, pattern);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
_edit->setText(lang(_curPasswordSalt.isEmpty() ? lng_cloud_password_set : lng_cloud_password_edit));
|
|
|
|
_edit->setVisible(_waitingConfirm.isEmpty());
|
|
|
|
_turnOff->setVisible(!_waitingConfirm.isEmpty() || !_curPasswordSalt.isEmpty());
|
|
|
|
update();
|
|
|
|
|
|
|
|
_newPasswordSalt.resize(_newPasswordSalt.size() + 8);
|
|
|
|
memset_rand(_newPasswordSalt.data() + _newPasswordSalt.size() - 8, 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CloudPasswordState::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
auto text = st::boxTextFont->elided(_waitingConfirm, width() - _turnOff->width() - st::boxTextFont->spacew);
|
2016-08-28 19:16:23 +00:00
|
|
|
if (!text.isEmpty()) {
|
2016-11-16 10:44:06 +00:00
|
|
|
p.setPen(st::windowFg);
|
2016-08-28 19:16:23 +00:00
|
|
|
p.setFont(st::boxTextFont);
|
|
|
|
p.drawTextLeft(0, 0, width(), text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CloudPasswordState::offPasswordDone(const MTPBool &result) {
|
|
|
|
onReloadPassword();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CloudPasswordState::offPasswordFail(const RPCError &error) {
|
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
|
|
|
|
|
|
|
onReloadPassword();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-19 17:26:31 +00:00
|
|
|
PrivacyWidget::PrivacyWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, lang(lng_settings_section_privacy)) {
|
2016-08-28 19:16:23 +00:00
|
|
|
createControls();
|
|
|
|
subscribe(Global::RefLocalPasscodeChanged(), [this]() { autoLockUpdated(); });
|
2016-08-19 17:26:31 +00:00
|
|
|
}
|
|
|
|
|
2017-04-18 17:37:14 +00:00
|
|
|
QString PrivacyWidget::GetAutoLockText() {
|
|
|
|
return (Global::AutoLock() % 3600) ? lng_passcode_autolock_minutes(lt_count, Global::AutoLock() / 60) : lng_passcode_autolock_hours(lt_count, Global::AutoLock() / 3600);
|
|
|
|
}
|
|
|
|
|
2016-08-28 19:16:23 +00:00
|
|
|
void PrivacyWidget::createControls() {
|
2016-08-22 17:16:21 +00:00
|
|
|
style::margins marginSmall(0, 0, 0, st::settingsSmallSkip);
|
|
|
|
style::margins marginSkip(0, 0, 0, st::settingsSkip);
|
|
|
|
style::margins slidedPadding(0, marginSmall.bottom() / 2, 0, marginSmall.bottom() - (marginSmall.bottom() / 2));
|
|
|
|
|
2017-09-13 16:57:44 +00:00
|
|
|
createChildRow(_blockedUsers, marginSmall, lang(lng_settings_blocked_users), SLOT(onBlockedUsers()));
|
|
|
|
createChildRow(_lastSeenPrivacy, marginSmall, lang(lng_settings_last_seen_privacy), SLOT(onLastSeenPrivacy()));
|
|
|
|
createChildRow(_callsPrivacy, marginSmall, lang(lng_settings_calls_privacy), SLOT(onCallsPrivacy()));
|
|
|
|
createChildRow(_groupsInvitePrivacy, marginSmall, lang(lng_settings_groups_invite_privacy), SLOT(onGroupsInvitePrivacy()));
|
|
|
|
createChildRow(_localPasscodeState, marginSmall);
|
2016-08-28 19:16:23 +00:00
|
|
|
auto label = lang(psIdleSupported() ? lng_passcode_autolock_away : lng_passcode_autolock_inactive);
|
2017-04-18 17:37:14 +00:00
|
|
|
auto value = GetAutoLockText();
|
2017-09-13 16:57:44 +00:00
|
|
|
createChildRow(_autoLock, marginSmall, slidedPadding, label, value, LabeledLink::Type::Primary, SLOT(onAutoLock()));
|
2016-08-28 19:16:23 +00:00
|
|
|
if (!Global::LocalPasscode()) {
|
2017-10-01 08:15:40 +00:00
|
|
|
_autoLock->hide(anim::type::instant);
|
2016-08-28 19:16:23 +00:00
|
|
|
}
|
2017-09-13 16:57:44 +00:00
|
|
|
createChildRow(_cloudPasswordState, marginSmall);
|
|
|
|
createChildRow(_showAllSessions, marginSmall, lang(lng_settings_show_sessions), SLOT(onShowSessions()));
|
|
|
|
createChildRow(_selfDestruction, marginSmall, lang(lng_settings_self_destruct), SLOT(onSelfDestruction()));
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-28 19:16:23 +00:00
|
|
|
void PrivacyWidget::autoLockUpdated() {
|
|
|
|
if (Global::LocalPasscode()) {
|
2017-04-18 17:37:14 +00:00
|
|
|
auto value = GetAutoLockText();
|
2016-08-28 19:16:23 +00:00
|
|
|
_autoLock->entity()->link()->setText(value);
|
|
|
|
resizeToWidth(width());
|
|
|
|
}
|
2017-10-01 08:15:40 +00:00
|
|
|
_autoLock->toggle(
|
|
|
|
Global::LocalPasscode(),
|
|
|
|
anim::type::normal);
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
|
|
|
|
2017-03-13 15:40:21 +00:00
|
|
|
void PrivacyWidget::onBlockedUsers() {
|
2017-08-17 08:31:24 +00:00
|
|
|
Ui::show(Box<PeerListBox>(std::make_unique<BlockedBoxController>(), [](not_null<PeerListBox*> box) {
|
2017-06-13 21:08:47 +00:00
|
|
|
box->addButton(langFactory(lng_close), [box] { box->closeBox(); });
|
|
|
|
box->addLeftButton(langFactory(lng_blocked_list_add), [box] { BlockedBoxController::BlockNewUser(); });
|
|
|
|
}));
|
2017-03-13 15:40:21 +00:00
|
|
|
}
|
|
|
|
|
2017-03-16 15:15:07 +00:00
|
|
|
void PrivacyWidget::onLastSeenPrivacy() {
|
|
|
|
Ui::show(Box<EditPrivacyBox>(std::make_unique<LastSeenPrivacyController>()));
|
|
|
|
}
|
|
|
|
|
2017-04-29 15:32:01 +00:00
|
|
|
void PrivacyWidget::onCallsPrivacy() {
|
|
|
|
Ui::show(Box<EditPrivacyBox>(std::make_unique<CallsPrivacyController>()));
|
|
|
|
}
|
|
|
|
|
2017-03-17 16:19:57 +00:00
|
|
|
void PrivacyWidget::onGroupsInvitePrivacy() {
|
|
|
|
Ui::show(Box<EditPrivacyBox>(std::make_unique<GroupsInvitePrivacyController>()));
|
|
|
|
}
|
|
|
|
|
2016-08-28 19:16:23 +00:00
|
|
|
void PrivacyWidget::onAutoLock() {
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<AutoLockBox>());
|
2016-08-19 17:26:31 +00:00
|
|
|
}
|
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
void PrivacyWidget::onShowSessions() {
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<SessionsBox>());
|
2016-08-19 17:26:31 +00:00
|
|
|
}
|
|
|
|
|
2017-03-20 15:41:17 +00:00
|
|
|
void PrivacyWidget::onSelfDestruction() {
|
|
|
|
Ui::show(Box<SelfDestructionBox>());
|
|
|
|
}
|
|
|
|
|
2016-08-19 17:26:31 +00:00
|
|
|
} // namespace Settings
|