Commit fbaac406 authored by Scott Wheeler's avatar Scott Wheeler

Make the API for DynamicPlaylist a little smarter and make it possible

to remove duplicate code from SearchPlaylist (a subclass).

This also fixes the bug that search and dynamic playlist are now updated
when the playlists they're composed from change.

svn path=/trunk/kdemultimedia/juk/; revision=241986
parent 8a183b46
...@@ -70,15 +70,8 @@ void DynamicPlaylist::showEvent(QShowEvent *e) ...@@ -70,15 +70,8 @@ void DynamicPlaylist::showEvent(QShowEvent *e)
Playlist::showEvent(e); Playlist::showEvent(e);
} }
//////////////////////////////////////////////////////////////////////////////// void DynamicPlaylist::updateItems()
// private methods
////////////////////////////////////////////////////////////////////////////////
void DynamicPlaylist::checkUpdateItems()
{ {
if(!m_dirty)
return;
PlaylistItemList siblings; PlaylistItemList siblings;
for(PlaylistList::ConstIterator it = m_playlists.begin(); it != m_playlists.end(); ++it) for(PlaylistList::ConstIterator it = m_playlists.begin(); it != m_playlists.end(); ++it)
...@@ -90,6 +83,19 @@ void DynamicPlaylist::checkUpdateItems() ...@@ -90,6 +83,19 @@ void DynamicPlaylist::checkUpdateItems()
m_siblings = newSiblings; m_siblings = newSiblings;
QTimer::singleShot(0, this, SLOT(slotUpdateItems())); QTimer::singleShot(0, this, SLOT(slotUpdateItems()));
} }
}
////////////////////////////////////////////////////////////////////////////////
// private methods
////////////////////////////////////////////////////////////////////////////////
void DynamicPlaylist::checkUpdateItems()
{
if(!m_dirty)
return;
updateItems();
m_dirty = false; m_dirty = false;
} }
......
...@@ -60,8 +60,15 @@ protected: ...@@ -60,8 +60,15 @@ protected:
*/ */
virtual void showEvent(QShowEvent *e); virtual void showEvent(QShowEvent *e);
/**
* Updates the items (unconditionally). This should be reimplemented in
* subclasses to refresh the items in the dynamic list (i.e. running a
* search).
*/
virtual void updateItems();
protected slots: protected slots:
void slotSetDirty(bool d = true) { m_dirty = d; } void slotSetDirty() { m_dirty = true; }
private: private:
/** /**
......
...@@ -26,46 +26,23 @@ ...@@ -26,46 +26,23 @@
SearchPlaylist::SearchPlaylist(const PlaylistSearch &search, QWidget *parent, const QString &name) : SearchPlaylist::SearchPlaylist(const PlaylistSearch &search, QWidget *parent, const QString &name) :
DynamicPlaylist(search.playlists(), parent, name), DynamicPlaylist(search.playlists(), parent, name),
m_search(search), m_search(search)
m_dirty(true)
{ {
// PlaylistList::Iterator it = search.playlists().begin();
// for(; it != search.playlists().end(); ++it)
// connect(*it, SIGNAL(signalChanged()), this, SLOT(slotSetDirty()));
}
////////////////////////////////////////////////////////////////////////////////
// protected methods
////////////////////////////////////////////////////////////////////////////////
void SearchPlaylist::showEvent(QShowEvent *e)
{
search();
Playlist::showEvent(e);
}
PlaylistItemList SearchPlaylist::items()
{
search();
return Playlist::items();
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// private methods // protected methods
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void SearchPlaylist::search() void SearchPlaylist::updateItems()
{ {
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...
// 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()); clearItems(Playlist::items());
m_search.search(); m_search.search();
createItems(m_search.matchedItems()); createItems(m_search.matchedItems());
m_dirty = false;
}
} }
#include "searchplaylist.moc" #include "searchplaylist.moc"
...@@ -28,17 +28,12 @@ public: ...@@ -28,17 +28,12 @@ public:
SearchPlaylist(const PlaylistSearch &search, QWidget *parent, const QString &name = QString::null); SearchPlaylist(const PlaylistSearch &search, QWidget *parent, const QString &name = QString::null);
protected: protected:
virtual void showEvent(QShowEvent *e); /**
virtual PlaylistItemList items(); * Runs the search to update the current items.
*/
private slots: void updateItems();
void slotSetDirty() { m_dirty = true; }
private:
void search();
PlaylistSearch m_search; PlaylistSearch m_search;
bool m_dirty;
}; };
#endif #endif
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