2020-03-27 11:40:50 +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"
|
|
|
|
|
2020-05-29 14:08:18 +00:00
|
|
|
class Image;
|
2020-04-09 08:15:47 +00:00
|
|
|
class FileLoader;
|
|
|
|
|
2020-05-22 11:57:13 +00:00
|
|
|
namespace Media {
|
|
|
|
namespace Clip {
|
|
|
|
enum Notification : int;
|
|
|
|
class ReaderPointer;
|
|
|
|
} // namespace Clip
|
|
|
|
} // namespace Media
|
|
|
|
|
2020-03-27 11:40:50 +00:00
|
|
|
namespace Data {
|
|
|
|
|
2020-05-22 11:57:13 +00:00
|
|
|
class DocumentMedia;
|
|
|
|
|
|
|
|
class VideoPreviewState final {
|
|
|
|
public:
|
|
|
|
explicit VideoPreviewState(DocumentMedia *media);
|
|
|
|
|
|
|
|
void automaticLoad(Data::FileOrigin origin) const;
|
|
|
|
[[nodiscard]] ::Media::Clip::ReaderPointer makeAnimation(
|
|
|
|
Fn<void(::Media::Clip::Notification)> callback) const;
|
|
|
|
[[nodiscard]] bool usingThumbnail() const;
|
|
|
|
[[nodiscard]] bool loading() const;
|
|
|
|
[[nodiscard]] bool loaded() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DocumentMedia *_media = nullptr;
|
|
|
|
bool _usingThumbnail = false;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-03-27 11:40:50 +00:00
|
|
|
class DocumentMedia final {
|
|
|
|
public:
|
|
|
|
explicit DocumentMedia(not_null<DocumentData*> owner);
|
|
|
|
~DocumentMedia();
|
|
|
|
|
2020-04-09 12:27:53 +00:00
|
|
|
[[nodiscard]] not_null<DocumentData*> owner() const;
|
|
|
|
|
2020-03-27 11:40:50 +00:00
|
|
|
void goodThumbnailWanted();
|
2020-05-29 15:10:25 +00:00
|
|
|
[[nodiscard]] Image *goodThumbnail() const;
|
2020-03-27 11:40:50 +00:00
|
|
|
void setGoodThumbnail(QImage thumbnail);
|
|
|
|
|
2020-04-08 15:09:29 +00:00
|
|
|
[[nodiscard]] Image *thumbnailInline() const;
|
2021-07-02 10:13:48 +00:00
|
|
|
[[nodiscard]] const QPainterPath &thumbnailPath() const;
|
2020-05-22 11:15:09 +00:00
|
|
|
|
2020-04-15 14:06:34 +00:00
|
|
|
[[nodiscard]] Image *thumbnail() const;
|
|
|
|
[[nodiscard]] QSize thumbnailSize() const;
|
|
|
|
void thumbnailWanted(Data::FileOrigin origin);
|
|
|
|
void setThumbnail(QImage thumbnail);
|
2020-04-08 15:09:29 +00:00
|
|
|
|
2020-05-22 11:15:09 +00:00
|
|
|
[[nodiscard]] QByteArray videoThumbnailContent() const;
|
|
|
|
[[nodiscard]] QSize videoThumbnailSize() const;
|
|
|
|
void videoThumbnailWanted(Data::FileOrigin origin);
|
|
|
|
void setVideoThumbnail(QByteArray content);
|
|
|
|
|
2020-04-09 08:15:47 +00:00
|
|
|
void checkStickerLarge();
|
|
|
|
void checkStickerSmall();
|
|
|
|
[[nodiscard]] Image *getStickerSmall();
|
|
|
|
[[nodiscard]] Image *getStickerLarge();
|
|
|
|
void checkStickerLarge(not_null<FileLoader*> loader);
|
|
|
|
|
2020-04-09 12:27:53 +00:00
|
|
|
void setBytes(const QByteArray &bytes);
|
|
|
|
[[nodiscard]] QByteArray bytes() const;
|
2020-04-09 14:02:09 +00:00
|
|
|
[[nodiscard]] bool loaded(bool check = false) const;
|
2020-04-10 13:18:51 +00:00
|
|
|
[[nodiscard]] float64 progress() const;
|
2021-11-05 18:32:26 +00:00
|
|
|
[[nodiscard]] bool canBePlayed(HistoryItem *item) const;
|
2020-04-09 12:27:53 +00:00
|
|
|
|
2020-04-10 14:19:43 +00:00
|
|
|
void automaticLoad(Data::FileOrigin origin, const HistoryItem *item);
|
|
|
|
|
2020-05-22 18:01:04 +00:00
|
|
|
void collectLocalData(not_null<DocumentMedia*> local);
|
|
|
|
|
2020-03-27 11:40:50 +00:00
|
|
|
// For DocumentData.
|
|
|
|
static void CheckGoodThumbnail(not_null<DocumentData*> document);
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum class Flag : uchar {
|
|
|
|
GoodThumbnailWanted = 0x01,
|
|
|
|
};
|
|
|
|
inline constexpr bool is_flag_type(Flag) { return true; };
|
|
|
|
using Flags = base::flags<Flag>;
|
|
|
|
|
|
|
|
static void ReadOrGenerateThumbnail(not_null<DocumentData*> document);
|
2020-04-10 13:18:51 +00:00
|
|
|
static void GenerateGoodThumbnail(
|
|
|
|
not_null<DocumentData*> document,
|
|
|
|
QByteArray data);
|
2020-03-27 11:40:50 +00:00
|
|
|
|
2020-04-15 14:06:34 +00:00
|
|
|
[[nodiscard]] bool thumbnailEnoughForSticker() const;
|
|
|
|
|
2020-05-22 18:01: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.
|
2020-03-27 11:40:50 +00:00
|
|
|
const not_null<DocumentData*> _owner;
|
|
|
|
std::unique_ptr<Image> _goodThumbnail;
|
2020-04-08 15:09:29 +00:00
|
|
|
mutable std::unique_ptr<Image> _inlineThumbnail;
|
2021-07-02 10:13:48 +00:00
|
|
|
mutable QPainterPath _pathThumbnail;
|
2020-04-15 14:06:34 +00:00
|
|
|
std::unique_ptr<Image> _thumbnail;
|
2020-04-09 08:15:47 +00:00
|
|
|
std::unique_ptr<Image> _sticker;
|
2020-04-09 12:27:53 +00:00
|
|
|
QByteArray _bytes;
|
2020-05-22 11:15:09 +00:00
|
|
|
QByteArray _videoThumbnailBytes;
|
2020-03-27 11:40:50 +00:00
|
|
|
Flags _flags;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Data
|