1
/***************************************************************************
3
copyright : (C) 2003 - 2004 by Scott Wheeler
4
email : wheeler@kde.org
5
***************************************************************************/
7
/***************************************************************************
9
* This program is free software; you can redistribute it and/or modify *
10
* it under the terms of the GNU General Public License as published by *
11
* the Free Software Foundation; either version 2 of the License, or *
12
* (at your option) any later version. *
14
***************************************************************************/
18
#include "dynamicplaylist.h"
19
#include "collectionlist.h"
20
#include "playlistcollection.h"
21
#include "tracksequencemanager.h"
23
class PlaylistDirtyObserver : public PlaylistObserver
26
PlaylistDirtyObserver(DynamicPlaylist *parent, Playlist *playlist) :
27
PlaylistObserver(playlist),
32
virtual void updateData() { m_parent->slotSetDirty(); }
33
virtual void updateCurrent() {}
36
DynamicPlaylist *m_parent;
39
////////////////////////////////////////////////////////////////////////////////
41
////////////////////////////////////////////////////////////////////////////////
43
DynamicPlaylist::DynamicPlaylist(const PlaylistList &playlists,
44
PlaylistCollection *collection,
46
const QString &iconName,
48
bool synchronizePlaying) :
49
Playlist(collection, true),
50
m_playlists(playlists),
52
m_synchronizePlaying(synchronizePlaying)
55
collection->setupPlaylist(this, iconName);
58
setSorting(columns() + 1);
60
for(PlaylistList::ConstIterator it = playlists.begin(); it != playlists.end(); ++it)
61
m_observers.append(new PlaylistDirtyObserver(this, *it));
63
connect(CollectionList::instance(), SIGNAL(signalCollectionChanged()), this, SLOT(slotSetDirty()));
66
DynamicPlaylist::~DynamicPlaylist()
70
for(QValueList<PlaylistObserver *>::ConstIterator it = m_observers.begin();
71
it != m_observers.end();
78
void DynamicPlaylist::setPlaylists(const PlaylistList &playlists)
80
m_playlists = playlists;
84
////////////////////////////////////////////////////////////////////////////////
86
////////////////////////////////////////////////////////////////////////////////
88
void DynamicPlaylist::slotReload()
90
for(PlaylistList::Iterator it = m_playlists.begin(); it != m_playlists.end(); ++it)
96
void DynamicPlaylist::lower(QWidget *top)
104
for(PlaylistList::Iterator it = m_playlists.begin();
105
it != m_playlists.end(); ++it)
107
(*it)->synchronizePlayingItems(l, true);
111
PlaylistItemList list = PlaylistItem::playingItems();
112
for(PlaylistItemList::Iterator it = list.begin(); it != list.end(); ++it) {
113
if((*it)->playlist() == this) {
120
TrackSequenceManager::instance()->setCurrentPlaylist(list.front()->playlist());
123
////////////////////////////////////////////////////////////////////////////////
125
////////////////////////////////////////////////////////////////////////////////
127
PlaylistItemList DynamicPlaylist::items()
130
return Playlist::items();
133
void DynamicPlaylist::showEvent(QShowEvent *e)
136
Playlist::showEvent(e);
139
void DynamicPlaylist::paintEvent(QPaintEvent *e)
142
Playlist::paintEvent(e);
145
void DynamicPlaylist::updateItems()
147
PlaylistItemList siblings;
149
for(PlaylistList::ConstIterator it = m_playlists.begin(); it != m_playlists.end(); ++it)
150
siblings += (*it)->items();
153
PlaylistItemList newSiblings = siblings;
154
if(m_siblings != newSiblings) {
155
m_siblings = newSiblings;
156
QTimer::singleShot(0, this, SLOT(slotUpdateItems()));
160
bool DynamicPlaylist::synchronizePlaying() const
162
return m_synchronizePlaying;
165
////////////////////////////////////////////////////////////////////////////////
167
////////////////////////////////////////////////////////////////////////////////
169
void DynamicPlaylist::checkUpdateItems()
179
////////////////////////////////////////////////////////////////////////////////
181
////////////////////////////////////////////////////////////////////////////////
183
void DynamicPlaylist::slotUpdateItems()
185
// This should be optimized to check to see which items are already in the
186
// list and just adding those and removing the ones that aren't.
189
createItems(m_siblings);
190
if(m_synchronizePlaying)
191
synchronizePlayingItems(m_playlists, true);
194
#include "dynamicplaylist.moc"