From bf616036b35b88979837da4b8be1b297461b20a4 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 9 Apr 2020 18:02:09 +0400 Subject: [PATCH] Check loaded status through DocumentMedia if possible. --- .../boxes/background_preview_box.cpp | 4 ++- .../boxes/background_preview_box.h | 5 +++ .../SourceFiles/boxes/edit_caption_box.cpp | 18 +++++++--- .../SourceFiles/boxes/sticker_set_box.cpp | 2 +- Telegram/SourceFiles/boxes/stickers_box.cpp | 3 +- .../chat_helpers/field_autocomplete.cpp | 2 +- .../chat_helpers/gifs_list_widget.cpp | 4 ++- .../chat_helpers/stickers_list_widget.cpp | 4 +-- Telegram/SourceFiles/core/application.cpp | 2 +- .../SourceFiles/data/data_cloud_themes.cpp | 6 ++-- Telegram/SourceFiles/data/data_document.cpp | 34 +++++++------------ Telegram/SourceFiles/data/data_document.h | 10 ++---- .../SourceFiles/data/data_document_media.cpp | 6 +++- .../SourceFiles/data/data_document_media.h | 1 + .../admin_log/history_admin_log_inner.cpp | 7 ++-- .../history/history_inner_widget.cpp | 8 ++--- .../view/history_view_context_menu.cpp | 6 ++-- .../history/view/history_view_list_widget.cpp | 3 +- .../view/media/history_view_document.cpp | 2 +- .../info/media/info_media_list_widget.cpp | 4 +-- .../media/view/media_view_overlay_widget.cpp | 24 ++++++------- .../SourceFiles/overview/overview_layout.cpp | 33 +++++++++--------- .../themes/window_themes_cloud_list.cpp | 26 +++++++------- .../window/themes/window_themes_cloud_list.h | 4 +-- .../window/window_media_preview.cpp | 4 +-- 25 files changed, 112 insertions(+), 110 deletions(-) diff --git a/Telegram/SourceFiles/boxes/background_preview_box.cpp b/Telegram/SourceFiles/boxes/background_preview_box.cpp index 475c04009..b8c6cb437 100644 --- a/Telegram/SourceFiles/boxes/background_preview_box.cpp +++ b/Telegram/SourceFiles/boxes/background_preview_box.cpp @@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "data/data_user.h" #include "data/data_document.h" +#include "data/data_document_media.h" #include "base/unixtime.h" #include "boxes/confirm_box.h" #include "boxes/background_preview_box.h" @@ -410,6 +411,7 @@ BackgroundPreviewBox::BackgroundPreviewBox( tr::lng_background_text2(tr::now), true)) , _paper(paper) +, _media(_paper.document() ? _paper.document()->createMediaView() : nullptr) , _radial([=](crl::time now) { radialAnimationCallback(now); }) { subscribe(_session->downloaderTaskFinished(), [=] { update(); }); } @@ -710,7 +712,7 @@ void BackgroundPreviewBox::checkLoadedDocument() { const auto document = _paper.document(); if (!_full.isNull() || !document - || !document->loaded(DocumentData::FilePathResolve::Checked) + || !_media->loaded(true) || _generating) { return; } diff --git a/Telegram/SourceFiles/boxes/background_preview_box.h b/Telegram/SourceFiles/boxes/background_preview_box.h index f0c929de1..773759e7a 100644 --- a/Telegram/SourceFiles/boxes/background_preview_box.h +++ b/Telegram/SourceFiles/boxes/background_preview_box.h @@ -15,6 +15,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/animations.h" #include "ui/effects/radial_animation.h" +namespace Data { +class DocumentMedia; +} // namespace Data + namespace Main { class Session; } // namespace Main @@ -71,6 +75,7 @@ private: AdminLog::OwnedItem _text1; AdminLog::OwnedItem _text2; Data::WallPaper _paper; + std::shared_ptr _media; QImage _full; QPixmap _scaled, _blurred, _fadeOutThumbnail; Ui::Animations::Simple _fadeIn; diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index 0d0c863d6..4fb068103 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_user.h" #include "data/data_session.h" #include "data/data_file_origin.h" +#include "data/data_document_media.h" #include "history/history.h" #include "history/history_item.h" #include "lang/lang_keys.h" @@ -157,6 +158,9 @@ EditCaptionBox::EditCaptionBox( maxW, maxH); }; + if (doc) { + _gifMedia = doc->createMediaView(); + } prepareGifPreview(doc); } else { maxW = dimensions.width(); @@ -248,8 +252,13 @@ EditCaptionBox::EditCaptionBox( _refreshThumbnail(); update(); } - if (doc && doc->isAnimation() && doc->loaded() && !_gifPreview) { - prepareGifPreview(doc); + if (doc && doc->isAnimation()) { + if (!_gifMedia) { + _gifMedia = doc->createMediaView(); + } + if (_gifMedia->loaded() && !_gifPreview) { + prepareGifPreview(doc); + } } }); @@ -306,6 +315,8 @@ void EditCaptionBox::updateEmojiPanelGeometry() { } void EditCaptionBox::prepareGifPreview(DocumentData* document) { + Expects(!document || (_gifMedia != nullptr)); + const auto isListEmpty = _preparedList.files.empty(); if (_gifPreview) { return; @@ -315,8 +326,7 @@ void EditCaptionBox::prepareGifPreview(DocumentData* document) { const auto callback = [=](Media::Clip::Notification notification) { clipCallback(notification); }; - _gifMedia = document ? document->createMediaView() : nullptr; - if (document && document->isAnimation() && document->loaded()) { + if (document && document->isAnimation() && _gifMedia->loaded()) { _gifPreview = Media::Clip::MakeReader( _gifMedia.get(), _msgId, diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.cpp b/Telegram/SourceFiles/boxes/sticker_set_box.cpp index 24036d519..5aea53dc2 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.cpp +++ b/Telegram/SourceFiles/boxes/sticker_set_box.cpp @@ -628,7 +628,7 @@ void StickerSetBox::Inner::paintSticker( if (document->sticker()->animated && !element.animated - && document->loaded()) { + && media->loaded()) { const_cast(this)->setupLottie(index); } diff --git a/Telegram/SourceFiles/boxes/stickers_box.cpp b/Telegram/SourceFiles/boxes/stickers_box.cpp index 69e48c12e..4ad659f92 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.cpp +++ b/Telegram/SourceFiles/boxes/stickers_box.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "data/data_channel.h" #include "data/data_file_origin.h" +#include "data/data_document_media.h" #include "core/application.h" #include "lang/lang_keys.h" #include "mainwidget.h" @@ -1913,7 +1914,7 @@ void StickersBox::Inner::readVisibleSets() { : _rows[i]->sticker->thumbnail(); if (!thumbnail || thumbnail->loaded() - || _rows[i]->sticker->loaded()) { + || _rows[i]->stickerMedia->loaded()) { _session->api().readFeaturedSetDelayed(_rows[i]->id); } } diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp index aa3d29535..c791b9560 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp @@ -643,7 +643,7 @@ void FieldAutocompleteInner::paintEvent(QPaintEvent *e) { if (document->sticker()->animated && !sticker.animated - && document->loaded()) { + && media->loaded()) { setupLottie(sticker); } diff --git a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp index 0023af14c..57f539f12 100644 --- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "data/data_user.h" #include "data/data_file_origin.h" +#include "data/data_document_media.h" #include "ui/widgets/buttons.h" #include "ui/widgets/input_fields.h" #include "ui/effects/ripple_animation.h" @@ -377,7 +378,8 @@ void GifsListWidget::selectInlineResult(int row, int column) { photo->thumbnail()->loadEvenCancelled(Data::FileOrigin()); } } else if (const auto document = item->getDocument()) { - if (document->loaded() + const auto media = document->activeMediaView(); + if ((media && media->loaded()) || QGuiApplication::keyboardModifiers() == Qt::ControlModifier) { _fileChosen.fire_copy(document); } else if (document->loading()) { diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index c0ac90ba2..0f2f326a0 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -987,7 +987,7 @@ void StickersListWidget::readVisibleFeatured( for (int j = 0; j < count; ++j) { if (!set.stickers[j].document->hasThumbnail() || set.stickers[j].document->thumbnail()->loaded() - || set.stickers[j].document->loaded()) { + || set.stickers[j].documentMedia->loaded()) { ++loaded; } } @@ -1718,7 +1718,7 @@ void StickersListWidget::paintSticker(Painter &p, Set &set, int y, int section, if (document->sticker()->animated && !sticker.animated - && document->loaded()) { + && media->loaded()) { setupLottie(set, section, index); } diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index 67d505718..4f54e30eb 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -300,7 +300,7 @@ void Application::showDocument(not_null document, HistoryItem *it if (cUseExternalVideoPlayer() && document->isVideoFile() - && document->loaded()) { + && !document->filepath().isEmpty()) { File::Launch(document->location(false).fname); } else { _mediaView->showDocument(document, item); diff --git a/Telegram/SourceFiles/data/data_cloud_themes.cpp b/Telegram/SourceFiles/data/data_cloud_themes.cpp index 106ecb682..e4c3a724e 100644 --- a/Telegram/SourceFiles/data/data_cloud_themes.cpp +++ b/Telegram/SourceFiles/data/data_cloud_themes.cpp @@ -217,15 +217,15 @@ void CloudThemes::loadDocumentAndInvoke( Data::FileOriginTheme(cloud.id, cloud.accessHash), QString()); value.callback = std::move(callback); - if (document->loaded()) { + if (value.documentMedia->loaded()) { invokeForLoaded(value); return; } if (!alreadyWaiting) { base::ObservableViewer( _session->downloaderTaskFinished() - ) | rpl::filter([=] { - return document->loaded(); + ) | rpl::filter([=, &value] { + return value.documentMedia->loaded(); }) | rpl::start_with_next([=, &value] { invokeForLoaded(value); }, value.subscription); diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index a8f5016f9..787d4593c 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -48,8 +48,6 @@ namespace { constexpr auto kMemoryForCache = 128 * 1024 * 1024; // was 32, updated to 128 const auto kAnimatedStickerDimensions = QSize(512, 512); -using FilePathResolve = DocumentData::FilePathResolve; - Core::MediaActiveCache &ActiveCache() { static auto Instance = Core::MediaActiveCache( kMemoryForCache, @@ -323,7 +321,7 @@ void DocumentOpenClickHandler::Open( LaunchWithWarning(location.name(), context); }; 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); location.accessDisable(); } else if (data->canBePlayed()) { @@ -364,7 +362,7 @@ void DocumentSaveClickHandler::Save( if (mode != Mode::ToNewFile && data->saveFromData()) { return; } - const auto filepath = data->filepath(FilePathResolve::Checked); + const auto filepath = data->filepath(true); const auto fileinfo = QFileInfo( ); const auto filedir = filepath.isEmpty() @@ -416,7 +414,7 @@ void DocumentOpenWithClickHandler::Open( } data->saveFromDataSilent(); - const auto path = data->filepath(FilePathResolve::Checked); + const auto path = data->filepath(true); if (!path.isEmpty()) { File::OpenWith(path, QCursor::pos()); } else { @@ -789,14 +787,14 @@ void DocumentData::automaticLoad( } void DocumentData::automaticLoadSettingsChanged() { - if (!cancelled() || status != FileReady || loaded()) { + if (!cancelled() || status != FileReady) { return; } _loader = nullptr; _flags &= ~Flag::DownloadCancelled; } -bool DocumentData::loaded(FilePathResolve resolve) const { +bool DocumentData::loaded(bool check) const { if (loading() && _loader->finished()) { if (_loader->cancelled()) { _flags |= Flag::DownloadCancelled; @@ -822,7 +820,7 @@ bool DocumentData::loaded(FilePathResolve resolve) const { } _owner->notifyDocumentLayoutChanged(this); } - return !rawBytes().isEmpty() || !filepath(resolve).isEmpty(); + return !rawBytes().isEmpty() || !filepath(check).isEmpty(); } void DocumentData::destroyLoader() const { @@ -881,7 +879,7 @@ void DocumentData::setLoadedInMediaCache(bool loaded) { return; } _flags = flags; - if (!this->loaded()) { + if (filepath().isEmpty()) { if (loadedInMediaCache()) { Local::writeFileLocation( mediaKey(), @@ -913,7 +911,7 @@ void DocumentData::save( const QString &toFile, LoadFromCloudSetting fromCloud, bool autoLoading) { - if (loaded(FilePathResolve::Checked)) { + if (loaded(true)) { auto &l = location(true); if (!toFile.isEmpty()) { if (!rawBytes().isEmpty()) { @@ -1111,27 +1109,19 @@ void DocumentData::setLocation(const FileLocation &loc) { } } -QString DocumentData::filepath(FilePathResolve resolve) const { - const auto check = (resolve != FilePathResolve::Cached); +QString DocumentData::filepath(bool check) const { return (check && _location.name().isEmpty()) ? QString() : location(check).name(); } bool DocumentData::saveFromData() { - if (!filepath(FilePathResolve::Checked).isEmpty()) { - return true; - } - return saveFromDataChecked(); + return !filepath(true).isEmpty() || saveFromDataChecked(); } bool DocumentData::saveFromDataSilent() { - if (!filepath(FilePathResolve::Checked).isEmpty()) { - return true; - } else if (Global::AskDownloadPath()) { - return false; - } - return saveFromDataChecked(); + return !filepath(true).isEmpty() + || (!Global::AskDownloadPath() && saveFromDataChecked()); } bool DocumentData::saveFromDataChecked() { diff --git a/Telegram/SourceFiles/data/data_document.h b/Telegram/SourceFiles/data/data_document.h index 8077e3a7b..b41c248d9 100644 --- a/Telegram/SourceFiles/data/data_document.h +++ b/Telegram/SourceFiles/data/data_document.h @@ -100,12 +100,7 @@ public: const HistoryItem *item); void automaticLoadSettingsChanged(); - enum class FilePathResolve { - Cached, - Checked, - }; - [[nodiscard]] bool loaded( - FilePathResolve resolve = FilePathResolve::Cached) const; + [[nodiscard]] bool loaded(bool check = false) const; [[nodiscard]] bool loading() const; [[nodiscard]] QString loadingFilePath() const; [[nodiscard]] bool displayLoading() const; @@ -131,8 +126,7 @@ public: bool saveFromData(); bool saveFromDataSilent(); - [[nodiscard]] QString filepath( - FilePathResolve resolve = FilePathResolve::Cached) const; + [[nodiscard]] QString filepath(bool check = false) const; [[nodiscard]] bool saveToCache() const; diff --git a/Telegram/SourceFiles/data/data_document_media.cpp b/Telegram/SourceFiles/data/data_document_media.cpp index 49b1de4c1..0491ce2e7 100644 --- a/Telegram/SourceFiles/data/data_document_media.cpp +++ b/Telegram/SourceFiles/data/data_document_media.cpp @@ -137,7 +137,7 @@ void DocumentMedia::checkStickerLarge() { } _owner->automaticLoad(_owner->stickerSetOrigin(), nullptr); - if (data->animated || !_owner->loaded()) { + if (data->animated || !loaded()) { return; } const auto bytes = _owner->rawBytes(); @@ -170,6 +170,10 @@ QByteArray DocumentMedia::bytes() const { return _bytes; } +bool DocumentMedia::loaded(bool check) const { + return !_bytes.isEmpty() || _owner->loaded(check);// checkLoadedTo(this); +} + void DocumentMedia::checkStickerSmall() { const auto data = _owner->sticker(); if ((data && data->animated) || _owner->thumbnailEnoughForSticker()) { diff --git a/Telegram/SourceFiles/data/data_document_media.h b/Telegram/SourceFiles/data/data_document_media.h index 7301006e3..1dfd2300a 100644 --- a/Telegram/SourceFiles/data/data_document_media.h +++ b/Telegram/SourceFiles/data/data_document_media.h @@ -34,6 +34,7 @@ public: void setBytes(const QByteArray &bytes); [[nodiscard]] QByteArray bytes() const; + [[nodiscard]] bool loaded(bool check = false) const; // For DocumentData. static void CheckGoodThumbnail(not_null document); diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp index 98e60fb67..1aad5b722 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -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), [=] { showContextInFolder(document); }); @@ -1181,8 +1181,7 @@ void InnerWidget::cancelContextDownload(not_null document) { } void InnerWidget::showContextInFolder(not_null document) { - const auto filepath = document->filepath( - DocumentData::FilePathResolve::Checked); + const auto filepath = document->filepath(true); if (!filepath.isEmpty()) { File::ShowInFolder(filepath); } @@ -1691,7 +1690,7 @@ void InnerWidget::performDrag() { // auto mimeData = std::make_unique(); // mimeData->setData(forwardMimeType, "1"); // if (auto document = (pressedMedia ? pressedMedia->getDocument() : nullptr)) { - // auto filepath = document->filepath(DocumentData::FilePathResolve::Checked); + // auto filepath = document->filepath(true); // if (!filepath.isEmpty()) { // QList urls; // urls.push_back(QUrl::fromLocalFile(filepath)); diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index d86c1af23..c372d017e 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -1248,8 +1248,7 @@ std::unique_ptr HistoryInner::prepareDrag() { result->setData(qsl("application/x-td-forward"), "1"); if (const auto media = view->media()) { if (const auto document = media->getDocument()) { - const auto filepath = document->filepath( - DocumentData::FilePathResolve::Checked); + const auto filepath = document->filepath(true); if (!filepath.isEmpty()) { QList urls; urls.push_back(QUrl::fromLocalFile(filepath)); @@ -1606,7 +1605,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { 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), [=] { showContextInFolder(document); }); @@ -1886,8 +1885,7 @@ void HistoryInner::cancelContextDownload(not_null document) { } void HistoryInner::showContextInFolder(not_null document) { - const auto filepath = document->filepath( - DocumentData::FilePathResolve::Checked); + const auto filepath = document->filepath(true); if (!filepath.isEmpty()) { File::ShowInFolder(filepath); } diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp index 397162308..95c549740 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp @@ -134,8 +134,7 @@ void OpenGif(FullMsgId itemId) { } void ShowInFolder(not_null document) { - const auto filepath = document->filepath( - DocumentData::FilePathResolve::Checked); + const auto filepath = document->filepath(true); if (!filepath.isEmpty()) { File::ShowInFolder(filepath); } @@ -205,8 +204,7 @@ void AddDocumentActions( : tr::lng_faved_stickers_add(tr::now)), [=] { ToggleFavedSticker(document, contextId); }); } - if (!document->filepath( - DocumentData::FilePathResolve::Checked).isEmpty()) { + if (!document->filepath(true).isEmpty()) { menu->addAction( (Platform::IsMac() ? tr::lng_context_show_in_finder(tr::now) diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 8bdbc2fe1..cc733a7b6 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -2375,8 +2375,7 @@ std::unique_ptr ListWidget::prepareDrag() { result->setData(qsl("application/x-td-forward"), "1"); if (const auto media = pressedView->media()) { if (const auto document = media->getDocument()) { - const auto filepath = document->filepath( - DocumentData::FilePathResolve::Checked); + const auto filepath = document->filepath(true); if (!filepath.isEmpty()) { QList urls; urls.push_back(QUrl::fromLocalFile(filepath)); diff --git a/Telegram/SourceFiles/history/view/media/history_view_document.cpp b/Telegram/SourceFiles/history/view/media/history_view_document.cpp index a6ea13324..b6513677b 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_document.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_document.cpp @@ -93,7 +93,7 @@ bool Document::dataFinished() const { } bool Document::dataLoaded() const { - return _data->loaded(); + return _dataMedia ? _dataMedia->loaded() : _data->loaded(); } void Document::createComponents(bool caption) { diff --git a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp index ca3aaa24b..2af34bd18 100644 --- a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp +++ b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp @@ -1270,7 +1270,7 @@ void ListWidget::showContextMenu( document->cancel(); }); } else { - auto filepath = document->filepath(DocumentData::FilePathResolve::Checked); + auto filepath = document->filepath(true); if (!filepath.isEmpty()) { auto handler = App::LambdaDelayed( st::defaultDropdownMenu.menu.ripple.hideDuration, @@ -1979,7 +1979,7 @@ void ListWidget::performDrag() { // auto mimeData = std::make_unique(); // mimeData->setData(forwardMimeType, "1"); // if (auto document = (pressedMedia ? pressedMedia->getDocument() : nullptr)) { - // auto filepath = document->filepath(DocumentData::FilePathResolve::Checked); + // auto filepath = document->filepath(true); // if (!filepath.isEmpty()) { // QList urls; // urls.push_back(QUrl::fromLocalFile(filepath)); diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 443f714e8..d569441d9 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -535,7 +535,7 @@ void OverlayWidget::documentUpdated(DocumentData *doc) { update(_docRect); } } else if (_streamed) { - const auto ready = _doc->loaded() + const auto ready = _docMedia->loaded() ? _doc->size : _doc->loading() ? 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->show(); } else { - if (_doc->loaded(DocumentData::FilePathResolve::Checked)) { + if (_docMedia->loaded(true)) { _docDownload->hide(); _docSaveAs->moveToLeft(_docRect.x() + 2 * st::mediaviewFilePadding + st::mediaviewFileIconSize, _docRect.y() + st::mediaviewFilePadding + st::mediaviewFileLinksTop); _docSaveAs->show(); @@ -634,7 +634,7 @@ void OverlayWidget::updateControls() { _saveVisible = (_photo && _photo->loaded()) || (_doc - && _doc->filepath(DocumentData::FilePathResolve::Checked).isEmpty() + && _doc->filepath(true).isEmpty() && !_doc->loading()); _saveNav = myrtlrect(width() - st::mediaviewIconSize.width() * 3, height() - st::mediaviewIconSize.height(), st::mediaviewIconSize.width(), st::mediaviewIconSize.height()); _saveNavIcon = style::centerrect(_saveNav, st::mediaviewSave); @@ -739,7 +739,7 @@ void OverlayWidget::updateActions() { if (IsServerMsgId(_msgid.msg)) { _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()) }); } if ((_doc && documentContentShown()) || (_photo && _photo->loaded())) { @@ -982,7 +982,7 @@ bool OverlayWidget::radialAnimationCallback(crl::time now) { && (!anim::Disabled() || updated)) { update(radialRect()); } - const auto ready = _doc && _doc->loaded(); + const auto ready = _doc && _docMedia->loaded(); const auto streamVideo = ready && _doc->canBePlayed(); const auto tryOpenImage = ready && (_doc->size < App::kImageSizeLimit); if (ready && ((tryOpenImage && !_radial.animating()) || streamVideo)) { @@ -1335,7 +1335,7 @@ void OverlayWidget::onDownload() { } location.accessDisable(); } else { - if (_doc->filepath(DocumentData::FilePathResolve::Checked).isEmpty() + if (_doc->filepath(true).isEmpty() && !_doc->loading()) { DocumentSaveClickHandler::Save( fileOrigin(), @@ -1380,7 +1380,7 @@ void OverlayWidget::onSaveCancel() { void OverlayWidget::onShowInFolder() { if (!_doc) return; - auto filepath = _doc->filepath(DocumentData::FilePathResolve::Checked); + auto filepath = _doc->filepath(true); if (!filepath.isEmpty()) { File::ShowInFolder(filepath); close(); @@ -2816,7 +2816,7 @@ void OverlayWidget::paintEvent(QPaintEvent *e) { const auto radialOpacity = radial ? _radial.opacity() : 0.; if (!_doc || !_doc->hasThumbnail()) { 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()); p.setPen(st::mediaviewFileExtFg); p.setFont(st::mediaviewFileExtFont); @@ -3058,7 +3058,7 @@ void OverlayWidget::paintRadialLoading( if (!_streamed->instance.waitingShown()) { return; } - } else if (!radial && (!_doc || _doc->loaded())) { + } else if (!radial && (!_doc || _docMedia->loaded())) { return; } @@ -3125,7 +3125,7 @@ void OverlayWidget::paintRadialLoadingContent( } else { const auto o = overLevel(OverIcon); paintBg( - _doc->loaded() ? radialOpacity : 1., + _docMedia->loaded() ? radialOpacity : 1., anim::brush(st::msgDateImgBg, st::msgDateImgBgOver, o)); 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) { if (_streamed) { playbackPauseResume(); - } else if (_doc && !_doc->loading() && (documentBubbleShown() || !_doc->loaded())) { + } else if (_doc && !_doc->loading() && (documentBubbleShown() || !_docMedia->loaded())) { onDocClick(); } } else if (e->key() == Qt::Key_Left) { @@ -3698,7 +3698,7 @@ void OverlayWidget::updateOver(QPoint pos) { } else if (documentContentShown() && contentRect().contains(pos)) { if ((_doc->isVideoFile() || _doc->isVideoMessage()) && _streamed) { updateOverState(OverVideo); - } else if (!_streamed && !_doc->loaded()) { + } else if (!_streamed && !_docMedia->loaded()) { updateOverState(OverIcon); } else if (_over != OverNone) { updateOverState(OverNone); diff --git a/Telegram/SourceFiles/overview/overview_layout.cpp b/Telegram/SourceFiles/overview/overview_layout.cpp index 0c1de4de1..b3c0ad9b3 100644 --- a/Telegram/SourceFiles/overview/overview_layout.cpp +++ b/Telegram/SourceFiles/overview/overview_layout.cpp @@ -443,7 +443,7 @@ void Video::paint(Painter &p, const QRect &clip, TextSelection selection, const const auto goodLoaded = _dataMedia->goodThumbnail() && _dataMedia->goodThumbnail()->loaded(); - bool loaded = _data->loaded(), displayLoading = _data->displayLoading(); + bool loaded = dataLoaded(), displayLoading = _data->displayLoading(); if (displayLoading) { ensureRadial(); if (!_radial->animating()) { @@ -560,7 +560,7 @@ bool Video::dataFinished() const { } bool Video::dataLoaded() const { - return _data->loaded(); + return _dataMedia ? _dataMedia->loaded() : !_data->filepath().isEmpty(); } bool Video::iconAnimated() const { @@ -573,7 +573,7 @@ TextState Video::getState( if (hasPoint(point)) { const auto link = (_data->loading() || _data->uploading()) ? _cancell - : (_data->loaded() || _data->canBePlayed()) + : (dataLoaded() || _data->canBePlayed()) ? _openl : _savel; return { parent(), link }; @@ -588,7 +588,7 @@ void Video::updateStatusText() { statusSize = FileStatusSizeFailed; } else if (_data->uploading()) { statusSize = _data->uploadingData->offset; - } else if (_data->loaded()) { + } else if (dataLoaded()) { statusSize = FileStatusSizeLoaded; } else { statusSize = FileStatusSizeReady; @@ -642,7 +642,7 @@ void Voice::initDimensions() { void Voice::paint(Painter &p, const QRect &clip, TextSelection selection, const PaintContext *context) { bool selected = (selection == FullSelection); - bool loaded = _data->loaded(), displayLoading = _data->displayLoading(); + bool loaded = dataLoaded(), displayLoading = _data->displayLoading(); if (displayLoading) { ensureRadial(); @@ -776,7 +776,7 @@ void Voice::paint(Painter &p, const QRect &clip, TextSelection selection, const TextState Voice::getState( QPoint point, StateRequest request) const { - const auto loaded = _data->loaded(); + const auto loaded = dataLoaded(); const auto nameleft = _st.songPadding.left() + _st.songThumbSize @@ -847,7 +847,7 @@ bool Voice::dataFinished() const { } bool Voice::dataLoaded() const { - return _data->loaded(); + return _dataMedia ? _dataMedia->loaded() : !_data->filepath().isEmpty(); } bool Voice::iconAnimated() const { @@ -882,7 +882,7 @@ bool Voice::updateStatusText() { int32 statusSize = 0, realDuration = 0; if (_data->status == FileDownloadFailed || _data->status == FileUploadFailed) { statusSize = FileStatusSizeFailed; - } else if (_data->loaded()) { + } else if (dataLoaded()) { statusSize = FileStatusSizeLoaded; } else { statusSize = FileStatusSizeReady; @@ -964,7 +964,7 @@ void Document::paint(Painter &p, const QRect &clip, TextSelection selection, con const auto cornerDownload = downloadInCorner(); _data->automaticLoad(parent()->fullId(), parent()); - const auto loaded = _data->loaded(); + const auto loaded = dataLoaded(); const auto displayLoading = _data->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 { - if (_data->loaded() + if (dataLoaded() || _data->loadedInMediaCache() || !downloadInCorner()) { return; @@ -1170,7 +1170,7 @@ TextState Document::cornerDownloadTextState( StateRequest request) const { auto result = TextState(parent()); if (!downloadInCorner() - || _data->loaded() + || dataLoaded() || _data->loadedInMediaCache()) { return result; } @@ -1187,7 +1187,7 @@ TextState Document::cornerDownloadTextState( TextState Document::getState( QPoint point, StateRequest request) const { - const auto loaded = _data->loaded(); + const auto loaded = dataLoaded(); const auto wthumb = withThumb(); if (_data->isSong()) { @@ -1308,12 +1308,12 @@ bool Document::dataFinished() const { } bool Document::dataLoaded() const { - return _data->loaded(); + return _dataMedia ? _dataMedia->loaded() : !_data->filepath().isEmpty(); } bool Document::iconAnimated() const { return _data->isSong() - || !_data->loaded() + || !dataLoaded() || (_radial && _radial->animating()); } @@ -1328,13 +1328,14 @@ bool Document::withThumb() const { bool Document::updateStatusText() { bool showPause = false; int32 statusSize = 0, realDuration = 0; - if (_data->status == FileDownloadFailed || _data->status == FileUploadFailed) { + if (_data->status == FileDownloadFailed + || _data->status == FileUploadFailed) { statusSize = FileStatusSizeFailed; } else if (_data->uploading()) { statusSize = _data->uploadingData->offset; } else if (_data->loading()) { statusSize = _data->loadOffset(); - } else if (_data->loaded()) { + } else if (dataLoaded()) { statusSize = FileStatusSizeLoaded; } else { statusSize = FileStatusSizeReady; diff --git a/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp b/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp index 6b79f2a59..a41fed61e 100644 --- a/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp +++ b/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp @@ -565,8 +565,8 @@ void CloudList::refreshColors(Element &element) { document->save( Data::FileOriginTheme(theme.id, theme.accessHash), QString()); - if (document->loaded()) { - refreshColorsFromDocument(element, document); + if (element.media->loaded()) { + refreshColorsFromDocument(element); } else { setWaiting(element, true); subscribeToDownloadFinished(); @@ -636,14 +636,13 @@ bool CloudList::amCreator(const Data::CloudTheme &theme) const { return (_window->session().userId() == theme.createdBy); } -void CloudList::refreshColorsFromDocument( - Element &element, - not_null document) { +void CloudList::refreshColorsFromDocument(Element &element) { + Expects(element.media != nullptr); + Expects(element.media->loaded()); + const auto id = element.id(); - const auto path = document->filepath(); - const auto data = element.media - ? base::take(element.media)->bytes() - : QByteArray(); + const auto path = element.media->owner()->filepath(); + const auto data = base::take(element.media)->bytes(); crl::async([=, guard = element.generating.make_guard()]() mutable { crl::on_main(std::move(guard), [ =, @@ -672,12 +671,13 @@ void CloudList::subscribeToDownloadFinished() { ) | rpl::start_with_next([=] { auto &&waiting = _elements | ranges::view::filter(&Element::waiting); const auto still = ranges::count_if(waiting, [&](Element &element) { - const auto id = element.theme.documentId; - const auto document = _window->session().data().document(id); - if (!document->loaded()) { + if (!element.media) { + element.waiting = false; + return false; + } else if (!element.media->loaded()) { return true; } - refreshColorsFromDocument(element, document); + refreshColorsFromDocument(element); element.waiting = false; return false; }); diff --git a/Telegram/SourceFiles/window/themes/window_themes_cloud_list.h b/Telegram/SourceFiles/window/themes/window_themes_cloud_list.h index c647fd5db..116b5284a 100644 --- a/Telegram/SourceFiles/window/themes/window_themes_cloud_list.h +++ b/Telegram/SourceFiles/window/themes/window_themes_cloud_list.h @@ -108,9 +108,7 @@ private: void insert(int index, const Data::CloudTheme &theme); void refreshColors(Element &element); void showMenu(Element &element); - void refreshColorsFromDocument( - Element &element, - not_null document); + void refreshColorsFromDocument(Element &element); void setWaiting(Element &element, bool waiting); void subscribeToDownloadFinished(); int resizeGetHeight(int newWidth); diff --git a/Telegram/SourceFiles/window/window_media_preview.cpp b/Telegram/SourceFiles/window/window_media_preview.cpp index 50a540b42..a70af5fde 100644 --- a/Telegram/SourceFiles/window/window_media_preview.cpp +++ b/Telegram/SourceFiles/window/window_media_preview.cpp @@ -244,7 +244,7 @@ QPixmap MediaPreviewWidget::currentImage() const { if (_document) { if (const auto sticker = _document->sticker()) { if (_cacheStatus != CacheLoaded) { - if (sticker->animated && !_lottie && _document->loaded()) { + if (sticker->animated && !_lottie && _documentMedia->loaded()) { const_cast(this)->setupLottie(); } if (_lottie && _lottie->ready()) { @@ -263,7 +263,7 @@ QPixmap MediaPreviewWidget::currentImage() const { } } else { _document->automaticLoad(_origin, nullptr); - if (_document->loaded()) { + if (_documentMedia->loaded()) { if (!_gif && !_gif.isBad()) { auto that = const_cast(this); that->_gif = Media::Clip::MakeReader(_documentMedia.get(), FullMsgId(), [=](Media::Clip::Notification notification) {