Replaced EditPeerHistoryVisibilityBox with generic box.
This commit is contained in:
		
							parent
							
								
									4a4cc766c2
								
							
						
					
					
						commit
						66e6bf8217
					
				
					 3 changed files with 55 additions and 124 deletions
				
			
		| 
						 | 
					@ -7,51 +7,33 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
#include "boxes/peers/edit_peer_history_visibility_box.h"
 | 
					#include "boxes/peers/edit_peer_history_visibility_box.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "boxes/peers/edit_peer_permissions_box.h"
 | 
					 | 
				
			||||||
#include "boxes/peers/edit_participants_box.h"
 | 
					 | 
				
			||||||
#include "data/data_channel.h"
 | 
					#include "data/data_channel.h"
 | 
				
			||||||
#include "data/data_chat.h"
 | 
					#include "data/data_chat.h"
 | 
				
			||||||
#include "data/data_peer.h"
 | 
					#include "data/data_peer.h"
 | 
				
			||||||
#include "lang/lang_keys.h"
 | 
					#include "lang/lang_keys.h"
 | 
				
			||||||
 | 
					#include "ui/layers/generic_box.h"
 | 
				
			||||||
#include "ui/widgets/checkbox.h"
 | 
					#include "ui/widgets/checkbox.h"
 | 
				
			||||||
#include "ui/widgets/labels.h"
 | 
					#include "ui/widgets/labels.h"
 | 
				
			||||||
#include "ui/wrap/padding_wrap.h"
 | 
					 | 
				
			||||||
#include "ui/wrap/slide_wrap.h"
 | 
					 | 
				
			||||||
#include "ui/wrap/vertical_layout.h"
 | 
					 | 
				
			||||||
#include "styles/style_layers.h"
 | 
					#include "styles/style_layers.h"
 | 
				
			||||||
