From 392cef8b75412ba168e88699e69da68b02efaa6c Mon Sep 17 00:00:00 2001 From: Voyager-xbmc Date: Tue, 17 Jul 2012 21:51:00 +0200 Subject: [PATCH] fix watched-unwatched for TV shows and episodes --- xbmc/video/windows/GUIWindowVideoNav.cpp | 20 ++++++++++++++++---- xbmc/video/windows/GUIWindowVideoNav.h | 2 +- xbmc/windows/GUIMediaWindow.cpp | 5 +++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/xbmc/video/windows/GUIWindowVideoNav.cpp b/xbmc/video/windows/GUIWindowVideoNav.cpp index 18ecaada45e1b..6e3ecc658ffe5 100644 --- a/xbmc/video/windows/GUIWindowVideoNav.cpp +++ b/xbmc/video/windows/GUIWindowVideoNav.cpp @@ -522,9 +522,9 @@ void CGUIWindowVideoNav::UpdateButtons() bool CGUIWindowVideoNav::GetFilteredItems(const CStdString &filter, CFileItemList &items) { - bool result = CGUIMediaWindow::GetFilteredItems(filter, items); - ApplyWatchedFilter(items); - return result || g_settings.GetWatchMode(m_vecItems->GetContent()) != VIDEO_SHOW_ALL; + bool listchanged = CGUIMediaWindow::GetFilteredItems(filter, items); + listchanged |= ApplyWatchedFilter(items); + return listchanged; } /// \brief Search for names, genres, artists, directors, and plots with search string \e strSearch in the @@ -1564,8 +1564,9 @@ CStdString CGUIWindowVideoNav::GetStartFolder(const CStdString &dir) return CGUIWindowVideoBase::GetStartFolder(dir); } -void CGUIWindowVideoNav::ApplyWatchedFilter(CFileItemList &items) +bool CGUIWindowVideoNav::ApplyWatchedFilter(CFileItemList &items) { + bool listchanged = false; CVideoDatabaseDirectory dir; NODE_TYPE node = dir.GetDirectoryChildType(items.GetPath()); @@ -1599,7 +1600,10 @@ void CGUIWindowVideoNav::ApplyWatchedFilter(CFileItemList &items) item->GetVideoInfoTag()->m_iEpisode = (int)item->GetProperty("unwatchedepisodes").asInteger(); if (watchMode == VIDEO_SHOW_WATCHED) item->GetVideoInfoTag()->m_iEpisode = (int)item->GetProperty("watchedepisodes").asInteger(); + if (watchMode == VIDEO_SHOW_ALL) + item->GetVideoInfoTag()->m_iEpisode = (int)item->GetProperty("totalepisodes").asInteger(); item->SetProperty("numepisodes", item->GetVideoInfoTag()->m_iEpisode); + listchanged = true; } if (filterWatched) @@ -1609,9 +1613,17 @@ void CGUIWindowVideoNav::ApplyWatchedFilter(CFileItemList &items) { items.Remove(i); i--; + listchanged = true; } } } + + if(node == NODE_TYPE_TITLE_TVSHOWS || node == NODE_TYPE_SEASONS) + // the watched filter may change the "numepisodes" property which is reflected in the TV_SHOWS and SEASONS nodes + // therefore, the items labels have to be refreshed, and possibly the list needs resorting as well. + FormatAndSort(items); + + return listchanged; } bool CGUIWindowVideoNav::GetItemsForTag(const CStdString &strHeading, const std::string &type, CFileItemList &items, int idTag /* = -1 */, bool showAll /* = true */) diff --git a/xbmc/video/windows/GUIWindowVideoNav.h b/xbmc/video/windows/GUIWindowVideoNav.h index 631851ba4b2a8..e7b22561773ba 100644 --- a/xbmc/video/windows/GUIWindowVideoNav.h +++ b/xbmc/video/windows/GUIWindowVideoNav.h @@ -49,7 +49,7 @@ class CGUIWindowVideoNav : public CGUIWindowVideoBase */ void LoadVideoInfo(CFileItemList &items); - void ApplyWatchedFilter(CFileItemList &items); + bool ApplyWatchedFilter(CFileItemList &items); virtual bool GetFilteredItems(const CStdString &filter, CFileItemList &items); virtual void OnItemLoaded(CFileItem* pItem) {}; diff --git a/xbmc/windows/GUIMediaWindow.cpp b/xbmc/windows/GUIMediaWindow.cpp index 627a39621e803..ab0eefd67affb 100644 --- a/xbmc/windows/GUIMediaWindow.cpp +++ b/xbmc/windows/GUIMediaWindow.cpp @@ -853,6 +853,7 @@ void CGUIMediaWindow::OnPrepareFileItems(CFileItemList &items) // to modify the fileitems. Eg. to modify the item label void CGUIMediaWindow::OnFinalizeFileItems(CFileItemList &items) { + m_unfilteredItems->SetPath(items.GetPath()); // use the original path - it'll likely be relied on for other things later. m_unfilteredItems->Append(items); CStdString filter(GetProperty("filter").asString()); @@ -1523,7 +1524,7 @@ void CGUIMediaWindow::OnFilterItems(const CStdString &filter) m_viewControl.Clear(); - CFileItemList items; + CFileItemList items(m_unfilteredItems->GetPath()); // use the original path - it'll likely be relied on for other things later. items.Append(*m_unfilteredItems); if (GetFilteredItems(filter, items)) { @@ -1546,7 +1547,7 @@ bool CGUIMediaWindow::GetFilteredItems(const CStdString &filter, CFileItemList & if (trimmedFilter.IsEmpty()) return true; - CFileItemList filteredItems; + CFileItemList filteredItems(items.GetPath()); // use the original path - it'll likely be relied on for other things later. bool numericMatch = StringUtils::IsNaturalNumber(trimmedFilter); for (int i = 0; i < items.Size(); i++) {