Commit c0575937 authored by Scott Wheeler's avatar Scott Wheeler

Ported PlaylistInterface over to using FileHandle instead of QStrings for

its references to files.

Removed several unused methods from the PlaylistSplitter class.

svn path=/trunk/kdemultimedia/juk/; revision=302272
parent 98968eb8
......@@ -186,10 +186,7 @@ void PlayerManager::play(const FileHandle &file)
player()->seekPosition(0);
}
else {
// TODO: currentFile() really should return a FileHanlde as such
// making the cast below not needed.
FileHandle currentFile = FileHandle(m_playlistInterface->currentFile());
FileHandle currentFile = m_playlistInterface->currentFile();
if(!currentFile.isNull()) {
player()->play(currentFile);
......@@ -303,9 +300,7 @@ void PlayerManager::playPause()
void PlayerManager::forward()
{
// TODO: nextFile() should return a FileHandle
FileHandle file = FileHandle(m_playlistInterface->nextFile());
FileHandle file = m_playlistInterface->nextFile();
if(!file.isNull())
play(file);
......@@ -315,9 +310,7 @@ void PlayerManager::forward()
void PlayerManager::back()
{
// TODO: previousFile() should return a FileHandle
FileHandle file = FileHandle(m_playlistInterface->previousFile());
FileHandle file = m_playlistInterface->previousFile();
if(!file.isNull())
play(file);
......@@ -372,9 +365,7 @@ void PlayerManager::slotPollPlay()
if(!player()->playing()) {
m_timer->stop();
// TODO: nextFile() should use FileHandle
FileHandle nextFile = FileHandle(m_playlistInterface->nextFile());
FileHandle nextFile = m_playlistInterface->nextFile();
if(!nextFile.isNull())
play(nextFile);
else
......
......@@ -370,7 +370,7 @@ PlaylistItemList Playlist::historyItems(PlaylistItem *current, bool random) cons
for(; it != m_history.begin() && j < 10; --it, ++j)
list.append(*it);
if (j < 10)
if(j < 10)
list.append(*it);
}
else if(current) {
......
......@@ -28,9 +28,9 @@ class PlaylistInterface
{
public:
virtual QString name() const = 0;
virtual QString nextFile() = 0;
virtual QString currentFile() = 0;
virtual QString previousFile() = 0;
virtual FileHandle nextFile() = 0;
virtual FileHandle currentFile() = 0;
virtual FileHandle previousFile() = 0;
};
#endif
......@@ -172,7 +172,7 @@ QString PlaylistSplitter::name() const
return m_playingItem ? m_playingItem->playlist()->name() : QString::null;
}
QString PlaylistSplitter::nextFile()
FileHandle PlaylistSplitter::nextFile()
{
PlaylistItem *i = 0;
......@@ -194,12 +194,14 @@ QString PlaylistSplitter::nextFile()
return play(i);
}
QString PlaylistSplitter::currentFile()
FileHandle PlaylistSplitter::currentFile()
{
PlaylistItem *i = 0;
bool random = action("randomPlay") && action<KToggleAction>("randomPlay")->isChecked();
PlaylistItemList selection = playlistSelection();
if(m_nextPlaylistItem && m_nextPlaylistItem != m_playingItem) {
i = m_nextPlaylistItem;
m_nextPlaylistItem = 0;
......@@ -207,8 +209,8 @@ QString PlaylistSplitter::currentFile()
// Play the selected item.
else if(playlistSelection().size() > 0) {
i = playlistSelection().first();
else if(!selection.isEmpty()) {
i = selection.first();
if(!i)
i = m_playingItem->playlist()->nextItem(0, random);
}
......@@ -223,50 +225,13 @@ QString PlaylistSplitter::currentFile()
return play(i);
}
QString PlaylistSplitter::playNextFile(bool random, bool loopPlaylist)
{
PlaylistItem *i;
// Four basic cases here: (1) We've asked for a specific next item, (2) play
// the item that's after the currently playing item, (3) play the selected
// item or (4) play the first item in the list.
// (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 = m_playingItem->playlist();
i = p->nextItem(m_playingItem, random);
if(!i && loopPlaylist) {
PlaylistItemList visibleItems = p->visibleItems();
i = visibleItems.isEmpty() ? 0 : visibleItems.front();
}
}
// (3) play the selected item
else if(playlistSelection().size() > 0) {
i = playlistSelection().first();
if(!i)
i = m_playingItem->playlist()->nextItem(0, random);
}
// (4) Play the first item in the list.
else
i = visiblePlaylist()->nextItem(0, random);
return play(i);
}
QString PlaylistSplitter::playPreviousFile(bool random)
FileHandle PlaylistSplitter::previousFile()
{
if(!m_playingItem)
return QString::null;
return FileHandle::null();
Playlist *p = m_playingItem->playlist();
PlaylistItem *i = p->previousItem(m_playingItem, random);
PlaylistItem *i = p->previousItem(m_playingItem, false);
return play(i);
}
......@@ -281,31 +246,6 @@ void PlaylistSplitter::populatePlayHistoryMenu(QPopupMenu *menu, bool random)
menu->insertItem((*it)->file().tag()->title(), ++i);
}
QString PlaylistSplitter::playSelectedFile()
{
if(playlistSelection().isEmpty())
return QString::null;
else
return play(playlistSelection().first());
}
QString PlaylistSplitter::playFirstFile()
{
Playlist *p = visiblePlaylist();
PlaylistItem *i = static_cast<PlaylistItem *>(p->firstChild());
return play(i);
}
QString PlaylistSplitter::playRandomFile()
{
Playlist *p = visiblePlaylist();
PlaylistItem *i = static_cast<PlaylistItem *>(p->firstChild());
// Not exactly random (the first item won't be taken into account)
return play(p->nextItem(i, true));
}
void PlaylistSplitter::open(const QString &file)
{
if(file.isEmpty())
......@@ -758,19 +698,19 @@ Playlist *PlaylistSplitter::openPlaylist(const QString &file)
return p;
}
QString PlaylistSplitter::play(PlaylistItem *item)
FileHandle PlaylistSplitter::play(PlaylistItem *item)
{
stop();
if(!item) {
kdDebug(65432) << k_funcinfo << "The current item is null." << endl;
return QString::null;
return FileHandle::null();
}
Playlist *p = item->playlist();
if(!p)
return QString::null;
return FileHandle::null();
p->setPlaying(item, true);
......@@ -782,7 +722,7 @@ QString PlaylistSplitter::play(PlaylistItem *item)
m_history->createItems(l);
}
return item->file().absFilePath();
return item->file();
}
void PlaylistSplitter::redisplaySearch()
......
......@@ -57,59 +57,19 @@ public:
* the format "[startingWith] i" where "i" is the first integer greater than
* 0 that does not currently exist in the PlaylistBox.
*/
QString uniquePlaylistName(const QString &startingWith, bool useParentheses = false);
/* This calls the above method with startingWith == i18n("Playlist") to
* produce "Playlist 1", "Playlist 2", ...
*/
QString uniquePlaylistName() { return uniquePlaylistName(i18n("Playlist")); }
////////////////////////////////////////////////////////////////////////////
// Variations on the theme "play stuff"
////////////////////////////////////////////////////////////////////////////
QString uniquePlaylistName(const QString &startingWith = i18n("Playlist"),
bool useParentheses = false);
virtual QString name() const;
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.
*/
QString playNextFile(bool random = false, bool loopPlaylist = false);
/**
* Returns the file name of the previous item and moves the playing indicator
* to the previous file.
*/
QString playPreviousFile(bool random = false);
virtual FileHandle nextFile();
virtual FileHandle currentFile();
virtual FileHandle previousFile();
/**
* Fills the menu passed in with the recently played history
*/
void populatePlayHistoryMenu(QPopupMenu *menu, bool random);
/**
* Returns the name of the currently selected file and moves the playing
* indicator to that file.
*/
QString playSelectedFile();
/**
* Returns the name of the first item in the playlist and moves the playing
* indicator to that file.
*/
QString playFirstFile();
/**
* Plays a random file in the currently visible playlist and returns it's
* name.
*/
QString playRandomFile();
////////////////////////////////////////////////////////////////////////////
/**
* Returns the name of the currently visible playlist.
*/
......@@ -171,8 +131,6 @@ public:
public slots:
// File slots
/**
* Open files or playlists.
*/
......@@ -184,14 +142,10 @@ public slots:
*/
void slotOpenDirectory();
// Tagger slots
void slotSaveTag() { m_editor->save(); }
void slotGuessTagInfo(TagGuesser::Type type);
void slotRenameFile();
// Playlist slots
/**
* Create a playlist and prompt the user for a name if no name was
* specified.
......@@ -210,8 +164,6 @@ public slots:
*/
void slotSelectPlaying();
// Other slots
/**
* Deletes the selected items from the hard disk.
*/
......@@ -258,8 +210,6 @@ public slots:
*/
void slotAddToPlaylist(const QStringList &files, Playlist *list, PlaylistItem *after = 0);
// PlaylistBox forwarding slots
void slotSavePlaylist() { m_playlistBox->save(); }
void slotSaveAsPlaylist() { m_playlistBox->saveAs(); }
void slotRenamePlaylist() { m_playlistBox->rename(); }
......@@ -320,7 +270,7 @@ private:
* A convenience function that sets the playing icon, sets the playing item
* and then returns the name of the file.
*/
QString play(PlaylistItem *item);
FileHandle play(PlaylistItem *item);
/**
* This should be called to update the shown items -- it does not restart the
......
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