2017-03-16 15:15:07 +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.
|
2017-03-16 15:15:07 +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
|
2017-03-16 15:15:07 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/abstract_box.h"
|
2017-03-22 15:38:40 +00:00
|
|
|
#include "mtproto/sender.h"
|
2018-09-11 09:11:52 +00:00
|
|
|
#include "apiwrap.h"
|
2017-03-16 15:15:07 +00:00
|
|
|
|
2018-09-19 09:06:21 +00:00
|
|
|
enum LangKey : int;
|
|
|
|
|
2017-03-16 15:15:07 +00:00
|
|
|
namespace Ui {
|
2018-09-19 09:06:21 +00:00
|
|
|
class VerticalLayout;
|
2017-03-16 15:15:07 +00:00
|
|
|
class FlatLabel;
|
|
|
|
class LinkButton;
|
2017-03-18 21:06:10 +00:00
|
|
|
template <typename Enum>
|
|
|
|
class RadioenumGroup;
|
2017-03-19 08:29:05 +00:00
|
|
|
template <typename Enum>
|
|
|
|
class Radioenum;
|
2017-03-16 15:15:07 +00:00
|
|
|
template <typename Widget>
|
2017-09-13 16:57:44 +00:00
|
|
|
class SlideWrap;
|
2017-03-16 15:15:07 +00:00
|
|
|
} // namespace Ui
|
|
|
|
|
2019-05-21 12:51:24 +00:00
|
|
|
class EditPrivacyBox;
|
|
|
|
|
|
|
|
class EditPrivacyController {
|
2017-03-16 15:15:07 +00:00
|
|
|
public:
|
2019-05-21 12:51:24 +00:00
|
|
|
using Key = ApiWrap::Privacy::Key;
|
|
|
|
using Option = ApiWrap::Privacy::Option;
|
2017-03-17 12:05:50 +00:00
|
|
|
enum class Exception {
|
|
|
|
Always,
|
|
|
|
Never,
|
|
|
|
};
|
2017-03-16 15:15:07 +00:00
|
|
|
|
2019-05-21 12:51:24 +00:00
|
|
|
[[nodiscard]] virtual Key key() = 0;
|
|
|
|
[[nodiscard]] virtual MTPInputPrivacyKey apiKey() = 0;
|
|
|
|
|
|
|
|
[[nodiscard]] virtual QString title() = 0;
|
|
|
|
[[nodiscard]] virtual bool hasOption(Option option) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
[[nodiscard]] virtual LangKey optionsTitleKey() = 0;
|
|
|
|
[[nodiscard]] virtual LangKey optionLabelKey(Option option);
|
|
|
|
[[nodiscard]] virtual rpl::producer<QString> warning() {
|
|
|
|
return rpl::never<QString>();
|
|
|
|
}
|
|
|
|
[[nodiscard]] virtual LangKey exceptionButtonTextKey(
|
|
|
|
Exception exception) = 0;
|
|
|
|
[[nodiscard]] virtual QString exceptionBoxTitle(
|
|
|
|
Exception exception) = 0;
|
|
|
|
[[nodiscard]] virtual auto exceptionsDescription()
|
|
|
|
-> rpl::producer<QString> = 0;
|
|
|
|
|
|
|
|
[[nodiscard]] virtual object_ptr<Ui::RpWidget> setupAboveWidget(
|
|
|
|
not_null<QWidget*> parent,
|
|
|
|
rpl::producer<Option> option) {
|
|
|
|
return { nullptr };
|
|
|
|
}
|
|
|
|
[[nodiscard]] virtual object_ptr<Ui::RpWidget> setupBelowWidget(
|
|
|
|
not_null<QWidget*> parent) {
|
|
|
|
return { nullptr };
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void confirmSave(
|
|
|
|
bool someAreDisallowed,
|
|
|
|
FnMut<void()> saveCallback) {
|
|
|
|
saveCallback();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~EditPrivacyController() = default;
|
2017-03-16 15:15:07 +00:00
|
|
|
|
2019-05-21 12:51:24 +00:00
|
|
|
protected:
|
|
|
|
EditPrivacyBox *view() const {
|
|
|
|
return _view;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void setView(EditPrivacyBox *box) {
|
|
|
|
_view = box;
|
|
|
|
}
|
|
|
|
|
|
|
|
EditPrivacyBox *_view = nullptr;
|
|
|
|
|
|
|
|
friend class EditPrivacyBox;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class EditPrivacyBox : public BoxContent, private MTP::Sender {
|
|
|
|
public:
|
|
|
|
using Value = ApiWrap::Privacy;
|
|
|
|
using Option = Value::Option;
|
|
|
|
using Exception = EditPrivacyController::Exception;
|
2017-03-16 15:15:07 +00:00
|
|
|
|
2018-09-11 09:11:52 +00:00
|
|
|
EditPrivacyBox(
|
|
|
|
QWidget*,
|
2019-05-21 12:51:24 +00:00
|
|
|
std::unique_ptr<EditPrivacyController> controller,
|
2018-09-19 09:06:21 +00:00
|
|
|
const Value &value);
|
|
|
|
|
2017-03-16 15:15:07 +00:00
|
|
|
protected:
|
|
|
|
void prepare() override;
|
|
|
|
|
2017-03-19 08:29:05 +00:00
|
|
|
private:
|
2017-03-17 12:05:50 +00:00
|
|
|
bool showExceptionLink(Exception exception) const;
|
2018-09-19 09:06:21 +00:00
|
|
|
void setupContent();
|
2017-03-16 15:15:07 +00:00
|
|
|
QVector<MTPInputPrivacyRule> collectResult();
|
2017-03-17 12:05:50 +00:00
|
|
|
|
2018-11-16 05:40:42 +00:00
|
|
|
Ui::Radioenum<Option> *addOption(
|
|
|
|
not_null<Ui::VerticalLayout*> container,
|
|
|
|
const std::shared_ptr<Ui::RadioenumGroup<Option>> &group,
|
|
|
|
Option option);
|
|
|
|
Ui::FlatLabel *addLabel(
|
|
|
|
not_null<Ui::VerticalLayout*> container,
|
|
|
|
rpl::producer<QString> text);
|
|
|
|
|
2019-05-20 18:40:53 +00:00
|
|
|
void editExceptions(Exception exception, Fn<void()> done);
|
|
|
|
std::vector<not_null<PeerData*>> &exceptions(Exception exception);
|
2017-03-16 15:15:07 +00:00
|
|
|
|
2019-05-21 12:51:24 +00:00
|
|
|
std::unique_ptr<EditPrivacyController> _controller;
|
2018-09-11 09:11:52 +00:00
|
|
|
Value _value;
|
2018-09-12 17:02:30 +00:00
|
|
|
|
|
|
|
};
|