From 25177d9022c70038da6726e51cae3f5d05669fcc Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 26 Mar 2019 23:24:31 +0300 Subject: [PATCH] Added updating of thumbnails when user edits media. --- .../SourceFiles/boxes/edit_caption_box.cpp | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index 02c55f155..f2645f15d 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -38,6 +38,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwidget.h" #include "core/file_utilities.h" +#include "core/mime_type.h" EditCaptionBox::EditCaptionBox( QWidget*, @@ -325,6 +326,76 @@ void EditCaptionBox::prepare() { const auto filePath = result.paths.front(); LOG(("FILE PATH: %1").arg(filePath)); _newMediaPath = filePath; + const auto preparedFile = Storage::PrepareMediaList( + QStringList(_newMediaPath), + st::sendMediaPreviewSize); + + const auto file = &preparedFile.files.front(); + const auto fileMedia = &file->information->media; + + const auto fileinfo = QFileInfo(_newMediaPath); + const auto filename = fileinfo.fileName(); + _isImage = fileIsImage(filename, Core::MimeTypeForFile(fileinfo).name()); + _isAudio = false; + + _animated = false; + _photo = false; + _doc = false; + + if (const auto image = base::get_if( + fileMedia) + && _isImage) { + _photo = true; + } else if (const auto video = base::get_if( + fileMedia)) { + _animated = true; + } else if (const auto song = base::get_if( + fileMedia)) { + const auto nameString = DocumentData::ComposeNameString( + filename, + song->title, + song->performer); + + _name.setText( + st::semiboldTextStyle, + nameString, + Ui::NameTextOptions()); + _status = formatSizeText(fileinfo.size()); + _statusw = std::max( + _name.maxWidth(), + st::normalFont->width(_status)); + + _doc = true; + _isAudio = true; + } else { + _name.setText( + st::semiboldTextStyle, + filename, + Ui::NameTextOptions()); + _status = formatSizeText(fileinfo.size()); + _statusw = std::max( + _name.maxWidth(), + st::normalFont->width(_status)); + + _doc = true; + } + + _thumbw = 0; + _thumbh = 0; + _thumbx = 0; + + if (!_doc) { + _thumb = App::pixmapFromImageInPlace( + file->preview.scaled(st::sendMediaPreviewSize, + st::confirmMaxHeight, + Qt::KeepAspectRatio)); + _thumbw = _thumb.width(); + _thumbh = _thumb.height(); + _thumbx = (st::boxWideWidth - _thumbw) / 2; + } + + captionResized(); + } };