mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-30 23:38:25 +00:00
Remember connection type settings.
This commit is contained in:
parent
7245319351
commit
9e6f2a5d2e
@ -43,6 +43,7 @@ void ConnectionBox::ShowApplyProxyConfirmation(const QMap<QString, QString> &fie
|
||||
p.password = fields.value(qsl("pass"));
|
||||
p.port = fields.value(qsl("port")).toInt();
|
||||
Global::SetConnectionType(dbictTcpProxy);
|
||||
Global::SetLastProxyType(dbictTcpProxy);
|
||||
Global::SetConnectionProxy(p);
|
||||
Local::writeSettings();
|
||||
Global::RefConnectionTypeChanged().notify();
|
||||
@ -79,13 +80,21 @@ void ConnectionBox::prepare() {
|
||||
connect(_portInput, SIGNAL(submitted(bool)), this, SLOT(onSubmit()));
|
||||
connect(_userInput, SIGNAL(submitted(bool)), this, SLOT(onSubmit()));
|
||||
connect(_passwordInput, SIGNAL(submitted(bool)), this, SLOT(onSubmit()));
|
||||
connect(_hostInput, SIGNAL(focused()), this, SLOT(onFieldFocus()));
|
||||
connect(_portInput, SIGNAL(focused()), this, SLOT(onFieldFocus()));
|
||||
connect(_userInput, SIGNAL(focused()), this, SLOT(onFieldFocus()));
|
||||
connect(_passwordInput, SIGNAL(focused()), this, SLOT(onFieldFocus()));
|
||||
|
||||
updateControlsVisibility();
|
||||
}
|
||||
|
||||
bool ConnectionBox::badProxyValue() const {
|
||||
return (_hostInput->getLastText().isEmpty() || !_portInput->getLastText().toInt());
|
||||
}
|
||||
|
||||
void ConnectionBox::updateControlsVisibility() {
|
||||
auto newHeight = st::boxOptionListPadding.top() + _autoRadio->heightNoMargins() + st::boxOptionListSkip + _httpProxyRadio->heightNoMargins() + st::boxOptionListSkip + _tcpProxyRadio->heightNoMargins() + st::boxOptionListSkip + st::connectionIPv6Skip + _tryIPv6->heightNoMargins() + st::boxOptionListPadding.bottom() + st::boxPadding.bottom();
|
||||
if (_typeGroup->value() == dbictAuto) {
|
||||
if (_typeGroup->value() == dbictAuto && badProxyValue()) {
|
||||
_hostInput->hide();
|
||||
_portInput->hide();
|
||||
_userInput->hide();
|
||||
@ -103,7 +112,7 @@ void ConnectionBox::updateControlsVisibility() {
|
||||
}
|
||||
|
||||
void ConnectionBox::setInnerFocus() {
|
||||
if (_hostInput->isHidden()) {
|
||||
if (_typeGroup->value() == dbictAuto) {
|
||||
setFocus();
|
||||
} else {
|
||||
_hostInput->setFocusFast();
|
||||
@ -122,12 +131,15 @@ void ConnectionBox::updateControlsPosition() {
|
||||
_httpProxyRadio->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), _autoRadio->bottomNoMargins() + st::boxOptionListSkip);
|
||||
|
||||
auto inputy = 0;
|
||||
if (type == dbictHttpProxy) {
|
||||
auto fieldsVisible = (type != dbictAuto) || (!badProxyValue() && Global::LastProxyType() != dbictAuto);
|
||||
auto fieldsBelowHttp = fieldsVisible && (type == dbictHttpProxy || (type == dbictAuto && Global::LastProxyType() == dbictHttpProxy));
|
||||
auto fieldsBelowTcp = fieldsVisible && (type == dbictTcpProxy || (type == dbictAuto && Global::LastProxyType() == dbictTcpProxy));
|
||||
if (fieldsBelowHttp) {
|
||||
inputy = _httpProxyRadio->bottomNoMargins() + st::boxOptionInputSkip;
|
||||
_tcpProxyRadio->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), inputy + st::boxOptionInputSkip + 2 * _hostInput->height() + st::boxOptionListSkip);
|
||||
} else {
|
||||
_tcpProxyRadio->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), _httpProxyRadio->bottomNoMargins() + st::boxOptionListSkip);
|
||||
if (type == dbictTcpProxy) {
|
||||
if (fieldsBelowTcp) {
|
||||
inputy = _tcpProxyRadio->bottomNoMargins() + st::boxOptionInputSkip;
|
||||
}
|
||||
}
|
||||
@ -139,13 +151,17 @@ void ConnectionBox::updateControlsPosition() {
|
||||
_passwordInput->moveToRight(st::boxPadding.right(), _userInput->y());
|
||||
}
|
||||
|
||||
auto tryipv6y = ((type == dbictTcpProxy) ? _userInput->bottomNoMargins() : _tcpProxyRadio->bottomNoMargins()) + st::boxOptionListSkip + st::connectionIPv6Skip;
|
||||
auto tryipv6y = (fieldsBelowTcp ? _userInput->bottomNoMargins() : _tcpProxyRadio->bottomNoMargins()) + st::boxOptionListSkip + st::connectionIPv6Skip;
|
||||
_tryIPv6->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), tryipv6y);
|
||||
}
|
||||
|
||||
void ConnectionBox::typeChanged(DBIConnectionType type) {
|
||||
if (type == dbictAuto) {
|
||||
setFocus();
|
||||
}
|
||||
updateControlsVisibility();
|
||||
if (type != dbictAuto) {
|
||||
Global::SetLastProxyType(type);
|
||||
if (!_hostInput->hasFocus() && !_portInput->hasFocus() && !_userInput->hasFocus() && !_passwordInput->hasFocus()) {
|
||||
_hostInput->setFocusFast();
|
||||
}
|
||||
@ -157,7 +173,16 @@ void ConnectionBox::typeChanged(DBIConnectionType type) {
|
||||
update();
|
||||
}
|
||||
|
||||
void ConnectionBox::onFieldFocus() {
|
||||
if (Global::LastProxyType() == dbictHttpProxy) {
|
||||
_typeGroup->setValue(dbictHttpProxy);
|
||||
} else if (Global::LastProxyType() == dbictTcpProxy) {
|
||||
_typeGroup->setValue(dbictTcpProxy);
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectionBox::onSubmit() {
|
||||
onFieldFocus();
|
||||
if (_hostInput->hasFocus()) {
|
||||
if (!_hostInput->getLastText().trimmed().isEmpty()) {
|
||||
_portInput->setFocus();
|
||||
@ -186,30 +211,33 @@ void ConnectionBox::onSubmit() {
|
||||
}
|
||||
|
||||
void ConnectionBox::onSave() {
|
||||
auto p = ProxyData();
|
||||
p.host = _hostInput->getLastText().trimmed();
|
||||
p.user = _userInput->getLastText().trimmed();
|
||||
p.password = _passwordInput->getLastText().trimmed();
|
||||
p.port = _portInput->getLastText().toInt();
|
||||
|
||||
auto type = _typeGroup->value();
|
||||
if (type == dbictAuto) {
|
||||
Global::SetConnectionType(type);
|
||||
Global::SetConnectionProxy(ProxyData());
|
||||
if (p.host.isEmpty() || !p.port) {
|
||||
p = ProxyData();
|
||||
}
|
||||
#ifndef TDESKTOP_DISABLE_NETWORK_PROXY
|
||||
QNetworkProxyFactory::setUseSystemConfiguration(false);
|
||||
QNetworkProxyFactory::setUseSystemConfiguration(true);
|
||||
#endif // !TDESKTOP_DISABLE_NETWORK_PROXY
|
||||
} else {
|
||||
ProxyData p;
|
||||
p.host = _hostInput->getLastText().trimmed();
|
||||
p.user = _userInput->getLastText().trimmed();
|
||||
p.password = _passwordInput->getLastText().trimmed();
|
||||
p.port = _portInput->getLastText().toInt();
|
||||
if (p.host.isEmpty()) {
|
||||
_hostInput->setFocus();
|
||||
_hostInput->showError();
|
||||
return;
|
||||
} else if (!p.port) {
|
||||
_portInput->setFocus();
|
||||
_portInput->showError();
|
||||
return;
|
||||
}
|
||||
Global::SetConnectionType(type);
|
||||
Global::SetConnectionProxy(p);
|
||||
Global::SetLastProxyType(type);
|
||||
}
|
||||
Global::SetConnectionType(type);
|
||||
Global::SetConnectionProxy(p);
|
||||
if (cPlatform() == dbipWindows && Global::TryIPv6() != _tryIPv6->checked()) {
|
||||
Global::SetTryIPv6(_tryIPv6->checked());
|
||||
Local::writeSettings();
|
||||
|
@ -49,12 +49,14 @@ protected:
|
||||
|
||||
private slots:
|
||||
void onSubmit();
|
||||
void onFieldFocus();
|
||||
void onSave();
|
||||
|
||||
private:
|
||||
void typeChanged(DBIConnectionType type);
|
||||
void updateControlsVisibility();
|
||||
void updateControlsPosition();
|
||||
bool badProxyValue() const;
|
||||
|
||||
object_ptr<Ui::InputField> _hostInput;
|
||||
object_ptr<Ui::PortInput> _portInput;
|
||||
|
@ -664,6 +664,7 @@ struct Data {
|
||||
bool NotificationsDemoIsShown = false;
|
||||
|
||||
DBIConnectionType ConnectionType = dbictAuto;
|
||||
DBIConnectionType LastProxyType = dbictAuto;
|
||||
bool TryIPv6 = (cPlatform() == dbipWindows) ? false : true;
|
||||
ProxyData ConnectionProxy;
|
||||
base::Observable<void> ConnectionTypeChanged;
|
||||
@ -784,6 +785,7 @@ DefineVar(Global, Notify::ScreenCorner, NotificationsCorner);
|
||||
DefineVar(Global, bool, NotificationsDemoIsShown);
|
||||
|
||||
DefineVar(Global, DBIConnectionType, ConnectionType);
|
||||
DefineVar(Global, DBIConnectionType, LastProxyType);
|
||||
DefineVar(Global, bool, TryIPv6);
|
||||
DefineVar(Global, ProxyData, ConnectionProxy);
|
||||
DefineRefVar(Global, base::Observable<void>, ConnectionTypeChanged);
|
||||
|
@ -377,6 +377,7 @@ DeclareVar(Notify::ScreenCorner, NotificationsCorner);
|
||||
DeclareVar(bool, NotificationsDemoIsShown);
|
||||
|
||||
DeclareVar(DBIConnectionType, ConnectionType);
|
||||
DeclareVar(DBIConnectionType, LastProxyType);
|
||||
DeclareVar(bool, TryIPv6);
|
||||
DeclareVar(ProxyData, ConnectionProxy);
|
||||
DeclareRefVar(base::Observable<void>, ConnectionTypeChanged);
|
||||
|
@ -522,7 +522,7 @@ enum {
|
||||
dbiAutoUpdate = 0x0c,
|
||||
dbiLastUpdateCheck = 0x0d,
|
||||
dbiWindowPosition = 0x0e,
|
||||
dbiConnectionType = 0x0f,
|
||||
dbiConnectionTypeOld = 0x0f,
|
||||
// 0x10 reserved
|
||||
dbiDefaultAttach = 0x11,
|
||||
dbiCatsAndDogs = 0x12,
|
||||
@ -576,6 +576,7 @@ enum {
|
||||
dbiLastSeenWarningSeenOld = 0x4c,
|
||||
dbiAuthSessionData = 0x4d,
|
||||
dbiLangPackKey = 0x4e,
|
||||
dbiConnectionType = 0x4f,
|
||||
|
||||
dbiEncryptedWithSalt = 333,
|
||||
dbiEncrypted = 444,
|
||||
@ -1128,7 +1129,7 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting
|
||||
Global::RefWorkMode().set(newMode());
|
||||
} break;
|
||||
|
||||
case dbiConnectionType: {
|
||||
case dbiConnectionTypeOld: {
|
||||
qint32 v;
|
||||
stream >> v;
|
||||
if (!_checkStreamStatus(stream)) return false;
|
||||
@ -1148,6 +1149,36 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting
|
||||
case dbictHttpAuto:
|
||||
default: Global::SetConnectionType(dbictAuto); break;
|
||||
};
|
||||
Global::SetLastProxyType(Global::ConnectionType());
|
||||
} break;
|
||||
|
||||
case dbiConnectionType: {
|
||||
ProxyData p;
|
||||
qint32 connectionType, lastProxyType, port;
|
||||
stream >> connectionType >> lastProxyType >> p.host >> port >> p.user >> p.password;
|
||||
if (!_checkStreamStatus(stream)) return false;
|
||||
|
||||
p.port = port;
|
||||
switch (connectionType) {
|
||||
case dbictHttpProxy:
|
||||
case dbictTcpProxy: {
|
||||
Global::SetConnectionType(DBIConnectionType(lastProxyType));
|
||||
} break;
|
||||
case dbictHttpAuto:
|
||||
default: Global::SetConnectionType(dbictAuto); break;
|
||||
};
|
||||
switch (lastProxyType) {
|
||||
case dbictHttpProxy:
|
||||
case dbictTcpProxy: {
|
||||
Global::SetLastProxyType(DBIConnectionType(lastProxyType));
|
||||
Global::SetConnectionProxy(p);
|
||||
} break;
|
||||
case dbictHttpAuto:
|
||||
default: {
|
||||
Global::SetLastProxyType(dbictAuto);
|
||||
Global::SetConnectionProxy(ProxyData());
|
||||
} break;
|
||||
}
|
||||
} break;
|
||||
|
||||
case dbiThemeKey: {
|
||||
@ -2310,11 +2341,10 @@ void writeSettings() {
|
||||
quint32 size = 12 * (sizeof(quint32) + sizeof(qint32));
|
||||
size += sizeof(quint32) + Serialize::bytearraySize(dcOptionsSerialized);
|
||||
|
||||
size += sizeof(quint32) + sizeof(qint32);
|
||||
if (Global::ConnectionType() == dbictHttpProxy || Global::ConnectionType() == dbictTcpProxy) {
|
||||
auto &proxy = Global::ConnectionProxy();
|
||||
size += Serialize::stringSize(proxy.host) + sizeof(qint32) + Serialize::stringSize(proxy.user) + Serialize::stringSize(proxy.password);
|
||||
}
|
||||
auto &proxy = Global::ConnectionProxy();
|
||||
size += sizeof(quint32) + sizeof(qint32) + sizeof(qint32);
|
||||
size += Serialize::stringSize(proxy.host) + sizeof(qint32) + Serialize::stringSize(proxy.user) + Serialize::stringSize(proxy.password);
|
||||
|
||||
if (_themeKey) {
|
||||
size += sizeof(quint32) + sizeof(quint64);
|
||||
}
|
||||
@ -2338,11 +2368,9 @@ void writeSettings() {
|
||||
data.stream << quint32(dbiScale) << qint32(cConfigScale());
|
||||
data.stream << quint32(dbiDcOptions) << dcOptionsSerialized;
|
||||
|
||||
data.stream << quint32(dbiConnectionType) << qint32(Global::ConnectionType());
|
||||
if (Global::ConnectionType() == dbictHttpProxy || Global::ConnectionType() == dbictTcpProxy) {
|
||||
auto &proxy = Global::ConnectionProxy();
|
||||
data.stream << proxy.host << qint32(proxy.port) << proxy.user << proxy.password;
|
||||
}
|
||||
data.stream << quint32(dbiConnectionType) << qint32(Global::ConnectionType()) << qint32(Global::LastProxyType());
|
||||
data.stream << proxy.host << qint32(proxy.port) << proxy.user << proxy.password;
|
||||
|
||||
data.stream << quint32(dbiTryIPv6) << qint32(Global::TryIPv6());
|
||||
if (_themeKey) {
|
||||
data.stream << quint32(dbiThemeKey) << quint64(_themeKey);
|
||||
|
Loading…
Reference in New Issue
Block a user