mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-09-05 09:05:14 +00:00
First version of the new Settings page is finished.
Added LocalStorageBox for watching info and clearing local storage. Local passcode and cloud password state display and editing done. Temporary download location clearing link added. Crash fixed in local storage clear + app close, now waiting for the clearing thread to quit. Some design improvements and testing.
This commit is contained in:
@@ -21,32 +21,181 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
||||
#include "stdafx.h"
|
||||
#include "settings/settings_privacy_widget.h"
|
||||
|
||||
#include "ui/widgets/widget_slide_wrap.h"
|
||||
#include "styles/style_settings.h"
|
||||
#include "lang.h"
|
||||
#include "application.h"
|
||||
#include "boxes/sessionsbox.h"
|
||||
#include "boxes/passcodebox.h"
|
||||
#include "boxes/autolockbox.h"
|
||||
#include "pspecific.h"
|
||||
|
||||
namespace Settings {
|
||||
|
||||
PrivacyWidget::PrivacyWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, lang(lng_settings_section_privacy)) {
|
||||
refreshControls();
|
||||
LocalPasscodeState::LocalPasscodeState(QWidget *parent) : TWidget(parent)
|
||||
, _edit(this, lang(Global::LocalPasscode() ? lng_passcode_change : lng_passcode_turn_on), st::defaultBoxLinkButton)
|
||||
, _turnOff(this, lang(lng_passcode_turn_off), st::defaultBoxLinkButton) {
|
||||
updateControls();
|
||||
connect(_edit, SIGNAL(clicked()), this, SLOT(onEdit()));
|
||||
connect(_turnOff, SIGNAL(clicked()), this, SLOT(onTurnOff()));
|
||||
subscribe(Global::RefLocalPasscodeChanged(), [this]() { updateControls(); });
|
||||
}
|
||||
|
||||
void PrivacyWidget::refreshControls() {
|
||||
int LocalPasscodeState::resizeGetHeight(int newWidth) {
|
||||
_edit->moveToLeft(0, 0, newWidth);
|
||||
_turnOff->moveToRight(0, 0, newWidth);
|
||||
return _edit->height();
|
||||
}
|
||||
|
||||
void LocalPasscodeState::onEdit() {
|
||||
Ui::showLayer(new PasscodeBox());
|
||||
}
|
||||
|
||||
void LocalPasscodeState::onTurnOff() {
|
||||
Ui::showLayer(new PasscodeBox(true));
|
||||
}
|
||||
|
||||
void LocalPasscodeState::updateControls() {
|
||||
_edit->setText(lang(Global::LocalPasscode() ? lng_passcode_change : lng_passcode_turn_on));
|
||||
_edit->moveToLeft(0, 0);
|
||||
_turnOff->setVisible(Global::LocalPasscode());
|
||||
}
|
||||
|
||||
CloudPasswordState::CloudPasswordState(QWidget *parent) : TWidget(parent)
|
||||
, _edit(this, lang(lng_cloud_password_set), st::defaultBoxLinkButton)
|
||||
, _turnOff(this, lang(lng_passcode_turn_off), st::defaultBoxLinkButton) {
|
||||
_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() {
|
||||
PasscodeBox *box = new PasscodeBox(_newPasswordSalt, _curPasswordSalt, _hasPasswordRecovery, _curPasswordHint);
|
||||
connect(box, SIGNAL(reloadPassword()), this, SLOT(onReloadPassword()));
|
||||
Ui::showLayer(box);
|
||||
}
|
||||
|
||||
void CloudPasswordState::onTurnOff() {
|
||||
if (_curPasswordSalt.isEmpty()) {
|
||||
_turnOff->hide();
|
||||
|
||||
MTPDaccount_passwordInputSettings::Flags flags = MTPDaccount_passwordInputSettings::Flag::f_email;
|
||||
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 {
|
||||
PasscodeBox *box = new PasscodeBox(_newPasswordSalt, _curPasswordSalt, _hasPasswordRecovery, _curPasswordHint, true);
|
||||
connect(box, SIGNAL(reloadPassword()), this, SLOT(onReloadPassword()));
|
||||
Ui::showLayer(box);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
auto text = st::linkFont->elided(_waitingConfirm, width() - _turnOff->width());
|
||||
if (!text.isEmpty()) {
|
||||
p.setPen(st::windowTextFg);
|
||||
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;
|
||||
}
|
||||
|
||||
PrivacyWidget::PrivacyWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, lang(lng_settings_section_privacy)) {
|
||||
createControls();
|
||||
subscribe(Global::RefLocalPasscodeChanged(), [this]() { autoLockUpdated(); });
|
||||
}
|
||||
|
||||
void PrivacyWidget::createControls() {
|
||||
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));
|
||||
|
||||
addChildRow(_editPasscode, marginSmall, lang(lng_passcode_turn_on), SLOT(onEditPasscode()));
|
||||
addChildRow(_editPassword, marginSmall, lang(lng_cloud_password_set), SLOT(onEditPassword()));
|
||||
addChildRow(_localPasscodeState, marginSmall);
|
||||
auto label = lang(psIdleSupported() ? lng_passcode_autolock_away : lng_passcode_autolock_inactive);
|
||||
auto value = (Global::AutoLock() % 3600) ? lng_passcode_autolock_minutes(lt_count, Global::AutoLock() / 60) : lng_passcode_autolock_hours(lt_count, Global::AutoLock() / 3600);
|
||||
addChildRow(_autoLock, marginSmall, slidedPadding, label, value, LabeledLink::Type::Primary, SLOT(onAutoLock()));
|
||||
if (!Global::LocalPasscode()) {
|
||||
_autoLock->hideFast();
|
||||
}
|
||||
addChildRow(_cloudPasswordState, marginSmall);
|
||||
addChildRow(_showAllSessions, marginSmall, lang(lng_settings_show_sessions), SLOT(onShowSessions()));
|
||||
}
|
||||
|
||||
void PrivacyWidget::onEditPasscode() {
|
||||
|
||||
void PrivacyWidget::autoLockUpdated() {
|
||||
if (Global::LocalPasscode()) {
|
||||
auto value = (Global::AutoLock() % 3600) ? lng_passcode_autolock_minutes(lt_count, Global::AutoLock() / 60) : lng_passcode_autolock_hours(lt_count, Global::AutoLock() / 3600);
|
||||
_autoLock->entity()->link()->setText(value);
|
||||
resizeToWidth(width());
|
||||
_autoLock->slideDown();
|
||||
} else {
|
||||
_autoLock->slideUp();
|
||||
}
|
||||
}
|
||||
|
||||
void PrivacyWidget::onEditPassword() {
|
||||
|
||||
void PrivacyWidget::onAutoLock() {
|
||||
Ui::showLayer(new AutoLockBox());
|
||||
}
|
||||
|
||||
void PrivacyWidget::onShowSessions() {
|
||||
|
Reference in New Issue
Block a user