Check loaded status through DocumentMedia if possible.

This commit is contained in:
John Preston 2020-04-09 18:02:09 +04:00
parent 669b79588e
commit bf616036b3
25 changed files with 112 additions and 110 deletions

View File

@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_session.h" #include "data/data_session.h"
#include "data/data_user.h" #include "data/data_user.h"
#include "data/data_document.h" #include "data/data_document.h"
#include "data/data_document_media.h"
#include "base/unixtime.h" #include "base/unixtime.h"
#include "boxes/confirm_box.h" #include "boxes/confirm_box.h"
#include "boxes/background_preview_box.h" #include "boxes/background_preview_box.h"
@ -410,6 +411,7 @@ BackgroundPreviewBox::BackgroundPreviewBox(
tr::lng_background_text2(tr::now), tr::lng_background_text2(tr::now),
true)) true))
, _paper(paper) , _paper(paper)
, _media(_paper.document() ? _paper.document()->createMediaView() : nullptr)
, _radial([=](crl::time now) { radialAnimationCallback(now); }) { , _radial([=](crl::time now) { radialAnimationCallback(now); }) {
subscribe(_session->downloaderTaskFinished(), [=] { update(); }); subscribe(_session->downloaderTaskFinished(), [=] { update(); });
} }
@ -710,7 +712,7 @@ void BackgroundPreviewBox::checkLoadedDocument() {
const auto document = _paper.document(); const auto document = _paper.document();
if (!_full.isNull() if (!_full.isNull()
|| !document || !document
|| !document->loaded(DocumentData::FilePathResolve::Checked) || !_media->loaded(true)
|| _generating) { || _generating) {
return; return;
} }

View File

@ -15,6 +15,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/effects/animations.h" #include "ui/effects/animations.h"
#include "ui/effects/radial_animation.h" #include "ui/effects/radial_animation.h"
namespace Data {
class DocumentMedia;
} // namespace Data
namespace Main { namespace Main {
class Session; class Session;
} // namespace Main } // namespace Main
@ -71,6 +75,7 @@ private:
AdminLog::OwnedItem _text1; AdminLog::OwnedItem _text1;
AdminLog::OwnedItem _text2; AdminLog::OwnedItem _text2;
Data::WallPaper _paper; Data::WallPaper _paper;
std::shared_ptr<Data::DocumentMedia> _media;
QImage _full; QImage _full;
QPixmap _scaled, _blurred, _fadeOutThumbnail; QPixmap _scaled, _blurred, _fadeOutThumbnail;
Ui::Animations::Simple _fadeIn; Ui::Animations::Simple _fadeIn;

View File

@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_user.h" #include "data/data_user.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "data/data_file_origin.h" #include "data/data_file_origin.h"
#include "data/data_document_media.h"
#include "history/history.h" #include "history/history.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
@ -157,6 +158,9 @@ EditCaptionBox::EditCaptionBox(
maxW, maxW,
maxH); maxH);
}; };
if (doc) {
_gifMedia = doc->createMediaView();
}
prepareGifPreview(doc); prepareGifPreview(doc);
} else { } else {
maxW = dimensions.width(); maxW = dimensions.width();
@ -248,8 +252,13 @@ EditCaptionBox::EditCaptionBox(
_refreshThumbnail(); _refreshThumbnail();
update(); update();
} }
if (doc && doc->isAnimation() && doc->loaded() && !_gifPreview) { if (doc && doc->isAnimation()) {
prepareGifPreview(doc); if (!_gifMedia) {
_gifMedia = doc->createMediaView();
}
if (_gifMedia->loaded() && !_gifPreview) {
prepareGifPreview(doc);
}
} }
}); });
@ -306,6 +315,8 @@ void EditCaptionBox::updateEmojiPanelGeometry() {
} }
void EditCaptionBox::prepareGifPreview(DocumentData* document) { void EditCaptionBox::prepareGifPreview(DocumentData* document) {
Expects(!document || (_gifMedia != nullptr));
const auto isListEmpty = _preparedList.files.empty(); const auto isListEmpty = _preparedList.files.empty();
if (_gifPreview) { if (_gifPreview) {
return; return;
@ -315,8 +326,7 @@ void EditCaptionBox::prepareGifPreview(DocumentData* document) {
const auto callback = [=](Media::Clip::Notification notification) { const auto callback = [=](Media::Clip::Notification notification) {
clipCallback(notification); clipCallback(notification);
}; };
_gifMedia = document ? document->createMediaView() : nullptr; if (document && document->isAnimation() && _gifMedia->loaded()) {
if (document && document->isAnimation() && document->loaded()) {
_gifPreview = Media::Clip::MakeReader( _gifPreview = Media::Clip::MakeReader(
_gifMedia.get(), _gifMedia.get(),
_msgId, _msgId,

View File

@ -628,7 +628,7 @@ void StickerSetBox::Inner::paintSticker(
if (document->sticker()->animated if (document->sticker()->animated
&& !element.animated && !element.animated
&& document->loaded()) { && media->loaded()) {
const_cast<Inner*>(this)->setupLottie(index); const_cast<Inner*>(this)->setupLottie(index);
} }

View File

@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_session.h" #include "data/data_session.h"
#include "data/data_channel.h" #include "data/data_channel.h"
#include "data/data_file_origin.h" #include "data/data_file_origin.h"
#include "data/data_document_media.h"
#include "core/application.h" #include "core/application.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "mainwidget.h" #include "mainwidget.h"
@ -1913,7 +1914,7 @@ void StickersBox::Inner::readVisibleSets() {
: _rows[i]->sticker->thumbnail(); : _rows[i]->sticker->thumbnail();
if (!thumbnail if (!thumbnail
|| thumbnail->loaded() || thumbnail->loaded()
|| _rows[i]->sticker->loaded()) { || _rows[i]->stickerMedia->loaded()) {
_session->api().readFeaturedSetDelayed(_rows[i]->id); _session->api().readFeaturedSetDelayed(_rows[i]->id);
} }
} }

View File

@ -643,7 +643,7 @@ void FieldAutocompleteInner::paintEvent(QPaintEvent *e) {
if (document->sticker()->animated if (document->sticker()->animated
&& !sticker.animated && !sticker.animated
&& document->loaded()) { && media->loaded()) {
setupLottie(sticker); setupLottie(sticker);
} }

View File

@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_session.h" #include "data/data_session.h"
#include "data/data_user.h" #include "data/data_user.h"
#include "data/data_file_origin.h" #include "data/data_file_origin.h"
#include "data/data_document_media.h"
#include "ui/widgets/buttons.h" #include "ui/widgets/buttons.h"
#include "ui/widgets/input_fields.h" #include "ui/widgets/input_fields.h"
#include "ui/effects/ripple_animation.h" #include "ui/effects/ripple_animation.h"
@ -377,7 +378,8 @@ void GifsListWidget::selectInlineResult(int row, int column) {
photo->thumbnail()->loadEvenCancelled(Data::FileOrigin()); photo->thumbnail()->loadEvenCancelled(Data::FileOrigin());
} }
} else if (const auto document = item->getDocument()) { } else if (const auto document = item->getDocument()) {
if (document->loaded() const auto media = document->activeMediaView();
if ((media && media->loaded())
|| QGuiApplication::keyboardModifiers() == Qt::ControlModifier) { || QGuiApplication::keyboardModifiers() == Qt::ControlModifier) {
_fileChosen.fire_copy(document); _fileChosen.fire_copy(document);
} else if (document->loading()) { } else if (document->loading()) {

View File

@ -987,7 +987,7 @@ void StickersListWidget::readVisibleFeatured(
for (int j = 0; j < count; ++j) { for (int j = 0; j < count; ++j) {
if (!set.stickers[j].document->hasThumbnail() if (!set.stickers[j].document->hasThumbnail()
|| set.stickers[j].document->thumbnail()->loaded() || set.stickers[j].document->thumbnail()->loaded()
|| set.stickers[j].document->loaded()) { || set.stickers[j].documentMedia->loaded()) {
++loaded; ++loaded;
} }
} }
@ -1718,7 +1718,7 @@ void StickersListWidget::paintSticker(Painter &p, Set &set, int y, int section,
if (document->sticker()->animated if (document->sticker()->animated
&& !sticker.animated && !sticker.animated
&& document->loaded()) { && media->loaded()) {
setupLottie(set, section, index); setupLottie(set, section, index);
} }

View File

@ -300,7 +300,7 @@ void Application::showDocument(not_null<DocumentData*> document, HistoryItem *it
if (cUseExternalVideoPlayer() if (cUseExternalVideoPlayer()
&& document->isVideoFile() && document->isVideoFile()
&& document->loaded()) { && !document->filepath().isEmpty()) {
File::Launch(document->location(false).fname); File::Launch(document->location(false).fname);
} else { } else {
_mediaView->showDocument(document, item); _mediaView->showDocument(document, item);

View File

@ -217,15 +217,15 @@ void CloudThemes::loadDocumentAndInvoke(
Data::FileOriginTheme(cloud.id, cloud.accessHash), Data::FileOriginTheme(cloud.id, cloud.accessHash),
QString()); QString());
value.callback = std::move(callback); value.callback = std::move(callback);
if (document->loaded()) { if (value.documentMedia->loaded()) {
invokeForLoaded(value); invokeForLoaded(value);
return; return;
} }
if (!alreadyWaiting) { if (!alreadyWaiting) {
base::ObservableViewer( base::ObservableViewer(
_session->downloaderTaskFinished() _session->downloaderTaskFinished()
) | rpl::filter([=] { ) | rpl::filter([=, &value] {
return document->loaded(); return value.documentMedia->loaded();
}) | rpl::start_with_next([=, &value] { }) | rpl::start_with_next([=, &value] {
invokeForLoaded(value); invokeForLoaded(value);
}, value.subscription); }, value.subscription);

View File

@ -48,8 +48,6 @@ namespace {
constexpr auto kMemoryForCache = 128 * 1024 * 1024; // was 32, updated to 128 constexpr auto kMemoryForCache = 128 * 1024 * 1024; // was 32, updated to 128
const auto kAnimatedStickerDimensions = QSize(512, 512); const auto kAnimatedStickerDimensions = QSize(512, 512);
using FilePathResolve = DocumentData::FilePathResolve;
Core::MediaActiveCache<DocumentData> &ActiveCache() { Core::MediaActiveCache<DocumentData> &ActiveCache() {
static auto Instance = Core::MediaActiveCache<DocumentData>( static auto Instance = Core::MediaActiveCache<DocumentData>(
kMemoryForCache, kMemoryForCache,
@ -323,7 +321,7 @@ void DocumentOpenClickHandler::Open(
LaunchWithWarning(location.name(), context); LaunchWithWarning(location.name(), context);
}; };
const auto &location = data->location(true); const auto &location = data->location(true);
if (data->isTheme() && data->loaded(DocumentData::FilePathResolve::Checked)) { if (data->isTheme() && data->loaded(true)) {
Core::App().showDocument(data, context); Core::App().showDocument(data, context);
location.accessDisable(); location.accessDisable();
} else if (data->canBePlayed()) { } else if (data->canBePlayed()) {
@ -364,7 +362,7 @@ void DocumentSaveClickHandler::Save(
if (mode != Mode::ToNewFile && data->saveFromData()) { if (mode != Mode::ToNewFile && data->saveFromData()) {
return; return;
} }
const auto filepath = data->filepath(FilePathResolve::Checked); const auto filepath = data->filepath(true);
const auto fileinfo = QFileInfo( const auto fileinfo = QFileInfo(
); );
const auto filedir = filepath.isEmpty() const auto filedir = filepath.isEmpty()
@ -416,7 +414,7 @@ void DocumentOpenWithClickHandler::Open(
} }
data->saveFromDataSilent(); data->saveFromDataSilent();
const auto path = data->filepath(FilePathResolve::Checked); const auto path = data->filepath(true);
if (!path.isEmpty()) { if (!path.isEmpty()) {
File::OpenWith(path, QCursor::pos()); File::OpenWith(path, QCursor::pos());
} else { } else {
@ -789,14 +787,14 @@ void DocumentData::automaticLoad(
} }
void DocumentData::automaticLoadSettingsChanged() { void DocumentData::automaticLoadSettingsChanged() {
if (!cancelled() || status != FileReady || loaded()) { if (!cancelled() || status != FileReady) {
return; return;
} }
_loader = nullptr; _loader = nullptr;
_flags &= ~Flag::DownloadCancelled; _flags &= ~Flag::DownloadCancelled;
} }
bool DocumentData::loaded(FilePathResolve resolve) const { bool DocumentData::loaded(bool check) const {
if (loading() && _loader->finished()) { if (loading() && _loader->finished()) {
if (_loader->cancelled()) { if (_loader->cancelled()) {
_flags |= Flag::DownloadCancelled; _flags |= Flag::DownloadCancelled;
@ -822,7 +820,7 @@ bool DocumentData::loaded(FilePathResolve resolve) const {
} }
_owner->notifyDocumentLayoutChanged(this); _owner->notifyDocumentLayoutChanged(this);
} }
return !rawBytes().isEmpty() || !filepath(resolve).isEmpty(); return !rawBytes().isEmpty() || !filepath(check).isEmpty();
} }
void DocumentData::destroyLoader() const { void DocumentData::destroyLoader() const {
@ -881,7 +879,7 @@ void DocumentData::setLoadedInMediaCache(bool loaded) {
return; return;
} }
_flags = flags; _flags = flags;
if (!this->loaded()) { if (filepath().isEmpty()) {
if (loadedInMediaCache()) { if (loadedInMediaCache()) {
Local::writeFileLocation( Local::writeFileLocation(
mediaKey(), mediaKey(),
@ -913,7 +911,7 @@ void DocumentData::save(
const QString &toFile, const QString &toFile,
LoadFromCloudSetting fromCloud, LoadFromCloudSetting fromCloud,
bool autoLoading) { bool autoLoading) {
if (loaded(FilePathResolve::Checked)) { if (loaded(true)) {
auto &l = location(true); auto &l = location(true);
if (!toFile.isEmpty()) { if (!toFile.isEmpty()) {
if (!rawBytes().isEmpty()) { if (!rawBytes().isEmpty()) {
@ -1111,27 +1109,19 @@ void DocumentData::setLocation(const FileLocation &loc) {
} }
} }
QString DocumentData::filepath(FilePathResolve resolve) const { QString DocumentData::filepath(bool check) const {
const auto check = (resolve != FilePathResolve::Cached);
return (check && _location.name().isEmpty()) return (check && _location.name().isEmpty())
? QString() ? QString()
: location(check).name(); : location(check).name();
} }
bool DocumentData::saveFromData() { bool DocumentData::saveFromData() {
if (!filepath(FilePathResolve::Checked).isEmpty()) { return !filepath(true).isEmpty() || saveFromDataChecked();
return true;
}
return saveFromDataChecked();
} }
bool DocumentData::saveFromDataSilent() { bool DocumentData::saveFromDataSilent() {
if (!filepath(FilePathResolve::Checked).isEmpty()) { return !filepath(true).isEmpty()
return true; || (!Global::AskDownloadPath() && saveFromDataChecked());
} else if (Global::AskDownloadPath()) {
return false;
}
return saveFromDataChecked();
} }
bool DocumentData::saveFromDataChecked() { bool DocumentData::saveFromDataChecked() {

View File

@ -100,12 +100,7 @@ public:
const HistoryItem *item); const HistoryItem *item);
void automaticLoadSettingsChanged(); void automaticLoadSettingsChanged();
enum class FilePathResolve { [[nodiscard]] bool loaded(bool check = false) const;
Cached,
Checked,
};
[[nodiscard]] bool loaded(
FilePathResolve resolve = FilePathResolve::Cached) const;
[[nodiscard]] bool loading() const; [[nodiscard]] bool loading() const;
[[nodiscard]] QString loadingFilePath() const; [[nodiscard]] QString loadingFilePath() const;
[[nodiscard]] bool displayLoading() const; [[nodiscard]] bool displayLoading() const;
@ -131,8 +126,7 @@ public:
bool saveFromData(); bool saveFromData();
bool saveFromDataSilent(); bool saveFromDataSilent();
[[nodiscard]] QString filepath( [[nodiscard]] QString filepath(bool check = false) const;
FilePathResolve resolve = FilePathResolve::Cached) const;
[[nodiscard]] bool saveToCache() const; [[nodiscard]] bool saveToCache() const;

View File

@ -137,7 +137,7 @@ void DocumentMedia::checkStickerLarge() {
} }
_owner->automaticLoad(_owner->stickerSetOrigin(), nullptr); _owner->automaticLoad(_owner->stickerSetOrigin(), nullptr);
if (data->animated || !_owner->loaded()) { if (data->animated || !loaded()) {
return; return;
} }
const auto bytes = _owner->rawBytes(); const auto bytes = _owner->rawBytes();
@ -170,6 +170,10 @@ QByteArray DocumentMedia::bytes() const {
return _bytes; return _bytes;
} }
bool DocumentMedia::loaded(bool check) const {
return !_bytes.isEmpty() || _owner->loaded(check);// checkLoadedTo(this);
}
void DocumentMedia::checkStickerSmall() { void DocumentMedia::checkStickerSmall() {
const auto data = _owner->sticker(); const auto data = _owner->sticker();
if ((data && data->animated) || _owner->thumbnailEnoughForSticker()) { if ((data && data->animated) || _owner->thumbnailEnoughForSticker()) {

View File

@ -34,6 +34,7 @@ public:
void setBytes(const QByteArray &bytes); void setBytes(const QByteArray &bytes);
[[nodiscard]] QByteArray bytes() const; [[nodiscard]] QByteArray bytes() const;
[[nodiscard]] bool loaded(bool check = false) const;
// For DocumentData. // For DocumentData.
static void CheckGoodThumbnail(not_null<DocumentData*> document); static void CheckGoodThumbnail(not_null<DocumentData*> document);

View File

@ -1075,7 +1075,7 @@ void InnerWidget::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
}); });
} }
} }
if (!document->filepath(DocumentData::FilePathResolve::Checked).isEmpty()) { if (!document->filepath(true).isEmpty()) {
_menu->addAction(Platform::IsMac() ? tr::lng_context_show_in_finder(tr::now) : tr::lng_context_show_in_folder(tr::now), [=] { _menu->addAction(Platform::IsMac() ? tr::lng_context_show_in_finder(tr::now) : tr::lng_context_show_in_folder(tr::now), [=] {
showContextInFolder(document); showContextInFolder(document);
}); });
@ -1181,8 +1181,7 @@ void InnerWidget::cancelContextDownload(not_null<DocumentData*> document) {
} }
void InnerWidget::showContextInFolder(not_null<DocumentData*> document) { void InnerWidget::showContextInFolder(not_null<DocumentData*> document) {
const auto filepath = document->filepath( const auto filepath = document->filepath(true);
DocumentData::FilePathResolve::Checked);
if (!filepath.isEmpty()) { if (!filepath.isEmpty()) {
File::ShowInFolder(filepath); File::ShowInFolder(filepath);
} }
@ -1691,7 +1690,7 @@ void InnerWidget::performDrag() {
// auto mimeData = std::make_unique<QMimeData>(); // auto mimeData = std::make_unique<QMimeData>();
// mimeData->setData(forwardMimeType, "1"); // mimeData->setData(forwardMimeType, "1");
// if (auto document = (pressedMedia ? pressedMedia->getDocument() : nullptr)) { // if (auto document = (pressedMedia ? pressedMedia->getDocument() : nullptr)) {
// auto filepath = document->filepath(DocumentData::FilePathResolve::Checked); // auto filepath = document->filepath(true);
// if (!filepath.isEmpty()) { // if (!filepath.isEmpty()) {
// QList<QUrl> urls; // QList<QUrl> urls;
// urls.push_back(QUrl::fromLocalFile(filepath)); // urls.push_back(QUrl::fromLocalFile(filepath));

View File

@ -1248,8 +1248,7 @@ std::unique_ptr<QMimeData> HistoryInner::prepareDrag() {
result->setData(qsl("application/x-td-forward"), "1"); result->setData(qsl("application/x-td-forward"), "1");
if (const auto media = view->media()) { if (const auto media = view->media()) {
if (const auto document = media->getDocument()) { if (const auto document = media->getDocument()) {
const auto filepath = document->filepath( const auto filepath = document->filepath(true);
DocumentData::FilePathResolve::Checked);
if (!filepath.isEmpty()) { if (!filepath.isEmpty()) {
QList<QUrl> urls; QList<QUrl> urls;
urls.push_back(QUrl::fromLocalFile(filepath)); urls.push_back(QUrl::fromLocalFile(filepath));
@ -1606,7 +1605,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
saveContextGif(itemId); saveContextGif(itemId);
}); });
} }
if (!document->filepath(DocumentData::FilePathResolve::Checked).isEmpty()) { if (!document->filepath(true).isEmpty()) {
_menu->addAction(Platform::IsMac() ? tr::lng_context_show_in_finder(tr::now) : tr::lng_context_show_in_folder(tr::now), [=] { _menu->addAction(Platform::IsMac() ? tr::lng_context_show_in_finder(tr::now) : tr::lng_context_show_in_folder(tr::now), [=] {
showContextInFolder(document); showContextInFolder(document);
}); });
@ -1886,8 +1885,7 @@ void HistoryInner::cancelContextDownload(not_null<DocumentData*> document) {
} }
void HistoryInner::showContextInFolder(not_null<DocumentData*> document) { void HistoryInner::showContextInFolder(not_null<DocumentData*> document) {
const auto filepath = document->filepath( const auto filepath = document->filepath(true);
DocumentData::FilePathResolve::Checked);
if (!filepath.isEmpty()) { if (!filepath.isEmpty()) {
File::ShowInFolder(filepath); File::ShowInFolder(filepath);
} }

View File

@ -134,8 +134,7 @@ void OpenGif(FullMsgId itemId) {
} }
void ShowInFolder(not_null<DocumentData*> document) { void ShowInFolder(not_null<DocumentData*> document) {
const auto filepath = document->filepath( const auto filepath = document->filepath(true);
DocumentData::FilePathResolve::Checked);
if (!filepath.isEmpty()) { if (!filepath.isEmpty()) {
File::ShowInFolder(filepath); File::ShowInFolder(filepath);
} }
@ -205,8 +204,7 @@ void AddDocumentActions(
: tr::lng_faved_stickers_add(tr::now)), : tr::lng_faved_stickers_add(tr::now)),
[=] { ToggleFavedSticker(document, contextId); }); [=] { ToggleFavedSticker(document, contextId); });
} }
if (!document->filepath( if (!document->filepath(true).isEmpty()) {
DocumentData::FilePathResolve::Checked).isEmpty()) {
menu->addAction( menu->addAction(
(Platform::IsMac() (Platform::IsMac()
? tr::lng_context_show_in_finder(tr::now) ? tr::lng_context_show_in_finder(tr::now)

View File

@ -2375,8 +2375,7 @@ std::unique_ptr<QMimeData> ListWidget::prepareDrag() {
result->setData(qsl("application/x-td-forward"), "1"); result->setData(qsl("application/x-td-forward"), "1");
if (const auto media = pressedView->media()) { if (const auto media = pressedView->media()) {
if (const auto document = media->getDocument()) { if (const auto document = media->getDocument()) {
const auto filepath = document->filepath( const auto filepath = document->filepath(true);
DocumentData::FilePathResolve::Checked);
if (!filepath.isEmpty()) { if (!filepath.isEmpty()) {
QList<QUrl> urls; QList<QUrl> urls;
urls.push_back(QUrl::fromLocalFile(filepath)); urls.push_back(QUrl::fromLocalFile(filepath));

View File

@ -93,7 +93,7 @@ bool Document::dataFinished() const {
} }
bool Document::dataLoaded() const { bool Document::dataLoaded() const {
return _data->loaded(); return _dataMedia ? _dataMedia->loaded() : _data->loaded();
} }
void Document::createComponents(bool caption) { void Document::createComponents(bool caption) {

View File

@ -1270,7 +1270,7 @@ void ListWidget::showContextMenu(
document->cancel(); document->cancel();
}); });
} else { } else {
auto filepath = document->filepath(DocumentData::FilePathResolve::Checked); auto filepath = document->filepath(true);
if (!filepath.isEmpty()) { if (!filepath.isEmpty()) {
auto handler = App::LambdaDelayed( auto handler = App::LambdaDelayed(
st::defaultDropdownMenu.menu.ripple.hideDuration, st::defaultDropdownMenu.menu.ripple.hideDuration,
@ -1979,7 +1979,7 @@ void ListWidget::performDrag() {
// auto mimeData = std::make_unique<QMimeData>(); // auto mimeData = std::make_unique<QMimeData>();
// mimeData->setData(forwardMimeType, "1"); // mimeData->setData(forwardMimeType, "1");
// if (auto document = (pressedMedia ? pressedMedia->getDocument() : nullptr)) { // if (auto document = (pressedMedia ? pressedMedia->getDocument() : nullptr)) {
// auto filepath = document->filepath(DocumentData::FilePathResolve::Checked); // auto filepath = document->filepath(true);
// if (!filepath.isEmpty()) { // if (!filepath.isEmpty()) {
// QList<QUrl> urls; // QList<QUrl> urls;
// urls.push_back(QUrl::fromLocalFile(filepath)); // urls.push_back(QUrl::fromLocalFile(filepath));

View File

@ -535,7 +535,7 @@ void OverlayWidget::documentUpdated(DocumentData *doc) {
update(_docRect); update(_docRect);
} }
} else if (_streamed) { } else if (_streamed) {
const auto ready = _doc->loaded() const auto ready = _docMedia->loaded()
? _doc->size ? _doc->size
: _doc->loading() : _doc->loading()
? std::clamp(_doc->loadOffset(), 0, _doc->size) ? std::clamp(_doc->loadOffset(), 0, _doc->size)
@ -609,7 +609,7 @@ void OverlayWidget::updateControls() {
_docCancel->moveToLeft(_docRect.x() + 2 * st::mediaviewFilePadding + st::mediaviewFileIconSize, _docRect.y() + st::mediaviewFilePadding + st::mediaviewFileLinksTop); _docCancel->moveToLeft(_docRect.x() + 2 * st::mediaviewFilePadding + st::mediaviewFileIconSize, _docRect.y() + st::mediaviewFilePadding + st::mediaviewFileLinksTop);
_docCancel->show(); _docCancel->show();
} else { } else {
if (_doc->loaded(DocumentData::FilePathResolve::Checked)) { if (_docMedia->loaded(true)) {
_docDownload->hide(); _docDownload->hide();
_docSaveAs->moveToLeft(_docRect.x() + 2 * st::mediaviewFilePadding + st::mediaviewFileIconSize, _docRect.y() + st::mediaviewFilePadding + st::mediaviewFileLinksTop); _docSaveAs->moveToLeft(_docRect.x() + 2 * st::mediaviewFilePadding + st::mediaviewFileIconSize, _docRect.y() + st::mediaviewFilePadding + st::mediaviewFileLinksTop);
_docSaveAs->show(); _docSaveAs->show();
@ -634,7 +634,7 @@ void OverlayWidget::updateControls() {
_saveVisible = (_photo && _photo->loaded()) _saveVisible = (_photo && _photo->loaded())
|| (_doc || (_doc
&& _doc->filepath(DocumentData::FilePathResolve::Checked).isEmpty() && _doc->filepath(true).isEmpty()
&& !_doc->loading()); && !_doc->loading());
_saveNav = myrtlrect(width() - st::mediaviewIconSize.width() * 3, height() - st::mediaviewIconSize.height(), st::mediaviewIconSize.width(), st::mediaviewIconSize.height()); _saveNav = myrtlrect(width() - st::mediaviewIconSize.width() * 3, height() - st::mediaviewIconSize.height(), st::mediaviewIconSize.width(), st::mediaviewIconSize.height());
_saveNavIcon = style::centerrect(_saveNav, st::mediaviewSave); _saveNavIcon = style::centerrect(_saveNav, st::mediaviewSave);
@ -739,7 +739,7 @@ void OverlayWidget::updateActions() {
if (IsServerMsgId(_msgid.msg)) { if (IsServerMsgId(_msgid.msg)) {
_actions.push_back({ tr::lng_context_to_msg(tr::now), SLOT(onToMessage()) }); _actions.push_back({ tr::lng_context_to_msg(tr::now), SLOT(onToMessage()) });
} }
if (_doc && !_doc->filepath(DocumentData::FilePathResolve::Checked).isEmpty()) { if (_doc && !_doc->filepath(true).isEmpty()) {
_actions.push_back({ Platform::IsMac() ? tr::lng_context_show_in_finder(tr::now) : tr::lng_context_show_in_folder(tr::now), SLOT(onShowInFolder()) }); _actions.push_back({ Platform::IsMac() ? tr::lng_context_show_in_finder(tr::now) : tr::lng_context_show_in_folder(tr::now), SLOT(onShowInFolder()) });
} }
if ((_doc && documentContentShown()) || (_photo && _photo->loaded())) { if ((_doc && documentContentShown()) || (_photo && _photo->loaded())) {
@ -982,7 +982,7 @@ bool OverlayWidget::radialAnimationCallback(crl::time now) {
&& (!anim::Disabled() || updated)) { && (!anim::Disabled() || updated)) {
update(radialRect()); update(radialRect());
} }
const auto ready = _doc && _doc->loaded(); const auto ready = _doc && _docMedia->loaded();
const auto streamVideo = ready && _doc->canBePlayed(); const auto streamVideo = ready && _doc->canBePlayed();
const auto tryOpenImage = ready && (_doc->size < App::kImageSizeLimit); const auto tryOpenImage = ready && (_doc->size < App::kImageSizeLimit);
if (ready && ((tryOpenImage && !_radial.animating()) || streamVideo)) { if (ready && ((tryOpenImage && !_radial.animating()) || streamVideo)) {
@ -1335,7 +1335,7 @@ void OverlayWidget::onDownload() {
} }
location.accessDisable(); location.accessDisable();
} else { } else {
if (_doc->filepath(DocumentData::FilePathResolve::Checked).isEmpty() if (_doc->filepath(true).isEmpty()
&& !_doc->loading()) { && !_doc->loading()) {
DocumentSaveClickHandler::Save( DocumentSaveClickHandler::Save(
fileOrigin(), fileOrigin(),
@ -1380,7 +1380,7 @@ void OverlayWidget::onSaveCancel() {
void OverlayWidget::onShowInFolder() { void OverlayWidget::onShowInFolder() {
if (!_doc) return; if (!_doc) return;
auto filepath = _doc->filepath(DocumentData::FilePathResolve::Checked); auto filepath = _doc->filepath(true);
if (!filepath.isEmpty()) { if (!filepath.isEmpty()) {
File::ShowInFolder(filepath); File::ShowInFolder(filepath);
close(); close();
@ -2816,7 +2816,7 @@ void OverlayWidget::paintEvent(QPaintEvent *e) {
const auto radialOpacity = radial ? _radial.opacity() : 0.; const auto radialOpacity = radial ? _radial.opacity() : 0.;
if (!_doc || !_doc->hasThumbnail()) { if (!_doc || !_doc->hasThumbnail()) {
p.fillRect(_docIconRect, _docIconColor); p.fillRect(_docIconRect, _docIconColor);
if ((!_doc || _doc->loaded()) && (!radial || radialOpacity < 1) && _docIcon) { if ((!_doc || _docMedia->loaded()) && (!radial || radialOpacity < 1) && _docIcon) {
_docIcon->paint(p, _docIconRect.x() + (_docIconRect.width() - _docIcon->width()), _docIconRect.y(), width()); _docIcon->paint(p, _docIconRect.x() + (_docIconRect.width() - _docIcon->width()), _docIconRect.y(), width());
p.setPen(st::mediaviewFileExtFg); p.setPen(st::mediaviewFileExtFg);
p.setFont(st::mediaviewFileExtFont); p.setFont(st::mediaviewFileExtFont);
@ -3058,7 +3058,7 @@ void OverlayWidget::paintRadialLoading(
if (!_streamed->instance.waitingShown()) { if (!_streamed->instance.waitingShown()) {
return; return;
} }
} else if (!radial && (!_doc || _doc->loaded())) { } else if (!radial && (!_doc || _docMedia->loaded())) {
return; return;
} }
@ -3125,7 +3125,7 @@ void OverlayWidget::paintRadialLoadingContent(
} else { } else {
const auto o = overLevel(OverIcon); const auto o = overLevel(OverIcon);
paintBg( paintBg(
_doc->loaded() ? radialOpacity : 1., _docMedia->loaded() ? radialOpacity : 1.,
anim::brush(st::msgDateImgBg, st::msgDateImgBgOver, o)); anim::brush(st::msgDateImgBg, st::msgDateImgBgOver, o));
const auto icon = [&]() -> const style::icon * { const auto icon = [&]() -> const style::icon * {
@ -3237,7 +3237,7 @@ void OverlayWidget::keyPressEvent(QKeyEvent *e) {
} else if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return || e->key() == Qt::Key_Space) { } else if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return || e->key() == Qt::Key_Space) {
if (_streamed) { if (_streamed) {
playbackPauseResume(); playbackPauseResume();
} else if (_doc && !_doc->loading() && (documentBubbleShown() || !_doc->loaded())) { } else if (_doc && !_doc->loading() && (documentBubbleShown() || !_docMedia->loaded())) {
onDocClick(); onDocClick();
} }
} else if (e->key() == Qt::Key_Left) { } else if (e->key() == Qt::Key_Left) {
@ -3698,7 +3698,7 @@ void OverlayWidget::updateOver(QPoint pos) {
} else if (documentContentShown() && contentRect().contains(pos)) { } else if (documentContentShown() && contentRect().contains(pos)) {
if ((_doc->isVideoFile() || _doc->isVideoMessage()) && _streamed) { if ((_doc->isVideoFile() || _doc->isVideoMessage()) && _streamed) {
updateOverState(OverVideo); updateOverState(OverVideo);
} else if (!_streamed && !_doc->loaded()) { } else if (!_streamed && !_docMedia->loaded()) {
updateOverState(OverIcon); updateOverState(OverIcon);
} else if (_over != OverNone) { } else if (_over != OverNone) {
updateOverState(OverNone); updateOverState(OverNone);

View File

@ -443,7 +443,7 @@ void Video::paint(Painter &p, const QRect &clip, TextSelection selection, const
const auto goodLoaded = _dataMedia->goodThumbnail() const auto goodLoaded = _dataMedia->goodThumbnail()
&& _dataMedia->goodThumbnail()->loaded(); && _dataMedia->goodThumbnail()->loaded();
bool loaded = _data->loaded(), displayLoading = _data->displayLoading(); bool loaded = dataLoaded(), displayLoading = _data->displayLoading();
if (displayLoading) { if (displayLoading) {
ensureRadial(); ensureRadial();
if (!_radial->animating()) { if (!_radial->animating()) {
@ -560,7 +560,7 @@ bool Video::dataFinished() const {
} }
bool Video::dataLoaded() const { bool Video::dataLoaded() const {
return _data->loaded(); return _dataMedia ? _dataMedia->loaded() : !_data->filepath().isEmpty();
} }
bool Video::iconAnimated() const { bool Video::iconAnimated() const {
@ -573,7 +573,7 @@ TextState Video::getState(
if (hasPoint(point)) { if (hasPoint(point)) {
const auto link = (_data->loading() || _data->uploading()) const auto link = (_data->loading() || _data->uploading())
? _cancell ? _cancell
: (_data->loaded() || _data->canBePlayed()) : (dataLoaded() || _data->canBePlayed())
? _openl ? _openl
: _savel; : _savel;
return { parent(), link }; return { parent(), link };
@ -588,7 +588,7 @@ void Video::updateStatusText() {
statusSize = FileStatusSizeFailed; statusSize = FileStatusSizeFailed;
} else if (_data->uploading()) { } else if (_data->uploading()) {
statusSize = _data->uploadingData->offset; statusSize = _data->uploadingData->offset;
} else if (_data->loaded()) { } else if (dataLoaded()) {
statusSize = FileStatusSizeLoaded; statusSize = FileStatusSizeLoaded;
} else { } else {
statusSize = FileStatusSizeReady; statusSize = FileStatusSizeReady;
@ -642,7 +642,7 @@ void Voice::initDimensions() {
void Voice::paint(Painter &p, const QRect &clip, TextSelection selection, const PaintContext *context) { void Voice::paint(Painter &p, const QRect &clip, TextSelection selection, const PaintContext *context) {
bool selected = (selection == FullSelection); bool selected = (selection == FullSelection);
bool loaded = _data->loaded(), displayLoading = _data->displayLoading(); bool loaded = dataLoaded(), displayLoading = _data->displayLoading();
if (displayLoading) { if (displayLoading) {
ensureRadial(); ensureRadial();
@ -776,7 +776,7 @@ void Voice::paint(Painter &p, const QRect &clip, TextSelection selection, const
TextState Voice::getState( TextState Voice::getState(
QPoint point, QPoint point,
StateRequest request) const { StateRequest request) const {
const auto loaded = _data->loaded(); const auto loaded = dataLoaded();
const auto nameleft = _st.songPadding.left() const auto nameleft = _st.songPadding.left()
+ _st.songThumbSize + _st.songThumbSize
@ -847,7 +847,7 @@ bool Voice::dataFinished() const {
} }
bool Voice::dataLoaded() const { bool Voice::dataLoaded() const {
return _data->loaded(); return _dataMedia ? _dataMedia->loaded() : !_data->filepath().isEmpty();
} }
bool Voice::iconAnimated() const { bool Voice::iconAnimated() const {
@ -882,7 +882,7 @@ bool Voice::updateStatusText() {
int32 statusSize = 0, realDuration = 0; int32 statusSize = 0, realDuration = 0;
if (_data->status == FileDownloadFailed || _data->status == FileUploadFailed) { if (_data->status == FileDownloadFailed || _data->status == FileUploadFailed) {
statusSize = FileStatusSizeFailed; statusSize = FileStatusSizeFailed;
} else if (_data->loaded()) { } else if (dataLoaded()) {
statusSize = FileStatusSizeLoaded; statusSize = FileStatusSizeLoaded;
} else { } else {
statusSize = FileStatusSizeReady; statusSize = FileStatusSizeReady;
@ -964,7 +964,7 @@ void Document::paint(Painter &p, const QRect &clip, TextSelection selection, con
const auto cornerDownload = downloadInCorner(); const auto cornerDownload = downloadInCorner();
_data->automaticLoad(parent()->fullId(), parent()); _data->automaticLoad(parent()->fullId(), parent());
const auto loaded = _data->loaded(); const auto loaded = dataLoaded();
const auto displayLoading = _data->displayLoading(); const auto displayLoading = _data->displayLoading();
if (displayLoading) { if (displayLoading) {
@ -1131,7 +1131,7 @@ void Document::paint(Painter &p, const QRect &clip, TextSelection selection, con
} }
void Document::drawCornerDownload(Painter &p, bool selected, const PaintContext *context) const { void Document::drawCornerDownload(Painter &p, bool selected, const PaintContext *context) const {
if (_data->loaded() if (dataLoaded()
|| _data->loadedInMediaCache() || _data->loadedInMediaCache()
|| !downloadInCorner()) { || !downloadInCorner()) {
return; return;
@ -1170,7 +1170,7 @@ TextState Document::cornerDownloadTextState(
StateRequest request) const { StateRequest request) const {
auto result = TextState(parent()); auto result = TextState(parent());
if (!downloadInCorner() if (!downloadInCorner()
|| _data->loaded() || dataLoaded()
|| _data->loadedInMediaCache()) { || _data->loadedInMediaCache()) {
return result; return result;
} }
@ -1187,7 +1187,7 @@ TextState Document::cornerDownloadTextState(
TextState Document::getState( TextState Document::getState(
QPoint point, QPoint point,
StateRequest request) const { StateRequest request) const {
const auto loaded = _data->loaded(); const auto loaded = dataLoaded();
const auto wthumb = withThumb(); const auto wthumb = withThumb();
if (_data->isSong()) { if (_data->isSong()) {
@ -1308,12 +1308,12 @@ bool Document::dataFinished() const {
} }
bool Document::dataLoaded() const { bool Document::dataLoaded() const {
return _data->loaded(); return _dataMedia ? _dataMedia->loaded() : !_data->filepath().isEmpty();
} }
bool Document::iconAnimated() const { bool Document::iconAnimated() const {
return _data->isSong() return _data->isSong()
|| !_data->loaded() || !dataLoaded()
|| (_radial && _radial->animating()); || (_radial && _radial->animating());
} }
@ -1328,13 +1328,14 @@ bool Document::withThumb() const {
bool Document::updateStatusText() { bool Document::updateStatusText() {
bool showPause = false; bool showPause = false;
int32 statusSize = 0, realDuration = 0; int32 statusSize = 0, realDuration = 0;
if (_data->status == FileDownloadFailed || _data->status == FileUploadFailed) { if (_data->status == FileDownloadFailed
|| _data->status == FileUploadFailed) {
statusSize = FileStatusSizeFailed; statusSize = FileStatusSizeFailed;
} else if (_data->uploading()) { } else if (_data->uploading()) {
statusSize = _data->uploadingData->offset; statusSize = _data->uploadingData->offset;
} else if (_data->loading()) { } else if (_data->loading()) {
statusSize = _data->loadOffset(); statusSize = _data->loadOffset();
} else if (_data->loaded()) { } else if (dataLoaded()) {
statusSize = FileStatusSizeLoaded; statusSize = FileStatusSizeLoaded;
} else { } else {
statusSize = FileStatusSizeReady; statusSize = FileStatusSizeReady;

View File

@ -565,8 +565,8 @@ void CloudList::refreshColors(Element &element) {
document->save( document->save(
Data::FileOriginTheme(theme.id, theme.accessHash), Data::FileOriginTheme(theme.id, theme.accessHash),
QString()); QString());
if (document->loaded()) { if (element.media->loaded()) {
refreshColorsFromDocument(element, document); refreshColorsFromDocument(element);
} else { } else {
setWaiting(element, true); setWaiting(element, true);
subscribeToDownloadFinished(); subscribeToDownloadFinished();
@ -636,14 +636,13 @@ bool CloudList::amCreator(const Data::CloudTheme &theme) const {
return (_window->session().userId() == theme.createdBy); return (_window->session().userId() == theme.createdBy);
} }
void CloudList::refreshColorsFromDocument( void CloudList::refreshColorsFromDocument(Element &element) {
Element &element, Expects(element.media != nullptr);
not_null<DocumentData*> document) { Expects(element.media->loaded());
const auto id = element.id(); const auto id = element.id();
const auto path = document->filepath(); const auto path = element.media->owner()->filepath();
const auto data = element.media const auto data = base::take(element.media)->bytes();
? base::take(element.media)->bytes()
: QByteArray();
crl::async([=, guard = element.generating.make_guard()]() mutable { crl::async([=, guard = element.generating.make_guard()]() mutable {
crl::on_main(std::move(guard), [ crl::on_main(std::move(guard), [
=, =,
@ -672,12 +671,13 @@ void CloudList::subscribeToDownloadFinished() {
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
auto &&waiting = _elements | ranges::view::filter(&Element::waiting); auto &&waiting = _elements | ranges::view::filter(&Element::waiting);
const auto still = ranges::count_if(waiting, [&](Element &element) { const auto still = ranges::count_if(waiting, [&](Element &element) {
const auto id = element.theme.documentId; if (!element.media) {
const auto document = _window->session().data().document(id); element.waiting = false;
if (!document->loaded()) { return false;
} else if (!element.media->loaded()) {
return true; return true;
} }
refreshColorsFromDocument(element, document); refreshColorsFromDocument(element);
element.waiting = false; element.waiting = false;
return false; return false;
}); });

View File

@ -108,9 +108,7 @@ private:
void insert(int index, const Data::CloudTheme &theme); void insert(int index, const Data::CloudTheme &theme);
void refreshColors(Element &element); void refreshColors(Element &element);
void showMenu(Element &element); void showMenu(Element &element);
void refreshColorsFromDocument( void refreshColorsFromDocument(Element &element);
Element &element,
not_null<DocumentData*> document);
void setWaiting(Element &element, bool waiting); void setWaiting(Element &element, bool waiting);
void subscribeToDownloadFinished(); void subscribeToDownloadFinished();
int resizeGetHeight(int newWidth); int resizeGetHeight(int newWidth);

View File

@ -244,7 +244,7 @@ QPixmap MediaPreviewWidget::currentImage() const {
if (_document) { if (_document) {
if (const auto sticker = _document->sticker()) { if (const auto sticker = _document->sticker()) {
if (_cacheStatus != CacheLoaded) { if (_cacheStatus != CacheLoaded) {
if (sticker->animated && !_lottie && _document->loaded()) { if (sticker->animated && !_lottie && _documentMedia->loaded()) {
const_cast<MediaPreviewWidget*>(this)->setupLottie(); const_cast<MediaPreviewWidget*>(this)->setupLottie();
} }
if (_lottie && _lottie->ready()) { if (_lottie && _lottie->ready()) {
@ -263,7 +263,7 @@ QPixmap MediaPreviewWidget::currentImage() const {
} }
} else { } else {
_document->automaticLoad(_origin, nullptr); _document->automaticLoad(_origin, nullptr);
if (_document->loaded()) { if (_documentMedia->loaded()) {
if (!_gif && !_gif.isBad()) { if (!_gif && !_gif.isBad()) {
auto that = const_cast<MediaPreviewWidget*>(this); auto that = const_cast<MediaPreviewWidget*>(this);
that->_gif = Media::Clip::MakeReader(_documentMedia.get(), FullMsgId(), [=](Media::Clip::Notification notification) { that->_gif = Media::Clip::MakeReader(_documentMedia.get(), FullMsgId(), [=](Media::Clip::Notification notification) {