OTHER: Let promoe enable xmms2d's equalizer plugin

This commit is contained in:
Thomas Frauendorfer 2008-12-03 21:32:58 +01:00
parent c6b75de31d
commit 8b1a61082c
5 changed files with 67 additions and 32 deletions

View file

@ -47,17 +47,17 @@ class XClient : public QObject {
bool connect (const char *path = NULL, const bool &sync = false,
QWidget* parent = NULL);
static void propDictToQHash (const std::string &key,
const Xmms::Dict::Variant &value,
const std::string &source,
const Xmms::Dict::Variant &value,
const std::string &source,
#ifdef SOURCEPREF_HACK
const QList<QRegExp> &priolist,
QHash<QString, int> &curr_prio,
#endif
QHash<QString, QVariant> &hash);
static void dictToQHash (const std::string &key,
const Xmms::Dict::Variant &value,
QHash<QString, QVariant> &hash);
static void dictToQHash (const std::string &key,
const Xmms::Dict::Variant &value,
QHash<QString, QVariant> &hash);
static QHash<QString, QVariant> convert_propdict (const Xmms::PropDict &);
static QHash<QString, QVariant> convert_dict (const Xmms::Dict &);
@ -88,11 +88,11 @@ class XClient : public QObject {
static QString stdToQ (const std::string &);
static std::string qToStd (const QString &);
bool isConnected () const {
return m_isconnected;
};
// static QDir esperanza_dir ();
void setDisconnectCallback (const Xmms::DisconnectCallback::slot_type &slot) { m_client->setDisconnectCallback (slot); }
const Xmms::Collection* collection () { if (m_client && m_client->isConnected ()) return &m_client->collection; else return NULL; }

View file

@ -118,10 +118,13 @@ XConfig::on_disconnect (XClient *client)
bool
XConfig::handle_config_value (const Xmms::Dict &value)
{
// FIXME: I should rework configuration handling, and perhaps I should
// abolish the call to handle_config_value_changed here.
bool ok = handle_config_value_changed (value);
if (ok) {
m_ready = true;
}
emit configLoaded ();
return ok;
}

View file

@ -39,9 +39,13 @@ class XConfig : public QObject
bool value_set (QString key, QString value);
bool value_register (QString key, QString defval);
bool has_key (const QString &key) const
{return m_config_cache.contains (key);};
bool isReady (void) {return m_ready;}
signals:
void configLoaded ();
void configChanged (QString key, QString value);
public slots:

View file

@ -25,6 +25,7 @@
#include "Skin.h"
#include <QPainter>
#include <QMessageBox>
EqualizerSlider::EqualizerSlider (QWidget *parent, int id) :
PixmapSlider (parent)
@ -110,28 +111,13 @@ EqualizerWidget::EqualizerWidget (QWidget *parent) : QWidget (parent)
}
connect (m_xconfig, SIGNAL (configChanged (QString, QString)),
this, SLOT (serverConfigChanged (QString, QString)));
this, SLOT (serverConfigValueChanged (QString, QString)));
// if the config from the server were already loaded, we will only
// receive configChanged signals for values that really change
// so we must request the existing values manually
// we request the config values manually if we already are connected
connect (m_xconfig, SIGNAL (configLoaded ()),
this, SLOT (loadServerConfig ()));
if (m_xconfig->isReady()) {
QString key;
QString value;
// set enabled checkbox
key = QString ("equalizer.enabled");
value = m_xconfig->value_get (key);
serverConfigChanged (key, value);
// set preamp
key = QString ("equalizer.preamp");
value = m_xconfig->value_get (key);
serverConfigChanged (key, value);
// Set band-sliders
for (int i=0; i < 10; i++) {
key = QString ("equalizer.legacy%1").arg(i);
value = m_xconfig->value_get (key);
serverConfigChanged (key, value);
}
loadServerConfig ();
}
}
@ -197,11 +183,51 @@ EqualizerWidget::paintEvent (QPaintEvent *event)
* update the serverconfiguraten if we change something
*/
void
EqualizerWidget::serverConfigChanged (QString key, QString value)
EqualizerWidget::loadServerConfig ()
{
// qDebug (key.toAscii ());
// qDebug (value.toAscii ());
// FIXME: Disable Widget if doesn't get enabled
// TODO: Add 'don't bother me again' checkbox
if (!(m_xconfig->values_get (QRegExp ("effect\\.order\\.\\d+")).
contains ("equalizer"))) {
int button = QMessageBox::information (this, "Equalizer not enabled",
"You need to enable the equalizer plugin on\n" \
"the server or the equalizer will not work\n\n" \
"Should promoe enable the equalizer plugin?",
"Enable", "Ignore");
if (button == 0) {
// Add 'equalizer' to first empty 'effect.order.<num>' entry,
// xmms2d takes care that there alway is at least one empty entry
int i = 0;
QString key = "effect.order.%1";
while (m_xconfig->has_key (key.arg (i))) {
if (m_xconfig->value_get (key.arg (i)).isEmpty ()) {
m_xconfig->value_set (key.arg (i), "equalizer");
break;
}
}
}
}
QString key;
QString value;
// set enabled checkbox
key = QString ("equalizer.enabled");
value = m_xconfig->value_get (key);
serverConfigValueChanged (key, value);
// set preamp
key = QString ("equalizer.preamp");
value = m_xconfig->value_get (key);
serverConfigValueChanged (key, value);
// Set band-sliders
for (int i=0; i < 10; i++) {
key = QString ("equalizer.legacy%1").arg(i);
value = m_xconfig->value_get (key);
serverConfigValueChanged (key, value);
}
}
void
EqualizerWidget::serverConfigValueChanged (QString key, QString value)
{
// FIXME: also test on use_legacy
if (key.startsWith ("equalizer.enabled")) {
if (value != "0") {

View file

@ -59,12 +59,14 @@ class EqualizerWidget : public QWidget
void setPixmaps(Skin *skin);
protected slots:
void serverConfigChanged (QString key, QString value);
void loadServerConfig ();
void serverConfigValueChanged (QString key, QString value);
void setEqualizerEnabled (bool enabled);
void updateServerPreamp (int value);
void updateServerBands (int value, int id);
private:
XConfig *m_xconfig;
QPixmap m_pixmap;
QPixmap m_graph;