void CPVRManager::ResetDatabase(bool bResetEPGOnly /* = false */) { CLog::Log(LOGNOTICE,"PVRManager - %s - clearing the PVR database", __FUNCTION__); g_EpgContainer.Stop(); CGUIDialogProgress* pDlgProgress = (CGUIDialogProgress*)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS); pDlgProgress->SetLine(0, ""); pDlgProgress->SetLine(1, g_localizeStrings.Get(19186)); // All data in the PVR database is being erased pDlgProgress->SetLine(2, ""); pDlgProgress->StartModal(); pDlgProgress->Progress(); if (m_addons && m_addons->IsPlaying()) { CLog::Log(LOGNOTICE,"PVRManager - %s - stopping playback", __FUNCTION__); CApplicationMessenger::Get().MediaStop(); } pDlgProgress->SetPercentage(10); pDlgProgress->Progress(); /* reset the EPG pointers */ if (m_database) m_database->ResetEPG(); /* stop the thread */ Stop(); pDlgProgress->SetPercentage(20); pDlgProgress->Progress(); if (!m_database) m_database = new CPVRDatabase; if (m_database && m_database->Open()) { /* clean the EPG database */ g_EpgContainer.Reset(); pDlgProgress->SetPercentage(30); pDlgProgress->Progress(); if (!bResetEPGOnly) { m_database->DeleteChannelGroups(); pDlgProgress->SetPercentage(50); pDlgProgress->Progress(); /* delete all channels */ m_database->DeleteChannels(); pDlgProgress->SetPercentage(70); pDlgProgress->Progress(); /* delete all channel and recording settings */ CVideoDatabase videoDatabase; if (videoDatabase.Open()) { videoDatabase.EraseVideoSettings("pvr://channels/"); videoDatabase.EraseVideoSettings("pvr://recordings/"); videoDatabase.Close(); } pDlgProgress->SetPercentage(80); pDlgProgress->Progress(); /* delete all client information */ m_database->DeleteClients(); pDlgProgress->SetPercentage(90); pDlgProgress->Progress(); } m_database->Close(); } CLog::Log(LOGNOTICE,"PVRManager - %s - %s database cleared", __FUNCTION__, bResetEPGOnly ? "EPG" : "PVR and EPG"); if (CSettings::Get().GetBool("pvrmanager.enabled")) { CLog::Log(LOGNOTICE,"PVRManager - %s - restarting the PVRManager", __FUNCTION__); m_database->Open(); Cleanup(); Start(); } pDlgProgress->SetPercentage(100); pDlgProgress->Close(); }
bool CPluginDirectory::WaitOnScriptResult(const CStdString &scriptPath, const CStdString &scriptName, bool retrievingDir) { const unsigned int timeBeforeProgressBar = 1500; const unsigned int timeToKillScript = 1000; unsigned int startTime = CTimeUtils::GetTimeMS(); CGUIDialogProgress *progressBar = NULL; CLog::Log(LOGDEBUG, "%s - waiting on the %s plugin...", __FUNCTION__, scriptName.c_str()); while (true) { CSingleExit ex(g_graphicsContext); // check if the python script is finished if (WaitForSingleObject(m_fetchComplete, 20) == WAIT_OBJECT_0) { // python has returned CLog::Log(LOGDEBUG, "%s- plugin returned %s", __FUNCTION__, m_success ? "successfully" : "failure"); break; } ex.Restore(); // check our script is still running #ifdef HAS_PYTHON if (!g_pythonParser.isRunning(g_pythonParser.getScriptId(scriptPath.c_str()))) #endif { // check whether we exited normally if (WaitForSingleObject(m_fetchComplete, 0) == WAIT_TIMEOUT) { // python didn't return correctly CLog::Log(LOGDEBUG, " %s - plugin exited prematurely - terminating", __FUNCTION__); m_success = false; } break; } // check whether we should pop up the progress dialog if (!progressBar && CTimeUtils::GetTimeMS() - startTime > timeBeforeProgressBar) { // loading takes more then 1.5 secs, show a progress dialog progressBar = (CGUIDialogProgress *)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS); // if script has shown progressbar don't override it if (progressBar && progressBar->IsActive()) { startTime = CTimeUtils::GetTimeMS(); progressBar = NULL; } if (progressBar) { progressBar->SetHeading(scriptName); progressBar->SetLine(0, retrievingDir ? 1040 : 10214); progressBar->SetLine(1, ""); progressBar->SetLine(2, ""); progressBar->ShowProgressBar(retrievingDir); progressBar->StartModal(); } } if (progressBar) { // update the progress bar and check for user cancel if (retrievingDir) { CStdString label; if (m_totalItems > 0) { label.Format(g_localizeStrings.Get(1042).c_str(), m_listItems->Size(), m_totalItems); progressBar->SetPercentage((int)((m_listItems->Size() * 100 ) / m_totalItems)); progressBar->ShowProgressBar(true); } else label.Format(g_localizeStrings.Get(1041).c_str(), m_listItems->Size()); progressBar->SetLine(2, label); } progressBar->Progress(); if (progressBar->IsCanceled()) { // user has cancelled our process - cancel our process if (!m_cancelled) { m_cancelled = true; startTime = CTimeUtils::GetTimeMS(); } if (m_cancelled && CTimeUtils::GetTimeMS() - startTime > timeToKillScript) { // cancel our script #ifdef HAS_PYTHON int id = g_pythonParser.getScriptId(scriptPath.c_str()); if (id != -1 && g_pythonParser.isRunning(id)) { CLog::Log(LOGDEBUG, "%s- cancelling plugin %s", __FUNCTION__, scriptName.c_str()); g_pythonParser.stopScript(id); break; } #endif } } } } if (progressBar) g_application.getApplicationMessenger().Close(progressBar, false, false); return !m_cancelled && m_success; }
bool CPluginDirectory::WaitOnScriptResult(const CStdString &scriptPath, int scriptId, const CStdString &scriptName, bool retrievingDir) { const unsigned int timeBeforeProgressBar = 1500; const unsigned int timeToKillScript = 1000; unsigned int startTime = XbmcThreads::SystemClockMillis(); CGUIDialogProgress *progressBar = NULL; bool cancelled = false; bool inMainAppThread = g_application.IsCurrentThread(); CLog::Log(LOGDEBUG, "%s - waiting on the %s (id=%d) plugin...", __FUNCTION__, scriptName.c_str(), scriptId); while (true) { { CSingleExit ex(g_graphicsContext); // check if the python script is finished if (m_fetchComplete.WaitMSec(20)) { // python has returned CLog::Log(LOGDEBUG, "%s- plugin returned %s", __FUNCTION__, m_success ? "successfully" : "failure"); break; } } // check our script is still running if (!CScriptInvocationManager::Get().IsRunning(scriptId)) { // check whether we exited normally if (!m_fetchComplete.WaitMSec(0)) { // python didn't return correctly CLog::Log(LOGDEBUG, " %s - plugin exited prematurely - terminating", __FUNCTION__); m_success = false; } break; } // check whether we should pop up the progress dialog if (!retrievingDir && !progressBar && XbmcThreads::SystemClockMillis() - startTime > timeBeforeProgressBar) { // loading takes more then 1.5 secs, show a progress dialog progressBar = (CGUIDialogProgress *)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS); // if script has shown progressbar don't override it if (progressBar && progressBar->IsActive()) { startTime = XbmcThreads::SystemClockMillis(); progressBar = NULL; } if (progressBar) { progressBar->SetHeading(scriptName); progressBar->SetLine(0, retrievingDir ? 1040 : 10214); progressBar->SetLine(1, ""); progressBar->SetLine(2, ""); progressBar->ShowProgressBar(retrievingDir); progressBar->StartModal(); } } if (progressBar) { // update the progress bar and check for user cancel progressBar->Progress(); if (progressBar->IsCanceled()) { // user has cancelled our process - cancel our process m_cancelled = true; } } else // if the progressBar exists and we call StartModal or Progress we get the // ProcessRenderLoop call anyway. if (inMainAppThread) g_windowManager.ProcessRenderLoop(); if (!cancelled && m_cancelled) { cancelled = true; startTime = XbmcThreads::SystemClockMillis(); } if (cancelled && XbmcThreads::SystemClockMillis() - startTime > timeToKillScript) { // cancel our script if (scriptId != -1 && CScriptInvocationManager::Get().IsRunning(scriptId)) { CLog::Log(LOGDEBUG, "%s- cancelling plugin %s (id=%d)", __FUNCTION__, scriptName.c_str(), scriptId); CScriptInvocationManager::Get().Stop(scriptId); break; } } } if (progressBar) CApplicationMessenger::Get().Close(progressBar, false, false); return !cancelled && m_success; }
void CPVRManager::ResetDatabase(bool bShowProgress /* = true */) { CLog::Log(LOGNOTICE,"PVRManager - %s - clearing the PVR database", __FUNCTION__); g_EpgContainer.Stop(); CGUIDialogProgress* pDlgProgress = NULL; if (bShowProgress) { pDlgProgress = (CGUIDialogProgress*)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS); pDlgProgress->SetLine(0, StringUtils::EmptyString); pDlgProgress->SetLine(1, g_localizeStrings.Get(19186)); // All data in the PVR database is being erased pDlgProgress->SetLine(2, StringUtils::EmptyString); pDlgProgress->StartModal(); pDlgProgress->Progress(); } if (m_addons && m_addons->IsPlaying()) { CLog::Log(LOGNOTICE,"PVRManager - %s - stopping playback", __FUNCTION__); CApplicationMessenger::Get().MediaStop(); } if (bShowProgress) { pDlgProgress->SetPercentage(10); pDlgProgress->Progress(); } /* stop the thread */ if (g_guiSettings.GetBool("pvrmanager.enabled")) Stop(); if (bShowProgress) { pDlgProgress->SetPercentage(20); pDlgProgress->Progress(); } if (!m_database) m_database = new CPVRDatabase; if (m_database && m_database->Open()) { /* clean the EPG database */ g_EpgContainer.Clear(true); if (bShowProgress) { pDlgProgress->SetPercentage(30); pDlgProgress->Progress(); } m_database->DeleteChannelGroups(); if (bShowProgress) { pDlgProgress->SetPercentage(50); pDlgProgress->Progress(); } /* delete all channels */ m_database->DeleteChannels(); if (bShowProgress) { pDlgProgress->SetPercentage(70); pDlgProgress->Progress(); } /* delete all channel settings */ m_database->DeleteChannelSettings(); if (bShowProgress) { pDlgProgress->SetPercentage(80); pDlgProgress->Progress(); } /* delete all client information */ m_database->DeleteClients(); if (bShowProgress) { pDlgProgress->SetPercentage(90); pDlgProgress->Progress(); } m_database->Close(); } CLog::Log(LOGNOTICE,"PVRManager - %s - PVR database cleared", __FUNCTION__); g_EpgContainer.Start(); if (g_guiSettings.GetBool("pvrmanager.enabled")) { CLog::Log(LOGNOTICE,"PVRManager - %s - restarting the PVRManager", __FUNCTION__); m_database->Open(); Cleanup(); Start(); } if (bShowProgress) { pDlgProgress->SetPercentage(100); pDlgProgress->Close(); } }
bool CMultiPathDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items) { CLog::Log(LOGDEBUG,"CMultiPathDirectory::GetDirectory(%s)", strPath.c_str()); vector<CStdString> vecPaths; if (!GetPaths(strPath, vecPaths)) return false; XbmcThreads::EndTime progressTime(3000); // 3 seconds before showing progress bar CGUIDialogProgress* dlgProgress = NULL; unsigned int iFailures = 0; for (unsigned int i = 0; i < vecPaths.size(); ++i) { // show the progress dialog if we have passed our time limit if (progressTime.IsTimePast() && !dlgProgress) { dlgProgress = (CGUIDialogProgress *)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS); if (dlgProgress) { dlgProgress->SetHeading(15310); dlgProgress->SetLine(0, 15311); dlgProgress->SetLine(1, ""); dlgProgress->SetLine(2, ""); dlgProgress->StartModal(); dlgProgress->ShowProgressBar(true); dlgProgress->SetProgressMax((int)vecPaths.size()*2); dlgProgress->Progress(); } } if (dlgProgress) { CURL url(vecPaths[i]); dlgProgress->SetLine(1, url.GetWithoutUserDetails()); dlgProgress->SetProgressAdvance(); dlgProgress->Progress(); } CFileItemList tempItems; CLog::Log(LOGDEBUG,"Getting Directory (%s)", vecPaths[i].c_str()); if (CDirectory::GetDirectory(vecPaths[i], tempItems, m_strFileMask, m_flags)) items.Append(tempItems); else { CLog::Log(LOGERROR,"Error Getting Directory (%s)", vecPaths[i].c_str()); iFailures++; } if (dlgProgress) { dlgProgress->SetProgressAdvance(); dlgProgress->Progress(); } } if (dlgProgress) dlgProgress->Close(); if (iFailures == vecPaths.size()) return false; // merge like-named folders into a sub multipath:// style url MergeItems(items); return true; }
bool CPartyModeManager::Enable(PartyModeContext context /*= PARTYMODECONTEXT_MUSIC*/, const CStdString& strXspPath /*= ""*/) { // Filter using our PartyMode xml file CSmartPlaylist playlist; CStdString partyModePath; bool playlistLoaded; m_bIsVideo = context == PARTYMODECONTEXT_VIDEO; if (!strXspPath.IsEmpty()) //if a path to a smartplaylist is supplied use it partyModePath = strXspPath; else if (m_bIsVideo) partyModePath = g_settings.GetUserDataItem("PartyMode-Video.xsp"); else partyModePath = g_settings.GetUserDataItem("PartyMode.xsp"); playlistLoaded=playlist.Load(partyModePath); if ( playlistLoaded ) { m_type = playlist.GetType(); if (context == PARTYMODECONTEXT_UNKNOWN) { //get it from the xsp file m_bIsVideo = (m_type.Equals("video") || m_type.Equals("mixed")); } if (m_type.Equals("mixed")) playlist.SetType("songs"); if (m_type.Equals("mixed")) playlist.SetType("video"); playlist.SetType(m_type); } else { m_strCurrentFilterMusic.Empty(); m_strCurrentFilterVideo.Empty(); m_type = m_bIsVideo ? "musicvideos" : "songs"; } CGUIDialogProgress* pDialog = (CGUIDialogProgress*)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS); int iHeading = (m_bIsVideo ? 20250 : 20121); int iLine0 = (m_bIsVideo ? 20251 : 20123); pDialog->SetHeading(iHeading); pDialog->SetLine(0, iLine0); pDialog->SetLine(1, ""); pDialog->SetLine(2, ""); pDialog->StartModal(); ClearState(); unsigned int time = XbmcThreads::SystemClockMillis(); vector< pair<int,int> > songIDs; if (m_type.Equals("songs") || m_type.Equals("mixed")) { CMusicDatabase db; if (db.Open()) { set<CStdString> playlists; if ( playlistLoaded ) m_strCurrentFilterMusic = playlist.GetWhereClause(db, playlists); CLog::Log(LOGINFO, "PARTY MODE MANAGER: Registering filter:[%s]", m_strCurrentFilterMusic.c_str()); m_iMatchingSongs = (int)db.GetSongIDs(m_strCurrentFilterMusic, songIDs); if (m_iMatchingSongs < 1 && m_type.Equals("songs")) { pDialog->Close(); db.Close(); OnError(16031, (CStdString)"Party mode found no matching songs. Aborting."); return false; } } else { pDialog->Close(); OnError(16033, (CStdString)"Party mode could not open database. Aborting."); return false; } db.Close(); } if (m_type.Equals("musicvideos") || m_type.Equals("mixed")) { vector< pair<int,int> > songIDs2; CVideoDatabase db; if (db.Open()) { set<CStdString> playlists; if ( playlistLoaded ) m_strCurrentFilterVideo = playlist.GetWhereClause(db, playlists); CLog::Log(LOGINFO, "PARTY MODE MANAGER: Registering filter:[%s]", m_strCurrentFilterVideo.c_str()); m_iMatchingSongs += (int)db.GetMusicVideoIDs(m_strCurrentFilterVideo, songIDs2); if (m_iMatchingSongs < 1) { pDialog->Close(); db.Close(); OnError(16031, (CStdString)"Party mode found no matching songs. Aborting."); return false; } } else { pDialog->Close(); OnError(16033, (CStdString)"Party mode could not open database. Aborting."); return false; } db.Close(); songIDs.insert(songIDs.end(),songIDs2.begin(),songIDs2.end()); } // calculate history size if (m_iMatchingSongs < 50) m_songsInHistory = 0; else m_songsInHistory = (int)(m_iMatchingSongs/2); if (m_songsInHistory > 200) m_songsInHistory = 200; CLog::Log(LOGINFO,"PARTY MODE MANAGER: Matching songs = %i, History size = %i", m_iMatchingSongs, m_songsInHistory); CLog::Log(LOGINFO,"PARTY MODE MANAGER: Party mode enabled!"); int iPlaylist = m_bIsVideo ? PLAYLIST_VIDEO : PLAYLIST_MUSIC; g_playlistPlayer.ClearPlaylist(iPlaylist); g_playlistPlayer.SetShuffle(iPlaylist, false); g_playlistPlayer.SetRepeat(iPlaylist, PLAYLIST::REPEAT_NONE); pDialog->SetLine(0, (m_bIsVideo ? 20252 : 20124)); pDialog->Progress(); // add initial songs if (!AddInitialSongs(songIDs)) { pDialog->Close(); return false; } CLog::Log(LOGDEBUG, "%s time for song fetch: %u", __FUNCTION__, XbmcThreads::SystemClockMillis() - time); // start playing g_playlistPlayer.SetCurrentPlaylist(iPlaylist); Play(0); pDialog->Close(); // open now playing window if (m_type.Equals("songs")) { if (g_windowManager.GetActiveWindow() != WINDOW_MUSIC_PLAYLIST) g_windowManager.ActivateWindow(WINDOW_MUSIC_PLAYLIST); } // done m_bEnabled = true; Announce(); return true; }
bool CShoutcastDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items) { CStdString strRoot = strPath; if (CUtil::HasSlashAtEnd(strRoot) && strRoot != "shout://") strRoot.Delete(strRoot.size() - 1); /* keep backward competability (for users who already have this source defined) */ if( strRoot.Equals("shout://www.shoutcast.com") || strRoot.Equals("shout://") || strRoot.Equals("shout://classic.shoutcast.com") || strRoot.Equals("shout://www.shoutcast.com/sbin/newxml.phtml") ) strRoot = SHOUTCAST_MASTER_LINK; CGUIDialogProgress* dlgProgress = (CGUIDialogProgress*)m_gWindowManager.GetWindow(WINDOW_DIALOG_PROGRESS); if (dlgProgress) { dlgProgress->ShowProgressBar(false); dlgProgress->SetHeading(260); dlgProgress->SetLine(0, 14003); dlgProgress->SetLine(1, ""); dlgProgress->SetLine(2, ""); dlgProgress->StartModal(); } CURL url(strRoot); CStdString protocol = url.GetProtocol(); url.SetProtocol("http"); CFileCurl http; //CURL doesn't seem to understand that data is encoded.. odd // opening as text for now //http.SetContentEncoding("deflate"); if( !http.Open(url, false) ) { CLog::Log(LOGERROR, "%s - Unable to get shoutcast dir", __FUNCTION__); if (dlgProgress) dlgProgress->Close(); return false; } /* restore protocol */ url.SetProtocol(protocol); CStdString content = http.GetContent(); if( !(content.Equals("text/html") || content.Equals("text/xml") || content.Equals("text/html;charset=utf-8") || content.Equals("text/xml;charset=utf-8") )) { CLog::Log(LOGERROR, "%s - Invalid content type %s", __FUNCTION__, content.c_str()); if (dlgProgress) dlgProgress->Close(); return false; } int size_read = 0; int size_total = (int)http.GetLength(); int data_size = 0; CStdString data; data.reserve(size_total); /* read response from server into string buffer */ char buffer[16384]; while( (size_read = http.Read(buffer, sizeof(buffer)-1)) > 0 ) { buffer[size_read] = 0; data += buffer; data_size += size_read; dlgProgress->Progress(); if (dlgProgress->IsCanceled()) { dlgProgress->Close(); return false; } } /* parse returned xml */ TiXmlDocument doc; doc.Parse(data.c_str()); TiXmlElement *root = doc.RootElement(); if(root == NULL) { CLog::Log(LOGERROR, "%s - Unable to parse xml", __FUNCTION__); CLog::Log(LOGDEBUG, "%s - Sample follows...\n%s", __FUNCTION__, data.c_str()); dlgProgress->Close(); return false; } /* clear data to keep memusage down, not needed anymore */ data.Empty(); bool result = false; if( strcmp(root->Value(), "genrelist") == 0 ) result = ParseGenres(root, items, url); else if( strcmp(root->Value(), "stationlist") == 0 ) result = ParseStations(root, items, url); else { CLog::Log(LOGERROR, "%s - Invalid root xml element for shoutcast",__FUNCTION__); CLog::Log(LOGDEBUG, "%s - Sample follows...\n%s", __FUNCTION__, data.c_str()); } if (dlgProgress) dlgProgress->Close(); return result; }
void CGUIDialogPVRChannelManager::SaveList() // XXX investigate: renumbering doesn't work { if (!m_bContainsChanges) return; CPVRDatabase *database = CPVRManager::Get()->GetTVDatabase(); if (!database || !database->Open()) return; CGUIDialogProgress* pDlgProgress = (CGUIDialogProgress*)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS); pDlgProgress->SetHeading(190); pDlgProgress->SetLine(0, ""); pDlgProgress->SetLine(1, 328); pDlgProgress->SetLine(2, ""); pDlgProgress->StartModal(); pDlgProgress->Progress(); pDlgProgress->SetPercentage(0); int iActiveChannels = 0; for (int iListPtr = 0; iListPtr < m_channelItems->Size(); iListPtr++) { if (m_channelItems->Get(iListPtr)->GetPropertyBOOL("ActiveChannel")) ++iActiveChannels; } // int iNextChannelNumber = 1; // int iNextHiddenChannelNumber = iActiveChannels + 1; bool bHasChangedItems = false; for (int iListPtr = 0; iListPtr < m_channelItems->Size(); iListPtr++) { bool bChanged = false; CFileItemPtr pItem = m_channelItems->Get(iListPtr); if (!pItem) continue; CPVRChannel *channel = pItem->GetPVRChannelInfoTag(); if (!channel) { //TODO add new channel continue; } /* get values from the form */ bool bHidden = !pItem->GetPropertyBOOL("ActiveChannel"); bool bVirtual = pItem->GetPropertyBOOL("Virtual"); bool bEPGEnabled = pItem->GetPropertyBOOL("UseEPG"); int iEPGSource = pItem->GetPropertyInt("EPGSource"); CStdString strChannelName = pItem->GetProperty("Name"); CStdString strIconPath = pItem->GetProperty("Icon"); CStdString strStreamURL = pItem->GetProperty("StreamURL"); /* set new values in the channel tag */ // TODO // if (bHidden) // bChanged = channel->SetChannelNumber(iNextHiddenChannelNumber++) || bChanged; // else // bChanged = channel->SetChannelNumber(iNextChannelNumber++) || bChanged; bChanged = channel->SetChannelName(strChannelName) || bChanged; bChanged = channel->SetHidden(bHidden) || bChanged; bChanged = channel->SetIconPath(strIconPath) || bChanged; if (bVirtual) bChanged = channel->SetStreamURL(strStreamURL) || bChanged; if (iEPGSource == 0) bChanged = channel->SetEPGScraper("client") || bChanged; // TODO add other scrapers bChanged = channel->SetEPGEnabled(bEPGEnabled) || bChanged; if (bChanged) { bHasChangedItems = true; channel->Persist(true); } pItem->SetProperty("Changed", false); pDlgProgress->SetPercentage(iListPtr * 100 / m_channelItems->Size()); } if (bHasChangedItems) { database->CommitInsertQueries(); CPVRManager::Get()->Start(); // XXX not a nice way to refresh the channels, but works for now } database->Close(); m_bContainsChanges = false; pDlgProgress->Close(); }