Commit 894d85d0 authored by Scott Wheeler's avatar Scott Wheeler

Much smarter job of handling updating of search playlists. It now only

adds the new matches and only clears the items which now don't match rather
than the old brute-force, "clear everything, show all matches".  This also
fixes #63908 for me.

CCMAIL:63908-done@bugs.kde.org

svn path=/trunk/kdemultimedia/juk/; revision=249599
parent ae124807
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <qfileinfo.h> #include <qfileinfo.h>
#include <qobject.h> #include <qobject.h>
#include <qptrstack.h> #include <qptrstack.h>
#include <qptrdict.h>
#include <qvaluevector.h> #include <qvaluevector.h>
#include "musicbrainzquery.h" #include "musicbrainzquery.h"
...@@ -54,8 +55,10 @@ typedef QValueList<PlaylistItem *> PlaylistItemList; ...@@ -54,8 +55,10 @@ typedef QValueList<PlaylistItem *> PlaylistItemList;
class PlaylistItem : public QObject, public KListViewItem class PlaylistItem : public QObject, public KListViewItem
{ {
friend class Playlist; friend class Playlist;
friend class SearchPlaylist;
friend class CollectionList; friend class CollectionList;
friend class QPtrList<PlaylistItem>; friend class QPtrList<PlaylistItem>;
friend class QPtrDict<PlaylistItem>;
/** /**
* Needs access to the destuctor, even though the destructor isn't used by QPtrStack. * Needs access to the destuctor, even though the destructor isn't used by QPtrStack.
......
...@@ -17,8 +17,11 @@ ...@@ -17,8 +17,11 @@
#include <kdebug.h> #include <kdebug.h>
#include <qptrdict.h>
#include "searchplaylist.h" #include "searchplaylist.h"
#include "playlistitem.h" #include "playlistitem.h"
#include "collectionlist.h"
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// public methods // public methods
...@@ -40,9 +43,31 @@ void SearchPlaylist::updateItems() ...@@ -40,9 +43,31 @@ void SearchPlaylist::updateItems()
// Here we don't simply use "clear" since that would involve a call to // Here we don't simply use "clear" since that would involve a call to
// items() which would in turn call this method... // items() which would in turn call this method...
clearItems(Playlist::items()); PlaylistItemList l = Playlist::items();
QPtrDict<PlaylistItem> oldItems(503);
for(PlaylistItemList::ConstIterator it = l.begin(); it != l.end(); ++it)
oldItems.insert((*it)->collectionItem(), *it);
m_search.search(); m_search.search();
createItems(m_search.matchedItems()); PlaylistItemList matched = m_search.matchedItems();
PlaylistItemList newItems;
for(PlaylistItemList::ConstIterator it = matched.begin(); it != matched.end(); ++it) {
if(!oldItems.remove((*it)->collectionItem()))
newItems.append((*it)->collectionItem());
}
// kdDebug(65432) << k_funcinfo << "newItems.size() == " << newItems.size() << endl;
for(QPtrDictIterator<PlaylistItem> it(oldItems); it.current(); ++it)
clearItem(it.current(), false);
if(!oldItems.isEmpty() && newItems.isEmpty())
emit signalCountChanged(this);
createItems(newItems);
} }
......
...@@ -36,7 +36,7 @@ protected: ...@@ -36,7 +36,7 @@ protected:
/** /**
* Runs the search to update the current items. * Runs the search to update the current items.
*/ */
void updateItems(); virtual void updateItems();
private: private:
PlaylistSearch m_search; PlaylistSearch m_search;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment