diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | e2de64d6f1beb9e492daf5b886e19933c1fa41dd (patch) | |
tree | 9047cf9e6b5c43878d5bf82660adae77ceee097a /juk/dynamicplaylist.cpp | |
download | tdemultimedia-e2de64d6f1beb9e492daf5b886e19933c1fa41dd.tar.gz tdemultimedia-e2de64d6f1beb9e492daf5b886e19933c1fa41dd.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdemultimedia@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'juk/dynamicplaylist.cpp')
-rw-r--r-- | juk/dynamicplaylist.cpp | 194 |
1 files changed, 194 insertions, 0 deletions
diff --git a/juk/dynamicplaylist.cpp b/juk/dynamicplaylist.cpp new file mode 100644 index 00000000..69d0a4ae --- /dev/null +++ b/juk/dynamicplaylist.cpp @@ -0,0 +1,194 @@ +/*************************************************************************** + begin : Mon May 5 2003 + copyright : (C) 2003 - 2004 by Scott Wheeler + email : wheeler@kde.org +***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include <kdebug.h> + +#include "dynamicplaylist.h" +#include "collectionlist.h" +#include "playlistcollection.h" +#include "tracksequencemanager.h" + +class PlaylistDirtyObserver : public PlaylistObserver +{ +public: + PlaylistDirtyObserver(DynamicPlaylist *parent, Playlist *playlist) : + PlaylistObserver(playlist), + m_parent(parent) + { + + } + virtual void updateData() { m_parent->slotSetDirty(); } + virtual void updateCurrent() {} + +private: + DynamicPlaylist *m_parent; +}; + +//////////////////////////////////////////////////////////////////////////////// +// public methods +//////////////////////////////////////////////////////////////////////////////// + +DynamicPlaylist::DynamicPlaylist(const PlaylistList &playlists, + PlaylistCollection *collection, + const QString &name, + const QString &iconName, + bool setupPlaylist, + bool synchronizePlaying) : + Playlist(collection, true), + m_playlists(playlists), + m_dirty(true), + m_synchronizePlaying(synchronizePlaying) +{ + if(setupPlaylist) + collection->setupPlaylist(this, iconName); + setName(name); + + setSorting(columns() + 1); + + for(PlaylistList::ConstIterator it = playlists.begin(); it != playlists.end(); ++it) + m_observers.append(new PlaylistDirtyObserver(this, *it)); + + connect(CollectionList::instance(), SIGNAL(signalCollectionChanged()), this, SLOT(slotSetDirty())); +} + +DynamicPlaylist::~DynamicPlaylist() +{ + lower(); + + for(QValueList<PlaylistObserver *>::ConstIterator it = m_observers.begin(); + it != m_observers.end(); + ++it) + { + delete *it; + } +} + +void DynamicPlaylist::setPlaylists(const PlaylistList &playlists) +{ + m_playlists = playlists; + updateItems(); +} + +//////////////////////////////////////////////////////////////////////////////// +// public slots +//////////////////////////////////////////////////////////////////////////////// + +void DynamicPlaylist::slotReload() +{ + for(PlaylistList::Iterator it = m_playlists.begin(); it != m_playlists.end(); ++it) + (*it)->slotReload(); + + checkUpdateItems(); +} + +void DynamicPlaylist::lower(QWidget *top) +{ + if(top == this) + return; + + if(playing()) { + PlaylistList l; + l.append(this); + for(PlaylistList::Iterator it = m_playlists.begin(); + it != m_playlists.end(); ++it) + { + (*it)->synchronizePlayingItems(l, true); + } + } + + PlaylistItemList list = PlaylistItem::playingItems(); + for(PlaylistItemList::Iterator it = list.begin(); it != list.end(); ++it) { + if((*it)->playlist() == this) { + list.remove(it); + break; + } + } + + if(!list.isEmpty()) + TrackSequenceManager::instance()->setCurrentPlaylist(list.front()->playlist()); +} + +//////////////////////////////////////////////////////////////////////////////// +// protected methods +//////////////////////////////////////////////////////////////////////////////// + +PlaylistItemList DynamicPlaylist::items() +{ + checkUpdateItems(); + return Playlist::items(); +} + +void DynamicPlaylist::showEvent(QShowEvent *e) +{ + checkUpdateItems(); + Playlist::showEvent(e); +} + +void DynamicPlaylist::paintEvent(QPaintEvent *e) +{ + checkUpdateItems(); + Playlist::paintEvent(e); +} + +void DynamicPlaylist::updateItems() +{ + 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())); + } +} + +bool DynamicPlaylist::synchronizePlaying() const +{ + return m_synchronizePlaying; +} + +//////////////////////////////////////////////////////////////////////////////// +// private methods +//////////////////////////////////////////////////////////////////////////////// + +void DynamicPlaylist::checkUpdateItems() +{ + if(!m_dirty) + return; + + updateItems(); + + m_dirty = false; +} + +//////////////////////////////////////////////////////////////////////////////// +// private slots +//////////////////////////////////////////////////////////////////////////////// + +void DynamicPlaylist::slotUpdateItems() +{ + // This should be optimized to check to see which items are already in the + // list and just adding those and removing the ones that aren't. + + clear(); + createItems(m_siblings); + if(m_synchronizePlaying) + synchronizePlayingItems(m_playlists, true); +} + +#include "dynamicplaylist.moc" |