mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 06:35:14 +00:00
Display channels promoted by proxy on top.
This commit is contained in:
@@ -897,240 +897,6 @@ void ProxyBox::addLabel(
|
||||
|
||||
} // namespace
|
||||
|
||||
void ConnectionBox::ShowApplyProxyConfirmation(
|
||||
Type type,
|
||||
const QMap<QString, QString> &fields) {
|
||||
const auto server = fields.value(qsl("server"));
|
||||
const auto port = fields.value(qsl("port")).toUInt();
|
||||
auto proxy = ProxyData();
|
||||
proxy.type = type;
|
||||
proxy.host = server;
|
||||
proxy.port = port;
|
||||
if (type == Type::Socks5) {
|
||||
proxy.user = fields.value(qsl("user"));
|
||||
proxy.password = fields.value(qsl("pass"));
|
||||
} else if (type == Type::Mtproto) {
|
||||
proxy.password = fields.value(qsl("secret"));
|
||||
}
|
||||
if (proxy) {
|
||||
const auto box = std::make_shared<QPointer<ConfirmBox>>();
|
||||
const auto text = lng_sure_enable_socks(
|
||||
lt_server,
|
||||
server,
|
||||
lt_port,
|
||||
QString::number(port));
|
||||
*box = Ui::show(Box<ConfirmBox>(text, lang(lng_sure_enable), [=] {
|
||||
auto &proxies = Global::RefProxiesList();
|
||||
if (ranges::find(proxies, proxy) == end(proxies)) {
|
||||
proxies.push_back(proxy);
|
||||
}
|
||||
Global::SetSelectedProxy(proxy);
|
||||
Global::SetUseProxy(true);
|
||||
Local::writeSettings();
|
||||
Sandbox::refreshGlobalProxy();
|
||||
Global::RefConnectionTypeChanged().notify();
|
||||
MTP::restart();
|
||||
if (const auto strong = box->data()) {
|
||||
strong->closeBox();
|
||||
}
|
||||
}), LayerOption::KeepOther);
|
||||
}
|
||||
}
|
||||
|
||||
ConnectionBox::ConnectionBox(QWidget *parent)
|
||||
: _hostInput(this, st::connectionHostInputField, langFactory(lng_connection_host_ph), Global::SelectedProxy().host)
|
||||
, _portInput(this, st::connectionPortInputField, langFactory(lng_connection_port_ph), QString::number(Global::SelectedProxy().port))
|
||||
, _userInput(this, st::connectionUserInputField, langFactory(lng_connection_user_ph), Global::SelectedProxy().user)
|
||||
, _passwordInput(this, st::connectionPasswordInputField, langFactory(lng_connection_password_ph), Global::SelectedProxy().password)
|
||||
, _typeGroup(std::make_shared<Ui::RadioenumGroup<Type>>(Global::SelectedProxy().type))
|
||||
, _autoRadio(this, _typeGroup, Type::None, lang(lng_connection_auto_rb), st::defaultBoxCheckbox)
|
||||
, _httpProxyRadio(this, _typeGroup, Type::Http, lang(lng_connection_http_proxy_rb), st::defaultBoxCheckbox)
|
||||
, _tcpProxyRadio(this, _typeGroup, Type::Socks5, lang(lng_connection_tcp_proxy_rb), st::defaultBoxCheckbox)
|
||||
, _tryIPv6(this, lang(lng_connection_try_ipv6), Global::TryIPv6(), st::defaultBoxCheckbox) {
|
||||
}
|
||||
|
||||
void ConnectionBox::prepare() {
|
||||
setTitle(langFactory(lng_connection_header));
|
||||
|
||||
addButton(langFactory(lng_connection_save), [this] { onSave(); });
|
||||
addButton(langFactory(lng_cancel), [this] { closeBox(); });
|
||||
|
||||
_typeGroup->setChangedCallback([this](Type value) { typeChanged(value); });
|
||||
|
||||
connect(_hostInput, SIGNAL(submitted(bool)), this, SLOT(onSubmit()));
|
||||
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::defaultCheckbox.margin.bottom() + st::boxOptionListPadding.bottom() + st::boxPadding.bottom();
|
||||
if (!proxyFieldsVisible()) {
|
||||
_hostInput->hide();
|
||||
_portInput->hide();
|
||||
_userInput->hide();
|
||||
_passwordInput->hide();
|
||||
} else {
|
||||
newHeight += 2 * st::boxOptionInputSkip + 2 * _hostInput->height();
|
||||
_hostInput->show();
|
||||
_portInput->show();
|
||||
_userInput->show();
|
||||
_passwordInput->show();
|
||||
}
|
||||
|
||||
setDimensions(st::boxWidth, newHeight);
|
||||
updateControlsPosition();
|
||||
}
|
||||
|
||||
bool ConnectionBox::proxyFieldsVisible() const {
|
||||
return (_typeGroup->value() == Type::Http
|
||||
|| _typeGroup->value() == Type::Socks5);
|
||||
}
|
||||
|
||||
void ConnectionBox::setInnerFocus() {
|
||||
if (proxyFieldsVisible()) {
|
||||
_hostInput->setFocusFast();
|
||||
} else {
|
||||
setFocus();
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectionBox::resizeEvent(QResizeEvent *e) {
|
||||
BoxContent::resizeEvent(e);
|
||||
|
||||
updateControlsPosition();
|
||||
}
|
||||
|
||||
void ConnectionBox::updateControlsPosition() {
|
||||
auto type = _typeGroup->value();
|
||||
_autoRadio->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), _autoRadio->getMargins().top() + st::boxOptionListPadding.top());
|
||||
_httpProxyRadio->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), _autoRadio->bottomNoMargins() + st::boxOptionListSkip);
|
||||
|
||||
auto inputy = 0;
|
||||
auto fieldsVisible = proxyFieldsVisible();
|
||||
auto fieldsBelowHttp = fieldsVisible && (type == Type::Http);
|
||||
auto fieldsBelowTcp = fieldsVisible && (type == Type::Socks5);
|
||||
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 (fieldsBelowTcp) {
|
||||
inputy = _tcpProxyRadio->bottomNoMargins() + st::boxOptionInputSkip;
|
||||
}
|
||||
}
|
||||
|
||||
if (inputy) {
|
||||
_hostInput->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left() + st::defaultCheck.diameter + st::defaultBoxCheckbox.textPosition.x() - st::defaultInputField.textMargins.left(), inputy);
|
||||
_portInput->moveToRight(st::boxPadding.right(), inputy);
|
||||
_userInput->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left() + st::defaultCheck.diameter + st::defaultBoxCheckbox.textPosition.x() - st::defaultInputField.textMargins.left(), _hostInput->y() + _hostInput->height() + st::boxOptionInputSkip);
|
||||
_passwordInput->moveToRight(st::boxPadding.right(), _userInput->y());
|
||||
}
|
||||
|
||||
auto tryipv6y = (fieldsBelowTcp ? _userInput->bottomNoMargins() : _tcpProxyRadio->bottomNoMargins()) + st::boxOptionListSkip + st::connectionIPv6Skip;
|
||||
_tryIPv6->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), tryipv6y);
|
||||
}
|
||||
|
||||
void ConnectionBox::typeChanged(Type type) {
|
||||
if (!proxyFieldsVisible()) {
|
||||
setFocus();
|
||||
}
|
||||
updateControlsVisibility();
|
||||
if (proxyFieldsVisible()) {
|
||||
if (!_hostInput->hasFocus() && !_portInput->hasFocus() && !_userInput->hasFocus() && !_passwordInput->hasFocus()) {
|
||||
_hostInput->setFocusFast();
|
||||
}
|
||||
if ((type == Type::Http) && !_portInput->getLastText().toInt()) {
|
||||
_portInput->setText(qsl("80"));
|
||||
_portInput->finishAnimating();
|
||||
}
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
void ConnectionBox::onFieldFocus() {
|
||||
}
|
||||
|
||||
void ConnectionBox::onSubmit() {
|
||||
onFieldFocus();
|
||||
if (_hostInput->hasFocus()) {
|
||||
if (!_hostInput->getLastText().trimmed().isEmpty()) {
|
||||
_portInput->setFocus();
|
||||
} else {
|
||||
_hostInput->showError();
|
||||
}
|
||||
} else if (_portInput->hasFocus()) {
|
||||
if (_portInput->getLastText().trimmed().toInt() > 0) {
|
||||
_userInput->setFocus();
|
||||
} else {
|
||||
_portInput->showError();
|
||||
}
|
||||
} else if (_userInput->hasFocus()) {
|
||||
_passwordInput->setFocus();
|
||||
} else if (_passwordInput->hasFocus()) {
|
||||
if (_hostInput->getLastText().trimmed().isEmpty()) {
|
||||
_hostInput->setFocus();
|
||||
_hostInput->showError();
|
||||
} else if (_portInput->getLastText().trimmed().toInt() <= 0) {
|
||||
_portInput->setFocus();
|
||||
_portInput->showError();
|
||||
} else {
|
||||
onSave();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectionBox::onSave() {
|
||||
auto proxy = ProxyData();
|
||||
proxy.host = _hostInput->getLastText().trimmed();
|
||||
proxy.user = _userInput->getLastText().trimmed();
|
||||
proxy.password = _passwordInput->getLastText().trimmed();
|
||||
proxy.port = _portInput->getLastText().toUInt();
|
||||
|
||||
auto type = _typeGroup->value();
|
||||
if (type == Type::None) {
|
||||
proxy = ProxyData();
|
||||
} else if (type == Type::Mtproto) {
|
||||
proxy = Global::SelectedProxy();
|
||||
} else {
|
||||
if (proxy.host.isEmpty()) {
|
||||
_hostInput->showError();
|
||||
return;
|
||||
} else if (!proxy.port) {
|
||||
_portInput->showError();
|
||||
return;
|
||||
}
|
||||
proxy.type = type;
|
||||
}
|
||||
Global::SetSelectedProxy(proxy ? proxy : ProxyData());
|
||||
Global::SetUseProxy(proxy ? true : false);
|
||||
if (cPlatform() == dbipWindows && Global::TryIPv6() != _tryIPv6->checked()) {
|
||||
Global::SetTryIPv6(_tryIPv6->checked());
|
||||
Local::writeSettings();
|
||||
Global::RefConnectionTypeChanged().notify();
|
||||
|
||||
App::restart();
|
||||
} else {
|
||||
Global::SetTryIPv6(_tryIPv6->checked());
|
||||
Local::writeSettings();
|
||||
Sandbox::refreshGlobalProxy();
|
||||
Global::RefConnectionTypeChanged().notify();
|
||||
|
||||
MTP::restart();
|
||||
closeBox();
|
||||
}
|
||||
}
|
||||
|
||||
AutoDownloadBox::AutoDownloadBox(QWidget *parent)
|
||||
: _photoPrivate(this, lang(lng_media_auto_private_chats), !(cAutoDownloadPhoto() & dbiadNoPrivate), st::defaultBoxCheckbox)
|
||||
, _photoGroups(this, lang(lng_media_auto_groups), !(cAutoDownloadPhoto() & dbiadNoGroups), st::defaultBoxCheckbox)
|
||||
@@ -1259,6 +1025,42 @@ ProxiesBoxController::ProxiesBoxController()
|
||||
}
|
||||
}
|
||||
|
||||
void ProxiesBoxController::ShowApplyConfirmation(
|
||||
Type type,
|
||||
const QMap<QString, QString> &fields) {
|
||||
const auto server = fields.value(qsl("server"));
|
||||
const auto port = fields.value(qsl("port")).toUInt();
|
||||
auto proxy = ProxyData();
|
||||
proxy.type = type;
|
||||
proxy.host = server;
|
||||
proxy.port = port;
|
||||
if (type == Type::Socks5) {
|
||||
proxy.user = fields.value(qsl("user"));
|
||||
proxy.password = fields.value(qsl("pass"));
|
||||
} else if (type == Type::Mtproto) {
|
||||
proxy.password = fields.value(qsl("secret"));
|
||||
}
|
||||
if (proxy) {
|
||||
const auto box = std::make_shared<QPointer<ConfirmBox>>();
|
||||
const auto text = lng_sure_enable_socks(
|
||||
lt_server,
|
||||
server,
|
||||
lt_port,
|
||||
QString::number(port));
|
||||
*box = Ui::show(Box<ConfirmBox>(text, lang(lng_sure_enable), [=] {
|
||||
auto &proxies = Global::RefProxiesList();
|
||||
if (ranges::find(proxies, proxy) == end(proxies)) {
|
||||
proxies.push_back(proxy);
|
||||
}
|
||||
Messenger::Instance().mtp()->setCurrentProxy(proxy, true);
|
||||
Local::writeSettings();
|
||||
if (const auto strong = box->data()) {
|
||||
strong->closeBox();
|
||||
}
|
||||
}), LayerOption::KeepOther);
|
||||
}
|
||||
}
|
||||
|
||||
rpl::producer<bool> ProxiesBoxController::proxyEnabledValue() const {
|
||||
return _proxyEnabledChanges.events_starting_with_copy(
|
||||
Global::UseProxy()
|
||||
@@ -1411,9 +1213,8 @@ void ProxiesBoxController::applyItem(int id) {
|
||||
|
||||
auto j = findByProxy(Global::SelectedProxy());
|
||||
|
||||
Global::SetSelectedProxy(item->data);
|
||||
Global::SetUseProxy(true);
|
||||
applyChanges();
|
||||
Messenger::Instance().mtp()->setCurrentProxy(item->data, true);
|
||||
saveDelayed();
|
||||
|
||||
if (j != end(_list)) {
|
||||
updateView(*j);
|
||||
@@ -1433,8 +1234,10 @@ void ProxiesBoxController::setDeleted(int id, bool deleted) {
|
||||
_lastSelectedProxy = base::take(Global::RefSelectedProxy());
|
||||
if (Global::UseProxy()) {
|
||||
_lastSelectedProxyUsed = true;
|
||||
Global::SetUseProxy(false);
|
||||
applyChanges();
|
||||
Messenger::Instance().mtp()->setCurrentProxy(
|
||||
ProxyData(),
|
||||
false);
|
||||
saveDelayed();
|
||||
} else {
|
||||
_lastSelectedProxyUsed = false;
|
||||
}
|
||||
@@ -1455,10 +1258,12 @@ void ProxiesBoxController::setDeleted(int id, bool deleted) {
|
||||
if (!Global::SelectedProxy() && _lastSelectedProxy == item->data) {
|
||||
Assert(!Global::UseProxy());
|
||||
|
||||
Global::SetSelectedProxy(base::take(_lastSelectedProxy));
|
||||
if (base::take(_lastSelectedProxyUsed)) {
|
||||
Global::SetUseProxy(true);
|
||||
applyChanges();
|
||||
Messenger::Instance().mtp()->setCurrentProxy(
|
||||
base::take(_lastSelectedProxy),
|
||||
true);
|
||||
} else {
|
||||
Global::SetSelectedProxy(base::take(_lastSelectedProxy));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1559,8 +1364,10 @@ bool ProxiesBoxController::setProxyEnabled(bool enabled) {
|
||||
}
|
||||
}
|
||||
}
|
||||
Global::SetUseProxy(enabled);
|
||||
applyChanges();
|
||||
Messenger::Instance().mtp()->setCurrentProxy(
|
||||
Global::SelectedProxy(),
|
||||
enabled);
|
||||
saveDelayed();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1580,13 +1387,8 @@ void ProxiesBoxController::setTryIPv6(bool enabled) {
|
||||
return;
|
||||
}
|
||||
Global::SetTryIPv6(enabled);
|
||||
applyChanges();
|
||||
}
|
||||
|
||||
void ProxiesBoxController::applyChanges() {
|
||||
Sandbox::refreshGlobalProxy();
|
||||
Global::RefConnectionTypeChanged().notify();
|
||||
MTP::restart();
|
||||
Global::RefConnectionTypeChanged().notify();
|
||||
saveDelayed();
|
||||
}
|
||||
|
||||
|
@@ -22,48 +22,6 @@ template <typename Enum>
|
||||
class Radioenum;
|
||||
} // namespace Ui
|
||||
|
||||
class ConnectionBox : public BoxContent {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
using Type = ProxyData::Type;
|
||||
|
||||
ConnectionBox(QWidget *parent);
|
||||
|
||||
static void ShowApplyProxyConfirmation(
|
||||
Type type,
|
||||
const QMap<QString, QString> &fields);
|
||||
|
||||
protected:
|
||||
void prepare() override;
|
||||
void setInnerFocus() override;
|
||||
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
|
||||
private slots:
|
||||
void onSubmit();
|
||||
void onFieldFocus();
|
||||
void onSave();
|
||||
|
||||
private:
|
||||
void typeChanged(Type type);
|
||||
void updateControlsVisibility();
|
||||
void updateControlsPosition();
|
||||
bool badProxyValue() const;
|
||||
bool proxyFieldsVisible() const;
|
||||
|
||||
object_ptr<Ui::InputField> _hostInput;
|
||||
object_ptr<Ui::PortInput> _portInput;
|
||||
object_ptr<Ui::InputField> _userInput;
|
||||
object_ptr<Ui::PasswordInput> _passwordInput;
|
||||
std::shared_ptr<Ui::RadioenumGroup<Type>> _typeGroup;
|
||||
object_ptr<Ui::Radioenum<Type>> _autoRadio;
|
||||
object_ptr<Ui::Radioenum<Type>> _httpProxyRadio;
|
||||
object_ptr<Ui::Radioenum<Type>> _tcpProxyRadio;
|
||||
object_ptr<Ui::Checkbox> _tryIPv6;
|
||||
|
||||
};
|
||||
|
||||
class AutoDownloadBox : public BoxContent {
|
||||
Q_OBJECT
|
||||
|
||||
@@ -98,6 +56,10 @@ public:
|
||||
|
||||
ProxiesBoxController();
|
||||
|
||||
static void ShowApplyConfirmation(
|
||||
Type type,
|
||||
const QMap<QString, QString> &fields);
|
||||
|
||||
static object_ptr<BoxContent> CreateOwningBox();
|
||||
object_ptr<BoxContent> create();
|
||||
|
||||
@@ -155,7 +117,6 @@ private:
|
||||
void setDeleted(int id, bool deleted);
|
||||
void updateView(const Item &item);
|
||||
void share(const ProxyData &proxy);
|
||||
void applyChanges();
|
||||
void saveDelayed();
|
||||
void refreshChecker(Item &item);
|
||||
void setupChecker(int id, const Checker &checker);
|
||||
|
Reference in New Issue
Block a user