2020-05-25 14:16:04 +00:00
|
|
|
/*
|
|
|
|
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 "base/flags.h"
|
|
|
|
#include "data/data_photo.h"
|
|
|
|
|
|
|
|
class FileLoader;
|
|
|
|
|
|
|
|
namespace Data {
|
|
|
|
|
|
|
|
class PhotoMedia final {
|
|
|
|
public:
|
|
|
|
explicit PhotoMedia(not_null<PhotoData*> owner);
|
|
|
|
~PhotoMedia();
|
|
|
|
|
|
|
|
[[nodiscard]] not_null<PhotoData*> owner() const;
|
|
|
|
|
|
|
|
[[nodiscard]] Image *thumbnailInline() const;
|
|
|
|
|
|
|
|
[[nodiscard]] Image *image(PhotoSize size) const;
|
2022-02-21 14:23:49 +00:00
|
|
|
[[nodiscard]] QByteArray imageBytes(PhotoSize size) const;
|
2020-05-25 14:16:04 +00:00
|
|
|
[[nodiscard]] QSize size(PhotoSize size) const;
|
|
|
|
void wanted(PhotoSize size, Data::FileOrigin origin);
|
2022-02-21 14:23:49 +00:00
|
|
|
void set(
|
|
|
|
PhotoSize size,
|
|
|
|
PhotoSize goodFor,
|
|
|
|
QImage image,
|
|
|
|
QByteArray bytes);
|
2020-05-25 14:16:04 +00:00
|
|
|
|
2022-06-03 11:58:02 +00:00
|
|
|
[[nodiscard]] QByteArray videoContent(PhotoSize size) const;
|
|
|
|
[[nodiscard]] QSize videoSize(PhotoSize size) const;
|
|
|
|
void videoWanted(PhotoSize size, Data::FileOrigin origin);
|
|
|
|
void setVideo(PhotoSize size, QByteArray content);
|
2020-07-03 08:42:09 +00:00
|
|
|
|
2020-05-25 14:16:04 +00:00
|
|
|
[[nodiscard]] bool loaded() const;
|
|
|
|
[[nodiscard]] float64 progress() const;
|
|
|
|
|
2021-12-03 10:59:08 +00:00
|
|
|
[[nodiscard]] bool autoLoadThumbnailAllowed(
|
|
|
|
not_null<PeerData*> peer) const;
|
2020-05-25 14:16:04 +00:00
|
|
|
void automaticLoad(Data::FileOrigin origin, const HistoryItem *item);
|
|
|
|
|
|
|
|
void collectLocalData(not_null<PhotoMedia*> local);
|
|
|
|
|
2022-03-07 07:09:03 +00:00
|
|
|
bool saveToFile(const QString &path);
|
2023-01-13 07:51:59 +00:00
|
|
|
bool setToClipboard();
|
2022-03-07 07:09:03 +00:00
|
|
|
|
2020-05-25 14:16:04 +00:00
|
|
|
private:
|
2020-08-25 18:03:41 +00:00
|
|
|
struct PhotoImage {
|
|
|
|
std::unique_ptr<Image> data;
|
2022-02-21 14:23:49 +00:00
|
|
|
QByteArray bytes;
|
2020-08-25 18:03:41 +00:00
|
|
|
PhotoSize goodFor = PhotoSize();
|
|
|
|
};
|
|
|
|
|
2022-02-21 14:23:49 +00:00
|
|
|
const PhotoImage *resolveLoadedImage(PhotoSize size) const;
|
|
|
|
|
2020-05-25 14:16:04 +00:00
|
|
|
// NB! Right now DocumentMedia can outlive Main::Session!
|
|
|
|
// In DocumentData::collectLocalData a shared_ptr is sent on_main.
|
|
|
|
// In case this is a problem the ~Gif code should be rewritten.
|
|
|
|
const not_null<PhotoData*> _owner;
|
|
|
|
mutable std::unique_ptr<Image> _inlineThumbnail;
|
2020-08-25 18:03:41 +00:00
|
|
|
std::array<PhotoImage, kPhotoSizeCount> _images;
|
2022-06-03 11:58:02 +00:00
|
|
|
QByteArray _videoBytesSmall;
|
|
|
|
QByteArray _videoBytesLarge;
|
2020-05-25 14:16:04 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Data
|