2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/connection_box.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2021-10-18 21:36:55 +00:00
|
|
|
#include "ui/boxes/confirm_box.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2018-04-28 15:58:22 +00:00
|
|
|
#include "base/qthelp_url.h"
|
2019-09-26 10:55:35 +00:00
|
|
|
#include "base/call_delayed.h"
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "core/application.h"
|
2021-06-10 22:49:08 +00:00
|
|
|
#include "core/core_settings.h"
|
2019-07-24 08:46:23 +00:00
|
|
|
#include "main/main_account.h"
|
2019-12-05 08:32:33 +00:00
|
|
|
#include "mtproto/facade.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/checkbox.h"
|
|
|
|
#include "ui/widgets/buttons.h"
|
2023-08-31 11:21:24 +00:00
|
|
|
#include "ui/widgets/fields/input_field.h"
|
|
|
|
#include "ui/widgets/fields/number_input.h"
|
|
|
|
#include "ui/widgets/fields/password_input.h"
|
2018-04-28 15:58:22 +00:00
|
|
|
#include "ui/widgets/labels.h"
|
2018-05-05 13:14:46 +00:00
|
|
|
#include "ui/widgets/dropdown_menu.h"
|
2018-04-28 15:58:22 +00:00
|
|
|
#include "ui/wrap/slide_wrap.h"
|
2018-04-28 09:27:43 +00:00
|
|
|
#include "ui/wrap/vertical_layout.h"
|
2018-04-28 15:58:22 +00:00
|
|
|
#include "ui/toast/toast.h"
|
2019-04-02 09:13:30 +00:00
|
|
|
#include "ui/effects/animations.h"
|
2018-05-03 15:05:18 +00:00
|
|
|
#include "ui/effects/radial_animation.h"
|
2020-10-10 09:15:37 +00:00
|
|
|
#include "ui/text/text_options.h"
|
2021-12-26 16:37:53 +00:00
|
|
|
#include "ui/text/text_utilities.h"
|
2021-06-11 09:30:12 +00:00
|
|
|
#include "ui/basic_click_handlers.h"
|
2022-09-16 20:23:27 +00:00
|
|
|
#include "ui/painter.h"
|
2022-02-28 03:59:36 +00:00
|
|
|
#include "boxes/abstract_box.h" // Ui::show().
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "styles/style_layers.h"
|
2016-11-15 11:56:49 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2018-04-28 09:27:43 +00:00
|
|
|
#include "styles/style_chat_helpers.h"
|
2018-05-05 13:14:46 +00:00
|
|
|
#include "styles/style_info.h"
|
2021-12-09 17:56:24 +00:00
|
|
|
#include "styles/style_menu_icons.h"
|
2018-04-28 09:27:43 +00:00
|
|
|
|
2019-09-04 07:19:15 +00:00
|
|
|
#include <QtGui/QGuiApplication>
|
|
|
|
#include <QtGui/QClipboard>
|
|
|
|
|
2018-04-28 09:27:43 +00:00
|
|
|
namespace {
|
|
|
|
|
2019-02-19 06:57:53 +00:00
|
|
|
constexpr auto kSaveSettingsDelayedTimeout = crl::time(1000);
|
2018-04-28 14:06:59 +00:00
|
|
|
|
2019-11-13 14:12:04 +00:00
|
|
|
using ProxyData = MTP::ProxyData;
|
|
|
|
|
2020-09-01 10:50:32 +00:00
|
|
|
class HostInput : public Ui::MaskedInputField {
|
|
|
|
public:
|
|
|
|
HostInput(
|
|
|
|
QWidget *parent,
|
|
|
|
const style::InputField &st,
|
|
|
|
rpl::producer<QString> placeholder,
|
|
|
|
const QString &val);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void correctValue(
|
|
|
|
const QString &was,
|
|
|
|
int wasCursor,
|
|
|
|
QString &now,
|
|
|
|
int &nowCursor) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
HostInput::HostInput(
|
|
|
|
QWidget *parent,
|
|
|
|
const style::InputField &st,
|
|
|
|
rpl::producer<QString> placeholder,
|
|
|
|
const QString &val)
|
|
|
|
: MaskedInputField(parent, st, std::move(placeholder), val) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void HostInput::correctValue(
|
|
|
|
const QString &was,
|
|
|
|
int wasCursor,
|
|
|
|
QString &now,
|
|
|
|
int &nowCursor) {
|
|
|
|
QString newText;
|
|
|
|
int newCursor = nowCursor;
|
|
|
|
newText.reserve(now.size());
|
2021-10-19 13:00:21 +00:00
|
|
|
for (auto i = 0, l = int(now.size()); i < l; ++i) {
|
2020-09-01 10:50:32 +00:00
|
|
|
if (now[i] == ',') {
|
|
|
|
newText.append('.');
|
|
|
|
} else {
|
|
|
|
newText.append(now[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setCorrectedText(now, nowCursor, newText, newCursor);
|
|
|
|
}
|
|
|
|
|
2019-07-08 16:02:45 +00:00
|
|
|
class Base64UrlInput : public Ui::MaskedInputField {
|
|
|
|
public:
|
|
|
|
Base64UrlInput(
|
|
|
|
QWidget *parent,
|
|
|
|
const style::InputField &st,
|
|
|
|
rpl::producer<QString> placeholder,
|
|
|
|
const QString &val);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void correctValue(
|
|
|
|
const QString &was,
|
|
|
|
int wasCursor,
|
|
|
|
QString &now,
|
|
|
|
int &nowCursor) override;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
Base64UrlInput::Base64UrlInput(
|
|
|
|
QWidget *parent,
|
|
|
|
const style::InputField &st,
|
|
|
|
rpl::producer<QString> placeholder,
|
|
|
|
const QString &val)
|
|
|
|
: MaskedInputField(parent, st, std::move(placeholder), val) {
|
|
|
|
if (!QRegularExpression("^[a-zA-Z0-9_\\-]+$").match(val).hasMatch()) {
|
|
|
|
setText(QString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Base64UrlInput::correctValue(
|
|
|
|
const QString &was,
|
|
|
|
int wasCursor,
|
|
|
|
QString &now,
|
|
|
|
int &nowCursor) {
|
|
|
|
QString newText;
|
|
|
|
newText.reserve(now.size());
|
|
|
|
auto newPos = nowCursor;
|
2021-10-19 13:00:21 +00:00
|
|
|
for (auto i = 0, l = int(now.size()); i < l; ++i) {
|
2019-07-08 16:02:45 +00:00
|
|
|
const auto ch = now[i];
|
|
|
|
if ((ch >= '0' && ch <= '9')
|
|
|
|
|| (ch >= 'a' && ch <= 'z')
|
|
|
|
|| (ch >= 'A' && ch <= 'Z')
|
|
|
|
|| (ch == '-')
|
|
|
|
|| (ch == '_')) {
|
|
|
|
newText.append(ch);
|
|
|
|
} else if (i < nowCursor) {
|
|
|
|
--newPos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setCorrectedText(now, nowCursor, newText, newPos);
|
|
|
|
}
|
|
|
|
|
2018-04-28 09:27:43 +00:00
|
|
|
class ProxyRow : public Ui::RippleButton {
|
|
|
|
public:
|
|
|
|
using View = ProxiesBoxController::ItemView;
|
2018-04-30 15:49:03 +00:00
|
|
|
using State = ProxiesBoxController::ItemState;
|
2018-04-28 09:27:43 +00:00
|
|
|
|
|
|
|
ProxyRow(QWidget *parent, View &&view);
|
|
|
|
|
|
|
|
void updateFields(View &&view);
|
|
|
|
|
|
|
|
rpl::producer<> deleteClicks() const;
|
|
|
|
rpl::producer<> restoreClicks() const;
|
|
|
|
rpl::producer<> editClicks() const;
|
2018-05-05 13:14:46 +00:00
|
|
|
rpl::producer<> shareClicks() const;
|
2018-04-28 09:27:43 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
int resizeGetHeight(int newWidth) override;
|
|
|
|
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void setupControls(View &&view);
|
|
|
|
int countAvailableWidth() const;
|
2019-04-01 17:44:54 +00:00
|
|
|
void radialAnimationCallback();
|
2019-04-02 09:13:30 +00:00
|
|
|
void paintCheck(Painter &p);
|
2018-05-05 13:14:46 +00:00
|
|
|
void showMenu();
|
2018-04-28 09:27:43 +00:00
|
|
|
|
|
|
|
View _view;
|
|
|
|
|
2019-06-12 13:26:04 +00:00
|
|
|
Ui::Text::String _title;
|
2018-05-05 13:14:46 +00:00
|
|
|
object_ptr<Ui::IconButton> _menuToggle;
|
|
|
|
rpl::event_stream<> _deleteClicks;
|
|
|
|
rpl::event_stream<> _restoreClicks;
|
|
|
|
rpl::event_stream<> _editClicks;
|
|
|
|
rpl::event_stream<> _shareClicks;
|
|
|
|
base::unique_qptr<Ui::DropdownMenu> _menu;
|
2018-05-04 18:28:26 +00:00
|
|
|
|
|
|
|
bool _set = false;
|
2019-04-02 09:13:30 +00:00
|
|
|
Ui::Animations::Simple _toggled;
|
|
|
|
Ui::Animations::Simple _setAnimation;
|
2018-05-03 15:05:18 +00:00
|
|
|
std::unique_ptr<Ui::InfiniteRadialAnimation> _progress;
|
2018-05-04 18:28:26 +00:00
|
|
|
std::unique_ptr<Ui::InfiniteRadialAnimation> _checking;
|
|
|
|
|
2018-04-28 09:27:43 +00:00
|
|
|
int _skipLeft = 0;
|
|
|
|
int _skipRight = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-09-18 11:19:05 +00:00
|
|
|
class ProxiesBox : public Ui::BoxContent {
|
2018-04-28 09:27:43 +00:00
|
|
|
public:
|
|
|
|
using View = ProxiesBoxController::ItemView;
|
|
|
|
|
2021-06-10 22:49:08 +00:00
|
|
|
ProxiesBox(
|
|
|
|
QWidget*,
|
|
|
|
not_null<ProxiesBoxController*> controller,
|
|
|
|
Core::SettingsProxy &settings);
|
2018-04-28 09:27:43 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void prepare() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void setupContent();
|
2018-04-28 15:58:22 +00:00
|
|
|
void createNoRowsLabel();
|
2018-04-28 14:06:59 +00:00
|
|
|
void addNewProxy();
|
2018-04-28 09:27:43 +00:00
|
|
|
void applyView(View &&view);
|
|
|
|
void setupButtons(int id, not_null<ProxyRow*> button);
|
2018-04-28 15:58:22 +00:00
|
|
|
int rowHeight() const;
|
2018-05-06 21:29:53 +00:00
|
|
|
void refreshProxyForCalls();
|
2018-04-28 09:27:43 +00:00
|
|
|
|
|
|
|
not_null<ProxiesBoxController*> _controller;
|
2021-06-10 22:49:08 +00:00
|
|
|
Core::SettingsProxy &_settings;
|
2018-05-06 21:29:53 +00:00
|
|
|
QPointer<Ui::Checkbox> _tryIPv6;
|
2018-11-05 13:58:24 +00:00
|
|
|
std::shared_ptr<Ui::RadioenumGroup<ProxyData::Settings>> _proxySettings;
|
2018-05-06 21:29:53 +00:00
|
|
|
QPointer<Ui::SlideWrap<Ui::Checkbox>> _proxyForCalls;
|
|
|
|
QPointer<Ui::DividerLabel> _about;
|
2018-04-28 15:58:22 +00:00
|
|
|
base::unique_qptr<Ui::RpWidget> _noRows;
|
2018-04-28 14:06:59 +00:00
|
|
|
object_ptr<Ui::VerticalLayout> _initialWrap;
|
|
|
|
QPointer<Ui::VerticalLayout> _wrap;
|
2018-05-06 21:29:53 +00:00
|
|
|
int _currentProxySupportsCallsId = 0;
|
2018-04-28 14:06:59 +00:00
|
|
|
|
2018-04-28 15:58:22 +00:00
|
|
|
base::flat_map<int, base::unique_qptr<ProxyRow>> _rows;
|
2018-04-28 09:27:43 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-06-30 08:56:06 +00:00
|
|
|
class ProxyBox final : public Ui::BoxContent {
|
2018-04-28 09:27:43 +00:00
|
|
|
public:
|
|
|
|
ProxyBox(
|
|
|
|
QWidget*,
|
|
|
|
const ProxyData &data,
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(ProxyData)> callback,
|
|
|
|
Fn<void(ProxyData)> shareCallback);
|
2018-04-28 09:27:43 +00:00
|
|
|
|
|
|
|
private:
|
2018-04-28 15:58:22 +00:00
|
|
|
using Type = ProxyData::Type;
|
|
|
|
|
2020-06-30 08:56:06 +00:00
|
|
|
void prepare() override;
|
|
|
|
void setInnerFocus() override {
|
|
|
|
_host->setFocusFast();
|
|
|
|
}
|
|
|
|
|
2018-04-28 15:58:22 +00:00
|
|
|
void refreshButtons();
|
|
|
|
ProxyData collectData();
|
|
|
|
void save();
|
|
|
|
void share();
|
|
|
|
void setupControls(const ProxyData &data);
|
|
|
|
void setupTypes();
|
|
|
|
void setupSocketAddress(const ProxyData &data);
|
|
|
|
void setupCredentials(const ProxyData &data);
|
|
|
|
void setupMtprotoCredentials(const ProxyData &data);
|
|
|
|
|
|
|
|
void addLabel(
|
|
|
|
not_null<Ui::VerticalLayout*> parent,
|
|
|
|
const QString &text) const;
|
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(ProxyData)> _callback;
|
|
|
|
Fn<void(ProxyData)> _shareCallback;
|
2018-04-28 09:27:43 +00:00
|
|
|
|
2018-04-28 15:58:22 +00:00
|
|
|
object_ptr<Ui::VerticalLayout> _content;
|
|
|
|
|
|
|
|
std::shared_ptr<Ui::RadioenumGroup<Type>> _type;
|
|
|
|
|
2018-05-15 17:22:28 +00:00
|
|
|
QPointer<Ui::SlideWrap<>> _aboutSponsored;
|
2020-09-01 10:50:32 +00:00
|
|
|
QPointer<HostInput> _host;
|
2021-01-19 06:22:25 +00:00
|
|
|
QPointer<Ui::NumberInput> _port;
|
2018-04-28 15:58:22 +00:00
|
|
|
QPointer<Ui::InputField> _user;
|
|
|
|
QPointer<Ui::PasswordInput> _password;
|
2019-07-08 16:02:45 +00:00
|
|
|
QPointer<Base64UrlInput> _secret;
|
2018-04-28 15:58:22 +00:00
|
|
|
|
|
|
|
QPointer<Ui::SlideWrap<Ui::VerticalLayout>> _credentials;
|
|
|
|
QPointer<Ui::SlideWrap<Ui::VerticalLayout>> _mtprotoCredentials;
|
|
|
|
|
2018-04-28 09:27:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ProxyRow::ProxyRow(QWidget *parent, View &&view)
|
|
|
|
: RippleButton(parent, st::proxyRowRipple)
|
2018-05-05 13:14:46 +00:00
|
|
|
, _menuToggle(this, st::topBarMenuToggle) {
|
2018-04-28 09:27:43 +00:00
|
|
|
setupControls(std::move(view));
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> ProxyRow::deleteClicks() const {
|
2018-05-05 13:14:46 +00:00
|
|
|
return _deleteClicks.events();
|
2018-04-28 09:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> ProxyRow::restoreClicks() const {
|
2018-05-05 13:14:46 +00:00
|
|
|
return _restoreClicks.events();
|
2018-04-28 09:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> ProxyRow::editClicks() const {
|
2018-05-05 13:14:46 +00:00
|
|
|
return _editClicks.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> ProxyRow::shareClicks() const {
|
|
|
|
return _shareClicks.events();
|
2018-04-28 09:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProxyRow::setupControls(View &&view) {
|
|
|
|
updateFields(std::move(view));
|
2019-04-02 09:13:30 +00:00
|
|
|
_toggled.stop();
|
|
|
|
_setAnimation.stop();
|
2018-04-28 09:27:43 +00:00
|
|
|
|
2018-05-05 13:14:46 +00:00
|
|
|
_menuToggle->addClickHandler([=] { showMenu(); });
|
2018-04-28 09:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ProxyRow::countAvailableWidth() const {
|
|
|
|
return width() - _skipLeft - _skipRight;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProxyRow::updateFields(View &&view) {
|
2018-05-04 18:28:26 +00:00
|
|
|
if (_view.selected != view.selected) {
|
|
|
|
_toggled.start(
|
|
|
|
[=] { update(); },
|
|
|
|
view.selected ? 0. : 1.,
|
|
|
|
view.selected ? 1. : 0.,
|
|
|
|
st::defaultRadio.duration);
|
|
|
|
}
|
2018-04-28 09:27:43 +00:00
|
|
|
_view = std::move(view);
|
|
|
|
const auto endpoint = _view.host + ':' + QString::number(_view.port);
|
2021-12-26 16:37:53 +00:00
|
|
|
_title.setMarkedText(
|
2018-04-28 09:27:43 +00:00
|
|
|
st::proxyRowTitleStyle,
|
2021-12-26 16:37:53 +00:00
|
|
|
TextWithEntities()
|
|
|
|
.append(_view.type)
|
|
|
|
.append(' ')
|
2022-02-06 15:29:24 +00:00
|
|
|
.append(Ui::Text::Link(endpoint, QString())),
|
2018-04-28 09:27:43 +00:00
|
|
|
Ui::ItemTextDefaultOptions());
|
|
|
|
|
2018-05-03 15:05:18 +00:00
|
|
|
const auto state = _view.state;
|
2018-05-04 18:28:26 +00:00
|
|
|
if (state == State::Connecting) {
|
2018-05-03 15:05:18 +00:00
|
|
|
if (!_progress) {
|
|
|
|
_progress = std::make_unique<Ui::InfiniteRadialAnimation>(
|
2019-04-01 17:44:54 +00:00
|
|
|
[=] { radialAnimationCallback(); },
|
2018-05-04 16:57:50 +00:00
|
|
|
st::proxyCheckingAnimation);
|
2018-05-04 18:28:26 +00:00
|
|
|
}
|
|
|
|
_progress->start();
|
|
|
|
} else if (_progress) {
|
|
|
|
_progress->stop();
|
|
|
|
}
|
|
|
|
if (state == State::Checking) {
|
|
|
|
if (!_checking) {
|
|
|
|
_checking = std::make_unique<Ui::InfiniteRadialAnimation>(
|
2019-04-01 17:44:54 +00:00
|
|
|
[=] { radialAnimationCallback(); },
|
2018-05-04 18:28:26 +00:00
|
|
|
st::proxyCheckingAnimation);
|
|
|
|
_checking->start();
|
2018-05-03 15:05:18 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-05-04 18:28:26 +00:00
|
|
|
_checking = nullptr;
|
|
|
|
}
|
|
|
|
const auto set = (state == State::Connecting || state == State::Online);
|
|
|
|
if (_set != set) {
|
|
|
|
_set = set;
|
|
|
|
_setAnimation.start(
|
|
|
|
[=] { update(); },
|
|
|
|
_set ? 0. : 1.,
|
|
|
|
_set ? 1. : 0.,
|
|
|
|
st::defaultRadio.duration);
|
2018-05-03 15:05:18 +00:00
|
|
|
}
|
|
|
|
|
2018-04-28 14:06:59 +00:00
|
|
|
setPointerCursor(!_view.deleted);
|
|
|
|
|
2018-04-28 09:27:43 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2019-04-01 17:44:54 +00:00
|
|
|
void ProxyRow::radialAnimationCallback() {
|
|
|
|
if (!anim::Disabled()) {
|
2018-05-03 15:05:18 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-28 09:27:43 +00:00
|
|
|
int ProxyRow::resizeGetHeight(int newWidth) {
|
|
|
|
const auto result = st::proxyRowPadding.top()
|
|
|
|
+ st::semiboldFont->height
|
|
|
|
+ st::proxyRowSkip
|
|
|
|
+ st::normalFont->height
|
|
|
|
+ st::proxyRowPadding.bottom();
|
|
|
|
auto right = st::proxyRowPadding.right();
|
2018-05-05 13:14:46 +00:00
|
|
|
_menuToggle->moveToRight(
|
2018-04-28 09:27:43 +00:00
|
|
|
right,
|
2018-05-05 13:14:46 +00:00
|
|
|
(result - _menuToggle->height()) / 2,
|
2018-04-28 09:27:43 +00:00
|
|
|
newWidth);
|
2018-05-05 13:14:46 +00:00
|
|
|
right += _menuToggle->width();
|
2018-04-28 09:27:43 +00:00
|
|
|
_skipRight = right;
|
|
|
|
_skipLeft = st::proxyRowPadding.left()
|
|
|
|
+ st::proxyRowIconSkip;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProxyRow::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
if (!_view.deleted) {
|
2019-04-02 09:13:30 +00:00
|
|
|
paintRipple(p, 0, 0);
|
2018-04-28 09:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const auto left = _skipLeft;
|
|
|
|
const auto availableWidth = countAvailableWidth();
|
|
|
|
auto top = st::proxyRowPadding.top();
|
|
|
|
|
|
|
|
if (_view.deleted) {
|
|
|
|
p.setOpacity(st::stickersRowDisabledOpacity);
|
|
|
|
}
|
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
paintCheck(p);
|
2018-05-04 18:28:26 +00:00
|
|
|
|
2018-04-28 09:27:43 +00:00
|
|
|
p.setPen(st::proxyRowTitleFg);
|
|
|
|
p.setFont(st::semiboldFont);
|
|
|
|
p.setTextPalette(st::proxyRowTitlePalette);
|
|
|
|
_title.drawLeftElided(p, left, top, availableWidth, width());
|
|
|
|
top += st::semiboldFont->height + st::proxyRowSkip;
|
|
|
|
|
|
|
|
const auto statusFg = [&] {
|
|
|
|
switch (_view.state) {
|
2018-04-30 15:49:03 +00:00
|
|
|
case State::Online:
|
2018-04-28 09:27:43 +00:00
|
|
|
return st::proxyRowStatusFgOnline;
|
2018-04-30 15:49:03 +00:00
|
|
|
case State::Unavailable:
|
2018-04-28 09:27:43 +00:00
|
|
|
return st::proxyRowStatusFgOffline;
|
2018-04-30 15:49:03 +00:00
|
|
|
case State::Available:
|
|
|
|
return st::proxyRowStatusFgAvailable;
|
2018-04-28 09:27:43 +00:00
|
|
|
default:
|
|
|
|
return st::proxyRowStatusFg;
|
|
|
|
}
|
|
|
|
}();
|
|
|
|
const auto status = [&] {
|
|
|
|
switch (_view.state) {
|
2018-04-30 15:49:03 +00:00
|
|
|
case State::Available:
|
2019-06-19 16:39:25 +00:00
|
|
|
return tr::lng_proxy_available(
|
|
|
|
tr::now,
|
2018-04-30 15:49:03 +00:00
|
|
|
lt_ping,
|
|
|
|
QString::number(_view.ping));
|
|
|
|
case State::Checking:
|
2019-06-19 15:09:03 +00:00
|
|
|
return tr::lng_proxy_checking(tr::now);
|
2018-04-30 15:49:03 +00:00
|
|
|
case State::Connecting:
|
2019-06-19 15:09:03 +00:00
|
|
|
return tr::lng_proxy_connecting(tr::now);
|
2018-04-30 15:49:03 +00:00
|
|
|
case State::Online:
|
2019-06-19 15:09:03 +00:00
|
|
|
return tr::lng_proxy_online(tr::now);
|
2018-04-30 15:49:03 +00:00
|
|
|
case State::Unavailable:
|
2019-06-19 15:09:03 +00:00
|
|
|
return tr::lng_proxy_unavailable(tr::now);
|
2018-04-28 09:27:43 +00:00
|
|
|
}
|
|
|
|
Unexpected("State in ProxyRow::paintEvent.");
|
|
|
|
}();
|
2018-05-05 13:14:46 +00:00
|
|
|
p.setPen(_view.deleted ? st::proxyRowStatusFg : statusFg);
|
2018-04-28 09:27:43 +00:00
|
|
|
p.setFont(st::normalFont);
|
|
|
|
|
2018-05-03 15:05:18 +00:00
|
|
|
auto statusLeft = left;
|
2018-05-04 18:28:26 +00:00
|
|
|
if (_checking) {
|
2019-04-01 17:44:54 +00:00
|
|
|
_checking->draw(
|
|
|
|
p,
|
|
|
|
{
|
|
|
|
st::proxyCheckingPosition.x() + statusLeft,
|
|
|
|
st::proxyCheckingPosition.y() + top
|
|
|
|
},
|
|
|
|
width());
|
|
|
|
statusLeft += st::proxyCheckingPosition.x()
|
|
|
|
+ st::proxyCheckingAnimation.size.width()
|
|
|
|
+ st::proxyCheckingSkip;
|
2018-05-03 15:05:18 +00:00
|
|
|
}
|
|
|
|
p.drawTextLeft(statusLeft, top, width(), status);
|
|
|
|
top += st::normalFont->height + st::proxyRowPadding.bottom();
|
2018-04-28 09:27:43 +00:00
|
|
|
}
|
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
void ProxyRow::paintCheck(Painter &p) {
|
2018-05-04 18:28:26 +00:00
|
|
|
const auto loading = _progress
|
|
|
|
? _progress->computeState()
|
2023-01-11 04:56:01 +00:00
|
|
|
: Ui::RadialState{ 0., 0, arc::kFullLength };
|
2019-04-02 09:13:30 +00:00
|
|
|
const auto toggled = _toggled.value(_view.selected ? 1. : 0.)
|
2018-05-04 18:28:26 +00:00
|
|
|
* (1. - loading.shown);
|
|
|
|
const auto _st = &st::defaultRadio;
|
2019-04-02 09:13:30 +00:00
|
|
|
const auto set = _setAnimation.value(_set ? 1. : 0.);
|
2018-05-04 18:28:26 +00:00
|
|
|
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
|
|
|
|
const auto left = st::proxyRowPadding.left();
|
|
|
|
const auto top = (height() - _st->diameter - _st->thickness) / 2;
|
|
|
|
const auto outerWidth = width();
|
|
|
|
|
|
|
|
auto pen = anim::pen(_st->untoggledFg, _st->toggledFg, toggled * set);
|
|
|
|
pen.setWidth(_st->thickness);
|
2019-01-02 12:11:13 +00:00
|
|
|
pen.setCapStyle(Qt::RoundCap);
|
2018-05-04 18:28:26 +00:00
|
|
|
p.setPen(pen);
|
|
|
|
p.setBrush(_st->bg);
|
2019-09-13 12:22:54 +00:00
|
|
|
const auto rect = style::rtlrect(QRectF(left, top, _st->diameter, _st->diameter).marginsRemoved(QMarginsF(_st->thickness / 2., _st->thickness / 2., _st->thickness / 2., _st->thickness / 2.)), outerWidth);
|
2018-09-20 16:39:59 +00:00
|
|
|
if (_progress && loading.shown > 0 && anim::Disabled()) {
|
|
|
|
anim::DrawStaticLoading(
|
|
|
|
p,
|
|
|
|
rect,
|
|
|
|
_st->thickness,
|
|
|
|
pen.color(),
|
|
|
|
_st->bg);
|
2023-01-11 04:56:01 +00:00
|
|
|
} else if (loading.arcLength < arc::kFullLength) {
|
2018-05-04 18:28:26 +00:00
|
|
|
p.drawArc(rect, loading.arcFrom, loading.arcLength);
|
|
|
|
} else {
|
|
|
|
p.drawEllipse(rect);
|
|
|
|
}
|
|
|
|
|
2018-09-20 16:39:59 +00:00
|
|
|
if (toggled > 0 && (!_progress || !anim::Disabled())) {
|
2018-05-04 18:28:26 +00:00
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.setBrush(anim::brush(_st->untoggledFg, _st->toggledFg, toggled * set));
|
|
|
|
|
|
|
|
auto skip0 = _st->diameter / 2., skip1 = _st->skip / 10., checkSkip = skip0 * (1. - toggled) + skip1 * toggled;
|
2019-09-13 12:22:54 +00:00
|
|
|
p.drawEllipse(style::rtlrect(QRectF(left, top, _st->diameter, _st->diameter).marginsRemoved(QMarginsF(checkSkip, checkSkip, checkSkip, checkSkip)), outerWidth));
|
2018-05-04 18:28:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-05 13:14:46 +00:00
|
|
|
void ProxyRow::showMenu() {
|
|
|
|
if (_menu) {
|
|
|
|
return;
|
|
|
|
}
|
2021-12-09 17:56:24 +00:00
|
|
|
_menu = base::make_unique_q<Ui::DropdownMenu>(
|
|
|
|
window(),
|
|
|
|
st::dropdownMenuWithIcons);
|
2018-05-05 13:14:46 +00:00
|
|
|
const auto weak = _menu.get();
|
|
|
|
_menu->setHiddenCallback([=] {
|
|
|
|
weak->deleteLater();
|
|
|
|
if (_menu == weak) {
|
|
|
|
_menuToggle->setForceRippled(false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
_menu->setShowStartCallback([=] {
|
|
|
|
if (_menu == weak) {
|
|
|
|
_menuToggle->setForceRippled(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
_menu->setHideStartCallback([=] {
|
|
|
|
if (_menu == weak) {
|
|
|
|
_menuToggle->setForceRippled(false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
_menuToggle->installEventFilter(_menu);
|
|
|
|
const auto addAction = [&](
|
|
|
|
const QString &text,
|
2021-12-09 17:56:24 +00:00
|
|
|
Fn<void()> callback,
|
|
|
|
const style::icon *icon) {
|
2021-12-30 10:37:17 +00:00
|
|
|
return _menu->addAction(text, std::move(callback), icon);
|
2018-05-05 13:14:46 +00:00
|
|
|
};
|
2019-06-19 15:09:03 +00:00
|
|
|
addAction(tr::lng_proxy_menu_edit(tr::now), [=] {
|
2018-05-05 13:14:46 +00:00
|
|
|
_editClicks.fire({});
|
2021-12-09 17:56:24 +00:00
|
|
|
}, &st::menuIconEdit);
|
2018-05-06 21:29:53 +00:00
|
|
|
if (_view.supportsShare) {
|
2019-06-19 15:09:03 +00:00
|
|
|
addAction(tr::lng_proxy_edit_share(tr::now), [=] {
|
2018-05-05 13:14:46 +00:00
|
|
|
_shareClicks.fire({});
|
2021-12-09 17:56:24 +00:00
|
|
|
}, &st::menuIconShare);
|
2018-05-05 13:14:46 +00:00
|
|
|
}
|
|
|
|
if (_view.deleted) {
|
2019-06-19 15:09:03 +00:00
|
|
|
addAction(tr::lng_proxy_menu_restore(tr::now), [=] {
|
2018-05-05 13:14:46 +00:00
|
|
|
_restoreClicks.fire({});
|
2021-12-10 12:10:14 +00:00
|
|
|
}, &st::menuIconRestore);
|
2018-05-05 13:14:46 +00:00
|
|
|
} else {
|
2019-06-19 15:09:03 +00:00
|
|
|
addAction(tr::lng_proxy_menu_delete(tr::now), [=] {
|
2018-05-05 13:14:46 +00:00
|
|
|
_deleteClicks.fire({});
|
2021-12-09 17:56:24 +00:00
|
|
|
}, &st::menuIconDelete);
|
2018-05-05 13:14:46 +00:00
|
|
|
}
|
2021-10-19 13:00:21 +00:00
|
|
|
const auto parentTopLeft = window()->mapToGlobal(QPoint());
|
|
|
|
const auto buttonTopLeft = _menuToggle->mapToGlobal(QPoint());
|
2018-05-05 13:14:46 +00:00
|
|
|
const auto parent = QRect(parentTopLeft, window()->size());
|
|
|
|
const auto button = QRect(buttonTopLeft, _menuToggle->size());
|
|
|
|
const auto bottom = button.y()
|
|
|
|
+ st::proxyDropdownDownPosition.y()
|
|
|
|
+ _menu->height()
|
|
|
|
- parent.y();
|
|
|
|
const auto top = button.y()
|
|
|
|
+ st::proxyDropdownUpPosition.y()
|
|
|
|
- _menu->height()
|
|
|
|
- parent.y();
|
|
|
|
if (bottom > parent.height() && top >= 0) {
|
|
|
|
const auto left = button.x()
|
|
|
|
+ button.width()
|
|
|
|
+ st::proxyDropdownUpPosition.x()
|
|
|
|
- _menu->width()
|
|
|
|
- parent.x();
|
|
|
|
_menu->move(left, top);
|
|
|
|
_menu->showAnimated(Ui::PanelAnimation::Origin::BottomRight);
|
|
|
|
} else {
|
|
|
|
const auto left = button.x()
|
|
|
|
+ button.width()
|
|
|
|
+ st::proxyDropdownDownPosition.x()
|
|
|
|
- _menu->width()
|
|
|
|
- parent.x();
|
|
|
|
_menu->move(left, bottom - _menu->height());
|
|
|
|
_menu->showAnimated(Ui::PanelAnimation::Origin::TopRight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-28 09:27:43 +00:00
|
|
|
ProxiesBox::ProxiesBox(
|
|
|
|
QWidget*,
|
2021-06-10 22:49:08 +00:00
|
|
|
not_null<ProxiesBoxController*> controller,
|
|
|
|
Core::SettingsProxy &settings)
|
2018-04-28 09:27:43 +00:00
|
|
|
: _controller(controller)
|
2021-06-10 22:49:08 +00:00
|
|
|
, _settings(settings)
|
2018-04-28 14:06:59 +00:00
|
|
|
, _initialWrap(this) {
|
2018-04-28 09:27:43 +00:00
|
|
|
_controller->views(
|
|
|
|
) | rpl::start_with_next([=](View &&view) {
|
|
|
|
applyView(std::move(view));
|
|
|
|
}, lifetime());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProxiesBox::prepare() {
|
2019-06-18 15:00:55 +00:00
|
|
|
setTitle(tr::lng_proxy_settings());
|
2018-04-28 09:27:43 +00:00
|
|
|
|
2019-06-18 16:53:27 +00:00
|
|
|
addButton(tr::lng_proxy_add(), [=] { addNewProxy(); });
|
|
|
|
addButton(tr::lng_close(), [=] { closeBox(); });
|
2018-04-28 09:27:43 +00:00
|
|
|
|
|
|
|
setupContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProxiesBox::setupContent() {
|
2018-05-06 21:29:53 +00:00
|
|
|
const auto inner = setInnerWidget(object_ptr<Ui::VerticalLayout>(this));
|
|
|
|
|
|
|
|
_tryIPv6 = inner->add(
|
|
|
|
object_ptr<Ui::Checkbox>(
|
|
|
|
inner,
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_connection_try_ipv6(tr::now),
|
2021-06-10 22:49:08 +00:00
|
|
|
_settings.tryIPv6()),
|
2018-05-06 21:29:53 +00:00
|
|
|
st::proxyTryIPv6Padding);
|
2018-11-05 13:58:24 +00:00
|
|
|
_proxySettings
|
|
|
|
= std::make_shared<Ui::RadioenumGroup<ProxyData::Settings>>(
|
2021-06-10 22:49:08 +00:00
|
|
|
_settings.settings());
|
2018-11-05 13:58:24 +00:00
|
|
|
inner->add(
|
|
|
|
object_ptr<Ui::Radioenum<ProxyData::Settings>>(
|
|
|
|
inner,
|
|
|
|
_proxySettings,
|
|
|
|
ProxyData::Settings::Disabled,
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_proxy_disable(tr::now)),
|
2018-11-05 13:58:24 +00:00
|
|
|
st::proxyUsePadding);
|
|
|
|
inner->add(
|
|
|
|
object_ptr<Ui::Radioenum<ProxyData::Settings>>(
|
|
|
|
inner,
|
|
|
|
_proxySettings,
|
|
|
|
ProxyData::Settings::System,
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_proxy_use_system_settings(tr::now)),
|
2018-11-05 13:58:24 +00:00
|
|
|
st::proxyUsePadding);
|
|
|
|
inner->add(
|
|
|
|
object_ptr<Ui::Radioenum<ProxyData::Settings>>(
|
2018-05-06 21:29:53 +00:00
|
|
|
inner,
|
2018-11-05 13:58:24 +00:00
|
|
|
_proxySettings,
|
|
|
|
ProxyData::Settings::Enabled,
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_proxy_use_custom(tr::now)),
|
2018-05-06 21:29:53 +00:00
|
|
|
st::proxyUsePadding);
|
|
|
|
_proxyForCalls = inner->add(
|
|
|
|
object_ptr<Ui::SlideWrap<Ui::Checkbox>>(
|
|
|
|
inner,
|
|
|
|
object_ptr<Ui::Checkbox>(
|
|
|
|
inner,
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_proxy_use_for_calls(tr::now),
|
2021-06-10 22:49:08 +00:00
|
|
|
_settings.useProxyForCalls()),
|
2018-05-06 21:29:53 +00:00
|
|
|
style::margins(
|
|
|
|
0,
|
|
|
|
st::proxyUsePadding.top(),
|
|
|
|
0,
|
|
|
|
st::proxyUsePadding.bottom())),
|
|
|
|
style::margins(
|
|
|
|
st::proxyTryIPv6Padding.left(),
|
|
|
|
0,
|
|
|
|
st::proxyTryIPv6Padding.right(),
|
|
|
|
st::proxyTryIPv6Padding.top()));
|
|
|
|
|
|
|
|
_about = inner->add(
|
|
|
|
object_ptr<Ui::DividerLabel>(
|
|
|
|
inner,
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
inner,
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_proxy_about(tr::now),
|
2018-05-06 21:29:53 +00:00
|
|
|
st::boxDividerLabel),
|
|
|
|
st::proxyAboutPadding),
|
|
|
|
style::margins(0, 0, 0, st::proxyRowPadding.top()));
|
|
|
|
|
|
|
|
_wrap = inner->add(std::move(_initialWrap));
|
|
|
|
inner->add(object_ptr<Ui::FixedHeightWidget>(
|
|
|
|
inner,
|
|
|
|
st::proxyRowPadding.bottom()));
|
|
|
|
|
2018-11-05 13:58:24 +00:00
|
|
|
_proxySettings->setChangedCallback([=](ProxyData::Settings value) {
|
|
|
|
if (!_controller->setProxySettings(value)) {
|
2021-06-10 22:49:08 +00:00
|
|
|
_proxySettings->setValue(_settings.settings());
|
2018-04-28 14:06:59 +00:00
|
|
|
addNewProxy();
|
|
|
|
}
|
2018-05-06 21:29:53 +00:00
|
|
|
refreshProxyForCalls();
|
2018-04-28 14:06:59 +00:00
|
|
|
});
|
2018-12-05 09:55:56 +00:00
|
|
|
_tryIPv6->checkedChanges(
|
|
|
|
) | rpl::start_with_next([=](bool checked) {
|
2018-04-28 15:58:22 +00:00
|
|
|
_controller->setTryIPv6(checked);
|
2018-12-05 09:55:56 +00:00
|
|
|
}, _tryIPv6->lifetime());
|
|
|
|
|
2018-11-05 13:58:24 +00:00
|
|
|
_controller->proxySettingsValue(
|
|
|
|
) | rpl::start_with_next([=](ProxyData::Settings value) {
|
|
|
|
_proxySettings->setValue(value);
|
|
|
|
}, inner->lifetime());
|
|
|
|
|
2018-12-05 09:55:56 +00:00
|
|
|
_proxyForCalls->entity()->checkedChanges(
|
|
|
|
) | rpl::start_with_next([=](bool checked) {
|
2018-05-06 21:29:53 +00:00
|
|
|
_controller->setProxyForCalls(checked);
|
2018-12-05 09:55:56 +00:00
|
|
|
}, _proxyForCalls->lifetime());
|
2018-04-28 14:06:59 +00:00
|
|
|
|
2018-04-28 15:58:22 +00:00
|
|
|
if (_rows.empty()) {
|
|
|
|
createNoRowsLabel();
|
|
|
|
}
|
2018-05-06 21:29:53 +00:00
|
|
|
refreshProxyForCalls();
|
|
|
|
_proxyForCalls->finishAnimating();
|
2018-04-28 15:58:22 +00:00
|
|
|
|
2018-04-28 14:06:59 +00:00
|
|
|
inner->resizeToWidth(st::boxWideWidth);
|
|
|
|
|
|
|
|
inner->heightValue(
|
|
|
|
) | rpl::map([=](int height) {
|
|
|
|
return std::min(
|
2018-05-06 21:29:53 +00:00
|
|
|
std::max(height, _about->y()
|
|
|
|
+ _about->height()
|
|
|
|
+ 3 * rowHeight()),
|
2018-04-28 14:06:59 +00:00
|
|
|
st::boxMaxListHeight);
|
2018-04-28 09:27:43 +00:00
|
|
|
}) | rpl::distinct_until_changed(
|
|
|
|
) | rpl::start_with_next([=](int height) {
|
|
|
|
setDimensions(st::boxWideWidth, height);
|
2018-04-28 14:06:59 +00:00
|
|
|
}, inner->lifetime());
|
2018-05-06 21:29:53 +00:00
|
|
|
}
|
2018-04-28 14:06:59 +00:00
|
|
|
|
2018-05-06 21:29:53 +00:00
|
|
|
void ProxiesBox::refreshProxyForCalls() {
|
|
|
|
if (!_proxyForCalls) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_proxyForCalls->toggle(
|
2018-11-05 13:58:24 +00:00
|
|
|
(_proxySettings->value() == ProxyData::Settings::Enabled
|
|
|
|
&& _currentProxySupportsCallsId != 0),
|
2018-05-06 21:29:53 +00:00
|
|
|
anim::type::normal);
|
2018-04-28 14:06:59 +00:00
|
|
|
}
|
|
|
|
|
2018-04-28 15:58:22 +00:00
|
|
|
int ProxiesBox::rowHeight() const {
|
|
|
|
return st::proxyRowPadding.top()
|
|
|
|
+ st::semiboldFont->height
|
|
|
|
+ st::proxyRowSkip
|
|
|
|
+ st::normalFont->height
|
|
|
|
+ st::proxyRowPadding.bottom();
|
|
|
|
}
|
|
|
|
|
2018-04-28 14:06:59 +00:00
|
|
|
void ProxiesBox::addNewProxy() {
|
2018-06-04 11:43:49 +00:00
|
|
|
getDelegate()->show(_controller->addNewItemBox());
|
2018-04-28 09:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProxiesBox::applyView(View &&view) {
|
2018-05-06 21:29:53 +00:00
|
|
|
if (view.selected) {
|
|
|
|
_currentProxySupportsCallsId = view.supportsCalls ? view.id : 0;
|
|
|
|
} else if (view.id == _currentProxySupportsCallsId) {
|
|
|
|
_currentProxySupportsCallsId = 0;
|
|
|
|
}
|
|
|
|
refreshProxyForCalls();
|
|
|
|
|
2018-04-28 09:27:43 +00:00
|
|
|
const auto id = view.id;
|
|
|
|
const auto i = _rows.find(id);
|
|
|
|
if (i == _rows.end()) {
|
2018-04-28 14:06:59 +00:00
|
|
|
const auto wrap = _wrap
|
|
|
|
? _wrap.data()
|
|
|
|
: _initialWrap.data();
|
2018-04-28 15:58:22 +00:00
|
|
|
const auto [i, ok] = _rows.emplace(id, nullptr);
|
|
|
|
i->second.reset(wrap->insert(
|
2018-04-28 14:06:59 +00:00
|
|
|
0,
|
2018-04-28 09:27:43 +00:00
|
|
|
object_ptr<ProxyRow>(
|
2018-04-28 14:06:59 +00:00
|
|
|
wrap,
|
2018-04-28 09:27:43 +00:00
|
|
|
std::move(view))));
|
2018-04-28 15:58:22 +00:00
|
|
|
setupButtons(id, i->second.get());
|
2020-03-29 09:05:32 +00:00
|
|
|
if (_noRows) {
|
|
|
|
_noRows.reset();
|
|
|
|
}
|
2020-06-30 08:25:06 +00:00
|
|
|
wrap->resizeToWidth(width());
|
2018-04-28 15:58:22 +00:00
|
|
|
} else if (view.host.isEmpty()) {
|
|
|
|
_rows.erase(i);
|
2018-04-28 09:27:43 +00:00
|
|
|
} else {
|
|
|
|
i->second->updateFields(std::move(view));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-28 15:58:22 +00:00
|
|
|
void ProxiesBox::createNoRowsLabel() {
|
|
|
|
_noRows.reset(_wrap->add(
|
|
|
|
object_ptr<Ui::FixedHeightWidget>(
|
|
|
|
_wrap,
|
|
|
|
rowHeight()),
|
|
|
|
st::proxyEmptyListPadding));
|
|
|
|
_noRows->resize(
|
|
|
|
(st::boxWideWidth
|
|
|
|
- st::proxyEmptyListPadding.left()
|
|
|
|
- st::proxyEmptyListPadding.right()),
|
|
|
|
_noRows->height());
|
|
|
|
const auto label = Ui::CreateChild<Ui::FlatLabel>(
|
|
|
|
_noRows.get(),
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_proxy_description(tr::now),
|
2018-04-28 15:58:22 +00:00
|
|
|
st::proxyEmptyListLabel);
|
|
|
|
_noRows->widthValue(
|
|
|
|
) | rpl::start_with_next([=](int width) {
|
|
|
|
label->resizeToWidth(width);
|
|
|
|
label->moveToLeft(0, 0);
|
2018-05-03 18:02:26 +00:00
|
|
|
}, label->lifetime());
|
2018-04-28 15:58:22 +00:00
|
|
|
}
|
|
|
|
|
2018-04-28 09:27:43 +00:00
|
|
|
void ProxiesBox::setupButtons(int id, not_null<ProxyRow*> button) {
|
|
|
|
button->deleteClicks(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
_controller->deleteItem(id);
|
|
|
|
}, button->lifetime());
|
|
|
|
|
|
|
|
button->restoreClicks(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
_controller->restoreItem(id);
|
|
|
|
}, button->lifetime());
|
|
|
|
|
|
|
|
button->editClicks(
|
|
|
|
) | rpl::start_with_next([=] {
|
2018-06-04 11:43:49 +00:00
|
|
|
getDelegate()->show(_controller->editItemBox(id));
|
2018-04-28 09:27:43 +00:00
|
|
|
}, button->lifetime());
|
2018-04-28 14:06:59 +00:00
|
|
|
|
2018-05-05 13:14:46 +00:00
|
|
|
button->shareClicks(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
_controller->shareItem(id);
|
|
|
|
}, button->lifetime());
|
|
|
|
|
2018-04-28 14:06:59 +00:00
|
|
|
button->clicks(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
_controller->applyItem(id);
|
|
|
|
}, button->lifetime());
|
2018-04-28 09:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ProxyBox::ProxyBox(
|
|
|
|
QWidget*,
|
|
|
|
const ProxyData &data,
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(ProxyData)> callback,
|
|
|
|
Fn<void(ProxyData)> shareCallback)
|
2018-04-28 15:58:22 +00:00
|
|
|
: _callback(std::move(callback))
|
2018-05-05 13:14:46 +00:00
|
|
|
, _shareCallback(std::move(shareCallback))
|
2018-04-28 15:58:22 +00:00
|
|
|
, _content(this) {
|
|
|
|
setupControls(data);
|
2018-04-28 09:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProxyBox::prepare() {
|
2019-06-18 15:00:55 +00:00
|
|
|
setTitle(tr::lng_proxy_edit());
|
2018-04-28 15:58:22 +00:00
|
|
|
|
2020-09-01 10:50:32 +00:00
|
|
|
connect(_host.data(), &HostInput::changed, [=] {
|
2020-06-30 08:56:06 +00:00
|
|
|
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);
|
2020-09-01 10:50:32 +00:00
|
|
|
if (_host->cursorPosition() == host.size()
|
2020-06-30 08:56:06 +00:00
|
|
|
&& 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());
|
|
|
|
|
2018-04-28 15:58:22 +00:00
|
|
|
refreshButtons();
|
2018-12-05 08:07:17 +00:00
|
|
|
setDimensionsToContent(st::boxWideWidth, _content);
|
2018-04-28 15:58:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProxyBox::refreshButtons() {
|
|
|
|
clearButtons();
|
2019-06-18 16:53:27 +00:00
|
|
|
addButton(tr::lng_settings_save(), [=] { save(); });
|
|
|
|
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
2018-04-28 15:58:22 +00:00
|
|
|
|
|
|
|
const auto type = _type->value();
|
|
|
|
if (type == Type::Socks5 || type == Type::Mtproto) {
|
2019-06-18 16:53:27 +00:00
|
|
|
addLeftButton(tr::lng_proxy_share(), [=] { share(); });
|
2018-04-28 15:58:22 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-28 09:27:43 +00:00
|
|
|
|
2018-04-28 15:58:22 +00:00
|
|
|
void ProxyBox::save() {
|
|
|
|
if (const auto data = collectData()) {
|
|
|
|
_callback(data);
|
|
|
|
closeBox();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProxyBox::share() {
|
|
|
|
if (const auto data = collectData()) {
|
2018-05-05 13:14:46 +00:00
|
|
|
_shareCallback(data);
|
2018-04-28 15:58:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ProxyData ProxyBox::collectData() {
|
|
|
|
auto result = ProxyData();
|
|
|
|
result.type = _type->value();
|
|
|
|
result.host = _host->getLastText().trimmed();
|
|
|
|
result.port = _port->getLastText().trimmed().toInt();
|
|
|
|
result.user = (result.type == Type::Mtproto)
|
|
|
|
? QString()
|
|
|
|
: _user->getLastText();
|
|
|
|
result.password = (result.type == Type::Mtproto)
|
|
|
|
? _secret->getLastText()
|
|
|
|
: _password->getLastText();
|
|
|
|
if (result.host.isEmpty()) {
|
|
|
|
_host->showError();
|
|
|
|
} else if (!result.port) {
|
|
|
|
_port->showError();
|
|
|
|
} else if ((result.type == Type::Http || result.type == Type::Socks5)
|
|
|
|
&& !result.password.isEmpty() && result.user.isEmpty()) {
|
|
|
|
_user->showError();
|
2018-06-25 19:22:03 +00:00
|
|
|
} else if (result.type == Type::Mtproto && !result.valid()) {
|
2018-04-28 15:58:22 +00:00
|
|
|
_secret->showError();
|
|
|
|
} else if (!result) {
|
|
|
|
_host->showError();
|
|
|
|
} else {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return ProxyData();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProxyBox::setupTypes() {
|
|
|
|
const auto types = std::map<Type, QString>{
|
|
|
|
{ Type::Http, "HTTP" },
|
|
|
|
{ Type::Socks5, "SOCKS5" },
|
|
|
|
{ Type::Mtproto, "MTPROTO" },
|
|
|
|
};
|
2021-03-13 08:26:58 +00:00
|
|
|
for (const auto &[type, label] : types) {
|
2018-04-28 15:58:22 +00:00
|
|
|
_content->add(
|
|
|
|
object_ptr<Ui::Radioenum<Type>>(
|
|
|
|
_content,
|
|
|
|
_type,
|
|
|
|
type,
|
|
|
|
label),
|
|
|
|
st::proxyEditTypePadding);
|
|
|
|
}
|
2018-05-15 17:22:28 +00:00
|
|
|
_aboutSponsored = _content->add(object_ptr<Ui::SlideWrap<>>(
|
|
|
|
_content,
|
|
|
|
object_ptr<Ui::PaddingWrap<>>(
|
|
|
|
_content,
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
_content,
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_proxy_sponsor_warning(tr::now),
|
2018-05-15 17:22:28 +00:00
|
|
|
st::boxDividerLabel),
|
|
|
|
st::proxyAboutSponsorPadding)));
|
2018-04-28 15:58:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProxyBox::setupSocketAddress(const ProxyData &data) {
|
2019-06-19 15:09:03 +00:00
|
|
|
addLabel(_content, tr::lng_proxy_address_label(tr::now));
|
2018-04-28 15:58:22 +00:00
|
|
|
const auto address = _content->add(
|
|
|
|
object_ptr<Ui::FixedHeightWidget>(
|
|
|
|
_content,
|
|
|
|
st::connectionHostInputField.heightMin),
|
|
|
|
st::proxyEditInputPadding);
|
2020-09-01 10:50:32 +00:00
|
|
|
_host = Ui::CreateChild<HostInput>(
|
2018-04-28 15:58:22 +00:00
|
|
|
address,
|
|
|
|
st::connectionHostInputField,
|
2019-06-18 14:07:45 +00:00
|
|
|
tr::lng_connection_host_ph(),
|
2018-04-28 15:58:22 +00:00
|
|
|
data.host);
|
2021-01-19 06:22:25 +00:00
|
|
|
_port = Ui::CreateChild<Ui::NumberInput>(
|
2018-04-28 15:58:22 +00:00
|
|
|
address,
|
|
|
|
st::connectionPortInputField,
|
2019-06-18 14:07:45 +00:00
|
|
|
tr::lng_connection_port_ph(),
|
2021-01-19 06:22:25 +00:00
|
|
|
data.port ? QString::number(data.port) : QString(),
|
|
|
|
65535);
|
2018-04-28 15:58:22 +00:00
|
|
|
address->widthValue(
|
|
|
|
) | rpl::start_with_next([=](int width) {
|
|
|
|
_port->moveToRight(0, 0);
|
|
|
|
_host->resize(
|
|
|
|
width - _port->width() - st::proxyEditSkip,
|
|
|
|
_host->height());
|
|
|
|
_host->moveToLeft(0, 0);
|
|
|
|
}, address->lifetime());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProxyBox::setupCredentials(const ProxyData &data) {
|
|
|
|
_credentials = _content->add(
|
|
|
|
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
|
|
|
_content,
|
|
|
|
object_ptr<Ui::VerticalLayout>(_content)));
|
|
|
|
const auto credentials = _credentials->entity();
|
2019-06-19 15:09:03 +00:00
|
|
|
addLabel(credentials, tr::lng_proxy_credentials_optional(tr::now));
|
2018-04-28 15:58:22 +00:00
|
|
|
_user = credentials->add(
|
|
|
|
object_ptr<Ui::InputField>(
|
|
|
|
credentials,
|
|
|
|
st::connectionUserInputField,
|
2019-06-18 14:07:45 +00:00
|
|
|
tr::lng_connection_user_ph(),
|
2018-04-28 15:58:22 +00:00
|
|
|
data.user),
|
|
|
|
st::proxyEditInputPadding);
|
|
|
|
|
|
|
|
auto passwordWrap = object_ptr<Ui::RpWidget>(credentials);
|
|
|
|
_password = Ui::CreateChild<Ui::PasswordInput>(
|
|
|
|
passwordWrap.data(),
|
|
|
|
st::connectionPasswordInputField,
|
2019-06-18 14:07:45 +00:00
|
|
|
tr::lng_connection_password_ph(),
|
2018-04-28 15:58:22 +00:00
|
|
|
(data.type == Type::Mtproto) ? QString() : data.password);
|
|
|
|
_password->move(0, 0);
|
|
|
|
_password->heightValue(
|
|
|
|
) | rpl::start_with_next([=, wrap = passwordWrap.data()](int height) {
|
|
|
|
wrap->resize(wrap->width(), height);
|
|
|
|
}, _password->lifetime());
|
|
|
|
passwordWrap->widthValue(
|
|
|
|
) | rpl::start_with_next([=](int width) {
|
|
|
|
_password->resize(width, _password->height());
|
|
|
|
}, _password->lifetime());
|
|
|
|
credentials->add(std::move(passwordWrap), st::proxyEditInputPadding);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProxyBox::setupMtprotoCredentials(const ProxyData &data) {
|
|
|
|
_mtprotoCredentials = _content->add(
|
|
|
|
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
|
|
|
_content,
|
|
|
|
object_ptr<Ui::VerticalLayout>(_content)));
|
|
|
|
const auto mtproto = _mtprotoCredentials->entity();
|
2019-06-19 15:09:03 +00:00
|
|
|
addLabel(mtproto, tr::lng_proxy_credentials(tr::now));
|
2018-04-28 15:58:22 +00:00
|
|
|
|
|
|
|
auto secretWrap = object_ptr<Ui::RpWidget>(mtproto);
|
2019-07-08 16:02:45 +00:00
|
|
|
_secret = Ui::CreateChild<Base64UrlInput>(
|
2018-04-28 15:58:22 +00:00
|
|
|
secretWrap.data(),
|
|
|
|
st::connectionUserInputField,
|
2019-06-18 14:07:45 +00:00
|
|
|
tr::lng_connection_proxy_secret_ph(),
|
2018-04-28 15:58:22 +00:00
|
|
|
(data.type == Type::Mtproto) ? data.password : QString());
|
|
|
|
_secret->move(0, 0);
|
|
|
|
_secret->heightValue(
|
|
|
|
) | rpl::start_with_next([=, wrap = secretWrap.data()](int height) {
|
|
|
|
wrap->resize(wrap->width(), height);
|
|
|
|
}, _secret->lifetime());
|
|
|
|
secretWrap->widthValue(
|
|
|
|
) | rpl::start_with_next([=](int width) {
|
|
|
|
_secret->resize(width, _secret->height());
|
|
|
|
}, _secret->lifetime());
|
|
|
|
mtproto->add(std::move(secretWrap), st::proxyEditInputPadding);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProxyBox::setupControls(const ProxyData &data) {
|
|
|
|
_type = std::make_shared<Ui::RadioenumGroup<Type>>(
|
|
|
|
(data.type == Type::None
|
|
|
|
? Type::Socks5
|
|
|
|
: data.type));
|
|
|
|
_content.create(this);
|
2018-05-06 21:29:53 +00:00
|
|
|
_content->resizeToWidth(st::boxWideWidth);
|
2018-04-28 15:58:22 +00:00
|
|
|
_content->moveToLeft(0, 0);
|
|
|
|
|
|
|
|
setupTypes();
|
|
|
|
setupSocketAddress(data);
|
|
|
|
setupCredentials(data);
|
|
|
|
setupMtprotoCredentials(data);
|
|
|
|
|
|
|
|
const auto handleType = [=](Type type) {
|
|
|
|
_credentials->toggle(
|
|
|
|
type == Type::Http || type == Type::Socks5,
|
|
|
|
anim::type::instant);
|
|
|
|
_mtprotoCredentials->toggle(
|
|
|
|
type == Type::Mtproto,
|
|
|
|
anim::type::instant);
|
2018-05-15 17:22:28 +00:00
|
|
|
_aboutSponsored->toggle(
|
|
|
|
type == Type::Mtproto,
|
|
|
|
anim::type::instant);
|
2018-04-28 15:58:22 +00:00
|
|
|
};
|
|
|
|
_type->setChangedCallback([=](Type type) {
|
|
|
|
handleType(type);
|
|
|
|
refreshButtons();
|
|
|
|
});
|
|
|
|
handleType(_type->value());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProxyBox::addLabel(
|
|
|
|
not_null<Ui::VerticalLayout*> parent,
|
|
|
|
const QString &text) const {
|
|
|
|
parent->add(
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
parent,
|
|
|
|
text,
|
|
|
|
st::proxyEditTitle),
|
|
|
|
st::proxyEditTitlePadding);
|
2018-04-28 09:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2020-06-10 14:52:44 +00:00
|
|
|
ProxiesBoxController::ProxiesBoxController(not_null<Main::Account*> account)
|
|
|
|
: _account(account)
|
2021-06-10 22:49:08 +00:00
|
|
|
, _settings(Core::App().settings().proxy())
|
2020-06-10 14:52:44 +00:00
|
|
|
, _saveTimer([] { Local::writeSettings(); }) {
|
2021-03-13 12:12:08 +00:00
|
|
|
_list = ranges::views::all(
|
2021-06-10 22:49:08 +00:00
|
|
|
_settings.list()
|
2021-03-13 12:12:08 +00:00
|
|
|
) | ranges::views::transform([&](const ProxyData &proxy) {
|
2018-04-28 09:27:43 +00:00
|
|
|
return Item{ ++_idCounter, proxy };
|
|
|
|
}) | ranges::to_vector;
|
2018-04-30 16:11:36 +00:00
|
|
|
|
2021-06-10 22:49:08 +00:00
|
|
|
_settings.connectionTypeChanges(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
_proxySettingsChanges.fire_copy(_settings.settings());
|
|
|
|
const auto i = findByProxy(_settings.selected());
|
2018-04-30 16:11:36 +00:00
|
|
|
if (i != end(_list)) {
|
|
|
|
updateView(*i);
|
2018-04-30 15:49:03 +00:00
|
|
|
}
|
2021-06-10 22:49:08 +00:00
|
|
|
}, _lifetime);
|
2018-04-30 16:11:36 +00:00
|
|
|
|
|
|
|
for (auto &item : _list) {
|
|
|
|
refreshChecker(item);
|
2018-04-30 15:49:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-11 14:03:53 +00:00
|
|
|
void ProxiesBoxController::ShowApplyConfirmation(
|
|
|
|
Type type,
|
|
|
|
const QMap<QString, QString> &fields) {
|
2022-11-29 21:46:36 +00:00
|
|
|
const auto server = fields.value(u"server"_q);
|
|
|
|
const auto port = fields.value(u"port"_q).toUInt();
|
2018-05-11 14:03:53 +00:00
|
|
|
auto proxy = ProxyData();
|
|
|
|
proxy.type = type;
|
|
|
|
proxy.host = server;
|
|
|
|
proxy.port = port;
|
|
|
|
if (type == Type::Socks5) {
|
2022-11-29 21:46:36 +00:00
|
|
|
proxy.user = fields.value(u"user"_q);
|
|
|
|
proxy.password = fields.value(u"pass"_q);
|
2018-05-11 14:03:53 +00:00
|
|
|
} else if (type == Type::Mtproto) {
|
2022-11-29 21:46:36 +00:00
|
|
|
proxy.password = fields.value(u"secret"_q);
|
2018-05-11 14:03:53 +00:00
|
|
|
}
|
|
|
|
if (proxy) {
|
2021-06-11 09:30:12 +00:00
|
|
|
const auto displayed = "https://" + server + "/";
|
|
|
|
const auto parsed = QUrl::fromUserInput(displayed);
|
|
|
|
const auto displayUrl = !UrlClickHandler::IsSuspicious(displayed)
|
|
|
|
? displayed
|
|
|
|
: parsed.isValid()
|
|
|
|
? QString::fromUtf8(parsed.toEncoded())
|
|
|
|
: UrlClickHandler::ShowEncoded(displayed);
|
|
|
|
const auto displayServer = QString(
|
|
|
|
displayUrl
|
|
|
|
).replace(
|
|
|
|
QRegularExpression(
|
|
|
|
"^https://",
|
|
|
|
QRegularExpression::CaseInsensitiveOption),
|
|
|
|
QString()
|
|
|
|
).replace(QRegularExpression("/$"), QString());
|
2019-06-19 16:39:25 +00:00
|
|
|
const auto text = tr::lng_sure_enable_socks(
|
|
|
|
tr::now,
|
2018-05-11 14:03:53 +00:00
|
|
|
lt_server,
|
2021-06-11 09:30:12 +00:00
|
|
|
displayServer,
|
2018-05-11 14:03:53 +00:00
|
|
|
lt_port,
|
2018-05-15 17:22:28 +00:00
|
|
|
QString::number(port))
|
|
|
|
+ (proxy.type == Type::Mtproto
|
2019-06-19 15:09:03 +00:00
|
|
|
? "\n\n" + tr::lng_proxy_sponsor_warning(tr::now)
|
2018-05-15 17:22:28 +00:00
|
|
|
: QString());
|
2020-09-24 12:48:02 +00:00
|
|
|
auto callback = [=](Fn<void()> &&close) {
|
2021-06-10 22:49:08 +00:00
|
|
|
auto &proxies = Core::App().settings().proxy().list();
|
2020-05-18 19:33:14 +00:00
|
|
|
if (!ranges::contains(proxies, proxy)) {
|
2018-05-11 14:03:53 +00:00
|
|
|
proxies.push_back(proxy);
|
|
|
|
}
|
2019-01-21 13:42:21 +00:00
|
|
|
Core::App().setCurrentProxy(
|
2018-11-05 13:58:24 +00:00
|
|
|
proxy,
|
|
|
|
ProxyData::Settings::Enabled);
|
2018-05-11 14:03:53 +00:00
|
|
|
Local::writeSettings();
|
2020-09-24 12:48:02 +00:00
|
|
|
close();
|
|
|
|
};
|
|
|
|
Ui::show(
|
2022-02-27 08:23:20 +00:00
|
|
|
Ui::MakeConfirmBox({
|
|
|
|
.text = text,
|
|
|
|
.confirmed = std::move(callback),
|
|
|
|
.confirmText = tr::lng_sure_enable(),
|
|
|
|
}),
|
2020-09-24 12:48:02 +00:00
|
|
|
Ui::LayerOption::KeepOther);
|
2019-07-08 16:02:45 +00:00
|
|
|
} else {
|
2022-02-27 08:23:20 +00:00
|
|
|
Ui::show(Ui::MakeInformBox(
|
2019-07-08 16:02:45 +00:00
|
|
|
(proxy.status() == ProxyData::Status::Unsupported
|
|
|
|
? tr::lng_proxy_unsupported(tr::now)
|
|
|
|
: tr::lng_proxy_invalid(tr::now))));
|
2018-05-11 14:03:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-05 13:58:24 +00:00
|
|
|
auto ProxiesBoxController::proxySettingsValue() const
|
|
|
|
-> rpl::producer<ProxyData::Settings> {
|
|
|
|
return _proxySettingsChanges.events_starting_with_copy(
|
2021-06-10 22:49:08 +00:00
|
|
|
_settings.settings()
|
2018-04-30 16:11:36 +00:00
|
|
|
) | rpl::distinct_until_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProxiesBoxController::refreshChecker(Item &item) {
|
2018-04-30 15:49:03 +00:00
|
|
|
using Variants = MTP::DcOptions::Variants;
|
2018-05-05 13:14:46 +00:00
|
|
|
const auto type = (item.data.type == Type::Http)
|
2018-04-30 15:49:03 +00:00
|
|
|
? Variants::Http
|
|
|
|
: Variants::Tcp;
|
2020-06-17 09:36:25 +00:00
|
|
|
const auto mtproto = &_account->mtp();
|
2018-04-30 15:49:03 +00:00
|
|
|
const auto dcId = mtproto->mainDcId();
|
2021-06-15 12:49:53 +00:00
|
|
|
const auto forFiles = false;
|
2018-04-30 15:49:03 +00:00
|
|
|
|
|
|
|
item.state = ItemState::Checking;
|
2019-07-15 08:21:28 +00:00
|
|
|
const auto setup = [&](Checker &checker, const bytes::vector &secret) {
|
2019-12-02 13:10:19 +00:00
|
|
|
checker = MTP::details::AbstractConnection::Create(
|
2018-05-17 19:58:00 +00:00
|
|
|
mtproto,
|
2018-04-30 15:49:03 +00:00
|
|
|
type,
|
2018-05-17 19:58:00 +00:00
|
|
|
QThread::currentThread(),
|
2019-07-15 08:21:28 +00:00
|
|
|
secret,
|
2018-05-17 19:58:00 +00:00
|
|
|
item.data);
|
2018-04-30 15:49:03 +00:00
|
|
|
setupChecker(item.id, checker);
|
|
|
|
};
|
2018-05-05 13:14:46 +00:00
|
|
|
if (item.data.type == Type::Mtproto) {
|
2019-07-15 08:21:28 +00:00
|
|
|
const auto secret = item.data.secretFromMtprotoPassword();
|
|
|
|
setup(item.checker, secret);
|
2018-04-30 15:49:03 +00:00
|
|
|
item.checker->connectToServer(
|
|
|
|
item.data.host,
|
|
|
|
item.data.port,
|
2019-07-15 08:21:28 +00:00
|
|
|
secret,
|
2021-06-15 12:49:53 +00:00
|
|
|
dcId,
|
|
|
|
forFiles);
|
2019-07-15 08:21:28 +00:00
|
|
|
item.checkerv6 = nullptr;
|
2018-04-30 15:49:03 +00:00
|
|
|
} else {
|
2020-06-17 09:36:25 +00:00
|
|
|
const auto options = mtproto->dcOptions().lookup(
|
2018-04-30 15:49:03 +00:00
|
|
|
dcId,
|
|
|
|
MTP::DcType::Regular,
|
|
|
|
true);
|
|
|
|
const auto connect = [&](
|
2019-07-15 08:21:28 +00:00
|
|
|
Checker &checker,
|
|
|
|
Variants::Address address) {
|
|
|
|
const auto &list = options.data[address][type];
|
|
|
|
if (list.empty()
|
2021-06-10 22:49:08 +00:00
|
|
|
|| ((address == Variants::IPv6)
|
|
|
|
&& !Core::App().settings().proxy().tryIPv6())) {
|
2019-07-15 08:21:28 +00:00
|
|
|
checker = nullptr;
|
|
|
|
return;
|
2018-04-30 15:49:03 +00:00
|
|
|
}
|
2019-07-15 08:21:28 +00:00
|
|
|
const auto &endpoint = list.front();
|
|
|
|
setup(checker, endpoint.secret);
|
|
|
|
checker->connectToServer(
|
|
|
|
QString::fromStdString(endpoint.ip),
|
|
|
|
endpoint.port,
|
|
|
|
endpoint.secret,
|
2021-06-15 12:49:53 +00:00
|
|
|
dcId,
|
|
|
|
forFiles);
|
2018-04-30 15:49:03 +00:00
|
|
|
};
|
2019-07-15 08:21:28 +00:00
|
|
|
connect(item.checker, Variants::IPv4);
|
|
|
|
connect(item.checkerv6, Variants::IPv6);
|
|
|
|
if (!item.checker && !item.checkerv6) {
|
|
|
|
item.state = ItemState::Unavailable;
|
|
|
|
}
|
2018-04-30 15:49:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProxiesBoxController::setupChecker(int id, const Checker &checker) {
|
2019-12-02 13:10:19 +00:00
|
|
|
using Connection = MTP::details::AbstractConnection;
|
2018-04-30 15:49:03 +00:00
|
|
|
const auto pointer = checker.get();
|
|
|
|
pointer->connect(pointer, &Connection::connected, [=] {
|
|
|
|
const auto item = findById(id);
|
|
|
|
const auto pingTime = pointer->pingTime();
|
|
|
|
item->checker = nullptr;
|
|
|
|
item->checkerv6 = nullptr;
|
|
|
|
if (item->state == ItemState::Checking) {
|
|
|
|
item->state = ItemState::Available;
|
|
|
|
item->ping = pingTime;
|
|
|
|
updateView(*item);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const auto failed = [=] {
|
|
|
|
const auto item = findById(id);
|
|
|
|
if (item->checker == pointer) {
|
|
|
|
item->checker = nullptr;
|
|
|
|
} else if (item->checkerv6 == pointer) {
|
|
|
|
item->checkerv6 = nullptr;
|
|
|
|
}
|
2018-05-04 18:28:26 +00:00
|
|
|
if (!item->checker
|
|
|
|
&& !item->checkerv6
|
|
|
|
&& item->state == ItemState::Checking) {
|
2018-04-30 15:49:03 +00:00
|
|
|
item->state = ItemState::Unavailable;
|
|
|
|
updateView(*item);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
pointer->connect(pointer, &Connection::disconnected, failed);
|
|
|
|
pointer->connect(pointer, &Connection::error, failed);
|
2018-04-28 09:27:43 +00:00
|
|
|
}
|
|
|
|
|
2020-06-10 14:52:44 +00:00
|
|
|
object_ptr<Ui::BoxContent> ProxiesBoxController::CreateOwningBox(
|
|
|
|
not_null<Main::Account*> account) {
|
|
|
|
auto controller = std::make_unique<ProxiesBoxController>(account);
|
2018-04-28 09:27:43 +00:00
|
|
|
auto box = controller->create();
|
|
|
|
Ui::AttachAsChild(box, std::move(controller));
|
|
|
|
return box;
|
|
|
|
}
|
|
|
|
|
2019-09-18 11:19:05 +00:00
|
|
|
object_ptr<Ui::BoxContent> ProxiesBoxController::create() {
|
2021-06-10 22:49:08 +00:00
|
|
|
auto result = Box<ProxiesBox>(this, _settings);
|
2023-05-02 09:33:19 +00:00
|
|
|
_show = result->uiShow();
|
2018-05-17 19:58:00 +00:00
|
|
|
for (const auto &item : _list) {
|
2018-04-28 09:27:43 +00:00
|
|
|
updateView(item);
|
|
|
|
}
|
2019-11-12 15:15:34 +00:00
|
|
|
return result;
|
2018-04-28 09:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto ProxiesBoxController::findById(int id) -> std::vector<Item>::iterator {
|
|
|
|
const auto result = ranges::find(
|
|
|
|
_list,
|
|
|
|
id,
|
|
|
|
[](const Item &item) { return item.id; });
|
|
|
|
Assert(result != end(_list));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-04-28 14:06:59 +00:00
|
|
|
auto ProxiesBoxController::findByProxy(const ProxyData &proxy)
|
|
|
|
->std::vector<Item>::iterator {
|
|
|
|
return ranges::find(
|
|
|
|
_list,
|
|
|
|
proxy,
|
|
|
|
[](const Item &item) { return item.data; });
|
|
|
|
}
|
|
|
|
|
2018-04-28 09:27:43 +00:00
|
|
|
void ProxiesBoxController::deleteItem(int id) {
|
|
|
|
setDeleted(id, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProxiesBoxController::restoreItem(int id) {
|
|
|
|
setDeleted(id, false);
|
|
|
|
}
|
|
|
|
|
2018-05-05 13:14:46 +00:00
|
|
|
void ProxiesBoxController::shareItem(int id) {
|
|
|
|
share(findById(id)->data);
|
|
|
|
}
|
|
|
|
|
2018-04-28 14:06:59 +00:00
|
|
|
void ProxiesBoxController::applyItem(int id) {
|
|
|
|
auto item = findById(id);
|
2021-06-10 22:49:08 +00:00
|
|
|
if (_settings.isEnabled() && (_settings.selected() == item->data)) {
|
2018-04-28 14:06:59 +00:00
|
|
|
return;
|
|
|
|
} else if (item->deleted) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-10 22:49:08 +00:00
|
|
|
auto j = findByProxy(_settings.selected());
|
2018-04-28 14:06:59 +00:00
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
Core::App().setCurrentProxy(
|
2018-11-05 13:58:24 +00:00
|
|
|
item->data,
|
|
|
|
ProxyData::Settings::Enabled);
|
2018-05-11 14:03:53 +00:00
|
|
|
saveDelayed();
|
2018-04-28 14:06:59 +00:00
|
|
|
|
|
|
|
if (j != end(_list)) {
|
|
|
|
updateView(*j);
|
|
|
|
}
|
|
|
|
updateView(*item);
|
|
|
|
}
|
|
|
|
|
2018-04-28 09:27:43 +00:00
|
|
|
void ProxiesBoxController::setDeleted(int id, bool deleted) {
|
|
|
|
auto item = findById(id);
|
|
|
|
item->deleted = deleted;
|
2018-04-28 14:06:59 +00:00
|
|
|
|
|
|
|
if (deleted) {
|
2021-06-10 22:49:08 +00:00
|
|
|
auto &proxies = _settings.list();
|
2018-04-28 14:06:59 +00:00
|
|
|
proxies.erase(ranges::remove(proxies, item->data), end(proxies));
|
|
|
|
|
2021-06-10 22:49:08 +00:00
|
|
|
if (item->data == _settings.selected()) {
|
|
|
|
_lastSelectedProxy = _settings.selected();
|
|
|
|
_settings.setSelected(MTP::ProxyData());
|
|
|
|
if (_settings.isEnabled()) {
|
2018-04-28 14:06:59 +00:00
|
|
|
_lastSelectedProxyUsed = true;
|
2019-01-21 13:42:21 +00:00
|
|
|
Core::App().setCurrentProxy(
|
2018-05-11 14:03:53 +00:00
|
|
|
ProxyData(),
|
2018-11-05 13:58:24 +00:00
|
|
|
ProxyData::Settings::System);
|
2018-05-11 14:03:53 +00:00
|
|
|
saveDelayed();
|
2018-04-28 14:06:59 +00:00
|
|
|
} else {
|
|
|
|
_lastSelectedProxyUsed = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2021-06-10 22:49:08 +00:00
|
|
|
auto &proxies = _settings.list();
|
2018-04-28 14:06:59 +00:00
|
|
|
if (ranges::find(proxies, item->data) == end(proxies)) {
|
|
|
|
auto insertBefore = item + 1;
|
|
|
|
while (insertBefore != end(_list) && insertBefore->deleted) {
|
|
|
|
++insertBefore;
|
|
|
|
}
|
|
|
|
auto insertBeforeIt = (insertBefore == end(_list))
|
|
|
|
? end(proxies)
|
|
|
|
: ranges::find(proxies, insertBefore->data);
|
|
|
|
proxies.insert(insertBeforeIt, item->data);
|
|
|
|
}
|
|
|
|
|
2021-06-10 22:49:08 +00:00
|
|
|
if (!_settings.selected() && _lastSelectedProxy == item->data) {
|
|
|
|
Assert(!_settings.isEnabled());
|
2018-04-28 14:06:59 +00:00
|
|
|
|
|
|
|
if (base::take(_lastSelectedProxyUsed)) {
|
2019-01-21 13:42:21 +00:00
|
|
|
Core::App().setCurrentProxy(
|
2018-05-11 14:03:53 +00:00
|
|
|
base::take(_lastSelectedProxy),
|
2018-11-05 13:58:24 +00:00
|
|
|
ProxyData::Settings::Enabled);
|
2018-05-11 14:03:53 +00:00
|
|
|
} else {
|
2021-06-10 22:49:08 +00:00
|
|
|
_settings.setSelected(base::take(_lastSelectedProxy));
|
2018-04-28 14:06:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
saveDelayed();
|
2018-04-28 09:27:43 +00:00
|
|
|
updateView(*item);
|
|
|
|
}
|
|
|
|
|
2019-09-18 11:19:05 +00:00
|
|
|
object_ptr<Ui::BoxContent> ProxiesBoxController::editItemBox(int id) {
|
2018-04-28 09:27:43 +00:00
|
|
|
return Box<ProxyBox>(findById(id)->data, [=](const ProxyData &result) {
|
|
|
|
auto i = findById(id);
|
|
|
|
auto j = ranges::find(
|
|
|
|
_list,
|
|
|
|
result,
|
|
|
|
[](const Item &item) { return item.data; });
|
|
|
|
if (j != end(_list) && j != i) {
|
2018-04-28 15:58:22 +00:00
|
|
|
replaceItemWith(i, j);
|
2018-04-28 09:27:43 +00:00
|
|
|
} else {
|
2018-04-28 15:58:22 +00:00
|
|
|
replaceItemValue(i, result);
|
2018-04-28 09:27:43 +00:00
|
|
|
}
|
2018-05-05 13:14:46 +00:00
|
|
|
}, [=](const ProxyData &proxy) {
|
|
|
|
share(proxy);
|
2018-04-28 09:27:43 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-04-28 15:58:22 +00:00
|
|
|
void ProxiesBoxController::replaceItemWith(
|
|
|
|
std::vector<Item>::iterator which,
|
|
|
|
std::vector<Item>::iterator with) {
|
2021-06-10 22:49:08 +00:00
|
|
|
auto &proxies = _settings.list();
|
2018-04-28 15:58:22 +00:00
|
|
|
proxies.erase(ranges::remove(proxies, which->data), end(proxies));
|
|
|
|
|
|
|
|
_views.fire({ which->id });
|
|
|
|
_list.erase(which);
|
|
|
|
|
|
|
|
if (with->deleted) {
|
|
|
|
restoreItem(with->id);
|
|
|
|
}
|
|
|
|
applyItem(with->id);
|
|
|
|
saveDelayed();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProxiesBoxController::replaceItemValue(
|
|
|
|
std::vector<Item>::iterator which,
|
|
|
|
const ProxyData &proxy) {
|
|
|
|
if (which->deleted) {
|
|
|
|
restoreItem(which->id);
|
|
|
|
}
|
|
|
|
|
2021-06-10 22:49:08 +00:00
|
|
|
auto &proxies = _settings.list();
|
2018-04-28 15:58:22 +00:00
|
|
|
const auto i = ranges::find(proxies, which->data);
|
|
|
|
Assert(i != end(proxies));
|
|
|
|
*i = proxy;
|
|
|
|
which->data = proxy;
|
2018-04-30 16:11:36 +00:00
|
|
|
refreshChecker(*which);
|
2018-04-28 15:58:22 +00:00
|
|
|
|
|
|
|
applyItem(which->id);
|
|
|
|
saveDelayed();
|
|
|
|
}
|
|
|
|
|
2019-09-18 11:19:05 +00:00
|
|
|
object_ptr<Ui::BoxContent> ProxiesBoxController::addNewItemBox() {
|
2018-04-28 09:27:43 +00:00
|
|
|
return Box<ProxyBox>(ProxyData(), [=](const ProxyData &result) {
|
|
|
|
auto j = ranges::find(
|
|
|
|
_list,
|
|
|
|
result,
|
|
|
|
[](const Item &item) { return item.data; });
|
|
|
|
if (j != end(_list)) {
|
|
|
|
if (j->deleted) {
|
|
|
|
restoreItem(j->id);
|
|
|
|
}
|
2018-04-28 15:58:22 +00:00
|
|
|
applyItem(j->id);
|
2018-04-28 09:27:43 +00:00
|
|
|
} else {
|
2018-04-28 15:58:22 +00:00
|
|
|
addNewItem(result);
|
2018-04-28 09:27:43 +00:00
|
|
|
}
|
2018-05-05 13:14:46 +00:00
|
|
|
}, [=](const ProxyData &proxy) {
|
|
|
|
share(proxy);
|
2018-04-28 09:27:43 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-04-28 15:58:22 +00:00
|
|
|
void ProxiesBoxController::addNewItem(const ProxyData &proxy) {
|
2021-06-10 22:49:08 +00:00
|
|
|
auto &proxies = _settings.list();
|
2018-04-28 15:58:22 +00:00
|
|
|
proxies.push_back(proxy);
|
|
|
|
|
|
|
|
_list.push_back({ ++_idCounter, proxy });
|
2018-04-30 16:11:36 +00:00
|
|
|
refreshChecker(_list.back());
|
2018-04-28 15:58:22 +00:00
|
|
|
applyItem(_list.back().id);
|
|
|
|
}
|
|
|
|
|
2018-11-05 13:58:24 +00:00
|
|
|
bool ProxiesBoxController::setProxySettings(ProxyData::Settings value) {
|
2021-06-10 22:49:08 +00:00
|
|
|
if (_settings.settings() == value) {
|
2018-05-04 18:28:26 +00:00
|
|
|
return true;
|
2018-11-05 13:58:24 +00:00
|
|
|
} else if (value == ProxyData::Settings::Enabled) {
|
2021-06-10 22:49:08 +00:00
|
|
|
if (_settings.list().empty()) {
|
2018-04-28 14:06:59 +00:00
|
|
|
return false;
|
2021-06-10 22:49:08 +00:00
|
|
|
} else if (!_settings.selected()) {
|
|
|
|
_settings.setSelected(_settings.list().back());
|
|
|
|
auto j = findByProxy(_settings.selected());
|
2018-04-28 14:06:59 +00:00
|
|
|
if (j != end(_list)) {
|
|
|
|
updateView(*j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-06-10 22:49:08 +00:00
|
|
|
Core::App().setCurrentProxy(_settings.selected(), value);
|
2018-05-11 14:03:53 +00:00
|
|
|
saveDelayed();
|
2018-04-28 14:06:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-05-06 21:29:53 +00:00
|
|
|
void ProxiesBoxController::setProxyForCalls(bool enabled) {
|
2021-06-10 22:49:08 +00:00
|
|
|
if (_settings.useProxyForCalls() == enabled) {
|
2018-05-06 21:29:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-06-10 22:49:08 +00:00
|
|
|
_settings.setUseProxyForCalls(enabled);
|
|
|
|
if (_settings.isEnabled() && _settings.selected().supportsCalls()) {
|
|
|
|
_settings.connectionTypeChangesNotify();
|
2018-05-06 21:29:53 +00:00
|
|
|
}
|
|
|
|
saveDelayed();
|
|
|
|
}
|
|
|
|
|
2018-04-28 15:58:22 +00:00
|
|
|
void ProxiesBoxController::setTryIPv6(bool enabled) {
|
2021-06-10 22:49:08 +00:00
|
|
|
if (Core::App().settings().proxy().tryIPv6() == enabled) {
|
2018-04-28 15:58:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-06-10 22:49:08 +00:00
|
|
|
Core::App().settings().proxy().setTryIPv6(enabled);
|
2020-06-17 09:36:25 +00:00
|
|
|
_account->mtp().restart();
|
2021-06-10 22:49:08 +00:00
|
|
|
_settings.connectionTypeChangesNotify();
|
2018-04-28 14:06:59 +00:00
|
|
|
saveDelayed();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProxiesBoxController::saveDelayed() {
|
|
|
|
_saveTimer.callOnce(kSaveSettingsDelayedTimeout);
|
|
|
|
}
|
|
|
|
|
2018-04-28 09:27:43 +00:00
|
|
|
auto ProxiesBoxController::views() const -> rpl::producer<ItemView> {
|
|
|
|
return _views.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProxiesBoxController::updateView(const Item &item) {
|
2021-06-10 22:49:08 +00:00
|
|
|
const auto selected = (_settings.selected() == item.data);
|
2018-04-28 09:27:43 +00:00
|
|
|
const auto deleted = item.deleted;
|
|
|
|
const auto type = [&] {
|
|
|
|
switch (item.data.type) {
|
2022-11-29 21:46:36 +00:00
|
|
|
case Type::Http: return u"HTTP"_q;
|
|
|
|
case Type::Socks5: return u"SOCKS5"_q;
|
|
|
|
case Type::Mtproto: return u"MTPROTO"_q;
|
2018-04-28 09:27:43 +00:00
|
|
|
}
|
|
|
|
Unexpected("Proxy type in ProxiesBoxController::updateView.");
|
|
|
|
}();
|
2018-04-30 16:11:36 +00:00
|
|
|
const auto state = [&] {
|
2021-06-10 22:49:08 +00:00
|
|
|
if (!selected || !_settings.isEnabled()) {
|
2018-04-30 16:11:36 +00:00
|
|
|
return item.state;
|
2020-06-17 09:36:25 +00:00
|
|
|
} else if (_account->mtp().dcstate() == MTP::ConnectedState) {
|
2018-04-30 16:11:36 +00:00
|
|
|
return ItemState::Online;
|
|
|
|
}
|
|
|
|
return ItemState::Connecting;
|
|
|
|
}();
|
2018-05-06 21:29:53 +00:00
|
|
|
const auto supportsShare = (item.data.type == Type::Socks5)
|
2018-05-05 13:14:46 +00:00
|
|
|
|| (item.data.type == Type::Mtproto);
|
2018-05-06 21:29:53 +00:00
|
|
|
const auto supportsCalls = item.data.supportsCalls();
|
2018-04-28 09:27:43 +00:00
|
|
|
_views.fire({
|
|
|
|
item.id,
|
|
|
|
type,
|
|
|
|
item.data.host,
|
|
|
|
item.data.port,
|
2018-04-30 15:49:03 +00:00
|
|
|
item.ping,
|
2018-04-28 09:27:43 +00:00
|
|
|
!deleted && selected,
|
|
|
|
deleted,
|
2018-05-06 21:29:53 +00:00
|
|
|
!deleted && supportsShare,
|
|
|
|
supportsCalls,
|
2018-04-30 16:11:36 +00:00
|
|
|
state });
|
2018-04-28 09:27:43 +00:00
|
|
|
}
|
2018-04-28 14:06:59 +00:00
|
|
|
|
2018-05-05 13:14:46 +00:00
|
|
|
void ProxiesBoxController::share(const ProxyData &proxy) {
|
|
|
|
if (proxy.type == Type::Http) {
|
|
|
|
return;
|
|
|
|
}
|
2022-11-29 21:46:36 +00:00
|
|
|
const auto link = u"https://t.me/"_q
|
2018-05-05 13:14:46 +00:00
|
|
|
+ (proxy.type == Type::Socks5 ? "socks" : "proxy")
|
|
|
|
+ "?server=" + proxy.host + "&port=" + QString::number(proxy.port)
|
|
|
|
+ ((proxy.type == Type::Socks5 && !proxy.user.isEmpty())
|
|
|
|
? "&user=" + qthelp::url_encode(proxy.user) : "")
|
|
|
|
+ ((proxy.type == Type::Socks5 && !proxy.password.isEmpty())
|
|
|
|
? "&pass=" + qthelp::url_encode(proxy.password) : "")
|
|
|
|
+ ((proxy.type == Type::Mtproto && !proxy.password.isEmpty())
|
|
|
|
? "&secret=" + proxy.password : "");
|
2019-09-04 07:19:15 +00:00
|
|
|
QGuiApplication::clipboard()->setText(link);
|
2023-05-02 09:33:19 +00:00
|
|
|
_show->showToast(tr::lng_username_copied(tr::now));
|
2018-05-05 13:14:46 +00:00
|
|
|
}
|
|
|
|
|
2018-04-28 14:06:59 +00:00
|
|
|
ProxiesBoxController::~ProxiesBoxController() {
|
|
|
|
if (_saveTimer.isActive()) {
|
2019-09-26 10:55:35 +00:00
|
|
|
base::call_delayed(
|
2018-04-28 14:06:59 +00:00
|
|
|
kSaveSettingsDelayedTimeout,
|
2019-09-04 07:19:15 +00:00
|
|
|
QCoreApplication::instance(),
|
2018-04-28 14:06:59 +00:00
|
|
|
[] { Local::writeSettings(); });
|
|
|
|
}
|
|
|
|
}
|