void NetTree::doDeleteVideo(bool remove) { if (!remove) return; ResultItem *item; if (m_type == DLG_TREE) item = qVariantValue<ResultItem *>(m_siteMap->GetCurrentNode()->GetData()); else { MythGenericTree *node = GetNodePtrFromButton(m_siteButtonList->GetItemCurrent()); if (!node) return; item = qVariantValue<ResultItem *>(node->GetData()); } if (!item) return; QString filename = GetDownloadFilename(item->GetTitle(), item->GetMediaURL()); if (filename.startsWith("myth://")) RemoteFile::DeleteFile(filename); else { QFile file(filename); file.remove(); } }
void GameUI::searchStart(void) { MythGenericTree *parent = m_gameUITree->GetCurrentNode()->getParent(); if (parent != NULL) { QStringList childList; QList<MythGenericTree*>::iterator it; QList<MythGenericTree*> *children = parent->getAllChildren(); for (it = children->begin(); it != children->end(); ++it) { MythGenericTree *child = *it; childList << child->GetText(); } MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack"); MythUISearchDialog *searchDialog = new MythUISearchDialog(popupStack, tr("Game Search"), childList, true, ""); if (searchDialog->Create()) { connect(searchDialog, SIGNAL(haveResult(QString)), SLOT(searchComplete(QString))); popupStack->AddScreen(searchDialog); } else delete searchDialog; } }
void NetTree::streamWebVideo() { ResultItem *item; if (m_type == DLG_TREE) item = qVariantValue<ResultItem *>(m_siteMap->GetCurrentNode()->GetData()); else { MythGenericTree *node = GetNodePtrFromButton(m_siteButtonList->GetItemCurrent()); if (!node) return; item = qVariantValue<ResultItem *>(node->GetData()); } if (!item) return; if (!item->GetDownloadable()) { showWebVideo(); return; } GetMythMainWindow()->HandleMedia("Internal", item->GetMediaURL(), item->GetDescription(), item->GetTitle(), item->GetSubtitle(), QString(), item->GetSeason(), item->GetEpisode(), QString(), item->GetTime().toInt(), item->GetDate().toString("yyyy")); }
MythGenericTree* MythGenericTree::getVisibleChildAt(uint reference) const { if (reference >= (uint)m_ordered_subnodes->count()) return NULL; QList<MythGenericTree*> *list; if (m_currentOrderingIndex == -1) list = m_subnodes; else list = m_ordered_subnodes; uint n = 0; for (int i = 0; i < list->size(); ++i) { MythGenericTree *child = list->at(i); if (child->IsVisible()) { if (n == reference) return child; n++; } } return NULL; }
/*! * \brief Remove the item from the tree * * \param item Item to be removed * \param deleteNode Also delete the node from the tree? Modifies the tree. * * \return True if successful */ void MythUIButtonTree::RemoveItem(MythUIButtonListItem *item, bool deleteNode) { if (!item || !m_rootNode) return; MythGenericTree *node = qVariantValue<MythGenericTree *>(item->GetData()); if (node && node->getParent()) { DoSetCurrentNode(node->getParent()); if (deleteNode) node->getParent()->deleteNode(node); else node->SetVisible(false); } MythUIButtonList *list = item->parent(); list->RemoveItem(item); if (list->IsEmpty()) { if (m_currentDepth > 0) m_currentDepth--; else if (m_activeListID > 1) m_activeListID--; SetTreeState(true); } }
void GameUI::showMenu() { MythGenericTree *node = m_gameUITree->GetCurrentNode(); MythScreenStack *popupStack = GetMythMainWindow()-> GetStack("popup stack"); MythDialogBox *showMenuPopup = new MythDialogBox(node->GetText(), popupStack, "showMenuPopup"); if (showMenuPopup->Create()) { showMenuPopup->SetReturnEvent(this, "showMenuPopup"); showMenuPopup->AddButton(tr("Scan For Changes")); if (isLeaf(node)) { RomInfo *romInfo = qVariantValue<RomInfo *>(node->GetData()); if (romInfo) { showMenuPopup->AddButton(tr("Show Information")); if (romInfo->Favorite()) showMenuPopup->AddButton(tr("Remove Favorite")); else showMenuPopup->AddButton(tr("Make Favorite")); showMenuPopup->AddButton(tr("Retrieve Details")); showMenuPopup->AddButton(tr("Edit Details")); } } popupStack->AddScreen(showMenuPopup); } else delete showMenuPopup; }
void MythGenericTree::reOrderAsSorted() { // // Arrange (recursively) my subnodes in the same order as my ordered // subnodes // if (m_subnodes->count() != m_ordered_subnodes->count()) { LOG(VB_GENERAL, LOG_ERR, "Can't reOrderAsSorted(), because the number " "of subnodes is different than the number of ordered subnodes"); return; } m_subnodes->clear(); m_currentOrderingIndex = -1; QList<MythGenericTree*>::iterator it; it = m_ordered_subnodes->begin(); MythGenericTree *child; while ((child = *it) != 0) { m_subnodes->append(child); child->reOrderAsSorted(); ++it; } }
void GameUI::toggleFavorite(void) { MythGenericTree *node = m_gameUITree->GetCurrentNode(); if (isLeaf(node)) { RomInfo *romInfo = qVariantValue<RomInfo *>(node->GetData()); romInfo->setFavorite(true); updateChangedNode(node, romInfo); } }
/*! * \brief Using a path based on the node IDs, set the currently * selected node * * \param route List defining the path using node IDs starting at the root node * * \return True if successful */ bool MythUIButtonTree::SetNodeById(QList<int> route) { MythGenericTree *node = m_rootNode->findNode(route); if (node && node->isSelectable()) { DoSetCurrentNode(node); SetTreeState(); return true; } return false; }
void GameUI::OnGameSearchDone(MetadataLookup *lookup) { if (m_busyPopup) { m_busyPopup->Close(); m_busyPopup = NULL; } if (!lookup) return; MythGenericTree *node = qVariantValue<MythGenericTree *>(lookup->GetData()); if (!node) return; RomInfo *metadata = qVariantValue<RomInfo *>(node->GetData()); if (!metadata) return; metadata->setGamename(lookup->GetTitle()); metadata->setYear(QString::number(lookup->GetYear())); metadata->setPlot(lookup->GetDescription()); metadata->setSystem(lookup->GetSystem()); QStringList coverart, fanart, screenshot; // Imagery ArtworkList coverartlist = lookup->GetArtwork(kArtworkCoverart); for (ArtworkList::const_iterator p = coverartlist.begin(); p != coverartlist.end(); ++p) { coverart.prepend((*p).url); } ArtworkList fanartlist = lookup->GetArtwork(kArtworkFanart); for (ArtworkList::const_iterator p = fanartlist.begin(); p != fanartlist.end(); ++p) { fanart.prepend((*p).url); } ArtworkList screenshotlist = lookup->GetArtwork(kArtworkScreenshot); for (ArtworkList::const_iterator p = screenshotlist.begin(); p != screenshotlist.end(); ++p) { screenshot.prepend((*p).url); } StartGameImageSet(node, coverart, fanart, screenshot); metadata->SaveToDatabase(); updateChangedNode(node, metadata); }
QList<int> MythGenericTree::getRouteById() { QList<int> routeByID; routeByID.push_front(getInt()); MythGenericTree *parent = this; while( (parent = parent->getParent()) ) { routeByID.push_front(parent->getInt()); } return routeByID; }
QList<MythGenericTree*> MythGenericTree::getRoute(void) { QList<MythGenericTree*> route; route.push_front(this); MythGenericTree *parent = this; while( (parent = parent->getParent()) ) { route.push_front(parent); } return route; }
void MythGenericTree::sortBySelectable() { m_ordered_subnodes->Sort(SortableMythGenericTreeList::SORT_SELECTABLE); QList<MythGenericTree*>::iterator it; it = m_subnodes->begin(); MythGenericTree *child; while ((child = *it) != 0) { child->sortBySelectable(); ++it; } }
QStringList MythGenericTree::getRouteByString() { QStringList routeByString; routeByString.push_front(getString()); MythGenericTree *parent = this; while( (parent = parent->getParent()) ) { routeByString.push_front(parent->getString()); } return routeByString; }
void GameUI::searchComplete(QString string) { if (!m_gameUITree->GetCurrentNode()) return; MythGenericTree *parent = m_gameUITree->GetCurrentNode()->getParent(); if (!parent) return; MythGenericTree *new_node = parent->getChildByName(string); if (new_node) m_gameUITree->SetCurrentNode(new_node); }
void MythGenericTree::sortByAttributeThenByString(int which_attribute) { m_ordered_subnodes->Sort(SortableMythGenericTreeList::SORT_ATT_THEN_STRING, which_attribute); QList<MythGenericTree*>::iterator it; it = m_subnodes->begin(); MythGenericTree *child; while ((child = *it) != 0) { child->sortByAttributeThenByString(which_attribute); ++it; } }
void MythGenericTree::addYourselfIfSelectable(QList<MythGenericTree*> *flat_list) { if (m_selectable) flat_list->append(this); QList<MythGenericTree*>::iterator it; it = m_subnodes->begin(); MythGenericTree *child; while ((child = *it) != 0) { child->addYourselfIfSelectable(flat_list); ++it; } }
/** \fn GalleryViewHelper::GetImageMetadataFromNode(int) * \brief Returns the data of the given node id * \param id The specified node id that shall be used * \return ImageMetadata */ ImageMetadata *GalleryViewHelper::GetImageMetadataFromNode(int i) { if (!m_currentNode) return NULL; MythGenericTree *node = m_currentNode->getChildAt(i); if (!node) return NULL; ImageMetadata *im = qVariantValue<ImageMetadata *>(node->GetData()); if (!im) return NULL; return im; }
/** \fn GalleryView::GetImageMetadataFromButton(MythUIButtonListItem *) * \brief Returns the data of the given image list item * \param item The given image list item * \return ImageMetadata */ ImageMetadata *GalleryView::GetImageMetadataFromButton(MythUIButtonListItem *item) { if (!item) return NULL; MythGenericTree *node = item->GetData().value<MythGenericTree *>(); if (!node) return NULL; ImageMetadata *data = node->GetData().value<ImageMetadata *>(); if (!data) return NULL; return data; }
/** \fn GalleryViewHelper::GetImageMetadataFromSelectedNode() * \brief Returns the data selected node * \return ImageMetadata */ ImageMetadata *GalleryViewHelper::GetImageMetadataFromSelectedNode() { if (!m_currentNode) return NULL; MythGenericTree *node = m_currentNode->getSelectedChild(); if (!node) return NULL; ImageMetadata *im = node->GetData().value<ImageMetadata *>(); if (!im) return NULL; return im; }
/** \fn GalleryView::GetImageMetadataFromSelectedButton() * \brief Returns the data of the currently selected image list item * \return ImageMetadata */ ImageMetadata *GalleryView::GetImageMetadataFromSelectedButton() { MythUIButtonListItem *item = m_imageList->GetItemCurrent(); if (!item) return NULL; MythGenericTree *node = item->GetData().value<MythGenericTree *>(); if (!node) return NULL; ImageMetadata *data = node->GetData().value<ImageMetadata *>(); if (!data) return NULL; return data; }
/*! * \brief Update a list with children of the tree node * * \param list List to refill * \param node Parent node whose children will appear in the list * * \return True if successful, False if the node had no children or was invalid */ bool MythUIButtonTree::UpdateList(MythUIButtonList *list, MythGenericTree *node) { disconnect(list, 0, 0, 0); list->Reset(); QList<MythGenericTree *> *nodelist = NULL; if (node) nodelist = node->getAllChildren(); if (!nodelist || nodelist->isEmpty()) return false; MythGenericTree *selectedNode = node->getSelectedChild(true); MythUIButtonListItem *selectedItem = NULL; QList<MythGenericTree *>::iterator it; for (it = nodelist->begin(); it != nodelist->end(); ++it) { MythGenericTree *childnode = *it; if (!childnode->IsVisible()) continue; MythUIButtonListItem *item = childnode->CreateListButton(list); if (childnode == selectedNode) selectedItem = item; } if (list->IsEmpty()) return false; if (selectedItem) list->SetItemCurrent(selectedItem); connect(list, SIGNAL(itemSelected(MythUIButtonListItem *)), SLOT(handleSelect(MythUIButtonListItem *))); connect(list, SIGNAL(itemClicked(MythUIButtonListItem *)), SLOT(handleClick(MythUIButtonListItem *))); connect(list, SIGNAL(itemVisible(MythUIButtonListItem *)), SLOT(handleVisible(MythUIButtonListItem *))); return true; }
/*! * \brief Using a path based on the node string, set the currently * selected node * * \param route List defining the path using node strings starting at the root node * * \return True if successful */ bool MythUIButtonTree::SetNodeByString(QStringList route) { if (!m_rootNode) { DoSetCurrentNode(NULL); return false; } MythGenericTree *foundNode = m_rootNode; bool foundit = false; if (!route.isEmpty()) { if (route[0] == m_rootNode->getString()) { if (route.size() > 1) { for (int i = 1; i < route.size(); i ++) { MythGenericTree *node = foundNode->getChildByName(route[i]); if (node) { node->becomeSelectedChild(); foundNode = node; foundit = true; } else { node = foundNode->getChildAt(0); if (node) { node->becomeSelectedChild(); foundNode = node; } break; } } } else foundit = true; } } DoSetCurrentNode(foundNode); m_currentDepth = qMax(0, (int)(foundNode->currentDepth() - m_depthOffset - m_numLists)); m_activeListID = qMin(foundNode->currentDepth() - m_depthOffset - 1, (int)(m_numLists - 1)); SetTreeState(true); return foundit; }
MythGenericTree* MythGenericTree::findNode(QList<int> route_of_branches, int depth) { // Starting from *this* node (which will often be root) find a set of // branches that have id's that match the collection passed in // route_of_branches. Return the end point of those branches. // // In practical terms, mythmusic will use this to force the playback // screen's ManagedTreeList to move to a given track in a given playlist MythGenericTree *node = NULL; for (int i = 0; i < route_of_branches.count(); i++) { if (!node) node = this; bool foundit = false; QList<MythGenericTree*>::iterator it; QList<MythGenericTree*> *children = node->getAllChildren(); if (!children) break; MythGenericTree *child = NULL; for (it = children->begin(); it != children->end(); ++it) { child = *it; if (!child) continue; if (child->getInt() == route_of_branches[i]) { node = child; foundit = true; break; } } if (!foundit) break; } return NULL; }
void MythGenericTree::sortByString() { m_ordered_subnodes->Sort(SortableMythGenericTreeList::SORT_STRING); QList<MythGenericTree*> *children = getAllChildren(); if (children && children->count() > 0) { SortableMythGenericTreeList::Iterator it; MythGenericTree *child = NULL; for (it = children->begin(); it != children->end(); ++it) { child = *it; if (!child) continue; child->sortByString(); } } }
void MythGenericTree::buildFlatListOfSubnodes(bool scrambled_parents) { // This builds a flat list of every selectable child according to the // current ordering index. m_flatenedSubnodes->clear(); QList<MythGenericTree*>::iterator it; it = m_subnodes->begin(); MythGenericTree *child; while ((child = *it) != 0) { child->addYourselfIfSelectable(m_flatenedSubnodes); ++it; } if (m_currentOrderingIndex > -1) m_flatenedSubnodes->SetAttributeIndex(m_currentOrderingIndex); }
void NetTree::showMenu(void) { QString label = tr("Playback/Download Options"); MythMenu *menu = new MythMenu(label, this, "options"); ResultItem *item = NULL; if (m_type == DLG_TREE) { MythGenericTree *node = m_siteMap->GetCurrentNode(); if (node) item = qVariantValue<ResultItem *>(node->GetData()); } else { MythGenericTree *node = GetNodePtrFromButton(m_siteButtonList->GetItemCurrent()); if (node) item = qVariantValue<ResultItem *>(node->GetData()); } if (item) { if (item->GetDownloadable()) menu->AddItem(tr("Stream Video"), SLOT(streamWebVideo())); menu->AddItem(tr("Open Web Link"), SLOT(showWebVideo())); if (item->GetDownloadable()) menu->AddItem(tr("Save This Video"), SLOT(doDownloadAndPlay())); } menu->AddItem(tr("Scan/Manage Subscriptions"), NULL, createShowManageMenu()); menu->AddItem(tr("Change View"), NULL, createShowViewMenu()); MythDialogBox *menuPopup = new MythDialogBox(menu, m_popupStack, "mythnettreemenupopup"); if (menuPopup->Create()) m_popupStack->AddScreen(menuPopup); else delete menuPopup; }
void NetTree::buildGenericTree(MythGenericTree *dst, QStringList paths, QString dirthumb, QList<ResultItem*> videos) { MythGenericTree *folder = NULL; // A little loop to determine what path of the provided path might // already exist in the tree. while (folder == NULL && paths.size()) { QString curPath = paths.takeFirst(); curPath.replace("|", "/"); MythGenericTree *tmp = dst->getChildByName(curPath); if (tmp) dst = tmp; else folder = new MythGenericTree( curPath, kSubFolder, false); } if (!folder) return; folder->SetData(dirthumb); dst->addNode(folder); // Add an upfolder if (m_type != DLG_TREE) { folder->addNode(QString(tr("Back")), kUpFolder, true, false); } if (paths.size()) buildGenericTree(folder, paths, dirthumb, videos); else { // File Handling for (QList<ResultItem*>::iterator it = videos.begin(); it != videos.end(); ++it) AddFileNode(folder, *it); } }
MythGenericTree* MythGenericTree::getChildById(int an_int) const { QList<MythGenericTree*> *children = getAllChildren(); if (children && children->count() > 0) { SortableMythGenericTreeList::Iterator it; MythGenericTree *child = NULL; for (it = children->begin(); it != children->end(); ++it) { child = *it; if (!child) continue; if (child->getInt() == an_int) return child; } } return NULL; }
void GameUI::resetOtherTrees(MythGenericTree *node) { MythGenericTree *top_level = node; while (top_level->getParent() != m_gameTree) { top_level = top_level->getParent(); } QList<MythGenericTree*>::iterator it; QList<MythGenericTree*> *children = m_gameTree->getAllChildren(); for (it = children->begin(); it != children->end(); ++it) { MythGenericTree *child = *it; if (child != top_level) { child->deleteAllChildren(); } } }