mirror of https://github.com/procxx/kepka.git
				
				
				
			Remove DocumentData::actionOnLoad. Fix GIF open.
This commit is contained in:
		
							parent
							
								
									261720c941
								
							
						
					
					
						commit
						c063d94aa5
					
				|  | @ -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"; | ||||
|  |  | |||
|  | @ -289,108 +289,91 @@ QString documentSaveFilename(const DocumentData *data, bool forceSavingAs = fals | |||
| void DocumentOpenClickHandler::Open( | ||||
| 		Data::FileOrigin origin, | ||||
| 		not_null<DocumentData*> 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<DocumentData*> 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 { | ||||
|  |  | |||
|  | @ -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<DocumentData*> 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<DocumentData*> 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; | ||||
|  |  | |||
|  | @ -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<char, QImage>; | |||
| // [0] == -1 -- counting, [0] == -2 -- could not count
 | ||||
| using VoiceWaveform = QVector<signed char>; | ||||
| 
 | ||||
| enum ActionOnLoad { | ||||
| 	ActionOnLoadNone, | ||||
| 	ActionOnLoadOpen, | ||||
| 	ActionOnLoadOpenWith, | ||||
| 	ActionOnLoadPlayInline | ||||
| }; | ||||
| 
 | ||||
| enum LocationType { | ||||
| 	UnknownFileLocation = 0, | ||||
| 	// 1, 2, etc are used as "version" value in mediaKey() method.
 | ||||
|  |  | |||
|  | @ -1095,8 +1095,7 @@ void InnerWidget::saveDocumentToFile(DocumentData *document) { | |||
| 	DocumentSaveClickHandler::Save( | ||||
| 		Data::FileOrigin(), | ||||
| 		document, | ||||
| 		nullptr, | ||||
| 		true); | ||||
| 		DocumentSaveClickHandler::Mode::ToNewFile); | ||||
| } | ||||
| 
 | ||||
| void InnerWidget::copyContextImage(PhotoData *photo) { | ||||
|  |  | |||
|  | @ -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()); | ||||
| 					} | ||||
| 				} | ||||
|  |  | |||
|  | @ -82,7 +82,7 @@ void HistoryDocument::createComponents(bool caption) { | |||
| 		mask |= HistoryDocumentCaptioned::Bit(); | ||||
| 	} | ||||
| 	UpdateComponents(mask); | ||||
| 	if (auto thumbed = Get<HistoryDocumentThumbed>()) { | ||||
| 	if (const auto thumbed = Get<HistoryDocumentThumbed>()) { | ||||
| 		thumbed->_linksavel = std::make_shared<DocumentSaveClickHandler>( | ||||
| 			_data, | ||||
| 			_parent->data()->fullId()); | ||||
|  | @ -90,7 +90,7 @@ void HistoryDocument::createComponents(bool caption) { | |||
| 			_data, | ||||
| 			_parent->data()->fullId()); | ||||
| 	} | ||||
| 	if (auto voice = Get<HistoryDocumentVoice>()) { | ||||
| 	if (const auto voice = Get<HistoryDocumentVoice>()) { | ||||
| 		voice->_seekl = std::make_shared<VoiceSeekClickHandler>( | ||||
| 			_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); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -101,23 +101,11 @@ void HistoryFileMedia::checkAnimationFinished() const { | |||
| } | ||||
| void HistoryFileMedia::setDocumentLinks( | ||||
| 		not_null<DocumentData*> document, | ||||
| 		not_null<HistoryItem*> realParent, | ||||
| 		bool inlinegif) { | ||||
| 	FileClickHandlerPtr open, save; | ||||
| 		not_null<HistoryItem*> realParent) { | ||||
| 	const auto context = realParent->fullId(); | ||||
| 	if (inlinegif) { | ||||
| 		open = std::make_shared<GifOpenClickHandler>(document, context); | ||||
| 	} else { | ||||
| 		open = std::make_shared<DocumentOpenClickHandler>(document, context); | ||||
| 	} | ||||
| 	if (inlinegif) { | ||||
| 		save = std::make_shared<GifOpenClickHandler>(document, context); | ||||
| 	} else { | ||||
| 		save = std::make_shared<DocumentSaveClickHandler>(document, context); | ||||
| 	} | ||||
| 	setLinks( | ||||
| 		std::move(open), | ||||
| 		std::move(save), | ||||
| 		std::make_shared<DocumentOpenClickHandler>(document, context), | ||||
| 		std::make_shared<DocumentSaveClickHandler>(document, context), | ||||
| 		std::make_shared<DocumentCancelClickHandler>(document, context)); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -49,8 +49,7 @@ protected: | |||
| 		FileClickHandlerPtr &&cancell); | ||||
| 	void setDocumentLinks( | ||||
| 		not_null<DocumentData*> document, | ||||
| 		not_null<HistoryItem*> realParent, | ||||
| 		bool inlinegif = false); | ||||
| 		not_null<HistoryItem*> realParent); | ||||
| 
 | ||||
| 	// >= 0 will contain download / upload string, _statusSize = loaded bytes
 | ||||
| 	// < 0 will contain played string, _statusSize = -(seconds + 1) played
 | ||||
|  |  | |||
|  | @ -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<DocumentOpenClickHandler>( | ||||
| 			_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<HistoryItem*> 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) { | ||||
|  |  | |||
|  | @ -29,8 +29,6 @@ public: | |||
| 		not_null<Element*> parent, | ||||
| 		not_null<DocumentData*> document); | ||||
| 
 | ||||
| 	void refreshParentId(not_null<HistoryItem*> 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<DocumentData*> _data; | ||||
| 	FileClickHandlerPtr _openInMediaviewLink; | ||||
| 	int _thumbw = 1; | ||||
| 	int _thumbh = 1; | ||||
| 	Text _caption; | ||||
|  |  | |||
|  | @ -123,7 +123,10 @@ void AddSaveDocumentAction( | |||
| 		Data::FileOrigin origin, | ||||
| 		not_null<DocumentData*> document) { | ||||
| 	const auto save = [=] { | ||||
| 		DocumentSaveClickHandler::Save(origin, document, nullptr, true); | ||||
| 		DocumentSaveClickHandler::Save( | ||||
| 			origin, | ||||
| 			document, | ||||
| 			DocumentSaveClickHandler::Mode::ToNewFile); | ||||
| 	}; | ||||
| 	menu->addAction( | ||||
| 		lang(document->isVideoFile() | ||||
|  |  | |||
|  | @ -1277,8 +1277,7 @@ void ListWidget::showContextMenu( | |||
| 							DocumentSaveClickHandler::Save( | ||||
| 								itemFullId, | ||||
| 								document, | ||||
| 								App::histItemById(itemFullId), | ||||
| 								true); | ||||
| 								DocumentSaveClickHandler::Mode::ToNewFile); | ||||
| 						}); | ||||
| 					_contextMenu->addAction( | ||||
| 						lang(isVideo | ||||
|  |  | |||
|  | @ -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); | ||||
| 
 | ||||
|  |  | |||
|  | @ -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()) { | ||||
|  |  | |||
|  | @ -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()) { | ||||
|  |  | |||
|  | @ -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<void()> _closeCallback; | ||||
| 
 | ||||
|  |  | |||
|  | @ -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; | ||||
|  |  | |||
|  | @ -188,35 +188,15 @@ ItemBase::~ItemBase() = default; | |||
| void RadialProgressItem::setDocumentLinks( | ||||
| 		not_null<DocumentData*> document) { | ||||
| 	const auto context = parent()->fullId(); | ||||
| 	const auto createSaveHandler = [&]() -> ClickHandlerPtr { | ||||
| 		if (document->isVideoMessage()) { | ||||
| 			return std::make_shared<GifOpenClickHandler>( | ||||
| 				document, | ||||
| 				context); | ||||
| 		} else if (document->isVoiceMessage()) { | ||||
| 			return std::make_shared<DocumentOpenClickHandler>( | ||||
| 				document, | ||||
| 				context); | ||||
| 		} | ||||
| 		return std::make_shared<DocumentSaveClickHandler>( | ||||
| 			document, | ||||
| 			context); | ||||
| 	}; | ||||
| 	setLinks( | ||||
| 		(document->isVideoMessage() | ||||
| 			? std::make_shared<GifOpenClickHandler>( | ||||
| 				document, | ||||
| 				context) | ||||
| 			: std::make_shared<DocumentOpenClickHandler>( | ||||
| 				document, | ||||
| 				context)), | ||||
| 		createSaveHandler(), | ||||
| 		std::make_shared<DocumentCancelClickHandler>( | ||||
| 			document, | ||||
| 			context)); | ||||
| 		std::make_shared<DocumentOpenClickHandler>(document, context), | ||||
| 		std::make_shared<DocumentSaveClickHandler>(document, context), | ||||
| 		std::make_shared<DocumentCancelClickHandler>(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<GifOpenClickHandler>(_data, parent->fullId()) | ||||
| 	: std::make_shared<DocumentOpenClickHandler>(_data, parent->fullId())) | ||||
| , _namel(std::make_shared<DocumentOpenClickHandler>(_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()); | ||||
|  |  | |||
|  | @ -644,7 +644,6 @@ void Controller::setDefaultFloatPlayerDelegate( | |||
| 	_defaultFloatPlayerDelegate = delegate; | ||||
| 	_floatPlayers = std::make_unique<Media::Player::FloatController>( | ||||
| 		delegate); | ||||
| 	_floatPlayers->closeEvents(); | ||||
| } | ||||
| 
 | ||||
| void Controller::replaceFloatPlayerDelegate( | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue