Commit 30148330 authored by Scott Wheeler's avatar Scott Wheeler

Moved the forward() and back() methods from the JuK class to the

PlayerManger class and fixed the bug where it would continue to play
beyond the end of the list (by just repeating the last item).

Started switching the semantics of nextFile() to *not* include the currently
selected item but to defer to currentFile() in that case.

Added PlaylistItem::playlist() and replaced a bunch of casts in
PlaylistSplitter.

svn path=/trunk/kdemultimedia/juk/; revision=291933
parent 37b11519
...@@ -142,8 +142,7 @@ void JuK::slotPopulateBackMenu() ...@@ -142,8 +142,7 @@ void JuK::slotPopulateBackMenu()
void JuK::forward() void JuK::forward()
{ {
play(m_splitter->playNextFile(m_randomPlayAction->isChecked(), m_player->forward();
m_loopPlaylistAction->isChecked()));
} }
void JuK::seekBack() void JuK::seekBack()
......
...@@ -133,16 +133,16 @@ void PlayerManager::play(const QString &fileName) ...@@ -133,16 +133,16 @@ void PlayerManager::play(const QString &fileName)
if(fileName.isNull()) { if(fileName.isNull()) {
if(player()->paused()) if(player()->paused())
player()->play(); player()->play();
if(player()->playing()) else if(player()->playing())
player()->seekPosition(0); player()->seekPosition(0);
else else {
player()->play(m_playlistInterface->nextFile()); QString file = m_playlistInterface->currentFile();
if(!file.isNull())
player()->play(file);
}
} }
else { else
if(player()->paused())
player()->stop();
player()->play(fileName); player()->play(fileName);
}
// Make sure that the player() actually starts before doing anything. // Make sure that the player() actually starts before doing anything.
...@@ -226,6 +226,24 @@ void PlayerManager::seekPosition(int position) ...@@ -226,6 +226,24 @@ void PlayerManager::seekPosition(int position)
player()->seekPosition(position); player()->seekPosition(position);
} }
void PlayerManager::forward()
{
QString file = m_playlistInterface->nextFile();
if(!file.isNull())
play(file);
else
stop();
}
void PlayerManager::back()
{
QString file = m_playlistInterface->previousFile();
if(!file.isNull())
play(file);
else
stop();
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// private slots // private slots
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
...@@ -239,7 +257,11 @@ void PlayerManager::slotPollPlay() ...@@ -239,7 +257,11 @@ void PlayerManager::slotPollPlay()
if(!player()->playing()) { if(!player()->playing()) {
m_timer->stop(); m_timer->stop();
play(m_playlistInterface->nextFile()); QString nextFile = m_playlistInterface->nextFile();
if(!nextFile.isNull())
play();
else
stop();
} }
else if(!m_sliderAction->dragging()) { else if(!m_sliderAction->dragging()) {
m_sliderAction->trackPositionSlider()->setValue(player()->position()); m_sliderAction->trackPositionSlider()->setValue(player()->position());
......
...@@ -35,6 +35,7 @@ class PlaylistInterface ...@@ -35,6 +35,7 @@ class PlaylistInterface
{ {
public: public:
virtual QString nextFile() = 0; virtual QString nextFile() = 0;
virtual QString currentFile() = 0;
virtual QString previousFile() = 0; virtual QString previousFile() = 0;
}; };
...@@ -73,6 +74,9 @@ public slots: ...@@ -73,6 +74,9 @@ public slots:
virtual void seek(long seekTime); virtual void seek(long seekTime);
virtual void seekPosition(int position); virtual void seekPosition(int position);
void forward();
void back();
void slotSetVolume(int volume); // TODO: make private void slotSetVolume(int volume); // TODO: make private
private: private:
......
...@@ -386,12 +386,12 @@ PlaylistItemList Playlist::historyItems(PlaylistItem *current, bool random) cons ...@@ -386,12 +386,12 @@ PlaylistItemList Playlist::historyItems(PlaylistItem *current, bool random) cons
PlaylistItem *Playlist::nextItem(PlaylistItem *current, bool random) PlaylistItem *Playlist::nextItem(PlaylistItem *current, bool random)
{ {
PlaylistItem *i; PlaylistItem *i = 0;
if(random) { if(random) {
if(m_randomList.count() <= 1 || m_visibleChanged) { if(m_randomList.count() <= 1 || m_visibleChanged) {
m_randomList = visibleItems(); m_randomList = visibleItems();
m_visibleChanged = false; // got the change m_visibleChanged = false;
} }
if(current) { if(current) {
...@@ -407,6 +407,7 @@ PlaylistItem *Playlist::nextItem(PlaylistItem *current, bool random) ...@@ -407,6 +407,7 @@ PlaylistItem *Playlist::nextItem(PlaylistItem *current, bool random)
} }
else { else {
m_history.clear(); m_history.clear();
if(current) if(current)
i = static_cast<PlaylistItem *>(current->itemBelow()); i = static_cast<PlaylistItem *>(current->itemBelow());
else { else {
......
...@@ -170,6 +170,11 @@ void PlaylistItem::guessTagInfo(TagGuesser::Type type) ...@@ -170,6 +170,11 @@ void PlaylistItem::guessTagInfo(TagGuesser::Type type)
} }
} }
Playlist *PlaylistItem::playlist() const
{
return static_cast<Playlist *>(listView());
}
QValueVector<int> PlaylistItem::cachedWidths() const QValueVector<int> PlaylistItem::cachedWidths() const
{ {
return m_data->cachedWidths(); return m_data->cachedWidths();
......
...@@ -98,8 +98,8 @@ public: ...@@ -98,8 +98,8 @@ public:
void setPlaying(bool playing = true) { m_playing = playing; } void setPlaying(bool playing = true) { m_playing = playing; }
virtual void setSelected(bool selected); virtual void setSelected(bool selected);
void guessTagInfo(TagGuesser::Type type); void guessTagInfo(TagGuesser::Type type);
Playlist *playlist() const;
/** /**
* The widths of items are cached when they're updated for us in computations * The widths of items are cached when they're updated for us in computations
......
...@@ -161,6 +161,51 @@ QString PlaylistSplitter::uniquePlaylistName(const QString &startingWith, bool u ...@@ -161,6 +161,51 @@ QString PlaylistSplitter::uniquePlaylistName(const QString &startingWith, bool u
} }
} }
QString PlaylistSplitter::nextFile()
{
PlaylistItem *i = 0;
if(m_nextPlaylistItem && m_nextPlaylistItem != m_playingItem) {
i = m_nextPlaylistItem;
m_nextPlaylistItem = 0;
}
else if(m_playingItem) {
i = m_playingItem->playlist()->nextItem(m_playingItem);
// TODO: check to see if we're in loop / random mode
}
return play(i);
}
QString PlaylistSplitter::currentFile()
{
PlaylistItem *i = 0;
const bool random = false; // TODO: should check this
if(m_nextPlaylistItem && m_nextPlaylistItem != m_playingItem) {
i = m_nextPlaylistItem;
m_nextPlaylistItem = 0;
}
// Play the selected item.
else if(playlistSelection().size() > 0) {
i = playlistSelection().first();
if(!i)
i = m_playingItem->playlist()->nextItem(0, random);
}
// Play the first item in the list.
else {
kdDebug(65432) << k_funcinfo << "Playing the first item in the current list." << endl;
i = visiblePlaylist()->nextItem(0, random);
}
return play(i);
}
QString PlaylistSplitter::playNextFile(bool random, bool loopPlaylist) QString PlaylistSplitter::playNextFile(bool random, bool loopPlaylist)
{ {
PlaylistItem *i; PlaylistItem *i;
...@@ -171,12 +216,14 @@ QString PlaylistSplitter::playNextFile(bool random, bool loopPlaylist) ...@@ -171,12 +216,14 @@ QString PlaylistSplitter::playNextFile(bool random, bool loopPlaylist)
// (1) we've asked for a specific next item // (1) we've asked for a specific next item
if(m_nextPlaylistItem && m_nextPlaylistItem != m_playingItem) { if(m_nextPlaylistItem && m_nextPlaylistItem != m_playingItem) {
kdDebug(65432) << k_funcinfo << "Playing the requested 'next' item." << endl;
i = m_nextPlaylistItem; i = m_nextPlaylistItem;
m_nextPlaylistItem = 0; m_nextPlaylistItem = 0;
} }
// (2) play the item after the currently selected item // (2) play the item after the currently selected item
else if(m_playingItem) { else if(m_playingItem) {
Playlist *p = static_cast<Playlist *>(m_playingItem->listView()); Playlist *p = m_playingItem->playlist();
i = p->nextItem(m_playingItem, random); i = p->nextItem(m_playingItem, random);
if(!i && loopPlaylist) { if(!i && loopPlaylist) {
PlaylistItemList visibleItems = p->visibleItems(); PlaylistItemList visibleItems = p->visibleItems();
...@@ -187,8 +234,9 @@ QString PlaylistSplitter::playNextFile(bool random, bool loopPlaylist) ...@@ -187,8 +234,9 @@ QString PlaylistSplitter::playNextFile(bool random, bool loopPlaylist)
else if(playlistSelection().size() > 0) { else if(playlistSelection().size() > 0) {
i = playlistSelection().first(); i = playlistSelection().first();
if(!i) if(!i)
i = static_cast<Playlist *>(m_playingItem->listView())->nextItem(0, random); i = m_playingItem->playlist()->nextItem(0, random);
} }
// (4) Play the first item in the list.
else else
i = visiblePlaylist()->nextItem(0, random); i = visiblePlaylist()->nextItem(0, random);
...@@ -200,15 +248,15 @@ QString PlaylistSplitter::playPreviousFile(bool random) ...@@ -200,15 +248,15 @@ QString PlaylistSplitter::playPreviousFile(bool random)
if(!m_playingItem) if(!m_playingItem)
return QString::null; return QString::null;
Playlist *p = static_cast<Playlist *>(m_playingItem->listView()); Playlist *p = m_playingItem->playlist();
PlaylistItem *i = p->previousItem(m_playingItem, random); PlaylistItem *i = p->previousItem(m_playingItem, random);
return play(i); return play(i);
} }
void PlaylistSplitter::populatePlayHistoryMenu(QPopupMenu* menu, bool random) void PlaylistSplitter::populatePlayHistoryMenu(QPopupMenu *menu, bool random)
{ {
Playlist *p = static_cast<Playlist *>(m_playingItem->listView()); Playlist *p = m_playingItem->playlist();
PlaylistItemList list = p->historyItems(m_playingItem, random); PlaylistItemList list = p->historyItems(m_playingItem, random);
menu->clear(); menu->clear();
int i = 0; int i = 0;
...@@ -248,7 +296,7 @@ void PlaylistSplitter::stop() ...@@ -248,7 +296,7 @@ void PlaylistSplitter::stop()
if(!m_playingItem) if(!m_playingItem)
return; return;
Playlist *p = static_cast<Playlist *>(m_playingItem->listView()); Playlist *p = m_playingItem->playlist();
if(p) if(p)
p->setPlaying(m_playingItem, false); p->setPlaying(m_playingItem, false);
...@@ -259,7 +307,7 @@ void PlaylistSplitter::stop() ...@@ -259,7 +307,7 @@ void PlaylistSplitter::stop()
QString PlaylistSplitter::playingArtist() const QString PlaylistSplitter::playingArtist() const
{ {
if(m_playingItem) { if(m_playingItem) {
int offset = static_cast<Playlist *>(m_playingItem->listView())->columnOffset(); int offset = m_playingItem->playlist()->columnOffset();
return m_playingItem->text(PlaylistItem::ArtistColumn + offset); return m_playingItem->text(PlaylistItem::ArtistColumn + offset);
} }
else else
...@@ -269,7 +317,7 @@ QString PlaylistSplitter::playingArtist() const ...@@ -269,7 +317,7 @@ QString PlaylistSplitter::playingArtist() const
QString PlaylistSplitter::playingTrack() const QString PlaylistSplitter::playingTrack() const
{ {
if(m_playingItem) { if(m_playingItem) {
int offset = static_cast<Playlist *>(m_playingItem->listView())->columnOffset(); int offset = m_playingItem->playlist()->columnOffset();
return m_playingItem->text(PlaylistItem::TrackColumn + offset); return m_playingItem->text(PlaylistItem::TrackColumn + offset);
} }
else else
...@@ -279,7 +327,7 @@ QString PlaylistSplitter::playingTrack() const ...@@ -279,7 +327,7 @@ QString PlaylistSplitter::playingTrack() const
QString PlaylistSplitter::playingList() const QString PlaylistSplitter::playingList() const
{ {
if(m_playingItem) if(m_playingItem)
return static_cast<Playlist *>(m_playingItem->listView())->name(); return m_playingItem->playlist()->name();
else else
return QString::null; return QString::null;
} }
...@@ -398,7 +446,7 @@ void PlaylistSplitter::slotSelectPlaying() ...@@ -398,7 +446,7 @@ void PlaylistSplitter::slotSelectPlaying()
if(!m_playingItem) if(!m_playingItem)
return; return;
Playlist *l = static_cast<Playlist *>(m_playingItem->listView()); Playlist *l = m_playingItem->playlist();
if(!l) if(!l)
return; return;
...@@ -731,10 +779,12 @@ QString PlaylistSplitter::play(PlaylistItem *item) ...@@ -731,10 +779,12 @@ QString PlaylistSplitter::play(PlaylistItem *item)
{ {
stop(); stop();
if(!item) if(!item) {
kdDebug(65432) << k_funcinfo << "The current item is null." << endl;
return QString::null; return QString::null;
}
Playlist *p = static_cast<Playlist *>(item->listView()); Playlist *p = item->playlist();
if(!p) if(!p)
return QString::null; return QString::null;
......
...@@ -71,6 +71,10 @@ public: ...@@ -71,6 +71,10 @@ public:
// Variations on the theme "play stuff" // Variations on the theme "play stuff"
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
virtual QString nextFile();
virtual QString currentFile();
virtual QString previousFile() { return playPreviousFile(); }
/** /**
* Returns the file name of the next item to be played and advances the next * Returns the file name of the next item to be played and advances the next
* file. * file.
...@@ -83,9 +87,6 @@ public: ...@@ -83,9 +87,6 @@ public:
*/ */
QString playPreviousFile(bool random = false); QString playPreviousFile(bool random = false);
QString nextFile() { return playNextFile(); }
QString previousFile() { return playPreviousFile(); }
/** /**
* Fills the menu passed in with the recently played history * Fills the menu passed in with the recently played history
*/ */
......
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