/* This file is part of Telegram Desktop, the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once #include "boxes/abstract_box.h" #include "mtproto/sender.h" namespace Data { class PhotoMedia; class CloudImageView; } // namespace Data namespace Main { class Session; } // namespace Main namespace Ui { class Checkbox; class FlatLabel; class EmptyUserpic; } // namespace Ui class InformBox; class ConfirmBox : public Ui::BoxContent, public ClickHandlerHost { public: using ConfirmedCallback = std::variant< v::null_t, FnMut, FnMut)>>; ConfirmBox( QWidget*, const QString &text, ConfirmedCallback confirmedCallback = FnMut(), FnMut cancelledCallback = FnMut()); ConfirmBox( QWidget*, const QString &text, const QString &confirmText, ConfirmedCallback confirmedCallback = FnMut(), FnMut cancelledCallback = FnMut()); ConfirmBox( QWidget*, const QString &text, const QString &confirmText, const style::RoundButton &confirmStyle, ConfirmedCallback confirmedCallback = FnMut(), FnMut cancelledCallback = FnMut()); ConfirmBox( QWidget*, const QString &text, const QString &confirmText, const QString &cancelText, ConfirmedCallback confirmedCallback = FnMut(), FnMut cancelledCallback = FnMut()); ConfirmBox( QWidget*, const QString &text, const QString &confirmText, const style::RoundButton &confirmStyle, const QString &cancelText, ConfirmedCallback confirmedCallback = FnMut(), FnMut cancelledCallback = FnMut()); ConfirmBox( QWidget*, const TextWithEntities &text, const QString &confirmText, ConfirmedCallback confirmedCallback = v::null, FnMut cancelledCallback = nullptr); void updateLink(); // If strict cancel is set the cancelledCallback is only called if the cancel button was pressed. void setStrictCancel(bool strictCancel) { _strictCancel = strictCancel; } void setMaxLineCount(int count); // ClickHandlerHost interface void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override; void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) override; protected: void prepare() override; void keyPressEvent(QKeyEvent *e) override; void paintEvent(QPaintEvent *e) override; void mouseMoveEvent(QMouseEvent *e) override; void mousePressEvent(QMouseEvent *e) override; void mouseReleaseEvent(QMouseEvent *e) override; void leaveEventHook(QEvent *e) override; private: struct InformBoxTag { }; ConfirmBox(const InformBoxTag &, const QString &text, const QString &doneText, Fn closedCallback); ConfirmBox(const InformBoxTag &, const TextWithEntities &text, const QString &doneText, Fn closedCallback); FnMut generateInformCallback(Fn closedCallback); friend class InformBox; void confirmed(); void init(const QString &text); void init(const TextWithEntities &text); void textUpdated(); void updateHover(); QString _confirmText; QString _cancelText; const style::RoundButton &_confirmStyle; bool _informative = false; Ui::Text::String _text; int _textWidth = 0; int _textHeight = 0; int _maxLineCount = 16; QPoint _lastMousePos; bool _confirmed = false; bool _cancelled = false; bool _strictCancel = false; ConfirmBox::ConfirmedCallback _confirmedCallback; FnMut _cancelledCallback; }; class InformBox : public ConfirmBox { public: InformBox(QWidget*, const QString &text, Fn closedCallback = nullptr); InformBox(QWidget*, const QString &text, const QString &doneText, Fn closedCallback = nullptr); InformBox(QWidget*, const TextWithEntities &text, Fn closedCallback = nullptr); InformBox(QWidget*, const TextWithEntities &text, const QString &doneText, Fn closedCallback = nullptr); }; class MaxInviteBox : public Ui::BoxContent, private base::Subscriber { public: MaxInviteBox(QWidget*, not_null channel); protected: void prepare() override; void paintEvent(QPaintEvent *e) override; void resizeEvent(QResizeEvent *e) override; void mouseMoveEvent(QMouseEvent *e) override; void mousePressEvent(QMouseEvent *e) override; void leaveEventHook(QEvent *e) override; private: void updateSelected(const QPoint &cursorGlobalPosition); not_null _channel; Ui::Text::String _text; int32 _textWidth, _textHeight; QRect _invitationLink; bool _linkOver = false; QPoint _lastMousePos; }; class PinMessageBox final : public Ui::BoxContent { public: PinMessageBox(QWidget*, not_null peer, MsgId msgId); protected: void prepare() override; void resizeEvent(QResizeEvent *e) override; void keyPressEvent(QKeyEvent *e) override; private: void pinMessage(); const not_null _peer; MTP::Sender _api; MsgId _msgId; object_ptr _text; object_ptr _notify = { nullptr }; mtpRequestId _requestId = 0; }; class DeleteMessagesBox final : public Ui::BoxContent { public: DeleteMessagesBox( QWidget*, not_null item, bool suggestModerateActions); DeleteMessagesBox( QWidget*, not_null session, MessageIdsList &&selected); DeleteMessagesBox(QWidget*, not_null peer, bool justClear); void setDeleteConfirmedCallback(Fn callback) { _deleteConfirmedCallback = std::move(callback); } protected: void prepare() override; void resizeEvent(QResizeEvent *e) override; void keyPressEvent(QKeyEvent *e) override; private: struct RevokeConfig { QString checkbox; TextWithEntities description; }; void deleteAndClear(); [[nodiscard]] PeerData *checkFromSinglePeer() const; [[nodiscard]] bool hasScheduledMessages() const; [[nodiscard]] std::optional revokeText( not_null peer) const; const not_null _session; PeerData * const _wipeHistoryPeer = nullptr; const bool _wipeHistoryJustClear = false; const MessageIdsList _ids; UserData *_moderateFrom = nullptr; ChannelData *_moderateInChannel = nullptr; bool _moderateBan = false; bool _moderateDeleteAll = false; object_ptr _text = { nullptr }; object_ptr _revoke = { nullptr }; object_ptr _banUser = { nullptr }; object_ptr _reportSpam = { nullptr }; object_ptr _deleteAll = { nullptr }; Fn _deleteConfirmedCallback; }; class ConfirmDontWarnBox : public Ui::BoxContent { public: ConfirmDontWarnBox( QWidget*, rpl::producer text, const QString &checkbox, rpl::producer confirm, FnMut callback); protected: void prepare() override; private: not_null setupContent( rpl::producer text, const QString &checkbox, FnMut callback); rpl::producer _confirm; FnMut _callback; not_null _content; };