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"
|
2017-03-16 15:15:07 +00:00
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
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
|
|
|
|
|
2017-03-22 15:38:40 +00:00
|
|
|
class EditPrivacyBox : public BoxContent, private MTP::Sender {
|
2017-03-16 15:15:07 +00:00
|
|
|
public:
|
|
|
|
enum class Option {
|
2017-03-17 12:05:50 +00:00
|
|
|
Everyone,
|
2017-03-16 15:15:07 +00:00
|
|
|
Contacts,
|
|
|
|
Nobody,
|
|
|
|
};
|
2017-03-17 12:05:50 +00:00
|
|
|
enum class Exception {
|
|
|
|
Always,
|
|
|
|
Never,
|
|
|
|
};
|
2017-03-16 15:15:07 +00:00
|
|
|
|
|
|
|
class Controller {
|
|
|
|
public:
|
|
|
|
virtual MTPInputPrivacyKey key() = 0;
|
|
|
|
|
|
|
|
virtual QString title() = 0;
|
2017-03-19 08:29:05 +00:00
|
|
|
virtual bool hasOption(Option option) {
|
|
|
|
return true;
|
2017-03-16 15:15:07 +00:00
|
|
|
}
|
|
|
|
virtual QString description() = 0;
|
2017-03-19 08:29:05 +00:00
|
|
|
virtual QString warning() {
|
|
|
|
return QString();
|
|
|
|
}
|
2017-03-17 12:05:50 +00:00
|
|
|
virtual QString exceptionLinkText(Exception exception, int count) = 0;
|
|
|
|
virtual QString exceptionBoxTitle(Exception exception) = 0;
|
2017-03-16 15:15:07 +00:00
|
|
|
virtual QString exceptionsDescription() = 0;
|
|
|
|
|
2017-03-17 18:44:55 +00:00
|
|
|
virtual void confirmSave(bool someAreDisallowed, base::lambda_once<void()> saveCallback) {
|
|
|
|
saveCallback();
|
|
|
|
}
|
|
|
|
|
2017-03-16 15:15:07 +00:00
|
|
|
virtual ~Controller() = default;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
EditPrivacyBox *view() const {
|
|
|
|
return _view;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void setView(EditPrivacyBox *box) {
|
|
|
|
_view = box;
|
|
|
|
}
|
|
|
|
|
|
|
|
EditPrivacyBox *_view = nullptr;
|
|
|
|
|
|
|
|
friend class EditPrivacyBox;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
EditPrivacyBox(QWidget*, std::unique_ptr<Controller> controller);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void prepare() override;
|
|
|
|
int resizeGetHeight(int newWidth) override;
|
|
|
|
|
2017-03-19 08:29:05 +00:00
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
2017-03-16 15:15:07 +00:00
|
|
|
|
2017-03-19 08:29:05 +00:00
|
|
|
private:
|
2017-03-16 15:15:07 +00:00
|
|
|
style::margins exceptionLinkMargins() const;
|
2017-03-17 12:05:50 +00:00
|
|
|
bool showExceptionLink(Exception exception) const;
|
2017-03-16 15:15:07 +00:00
|
|
|
void createWidgets();
|
|
|
|
QVector<MTPInputPrivacyRule> collectResult();
|
2017-03-22 15:38:40 +00:00
|
|
|
void loadData();
|
2017-03-16 15:15:07 +00:00
|
|
|
int countDefaultHeight(int newWidth);
|
2017-03-17 12:05:50 +00:00
|
|
|
|
|
|
|
void editExceptionUsers(Exception exception);
|
|
|
|
QString exceptionLinkText(Exception exception);
|
2017-08-17 08:31:24 +00:00
|
|
|
std::vector<not_null<UserData*>> &exceptionUsers(Exception exception);
|
2017-09-13 16:57:44 +00:00
|
|
|
object_ptr<Ui::SlideWrap<Ui::LinkButton>> &exceptionLink(Exception exception);
|
2017-03-16 15:15:07 +00:00
|
|
|
|
|
|
|
std::unique_ptr<Controller> _controller;
|
2017-03-17 12:05:50 +00:00
|
|
|
Option _option = Option::Everyone;
|
2017-03-16 15:15:07 +00:00
|
|
|
|
2017-03-18 21:06:10 +00:00
|
|
|
std::shared_ptr<Ui::RadioenumGroup<Option>> _optionGroup;
|
2017-03-16 15:15:07 +00:00
|
|
|
object_ptr<Ui::FlatLabel> _loading;
|
|
|
|
object_ptr<Ui::FlatLabel> _description = { nullptr };
|
2017-03-19 08:29:05 +00:00
|
|
|
object_ptr<Ui::Radioenum<Option>> _everyone = { nullptr };
|
|
|
|
object_ptr<Ui::Radioenum<Option>> _contacts = { nullptr };
|
|
|
|
object_ptr<Ui::Radioenum<Option>> _nobody = { nullptr };
|
|
|
|
object_ptr<Ui::FlatLabel> _warning = { nullptr };
|
2017-03-16 15:15:07 +00:00
|
|
|
object_ptr<Ui::FlatLabel> _exceptionsTitle = { nullptr };
|
2017-09-13 16:57:44 +00:00
|
|
|
object_ptr<Ui::SlideWrap<Ui::LinkButton>> _alwaysLink = { nullptr };
|
|
|
|
object_ptr<Ui::SlideWrap<Ui::LinkButton>> _neverLink = { nullptr };
|
2017-03-16 15:15:07 +00:00
|
|
|
object_ptr<Ui::FlatLabel> _exceptionsDescription = { nullptr };
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
std::vector<not_null<UserData*>> _alwaysUsers;
|
|
|
|
std::vector<not_null<UserData*>> _neverUsers;
|
2017-03-16 15:15:07 +00:00
|
|
|
|
|
|
|
};
|