From c98cadb1f2393007de434c92b5a79b55d26ed633 Mon Sep 17 00:00:00 2001 From: Jonne Lehtinen Date: Sat, 27 May 2006 18:37:35 +0300 Subject: [PATCH] OTHER: Use Xmms::*Dict instead of QHash for various functions. --- MainDisplay.cpp | 30 ++++++++++++++++++--------- MainDisplay.h | 2 +- PlaylistList.cpp | 52 +++++++++++++++++++++++++++-------------------- PlaylistList.h | 4 ++-- PlaylistShade.cpp | 18 ++++++++++------ PlaylistShade.h | 3 ++- ShadedDisplay.cpp | 17 ++++++++++------ ShadedDisplay.h | 2 +- XMMSHandler.cpp | 34 ++++++++++++------------------- XMMSHandler.h | 8 ++++---- 10 files changed, 96 insertions(+), 74 deletions(-) diff --git a/MainDisplay.cpp b/MainDisplay.cpp index 5d53f26..062734c 100644 --- a/MainDisplay.cpp +++ b/MainDisplay.cpp @@ -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 &)), - this, SLOT(setMediainfo (const QHash &))); + 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 &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 ("artist").c_str ()) + + " - " + + QString::fromUtf8 (info.get ("album").c_str ()) + + " - " + + QString::fromUtf8 (info.get ("title").c_str ()); } else { - n = h.value("url"); + n = QString::fromUtf8 (info.get ("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 ("bitrate")/1000, 3); + if (info.contains ("samplerate")) { + m_khz->setNumber (info.get ("samplerate")/1000, 2); + } else { + m_khz->setNumber(0, 1); + } + if (info.contains ("channels:in") && + info.get ("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 ("duration")); m_slider->hideBar (false); } diff --git a/MainDisplay.h b/MainDisplay.h index 763b425..a3db8eb 100644 --- a/MainDisplay.h +++ b/MainDisplay.h @@ -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 &); + void setMediainfo (const Xmms::PropDict &); void togglePL(void); void toggleTime(void); diff --git a/PlaylistList.cpp b/PlaylistList.cpp index afd1368..6670689 100644 --- a/PlaylistList.cpp +++ b/PlaylistList.cpp @@ -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 &)), - this, SLOT(mediainfoChanged(uint, const QHash &))); + connect (&xmmsh, SIGNAL(mediainfoChanged(uint, const Xmms::PropDict &)), + this, SLOT(mediainfoChanged(uint, const Xmms::PropDict &))); - connect (&xmmsh, SIGNAL(playlistChanged(const QHash &)), - this, SLOT(playlistChanged(const QHash &))); + 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 &h) +PlaylistList::playlistChanged (const Xmms::Dict &change) { - int signal = h.value("type").toUInt(); + uint signal = change.get ("type"); XMMSHandler &xmmsh = XMMSHandler::getInstance (); switch (signal) { case XMMS_PLAYLIST_CHANGED_ADD: { - uint id = h.value("id").toUInt(); + uint id = change.get ("id"); if (m_itemmap->contains (id)) { addItem (m_itemmap->value (id)); } else { @@ -131,8 +131,8 @@ PlaylistList::playlistChanged (const QHash &h) break; case XMMS_PLAYLIST_CHANGED_INSERT: { - uint id = h.value("id").toUInt (); - uint pos = h.value("position").toUInt (); + uint id = change.get ("id"); + uint pos = change.get ("position"); if (m_itemmap->contains (id)) { addItem (m_itemmap->value (id)); @@ -144,7 +144,7 @@ PlaylistList::playlistChanged (const QHash &h) break; case XMMS_PLAYLIST_CHANGED_REMOVE: { - int pos = h.value("position").toUInt(); + uint pos = change.get ("position"); PlaylistItem *i = m_items->value (pos); if (!i) { @@ -210,28 +210,36 @@ PlaylistList::currentID (uint id) } void -PlaylistList::mediainfoChanged (uint id, const QHash &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 ("artist").c_str ()) + + " - " + + QString::fromUtf8 (info.get ("album").c_str ()) + + " - " + + QString::fromUtf8 (info.get ("title").c_str ()); + } else if (info.contains ("channel")) { + n = QString::fromUtf8 (info.get ("channel").c_str ()) + + " - " + + QString::fromUtf8 (info.get ("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 ("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 ("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 (); diff --git a/PlaylistList.h b/PlaylistList.h index 76a5536..8612c80 100644 --- a/PlaylistList.h +++ b/PlaylistList.h @@ -27,8 +27,8 @@ class PlaylistList : public QWidget { public slots: void setPixmaps (Skin *skin); void playlistList (const QList &); - void mediainfoChanged (uint, const QHash &); - void playlistChanged (const QHash &); + void mediainfoChanged (uint, const Xmms::PropDict &); + void playlistChanged (const Xmms::Dict &); void currentID (uint); void setStatus (Xmms::Playback::Status s); void settingsSaved (); diff --git a/PlaylistShade.cpp b/PlaylistShade.cpp index 0bf29fb..b88fd50 100644 --- a/PlaylistShade.cpp +++ b/PlaylistShade.cpp @@ -1,4 +1,5 @@ #include "XMMSHandler.h" +#include #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)), - this, SLOT(setMediainfo (QHash))); + 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 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 ("artist").c_str ()) + + " - " + + QString::fromUtf8 (info.get ("album").c_str ()) + + " - " + + QString::fromUtf8 (info.get ("title").c_str ()); } else { - n = h.value("url"); + n = QString::fromUtf8 (info.get ("url").c_str ()); } m_text = (n); diff --git a/PlaylistShade.h b/PlaylistShade.h index 66e0e63..3c43fd9 100644 --- a/PlaylistShade.h +++ b/PlaylistShade.h @@ -1,6 +1,7 @@ #ifndef __PLAYLISTSHADE_H__ #define __PLAYLISTSHADE_H__ +#include #include "Skin.h" #include @@ -19,7 +20,7 @@ class PlaylistShade : public QWidget { public slots: void setPixmaps (Skin *skin); - void setMediainfo (QHash h); + void setMediainfo (const Xmms::PropDict &info); void settingsSaved (); private: diff --git a/ShadedDisplay.cpp b/ShadedDisplay.cpp index 5b109b9..68b6b09 100644 --- a/ShadedDisplay.cpp +++ b/ShadedDisplay.cpp @@ -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 &)), - this, SLOT(setMediainfo (const QHash &))); + connect (&xmmsh, SIGNAL(currentSong (const Xmms::PropDict &)), + this, SLOT(setMediainfo (const Xmms::PropDict &))); } void -ShadedDisplay::setMediainfo (const QHash &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 ("artist").c_str ()) + + " - " + + QString::fromUtf8 (info.get ("album").c_str ()) + + " - " + + QString::fromUtf8 (info.get ("title").c_str ()); } else { - n = h.value("url"); + n = QString::fromUtf8 (info.get ("url").c_str ()); } m_title->setText (n); } diff --git a/ShadedDisplay.h b/ShadedDisplay.h index 55d757c..7aaa471 100644 --- a/ShadedDisplay.h +++ b/ShadedDisplay.h @@ -33,7 +33,7 @@ class ShadedDisplay : public SkinDisplay public slots: void setStatus (Xmms::Playback::Status status); void setPlaytime (uint time); - void setMediainfo (const QHash &h); + void setMediainfo (const Xmms::PropDict &info); }; #endif diff --git a/XMMSHandler.cpp b/XMMSHandler.cpp index 5d95665..db0b3a0 100644 --- a/XMMSHandler.cpp +++ b/XMMSHandler.cpp @@ -2,7 +2,6 @@ #include "XmmsQT4.h" #include "XMMSHandler.h" -#include #include #include @@ -179,13 +178,13 @@ XMMSHandler::DictToQHash (const std::string &key, const Xmms::Dict::Variant &value, QHash &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 &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 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 hash; - propdict.each (boost::bind (&XMMSHandler::PropDictToQHash, this, - _1, _2, _3, boost::ref (hash))); - unsigned int id = propdict.get("id"); - emit mediainfoChanged (id, hash); + unsigned int id = propdict.get("id"); + emit mediainfoChanged (id, propdict); if (id == m_currentid) { - emit currentSong (hash); + emit currentSong (propdict); } return false; } diff --git a/XMMSHandler.h b/XMMSHandler.h index 4a3d72c..d3ff7d9 100644 --- a/XMMSHandler.h +++ b/XMMSHandler.h @@ -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 &); - void currentSong (const QHash &); + void mediainfoChanged (uint, const Xmms::PropDict &); + void currentSong (const Xmms::PropDict &); void playlistList (const QList &); void currentID (uint); - void playlistChanged (const QHash &); + void playlistChanged (const Xmms::Dict &); /* void medialibResponse (uint, const QList > &); */ @@ -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; };