[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [Amarok]  Thread the parsing of device metadata, to stop blo
From:       Alejandro Wainzinger <aikawarazuni () gmail ! com>
Date:       2009-12-29 11:30:03
Message-ID: 200912291130.nBTBU3QU010154 () Wurst ! kollide ! net
[Download RAW message or body]

commit 602801f67eeb506d17b2294f8ae22ff233c1e134
Author:     Alejandro Wainzinger <aikawarazuni@gmail.com>
AuthorDate: Tue Dec 29 03:15:31 2009 -0800
Commit:     Alejandro Wainzinger <aikawarazuni@gmail.com>
CommitDate: Tue Dec 29 03:15:31 2009 -0800

    Thread the parsing of device metadata, to stop blocking the GUI during parse of a \
large collection.

diff --git a/src/collection/mediadevicecollection/MediaDeviceCollection.cpp \
b/src/collection/mediadevicecollection/MediaDeviceCollection.cpp index \
                6955aea..1c2654a 100644
--- a/src/collection/mediadevicecollection/MediaDeviceCollection.cpp
+++ b/src/collection/mediadevicecollection/MediaDeviceCollection.cpp
@@ -161,7 +161,7 @@ MediaDeviceCollection::startFullScanDevice()
     // If handler successfully connected to device
 
     m_handler->parseTracks();
-    emit collectionReady( this );
+    //emit collectionReady( this );
 }
 
 Meta::MediaDeviceHandler*
diff --git a/src/collection/mediadevicecollection/handler/MediaDeviceHandler.cpp \
b/src/collection/mediadevicecollection/handler/MediaDeviceHandler.cpp index \
                8a65e80..1d9b5d0 100644
--- a/src/collection/mediadevicecollection/handler/MediaDeviceHandler.cpp
+++ b/src/collection/mediadevicecollection/handler/MediaDeviceHandler.cpp
@@ -810,14 +810,14 @@ MediaDeviceHandler::setupYearMap( Meta::MediaDeviceTrackPtr \
track, YearMap& year  track->setYear( yearPtr );
 }
 
-void
-MediaDeviceHandler::parseTracks()
+bool
+MediaDeviceHandler::privateParseTracks()
 {
     DEBUG_BLOCK
 
     setupReadCapability();
     if ( !m_rcb )
-        return;
+        return false;
 
     TrackMap trackMap;
     ArtistMap artistMap;
@@ -941,6 +941,8 @@ MediaDeviceHandler::parseTracks()
     m_memColl->releaseLock();
 
     m_memColl->collectionUpdated();
+
+    return true;
 }
 
 void
@@ -1227,6 +1229,47 @@ MediaDeviceHandler::metadataChanged( YearPtr year )
     Q_UNUSED( year );
 }
 
+void
+MediaDeviceHandler::parseTracks()
+{
+    ThreadWeaver::Weaver::instance()->enqueue( new ParseWorkerThread( this ) );
+}
+
+// ParseWorkerThread
+
+ParseWorkerThread::ParseWorkerThread( MediaDeviceHandler* handler )
+        : ThreadWeaver::Job()
+        , m_success( false )
+        , m_handler( handler )
+{
+    connect( this, SIGNAL( done( ThreadWeaver::Job* ) ), this, SLOT( \
slotDoneSuccess(ThreadWeaver::Job*)) ); +}
+
+ParseWorkerThread::~ParseWorkerThread()
+{
+    //nothing to do
+}
+
+bool
+ParseWorkerThread::success() const
+{
+    return m_success;
+}
+
+void
+ParseWorkerThread::run()
+{
+    m_success = m_handler->privateParseTracks();
+}
+
+void
+ParseWorkerThread::slotDoneSuccess( ThreadWeaver::Job* )
+{
+    m_handler->m_memColl->emitCollectionReady();
+}
+
+// CopyWorkerThread
+
 CopyWorkerThread::CopyWorkerThread( const Meta::TrackPtr &track, MediaDeviceHandler* \
handler )  : ThreadWeaver::Job()
         , m_success( false )
diff --git a/src/collection/mediadevicecollection/handler/MediaDeviceHandler.h \
b/src/collection/mediadevicecollection/handler/MediaDeviceHandler.h index \
                60aa4ef..4e6c022 100644
--- a/src/collection/mediadevicecollection/handler/MediaDeviceHandler.h
+++ b/src/collection/mediadevicecollection/handler/MediaDeviceHandler.h
@@ -101,6 +101,10 @@ public:
     */
     virtual ~MediaDeviceHandler();
 
+    // Declare thread as friend class
+
+    friend class ParseWorkerThread;
+
     /**
     * Begins an attempt to connect to the device, and emits
     * attemptConnectionDone when it finishes.
@@ -226,7 +230,8 @@ public slots:
     void renamePlaylist( const Meta::MediaDevicePlaylistPtr &playlist );
     void deletePlaylists( const Meta::MediaDevicePlaylistList &playlistlist );
 
-
+    bool privateParseTracks();
+    
     void copyNextTrackToDevice();
     bool privateCopyTrackToDevice( const Meta::TrackPtr& track );
 
@@ -379,6 +384,58 @@ private:
 };
 
 /**
+* The ParseWorkerThread is used to run a full parse of the device's database in
+* a separate thread. Once done, it informs the Collection it is done
+*/
+
+class ParseWorkerThread : public ThreadWeaver::Job
+{
+    Q_OBJECT
+public:
+    /**
+    * The constructor.
+    * @param handler The handler
+    */
+
+    ParseWorkerThread( MediaDeviceHandler* handler);
+
+    /**
+    * The destructor.
+    */
+
+    virtual ~ParseWorkerThread();
+
+    /**
+    * Sees the success variable, which says whether or not the copy completed
+successfully.
+    * @return Whether or not the copy was successful, i.e. m_success
+    */
+
+    virtual bool success() const;
+
+signals:
+
+private slots:
+    /**
+    * Is called when the job is done successfully, and simply
+    * calls Collection's emitCollectionReady()
+    * @param job The job that was done
+    */
+
+    void slotDoneSuccess( ThreadWeaver::Job* );
+
+protected:
+    /**
+    * Reimplemented, simply runs the parse method.
+    */
+    virtual void run();
+
+private:
+    bool m_success; /// Whether or not the parse was successful
+    MediaDeviceHandler *m_handler; /// The handler
+};
+
+/**
 * The CopyWorkerThread is used to run a copy operation on a single track in a \
                separate thread.
 * Copying is generally done one thread at a time so as to not hurt performance, and \
                because
 * many copying mechanisms like that of libmtp can only copy one file at a time.  \
Copying


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic