tdesktop/Telegram/SourceFiles/ui/chat/attach/attach_prepare.h

145 lines
3.3 KiB
C
Raw Normal View History

/*
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
2021-02-08 03:13:40 +00:00
#include "editor/photo_editor_common.h"
2020-10-16 07:52:55 +00:00
#include <QtCore/QSemaphore>
2020-10-15 14:27:16 +00:00
#include <deque>
namespace Ui {
class RpWidget;
2020-10-17 09:51:55 +00:00
class SendFilesWay;
struct PreparedFileInformation {
struct Image {
QImage data;
QByteArray bytes;
QByteArray format;
bool animated = false;
2021-02-08 03:13:40 +00:00
Editor::PhotoModifications modifications;
};
struct Song {
int duration = -1;
QString title;
QString performer;
QImage cover;
};
struct Video {
bool isGifv = false;
bool isWebmSticker = false;
bool supportsStreaming = false;
int duration = -1;
QImage thumbnail;
};
QString filemime;
std::variant<v::null_t, Image, Song, Video> media;
};
enum class AlbumType {
None,
PhotoVideo,
Music,
File,
};
struct PreparedFile {
2020-10-16 07:52:55 +00:00
// File-s can be grouped if 'groupFiles'.
// File-s + Photo-s can be grouped if 'groupFiles && !sendImagesAsPhotos'.
2020-10-17 09:51:55 +00:00
// Photo-s can be grouped if 'groupFiles'.
// Photo-s + Video-s can be grouped if 'groupFiles && sendImagesAsPhotos'.
// Video-s can be grouped if 'groupFiles'.
// Music-s can be grouped if 'groupFiles'.
enum class Type {
None,
Photo,
Video,
Music,
File,
};
PreparedFile(const QString &path);
PreparedFile(PreparedFile &&other);
PreparedFile &operator=(PreparedFile &&other);
~PreparedFile();
[[nodiscard]] bool canBeInAlbumType(AlbumType album) const;
[[nodiscard]] AlbumType albumType(bool sendImagesAsPhotos) const;
QString path;
QByteArray content;
2022-05-10 14:22:28 +00:00
int64 size = 0;
std::unique_ptr<Ui::PreparedFileInformation> information;
QImage preview;
QSize shownDimensions;
Type type = Type::File;
};
[[nodiscard]] bool CanBeInAlbumType(PreparedFile::Type type, AlbumType album);
struct PreparedList {
enum class Error {
None,
NonLocalUrl,
Directory,
EmptyFile,
TooLargeFile,
};
PreparedList() = default;
PreparedList(Error error, QString errorData)
: error(error)
, errorData(errorData) {
}
2020-10-17 09:51:55 +00:00
PreparedList(PreparedList &&other) = default;
PreparedList &operator=(PreparedList &&other) = default;
[[nodiscard]] static PreparedList Reordered(
PreparedList &&list,
std::vector<int> order);
void mergeToEnd(PreparedList &&other, bool cutToAlbumSize = false);
2020-10-17 09:51:55 +00:00
[[nodiscard]] bool canAddCaption(bool sendingAlbum) const;
2020-10-16 07:52:55 +00:00
[[nodiscard]] bool canBeSentInSlowmode() const;
[[nodiscard]] bool canBeSentInSlowmodeWith(
const PreparedList &other) const;
2020-10-19 15:37:59 +00:00
[[nodiscard]] bool hasGroupOption(bool slowmode) const;
[[nodiscard]] bool hasSendImagesAsPhotosOption(bool slowmode) const;
Error error = Error::None;
QString errorData;
std::vector<PreparedFile> files;
2020-10-15 14:27:16 +00:00
std::deque<PreparedFile> filesToProcess;
std::optional<bool> overrideSendImagesAsPhotos;
};
2020-10-17 09:51:55 +00:00
struct PreparedGroup {
PreparedList list;
AlbumType type = AlbumType::None;
[[nodiscard]] bool sentWithCaption() const {
return (list.files.size() == 1)
|| (type == AlbumType::PhotoVideo);
}
2020-10-17 09:51:55 +00:00
};
[[nodiscard]] std::vector<PreparedGroup> DivideByGroups(
PreparedList &&list,
SendFilesWay way,
bool slowmode);
[[nodiscard]] int MaxAlbumItems();
2020-10-13 17:15:52 +00:00
[[nodiscard]] bool ValidateThumbDimensions(int width, int height);
[[nodiscard]] QPixmap PrepareSongCoverForThumbnail(QImage image, int size);
} // namespace Ui