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