Skip to content

Commit

Permalink
media library: adjust the paths and the history to be able to return …
Browse files Browse the repository at this point in the history
…to a filtered list
  • Loading branch information
Montellese committed Oct 8, 2012
1 parent b027242 commit 9a1699b
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 9 deletions.
29 changes: 28 additions & 1 deletion xbmc/music/windows/GUIWindowMusicBase.cpp
Expand Up @@ -1314,11 +1314,38 @@ void CGUIWindowMusicBase::OnRetrieveMusicInfo(CFileItemList& items)

bool CGUIWindowMusicBase::GetDirectory(const CStdString &strDirectory, CFileItemList &items)
{
CStdString directory = strDirectory;

// check if the path contains a filter and if so load it and
// remove it from the path to get proper GUI view states etc
CSmartPlaylist filterXsp;
CMusicDbUrl musicUrl;
if (musicUrl.FromString(strDirectory))
{
CVariant filter;
if (musicUrl.GetOption("filter", filter))
{
// load the filter and if it's type does not match the
// path's item type reset it
if (filterXsp.LoadFromJson(filter.asString()) && !filterXsp.GetType().Equals(musicUrl.GetType().c_str()))
filterXsp.Reset();

// remove the "filter" option from the path
musicUrl.AddOption("filter", "");
}
directory = musicUrl.ToString();
}

items.SetThumbnailImage("");
bool bResult = CGUIMediaWindow::GetDirectory(strDirectory,items);
bool bResult = CGUIMediaWindow::GetDirectory(directory, items);
if (bResult)
CMusicThumbLoader::FillThumb(items);

// (re-)apply the previously retrieved filter
// because it was reset in CGUIMediaWindow::GetDirectory()
if (!filterXsp.IsEmpty())
m_filter = filterXsp;

// add in the "New Playlist" item if we're in the playlists folder
if ((items.GetPath() == "special://musicplaylists/") && !items.Contains("newplaylist://"))
{
Expand Down
31 changes: 29 additions & 2 deletions xbmc/video/windows/GUIWindowVideoBase.cpp
Expand Up @@ -1783,7 +1783,34 @@ bool CGUIWindowVideoBase::Update(const CStdString &strDirectory)

bool CGUIWindowVideoBase::GetDirectory(const CStdString &strDirectory, CFileItemList &items)
{
bool bResult = CGUIMediaWindow::GetDirectory(strDirectory,items);
CStdString directory = strDirectory;

// check if the path contains a filter and if so load it and
// remove it from the path to get proper GUI view states etc
CSmartPlaylist filterXsp;
CVideoDbUrl videoUrl;
if (videoUrl.FromString(strDirectory))
{
CVariant filter;
if (videoUrl.GetOption("filter", filter))
{
// load the filter and if it's type does not match the
// path's item type reset it
if (filterXsp.LoadFromJson(filter.asString()) && !filterXsp.GetType().Equals(videoUrl.GetItemType().c_str()))
filterXsp.Reset();

// remove the "filter" option from the path
videoUrl.AddOption("filter", "");
}
directory = videoUrl.ToString();
}

bool bResult = CGUIMediaWindow::GetDirectory(directory, items);

// (re-)apply the previously retrieved filter
// because it was reset in CGUIMediaWindow::GetDirectory()
if (!filterXsp.IsEmpty())
m_filter = filterXsp;

// add in the "New Playlist" item if we're in the playlists folder
if ((items.GetPath() == "special://videoplaylists/") && !items.Contains("newplaylist://"))
Expand All @@ -1809,7 +1836,7 @@ bool CGUIWindowVideoBase::GetDirectory(const CStdString &strDirectory, CFileItem
// we may also be in a tvshow files listing
// (ideally this should be removed, and our stack regexps tidied up if necessary
// No "normal" episodes should stack, and multi-parts should be supported)
ADDON::ScraperPtr info = m_database.GetScraperForPath(strDirectory);
ADDON::ScraperPtr info = m_database.GetScraperForPath(directory);
if (info && info->Content() == CONTENT_TVSHOWS)
m_stackingAvailable = false;

Expand Down
29 changes: 23 additions & 6 deletions xbmc/windows/GUIMediaWindow.cpp
Expand Up @@ -232,6 +232,13 @@ bool CGUIMediaWindow::OnMessage(CGUIMessage& message)
CGUIDialogContextMenu* pDlg = (CGUIDialogContextMenu*)g_windowManager.GetWindow(WINDOW_DIALOG_CONTEXT_MENU);
if (pDlg && pDlg->IsActive())
pDlg->Close();

// get rid of any active filtering
if (m_canFilterAdvanced)
{
m_canFilterAdvanced = false;
m_filter.Reset();
}

// Call ClearFileItems() after our window has finished doing any WindowClose
// animations
Expand Down Expand Up @@ -634,7 +641,7 @@ bool CGUIMediaWindow::GetDirectory(const CStdString &strDirectory, CFileItemList
if (items.Size())
items.Clear();

CStdString strParentPath=m_history.GetParentPath();
CStdString strParentPath = m_history.GetParentPath();

CLog::Log(LOGDEBUG,"CGUIMediaWindow::GetDirectory (%s)", strDirectory.c_str());
CLog::Log(LOGDEBUG," ParentPath = [%s]", strParentPath.c_str());
Expand Down Expand Up @@ -697,6 +704,7 @@ bool CGUIMediaWindow::GetDirectory(const CStdString &strDirectory, CFileItemList

// clear the filter
SetProperty("filter", "");
m_canFilterAdvanced = false;
m_filter.Reset();
return true;
}
Expand All @@ -721,18 +729,18 @@ bool CGUIMediaWindow::Update(const CStdString &strDirectory)
GetDirectoryHistoryString(pItem.get(), strSelectedItem);
}
}

CStdString strCurrentDirectory = m_vecItems->GetPath();

CStdString strOldDirectory = m_vecItems->GetPath();

m_history.SetSelectedItem(strSelectedItem, strOldDirectory);
m_history.SetSelectedItem(strSelectedItem, strCurrentDirectory);

CFileItemList items;
if (!GetDirectory(strDirectory, items))
{
CLog::Log(LOGERROR,"CGUIMediaWindow::GetDirectory(%s) failed", strDirectory.c_str());
// if the directory is the same as the old directory, then we'll return
// false. Else, we assume we can get the previous directory
if (strDirectory.Equals(strOldDirectory))
if (strDirectory.Equals(strCurrentDirectory))
return false;

// We assume, we can get the parent
Expand Down Expand Up @@ -946,6 +954,13 @@ bool CGUIMediaWindow::OnClick(int iItem)
if (!items.AlwaysCache())
items.RemoveDiscCache(GetID());

// if we have a filtered list, we need to add the filtered
// path to be able to come back to the filtered view
CStdString strCurrentDirectory = m_vecItems->GetPath();
if (m_canFilterAdvanced && !m_filter.IsEmpty() &&
!m_unfilteredItems->GetPath().Equals(strCurrentDirectory))
m_history.AddPath(strCurrentDirectory);

CFileItem directory(*pItem);
if (!Update(directory.GetPath()))
ShowShareErrorMessage(&directory);
Expand Down Expand Up @@ -1098,7 +1113,6 @@ void CGUIMediaWindow::GoParentFolder()

// if vector is not empty, pop parent
// if vector is empty, parent is root source listing
CStdString strOldPath(m_vecItems->GetPath());
strParent = m_history.RemoveParentPath();
Update(strParent);
}
Expand Down Expand Up @@ -1549,6 +1563,8 @@ void CGUIMediaWindow::OnFilterItems(const CStdString &filter)

if (!m_canFilterAdvanced)
SetProperty("filter", filter);
else
m_vecItems->SetPath(items.GetPath());
}

// and update our view control + buttons
Expand Down Expand Up @@ -1676,6 +1692,7 @@ bool CGUIMediaWindow::GetAdvanceFilteredItems(CFileItemList &items, bool &hasNew

items.ClearItems();
items.Append(filteredItems);
items.SetPath(resultItems.GetPath());
return true;
}

Expand Down

0 comments on commit 9a1699b

Please sign in to comment.