2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2023-01-10 18:56:20 +00:00
|
|
|
#include "base/flags.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/abstract_box.h"
|
2020-10-13 12:07:53 +00:00
|
|
|
#include "ui/chat/attach/attach_prepare.h"
|
2020-10-15 14:27:16 +00:00
|
|
|
#include "ui/chat/attach/attach_send_files_way.h"
|
2022-12-16 08:36:50 +00:00
|
|
|
#include "ui/widgets/popup_menu.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localimageloader.h"
|
2017-12-19 16:57:42 +00:00
|
|
|
#include "storage/storage_media_prepare.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2023-05-18 13:46:24 +00:00
|
|
|
namespace style {
|
|
|
|
struct ComposeControls;
|
|
|
|
} // namespace style
|
|
|
|
|
2018-05-26 14:58:21 +00:00
|
|
|
namespace Window {
|
2019-06-06 10:21:40 +00:00
|
|
|
class SessionController;
|
2018-05-26 14:58:21 +00:00
|
|
|
} // namespace Window
|
|
|
|
|
2019-08-12 12:11:34 +00:00
|
|
|
namespace Api {
|
|
|
|
struct SendOptions;
|
2019-08-20 13:21:10 +00:00
|
|
|
enum class SendType;
|
2019-08-12 12:11:34 +00:00
|
|
|
} // namespace Api
|
|
|
|
|
2018-11-22 12:48:50 +00:00
|
|
|
namespace ChatHelpers {
|
|
|
|
class TabbedPanel;
|
2023-05-18 13:46:24 +00:00
|
|
|
class Show;
|
2018-11-22 12:48:50 +00:00
|
|
|
} // namespace ChatHelpers
|
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
namespace Ui {
|
2020-10-15 14:27:16 +00:00
|
|
|
class Checkbox;
|
2016-11-11 13:46:04 +00:00
|
|
|
class RoundButton;
|
2018-05-20 17:42:30 +00:00
|
|
|
class InputField;
|
2017-12-19 16:57:42 +00:00
|
|
|
struct GroupMediaLayout;
|
2018-11-22 12:48:50 +00:00
|
|
|
class EmojiButton;
|
2020-10-13 15:11:53 +00:00
|
|
|
class AlbumPreview;
|
2020-10-16 07:52:55 +00:00
|
|
|
class VerticalLayout;
|
2021-04-26 08:23:54 +00:00
|
|
|
class FlatLabel;
|
2022-12-16 08:36:50 +00:00
|
|
|
class PopupMenu;
|
2016-10-28 09:20:24 +00:00
|
|
|
} // namespace Ui
|
|
|
|
|
2018-04-06 16:23:09 +00:00
|
|
|
namespace Window {
|
2019-06-06 10:21:40 +00:00
|
|
|
class SessionController;
|
2018-04-06 16:23:09 +00:00
|
|
|
} // namespace Window
|
|
|
|
|
2020-08-10 12:22:54 +00:00
|
|
|
namespace SendMenu {
|
|
|
|
enum class Type;
|
|
|
|
} // namespace SendMenu
|
2019-08-28 16:46:47 +00:00
|
|
|
|
2023-01-10 18:56:20 +00:00
|
|
|
enum class SendFilesAllow {
|
|
|
|
OnlyOne = (1 << 0),
|
|
|
|
Photos = (1 << 1),
|
|
|
|
Videos = (1 << 2),
|
|
|
|
Music = (1 << 3),
|
|
|
|
Files = (1 << 4),
|
|
|
|
Stickers = (1 << 5),
|
|
|
|
Gifs = (1 << 6),
|
|
|
|
EmojiWithoutPremium = (1 << 7),
|
|
|
|
Texts = (1 << 8),
|
|
|
|
};
|
|
|
|
inline constexpr bool is_flag_type(SendFilesAllow) { return true; }
|
|
|
|
using SendFilesLimits = base::flags<SendFilesAllow>;
|
|
|
|
|
|
|
|
using SendFilesCheck = Fn<bool(
|
|
|
|
const Ui::PreparedFile &file,
|
|
|
|
bool compress,
|
|
|
|
bool silent)>;
|
|
|
|
|
|
|
|
[[nodiscard]] SendFilesLimits DefaultLimitsForPeer(not_null<PeerData*> peer);
|
|
|
|
[[nodiscard]] SendFilesCheck DefaultCheckForPeer(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<PeerData*> peer);
|
2023-05-18 13:46:24 +00:00
|
|
|
[[nodiscard]] SendFilesCheck DefaultCheckForPeer(
|
|
|
|
std::shared_ptr<Ui::Show> show,
|
|
|
|
not_null<PeerData*> peer);
|
|
|
|
|
|
|
|
using SendFilesConfirmed = Fn<void(
|
|
|
|
Ui::PreparedList &&list,
|
|
|
|
Ui::SendFilesWay way,
|
|
|
|
TextWithTags &&caption,
|
|
|
|
Api::SendOptions options,
|
|
|
|
bool ctrlShiftEnter)>;
|
|
|
|
|
|
|
|
struct SendFilesBoxDescriptor {
|
|
|
|
std::shared_ptr<ChatHelpers::Show> show;
|
|
|
|
Ui::PreparedList list;
|
|
|
|
TextWithTags caption;
|
|
|
|
SendFilesLimits limits = {};
|
|
|
|
SendFilesCheck check;
|
|
|
|
Api::SendType sendType = {};
|
|
|
|
SendMenu::Type sendMenuType = {};
|
|
|
|
const style::ComposeControls *stOverride = nullptr;
|
|
|
|
SendFilesConfirmed confirmed;
|
|
|
|
Fn<void()> cancelled;
|
|
|
|
};
|
2023-01-10 18:56:20 +00:00
|
|
|
|
2019-09-18 11:19:05 +00:00
|
|
|
class SendFilesBox : public Ui::BoxContent {
|
2014-05-30 08:53:19 +00:00
|
|
|
public:
|
2019-07-17 10:37:42 +00:00
|
|
|
enum class SendLimit {
|
|
|
|
One,
|
|
|
|
Many
|
|
|
|
};
|
2017-12-21 16:15:37 +00:00
|
|
|
SendFilesBox(
|
|
|
|
QWidget*,
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2020-10-13 12:07:53 +00:00
|
|
|
Ui::PreparedList &&list,
|
2018-05-24 14:57:41 +00:00
|
|
|
const TextWithTags &caption,
|
2023-01-10 18:56:20 +00:00
|
|
|
SendFilesLimits limits,
|
|
|
|
SendFilesCheck check,
|
2019-08-28 16:46:47 +00:00
|
|
|
Api::SendType sendType,
|
2020-08-10 12:22:54 +00:00
|
|
|
SendMenu::Type sendMenuType);
|
2023-05-18 13:46:24 +00:00
|
|
|
SendFilesBox(QWidget*, SendFilesBoxDescriptor &&descriptor);
|
2017-12-21 16:15:37 +00:00
|
|
|
|
2023-05-18 13:46:24 +00:00
|
|
|
void setConfirmedCallback(SendFilesConfirmed callback) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_confirmedCallback = std::move(callback);
|
2016-11-28 15:45:07 +00:00
|
|
|
}
|
2018-06-04 15:35:11 +00:00
|
|
|
void setCancelledCallback(Fn<void()> callback) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_cancelledCallback = std::move(callback);
|
2016-11-28 15:45:07 +00:00
|
|
|
}
|
2015-10-11 08:37:24 +00:00
|
|
|
|
2017-12-05 08:43:18 +00:00
|
|
|
~SendFilesBox();
|
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
protected:
|
2016-12-13 17:07:56 +00:00
|
|
|
void prepare() override;
|
|
|
|
void setInnerFocus() override;
|
|
|
|
|
2016-08-16 16:53:10 +00:00
|
|
|
void keyPressEvent(QKeyEvent *e) override;
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
private:
|
2020-10-16 10:38:12 +00:00
|
|
|
class Block final {
|
|
|
|
public:
|
|
|
|
Block(
|
|
|
|
not_null<QWidget*> parent,
|
2023-05-18 13:46:24 +00:00
|
|
|
const style::ComposeControls &st,
|
2020-10-16 10:38:12 +00:00
|
|
|
not_null<std::vector<Ui::PreparedFile>*> items,
|
|
|
|
int from,
|
|
|
|
int till,
|
|
|
|
Fn<bool()> gifPaused,
|
|
|
|
Ui::SendFilesWay way);
|
|
|
|
Block(Block &&other) = default;
|
|
|
|
Block &operator=(Block &&other) = default;
|
|
|
|
|
|
|
|
[[nodiscard]] int fromIndex() const;
|
|
|
|
[[nodiscard]] int tillIndex() const;
|
|
|
|
[[nodiscard]] object_ptr<Ui::RpWidget> takeWidget();
|
|
|
|
|
2020-10-17 17:09:06 +00:00
|
|
|
[[nodiscard]] rpl::producer<int> itemDeleteRequest() const;
|
|
|
|
[[nodiscard]] rpl::producer<int> itemReplaceRequest() const;
|
2021-02-20 03:30:14 +00:00
|
|
|
[[nodiscard]] rpl::producer<int> itemModifyRequest() const;
|
2020-10-17 17:09:06 +00:00
|
|
|
|
2020-10-16 10:38:12 +00:00
|
|
|
void setSendWay(Ui::SendFilesWay way);
|
2022-12-16 08:36:50 +00:00
|
|
|
void toggleSpoilers(bool enabled);
|
2022-12-13 12:11:52 +00:00
|
|
|
void applyChanges();
|
2020-10-16 10:38:12 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
base::unique_qptr<Ui::RpWidget> _preview;
|
|
|
|
not_null<std::vector<Ui::PreparedFile>*> _items;
|
|
|
|
int _from = 0;
|
|
|
|
int _till = 0;
|
|
|
|
bool _isAlbum = false;
|
2020-10-19 08:49:31 +00:00
|
|
|
bool _isSingleMedia = false;
|
2020-10-16 10:38:12 +00:00
|
|
|
|
2020-10-16 07:52:55 +00:00
|
|
|
};
|
2022-12-16 08:36:50 +00:00
|
|
|
|
2017-12-22 17:42:33 +00:00
|
|
|
void initSendWay();
|
2020-10-16 07:52:55 +00:00
|
|
|
void initPreview();
|
2022-12-16 08:36:50 +00:00
|
|
|
[[nodiscard]] bool hasSendMenu() const;
|
|
|
|
[[nodiscard]] bool hasSpoilerMenu() const;
|
|
|
|
[[nodiscard]] bool allWithSpoilers();
|
2023-01-10 18:56:20 +00:00
|
|
|
[[nodiscard]] bool checkWithWay(
|
|
|
|
Ui::SendFilesWay way,
|
|
|
|
bool silent = false) const;
|
|
|
|
[[nodiscard]] bool checkWith(
|
|
|
|
const Ui::PreparedList &added,
|
|
|
|
Ui::SendFilesWay way,
|
|
|
|
bool silent = false) const;
|
2022-12-16 08:36:50 +00:00
|
|
|
void addMenuButton();
|
|
|
|
void applyBlockChanges();
|
|
|
|
void toggleSpoilers(bool enabled);
|
2017-12-22 17:42:33 +00:00
|
|
|
|
2022-05-11 09:59:38 +00:00
|
|
|
bool validateLength(const QString &text) const;
|
2022-12-16 08:36:50 +00:00
|
|
|
void refreshButtons();
|
|
|
|
void refreshControls(bool initial = false);
|
2017-12-22 17:42:33 +00:00
|
|
|
void setupSendWayControls();
|
|
|
|
void setupCaption();
|
|
|
|
|
2018-11-22 12:48:50 +00:00
|
|
|
void setupEmojiPanel();
|
2022-12-16 08:36:50 +00:00
|
|
|
void updateSendWayControls();
|
2018-11-22 12:48:50 +00:00
|
|
|
void updateEmojiPanelGeometry();
|
2019-09-05 10:51:36 +00:00
|
|
|
void emojiFilterForGeometry(not_null<QEvent*> event);
|
2018-11-22 12:48:50 +00:00
|
|
|
|
2017-12-29 17:02:23 +00:00
|
|
|
void preparePreview();
|
2020-10-16 10:38:12 +00:00
|
|
|
void generatePreviewFrom(int fromBlock);
|
2017-03-10 14:14:10 +00:00
|
|
|
|
2019-08-12 12:11:34 +00:00
|
|
|
void send(Api::SendOptions options, bool ctrlShiftEnter = false);
|
|
|
|
void sendSilent();
|
|
|
|
void sendScheduled();
|
2023-04-22 18:26:09 +00:00
|
|
|
void sendWhenOnline();
|
2017-12-19 16:57:42 +00:00
|
|
|
void captionResized();
|
2020-11-02 07:07:03 +00:00
|
|
|
void saveSendWaySettings();
|
2017-12-19 16:57:42 +00:00
|
|
|
|
2020-06-13 14:13:56 +00:00
|
|
|
void setupDragArea();
|
2020-10-16 14:11:23 +00:00
|
|
|
void refreshTitleText();
|
2015-10-11 08:37:24 +00:00
|
|
|
void updateBoxSize();
|
2016-11-28 15:45:07 +00:00
|
|
|
void updateControlsGeometry();
|
2018-12-26 06:47:03 +00:00
|
|
|
void updateCaptionPlaceholder();
|
2015-10-11 08:37:24 +00:00
|
|
|
|
2017-12-29 17:02:23 +00:00
|
|
|
bool canAddFiles(not_null<const QMimeData*> data) const;
|
|
|
|
bool addFiles(not_null<const QMimeData*> data);
|
2020-10-13 12:07:53 +00:00
|
|
|
bool addFiles(Ui::PreparedList list);
|
2020-10-16 14:11:23 +00:00
|
|
|
void addFile(Ui::PreparedFile &&file);
|
2020-10-17 17:09:06 +00:00
|
|
|
void pushBlock(int from, int till);
|
2017-12-29 17:02:23 +00:00
|
|
|
|
2020-01-05 21:04:47 +00:00
|
|
|
void openDialogToAddFileToAlbum();
|
2022-12-13 12:11:52 +00:00
|
|
|
void refreshAllAfterChanges(int fromItem, Fn<void()> perform = nullptr);
|
2020-10-16 14:11:23 +00:00
|
|
|
|
|
|
|
void enqueueNextPrepare();
|
|
|
|
void addPreparedAsyncFile(Ui::PreparedFile &&file);
|
2020-01-05 21:04:47 +00:00
|
|
|
|
2023-05-18 13:46:24 +00:00
|
|
|
const std::shared_ptr<ChatHelpers::Show> _show;
|
|
|
|
const style::ComposeControls &_st;
|
2019-08-20 13:21:10 +00:00
|
|
|
const Api::SendType _sendType = Api::SendType();
|
2018-05-26 14:58:21 +00:00
|
|
|
|
2016-11-28 15:45:07 +00:00
|
|
|
QString _titleText;
|
2020-10-19 10:02:39 +00:00
|
|
|
rpl::variable<int> _titleHeight = 0;
|
2017-12-22 17:42:33 +00:00
|
|
|
|
2020-10-13 12:07:53 +00:00
|
|
|
Ui::PreparedList _list;
|
2020-10-17 17:09:06 +00:00
|
|
|
std::optional<int> _removingIndex;
|
2015-12-19 14:37:28 +00:00
|
|
|
|
2023-01-10 18:56:20 +00:00
|
|
|
SendFilesLimits _limits = {};
|
2023-05-18 13:46:24 +00:00
|
|
|
SendMenu::Type _sendMenuType = {};
|
2015-12-19 14:37:28 +00:00
|
|
|
|
2023-01-10 18:56:20 +00:00
|
|
|
SendFilesCheck _check;
|
2023-05-18 13:46:24 +00:00
|
|
|
SendFilesConfirmed _confirmedCallback;
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void()> _cancelledCallback;
|
2016-11-28 15:45:07 +00:00
|
|
|
bool _confirmed = false;
|
2015-12-19 14:37:28 +00:00
|
|
|
|
2018-05-20 17:42:30 +00:00
|
|
|
object_ptr<Ui::InputField> _caption = { nullptr };
|
2022-08-15 16:10:38 +00:00
|
|
|
TextWithTags _prefilledCaptionText;
|
2018-11-22 12:48:50 +00:00
|
|
|
object_ptr<Ui::EmojiButton> _emojiToggle = { nullptr };
|
|
|
|
base::unique_qptr<ChatHelpers::TabbedPanel> _emojiPanel;
|
|
|
|
base::unique_qptr<QObject> _emojiFilter;
|
|
|
|
|
2020-10-15 14:27:16 +00:00
|
|
|
object_ptr<Ui::Checkbox> _groupFiles = { nullptr };
|
2020-10-17 09:51:55 +00:00
|
|
|
object_ptr<Ui::Checkbox> _sendImagesAsPhotos = { nullptr };
|
2022-12-12 11:35:41 +00:00
|
|
|
object_ptr<Ui::Checkbox> _wayRemember = { nullptr };
|
2021-04-26 08:23:54 +00:00
|
|
|
object_ptr<Ui::FlatLabel> _hintLabel = { nullptr };
|
2020-10-15 14:27:16 +00:00
|
|
|
rpl::variable<Ui::SendFilesWay> _sendWay = Ui::SendFilesWay();
|
2016-02-21 12:30:16 +00:00
|
|
|
|
2017-12-22 17:42:33 +00:00
|
|
|
rpl::variable<int> _footerHeight = 0;
|
2020-10-15 14:27:16 +00:00
|
|
|
rpl::lifetime _dimensionsLifetime;
|
2017-12-19 16:57:42 +00:00
|
|
|
|
2020-10-16 07:52:55 +00:00
|
|
|
object_ptr<Ui::ScrollArea> _scroll;
|
|
|
|
QPointer<Ui::VerticalLayout> _inner;
|
|
|
|
std::vector<Block> _blocks;
|
2020-10-16 17:48:27 +00:00
|
|
|
Fn<void()> _whenReadySend;
|
2020-10-16 14:11:23 +00:00
|
|
|
bool _preparing = false;
|
2017-12-19 16:57:42 +00:00
|
|
|
|
2022-12-16 08:36:50 +00:00
|
|
|
base::unique_qptr<Ui::PopupMenu> _menu;
|
|
|
|
|
2017-12-22 17:42:33 +00:00
|
|
|
QPointer<Ui::RoundButton> _send;
|
2020-10-15 14:27:16 +00:00
|
|
|
QPointer<Ui::RoundButton> _addFile;
|
2017-12-19 16:57:42 +00:00
|
|
|
|
|
|
|
};
|