Implement creation, deletion and switching of playlists (Idlists)

This commit is contained in:
Thomas Frauendorfer 2008-02-08 14:36:30 +01:00
parent 0da2995880
commit d93f2ee188
14 changed files with 517 additions and 3 deletions

View file

@ -8,6 +8,7 @@ OBJECTS_DIR = .obj
SOURCES += xclient.cpp \
xclientcache.cpp \
xconfig.cpp \
xcollection.cpp \
playlistmodel.cpp \
xmmsqt4.cpp
@ -15,6 +16,7 @@ SOURCES += xclient.cpp \
HEADERS += xclient.h \
xclientcache.h \
xconfig.h \
xcollection.h \
playlistmodel.h \
xmmsqt4.h \
debug.h

View file

@ -24,6 +24,7 @@
#include <QSettings>
#include "xclient.h"
#include "xcollection.h"
#include "xmmsqt4.h"
#include "debug.h"
@ -74,6 +75,7 @@ XClient::XClient (QObject *parent, const std::string &name) : QObject (parent),
m_isconnected = false;
m_cache = new XClientCache (this, this);
m_config = new XConfig (this, this);
m_collection = new XCollection (this);
m_name = name;
}
@ -128,7 +130,7 @@ try_again:
qWarning ("Couldn't establish sync connection!");
}
}
m_isconnected = true;
emit gotConnection (this);

View file

@ -32,6 +32,7 @@ class XClient;
#include "xconfig.h"
class XConfig;
class XCollection;
/*
class XSettings : public QObject
@ -73,6 +74,10 @@ class XClient : public QObject {
return m_config;
};
XCollection *xcollection () const {
return m_collection;
}
const Xmms::Client *sync () const {
return &m_sync;
};
@ -106,6 +111,7 @@ class XClient : public QObject {
// Xmms::Client *m_client;
XClientCache *m_cache;
XConfig *m_config;
XCollection *m_collection;
bool m_isconnected;
Xmms::Client m_sync;

145
lib/xcollection.cpp Normal file
View file

@ -0,0 +1,145 @@
/**
* This file is a part of Promoe, an XMMS2 Client.
*
* Copyright (C) 2008 Thomas Frauendorfer
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "xcollection.h"
#include <QHash>
#include <QString>
XCollection::XCollection (XClient * client) : QObject ( client)
{
m_client = client;
connect (client, SIGNAL (gotConnection (XClient *)),
this, SLOT (on_connect (XClient *)));
if (client->isConnected ()) {
on_connect (client);
}
}
void
XCollection::on_connect (XClient *client)
{
client->collection ()->broadcastCollectionChanged ()
(Xmms::bind (&XCollection::on_collection_modified, this));
client->collection ()->list ("Playlists")
(Xmms::bind (&XCollection::handle_playlists_list, this));
m_client = client;
}
bool
XCollection::on_collection_modified (const Xmms::Dict &value)
{
QString newname = QString ();
QHash<QString, QVariant> tmp = XClient::convert_dict (value);
int type = tmp["type"].toInt ();
QString name = tmp["name"].toString ();
// FIXME: handle other namespaces than "Playlists"
if (tmp["namespace"].toString () != "Playlists") {
return true;
}
if (type == XMMS_COLLECTION_CHANGED_RENAME)
newname = tmp["newname"].toString ();
// FIXME: use namespace parameter
switch (type) {
case XMMS_COLLECTION_CHANGED_ADD:
m_playlists.append (name);
break;
case XMMS_COLLECTION_CHANGED_REMOVE:
m_playlists.removeAll (name);
break;
case XMMS_COLLECTION_CHANGED_RENAME:
m_playlists.removeAll (name);
m_playlists.append (newname);
break;
case XMMS_COLLECTION_CHANGED_UPDATE:
// do nothing here
break;
default:
qDebug ("Unhandled collection change type %i", type);
}
m_playlists.sort ();
/*
qDebug ("---");
foreach (QString s, m_playlists) {
qDebug (s.toAscii ());
}
*/
emit collectionModified (tmp["name"].toString (),
tmp["namespace"].toString (),
type, newname);
return true;
}
bool
XCollection::handle_playlists_list (const Xmms::List< std::string > &list)
{
m_playlists.clear ();
for (list.first (); list.isValid (); ++list) {
m_playlists.append (XClient::stdToQ(*list));
}
m_playlists.sort ();
return true;
}
QStringList
XCollection::list (QString ns) {
// FIXME: use the ns parameter.
// We will need to handle querying the serverside playlists bettter...
return m_playlists;
}
// FIXME: Probably should be in another file
bool
XCollection::setActivePlaylist (QString name) {
if (!m_client->isConnected ()) return false;
m_client->playlist ()->load (name.toStdString ());
return true;
}
// FIXME: should be done in a more generic way
bool
XCollection::addIdlist (QString name) {
if (!m_client->isConnected ()) return false;
m_client->playlist ()->create (name.toStdString ());
return true;
}
bool
XCollection::remove (QString name, QString ns) {
if (!m_client->isConnected ()) return false;
m_client->collection ()->remove (name.toStdString (), ns.toAscii ());
return true;
}

51
lib/xcollection.h Normal file
View file

@ -0,0 +1,51 @@
/**
* This file is a part of Promoe, an XMMS2 Client.
*
* Copyright (C) 2008 Thomas Frauendorfer
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef __XCollection_H__
#define __XCollection_H__
#include "xclient.h"
#include <QObject>
class QString;
class QStringList;
class XCollection : public QObject
{
Q_OBJECT
public:
XCollection (XClient *client);
QStringList list (QString ns = "Playlists");
bool setActivePlaylist (QString name);
bool addIdlist (QString name);
bool remove (QString name, QString ns);
signals:
void collectionModified (QString collection, QString ns, int type,
QString newname);
protected slots:
void on_connect (XClient *);
private:
bool on_collection_modified (const Xmms::Dict &value);
bool handle_playlists_list (const Xmms::List< std::string > &list);
XClient *m_client;
QStringList m_playlists;
};
#endif

View file

@ -49,7 +49,7 @@ XConfig::value_get (QString key)
bool
XConfig::value_set (QString key, QString val)
{
/* Only send change request to server here
/* Only send change request to server from here
* update of local cache will be done through handle_config_value_changed
*/
if (!m_client->isConnected ()) {