tdesktop/Telegram/SourceFiles/boxes/edit_privacy_box.h

141 lines
3.4 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
2017-04-06 14:38:10 +00:00
#include "boxes/abstract_box.h"
#include "mtproto/sender.h"
#include "apiwrap.h"
namespace Ui {
class VerticalLayout;
class FlatLabel;
class LinkButton;
template <typename Enum>
class RadioenumGroup;
template <typename Enum>
class Radioenum;
template <typename Widget>
2017-09-13 16:57:44 +00:00
class SlideWrap;
} // namespace Ui
2019-09-18 11:19:05 +00:00
namespace Window {
class SessionController;
} // namespace Window
class EditPrivacyBox;
class EditPrivacyController {
public:
using Key = ApiWrap::Privacy::Key;
using Option = ApiWrap::Privacy::Option;
enum class Exception {
Always,
Never,
};
[[nodiscard]] virtual Key key() = 0;
[[nodiscard]] virtual MTPInputPrivacyKey apiKey() = 0;
[[nodiscard]] virtual rpl::producer<QString> title() = 0;
[[nodiscard]] virtual bool hasOption(Option option) {
return true;
}
2019-06-18 12:16:43 +00:00
[[nodiscard]] virtual rpl::producer<QString> optionsTitleKey() = 0;
2019-06-19 15:09:03 +00:00
[[nodiscard]] virtual QString optionLabel(Option option);
[[nodiscard]] virtual rpl::producer<QString> warning() {
return nullptr;
}
2019-06-18 12:16:43 +00:00
[[nodiscard]] virtual rpl::producer<QString> exceptionButtonTextKey(
Exception exception) = 0;
[[nodiscard]] virtual rpl::producer<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 };
}
2019-08-29 08:44:03 +00:00
[[nodiscard]] virtual object_ptr<Ui::RpWidget> setupMiddleWidget(
not_null<Window::SessionController*> controller,
not_null<QWidget*> parent,
rpl::producer<Option> option) {
return { nullptr };
}
[[nodiscard]] virtual object_ptr<Ui::RpWidget> setupBelowWidget(
2019-07-24 14:00:30 +00:00
not_null<Window::SessionController*> controller,
not_null<QWidget*> parent) {
return { nullptr };
}
virtual void confirmSave(
bool someAreDisallowed,
FnMut<void()> saveCallback) {
saveCallback();
}
2019-08-29 08:44:03 +00:00
virtual void saveAdditional() {
}
virtual ~EditPrivacyController() = default;
protected:
EditPrivacyBox *view() const {
return _view;
}
private:
void setView(EditPrivacyBox *box) {
_view = box;
}
EditPrivacyBox *_view = nullptr;
friend class EditPrivacyBox;
};
2019-11-27 08:02:56 +00:00
class EditPrivacyBox : public Ui::BoxContent {
public:
using Value = ApiWrap::Privacy;
using Option = Value::Option;
using Exception = EditPrivacyController::Exception;
EditPrivacyBox(
QWidget*,
2019-07-24 14:00:30 +00:00
not_null<Window::SessionController*> window,
std::unique_ptr<EditPrivacyController> controller,
const Value &value);
2019-08-29 08:44:03 +00:00
static Ui::Radioenum<Option> *AddOption(
not_null<Ui::VerticalLayout*> container,
not_null<EditPrivacyController*> controller,
const std::shared_ptr<Ui::RadioenumGroup<Option>> &group,
Option option);
protected:
void prepare() override;
private:
bool showExceptionLink(Exception exception) const;
void setupContent();
QVector<MTPInputPrivacyRule> collectResult();
2018-11-16 05:40:42 +00:00
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);
2019-07-24 14:00:30 +00:00
const not_null<Window::SessionController*> _window;
std::unique_ptr<EditPrivacyController> _controller;
Value _value;
};