#include "styles/style_info.h"
 | 
					#include "styles/style_info.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace {
 | 
					void EditPeerHistoryVisibilityBox(
 | 
				
			||||||
 | 
							not_null<Ui::GenericBox*> box,
 | 
				
			||||||
void AddRadioButton(
 | 
					 | 
				
			||||||
		not_null<Ui::VerticalLayout*> container,
 | 
					 | 
				
			||||||
		HistoryVisibility value,
 | 
					 | 
				
			||||||
		const QString &groupText,
 | 
					 | 
				
			||||||
		rpl::producer<QString> groupAbout,
 | 
					 | 
				
			||||||
		std::shared_ptr<Ui::RadioenumGroup<HistoryVisibility>> historyVisibility) {
 | 
					 | 
				
			||||||
	container->add(object_ptr<Ui::FixedHeightWidget>(
 | 
					 | 
				
			||||||
		container,
 | 
					 | 
				
			||||||
		st::editPeerHistoryVisibilityTopSkip));
 | 
					 | 
				
			||||||
	container->add(object_ptr<Ui::Radioenum<HistoryVisibility>>(
 | 
					 | 
				
			||||||
		container,
 | 
					 | 
				
			||||||
		historyVisibility,
 | 
					 | 
				
			||||||
		value,
 | 
					 | 
				
			||||||
		groupText,
 | 
					 | 
				
			||||||
		st::defaultBoxCheckbox));
 | 
					 | 
				
			||||||
	container->add(object_ptr<Ui::PaddingWrap<Ui::FlatLabel>>(
 | 
					 | 
				
			||||||
		container,
 | 
					 | 
				
			||||||
		object_ptr<Ui::FlatLabel>(
 | 
					 | 
				
			||||||
			container,
 | 
					 | 
				
			||||||
			std::move(groupAbout),
 | 
					 | 
				
			||||||
			st::editPeerPrivacyLabel),
 | 
					 | 
				
			||||||
		st::editPeerPreHistoryLabelMargins));
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void FillContent(
 | 
					 | 
				
			||||||
		not_null<Ui::VerticalLayout*> parent,
 | 
					 | 
				
			||||||
		not_null<PeerData*> peer,
 | 
							not_null<PeerData*> peer,
 | 
				
			||||||
		std::shared_ptr<Ui::RadioenumGroup<HistoryVisibility>> historyVisibility,
 | 
							Fn<void(HistoryVisibility)> savedCallback,
 | 
				
			||||||
		HistoryVisibility savedValue) {
 | 
							HistoryVisibility historyVisibilitySavedValue) {
 | 
				
			||||||
 | 
						const auto historyVisibility = std::make_shared<
 | 
				
			||||||
 | 
							Ui::RadioenumGroup<HistoryVisibility>
 | 
				
			||||||
 | 
						>(historyVisibilitySavedValue);
 | 
				
			||||||
 | 
						peer->updateFull();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						box->setTitle(tr::lng_manage_history_visibility_title());
 | 
				
			||||||
 | 
						box->addButton(tr::lng_settings_save(), [=] {
 | 
				
			||||||
 | 
							savedCallback(historyVisibility->value());
 | 
				
			||||||
 | 
							box->closeBox();
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
						box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const auto canEdit = [&] {
 | 
						const auto canEdit = [&] {
 | 
				
			||||||
		if (const auto chat = peer->asChat()) {
 | 
							if (const auto chat = peer->asChat()) {
 | 
				
			||||||
			return chat->canEditPreHistoryHidden();
 | 
								return chat->canEditPreHistoryHidden();
 | 
				
			||||||
| 
						 | 
					@ -64,68 +46,33 @@ void FillContent(
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	historyVisibility->setValue(savedValue);
 | 
						box->addSkip(st::editPeerHistoryVisibilityTopSkip);
 | 
				
			||||||
 | 
						box->addRow(object_ptr<Ui::Radioenum<HistoryVisibility>>(
 | 
				
			||||||
	const auto result = parent->add(
 | 
							box,
 | 
				
			||||||
		object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
 | 
							historyVisibility,
 | 
				
			||||||
			parent,
 | 
					 | 
				
			||||||
			object_ptr<Ui::VerticalLayout>(parent),
 | 
					 | 
				
			||||||
			st::editPeerHistoryVisibilityMargins));
 | 
					 | 
				
			||||||
	const auto container = result->entity();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	Assert(historyVisibility != nullptr);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	AddRadioButton(
 | 
					 | 
				
			||||||
		container,
 | 
					 | 
				
			||||||
		HistoryVisibility::Visible,
 | 
							HistoryVisibility::Visible,
 | 
				
			||||||
		tr::lng_manage_history_visibility_shown(tr::now),
 | 
							tr::lng_manage_history_visibility_shown(tr::now),
 | 
				
			||||||
		tr::lng_manage_history_visibility_shown_about(),
 | 
							st::defaultBoxCheckbox));
 | 
				
			||||||
		historyVisibility);
 | 
						box->addRow(
 | 
				
			||||||
	AddRadioButton(
 | 
							object_ptr<Ui::FlatLabel>(
 | 
				
			||||||
		container,
 | 
								box,
 | 
				
			||||||
 | 
								tr::lng_manage_history_visibility_shown_about(),
 | 
				
			||||||
 | 
								st::editPeerPrivacyLabel),
 | 
				
			||||||
 | 
							st::editPeerPreHistoryLabelMargins + st::boxRowPadding);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						box->addSkip(st::editPeerHistoryVisibilityTopSkip);
 | 
				
			||||||
 | 
						box->addRow(object_ptr<Ui::Radioenum<HistoryVisibility>>(
 | 
				
			||||||
 | 
							box,
 | 
				
			||||||
 | 
							historyVisibility,
 | 
				
			||||||
		HistoryVisibility::Hidden,
 | 
							HistoryVisibility::Hidden,
 | 
				
			||||||
		tr::lng_manage_history_visibility_hidden(tr::now),
 | 
							tr::lng_manage_history_visibility_hidden(tr::now),
 | 
				
			||||||
		(peer->isChat()
 | 
							st::defaultBoxCheckbox));
 | 
				
			||||||
			? tr::lng_manage_history_visibility_hidden_legacy
 | 
						box->addRow(
 | 
				
			||||||
			: tr::lng_manage_history_visibility_hidden_about)(),
 | 
							object_ptr<Ui::FlatLabel>(
 | 
				
			||||||
		historyVisibility);
 | 
								box,
 | 
				
			||||||
}
 | 
								(peer->isChat()
 | 
				
			||||||
 | 
									? tr::lng_manage_history_visibility_hidden_legacy
 | 
				
			||||||
} // namespace
 | 
									: tr::lng_manage_history_visibility_hidden_about)(),
 | 
				
			||||||
 | 
								st::editPeerPrivacyLabel),
 | 
				
			||||||
EditPeerHistoryVisibilityBox::EditPeerHistoryVisibilityBox(
 | 
							st::editPeerPreHistoryLabelMargins + st::boxRowPadding);
 | 
				
			||||||
	QWidget*,
 | 
					 | 
				
			||||||
	not_null<PeerData*> peer,
 | 
					 | 
				
			||||||
	FnMut<void(HistoryVisibility)> savedCallback,
 | 
					 | 
				
			||||||
	HistoryVisibility historyVisibilitySavedValue)
 | 
					 | 
				
			||||||
: _peer(peer)
 | 
					 | 
				
			||||||
, _savedCallback(std::move(savedCallback))
 | 
					 | 
				
			||||||
, _historyVisibilitySavedValue(historyVisibilitySavedValue)
 | 
					 | 
				
			||||||
, _historyVisibility(
 | 
					 | 
				
			||||||
	std::make_shared<Ui::RadioenumGroup<HistoryVisibility>>(
 | 
					 | 
				
			||||||
		_historyVisibilitySavedValue)) {
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void EditPeerHistoryVisibilityBox::prepare() {
 | 
					 | 
				
			||||||
	_peer->updateFull();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	setTitle(tr::lng_manage_history_visibility_title());
 | 
					 | 
				
			||||||
	addButton(tr::lng_settings_save(), [=] {
 | 
					 | 
				
			||||||
		auto local = std::move(_savedCallback);
 | 
					 | 
				
			||||||
		local(_historyVisibility->value());
 | 
					 | 
				
			||||||
		closeBox();
 | 
					 | 
				
			||||||
	});
 | 
					 | 
				
			||||||
	addButton(tr::lng_cancel(), [=] { closeBox(); });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	setupContent();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void EditPeerHistoryVisibilityBox::setupContent() {
 | 
					 | 
				
			||||||
	const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
 | 
					 | 
				
			||||||
	FillContent(
 | 
					 | 
				
			||||||
		content,
 | 
					 | 
				
			||||||
		_peer,
 | 
					 | 
				
			||||||
		_historyVisibility,
 | 
					 | 
				
			||||||
		_historyVisibilitySavedValue);
 | 
					 | 
				
			||||||
	setDimensionsToContent(st::boxWidth, content);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,32 +7,17 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "boxes/abstract_box.h"
 | 
					namespace Ui {
 | 
				
			||||||
#include "ui/widgets/checkbox.h"
 | 
					class GenericBox;
 | 
				
			||||||
 | 
					} // namespace Ui
 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum class HistoryVisibility {
 | 
					enum class HistoryVisibility {
 | 
				
			||||||
	Visible,
 | 
						Visible,
 | 
				
			||||||
	Hidden,
 | 
						Hidden,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class EditPeerHistoryVisibilityBox : public Ui::BoxContent {
 | 
					void EditPeerHistoryVisibilityBox(
 | 
				
			||||||
public:
 | 
						not_null<Ui::GenericBox*> box,
 | 
				
			||||||
	EditPeerHistoryVisibilityBox(
 | 
						not_null<PeerData*> peer,
 | 
				
			||||||
		QWidget*,
 | 
						Fn<void(HistoryVisibility)> savedCallback,
 | 
				
			||||||
		not_null<PeerData*> peer,
 | 
						HistoryVisibility historyVisibilitySavedValue);
 | 
				
			||||||
		FnMut<void(HistoryVisibility)> savedCallback,
 | 
					 | 
				
			||||||
		HistoryVisibility historyVisibilitySavedValue);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
protected:
 | 
					 | 
				
			||||||
	void prepare() override;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
private:
 | 
					 | 
				
			||||||
	void setupContent();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	not_null<PeerData*> _peer;
 | 
					 | 
				
			||||||
	FnMut<void(HistoryVisibility)> _savedCallback;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	HistoryVisibility _historyVisibilitySavedValue;
 | 
					 | 
				
			||||||
	std::shared_ptr<Ui::RadioenumGroup<HistoryVisibility>> _historyVisibility;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -837,12 +837,11 @@ void Controller::fillHistoryVisibilityButton() {
 | 
				
			||||||
		_historyVisibilitySavedValue = checked;
 | 
							_historyVisibilitySavedValue = checked;
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
	const auto buttonCallback = [=] {
 | 
						const auto buttonCallback = [=] {
 | 
				
			||||||
		_navigation->parentController()->show(
 | 
							_navigation->parentController()->show(Box(
 | 
				
			||||||
			Box<EditPeerHistoryVisibilityBox>(
 | 
								EditPeerHistoryVisibilityBox,
 | 
				
			||||||
				_peer,
 | 
								_peer,
 | 
				
			||||||
				boxCallback,
 | 
								boxCallback,
 | 
				
			||||||
				*_historyVisibilitySavedValue),
 | 
								*_historyVisibilitySavedValue));
 | 
				
			||||||
			Ui::LayerOption::KeepOther);
 | 
					 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
	AddButtonWithText(
 | 
						AddButtonWithText(
 | 
				
			||||||
		container,
 | 
							container,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue