tdesktop/Telegram/SourceFiles/boxes/confirm_box.h

272 lines
7.7 KiB
C
Raw Normal View History

/*
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
2017-04-06 14:38:10 +00:00
#include "boxes/abstract_box.h"
#include "mtproto/sender.h"
2020-05-25 14:16:04 +00:00
namespace Data {
class PhotoMedia;
2020-05-28 14:32:10 +00:00
class CloudImageView;
2020-05-25 14:16:04 +00:00
} // namespace Data
2019-07-24 14:00:30 +00:00
namespace Main {
class Session;
} // namespace Main
namespace Ui {
class Checkbox;
class FlatLabel;
class EmptyUserpic;
} // namespace Ui
2015-10-03 10:09:09 +00:00
class InformBox;
2019-09-18 11:19:05 +00:00
class ConfirmBox : public Ui::BoxContent, public ClickHandlerHost {
public:
ConfirmBox(QWidget*, const QString &text, FnMut<void()> confirmedCallback = FnMut<void()>(), FnMut<void()> cancelledCallback = FnMut<void()>());
ConfirmBox(QWidget*, const QString &text, const QString &confirmText, FnMut<void()> confirmedCallback = FnMut<void()>(), FnMut<void()> cancelledCallback = FnMut<void()>());
ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const style::RoundButton &confirmStyle, FnMut<void()> confirmedCallback = FnMut<void()>(), FnMut<void()> cancelledCallback = FnMut<void()>());
ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const QString &cancelText, FnMut<void()> confirmedCallback = FnMut<void()>(), FnMut<void()> cancelledCallback = FnMut<void()>());
ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const style::RoundButton &confirmStyle, const QString &cancelText, FnMut<void()> confirmedCallback = FnMut<void()>(), FnMut<void()> cancelledCallback = FnMut<void()>());
ConfirmBox(QWidget*, const TextWithEntities &text, const QString &confirmText, FnMut<void()> confirmedCallback = nullptr, FnMut<void()> 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;
}
2018-05-30 15:08:12 +00:00
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<void()> closedCallback);
ConfirmBox(const InformBoxTag &, const TextWithEntities &text, const QString &doneText, Fn<void()> closedCallback);
FnMut<void()> generateInformCallback(Fn<void()> closedCallback);
2015-10-03 10:09:09 +00:00
friend class InformBox;
void confirmed();
void init(const QString &text);
void init(const TextWithEntities &text);
void textUpdated();
2018-05-30 15:08:12 +00:00
void updateHover();
QString _confirmText;
QString _cancelText;
const style::RoundButton &_confirmStyle;
bool _informative = false;
2019-06-12 13:26:04 +00:00
Ui::Text::String _text;
int _textWidth = 0;
int _textHeight = 0;
2018-05-30 15:08:12 +00:00
int _maxLineCount = 16;
QPoint _lastMousePos;
2015-10-03 10:09:09 +00:00
bool _confirmed = false;
bool _cancelled = false;
bool _strictCancel = false;
FnMut<void()> _confirmedCallback;
FnMut<void()> _cancelledCallback;
2015-10-03 10:09:09 +00:00
};
class InformBox : public ConfirmBox {
public:
InformBox(QWidget*, const QString &text, Fn<void()> closedCallback = nullptr);
InformBox(QWidget*, const QString &text, const QString &doneText, Fn<void()> closedCallback = nullptr);
InformBox(QWidget*, const TextWithEntities &text, Fn<void()> closedCallback = nullptr);
InformBox(QWidget*, const TextWithEntities &text, const QString &doneText, Fn<void()> closedCallback = nullptr);
};
2015-09-10 11:20:28 +00:00
2019-09-18 11:19:05 +00:00
class MaxInviteBox : public Ui::BoxContent, private base::Subscriber {
public:
MaxInviteBox(QWidget*, not_null<ChannelData*> channel);
2016-03-04 22:04:15 +00:00
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<ChannelData*> _channel;
2019-06-12 13:26:04 +00:00
Ui::Text::String _text;
int32 _textWidth, _textHeight;
QRect _invitationLink;
bool _linkOver = false;
QPoint _lastMousePos;
};
2016-03-04 22:04:15 +00:00
class PinMessageBox final : public Ui::BoxContent {
public:
PinMessageBox(QWidget*, not_null<PeerData*> peer, MsgId msgId);
protected:
void prepare() override;
void resizeEvent(QResizeEvent *e) override;
void keyPressEvent(QKeyEvent *e) override;
private:
void pinMessage();
const not_null<PeerData*> _peer;
MTP::Sender _api;
MsgId _msgId;
object_ptr<Ui::FlatLabel> _text;
2017-11-21 13:23:56 +00:00
object_ptr<Ui::Checkbox> _notify = { nullptr };
mtpRequestId _requestId = 0;
};
class DeleteMessagesBox final : public Ui::BoxContent {
public:
DeleteMessagesBox(
QWidget*,
not_null<HistoryItem*> item,
bool suggestModerateActions);
2019-07-24 14:00:30 +00:00
DeleteMessagesBox(
QWidget*,
not_null<Main::Session*> session,
MessageIdsList &&selected);
2019-03-21 13:48:40 +00:00
DeleteMessagesBox(QWidget*, not_null<PeerData*> peer, bool justClear);
void setDeleteConfirmedCallback(Fn<void()> callback) {
_deleteConfirmedCallback = std::move(callback);
}
protected:
void prepare() override;
void resizeEvent(QResizeEvent *e) override;
void keyPressEvent(QKeyEvent *e) override;
private:
2019-03-21 12:49:27 +00:00
struct RevokeConfig {
QString checkbox;
TextWithEntities description;
};
void deleteAndClear();
2019-08-16 15:08:51 +00:00
[[nodiscard]] PeerData *checkFromSinglePeer() const;
[[nodiscard]] bool hasScheduledMessages() const;
[[nodiscard]] std::optional<RevokeConfig> revokeText(
not_null<PeerData*> peer) const;
2019-07-24 14:00:30 +00:00
const not_null<Main::Session*> _session;
2019-03-21 13:48:40 +00:00
PeerData * const _wipeHistoryPeer = nullptr;
const bool _wipeHistoryJustClear = false;
const MessageIdsList _ids;
UserData *_moderateFrom = nullptr;
ChannelData *_moderateInChannel = nullptr;
2017-06-04 11:09:29 +00:00
bool _moderateBan = false;
bool _moderateDeleteAll = false;
object_ptr<Ui::FlatLabel> _text = { nullptr };
2019-03-20 13:02:02 +00:00
object_ptr<Ui::Checkbox> _revoke = { nullptr };
object_ptr<Ui::Checkbox> _banUser = { nullptr };
object_ptr<Ui::Checkbox> _reportSpam = { nullptr };
object_ptr<Ui::Checkbox> _deleteAll = { nullptr };
Fn<void()> _deleteConfirmedCallback;
};
class ConfirmInviteBox final
2019-09-18 11:19:05 +00:00
: public Ui::BoxContent
2019-09-16 11:14:06 +00:00
, private base::Subscriber {
public:
ConfirmInviteBox(
QWidget*,
2019-07-24 14:00:30 +00:00
not_null<Main::Session*> session,
const MTPDchatInvite &data,
Fn<void()> submit);
~ConfirmInviteBox();
protected:
void prepare() override;
void resizeEvent(QResizeEvent *e) override;
void paintEvent(QPaintEvent *e) override;
private:
2020-05-28 14:32:10 +00:00
struct Participant {
not_null<UserData*> user;
std::shared_ptr<Data::CloudImageView> userpic;
};
static std::vector<Participant> GetParticipants(
2019-07-24 14:00:30 +00:00
not_null<Main::Session*> session,
const MTPDchatInvite &data);
2019-07-24 14:00:30 +00:00
const not_null<Main::Session*> _session;
Fn<void()> _submit;
object_ptr<Ui::FlatLabel> _title;
object_ptr<Ui::FlatLabel> _status;
2020-05-25 14:16:04 +00:00
std::shared_ptr<Data::PhotoMedia> _photo;
std::unique_ptr<Ui::EmptyUserpic> _photoEmpty;
2020-05-28 14:32:10 +00:00
std::vector<Participant> _participants;
bool _isChannel = false;
int _userWidth = 0;
};
2018-12-05 08:07:17 +00:00
2019-09-18 11:19:05 +00:00
class ConfirmDontWarnBox : public Ui::BoxContent {
2018-12-05 08:07:17 +00:00
public:
ConfirmDontWarnBox(
QWidget*,
rpl::producer<TextWithEntities> text,
2018-12-05 08:07:17 +00:00
const QString &checkbox,
rpl::producer<QString> confirm,
2018-12-05 08:07:17 +00:00
FnMut<void(bool)> callback);
protected:
void prepare() override;
private:
not_null<Ui::RpWidget*> setupContent(
rpl::producer<TextWithEntities> text,
2018-12-05 08:07:17 +00:00
const QString &checkbox,
FnMut<void(bool)> callback);
rpl::producer<QString> _confirm;
2018-12-05 08:07:17 +00:00
FnMut<void()> _callback;
not_null<Ui::RpWidget*> _content;
};