void CPVRClients::ProcessMenuHooks(int iClientID, PVR_MENUHOOK_CAT cat) { PVR_MENUHOOKS *hooks = NULL; // get client id if (iClientID < 0 && cat == PVR_MENUHOOK_SETTING) { PVR_CLIENTMAP clients; GetConnectedClients(clients); if (clients.size() == 1) { iClientID = clients.begin()->first; } else if (clients.size() > 1) { // have user select client CGUIDialogSelect* pDialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); pDialog->Reset(); pDialog->SetHeading(19196); PVR_CLIENTMAP_ITR itrClients; for (itrClients = clients.begin(); itrClients != clients.end(); itrClients++) { pDialog->Add(itrClients->second->GetBackendName()); } pDialog->DoModal(); int selection = pDialog->GetSelectedLabel(); if (selection >= 0) { itrClients = clients.begin(); for (int i = 0; i < selection; i++) itrClients++; iClientID = itrClients->first; } } } if (iClientID < 0) iClientID = GetPlayingClientID(); PVR_CLIENT client; if (GetConnectedClient(iClientID, client) && client->HaveMenuHooks(cat)) { hooks = client->GetMenuHooks(); std::vector<int> hookIDs; CGUIDialogSelect* pDialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); pDialog->Reset(); pDialog->SetHeading(19196); for (unsigned int i = 0; i < hooks->size(); i++) pDialog->Add(client->GetString(hooks->at(i).iLocalizedStringId)); pDialog->DoModal(); int selection = pDialog->GetSelectedLabel(); if (selection >= 0) client->CallMenuHook(hooks->at(selection)); } }
void CPVRClients::ProcessMenuHooks(int iClientID) { PVR_MENUHOOKS *hooks = NULL; CSingleLock lock(m_critSection); if (iClientID < 0) iClientID = GetPlayingClientID(); if (GetMenuHooks(iClientID, hooks)) { boost::shared_ptr<CPVRClient> client = m_clientMap.find(iClientID)->second; lock.Leave(); std::vector<long> hookIDs; CGUIDialogSelect* pDialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); pDialog->Reset(); pDialog->SetHeading(19196); for (unsigned int i = 0; i < hooks->size(); i++) pDialog->Add(client->GetString(hooks->at(i).string_id)); pDialog->DoModal(); int selection = pDialog->GetSelectedLabel(); if (selection >= 0) { client->CallMenuHook(hooks->at(selection)); } } else { CLog::Log(LOGERROR, "PVR - %s - cannot find client %d",__FUNCTION__, iClientID); } }
bool CGUIControlListSetting::OnClick() { if (m_pButton == NULL) return false; CGUIDialogSelect *dialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (dialog == NULL) return false; CFileItemList options; if (!GetItems(m_pSetting, options) || options.Size() <= 1) return false; const CSettingControlList *control = static_cast<const CSettingControlList*>(m_pSetting->GetControl()); dialog->Reset(); dialog->SetHeading(g_localizeStrings.Get(m_pSetting->GetLabel())); dialog->SetItems(&options); dialog->SetMultiSelection(control->CanMultiSelect()); dialog->DoModal(); if (!dialog->IsConfirmed()) return false; const CFileItemList &items = dialog->GetSelectedItems(); std::vector<CVariant> values; for (int index = 0; index < items.Size(); index++) { const CFileItemPtr item = items[index]; if (item == NULL || !item->HasProperty("value")) return false; values.push_back(item->GetProperty("value")); } bool ret = false; switch (m_pSetting->GetType()) { case SettingTypeInteger: if (values.size() > 1) return false; ret = ((CSettingInt *)m_pSetting)->SetValue((int)values.at(0).asInteger()); case SettingTypeString: if (values.size() > 1) return false; ret = ((CSettingString *)m_pSetting)->SetValue(values.at(0).asString()); case SettingTypeList: ret = CSettings::Get().SetList(m_pSetting->GetId(), values); default: break; } if (ret) Update(); return ret; }
string CGUIDialogVideoInfo::ChooseArtType(const CFileItem &videoItem, map<string, string> ¤tArt) { // prompt for choice CGUIDialogSelect *dialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (!dialog || !videoItem.HasVideoInfoTag()) return ""; CFileItemList items; dialog->SetHeading(13511); dialog->Reset(); dialog->SetUseDetails(true); dialog->EnableButton(true, 13516); CVideoDatabase db; db.Open(); vector<string> artTypes = CVideoThumbLoader::GetArtTypes(videoItem.GetVideoInfoTag()->m_type); // add in any stored art for this item that is non-empty. db.GetArtForItem(videoItem.GetVideoInfoTag()->m_iDbId, videoItem.GetVideoInfoTag()->m_type, currentArt); for (CGUIListItem::ArtMap::iterator i = currentArt.begin(); i != currentArt.end(); ++i) { if (!i->second.empty() && find(artTypes.begin(), artTypes.end(), i->first) == artTypes.end()) artTypes.push_back(i->first); } // add any art types that exist for other media items of the same type vector<string> dbArtTypes; db.GetArtTypes(videoItem.GetVideoInfoTag()->m_type, dbArtTypes); for (vector<string>::const_iterator it = dbArtTypes.begin(); it != dbArtTypes.end(); it++) { if (find(artTypes.begin(), artTypes.end(), *it) == artTypes.end()) artTypes.push_back(*it); } for (vector<string>::const_iterator i = artTypes.begin(); i != artTypes.end(); ++i) { string type = *i; CFileItemPtr item(new CFileItem(type, "false")); item->SetLabel(type); if (videoItem.HasArt(type)) item->SetArt("thumb", videoItem.GetArt(type)); items.Add(item); } dialog->SetItems(&items); dialog->DoModal(); if (dialog->IsButtonPressed()) { // Get the new artwork name CStdString strArtworkName; if (!CGUIKeyboardFactory::ShowAndGetInput(strArtworkName, g_localizeStrings.Get(13516), false)) return ""; return strArtworkName; } return dialog->GetSelectedItem()->GetLabel(); }
void CPVRClients::ProcessMenuHooks(int iClientID) { PVR_MENUHOOKS *hooks = NULL; if (iClientID < 0) iClientID = GetPlayingClientID(); boost::shared_ptr<CPVRClient> client; if (GetConnectedClient(iClientID, client) && client->HaveMenuHooks()) { hooks = client->GetMenuHooks(); std::vector<int> hookIDs; CGUIDialogSelect* pDialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); pDialog->Reset(); pDialog->SetHeading(19196); for (unsigned int i = 0; i < hooks->size(); i++) pDialog->Add(client->GetString(hooks->at(i).iLocalizedStringId)); pDialog->DoModal(); int selection = pDialog->GetSelectedLabel(); if (selection >= 0) client->CallMenuHook(hooks->at(selection)); } }
bool CGUIDialogPVRChannelManager::OnClickButtonNewChannel() { int iSelection = 0; if (g_PVRClients->ConnectedClientAmount() > 1) { CGUIDialogSelect* pDlgSelect = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (!pDlgSelect) return false; pDlgSelect->SetHeading(19213); // Select Client PVR_CLIENT_ITR itr; for (itr = m_clientsWithSettingsList.begin() ; itr != m_clientsWithSettingsList.end(); ++itr) pDlgSelect->Add((*itr)->Name()); pDlgSelect->DoModal(); iSelection = pDlgSelect->GetSelectedLabel(); } if (iSelection >= 0 && iSelection < (int)m_clientsWithSettingsList.size()) { int iClientID = m_clientsWithSettingsList[iSelection]->GetID(); CPVRChannelPtr channel(new CPVRChannel(m_bIsRadio)); channel->SetChannelName(g_localizeStrings.Get(19204)); // New channel channel->SetEPGEnabled(g_PVRClients->SupportsEPG(iClientID)); channel->SetClientID(iClientID); if (g_PVRClients->OpenDialogChannelAdd(channel)) Update(); else CGUIDialogOK::ShowAndGetInput(2103, 0, 16029, 0); // Add-on error;Check the log file for details. } return true; }
bool CGUIWindowPVRBase::OpenGroupSelectionDialog(void) { CGUIDialogSelect *dialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (!dialog) return false; CFileItemList options; g_PVRChannelGroups->Get(m_bRadio)->GetGroupList(&options, true); dialog->Reset(); dialog->SetHeading(g_localizeStrings.Get(19146)); dialog->SetItems(&options); dialog->SetMultiSelection(false); dialog->SetSelected(m_group->GroupName()); dialog->DoModal(); if (!dialog->IsConfirmed()) return false; const CFileItemPtr item = dialog->GetSelectedItem(); if (!item) return false; SetGroup(g_PVRChannelGroups->Get(m_bRadio)->GetByName(item->m_strTitle)); return true; }
void CPVRClients::ProcessMenuHooks(int iClientID) { PVR_MENUHOOKS *hooks = NULL; if (iClientID < 0) iClientID = GetPlayingClientID(); if (GetMenuHooks(iClientID, hooks)) { boost::shared_ptr<CPVRClient> client; if (!GetValidClient(iClientID, client)) return; std::vector<int> hookIDs; CGUIDialogSelect* pDialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); pDialog->Reset(); pDialog->SetHeading(19196); for (unsigned int i = 0; i < hooks->size(); i++) pDialog->Add(client->GetString(hooks->at(i).iLocalizedStringId)); pDialog->DoModal(); int selection = pDialog->GetSelectedLabel(); if (selection >= 0) { client->CallMenuHook(hooks->at(selection)); } } else { CLog::Log(LOGERROR, "PVR - %s - cannot find client %d",__FUNCTION__, iClientID); } }
PVR_ERROR CPVRClients::DeleteAllRecordingsFromTrash() { PVR_ERROR error(PVR_ERROR_NO_ERROR); PVR_CLIENTMAP clients; GetConnectedClients(clients); std::vector<PVR_CLIENT> suppClients; for (PVR_CLIENTMAP_CITR itrClients = clients.begin(); itrClients != clients.end(); ++itrClients) { if (itrClients->second->SupportsRecordingsUndelete() && itrClients->second->GetRecordingsAmount(true) > 0) suppClients.push_back(itrClients->second); } int selection = 0; if (suppClients.size() > 1) { // have user select client CGUIDialogSelect* pDialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); pDialog->Reset(); pDialog->SetHeading(19292); /* Delete all permanently */ pDialog->Add(g_localizeStrings.Get(24032)); /* All Add-ons */ PVR_CLIENTMAP_CITR itrClients; for (itrClients = clients.begin(); itrClients != clients.end(); ++itrClients) { if (itrClients->second->SupportsRecordingsUndelete() && itrClients->second->GetRecordingsAmount(true) > 0) pDialog->Add(itrClients->second->GetBackendName()); } pDialog->DoModal(); selection = pDialog->GetSelectedLabel(); } if (selection == 0) { typedef std::vector<PVR_CLIENT>::const_iterator suppClientsCITR; for (suppClientsCITR itrSuppClients = suppClients.begin(); itrSuppClients != suppClients.end(); ++itrSuppClients) { PVR_ERROR currentError = (*itrSuppClients)->DeleteAllRecordingsFromTrash(); if (currentError != PVR_ERROR_NO_ERROR) { CLog::Log(LOGERROR, "PVR - %s - cannot delete all recordings from client '%d': %s",__FUNCTION__, (*itrSuppClients)->GetID(), CPVRClient::ToString(currentError)); error = currentError; } } } else if (selection >= 1 && selection <= (int)suppClients.size()) { PVR_ERROR currentError = suppClients[selection-1]->DeleteAllRecordingsFromTrash(); if (currentError != PVR_ERROR_NO_ERROR) { CLog::Log(LOGERROR, "PVR - %s - cannot delete all recordings from client '%d': %s",__FUNCTION__, suppClients[selection-1]->GetID(), CPVRClient::ToString(currentError)); error = currentError; } } return error; }
void CGUIWindowVideoNav::OnLinkMovieToTvShow(int itemnumber, bool bRemove) { CFileItemList list; if (bRemove) { vector<int> ids; if (!m_database.GetLinksToTvShow(m_vecItems->Get(itemnumber)->GetVideoInfoTag()->m_iDbId,ids)) return; for (unsigned int i=0;i<ids.size();++i) { CVideoInfoTag tag; m_database.GetTvShowInfo("",tag,ids[i]); CFileItemPtr show(new CFileItem(tag)); list.Add(show); } } else { m_database.GetTvShowsNav("videodb://2/2",list); // remove already linked shows vector<int> ids; if (!m_database.GetLinksToTvShow(m_vecItems->Get(itemnumber)->GetVideoInfoTag()->m_iDbId,ids)) return; for (int i=0;i<list.Size();) { unsigned int j; for (j=0;j<ids.size();++j) { if (list[i]->GetVideoInfoTag()->m_iDbId == ids[j]) break; } if (j == ids.size()) i++; else list.Remove(i); } } int iSelectedLabel = 0; if (list.Size() > 1) { list.Sort(g_guiSettings.GetBool("filelists.ignorethewhensorting") ? SORT_METHOD_LABEL_IGNORE_THE : SORT_METHOD_LABEL, SORT_ORDER_ASC); CGUIDialogSelect* pDialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); pDialog->Reset(); pDialog->SetItems(&list); pDialog->SetHeading(20356); pDialog->DoModal(); iSelectedLabel = pDialog->GetSelectedLabel(); } if (iSelectedLabel > -1) { m_database.LinkMovieToTvshow(m_vecItems->Get(itemnumber)->GetVideoInfoTag()->m_iDbId, list[iSelectedLabel]->GetVideoInfoTag()->m_iDbId, bRemove); CUtil::DeleteVideoDatabaseDirectoryCache(); } }
bool CGUIDialogSimpleMenu::ShowPlaySelection(CFileItem& item, const std::string& directory) { CFileItemList items; if (!XFILE::CDirectory::GetDirectory(directory, items, XFILE::CDirectory::CHints(), true)) { CLog::Log(LOGERROR, "CGUIWindowVideoBase::ShowPlaySelection - Failed to get play directory for %s", directory.c_str()); return true; } if (items.IsEmpty()) { CLog::Log(LOGERROR, "CGUIWindowVideoBase::ShowPlaySelection - Failed to get any items %s", directory.c_str()); return true; } CGUIDialogSelect* dialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); while (true) { dialog->Reset(); dialog->SetHeading(25006 /* Select playback item */); dialog->SetItems(&items); dialog->SetUseDetails(true); dialog->DoModal(); CFileItemPtr item_new = dialog->GetSelectedItem(); if (!item_new || dialog->GetSelectedLabel() < 0) { CLog::Log(LOGDEBUG, "CGUIWindowVideoBase::ShowPlaySelection - User aborted %s", directory.c_str()); break; } if (item_new->m_bIsFolder == false) { std::string original_path = item.GetPath(); item.Reset(); item = *item_new; item.SetProperty("original_listitem_url", original_path); return true; } items.Clear(); if (!XFILE::CDirectory::GetDirectory(item_new->GetPath(), items, XFILE::CDirectory::CHints(), true) || items.IsEmpty()) { CLog::Log(LOGERROR, "CGUIWindowVideoBase::ShowPlaySelection - Failed to get any items %s", item_new->GetPath().c_str()); break; } } return false; }
/// \brief Search the current directory for a string got from the virtual keyboard void CGUIWindowVideoInfo::OnSearch(CStdString& strSearch) { if (m_dlgProgress) { m_dlgProgress->SetHeading(194); m_dlgProgress->SetLine(0, strSearch); m_dlgProgress->SetLine(1, ""); m_dlgProgress->SetLine(2, ""); m_dlgProgress->StartModal(); m_dlgProgress->Progress(); } CFileItemList items; DoSearch(strSearch, items); if (items.Size()) { CGUIDialogSelect* pDlgSelect = (CGUIDialogSelect*)m_gWindowManager.GetWindow(WINDOW_DIALOG_SELECT); pDlgSelect->Reset(); pDlgSelect->SetHeading(283); items.Sort(SORT_METHOD_LABEL, SORT_ORDER_ASC); for (int i = 0; i < (int)items.Size(); i++) { CFileItem* pItem = items[i]; pDlgSelect->Add(pItem->GetLabel()); } pDlgSelect->DoModal(); int iItem = pDlgSelect->GetSelectedLabel(); if (iItem < 0) { if (m_dlgProgress) m_dlgProgress->Close(); return ; } CFileItem* pSelItem = new CFileItem(*items[iItem]); OnSearchItemFound(pSelItem); delete pSelItem; if (m_dlgProgress) m_dlgProgress->Close(); } else { if (m_dlgProgress) m_dlgProgress->Close(); CGUIDialogOK::ShowAndGetInput(194, 284, 0, 0); } }
/// \brief Search the current directory for a string got from the virtual keyboard void CGUIDialogVideoInfo::OnSearch(CStdString& strSearch) { CGUIDialogProgress *progress = (CGUIDialogProgress *)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS); if (progress) { progress->SetHeading(194); progress->SetLine(0, strSearch); progress->SetLine(1, ""); progress->SetLine(2, ""); progress->StartModal(); progress->Progress(); } CFileItemList items; DoSearch(strSearch, items); if (progress) progress->Close(); if (items.Size()) { CGUIDialogSelect* pDlgSelect = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); pDlgSelect->Reset(); pDlgSelect->SetHeading(283); for (int i = 0; i < (int)items.Size(); i++) { CFileItemPtr pItem = items[i]; pDlgSelect->Add(pItem->GetLabel()); } pDlgSelect->DoModal(); int iItem = pDlgSelect->GetSelectedLabel(); if (iItem < 0) return; CFileItem* pSelItem = new CFileItem(*items[iItem]); OnSearchItemFound(pSelItem); delete pSelItem; } else { CGUIDialogOK::ShowAndGetInput(194, 284, 0, 0); } }
RENDER_STEREO_MODE CStereoscopicsManager::GetStereoModeByUserChoice(const std::string &heading) { RENDER_STEREO_MODE mode = GetStereoMode(); // if no stereo mode is set already, suggest mode of current video by preselecting it if (mode == RENDER_STEREO_MODE_OFF && g_infoManager.EvaluateBool("videoplayer.isstereoscopic")) mode = GetStereoModeOfPlayingVideo(); CGUIDialogSelect* pDlgSelect = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); pDlgSelect->Reset(); if (heading.empty()) pDlgSelect->SetHeading(g_localizeStrings.Get(36528).c_str()); else pDlgSelect->SetHeading(heading.c_str()); // prepare selectable stereo modes std::vector<RENDER_STEREO_MODE> selectableModes; for (int i = RENDER_STEREO_MODE_OFF; i < RENDER_STEREO_MODE_COUNT; i++) { RENDER_STEREO_MODE selectableMode = (RENDER_STEREO_MODE) i; if (g_Windowing.SupportsStereo(selectableMode)) { selectableModes.push_back(selectableMode); std::string label = GetLabelForStereoMode((RENDER_STEREO_MODE) i); pDlgSelect->Add( label ); if (mode == selectableMode) pDlgSelect->SetSelected( label ); } // inject AUTO pseudo mode after OFF if (i == RENDER_STEREO_MODE_OFF) { selectableModes.push_back(RENDER_STEREO_MODE_AUTO); pDlgSelect->Add(GetLabelForStereoMode(RENDER_STEREO_MODE_AUTO)); } } pDlgSelect->DoModal(); int iItem = pDlgSelect->GetSelectedLabel(); if (iItem > -1 && pDlgSelect->IsConfirmed()) mode = (RENDER_STEREO_MODE) selectableModes[iItem]; else mode = GetStereoMode(); return mode; }
bool CGUIWindowSettingsProfile::GetAutoLoginProfileChoice(int &iProfile) { CGUIDialogSelect *dialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (!dialog) return false; // add items // "Most recent" option comes first, so up indices by 1 int autoLoginProfileId = CProfilesManager::Get().GetAutoLoginProfileId() + 1; CFileItemList items; CFileItemPtr item(new CFileItem()); item->SetLabel(g_localizeStrings.Get(37014)); // Most recent item->SetIconImage("unknown-user.png"); items.Add(item); for (unsigned int i = 0; i < CProfilesManager::Get().GetNumberOfProfiles(); i++) { const CProfile *profile = CProfilesManager::Get().GetProfile(i); CStdString locked = g_localizeStrings.Get(profile->getLockMode() > 0 ? 20166 : 20165); CFileItemPtr item(new CFileItem(profile->getName())); item->SetProperty("Addon.Summary", locked); // lock setting CStdString thumb = profile->getThumb(); if (thumb.IsEmpty()) thumb = "unknown-user.png"; item->SetIconImage(thumb); items.Add(item); } dialog->SetHeading(20093); // Profile name dialog->Reset(); dialog->SetUseDetails(true); dialog->EnableButton(true, 222); // Cancel dialog->SetItems(&items); dialog->SetSelected(autoLoginProfileId); dialog->DoModal(); if (dialog->IsButtonPressed() || dialog->GetSelectedLabel() < 0) return false; // user cancelled iProfile = dialog->GetSelectedLabel() - 1; return true; }
bool CGUIControlListSetting::OnClick() { if (m_pButton == NULL) return false; CGUIDialogSelect *dialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (dialog == NULL) return false; CFileItemList options; if (!GetItems(m_pSetting, options) || options.Size() <= 1) return false; dialog->Reset(); dialog->SetHeading(g_localizeStrings.Get(m_pSetting->GetLabel())); dialog->SetItems(&options); dialog->SetMultiSelection(false); dialog->DoModal(); if (!dialog->IsConfirmed()) return false; const CFileItemPtr item = dialog->GetSelectedItem(); if (item == NULL || !item->HasProperty("value")) return false; CVariant value = item->GetProperty("value"); switch (m_pSetting->GetType()) { case SettingTypeInteger: return ((CSettingInt *)m_pSetting)->SetValue((int)value.asInteger()); case SettingTypeString: return ((CSettingString *)m_pSetting)->SetValue(value.asString()); default: break; } return true; }
string CGUIDialogVideoInfo::ChooseArtType(const CFileItem &videoItem, map<string, string> ¤tArt) { // prompt for choice CGUIDialogSelect *dialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (!dialog || !videoItem.HasVideoInfoTag()) return ""; CFileItemList items; dialog->SetHeading(13511); dialog->Reset(); dialog->SetUseDetails(true); CVideoDatabase db; db.Open(); vector<string> artTypes = CVideoThumbLoader::GetArtTypes(videoItem.GetVideoInfoTag()->m_type); // add in any stored art for this item that is non-empty. db.GetArtForItem(videoItem.GetVideoInfoTag()->m_iDbId, videoItem.GetVideoInfoTag()->m_type, currentArt); for (CGUIListItem::ArtMap::iterator i = currentArt.begin(); i != currentArt.end(); ++i) { if (!i->second.empty() && find(artTypes.begin(), artTypes.end(), i->first) == artTypes.end()) artTypes.push_back(i->first); } for (vector<string>::const_iterator i = artTypes.begin(); i != artTypes.end(); ++i) { string type = *i; CFileItemPtr item(new CFileItem(type, "false")); item->SetLabel(type); if (videoItem.HasArt(type)) item->SetArt("thumb", videoItem.GetArt(type)); items.Add(item); } dialog->SetItems(&items); dialog->DoModal(); return dialog->GetSelectedItem()->GetLabel(); }
bool CMusicInfoScanner::DownloadArtistInfo(const CStdString& strPath, const CStdString& strArtist, bool& bCanceled, CGUIDialogProgress* pDialog) { XFILE::MUSICDATABASEDIRECTORY::CQueryParams params; XFILE::MUSICDATABASEDIRECTORY::CDirectoryNode::GetDatabaseInfo(strPath, params); bCanceled = false; CArtist artist; m_musicDatabase.Open(); if (m_musicDatabase.GetArtistInfo(params.GetArtistId(),artist)) // already got the info return true; // find artist info ADDON::ScraperPtr info; if (!m_musicDatabase.GetScraperForPath(strPath, info, ADDON::ADDON_SCRAPER_ARTISTS) || !info) { m_musicDatabase.Close(); return false; } if (m_handle) { m_handle->SetTitle(StringUtils::Format(g_localizeStrings.Get(20320), info->Name().c_str())); m_handle->SetText(strArtist); } // clear our scraper cache info->ClearCache(); CMusicInfoScraper scraper(info); // handle nfo files CStdString strArtistPath, strNfo; m_musicDatabase.GetArtistPath(params.GetArtistId(),strArtistPath); URIUtils::AddFileToFolder(strArtistPath,"artist.nfo",strNfo); CNfoFile::NFOResult result=CNfoFile::NO_NFO; CNfoFile nfoReader; if (XFILE::CFile::Exists(strNfo)) { CLog::Log(LOGDEBUG,"Found matching nfo file: %s", strNfo.c_str()); result = nfoReader.Create(strNfo, info); if (result == CNfoFile::FULL_NFO) { CLog::Log(LOGDEBUG, "%s Got details from nfo", __FUNCTION__); CArtist artist; nfoReader.GetDetails(artist); m_musicDatabase.SetArtistInfo(params.GetArtistId(), artist); map<string, string> artwork = GetArtistArtwork(params.GetArtistId(), &artist); m_musicDatabase.SetArtForItem(params.GetArtistId(), "artist", artwork); m_musicDatabase.Close(); return true; } else if (result == CNfoFile::URL_NFO || result == CNfoFile::COMBINED_NFO) { CScraperUrl scrUrl(nfoReader.ScraperUrl()); CMusicArtistInfo artist("nfo",scrUrl); info = nfoReader.GetScraperInfo(); CLog::Log(LOGDEBUG,"-- nfo-scraper: %s",info->Name().c_str()); CLog::Log(LOGDEBUG,"-- nfo url: %s", scrUrl.m_url[0].m_url.c_str()); scraper.SetScraperInfo(info); scraper.GetArtists().push_back(artist); } else CLog::Log(LOGERROR,"Unable to find an url in nfo file: %s", strNfo.c_str()); } if (!scraper.GetArtistCount()) { scraper.FindArtistInfo(strArtist); while (!scraper.Completed()) { if (m_bStop) { scraper.Cancel(); bCanceled = true; } Sleep(1); } } int iSelectedArtist = 0; if (result == CNfoFile::NO_NFO) { if (scraper.Succeeded() && scraper.GetArtistCount() >= 1) { // now load the first match if (pDialog && scraper.GetArtistCount() > 1) { // if we found more then 1 album, let user choose one CGUIDialogSelect *pDlg = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (pDlg) { pDlg->SetHeading(g_localizeStrings.Get(21890)); pDlg->Reset(); pDlg->EnableButton(true, 413); // manual for (int i = 0; i < scraper.GetArtistCount(); ++i) { // set the label to artist CFileItem item(scraper.GetArtist(i).GetArtist()); CStdString strTemp=scraper.GetArtist(i).GetArtist().strArtist; if (!scraper.GetArtist(i).GetArtist().strBorn.IsEmpty()) strTemp += " ("+scraper.GetArtist(i).GetArtist().strBorn+")"; if (!scraper.GetArtist(i).GetArtist().genre.empty()) { CStdString genres = StringUtils::Join(scraper.GetArtist(i).GetArtist().genre, g_advancedSettings.m_musicItemSeparator); if (!genres.empty()) strTemp.Format("[%s] %s", genres.c_str(), strTemp.c_str()); } item.SetLabel(strTemp); item.m_idepth = i; // use this to hold the index of the album in the scraper pDlg->Add(&item); } pDlg->DoModal(); // and wait till user selects one if (pDlg->GetSelectedLabel() < 0) { // none chosen if (!pDlg->IsButtonPressed()) { bCanceled = true; return false; } // manual button pressed CStdString strNewArtist = strArtist; if (!CGUIKeyboardFactory::ShowAndGetInput(strNewArtist, g_localizeStrings.Get(16025), false)) return false; if (pDialog) { pDialog->SetLine(0, strNewArtist); pDialog->Progress(); } m_musicDatabase.Close(); return DownloadArtistInfo(strPath,strNewArtist,bCanceled,pDialog); } iSelectedArtist = pDlg->GetSelectedItem()->m_idepth; } } } else { m_musicDatabase.Close(); return false; } } scraper.LoadArtistInfo(iSelectedArtist, strArtist); while (!scraper.Completed()) { if (m_bStop) { scraper.Cancel(); bCanceled = true; } Sleep(1); } if (scraper.Succeeded()) { artist = scraper.GetArtist(iSelectedArtist).GetArtist(); if (result == CNfoFile::COMBINED_NFO) nfoReader.GetDetails(artist,NULL,true); m_musicDatabase.SetArtistInfo(params.GetArtistId(), artist); } // check thumb stuff map<string, string> artwork = GetArtistArtwork(params.GetArtistId(), &artist); m_musicDatabase.SetArtForItem(params.GetArtistId(), "artist", artwork); m_musicDatabase.Close(); return true; }
bool CGUIDialogAddonSettings::ShowVirtualKeyboard(int iControl) { int controlId = CONTROL_START_SETTING; bool bCloseDialog = false; const TiXmlElement *setting = GetFirstSetting(); while (setting) { if (controlId == iControl) { const CGUIControl* control = GetControl(controlId); const std::string id = XMLUtils::GetAttribute(setting, "id"); const std::string type = XMLUtils::GetAttribute(setting, "type"); //Special handling for actions: does not require id attribute. TODO: refactor me. if (control && control->GetControlType() == CGUIControl::GUICONTROL_BUTTON && type == "action") { const char *option = setting->Attribute("option"); std::string action = XMLUtils::GetAttribute(setting, "action"); if (!action.empty()) { // replace $CWD with the url of plugin/script StringUtils::Replace(action, "$CWD", m_addon->Path()); StringUtils::Replace(action, "$ID", m_addon->ID()); if (option) bCloseDialog = (strcmpi(option, "close") == 0); CApplicationMessenger::Get().ExecBuiltIn(action); } break; } if (control && control->GetControlType() == CGUIControl::GUICONTROL_BUTTON && !id.empty() && !type.empty()) { const char *option = setting->Attribute("option"); const char *source = setting->Attribute("source"); std::string value = m_buttonValues[id]; std::string label = GetString(setting->Attribute("label")); if (type == "text") { // get any options bool bHidden = false; bool bEncoded = false; if (option) { bHidden = (strstr(option, "hidden") != NULL); bEncoded = (strstr(option, "urlencoded") != NULL); } if (bEncoded) value = CURL::Decode(value); if (CGUIKeyboardFactory::ShowAndGetInput(value, label, true, bHidden)) { // if hidden hide input if (bHidden) { std::string hiddenText; hiddenText.append(value.size(), L'*'); ((CGUIButtonControl *)control)->SetLabel2(hiddenText); } else ((CGUIButtonControl*) control)->SetLabel2(value); if (bEncoded) value = CURL::Encode(value); } } else if (type == "number" && CGUIDialogNumeric::ShowAndGetNumber(value, label)) { ((CGUIButtonControl*) control)->SetLabel2(value); } else if (type == "ipaddress" && CGUIDialogNumeric::ShowAndGetIPAddress(value, label)) { ((CGUIButtonControl*) control)->SetLabel2(value); } else if (type == "select") { CGUIDialogSelect *pDlg = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (pDlg) { pDlg->SetHeading(label.c_str()); pDlg->Reset(); int selected = -1; vector<std::string> valuesVec; if (setting->Attribute("values")) StringUtils::Tokenize(setting->Attribute("values"), valuesVec, "|"); else if (setting->Attribute("lvalues")) { // localize StringUtils::Tokenize(setting->Attribute("lvalues"), valuesVec, "|"); for (unsigned int i = 0; i < valuesVec.size(); i++) { if (i == (unsigned int)atoi(value.c_str())) selected = i; std::string localized = m_addon->GetString(atoi(valuesVec[i].c_str())); if (localized.empty()) localized = g_localizeStrings.Get(atoi(valuesVec[i].c_str())); valuesVec[i] = localized; } } else if (source) { valuesVec = GetFileEnumValues(source, XMLUtils::GetAttribute(setting, "mask"), XMLUtils::GetAttribute(setting, "option")); } for (unsigned int i = 0; i < valuesVec.size(); i++) { pDlg->Add(valuesVec[i]); if (selected == (int)i || (selected < 0 && StringUtils::EqualsNoCase(valuesVec[i], value))) pDlg->SetSelected(i); // FIXME: the SetSelected() does not select "i", it always defaults to the first position } pDlg->DoModal(); int iSelected = pDlg->GetSelectedLabel(); if (iSelected >= 0) { if (setting->Attribute("lvalues")) value = StringUtils::Format("%i", iSelected); else value = valuesVec[iSelected]; ((CGUIButtonControl*) control)->SetLabel2(valuesVec[iSelected]); } } } else if (type == "audio" || type == "video" || type == "image" || type == "executable" || type == "file" || type == "folder") { // setup the shares VECSOURCES *shares = NULL; if (source && strcmpi(source, "") != 0) shares = CMediaSourceSettings::Get().GetSources(source); VECSOURCES localShares; if (!shares) { g_mediaManager.GetLocalDrives(localShares); if (!source || strcmpi(source, "local") != 0) g_mediaManager.GetNetworkLocations(localShares); } else // always append local drives { localShares = *shares; g_mediaManager.GetLocalDrives(localShares); } if (type == "folder") { // get any options bool bWriteOnly = false; if (option) bWriteOnly = (strcmpi(option, "writeable") == 0); if (CGUIDialogFileBrowser::ShowAndGetDirectory(localShares, label, value, bWriteOnly)) ((CGUIButtonControl*) control)->SetLabel2(value); } else if (type == "image") { if (CGUIDialogFileBrowser::ShowAndGetImage(localShares, label, value)) ((CGUIButtonControl*) control)->SetLabel2(value); } else { // set the proper mask std::string strMask; if (setting->Attribute("mask")) { strMask = setting->Attribute("mask"); // convert mask qualifiers StringUtils::Replace(strMask, "$AUDIO", g_advancedSettings.GetMusicExtensions()); StringUtils::Replace(strMask, "$VIDEO", g_advancedSettings.m_videoExtensions); StringUtils::Replace(strMask, "$IMAGE", g_advancedSettings.m_pictureExtensions); #if defined(_WIN32_WINNT) StringUtils::Replace(strMask, "$EXECUTABLE", ".exe|.bat|.cmd|.py"); #else StringUtils::Replace(strMask, "$EXECUTABLE", ""); #endif } else { if (type == "video") strMask = g_advancedSettings.m_videoExtensions; else if (type == "audio") strMask = g_advancedSettings.GetMusicExtensions(); else if (type == "executable") #if defined(_WIN32_WINNT) strMask = ".exe|.bat|.cmd|.py"; #else strMask = ""; #endif } // get any options bool bUseThumbs = false; bool bUseFileDirectories = false; if (option) { vector<string> options = StringUtils::Split(option, '|'); bUseThumbs = find(options.begin(), options.end(), "usethumbs") != options.end(); bUseFileDirectories = find(options.begin(), options.end(), "treatasfolder") != options.end(); } if (CGUIDialogFileBrowser::ShowAndGetFile(localShares, strMask, label, value, bUseThumbs, bUseFileDirectories)) ((CGUIButtonControl*) control)->SetLabel2(value); } } else if (type == "date") { CDateTime date; if (!value.empty()) date.SetFromDBDate(value); SYSTEMTIME timedate; date.GetAsSystemTime(timedate); if(CGUIDialogNumeric::ShowAndGetDate(timedate, label)) { date = timedate; value = date.GetAsDBDate(); ((CGUIButtonControl*) control)->SetLabel2(value); } } else if (type == "time") { SYSTEMTIME timedate; if (value.size() >= 5) { // assumes HH:MM timedate.wHour = atoi(value.substr(0, 2).c_str()); timedate.wMinute = atoi(value.substr(3, 2).c_str()); } if (CGUIDialogNumeric::ShowAndGetTime(timedate, label)) { value = StringUtils::Format("%02d:%02d", timedate.wHour, timedate.wMinute); ((CGUIButtonControl*) control)->SetLabel2(value); } } else if (type == "addon") { const char *strType = setting->Attribute("addontype"); if (strType) { vector<string> addonTypes = StringUtils::Split(strType, ','); vector<ADDON::TYPE> types; for (vector<string>::iterator i = addonTypes.begin(); i != addonTypes.end(); ++i) { StringUtils::Trim(*i); ADDON::TYPE type = TranslateType(*i); if (type != ADDON_UNKNOWN) types.push_back(type); } if (types.size() > 0) { const char *strMultiselect = setting->Attribute("multiselect"); bool multiSelect = strMultiselect && strcmpi(strMultiselect, "true") == 0; if (multiSelect) { // construct vector of addon IDs (IDs are comma seperated in single string) vector<string> addonIDs = StringUtils::Split(value, ','); if (CGUIWindowAddonBrowser::SelectAddonID(types, addonIDs, false) == 1) { value = StringUtils::Join(addonIDs, ","); ((CGUIButtonControl*) control)->SetLabel2(GetAddonNames(value)); } } else // no need of string splitting/joining if we select only 1 addon if (CGUIWindowAddonBrowser::SelectAddonID(types, value, false) == 1) ((CGUIButtonControl*) control)->SetLabel2(GetAddonNames(value)); } } } m_buttonValues[id] = value; break; } } setting = setting->NextSiblingElement("setting"); controlId++; } EnableControls(); return bCloseDialog; }
bool CGUIDialogPVRChannelManager::OnClickButtonNewChannel(CGUIMessage &message) { std::vector<long> clients; CGUIDialogSelect* pDlgSelect = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (!pDlgSelect) return false; pDlgSelect->SetHeading(19213); // Select Client pDlgSelect->Add(g_localizeStrings.Get(19209)); clients.push_back(PVR_VIRTUAL_CLIENT_ID); PVR_CLIENTMAP clientMap; if (g_PVRClients->GetConnectedClients(clientMap) > 0) { PVR_CLIENTMAP_ITR itr; for (itr = clientMap.begin() ; itr != clientMap.end(); itr++) { clients.push_back((*itr).first); pDlgSelect->Add((*itr).second->Name()); } } pDlgSelect->DoModal(); int selection = pDlgSelect->GetSelectedLabel(); if (selection >= 0 && selection <= (int) clients.size()) { int clientID = clients[selection]; if (clientID == PVR_VIRTUAL_CLIENT_ID) { CStdString strURL = ""; if (CGUIKeyboardFactory::ShowAndGetInput(strURL, g_localizeStrings.Get(19214), false)) { if (!strURL.empty()) { CPVRChannel *newchannel = new CPVRChannel(m_bIsRadio); newchannel->SetChannelName(g_localizeStrings.Get(19204)); newchannel->SetEPGEnabled(false); newchannel->SetVirtual(true); newchannel->SetStreamURL(strURL); newchannel->SetClientID(PVR_VIRTUAL_CLIENT_ID); if (g_PVRChannelGroups->CreateChannel(*newchannel)) g_PVRChannelGroups->GetGroupAll(m_bIsRadio)->Persist(); CFileItemPtr channel(new CFileItem(*newchannel)); if (channel) { channel->SetProperty("ActiveChannel", true); channel->SetProperty("Name", g_localizeStrings.Get(19204)); channel->SetProperty("UseEPG", false); channel->SetProperty("Icon", newchannel->IconPath()); channel->SetProperty("EPGSource", (int)0); channel->SetProperty("ClientName", g_localizeStrings.Get(19209)); channel->SetProperty("ParentalLocked", false); m_channelItems->AddFront(channel, m_iSelected); m_viewControl.SetItems(*m_channelItems); Renumber(); } } } } else { CGUIDialogOK::ShowAndGetInput(19033,19038,0,0); } } return true; }
bool CWeather::GetSearchResults(const CStdString &strSearch, CStdString &strResult) { // Check to see if the user entered a weather.com code if (strSearch.size() == 8) { strResult = ""; int i = 0; for (i = 0; i < 4; ++i) { strResult += toupper(strSearch[i]); if (!isalpha(strSearch[i])) break; } if (i == 4) { for ( ; i < 8; ++i) { strResult += strSearch[i]; if (!isdigit(strSearch[i])) break; } if (i == 8) { return true; // match } } // no match, wipe string strResult = ""; } CGUIDialogSelect *pDlgSelect = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); CGUIDialogProgress *pDlgProgress = (CGUIDialogProgress*)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS); //do the download CStdString strURL; CStdString strXML; XFILE::CFileCurl httpUtil; if (pDlgProgress) { pDlgProgress->SetHeading(410); //"Accessing Weather.com" pDlgProgress->SetLine(0, 194); //"Searching" pDlgProgress->SetLine(1, strSearch); pDlgProgress->SetLine(2, ""); pDlgProgress->StartModal(); pDlgProgress->Progress(); } strURL.Format("http://xoap.weather.com/search/search?where=%s", strSearch); if (!httpUtil.Get(strURL, strXML)) { if (pDlgProgress) pDlgProgress->Close(); return false; } //some select dialog init stuff if (!pDlgSelect) { if (pDlgProgress) pDlgProgress->Close(); return false; } pDlgSelect->SetHeading(396); //"Select Location" pDlgSelect->Reset(); /////////////////////////////// // load the xml file /////////////////////////////// TiXmlDocument xmlDoc; xmlDoc.Parse(strXML.c_str()); if (xmlDoc.Error()) return false; TiXmlElement *pRootElement = xmlDoc.RootElement(); if (pRootElement) { CStdString strItemTmp; TiXmlElement *pElement = pRootElement->FirstChildElement("loc"); while (pElement) { if (!pElement->NoChildren()) { strItemTmp.Format("%s - %s", pElement->Attribute("id"), pElement->FirstChild()->Value()); pDlgSelect->Add(strItemTmp); } pElement = pElement->NextSiblingElement("loc"); } } if (pDlgProgress) pDlgProgress->Close(); pDlgSelect->EnableButton(true, 222); //'Cancel' button returns to weather settings pDlgSelect->DoModal(); if (pDlgSelect->GetSelectedLabel() < 0) { if (pDlgSelect->IsButtonPressed()) { pDlgSelect->Close(); //close the select dialog and return to weather settings return true; } } //copy the selected code into the settings if (pDlgSelect->GetSelectedLabel() >= 0) strResult = pDlgSelect->GetSelectedLabelText(); if (pDlgProgress) pDlgProgress->Close(); return true; }
INFO_RET CMusicInfoScanner::DownloadArtistInfo(const CArtist& artist, const ADDON::ScraperPtr& info, MUSIC_GRABBER::CMusicArtistInfo& artistInfo, CGUIDialogProgress* pDialog) { if (m_handle) { m_handle->SetTitle(StringUtils::Format(g_localizeStrings.Get(20320).c_str(), info->Name().c_str())); m_handle->SetText(artist.strArtist); } // clear our scraper cache info->ClearCache(); CMusicInfoScraper scraper(info); bool bMusicBrainz = false; if (!artist.strMusicBrainzArtistID.empty()) { CScraperUrl musicBrainzURL; if (ResolveMusicBrainz(artist.strMusicBrainzArtistID, info, musicBrainzURL)) { CMusicArtistInfo artistNfo("nfo", musicBrainzURL); scraper.GetArtists().clear(); scraper.GetArtists().push_back(artistNfo); bMusicBrainz = true; } } // handle nfo files std::string path = artist.strPath; if (path.empty()) m_musicDatabase.GetArtistPath(artist.idArtist, path); std::string strNfo = URIUtils::AddFileToFolder(path, "artist.nfo"); CNfoFile::NFOResult result=CNfoFile::NO_NFO; CNfoFile nfoReader; if (XFILE::CFile::Exists(strNfo)) { CLog::Log(LOGDEBUG,"Found matching nfo file: %s", strNfo.c_str()); result = nfoReader.Create(strNfo, info); if (result == CNfoFile::FULL_NFO) { CLog::Log(LOGDEBUG, "%s Got details from nfo", __FUNCTION__); nfoReader.GetDetails(artistInfo.GetArtist()); return INFO_ADDED; } else if (result == CNfoFile::URL_NFO || result == CNfoFile::COMBINED_NFO) { CScraperUrl scrUrl(nfoReader.ScraperUrl()); CMusicArtistInfo artistNfo("nfo",scrUrl); ADDON::ScraperPtr nfoReaderScraper = nfoReader.GetScraperInfo(); CLog::Log(LOGDEBUG,"-- nfo-scraper: %s",nfoReaderScraper->Name().c_str()); CLog::Log(LOGDEBUG,"-- nfo url: %s", scrUrl.m_url[0].m_url.c_str()); scraper.SetScraperInfo(nfoReaderScraper); scraper.GetArtists().push_back(artistNfo); } else CLog::Log(LOGERROR,"Unable to find an url in nfo file: %s", strNfo.c_str()); } if (!scraper.GetArtistCount()) { scraper.FindArtistInfo(artist.strArtist); while (!scraper.Completed()) { if (m_bStop) { scraper.Cancel(); return INFO_CANCELLED; } Sleep(1); } } int iSelectedArtist = 0; if (result == CNfoFile::NO_NFO && !bMusicBrainz) { if (scraper.GetArtistCount() >= 1) { // now load the first match if (pDialog && scraper.GetArtistCount() > 1) { // if we found more then 1 album, let user choose one CGUIDialogSelect *pDlg = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (pDlg) { pDlg->SetHeading(g_localizeStrings.Get(21890)); pDlg->Reset(); pDlg->EnableButton(true, 413); // manual for (int i = 0; i < scraper.GetArtistCount(); ++i) { // set the label to artist CFileItem item(scraper.GetArtist(i).GetArtist()); std::string strTemp=scraper.GetArtist(i).GetArtist().strArtist; if (!scraper.GetArtist(i).GetArtist().strBorn.empty()) strTemp += " ("+scraper.GetArtist(i).GetArtist().strBorn+")"; if (!scraper.GetArtist(i).GetArtist().genre.empty()) { std::string genres = StringUtils::Join(scraper.GetArtist(i).GetArtist().genre, g_advancedSettings.m_musicItemSeparator); if (!genres.empty()) strTemp = StringUtils::Format("[%s] %s", genres.c_str(), strTemp.c_str()); } item.SetLabel(strTemp); item.m_idepth = i; // use this to hold the index of the album in the scraper pDlg->Add(&item); } pDlg->DoModal(); // and wait till user selects one if (pDlg->GetSelectedLabel() < 0) { // none chosen if (!pDlg->IsButtonPressed()) return INFO_CANCELLED; // manual button pressed std::string strNewArtist = artist.strArtist; if (!CGUIKeyboardFactory::ShowAndGetInput(strNewArtist, g_localizeStrings.Get(16025), false)) return INFO_CANCELLED; if (pDialog) { pDialog->SetLine(0, strNewArtist); pDialog->Progress(); } CArtist newArtist; newArtist.strArtist = strNewArtist; return DownloadArtistInfo(newArtist, info, artistInfo, pDialog); } iSelectedArtist = pDlg->GetSelectedItem()->m_idepth; } } } else return INFO_NOT_FOUND; } scraper.LoadArtistInfo(iSelectedArtist, artist.strArtist); while (!scraper.Completed()) { if (m_bStop) { scraper.Cancel(); return INFO_CANCELLED; } Sleep(1); } if (!scraper.Succeeded()) return INFO_ERROR; artistInfo = scraper.GetArtist(iSelectedArtist); if (result == CNfoFile::COMBINED_NFO) nfoReader.GetDetails(artistInfo.GetArtist(), NULL, true); return INFO_ADDED; }
void CGUIDialogSmartPlaylistRule::OnBrowse() { CFileItemList items; CMusicDatabase database; database.Open(); CVideoDatabase videodatabase; videodatabase.Open(); VIDEODB_CONTENT_TYPE type = VIDEODB_CONTENT_MOVIES; if (m_type.Equals("tvshows")) type = VIDEODB_CONTENT_TVSHOWS; else if (m_type.Equals("musicvideos")) type = VIDEODB_CONTENT_MUSICVIDEOS; else if (m_type.Equals("episodes")) type = VIDEODB_CONTENT_EPISODES; int iLabel = 0; if (m_rule.m_field == CSmartPlaylistRule::FIELD_GENRE) { if (m_type.Equals("tvshows") || m_type.Equals("episodes") || m_type.Equals("movies")) videodatabase.GetGenresNav("videodb://2/1/",items,type); else if (m_type.Equals("songs") || m_type.Equals("albums") || m_type.Equals("mixed")) database.GetGenresNav("musicdb://4/",items); if (m_type.Equals("musicvideos") || m_type.Equals("mixed")) { CFileItemList items2; videodatabase.GetGenresNav("videodb://3/1/",items2,VIDEODB_CONTENT_MUSICVIDEOS); items.Append(items2); } iLabel = 515; } else if (m_rule.m_field == CSmartPlaylistRule::FIELD_COUNTRY) { videodatabase.GetCountriesNav("videodb://2/1/",items,type); iLabel = 574; } else if (m_rule.m_field == CSmartPlaylistRule::FIELD_ARTIST || m_rule.m_field == CSmartPlaylistRule::FIELD_ALBUMARTIST) { if (m_type.Equals("songs") || m_type.Equals("mixed") || m_type.Equals("albums")) database.GetArtistsNav("musicdb://5/",items,-1,m_rule.m_field == CSmartPlaylistRule::FIELD_ALBUMARTIST); if (m_type.Equals("musicvideos") || m_type.Equals("mixed")) { CFileItemList items2; videodatabase.GetMusicVideoArtistsByName("",items2); items.Append(items2); } iLabel = 557; } else if (m_rule.m_field == CSmartPlaylistRule::FIELD_ALBUM) { if (m_type.Equals("songs") || m_type.Equals("mixed") || m_type.Equals("albums")) database.GetAlbumsNav("musicdb://6/",items,-1,-1,-1,-1); if (m_type.Equals("musicvideos") || m_type.Equals("mixed")) { CFileItemList items2; videodatabase.GetMusicVideoAlbumsByName("",items2); items.Append(items2); } iLabel = 558; } else if (m_rule.m_field == CSmartPlaylistRule::FIELD_ACTOR) { videodatabase.GetActorsNav("",items,type); iLabel = 20337; } else if (m_rule.m_field == CSmartPlaylistRule::FIELD_DIRECTOR) { videodatabase.GetDirectorsNav("",items,type); iLabel = 20339; } else if (m_rule.m_field == CSmartPlaylistRule::FIELD_STUDIO) { videodatabase.GetStudiosNav("",items,type); iLabel = 572; } else if (m_rule.m_field == CSmartPlaylistRule::FIELD_WRITER) { videodatabase.GetWritersNav("",items,type); iLabel = 20417; } else if (m_rule.m_field == CSmartPlaylistRule::FIELD_TVSHOWTITLE) { videodatabase.GetTvShowsNav("",items); iLabel = 20343; } else if (m_rule.m_field == CSmartPlaylistRule::FIELD_PLAYLIST) { // use filebrowser to grab another smart playlist // Note: This can cause infinite loops (playlist that refers to the same playlist) but I don't // think there's any decent way to deal with this, as the infinite loop may be an arbitrary // number of playlists deep, eg playlist1 -> playlist2 -> playlist3 ... -> playlistn -> playlist1 CStdString path = "special://videoplaylists/"; if (m_type.Equals("songs") || m_type.Equals("albums")) path = "special://musicplaylists/"; XFILE::CDirectory::GetDirectory(path, items, ".xsp",false,false,XFILE::DIR_CACHE_ONCE,true,true); iLabel = 559; } else if (m_rule.m_field == CSmartPlaylistRule::FIELD_PATH) { VECSOURCES sources; if (m_type == "songs" || m_type == "mixed") sources = *g_settings.GetSourcesFromType("music"); if (m_type != "songs") { VECSOURCES sources2 = *g_settings.GetSourcesFromType("video"); sources.insert(sources.end(),sources2.begin(),sources2.end()); } g_mediaManager.GetLocalDrives(sources); CGUIDialogFileBrowser::ShowAndGetDirectory(sources,g_localizeStrings.Get(657),m_rule.m_parameter,false); UpdateButtons(); return; } else { // TODO: Add browseability in here. assert(false); } // sort the items items.Sort(SORT_METHOD_LABEL, SORT_ORDER_ASC); CGUIDialogSelect* pDialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); pDialog->Reset(); pDialog->SetItems(&items); CStdString strHeading; strHeading.Format(g_localizeStrings.Get(13401),g_localizeStrings.Get(iLabel)); pDialog->SetHeading(strHeading); pDialog->DoModal(); if (pDialog->GetSelectedLabel() > -1) { m_rule.m_parameter = pDialog->GetSelectedLabelText(); UpdateButtons(); } pDialog->Reset(); }
INFO_RET CMusicInfoScanner::DownloadAlbumInfo(const CAlbum& album, const ADDON::ScraperPtr& info, CMusicAlbumInfo& albumInfo, CGUIDialogProgress* pDialog) { if (m_handle) { m_handle->SetTitle(StringUtils::Format(g_localizeStrings.Get(20321).c_str(), info->Name().c_str())); m_handle->SetText(StringUtils::Join(album.artist, g_advancedSettings.m_musicItemSeparator) + " - " + album.strAlbum); } // clear our scraper cache info->ClearCache(); CMusicInfoScraper scraper(info); bool bMusicBrainz = false; if (!album.strMusicBrainzAlbumID.empty()) { CScraperUrl musicBrainzURL; if (ResolveMusicBrainz(album.strMusicBrainzAlbumID, info, musicBrainzURL)) { CMusicAlbumInfo albumNfo("nfo", musicBrainzURL); scraper.GetAlbums().clear(); scraper.GetAlbums().push_back(albumNfo); bMusicBrainz = true; } } // handle nfo files std::string path = album.strPath; if (path.empty()) m_musicDatabase.GetAlbumPath(album.idAlbum, path); std::string strNfo = URIUtils::AddFileToFolder(path, "album.nfo"); CNfoFile::NFOResult result = CNfoFile::NO_NFO; CNfoFile nfoReader; if (XFILE::CFile::Exists(strNfo)) { CLog::Log(LOGDEBUG,"Found matching nfo file: %s", strNfo.c_str()); result = nfoReader.Create(strNfo, info); if (result == CNfoFile::FULL_NFO) { CLog::Log(LOGDEBUG, "%s Got details from nfo", __FUNCTION__); nfoReader.GetDetails(albumInfo.GetAlbum()); return INFO_ADDED; } else if (result == CNfoFile::URL_NFO || result == CNfoFile::COMBINED_NFO) { CScraperUrl scrUrl(nfoReader.ScraperUrl()); CMusicAlbumInfo albumNfo("nfo",scrUrl); ADDON::ScraperPtr nfoReaderScraper = nfoReader.GetScraperInfo(); CLog::Log(LOGDEBUG,"-- nfo-scraper: %s", nfoReaderScraper->Name().c_str()); CLog::Log(LOGDEBUG,"-- nfo url: %s", scrUrl.m_url[0].m_url.c_str()); scraper.SetScraperInfo(nfoReaderScraper); scraper.GetAlbums().clear(); scraper.GetAlbums().push_back(albumNfo); } else CLog::Log(LOGERROR,"Unable to find an url in nfo file: %s", strNfo.c_str()); } if (!scraper.CheckValidOrFallback(CSettings::Get().GetString("musiclibrary.albumsscraper"))) { // the current scraper is invalid, as is the default - bail CLog::Log(LOGERROR, "%s - current and default scrapers are invalid. Pick another one", __FUNCTION__); return INFO_ERROR; } if (!scraper.GetAlbumCount()) { scraper.FindAlbumInfo(album.strAlbum, StringUtils::Join(album.artist, g_advancedSettings.m_musicItemSeparator)); while (!scraper.Completed()) { if (m_bStop) { scraper.Cancel(); return INFO_CANCELLED; } Sleep(1); } } CGUIDialogSelect *pDlg = NULL; int iSelectedAlbum=0; if (result == CNfoFile::NO_NFO && !bMusicBrainz) { iSelectedAlbum = -1; // set negative so that we can detect a failure if (scraper.Succeeded() && scraper.GetAlbumCount() >= 1) { double bestRelevance = 0; double minRelevance = THRESHOLD; if (scraper.GetAlbumCount() > 1) // score the matches { //show dialog with all albums found if (pDialog) { pDlg = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); pDlg->SetHeading(g_localizeStrings.Get(181).c_str()); pDlg->Reset(); pDlg->EnableButton(true, 413); // manual } for (int i = 0; i < scraper.GetAlbumCount(); ++i) { CMusicAlbumInfo& info = scraper.GetAlbum(i); double relevance = info.GetRelevance(); if (relevance < 0) relevance = CUtil::AlbumRelevance(info.GetAlbum().strAlbum, album.strAlbum, StringUtils::Join(info.GetAlbum().artist, g_advancedSettings.m_musicItemSeparator), StringUtils::Join(album.artist, g_advancedSettings.m_musicItemSeparator)); // if we're doing auto-selection (ie querying all albums at once, then allow 95->100% for perfect matches) // otherwise, perfect matches only if (relevance >= max(minRelevance, bestRelevance)) { // we auto-select the best of these bestRelevance = relevance; iSelectedAlbum = i; } if (pDialog) { // set the label to [relevance] album - artist std::string strTemp = StringUtils::Format("[%0.2f] %s", relevance, info.GetTitle2().c_str()); CFileItem item(strTemp); item.m_idepth = i; // use this to hold the index of the album in the scraper pDlg->Add(&item); } if (relevance > .99f) // we're so close, no reason to search further break; } if (pDialog && bestRelevance < THRESHOLD) { pDlg->Sort(false); pDlg->DoModal(); // and wait till user selects one if (pDlg->GetSelectedLabel() < 0) { // none chosen if (!pDlg->IsButtonPressed()) return INFO_CANCELLED; // manual button pressed std::string strNewAlbum = album.strAlbum; if (!CGUIKeyboardFactory::ShowAndGetInput(strNewAlbum, g_localizeStrings.Get(16011), false)) return INFO_CANCELLED; if (strNewAlbum == "") return INFO_CANCELLED; std::string strNewArtist = StringUtils::Join(album.artist, g_advancedSettings.m_musicItemSeparator); if (!CGUIKeyboardFactory::ShowAndGetInput(strNewArtist, g_localizeStrings.Get(16025), false)) return INFO_CANCELLED; pDialog->SetLine(0, strNewAlbum); pDialog->SetLine(1, strNewArtist); pDialog->Progress(); CAlbum newAlbum = album; newAlbum.strAlbum = strNewAlbum; newAlbum.artist = StringUtils::Split(strNewArtist, g_advancedSettings.m_musicItemSeparator); return DownloadAlbumInfo(newAlbum, info, albumInfo, pDialog); } iSelectedAlbum = pDlg->GetSelectedItem()->m_idepth; } } else { CMusicAlbumInfo& info = scraper.GetAlbum(0); double relevance = info.GetRelevance(); if (relevance < 0) relevance = CUtil::AlbumRelevance(info.GetAlbum().strAlbum, album.strAlbum, StringUtils::Join(info.GetAlbum().artist, g_advancedSettings.m_musicItemSeparator), StringUtils::Join(album.artist, g_advancedSettings.m_musicItemSeparator)); if (relevance < THRESHOLD) return INFO_NOT_FOUND; iSelectedAlbum = 0; } } if (iSelectedAlbum < 0) return INFO_NOT_FOUND; } scraper.LoadAlbumInfo(iSelectedAlbum); while (!scraper.Completed()) { if (m_bStop) { scraper.Cancel(); return INFO_CANCELLED; } Sleep(1); } if (!scraper.Succeeded()) return INFO_ERROR; albumInfo = scraper.GetAlbum(iSelectedAlbum); if (result == CNfoFile::COMBINED_NFO) nfoReader.GetDetails(albumInfo.GetAlbum(), NULL, true); return INFO_ADDED; }
int CGUIWindowAddonBrowser::SelectAddonID(const vector<ADDON::TYPE> &types, CStdStringArray &addonIDs, bool showNone /*= false*/, bool multipleSelection /*= true*/) { CGUIDialogSelect *dialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (!dialog) return 0; CFileItemList items; CStdString heading; int iTypes = 0; for (vector<ADDON::TYPE>::const_iterator it = types.begin(); it != types.end(); ++it) { if (*it == ADDON_UNKNOWN) continue; ADDON::VECADDONS addons; iTypes++; if (*it == ADDON_AUDIO) CAddonsDirectory::GetScriptsAndPlugins("audio",addons); else if (*it == ADDON_EXECUTABLE) CAddonsDirectory::GetScriptsAndPlugins("executable",addons); else if (*it == ADDON_IMAGE) CAddonsDirectory::GetScriptsAndPlugins("image",addons); else if (*it == ADDON_VIDEO) CAddonsDirectory::GetScriptsAndPlugins("video",addons); else CAddonMgr::Get().GetAddons(*it, addons); for (ADDON::IVECADDONS it2 = addons.begin() ; it2 != addons.end() ; ++it2) { CFileItemPtr item(CAddonsDirectory::FileItemFromAddon(*it2, "")); if (!items.Contains(item->GetPath())) items.Add(item); } if (!heading.IsEmpty()) heading += ", "; heading += TranslateType(*it, true); } if (iTypes == 0) return 0; dialog->SetHeading(heading); dialog->Reset(); dialog->SetUseDetails(true); if (multipleSelection) showNone = false; if (multipleSelection || iTypes > 1) dialog->EnableButton(true, 186); else dialog->EnableButton(true, 21452); if (showNone) { CFileItemPtr item(new CFileItem("", false)); item->SetLabel(g_localizeStrings.Get(231)); item->SetLabel2(g_localizeStrings.Get(24040)); item->SetIconImage("DefaultAddonNone.png"); item->SetSpecialSort(SortSpecialOnTop); items.Add(item); } items.Sort(SORT_METHOD_LABEL, SortOrderAscending); if (addonIDs.size() > 0) { for (CStdStringArray::const_iterator it = addonIDs.begin(); it != addonIDs.end() ; it++) { CFileItemPtr item = items.Get(*it); if (item) item->Select(true); } } dialog->SetItems(&items); dialog->SetMultiSelection(multipleSelection); dialog->DoModal(); if (!multipleSelection && iTypes == 1 && dialog->IsButtonPressed()) { // switch to the addons browser. vector<CStdString> params; params.push_back("addons://all/"+TranslateType(types[0],false)+"/"); params.push_back("return"); g_windowManager.ActivateWindow(WINDOW_ADDON_BROWSER, params); return 2; } if (!dialog->IsConfirmed()) return 0; addonIDs.clear(); const CFileItemList& list = dialog->GetSelectedItems(); for (int i = 0 ; i < list.Size() ; i++) addonIDs.push_back(list.Get(i)->GetPath()); return 1; }
int CGUIWindowAddonBrowser::SelectAddonID(const vector<ADDON::TYPE> &types, vector<string> &addonIDs, bool showNone /* = false */, bool showDetails /* = true */, bool multipleSelection /* = true */, bool showInstalled /* = true */, bool showInstallable /* = false */, bool showMore /* = true */) { // if we shouldn't show neither installed nor installable addons the list will be empty if (!showInstalled && !showInstallable) return 0; // can't show the "Get More" button if we already show installable addons if (showInstallable) showMore = false; CGUIDialogSelect *dialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (!dialog) return 0; // get rid of any invalid addon types vector<ADDON::TYPE> validTypes(types.size()); std::copy_if(types.begin(), types.end(), validTypes.begin(), [](ADDON::TYPE type) { return type != ADDON_UNKNOWN; }); if (validTypes.empty()) return 0; // get all addons to show VECADDONS addons; if (showInstalled) { for (vector<ADDON::TYPE>::const_iterator type = validTypes.begin(); type != validTypes.end(); ++type) { VECADDONS typeAddons; if (*type == ADDON_AUDIO) CAddonsDirectory::GetScriptsAndPlugins("audio", typeAddons); else if (*type == ADDON_EXECUTABLE) CAddonsDirectory::GetScriptsAndPlugins("executable", typeAddons); else if (*type == ADDON_IMAGE) CAddonsDirectory::GetScriptsAndPlugins("image", typeAddons); else if (*type == ADDON_VIDEO) CAddonsDirectory::GetScriptsAndPlugins("video", typeAddons); else CAddonMgr::Get().GetAddons(*type, typeAddons); addons.insert(addons.end(), typeAddons.begin(), typeAddons.end()); } } if (showInstallable || showMore) { VECADDONS installableAddons; CAddonDatabase database; if (database.Open() && database.GetAddons(installableAddons)) { for (ADDON::IVECADDONS addon = installableAddons.begin(); addon != installableAddons.end();) { AddonPtr pAddon = *addon; // check if the addon matches one of the provided addon types bool matchesType = false; for (vector<ADDON::TYPE>::const_iterator type = validTypes.begin(); type != validTypes.end(); ++type) { if (pAddon->IsType(*type)) { matchesType = true; break; } } // only show addons that match one of the provided addon types and that aren't disabled if (matchesType && !CAddonMgr::Get().IsAddonDisabled(pAddon->ID())) { // check if the addon is installed bool isInstalled = CAddonMgr::Get().IsAddonInstalled(pAddon->ID()); // check if the addon is installed or can be installed if ((showInstallable || showMore) && !isInstalled && CAddonMgr::Get().CanAddonBeInstalled(pAddon)) { ++addon; continue; } } addon = installableAddons.erase(addon); } if (showInstallable) addons.insert(addons.end(), installableAddons.begin(), installableAddons.end()); else if (showMore) showMore = !installableAddons.empty(); } } if (addons.empty() && !showNone) return 0; // turn the addons into items std::map<std::string, AddonPtr> addonMap; CFileItemList items; for (ADDON::IVECADDONS addon = addons.begin(); addon != addons.end(); ++addon) { CFileItemPtr item(CAddonsDirectory::FileItemFromAddon(*addon, (*addon)->ID())); if (!items.Contains(item->GetPath())) { items.Add(item); addonMap.insert(std::make_pair(item->GetPath(), *addon)); } } if (items.IsEmpty() && !showNone) return 0; std::string heading; for (vector<ADDON::TYPE>::const_iterator type = validTypes.begin(); type != validTypes.end(); ++type) { if (!heading.empty()) heading += ", "; heading += TranslateType(*type, true); } dialog->SetHeading(CVariant{std::move(heading)}); dialog->Reset(); dialog->SetUseDetails(showDetails); if (multipleSelection) { showNone = false; showMore = false; dialog->EnableButton(true, 186); } else if (showMore) dialog->EnableButton(true, 21452); if (showNone) { CFileItemPtr item(new CFileItem("", false)); item->SetLabel(g_localizeStrings.Get(231)); item->SetLabel2(g_localizeStrings.Get(24040)); item->SetIconImage("DefaultAddonNone.png"); item->SetSpecialSort(SortSpecialOnTop); items.Add(item); } items.Sort(SortByLabel, SortOrderAscending); if (addonIDs.size() > 0) { for (vector<string>::const_iterator it = addonIDs.begin(); it != addonIDs.end() ; ++it) { CFileItemPtr item = items.Get(*it); if (item) item->Select(true); } } dialog->SetItems(&items); dialog->SetMultiSelection(multipleSelection); dialog->DoModal(); // if the "Get More" button has been pressed and we haven't shown the // installable addons so far show a list of installable addons if (showMore&& dialog->IsButtonPressed()) return SelectAddonID(types, addonIDs, showNone, showDetails, multipleSelection, false, true, false); if (!dialog->IsConfirmed()) return 0; addonIDs.clear(); const CFileItemList& list = dialog->GetSelectedItems(); for (int i = 0; i < list.Size(); i++) { const CFileItemPtr& item = list.Get(i); // check if one of the selected addons needs to be installed if (showInstallable) { std::map<std::string, AddonPtr>::const_iterator itAddon = addonMap.find(item->GetPath()); if (itAddon != addonMap.end()) { const AddonPtr& addon = itAddon->second; // if the addon isn't installed we need to install it if (!CAddonMgr::Get().IsAddonInstalled(addon->ID())) { AddonPtr installedAddon; if (!CAddonInstaller::Get().InstallModal(addon->ID(), installedAddon, false)) continue; } // if the addon is disabled we need to enable it if (CAddonMgr::Get().IsAddonDisabled(addon->ID())) CAddonMgr::Get().EnableAddon(addon->ID()); } } addonIDs.push_back(item->GetPath()); } return 1; }
void CGUIDialogSmartPlaylistRule::OnBrowse() { CFileItemList items; CMusicDatabase database; database.Open(); CVideoDatabase videodatabase; videodatabase.Open(); VIDEODB_CONTENT_TYPE type = VIDEODB_CONTENT_MOVIES; if (m_type.Equals("tvshows")) type = VIDEODB_CONTENT_TVSHOWS; else if (m_type.Equals("musicvideos")) type = VIDEODB_CONTENT_MUSICVIDEOS; else if (m_type.Equals("episodes")) type = VIDEODB_CONTENT_EPISODES; int iLabel = 0; if (m_rule.m_field == FieldGenre) { if (m_type.Equals("tvshows") || m_type.Equals("episodes") || m_type.Equals("movies")) videodatabase.GetGenresNav("videodb://2/1/",items,type); else if (m_type.Equals("songs") || m_type.Equals("albums") || m_type.Equals("artists") || m_type.Equals("mixed")) database.GetGenresNav("musicdb://1/",items); if (m_type.Equals("musicvideos") || m_type.Equals("mixed")) { CFileItemList items2; videodatabase.GetGenresNav("videodb://3/1/",items2,VIDEODB_CONTENT_MUSICVIDEOS); items.Append(items2); } iLabel = 515; } else if (m_rule.m_field == FieldCountry) { videodatabase.GetCountriesNav("videodb://2/1/",items,type); iLabel = 574; } else if (m_rule.m_field == FieldArtist || m_rule.m_field == FieldAlbumArtist) { if (m_type.Equals("songs") || m_type.Equals("mixed") || m_type.Equals("albums") || m_type.Equals("artists")) database.GetArtistsNav("musicdb://2/", items, m_rule.m_field == FieldAlbumArtist, -1); if (m_type.Equals("musicvideos") || m_type.Equals("mixed")) { CFileItemList items2; videodatabase.GetMusicVideoArtistsByName("",items2); items.Append(items2); } iLabel = 557; } else if (m_rule.m_field == FieldAlbum) { if (m_type.Equals("songs") || m_type.Equals("mixed") || m_type.Equals("albums")) database.GetAlbumsNav("musicdb://3/", items); if (m_type.Equals("musicvideos") || m_type.Equals("mixed")) { CFileItemList items2; videodatabase.GetMusicVideoAlbumsByName("",items2); items.Append(items2); } iLabel = 558; } else if (m_rule.m_field == FieldActor) { videodatabase.GetActorsNav("",items,type); iLabel = 20337; } else if (m_rule.m_field == FieldYear) { if (m_type.Equals("songs") || m_type.Equals("mixed") || m_type.Equals("albums")) database.GetYearsNav("musicdb://9/", items); if (!m_type.Equals("songs") && !m_type.Equals("albums")) { CFileItemList items2; videodatabase.GetYearsNav("", items2, type); items.Append(items2); } iLabel = 562; } else if (m_rule.m_field == FieldDirector) { videodatabase.GetDirectorsNav("",items,type); iLabel = 20339; } else if (m_rule.m_field == FieldStudio) { videodatabase.GetStudiosNav("",items,type); iLabel = 572; } else if (m_rule.m_field == FieldWriter) { videodatabase.GetWritersNav("",items,type); iLabel = 20417; } else if (m_rule.m_field == FieldTvShowTitle) { videodatabase.GetTvShowsNav("videodb://2/2/",items); iLabel = 20343; } else if (m_rule.m_field == FieldPlaylist) { // use filebrowser to grab another smart playlist // Note: This can cause infinite loops (playlist that refers to the same playlist) but I don't // think there's any decent way to deal with this, as the infinite loop may be an arbitrary // number of playlists deep, eg playlist1 -> playlist2 -> playlist3 ... -> playlistn -> playlist1 CStdString path = "special://videoplaylists/"; if (m_type.Equals("songs") || m_type.Equals("albums")) path = "special://musicplaylists/"; XFILE::CDirectory::GetDirectory(path, items, ".xsp", XFILE::DIR_FLAG_NO_FILE_DIRS); for (int i = 0; i < items.Size(); i++) { CFileItemPtr item = items[i]; CSmartPlaylist playlist; if (playlist.OpenAndReadName(item->GetPath())) item->SetLabel(playlist.GetName()); } iLabel = 559; } else if (m_rule.m_field == FieldPath) { VECSOURCES sources; if (m_type == "songs" || m_type == "mixed") sources = *g_settings.GetSourcesFromType("music"); if (m_type != "songs") { VECSOURCES sources2 = *g_settings.GetSourcesFromType("video"); sources.insert(sources.end(),sources2.begin(),sources2.end()); } g_mediaManager.GetLocalDrives(sources); CStdString path = m_rule.GetLocalizedParameter(m_type); CGUIDialogFileBrowser::ShowAndGetDirectory(sources, g_localizeStrings.Get(657), path, false); if (m_rule.m_parameter.size() > 0) m_rule.m_parameter.clear(); if (!path.empty()) m_rule.m_parameter.push_back(path); UpdateButtons(); return; } else if (m_rule.m_field == FieldSet) { videodatabase.GetSetsNav("videodb://1/7/", items, VIDEODB_CONTENT_MOVIES); iLabel = 20434; } else if (m_rule.m_field == FieldTag) { if (m_type == "movies") videodatabase.GetTagsNav("videodb://1/9/", items, VIDEODB_CONTENT_MOVIES); else return; iLabel = 20459; } else { // TODO: Add browseability in here. assert(false); } // sort the items items.Sort(SORT_METHOD_LABEL, SortOrderAscending); CGUIDialogSelect* pDialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); pDialog->Reset(); pDialog->SetItems(&items); CStdString strHeading; strHeading.Format(g_localizeStrings.Get(13401),g_localizeStrings.Get(iLabel)); pDialog->SetHeading(strHeading); pDialog->SetMultiSelection(true); if (!m_rule.m_parameter.empty()) pDialog->SetSelected(m_rule.m_parameter); pDialog->DoModal(); if (pDialog->IsConfirmed()) { const CFileItemList &items = pDialog->GetSelectedItems(); m_rule.m_parameter.clear(); for (int index = 0; index < items.Size(); index++) m_rule.m_parameter.push_back(items[index]->GetLabel()); UpdateButtons(); } pDialog->Reset(); }
int CGUIWindowAddonBrowser::SelectAddonID(ADDON::TYPE type, CStdStringArray &addonIDs, bool showNone /*= false*/, bool multipleSelection /*= true*/) { CGUIDialogSelect *dialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (type == ADDON_UNKNOWN || !dialog) return 0; ADDON::VECADDONS addons; if (type == ADDON_AUDIO) CAddonsDirectory::GetScriptsAndPlugins("audio",addons); else if (type == ADDON_EXECUTABLE) CAddonsDirectory::GetScriptsAndPlugins("executable",addons); else if (type == ADDON_IMAGE) CAddonsDirectory::GetScriptsAndPlugins("image",addons); else if (type == ADDON_VIDEO) CAddonsDirectory::GetScriptsAndPlugins("video",addons); else CAddonMgr::Get().GetAddons(type, addons); CFileItemList items; for (ADDON::IVECADDONS i = addons.begin(); i != addons.end(); ++i) items.Add(CAddonsDirectory::FileItemFromAddon(*i, "")); dialog->SetHeading(TranslateType(type, true)); dialog->Reset(); dialog->SetUseDetails(true); if (multipleSelection) { showNone = false; dialog->EnableButton(true, 186); } else dialog->EnableButton(true, 21452); if (showNone) { CFileItemPtr item(new CFileItem("", false)); item->SetLabel(g_localizeStrings.Get(231)); item->SetLabel2(g_localizeStrings.Get(24040)); item->SetIconImage("DefaultAddonNone.png"); item->SetSpecialSort(SORT_ON_TOP); items.Add(item); } items.Sort(SORT_METHOD_LABEL, SORT_ORDER_ASC); if (addonIDs.size() > 0) { for (CStdStringArray::const_iterator it = addonIDs.begin(); it != addonIDs.end() ; it++) { CFileItemPtr item = items.Get(*it); if (item) item->Select(true); } } dialog->SetItems(&items); dialog->SetMultiSelection(multipleSelection); dialog->DoModal(); if (!multipleSelection && dialog->IsButtonPressed()) { // switch to the addons browser. vector<CStdString> params; params.push_back("addons://all/"+TranslateType(type,false)+"/"); params.push_back("return"); g_windowManager.ActivateWindow(WINDOW_ADDON_BROWSER, params); return 2; } if (!multipleSelection && dialog->GetSelectedLabel() == -1) return 0; addonIDs.clear(); const CFileItemList& list = dialog->GetSelectedItems(); for (int i = 0 ; i < list.Size() ; i++) addonIDs.push_back(list.Get(i)->GetPath()); return 1; }
bool CGUIDialogPVRChannelManager::OnMessage(CGUIMessage& message) { unsigned int iControl = 0; unsigned int iMessage = message.GetMessage(); switch (iMessage) { case GUI_MSG_WINDOW_DEINIT: { Clear(); } break; case GUI_MSG_WINDOW_INIT: { CGUIWindow::OnMessage(message); m_iSelected = 0; m_bIsRadio = false; m_bMovingMode = false; m_bContainsChanges = false; SetProperty("IsRadio", ""); Update(); SetData(m_iSelected); return true; } break; case GUI_MSG_CLICKED: { iControl = message.GetSenderId(); if (iControl == CONTROL_LIST_CHANNELS) { if (!m_bMovingMode) { int iAction = message.GetParam1(); int iItem = m_viewControl.GetSelectedItem(); /* Check file item is in list range and get his pointer */ if (iItem < 0 || iItem >= (int)m_channelItems->Size()) return true; /* Process actions */ if (iAction == ACTION_SELECT_ITEM || iAction == ACTION_CONTEXT_MENU || iAction == ACTION_MOUSE_RIGHT_CLICK) { /* Show Contextmenu */ OnPopupMenu(iItem); } } else { CFileItemPtr pItem = m_channelItems->Get(m_iSelected); if (pItem) { pItem->SetProperty("Changed", true); pItem->Select(false); m_bMovingMode = false; m_bContainsChanges = true; return true; } else return false; } } else if (iControl == BUTTON_OK) { SaveList(); Close(); return true; } else if (iControl == BUTTON_APPLY) { SaveList(); return true; } else if (iControl == BUTTON_CANCEL) { Close(); return true; } else if (iControl == BUTTON_RADIO_TV) { if (m_bContainsChanges) { // prompt user for confirmation of channel record CGUIDialogYesNo* pDialog = (CGUIDialogYesNo*)g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO); if (!pDialog) return true; pDialog->SetHeading(20052); pDialog->SetLine(0, ""); pDialog->SetLine(1, 19212); pDialog->SetLine(2, 20103); pDialog->DoModal(); if (pDialog->IsConfirmed()) SaveList(); } m_iSelected = 0; m_bMovingMode = false; m_bContainsChanges = false; m_bIsRadio = !m_bIsRadio; SetProperty("IsRadio", m_bIsRadio ? "true" : ""); Update(); SetData(m_iSelected); return true; } else if (iControl == RADIOBUTTON_ACTIVE) { CGUIRadioButtonControl *pRadioButton = (CGUIRadioButtonControl *)GetControl(RADIOBUTTON_ACTIVE); if (pRadioButton) { CFileItemPtr pItem = m_channelItems->Get(m_iSelected); if (pItem) { pItem->SetProperty("Changed", true); pItem->SetProperty("ActiveChannel", pRadioButton->IsSelected()); m_bContainsChanges = true; Renumber(); } } } else if (iControl == EDIT_NAME) { CGUIEditControl *pEdit = (CGUIEditControl *)GetControl(EDIT_NAME); if (pEdit) { CFileItemPtr pItem = m_channelItems->Get(m_iSelected); if (pItem) { pItem->SetProperty("Changed", true); pItem->SetProperty("Name", pEdit->GetLabel2()); m_bContainsChanges = true; } } } else if (iControl == BUTTON_CHANNEL_LOGO) { CFileItemPtr pItem = m_channelItems->Get(m_iSelected); if (!pItem) return false; if (g_settings.GetCurrentProfile().canWriteSources() && !g_passwordManager.IsProfileLockUnlocked()) return false; else if (!g_passwordManager.IsMasterLockUnlocked(true)) return false; // setup our thumb list CFileItemList items; // add the current thumb, if available if (!pItem->GetProperty("Icon").IsEmpty()) { CFileItemPtr current(new CFileItem("thumb://Current", false)); current->SetThumbnailImage(pItem->GetPVRChannelInfoTag()->IconPath()); current->SetLabel(g_localizeStrings.Get(20016)); items.Add(current); } else if (pItem->HasThumbnail()) { // already have a thumb that the share doesn't know about - must be a local one, so we mayaswell reuse it. CFileItemPtr current(new CFileItem("thumb://Current", false)); current->SetThumbnailImage(pItem->GetThumbnailImage()); current->SetLabel(g_localizeStrings.Get(20016)); items.Add(current); } // and add a "no thumb" entry as well CFileItemPtr nothumb(new CFileItem("thumb://None", false)); nothumb->SetIconImage(pItem->GetIconImage()); nothumb->SetLabel(g_localizeStrings.Get(20018)); items.Add(nothumb); CStdString strThumb; VECSOURCES shares; if (g_guiSettings.GetString("pvrmenu.iconpath") != "") { CMediaSource share1; share1.strPath = g_guiSettings.GetString("pvrmenu.iconpath"); share1.strName = g_localizeStrings.Get(19018); shares.push_back(share1); } g_mediaManager.GetLocalDrives(shares); if (!CGUIDialogFileBrowser::ShowAndGetImage(items, shares, g_localizeStrings.Get(1030), strThumb)) return false; if (strThumb == "thumb://Current") return true; if (strThumb == "thumb://None") strThumb = ""; pItem->SetProperty("Icon", strThumb); pItem->SetProperty("Changed", true); m_bContainsChanges = true; return true; } else if (iControl == RADIOBUTTON_USEEPG) { CGUIRadioButtonControl *pRadioButton = (CGUIRadioButtonControl *)GetControl(RADIOBUTTON_USEEPG); if (pRadioButton) { CFileItemPtr pItem = m_channelItems->Get(m_iSelected); if (pItem) { pItem->SetProperty("Changed", true); pItem->SetProperty("UseEPG", pRadioButton->IsSelected()); m_bContainsChanges = true; } } } else if (iControl == SPIN_EPGSOURCE_SELECTION) { /// TODO: Add EPG scraper support return true; CGUISpinControlEx *pSpin = (CGUISpinControlEx *)GetControl(SPIN_EPGSOURCE_SELECTION); if (pSpin) { CFileItemPtr pItem = m_channelItems->Get(m_iSelected); if (pItem) { pItem->SetProperty("EPGSource", (int)0); pItem->SetProperty("Changed", true); m_bContainsChanges = true; return true; } } } else if (iControl == BUTTON_GROUP_MANAGER) { /* Load group manager dialog */ CGUIDialogPVRGroupManager* pDlgInfo = (CGUIDialogPVRGroupManager*)g_windowManager.GetWindow(WINDOW_DIALOG_PVR_GROUP_MANAGER); if (!pDlgInfo) return false; pDlgInfo->SetRadio(m_bIsRadio); /* Open dialog window */ pDlgInfo->DoModal(); return true; } else if (iControl == BUTTON_EDIT_CHANNEL) { CFileItemPtr pItem = m_channelItems->Get(m_iSelected); if (!pItem) return false; if (pItem->GetPropertyBOOL("Virtual")) { CStdString strURL = pItem->GetProperty("StreamURL"); if (CGUIDialogKeyboard::ShowAndGetInput(strURL, g_localizeStrings.Get(19214), false)) pItem->SetProperty("StreamURL", strURL); return true; } CGUIDialogOK::ShowAndGetInput(19033,19038,0,0); return true; } else if (iControl == BUTTON_DELETE_CHANNEL) { CFileItemPtr pItem = m_channelItems->Get(m_iSelected); if (!pItem) return false; // prompt user for confirmation of channel record CGUIDialogYesNo* pDialog = (CGUIDialogYesNo*)g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO); if (!pDialog) return true; pDialog->SetHeading(19211); pDialog->SetLine(0, ""); pDialog->SetLine(1, 750); pDialog->SetLine(2, ""); pDialog->DoModal(); if (pDialog->IsConfirmed()) { if (pItem->GetPropertyBOOL("Virtual")) { CPVRDatabase *database = CPVRManager::Get()->GetTVDatabase(); database->Open(); database->Delete(*pItem->GetPVRChannelInfoTag()); database->Close(); m_channelItems->Remove(m_iSelected); m_viewControl.SetItems(*m_channelItems); Renumber(); return true; } CGUIDialogOK::ShowAndGetInput(19033,19038,0,0); } return true; } else if (iControl == BUTTON_NEW_CHANNEL) { std::vector<long> clients; CGUIDialogSelect* pDlgSelect = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (!pDlgSelect) return false; pDlgSelect->SetHeading(19213); // Select Client pDlgSelect->Add(g_localizeStrings.Get(19209)); clients.push_back(XBMC_VIRTUAL_CLIENTID); std::map<long, CStdString> clientMap; if (CPVRManager::GetClients()->GetClients(&clientMap) > 0) { std::map<long,CStdString>::iterator itr; for (itr = clientMap.begin() ; itr != clientMap.end(); itr++) { clients.push_back((*itr).first); pDlgSelect->Add(clientMap[(*itr).first]); } } pDlgSelect->DoModal(); int selection = pDlgSelect->GetSelectedLabel(); if (selection >= 0 && selection <= (int) clients.size()) { int clientID = clients[selection]; if (clientID == XBMC_VIRTUAL_CLIENTID) { CStdString strURL = ""; if (CGUIDialogKeyboard::ShowAndGetInput(strURL, g_localizeStrings.Get(19214), false)) { if (!strURL.IsEmpty()) { CPVRChannel newchannel(m_bIsRadio); newchannel.SetChannelName(g_localizeStrings.Get(19204)); newchannel.SetEPGEnabled(false); newchannel.SetVirtual(true); newchannel.SetStreamURL(strURL); newchannel.SetClientID(XBMC_VIRTUAL_CLIENTID); CPVRDatabase *database = CPVRManager::Get()->GetTVDatabase(); database->Open(); database->Persist(newchannel); database->Close(); CFileItemPtr channel(new CFileItem(newchannel)); if (channel) { channel->SetProperty("ActiveChannel", true); channel->SetProperty("Name", g_localizeStrings.Get(19204)); channel->SetProperty("UseEPG", false); channel->SetProperty("Icon", newchannel.IconPath()); channel->SetProperty("EPGSource", (int)0); channel->SetProperty("ClientName", g_localizeStrings.Get(19209)); m_channelItems->AddFront(channel, m_iSelected); m_viewControl.SetItems(*m_channelItems); Renumber(); } } } } else { CGUIDialogOK::ShowAndGetInput(19033,19038,0,0); } } return true; } } break; } return CGUIDialog::OnMessage(message); }
bool CMusicInfoScanner::DownloadArtistInfo(const CStdString& strPath, const CStdString& strArtist, CGUIDialogProgress* pDialog) { DIRECTORY::MUSICDATABASEDIRECTORY::CQueryParams params; DIRECTORY::MUSICDATABASEDIRECTORY::CDirectoryNode::GetDatabaseInfo(strPath, params); CArtist artist; m_musicDatabase.Open(); if (m_musicDatabase.GetArtistInfo(params.GetArtistId(),artist)) // already got the info return true; // find artist info SScraperInfo info; if (!m_musicDatabase.GetScraperForPath(strPath,info)) { m_musicDatabase.Close(); return false; } if (m_pObserver) { m_pObserver->OnStateChanged(DOWNLOADING_ARTIST_INFO); m_pObserver->OnDirectoryChanged(strArtist); } CMusicInfoScraper scraper(info); // handle nfo files CStdString strArtistPath, strNfo; m_musicDatabase.GetArtistPath(params.GetArtistId(),strArtistPath); CUtil::AddFileToFolder(strArtistPath,"artist.nfo",strNfo); if (XFILE::CFile::Exists(strNfo)) { CLog::Log(LOGDEBUG,"Found matching nfo file: %s", strNfo.c_str()); CNfoFile nfoReader("albums"); if (nfoReader.Create(strNfo) == S_OK) { if (nfoReader.m_strScraper == "NFO") { CLog::Log(LOGDEBUG, "%s Got details from nfo", __FUNCTION__); CArtist artist; nfoReader.GetDetails(artist); m_musicDatabase.SetArtistInfo(params.GetArtistId(), artist); m_musicDatabase.Close(); return true; } else { CScraperUrl scrUrl(nfoReader.m_strImDbUrl); CMusicArtistInfo artist("nfo",scrUrl); scraper.GetArtists().push_back(artist); } } else CLog::Log(LOGERROR,"Unable to find an url in nfo file: %s", strNfo.c_str()); } if (!scraper.GetArtistCount()) scraper.FindArtistinfo(strArtist); while (!scraper.Completed()) { if (m_bStop) { scraper.Cancel(); break; } Sleep(1); } if (scraper.Successfull() && scraper.GetArtistCount() >= 1) { int iSelectedArtist = 0; // now load the first match if (pDialog && scraper.GetArtistCount() > 1) { // if we found more then 1 album, let user choose one CGUIDialogSelect *pDlg = (CGUIDialogSelect*)m_gWindowManager.GetWindow(WINDOW_DIALOG_SELECT); if (pDlg) { pDlg->SetHeading(g_localizeStrings.Get(21890)); pDlg->Reset(); pDlg->EnableButton(true); pDlg->SetButtonLabel(413); // manual for (int i = 0; i < scraper.GetArtistCount(); ++i) { // set the label to artist CFileItem item(scraper.GetArtist(i).GetArtist()); CStdString strTemp=scraper.GetArtist(i).GetArtist().strArtist; if (!scraper.GetArtist(i).GetArtist().strBorn.IsEmpty()) strTemp += " ("+scraper.GetArtist(i).GetArtist().strBorn+")"; if (!scraper.GetArtist(i).GetArtist().strGenre.IsEmpty()) strTemp.Format("[%s] %s",scraper.GetArtist(i).GetArtist().strGenre.c_str(),strTemp.c_str()); item.SetLabel(strTemp); item.m_idepth = i; // use this to hold the index of the album in the scraper pDlg->Add(&item); } pDlg->DoModal(); // and wait till user selects one if (pDlg->GetSelectedLabel() < 0) { // none chosen if (!pDlg->IsButtonPressed()) return false; // manual button pressed CStdString strNewArtist = strArtist; if (!CGUIDialogKeyboard::ShowAndGetInput(strNewArtist, g_localizeStrings.Get(16025), false)) return false; if (pDialog) { pDialog->SetLine(0, strNewArtist); pDialog->Progress(); } m_musicDatabase.Close(); return DownloadArtistInfo(strPath,strArtist,pDialog); } iSelectedArtist = pDlg->GetSelectedItem().m_idepth; } } scraper.LoadArtistinfo(iSelectedArtist); while (!scraper.Completed()) { if (m_bStop) { scraper.Cancel(); break; } Sleep(1); } if (scraper.Successfull()) { artist = scraper.GetArtist(iSelectedArtist).GetArtist(); m_musicDatabase.SetArtistInfo(params.GetArtistId(), artist); } } else { m_musicDatabase.Close(); return false; } // check thumb stuff if (artist.thumbURL.m_url.size()) { CFileItem item(strArtist); CStdString thumb = item.GetCachedArtistThumb(); if (!XFILE::CFile::Exists(thumb)) CScraperUrl::DownloadThumbnail(thumb,artist.thumbURL.m_url[0]); } m_musicDatabase.Close(); return true; }