OTHER: Use Xmms::*Dict instead of QHash for various functions.
This commit is contained in:
parent
f16efc80e3
commit
c98cadb1f2
10 changed files with 96 additions and 74 deletions
|
@ -59,8 +59,8 @@ MainDisplay::MainDisplay (QWidget *parent) : SkinDisplay(parent)
|
|||
m_vslider->move (107, 57);
|
||||
|
||||
XMMSHandler &xmmsh = XMMSHandler::getInstance ();
|
||||
connect (&xmmsh, SIGNAL(currentSong (const QHash<QString, QString> &)),
|
||||
this, SLOT(setMediainfo (const QHash<QString, QString> &)));
|
||||
connect (&xmmsh, SIGNAL(currentSong (const Xmms::PropDict &)),
|
||||
this, SLOT(setMediainfo (const Xmms::PropDict &)));
|
||||
connect (&xmmsh, SIGNAL(playbackStatusChanged(Xmms::Playback::Status)),
|
||||
this, SLOT(setStatus(Xmms::Playback::Status)));
|
||||
connect (&xmmsh, SIGNAL(playtimeChanged(uint)),
|
||||
|
@ -123,24 +123,34 @@ MainDisplay::setPlaytime (uint time)
|
|||
}
|
||||
|
||||
void
|
||||
MainDisplay::setMediainfo (const QHash<QString, QString> &h)
|
||||
MainDisplay::setMediainfo (const Xmms::PropDict &info)
|
||||
{
|
||||
QString n;
|
||||
if (h.contains ("artist") && h.contains ("album") && h.contains ("title")) {
|
||||
n = h.value("artist") + " - " + h.value("album") + " - " + h.value("title");
|
||||
if (info.contains ("artist") && info.contains ("album") &&
|
||||
info.contains ("title")) {
|
||||
n = QString::fromUtf8 (info.get<std::string> ("artist").c_str ())
|
||||
+ " - " +
|
||||
QString::fromUtf8 (info.get<std::string> ("album").c_str ())
|
||||
+ " - " +
|
||||
QString::fromUtf8 (info.get<std::string> ("title").c_str ());
|
||||
} else {
|
||||
n = h.value("url");
|
||||
n = QString::fromUtf8 (info.get<std::string> ("url").c_str ());
|
||||
}
|
||||
m_text->setText (n);
|
||||
|
||||
m_kbps->setNumber (h.value("bitrate").toUInt()/1000, 3);
|
||||
m_khz->setNumber (h.value("samplerate").toUInt()/1000, 2);
|
||||
if (h.value("channels:in").toUInt() > 1) {
|
||||
m_kbps->setNumber (info.get<uint32_t> ("bitrate")/1000, 3);
|
||||
if (info.contains ("samplerate")) {
|
||||
m_khz->setNumber (info.get<uint32_t> ("samplerate")/1000, 2);
|
||||
} else {
|
||||
m_khz->setNumber(0, 1);
|
||||
}
|
||||
if (info.contains ("channels:in") &&
|
||||
info.get<uint32_t> ("channels:in") > 1) {
|
||||
m_stereo->setStereoMono (1, 0);
|
||||
} else {
|
||||
m_stereo->setStereoMono (0, 1);
|
||||
}
|
||||
m_slider->setMax (h.value("duration").toUInt());
|
||||
m_slider->setMax (info.get<uint32_t> ("duration"));
|
||||
m_slider->hideBar (false);
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ class MainDisplay : public SkinDisplay
|
|||
void setPixmaps(Skin *skin);
|
||||
void setStatus (Xmms::Playback::Status status);
|
||||
void setPlaytime (uint time);
|
||||
void setMediainfo (const QHash<QString,QString> &);
|
||||
void setMediainfo (const Xmms::PropDict &);
|
||||
void togglePL(void);
|
||||
void toggleTime(void);
|
||||
|
||||
|
|
|
@ -81,11 +81,11 @@ PlaylistList::PlaylistList (QWidget *parent) : QWidget (parent)
|
|||
connect (&xmmsh, SIGNAL(currentID(uint)),
|
||||
this, SLOT(currentID(uint)));
|
||||
|
||||
connect (&xmmsh, SIGNAL(mediainfoChanged(uint, const QHash<QString, QString> &)),
|
||||
this, SLOT(mediainfoChanged(uint, const QHash<QString, QString> &)));
|
||||
connect (&xmmsh, SIGNAL(mediainfoChanged(uint, const Xmms::PropDict &)),
|
||||
this, SLOT(mediainfoChanged(uint, const Xmms::PropDict &)));
|
||||
|
||||
connect (&xmmsh, SIGNAL(playlistChanged(const QHash<QString, QString> &)),
|
||||
this, SLOT(playlistChanged(const QHash<QString, QString> &)));
|
||||
connect (&xmmsh, SIGNAL(playlistChanged(const Xmms::Dict &)),
|
||||
this, SLOT(playlistChanged(const Xmms::Dict &)));
|
||||
|
||||
connect (&xmmsh, SIGNAL(playbackStatusChanged(Xmms::Playback::Status)),
|
||||
this, SLOT(setStatus(Xmms::Playback::Status)));
|
||||
|
@ -114,14 +114,14 @@ PlaylistList::setStatus (Xmms::Playback::Status s)
|
|||
}
|
||||
|
||||
void
|
||||
PlaylistList::playlistChanged (const QHash<QString,QString> &h)
|
||||
PlaylistList::playlistChanged (const Xmms::Dict &change)
|
||||
{
|
||||
int signal = h.value("type").toUInt();
|
||||
uint signal = change.get<uint32_t> ("type");
|
||||
XMMSHandler &xmmsh = XMMSHandler::getInstance ();
|
||||
switch (signal) {
|
||||
case XMMS_PLAYLIST_CHANGED_ADD:
|
||||
{
|
||||
uint id = h.value("id").toUInt();
|
||||
uint id = change.get<uint32_t> ("id");
|
||||
if (m_itemmap->contains (id)) {
|
||||
addItem (m_itemmap->value (id));
|
||||
} else {
|
||||
|
@ -131,8 +131,8 @@ PlaylistList::playlistChanged (const QHash<QString,QString> &h)
|
|||
break;
|
||||
case XMMS_PLAYLIST_CHANGED_INSERT:
|
||||
{
|
||||
uint id = h.value("id").toUInt ();
|
||||
uint pos = h.value("position").toUInt ();
|
||||
uint id = change.get<uint32_t> ("id");
|
||||
uint pos = change.get<uint32_t> ("position");
|
||||
|
||||
if (m_itemmap->contains (id)) {
|
||||
addItem (m_itemmap->value (id));
|
||||
|
@ -144,7 +144,7 @@ PlaylistList::playlistChanged (const QHash<QString,QString> &h)
|
|||
break;
|
||||
case XMMS_PLAYLIST_CHANGED_REMOVE:
|
||||
{
|
||||
int pos = h.value("position").toUInt();
|
||||
uint pos = change.get<uint32_t> ("position");
|
||||
PlaylistItem *i = m_items->value (pos);
|
||||
|
||||
if (!i) {
|
||||
|
@ -210,28 +210,36 @@ PlaylistList::currentID (uint id)
|
|||
}
|
||||
|
||||
void
|
||||
PlaylistList::mediainfoChanged (uint id, const QHash<QString, QString> &h)
|
||||
PlaylistList::mediainfoChanged (uint id, const Xmms::PropDict &info)
|
||||
{
|
||||
PlaylistItem *i = m_itemmap->value (id);
|
||||
if (i) {
|
||||
QString n;
|
||||
if (h.contains ("artist") && h.contains ("album") && h.contains ("title")) {
|
||||
n = h.value("artist") + " - " + h.value("album") + " - " + h.value("title");
|
||||
if (info.contains ("artist") && info.contains ("album") &&
|
||||
info.contains ("title")) {
|
||||
n = QString::fromUtf8 (info.get<std::string> ("artist").c_str ())
|
||||
+ " - " +
|
||||
QString::fromUtf8 (info.get<std::string> ("album").c_str ())
|
||||
+ " - " +
|
||||
QString::fromUtf8 (info.get<std::string> ("title").c_str ());
|
||||
} else if (info.contains ("channel")) {
|
||||
n = QString::fromUtf8 (info.get<std::string> ("channel").c_str ())
|
||||
+ " - " +
|
||||
QString::fromUtf8 (info.get<std::string> ("title").c_str ());
|
||||
} else {
|
||||
if (h.contains ("channel")) {
|
||||
n = h.value("channel") + " - " + h.value("title");
|
||||
} else {
|
||||
QString t = h.value("url");
|
||||
n = t.section ("/", -1);
|
||||
}
|
||||
n = QString::fromUtf8 (info.get<std::string> ("url").c_str ());
|
||||
n = n.section ("/", -1);
|
||||
}
|
||||
|
||||
i->setText (n);
|
||||
if (h.contains ("duration")) {
|
||||
int d = h.value("duration").toInt();
|
||||
|
||||
if (info.contains ("duration")) {
|
||||
unsigned int duration = info.get<uint32_t> ("duration");
|
||||
QString dur;
|
||||
dur.sprintf ("%02d:%02d", d/60000, (d/1000)%60);
|
||||
dur.sprintf ("%02d:%02d", duration/60000, (duration/1000)%60);
|
||||
i->setDuration (dur);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
update ();
|
||||
|
|
|
@ -27,8 +27,8 @@ class PlaylistList : public QWidget {
|
|||
public slots:
|
||||
void setPixmaps (Skin *skin);
|
||||
void playlistList (const QList<uint> &);
|
||||
void mediainfoChanged (uint, const QHash<QString,QString> &);
|
||||
void playlistChanged (const QHash<QString,QString> &);
|
||||
void mediainfoChanged (uint, const Xmms::PropDict &);
|
||||
void playlistChanged (const Xmms::Dict &);
|
||||
void currentID (uint);
|
||||
void setStatus (Xmms::Playback::Status s);
|
||||
void settingsSaved ();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "XMMSHandler.h"
|
||||
#include <xmmsclient/xmmsclient++.h>
|
||||
|
||||
#include "PlaylistShade.h"
|
||||
#include "Playlist.h"
|
||||
|
@ -18,8 +19,8 @@ PlaylistShade::PlaylistShade (QWidget *parent) : QWidget (parent)
|
|||
connect (skin, SIGNAL (skinChanged (Skin *)),
|
||||
this, SLOT (setPixmaps(Skin *)));
|
||||
|
||||
connect (&xmmsh, SIGNAL(currentSong (QHash<QString, QString>)),
|
||||
this, SLOT(setMediainfo (QHash<QString, QString>)));
|
||||
connect (&xmmsh, SIGNAL(currentSong (const Xmms::PropDict &)),
|
||||
this, SLOT(setMediainfo (const Xmms::PropDict &)));
|
||||
|
||||
connect (&xmmsh, SIGNAL(settingsSaved ()),
|
||||
this, SLOT(settingsSaved ()));
|
||||
|
@ -37,13 +38,18 @@ PlaylistShade::settingsSaved ()
|
|||
}
|
||||
|
||||
void
|
||||
PlaylistShade::setMediainfo (QHash<QString, QString> h)
|
||||
PlaylistShade::setMediainfo (const Xmms::PropDict &info)
|
||||
{
|
||||
QString n;
|
||||
if (h.contains ("artist") && h.contains ("album") && h.contains ("title")) {
|
||||
n = h.value("artist") + " - " + h.value("album") + " - " + h.value("title");
|
||||
if (info.contains ("artist") && info.contains ("album") &&
|
||||
info.contains ("title")) {
|
||||
n = QString::fromUtf8 (info.get<std::string> ("artist").c_str ())
|
||||
+ " - " +
|
||||
QString::fromUtf8 (info.get<std::string> ("album").c_str ())
|
||||
+ " - " +
|
||||
QString::fromUtf8 (info.get<std::string> ("title").c_str ());
|
||||
} else {
|
||||
n = h.value("url");
|
||||
n = QString::fromUtf8 (info.get<std::string> ("url").c_str ());
|
||||
}
|
||||
m_text = (n);
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef __PLAYLISTSHADE_H__
|
||||
#define __PLAYLISTSHADE_H__
|
||||
|
||||
#include <xmmsclient/xmmsclient++.h>
|
||||
#include "Skin.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
@ -19,7 +20,7 @@ class PlaylistShade : public QWidget {
|
|||
|
||||
public slots:
|
||||
void setPixmaps (Skin *skin);
|
||||
void setMediainfo (QHash<QString, QString> h);
|
||||
void setMediainfo (const Xmms::PropDict &info);
|
||||
void settingsSaved ();
|
||||
|
||||
private:
|
||||
|
|
|
@ -63,18 +63,23 @@ ShadedDisplay::ShadedDisplay (QWidget *parent) : SkinDisplay (parent)
|
|||
this, SLOT(setStatus(Xmms::Playback::Status)));
|
||||
connect (&xmmsh, SIGNAL(playtimeChanged(uint)),
|
||||
this, SLOT(setPlaytime(uint)));
|
||||
connect (&xmmsh, SIGNAL(currentSong (const QHash<QString, QString> &)),
|
||||
this, SLOT(setMediainfo (const QHash<QString, QString> &)));
|
||||
connect (&xmmsh, SIGNAL(currentSong (const Xmms::PropDict &)),
|
||||
this, SLOT(setMediainfo (const Xmms::PropDict &)));
|
||||
}
|
||||
|
||||
void
|
||||
ShadedDisplay::setMediainfo (const QHash<QString, QString> &h)
|
||||
ShadedDisplay::setMediainfo (const Xmms::PropDict &info)
|
||||
{
|
||||
QString n;
|
||||
if (h.contains ("artist") && h.contains ("album") && h.contains ("title")) {
|
||||
n = h.value("artist") + " - " + h.value("album") + " - " + h.value("title");
|
||||
if (info.contains ("artist") && info.contains ("album") &&
|
||||
info.contains ("title")) {
|
||||
n = QString::fromUtf8 (info.get<std::string> ("artist").c_str ())
|
||||
+ " - " +
|
||||
QString::fromUtf8 (info.get<std::string> ("album").c_str ())
|
||||
+ " - " +
|
||||
QString::fromUtf8 (info.get<std::string> ("title").c_str ());
|
||||
} else {
|
||||
n = h.value("url");
|
||||
n = QString::fromUtf8 (info.get<std::string> ("url").c_str ());
|
||||
}
|
||||
m_title->setText (n);
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ class ShadedDisplay : public SkinDisplay
|
|||
public slots:
|
||||
void setStatus (Xmms::Playback::Status status);
|
||||
void setPlaytime (uint time);
|
||||
void setMediainfo (const QHash<QString, QString> &h);
|
||||
void setMediainfo (const Xmms::PropDict &info);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include "XmmsQT4.h"
|
||||
#include "XMMSHandler.h"
|
||||
#include <iostream>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
|
@ -179,13 +178,13 @@ XMMSHandler::DictToQHash (const std::string &key,
|
|||
const Xmms::Dict::Variant &value,
|
||||
QHash<QString, QString> &hash)
|
||||
{
|
||||
if (value.type () == typeid (int)) {
|
||||
if (value.type () == typeid (int32_t)) {
|
||||
hash.insert (QString::fromLatin1 (key.c_str ()),
|
||||
QString::number (boost::get< int > (value)));
|
||||
} else if (value.type () == typeid (unsigned int)) {
|
||||
QString::number (boost::get< int32_t > (value)));
|
||||
} else if (value.type () == typeid (uint32_t)) {
|
||||
hash.insert (QString::fromLatin1 (key.c_str ()),
|
||||
QString::number (boost::get< unsigned int > (value)));
|
||||
} else if (value.type () == typeid (unsigned int)) {
|
||||
QString::number (boost::get< uint32_t > (value)));
|
||||
} else if (value.type () == typeid (std::string)) {
|
||||
hash.insert (QString::fromLatin1 (key.c_str ()),
|
||||
QString::fromUtf8 (boost::get< std::string > (value).c_str ()));
|
||||
}
|
||||
|
@ -197,12 +196,12 @@ XMMSHandler::PropDictToQHash (const std::string &key,
|
|||
const std::string &source,
|
||||
QHash<QString, QString> &hash)
|
||||
{
|
||||
if (value.type () == typeid (int)) {
|
||||
if (value.type () == typeid (int32_t)) {
|
||||
hash.insert (QString::fromLatin1 (key.c_str ()),
|
||||
QString::number (boost::get< int > (value)));
|
||||
} else if (value.type () == typeid (unsigned int)) {
|
||||
QString::number (boost::get< int32_t > (value)));
|
||||
} else if (value.type () == typeid (uint32_t)) {
|
||||
hash.insert (QString::fromLatin1 (key.c_str ()),
|
||||
QString::number (boost::get< unsigned int > (value)));
|
||||
QString::number (boost::get< uint32_t > (value)));
|
||||
} else {
|
||||
hash.insert (QString::fromLatin1 (key.c_str ()),
|
||||
QString::fromUtf8 (boost::get< std::string > (value).c_str()));
|
||||
|
@ -235,25 +234,18 @@ XMMSHandler::medialib_select (XMMSResultDictList *res)
|
|||
bool
|
||||
XMMSHandler::playlist_changed (const Xmms::Dict &list)
|
||||
{
|
||||
QHash<QString, QString> hash;
|
||||
list.each (boost::bind (&XMMSHandler::DictToQHash, this,
|
||||
_1, _2, boost::ref (hash)));
|
||||
emit playlistChanged (hash);
|
||||
emit playlistChanged (list);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
XMMSHandler::medialib_info (const Xmms::PropDict &propdict)
|
||||
{
|
||||
|
||||
QHash<QString, QString> hash;
|
||||
propdict.each (boost::bind (&XMMSHandler::PropDictToQHash, this,
|
||||
_1, _2, _3, boost::ref (hash)));
|
||||
unsigned int id = propdict.get<int>("id");
|
||||
emit mediainfoChanged (id, hash);
|
||||
unsigned int id = propdict.get<uint32_t>("id");
|
||||
emit mediainfoChanged (id, propdict);
|
||||
|
||||
if (id == m_currentid) {
|
||||
emit currentSong (hash);
|
||||
emit currentSong (propdict);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -65,11 +65,11 @@ class XMMSHandler : public QObject {
|
|||
void settingsSaved ();
|
||||
void playbackStatusChanged (Xmms::Playback::Status status);
|
||||
void playtimeChanged (uint time);
|
||||
void mediainfoChanged (uint, const QHash<QString, QString> &);
|
||||
void currentSong (const QHash<QString, QString> &);
|
||||
void mediainfoChanged (uint, const Xmms::PropDict &);
|
||||
void currentSong (const Xmms::PropDict &);
|
||||
void playlistList (const QList<uint> &);
|
||||
void currentID (uint);
|
||||
void playlistChanged (const QHash<QString, QString> &);
|
||||
void playlistChanged (const Xmms::Dict &);
|
||||
/*
|
||||
void medialibResponse (uint, const QList<QHash<QString, QString> > &);
|
||||
*/
|
||||
|
@ -93,7 +93,7 @@ class XMMSHandler : public QObject {
|
|||
bool volume_error (const std::string &error);
|
||||
|
||||
XmmsQT4 *m_qt4;
|
||||
int m_currentid;
|
||||
unsigned int m_currentid;
|
||||
bool m_masterchan;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue