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

List:       kde-commits
Subject:    kdemultimedia/juk
From:       Michael Pyne <michael.pyne () kdemail ! net>
Date:       2004-08-01 3:11:03
Message-ID: 20040801031103.B673B9905 () office ! kde ! org
[Download RAW message or body]

CVS commit by mpyne: 

Fix album random play.  Apparently the idea was to randomly select an album and play \
it from beginning to end, not in random order. :-)


  M +52 -15    playlist.cpp   1.238
  M +6 -1      playlist.h   1.130


--- kdemultimedia/juk/playlist.h  #1.129:1.130
@@ -444,4 +444,9 @@ private:
     PlaylistItem *nextItem(PlaylistItem *current = 0) const;
 
+    /** Sets up album random play to play songs with the same album as
+     * the given PlaylistItem.
+     */
+    void initAlbumSearch(const PlaylistItem *item);
+
     /**
      * Load the playlist from a file.  \a fileName should be the absolute path.
@@ -574,7 +579,7 @@ private:
 
     PlaylistItemList m_randomList;
-    QString m_randomAlbum;
     PlaylistItemList m_history;
     PlaylistSearch m_search;
+    PlaylistSearch m_albumSearch;
 
     bool m_searchEnabled;

--- kdemultimedia/juk/playlist.cpp  #1.237:1.238
@@ -413,5 +413,6 @@ void Playlist::playNext()
 
     if(random && list->m_randomList.isEmpty()) {
-        m_randomAlbum = QString::null;
+        m_albumSearch.clearComponents();
+        m_albumSearch.search();
         list->m_randomList = list->visibleItems();
 
@@ -426,4 +427,7 @@ void Playlist::playNext()
     if(m_playNextItem) {
         next = m_playNextItem;
+        initAlbumSearch(next);
+        m_albumSearch.clearItem(next);
+
         m_playNextItem = 0;
 
@@ -433,15 +437,25 @@ void Playlist::playNext()
     else if(random) {
         if(albumRandom) {
-            PlaylistItemList albumMatches;
+            if(m_albumSearch.isNull() || m_albumSearch.matchedItems().isEmpty()) {
+                next = list->m_randomList[KApplication::random() % \
list->m_randomList.count()]; +                initAlbumSearch(next);
+            }
+
+            // This can be null if initAlbumSearch() left the m_albumSearch
+            // empty because the album text was empty.
+
+            if(!m_albumSearch.isNull()) {
+                PlaylistItemList albumMatches = m_albumSearch.matchedItems();
             PlaylistItemList::ConstIterator it;
 
-            for(it = list->m_randomList.begin(); !m_randomAlbum.isNull() && it != \
                list->m_randomList.end(); ++it)
-                if((*it) != m_playingItem && (*it)->file().tag()->album() == \
                m_randomAlbum)
-                    albumMatches.append(*it);
+                next = albumMatches[0];
 
-            if(albumMatches.isEmpty())
-                next = list->m_randomList[KApplication::random() % \
                list->m_randomList.count()];
-            else
-                next = albumMatches[KApplication::random() % albumMatches.count()];
+                // Pick first song
+
+                for(unsigned i = 0; i < albumMatches.count(); ++i)
+                    if(albumMatches[i]->file().tag()->track() < \
next->file().tag()->track()) +                        next = albumMatches[i];
+                m_albumSearch.clearItem(next);
+            }
         }
         else
@@ -459,8 +473,4 @@ void Playlist::playNext()
     }
 
-    m_randomAlbum = QString::null;
-    if(next)
-        m_randomAlbum = next->file().tag()->album();
-
     setPlaying(next);
 }
@@ -469,5 +479,6 @@ void Playlist::stop()
 {
     m_history.clear();
-    m_randomAlbum = QString::null;
+    m_albumSearch.clearComponents();
+    m_albumSearch.search();
     setPlaying(0);
 }
@@ -1257,4 +1268,5 @@ void Playlist::setup()
     connect(header(), SIGNAL(indexChange(int, int, int)), this, \
SLOT(slotColumnOrderChanged(int, int, int)));  setSorting(1);
+    m_albumSearch.addPlaylist(this);
 }
 
@@ -1278,4 +1290,29 @@ PlaylistItem *Playlist::nextItem(Playlis
 }
 
+void Playlist::initAlbumSearch(const PlaylistItem *item)
+{
+    ColumnList columns;
+    
+    m_albumSearch.setSearchMode(PlaylistSearch::MatchAll);
+    m_albumSearch.clearComponents();
+
+    // if the album name is empty, it will mess up the search,
+    // so ignore empty album names.
+
+    if(item->file().tag()->album().isEmpty())
+        return;
+
+    columns.append(PlaylistItem::AlbumColumn);
+
+    m_albumSearch.addComponent(PlaylistSearch::Component(
+        item->file().tag()->album(),
+        true,
+        columns,
+        PlaylistSearch::Component::Exact)
+    );
+
+    m_albumSearch.search();
+}
+
 void Playlist::loadFile(const QString &fileName, const QFileInfo &fileInfo)
 {


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

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