From c063d94aa51d2fbaa01d569fccc2956b3102e8f2 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 11 Mar 2019 18:35:11 +0400 Subject: [PATCH] Remove DocumentData::actionOnLoad. Fix GIF open. --- Telegram/Resources/langs/lang.strings | 2 +- Telegram/SourceFiles/data/data_document.cpp | 180 ++++++------------ Telegram/SourceFiles/data/data_document.h | 29 +-- Telegram/SourceFiles/data/data_types.h | 8 - .../admin_log/history_admin_log_inner.cpp | 3 +- .../history/history_inner_widget.cpp | 5 +- .../history/media/history_media_document.cpp | 6 +- .../history/media/history_media_file.cpp | 18 +- .../history/media/history_media_file.h | 3 +- .../history/media/history_media_gif.cpp | 29 +-- .../history/media/history_media_gif.h | 3 - .../view/history_view_context_menu.cpp | 5 +- .../info/media/info_media_list_widget.cpp | 3 +- Telegram/SourceFiles/mainwidget.cpp | 4 - .../media/player/media_player_instance.cpp | 22 +-- .../media/player/media_player_widget.cpp | 6 +- .../media/player/media_player_widget.h | 1 + .../media/view/media_view_overlay_widget.cpp | 35 ++-- .../SourceFiles/overview/overview_layout.cpp | 62 +++--- .../SourceFiles/window/window_controller.cpp | 1 - 20 files changed, 148 insertions(+), 277 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index d9361da9e..96411e51d 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1492,7 +1492,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_player_message_today" = "Today at {time}"; "lng_player_message_yesterday" = "Yesterday at {time}"; "lng_player_message_date" = "{date} at {time}"; -"lng_player_cant_stream" = "This file can't be played before it is fully downloaded.\n\nWould you like to download it?"; +//"lng_player_cant_stream" = "This file can't be played before it is fully downloaded.\n\nWould you like to download it?"; "lng_player_download" = "Download"; "lng_rights_edit_admin" = "Manage permissions"; diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index bcce00f61..c263d0db5 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -289,108 +289,91 @@ QString documentSaveFilename(const DocumentData *data, bool forceSavingAs = fals void DocumentOpenClickHandler::Open( Data::FileOrigin origin, not_null data, - HistoryItem *context, - ActionOnLoad action) { - if (!data->date) return; + HistoryItem *context) { + if (!data->date) { + return; + } - const auto msgId = context ? context->fullId() : FullMsgId(); - const auto playVoice = data->isVoiceMessage(); - const auto playAnimation = data->isAnimation(); const auto &location = data->location(true); if (data->isTheme() && !location.isEmpty() && location.accessEnable()) { Core::App().showDocument(data, context); location.accessDisable(); - return; } else if (data->canBePlayed()) { if (data->isAudioFile() || data->isVoiceMessage() || data->isVideoMessage()) { + const auto msgId = context ? context->fullId() : FullMsgId(); Media::Player::instance()->playPause({ data, msgId }); + } else if (context && data->isAnimation()) { + data->owner().requestAnimationPlayInline(context); } else { Core::App().showDocument(data, context); } - return; - } - if (!location.isEmpty() || (!data->data().isEmpty() && (playVoice || playAnimation))) { - if (playVoice) { - Media::Player::instance()->playPause({ data, msgId }); - } else if (data->size < App::kImageSizeLimit) { - if (!data->data().isEmpty() && playAnimation) { - if (action == ActionOnLoadPlayInline && context) { - data->owner().requestAnimationPlayInline(context); - } else { - Core::App().showDocument(data, context); - } - } else if (location.accessEnable()) { - if (playAnimation || QImageReader(location.name()).canRead()) { - if (playAnimation && action == ActionOnLoadPlayInline && context) { - data->owner().requestAnimationPlayInline(context); - } else { - Core::App().showDocument(data, context); - } - } else { - LaunchWithWarning(location.name(), context); - } + } else if (!location.isEmpty()) { + if (data->size < App::kImageSizeLimit && location.accessEnable()) { + const auto guard = gsl::finally([&] { location.accessDisable(); - } else { - LaunchWithWarning(location.name(), context); + }); + if (QImageReader(location.name()).canRead()) { + Core::App().showDocument(data, context); + return; } - } else { - LaunchWithWarning(location.name(), context); } - return; + LaunchWithWarning(location.name(), context); + } else if (data->status == FileReady + || data->status == FileDownloadFailed) { + DocumentSaveClickHandler::Save(origin, data); } - - if (data->status != FileReady - && data->status != FileDownloadFailed) return; - - QString filename; - if (!data->saveToCache() - || (location.isEmpty() && (!data->data().isEmpty()))) { - filename = documentSaveFilename(data); - if (filename.isEmpty()) return; - } - - data->save(origin, filename, action, msgId); } void DocumentOpenClickHandler::onClickImpl() const { - const auto data = document(); - const auto action = data->isVoiceMessage() - ? ActionOnLoadNone - : ActionOnLoadOpen; - Open(context(), data, getActionItem(), action); -} - -void GifOpenClickHandler::onClickImpl() const { - Open(context(), document(), getActionItem(), ActionOnLoadPlayInline); + Open(context(), document(), getActionItem()); } void DocumentSaveClickHandler::Save( Data::FileOrigin origin, not_null data, - HistoryItem *context, - bool forceSavingAs) { - if (!data->date) return; + Mode mode) { + if (!data->date) { + return; + } - auto filepath = data->filepath( - DocumentData::FilePathResolveSaveFromDataSilent, - forceSavingAs); - if (!filepath.isEmpty() && !forceSavingAs) { - File::OpenWith(filepath, QCursor::pos()); - } else { - auto fileinfo = QFileInfo(filepath); - auto filedir = filepath.isEmpty() ? QDir() : fileinfo.dir(); - auto filename = filepath.isEmpty() ? QString() : fileinfo.fileName(); - auto newfname = documentSaveFilename(data, forceSavingAs, filename, filedir); - if (!newfname.isEmpty()) { - data->save(origin, newfname, ActionOnLoadNone, FullMsgId()); + if (mode == Mode::ToCacheOrFile + && data->loaded(DocumentData::FilePathResolveSaveFromDataSilent)) { + File::OpenWith(data->filepath(), QCursor::pos()); + return; + } + auto savename = QString(); + if (mode != Mode::ToCacheOrFile || !data->saveToCache()) { + const auto filepath = data->filepath( + DocumentData::FilePathResolveChecked); + if (mode != Mode::ToNewFile + && (!filepath.isEmpty() + || !data->filepath( + DocumentData::FilePathResolveSaveFromData).isEmpty())) { + return; + } + const auto fileinfo = QFileInfo(filepath); + const auto filedir = filepath.isEmpty() + ? QDir() + : fileinfo.dir(); + const auto filename = filepath.isEmpty() + ? QString() + : fileinfo.fileName(); + savename = documentSaveFilename( + data, + (mode == Mode::ToNewFile), + filename, + filedir); + if (savename.isEmpty()) { + return; } } + data->save(origin, savename); } void DocumentSaveClickHandler::onClickImpl() const { - Save(context(), document(), getActionItem()); + Save(context(), document()); } void DocumentCancelClickHandler::onClickImpl() const { @@ -695,8 +678,6 @@ void DocumentData::automaticLoad( save( origin, filename, - _actionOnLoad, - _actionOnLoadMsgId, loadFromCloud, true); } @@ -708,41 +689,6 @@ void DocumentData::automaticLoadSettingsChanged() { _loader = nullptr; } -void DocumentData::performActionOnLoad() { - if (_actionOnLoad == ActionOnLoadNone) { - return; - } - - const auto loc = location(true); - const auto &already = loc.name(); - const auto item = _actionOnLoadMsgId.msg - ? App::histItemById(_actionOnLoadMsgId) - : nullptr; - const auto showImage = !isVideoFile() && (size < App::kImageSizeLimit); - const auto playVoice = isVoiceMessage(); - const auto playMusic = isAudioFile(); - const auto playAnimation = isAnimation() - && loaded() - && showImage - && item; - if (isTheme()) { - if (!loc.isEmpty() && loc.accessEnable()) { - Core::App().showDocument(this, item); - loc.accessDisable(); - } - } else if (_actionOnLoad == ActionOnLoadOpenWith) { - if (!already.isEmpty()) { - File::OpenWith(already, QCursor::pos()); - } - } else if (playVoice - || playMusic - || playAnimation - || !already.isEmpty()) { - DocumentOpenClickHandler::Open({}, this, item, _actionOnLoad); - } - _actionOnLoad = ActionOnLoadNone; -} - bool DocumentData::loaded(FilePathResolveType type) const { if (loading() && _loader->finished()) { if (_loader->cancelled()) { @@ -834,8 +780,6 @@ bool DocumentData::waitingForAlbum() const { void DocumentData::save( Data::FileOrigin origin, const QString &toFile, - ActionOnLoad action, - const FullMsgId &actionMsgId, LoadFromCloudSetting fromCloud, bool autoLoading) { if (loaded(FilePathResolveChecked)) { @@ -858,9 +802,6 @@ void DocumentData::save( l.accessDisable(); } } - _actionOnLoad = action; - _actionOnLoadMsgId = actionMsgId; - performActionOnLoad(); return; } @@ -874,8 +815,6 @@ void DocumentData::save( } } - _actionOnLoad = action; - _actionOnLoadMsgId = actionMsgId; if (_loader) { if (fromCloud == LoadFromCloudOrLocal) { _loader->permitLoadFromCloud(); @@ -929,8 +868,6 @@ void DocumentData::cancel() { destroyLoader(CancelledMtpFileLoader); _owner->notifyDocumentLayoutChanged(this); App::main()->documentLoadProgress(this); - - _actionOnLoad = ActionOnLoadNone; } bool DocumentData::cancelled() const { @@ -1009,19 +946,19 @@ void DocumentData::setLocation(const FileLocation &loc) { } } -QString DocumentData::filepath(FilePathResolveType type, bool forceSavingAs) const { +QString DocumentData::filepath(FilePathResolveType type) const { bool check = (type != FilePathResolveCached); QString result = (check && _location.name().isEmpty()) ? QString() : location(check).name(); bool saveFromData = result.isEmpty() && !data().isEmpty(); if (saveFromData) { if (type != FilePathResolveSaveFromData && type != FilePathResolveSaveFromDataSilent) { saveFromData = false; - } else if (type == FilePathResolveSaveFromDataSilent && (Global::AskDownloadPath() || forceSavingAs)) { + } else if (type == FilePathResolveSaveFromDataSilent && Global::AskDownloadPath()) { saveFromData = false; } } if (saveFromData) { - QString filename = documentSaveFilename(this, forceSavingAs); + QString filename = documentSaveFilename(this); if (!filename.isEmpty()) { QFile f(filename); if (f.open(QIODevice::WriteOnly)) { @@ -1194,7 +1131,8 @@ bool DocumentData::hasRemoteLocation() const { } bool DocumentData::canBeStreamed() const { - return hasRemoteLocation() && supportsStreaming(); + // For now video messages are not streamed. + return hasRemoteLocation() && supportsStreaming() && !isVideoMessage(); } bool DocumentData::canBePlayed() const { diff --git a/Telegram/SourceFiles/data/data_document.h b/Telegram/SourceFiles/data/data_document.h index 8e4417566..f34d09f2e 100644 --- a/Telegram/SourceFiles/data/data_document.h +++ b/Telegram/SourceFiles/data/data_document.h @@ -113,8 +113,6 @@ public: void save( Data::FileOrigin origin, const QString &toFile, - ActionOnLoad action = ActionOnLoadNone, - const FullMsgId &actionMsgId = FullMsgId(), LoadFromCloudSetting fromCloud = LoadFromCloudOrLocal, bool autoLoading = false); void cancel(); @@ -131,13 +129,10 @@ public: void setLocation(const FileLocation &loc); [[nodiscard]] QString filepath( - FilePathResolveType type = FilePathResolveCached, - bool forceSavingAs = false) const; + FilePathResolveType type = FilePathResolveCached) const; [[nodiscard]] bool saveToCache() const; - void performActionOnLoad(); - void unload(); [[nodiscard]] Image *getReplyPreview(Data::FileOrigin origin); @@ -285,8 +280,6 @@ private: SupportsStreaming _supportsStreaming = SupportsStreaming::Unknown; bool _inappPlaybackFailed = false; - ActionOnLoad _actionOnLoad = ActionOnLoadNone; - FullMsgId _actionOnLoadMsgId; mutable FileLoader *_loader = nullptr; }; @@ -313,12 +306,16 @@ private: class DocumentSaveClickHandler : public DocumentClickHandler { public: + enum class Mode { + ToCacheOrFile, + ToFile, + ToNewFile, + }; using DocumentClickHandler::DocumentClickHandler; static void Save( Data::FileOrigin origin, not_null document, - HistoryItem *context, - bool forceSavingAs = false); + Mode mode = Mode::ToCacheOrFile); protected: void onClickImpl() const override; @@ -331,8 +328,7 @@ public: static void Open( Data::FileOrigin origin, not_null document, - HistoryItem *context, - ActionOnLoad action = ActionOnLoadOpen); + HistoryItem *context); protected: void onClickImpl() const override; @@ -348,15 +344,6 @@ protected: }; -class GifOpenClickHandler : public DocumentOpenClickHandler { -public: - using DocumentOpenClickHandler::DocumentOpenClickHandler; - -protected: - void onClickImpl() const override; - -}; - class VoiceSeekClickHandler : public DocumentOpenClickHandler { public: using DocumentOpenClickHandler::DocumentOpenClickHandler; diff --git a/Telegram/SourceFiles/data/data_types.h b/Telegram/SourceFiles/data/data_types.h index 4574299f7..9f8de5a00 100644 --- a/Telegram/SourceFiles/data/data_types.h +++ b/Telegram/SourceFiles/data/data_types.h @@ -295,7 +295,6 @@ class DocumentSaveClickHandler; class DocumentOpenClickHandler; class DocumentCancelClickHandler; class DocumentWrappedClickHandler; -class GifOpenClickHandler; class VoiceSeekClickHandler; using PhotoId = uint64; @@ -313,13 +312,6 @@ using PreparedPhotoThumbs = base::flat_map; // [0] == -1 -- counting, [0] == -2 -- could not count using VoiceWaveform = QVector; -enum ActionOnLoad { - ActionOnLoadNone, - ActionOnLoadOpen, - ActionOnLoadOpenWith, - ActionOnLoadPlayInline -}; - enum LocationType { UnknownFileLocation = 0, // 1, 2, etc are used as "version" value in mediaKey() method. 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 c6f99ef25..2f79645b6 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -1095,8 +1095,7 @@ void InnerWidget::saveDocumentToFile(DocumentData *document) { DocumentSaveClickHandler::Save( Data::FileOrigin(), document, - nullptr, - true); + DocumentSaveClickHandler::Mode::ToNewFile); } void InnerWidget::copyContextImage(PhotoData *photo) { diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 9e23d944a..0344b9b34 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -1826,8 +1826,7 @@ void HistoryInner::saveDocumentToFile( DocumentSaveClickHandler::Save( contextId, document, - App::histItemById(contextId), - true); + DocumentSaveClickHandler::Mode::ToNewFile); } void HistoryInner::openContextGif(FullMsgId itemId) { @@ -3066,7 +3065,7 @@ QString HistoryInner::tooltipText() const { if (const auto media = view->media()) { if (media->hidesForwardedInfo()) { dateText += "\n" + lng_forwarded( - lt_user, + lt_user, forwarded->originalSender->shortName()); } } diff --git a/Telegram/SourceFiles/history/media/history_media_document.cpp b/Telegram/SourceFiles/history/media/history_media_document.cpp index 4d95cf673..877255cca 100644 --- a/Telegram/SourceFiles/history/media/history_media_document.cpp +++ b/Telegram/SourceFiles/history/media/history_media_document.cpp @@ -82,7 +82,7 @@ void HistoryDocument::createComponents(bool caption) { mask |= HistoryDocumentCaptioned::Bit(); } UpdateComponents(mask); - if (auto thumbed = Get()) { + if (const auto thumbed = Get()) { thumbed->_linksavel = std::make_shared( _data, _parent->data()->fullId()); @@ -90,7 +90,7 @@ void HistoryDocument::createComponents(bool caption) { _data, _parent->data()->fullId()); } - if (auto voice = Get()) { + if (const auto voice = Get()) { voice->_seekl = std::make_shared( _data, _parent->data()->fullId()); @@ -98,7 +98,7 @@ void HistoryDocument::createComponents(bool caption) { } void HistoryDocument::fillNamedFromData(HistoryDocumentNamed *named) { - auto nameString = named->_name = _data->composeNameString(); + const auto nameString = named->_name = _data->composeNameString(); named->_namew = st::semiboldFont->width(nameString); } diff --git a/Telegram/SourceFiles/history/media/history_media_file.cpp b/Telegram/SourceFiles/history/media/history_media_file.cpp index 84a2ecf89..62e3d2cf7 100644 --- a/Telegram/SourceFiles/history/media/history_media_file.cpp +++ b/Telegram/SourceFiles/history/media/history_media_file.cpp @@ -101,23 +101,11 @@ void HistoryFileMedia::checkAnimationFinished() const { } void HistoryFileMedia::setDocumentLinks( not_null document, - not_null realParent, - bool inlinegif) { - FileClickHandlerPtr open, save; + not_null realParent) { const auto context = realParent->fullId(); - if (inlinegif) { - open = std::make_shared(document, context); - } else { - open = std::make_shared(document, context); - } - if (inlinegif) { - save = std::make_shared(document, context); - } else { - save = std::make_shared(document, context); - } setLinks( - std::move(open), - std::move(save), + std::make_shared(document, context), + std::make_shared(document, context), std::make_shared(document, context)); } diff --git a/Telegram/SourceFiles/history/media/history_media_file.h b/Telegram/SourceFiles/history/media/history_media_file.h index df77e2090..ff2017757 100644 --- a/Telegram/SourceFiles/history/media/history_media_file.h +++ b/Telegram/SourceFiles/history/media/history_media_file.h @@ -49,8 +49,7 @@ protected: FileClickHandlerPtr &&cancell); void setDocumentLinks( not_null document, - not_null realParent, - bool inlinegif = false); + not_null realParent); // >= 0 will contain download / upload string, _statusSize = loaded bytes // < 0 will contain played string, _statusSize = -(seconds + 1) played diff --git a/Telegram/SourceFiles/history/media/history_media_gif.cpp b/Telegram/SourceFiles/history/media/history_media_gif.cpp index 7f28b9055..e2a51d847 100644 --- a/Telegram/SourceFiles/history/media/history_media_gif.cpp +++ b/Telegram/SourceFiles/history/media/history_media_gif.cpp @@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/history_view_element.h" #include "history/view/history_view_cursor_state.h" #include "window/window_controller.h" +#include "core/application.h" // for Application::showDocument. #include "ui/image/image.h" #include "data/data_session.h" #include "data/data_document.h" @@ -52,7 +53,7 @@ HistoryGif::HistoryGif( , _data(document) , _caption(st::minPhotoSize - st::msgPadding.left() - st::msgPadding.right()) { const auto item = parent->data(); - setDocumentLinks(_data, item, !_data->isVideoMessage()); + setDocumentLinks(_data, item); setStatusSize(FileStatusSizeReady); @@ -68,12 +69,6 @@ QSize HistoryGif::countOptimalSize() { _parent->skipBlockWidth(), _parent->skipBlockHeight()); } - if (!_openInMediaviewLink) { - _openInMediaviewLink = std::make_shared( - _data, - _parent->data()->fullId()); - } - auto tw = 0; auto th = 0; if (_gif && _gif->state() == Media::Clip::State::Error) { @@ -635,10 +630,12 @@ TextState HistoryGif::textState(QPoint point, StateRequest request) const { if (QRect(usex + paintx, painty, usew, painth).contains(point)) { if (_data->uploading()) { result.link = _cancell; - } else if (!_gif || !cAutoPlayGif() || _data->isVideoMessage()) { - result.link = _data->loaded() ? _openl : (_data->loading() ? _cancell : _savel); } else { - result.link = _openInMediaviewLink; + result.link = _data->loaded() + ? _openl : + _data->loading() + ? _cancell + : _savel; } } if (isRound || _caption.isEmpty()) { @@ -771,15 +768,6 @@ void HistoryGif::updateStatusText() const { } } -void HistoryGif::refreshParentId(not_null realParent) { - HistoryFileMedia::refreshParentId(realParent); - - const auto fullId = realParent->fullId(); - if (_openInMediaviewLink) { - _openInMediaviewLink->setMessageId(fullId); - } -} - QString HistoryGif::additionalInfoString() const { if (_data->isVideoMessage()) { updateStatusText(); @@ -879,6 +867,9 @@ void HistoryGif::playAnimation(bool autoplay) { return; } else if (_gif && autoplay) { return; + } else if (_gif && cAutoPlayGif()) { + Core::App().showDocument(_data, _parent->data()); + return; } using Mode = Media::Clip::Reader::Mode; if (_gif) { diff --git a/Telegram/SourceFiles/history/media/history_media_gif.h b/Telegram/SourceFiles/history/media/history_media_gif.h index 891ab8c0e..766324320 100644 --- a/Telegram/SourceFiles/history/media/history_media_gif.h +++ b/Telegram/SourceFiles/history/media/history_media_gif.h @@ -29,8 +29,6 @@ public: not_null parent, not_null document); - void refreshParentId(not_null realParent) override; - void draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const override; TextState textState(QPoint point, StateRequest request) const override; @@ -104,7 +102,6 @@ private: bool isSeparateRoundVideo() const; not_null _data; - FileClickHandlerPtr _openInMediaviewLink; int _thumbw = 1; int _thumbh = 1; Text _caption; diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp index 4c17541d2..497f3a026 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp @@ -123,7 +123,10 @@ void AddSaveDocumentAction( Data::FileOrigin origin, not_null document) { const auto save = [=] { - DocumentSaveClickHandler::Save(origin, document, nullptr, true); + DocumentSaveClickHandler::Save( + origin, + document, + DocumentSaveClickHandler::Mode::ToNewFile); }; menu->addAction( lang(document->isVideoFile() diff --git a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp index d80c8e634..2ffd6da8d 100644 --- a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp +++ b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp @@ -1277,8 +1277,7 @@ void ListWidget::showContextMenu( DocumentSaveClickHandler::Save( itemFullId, document, - App::histItemById(itemFullId), - true); + DocumentSaveClickHandler::Mode::ToNewFile); }); _contextMenu->addAction( lang(isVideo diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index c577d8013..cc083b92a 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -1388,10 +1388,6 @@ void MainWidget::documentLoadProgress(FileLoader *loader) { } void MainWidget::documentLoadProgress(DocumentData *document) { - if (document->loaded()) { - document->performActionOnLoad(); - } - session().data().requestDocumentViewRepaint(document); session().documentUpdated.notify(document, true); diff --git a/Telegram/SourceFiles/media/player/media_player_instance.cpp b/Telegram/SourceFiles/media/player/media_player_instance.cpp index 108bcf82b..cb5ba2b87 100644 --- a/Telegram/SourceFiles/media/player/media_player_instance.cpp +++ b/Telegram/SourceFiles/media/player/media_player_instance.cpp @@ -137,15 +137,12 @@ void Instance::setCurrent(const AudioMsgId &audioId) { return (check.audio() != audioId.audio()) || (check.contextId() != audioId.contextId()); }; - const auto trackChanged = changed(data->current); - if (trackChanged && data->streamed && changed(data->streamed->id)) { + if (changed(data->current) + && data->streamed + && changed(data->streamed->id)) { clearStreamed(data); } data->current = audioId; - if (!trackChanged) { - return; - } - data->current = audioId; data->isPlaying = false; const auto history = data->history; @@ -362,6 +359,7 @@ void Instance::play(const AudioMsgId &audioId) { playStreamed(audioId, std::move(loader)); } else if (document->isVideoMessage()) { if (const auto item = App::histItemById(audioId.contextId())) { + setCurrent(audioId); App::wnd()->controller()->startRoundVideo(item); } } @@ -378,7 +376,6 @@ void Instance::playPause(const AudioMsgId &audioId) { } else { play(audioId); } - } void Instance::playStreamed( @@ -462,7 +459,9 @@ void Instance::playPause(AudioMsgId::Type type) { emitUpdate(type); } else { const auto state = getState(type); - if (state.id) { + if (state.id + && state.id.audio() == data->current.audio() + && state.id.contextId() == data->current.contextId()) { if (IsStopped(state.state)) { play(state.id); } else if (IsPaused(state.state) || state.state == State::Pausing) { @@ -470,7 +469,7 @@ void Instance::playPause(AudioMsgId::Type type) { } else { mixer()->pause(state.id); } - } else if (auto data = getData(type)) { + } else { play(data->current); } } @@ -697,14 +696,13 @@ void Instance::handleStreamingError( document->setNotSupportsStreaming(); DocumentSaveClickHandler::Save( (contextId ? contextId : ::Data::FileOrigin()), - document, - App::histItemById(contextId)); + document); } else if (error == Streaming::Error::OpenFailed) { document->setInappPlaybackFailed(); DocumentSaveClickHandler::Save( (contextId ? contextId : ::Data::FileOrigin()), document, - App::histItemById(contextId)); + DocumentSaveClickHandler::Mode::ToFile); } emitUpdate(data->type); if (data->streamed && data->streamed->player.failed()) { diff --git a/Telegram/SourceFiles/media/player/media_player_widget.cpp b/Telegram/SourceFiles/media/player/media_player_widget.cpp index a1d5b93c7..606b3c563 100644 --- a/Telegram/SourceFiles/media/player/media_player_widget.cpp +++ b/Telegram/SourceFiles/media/player/media_player_widget.cpp @@ -499,9 +499,13 @@ void Widget::updateTimeLabel() { void Widget::handleSongChange() { const auto current = instance()->current(_type); const auto document = current.audio(); - if (!current || !document) { + if (!current + || !document + || ((_lastSongId.audio() == document) + && (_lastSongId.contextId() == current.contextId()))) { return; } + _lastSongId = current; TextWithEntities textWithEntities; if (document->isVoiceMessage() || document->isVideoMessage()) { diff --git a/Telegram/SourceFiles/media/player/media_player_widget.h b/Telegram/SourceFiles/media/player/media_player_widget.h index b3009c44e..88c1e8324 100644 --- a/Telegram/SourceFiles/media/player/media_player_widget.h +++ b/Telegram/SourceFiles/media/player/media_player_widget.h @@ -93,6 +93,7 @@ private: // We switch to Type::Song only if _voiceIsActive == false. // We change _voiceIsActive to false only manually or from tracksFinished(). AudioMsgId::Type _type = AudioMsgId::Type::Unknown; + AudioMsgId _lastSongId; bool _voiceIsActive = false; Fn _closeCallback; diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 2a4cd0782..0836c3359 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -1065,7 +1065,10 @@ void OverlayWidget::onSaveAs() { if (_doc->data().isEmpty()) location.accessDisable(); } else { if (!documentContentShown()) { - DocumentSaveClickHandler::Save(fileOrigin(), _doc, App::histItemById(_msgid), true); + DocumentSaveClickHandler::Save( + fileOrigin(), + _doc, + DocumentSaveClickHandler::Mode::ToNewFile); updateControls(); } else { _saveVisible = false; @@ -1109,8 +1112,7 @@ void OverlayWidget::onDocClick() { DocumentOpenClickHandler::Open( fileOrigin(), _doc, - App::histItemById(_msgid), - ActionOnLoadNone); + App::histItemById(_msgid)); if (_doc->loading() && !_radial.animating()) { _radial.start(_doc->progress()); } @@ -1155,7 +1157,7 @@ void OverlayWidget::onDownload() { DocumentSaveClickHandler::Save( fileOrigin(), _doc, - App::histItemById(_msgid)); + DocumentSaveClickHandler::Mode::ToFile); updateControls(); } else { _saveVisible = false; @@ -3145,22 +3147,15 @@ void OverlayWidget::mousePressEvent(QMouseEvent *e) { _lastAction = e->pos(); } else if (_over == OverRightNav && moveToNext(1)) { _lastAction = e->pos(); - } else if (_over == OverName) { - _down = OverName; - } else if (_over == OverDate) { - _down = OverDate; - } else if (_over == OverHeader) { - _down = OverHeader; - } else if (_over == OverSave) { - _down = OverSave; - } else if (_over == OverIcon) { - _down = OverIcon; - } else if (_over == OverMore) { - _down = OverMore; - } else if (_over == OverClose) { - _down = OverClose; - } else if (_over == OverVideo) { - _down = OverVideo; + } else if (_over == OverName + || _over == OverDate + || _over == OverHeader + || _over == OverSave + || _over == OverIcon + || _over == OverMore + || _over == OverClose + || _over == OverVideo) { + _down = _over; } else if (!_saveMsg.contains(e->pos()) || !_saveMsgStarted) { _pressed = true; _dragging = 0; diff --git a/Telegram/SourceFiles/overview/overview_layout.cpp b/Telegram/SourceFiles/overview/overview_layout.cpp index 636cf23ec..10e19d54e 100644 --- a/Telegram/SourceFiles/overview/overview_layout.cpp +++ b/Telegram/SourceFiles/overview/overview_layout.cpp @@ -188,35 +188,15 @@ ItemBase::~ItemBase() = default; void RadialProgressItem::setDocumentLinks( not_null document) { const auto context = parent()->fullId(); - const auto createSaveHandler = [&]() -> ClickHandlerPtr { - if (document->isVideoMessage()) { - return std::make_shared( - document, - context); - } else if (document->isVoiceMessage()) { - return std::make_shared( - document, - context); - } - return std::make_shared( - document, - context); - }; setLinks( - (document->isVideoMessage() - ? std::make_shared( - document, - context) - : std::make_shared( - document, - context)), - createSaveHandler(), - std::make_shared( - document, - context)); + std::make_shared(document, context), + std::make_shared(document, context), + std::make_shared(document, context)); } -void RadialProgressItem::clickHandlerActiveChanged(const ClickHandlerPtr &action, bool active) { +void RadialProgressItem::clickHandlerActiveChanged( + const ClickHandlerPtr &action, + bool active) { ItemBase::clickHandlerActiveChanged(action, active); if (action == _openl || action == _savel || action == _cancell) { if (iconAnimated()) { @@ -229,7 +209,10 @@ void RadialProgressItem::clickHandlerActiveChanged(const ClickHandlerPtr &action } } -void RadialProgressItem::setLinks(ClickHandlerPtr &&openl, ClickHandlerPtr &&savel, ClickHandlerPtr &&cancell) { +void RadialProgressItem::setLinks( + ClickHandlerPtr &&openl, + ClickHandlerPtr &&savel, + ClickHandlerPtr &&cancell) { _openl = std::move(openl); _savel = std::move(savel); _cancell = std::move(cancell); @@ -585,9 +568,7 @@ Voice::Voice( const style::OverviewFileLayout &st) : RadialProgressItem(parent) , _data(voice) -, _namel(_data->isVideoMessage() - ? std::make_shared(_data, parent->fullId()) - : std::make_shared(_data, parent->fullId())) +, _namel(std::make_shared(_data, parent->fullId())) , _st(st) { AddComponents(Info::Bit()); @@ -670,13 +651,18 @@ void Voice::paint(Painter &p, const QRect &clip, TextSelection selection, const p.setBrush(st::imageBg); p.drawEllipse(inner); } + const auto &checkLink = (_data->loading() || _data->uploading()) + ? _cancell + : (_data->canBePlayed() || loaded) + ? _openl + : _savel; if (selected) { p.setBrush((thumbLoaded || blurred) ? st::msgDateImgBgSelected : st::msgFileInBgSelected); } else if (_data->hasThumbnail()) { - auto over = ClickHandler::showAsActive(loaded ? _openl : (_data->loading() ? _cancell : _openl)); + auto over = ClickHandler::showAsActive(checkLink); p.setBrush(anim::brush(st::msgDateImgBg, st::msgDateImgBgOver, _a_iconOver.current(context->ms, over ? 1. : 0.))); } else { - auto over = ClickHandler::showAsActive(loaded ? _openl : (_data->loading() ? _cancell : _openl)); + auto over = ClickHandler::showAsActive(checkLink); p.setBrush(anim::brush(st::msgFileInBg, st::msgFileInBgOver, _a_iconOver.current(context->ms, over ? 1. : 0.))); } { @@ -690,12 +676,12 @@ void Voice::paint(Painter &p, const QRect &clip, TextSelection selection, const _radial->draw(p, rinner, st::msgFileRadialLine, bg); } - auto icon = [&] { + const auto icon = [&] { if (_data->loading() || _data->uploading()) { return &(selected ? _st.songCancelSelected : _st.songCancel); } else if (showPause) { return &(selected ? _st.songPauseSelected : _st.songPause); - } else if (_status.size() < 0 || _status.size() == FileStatusSizeLoaded) { + } else if (_data->canBePlayed()) { return &(selected ? _st.songPlaySelected : _st.songPlay); } return &(selected ? _st.songDownloadSelected : _st.songDownload); @@ -760,11 +746,11 @@ TextState Voice::getState( _st.songThumbSize, _width); if (inner.contains(point)) { - const auto link = loaded - ? _openl - : (_data->loading() || _data->uploading()) + const auto link = (_data->loading() || _data->uploading()) ? _cancell - : _openl; + : (_data->canBePlayed() || loaded) + ? _openl + : _savel; return { parent(), link }; } auto result = TextState(parent()); diff --git a/Telegram/SourceFiles/window/window_controller.cpp b/Telegram/SourceFiles/window/window_controller.cpp index c77079962..35f5d754d 100644 --- a/Telegram/SourceFiles/window/window_controller.cpp +++ b/Telegram/SourceFiles/window/window_controller.cpp @@ -644,7 +644,6 @@ void Controller::setDefaultFloatPlayerDelegate( _defaultFloatPlayerDelegate = delegate; _floatPlayers = std::make_unique( delegate); - _floatPlayers->closeEvents(); } void Controller::replaceFloatPlayerDelegate(