From 441989a8e1d4cde83715fc5fc818f75c17b5d1a8 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 4 Jan 2019 16:21:30 +0400 Subject: [PATCH] Remove EditChannelBox. --- .../SourceFiles/boxes/add_contact_box.cpp | 271 ------------------ Telegram/SourceFiles/boxes/add_contact_box.h | 56 ---- 2 files changed, 327 deletions(-) diff --git a/Telegram/SourceFiles/boxes/add_contact_box.cpp b/Telegram/SourceFiles/boxes/add_contact_box.cpp index 4a9f7e8aa8..8ed7443348 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/add_contact_box.cpp @@ -1172,277 +1172,6 @@ bool EditNameBox::saveSelfFail(const RPCError &error) { return true; } -EditChannelBox::EditChannelBox(QWidget*, not_null channel) -: _channel(channel) -, _title(this, st::defaultInputField, langFactory(_channel->isMegagroup() ? lng_dlg_new_group_name : lng_dlg_new_channel_name), _channel->name) -, _description( - this, - st::newGroupDescription, - Ui::InputField::Mode::MultiLine, - langFactory(lng_create_group_description), - _channel->about()) -, _sign(this, lang(lng_edit_sign_messages), channel->addsSignature(), st::defaultBoxCheckbox) -, _inviteGroup(std::make_shared>(channel->anyoneCanAddMembers() ? Invites::Everybody : Invites::OnlyAdmins)) -, _inviteEverybody(this, _inviteGroup, Invites::Everybody, lang(lng_edit_group_invites_everybody)) -, _inviteOnlyAdmins(this, _inviteGroup, Invites::OnlyAdmins, lang(lng_edit_group_invites_only_admins)) -, _publicLink(this, lang(channel->isPublic() ? lng_profile_edit_public_link : lng_profile_create_public_link), st::boxLinkButton) { -} - -void EditChannelBox::prepare() { - setTitle(langFactory(_channel->isMegagroup() ? lng_edit_group : lng_edit_channel_title)); - - addButton(langFactory(lng_settings_save), [this] { save(); }); - addButton(langFactory(lng_cancel), [this] { closeBox(); }); - - subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(Notify::PeerUpdate::Flag::NameChanged, [this](const Notify::PeerUpdate &update) { - if (update.peer == _channel) { - handleChannelNameChange(); - } - })); - - setMouseTracking(true); - - _title->setMaxLength(kMaxGroupChannelTitle); - _title->setInstantReplaces(Ui::InstantReplaces::Default()); - _title->setInstantReplacesEnabled(Global::ReplaceEmojiValue()); - Ui::Emoji::SuggestionsController::Init( - getDelegate()->outerContainer(), - _title); - - _description->setMaxLength(kMaxChannelDescription); - _description->setInstantReplaces(Ui::InstantReplaces::Default()); - _description->setInstantReplacesEnabled(Global::ReplaceEmojiValue()); - - connect(_description, &Ui::InputField::resized, [=] { descriptionResized(); }); - connect(_description, &Ui::InputField::submitted, [=] { save(); }); - connect(_description, &Ui::InputField::cancelled, [=] { closeBox(); }); - Ui::Emoji::SuggestionsController::Init( - getDelegate()->outerContainer(), - _description); - - _publicLink->addClickHandler([=] { setupPublicLink(); }); - _publicLink->setVisible(_channel->canEditUsername()); - _sign->setVisible(canEditSignatures()); - _inviteEverybody->setVisible(canEditInvites()); - _inviteOnlyAdmins->setVisible(canEditInvites()); - - updateMaxHeight(); -} - -void EditChannelBox::setInnerFocus() { - _title->setFocusFast(); -} - -void EditChannelBox::keyPressEvent(QKeyEvent *e) { - if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) { - if (_title->hasFocus()) { - save(); - } - } else { - BoxContent::keyPressEvent(e); - } -} - -void EditChannelBox::handleChannelNameChange() { - _publicLink->setText(lang(_channel->isPublic() ? lng_profile_edit_public_link : lng_profile_create_public_link)); - _sign->setChecked(_channel->addsSignature()); -} - -void EditChannelBox::descriptionResized() { - updateMaxHeight(); - update(); -} - -bool EditChannelBox::canEditSignatures() const { - return _channel->canEditInformation() && !_channel->isMegagroup(); -} - -bool EditChannelBox::canEditInvites() const { - return _channel->canEditInformation() && _channel->isMegagroup(); -} - -void EditChannelBox::updateMaxHeight() { - auto newHeight = st::newGroupInfoPadding.top() + _title->height(); - newHeight += st::newGroupDescriptionPadding.top() + _description->height() + st::newGroupDescriptionPadding.bottom(); - if (canEditSignatures()) { - newHeight += st::newGroupPublicLinkPadding.top() + _sign->heightNoMargins() + st::newGroupPublicLinkPadding.bottom(); - } - if (canEditInvites()) { - newHeight += st::boxTitleHeight + _inviteEverybody->heightNoMargins(); - newHeight += st::boxLittleSkip + _inviteOnlyAdmins->heightNoMargins(); - } - if (_channel->canEditUsername()) { - newHeight += st::newGroupPublicLinkPadding.top() + _publicLink->height() + st::newGroupPublicLinkPadding.bottom(); - } - newHeight += st::boxPadding.bottom() + st::newGroupInfoPadding.bottom(); - setDimensions(st::boxWideWidth, newHeight); -} - -void EditChannelBox::resizeEvent(QResizeEvent *e) { - BoxContent::resizeEvent(e); - - _title->resize(width() - st::boxPadding.left() - st::newGroupInfoPadding.left() - st::boxPadding.right(), _title->height()); - _title->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), st::newGroupInfoPadding.top() + st::newGroupNamePosition.y()); - - _description->resize(width() - st::boxPadding.left() - st::newGroupInfoPadding.left() - st::boxPadding.right(), _description->height()); - _description->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _title->y() + _title->height() + st::newGroupDescriptionPadding.top()); - - _sign->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _description->y() + _description->height() + st::newGroupDescriptionPadding.bottom() + st::newGroupPublicLinkPadding.top()); - - _inviteEverybody->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _description->y() + _description->height() + st::boxTitleHeight); - _inviteOnlyAdmins->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _inviteEverybody->bottomNoMargins() + st::boxLittleSkip); - - if (canEditSignatures()) { - _publicLink->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _sign->bottomNoMargins() + st::newGroupDescriptionPadding.bottom() + st::newGroupPublicLinkPadding.top()); - } else if (canEditInvites()) { - _publicLink->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _inviteOnlyAdmins->bottomNoMargins() + st::newGroupDescriptionPadding.bottom() + st::newGroupPublicLinkPadding.top()); - } else { - _publicLink->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _description->y() + _description->height() + st::newGroupDescriptionPadding.bottom() + st::newGroupPublicLinkPadding.top()); - } -} - -void EditChannelBox::paintEvent(QPaintEvent *e) { - BoxContent::paintEvent(e); - - if (canEditInvites()) { - Painter p(this); - p.setPen(st::boxTitleFg); - p.setFont(st::autoDownloadTitleFont); - p.drawTextLeft(st::boxTitlePosition.x(), _description->y() + _description->height() + st::boxTitlePosition.y(), width(), lang(lng_edit_group_who_invites)); - } -} - -void EditChannelBox::save() { - if (_saveTitleRequestId || _saveDescriptionRequestId || _saveSignRequestId || _saveInvitesRequestId) return; - - auto title = TextUtilities::PrepareForSending(_title->getLastText()); - auto description = TextUtilities::PrepareForSending(_description->getLastText(), TextUtilities::PrepareTextOption::CheckLinks); - if (title.isEmpty()) { - _title->setFocus(); - _title->showError(); - return; - } - _sentTitle = title; - _sentDescription = description; - if (_sentTitle == _channel->name) { - saveDescription(); - } else { - _saveTitleRequestId = MTP::send( - MTPchannels_EditTitle( - _channel->inputChannel, - MTP_string(_sentTitle)), - rpcDone(&EditChannelBox::onSaveTitleDone), - rpcFail(&EditChannelBox::onSaveFail)); - } -} - -void EditChannelBox::setupPublicLink() { - Ui::show( - Box(_channel, true), - LayerOption::KeepOther); -} - -void EditChannelBox::saveDescription() { - if (_sentDescription == _channel->about()) { - saveSign(); - } else { - _saveDescriptionRequestId = MTP::send( - MTPmessages_EditChatAbout( - _channel->input, - MTP_string(_sentDescription)), - rpcDone(&EditChannelBox::onSaveDescriptionDone), - rpcFail(&EditChannelBox::onSaveFail)); - } -} - -void EditChannelBox::saveSign() { - if (!canEditSignatures() || _channel->addsSignature() == _sign->checked()) { - saveInvites(); - } else { - _saveSignRequestId = MTP::send( - MTPchannels_ToggleSignatures( - _channel->inputChannel, - MTP_bool(_sign->checked())), - rpcDone(&EditChannelBox::onSaveSignDone), - rpcFail(&EditChannelBox::onSaveFail)); - } -} - -void EditChannelBox::saveInvites() { - // #TODO groups - //if (!canEditInvites() || _channel->anyoneCanAddMembers() == (_inviteGroup->value() == Invites::Everybody)) { - // closeBox(); - //} else { - // _saveInvitesRequestId = MTP::send(MTPchannels_ToggleInvites(_channel->inputChannel, MTP_bool(_inviteGroup->value() == Invites::Everybody)), rpcDone(&EditChannelBox::onSaveInvitesDone), rpcFail(&EditChannelBox::onSaveFail)); - //} -} - -bool EditChannelBox::onSaveFail(const RPCError &error, mtpRequestId req) { - if (MTP::isDefaultHandledError(error)) return false; - - QString err(error.type()); - if (req == _saveTitleRequestId) { - _saveTitleRequestId = 0; - if (err == qstr("CHAT_NOT_MODIFIED") || err == qstr("CHAT_TITLE_NOT_MODIFIED")) { - _channel->setName(_sentTitle, _channel->username); - saveDescription(); - return true; - } else if (err == qstr("NO_CHAT_TITLE")) { - _title->setFocus(); - _title->showError(); - return true; - } else { - _title->setFocus(); - } - } else if (req == _saveDescriptionRequestId) { - _saveDescriptionRequestId = 0; - if (err == qstr("CHAT_ABOUT_NOT_MODIFIED")) { - _channel->setAbout(_sentDescription); - saveSign(); - return true; - } else { - _description->setFocus(); - } - } else if (req == _saveSignRequestId) { - _saveSignRequestId = 0; - if (err == qstr("CHAT_NOT_MODIFIED")) { - saveInvites(); - return true; - } - } else if (req == _saveInvitesRequestId) { - _saveInvitesRequestId = 0; - if (err == qstr("CHAT_NOT_MODIFIED")) { - closeBox(); - return true; - } - } - return true; -} - -void EditChannelBox::onSaveTitleDone(const MTPUpdates &result) { - _saveTitleRequestId = 0; - Auth().api().applyUpdates(result); - saveDescription(); -} - -void EditChannelBox::onSaveDescriptionDone(const MTPBool &result) { - _saveDescriptionRequestId = 0; - _channel->setAbout(_sentDescription); - saveSign(); -} - -void EditChannelBox::onSaveSignDone(const MTPUpdates &result) { - _saveSignRequestId = 0; - Auth().api().applyUpdates(result); - saveInvites(); -} - -void EditChannelBox::onSaveInvitesDone(const MTPUpdates &result) { - _saveSignRequestId = 0; - Auth().api().applyUpdates(result); - closeBox(); -} - RevokePublicLinkBox::Inner::Inner(QWidget *parent, Fn revokeCallback) : TWidget(parent) , _rowHeight(st::contactsPadding.top() + st::contactsPhotoSize + st::contactsPadding.bottom()) , _revokeWidth(st::normalFont->width(lang(lng_channels_too_much_public_revoke))) diff --git a/Telegram/SourceFiles/boxes/add_contact_box.h b/Telegram/SourceFiles/boxes/add_contact_box.h index 5f41428a5e..07aab2e99a 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.h +++ b/Telegram/SourceFiles/boxes/add_contact_box.h @@ -205,62 +205,6 @@ private: }; -class EditChannelBox : public BoxContent, public RPCSender { -public: - EditChannelBox(QWidget*, not_null channel); - -protected: - void prepare() override; - void setInnerFocus() override; - - void keyPressEvent(QKeyEvent *e) override; - void resizeEvent(QResizeEvent *e) override; - void paintEvent(QPaintEvent *e) override; - -private: - void updateMaxHeight(); - bool canEditSignatures() const; - bool canEditInvites() const; - void handleChannelNameChange(); - void descriptionResized(); - void setupPublicLink(); - void save(); - - void onSaveTitleDone(const MTPUpdates &result); - void onSaveDescriptionDone(const MTPBool &result); - void onSaveSignDone(const MTPUpdates &result); - void onSaveInvitesDone(const MTPUpdates &result); - bool onSaveFail(const RPCError &error, mtpRequestId req); - - void saveDescription(); - void saveSign(); - void saveInvites(); - - not_null _channel; - - object_ptr _title; - object_ptr _description; - object_ptr _sign; - - enum class Invites { - Everybody, - OnlyAdmins, - }; - std::shared_ptr> _inviteGroup; - object_ptr> _inviteEverybody; - object_ptr> _inviteOnlyAdmins; - - object_ptr _publicLink; - - mtpRequestId _saveTitleRequestId = 0; - mtpRequestId _saveDescriptionRequestId = 0; - mtpRequestId _saveSignRequestId = 0; - mtpRequestId _saveInvitesRequestId = 0; - - QString _sentTitle, _sentDescription; - -}; - class RevokePublicLinkBox : public BoxContent, public RPCSender { public: RevokePublicLinkBox(QWidget*, Fn revokeCallback);