From 5b5600aadd9d679c43e8d946b7bb7efb651053b1 Mon Sep 17 00:00:00 2001 From: Thomas Frauendorfer Date: Sun, 17 Feb 2008 17:49:16 +0100 Subject: [PATCH] Enable loading playlists from filesystem --- lib/xcollection.cpp | 32 ++++++++++++++++++++++++++++++-- lib/xcollection.h | 1 + lib/xcollection_p.h | 4 +++- src/playlist/playlistwidget.cpp | 18 ++++++++++++++++++ src/playlist/playlistwidget.h | 1 + 5 files changed, 53 insertions(+), 3 deletions(-) diff --git a/lib/xcollection.cpp b/lib/xcollection.cpp index 00b6b76..38c2475 100644 --- a/lib/xcollection.cpp +++ b/lib/xcollection.cpp @@ -29,8 +29,10 @@ * Private implemention to hide from collection.h */ -XCollection::Private::Private (XCollection *collection) : QObject (collection) +XCollection::Private::Private (XCollection *collection, XClient* client) + : QObject (collection) { + m_client = client; } bool @@ -84,6 +86,17 @@ XCollection::Private::on_collection_modified (const Xmms::Dict &value) return true; } +bool +XCollection::Private::handle_idlist_created (const Xmms::Coll::Coll &idlist) +{ + // we add a idlist, we don't want to sort it in any way + // I hope this does the trick. + std::list < std::string > tmp; + + m_client->playlist ()->addCollection (idlist, tmp); + + return true; +} /* @@ -92,7 +105,7 @@ XCollection::Private::on_collection_modified (const Xmms::Dict &value) XCollection::XCollection (XClient * client) : QObject ( client) { m_client = client; - d = new XCollection::Private (this); + d = new XCollection::Private (this, client); connect (client, SIGNAL (gotConnection (XClient *)), this, SLOT (on_connect (XClient *))); @@ -225,3 +238,18 @@ XCollection::playlistClear (QString name) return true; } + +bool +XCollection::addPlsFile (QUrl url) +{ + if (url.scheme ().isEmpty ()) { + //the protocol identifier is missing + //we guess we might be local, so just add file:// + url.setScheme ("file"); + } + m_client->collection ()->idlistFromPlaylistFile + (std::string (url.toEncoded ())) + (Xmms::bind (&XCollection::Private::handle_idlist_created, d)); + + return true; +} diff --git a/lib/xcollection.h b/lib/xcollection.h index 4284a7a..4bd095a 100644 --- a/lib/xcollection.h +++ b/lib/xcollection.h @@ -42,6 +42,7 @@ class XCollection : public QObject bool addIdlist (QString name); bool playlistAddUrl (QUrl url, QString plsname = ""); bool playlistClear (QString name = ""); + bool addPlsFile (QUrl url); signals: void collectionModified (QString collection, QString ns, int type, diff --git a/lib/xcollection_p.h b/lib/xcollection_p.h index f1e6939..d575671 100644 --- a/lib/xcollection_p.h +++ b/lib/xcollection_p.h @@ -32,14 +32,16 @@ class XCollection::Private : public QObject { Q_OBJECT public: - Private (XCollection *collection); + Private (XCollection* collection, XClient* client); bool on_collection_modified (const Xmms::Dict &value); bool handle_playlists_list (const Xmms::List< std::string > &list); bool handle_active_pls_changed (const std::string &name); + bool handle_idlist_created (const Xmms::Coll::Coll &idlist ); QStringList m_playlists; QString m_activePlaylist; + XClient* m_client; signals: void collectionModified (QString collection, QString ns, int type, diff --git a/src/playlist/playlistwidget.cpp b/src/playlist/playlistwidget.cpp index fb79fe3..2e8ad75 100644 --- a/src/playlist/playlistwidget.cpp +++ b/src/playlist/playlistwidget.cpp @@ -39,6 +39,7 @@ #include #include #include +#include /* * @@ -291,6 +292,7 @@ PlaylistWidget::addButtons (void) Skin::PLS_LST_SAV_1); b = new PlaylistMenuButton (m_lst, Skin::PLS_LST_OPN_0, Skin::PLS_LST_OPN_1); + connect (b, SIGNAL (activated ()), this, SLOT (menuAddPls ())); } void @@ -360,6 +362,22 @@ PlaylistWidget::menuAddFile () } +void +PlaylistWidget::menuAddPls () +{ + QStringList files; + + FileDialog fd (this, "add_Playlist"); + files = fd.getFiles (); + + if (files.count () > 0) { + XMMSHandler::getInstance ().xcollection ()->playlistClear (); + } + + QString file = files[0]; + XMMSHandler::getInstance ().xcollection ()->addPlsFile (QUrl (file)); +} + void PlaylistWidget::resizeEvent (QResizeEvent *event) { diff --git a/src/playlist/playlistwidget.h b/src/playlist/playlistwidget.h index 6ee036f..f945a25 100644 --- a/src/playlist/playlistwidget.h +++ b/src/playlist/playlistwidget.h @@ -85,6 +85,7 @@ class PlaylistWidget : public QWidget { void menuAddUrl (); void menuAddDir (); void menuAddFile (); + void menuAddPls (); protected slots: void openPlaylistChooser ();