2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Use both thumbnails in photos and documents.

Fixes #5602.
This commit is contained in:
John Preston
2019-01-25 18:37:28 +04:00
parent a70e72f75d
commit a1baa23a52
56 changed files with 1358 additions and 878 deletions

View File

@@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#pragma once
#include "data/data_types.h"
#include "ui/image/image.h"
namespace Images {
class Source;
@@ -19,6 +20,10 @@ struct Key;
} // namespace Cache
} // namespace Storage
namespace Data {
class Session;
} // namespace Data
class AuthSession;
class mtpFileLoader;
@@ -75,9 +80,10 @@ class Document;
class DocumentData {
public:
DocumentData(DocumentId id, not_null<AuthSession*> session);
DocumentData(not_null<Data::Session*> owner, DocumentId id);
not_null<AuthSession*> session() const;
[[nodiscard]] Data::Session &owner() const;
[[nodiscard]] AuthSession &session() const;
void setattributes(
const QVector<MTPDocumentAttribute> &attributes);
@@ -93,11 +99,11 @@ public:
FilePathResolveSaveFromData,
FilePathResolveSaveFromDataSilent,
};
bool loaded(
[[nodiscard]] bool loaded(
FilePathResolveType type = FilePathResolveCached) const;
bool loading() const;
QString loadingFilePath() const;
bool displayLoading() const;
[[nodiscard]] bool loading() const;
[[nodiscard]] QString loadingFilePath() const;
[[nodiscard]] bool displayLoading() const;
void save(
Data::FileOrigin origin,
const QString &toFile,
@@ -106,19 +112,19 @@ public:
LoadFromCloudSetting fromCloud = LoadFromCloudOrLocal,
bool autoLoading = false);
void cancel();
bool cancelled() const;
float64 progress() const;
int32 loadOffset() const;
bool uploading() const;
[[nodiscard]] bool cancelled() const;
[[nodiscard]] float64 progress() const;
[[nodiscard]] int32 loadOffset() const;
[[nodiscard]] bool uploading() const;
void setWaitingForAlbum();
bool waitingForAlbum() const;
[[nodiscard]] bool waitingForAlbum() const;
QByteArray data() const;
const FileLocation &location(bool check = false) const;
[[nodiscard]] QByteArray data() const;
[[nodiscard]] const FileLocation &location(bool check = false) const;
void setLocation(const FileLocation &loc);
QString filepath(
[[nodiscard]] QString filepath(
FilePathResolveType type = FilePathResolveCached,
bool forceSavingAs = false) const;
@@ -127,44 +133,50 @@ public:
void performActionOnLoad();
void unload();
Image *getReplyPreview(Data::FileOrigin origin);
[[nodiscard]] Image *getReplyPreview(Data::FileOrigin origin);
StickerData *sticker() const;
void checkSticker();
void checkStickerThumb();
Image *getStickerThumb();
Image *getStickerImage();
Data::FileOrigin stickerSetOrigin() const;
Data::FileOrigin stickerOrGifOrigin() const;
bool isStickerSetInstalled() const;
SongData *song();
const SongData *song() const;
VoiceData *voice();
const VoiceData *voice() const;
[[nodiscard]] StickerData *sticker() const;
void checkStickerLarge();
void checkStickerSmall();
[[nodiscard]] Image *getStickerSmall();
[[nodiscard]] Image *getStickerLarge();
[[nodiscard]] Data::FileOrigin stickerSetOrigin() const;
[[nodiscard]] Data::FileOrigin stickerOrGifOrigin() const;
[[nodiscard]] bool isStickerSetInstalled() const;
[[nodiscard]] SongData *song();
[[nodiscard]] const SongData *song() const;
[[nodiscard]] VoiceData *voice();
[[nodiscard]] const VoiceData *voice() const;
bool isVoiceMessage() const;
bool isVideoMessage() const;
bool isSong() const;
bool isAudioFile() const;
bool isVideoFile() const;
bool isAnimation() const;
bool isGifv() const;
bool isTheme() const;
bool isSharedMediaMusic() const;
int32 duration() const;
bool isImage() const;
[[nodiscard]] bool isVoiceMessage() const;
[[nodiscard]] bool isVideoMessage() const;
[[nodiscard]] bool isSong() const;
[[nodiscard]] bool isAudioFile() const;
[[nodiscard]] bool isVideoFile() const;
[[nodiscard]] bool isAnimation() const;
[[nodiscard]] bool isGifv() const;
[[nodiscard]] bool isTheme() const;
[[nodiscard]] bool isSharedMediaMusic() const;
[[nodiscard]] int32 duration() const;
[[nodiscard]] bool isImage() const;
void recountIsImage();
bool supportsStreaming() const;
[[nodiscard]] bool supportsStreaming() const;
void setData(const QByteArray &data) {
_data = data;
}
bool checkWallPaperProperties();
bool isWallPaper() const;
[[nodiscard]] bool isWallPaper() const;
bool hasGoodStickerThumb() const;
[[nodiscard]] bool hasThumbnail() const;
void loadThumbnail(Data::FileOrigin origin);
[[nodiscard]] Image *thumbnailInline() const;
[[nodiscard]] Image *thumbnail() const;
void updateThumbnails(
ImagePtr thumbnailInline,
ImagePtr thumbnail);
Image *goodThumbnail() const;
Storage::Cache::Key goodThumbnailCacheKey() const;
[[nodiscard]] Image *goodThumbnail() const;
[[nodiscard]] Storage::Cache::Key goodThumbnailCacheKey() const;
void setGoodThumbnail(QImage &&image, QByteArray &&bytes);
void refreshGoodThumbnail();
void replaceGoodThumbnail(std::unique_ptr<Images::Source> &&source);
@@ -175,11 +187,11 @@ public:
const QByteArray &fileReference);
void setContentUrl(const QString &url);
void setWebLocation(const WebFileLocation &location);
bool hasRemoteLocation() const;
bool hasWebLocation() const;
bool isValid() const;
MTPInputDocument mtpInput() const;
QByteArray fileReference() const;
[[nodiscard]] bool hasRemoteLocation() const;
[[nodiscard]] bool hasWebLocation() const;
[[nodiscard]] bool isNull() const;
[[nodiscard]] MTPInputDocument mtpInput() const;
[[nodiscard]] QByteArray fileReference() const;
void refreshFileReference(const QByteArray &value);
void refreshStickerThumbFileReference();
@@ -187,22 +199,22 @@ public:
// (for example for displaying an external inline bot result)
// and it has downloaded data, we can collect that data from it
// to (this) received from the server "same" document.
void collectLocalData(DocumentData *local);
void collectLocalData(not_null<DocumentData*> local);
QString filename() const;
QString mimeString() const;
bool hasMimeType(QLatin1String mime) const;
[[nodiscard]] QString filename() const;
[[nodiscard]] QString mimeString() const;
[[nodiscard]] bool hasMimeType(QLatin1String mime) const;
void setMimeString(const QString &mime);
MediaKey mediaKey() const;
Storage::Cache::Key cacheKey() const;
uint8 cacheTag() const;
[[nodiscard]] MediaKey mediaKey() const;
[[nodiscard]] Storage::Cache::Key cacheKey() const;
[[nodiscard]] uint8 cacheTag() const;
static QString ComposeNameString(
[[nodiscard]] static QString ComposeNameString(
const QString &filename,
const QString &songTitle,
const QString &songPerformer);
QString composeNameString() const;
[[nodiscard]] QString composeNameString() const;
~DocumentData();
@@ -210,7 +222,6 @@ public:
DocumentType type = FileDocument;
QSize dimensions;
int32 date = 0;
ImagePtr thumb;
int32 size = 0;
FileStatus status = FileReady;
@@ -225,6 +236,8 @@ private:
void destroyLoader(mtpFileLoader *newValue = nullptr) const;
[[nodiscard]] bool thumbnailEnoughForSticker() const;
// Two types of location: from MTProto by dc+access or from web by url
int32 _dc = 0;
uint64 _access = 0;
@@ -234,10 +247,12 @@ private:
QString _mimeString;
WebFileLocation _urlLocation;
ImagePtr _thumbnailInline;
ImagePtr _thumbnail;
std::unique_ptr<Image> _goodThumbnail;
std::unique_ptr<Image> _replyPreview;
Data::ReplyPreview _replyPreview;
not_null<AuthSession*> _session;
not_null<Data::Session*> _owner;
FileLocation _location;
QByteArray _data;