Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit f6b790e6 authored by Scott Wheeler's avatar Scott Wheeler

Keep showing the playing item when a dynamic list is created and restore it

when it goes away.

FEATURE:77467

svn path=/trunk/kdemultimedia/juk/; revision=362147
parent 9701fa5b
......@@ -138,9 +138,7 @@ signals:
* \see Playlsit::isColumnVisible()
*/
void signalVisibleColumnsChanged();
void signalNewTag(const QString &, unsigned);
void signalRemovedTag(const QString &, unsigned);
private:
......
......@@ -43,10 +43,12 @@ DynamicPlaylist::DynamicPlaylist(const PlaylistList &playlists,
PlaylistCollection *collection,
const QString &name,
const QString &iconName,
bool setupPlaylist) :
bool setupPlaylist,
bool synchronizePlaying) :
Playlist(collection, true),
m_playlists(playlists),
m_dirty(true)
m_dirty(true),
m_synchronizePlaying(synchronizePlaying)
{
if(setupPlaylist)
collection->setupPlaylist(this, iconName);
......@@ -54,14 +56,25 @@ DynamicPlaylist::DynamicPlaylist(const PlaylistList &playlists,
setSorting(columns() + 1);
for(PlaylistList::ConstIterator it = playlists.begin(); it != playlists.end(); ++it)
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()
{
if(playing()) {
PlaylistList l;
l.append(this);
for(PlaylistList::Iterator it = m_playlists.begin();
it != m_playlists.end(); ++it)
{
(*it)->synchronizePlayingItems(l, true);
}
}
for(QValueList<PlaylistObserver *>::ConstIterator it = m_observers.begin();
it != m_observers.end();
++it)
......@@ -144,6 +157,8 @@ void DynamicPlaylist::slotUpdateItems()
clear();
createItems(m_siblings);
if(m_synchronizePlaying)
synchronizePlayingItems(m_playlists, true);
}
#include "dynamicplaylist.moc"
......@@ -33,7 +33,8 @@ public:
PlaylistCollection *collection,
const QString &name = QString::null,
const QString &iconName = "midi",
bool setupPlaylist = true);
bool setupPlaylist = true,
bool synchronizePlaying = false);
virtual ~DynamicPlaylist();
......@@ -92,6 +93,7 @@ private:
PlaylistItemList m_siblings;
PlaylistList m_playlists;
bool m_dirty;
bool m_synchronizePlaying;
};
#endif
......@@ -543,7 +543,7 @@ void Playlist::clearItems(const PlaylistItemList &items)
PlaylistItem *Playlist::playingItem() // static
{
return PlaylistItem::m_playingItems.isEmpty() ? 0 : PlaylistItem::m_playingItems.front();
return PlaylistItem::playingItems().isEmpty() ? 0 : PlaylistItem::playingItems().front();
}
QStringList Playlist::files() const
......@@ -647,6 +647,23 @@ void Playlist::markItemSelected(PlaylistItem *item, bool selected)
m_selectedCount--;
}
void Playlist::synchronizePlayingItems(const PlaylistList &sources, bool setMaster)
{
for(PlaylistList::ConstIterator it = sources.begin(); it != sources.end(); ++it) {
if((*it)->playing()) {
CollectionListItem *base = playingItem()->collectionItem();
for(QListViewItemIterator itemIt(this); itemIt.current(); ++itemIt) {
PlaylistItem *item = static_cast<PlaylistItem *>(itemIt.current());
if(base == item->collectionItem()) {
item->setPlaying(true, setMaster);
return;
}
}
return;
}
}
}
////////////////////////////////////////////////////////////////////////////////
// public slots
////////////////////////////////////////////////////////////////////////////////
......@@ -1141,8 +1158,8 @@ void Playlist::refreshAlbums(const PlaylistItemList &items, const QImage &image)
void Playlist::updatePlaying() const
{
for(PlaylistItemList::ConstIterator it = PlaylistItem::m_playingItems.begin();
it != PlaylistItem::m_playingItems.end(); ++it)
for(PlaylistItemList::ConstIterator it = PlaylistItem::playingItems().begin();
it != PlaylistItem::playingItems().end(); ++it)
{
(*it)->listView()->triggerUpdate();
}
......
......@@ -300,6 +300,13 @@ public:
*/
virtual bool searchIsEditable() const { return false; }
/**
* Synchronizes the the playing item in this playlist with the playing item
* in \a sources. If \a setMaster is true, this list will become the source
* for determining the next item.
*/
void synchronizePlayingItems(const PlaylistList &sources, bool setMaster);
/**
* Playlists have a common set of shared settings such as visible columns
* that should be applied just before the playlist is shown. Calling this
......
......@@ -649,7 +649,8 @@ void PlaylistBox::slotPlaylistChanged()
action("deleteItemPlaylist")->setText(i18n("R&emove"));
}
else if(!playlists.isEmpty()) {
DynamicPlaylist *p = new DynamicPlaylist(playlists, this, i18n("Dynamic List"), "midi", false);
DynamicPlaylist *p =
new DynamicPlaylist(playlists, this, i18n("Dynamic List"), "midi", false, true);
p->applySharedSettings();
playlistStack()->raiseWidget(p);
......
......@@ -50,11 +50,13 @@ PlaylistItem::~PlaylistItem()
// stark advantage of working reliably. I'll tell anyone who tries to
// optimize this, the timing issues can be *hard*. -- mpyne
if(playlist()->playingItem() == this)
playlist()->setPlaying(0);
m_collectionItem->removeChildItem(this);
m_playingItems.remove(this);
if(m_playingItems.find(this) != m_playingItems.end()) {
m_playingItems.remove(this);
if(m_playingItems.isEmpty())
playlist()->setPlaying(0);
}
}
void PlaylistItem::setFile(const FileHandle &file)
......@@ -146,22 +148,27 @@ void PlaylistItem::setText(int column, const QString &text)
playlist()->slotWeightDirty(column);
}
void PlaylistItem::setPlaying(bool playing)
void PlaylistItem::setPlaying(bool playing, bool master)
{
m_playing = playing;
listView()->triggerUpdate();
m_playingItems.remove(this);
if(playing)
m_playingItems.append(this);
if(playing) {
if(master)
m_playingItems.prepend(this);
else
m_playingItems.append(this);
}
else {
// This is a tricky little recursion, but it
// in fact does clear the list.
m_playingItems.remove(this);
if(!m_playingItems.isEmpty())
m_playingItems.front()->setPlaying(false);
}
listView()->triggerUpdate();
}
void PlaylistItem::setSelected(bool selected)
......
......@@ -73,7 +73,7 @@ public:
virtual QString text(int column) const;
virtual void setText(int column, const QString &text);
void setPlaying(bool playing = true);
void setPlaying(bool playing = true, bool master = true);
virtual void setSelected(bool selected);
void guessTagInfo(TagGuesser::Type type);
......@@ -117,6 +117,13 @@ public:
*/
PlaylistItem *itemAbove() { return static_cast<PlaylistItem *>(KListViewItem::itemAbove()); }
/**
* Returns a reference to the list of the currnetly playing items, with the
* first being the "master" item (i.e. the item from which the next track is
* chosen).
*/
static const PlaylistItemList &playingItems() { return m_playingItems; }
protected:
/**
* Items should always be created using Playlist::createItem() or through a
......
......@@ -28,8 +28,10 @@
SearchPlaylist::SearchPlaylist(PlaylistCollection *collection,
const PlaylistSearch &search,
const QString &name,
bool setupPlaylist) :
DynamicPlaylist(search.playlists(), collection, name, "find", setupPlaylist),
bool setupPlaylist,
bool synchronizePlaying) :
DynamicPlaylist(search.playlists(), collection, name, "find",
setupPlaylist, synchronizePlaying),
m_search(search)
{
......
......@@ -25,7 +25,8 @@ public:
SearchPlaylist(PlaylistCollection *collection,
const PlaylistSearch &search = PlaylistSearch(),
const QString &name = QString::null,
bool setupPlaylist = true);
bool setupPlaylist = true,
bool synchronizePlaying = false);
PlaylistSearch playlistSearch() const { return m_search; }
void setPlaylistSearch(const PlaylistSearch &s, bool update = 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