remove state about playing from playlists, and some other GUI code, break a lot of stuff

parent 8f8805b5
......@@ -381,8 +381,7 @@ void CollectionList::removeWatched(const QString &file)
void CollectionListItem::refresh()
{
int offset = CollectionList::instance()->columnOffset();
int columns = lastColumn() + offset + 1;
int columns = lastColumn() + 1;
data()->metadata.resize(columns);
data()->cachedWidths.resize(columns);
......
......@@ -27,6 +27,12 @@
#include "cache.h"
#include "coverinfo.h"
/**
* Used to give every track added in the program a unique identifier. See
* PlaylistItem
*/
quint32 g_trackID = 0;
AddProperty(Title, tag()->title())
AddProperty(Artist, tag()->artist())
AddProperty(Album, tag()->album())
......@@ -70,7 +76,10 @@ class FileHandle::FileHandlePrivate : public RefCounter
public:
FileHandlePrivate() :
tag(0),
coverInfo(0) {}
coverInfo(0),
id(g_trackID++)
{
}
~FileHandlePrivate()
{
......@@ -84,6 +93,7 @@ public:
QFileInfo fileInfo;
QDateTime modificationTime;
QDateTime lastModified;
quint32 id;
};
////////////////////////////////////////////////////////////////////////////////
......@@ -214,6 +224,11 @@ const QDateTime &FileHandle::lastModified() const
return d->lastModified;
}
quint32 FileHandle::id() const
{
return d->id;
}
void FileHandle::read(CacheDataStream &s)
{
switch(s.cacheVersion()) {
......
......@@ -70,6 +70,8 @@ public:
QString property(const QString &name) const;
static const FileHandle &null();
quint32 id() const;
private:
class FileHandlePrivate;
......
......@@ -36,10 +36,10 @@
#include <KUrl>
#include <KStandardDirs>
static QByteArray idFromPlaylistItem(const PlaylistItem *item)
static QByteArray idFromFileHandle(const FileHandle &item)
{
return QByteArray("/org/kde/juk/tid_") +
QByteArray::number(item->trackId(), 16).rightJustified(8, '0');
QByteArray::number(item.id(), 16).rightJustified(8, '0');
}
MediaPlayer2Player::MediaPlayer2Player(QObject* parent)
......@@ -111,14 +111,14 @@ void MediaPlayer2Player::Play() const
void MediaPlayer2Player::SetPosition(const QDBusObjectPath& TrackId, qlonglong Position) const
{
PlaylistItem *playingItem = Playlist::playingItem();
const FileHandle &filehandle = PlayerManager::instance()->playingFile();
if (!playingItem) {
if (filehandle.isNull()) {
return;
}
// Verify the SetPosition call is against the currently playing track
QByteArray currentTrackId = idFromPlaylistItem(playingItem);
QByteArray currentTrackId = idFromFileHandle(filehandle);
if (TrackId.path().toLatin1() == currentTrackId) {
PlayerManager::instance()->seek(Position / 1000);
......@@ -187,13 +187,12 @@ QVariantMap MediaPlayer2Player::Metadata() const
// The track ID is annoying since it must result in a valid DBus object
// path, and the regex for that is, and I quote: [a-zA-Z0-9_]*, along with
// the normal / delimiters for paths.
PlaylistItem *item = Playlist::playingItem();
if (!item)
return metaData;
FileHandle playingFile = item->file();
QByteArray playingTrackFileId = idFromPlaylistItem(item);
const FileHandle &playingFile = PlayerManager::instance()->playingFile();
if (playingFile.isNull())
return metaData;
QByteArray playingTrackFileId = idFromFileHandle(playingFile);
metaData["mpris:trackid"] =
QVariant::fromValue<QDBusObjectPath>(
QDBusObjectPath(playingTrackFileId.constData()));
......@@ -209,7 +208,7 @@ QVariantMap MediaPlayer2Player::Metadata() const
if(playingFile.coverInfo()->hasCover()) {
QString fallbackFileName = KStandardDirs::locateLocal("tmp",
QString("juk-cover-%1.png").arg(item->trackId()));
QString("juk-cover-%1.png").arg(playingFile.id()));
QString path = fallbackFileName;
if(!QFile::exists(path)) {
......
......@@ -38,7 +38,6 @@
#include <math.h>
#include "playlist/playlistinterface.h"
#include "playeradaptor.h"
#include "slideraction.h"
#include "statuslabel.h"
......@@ -184,11 +183,6 @@ QString PlayerManager::playingString() const
return m_file.tag()->playingString();
}
void PlayerManager::setPlaylistInterface(PlaylistInterface *interface)
{
m_playlistInterface = interface;
}
void PlayerManager::setStatusLabel(StatusLabel *label)
{
m_statusLabel = label;
......@@ -203,7 +197,7 @@ void PlayerManager::play(const FileHandle &file)
if(!m_setup)
setup();
if(!m_media[0] || !m_media[1] || !m_playlistInterface)
if(!m_media[0] || !m_media[1])
return;
stopCrossfade();
......@@ -219,8 +213,8 @@ void PlayerManager::play(const FileHandle &file)
emit seeked(0);
}
else {
m_playlistInterface->playNext();
m_file = m_playlistInterface->currentFile();
// m_playlistInterface->playNext();
// m_file = m_playlistInterface->currentFile();
if(!m_file.isNull())
{
......@@ -249,7 +243,6 @@ void PlayerManager::play(const QString &file)
{
CollectionListItem *item = CollectionList::instance()->lookup(file);
if(item) {
Playlist::setPlaying(item);
play(item->file());
}
}
......@@ -278,7 +271,7 @@ void PlayerManager::pause()
void PlayerManager::stop()
{
if(!m_setup || !m_playlistInterface)
if(!m_setup)
return;
action("pause")->setEnabled(false);
......@@ -350,24 +343,24 @@ void PlayerManager::playPause()
void PlayerManager::forward()
{
m_playlistInterface->playNext();
FileHandle file = m_playlistInterface->currentFile();
// m_playlistInterface->playNext();
// FileHandle file = m_playlistInterface->currentFile();
if(!file.isNull())
play(file);
else
stop();
// if(!file.isNull())
// play(file);
// else
// stop();
}
void PlayerManager::back()
{
m_playlistInterface->playPrevious();
FileHandle file = m_playlistInterface->currentFile();
// m_playlistInterface->playPrevious();
// FileHandle file = m_playlistInterface->currentFile();
if(!file.isNull())
play(file);
else
stop();
// if(!file.isNull())
// play(file);
// else
// stop();
}
void PlayerManager::volumeUp()
......@@ -414,13 +407,13 @@ void PlayerManager::slotNeedNextUrl()
if(m_file.isNull() || !m_crossfadeTracks)
return;
m_playlistInterface->playNext();
FileHandle nextFile = m_playlistInterface->currentFile();
// m_playlistInterface->playNext();
// FileHandle nextFile = m_playlistInterface->currentFile();
if(!nextFile.isNull()) {
m_file = nextFile;
crossfadeToFile(m_file);
}
// if(!nextFile.isNull()) {
// m_file = nextFile;
// crossfadeToFile(m_file);
// }
}
void PlayerManager::slotFinished()
......@@ -436,8 +429,8 @@ void PlayerManager::slotFinished()
if(mediaObject != m_media[m_curOutputPath])
return;
m_playlistInterface->playNext();
m_file = m_playlistInterface->currentFile();
// m_playlistInterface->playNext();
// m_file = m_playlistInterface->currentFile();
if(m_file.isNull()) {
stop();
......@@ -457,7 +450,7 @@ void PlayerManager::slotLength(qint64 msec)
void PlayerManager::slotTick(qint64 msec)
{
if(!m_setup || !m_playlistInterface)
if(!m_setup)
return;
if(m_statusLabel)
......@@ -581,7 +574,6 @@ void PlayerManager::slotVolumeChanged(qreal volume)
PlayerManager::PlayerManager() :
QObject(),
m_playlistInterface(0),
m_statusLabel(0),
m_setup(false),
m_crossfadeTracks(true),
......
......@@ -32,7 +32,6 @@
class Scrobbler;
class KSelectAction;
class StatusLabel;
class PlaylistInterface;
class QPixmap;
namespace Phonon
......@@ -83,7 +82,6 @@ public:
KSelectAction* outputDeviceSelectAction();
void setPlaylistInterface(PlaylistInterface *interface);
void setStatusLabel(StatusLabel *label);
QString randomPlayMode() const;
......@@ -143,7 +141,6 @@ private slots:
private:
FileHandle m_file;
PlaylistInterface *m_playlistInterface;
StatusLabel *m_statusLabel;
Scrobbler *m_scrobbler;
bool m_muted;
......
......@@ -106,11 +106,6 @@ QString PlaylistCollection::name() const
return currentPlaylist()->name();
}
FileHandle PlaylistCollection::currentFile() const
{
return currentPlaylist()->currentFile();
}
int PlaylistCollection::count() const
{
return currentPlaylist()->count();
......@@ -121,45 +116,6 @@ int PlaylistCollection::time() const
return currentPlaylist()->time();
}
void PlaylistCollection::playFirst()
{
m_playing = true;
currentPlaylist()->playFirst();
currentChanged();
}
void PlaylistCollection::playNextAlbum()
{
m_playing = true;
currentPlaylist()->playNextAlbum();
currentChanged();
}
void PlaylistCollection::playPrevious()
{
m_playing = true;
currentPlaylist()->playPrevious();
currentChanged();
}
void PlaylistCollection::playNext()
{
m_playing = true;
currentPlaylist()->playNext();
currentChanged();
}
void PlaylistCollection::stop()
{
m_playing = false;
currentPlaylist()->stop();
weChanged();
}
bool PlaylistCollection::playing() const
{
return m_playing;
}
QStringList PlaylistCollection::playlists() const
{
......@@ -621,10 +577,7 @@ Playlist *PlaylistCollection::currentPlaylist() const
if(m_upcomingPlaylist && m_upcomingPlaylist->active())
return m_upcomingPlaylist;
if(Playlist::playingItem())
return Playlist::playingItem()->playlist();
else
return visiblePlaylist();
return visiblePlaylist();
}
Playlist *PlaylistCollection::visiblePlaylist() const
......
......@@ -56,13 +56,8 @@ public:
static PlaylistCollection *instance() { return m_instance; }
virtual QString name() const;
virtual FileHandle currentFile() const;
virtual int count() const;
virtual int time() const;
virtual void playNext();
virtual void playPrevious();
virtual void stop();
virtual bool playing() const;
void playFirst();
void playNextAlbum();
......@@ -236,9 +231,6 @@ private:
const QString &icon = QString(),
const KShortcut &shortcut = KShortcut());
private slots:
void slotPlayFirst() { m_collection->playFirst(); }
void slotPlayNextAlbum() { m_collection->playNextAlbum(); }
void slotOpen() { m_collection->open(); }
void slotManageFolders() { m_collection->addFolder(); }
void slotRename() { m_collection->rename(); }
......
......@@ -65,15 +65,8 @@ class PlaylistInterface : public Watched
{
public:
virtual QString name() const = 0;
virtual FileHandle currentFile() const = 0;
virtual int time() const = 0;
virtual int count() const = 0;
virtual void playNext() = 0;
virtual void playPrevious() = 0;
virtual void stop() = 0;
virtual bool playing() const = 0;
};
class PlaylistObserver
......
......@@ -56,8 +56,8 @@ PlaylistItem::~PlaylistItem()
if(m_playingItems.contains(this)) {
m_playingItems.removeAll(this);
if(m_playingItems.isEmpty())
playlist()->setPlaying(0);
// if(m_playingItems.isEmpty())
// playlist()->setPlaying(0);
}
playlist()->updateDeletedItem(this);
......@@ -89,8 +89,7 @@ FileHandle PlaylistItem::file() const
void PlaylistItem::setText(int column, const QString &text)
{
int offset = playlist()->columnOffset();
if(column - offset >= 0 && column + offset <= lastColumn()) {
if(column >= 0 && column <= lastColumn()) {
// K3ListViewItem::setText(column, QString());
return;
}
......@@ -228,7 +227,7 @@ int PlaylistItem::compare(PlaylistItem *playlistItem, int column, bool ascending
{
// reimplemented from QListViewItem
int offset = playlist()->columnOffset();
// int offset = playlist()->columnOffset();
if(!playlistItem)
return 0;
......@@ -255,15 +254,14 @@ int PlaylistItem::compare(PlaylistItem *playlistItem, int column, bool ascending
return c;
// }
}
return compare(this, playlistItem, 0 + offset, ascending);
return compare(this, playlistItem, 0, ascending);
}
}
int PlaylistItem::compare(const PlaylistItem *firstItem, const PlaylistItem *secondItem, int column, bool) const
{
int offset = playlist()->columnOffset();
if(column < 0 || column >= lastColumn() + offset || !firstItem->d || !secondItem->d)
if(column < 0 || column >= lastColumn() || !firstItem->d || !secondItem->d)
return 0;
// if(column < offset) {
......@@ -306,8 +304,8 @@ int PlaylistItem::compare(const PlaylistItem *firstItem, const PlaylistItem *sec
// return 1;
// break;
// default:
return QString::localeAwareCompare(firstItem->d->metadata[column - offset],
secondItem->d->metadata[column - offset]);
return QString::localeAwareCompare(firstItem->d->metadata[column],
secondItem->d->metadata[column]);
// }
}
......@@ -316,10 +314,6 @@ bool PlaylistItem::isValid() const
return bool(d->fileHandle.tag());
}
void PlaylistItem::setTrackId(quint32 id)
{
m_trackId = id;
}
////////////////////////////////////////////////////////////////////////////////
// PlaylistItem private methods
......
......@@ -96,13 +96,6 @@ public:
virtual CollectionListItem *collectionItem() { return m_collectionItem; }
/**
* This is an identifier for the playlist item which will remain unique
* throughout the process lifetime. It stays constant once the PlaylistItem
* is created.
*/
quint32 trackId() const { return m_trackId; }
/**
* The widths of items are cached when they're updated for us in computations
* in the "weighted" listview column width mode.
......@@ -186,7 +179,6 @@ private:
void setup(CollectionListItem *item);
CollectionListItem *m_collectionItem;
quint32 m_trackId;
bool m_watched;
static PlaylistItemList m_playingItems;
Playlist *m_playlist;
......
......@@ -185,8 +185,8 @@ void DynamicPlaylist::slotUpdateItems()
clear();
createItems(m_siblings);
if(m_synchronizePlaying)
synchronizePlayingItems(m_playlists, true);
// if(m_synchronizePlaying)
// synchronizePlayingItems(m_playlists, true);
}
#include "dynamicplaylist.moc"
......
This diff is collapsed.
This diff is collapsed.
......@@ -79,11 +79,6 @@ void SearchPlaylist::updateItems()
weChanged();
createItems(newItems);
if(synchronizePlaying()) {
kDebug() << "synchronizing playing";
synchronizePlayingItems(m_search.playlists(), true);
}
}
......
......@@ -80,34 +80,34 @@ void UpcomingPlaylist::appendItems(const PlaylistItemList &itemList)
// slotWeightDirty();
}
void UpcomingPlaylist::playNext()
{
initialize();
PlaylistItem *next = TrackSequenceManager::instance()->nextItem();
if(next) {
setPlaying(next);
Playlist *source = m_playlistIndex[next];
if(source) {
PlaylistList l;
l.append(this);
source->synchronizePlayingItems(l, false);
}
}
else {
removeIteratorOverride();
// Normally we continue to play the currently playing item that way
// a user can continue to hear their song when deselecting Play Queue.
// However we're technically still "playing" when the queue empties and
// we reinstall the old iterator so in this situation manually advance
// to the next track. (Otherwise we hear the same song twice in a row
// during the transition)
setPlaying(manager()->nextItem());
}
}
// void UpcomingPlaylist::playNext()
// {
// initialize();
//
// PlaylistItem *next = TrackSequenceManager::instance()->nextItem();
//
// if(next) {
// setPlaying(next);
// Playlist *source = m_playlistIndex[next];
// if(source) {
// PlaylistList l;
// l.append(this);
// source->synchronizePlayingItems(l, false);
// }
// }
// else {
// removeIteratorOverride();
//
// // Normally we continue to play the currently playing item that way
// // a user can continue to hear their song when deselecting Play Queue.
// // However we're technically still "playing" when the queue empties and
// // we reinstall the old iterator so in this situation manually advance
// // to the next track. (Otherwise we hear the same song twice in a row
// // during the transition)
//
// setPlaying(manager()->nextItem());
// }
// }
void UpcomingPlaylist::clearItem(PlaylistItem *item, bool emitChanged)
{
......@@ -155,10 +155,10 @@ void UpcomingPlaylist::removeIteratorOverride()
// XXX: Reset to the last playing playlist?
m_oldIterator->reset();
if(playingItem())
m_oldIterator->setCurrent(playingItem()->collectionItem());
// if(playingItem())
// m_oldIterator->setCurrent(playingItem()->collectionItem());
setPlaying(manager()->currentItem(), true);
// setPlaying(manager()->currentItem(), true);
Watched::currentChanged();
}
......@@ -214,9 +214,9 @@ void UpcomingPlaylist::UpcomingSequenceIterator::setCurrent(PlaylistItem *curren
// If the upcoming playlist is playing something, clear it out since
// apparently the user didn't want to hear it.
PlaylistItem *playingItem = m_playlist->playingItem();
if(playingItem && playingItem->playlist() == m_playlist && currentItem != playingItem)
m_playlist->clearItem(playingItem);
// PlaylistItem *playingItem = m_playlist->playingItem();
// if(playingItem && playingItem->playlist() == m_playlist && currentItem != playingItem)
// m_playlist->clearItem(playingItem);
// If a different playlist owns this item, add it to the upcoming playlist
......
......@@ -83,7 +83,7 @@ public:
* Reimplemented to set the playing item in both the source playlist
* and the upcoming playlist.
*/
virtual void playNext();
// virtual void playNext();
/**
* Reimplemented to remove the item from the Playlist index.
......
......@@ -1263,3 +1263,106 @@ void PlaylistView::setSearchEnabled(bool enabled)
// TrackSequenceManager::instance()->setNextItem(m_backMenuItems[number]);
// action("forward")->trigger();
// }
////////////////////////////////////////////////////////////////////////////////
// protected slots
////////////////////////////////////////////////////////////////////////////////
// void Playlist::slotPopulateBackMenu() const
// {
// if(!playingItem())
// return;
//
// QMenu *menu = action<KToolBarPopupAction>("back")->menu();
// menu->clear();
// m_backMenuItems.clear();
//
// int count = 0;
// PlaylistItemList::ConstIterator it = m_history.constEnd();
//
// QAction *action;
//
// while(it != m_history.constBegin() && count < 10) {
// ++count;
// --it;
// action = new QAction((*it)->file().tag()->title(), menu);
// action->setData(count);
// menu->addAction(action);
// m_backMenuItems[count] = *it;
// }
// }
//
// void Playlist::slotPlayFromBackMenu(QAction *backAction) const
// {
// int number = backAction->data().toInt();
//
// if(!m_backMenuItems.contains(number))
// return;
//
// TrackSequenceManager::instance()->setNextItem(m_backMenuItems[number]);
// action("forward")->trigger();
// }
//
// void Playlist::playFirst()
// {
// TrackSequenceManager::instance()->setNextItem(m_items.first());
// action("forward")->trigger();
// }
//
// void Playlist::playNextAlbum()
// {
// PlaylistItem *current = TrackSequenceManager::instance()->currentItem();
// if(!current)
// return; // No next album if we're not already playing.
//
// QString currentAlbum = current->file().tag()->album();
// current = TrackSequenceManager::instance()->nextItem();
//
// while(current && current->file().tag()->album() == currentAlbum)
// current = TrackSequenceManager::instance()->nextItem();
//
// TrackSequenceManager::instance()->setNextItem(current);
// action("forward")->trigger();
// }
//
// void Playlist::playNext()
// {
// TrackSequenceManager::instance()->setCurrentPlaylist(this);
// setPlaying(TrackSequenceManager::instance()->nextItem());
// }
//
// void Playlist::stop()
// {
// m_history.clear();
// setPlaying(0);
// }
//
// void Playlist::playPrevious()
// {
// if(!playingItem())
// return;
//
// bool random = action("randomPlay") && action<KToggleAction>("randomPlay")->isChecked();
//
// PlaylistItem *previous = 0;
//
// if(random && !m_history.isEmpty()) {<