Commit 305309a2 authored by Scott Wheeler's avatar Scott Wheeler

Make Folder Playlists a real type that's restored as such. Now they automatically

update with the content (at least on a restart; directory watching will come later).

CCMAIL:81060-done@bugs.kde.org

svn path=/trunk/kdemultimedia/juk/; revision=344845
parent bd46407b
......@@ -28,6 +28,7 @@
#include "searchplaylist.h"
#include "historyplaylist.h"
#include "upcomingplaylist.h"
#include "folderplaylist.h"
#include "playlistcollection.h"
#include "actioncollection.h"
......@@ -35,7 +36,15 @@ using namespace ActionCollection;
Cache *Cache::m_cache = 0;
static const int playlistCacheVersion = 2;
enum PlaylistType { Normal = 0, Search = 1, History = 2, Upcoming = 3 };
enum PlaylistType
{
Normal = 0,
Search = 1,
History = 2,
Upcoming = 3,
Folder = 4
};
////////////////////////////////////////////////////////////////////////////////
// public methods
......@@ -130,26 +139,34 @@ void Cache::loadPlaylists(PlaylistCollection *collection) // static
}
case History:
{
action<KToggleAction>("showHistory")->setChecked(true);
collection->setHistoryPlaylistEnabled(true);
s >> *collection->historyPlaylist();
playlist = collection->historyPlaylist();
action<KToggleAction>("showHistory")->setChecked(true);
collection->setHistoryPlaylistEnabled(true);
s >> *collection->historyPlaylist();
playlist = collection->historyPlaylist();
break;
}
case Upcoming:
{
UpcomingPlaylist *p = new UpcomingPlaylist(collection);
action<KToggleAction>("saveUpcomingTracks")->setChecked(true);
s >> *p;
playlist = p;
collection->setUpcomingPlaylist(p);
break;
}
case Upcoming:
{
UpcomingPlaylist *p = new UpcomingPlaylist(collection);
action<KToggleAction>("saveUpcomingTracks")->setChecked(true);
s >> *p;
playlist = p;
collection->setUpcomingPlaylist(p);
case Folder:
{
kdDebug(65432) << "reading folder" << endl;
FolderPlaylist *p = new FolderPlaylist(collection);
s >> *p;
playlist = p;
break;
}
}
default:
kdDebug(65432) << "reading playlist" << endl;
Playlist *p = new Playlist(collection, true);
s >> *p;
s >> *p;
playlist = p;
break;
}
if(version == 2) {
......@@ -169,7 +186,7 @@ void Cache::loadPlaylists(PlaylistCollection *collection) // static
f.reset();
while(!fs.atEnd()) {
while(!fs.atEnd()) {
Playlist *p = new Playlist(collection);
fs >> *p;
}
......@@ -187,33 +204,39 @@ void Cache::savePlaylists(const PlaylistList &playlists)
QFile f(playlistsFile);
if(!f.open(IO_WriteOnly))
return;
return;
QByteArray data;
QDataStream s(data, IO_WriteOnly);
for(PlaylistList::ConstIterator it = playlists.begin(); it != playlists.end(); it++) {
if(*it) {
if(dynamic_cast<HistoryPlaylist *>(*it)) {
s << Q_INT32(History)
<< *static_cast<HistoryPlaylist *>(*it);
}
else if(dynamic_cast<SearchPlaylist *>(*it)) {
s << Q_INT32(Search)
<< *static_cast<SearchPlaylist *>(*it);
}
else if(dynamic_cast<UpcomingPlaylist *>(*it)) {
if(!action<KToggleAction>("saveUpcomingTracks")->isChecked())
continue;
s << Q_INT32(Upcoming)
<< *static_cast<UpcomingPlaylist *>(*it);
}
else {
s << Q_INT32(Normal)
<< *(*it);
}
s << Q_INT32((*it)->sortColumn());
}
if(*it) {
if(dynamic_cast<HistoryPlaylist *>(*it)) {
s << Q_INT32(History)
<< *static_cast<HistoryPlaylist *>(*it);
}
else if(dynamic_cast<SearchPlaylist *>(*it)) {
s << Q_INT32(Search)
<< *static_cast<SearchPlaylist *>(*it);
}
else if(dynamic_cast<UpcomingPlaylist *>(*it)) {
if(!action<KToggleAction>("saveUpcomingTracks")->isChecked())
continue;
s << Q_INT32(Upcoming)
<< *static_cast<UpcomingPlaylist *>(*it);
}
else if(dynamic_cast<FolderPlaylist *>(*it)) {
kdDebug(65432) << "saving folder " << (*it)->name() << endl;
s << Q_INT32(Folder)
<< *static_cast<FolderPlaylist *>(*it);
}
else {
kdDebug(65432) << "saving playlist " << (*it)->name() << endl;
s << Q_INT32(Normal)
<< *(*it);
}
s << Q_INT32((*it)->sortColumn());
}
}
QDataStream fs(&f);
......
......@@ -13,6 +13,9 @@
***************************************************************************/
#include "folderplaylist.h"
#include "playlistcollection.h"
#include <qtimer.h>
////////////////////////////////////////////////////////////////////////////////
// public methods
......@@ -20,10 +23,10 @@
FolderPlaylist::FolderPlaylist(PlaylistCollection *collection, const QString &folder,
const QString &name) :
Playlist(collection, name),
Playlist(collection, name, "folder"),
m_folder(folder)
{
addFiles(folder, false);
QTimer::singleShot(0, this, SLOT(slotUpdate()));
}
FolderPlaylist::~FolderPlaylist()
......@@ -31,4 +34,48 @@ FolderPlaylist::~FolderPlaylist()
}
QString FolderPlaylist::folder() const
{
return m_folder;
}
void FolderPlaylist::setFolder(const QString &s)
{
m_folder = s;
QTimer::singleShot(0, this, SLOT(slotUpdate()));
}
////////////////////////////////////////////////////////////////////////////////
// private slots
////////////////////////////////////////////////////////////////////////////////
void FolderPlaylist::slotUpdate()
{
if(!m_folder.isNull())
addFiles(m_folder, false);
}
////////////////////////////////////////////////////////////////////////////////
// helper functions
////////////////////////////////////////////////////////////////////////////////
QDataStream &operator<<(QDataStream &s, const FolderPlaylist &p)
{
s << p.name()
<< p.folder();
return s;
}
QDataStream &operator>>(QDataStream &s, FolderPlaylist &p)
{
QString name;
QString folder;
s >> name
>> folder;
p.setFolder(folder);
p.setName(name);
return s;
}
#include "folderplaylist.moc"
......@@ -22,12 +22,20 @@ class FolderPlaylist : public Playlist
Q_OBJECT
public:
FolderPlaylist(PlaylistCollection *collection, const QString &folder,
FolderPlaylist(PlaylistCollection *collection, const QString &folder = QString::null,
const QString &name = QString::null);
virtual ~FolderPlaylist();
QString folder() const;
void setFolder(const QString &s);
private slots:
void slotUpdate();
private:
QString m_folder;
};
QDataStream &operator<<(QDataStream &s, const FolderPlaylist &p);
QDataStream &operator>>(QDataStream &s, FolderPlaylist &p);
#endif
......@@ -506,11 +506,11 @@ void Playlist::clearItems(const PlaylistItemList &items)
dataChanged();
}
QStringList Playlist::files()
QStringList Playlist::files() const
{
QStringList list;
for(QListViewItemIterator it(this); it.current(); ++it)
for(QListViewItemIterator it(const_cast<Playlist *>(this)); it.current(); ++it)
list.append(static_cast<PlaylistItem *>(*it)->file().absFilePath());
return list;
......@@ -1809,7 +1809,7 @@ void Playlist::slotPlayCurrent()
// helper functions
////////////////////////////////////////////////////////////////////////////////
QDataStream &operator<<(QDataStream &s, Playlist &p)
QDataStream &operator<<(QDataStream &s, const Playlist &p)
{
s << p.name();
s << p.fileName();
......
......@@ -122,7 +122,7 @@ public:
/**
* All of the (media) files in the list.
*/
QStringList files();
QStringList files() const;
/**
* Returns a list of all of the items in the playlist.
......@@ -611,7 +611,7 @@ private:
bool processEvents();
QDataStream &operator<<(QDataStream &s, Playlist &p);
QDataStream &operator<<(QDataStream &s, const Playlist &p);
QDataStream &operator>>(QDataStream &s, Playlist &p);
// template method implementations
......
......@@ -127,7 +127,8 @@ private:
* @see TrackSequenceManager
* @author Michael Pyne <michael.pyne@kdemail.net>
*/
class UpcomingPlaylist::UpcomingSequenceIterator : public TrackSequenceIterator {
class UpcomingPlaylist::UpcomingSequenceIterator : public TrackSequenceIterator
{
public:
/**
* Default constructor.
......
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