Commit 89beded5 authored by Scott Wheeler's avatar Scott Wheeler

Make Playlist::items() virtual -- my code had assumed that it already was

and there were some code paths that weren't being called because of this.

Fixed the errors that this uncovered including returning proper values from
DynamicPlaylist::items() and SearchPlaylist::items().  Previously it was
returning the set of "matched" items from the component playlists rather
than the actual displayed items in the playlist.

This also makes it possible to have a DynamicPlaylist composed of search
playlists, which was the problem that lead to the discovery of the issues
above.

svn path=/trunk/kdemultimedia/juk/; revision=238884
parent 7bbda9f6
......@@ -58,14 +58,10 @@ void DynamicPlaylist::slotReload()
// protected methods
////////////////////////////////////////////////////////////////////////////////
PlaylistItemList DynamicPlaylist::items() const
PlaylistItemList DynamicPlaylist::items()
{
PlaylistItemList l;
for(PlaylistList::ConstIterator it = m_playlists.begin(); it != m_playlists.end(); ++it)
l += (*it)->items();
return l;
checkUpdateItems();
return Playlist::items();
}
void DynamicPlaylist::showEvent(QShowEvent *e)
......@@ -80,14 +76,21 @@ void DynamicPlaylist::showEvent(QShowEvent *e)
void DynamicPlaylist::checkUpdateItems()
{
if(m_dirty) {
PlaylistItemList newItems = items();
if(m_items != newItems) {
m_items = newItems;
QTimer::singleShot(0, this, SLOT(slotUpdateItems()));
}
m_dirty = false;
if(!m_dirty)
return;
PlaylistItemList siblings;
for(PlaylistList::ConstIterator it = m_playlists.begin(); it != m_playlists.end(); ++it)
siblings += (*it)->items();
PlaylistItemList newSiblings = siblings;
if(m_siblings != newSiblings) {
m_siblings = newSiblings;
QTimer::singleShot(0, this, SLOT(slotUpdateItems()));
}
m_dirty = false;
}
////////////////////////////////////////////////////////////////////////////////
......@@ -100,7 +103,7 @@ void DynamicPlaylist::slotUpdateItems()
// list and just adding those and removing the ones that aren't.
clear();
createItems(m_items);
createItems(m_siblings);
}
#include "dynamicplaylist.moc"
......@@ -52,7 +52,7 @@ protected:
* list this should return only the matched items. By default it returns
* all of the items in the playlists associated with this dynamic list.
*/
virtual PlaylistItemList items() const;
virtual PlaylistItemList items();
/**
* Reimplemented from QWidget. Here it updates the list of items (when
......@@ -75,7 +75,7 @@ private slots:
void slotUpdateItems();
private:
PlaylistItemList m_items;
PlaylistItemList m_siblings;
PlaylistList m_playlists;
bool m_dirty;
};
......
......@@ -78,7 +78,7 @@ public:
/**
* Returns a list of all of the \e visible items in the playlist.
*/
PlaylistItemList items();
virtual PlaylistItemList items();
/**
* Returns a list of all of the items in the playlist.
......
......@@ -406,9 +406,11 @@ void PlaylistItem::Data::setFile(const QString &file)
// PlaylistItem::Data protected methods
////////////////////////////////////////////////////////////////////////////////
PlaylistItem::Data::Data(const QFileInfo &file, const QString &path) : m_fileInfo(file), m_absFileName(path)
PlaylistItem::Data::Data(const QFileInfo &file, const QString &path) :
m_fileInfo(file),
m_referenceCount(1),
m_absFileName(path)
{
m_referenceCount = 1;
m_dataTag = Tag::createTag(path);
}
......
......@@ -15,7 +15,10 @@
* *
***************************************************************************/
#include <kdebug.h>
#include "searchplaylist.h"
#include "playlistitem.h"
////////////////////////////////////////////////////////////////////////////////
// public methods
......@@ -37,19 +40,32 @@ SearchPlaylist::SearchPlaylist(const PlaylistSearch &search, QWidget *parent, co
void SearchPlaylist::showEvent(QShowEvent *e)
{
if(m_dirty) {
clear();
m_search.search();
createItems(m_search.matchedItems());
m_dirty = false;
}
search();
Playlist::showEvent(e);
}
DynamicPlaylist::showEvent(e);
PlaylistItemList SearchPlaylist::items()
{
search();
return Playlist::items();
}
PlaylistItemList SearchPlaylist::items() const
////////////////////////////////////////////////////////////////////////////////
// private methods
////////////////////////////////////////////////////////////////////////////////
void SearchPlaylist::search()
{
return m_search.matchedItems();
if(m_dirty) {
// Here we don't simply use "clear" since that would involve a call to
// items() which would in turn call this method...
clearItems(Playlist::items());
m_search.search();
createItems(m_search.matchedItems());
m_dirty = false;
}
}
#include "searchplaylist.moc"
......@@ -29,11 +29,14 @@ public:
protected:
virtual void showEvent(QShowEvent *e);
virtual PlaylistItemList items() const;
virtual PlaylistItemList items();
private slots:
void slotSetDirty() { m_dirty = true; }
private:
void search();
PlaylistSearch m_search;
bool m_dirty;
};
......
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