data_photo_media.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 "data/data_photo.h"
  9. class FileLoader;
  10. namespace Data {
  11. class PhotoMedia final {
  12. public:
  13. explicit PhotoMedia(not_null<PhotoData*> owner);
  14. ~PhotoMedia();
  15. [[nodiscard]] not_null<PhotoData*> owner() const;
  16. [[nodiscard]] Image *thumbnailInline() const;
  17. [[nodiscard]] Image *image(PhotoSize size) const;
  18. [[nodiscard]] QByteArray imageBytes(PhotoSize size) const;
  19. [[nodiscard]] QSize size(PhotoSize size) const;
  20. void wanted(PhotoSize size, Data::FileOrigin origin);
  21. void set(
  22. PhotoSize size,
  23. PhotoSize goodFor,
  24. QImage image,
  25. QByteArray bytes);
  26. [[nodiscard]] QByteArray videoContent(PhotoSize size) const;
  27. [[nodiscard]] QSize videoSize(PhotoSize size) const;
  28. void videoWanted(PhotoSize size, Data::FileOrigin origin);
  29. void setVideo(PhotoSize size, QByteArray content);
  30. [[nodiscard]] bool loaded() const;
  31. [[nodiscard]] float64 progress() const;
  32. [[nodiscard]] bool autoLoadThumbnailAllowed(
  33. not_null<PeerData*> peer) const;
  34. void automaticLoad(FileOrigin origin, const HistoryItem *item);
  35. void automaticLoad(FileOrigin origin, not_null<PeerData*> peer);
  36. void collectLocalData(not_null<PhotoMedia*> local);
  37. bool saveToFile(const QString &path);
  38. bool setToClipboard();
  39. private:
  40. struct PhotoImage {
  41. std::unique_ptr<Image> data;
  42. QByteArray bytes;
  43. PhotoSize goodFor = PhotoSize();
  44. };
  45. const PhotoImage *resolveLoadedImage(PhotoSize size) const;
  46. // NB! Right now DocumentMedia can outlive Main::Session!
  47. // In DocumentData::collectLocalData a shared_ptr is sent on_main.
  48. // In case this is a problem the ~Gif code should be rewritten.
  49. const not_null<PhotoData*> _owner;
  50. mutable std::unique_ptr<Image> _inlineThumbnail;
  51. std::array<PhotoImage, kPhotoSizeCount> _images;
  52. QByteArray _videoBytesSmall;
  53. QByteArray _videoBytesLarge;
  54. };
  55. } // namespace Data