Commit 7bbda9f6 authored by Scott Wheeler's avatar Scott Wheeler

Clean up the API for "unique sets" generated by the collection list. This

reduces the number of API methods and makes it more extensible.

svn path=/trunk/kdemultimedia/juk/; revision=238825
parent 007138d7
......@@ -107,8 +107,12 @@ void CollectionList::slotCheckCache()
// protected methods
////////////////////////////////////////////////////////////////////////////////
CollectionList::CollectionList(QWidget *parent) : Playlist(parent, i18n("Collection List")),
m_itemsDict(5003)
CollectionList::CollectionList(QWidget *parent) :
Playlist(parent, i18n("Collection List")),
m_itemsDict(5003),
m_viewModeItems(m_uniqueSetCount, SortedStringList()),
m_uniqueSets(m_uniqueSetCount, SortedStringList()),
m_uniqueSetLast(m_uniqueSetCount, QString::null)
{
m_dirWatch = new KDirWatch();
connect(m_dirWatch, SIGNAL(deleted(const QString &)), this, SLOT(slotRemoveItem(const QString &)));
......@@ -157,47 +161,15 @@ void CollectionList::contentsDragMoveEvent(QDragMoveEvent *e)
e->accept(false);
}
void CollectionList::addArtist(const QString &artist)
void CollectionList::addUnique(UniqueSetType t, const QString &value)
{
if(artist.isEmpty())
if(value.isEmpty())
return;
// 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))
m_viewModeItems["artists"].insert(artist);
else
previousArtist = artist;
}
void CollectionList::addAlbum(const QString &album)
{
if(album.isEmpty())
return;
// 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))
m_viewModeItems["albums"].insert(album);
else
previousAlbum = album;
}
void CollectionList::addGenre(const QString &genre)
{
if(genre.isEmpty())
return;
// Do a bit of caching since there will very often be "two in a row" insertions.
static QString previousGenre;
if(genre == previousGenre || m_genres.insert(genre))
m_viewModeItems["genres"].insert(genre);
if(value == m_uniqueSetLast[t] || m_uniqueSets[t].insert(value))
m_viewModeItems[t].insert(value);
else
previousGenre = genre;
m_uniqueSetLast[t] = value;
}
////////////////////////////////////////////////////////////////////////////////
......@@ -227,9 +199,9 @@ void CollectionListItem::slotRefresh()
{
slotRefreshImpl();
CollectionList::instance()->addArtist(text(ArtistColumn));
CollectionList::instance()->addAlbum(text(AlbumColumn));
CollectionList::instance()->addGenre(text(GenreColumn));
CollectionList::instance()->addUnique(CollectionList::Artists, text(ArtistColumn));
CollectionList::instance()->addUnique(CollectionList::Albums, text(AlbumColumn));
CollectionList::instance()->addUnique(CollectionList::Genres, text(GenreColumn));
// This is connected to slotRefreshImpl() for all of the items children.
emit signalRefreshed();
......@@ -239,8 +211,9 @@ void CollectionListItem::slotRefresh()
// CollectionListItem protected methods
////////////////////////////////////////////////////////////////////////////////
CollectionListItem::CollectionListItem(const QFileInfo &file, const QString &path) : PlaylistItem(CollectionList::instance()),
m_path(path)
CollectionListItem::CollectionListItem(const QFileInfo &file, const QString &path) :
PlaylistItem(CollectionList::instance()),
m_path(path)
{
CollectionList *l = CollectionList::instance();
if(l) {
......
......@@ -49,12 +49,26 @@ class CollectionList : public Playlist
Q_OBJECT
public:
/**
* A variety of unique value lists will be kept in the collection. This
* enum can be used as an index into those structures.
*/
enum UniqueSetType { Artists = 0, Albums = 1, Genres = 2 };
static CollectionList *instance();
static void initialize(QWidget *parent, bool restoreOnLoad = true);
QStringList artists() const { return m_artists.values(); }
QStringList albums() const { return m_albums.values(); }
QStringList genres() const { return m_genres.values(); }
/**
* Returns a unique set of values associated with the type specified.
*/
QStringList uniqueSet(UniqueSetType t) const { return m_uniqueSets[t].values(); }
/**
* This is similar to uniqueSet() but in this case only returns values for
* which there are two or more occurances in the collection list. This is
* useful when grouping items.
*/
QStringList viewModeItems(UniqueSetType t) const { return m_viewModeItems[t].values(); }
CollectionListItem *lookup(const QString &file) { return m_itemsDict.find(file); }
virtual PlaylistItem *createItem(const QFileInfo &file,
......@@ -62,8 +76,6 @@ 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();
......@@ -78,25 +90,14 @@ protected:
virtual void contentsDragMoveEvent(QDragMoveEvent *e);
// These methods are used by CollectionListItem, which is a friend class.
void addToDict(const QString &file, CollectionListItem *item) { m_itemsDict.replace(file, item); }
void removeFromDict(const QString &file) { m_itemsDict.remove(file); }
/**
* This checks to see if the artist given is in the artist list maintained
* by the collection list (for use in autocompletion and the TagEditor
* combo boxes), and if it is not, it adds it to the list.
*/
void addArtist(const QString &artist);
/**
* This is similar to addArtist(), but is for album names.
*/
void addAlbum(const QString &album);
/**
* Again, similar to the above, but for genres.
* Add a value to one of the unique value lists; use the UniqueSetType as a key.
*/
void addGenre(const QString &genre);
void addUnique(UniqueSetType t, const QString &value);
void emitNumberOfItemsChanged() { emit signalNumberOfItemsChanged(this); }
......@@ -113,13 +114,21 @@ private slots:
void slotCreateGroup();
private:
/**
* Just the size of the above enum to keep from hard coding it in several
* locations.
*/
static const int m_uniqueSetCount = 3;
static CollectionList *m_list;
QDict<CollectionListItem> m_itemsDict;
SortedStringList m_artists;
SortedStringList m_albums;
SortedStringList m_genres;
KDirWatch *m_dirWatch;
QMap<QString, SortedStringList> m_viewModeItems;
QValueVector<SortedStringList> m_viewModeItems;
QValueVector<SortedStringList> m_uniqueSets;
QValueVector<QString> m_uniqueSetLast;
};
class CollectionListItem : public PlaylistItem
......
......@@ -950,10 +950,10 @@ void Playlist::slotRenameTag()
switch(m_currentColumn)
{
case PlaylistItem::TrackColumn:
edit->completionObject()->setItems(list->artists());
edit->completionObject()->setItems(list->uniqueSet(CollectionList::Artists));
break;
case PlaylistItem::AlbumColumn:
edit->completionObject()->setItems(list->albums());
edit->completionObject()->setItems(list->uniqueSet(CollectionList::Albums));
break;
case PlaylistItem::GenreColumn:
QStringList genreStrings;
......
......@@ -225,7 +225,7 @@ void TagEditor::slotUpdateCollection()
// silly to build and maintain unsorted lists and have to call sort
// every time that you want to verify that a list is sorted.
QStringList artistList = list->artists();
QStringList artistList = list->uniqueSet(CollectionList::Artists);
artistList.sort();
m_artistNameBox->listBox()->insertStringList(artistList);
......@@ -235,7 +235,7 @@ void TagEditor::slotUpdateCollection()
if(m_albumNameBox->listBox()) {
m_albumNameBox->listBox()->clear();
QStringList albumList = list->albums();
QStringList albumList = list->uniqueSet(CollectionList::Albums);
albumList.sort();
m_albumNameBox->listBox()->insertStringList(albumList);
......
......@@ -258,15 +258,15 @@ void TreeViewMode::slotSetupCategories()
i = new PlaylistBox::Item(collectionItem, "cdimage", i18n("Artists"));
m_searchCategories.insert("artists", i);
setupCategory("artists", CollectionList::instance()->viewModeItems()["artists"].values(), 1);
setupCategory("artists", CollectionList::instance()->viewModeItems(CollectionList::Artists), 1);
i = new PlaylistBox::Item(collectionItem, "cdimage", i18n("Albums"));
m_searchCategories.insert("albums", i);
setupCategory("albums", CollectionList::instance()->viewModeItems()["albums"].values(), 2);
setupCategory("albums", CollectionList::instance()->viewModeItems(CollectionList::Albums), 2);
i = new PlaylistBox::Item(collectionItem, "cdimage", i18n("Genres"));
m_searchCategories.insert("genres", i);
setupCategory("genres", CollectionList::instance()->viewModeItems()["genres"].values(), 4);
setupCategory("genres", CollectionList::instance()->viewModeItems(CollectionList::Genres), 4);
for(QDictIterator<PlaylistBox::Item> it(m_searchCategories); it.current(); ++it)
it.current()->setSortedFirst(true);
......
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