[vlmc-devel] MediaLibrary: Start media discovery after settings are restored

Hugo Beauzée-Luyssen git at videolan.org
Mon Jul 4 15:34:43 CEST 2016


vlmc | branch: medialibrary | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Mon Jun  6 01:14:27 2016 +0200| [0b14bad56453ca3c7dce8bf321c66d4ae21a3fa1] | committer: Hugo Beauzée-Luyssen

MediaLibrary: Start media discovery after settings are restored

Or after the first run

> https://code.videolan.org/videolan/vlmc/commit/0b14bad56453ca3c7dce8bf321c66d4ae21a3fa1
---

 src/Library/MediaLibrary.cpp | 39 ++++++++++++++++++++++++++++++++-------
 src/Library/MediaLibrary.h   | 12 +++++++++++-
 2 files changed, 43 insertions(+), 8 deletions(-)

diff --git a/src/Library/MediaLibrary.cpp b/src/Library/MediaLibrary.cpp
index be388d5..ee63c78 100644
--- a/src/Library/MediaLibrary.cpp
+++ b/src/Library/MediaLibrary.cpp
@@ -24,20 +24,45 @@
 #include "Settings/Settings.h"
 
 MediaLibrary::MediaLibrary( Settings* settings )
+    : m_initialized( false )
 {
     m_ml.reset( NewMediaLibrary() );
-    settings->createVar( SettingValue::List, QStringLiteral( "vlmc/mlDirs" ), QVariant(),
-                                       "", "", SettingValue::Nothing );
-    connect( settings, &Settings::postLoad, this, &MediaLibrary::postLoad, Qt::DirectConnection );
+    auto s = settings->createVar( SettingValue::List, QStringLiteral( "vlmc/mlDirs" ), QVariantList(),
+                        "Media Library folders", "List of folders VLMC will search for media files",
+                         SettingValue::Folders );
+    connect( s, &SettingValue::changed, this, &MediaLibrary::mlDirsChanged );
+    auto ws = settings->value( "vlmc/WorkspaceLocation" );
+    connect( ws, &SettingValue::changed, this, &MediaLibrary::workspaceChanged );
 }
 
-void MediaLibrary::postLoad()
+void
+MediaLibrary::mlDirsChanged( const QVariant& value )
 {
-    auto workspace = VLMC_GET_STRING( "vlmc/Workspace" ).toStdString();
-    Q_ASSERT( workspace.length() != 0 );
-    m_ml->initialize( workspace + "/ml.db", workspace + "/thumbnails/", this );
+    // We can't handle this event without an initialized media library, and therefor without a valid
+    // workspace. In theory, the workspace SettingValue is created before the mlDirs,
+    // so it should be loaded before.
+    Q_ASSERT( m_initialized == true );
+
+    const auto list = value.toStringList();
+    Q_ASSERT( list.empty() == false );
+    for ( const auto f : list )
+        m_ml->discover( f.toStdString() );
 }
 
+void
+MediaLibrary::workspaceChanged( const QVariant& workspace )
+{
+    Q_ASSERT( workspace.isNull() == false && workspace.canConvert<QString>() );
+
+    if ( m_initialized == false )
+    {
+        auto w = workspace.toString().toStdString();
+        Q_ASSERT( w.empty() == false );
+        m_ml->initialize( w + "/ml.db", w + "/thumbnails/", this );
+        m_initialized = true;
+    }
+    //else FIXME, and relocate the media library
+}
 
 void MediaLibrary::onMediaAdded( std::vector<medialibrary::MediaPtr> )
 {
diff --git a/src/Library/MediaLibrary.h b/src/Library/MediaLibrary.h
index 821a108..06f9f2c 100644
--- a/src/Library/MediaLibrary.h
+++ b/src/Library/MediaLibrary.h
@@ -39,8 +39,17 @@ class MediaLibrary : public QObject, private medialibrary::IMediaLibraryCb
 public:
     explicit MediaLibrary( Settings* settings );
 
+signals:
+    void    progressUpdated( int percent );
+    void    discoveryStarted( QString );
+    void    discoveryCompleted( QString );
+    void    reloadStarted( QString );
+    void    reloadCompleted( QString );
+
+
 private:
-    void postLoad();
+    void mlDirsChanged( const QVariant& value );
+    void workspaceChanged(const QVariant& workspace );
 
 private:
     virtual void onMediaAdded( std::vector<medialibrary::MediaPtr> media ) override;
@@ -62,6 +71,7 @@ private:
 
 private:
     std::unique_ptr<medialibrary::IMediaLibrary> m_ml;
+    bool m_initialized;
 };
 
 #endif // MEDIALIBRARY_H



More information about the Vlmc-devel mailing list