bool CPlexDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items) { CStdString strRoot = strPath; if (CUtil::HasSlashAtEnd(strRoot) && strRoot != "plex://") strRoot.Delete(strRoot.size() - 1); strRoot.Replace(" ", "%20"); // Start the download thread running. printf("PlexDirectory::GetDirectory(%s)\n", strRoot.c_str()); m_url = strRoot; CThread::Create(false, 0); // Now display progress, look for cancel. CGUIDialogProgress* dlgProgress = 0; int time = GetTickCount(); while (m_downloadEvent.WaitMSec(100) == false) { // If enough time has passed, display the dialog. if (GetTickCount() - time > 1000 && m_allowPrompting == true) { dlgProgress = (CGUIDialogProgress*)m_gWindowManager.GetWindow(WINDOW_DIALOG_PROGRESS); if (dlgProgress) { dlgProgress->ShowProgressBar(false); dlgProgress->SetHeading(40203); dlgProgress->SetLine(0, 40204); dlgProgress->SetLine(1, ""); dlgProgress->SetLine(2, ""); dlgProgress->StartModal(); } } if (dlgProgress) { dlgProgress->Progress(); if (dlgProgress->IsCanceled()) { items.m_wasListingCancelled = true; m_http.Cancel(); StopThread(); } } } if (dlgProgress) dlgProgress->Close(); // Wait for the thread to exit. WaitForThreadExit(INFINITE); // See if we suceeded. if (m_bSuccess == false) return false; // See if we're supposed to parse the results or not. if (m_bParseResults == false) return true; // Parse returned xml. TiXmlDocument doc; doc.Parse(m_data.c_str()); TiXmlElement* root = doc.RootElement(); if (root == 0) { CLog::Log(LOGERROR, "%s - Unable to parse XML\n%s", __FUNCTION__, m_data.c_str()); return false; } // Get the fanart. const char* fanart = root->Attribute("art"); string strFanart; if (fanart && strlen(fanart) > 0) strFanart = ProcessUrl(strPath, fanart, false); // Walk the parsed tree. string strFileLabel = "%N - %T"; string strDirLabel = "%B"; string strSecondDirLabel = "%Y"; Parse(m_url, root, items, strFileLabel, strDirLabel, strSecondDirLabel); // Set the window titles const char* title1 = root->Attribute("title1"); const char* title2 = root->Attribute("title2"); if (title1 && strlen(title1) > 0) items.SetFirstTitle(title1); if (title2 && strlen(title2) > 0) items.SetSecondTitle(title2); // Set fanart on items if they don't have their own. for (int i=0; i<items.Size(); i++) { CFileItemPtr pItem = items[i]; if (strFanart.size() > 0 && pItem->GetQuickFanart().size() == 0) pItem->SetQuickFanart(strFanart); // Make sure sort label is lower case. string sortLabel = pItem->GetLabel(); boost::to_lower(sortLabel); pItem->SetSortLabel(sortLabel); } // Set fanart on directory. if (strFanart.size() > 0) items.SetQuickFanart(strFanart); // Set the view mode. const char* viewmode = root->Attribute("viewmode"); if (viewmode && strlen(viewmode) > 0) { CGUIViewState* viewState = CGUIViewState::GetViewState(0, items); viewState->SaveViewAsControl(atoi(viewmode)); } // Override labels. const char* fileLabel = root->Attribute("filelabel"); if (fileLabel && strlen(fileLabel) > 0) strFileLabel = fileLabel; const char* dirLabel = root->Attribute("dirlabel"); if (dirLabel && strlen(dirLabel) > 0) strDirLabel = dirLabel; // Add the sort method. items.AddSortMethod(SORT_METHOD_NONE, 552, LABEL_MASKS(strFileLabel, "%D", strDirLabel, strSecondDirLabel)); // Set the content label. const char* content = root->Attribute("content"); if (content && strlen(content) > 0) { items.SetContent(content); } // Check for dialog message attributes CStdString strMessage = ""; const char* header = root->Attribute("header"); if (header && strlen(header) > 0) { const char* message = root->Attribute("message"); if (message && strlen(message) > 0) strMessage = message; items.m_displayMessage = true; items.m_displayMessageTitle = header; items.m_displayMessageContents = root->Attribute("message"); // Don't cache these. m_dirCacheType = DIR_CACHE_NEVER; } // See if this directory replaces the parent. const char* replace = root->Attribute("replaceParent"); if (replace && strcmp(replace, "1") == 0) items.SetReplaceListing(true); // See if we're saving this into the history or not. const char* noHistory = root->Attribute("noHistory"); if (noHistory && strcmp(noHistory, "1") == 0) items.SetSaveInHistory(false); // See if we're not supposed to cache this directory. const char* noCache = root->Attribute("nocache"); if (noCache && strcmp(noCache, "1") == 0) m_dirCacheType = DIR_CACHE_NEVER; return true; }