Skip to content

Commit

Permalink
Merge pull request xbmc#1176 from Voyager-xbmc/fix-watched-unwatched-…
Browse files Browse the repository at this point in the history
…tvshows

Fix watched-unwatched for TV shows and Seasons
  • Loading branch information
jmarshallnz committed Jul 25, 2012
2 parents cb6496e + 392cef8 commit 82b31e5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
20 changes: 16 additions & 4 deletions xbmc/video/windows/GUIWindowVideoNav.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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)
Expand All @@ -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 */)
Expand Down
2 changes: 1 addition & 1 deletion xbmc/video/windows/GUIWindowVideoNav.h
Expand Up @@ -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) {};
Expand Down
5 changes: 3 additions & 2 deletions xbmc/windows/GUIMediaWindow.cpp
Expand Up @@ -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());
Expand Down Expand Up @@ -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))
{
Expand All @@ -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++)
{
Expand Down

0 comments on commit 82b31e5

Please sign in to comment.