Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 0fde937c authored by Aaron J. Seigo's avatar Aaron J. Seigo

make the back button a drop down showing the last items played for easy

skipping into the past... the only oddity is that when switching between
random and non-random playing you lose the history...

svn path=/trunk/kdemultimedia/juk/; revision=223891
parent 60265d7c
......@@ -132,7 +132,9 @@ void JuK::setupActions()
m_playAction = new KAction(i18n("&Play"), "player_play", 0, this, SLOT(play()), actionCollection(), "play");
m_pauseAction = new KAction(i18n("P&ause"), "player_pause", 0, this, SLOT(pause()), actionCollection(), "pause");
m_stopAction = new KAction(i18n("&Stop"), "player_stop", 0, this, SLOT(stop()), actionCollection(), "stop");
m_backAction = new KAction(i18n("Skip &Back"), "player_start", 0, this, SLOT(back()), actionCollection(), "back");
m_backAction = new KToolBarPopupAction(i18n("Skip &Back"), "player_start", 0, this, SLOT(back()), actionCollection(), "back");
connect(m_backAction->popupMenu(), SIGNAL(aboutToShow()), this, SLOT(slotPopulateBackMenu()));
connect(m_backAction->popupMenu(), SIGNAL(activated(int)), this, SLOT(back(int)));
m_forwardAction = new KAction(i18n("Skip &Forward"), "player_end", 0, this, SLOT(forward()), actionCollection(), "forward");
m_loopPlaylistAction = new KToggleAction(i18n("&Loop Playlist"), 0, 0, actionCollection(), "loopPlaylist");
......@@ -589,6 +591,21 @@ void JuK::back()
play(m_splitter->playPreviousFile(m_randomPlayAction->isChecked()));
}
void JuK::back(int howMany)
{
for (--howMany; howMany > 0; --howMany)
{
m_splitter->playPreviousFile(m_randomPlayAction->isChecked());
}
play(m_splitter->playPreviousFile(m_randomPlayAction->isChecked()));
}
void JuK::slotPopulateBackMenu()
{
m_splitter->populatePlayHistoryMenu(m_backAction->popupMenu(), m_randomPlayAction->isChecked());
}
void JuK::forward()
{
play(m_splitter->playNextFile(m_randomPlayAction->isChecked(), m_loopPlaylistAction->isChecked()));
......
......@@ -27,6 +27,7 @@
#include <kstdaction.h>
#include <kmainwindow.h>
#include <kmenubar.h>
#include <kpopupmenu.h>
#include <qlabel.h>
......@@ -106,6 +107,8 @@ private slots:
void pause();
void stop();
void back();
void back(int howMany);
void slotPopulateBackMenu();
void forward();
void seekBack();
void seekForward();
......@@ -163,7 +166,7 @@ private:
KAction *m_playAction;
KAction *m_pauseAction;
KAction *m_stopAction;
KAction *m_backAction;
KToolBarPopupAction *m_backAction;
KAction *m_forwardAction;
KToggleAction *m_loopPlaylistAction;
......
......@@ -317,6 +317,29 @@ PlaylistItemList Playlist::selectedItems() const
return list;
}
PlaylistItemList Playlist::historyItems(PlaylistItem *current, bool random) const
{
PlaylistItemList list;
if (random)
{
QPtrListIterator<PlaylistItem> it(m_history);
it.toLast();
for (int j = 0; it.current() && j < 10; --it, ++j)
list.append(it.current());
}
else if (current)
{
current = static_cast<PlaylistItem *>(current->itemAbove());
for (int j = 0;
current && j < 10;
++j, current = static_cast<PlaylistItem *>(current->itemAbove()))
list.append(current);
}
return list;
}
PlaylistItem *Playlist::nextItem(PlaylistItem *current, bool random)
{
if(!current)
......@@ -332,7 +355,7 @@ PlaylistItem *Playlist::nextItem(PlaylistItem *current, bool random)
m_randomList.remove(current);
m_history.push(current);
m_history.append(current);
i = current;
while(i == current) {
......@@ -340,7 +363,10 @@ PlaylistItem *Playlist::nextItem(PlaylistItem *current, bool random)
}
}
else
{
m_history.clear();
i = static_cast<PlaylistItem *>(current->itemBelow());
}
return i;
}
......@@ -350,13 +376,15 @@ PlaylistItem *Playlist::previousItem(PlaylistItem *current, bool random)
if(!current)
return 0;
if(random && !m_history.isEmpty()) {
PlaylistItem * item = m_history.pop();
if(random && !m_history.isEmpty())
{
PlaylistItem * item = m_history.take(m_history.count() - 1);
//should we add it to the random list ?
//m_randomList.append(item);
return item;
}
m_history.clear();
if(!current->itemAbove())
return current;
......
......@@ -86,6 +86,11 @@ public:
*/
PlaylistItemList selectedItems() const;
/**
* Returns a list of the last 10 played items.
*/
PlaylistItemList historyItems(PlaylistItem *current, bool random) const;
/**
* Allow duplicate files in the playlist.
*/
......@@ -249,7 +254,7 @@ private:
SortedStringList m_members;
int m_processed;
bool m_allowDuplicates;
QPtrStack<PlaylistItem> m_history;
QPtrList<PlaylistItem> m_history;
QString m_fileName;
......
......@@ -45,6 +45,7 @@ class PlaylistItem : public QObject, public KListViewItem
{
friend class Playlist;
friend class CollectionList;
friend class QPtrList<PlaylistItem>;
/**
* Needs access to the destuctor, even though the destructor isn't used by QPtrStack.
......
......@@ -20,6 +20,7 @@
#include <klineeditdlg.h>
#include <kdebug.h>
#include <qpopupmenu.h>
#include "playlistsplitter.h"
#include "directorylist.h"
......@@ -141,6 +142,18 @@ QString PlaylistSplitter::playPreviousFile(bool random)
return play(i);
}
void PlaylistSplitter::populatePlayHistoryMenu(QPopupMenu* menu, bool random)
{
Playlist *p = static_cast<Playlist *>(m_playingItem->listView());
PlaylistItemList list = p->historyItems(m_playingItem, random);
menu->clear();
int i = 0;
for (PlaylistItemList::iterator it = list.begin(); it != list.end(); ++it)
{
menu->insertItem((*it)->tag()->track(), ++i);
}
}
QString PlaylistSplitter::playSelectedFile()
{
if(playlistSelection().isEmpty())
......
......@@ -81,6 +81,11 @@ public:
*/
QString playPreviousFile(bool random = false);
/**
* 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.
......
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