Commit 91771ea4 authored by Scott Wheeler's avatar Scott Wheeler

Cleaned up the behavior of "Play Next" by making it get reset on back,

selecting an item on your own, or stop.

This also prompted a bunch of other cleanups including removing knowledge
of the PlaylistSplitter from the Playlist and CollectionList classes and a
bunch of other stuff that offended me along the way.

svn path=/trunk/kdemultimedia/juk/; revision=212243
parent fb2570cc
......@@ -26,7 +26,6 @@
#include <qtimer.h>
#include "collectionlist.h"
#include "playlistsplitter.h"
#include "cache.h"
#include "splashscreen.h"
......@@ -41,9 +40,9 @@ CollectionList *CollectionList::instance()
return list;
}
void CollectionList::initialize(PlaylistSplitter *s, QWidget *parent, bool restoreOnLoad)
void CollectionList::initialize(QWidget *parent, bool restoreOnLoad)
{
list = new CollectionList(s, parent);
list = new CollectionList(parent);
if(restoreOnLoad)
for(QDictIterator<Tag>it(*Cache::instance()); it.current(); ++it)
......@@ -54,21 +53,6 @@ void CollectionList::initialize(PlaylistSplitter *s, QWidget *parent, bool resto
// public methods
////////////////////////////////////////////////////////////////////////////////
QStringList CollectionList::artists() const
{
return m_artistList.values();
}
QStringList CollectionList::albums() const
{
return m_albumList.values();
}
CollectionListItem *CollectionList::lookup(const QString &file)
{
return m_itemsDict.find(file);
}
PlaylistItem *CollectionList::createItem(const QFileInfo &file, QListViewItem *)
{
QString filePath = resolveSymLinks(file);
......@@ -83,11 +67,6 @@ PlaylistItem *CollectionList::createItem(const QFileInfo &file, QListViewItem *)
// public slots
////////////////////////////////////////////////////////////////////////////////
void CollectionList::paste()
{
decode(kapp->clipboard()->data());
}
void CollectionList::clear()
{
int result = KMessageBox::warningYesNo(this,
......@@ -111,7 +90,7 @@ void CollectionList::slotCheckCache()
// protected methods
////////////////////////////////////////////////////////////////////////////////
CollectionList::CollectionList(PlaylistSplitter *s, QWidget *parent) : Playlist(s, parent, i18n("Collection List")) //, m_finishedLoading(false)
CollectionList::CollectionList(QWidget *parent) : Playlist(parent, i18n("Collection List"))
{
}
......@@ -133,8 +112,7 @@ void CollectionList::decode(QMimeSource *s)
for(KURL::List::Iterator it = urls.begin(); it != urls.end(); it++)
files.append((*it).path());
if(playlistSplitter())
playlistSplitter()->addToPlaylist(files, this);
emit signalFilesDropped(files, this);
}
void CollectionList::contentsDropEvent(QDropEvent *e)
......@@ -158,7 +136,7 @@ void CollectionList::addArtist(const QString &artist)
// Do a bit of caching since there will very often be "two in a row" insertions.
static QString previousArtist;
if(artist != previousArtist && !m_artistList.insert(artist))
if(artist != previousArtist && !m_artists.insert(artist))
previousArtist = artist;
}
......@@ -167,7 +145,7 @@ void CollectionList::addAlbum(const QString &album)
// Do a bit of caching since there will very often be "two in a row" insertions.
static QString previousAlbum;
if(album != previousAlbum && !m_albumList.insert(album))
if(album != previousAlbum && !m_albums.insert(album))
previousAlbum = album;
}
////////////////////////////////////////////////////////////////////////////////
......
......@@ -18,6 +18,9 @@
#ifndef COLLECTIONLIST_H
#define COLLECTIONLIST_H
#include <kapplication.h>
#include <qclipboard.h>
#include <qdict.h>
#include "playlist.h"
......@@ -35,7 +38,6 @@
* "initialize()" method.
*/
class PlaylistSplitter;
class CollectionListItem;
class CollectionList : public Playlist
......@@ -46,21 +48,21 @@ class CollectionList : public Playlist
public:
static CollectionList *instance();
static void initialize(PlaylistSplitter *s, QWidget *parent, bool restoreOnLoad = true);
static void initialize(QWidget *parent, bool restoreOnLoad = true);
QStringList artists() const;
QStringList albums() const;
QStringList artists() const { return m_artists.values(); }
QStringList albums() const { return m_albums.values(); }
CollectionListItem *lookup(const QString &file);
CollectionListItem *lookup(const QString &file) { return m_itemsDict.find(file); }
virtual PlaylistItem *createItem(const QFileInfo &file, QListViewItem *);
public slots:
virtual void paste();
virtual void paste() { decode(kapp->clipboard()->data()); }
virtual void clear();
void slotCheckCache();
protected:
CollectionList(PlaylistSplitter *s, QWidget *parent);
CollectionList(QWidget *parent);
virtual ~CollectionList();
virtual void decode(QMimeSource *s);
......@@ -88,8 +90,8 @@ protected:
private:
static CollectionList *list;
QDict<CollectionListItem> m_itemsDict;
SortedStringList m_artistList;
SortedStringList m_albumList;
SortedStringList m_artists;
SortedStringList m_albums;
};
class CollectionListItem : public PlaylistItem
......
......@@ -42,26 +42,23 @@
#include "playlist.h"
#include "collectionlist.h"
#include "playlistsplitter.h"
#include "playlistbox.h"
#include "playlistsplitter.h"
#include "tag.h"
#include "genrelistlist.h"
////////////////////////////////////////////////////////////////////////////////
// public m_members
// public members
////////////////////////////////////////////////////////////////////////////////
Playlist::Playlist(PlaylistSplitter *s, QWidget *parent, const QString &name) : KListView(parent, name.latin1()),
m_playlistName(name),
m_splitter(s)
Playlist::Playlist(QWidget *parent, const QString &name) : KListView(parent, name.latin1()),
m_playlistName(name)
{
setup();
}
Playlist::Playlist(PlaylistSplitter *s, const QFileInfo &playlistFile, QWidget *parent, const char *name) : KListView(parent, name),
m_playlistFileName(playlistFile.absFilePath()),
m_splitter(s)
Playlist::Playlist(const QFileInfo &playlistFile, QWidget *parent, const char *name) : KListView(parent, name),
m_playlistFileName(playlistFile.absFilePath())
{
setup();
......@@ -122,9 +119,9 @@ void Playlist::save()
void Playlist::saveAs()
{
QStringList extensions = m_splitter->playlistExtensions();
QStringList extensions = PlaylistSplitter::playlistExtensions();
m_playlistFileName = KFileDialog::getSaveFileName(QString::null, m_splitter->extensionsString(extensions, i18n("Playlists")));
m_playlistFileName = KFileDialog::getSaveFileName(QString::null, PlaylistSplitter::extensionsString(extensions, i18n("Playlists")));
m_playlistFileName = m_playlistFileName.stripWhiteSpace();
if(m_playlistFileName != QString::null) {
......@@ -258,12 +255,6 @@ void Playlist::setName(const QString &n)
// public slots
////////////////////////////////////////////////////////////////////////////////
void Playlist::slotPlayNext()
{
if(m_splitter)
m_splitter->playSelectedFileNext();
}
void Playlist::copy()
{
kapp->clipboard()->setData(dragObject(0), QClipboard::Clipboard);
......@@ -329,11 +320,6 @@ QDragObject *Playlist::dragObject(QWidget *parent)
return drag;
}
QDragObject *Playlist::dragObject()
{
return dragObject(this);
}
bool Playlist::canDecode(QMimeSource *s)
{
KURL::List urls;
......@@ -352,8 +338,7 @@ void Playlist::decode(QMimeSource *s)
for(KURL::List::Iterator it = urls.begin(); it != urls.end(); it++)
fileList.append((*it).path());
if(m_splitter)
m_splitter->addToPlaylist(fileList, this);
emit signalFilesDropped(fileList, this);
}
bool Playlist::eventFilter(QObject* watched, QEvent* e)
......@@ -469,7 +454,7 @@ QString Playlist::resolveSymLinks(const QFileInfo &file)
}
////////////////////////////////////////////////////////////////////////////////
// private m_members
// private members
////////////////////////////////////////////////////////////////////////////////
void Playlist::setup()
......@@ -527,7 +512,7 @@ void Playlist::setup()
m_rmbMenu = new KPopupMenu(this);
m_rmbMenu->insertItem(SmallIcon("player_play"), i18n("Play Next"), this, SLOT(slotPlayNext()));
m_rmbMenu->insertItem(SmallIcon("player_play"), i18n("Play Next"), this, SLOT(slotSetNext()));
m_rmbMenu->insertSeparator();
m_rmbMenu->insertItem(SmallIcon("editcut"), i18n("Cut"), this, SLOT(cut()));
m_rmbMenu->insertItem(SmallIcon("editcopy"), i18n("Copy"), this, SLOT(copy()));
......
......@@ -26,7 +26,6 @@
#include "playlistitem.h"
#include "sortedstringlist.h"
class PlaylistSplitter;
class KPopupMenu;
class KPopupMenu;
......@@ -43,13 +42,13 @@ public:
* Before creating a playlist directly, please see
* PlaylistSplitter::createPlaylist().
*/
Playlist(PlaylistSplitter *s, QWidget *parent, const QString &name = QString::null);
Playlist(QWidget *parent, const QString &name = QString::null);
/**
* Before creating a playlist directly, please see
* PlaylistSplitter::openPlaylist().
*/
Playlist(PlaylistSplitter *s, const QFileInfo &playlistFile, QWidget *parent, const char *name = 0);
Playlist(const QFileInfo &playlistFile, QWidget *parent, const char *name = 0);
virtual ~Playlist();
......@@ -126,7 +125,7 @@ public slots:
* Remove the currently selected items from the playlist and disk.
*/
void slotDeleteSelectedItems() { deleteFromDisk(selectedItems()); };
virtual void slotPlayNext();
virtual void slotSetNext() { emit signalSetNext(selectedItems().getFirst()); }
/*
* The edit slots are required to use the canonical names so that they are
......@@ -147,12 +146,11 @@ protected:
virtual bool eventFilter(QObject* watched, QEvent* e);
virtual QDragObject *dragObject(QWidget *parent);
virtual QDragObject *dragObject();
virtual QDragObject *dragObject() { return dragObject(this); }
virtual bool canDecode(QMimeSource *s);
virtual void decode(QMimeSource *s);
virtual void contentsDropEvent(QDropEvent *e);
virtual void contentsDragMoveEvent(QDragMoveEvent *e);
PlaylistSplitter *playlistSplitter() const { return m_splitter; }
static QString resolveSymLinks(const QFileInfo &file);
......@@ -190,8 +188,9 @@ signals:
* list.
*/
void signalAboutToRemove(PlaylistItem *item);
void signalToggleColumnVisible(int column);
void signalFilesDropped(const QStringList &files, Playlist *);
void signalSetNext(PlaylistItem *item);
private:
void setup();
......@@ -218,7 +217,6 @@ private:
* file name.
*/
QString m_playlistName;
PlaylistSplitter *m_splitter;
KPopupMenu *m_rmbMenu;
KPopupMenu *m_headerMenu;
......
......@@ -216,7 +216,7 @@ void PlaylistBox::duplicate(Item *item)
QLineEdit::Normal, m_splitter->uniquePlaylistName(item->text(), true), &ok);
if(ok) {
Playlist *p = m_splitter->createPlaylist(name);
m_splitter->addToPlaylist(item->playlist()->files(), p);
m_splitter->slotAddToPlaylist(item->playlist()->files(), p);
}
}
}
......@@ -268,7 +268,7 @@ void PlaylistBox::decode(QMimeSource *s, Item *item)
for(KURL::List::Iterator it = urls.begin(); it != urls.end(); it++)
files.append((*it).path());
m_splitter->addToPlaylist(files, item->playlist());
m_splitter->slotAddToPlaylist(files, item->playlist());
}
}
......
......@@ -64,7 +64,6 @@ PlaylistSplitter::PlaylistSplitter(QWidget *parent, bool restore, const char *na
setupLayout();
readConfig();
connect(this, SIGNAL(signalDoubleClicked()), this, SLOT(slotClearNextItem()));
}
PlaylistSplitter::~PlaylistSplitter()
......@@ -101,103 +100,52 @@ QString PlaylistSplitter::uniquePlaylistName(const QString &startingWith, bool u
QString PlaylistSplitter::playNextFile(bool random)
{
Playlist *p;
PlaylistItem *i;
if(m_playingItem) {
m_playingItem->setPixmap(0, 0);
// 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.
p = static_cast<Playlist *>(m_playingItem->listView());
if(m_nextPlaylistItem) {
i = m_nextPlaylistItem;
m_nextPlaylistItem = 0;
}
else if(m_playingItem) {
Playlist *p = static_cast<Playlist *>(m_playingItem->listView());
i = p->nextItem(m_playingItem, random);
}
else {
PlaylistItemList items = playlistSelection();
if(!items.isEmpty())
i = items.first();
else {
p = visiblePlaylist();
i = static_cast<PlaylistItem *>(p->firstChild());
}
i = playlistSelection().getFirst();
if(!i)
i = static_cast<PlaylistItem *>(visiblePlaylist()->firstChild());
}
if (m_nextPlaylistItem) {
i = m_nextPlaylistItem;
m_nextPlaylistItem = 0;
}
if(i) {
i->setPixmap(0, QPixmap(UserIcon("playing")));
m_playingItem = i;
return i->absFilePath();
}
else
return QString::null;
return play(i);
}
QString PlaylistSplitter::playPreviousFile(bool random)
{
if(m_playingItem) {
Playlist *p = static_cast<Playlist *>(m_playingItem->listView());
PlaylistItem *i = p->previousItem(m_playingItem, random);
m_playingItem->setPixmap(0, 0);
i->setPixmap(0, QPixmap(UserIcon("playing")));
m_playingItem = i;
return i->absFilePath();
}
else
return QString::null;
}
QString PlaylistSplitter::playSelectedFile()
{
stop();
PlaylistItemList items = playlistSelection();
if(!items.isEmpty()) {
PlaylistItem *i = items.first();
i->setPixmap(0, QPixmap(UserIcon("playing")));
m_playingItem = i;
return i->absFilePath();
}
else
if(!m_playingItem)
return QString::null;
}
QString PlaylistSplitter::playSelectedFileNext()
{
PlaylistItemList items = playlistSelection();
if(items.isEmpty()) {
m_nextPlaylistItem = 0L;
return QString::null;
}
Playlist *p = static_cast<Playlist *>(m_playingItem->listView());
PlaylistItem *i = p->previousItem(m_playingItem, random);
m_nextPlaylistItem = items.first();
return m_nextPlaylistItem->absFilePath();
return play(i);
}
QString PlaylistSplitter::playFirstFile()
{
stop();
Playlist *p = visiblePlaylist();
PlaylistItem *i = static_cast<PlaylistItem *>(p->firstChild());
if(i) {
i->setPixmap(0, QPixmap(UserIcon("playing")));
m_playingItem = i;
return i->absFilePath();
}
else
return QString::null;
return play(i);
}
void PlaylistSplitter::stop()
{
m_nextPlaylistItem = 0;
if(m_playingItem) {
m_playingItem->setPixmap(0, 0);
m_playingItem = 0;
......@@ -228,27 +176,6 @@ QString PlaylistSplitter::playingList() const
return QString::null;
}
void PlaylistSplitter::addToPlaylist(const QString &file, Playlist *list)
{
KApplication::setOverrideCursor(Qt::waitCursor);
addImpl(file, list);
KApplication::restoreOverrideCursor();
if(m_editor)
m_editor->slotUpdateCollection();
}
void PlaylistSplitter::addToPlaylist(const QStringList &files, Playlist *list)
{
KApplication::setOverrideCursor(Qt::waitCursor);
for(QStringList::ConstIterator it = files.begin(); it != files.end(); ++it)
addImpl(*it, list);
KApplication::restoreOverrideCursor();
if(m_editor)
m_editor->slotUpdateCollection();
}
QString PlaylistSplitter::extensionsString(const QStringList &extensions, const QString &type) // static
{
QStringList l;
......@@ -274,9 +201,9 @@ void PlaylistSplitter::open(const QString &file)
if(visiblePlaylist() == m_collection ||
KMessageBox::questionYesNo(this, i18n("Do you want to add this item to the current list or to the collection list?"),
QString::null, KGuiItem(i18n("Current")), KGuiItem(i18n("Collection"))) == KMessageBox::No)
addToPlaylist(file, m_collection);
slotAddToPlaylist(file, m_collection);
else
addToPlaylist(file, visiblePlaylist());
slotAddToPlaylist(file, visiblePlaylist());
}
void PlaylistSplitter::open(const QStringList &files)
......@@ -287,14 +214,14 @@ void PlaylistSplitter::open(const QStringList &files)
if(visiblePlaylist() == m_collection ||
KMessageBox::questionYesNo(this, i18n("Do you want to add these items to the current list or to the collection list?"),
QString::null, KGuiItem(i18n("Current")), KGuiItem(i18n("Collection"))) == KMessageBox::No)
addToPlaylist(files, m_collection);
slotAddToPlaylist(files, m_collection);
else
addToPlaylist(files, visiblePlaylist());
slotAddToPlaylist(files, visiblePlaylist());
}
Playlist *PlaylistSplitter::createPlaylist(const QString &name)
{
Playlist *p = new Playlist(this, m_playlistStack, name.latin1());
Playlist *p = new Playlist(m_playlistStack, name.latin1());
setupPlaylist(p, true);
return p;
}
......@@ -372,6 +299,27 @@ void PlaylistSplitter::slotDeleteSelectedItems()
p->slotDeleteSelectedItems();
}
void PlaylistSplitter::slotAddToPlaylist(const QString &file, Playlist *list)
{
KApplication::setOverrideCursor(Qt::waitCursor);
addImpl(file, list);
KApplication::restoreOverrideCursor();
if(m_editor)
m_editor->slotUpdateCollection();
}
void PlaylistSplitter::slotAddToPlaylist(const QStringList &files, Playlist *list)
{
KApplication::setOverrideCursor(Qt::waitCursor);
for(QStringList::ConstIterator it = files.begin(); it != files.end(); ++it)
addImpl(*it, list);
KApplication::restoreOverrideCursor();
if(m_editor)
m_editor->slotUpdateCollection();
}
void PlaylistSplitter::slotToggleColumnVisible(int column)
{
m_visibleColumns[column] = ! m_visibleColumns[column];
......@@ -413,7 +361,7 @@ void PlaylistSplitter::setupLayout()
// fact is a subclass) so it is created here rather than by using
// slotCreatePlaylist().
CollectionList::initialize(this, m_playlistStack, m_restore);
CollectionList::initialize(m_playlistStack, m_restore);
m_collection = CollectionList::instance();
setupPlaylist(m_collection, true, "folder_sound");
......@@ -443,7 +391,7 @@ void PlaylistSplitter::readConfig()
if(f.open(IO_ReadOnly)) {
QDataStream s(&f);
while(!s.atEnd()) {
Playlist *p = new Playlist(this, m_playlistStack);
Playlist *p = new Playlist(m_playlistStack);
s >> *p;
// check to see if we've alredy loaded this item before continuing
......@@ -553,6 +501,8 @@ void PlaylistSplitter::setupPlaylist(Playlist *p, bool raise, const char *icon)
connect(p, SIGNAL(signalCollectionChanged()), m_editor, SLOT(slotUpdateCollection()));
connect(p, SIGNAL(signalNumberOfItemsChanged(Playlist *)), this, SLOT(slotPlaylistCountChanged(Playlist *)));
connect(p, SIGNAL(signalAboutToRemove(PlaylistItem *)), this, SLOT(slotPlaylistItemRemoved(PlaylistItem *)));
connect(p, SIGNAL(signalFilesDropped(const QStringList &, Playlist *)), this, SLOT(slotAddToPlaylist(const QStringList &, Playlist *)));
connect(p, SIGNAL(signalSetNext(PlaylistItem *)), this, SLOT(slotSetNextItem(PlaylistItem *)));
connect(p, SIGNAL(signalToggleColumnVisible(int)), this, SLOT(slotToggleColumnVisible(int)));
......@@ -570,7 +520,7 @@ Playlist *PlaylistSplitter::openPlaylist(const QString &file)
if(!fileInfo.exists() || !fileInfo.isFile() || !fileInfo.isReadable() || m_playlistFiles.insert(fileInfo.absFilePath()))
return 0;
Playlist *p = new Playlist(this, file, m_playlistStack, fileInfo.baseName(true).latin1());
Playlist *p = new Playlist(file, m_playlistStack, fileInfo.baseName(true).latin1());
setupPlaylist(p);
return p;
}
......@@ -588,6 +538,19 @@ void PlaylistSplitter::setupColumns(Playlist *p)
}
}
QString PlaylistSplitter::play(PlaylistItem *item)
{
stop();
if(!item)
return QString::null;
item->setPixmap(0, QPixmap(UserIcon("playing")));
m_playingItem = item;
return item->absFilePath();
}
////////////////////////////////////////////////////////////////////////////////
// private slots
////////////////////////////////////////////////////////////////////////////////
......
......@@ -82,13 +82,7 @@ public:
* Returns the name of the currently selected file and moves the playing
* indicator to that file.
*/
QString playSelectedFile();
/**
* Returns the name of the currently selected file and stores it so that
* it's forced to be the next file played.
*/
QString playSelectedFileNext();
QString playSelectedFile() { return play(playlistSelection().getFirst()); }
/**
* Returns the name of the first item in the playlist and moves the playing
......@@ -118,16 +112,6 @@ public:
*/
int selectedPlaylistCount() const { return visiblePlaylist()->childCount(); }
/**
* Add the file to the playlist.
*/
void addToPlaylist(const QString &file, Playlist *list);
/**
* Adds the files to the playlist.
*/
void addToPlaylist(const QStringList &files, Playlist *list);
/**
* Returns true if the the collection list is the visible playlist.
*/
......@@ -185,9 +169,6 @@ public slots:
// Tagger slots
/**
* Save.
*/
void slotSaveTag() { m_editor->save(); }