2017-03-16 15:15:07 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|
|
|
*/
|
|
|
|
#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>
|
|
|
|
class WidgetSlideWrap;
|
|
|
|
} // 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);
|
|
|
|
QVector<UserData*> &exceptionUsers(Exception exception);
|
|
|
|
object_ptr<Ui::WidgetSlideWrap<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 };
|
|
|
|
object_ptr<Ui::WidgetSlideWrap<Ui::LinkButton>> _alwaysLink = { nullptr };
|
|
|
|
object_ptr<Ui::WidgetSlideWrap<Ui::LinkButton>> _neverLink = { nullptr };
|
|
|
|
object_ptr<Ui::FlatLabel> _exceptionsDescription = { nullptr };
|
|
|
|
|
|
|
|
QVector<UserData*> _alwaysUsers;
|
|
|
|
QVector<UserData*> _neverUsers;
|
|
|
|
|
|
|
|
};
|