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()
void JuK::forward()
{
play(m_splitter->playNextFile(m_randomPlayAction->isChecked(),
m_loopPlaylistAction->isChecked()));
m_player->forward();
}
void JuK::seekBack()
......
......@@ -133,16 +133,16 @@ void PlayerManager::play(const QString &fileName)
if(fileName.isNull()) {
if(player()->paused())
player()->play();
if(player()->playing())
else if(player()->playing())
player()->seekPosition(0);
else
player()->play(m_playlistInterface->nextFile());
else {
QString file = m_playlistInterface->currentFile();
if(!file.isNull())
player()->play(file);
}
}
else {
if(player()->paused())
player()->stop();
else
player()->play(fileName);
}
// Make sure that the player() actually starts before doing anything.
......@@ -226,6 +226,24 @@ void PlayerManager::seekPosition(int 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
////////////////////////////////////////////////////////////////////////////////
......@@ -239,7 +257,11 @@ void PlayerManager::slotPollPlay()
if(!player()->playing()) {
m_timer->stop();
play(m_playlistInterface->nextFile());
QString nextFile = m_playlistInterface->nextFile();
if(!nextFile.isNull())
play();
else
stop();
}
else if(!m_sliderAction->dragging()) {
m_sliderAction->trackPositionSlider()->setValue(player()->position());
......
......@@ -35,6 +35,7 @@ class PlaylistInterface
{
public:
virtual QString nextFile() = 0;
virtual QString currentFile() = 0;
virtual QString previousFile() = 0;
};
......@@ -73,6 +74,9 @@ public slots:
virtual void seek(long seekTime);
virtual void seekPosition(int position);
void forward();
void back();
void slotSetVolume(int volume); // TODO: make private
private:
......
......@@ -386,12 +386,12 @@ PlaylistItemList Playlist::historyItems(PlaylistItem *current, bool random) cons
PlaylistItem *Playlist::nextItem(PlaylistItem *current, bool random)
{
PlaylistItem *i;
PlaylistItem *i = 0;
if(random) {
if(m_randomList.count() <= 1 || m_visibleChanged) {
m_randomList = visibleItems();
m_visibleChanged = false; // got the change
m_visibleChanged = false;
}
if(current) {
......@@ -407,6 +407,7 @@ PlaylistItem *Playlist::nextItem(PlaylistItem *current, bool random)
}
else {
m_history.clear();
if(current)
i = static_cast<PlaylistItem *>(current->itemBelow());
else {
......
......@@ -170,6 +170,11 @@ void PlaylistItem::guessTagInfo(TagGuesser::Type type)
}
}
Playlist *PlaylistItem::playlist() const
{
return static_cast<Playlist *>(listView());
}
QValueVector<int> PlaylistItem::cachedWidths() const
{
return m_data->cachedWidths();
......
......@@ -98,8 +98,8 @@ public:
void setPlaying(bool playing = true) { m_playing = playing; }
virtual void setSelected(bool selected);
void guessTagInfo(TagGuesser::Type type);
Playlist *playlist() const;
/**
* 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
}
}
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)
{
PlaylistItem *i;
......@@ -171,12 +216,14 @@ QString PlaylistSplitter::playNextFile(bool random, bool loopPlaylist)
// (1) we've asked for a specific next item
if(m_nextPlaylistItem && m_nextPlaylistItem != m_playingItem) {
kdDebug(65432) << k_funcinfo << "Playing the requested 'next' item." << endl;
i = m_nextPlaylistItem;
m_nextPlaylistItem = 0;
}
// (2) play the item after the currently selected item
else if(m_playingItem) {
Playlist *p = static_cast<Playlist *>(m_playingItem->listView());
Playlist *p = m_playingItem->playlist();
i = p->nextItem(m_playingItem, random);
if(!i && loopPlaylist) {
PlaylistItemList visibleItems = p->visibleItems();
......@@ -187,8 +234,9 @@ QString PlaylistSplitter::playNextFile(bool random, bool loopPlaylist)
else if(playlistSelection().size() > 0) {
i = playlistSelection().first();
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
i = visiblePlaylist()->nextItem(0, random);
......@@ -200,15 +248,15 @@ QString PlaylistSplitter::playPreviousFile(bool random)
if(!m_playingItem)
return QString::null;
Playlist *p = static_cast<Playlist *>(m_playingItem->listView());
Playlist *p = m_playingItem->playlist();
PlaylistItem *i = p->previousItem(m_playingItem, random);
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);
menu->clear();
int i = 0;
......@@ -248,7 +296,7 @@ void PlaylistSplitter::stop()
if(!m_playingItem)
return;
Playlist *p = static_cast<Playlist *>(m_playingItem->listView());
Playlist *p = m_playingItem->playlist();
if(p)
p->setPlaying(m_playingItem, false);
......@@ -259,7 +307,7 @@ void PlaylistSplitter::stop()
QString PlaylistSplitter::playingArtist() const
{
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);
}
else
......@@ -269,7 +317,7 @@ QString PlaylistSplitter::playingArtist() const
QString PlaylistSplitter::playingTrack() const
{
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);
}
else
......@@ -279,7 +327,7 @@ QString PlaylistSplitter::playingTrack() const
QString PlaylistSplitter::playingList() const
{
if(m_playingItem)
return static_cast<Playlist *>(m_playingItem->listView())->name();
return m_playingItem->playlist()->name();
else
return QString::null;
}
......@@ -398,7 +446,7 @@ void PlaylistSplitter::slotSelectPlaying()
if(!m_playingItem)
return;
Playlist *l = static_cast<Playlist *>(m_playingItem->listView());
Playlist *l = m_playingItem->playlist();
if(!l)
return;
......@@ -731,10 +779,12 @@ QString PlaylistSplitter::play(PlaylistItem *item)
{
stop();
if(!item)
if(!item) {
kdDebug(65432) << k_funcinfo << "The current item is null." << endl;
return QString::null;
}
Playlist *p = static_cast<Playlist *>(item->listView());
Playlist *p = item->playlist();
if(!p)
return QString::null;
......
......@@ -71,6 +71,10 @@ public:
// 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
* file.
......@@ -83,9 +87,6 @@ public:
*/
QString playPreviousFile(bool random = false);
QString nextFile() { return playNextFile(); }
QString previousFile() { return playPreviousFile(); }
/**
* 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