Enable loading playlists from filesystem

This commit is contained in:
Thomas Frauendorfer 2008-02-17 17:49:16 +01:00
parent 6af763a954
commit 5b5600aadd
5 changed files with 53 additions and 3 deletions

View file

@ -29,8 +29,10 @@
* Private implemention to hide <xmmsclient/xmmsclient++> from collection.h * Private implemention to hide <xmmsclient/xmmsclient++> from collection.h
*/ */
XCollection::Private::Private (XCollection *collection) : QObject (collection) XCollection::Private::Private (XCollection *collection, XClient* client)
: QObject (collection)
{ {
m_client = client;
} }
bool bool
@ -84,6 +86,17 @@ XCollection::Private::on_collection_modified (const Xmms::Dict &value)
return true; 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) XCollection::XCollection (XClient * client) : QObject ( client)
{ {
m_client = client; m_client = client;
d = new XCollection::Private (this); d = new XCollection::Private (this, client);
connect (client, SIGNAL (gotConnection (XClient *)), connect (client, SIGNAL (gotConnection (XClient *)),
this, SLOT (on_connect (XClient *))); this, SLOT (on_connect (XClient *)));
@ -225,3 +238,18 @@ XCollection::playlistClear (QString name)
return true; 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;
}

View file

@ -42,6 +42,7 @@ class XCollection : public QObject
bool addIdlist (QString name); bool addIdlist (QString name);
bool playlistAddUrl (QUrl url, QString plsname = ""); bool playlistAddUrl (QUrl url, QString plsname = "");
bool playlistClear (QString name = ""); bool playlistClear (QString name = "");
bool addPlsFile (QUrl url);
signals: signals:
void collectionModified (QString collection, QString ns, int type, void collectionModified (QString collection, QString ns, int type,

View file

@ -32,14 +32,16 @@ class XCollection::Private : public QObject {
Q_OBJECT Q_OBJECT
public: public:
Private (XCollection *collection); Private (XCollection* collection, XClient* client);
bool on_collection_modified (const Xmms::Dict &value); bool on_collection_modified (const Xmms::Dict &value);
bool handle_playlists_list (const Xmms::List< std::string > &list); bool handle_playlists_list (const Xmms::List< std::string > &list);
bool handle_active_pls_changed (const std::string &name); bool handle_active_pls_changed (const std::string &name);
bool handle_idlist_created (const Xmms::Coll::Coll &idlist );
QStringList m_playlists; QStringList m_playlists;
QString m_activePlaylist; QString m_activePlaylist;
XClient* m_client;
signals: signals:
void collectionModified (QString collection, QString ns, int type, void collectionModified (QString collection, QString ns, int type,

View file

@ -39,6 +39,7 @@
#include <QSettings> #include <QSettings>
#include <QFileDialog> #include <QFileDialog>
#include <QPainter> #include <QPainter>
#include <QUrl>
/* /*
* *
@ -291,6 +292,7 @@ PlaylistWidget::addButtons (void)
Skin::PLS_LST_SAV_1); Skin::PLS_LST_SAV_1);
b = new PlaylistMenuButton (m_lst, Skin::PLS_LST_OPN_0, b = new PlaylistMenuButton (m_lst, Skin::PLS_LST_OPN_0,
Skin::PLS_LST_OPN_1); Skin::PLS_LST_OPN_1);
connect (b, SIGNAL (activated ()), this, SLOT (menuAddPls ()));
} }
void 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 void
PlaylistWidget::resizeEvent (QResizeEvent *event) PlaylistWidget::resizeEvent (QResizeEvent *event)
{ {

View file

@ -85,6 +85,7 @@ class PlaylistWidget : public QWidget {
void menuAddUrl (); void menuAddUrl ();
void menuAddDir (); void menuAddDir ();
void menuAddFile (); void menuAddFile ();
void menuAddPls ();
protected slots: protected slots:
void openPlaylistChooser (); void openPlaylistChooser ();