Skip to content
Browse files

changed: replace the music scan dialog by the extended progress bar

  • Loading branch information...
1 parent 779a390 commit 41dcd4da21604b9aed46dcdfe2d66daec5938bb5 spiff committed Oct 6, 2012
View
33 xbmc/Application.cpp
@@ -5885,14 +5885,8 @@ void CApplication::StartMusicScan(const CStdString &strDirectory, int flags)
}
if (!(flags & CMusicInfoScanner::SCAN_BACKGROUND))
- {
- CGUIDialogMusicScan *musicScan = (CGUIDialogMusicScan *)g_windowManager.GetWindow(WINDOW_DIALOG_MUSIC_SCAN);
- if (musicScan)
- {
- m_musicInfoScanner->SetObserver(musicScan);
- musicScan->ShowScan();
- }
- }
+ m_musicInfoScanner->ShowDialog(true);
+
m_musicInfoScanner->Start(strDirectory, flags);
}
@@ -5902,15 +5896,8 @@ void CApplication::StartMusicAlbumScan(const CStdString& strDirectory,
if (m_musicInfoScanner->IsScanning())
return;
- if (!g_guiSettings.GetBool("musiclibrary.backgroundupdate"))
- {
- CGUIDialogMusicScan *musicScan = (CGUIDialogMusicScan *)g_windowManager.GetWindow(WINDOW_DIALOG_MUSIC_SCAN);
- if (musicScan)
- {
- m_musicInfoScanner->SetObserver(musicScan);
- musicScan->ShowScan();
- }
- }
+ m_musicInfoScanner->ShowDialog(true);
+
m_musicInfoScanner->FetchAlbumInfo(strDirectory,refresh);
}
@@ -5920,17 +5907,9 @@ void CApplication::StartMusicArtistScan(const CStdString& strDirectory,
if (m_musicInfoScanner->IsScanning())
return;
- if (!g_guiSettings.GetBool("musiclibrary.backgroundupdate"))
- {
- CGUIDialogMusicScan *musicScan = (CGUIDialogMusicScan *)g_windowManager.GetWindow(WINDOW_DIALOG_MUSIC_SCAN);
- if (musicScan)
- {
- m_musicInfoScanner->SetObserver(musicScan);
- musicScan->ShowScan();
- }
- }
- m_musicInfoScanner->FetchArtistInfo(strDirectory,refresh);
+ m_musicInfoScanner->ShowDialog(true);
+ m_musicInfoScanner->FetchArtistInfo(strDirectory,refresh);
}
void CApplication::CheckPlayingProgress()
View
7 xbmc/interfaces/Builtins.cpp
@@ -31,7 +31,6 @@
#include "dialogs/GUIDialogFileBrowser.h"
#include "guilib/GUIKeyboardFactory.h"
#include "dialogs/GUIDialogKaiToast.h"
-#include "music/dialogs/GUIDialogMusicScan.h"
#include "dialogs/GUIDialogNumeric.h"
#include "dialogs/GUIDialogProgress.h"
#include "video/dialogs/GUIDialogVideoScan.h"
@@ -55,6 +54,7 @@
#include "utils/URIUtils.h"
#include "Util.h"
#include "URL.h"
+#include "music/MusicDatabase.h"
#include "filesystem/PluginDirectory.h"
#ifdef HAS_FILESYSTEM_RAR
@@ -1239,12 +1239,7 @@ int CBuiltins::Execute(const CStdString& execString)
g_application.StopPlaying();
if (g_application.IsMusicScanning())
- {
g_application.StopMusicScan();
- CGUIDialogMusicScan *musicScan = (CGUIDialogMusicScan *)g_windowManager.GetWindow(WINDOW_DIALOG_MUSIC_SCAN);
- if (musicScan)
- musicScan->Close(true);
- }
if (g_application.IsVideoScanning())
{
View
127 xbmc/music/infoscanner/MusicInfoScanner.cpp
@@ -32,6 +32,7 @@
#include "NfoFile.h"
#include "music/tags/MusicInfoTag.h"
#include "guilib/GUIWindowManager.h"
+#include "dialogs/GUIDialogExtendedProgressBar.h"
#include "dialogs/GUIDialogProgress.h"
#include "dialogs/GUIDialogSelect.h"
#include "guilib/GUIKeyboardFactory.h"
@@ -49,6 +50,7 @@
#include "TextureCache.h"
#include "ThumbLoader.h"
#include "interfaces/AnnouncementManager.h"
+#include "GUIUserMessages.h"
#include <algorithm>
@@ -60,7 +62,8 @@ using namespace MUSIC_GRABBER;
CMusicInfoScanner::CMusicInfoScanner() : CThread("CMusicInfoScanner")
{
m_bRunning = false;
- m_pObserver = NULL;
+ m_showDialog = false;
+ m_handle = NULL;
m_bCanInterrupt = false;
m_currentItem=0;
m_itemCount=0;
@@ -80,17 +83,21 @@ void CMusicInfoScanner::Process()
m_musicDatabase.Open();
- if (m_pObserver)
- m_pObserver->OnStateChanged(PREPARING);
+ if (m_showDialog && !g_guiSettings.GetBool("musiclibrary.backgroundupdate"))
+ {
+ CGUIDialogExtendedProgressBar* dialog =
+ (CGUIDialogExtendedProgressBar*)g_windowManager.GetWindow(WINDOW_DIALOG_EXT_PROGRESS);
+ m_handle = dialog->GetHandle(g_localizeStrings.Get(314));
+ }
m_bCanInterrupt = true;
if (m_scanType == 0) // load info from files
{
CLog::Log(LOGDEBUG, "%s - Starting scan", __FUNCTION__);
- if (m_pObserver)
- m_pObserver->OnStateChanged(READING_MUSIC_INFO);
+ if (m_handle)
+ m_handle->SetTitle(g_localizeStrings.Get(505));
// Reset progress vars
m_currentItem=0;
@@ -99,7 +106,7 @@ void CMusicInfoScanner::Process()
// Create the thread to count all files to be scanned
SetPriority( GetMinPriority() );
CThread fileCountReader(this, "CMusicInfoScanner");
- if (m_pObserver)
+ if (m_handle)
fileCountReader.Create();
// Database operations should not be canceled
@@ -130,13 +137,16 @@ void CMusicInfoScanner::Process()
if (m_needsCleanup)
{
- if (m_pObserver)
- m_pObserver->OnStateChanged(CLEANING_UP_DATABASE);
+ if (m_handle)
+ {
+ m_handle->SetTitle(g_localizeStrings.Get(700));
+ m_handle->SetText("");
+ }
m_musicDatabase.CleanupOrphanedItems();
- if (m_pObserver)
- m_pObserver->OnStateChanged(COMPRESSING_DATABASE);
+ if (m_handle)
+ m_handle->SetTitle(g_localizeStrings.Get(331));
m_musicDatabase.Compress(false);
}
@@ -155,16 +165,15 @@ void CMusicInfoScanner::Process()
bool bCanceled;
if (m_scanType == 1) // load album info
{
- if (m_pObserver)
- m_pObserver->OnStateChanged(DOWNLOADING_ALBUM_INFO);
-
+ if (m_handle)
+ m_handle->SetTitle(g_localizeStrings.Get(21885));
int iCurrentItem = 1;
for (set<CAlbum>::iterator it=m_albumsToScan.begin();it != m_albumsToScan.end();++it)
{
- if (m_pObserver)
+ if (m_handle)
{
- m_pObserver->OnDirectoryChanged(StringUtils::Join(it->artist, g_advancedSettings.m_musicItemSeparator)+" - "+it->strAlbum);
- m_pObserver->OnSetProgress(iCurrentItem++, m_albumsToScan.size());
+ m_handle->SetText(StringUtils::Join(it->artist, g_advancedSettings.m_musicItemSeparator)+" - "+it->strAlbum);
+ m_handle->SetPercentage(iCurrentItem++/(double)m_albumsToScan.size());
}
CMusicAlbumInfo albumInfo;
@@ -176,16 +185,16 @@ void CMusicInfoScanner::Process()
}
if (m_scanType == 2) // load artist info
{
- if (m_pObserver)
- m_pObserver->OnStateChanged(DOWNLOADING_ARTIST_INFO);
+ if (m_handle)
+ m_handle->SetTitle(g_localizeStrings.Get(21886));
int iCurrentItem=1;
for (set<CArtist>::iterator it=m_artistsToScan.begin();it != m_artistsToScan.end();++it)
{
- if (m_pObserver)
+ if (m_handle)
{
- m_pObserver->OnDirectoryChanged(it->strArtist);
- m_pObserver->OnSetProgress(iCurrentItem++, m_artistsToScan.size());
+ m_handle->SetText(it->strArtist);
+ m_handle->SetPercentage(iCurrentItem++/(double)m_artistsToScan.size()*100);
}
DownloadArtistInfo(it->genre[0],it->strArtist,bCanceled); // genre field holds path - see fetchartistinfo()
@@ -202,8 +211,18 @@ void CMusicInfoScanner::Process()
}
ANNOUNCEMENT::CAnnouncementManager::Announce(ANNOUNCEMENT::AudioLibrary, "xbmc", "OnScanFinished");
m_bRunning = false;
- if (m_pObserver)
- m_pObserver->OnFinished();
+ if (m_showDialog)
+ {
+ // clear cache
+ CUtil::DeleteMusicDatabaseDirectoryCache();
+
+ // send message
+ CGUIMessage msg(GUI_MSG_SCAN_FINISHED, 0, 0, 0);
+ g_windowManager.SendThreadMessage(msg);
+ }
+ if (m_handle)
+ m_handle->MarkFinished();
+ m_handle = NULL;
}
void CMusicInfoScanner::Start(const CStdString& strDirectory, int flags)
@@ -346,10 +365,26 @@ void CMusicInfoScanner::SetObserver(IMusicInfoScannerObserver* pObserver)
m_pObserver = pObserver;
}
+static void OnDirectoryScanned(const CStdString& strDirectory)
+{
+ 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 CMusicInfoScanner::DoScan(const CStdString& strDirectory)
{
- if (m_pObserver)
- m_pObserver->OnDirectoryChanged(strDirectory);
+ if (m_handle)
+ m_handle->SetText(Prettify(strDirectory));
/*
* remove this path from the list we're processing. This must be done prior to
@@ -394,8 +429,8 @@ bool CMusicInfoScanner::DoScan(const CStdString& strDirectory)
// and then scan in the new information
if (RetrieveMusicInfo(items, strDirectory) > 0)
{
- if (m_pObserver)
- m_pObserver->OnDirectoryScanned(strDirectory);
+ if (m_handle)
+ OnDirectoryScanned(strDirectory);
}
// save information about this folder
@@ -406,12 +441,12 @@ bool CMusicInfoScanner::DoScan(const CStdString& strDirectory)
CLog::Log(LOGDEBUG, "%s Skipping dir '%s' due to no change", __FUNCTION__, strDirectory.c_str());
m_currentItem += CountFiles(items, false); // false for non-recursive
- // notify our observer of our progress
- if (m_pObserver)
+ // updated the dialog with our progress
+ if (m_handle)
{
if (m_itemCount>0)
- m_pObserver->OnSetProgress(m_currentItem, m_itemCount);
- m_pObserver->OnDirectoryScanned(strDirectory);
+ m_handle->SetPercentage(m_currentItem/(double)m_itemCount*100);
+ OnDirectoryScanned(strDirectory);
}
}
@@ -479,10 +514,10 @@ int CMusicInfoScanner::RetrieveMusicInfo(CFileItemList& items, const CStdString&
pLoader->Load(pItem->GetPath(), tag);
}
- // if we have the itemcount, notify our
- // observer with the progress we made
- if (m_pObserver && m_itemCount>0)
- m_pObserver->OnSetProgress(m_currentItem, m_itemCount);
+ // if we have the itemcount, update our
+ // dialog with the progress we made
+ if (m_handle && m_itemCount>0)
+ m_handle->SetPercentage(m_currentItem/(double)m_itemCount*100);
if (tag.Loaded())
{
@@ -604,8 +639,8 @@ int CMusicInfoScanner::RetrieveMusicInfo(CFileItemList& items, const CStdString&
}
}
}
- if (m_pObserver)
- m_pObserver->OnStateChanged(READING_MUSIC_INFO);
+ if (m_handle)
+ m_handle->SetTitle(g_localizeStrings.Get(505));
return songsToAdd.size();
}
@@ -888,10 +923,10 @@ bool CMusicInfoScanner::DownloadAlbumInfo(const CStdString& strPath, const CStdS
return false;
}
- if (m_pObserver)
+ if (m_handle)
{
- m_pObserver->OnStateChanged(DOWNLOADING_ALBUM_INFO);
- m_pObserver->OnDirectoryChanged(strAlbum);
+ m_handle->SetTitle(g_localizeStrings.Get(21885));
+ m_handle->SetText(strArtist+" - "+strAlbum);
}
// clear our scraper cache
@@ -1122,15 +1157,15 @@ bool CMusicInfoScanner::DownloadArtistInfo(const CStdString& strPath, const CStd
return false;
}
- // clear our scraper cache
- info->ClearCache();
-
- if (m_pObserver)
+ if (m_handle)
{
- m_pObserver->OnStateChanged(DOWNLOADING_ARTIST_INFO);
- m_pObserver->OnDirectoryChanged(strArtist);
+ m_handle->SetTitle(g_localizeStrings.Get(21886));
+ m_handle->SetText(strArtist);
}
+ // clear our scraper cache
+ info->ClearCache();
+
CMusicInfoScraper scraper(info);
// handle nfo files
CStdString strArtistPath, strNfo;
View
7 xbmc/music/infoscanner/MusicInfoScanner.h
@@ -24,6 +24,7 @@
class CAlbum;
class CArtist;
+class CGUIDialogProgressBarHandle;
namespace MUSIC_INFO
{
@@ -60,6 +61,9 @@ class CMusicInfoScanner : CThread, public IRunnable
void Stop();
void SetObserver(IMusicInfoScannerObserver* pObserver);
+ //! \brief Set whether or not to show a progress dialog
+ void ShowDialog(bool show) { m_showDialog = show; }
+
/*! \brief Categorise songs into albums
Albums are defined uniquely by the album name and album artist.
@@ -117,7 +121,8 @@ class CMusicInfoScanner : CThread, public IRunnable
int CountFilesRecursively(const CStdString& strPath);
protected:
- IMusicInfoScannerObserver* m_pObserver;
+ bool m_showDialog;
+ CGUIDialogProgressBarHandle* m_handle;
int m_currentItem;
int m_itemCount;
bool m_bRunning;

0 comments on commit 41dcd4d

Please sign in to comment.
Something went wrong with that request. Please try again.