diff options
author | spiff <spiff@xbmc.org> | 2012-10-07 13:31:25 +0200 |
---|---|---|
committer | spiff <spiff@xbmc.org> | 2012-10-08 22:28:03 +0200 |
commit | 27b5b041e20e6b17d4dadee5c9696834c65f4b24 (patch) | |
tree | 9a09d630f386aa736b5aae8b2cff8eab89428fe9 | |
parent | 518a2ca138e9210f6dbec9c2e9e9e26de3feba06 (diff) |
changed: replace video scan dialog with the extended progress bar
-rw-r--r-- | xbmc/Application.cpp | 11 | ||||
-rw-r--r-- | xbmc/interfaces/Builtins.cpp | 8 | ||||
-rw-r--r-- | xbmc/video/VideoDatabase.cpp | 19 | ||||
-rw-r--r-- | xbmc/video/VideoDatabase.h | 3 | ||||
-rw-r--r-- | xbmc/video/VideoInfoScanner.cpp | 115 | ||||
-rw-r--r-- | xbmc/video/VideoInfoScanner.h | 9 |
6 files changed, 83 insertions, 82 deletions
diff --git a/xbmc/Application.cpp b/xbmc/Application.cpp index f85326ec5d..6a6e26f34b 100644 --- a/xbmc/Application.cpp +++ b/xbmc/Application.cpp @@ -5857,15 +5857,8 @@ void CApplication::StartVideoScan(const CStdString &strDirectory, bool scanAll) if (m_videoInfoScanner->IsScanning()) return; - if (!g_guiSettings.GetBool("videolibrary.backgroundupdate")) - { - CGUIDialogVideoScan *videoScan = (CGUIDialogVideoScan *)g_windowManager.GetWindow(WINDOW_DIALOG_VIDEO_SCAN); - if (videoScan) - { - m_videoInfoScanner->SetObserver(videoScan); - videoScan->ShowScan(); - } - } + m_videoInfoScanner->ShowDialog(true); + m_videoInfoScanner->Start(strDirectory,scanAll); } diff --git a/xbmc/interfaces/Builtins.cpp b/xbmc/interfaces/Builtins.cpp index ea1554c38d..58ebef89f9 100644 --- a/xbmc/interfaces/Builtins.cpp +++ b/xbmc/interfaces/Builtins.cpp @@ -33,7 +33,6 @@ #include "dialogs/GUIDialogKaiToast.h" #include "dialogs/GUIDialogNumeric.h" #include "dialogs/GUIDialogProgress.h" -#include "video/dialogs/GUIDialogVideoScan.h" #include "dialogs/GUIDialogYesNo.h" #include "GUIUserMessages.h" #include "windows/GUIWindowLoginScreen.h" @@ -1242,14 +1241,7 @@ int CBuiltins::Execute(const CStdString& execString) g_application.StopMusicScan(); if (g_application.IsVideoScanning()) - { g_application.StopVideoScan(); - CGUIDialogVideoScan *videoScan = (CGUIDialogVideoScan *)g_windowManager.GetWindow(WINDOW_DIALOG_VIDEO_SCAN); - if (videoScan) - { - videoScan->Close(true); - } - } ADDON::CAddonMgr::Get().StopServices(true); diff --git a/xbmc/video/VideoDatabase.cpp b/xbmc/video/VideoDatabase.cpp index 5b86133b9b..fa6c4b7363 100644 --- a/xbmc/video/VideoDatabase.cpp +++ b/xbmc/video/VideoDatabase.cpp @@ -35,6 +35,7 @@ #include "filesystem/Directory.h" #include "filesystem/File.h" #include "filesystem/SpecialProtocol.h" +#include "dialogs/GUIDialogExtendedProgressBar.h" #include "dialogs/GUIDialogProgress.h" #include "dialogs/GUIDialogYesNo.h" #include "FileItem.h" @@ -7473,7 +7474,7 @@ void CVideoDatabase::GetMusicVideoDirectorsByName(const CStdString& strSearch, C } } -void CVideoDatabase::CleanDatabase(IVideoInfoScannerObserver* pObserver, const set<int>* paths) +void CVideoDatabase::CleanDatabase(CGUIDialogProgressBarHandle* handle, const set<int>* paths) { CGUIDialogProgress *progress=NULL; try @@ -7507,7 +7508,7 @@ void CVideoDatabase::CleanDatabase(IVideoInfoScannerObserver* pObserver, const s m_pDS->query(sql.c_str()); if (m_pDS->num_rows() == 0) return; - if (!pObserver) + if (!handle) { progress = (CGUIDialogProgress *)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS); if (progress) @@ -7523,10 +7524,8 @@ void CVideoDatabase::CleanDatabase(IVideoInfoScannerObserver* pObserver, const s } else { - pObserver->OnDirectoryChanged(""); - pObserver->OnSetTitle(""); - pObserver->OnSetCurrentProgress(0,1); - pObserver->OnStateChanged(CLEANING_UP_DATABASE); + handle->SetTitle(g_localizeStrings.Get(700)); + handle->SetText(""); } CStdString filesToDelete = ""; @@ -7569,7 +7568,7 @@ void CVideoDatabase::CleanDatabase(IVideoInfoScannerObserver* pObserver, const s filesToDelete += m_pDS->fv("files.idFile").get_asString() + ","; } - if (!pObserver) + if (!handle) { if (progress) { @@ -7584,7 +7583,7 @@ void CVideoDatabase::CleanDatabase(IVideoInfoScannerObserver* pObserver, const s } } else - pObserver->OnSetProgress(current,total); + handle->SetPercentage(current/(float)total*100); m_pDS->next(); current++; @@ -7845,8 +7844,8 @@ void CVideoDatabase::CleanDatabase(IVideoInfoScannerObserver* pObserver, const s CommitTransaction(); - if (pObserver) - pObserver->OnStateChanged(COMPRESSING_DATABASE); + if (handle) + handle->SetTitle(g_localizeStrings.Get(331)); Compress(false); diff --git a/xbmc/video/VideoDatabase.h b/xbmc/video/VideoDatabase.h index 16fdfca12d..616403a4b1 100644 --- a/xbmc/video/VideoDatabase.h +++ b/xbmc/video/VideoDatabase.h @@ -32,6 +32,7 @@ class CFileItem; class CFileItemList; class CVideoSettings; class CGUIDialogProgress; +class CGUIDialogProgressBarHandle; namespace dbiplus { @@ -602,7 +603,7 @@ public: bool HasContent(VIDEODB_CONTENT_TYPE type); bool HasSets() const; - void CleanDatabase(VIDEO::IVideoInfoScannerObserver* pObserver=NULL, const std::set<int>* paths=NULL); + void CleanDatabase(CGUIDialogProgressBarHandle* handle=NULL, const std::set<int>* paths=NULL); /*! \brief Add a file to the database, if necessary If the file is already in the database, we simply return its id. diff --git a/xbmc/video/VideoInfoScanner.cpp b/xbmc/video/VideoInfoScanner.cpp index 53552c5280..8e5ac589e4 100644 --- a/xbmc/video/VideoInfoScanner.cpp +++ b/xbmc/video/VideoInfoScanner.cpp @@ -31,6 +31,7 @@ #include "VideoInfoDownloader.h" #include "GUIInfoManager.h" #include "filesystem/File.h" +#include "dialogs/GUIDialogExtendedProgressBar.h" #include "dialogs/GUIDialogProgress.h" #include "dialogs/GUIDialogYesNo.h" #include "dialogs/GUIDialogOK.h" @@ -40,12 +41,14 @@ #include "settings/Settings.h" #include "utils/StringUtils.h" #include "guilib/LocalizeStrings.h" +#include "guilib/GUIWindowManager.h" #include "utils/TimeUtils.h" #include "utils/log.h" #include "utils/URIUtils.h" #include "utils/Variant.h" #include "ThumbLoader.h" #include "TextureCache.h" +#include "GUIUserMessages.h" #include "URL.h" using namespace std; @@ -58,7 +61,8 @@ namespace VIDEO CVideoInfoScanner::CVideoInfoScanner() : CThread("CVideoInfoScanner") { m_bRunning = false; - m_pObserver = NULL; + m_handle = NULL; + m_showDialog = false; m_bCanInterrupt = false; m_currentItem = 0; m_itemCount = 0; @@ -78,8 +82,12 @@ namespace VIDEO m_database.Open(); - if (m_pObserver) - m_pObserver->OnStateChanged(PREPARING); + if (m_showDialog && !g_guiSettings.GetBool("videolibrary.backgroundupdate")) + { + CGUIDialogExtendedProgressBar* dialog = + (CGUIDialogExtendedProgressBar*)g_windowManager.GetWindow(WINDOW_DIALOG_EXT_PROGRESS); + m_handle = dialog->GetHandle(g_localizeStrings.Get(314)); + } m_bCanInterrupt = true; @@ -114,11 +122,11 @@ namespace VIDEO if (!bCancelled) { if (m_bClean) - CleanDatabase(m_pObserver,&m_pathsToClean); + CleanDatabase(m_handle,&m_pathsToClean); else { - if (m_pObserver) - m_pObserver->OnStateChanged(COMPRESSING_DATABASE); + if (m_handle) + m_handle->SetTitle(g_localizeStrings.Get(331)); m_database.Compress(false); } } @@ -130,13 +138,14 @@ namespace VIDEO ANNOUNCEMENT::CAnnouncementManager::Announce(ANNOUNCEMENT::VideoLibrary, "xbmc", "OnScanFinished"); m_bRunning = false; - if (m_pObserver) - m_pObserver->OnFinished(); } catch (...) { CLog::Log(LOGERROR, "VideoInfoScanner: Exception while scanning."); } + if (m_handle) + m_handle->MarkFinished(); + m_handle = NULL; } void CVideoInfoScanner::Start(const CStdString& strDirectory, bool scanAll) @@ -177,26 +186,37 @@ namespace VIDEO StopThread(); } - void CVideoInfoScanner::CleanDatabase(IVideoInfoScannerObserver* pObserver /*= NULL */, const set<int>* paths /*= NULL */) + void CVideoInfoScanner::CleanDatabase(CGUIDialogProgressBarHandle* handle /*= NULL */, const set<int>* paths /*= NULL */) { m_bRunning = true; m_database.Open(); - m_database.CleanDatabase(pObserver, paths); + m_database.CleanDatabase(handle, paths); m_database.Close(); m_bRunning = false; } - void CVideoInfoScanner::SetObserver(IVideoInfoScannerObserver* pObserver) + static void OnDirectoryScanned(const CStdString& strDirectory) { - m_pObserver = pObserver; + CGUIMessage msg(GUI_MSG_DIRECTORY_SCANNED, 0, 0, 0); + msg.SetStringParam(strDirectory); + g_windowManager.SendThreadMessage(msg); + } + + static CStdString Prettify(const CStdString& strDirectory) + { + CURL url(strDirectory); + CStdString strStrippedPath = url.GetWithoutUserDetails(); + CURL::Decode(strStrippedPath); + + return strStrippedPath; } bool CVideoInfoScanner::DoScan(const CStdString& strDirectory) { - if (m_pObserver) + if (m_handle) { - m_pObserver->OnDirectoryChanged(strDirectory); - m_pObserver->OnSetTitle(g_localizeStrings.Get(20415)); + m_handle->SetTitle(g_localizeStrings.Get(20415)); + m_handle->SetText(Prettify(strDirectory)); } /* @@ -231,8 +251,11 @@ namespace VIDEO CStdString hash, dbHash; if (content == CONTENT_MOVIES ||content == CONTENT_MUSICVIDEOS) { - if (m_pObserver) - m_pObserver->OnStateChanged(content == CONTENT_MOVIES ? FETCHING_MOVIE_INFO : FETCHING_MUSICVIDEO_INFO); + if (m_handle) + { + int str = content == CONTENT_MOVIES ? 20374:20408; + m_handle->SetTitle(g_localizeStrings.Get(str)); + } CStdString fastHash = GetFastHash(strDirectory); if (m_database.GetPathHash(strDirectory, dbHash) && !fastHash.IsEmpty() && fastHash == dbHash) @@ -264,8 +287,8 @@ namespace VIDEO else CLog::Log(LOGDEBUG, "VideoInfoScanner: Skipping dir '%s' due to no change", strDirectory.c_str()); bSkip = true; - if (m_pObserver) - m_pObserver->OnDirectoryScanned(strDirectory); + if (m_handle) + OnDirectoryScanned(strDirectory); } // update the hash to a fast hash if needed if (CanFastHash(items) && !fastHash.IsEmpty()) @@ -274,8 +297,8 @@ namespace VIDEO } else if (content == CONTENT_TVSHOWS) { - if (m_pObserver) - m_pObserver->OnStateChanged(FETCHING_TVSHOW_INFO); + if (m_handle) + m_handle->SetTitle(g_localizeStrings.Get(20409)); if (foundDirectly && !settings.parent_name_root) { @@ -323,8 +346,8 @@ namespace VIDEO m_database.SetPathHash(strDirectory, hash); } - if (m_pObserver) - m_pObserver->OnDirectoryScanned(strDirectory); + if (m_handle) + OnDirectoryScanned(strDirectory); for (int i = 0; i < items.Size(); ++i) { @@ -382,13 +405,8 @@ namespace VIDEO if (info2->Content() == CONTENT_MOVIES || info2->Content() == CONTENT_MUSICVIDEOS) { - if (m_pObserver) - { - m_pObserver->OnSetCurrentProgress(i, items.Size()); - if (!pItem->m_bIsFolder && m_itemCount) - m_pObserver->OnSetProgress(m_currentItem++, m_itemCount); - } - + if (m_handle) + m_handle->SetPercentage(i*100.f/items.Size()); } // clear our scraper cache @@ -619,8 +637,8 @@ namespace VIDEO if (m_bStop || (progress && progress->IsCanceled())) return INFO_CANCELLED; - if (m_pObserver) - m_pObserver->OnDirectoryChanged(item->GetPath()); + if (m_handle) + m_handle->SetText(Prettify(item->GetPath())); CStdString showTitle = m_database.GetTvShowTitleById(showID); return OnProcessSeriesFolder(files, scraper, useLocal, showID, showTitle, progress); @@ -640,15 +658,13 @@ namespace VIDEO { m_currentItem += numFilesInFolder; - // notify our observer of our progress - if (m_pObserver) + // update our dialog with our progress + if (m_handle) { if (m_itemCount>0) - { - m_pObserver->OnSetProgress(m_currentItem, m_itemCount); - m_pObserver->OnSetCurrentProgress(numFilesInFolder, numFilesInFolder); - } - m_pObserver->OnDirectoryScanned(item->GetPath()); + m_handle->SetPercentage(m_currentItem*100.f/m_itemCount); + + OnDirectoryScanned(item->GetPath()); } return; } @@ -1049,8 +1065,8 @@ namespace VIDEO strTitle.Format("%s - %ix%i - %s", strShowTitle.c_str(), movieDetails.m_iSeason, movieDetails.m_iEpisode, strTitle.c_str()); } - if (m_pObserver) - m_pObserver->OnSetTitle(strTitle); + if (m_handle) + m_handle->SetText(strTitle); CLog::Log(LOGDEBUG, "VideoInfoScanner: Adding new item to %s:%s", TranslateContent(content).c_str(), pItem->GetPath().c_str()); long lResult = -1; @@ -1224,19 +1240,16 @@ namespace VIDEO pDlgProgress->SetPercentage((int)((float)(iCurr++)/iMax*100)); pDlgProgress->Progress(); } - if (m_pObserver) - { - if (m_itemCount > 0) - m_pObserver->OnSetProgress(m_currentItem++, m_itemCount); - m_pObserver->OnSetCurrentProgress(iCurr++, iMax); - } + if (m_handle) + m_handle->SetPercentage(100.f*iCurr++/iMax); + if ((pDlgProgress && pDlgProgress->IsCanceled()) || m_bStop) return INFO_CANCELLED; if (m_database.GetEpisodeId(file->strPath, file->iEpisode, file->iSeason) > -1) { - if (m_pObserver) - m_pObserver->OnSetTitle(g_localizeStrings.Get(20415)); + if (m_handle) + m_handle->SetTitle(g_localizeStrings.Get(20415)); continue; } @@ -1510,8 +1523,8 @@ namespace VIDEO if (nfoFile) nfoFile->GetDetails(movieDetails,NULL,true); - if (m_pObserver && url.strTitle.IsEmpty()) - m_pObserver->OnSetTitle(movieDetails.m_strTitle); + if (m_handle && url.strTitle.IsEmpty()) + m_handle->SetText(movieDetails.m_strTitle); if (pDialog) { diff --git a/xbmc/video/VideoInfoScanner.h b/xbmc/video/VideoInfoScanner.h index 4aaa342f54..cde535a091 100644 --- a/xbmc/video/VideoInfoScanner.h +++ b/xbmc/video/VideoInfoScanner.h @@ -73,9 +73,11 @@ namespace VIDEO */ void Start(const CStdString& strDirectory, bool scanAll = false); bool IsScanning(); - void CleanDatabase(IVideoInfoScannerObserver* pObserver=NULL, const std::set<int>* paths=NULL); + void CleanDatabase(CGUIDialogProgressBarHandle* handle=NULL, const std::set<int>* paths=NULL); void Stop(); - void SetObserver(IVideoInfoScannerObserver* pObserver); + + //! \brief Set whether or not to show a progress dialog + void ShowDialog(bool show) { m_showDialog = show; } /*! \brief Add an item to the database. \param pItem item to add to the database. @@ -225,7 +227,8 @@ namespace VIDEO */ CStdString GetParentDir(const CFileItem &item) const; - IVideoInfoScannerObserver* m_pObserver; + bool m_showDialog; + CGUIDialogProgressBarHandle* m_handle; int m_currentItem; int m_itemCount; bool m_bRunning; |