Implement a XSettings Class as interface to xmms2d's serverside config

This commit is contained in:
Thomas Frauendorfer 2007-10-10 16:46:16 +02:00
parent 778d828db8
commit cbb6ed1d15
6 changed files with 127 additions and 10 deletions

View file

@ -4,12 +4,14 @@ include (../config.pri)
SOURCES += xclient.cpp \
xclientcache.cpp \
xsettings.cpp \
playlistmodel.cpp \
xmmsqt4.cpp
HEADERS += xclient.h \
xclientcache.h \
xsettings.h \
playlistmodel.h \
xmmsqt4.h \
debug.h

View file

@ -27,9 +27,10 @@
#include "xmmsqt4.h"
#include "debug.h"
/*
XSettings::XSettings (QObject *parent) : QObject (parent)
{
/* dummy */
// * dummy *
}
void
@ -37,6 +38,7 @@ XSettings::change_settings ()
{
emit settingsChanged ();
}
*/
QString
XClient::stdToQ (const std::string &str)
@ -71,7 +73,7 @@ XClient::XClient (QObject *parent, const std::string &name) : QObject (parent),
m_client = NULL;
m_isconnected = false;
m_cache = new XClientCache (this, this);
m_settings = new XSettings (this);
m_settings = new XSettings (this, this);
m_name = name;
}

View file

@ -29,7 +29,9 @@ class XClient;
#include <QWidget>
#include "xclientcache.h"
#include "xsettings.h"
/*
class XSettings : public QObject
{
Q_OBJECT
@ -40,6 +42,7 @@ class XSettings : public QObject
signals:
void settingsChanged ();
};
*/
class XClient : public QObject {
Q_OBJECT

67
lib/xsettings.cpp Normal file
View file

@ -0,0 +1,67 @@
#include <xmmsclient/xmmsclient++.h>
#include "xsettings.h"
#include <QList>
XSettings::XSettings (QObject *parent, XClient *client) : QObject (parent)
{
connect (client, SIGNAL(gotConnection (XClient *)),
this, SLOT (got_connection (XClient *)));
if (client->isConnected ()) {
got_connection (client);
}
}
QString
XSettings::valueGet (QString key)
{
/* local cache should be identical to serverside config */
return m_config_cache.value (key);
}
void
XSettings::valueSet (QString key, QString val)
{
/* Only send change request to server here
* update of local cache will be done through handle_config_value_changed
*/
m_client->config ()->valueSet (key.toStdString (), val.toStdString ());
}
void
XSettings::valueRegister (QString key, QString defval)
{
m_client->config ()->valueRegister (key.toStdString (),
defval.toStdString ());
}
void
XSettings::got_connection (XClient *client)
{
client->config ()->valueList ()
(Xmms::bind (&XSettings::handle_config_value_changed, this));
client->config ()->broadcastValueChanged ()
(Xmms::bind (&XSettings::handle_config_value_changed, this));
m_client = client;
}
bool
XSettings::handle_config_value_changed (const Xmms::Dict &value)
{
QHash <QString, QVariant> tmp = XClient::convert_dict(value);
QHash<QString, QVariant>::const_iterator i = tmp.constBegin ();
while (i != tmp.constEnd ())
{
m_config_cache[i.key ()] = i.value ().toString ();
emit configChanged (i.key (), i.value ().toString ());
i++;
}
// TODO
return true;
}

51
lib/xsettings.h Normal file
View file

@ -0,0 +1,51 @@
/**
* This file is a part of Promoe, an XMMS2 Client
*
* Copyright (C) 2007 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; either version 2
* of the License, or (at your option) any later version.
*
* 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 __XSETTINGS__
#define __XSETTINGS__
class XSettings;
#include "xclient.h"
#include <QObject>
#include <QHash>
#include <QString>
class XSettings : public QObject
{
Q_OBJECT
public:
XSettings (QObject *parent, XClient *client);
QString valueGet (QString key);
void valueSet (QString key, QString value);
void valueRegister (QString key, QString defval);
signals:
void configChanged(QString key, QString value);
public slots:
void got_connection(XClient *);
private:
bool handle_config_value_changed (const Xmms::Dict &value);
QHash < QString, QString > m_config_cache;
XClient *m_client;
};
#endif