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

Move PreparedFile/PreparedList to td_ui.

This commit is contained in:
John Preston
2020-10-13 15:07:53 +03:00
parent 39cf51c066
commit b3b11bd9e7
25 changed files with 358 additions and 302 deletions

View File

@@ -489,7 +489,7 @@ FileLoadTask::FileLoadTask(
not_null<Main::Session*> session,
const QString &filepath,
const QByteArray &content,
std::unique_ptr<FileMediaInformation> information,
std::unique_ptr<Ui::PreparedFileInformation> information,
SendMediaType type,
const FileLoadTo &to,
const TextWithTags &caption,
@@ -528,11 +528,13 @@ FileLoadTask::FileLoadTask(
, _caption(caption) {
}
std::unique_ptr<FileMediaInformation> FileLoadTask::ReadMediaInformation(
FileLoadTask::~FileLoadTask() = default;
std::unique_ptr<Ui::PreparedFileInformation> FileLoadTask::ReadMediaInformation(
const QString &filepath,
const QByteArray &content,
const QString &filemime) {
auto result = std::make_unique<FileMediaInformation>();
auto result = std::make_unique<Ui::PreparedFileInformation>();
result->filemime = filemime;
if (CheckForSong(filepath, content, result)) {
@@ -565,7 +567,7 @@ bool FileLoadTask::CheckMimeOrExtensions(
bool FileLoadTask::CheckForSong(
const QString &filepath,
const QByteArray &content,
std::unique_ptr<FileMediaInformation> &result) {
std::unique_ptr<Ui::PreparedFileInformation> &result) {
static const auto mimes = {
qstr("audio/mp3"),
qstr("audio/m4a"),
@@ -606,7 +608,7 @@ bool FileLoadTask::CheckForSong(
bool FileLoadTask::CheckForVideo(
const QString &filepath,
const QByteArray &content,
std::unique_ptr<FileMediaInformation> &result) {
std::unique_ptr<Ui::PreparedFileInformation> &result) {
static const auto mimes = {
qstr("video/mp4"),
qstr("video/quicktime"),
@@ -640,7 +642,7 @@ bool FileLoadTask::CheckForVideo(
bool FileLoadTask::CheckForImage(
const QString &filepath,
const QByteArray &content,
std::unique_ptr<FileMediaInformation> &result) {
std::unique_ptr<Ui::PreparedFileInformation> &result) {
auto animated = false;
auto image = [&] {
if (filepath.endsWith(qstr(".tgs"), Qt::CaseInsensitive)) {
@@ -665,13 +667,13 @@ bool FileLoadTask::CheckForImage(
bool FileLoadTask::FillImageInformation(
QImage &&image,
bool animated,
std::unique_ptr<FileMediaInformation> &result) {
std::unique_ptr<Ui::PreparedFileInformation> &result) {
Expects(result != nullptr);
if (image.isNull()) {
return false;
}
auto media = FileMediaInformation::Image();
auto media = Ui::PreparedFileInformation::Image();
media.data = std::move(image);
media.animated = animated;
result->media = media;
@@ -717,7 +719,7 @@ void FileLoadTask::process() {
_information = readMediaInformation(Core::MimeTypeForFile(info).name());
}
filemime = _information->filemime;
if (auto image = std::get_if<FileMediaInformation::Image>(
if (auto image = std::get_if<Ui::PreparedFileInformation::Image>(
&_information->media)) {
fullimage = base::take(image->data);
if (!Core::IsMimeSticker(filemime)) {
@@ -732,7 +734,7 @@ void FileLoadTask::process() {
filemime = "audio/ogg";
} else {
if (_information) {
if (auto image = std::get_if<FileMediaInformation::Image>(
if (auto image = std::get_if<Ui::PreparedFileInformation::Image>(
&_information->media)) {
fullimage = base::take(image->data);
}
@@ -757,7 +759,7 @@ void FileLoadTask::process() {
}
} else {
if (_information) {
if (auto image = std::get_if<FileMediaInformation::Image>(
if (auto image = std::get_if<Ui::PreparedFileInformation::Image>(
&_information->media)) {
fullimage = base::take(image->data);
}
@@ -807,13 +809,13 @@ void FileLoadTask::process() {
_information = readMediaInformation(filemime);
filemime = _information->filemime;
}
if (auto song = std::get_if<FileMediaInformation::Song>(
if (auto song = std::get_if<Ui::PreparedFileInformation::Song>(
&_information->media)) {
isSong = true;
auto flags = MTPDdocumentAttributeAudio::Flag::f_title | MTPDdocumentAttributeAudio::Flag::f_performer;
attributes.push_back(MTP_documentAttributeAudio(MTP_flags(flags), MTP_int(song->duration), MTP_string(song->title), MTP_string(song->performer), MTPstring()));
thumbnail = PrepareFileThumbnail(std::move(song->cover));
} else if (auto video = std::get_if<FileMediaInformation::Video>(
} else if (auto video = std::get_if<Ui::PreparedFileInformation::Video>(
&_information->media)) {
isVideo = true;
auto coverWidth = video->thumbnail.width();
@@ -996,6 +998,11 @@ FileLoadResult *FileLoadTask::peekResult() const {
return _result.get();
}
std::unique_ptr<Ui::PreparedFileInformation> FileLoadTask::readMediaInformation(
const QString &filemime) const {
return ReadMediaInformation(_filepath, _content, filemime);
}
void FileLoadTask::removeFromAlbum() {
if (!_album) {
return;