Skip to content

Commit

Permalink
Merge pull request #3529 from jmarshallnz/library_urls_switch_on_fetch
Browse files Browse the repository at this point in the history
Switch library:// URLs to 'real' URLs on fetch, rather than list
  • Loading branch information
jmarshallnz committed Nov 1, 2013
2 parents 752cb79 + d6e3e5f commit a942217
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 54 deletions.
2 changes: 1 addition & 1 deletion xbmc/dialogs/GUIDialogContextMenu.cpp
Expand Up @@ -645,7 +645,7 @@ bool CGUIDialogContextMenu::OnContextButton(const CStdString &type, const CFileI
CMediaSource *CGUIDialogContextMenu::GetShare(const CStdString &type, const CFileItem *item)
{
VECSOURCES *shares = CMediaSourceSettings::Get().GetSources(type);
if (!shares) return NULL;
if (!shares || !item) return NULL;
for (unsigned int i = 0; i < shares->size(); i++)
{
CMediaSource &testShare = shares->at(i);
Expand Down
52 changes: 25 additions & 27 deletions xbmc/filesystem/LibraryDirectory.cpp
Expand Up @@ -47,12 +47,12 @@ CLibraryDirectory::~CLibraryDirectory(void)

bool CLibraryDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items)
{
CStdString libNode = GetNode(strPath);
if (libNode.IsEmpty())
std::string libNode = GetNode(strPath);
if (libNode.empty())
return false;

if (URIUtils::HasExtension(libNode, ".xml"))
{ // a filter node
{ // a filter or folder node
TiXmlElement *node = LoadXML(libNode);
if (node)
{
Expand All @@ -75,9 +75,17 @@ bool CLibraryDirectory::GetDirectory(const CStdString& strPath, CFileItemList &i
CSmartPlaylistDirectory::GetDirectory(playlist, items))
{
items.SetProperty("library.filter", "true");
items.SetPath(items.GetProperty("path.db").asString());
return true;
}
}
else if (type == "folder")
{
CStdString path;
XMLUtils::GetPath(node, "path", path);
if (!path.IsEmpty())
return CDirectory::GetDirectory(path, items, m_strFileMask, m_flags);
}
}
return false;
}
Expand Down Expand Up @@ -112,27 +120,14 @@ bool CLibraryDirectory::GetDirectory(const CStdString& strPath, CFileItemList &i
if (XMLUtils::GetString(node, "label", label))
label = CGUIControlFactory::FilterLabel(label);
XMLUtils::GetString(node, "icon", icon);
CStdString type = node->Attribute("type");
int order = 0;
node->Attribute("order", &order);
CFileItemPtr item;
if (type == "folder")
{ // folder type - grab our path
CStdString path;
XMLUtils::GetPath(node, "path", path);
if (path.IsEmpty())
{
CLog::Log(LOGERROR, "<path> tag must be not be empty for type=\"folder\" node '%s'", xml.c_str());
continue;
}
item.reset(new CFileItem(path, true));
}
else
{ // virtual folder or filter
URIUtils::RemoveSlashAtEnd(xml);
CStdString folder = URIUtils::GetFileName(xml);
item.reset(new CFileItem(URIUtils::AddFileToFolder(strPath, folder), true));
}

// create item
URIUtils::RemoveSlashAtEnd(xml);
CStdString folder = URIUtils::GetFileName(xml);
CFileItemPtr item(new CFileItem(URIUtils::AddFileToFolder(strPath, folder), true));

item->SetLabel(label);
if (!icon.IsEmpty() && g_TextureManager.HasTexture(icon))
item->SetIconImage(icon);
Expand All @@ -144,7 +139,7 @@ bool CLibraryDirectory::GetDirectory(const CStdString& strPath, CFileItemList &i
return true;
}

TiXmlElement *CLibraryDirectory::LoadXML(const CStdString &xmlFile)
TiXmlElement *CLibraryDirectory::LoadXML(const std::string &xmlFile)
{
if (!CFile::Exists(xmlFile))
return NULL;
Expand All @@ -157,19 +152,22 @@ TiXmlElement *CLibraryDirectory::LoadXML(const CStdString &xmlFile)
return NULL;

// check the condition
CStdString condition = xml->Attribute("visible");
if (condition.IsEmpty() || g_infoManager.EvaluateBool(condition))
std::string condition;
xml->QueryStringAttribute("visible", &condition);
if (condition.empty() || g_infoManager.EvaluateBool(condition))
return xml;

return NULL;
}

bool CLibraryDirectory::Exists(const char* strPath)
{
return !GetNode(strPath).IsEmpty();
if (strPath)
return !GetNode(std::string(strPath)).empty();
return false;
}

CStdString CLibraryDirectory::GetNode(const CStdString &path)
std::string CLibraryDirectory::GetNode(const std::string &path)
{
CURL url(path);
CStdString libDir = URIUtils::AddFileToFolder(CProfilesManager::Get().GetLibraryFolder(), url.GetHostName() + "/");
Expand Down
4 changes: 2 additions & 2 deletions xbmc/filesystem/LibraryDirectory.h
Expand Up @@ -37,14 +37,14 @@ namespace XFILE
\param path the library:// path to parse
\return path to the XML file or directory corresponding to this path
*/
CStdString GetNode(const CStdString &path);
std::string GetNode(const std::string &path);

/*! \brief load the XML file and return a pointer to the <node> root element.
Checks visible attribute and only returns non-NULL for valid nodes that should be visible.
\param xmlFile the XML file to load and parse
\return the TiXmlElement pointer to the node, if it should be visible.
*/
TiXmlElement *LoadXML(const CStdString &xmlFile);
TiXmlElement *LoadXML(const std::string &xmlFile);

CXBMCTinyXML m_doc;
};
Expand Down
15 changes: 6 additions & 9 deletions xbmc/music/windows/GUIWindowMusicSongs.cpp
Expand Up @@ -294,7 +294,7 @@ void CGUIWindowMusicSongs::GetContextButtons(int itemNumber, CContextButtons &bu
bool inPlaylists = m_vecItems->GetPath().Equals(CUtil::MusicPlaylistsLocation()) ||
m_vecItems->GetPath().Equals("special://musicplaylists/");

if (m_vecItems->IsVirtualDirectoryRoot())
if (m_vecItems->IsVirtualDirectoryRoot() || m_vecItems->GetPath() == "sources://music/")
{
// get the usual music shares, and anything for all media windows
CGUIDialogContextMenu::GetContextButtons("music", item, buttons);
Expand Down Expand Up @@ -387,16 +387,13 @@ bool CGUIWindowMusicSongs::OnContextButton(int itemNumber, CONTEXT_BUTTON button
CFileItemPtr item;
if (itemNumber >= 0 && itemNumber < m_vecItems->Size())
item = m_vecItems->Get(itemNumber);
if ( m_vecItems->IsVirtualDirectoryRoot() && item)
if (CGUIDialogContextMenu::OnContextButton("music", item, button))
{
if (CGUIDialogContextMenu::OnContextButton("music", item, button))
{
if (button == CONTEXT_BUTTON_REMOVE_SOURCE)
OnRemoveSource(itemNumber);
if (button == CONTEXT_BUTTON_REMOVE_SOURCE)
OnRemoveSource(itemNumber);

Update("");
return true;
}
Update("");
return true;
}

switch (button)
Expand Down
11 changes: 4 additions & 7 deletions xbmc/pictures/GUIWindowPictures.cpp
Expand Up @@ -470,7 +470,7 @@ void CGUIWindowPictures::GetContextButtons(int itemNumber, CContextButtons &butt

if (item && !item->GetProperty("pluginreplacecontextitems").asBoolean())
{
if ( m_vecItems->IsVirtualDirectoryRoot() && item)
if ( m_vecItems->IsVirtualDirectoryRoot() || m_vecItems->GetPath() == "sources://pictures/" )
{
CGUIDialogContextMenu::GetContextButtons("pictures", item, buttons);
}
Expand Down Expand Up @@ -514,13 +514,10 @@ void CGUIWindowPictures::GetContextButtons(int itemNumber, CContextButtons &butt
bool CGUIWindowPictures::OnContextButton(int itemNumber, CONTEXT_BUTTON button)
{
CFileItemPtr item = (itemNumber >= 0 && itemNumber < m_vecItems->Size()) ? m_vecItems->Get(itemNumber) : CFileItemPtr();
if (m_vecItems->IsVirtualDirectoryRoot() && item)
if (CGUIDialogContextMenu::OnContextButton("pictures", item, button))
{
if (CGUIDialogContextMenu::OnContextButton("pictures", item, button))
{
Update("");
return true;
}
Update("");
return true;
}
switch (button)
{
Expand Down
11 changes: 4 additions & 7 deletions xbmc/programs/GUIWindowPrograms.cpp
Expand Up @@ -103,7 +103,7 @@ void CGUIWindowPrograms::GetContextButtons(int itemNumber, CContextButtons &butt
CFileItemPtr item = m_vecItems->Get(itemNumber);
if (item && !item->GetProperty("pluginreplacecontextitems").asBoolean())
{
if ( m_vecItems->IsVirtualDirectoryRoot() )
if ( m_vecItems->IsVirtualDirectoryRoot() || m_vecItems->GetPath() == "sources://programs/" )
{
CGUIDialogContextMenu::GetContextButtons("programs", item, buttons);
}
Expand All @@ -124,13 +124,10 @@ bool CGUIWindowPrograms::OnContextButton(int itemNumber, CONTEXT_BUTTON button)
{
CFileItemPtr item = (itemNumber >= 0 && itemNumber < m_vecItems->Size()) ? m_vecItems->Get(itemNumber) : CFileItemPtr();

if (item && m_vecItems->IsVirtualDirectoryRoot())
if (CGUIDialogContextMenu::OnContextButton("programs", item, button))
{
if (CGUIDialogContextMenu::OnContextButton("programs", item, button))
{
Update("");
return true;
}
Update("");
return true;
}
switch (button)
{
Expand Down
15 changes: 14 additions & 1 deletion xbmc/windows/GUIMediaWindow.cpp
Expand Up @@ -829,8 +829,15 @@ bool CGUIMediaWindow::Update(const CStdString &strDirectory, bool updateFilterPa
else if (iWindow == WINDOW_FILES || iWindow == WINDOW_PROGRAMS)
showLabel = 1026;
}
if (strDirectory.Equals("sources://video/"))
if (m_vecItems->GetPath().Equals("sources://video/"))
showLabel = 999;
else if (m_vecItems->GetPath().Equals("sources://music/"))
showLabel = 998;
else if (m_vecItems->GetPath().Equals("sources://pictures/"))
showLabel = 997;
else if (m_vecItems->GetPath().Equals("sources://programs/") ||
m_vecItems->GetPath().Equals("sources://files/"))
showLabel = 1026;
if (showLabel && (m_vecItems->Size() == 0 || !m_guiState->DisableAddSourceButtons())) // add 'add source button'
{
CStdString strLabel = g_localizeStrings.Get(showLabel);
Expand Down Expand Up @@ -1478,7 +1485,13 @@ void CGUIMediaWindow::OnInitWindow()
{
// initial fetch is done unthreaded to ensure the items are setup prior to skin animations kicking off
m_rootDir.SetAllowThreads(false);

// the start directory may change during Refresh
bool updateStartDirectory = (m_startDirectory == m_vecItems->GetPath());
Refresh();
if (updateStartDirectory)
m_startDirectory = m_vecItems->GetPath();

m_rootDir.SetAllowThreads(true);

if (m_iSelectedItem > -1)
Expand Down

0 comments on commit a942217

Please sign in to comment.