Skip to content

Commit

Permalink
Merge pull request xbmc#5804 from xhaggi/fix-gui-viewstate-items-refe…
Browse files Browse the repository at this point in the history
…rence

 [RFC][gui] fix: view state holds wrong file item list while operating with it
  • Loading branch information
xhaggi committed Jan 22, 2015
2 parents 40a8a90 + 9fcff9a commit 8e3fae6
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions xbmc/windows/GUIMediaWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,7 @@ bool CGUIMediaWindow::GetDirectory(const std::string &strDirectory, CFileItemLis
m_history.RemoveParentPath();
}

// update the view state to the currently fetched items
// TODO we should remove the second call m_guiState.reset() in Update() and pass the right file item ref here
// update the view state's reference to the current items
m_guiState.reset(CGUIViewState::GetViewState(GetID(), items));

if (m_guiState.get() && !m_guiState->HideParentDirItems() && !items.GetPath().empty())
Expand Down Expand Up @@ -752,8 +751,8 @@ bool CGUIMediaWindow::Update(const std::string &strDirectory, bool updateFilterP
if (canfilter && url.HasOption("filter"))
directory = RemoveParameterFromPath(directory, "filter");

CFileItemList items;
if (!GetDirectory(directory, items))
ClearFileItems();
if (!GetDirectory(directory, *m_vecItems))
{
CLog::Log(LOGERROR,"CGUIMediaWindow::GetDirectory(%s) failed", url.GetRedacted().c_str());
// Try to return to the previous directory, if not the same
Expand All @@ -766,14 +765,11 @@ bool CGUIMediaWindow::Update(const std::string &strDirectory, bool updateFilterP
return false;
}

if (items.GetLabel().empty())
items.SetLabel(CUtil::GetTitleFromPath(items.GetPath(), true));

ClearFileItems();
m_vecItems->Copy(items);
if (m_vecItems->GetLabel().empty())
m_vecItems->SetLabel(CUtil::GetTitleFromPath(m_vecItems->GetPath(), true));

// check the given path for filter data
UpdateFilterPath(strDirectory, items, updateFilterPath);
UpdateFilterPath(strDirectory, *m_vecItems, updateFilterPath);

// if we're getting the root source listing
// make sure the path history is clean
Expand Down Expand Up @@ -826,8 +822,6 @@ bool CGUIMediaWindow::Update(const std::string &strDirectory, bool updateFilterP

m_vecItems->FillInDefaultIcons();

m_guiState.reset(CGUIViewState::GetViewState(GetID(), *m_vecItems));

// remember the original (untouched) list of items (for filtering etc)
m_unfilteredItems->SetPath(m_vecItems->GetPath()); // use the original path - it'll likely be relied on for other things later.
m_unfilteredItems->Append(*m_vecItems);
Expand Down

0 comments on commit 8e3fae6

Please sign in to comment.