Members of the KDE Community are recommended to subscribe to the kde-community mailing list at to allow them to participate in important discussions and receive other important announcements

Commit 355d3f51 authored by Scott Wheeler's avatar Scott Wheeler

Build the artist / album list in a smarter way. Also added some docs to

SortedStringList and removed the "Color" property of tree nodes since at
the moment it's a normal binary search tree rather than a red-black tree
(got lazy, BST was pretty balanced in the cases I'm using it in).

svn path=/trunk/kdemultimedia/juk/; revision=231726
parent 7cdee8b4
......@@ -159,19 +159,30 @@ void CollectionList::contentsDragMoveEvent(QDragMoveEvent *e)
void CollectionList::addArtist(const QString &artist)
// Do a bit of caching since there will very often be "two in a row" insertions.
static QString previousArtist;
if(artist != previousArtist && !m_artists.insert(artist))
if(artist == previousArtist || m_artists.insert(artist))
previousArtist = artist;
void CollectionList::addAlbum(const QString &album)
// Do a bit of caching since there will very often be "two in a row" insertions.
static QString previousAlbum;
if(album != previousAlbum && !m_albums.insert(album))
if(album == previousAlbum || m_albums.insert(album))
previousAlbum = album;
......@@ -27,6 +27,7 @@
#include "playlist.h"
#include "playlistitem.h"
#include "sortedstringlist.h"
#include "stringhash.h"
class CollectionListItem;
......@@ -60,6 +61,8 @@ public:
QListViewItem * = 0,
bool = false);
QMap<QString, SortedStringList> viewModeItems() const { return m_viewModeItems; }
public slots:
virtual void paste() { decode(kapp->clipboard()->data()); }
virtual void clear();
......@@ -109,6 +112,7 @@ private:
SortedStringList m_artists;
SortedStringList m_albums;
KDirWatch *m_dirWatch;
QMap<QString, SortedStringList> m_viewModeItems;
class CollectionListItem : public PlaylistItem
......@@ -22,16 +22,13 @@
class SortedStringList::Node
enum Color { Red, Black };
Node(const QString &value) : key(value), parent(0), left(0), right(0), color(Black) {}
Node(const QString &value) : key(value), parent(0), left(0), right(0) {}
~Node() {}
QString key;
Node *parent;
Node *left;
Node *right;
Color color;
SortedStringList::SortedStringList() : m_root(0)
......@@ -27,6 +27,10 @@ public:
* Insert the value. Returns true if the item was already in the list
* or false otherwise.
bool insert(const QString &value);
bool contains(const QString &value) const;
bool remove(const QString &value);
......@@ -52,7 +56,6 @@ private:
Node *treeMinimum(Node *n) const;
Node *treeSuccessor(Node *n) const;
Node *m_root;
......@@ -199,11 +199,11 @@ void TreeViewMode::setShown(bool show)
i = new PlaylistBox::Item(collectionItem, "cdimage", i18n("Artists"));
m_categories.insert("artists", i);
setupCategory(i, CollectionList::instance()->artists());
setupCategory(i, CollectionList::instance()->viewModeItems()["artists"].values());
i = new PlaylistBox::Item(collectionItem, "cdimage", i18n("Albums"));
m_categories.insert("albums", i);
setupCategory(i, CollectionList::instance()->albums());
setupCategory(i, CollectionList::instance()->viewModeItems()["albums"].values());
for(QDictIterator<PlaylistBox::Item> it(m_categories); it.current(); ++it)
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