From cffda47f046f3170d84c0b8618d763e8e2b97380 Mon Sep 17 00:00:00 2001 From: montellese Date: Tue, 12 Nov 2013 13:09:49 +0100 Subject: [PATCH] context menu: move "Remove from library" to "Manage..." sub menu --- xbmc/music/windows/GUIWindowMusicNav.cpp | 2 +- xbmc/video/dialogs/GUIDialogVideoInfo.cpp | 162 ++++++++++++++++++++++++++++++ xbmc/video/dialogs/GUIDialogVideoInfo.h | 3 + xbmc/video/windows/GUIWindowVideoNav.cpp | 123 +---------------------- xbmc/video/windows/GUIWindowVideoNav.h | 2 - 5 files changed, 168 insertions(+), 124 deletions(-) diff --git a/xbmc/music/windows/GUIWindowMusicNav.cpp b/xbmc/music/windows/GUIWindowMusicNav.cpp index 38148b6..d3d2aac 100644 --- a/xbmc/music/windows/GUIWindowMusicNav.cpp +++ b/xbmc/music/windows/GUIWindowMusicNav.cpp @@ -671,7 +671,7 @@ bool CGUIWindowMusicNav::OnContextButton(int itemNumber, CONTEXT_BUTTON button) } else { - CGUIWindowVideoNav::DeleteItem(item.get()); + CGUIDialogVideoInfo::DeleteVideoItemFromDatabase(item); CUtil::DeleteVideoDatabaseDirectoryCache(); } Refresh(); diff --git a/xbmc/video/dialogs/GUIDialogVideoInfo.cpp b/xbmc/video/dialogs/GUIDialogVideoInfo.cpp index bed1532..edbba07 100644 --- a/xbmc/video/dialogs/GUIDialogVideoInfo.cpp +++ b/xbmc/video/dialogs/GUIDialogVideoInfo.cpp @@ -53,11 +53,14 @@ #include "video/VideoThumbLoader.h" #include "filesystem/Directory.h" #include "filesystem/VideoDatabaseDirectory.h" +#include "filesystem/VideoDatabaseDirectory/QueryParams.h" #ifdef HAS_UPNP #include "network/upnp/UPnP.h" #endif +#include "utils/FileUtils.h" using namespace std; +using namespace XFILE::VIDEODATABASEDIRECTORY; using namespace XFILE; #define CONTROL_IMAGE 3 @@ -982,6 +985,9 @@ int CGUIDialogVideoInfo::ManageVideoItem(const CFileItemPtr &item) item->GetVideoInfoTag()->m_iBookmarkId > 0) buttons.Add(CONTEXT_BUTTON_UNLINK_BOOKMARK, 20405); + if (!item->m_bIsFolder || type == VIDEODB_CONTENT_TVSHOWS) + buttons.Add(CONTEXT_BUTTON_DELETE, 646); + bool result = false; int button = CGUIDialogContextMenu::ShowAndGetChoice(buttons); if (button >= 0) @@ -1025,6 +1031,10 @@ int CGUIDialogVideoInfo::ManageVideoItem(const CFileItemPtr &item) result = true; break; + case CONTEXT_BUTTON_DELETE: + result = DeleteVideoItem(item); + break; + default: result = false; break; @@ -1042,6 +1052,9 @@ int CGUIDialogVideoInfo::ManageVideoItem(const CFileItemPtr &item) //Add change a title's name bool CGUIDialogVideoInfo::UpdateVideoItemTitle(const CFileItemPtr &pItem) { + if (!pItem->HasVideoInfoTag()) + return false; + // dont allow update while scanning if (g_application.IsVideoScanning()) { @@ -1131,6 +1144,155 @@ bool CGUIDialogVideoInfo::MarkWatched(const CFileItemPtr &item, bool bMark) return true; } +bool CGUIDialogVideoInfo::CanDeleteVideoItem(const CFileItemPtr &item) +{ + if (item == NULL || !item->HasVideoInfoTag()) + return false; + + CQueryParams params; + CVideoDatabaseDirectory::GetQueryParams(item->GetPath(), params); + + return params.GetMovieId() != -1 || + params.GetEpisodeId() != -1 || + params.GetMVideoId() != -1 || + (params.GetTvShowId() != -1 && params.GetSeason() <= -1 && + !CVideoDatabaseDirectory::IsAllItem(item->GetPath())); +} + +bool CGUIDialogVideoInfo::DeleteVideoItemFromDatabase(const CFileItemPtr &item, bool unavailable /* = false */) +{ + if (!item->HasVideoInfoTag() || !CanDeleteVideoItem(item)) + return false; + + // dont allow update while scanning + if (g_application.IsVideoScanning()) + { + CGUIDialogOK::ShowAndGetInput(257, 0, 14057, 0); + return false; + } + + CGUIDialogYesNo* pDialog = (CGUIDialogYesNo*)g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO); + if (pDialog == NULL) + return false; + + int heading = -1; + VIDEODB_CONTENT_TYPE type = (VIDEODB_CONTENT_TYPE)item->GetVideoContentType(); + switch (type) + { + case VIDEODB_CONTENT_MOVIES: + heading = 432; + break; + case VIDEODB_CONTENT_EPISODES: + heading = 20362; + break; + case VIDEODB_CONTENT_TVSHOWS: + heading = 20363; + break; + case VIDEODB_CONTENT_MUSICVIDEOS: + heading = 20392; + break; + + default: + return false; + } + + pDialog->SetHeading(heading); + + if (unavailable) + { + pDialog->SetLine(0, g_localizeStrings.Get(662)); + pDialog->SetLine(1, g_localizeStrings.Get(663)); + } + else + { + pDialog->SetLine(0, StringUtils::Format(g_localizeStrings.Get(433), item->GetLabel().c_str())); + pDialog->SetLine(1, ""); + } + pDialog->SetLine(2, ""); + pDialog->DoModal(); + + if (!pDialog->IsConfirmed()) + return false; + + CStdString path; + CVideoDatabase database; + database.Open(); + + database.GetFilePathById(item->GetVideoInfoTag()->m_iDbId, path, type); + if (path.empty()) + return false; + + switch (type) + { + case VIDEODB_CONTENT_MOVIES: + database.DeleteMovie(path); + break; + case VIDEODB_CONTENT_EPISODES: + database.DeleteEpisode(path, item->GetVideoInfoTag()->m_iDbId); + break; + case VIDEODB_CONTENT_TVSHOWS: + database.DeleteTvShow(path); + break; + case VIDEODB_CONTENT_MUSICVIDEOS: + database.DeleteMusicVideo(path); + break; + + default: + return false; + } + + if (type == VIDEODB_CONTENT_TVSHOWS) + database.SetPathHash(path,""); + else + database.SetPathHash(URIUtils::GetDirectory(path), ""); + + return true; +} + +bool CGUIDialogVideoInfo::DeleteVideoItem(const CFileItemPtr &item, bool unavailable /* = false */) +{ + // delete the video item from the database + if (!DeleteVideoItemFromDatabase(item, unavailable)) + return false; + + bool result = true; + // check if the user is allowed to delete the actual file as well + if ((CProfilesManager::Get().GetCurrentProfile().getLockMode() == LOCK_MODE_EVERYONE || + !CProfilesManager::Get().GetCurrentProfile().filesLocked() || + g_passwordManager.IsMasterLockUnlocked(true)) && + CSettings::Get().GetBool("filelists.allowfiledeletion")) + { + CStdString strDeletePath = item->GetVideoInfoTag()->GetPath(); + + if (URIUtils::GetFileName(strDeletePath).Equals("VIDEO_TS.IFO")) + { + strDeletePath = URIUtils::GetDirectory(strDeletePath); + if (StringUtils::EndsWithNoCase(strDeletePath, "video_ts/")) + { + URIUtils::RemoveSlashAtEnd(strDeletePath); + strDeletePath = URIUtils::GetDirectory(strDeletePath); + } + } + if (URIUtils::HasSlashAtEnd(strDeletePath)) + item->m_bIsFolder = true; + + // check if the file/directory can be deleted + if (CUtil::SupportsWriteFileOperations(strDeletePath)) + { + item->SetPath(strDeletePath); + + // HACK: stacked files need to be treated as folders in order to be deleted + if (item->IsStack()) + item->m_bIsFolder = true; + result = CFileUtils::DeleteItem(item); + } + } + + CUtil::DeleteVideoDatabaseDirectoryCache(); + + return result; +} + bool CGUIDialogVideoInfo::GetMoviesForSet(const CFileItem *setItem, CFileItemList &originalMovies, CFileItemList &selectedMovies) { CVideoDatabase videodb; diff --git a/xbmc/video/dialogs/GUIDialogVideoInfo.h b/xbmc/video/dialogs/GUIDialogVideoInfo.h index 2ce4aca..d69d768 100644 --- a/xbmc/video/dialogs/GUIDialogVideoInfo.h +++ b/xbmc/video/dialogs/GUIDialogVideoInfo.h @@ -49,6 +49,9 @@ public: static int ManageVideoItem(const CFileItemPtr &item); static bool UpdateVideoItemTitle(const CFileItemPtr &pItem); static bool MarkWatched(const CFileItemPtr &item, bool bMark); + static bool CanDeleteVideoItem(const CFileItemPtr &item); + static bool DeleteVideoItemFromDatabase(const CFileItemPtr &item, bool unavailable = false); + static bool DeleteVideoItem(const CFileItemPtr &item, bool unavailable = false); static bool GetMoviesForSet(const CFileItem *setItem, CFileItemList &originalMovies, CFileItemList &selectedMovies); static bool GetSetForMovie(const CFileItem *movieItem, CFileItemPtr &selectedSet); diff --git a/xbmc/video/windows/GUIWindowVideoNav.cpp b/xbmc/video/windows/GUIWindowVideoNav.cpp index 21b3a12..c98378a 100644 --- a/xbmc/video/windows/GUIWindowVideoNav.cpp +++ b/xbmc/video/windows/GUIWindowVideoNav.cpp @@ -645,21 +645,6 @@ void CGUIWindowVideoNav::OnInfo(CFileItem* pItem, ADDON::ScraperPtr& scraper) CGUIWindowVideoBase::OnInfo(pItem,scraper); } -bool CGUIWindowVideoNav::CanDelete(const CStdString& strPath) -{ - CQueryParams params; - CVideoDatabaseDirectory::GetQueryParams(strPath,params); - - if (params.GetMovieId() != -1 || - params.GetEpisodeId() != -1 || - params.GetMVideoId() != -1 || - (params.GetTvShowId() != -1 && params.GetSeason() <= -1 - && !CVideoDatabaseDirectory::IsAllItem(strPath))) - return true; - - return false; -} - void CGUIWindowVideoNav::OnDeleteItem(CFileItemPtr pItem) { if (m_vecItems->IsParentFolder()) @@ -719,114 +704,13 @@ void CGUIWindowVideoNav::OnDeleteItem(CFileItemPtr pItem) } else { - if (!DeleteItem(pItem.get())) + if (!CGUIDialogVideoInfo::DeleteVideoItem(pItem)) return; - - CStdString strDeletePath; - if (pItem->m_bIsFolder) - strDeletePath=pItem->GetVideoInfoTag()->m_strPath; - else - strDeletePath=pItem->GetVideoInfoTag()->m_strFileNameAndPath; - - if (URIUtils::GetFileName(strDeletePath).Equals("VIDEO_TS.IFO")) - { - strDeletePath = URIUtils::GetDirectory(strDeletePath); - if (StringUtils::EndsWithNoCase(strDeletePath, "video_ts/")) - { - URIUtils::RemoveSlashAtEnd(strDeletePath); - strDeletePath = URIUtils::GetDirectory(strDeletePath); - } - } - if (URIUtils::HasSlashAtEnd(strDeletePath)) - pItem->m_bIsFolder=true; - - if (CSettings::Get().GetBool("filelists.allowfiledeletion") && - CUtil::SupportsWriteFileOperations(strDeletePath)) - { - pItem->SetPath(strDeletePath); - CGUIWindowVideoBase::OnDeleteItem(pItem); - } } CUtil::DeleteVideoDatabaseDirectoryCache(); } -bool CGUIWindowVideoNav::DeleteItem(CFileItem* pItem, bool bUnavailable /* = false */) -{ - if (!pItem->HasVideoInfoTag() || !CanDelete(pItem->GetPath())) - return false; - - VIDEODB_CONTENT_TYPE iType=VIDEODB_CONTENT_MOVIES; - if (pItem->HasVideoInfoTag() && !pItem->GetVideoInfoTag()->m_strShowTitle.empty()) - iType = VIDEODB_CONTENT_TVSHOWS; - if (pItem->HasVideoInfoTag() && pItem->GetVideoInfoTag()->m_iSeason > -1 && !pItem->m_bIsFolder) - iType = VIDEODB_CONTENT_EPISODES; - if (pItem->HasVideoInfoTag() && !pItem->GetVideoInfoTag()->m_artist.empty()) - iType = VIDEODB_CONTENT_MUSICVIDEOS; - - // dont allow update while scanning - if (g_application.IsVideoScanning()) - { - CGUIDialogOK::ShowAndGetInput(257, 0, 14057, 0); - return false; - } - - - CGUIDialogYesNo* pDialog = (CGUIDialogYesNo*)g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO); - if (!pDialog) - return false; - if (iType == VIDEODB_CONTENT_MOVIES) - pDialog->SetHeading(432); - if (iType == VIDEODB_CONTENT_EPISODES) - pDialog->SetHeading(20362); - if (iType == VIDEODB_CONTENT_TVSHOWS) - pDialog->SetHeading(20363); - if (iType == VIDEODB_CONTENT_MUSICVIDEOS) - pDialog->SetHeading(20392); - - if(bUnavailable) - { - pDialog->SetLine(0, g_localizeStrings.Get(662)); - pDialog->SetLine(1, g_localizeStrings.Get(663)); - pDialog->SetLine(2, "");; - pDialog->DoModal(); - } - else - { - CStdString strLine = StringUtils::Format(g_localizeStrings.Get(433), pItem->GetLabel().c_str()); - pDialog->SetLine(0, strLine); - pDialog->SetLine(1, ""); - pDialog->SetLine(2, "");; - pDialog->DoModal(); - } - - if (!pDialog->IsConfirmed()) - return false; - - CStdString path; - CVideoDatabase database; - database.Open(); - - database.GetFilePathById(pItem->GetVideoInfoTag()->m_iDbId, path, iType); - if (path.empty()) - return false; - if (iType == VIDEODB_CONTENT_MOVIES) - database.DeleteMovie(path); - if (iType == VIDEODB_CONTENT_EPISODES) - database.DeleteEpisode(path, pItem->GetVideoInfoTag()->m_iDbId); - if (iType == VIDEODB_CONTENT_TVSHOWS) - database.DeleteTvShow(path); - if (iType == VIDEODB_CONTENT_MUSICVIDEOS) - database.DeleteMusicVideo(path); - - if (iType == VIDEODB_CONTENT_TVSHOWS) - database.SetPathHash(path,""); - else - database.SetPathHash(URIUtils::GetDirectory(path), ""); - - return true; -} - void CGUIWindowVideoNav::GetContextButtons(int itemNumber, CContextButtons &buttons) { CFileItemPtr item; @@ -989,9 +873,6 @@ void CGUIWindowVideoNav::GetContextButtons(int itemNumber, CContextButtons &butt else buttons.Add(CONTEXT_BUTTON_SET_ACTOR_THUMB, 20403); } - if (item->IsVideoDb() && item->HasVideoInfoTag() && - (!item->m_bIsFolder || node == NODE_TYPE_TITLE_TVSHOWS)) - buttons.Add(CONTEXT_BUTTON_DELETE, 646); } if (!m_vecItems->IsVideoDb() && !m_vecItems->IsVirtualDirectoryRoot()) @@ -1423,7 +1304,7 @@ bool CGUIWindowVideoNav::OnClick(int iItem) if (!item->m_bIsFolder && item->IsVideoDb() && !item->Exists()) { CLog::Log(LOGDEBUG, "%s called on '%s' but file doesn't exist", __FUNCTION__, item->GetPath().c_str()); - if (!DeleteItem(item.get(), true)) + if (!CGUIDialogVideoInfo::DeleteVideoItemFromDatabase(item, true)) return true; // update list diff --git a/xbmc/video/windows/GUIWindowVideoNav.h b/xbmc/video/windows/GUIWindowVideoNav.h index c17ce6e..f4f5990 100644 --- a/xbmc/video/windows/GUIWindowVideoNav.h +++ b/xbmc/video/windows/GUIWindowVideoNav.h @@ -35,8 +35,6 @@ public: virtual bool OnMessage(CGUIMessage& message); virtual void OnInfo(CFileItem* pItem, ADDON::ScraperPtr &info); - static bool CanDelete(const CStdString& strPath); - static bool DeleteItem(CFileItem* pItem, bool bUnavailable=false); /*! \brief Load video information from the database for these items (public static version) Useful for grabbing information for file listings, from watched status to full metadata -- 2.7.4