tdesktop/Telegram/SourceFiles/boxes/connection_box.h

128 lines
3.0 KiB
C
Raw Normal View History

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "base/timer.h"
2019-09-18 11:19:05 +00:00
#include "base/object_ptr.h"
#include "core/core_settings.h"
#include "mtproto/connection_abstract.h"
2019-11-13 14:12:04 +00:00
#include "mtproto/mtproto_proxy_data.h"
namespace Ui {
2019-09-18 11:19:05 +00:00
class BoxContent;
class InputField;
class PortInput;
class PasswordInput;
class Checkbox;
template <typename Enum>
class RadioenumGroup;
template <typename Enum>
class Radioenum;
} // namespace Ui
2020-06-10 14:52:44 +00:00
namespace Main {
class Account;
} // namespace Main
class ProxiesBoxController {
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
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
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;
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);
void applyItem(int id);
2019-09-18 11:19:05 +00:00
object_ptr<Ui::BoxContent> editItemBox(int id);
object_ptr<Ui::BoxContent> addNewItemBox();
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);
rpl::producer<ProxyData::Settings> proxySettingsValue() const;
2018-04-28 09:27:43 +00:00
rpl::producer<ItemView> views() const;
~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;
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);
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);
void saveDelayed();
2018-04-30 16:11:36 +00:00
void refreshChecker(Item &item);
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;
Core::SettingsProxy &_settings;
2018-04-28 09:27:43 +00:00
int _idCounter = 0;
std::vector<Item> _list;
rpl::event_stream<ItemView> _views;
base::Timer _saveTimer;
rpl::event_stream<ProxyData::Settings> _proxySettingsChanges;
QPointer<QWidget> _toastParent;
ProxyData _lastSelectedProxy;
bool _lastSelectedProxyUsed = false;
2018-04-28 09:27:43 +00:00
rpl::lifetime _lifetime;
2018-04-28 09:27:43 +00:00
};