From 48257fc6521cc89c2934f9ceea46a07697afc6d8 Mon Sep 17 00:00:00 2001 From: CrystalP Date: Thu, 11 Jan 2024 02:52:55 -0500 Subject: [PATCH] [video] Do not lose extras of the movie added to another via Browse files --- .../resources/strings.po | 8 ++++- xbmc/video/VideoDatabase.cpp | 7 ++-- xbmc/video/VideoDatabase.h | 14 +++++++- .../dialogs/GUIDialogVideoManagerExtras.cpp | 36 +++++++++---------- .../dialogs/GUIDialogVideoManagerVersions.cpp | 22 ++++++------ 5 files changed, 54 insertions(+), 33 deletions(-) diff --git a/addons/resource.language.en_gb/resources/strings.po b/addons/resource.language.en_gb/resources/strings.po index d8d9453f1865b..625c113f7a4f2 100644 --- a/addons/resource.language.en_gb/resources/strings.po +++ b/addons/resource.language.en_gb/resources/strings.po @@ -23968,7 +23968,13 @@ msgctxt "#40037" msgid "The movie to be added has multiple versions.[CR]The type of the default version will be selected in the next dialog. The other versions will keep their current type.[CR]Do you want to continue?" msgstr "" -#empty strings with id 40038 to 40199 +#. Addition of new version: the default version of a movie with multiple versions cannot be turned into a version of another movie. +#: xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp +msgctxt "#40038" +msgid "The default version of a movie with multiple versions cannot be added to another movie. Please move or remove the other versions first." +msgstr "" + +#empty strings with id 40039 to 40199 #. Select default video version setting #: system/settings/settings.xml diff --git a/xbmc/video/VideoDatabase.cpp b/xbmc/video/VideoDatabase.cpp index b97252ae750d0..a422b7ff5c7e5 100644 --- a/xbmc/video/VideoDatabase.cpp +++ b/xbmc/video/VideoDatabase.cpp @@ -12223,7 +12223,8 @@ bool CVideoDatabase::GetDefaultVersionForVideo(VideoDbContentType itemType, bool CVideoDatabase::ConvertVideoToVersion(VideoDbContentType itemType, int dbIdSource, int dbIdTarget, - int idVideoVersion) + int idVideoVersion, + VideoAssetType assetType) { int idFile = -1; MediaType mediaType; @@ -12257,8 +12258,8 @@ bool CVideoDatabase::ConvertVideoToVersion(VideoDbContentType itemType, } // Rename the default version - ExecuteQuery( - PrepareSQL("UPDATE videoversion SET idType = %i WHERE idFile = %i", idVideoVersion, idFile)); + ExecuteQuery(PrepareSQL("UPDATE videoversion SET idType = %i, itemType = %i WHERE idFile = %i", + idVideoVersion, assetType, idFile)); CommitTransaction(); diff --git a/xbmc/video/VideoDatabase.h b/xbmc/video/VideoDatabase.h index 45cfda3402059..e7762feaf6a6d 100644 --- a/xbmc/video/VideoDatabase.h +++ b/xbmc/video/VideoDatabase.h @@ -1015,10 +1015,22 @@ class CVideoDatabase : public CDatabase CFileItemList& items, VideoAssetType videoAssetType); void GetDefaultVideoVersion(VideoDbContentType itemType, int dbId, CFileItem& item); + + /*! + * \brief Remove a video from the library and transfer all of its assets to another video of the + * same type. + * \param itemType Type of the video being converted + * \param dbIdSource id of the video being converted + * \param dbIdTarget id that the video will be attached to + * \param idVideoVersion new versiontype of the default version of the video + * \param assetType new asset type of the default version of the video + * \return true for success, false otherwise + */ bool ConvertVideoToVersion(VideoDbContentType itemType, int dbIdSource, int dbIdTarget, - int idVideoVersion); + int idVideoVersion, + VideoAssetType assetType); void SetDefaultVideoVersion(VideoDbContentType itemType, int dbId, int idFile); void SetVideoVersion(int idFile, int idVideoVersion); int AddVideoVersionType(const std::string& typeVideoVersion, diff --git a/xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp b/xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp index 027f9d3f1b9f7..e35da64f90be8 100644 --- a/xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp +++ b/xbmc/video/dialogs/GUIDialogVideoManagerExtras.cpp @@ -53,7 +53,12 @@ bool CGUIDialogVideoManagerExtras::OnMessage(CGUIMessage& message) const int control{message.GetSenderId()}; if (control == CONTROL_BUTTON_ADD_EXTRAS) { - AddVideoExtra(); + if (AddVideoExtra()) + { + // refresh data and controls + Refresh(); + UpdateControls(); + } } break; } @@ -107,6 +112,9 @@ bool CGUIDialogVideoManagerExtras::AddVideoExtra() const VideoAssetInfo newAsset{m_database.GetVideoVersionInfo(path)}; + std::string typeNewVideoVersion{ + CGUIDialogVideoManagerExtras::GenerateVideoExtra(URIUtils::GetFileName(path))}; + if (newAsset.m_idFile != -1 && newAsset.m_assetTypeId != -1) { // The video already is an asset of the movie @@ -183,16 +191,15 @@ bool CGUIDialogVideoManagerExtras::AddVideoExtra() CGUIDialogOK::ShowAndGetInput(CVariant{40015}, CVariant{40034}); return false; } - else - { - if (newAsset.m_mediaType == MediaTypeMovie) - { - // @todo: should be in a database transaction with the addition as a new asset below - m_database.DeleteMovie(newAsset.m_idMedia); - } - else - return false; - } + + const int idNewVideoVersion{m_database.AddVideoVersionType( + typeNewVideoVersion, VideoAssetTypeOwner::AUTO, VideoAssetType::EXTRA)}; + + if (idNewVideoVersion == -1) + return false; + + return m_database.ConvertVideoToVersion(itemType, newAsset.m_idMedia, dbId, + idNewVideoVersion, VideoAssetType::EXTRA); } else { @@ -212,9 +219,6 @@ bool CGUIDialogVideoManagerExtras::AddVideoExtra() CURL::GetRedacted(item.GetPath())); } - const std::string typeNewVideoVersion{ - CGUIDialogVideoManagerExtras::GenerateVideoExtra(URIUtils::GetFileName(path))}; - const int idNewVideoVersion{m_database.AddVideoVersionType( typeNewVideoVersion, VideoAssetTypeOwner::AUTO, VideoAssetType::EXTRA)}; @@ -223,10 +227,6 @@ bool CGUIDialogVideoManagerExtras::AddVideoExtra() m_database.AddExtrasVideoVersion(itemType, dbId, idNewVideoVersion, item); - // refresh data and controls - Refresh(); - UpdateControls(); - return true; } return false; diff --git a/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp b/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp index 48cee292e9106..46bb3f159765e 100644 --- a/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp +++ b/xbmc/video/dialogs/GUIDialogVideoManagerVersions.cpp @@ -383,7 +383,8 @@ bool CGUIDialogVideoManagerVersions::ChooseVideoAndConvertToVideoVersion( return false; } - return videoDb.ConvertVideoToVersion(itemType, sourceDbId, targetDbId, idVideoVersion); + return videoDb.ConvertVideoToVersion(itemType, sourceDbId, targetDbId, idVideoVersion, + VideoAssetType::VERSION); } bool CGUIDialogVideoManagerVersions::GetAllOtherMovies(const std::shared_ptr& item, @@ -557,18 +558,19 @@ bool CGUIDialogVideoManagerVersions::AddVideoVersionFilePicker() if (list.Size() > 1) { // cannot add the default version of a movie with multiple versions to another movie - CGUIDialogOK::ShowAndGetInput(CVariant{40014}, CVariant{40033}); + CGUIDialogOK::ShowAndGetInput(CVariant{40014}, CVariant{40038}); return false; } + + const int idNewVideoVersion{ChooseVideoAsset(m_videoAsset, VideoAssetType::VERSION)}; + if (idNewVideoVersion != -1) + { + return m_database.ConvertVideoToVersion(itemType, newAsset.m_idMedia, dbId, + idNewVideoVersion, VideoAssetType::VERSION); + } else { - if (newAsset.m_mediaType == MediaTypeMovie) - { - // @todo: should be in a database transaction with the addition as a new asset below - m_database.DeleteMovie(newAsset.m_idMedia); - } - else - return false; + return false; } } else @@ -645,7 +647,7 @@ bool CGUIDialogVideoManagerVersions::AddSimilarMovieAsVersion( const int sourceDbId{itemMovie->GetVideoInfoTag()->m_iDbId}; const int targetDbId{m_videoAsset->GetVideoInfoTag()->m_iDbId}; return videoDb.ConvertVideoToVersion(VideoDbContentType::MOVIES, sourceDbId, targetDbId, - idVideoVersion); + idVideoVersion, VideoAssetType::VERSION); } bool CGUIDialogVideoManagerVersions::PostProcessList(CFileItemList& list, int dbId)