2017-03-16 18:15:07 +03: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.
|
2017-03-16 18:15:07 +03: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
|
2017-03-16 18:15:07 +03:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-04-06 17:38:10 +03:00
|
|
|
#include "boxes/abstract_box.h"
|
2017-03-22 18:38:40 +03:00
|
|
|
#include "mtproto/sender.h"
|
2018-09-11 12:11:52 +03:00
|
|
|
#include "apiwrap.h"
|
2017-03-16 18:15:07 +03:00
|
|
|
|
2018-09-12 20:02:30 +03:00
|
|
|
namespace Calls {
|
|
|
|
enum class PeerToPeer;
|
|
|
|
} // namespace Calls
|
|
|
|
|
2017-03-16 18:15:07 +03:00
|
|
|
namespace Ui {
|
|
|
|
class FlatLabel;
|
|
|
|
class LinkButton;
|
2017-03-19 00:06:10 +03:00
|
|
|
template <typename Enum>
|
|
|
|
class RadioenumGroup;
|
2017-03-19 11:29:05 +03:00
|
|
|
template <typename Enum>
|
|
|
|
class Radioenum;
|
2017-03-16 18:15:07 +03:00
|
|
|
template <typename Widget>
|
2017-09-13 19:57:44 +03:00
|
|
|
class SlideWrap;
|
2017-03-16 18:15:07 +03:00
|
|
|
} // namespace Ui
|
|
|
|
|
2017-03-22 18:38:40 +03:00
|
|
|
class EditPrivacyBox : public BoxContent, private MTP::Sender {
|
2017-03-16 18:15:07 +03:00
|
|
|
public:
|
2018-09-11 12:11:52 +03:00
|
|
|
using Value = ApiWrap::Privacy;
|
|
|
|
using Option = Value::Option;
|
2017-03-17 15:05:50 +03:00
|
|
|
enum class Exception {
|
|
|
|
Always,
|
|
|
|
Never,
|
|
|
|
};
|
2017-03-16 18:15:07 +03:00
|
|
|
|
|
|
|
class Controller {
|
|
|
|
public:
|
2018-09-11 12:11:52 +03:00
|
|
|
using Key = ApiWrap::Privacy::Key;
|
|
|
|
|
|
|
|
virtual Key key() = 0;
|
|
|
|
virtual MTPInputPrivacyKey apiKey() = 0;
|
2017-03-16 18:15:07 +03:00
|
|
|
|
|
|
|
virtual QString title() = 0;
|
2017-03-19 11:29:05 +03:00
|
|
|
virtual bool hasOption(Option option) {
|
|
|
|
return true;
|
2017-03-16 18:15:07 +03:00
|
|
|
}
|
|
|
|
virtual QString description() = 0;
|
2017-03-19 11:29:05 +03:00
|
|
|
virtual QString warning() {
|
|
|
|
return QString();
|
|
|
|
}
|
2017-03-17 15:05:50 +03:00
|
|
|
virtual QString exceptionLinkText(Exception exception, int count) = 0;
|
|
|
|
virtual QString exceptionBoxTitle(Exception exception) = 0;
|
2017-03-16 18:15:07 +03:00
|
|
|
virtual QString exceptionsDescription() = 0;
|
|
|
|
|
2018-06-04 18:35:11 +03:00
|
|
|
virtual void confirmSave(bool someAreDisallowed, FnMut<void()> saveCallback) {
|
2017-03-17 21:44:55 +03:00
|
|
|
saveCallback();
|
|
|
|
}
|
|
|
|
|
2017-03-16 18:15:07 +03:00
|
|
|
virtual ~Controller() = default;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
EditPrivacyBox *view() const {
|
|
|
|
return _view;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void setView(EditPrivacyBox *box) {
|
|
|
|
_view = box;
|
|
|
|
}
|
|
|
|
|
|
|
|
EditPrivacyBox *_view = nullptr;
|
|
|
|
|
|
|
|
friend class EditPrivacyBox;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-09-11 12:11:52 +03:00
|
|
|
EditPrivacyBox(
|
|
|
|
QWidget*,
|
|
|
|
std::unique_ptr<Controller> controller,
|
|
|
|
rpl::producer<Value> preloaded);
|
2017-03-16 18:15:07 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void prepare() override;
|
|
|
|
int resizeGetHeight(int newWidth) override;
|
|
|
|
|
2017-03-19 11:29:05 +03:00
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
2017-03-16 18:15:07 +03:00
|
|
|
|
2017-03-19 11:29:05 +03:00
|
|
|
private:
|
2017-03-16 18:15:07 +03:00
|
|
|
style::margins exceptionLinkMargins() const;
|
2017-03-17 15:05:50 +03:00
|
|
|
bool showExceptionLink(Exception exception) const;
|
2017-03-16 18:15:07 +03:00
|
|
|
void createWidgets();
|
|
|
|
QVector<MTPInputPrivacyRule> collectResult();
|
2018-09-11 12:11:52 +03:00
|
|
|
void dataReady(Value &&value);
|
2017-03-16 18:15:07 +03:00
|
|
|
int countDefaultHeight(int newWidth);
|
2017-03-17 15:05:50 +03:00
|
|
|
|
|
|
|
void editExceptionUsers(Exception exception);
|
|
|
|
QString exceptionLinkText(Exception exception);
|
2017-08-17 11:31:24 +03:00
|
|
|
std::vector<not_null<UserData*>> &exceptionUsers(Exception exception);
|
2018-09-11 12:11:52 +03:00
|
|
|
object_ptr<Ui::SlideWrap<Ui::LinkButton>> &exceptionLink(
|
|
|
|
Exception exception);
|
2017-03-16 18:15:07 +03:00
|
|
|
|
|
|
|
std::unique_ptr<Controller> _controller;
|
2018-09-11 12:11:52 +03:00
|
|
|
Value _value;
|
|
|
|
bool _prepared = false;
|
2017-03-16 18:15:07 +03:00
|
|
|
|
2017-03-19 00:06:10 +03:00
|
|
|
std::shared_ptr<Ui::RadioenumGroup<Option>> _optionGroup;
|
2017-03-16 18:15:07 +03:00
|
|
|
object_ptr<Ui::FlatLabel> _loading;
|
|
|
|
object_ptr<Ui::FlatLabel> _description = { nullptr };
|
2017-03-19 11:29:05 +03: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 18:15:07 +03:00
|
|
|
object_ptr<Ui::FlatLabel> _exceptionsTitle = { nullptr };
|
2017-09-13 19:57:44 +03:00
|
|
|
object_ptr<Ui::SlideWrap<Ui::LinkButton>> _alwaysLink = { nullptr };
|
|
|
|
object_ptr<Ui::SlideWrap<Ui::LinkButton>> _neverLink = { nullptr };
|
2017-03-16 18:15:07 +03:00
|
|
|
object_ptr<Ui::FlatLabel> _exceptionsDescription = { nullptr };
|
|
|
|
|
|
|
|
};
|
2018-09-12 20:02:30 +03:00
|
|
|
|
|
|
|
class EditCallsPeerToPeer : public BoxContent {
|
|
|
|
public:
|
|
|
|
EditCallsPeerToPeer(QWidget*) {
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void prepare() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
using PeerToPeer = Calls::PeerToPeer;
|
|
|
|
|
|
|
|
void chosen(PeerToPeer value);
|
|
|
|
|
|
|
|
std::vector<object_ptr<Ui::Radioenum<PeerToPeer>>> _options;
|
|
|
|
|
|
|
|
};
|