Implement a XSettings Class as interface to xmms2d's serverside config
This commit is contained in:
parent
778d828db8
commit
cbb6ed1d15
6 changed files with 127 additions and 10 deletions
|
@ -4,12 +4,14 @@ include (../config.pri)
|
||||||
|
|
||||||
SOURCES += xclient.cpp \
|
SOURCES += xclient.cpp \
|
||||||
xclientcache.cpp \
|
xclientcache.cpp \
|
||||||
|
xsettings.cpp \
|
||||||
playlistmodel.cpp \
|
playlistmodel.cpp \
|
||||||
xmmsqt4.cpp
|
xmmsqt4.cpp
|
||||||
|
|
||||||
|
|
||||||
HEADERS += xclient.h \
|
HEADERS += xclient.h \
|
||||||
xclientcache.h \
|
xclientcache.h \
|
||||||
|
xsettings.h \
|
||||||
playlistmodel.h \
|
playlistmodel.h \
|
||||||
xmmsqt4.h \
|
xmmsqt4.h \
|
||||||
debug.h
|
debug.h
|
||||||
|
|
|
@ -27,9 +27,10 @@
|
||||||
#include "xmmsqt4.h"
|
#include "xmmsqt4.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
|
/*
|
||||||
XSettings::XSettings (QObject *parent) : QObject (parent)
|
XSettings::XSettings (QObject *parent) : QObject (parent)
|
||||||
{
|
{
|
||||||
/* dummy */
|
// * dummy *
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -37,6 +38,7 @@ XSettings::change_settings ()
|
||||||
{
|
{
|
||||||
emit settingsChanged ();
|
emit settingsChanged ();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
QString
|
QString
|
||||||
XClient::stdToQ (const std::string &str)
|
XClient::stdToQ (const std::string &str)
|
||||||
|
@ -71,7 +73,7 @@ XClient::XClient (QObject *parent, const std::string &name) : QObject (parent),
|
||||||
m_client = NULL;
|
m_client = NULL;
|
||||||
m_isconnected = false;
|
m_isconnected = false;
|
||||||
m_cache = new XClientCache (this, this);
|
m_cache = new XClientCache (this, this);
|
||||||
m_settings = new XSettings (this);
|
m_settings = new XSettings (this, this);
|
||||||
m_name = name;
|
m_name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,9 @@ class XClient;
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
#include "xclientcache.h"
|
#include "xclientcache.h"
|
||||||
|
#include "xsettings.h"
|
||||||
|
|
||||||
|
/*
|
||||||
class XSettings : public QObject
|
class XSettings : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -40,6 +42,7 @@ class XSettings : public QObject
|
||||||
signals:
|
signals:
|
||||||
void settingsChanged ();
|
void settingsChanged ();
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
class XClient : public QObject {
|
class XClient : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
67
lib/xsettings.cpp
Normal file
67
lib/xsettings.cpp
Normal 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
51
lib/xsettings.h
Normal 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
|
|
@ -14,11 +14,6 @@
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
static bool log ( /*const std::string& text = ""*/ )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
XMMSHandler &XMMSHandler::getInstance ()
|
XMMSHandler &XMMSHandler::getInstance ()
|
||||||
{
|
{
|
||||||
static XMMSHandler singleton(NULL, "Prome_Main");
|
static XMMSHandler singleton(NULL, "Prome_Main");
|
||||||
|
@ -54,9 +49,6 @@ XMMSHandler::connect_handler (const char *ipcpath, const bool &sync, QWidget *pa
|
||||||
connect(ipcpath, sync, parent);
|
connect(ipcpath, sync, parent);
|
||||||
|
|
||||||
using Xmms::bind;
|
using Xmms::bind;
|
||||||
// m_client->playlist.listEntries () (bind (&XMMSHandler::playlist_list, this));
|
|
||||||
// m_client->playlist.broadcastChanged () (bind (&XMMSHandler::playlist_changed, this));
|
|
||||||
|
|
||||||
m_client->medialib.broadcastEntryChanged () (bind (&XMMSHandler::medialib_entry_changed, this));
|
m_client->medialib.broadcastEntryChanged () (bind (&XMMSHandler::medialib_entry_changed, this));
|
||||||
|
|
||||||
m_client->playback.currentID () (bind (&XMMSHandler::playback_current_id, this));
|
m_client->playback.currentID () (bind (&XMMSHandler::playback_current_id, this));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue