2014-05-30 12:53:19 +04:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 13:23:14 +03:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2014-05-30 12:53:19 +04:00
|
|
|
|
2018-01-03 13:23:14 +03:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2014-05-30 12:53:19 +04:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-04-06 17:38:10 +03:00
|
|
|
#include "boxes/abstract_box.h"
|
2018-04-28 18:06:59 +04:00
|
|
|
#include "base/timer.h"
|
2018-04-30 19:49:03 +04:00
|
|
|
#include "mtproto/connection_abstract.h"
|
2014-05-30 12:53:19 +04:00
|
|
|
|
2016-10-28 12:20:24 +03:00
|
|
|
namespace Ui {
|
2016-11-15 14:56:49 +03:00
|
|
|
class InputField;
|
|
|
|
class PortInput;
|
|
|
|
class PasswordInput;
|
2016-10-28 12:20:24 +03:00
|
|
|
class Checkbox;
|
2017-03-19 00:06:10 +03:00
|
|
|
template <typename Enum>
|
|
|
|
class RadioenumGroup;
|
|
|
|
template <typename Enum>
|
|
|
|
class Radioenum;
|
2016-10-28 12:20:24 +03:00
|
|
|
} // namespace Ui
|
|
|
|
|
2016-12-13 20:07:56 +03:00
|
|
|
class ConnectionBox : public BoxContent {
|
2014-05-30 12:53:19 +04:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2018-05-05 16:14:46 +03:00
|
|
|
using Type = ProxyData::Type;
|
|
|
|
|
2016-12-13 20:07:56 +03:00
|
|
|
ConnectionBox(QWidget *parent);
|
2014-05-30 12:53:19 +04:00
|
|
|
|
2018-04-27 20:16:50 +04:00
|
|
|
static void ShowApplyProxyConfirmation(
|
2018-05-05 16:14:46 +03:00
|
|
|
Type type,
|
2018-04-27 20:16:50 +04:00
|
|
|
const QMap<QString, QString> &fields);
|
2017-06-27 23:11:38 +03:00
|
|
|
|
2015-04-02 13:33:19 +03:00
|
|
|
protected:
|
2016-12-13 20:07:56 +03:00
|
|
|
void prepare() override;
|
|
|
|
void setInnerFocus() override;
|
|
|
|
|
2016-08-16 19:53:10 +03:00
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
2014-05-30 12:53:19 +04:00
|
|
|
|
2016-12-13 20:07:56 +03:00
|
|
|
private slots:
|
|
|
|
void onSubmit();
|
2017-06-28 01:03:37 +03:00
|
|
|
void onFieldFocus();
|
2016-12-13 20:07:56 +03:00
|
|
|
void onSave();
|
2015-04-02 13:33:19 +03:00
|
|
|
|
|
|
|
private:
|
2018-04-27 21:26:45 +04:00
|
|
|
void typeChanged(Type type);
|
2016-11-18 16:34:58 +03:00
|
|
|
void updateControlsVisibility();
|
2016-12-13 20:07:56 +03:00
|
|
|
void updateControlsPosition();
|
2017-06-28 01:03:37 +03:00
|
|
|
bool badProxyValue() const;
|
2018-04-24 23:09:20 +04:00
|
|
|
bool proxyFieldsVisible() const;
|
2016-11-18 16:34:58 +03:00
|
|
|
|
2016-12-13 20:07:56 +03:00
|
|
|
object_ptr<Ui::InputField> _hostInput;
|
|
|
|
object_ptr<Ui::PortInput> _portInput;
|
|
|
|
object_ptr<Ui::InputField> _userInput;
|
|
|
|
object_ptr<Ui::PasswordInput> _passwordInput;
|
2018-04-27 21:26:45 +04:00
|
|
|
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;
|
2016-12-13 20:07:56 +03:00
|
|
|
object_ptr<Ui::Checkbox> _tryIPv6;
|
2016-08-16 19:53:10 +03:00
|
|
|
|
2014-05-30 12:53:19 +04:00
|
|
|
};
|
2015-12-24 00:19:57 +03:00
|
|
|
|
2016-12-13 20:07:56 +03:00
|
|
|
class AutoDownloadBox : public BoxContent {
|
2015-12-24 00:19:57 +03:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2016-12-13 20:07:56 +03:00
|
|
|
AutoDownloadBox(QWidget *parent);
|
2015-12-24 00:19:57 +03:00
|
|
|
|
|
|
|
protected:
|
2016-12-13 20:07:56 +03:00
|
|
|
void prepare() override;
|
|
|
|
|
2016-08-16 19:53:10 +03:00
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
2015-12-24 00:19:57 +03:00
|
|
|
|
2016-12-13 20:07:56 +03:00
|
|
|
private slots:
|
|
|
|
void onSave();
|
|
|
|
|
2015-12-24 00:19:57 +03:00
|
|
|
private:
|
2016-12-13 20:07:56 +03:00
|
|
|
object_ptr<Ui::Checkbox> _photoPrivate;
|
|
|
|
object_ptr<Ui::Checkbox> _photoGroups;
|
|
|
|
object_ptr<Ui::Checkbox> _audioPrivate;
|
|
|
|
object_ptr<Ui::Checkbox> _audioGroups;
|
|
|
|
object_ptr<Ui::Checkbox> _gifPrivate;
|
|
|
|
object_ptr<Ui::Checkbox> _gifGroups;
|
|
|
|
object_ptr<Ui::Checkbox> _gifPlay;
|
|
|
|
|
|
|
|
int _sectionHeight = 0;
|
2016-08-16 19:53:10 +03:00
|
|
|
|
2015-12-24 00:19:57 +03:00
|
|
|
};
|
2018-04-28 13:27:43 +04:00
|
|
|
|
2018-04-30 20:11:36 +04:00
|
|
|
class ProxiesBoxController : public base::Subscriber {
|
2018-04-28 13:27:43 +04:00
|
|
|
public:
|
2018-05-05 16:14:46 +03:00
|
|
|
using Type = ProxyData::Type;
|
|
|
|
|
2018-04-28 13:27:43 +04:00
|
|
|
ProxiesBoxController();
|
|
|
|
|
|
|
|
static object_ptr<BoxContent> CreateOwningBox();
|
|
|
|
object_ptr<BoxContent> create();
|
|
|
|
|
2018-04-30 19:49:03 +04:00
|
|
|
enum class ItemState {
|
|
|
|
Connecting,
|
|
|
|
Online,
|
|
|
|
Checking,
|
|
|
|
Available,
|
|
|
|
Unavailable
|
|
|
|
};
|
2018-04-28 13:27:43 +04:00
|
|
|
struct ItemView {
|
|
|
|
int id = 0;
|
|
|
|
QString type;
|
|
|
|
QString host;
|
|
|
|
uint32 port = 0;
|
|
|
|
int ping = 0;
|
|
|
|
bool selected = false;
|
|
|
|
bool deleted = false;
|
2018-05-07 00:29:53 +03:00
|
|
|
bool supportsShare = false;
|
|
|
|
bool supportsCalls = false;
|
2018-04-30 19:49:03 +04:00
|
|
|
ItemState state = ItemState::Checking;
|
2018-04-28 13:27:43 +04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
void deleteItem(int id);
|
|
|
|
void restoreItem(int id);
|
2018-05-05 16:14:46 +03:00
|
|
|
void shareItem(int id);
|
2018-04-28 18:06:59 +04:00
|
|
|
void applyItem(int id);
|
2018-04-28 13:27:43 +04:00
|
|
|
object_ptr<BoxContent> editItemBox(int id);
|
|
|
|
object_ptr<BoxContent> addNewItemBox();
|
2018-04-28 18:06:59 +04:00
|
|
|
bool setProxyEnabled(bool enabled);
|
2018-05-07 00:29:53 +03:00
|
|
|
void setProxyForCalls(bool enabled);
|
2018-04-28 19:58:22 +04:00
|
|
|
void setTryIPv6(bool enabled);
|
2018-04-30 20:11:36 +04:00
|
|
|
rpl::producer<bool> proxyEnabledValue() const;
|
2018-04-28 13:27:43 +04:00
|
|
|
|
|
|
|
rpl::producer<ItemView> views() const;
|
|
|
|
|
2018-04-28 18:06:59 +04:00
|
|
|
~ProxiesBoxController();
|
|
|
|
|
2018-04-28 13:27:43 +04:00
|
|
|
private:
|
2018-04-30 19:49:03 +04:00
|
|
|
using Checker = MTP::internal::ConnectionPointer;
|
2018-04-28 13:27:43 +04:00
|
|
|
struct Item {
|
|
|
|
int id = 0;
|
|
|
|
ProxyData data;
|
|
|
|
bool deleted = false;
|
2018-04-30 19:49:03 +04:00
|
|
|
Checker checker;
|
|
|
|
Checker checkerv6;
|
|
|
|
ItemState state = ItemState::Checking;
|
|
|
|
int ping = 0;
|
|
|
|
|
2018-04-28 13:27:43 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<Item>::iterator findById(int id);
|
2018-04-28 18:06:59 +04:00
|
|
|
std::vector<Item>::iterator findByProxy(const ProxyData &proxy);
|
2018-04-28 13:27:43 +04:00
|
|
|
void setDeleted(int id, bool deleted);
|
|
|
|
void updateView(const Item &item);
|
2018-05-05 16:14:46 +03:00
|
|
|
void share(const ProxyData &proxy);
|
2018-04-28 18:06:59 +04:00
|
|
|
void applyChanges();
|
|
|
|
void saveDelayed();
|
2018-04-30 20:11:36 +04:00
|
|
|
void refreshChecker(Item &item);
|
2018-04-30 19:49:03 +04:00
|
|
|
void setupChecker(int id, const Checker &checker);
|
2018-04-28 13:27:43 +04:00
|
|
|
|
2018-04-28 19:58:22 +04: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);
|
|
|
|
|
2018-04-28 13:27:43 +04:00
|
|
|
int _idCounter = 0;
|
|
|
|
std::vector<Item> _list;
|
|
|
|
rpl::event_stream<ItemView> _views;
|
2018-04-28 18:06:59 +04:00
|
|
|
base::Timer _saveTimer;
|
2018-04-30 20:11:36 +04:00
|
|
|
rpl::event_stream<bool> _proxyEnabledChanges;
|
2018-04-28 18:06:59 +04:00
|
|
|
|
|
|
|
ProxyData _lastSelectedProxy;
|
|
|
|
bool _lastSelectedProxyUsed = false;
|
2018-04-28 13:27:43 +04:00
|
|
|
|
|
|
|
};
|