1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
#include <xmmsclient/xmmsclient++.h>
#include <QObject>
#include <QHash>
#include <QVariant>
#include <QErrorMessage>
#include <QSettings>
#include "xclient.h"
#include "xmmsqt4.h"
XSettings::XSettings (QObject *parent) : QObject (parent)
{
/* dummy */
}
void
XSettings::change_settings ()
{
emit settingsChanged ();
}
bool XClient::log ()
{
return false;
}
XClient::XClient (QObject *parent, const std::string &name) : QObject (parent), Xmms::Client (name)
{
m_cache = new XMediainfoCache (this, this);
m_settings = new XSettings (this);
}
bool
XClient::connect (const std::string &ipcpath)
{
bool tried_once = false;
try_again:
try {
Xmms::Client::connect (ipcpath);
}
catch (Xmms::connection_error& e) {
if (ipcpath == "" && !tried_once) {
QSettings s;
if (s.value ("core/autostart", true).toBool ()) {
if (!system ("xmms2-launcher")) {
tried_once = true;
goto try_again;
}
}
}
QErrorMessage *err = new QErrorMessage ();
err->showMessage ("Couldn't connect to XMMS2, please try again.");
err->exec ();
delete err;
return false;
}
setMainloop (new XmmsQT4 (getConnection ()));
emit gotConnection (this);
return true;
}
void
XClient::propDictToQHash (const std::string &key,
const Xmms::Dict::Variant &value,
const std::string &source,
QHash<QString, QVariant> &hash)
{
if (value.type () == typeid (int32_t)) {
hash.insert (QString::fromLatin1 (key.c_str ()),
QVariant (boost::get< int32_t > (value)));
} else if (value.type () == typeid (uint32_t)) {
hash.insert (QString::fromLatin1 (key.c_str ()),
QVariant (boost::get< uint32_t > (value)));
} else {
QString val = QString::fromUtf8 (boost::get< std::string > (value).c_str ());
if (key == "url") {
val = val.mid (val.lastIndexOf ("/") + 1);
}
hash.insert (QString::fromLatin1 (key.c_str ()),
QVariant (val));
}
}
QHash<QString, QVariant>
XClient::convert_propdict (const Xmms::PropDict &dict)
{
QHash<QString, QVariant> hash;
dict.each (boost::bind (&XClient::propDictToQHash,
_1, _2, _3, boost::ref (hash)));
return hash;
}
|