diff --git a/lib/compat.h b/lib/compat.h new file mode 100644 index 0000000..b4d21b0 --- /dev/null +++ b/lib/compat.h @@ -0,0 +1,61 @@ +/** + * This file is a part of Esperanza, an XMMS2 Client. + * + * Copyright (C) 2005-2007 XMMS2 Team + * + * 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 __COMPAT_H__ +#define __COMPAT_H__ + +#ifdef HAVE_XMMSV +#undef HAVE_XMMSV +#define HAVE_XMMSV 1 +#else +#include +#define HAVE_XMMSV (XMMS_IPC_PROTOCOL_VERSION >= 13) +#endif + +#include +#include + +#if HAVE_XMMSV +#include +#include +#endif + +inline QString +decodeXmmsUrl (const QString &path) +{ + QByteArray p_enc = path.toUtf8 (); +#if HAVE_XMMSV + // TODO: error checking... + xmmsv_t *v_enc = xmmsv_new_string (p_enc.constData ()); + xmmsv_t *p_dec = xmmsv_decode_url (v_enc); + xmmsv_unref (v_enc); + const char *p; + unsigned int p_len; + xmmsv_get_bin (p_dec, reinterpret_cast(&p), &p_len); + QString ret = QString::fromUtf8 (p, p_len); + xmmsv_unref (p_dec); + // Free p? + return ret; +#else + char *p_dec = const_cast (xmmsc_result_decode_url (NULL, p_enc.constData ())); + return QString::fromUtf8 (p_dec); + free (p_dec); +#endif +} + + +#endif diff --git a/lib/lib.pro b/lib/lib.pro index b0830a6..087321c 100644 --- a/lib/lib.pro +++ b/lib/lib.pro @@ -28,6 +28,7 @@ HEADERS += xclient.h \ playlistmodel.h \ xmmsqt4.h \ sourcepref.h \ + compat.h \ debug.h QT += network diff --git a/lib/xclient.cpp b/lib/xclient.cpp index a4aee6a..f182467 100644 --- a/lib/xclient.cpp +++ b/lib/xclient.cpp @@ -14,8 +14,8 @@ * GNU General Public License for more details. */ - #include +#include "compat.h" #include #include @@ -32,7 +32,11 @@ #include "debug.h" #include "playlistmodel.h" +#if !HAVE_XMMSV #include "sourcepref.h" +#endif + +#include QString XClient::stdToQ (const std::string &str) @@ -222,14 +226,16 @@ XClient::propDictToQHash (const std::string &key, } else { QString val; if (key == "url") { - /* This really is wrong ...*/ - char *c = const_cast(xmmsc_result_decode_url (NULL, boost::get< std::string >(value).c_str ())); - val = QString::fromUtf8 (c); - val = val.mid (val.lastIndexOf ("/") + 1); + QString tmp = QString::fromUtf8 (boost::get< std::string >(value).c_str ()); +#if 0 + val = decodeXmmsUrl (tmp); +#else + tmp = decodeXmmsUrl (tmp); + val = tmp.mid (tmp.lastIndexOf ("/") + 1); if (val.isEmpty ()) { - val = QString::fromUtf8 (c); + val = tmp; } - free (c); +#endif } else { val = QString::fromUtf8 (boost::get< std::string > (value).c_str ()); } diff --git a/lib/xclient.h b/lib/xclient.h index d0fcfc7..0c8d42e 100644 --- a/lib/xclient.h +++ b/lib/xclient.h @@ -19,6 +19,7 @@ #define __XCLIENT_H__ #include +#include "compat.h" #include #include @@ -33,6 +34,10 @@ class XCollection; class PlaylistModel; #define SOURCEPREF_HACK +// Doesn't work for XMMSV yet +#if HAVE_XMMSV +#undef SOURCEPREF_HACK +#endif class XClient : public QObject { Q_OBJECT diff --git a/src/BrowseModel.cpp b/src/BrowseModel.cpp index caf3b2d..101bdb1 100644 --- a/src/BrowseModel.cpp +++ b/src/BrowseModel.cpp @@ -128,11 +128,8 @@ BrowseModel::list_cb (const Xmms::List< Xmms::Dict > &res) } name += QString::fromStdString (d.get ("title")); } else { - const char *tmp; QString tmp2 = path.mid (path.lastIndexOf ("/")+1); - tmp = xmmsc_result_decode_url (NULL, tmp2.toAscii ()); - name = QString::fromUtf8 (tmp); - free ((char *)tmp); + name = decodeXmmsUrl (tmp2); } }