OTHER: Handle source preferences correctly
This is done through some ugly hack, that will have to exist until xmms2d or the c++ bindings make things easier for us client developers ;-)
This commit is contained in:
parent
1fe1c8f9be
commit
d4cb52ecd9
4 changed files with 120 additions and 2 deletions
|
@ -27,6 +27,7 @@ HEADERS += xclient.h \
|
||||||
xcollection_p.h \
|
xcollection_p.h \
|
||||||
playlistmodel.h \
|
playlistmodel.h \
|
||||||
xmmsqt4.h \
|
xmmsqt4.h \
|
||||||
|
sourcepref.h \
|
||||||
debug.h
|
debug.h
|
||||||
|
|
||||||
QT += network
|
QT += network
|
||||||
|
|
78
lib/sourcepref.h
Normal file
78
lib/sourcepref.h
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
/**
|
||||||
|
* This file is a part of Promoe, an XMMS2 Client.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2008 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file contains a hack to be able to honor source preferences when
|
||||||
|
* converting a Propdicts to a QHash<QString, QVariant>.
|
||||||
|
* It is only included in xclient.cpp and only used internally in that class
|
||||||
|
*
|
||||||
|
* The limitations that make this file necessary will be fixed with Coll2. So
|
||||||
|
* this file can be removed as soon as Coll2 reaches xmms2-stabe
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Minor note: At the time of writing this file, Coll2 wasn't in -devel, so
|
||||||
|
* this might still take some time
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SOURCEPREF__
|
||||||
|
#define __SOURCEPREF__
|
||||||
|
|
||||||
|
#include <xmmsclient/xmmsclient++/dict.h>
|
||||||
|
|
||||||
|
#include <QList>
|
||||||
|
#include <QRegExp>
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This class is used to get the source preference from a propdict as a
|
||||||
|
* QList<QRegExp>.
|
||||||
|
*/
|
||||||
|
class MyPropDict : public Xmms::PropDict
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MyPropDict (const Xmms::PropDict &d) : PropDict (d) {}
|
||||||
|
|
||||||
|
QList<QRegExp> getSourcePreference () {
|
||||||
|
const char **sourcepref =
|
||||||
|
xmmsc_result_source_preference_get (result_);
|
||||||
|
QList<QRegExp> prio_list;
|
||||||
|
|
||||||
|
for (; *sourcepref; ++sourcepref) {
|
||||||
|
prio_list.append (QRegExp (*sourcepref,
|
||||||
|
Qt::CaseSensitive,
|
||||||
|
QRegExp::Wildcard));
|
||||||
|
}
|
||||||
|
|
||||||
|
return prio_list;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
getPriority (const QString source, const QList<QRegExp> prio_list) {
|
||||||
|
for (int i=0; i < prio_list.size (); ++i) {
|
||||||
|
if (prio_list[i].exactMatch (source))
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If source doesn't match any expression in prio_list return an invalid
|
||||||
|
// value. (The biggest valid value is prio_list.length () -1 )
|
||||||
|
// In that case, the caller should not use the value corresponding with
|
||||||
|
// this source
|
||||||
|
return prio_list.size ();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -31,6 +31,8 @@
|
||||||
#include "xmmsqt4.h"
|
#include "xmmsqt4.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
|
#include "sourcepref.h"
|
||||||
|
|
||||||
QString
|
QString
|
||||||
XClient::stdToQ (const std::string &str)
|
XClient::stdToQ (const std::string &str)
|
||||||
{
|
{
|
||||||
|
@ -186,8 +188,29 @@ void
|
||||||
XClient::propDictToQHash (const std::string &key,
|
XClient::propDictToQHash (const std::string &key,
|
||||||
const Xmms::Dict::Variant &value,
|
const Xmms::Dict::Variant &value,
|
||||||
const std::string &source,
|
const std::string &source,
|
||||||
|
#ifdef SOURCEPREF_HACK
|
||||||
|
const QList<QRegExp> &prio_list,
|
||||||
|
QHash<QString, int> &curr_prio,
|
||||||
|
#endif
|
||||||
QHash<QString, QVariant> &hash)
|
QHash<QString, QVariant> &hash)
|
||||||
{
|
{
|
||||||
|
#ifdef SOURCEPREF_HACK
|
||||||
|
// braces because of tmp_prio definition
|
||||||
|
{
|
||||||
|
int tmp_prio = getPriority (QString::fromStdString (source), prio_list);
|
||||||
|
QString tmp_key = QString::fromStdString (key);
|
||||||
|
// Don't add a new value if the priority of it isn't better than the
|
||||||
|
// priority already present in hash. If there is no "*" source
|
||||||
|
// preference, this also get's rid of values we don't want at all
|
||||||
|
if (tmp_prio >= curr_prio.value (tmp_key, prio_list.size ()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Set the priority of the current source-key combination for the key, so
|
||||||
|
// that we do not overwrite our value with a worse source for this key.
|
||||||
|
// (higher priority values are worse)
|
||||||
|
curr_prio[tmp_key] = tmp_prio;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if (value.type () == typeid (int32_t)) {
|
if (value.type () == typeid (int32_t)) {
|
||||||
hash.insert (QString::fromLatin1 (key.c_str ()),
|
hash.insert (QString::fromLatin1 (key.c_str ()),
|
||||||
QVariant (boost::get< int32_t > (value)));
|
QVariant (boost::get< int32_t > (value)));
|
||||||
|
@ -220,8 +243,18 @@ QHash<QString, QVariant>
|
||||||
XClient::convert_propdict (const Xmms::PropDict &dict)
|
XClient::convert_propdict (const Xmms::PropDict &dict)
|
||||||
{
|
{
|
||||||
QHash<QString, QVariant> hash;
|
QHash<QString, QVariant> hash;
|
||||||
|
#ifdef SOURCEPREF_HACK
|
||||||
|
MyPropDict d (dict);
|
||||||
|
QList<QRegExp> priolist = d.getSourcePreference ();
|
||||||
|
QHash<QString, int> curr_prio;
|
||||||
|
#endif
|
||||||
dict.each (boost::bind (&XClient::propDictToQHash,
|
dict.each (boost::bind (&XClient::propDictToQHash,
|
||||||
_1, _2, _3, boost::ref (hash)));
|
_1, _2, _3,
|
||||||
|
#ifdef SOURCEPREF_HACK
|
||||||
|
boost::ref (priolist),
|
||||||
|
boost::ref (curr_prio),
|
||||||
|
#endif
|
||||||
|
boost::ref (hash)));
|
||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
#include <QRegExp>
|
||||||
class QWidget;
|
class QWidget;
|
||||||
|
|
||||||
class XClientCache;
|
class XClientCache;
|
||||||
|
@ -30,6 +31,7 @@ class XConfig;
|
||||||
class XPlayback;
|
class XPlayback;
|
||||||
class XCollection;
|
class XCollection;
|
||||||
|
|
||||||
|
#define SOURCEPREF_HACK
|
||||||
|
|
||||||
class XClient : public QObject {
|
class XClient : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -41,7 +43,11 @@ class XClient : public QObject {
|
||||||
static void propDictToQHash (const std::string &key,
|
static void propDictToQHash (const std::string &key,
|
||||||
const Xmms::Dict::Variant &value,
|
const Xmms::Dict::Variant &value,
|
||||||
const std::string &source,
|
const std::string &source,
|
||||||
QHash<QString, QVariant> &hash);
|
#ifdef SOURCEPREF_HACK
|
||||||
|
const QList<QRegExp> &priolist,
|
||||||
|
QHash<QString, int> &curr_prio,
|
||||||
|
#endif
|
||||||
|
QHash<QString, QVariant> &hash);
|
||||||
|
|
||||||
static void dictToQHash (const std::string &key,
|
static void dictToQHash (const std::string &key,
|
||||||
const Xmms::Dict::Variant &value,
|
const Xmms::Dict::Variant &value,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue