mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Accept IPv4:port in proxy host input field.
This commit is contained in:
parent
4b1e9e3b9d
commit
5d32ba5867
1 changed files with 31 additions and 4 deletions
|
@ -171,7 +171,7 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class ProxyBox : public Ui::BoxContent {
|
class ProxyBox final : public Ui::BoxContent {
|
||||||
public:
|
public:
|
||||||
ProxyBox(
|
ProxyBox(
|
||||||
QWidget*,
|
QWidget*,
|
||||||
|
@ -179,12 +179,14 @@ public:
|
||||||
Fn<void(ProxyData)> callback,
|
Fn<void(ProxyData)> callback,
|
||||||
Fn<void(ProxyData)> shareCallback);
|
Fn<void(ProxyData)> shareCallback);
|
||||||
|
|
||||||
protected:
|
|
||||||
void prepare() override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using Type = ProxyData::Type;
|
using Type = ProxyData::Type;
|
||||||
|
|
||||||
|
void prepare() override;
|
||||||
|
void setInnerFocus() override {
|
||||||
|
_host->setFocusFast();
|
||||||
|
}
|
||||||
|
|
||||||
void refreshButtons();
|
void refreshButtons();
|
||||||
ProxyData collectData();
|
ProxyData collectData();
|
||||||
void save();
|
void save();
|
||||||
|
@ -765,6 +767,31 @@ ProxyBox::ProxyBox(
|
||||||
void ProxyBox::prepare() {
|
void ProxyBox::prepare() {
|
||||||
setTitle(tr::lng_proxy_edit());
|
setTitle(tr::lng_proxy_edit());
|
||||||
|
|
||||||
|
connect(_host.data(), &Ui::InputField::changed, [=] {
|
||||||
|
Ui::PostponeCall(_host, [=] {
|
||||||
|
const auto host = _host->getLastText().trimmed();
|
||||||
|
static const auto mask = u"^\\d+\\.\\d+\\.\\d+\\.\\d+:(\\d*)$"_q;
|
||||||
|
const auto match = QRegularExpression(mask).match(host);
|
||||||
|
if (_host->textCursor().position() == host.size()
|
||||||
|
&& match.hasMatch()) {
|
||||||
|
const auto port = match.captured(1);
|
||||||
|
_port->setText(port);
|
||||||
|
_port->setCursorPosition(port.size());
|
||||||
|
_port->setFocus();
|
||||||
|
_host->setText(host.mid(0, host.size() - port.size() - 1));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
_port.data()->events(
|
||||||
|
) | rpl::start_with_next([=](not_null<QEvent*> e) {
|
||||||
|
if (e->type() == QEvent::KeyPress
|
||||||
|
&& (static_cast<QKeyEvent*>(e.get())->key() == Qt::Key_Backspace)
|
||||||
|
&& _port->cursorPosition() == 0) {
|
||||||
|
_host->setCursorPosition(_host->getLastText().size());
|
||||||
|
_host->setFocus();
|
||||||
|
}
|
||||||
|
}, _port->lifetime());
|
||||||
|
|
||||||
refreshButtons();
|
refreshButtons();
|
||||||
setDimensionsToContent(st::boxWideWidth, _content);
|
setDimensionsToContent(st::boxWideWidth, _content);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue