Improve code style a bit.

This commit is contained in:
John Preston 2019-03-19 19:45:46 +04:00
parent 4148099115
commit 241526f127
5 changed files with 114 additions and 115 deletions

View File

@ -23,7 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace {
void AddRoundButton(
void AddRadioButton(
not_null<Ui::VerticalLayout*> container,
HistoryVisibility value,
LangKey groupTextKey,
@ -52,7 +52,6 @@ void FillContent(
not_null<PeerData*> peer,
std::shared_ptr<Ui::RadioenumGroup<HistoryVisibility>> historyVisibility,
std::optional<HistoryVisibility> savedValue = std::nullopt) {
const auto canEdit = [&] {
if (const auto chat = peer->asChat()) {
return chat->canEditPreHistoryHidden();
@ -75,21 +74,22 @@ void FillContent(
historyVisibility->setValue(defaultValue);
const auto result = parent->add(object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
const auto result = parent->add(
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
parent,
object_ptr<Ui::VerticalLayout>(parent),
st::editPeerHistoryVisibilityMargins));
const auto container = result->entity();
Expects(historyVisibility != nullptr);
Assert(historyVisibility != nullptr);
AddRoundButton(
AddRadioButton(
container,
HistoryVisibility::Visible,
lng_manage_history_visibility_shown,
lng_manage_history_visibility_shown_about,
historyVisibility);
AddRoundButton(
AddRadioButton(
container,
HistoryVisibility::Hidden,
lng_manage_history_visibility_hidden,
@ -130,6 +130,10 @@ void EditPeerHistoryVisibilityBox::prepare() {
void EditPeerHistoryVisibilityBox::setupContent() {
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
FillContent(content, _peer, _historyVisibility, _historyVisibilitySavedValue);
FillContent(
content,
_peer,
_historyVisibility,
_historyVisibilitySavedValue);
setDimensionsToContent(st::boxWidth, content);
}

View File

@ -31,12 +31,11 @@ enum class HistoryVisibility {
class EditPeerHistoryVisibilityBox : public BoxContent {
public:
EditPeerHistoryVisibilityBox(
QWidget*,
not_null<PeerData*> peer,
FnMut<void(HistoryVisibility)> savedCallback,
std::optional<HistoryVisibility> historyVisibilitySavedValue = std::nullopt);
std::optional<HistoryVisibility> historyVisibilitySavedValue = {});
protected:
void prepare() override;
@ -48,6 +47,6 @@ private:
FnMut<void(HistoryVisibility)> _savedCallback;
std::optional<HistoryVisibility> _historyVisibilitySavedValue;
std::shared_ptr<Ui::RadioenumGroup<HistoryVisibility>> _historyVisibility = nullptr;
std::shared_ptr<Ui::RadioenumGroup<HistoryVisibility>> _historyVisibility;
};

View File

@ -492,40 +492,37 @@ void Controller::showEditPeerTypeBox(std::optional<LangKey> error) {
_usernameSavedValue = publicLink;
refreshHistoryVisibility();
};
Ui::show(Box<EditPeerTypeBox>(
Ui::show(
Box<EditPeerTypeBox>(
_peer,
boxCallback,
_privacySavedValue,
_usernameSavedValue,
error
), LayerOption::KeepOther);
error),
LayerOption::KeepOther);
}
void Controller::fillPrivacyTypeButton() {
Expects(_controls.buttonsLayout != nullptr);
// Create Privacy Button.
_privacySavedValue = (_peer->isChannel()
&& _peer->asChannel()->isPublic())
? Privacy::Public
: Privacy::Private;
const auto buttonCallback = [=] {
showEditPeerTypeBox();
};
AddButtonWithText(
_controls.buttonsLayout,
std::move(Lang::Viewer((_peer->isChat() || _peer->isMegagroup())
Lang::Viewer((_peer->isChat() || _peer->isMegagroup())
? lng_manage_peer_group_type
: lng_manage_peer_channel_type)),
: lng_manage_peer_channel_type),
_updadePrivacyType.events(
) | rpl::map([](Privacy flag) {
return lang(Privacy::Public == flag
? lng_manage_public_peer_title
: lng_manage_private_peer_title);
}),
buttonCallback);
[=] { showEditPeerTypeBox(); });
_updadePrivacyType.fire(std::move(_privacySavedValue.value()));
}
@ -533,13 +530,13 @@ void Controller::fillPrivacyTypeButton() {
void Controller::fillInviteLinkButton() {
Expects(_controls.buttonsLayout != nullptr);
const auto boxCallback = [=](Privacy checked, QString publicLink) {};
const auto boxCallback = [=](Privacy checked, QString publicLink) {
};
const auto buttonCallback = [=] {
Ui::show(Box<EditPeerTypeBox>(
_peer,
boxCallback
), LayerOption::KeepOther);
Ui::show(
Box<EditPeerTypeBox>(_peer, boxCallback),
LayerOption::KeepOther);
};
AddButtonWithText(
@ -591,18 +588,19 @@ void Controller::fillHistoryVisibilityButton() {
_historyVisibilitySavedValue = checked;
};
const auto buttonCallback = [=] {
Ui::show(Box<EditPeerHistoryVisibilityBox>(
Ui::show(
Box<EditPeerHistoryVisibilityBox>(
_peer,
boxCallback,
_historyVisibilitySavedValue
), LayerOption::KeepOther);
_historyVisibilitySavedValue),
LayerOption::KeepOther);
};
AddButtonWithText(
container,
std::move(Lang::Viewer(lng_manage_history_visibility_title)),
updateHistoryVisibility->events(
) | rpl::map([](HistoryVisibility flag) {
return lang(HistoryVisibility::Visible == flag
return lang((HistoryVisibility::Visible == flag)
? lng_manage_history_visibility_shown
: lng_manage_history_visibility_hidden);
}),
@ -618,6 +616,7 @@ void Controller::fillHistoryVisibilityButton() {
void Controller::fillManageSection() {
Expects(_controls.buttonsLayout != nullptr);
const auto navigation = App::wnd()->controller();
const auto chat = _peer->asChat();
@ -648,7 +647,6 @@ void Controller::fillManageSection() {
: chat->canEditPreHistoryHidden();
}();
const auto canEditPermissions = [=] {
return isChannel
? channel->canEditPermissions()
@ -705,7 +703,8 @@ void Controller::fillManageSection() {
|| canEditSignatures
|| canEditInviteLink
|| canEditUsername) {
AddSkip(_controls.buttonsLayout,
AddSkip(
_controls.buttonsLayout,
st::editPeerTopButtonsLayoutSkip,
st::editPeerTopButtonsLayoutSkipCustomBottom);
}
@ -784,9 +783,9 @@ void Controller::fillManageSection() {
if (canDeleteChannel) {
AddButtonDelete(
_controls.buttonsLayout,
std::move(Lang::Viewer(_isGroup
Lang::Viewer(_isGroup
? lng_profile_delete_group
: lng_profile_delete_channel)),
: lng_profile_delete_channel),
[=]{ deleteWithConfirmation(); }
);
}
@ -868,9 +867,8 @@ bool Controller::validateDescription(Saving &to) const {
}
bool Controller::validateHistoryVisibility(Saving &to) const {
if (!_controls.historyVisibilityWrap) return true;
if (!_controls.historyVisibilityWrap->toggled()
if (!_controls.historyVisibilityWrap
|| !_controls.historyVisibilityWrap->toggled()
|| (_privacySavedValue == Privacy::Public)) {
return true;
}
@ -895,12 +893,12 @@ void Controller::save() {
}
if (const auto saving = validate()) {
_savingData = *saving;
pushSaveStage([this] { saveUsername(); });
pushSaveStage([this] { saveTitle(); });
pushSaveStage([this] { saveDescription(); });
pushSaveStage([this] { saveHistoryVisibility(); });
pushSaveStage([this] { saveSignatures(); });
pushSaveStage([this] { savePhoto(); });
pushSaveStage([=] { saveUsername(); });
pushSaveStage([=] { saveTitle(); });
pushSaveStage([=] { saveDescription(); });
pushSaveStage([=] { saveHistoryVisibility(); });
pushSaveStage([=] { saveSignatures(); });
pushSaveStage([=] { savePhoto(); });
continueSave();
}
}
@ -1136,9 +1134,9 @@ void Controller::deleteWithConfirmation() {
}
void Controller::deleteChannel() {
const auto channel = _peer->asChannel();
Assert(channel != nullptr);
Expects(_peer->isChannel());
const auto channel = _peer->asChannel();
const auto chat = channel->migrateFrom();
Ui::hideLayer();
@ -1229,7 +1227,8 @@ bool EditPeerInfoBox::Available(not_null<PeerData*> peer) {
|| channel->canViewBanned()
|| channel->canEditInformation()
|| channel->canEditPermissions()
|| (channel->hasAdminRights() || channel->amCreator());
|| channel->hasAdminRights()
|| channel->amCreator();
} else {
return false;
}

View File

@ -84,7 +84,6 @@ public:
}
private:
struct Controls {
std::shared_ptr<Ui::RadioenumGroup<Privacy>> privacy;
Ui::SlideWrap<Ui::RpWidget> *usernameWrap = nullptr;
@ -165,7 +164,8 @@ Controller::Controller(
, _privacySavedValue(privacySavedValue)
, _usernameSavedValue(usernameSavedValue)
, _isGroup(_peer->isChat() || _peer->isMegagroup())
, _isInviteLink(!_privacySavedValue.has_value() && !_usernameSavedValue.has_value())
, _isInviteLink(!_privacySavedValue.has_value()
&& !_usernameSavedValue.has_value())
, _isAllowSave(!_usernameSavedValue.value_or(QString()).isEmpty())
, _wrap(container)
, _checkUsernameTimer([=] { checkUsernameAvailability(); }) {
@ -194,7 +194,6 @@ void Controller::createContent() {
}
}
void Controller::addRoundButton(
not_null<Ui::VerticalLayout*> container,
Privacy value,
@ -223,7 +222,6 @@ void Controller::addRoundButton(
void Controller::fillPrivaciesButtons(
not_null<Ui::VerticalLayout*> parent,
std::optional<Privacy> savedValue) {
const auto canEditUsername = [&] {
if (const auto chat = _peer->asChat()) {
return chat->canEditUsername();

View File

@ -39,7 +39,6 @@ enum class UsernameState {
class EditPeerTypeBox : public BoxContent {
public:
EditPeerTypeBox(
QWidget*,
not_null<PeerData*> p,
@ -56,9 +55,9 @@ private:
not_null<PeerData*> _peer;
FnMut<void(Privacy, QString)> _savedCallback;
std::optional<Privacy> _privacySavedValue = std::nullopt;
std::optional<QString> _usernameSavedValue = std::nullopt;
std::optional<LangKey> _usernameError = std::nullopt;
std::optional<Privacy> _privacySavedValue;
std::optional<QString> _usernameSavedValue;
std::optional<LangKey> _usernameError;
rpl::event_stream<> _focusRequests;