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
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2018-04-28 14:06:59 +00:00
|
|
|
#include "base/timer.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "base/object_ptr.h"
|
2018-04-30 15:49:03 +00:00
|
|
|
#include "mtproto/connection_abstract.h"
|
2019-11-13 14:12:04 +00:00
|
|
|
#include "mtproto/mtproto_proxy_data.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
namespace Ui {
|
2019-09-18 11:19:05 +00:00
|
|
|
class BoxContent;
|
2016-11-15 11:56:49 +00:00
|
|
|
class InputField;
|
|
|
|
class PortInput;
|
|
|
|
class PasswordInput;
|
2016-10-28 09:20:24 +00:00
|
|
|
class Checkbox;
|
2017-03-18 21:06:10 +00:00
|
|
|
template <typename Enum>
|
|
|
|
class RadioenumGroup;
|
|
|
|
template <typename Enum>
|
|
|
|
class Radioenum;
|
2016-10-28 09:20:24 +00:00
|
|
|
} // namespace Ui
|
|
|
|
|
2020-06-10 14:52:44 +00:00
|
|
|
namespace Main {
|
|
|
|
class Account;
|
|
|
|
} // namespace Main
|
|
|
|
|
2018-04-30 16:11:36 +00:00
|
|
|
class ProxiesBoxController : public base::Subscriber {
|
2018-04-28 09:27:43 +00:00
|
|
|
public:
|
2019-11-13 14:12:04 +00:00
|
|
|
using ProxyData = MTP::ProxyData;
|
2018-05-05 13:14:46 +00:00
|
|
|
using Type = ProxyData::Type;
|
|
|
|
|
2020-06-10 14:52:44 +00:00
|
|
|
explicit ProxiesBoxController(not_null<Main::Account*> account);
|
2018-04-28 09:27:43 +00:00
|
|
|
|
2018-05-11 14:03:53 +00:00
|
|
|
static void ShowApplyConfirmation(
|
|
|
|
Type type,
|
|
|
|
const QMap<QString, QString> &fields);
|
|
|
|
|
2020-06-10 14:52:44 +00:00
|
|
|
static object_ptr<Ui::BoxContent> CreateOwningBox(
|
|
|
|
not_null<Main::Account*> account);
|
2019-09-18 11:19:05 +00:00
|
|
|
object_ptr<Ui::BoxContent> create();
|
2018-04-28 09:27:43 +00:00
|
|
|
|
2018-04-30 15:49:03 +00:00
|
|
|
enum class ItemState {
|
|
|
|
Connecting,
|
|
|
|
Online,
|
|
|
|
Checking,
|
|
|
|
Available,
|
|
|
|
Unavailable
|
|
|
|
};
|
2018-04-28 09:27:43 +00:00
|
|
|
struct ItemView {
|
|
|
|
int id = 0;
|
|
|
|
QString type;
|
|
|
|
QString host;
|
|
|
|
uint32 port = 0;
|
|
|
|
int ping = 0;
|
|
|
|
bool selected = false;
|
|
|
|
bool deleted = false;
|
2018-05-06 21:29:53 +00:00
|
|
|
bool supportsShare = false;
|
|
|
|
bool supportsCalls = false;
|
2018-04-30 15:49:03 +00:00
|
|
|
ItemState state = ItemState::Checking;
|
2018-04-28 09:27:43 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
void deleteItem(int id);
|
|
|
|
void restoreItem(int id);
|
2018-05-05 13:14:46 +00:00
|
|
|
void shareItem(int id);
|
2018-04-28 14:06:59 +00:00
|
|
|
void applyItem(int id);
|
2019-09-18 11:19:05 +00:00
|
|
|
object_ptr<Ui::BoxContent> editItemBox(int id);
|
|
|
|
object_ptr<Ui::BoxContent> addNewItemBox();
|
2018-11-05 13:58:24 +00:00
|
|
|
bool setProxySettings(ProxyData::Settings value);
|
2018-05-06 21:29:53 +00:00
|
|
|
void setProxyForCalls(bool enabled);
|
2018-04-28 15:58:22 +00:00
|
|
|
void setTryIPv6(bool enabled);
|
2018-11-05 13:58:24 +00:00
|
|
|
rpl::producer<ProxyData::Settings> proxySettingsValue() const;
|
2018-04-28 09:27:43 +00:00
|
|
|
|
|
|
|
rpl::producer<ItemView> views() const;
|
|
|
|
|
2018-04-28 14:06:59 +00:00
|
|
|
~ProxiesBoxController();
|
|
|
|
|
2018-04-28 09:27:43 +00:00
|
|
|
private:
|
2019-12-02 13:10:19 +00:00
|
|
|
using Checker = MTP::details::ConnectionPointer;
|
2018-04-28 09:27:43 +00:00
|
|
|
struct Item {
|
|
|
|
int id = 0;
|
|
|
|
ProxyData data;
|
|
|
|
bool deleted = false;
|
2018-04-30 15:49:03 +00:00
|
|
|
Checker checker;
|
|
|
|
Checker checkerv6;
|
|
|
|
ItemState state = ItemState::Checking;
|
|
|
|
int ping = 0;
|
|
|
|
|
2018-04-28 09:27:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<Item>::iterator findById(int id);
|
2018-04-28 14:06:59 +00:00
|
|
|
std::vector<Item>::iterator findByProxy(const ProxyData &proxy);
|
2018-04-28 09:27:43 +00:00
|
|
|
void setDeleted(int id, bool deleted);
|
|
|
|
void updateView(const Item &item);
|
2018-05-05 13:14:46 +00:00
|
|
|
void share(const ProxyData &proxy);
|
2018-04-28 14:06:59 +00:00
|
|
|
void saveDelayed();
|
2018-04-30 16:11:36 +00:00
|
|
|
void refreshChecker(Item &item);
|
2018-04-30 15:49:03 +00:00
|
|
|
void setupChecker(int id, const Checker &checker);
|
2018-04-28 09:27:43 +00:00
|
|
|
|
2018-04-28 15:58:22 +00:00
|
|
|
void replaceItemWith(
|
|
|
|
std::vector<Item>::iterator which,
|
|
|
|
std::vector<Item>::iterator with);
|
|
|
|
void replaceItemValue(
|
|
|
|
std::vector<Item>::iterator which,
|
|
|
|
const ProxyData &proxy);
|
|
|
|
void addNewItem(const ProxyData &proxy);
|
|
|
|
|
2020-06-10 14:52:44 +00:00
|
|
|
const not_null<Main::Account*> _account;
|
2018-04-28 09:27:43 +00:00
|
|
|
int _idCounter = 0;
|
|
|
|
std::vector<Item> _list;
|
|
|
|
rpl::event_stream<ItemView> _views;
|
2018-04-28 14:06:59 +00:00
|
|
|
base::Timer _saveTimer;
|
2018-11-05 13:58:24 +00:00
|
|
|
rpl::event_stream<ProxyData::Settings> _proxySettingsChanges;
|
2018-04-28 14:06:59 +00:00
|
|
|
|
|
|
|
ProxyData _lastSelectedProxy;
|
|
|
|
bool _lastSelectedProxyUsed = false;
|
2018-04-28 09:27:43 +00:00
|
|
|
|
|
|
|
};
|