extragear/multimedia/amarok/src

Casey Link unnamedrambler at gmail.com
Wed Dec 3 20:46:34 CET 2008


SVN commit 892203 by link:

The DirectoryLoader now sorts paths in a meaningful way. This
fixes the order of folders dragged & dropped onto the playlist from the
filebrowser. This assumes the files, when sorted in lexigraphical order,
will be in the desired order. Possible improvement is comparing the
Meta::TrackPtr's track# tag.

BUG: 176673
BUG: 176156
CCMAIL: amarok-devel at kde.org

 M  +39 -13    DirectoryLoader.cpp  
 M  +5 -0      DirectoryLoader.h  


--- trunk/extragear/multimedia/amarok/src/DirectoryLoader.cpp #892202:892203
@@ -26,9 +26,10 @@
 #include "playlist/PlaylistController.h"
 #include "playlistmanager/PlaylistManager.h"
 
-#include <KFileItem>
 #include <kio/job.h> // KIO::listRecursive
 
+#include <QtAlgorithms>
+
 DirectoryLoader::DirectoryLoader()
     : QObject( 0 )
         , m_listOperations( 0 )
@@ -115,15 +116,8 @@
     const KUrl dir = static_cast<KIO::SimpleJob*>( job )->url();
     foreach( const KIO::UDSEntry &entry, list )
     {
-        KUrl currentUrl = dir;
-        currentUrl.addPath( entry.stringValue( KIO::UDSEntry::UDS_NAME ) );
-        debug() << "listing url: " << currentUrl;
-        if( !entry.isDir() )
-        {
-            Meta::TrackPtr track = CollectionManager::instance()->trackForUrl( currentUrl );
-            if( track )
-                m_tracks.append( track );
-        }
+        KFileItem item( entry, dir, true, true );
+        m_expanded.append( item );
     }
 }
 
@@ -138,13 +132,45 @@
 void
 DirectoryLoader::finishUrlList()
 {
-    if( !m_tracks.isEmpty() )
+    if( !m_expanded.isEmpty() )
     {
-        //qStableSort( m_tracks.begin(), m_tracks.end(), Meta::Track::lessThan ); //this will screw up if we add multiple dirs at once, or a playlist containing stuff from multiple
-        //                                                                          albums as it will sort across all track numbers, regardless of dir/album of the track
+        qStableSort( m_expanded.begin(), m_expanded.end(), DirectoryLoader::directorySensitiveLessThan );
+        foreach( const KFileItem& item, m_expanded )
+        {
+            if( !item.isDir() )
+            {
+                Meta::TrackPtr track = CollectionManager::instance()->trackForUrl( item.url() );
+                if( track )
+                    m_tracks.append( track );
+            }
+        }
         emit finished( m_tracks );
     }
     if( !m_localConnection )
         deleteLater();
 }
 
+bool
+DirectoryLoader::directorySensitiveLessThan( const KFileItem& item1, const KFileItem& item2 )
+{
+    QString dir1 =  item1.url().directory();
+    QString dir2 =  item2.url().directory();
+
+    debug() << "dir1: " << dir1;
+    debug() << "dir2: " << dir2;
+    if(dir1 == dir2)
+    {
+        debug() << "dir1==dir2";
+        return item1.url().url() < item2.url().url();
+    }
+    else if( dir1 < dir2 )
+    {
+        debug() << "dir1<dir2";
+        return true;
+    } else {
+        debug() << "dir1>dir2";
+        return false;
+    }
+}
+
+
--- trunk/extragear/multimedia/amarok/src/DirectoryLoader.h #892202:892203
@@ -25,11 +25,14 @@
 
 #include "Meta.h"
 
+#include <KFileItem>
+
 class KJob;
 namespace KIO {
     class Job;
     class UDSEntry;
     typedef QList< UDSEntry >  UDSEntryList;
+    typedef QList< KFileItem > KFileItemList;
 }
 
 
@@ -56,12 +59,14 @@
 
     private:
         void finishUrlList();
+        static bool directorySensitiveLessThan( const KFileItem& item1, const KFileItem& item2);
         /**
          * the number of directory list operations. this is used so that
          * the last directory operations knows its the last */
         int m_listOperations; 
         bool m_localConnection; //!was insertAtRow called? otherwise finishUrlList should deleteLater
         int m_row; //! for insertAtRow
+        KIO::KFileItemList m_expanded;
         Meta::TrackList m_tracks; //! the tracks found. they get all sorted at the end.
 };
 #endif


More information about the Amarok-devel mailing list