Commit 09dd6317 authored by Scott Wheeler's avatar Scott Wheeler

Track PlaylistItem (in the upcoming playlist) -> source playlist relationships

so that we can show the playing track in both playlists.  This is *close* to
working properly (but misses some notable cases like say, the first item).

Also removed a now unused function in Playlist.

svn path=/trunk/kdemultimedia/juk/; revision=362170
parent 92265e0c
......@@ -1410,25 +1410,6 @@ void Playlist::setup()
setSorting(1);
}
PlaylistItem *Playlist::nextItem(PlaylistItem *current) const
{
if(current) {
QListViewItemIterator it(current, QListViewItemIterator::Visible);
++it;
return static_cast<PlaylistItem *>(it.current());
}
else {
QListViewItemIterator it(const_cast<Playlist *>(this),
QListViewItemIterator::Selected |
QListViewItemIterator::Visible);
if(!it.current()) {
it = QListViewItemIterator(const_cast<Playlist *>(this),
QListViewItemIterator::Visible);
}
return static_cast<PlaylistItem *>(it.current());
}
}
void Playlist::loadFile(const QString &fileName, const QFileInfo &fileInfo)
{
QFile file(fileName);
......
......@@ -445,6 +445,9 @@ protected:
*/
void setCanDeletePlaylist(bool canDelete);
template <class ItemType, class SiblingType>
ItemType *createItem(SiblingType *sibling, ItemType *after = 0);
/**
* As a template this allows us to use the same code to initialize the items
* in subclasses. CollectionItemType should always be CollectionListItem and
......@@ -482,8 +485,6 @@ signals:
private:
void setup();
PlaylistItem *nextItem(PlaylistItem *current = 0) const;
/**
* Load the playlist from a file. \a fileName should be the absolute path.
* \a fileInfo should point to the same file as \a fileName. This is a
......@@ -703,27 +704,34 @@ ItemType *Playlist::createItem(const FileHandle &file, QListViewItem *after,
return 0;
}
template <class ItemType, class SiblingType>
ItemType *Playlist::createItem(SiblingType *sibling, ItemType *after)
{
m_disableColumnWidthUpdates = true;
if(!m_members.insert(sibling->file().absFilePath()) || m_allowDuplicates) {
after = new ItemType(sibling->collectionItem(), this, after);
setupItem(after);
if(!m_randomList.isEmpty() && !m_visibleChanged)
m_randomList.append(after);
}
m_disableColumnWidthUpdates = false;
return after;
}
template <class CollectionItemType, class ItemType, class SiblingType>
void Playlist::createItems(const QValueList<SiblingType *> &siblings, ItemType *after)
{
if(siblings.isEmpty())
return;
m_disableColumnWidthUpdates = true;
ItemType *newItem = after;
QValueListConstIterator<SiblingType *> it = siblings.begin();
for(; it != siblings.end(); ++it) {
if(!m_members.insert((*it)->file().absFilePath()) || m_allowDuplicates) {
newItem = new ItemType((*it)->collectionItem(), this, newItem);
setupItem(newItem);
if(!m_randomList.isEmpty() && !m_visibleChanged)
m_randomList.append(newItem);
}
}
for(; it != siblings.end(); ++it)
after = createItem(*it, after);
dataChanged();
m_disableColumnWidthUpdates = false;
slotWeightDirty();
}
......
......@@ -89,7 +89,8 @@ const QPixmap *PlaylistItem::pixmap(int column) const
if((column - offset) == CoverColumn && d->fileHandle.coverInfo()->hasCover())
return &image;
if(column == playlist()->leftColumn() && m_playing)
if(column == playlist()->leftColumn() &&
m_playingItems.contains(const_cast<PlaylistItem *>(this)))
return &playing;
return KListViewItem::pixmap(column);
......@@ -150,7 +151,6 @@ void PlaylistItem::setText(int column, const QString &text)
void PlaylistItem::setPlaying(bool playing, bool master)
{
m_playing = playing;
m_playingItems.remove(this);
if(playing) {
......@@ -237,16 +237,14 @@ void PlaylistItem::clear()
PlaylistItem::PlaylistItem(CollectionListItem *item, Playlist *parent) :
KListViewItem(parent),
d(0),
m_playing(false)
d(0)
{
setup(item);
}
PlaylistItem::PlaylistItem(CollectionListItem *item, Playlist *parent, QListViewItem *after) :
KListViewItem(parent, after),
d(0),
m_playing(false)
d(0)
{
setup(item);
}
......@@ -255,8 +253,7 @@ PlaylistItem::PlaylistItem(CollectionListItem *item, Playlist *parent, QListView
// This constructor should only be used by the CollectionList subclass.
PlaylistItem::PlaylistItem(CollectionList *parent) :
KListViewItem(parent),
m_playing(false)
KListViewItem(parent)
{
d = new Data;
m_collectionItem = static_cast<CollectionListItem *>(this);
......@@ -265,7 +262,7 @@ PlaylistItem::PlaylistItem(CollectionList *parent) :
void PlaylistItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int align)
{
if(!m_playing)
if(!m_playingItems.contains(this))
return KListViewItem::paintCell(p, cg, column, width, align);
QColorGroup colorGroup = cg;
......
......@@ -116,7 +116,7 @@ void DefaultSequenceIterator::advance()
PlaylistItem *next = current()->itemBelow();
if(!next && loop) {
Playlist *p = current()->playlist();
next = static_cast<PlaylistItem *>(p->firstChild());
next = p->firstChild();
}
setCurrent(next);
......
......@@ -75,7 +75,40 @@ void UpcomingPlaylist::appendItems(const PlaylistItemList &itemList)
if(itemList.isEmpty())
return;
createItems(itemList, playingItem());
PlaylistItem *after = static_cast<PlaylistItem *>(lastItem());
for(PlaylistItemList::ConstIterator it = itemList.begin(); it != itemList.end(); ++it) {
after = createItem(*it, after);
m_playlistIndex.insert(after, (*it)->playlist());
}
dataChanged();
slotWeightDirty();
}
void UpcomingPlaylist::playNext()
{
TrackSequenceManager::instance()->setCurrentPlaylist(this);
setPlaying(TrackSequenceManager::instance()->nextItem());
if(!playing())
return;
Playlist *source = m_playlistIndex[playingItem()];
if(!source)
return;
PlaylistList l;
l.append(this);
source->synchronizePlayingItems(l, false);
}
void UpcomingPlaylist::clearItem(PlaylistItem *item, bool emitChanged)
{
m_playlistIndex.remove(item);
Playlist::clearItem(item, emitChanged);
}
void UpcomingPlaylist::removeIteratorOverride()
......
......@@ -19,6 +19,8 @@
#include <klocale.h>
#include <qdatastream.h>
#include <qptrdict.h>
#include <qguardedptr.h>
#include "playlist.h"
#include "tracksequenceiterator.h"
......@@ -80,6 +82,16 @@ public:
*/
void appendItems(const PlaylistItemList &itemList);
virtual void playNext();
virtual void clearItem(PlaylistItem *item, bool emitChanged = true);
/**
* Returns a reference to the index between items in the list and the
* playlist that they came from. This is used to remap the currently
* playing item to the source playlist.
*/
QMap< PlaylistItem *, QGuardedPtr<Playlist> > &playlistIndex() const;
private:
/**
......@@ -116,6 +128,7 @@ private:
TrackSequenceIterator *m_oldIterator;
int m_defaultSize;
QMap< PlaylistItem *, QGuardedPtr<Playlist> > m_playlistIndex;
};
/**
......
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