void BFBackupTree::RefreshPlaceholders () { Freeze (); // only refresh filled placeholders! if ( GetFillBlackfiskPlaceholders() ) { VectorTreeItemId vecIdsDate; VectorTreeItemId vecIdsTime; VectorTreeItemId vecIdsAll; // find all items with a label matching to the old filled placeholders if ( !(BFCore::Instance().GetDateString_Old().IsEmpty()) ) vecIdsDate = FindItems (GetRootItem(), BF_BACKUPTREE_FILLED_DATE_MASK); if ( !(BFCore::Instance().GetTimeString_Old().IsEmpty()) ) vecIdsTime = FindItems (GetRootItem(), BF_BACKUPTREE_FILLED_TIME_MASK); vecIdsAll.reserve(vecIdsDate.size() + vecIdsTime.size()); vecIdsAll.insert( vecIdsAll.end(), vecIdsDate.begin(), vecIdsDate.end() ); vecIdsAll.insert( vecIdsAll.end(), vecIdsTime.begin(), vecIdsTime.end() ); // are there items to refresh? if ( !(vecIdsAll.empty()) ) { wxString strPath; wxString strLabel; // iterate on the items for (ItVectorTreeItemId it = vecIdsAll.begin(); it != vecIdsAll.end(); ++it) { strPath = GetPathByItem(*it); while ( strPath.Matches(BF_BACKUPTREE_PLACEHOLDER_MASK) || strPath.Matches(BF_BACKUPTREE_PLACEHOLDER_MASK)) { strLabel = GetItemText(*it); if ( strLabel.Matches(BF_BACKUPTREE_FILLED_DATE_MASK) || strLabel.Matches(BF_BACKUPTREE_FILLED_TIME_MASK)) { strLabel = strPath.AfterLast(wxFILE_SEP_PATH); SetItemText(*it, BFBackup::FillBlackfiskPlaceholders(strLabel)); } // cut the last diretory from path strPath = strPath.BeforeLast(wxFILE_SEP_PATH); } } } } Thaw(); }
void UPNPScanner::FindItems(const QDomNode &n, MediaServerItem &content) { QDomElement node = n.toElement(); if (node.isNull()) return; if (node.tagName() == "container") { QString title = "ERROR"; QDomNode next = node.firstChild(); while (!next.isNull()) { QDomElement container = next.toElement(); if (!container.isNull() && container.tagName() == "title") title = container.text(); next = next.nextSibling(); } MediaServerItem container = MediaServerItem(node.attribute("id", "ERROR"), node.attribute("parentID", "ERROR"), title, QString()); content.Add(container); return; } if (node.tagName() == "item") { QString title = "ERROR"; QString url = "ERROR"; QDomNode next = node.firstChild(); while (!next.isNull()) { QDomElement item = next.toElement(); if (!item.isNull()) { if(item.tagName() == "res") url = item.text(); if(item.tagName() == "title") title = item.text(); } next = next.nextSibling(); } MediaServerItem item = MediaServerItem(node.attribute("id", "ERROR"), node.attribute("parentID", "ERROR"), title, url); content.Add(item); return; } QDomNode next = node.firstChild(); while (!next.isNull()) { FindItems(next, content); next = next.nextSibling(); } }
wxTreeItemId BFBackupTree::FindItem (wxTreeItemId idStart, const wxString& strLabel, bool bGoDeep /*= true*/) { VectorTreeItemId vecIds = FindItems(idStart, strLabel, bGoDeep, false); if (vecIds.size() > 0) return vecIds[0]; return wxTreeItemId(); }
VectorTreeItemId BFBackupTree::FindItems (wxTreeItemId idStart, const wxString& strLabel, bool bGoDeep /*= true*/, bool bSearchForAll /*= true*/) { VectorTreeItemId vecRes, vecDeep; wxTreeItemId idCurr; wxTreeItemIdValue idCookie; if (GetItemText(idStart).Matches(strLabel)) vecRes.push_back(idStart); if (ItemHasChildren(idStart)) { for (idCurr = GetFirstChild(idStart, idCookie); idCurr.IsOk(); idCurr = GetNextChild(idStart, idCookie)) { if ( !bSearchForAll && vecRes.size() == 1 ) return vecRes; if (bGoDeep) { vecDeep = FindItems(idCurr, strLabel, true); vecRes.reserve ( vecRes.size() + vecDeep.size() ); vecRes.insert ( vecRes.end(), vecDeep.begin(), vecDeep.end() ); } else { if (GetItemText(idCurr).Matches(strLabel)) vecRes.push_back(idCurr); } } } return vecRes; }
void BFBackupTree::UpdatePlaceholders () { Freeze(); wxString strLabel; if (bFillBlackfiskPlaceholders_) // --- "<date>" => "2000-01-01" --- { VectorTreeItemId vecIds; // find all items with a placeholder in its label vecIds = FindItems(GetRootItem(), BF_BACKUPTREE_PLACEHOLDER_MASK); // iterate on the items for (ItVectorTreeItemId it = vecIds.begin(); it != vecIds.end(); ++it) { strLabel = GetItemText(*it); SetItemText(*it, BFBackup::FillBlackfiskPlaceholders(strLabel)); } } else // --- "2000-01-01" => "<date>" --- { BFTaskVector vecTasks; wxString strPlaceholder; // find all tasks with placeholders BFProject::Instance().FindAllTasksWithPlaceholders(vecTasks); // iterate over all relevant items for (BFTaskVectorIt it = vecTasks.begin(); it != vecTasks.end(); ++it) { // get the corrosponding tree-item wxTreeItemId id = FindItem (GetRootItem(), (*it)->GetOID()); // ** name ** if ((*it)->GetName().Matches(BF_BACKUPTREE_PLACEHOLDER_MASK)) SetItemText(id, (*it)->GetName()); // ** destination ** strPlaceholder = (*it)->GetDestination(); while (strPlaceholder.Matches(BF_BACKUPTREE_PLACEHOLDER_MASK)) { strLabel = strPlaceholder.AfterLast(wxFILE_SEP_PATH); if (strLabel.Matches(BF_BACKUPTREE_PLACEHOLDER_MASK)) { // find the tree-item with the path wxTreeItemId idCurr = FindItemByPath(GetRootItem(), strPlaceholder); // reset the item text if (idCurr.IsOk()) SetItemText(idCurr, strLabel); } // cut the last diretory from path strPlaceholder = strPlaceholder.BeforeLast(wxFILE_SEP_PATH); } } } Thaw(); }
/** * \fn UPNPScanner::ParseBrowse(const QUrl&, QNetworkReply*) * Parse the XML returned from Content Directory Service browse request. */ void UPNPScanner::ParseBrowse(const QUrl &url, QNetworkReply *reply) { QByteArray data = reply->readAll(); if (data.isEmpty()) return; // Open the response for parsing QDomDocument *parent = new QDomDocument(); QString errorMessage; int errorLine = 0; int errorColumn = 0; if (!parent->setContent(data, false, &errorMessage, &errorLine, &errorColumn)) { LOG(VB_GENERAL, LOG_ERR, LOC + QString("DIDL Parse error, Line: %1 Col: %2 Error: '%3'") .arg(errorLine).arg(errorColumn).arg(errorMessage)); delete parent; return; } LOG(VB_UPNP, LOG_INFO, "\n\n" + parent->toString(4) + "\n\n"); // pull out the actual result QDomDocument *result = NULL; uint num = 0; uint total = 0; uint updateid = 0; QDomElement docElem = parent->documentElement(); QDomNode n = docElem.firstChild(); if (!n.isNull()) result = FindResult(n, num, total, updateid); delete parent; if (!result || num < 1 || total < 1) { LOG(VB_GENERAL, LOG_ERR, LOC + QString("Failed to find result for %1") .arg(url.toString())); return; } // determine the 'server' which requested the browse m_lock.lock(); MediaServer* server = NULL; QHashIterator<QString,MediaServer*> it(m_servers); while (it.hasNext()) { it.next(); if (url == it.value()->m_controlURL) { server = it.value(); break; } } // discard unmatched responses if (!server) { m_lock.unlock(); LOG(VB_GENERAL, LOG_ERR, LOC + QString("Received unknown response for %1").arg(url.toString())); return; } // check the update ID if (server->m_systemUpdateID != (int)updateid) { // if this is not the root container, this browse will now fail // as the appropriate parentID will not be found LOG(VB_GENERAL, LOG_ERR, LOC + QString("%1 updateID changed during browse (old %2 new %3)") .arg(server->m_friendlyName).arg(server->m_systemUpdateID) .arg(updateid)); m_scanComplete &= server->ResetContent(updateid); Debug(); } // find containers (directories) and actual items and add them docElem = result->documentElement(); n = docElem.firstChild(); while (!n.isNull()) { FindItems(n, *server); n = n.nextSibling(); } delete result; m_lock.unlock(); }