attach_prepare.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. #include "editor/photo_editor_common.h"
  9. #include "ui/chat/attach/attach_send_files_way.h"
  10. #include "ui/rect_part.h"
  11. #include <QtCore/QSemaphore>
  12. #include <deque>
  13. namespace Ui {
  14. class RpWidget;
  15. class SendFilesWay;
  16. struct PreparedFileInformation {
  17. struct Image {
  18. QImage data;
  19. QByteArray bytes;
  20. QByteArray format;
  21. bool animated = false;
  22. Editor::PhotoModifications modifications;
  23. };
  24. struct Song {
  25. crl::time duration = -1;
  26. QString title;
  27. QString performer;
  28. QImage cover;
  29. };
  30. struct Video {
  31. bool isGifv = false;
  32. bool isWebmSticker = false;
  33. bool supportsStreaming = false;
  34. crl::time duration = -1;
  35. QImage thumbnail;
  36. };
  37. QString filemime;
  38. std::variant<v::null_t, Image, Song, Video> media;
  39. };
  40. enum class AlbumType {
  41. None,
  42. PhotoVideo,
  43. Music,
  44. File,
  45. };
  46. struct PreparedFile {
  47. // File-s can be grouped if 'groupFiles'.
  48. // File-s + Photo-s can be grouped if 'groupFiles && !sendImagesAsPhotos'.
  49. // Photo-s can be grouped if 'groupFiles'.
  50. // Photo-s + Video-s can be grouped if 'groupFiles && sendImagesAsPhotos'.
  51. // Video-s can be grouped if 'groupFiles'.
  52. // Music-s can be grouped if 'groupFiles'.
  53. enum class Type {
  54. None,
  55. Photo,
  56. Video,
  57. Music,
  58. File,
  59. };
  60. PreparedFile(const QString &path);
  61. PreparedFile(PreparedFile &&other);
  62. PreparedFile &operator=(PreparedFile &&other);
  63. ~PreparedFile();
  64. [[nodiscard]] bool canBeInAlbumType(AlbumType album) const;
  65. [[nodiscard]] AlbumType albumType(bool sendImagesAsPhotos) const;
  66. [[nodiscard]] bool isSticker() const;
  67. [[nodiscard]] bool isVideoFile() const;
  68. [[nodiscard]] bool isGifv() const;
  69. QString path;
  70. QByteArray content;
  71. int64 size = 0;
  72. std::unique_ptr<PreparedFileInformation> information;
  73. std::unique_ptr<PreparedFile> videoCover;
  74. QImage preview;
  75. QSize shownDimensions;
  76. QSize originalDimensions;
  77. Type type = Type::File;
  78. bool spoiler = false;
  79. };
  80. [[nodiscard]] bool CanBeInAlbumType(PreparedFile::Type type, AlbumType album);
  81. [[nodiscard]] bool InsertTextOnImageCancel(const QString &text);
  82. struct PreparedList {
  83. enum class Error {
  84. None,
  85. NonLocalUrl,
  86. Directory,
  87. EmptyFile,
  88. TooLargeFile,
  89. };
  90. PreparedList() = default;
  91. PreparedList(Error error, QString errorData)
  92. : error(error)
  93. , errorData(errorData) {
  94. }
  95. PreparedList(PreparedList &&other) = default;
  96. PreparedList &operator=(PreparedList &&other) = default;
  97. [[nodiscard]] static PreparedList Reordered(
  98. PreparedList &&list,
  99. std::vector<int> order);
  100. void mergeToEnd(PreparedList &&other, bool cutToAlbumSize = false);
  101. [[nodiscard]] bool canAddCaption(bool sendingAlbum, bool compress) const;
  102. [[nodiscard]] bool canMoveCaption(
  103. bool sendingAlbum,
  104. bool compress) const;
  105. [[nodiscard]] bool canChangePrice(
  106. bool sendingAlbum,
  107. bool compress) const;
  108. [[nodiscard]] bool canBeSentInSlowmode() const;
  109. [[nodiscard]] bool canBeSentInSlowmodeWith(
  110. const PreparedList &other) const;
  111. [[nodiscard]] bool hasGroupOption(bool slowmode) const;
  112. [[nodiscard]] bool hasSendImagesAsPhotosOption(bool slowmode) const;
  113. [[nodiscard]] bool canHaveEditorHintLabel() const;
  114. [[nodiscard]] bool hasSticker() const;
  115. [[nodiscard]] bool hasSpoilerMenu(bool compress) const;
  116. Error error = Error::None;
  117. QString errorData;
  118. std::vector<PreparedFile> files;
  119. std::deque<PreparedFile> filesToProcess;
  120. std::optional<bool> overrideSendImagesAsPhotos;
  121. };
  122. struct PreparedGroup {
  123. PreparedList list;
  124. AlbumType type = AlbumType::None;
  125. [[nodiscard]] bool sentWithCaption() const {
  126. return (list.files.size() == 1)
  127. || (type == AlbumType::PhotoVideo);
  128. }
  129. };
  130. [[nodiscard]] std::vector<PreparedGroup> DivideByGroups(
  131. PreparedList &&list,
  132. SendFilesWay way,
  133. bool slowmode);
  134. struct PreparedBundle {
  135. std::vector<PreparedGroup> groups;
  136. SendFilesWay way;
  137. TextWithTags caption;
  138. int totalCount = 0;
  139. bool sendComment = false;
  140. bool ctrlShiftEnter = false;
  141. };
  142. [[nodiscard]] std::shared_ptr<PreparedBundle> PrepareFilesBundle(
  143. std::vector<PreparedGroup> groups,
  144. SendFilesWay way,
  145. TextWithTags caption,
  146. bool ctrlShiftEnter);
  147. [[nodiscard]] int MaxAlbumItems();
  148. [[nodiscard]] bool ValidateThumbDimensions(int width, int height);
  149. [[nodiscard]] QPixmap PrepareSongCoverForThumbnail(QImage image, int size);
  150. [[nodiscard]] QPixmap BlurredPreviewFromPixmap(
  151. QPixmap pixmap,
  152. RectParts corners);
  153. } // namespace Ui