connection_box.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. #include "base/timer.h"
  9. #include "base/object_ptr.h"
  10. #include "core/core_settings_proxy.h"
  11. #include "mtproto/connection_abstract.h"
  12. #include "mtproto/mtproto_proxy_data.h"
  13. namespace Ui {
  14. class Show;
  15. class BoxContent;
  16. class InputField;
  17. class PortInput;
  18. class PasswordInput;
  19. class Checkbox;
  20. template <typename Enum>
  21. class RadioenumGroup;
  22. template <typename Enum>
  23. class Radioenum;
  24. } // namespace Ui
  25. namespace Main {
  26. class Account;
  27. } // namespace Main
  28. namespace Window {
  29. class SessionController;
  30. } // namespace Window
  31. class ProxiesBoxController {
  32. public:
  33. using ProxyData = MTP::ProxyData;
  34. using Type = ProxyData::Type;
  35. explicit ProxiesBoxController(not_null<Main::Account*> account);
  36. static void ShowApplyConfirmation(
  37. Window::SessionController *controller,
  38. Type type,
  39. const QMap<QString, QString> &fields);
  40. static object_ptr<Ui::BoxContent> CreateOwningBox(
  41. not_null<Main::Account*> account);
  42. object_ptr<Ui::BoxContent> create();
  43. enum class ItemState {
  44. Connecting,
  45. Online,
  46. Checking,
  47. Available,
  48. Unavailable
  49. };
  50. struct ItemView {
  51. int id = 0;
  52. QString type;
  53. QString host;
  54. uint32 port = 0;
  55. int ping = 0;
  56. bool selected = false;
  57. bool deleted = false;
  58. bool supportsShare = false;
  59. bool supportsCalls = false;
  60. ItemState state = ItemState::Checking;
  61. };
  62. void deleteItem(int id);
  63. void restoreItem(int id);
  64. void shareItem(int id);
  65. void applyItem(int id);
  66. object_ptr<Ui::BoxContent> editItemBox(int id);
  67. object_ptr<Ui::BoxContent> addNewItemBox();
  68. bool setProxySettings(ProxyData::Settings value);
  69. void setProxyForCalls(bool enabled);
  70. void setTryIPv6(bool enabled);
  71. rpl::producer<ProxyData::Settings> proxySettingsValue() const;
  72. [[nodiscard]] bool contains(const ProxyData &proxy) const;
  73. void addNewItem(const ProxyData &proxy);
  74. rpl::producer<ItemView> views() const;
  75. ~ProxiesBoxController();
  76. private:
  77. using Checker = MTP::details::ConnectionPointer;
  78. struct Item {
  79. int id = 0;
  80. ProxyData data;
  81. bool deleted = false;
  82. Checker checker;
  83. Checker checkerv6;
  84. ItemState state = ItemState::Checking;
  85. int ping = 0;
  86. };
  87. std::vector<Item>::iterator findById(int id);
  88. std::vector<Item>::iterator findByProxy(const ProxyData &proxy);
  89. void setDeleted(int id, bool deleted);
  90. void updateView(const Item &item);
  91. void share(const ProxyData &proxy);
  92. void saveDelayed();
  93. void refreshChecker(Item &item);
  94. void setupChecker(int id, const Checker &checker);
  95. void replaceItemWith(
  96. std::vector<Item>::iterator which,
  97. std::vector<Item>::iterator with);
  98. void replaceItemValue(
  99. std::vector<Item>::iterator which,
  100. const ProxyData &proxy);
  101. const not_null<Main::Account*> _account;
  102. Core::SettingsProxy &_settings;
  103. int _idCounter = 0;
  104. std::vector<Item> _list;
  105. rpl::event_stream<ItemView> _views;
  106. base::Timer _saveTimer;
  107. rpl::event_stream<ProxyData::Settings> _proxySettingsChanges;
  108. std::shared_ptr<Ui::Show> _show;
  109. ProxyData _lastSelectedProxy;
  110. bool _lastSelectedProxyUsed = false;
  111. rpl::lifetime _lifetime;
  112. };