Commit c6a02f84 authored by Scott Wheeler's avatar Scott Wheeler

Forgot to commit this earlier...make the back popup menu work again.

svn path=/trunk/kdemultimedia/juk/; revision=322587
parent e4793ba3
......@@ -153,6 +153,11 @@ CollectionList::CollectionList(PlaylistCollection *collection) :
connect(action("showPlaying"), SIGNAL(activated()), this, SLOT(slotShowPlaying()));
m_dirWatch->startScan();
connect(action<KToolBarPopupAction>("back")->popupMenu(), SIGNAL(aboutToShow()),
this, SLOT(slotPopulateBackMenu()));
connect(action<KToolBarPopupAction>("back")->popupMenu(), SIGNAL(activated(int)),
this, SLOT(slotPlayFromBackMenu(int)));
KConfigGroup config(KGlobal::config(), "Playlists");
setSortColumn(config.readNumEntry("CollectionListSortColumn", 1));
......
......@@ -104,8 +104,8 @@ void JuK::setupActions()
KStdAction::clear(kapp, SLOT(clear()), actions());
KStdAction::selectAll(kapp, SLOT(selectAll()), actions());
m_showHistoryAction = new KToggleAction(i18n("Show &History"), "history", 0, actions(), "showHistory");
m_randomPlayAction = new KToggleAction(i18n("&Random Play"), 0, actions(), "randomPlay");
m_showHistoryAction = new KToggleAction(i18n("Show &History"), "history", 0, actions(), "showHistory");
m_randomPlayAction = new KToggleAction(i18n("&Random Play"), 0, actions(), "randomPlay");
m_showHistoryAction->setCheckedState(i18n("Hide &History"));
......@@ -113,14 +113,9 @@ void JuK::setupActions()
new KAction(i18n("P&ause"), "player_pause", 0, m_player, SLOT(pause()), actions(), "pause");
new KAction(i18n("&Stop"), "player_stop", 0, m_player, SLOT(stop()), actions(), "stop");
// m_backAction = new KToolBarPopupAction(i18n("Previous &Track"), "player_start", 0,
// this, SLOT(back()), actions(), "back");
// TODO: switch this back to being a popup action
new KAction(i18n("Previous &Track"), "player_start", 0, m_player, SLOT(back()), actions(), "back");
new KAction(i18n("&Next Track"), "player_end", 0, m_player, SLOT(forward()), actions(), "forward");
new KToggleAction(i18n("&Loop Playlist"), 0, 0, actions(), "loopPlaylist");
new KToolBarPopupAction(i18n("Previous &Track"), "player_start", KShortcut(), m_player, SLOT(back()), actions(), "back");
new KAction(i18n("&Next Track"), "player_end", KShortcut(), m_player, SLOT(forward()), actions(), "forward");
new KToggleAction(i18n("&Loop Playlist"), 0, KShortcut(), actions(), "loopPlaylist");
// the following are not visible by default
......
......@@ -263,8 +263,10 @@ void Playlist::SharedSettings::writeConfig()
PlaylistItem *Playlist::m_playingItem = 0;
PlaylistItem *Playlist::m_playNextItem = 0;
QMap<int, PlaylistItem *> Playlist::m_backMenuItems;
int Playlist::m_leftColumn = 0;
Playlist::Playlist(PlaylistCollection *collection, const QString &name,
const QString &iconName) :
KListView(collection->playlistStack(), name.latin1()),
......@@ -389,8 +391,7 @@ void Playlist::playFirst()
m_playNextItem = static_cast<PlaylistItem*>(QListViewItemIterator(
this, QListViewItemIterator::Visible).current());
action("stop")->activate();
action("play")->activate();
action("forward")->activate();
}
void Playlist::playNext()
......@@ -443,6 +444,7 @@ void Playlist::playNext()
void Playlist::stop()
{
m_history.clear();
setPlaying(0);
}
......@@ -572,32 +574,6 @@ PlaylistItemList Playlist::selectedItems()
return list;
}
PlaylistItemList Playlist::historyItems(PlaylistItem *current, bool random) const
{
PlaylistItemList list;
if (random && !m_history.isEmpty()) {
PlaylistItemList::ConstIterator it = m_history.end();
--it;
int j = 0;
for(; it != m_history.begin() && j < 10; --it, ++j)
list.append(*it);
if(j < 10)
list.append(*it);
}
else if(current) {
current = static_cast<PlaylistItem *>(current->itemAbove());
for(int j = 0; current && j < 10; ++j) {
list.append(current);
current = static_cast<PlaylistItem *>(current->itemAbove());
}
}
return list;
}
void Playlist::updateLeftColumn()
{
int newLeftColumn = leftMostVisibleColumn();
......@@ -1192,6 +1168,39 @@ void Playlist::setupItem(PlaylistItem *item)
}
}
////////////////////////////////////////////////////////////////////////////////
// protected slots
////////////////////////////////////////////////////////////////////////////////
void Playlist::slotPopulateBackMenu() const
{
if(!m_playingItem)
return;
KPopupMenu *menu = action<KToolBarPopupAction>("back")->popupMenu();
menu->clear();
m_backMenuItems.clear();
int count = 0;
PlaylistItemList::ConstIterator it = m_playingItem->playlist()->m_history.end();
while(it != m_playingItem->playlist()->m_history.begin() && count < 10) {
++count;
--it;
int index = menu->insertItem((*it)->file().tag()->title());
m_backMenuItems[index] = *it;
}
}
void Playlist::slotPlayFromBackMenu(int number) const
{
if(!m_backMenuItems.contains(number))
return;
m_playNextItem = m_backMenuItems[number];
action("forward")->activate();
}
////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////
......@@ -1266,6 +1275,9 @@ void Playlist::setPlaying(PlaylistItem *item, bool addToHistory)
m_playingItem = item;
item->setPixmap(m_leftColumn, UserIcon("playing"));
item->setPlaying(true);
bool enableBack = !m_playingItem->playlist()->m_history.isEmpty();
action<KToolBarPopupAction>("back")->popupMenu()->setEnabled(enableBack);
}
bool Playlist::playing() const
......@@ -1733,8 +1745,7 @@ void Playlist::slotPlayCurrent()
QListViewItemIterator::Visible);
m_playNextItem = static_cast<PlaylistItem *>(it.current());
action("stop")->activate();
action("play")->activate();
action("forward")->activate();
}
////////////////////////////////////////////////////////////////////////////////
......
......@@ -130,11 +130,6 @@ public:
*/
PlaylistItemList selectedItems();
/**
* Returns a list of the last 10 played items.
*/
PlaylistItemList historyItems(PlaylistItem *current, bool random) const;
/**
* Allow duplicate files in the playlist.
*/
......@@ -409,6 +404,10 @@ protected:
template <class CollectionItemType, class ItemType, class SiblingType>
void createItems(const QValueList<SiblingType *> &siblings);
protected slots:
void slotPopulateBackMenu() const;
void slotPlayFromBackMenu(int number) const;
signals:
/**
......@@ -592,6 +591,7 @@ private:
static int m_leftColumn;
static PlaylistItem *m_playingItem;
static PlaylistItem *m_playNextItem;
static QMap<int, PlaylistItem *> m_backMenuItems;
};
void processEvents();
......
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