From cbb6ed1d15c389e9f15506d110bfd1153b07bdc9 Mon Sep 17 00:00:00 2001 From: Thomas Frauendorfer Date: Wed, 10 Oct 2007 16:46:16 +0200 Subject: [PATCH] Implement a XSettings Class as interface to xmms2d's serverside config --- lib/lib.pro | 2 ++ lib/xclient.cpp | 6 ++-- lib/xclient.h | 3 ++ lib/xsettings.cpp | 67 +++++++++++++++++++++++++++++++++++++++++++++ lib/xsettings.h | 51 ++++++++++++++++++++++++++++++++++ src/XMMSHandler.cpp | 8 ------ 6 files changed, 127 insertions(+), 10 deletions(-) create mode 100644 lib/xsettings.cpp create mode 100644 lib/xsettings.h diff --git a/lib/lib.pro b/lib/lib.pro index 480ec93..efbd664 100644 --- a/lib/lib.pro +++ b/lib/lib.pro @@ -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 diff --git a/lib/xclient.cpp b/lib/xclient.cpp index c7d7fb5..f1a44fe 100644 --- a/lib/xclient.cpp +++ b/lib/xclient.cpp @@ -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; } diff --git a/lib/xclient.h b/lib/xclient.h index 5036e15..ef34b3e 100644 --- a/lib/xclient.h +++ b/lib/xclient.h @@ -29,7 +29,9 @@ class XClient; #include #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 diff --git a/lib/xsettings.cpp b/lib/xsettings.cpp new file mode 100644 index 0000000..936f7d4 --- /dev/null +++ b/lib/xsettings.cpp @@ -0,0 +1,67 @@ +#include + +#include "xsettings.h" + +#include + +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 tmp = XClient::convert_dict(value); + + QHash::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; +} diff --git a/lib/xsettings.h b/lib/xsettings.h new file mode 100644 index 0000000..8f727d4 --- /dev/null +++ b/lib/xsettings.h @@ -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 +#include +#include + +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 diff --git a/src/XMMSHandler.cpp b/src/XMMSHandler.cpp index aebfdc4..cd46487 100644 --- a/src/XMMSHandler.cpp +++ b/src/XMMSHandler.cpp @@ -14,11 +14,6 @@ #include #include -static bool log ( /*const std::string& text = ""*/ ) -{ - return false; -} - XMMSHandler &XMMSHandler::getInstance () { 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); 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->playback.currentID () (bind (&XMMSHandler::playback_current_id, this));