diff --git a/PlaylistList.cpp b/PlaylistList.cpp index 9db6c90..753e101 100644 --- a/PlaylistList.cpp +++ b/PlaylistList.cpp @@ -56,6 +56,50 @@ PlaylistList::PlaylistList (QWidget *parent) : QWidget (parent) connect (xmmsh, SIGNAL(currentID(uint)), this, SLOT(currentID(uint))); connect (xmmsh, SIGNAL(mediainfoChanged(uint, QHash)), this, SLOT(mediainfoChanged(uint, QHash))); + connect (xmmsh, SIGNAL(playlistChanged(QHash)), + this, SLOT(playlistChanged(QHash))); +} + +void +PlaylistList::playlistChanged (QHash h) +{ + int signal = h.value("type").toUInt(); + XMMSHandler *xmmsh = XMMSHandler::getInstance (); + switch (signal) { + case XMMS_PLAYLIST_CHANGED_ADD: + new PlaylistItem (this, h.value("id").toUInt()); + break; + case XMMS_PLAYLIST_CHANGED_INSERT: + break; + case XMMS_PLAYLIST_CHANGED_REMOVE: + { + int pos = h.value("position").toUInt(); + PlaylistItem *i = m_items->value (pos); + if (!i) { + qDebug ("no item in playlist?"); + return; + } + m_items->removeAt (pos); + m_itemmap->remove (i->getID ()); + delete i; + } + break; + case XMMS_PLAYLIST_CHANGED_MOVE: + break; + case XMMS_PLAYLIST_CHANGED_CLEAR: + case XMMS_PLAYLIST_CHANGED_SHUFFLE: + case XMMS_PLAYLIST_CHANGED_SORT: + { + m_itemmap->clear (); + while (!m_items->isEmpty()) + delete m_items->takeFirst(); + + xmmsh->requestPlaylistList (); + } + break; + } + + update (); } void diff --git a/PlaylistList.h b/PlaylistList.h index eb49cab..34a8070 100644 --- a/PlaylistList.h +++ b/PlaylistList.h @@ -22,6 +22,7 @@ class PlaylistList : public QWidget { void setPixmaps (Skin *skin); void playlistList (QList); void mediainfoChanged (uint, QHash); + void playlistChanged (QHash); void currentID (uint); private: diff --git a/XMMSHandler.cpp b/XMMSHandler.cpp index f7c6af5..e402828 100644 --- a/XMMSHandler.cpp +++ b/XMMSHandler.cpp @@ -32,6 +32,9 @@ XMMSHandler::XMMSHandler (void) : sigc::trackable () XMMSResultValueList *l = m_xmmsc->playlist_list (); l->connect (sigc::mem_fun (this, &XMMSHandler::playlist_list)); + XMMSResultDict *p = m_xmmsc->broadcast_playlist_changed (); + p->connect (sigc::mem_fun (this, &XMMSHandler::playlist_changed)); + XMMSResultValue *r = m_xmmsc->signal_playback_playtime (); r->connect (sigc::mem_fun (this, &XMMSHandler::playback_playtime)); @@ -52,6 +55,13 @@ XMMSHandler::requestMediainfo (uint id) r->connect (sigc::mem_fun (this, &XMMSHandler::medialib_info)); } +void +XMMSHandler::requestPlaylistList (void) +{ + XMMSResultValueList *r = m_xmmsc->playlist_list (); + r->connect (sigc::mem_fun (this, &XMMSHandler::playlist_list)); +} + void XMMSHandler::playlist_list (XMMSResultValueList *res) { @@ -118,10 +128,40 @@ XMMSHandler::setPlaytime (void) } -void -XMMSHandler::medialib_info (XMMSResultDict *res) +QHash +XMMSHandler::DictToQHash (XMMSResultDict *res) +{ + QHash h; + std::list l = res->getDictKeys (); + + std::list::const_iterator it; + for(it=l.begin(); it!=l.end(); ++it) + { + if (res->getDictValueType (*it) == XMMSC_RESULT_VALUE_TYPE_UINT32) { + uint i; + res->getValue (*it, &i); + QString t; + t.setNum (i); + h.insert (QString::fromLatin1(*it), t); + } else if (res->getDictValueType (*it) == XMMSC_RESULT_VALUE_TYPE_INT32) { + int i; + res->getValue (*it, &i); + QString t; + t.setNum (i); + h.insert (QString::fromLatin1(*it), t); + } else if (res->getDictValueType (*it) == XMMSC_RESULT_VALUE_TYPE_STRING) { + char *c; + res->getValue (*it, &c); + h.insert (QString::fromLatin1(*it), QString::fromUtf8 (c)); + } + } + + return h; +} + +QHash +XMMSHandler::PropDictToQHash (XMMSResultDict *res) { - int id; QHash h; std::list l = res->getPropDictKeys (); @@ -147,6 +187,22 @@ XMMSHandler::medialib_info (XMMSResultDict *res) } } + return h; +} + +void +XMMSHandler::playlist_changed (XMMSResultDict *res) +{ + QHash h(DictToQHash (res)); + emit playlistChanged (h); +} + +void +XMMSHandler::medialib_info (XMMSResultDict *res) +{ + int id; + QHash h(PropDictToQHash (res)); + res->getValue ("id", &id); emit mediainfoChanged (id, h); diff --git a/XMMSHandler.h b/XMMSHandler.h index 9e6046b..5fc2158 100644 --- a/XMMSHandler.h +++ b/XMMSHandler.h @@ -17,10 +17,12 @@ class XMMSHandler : public QObject, public sigc::trackable { void playback_playtime (XMMSResultValue *res); void playback_current_id (XMMSResultValue *res); void medialib_info (XMMSResultDict *res); + void playlist_changed (XMMSResultDict *res); void playback_status (XMMSResultValue *res); void playlist_list (XMMSResultValueList *res); void requestMediainfo (uint id); + void requestPlaylistList (void); const XMMSClient *getXMMS () { return m_xmmsc; } @@ -46,12 +48,15 @@ class XMMSHandler : public QObject, public sigc::trackable { void currentSong (QHash); void playlistList (QList); void currentID (uint); + void playlistChanged (QHash); private: XmmsQT4 *m_qt4; XMMSClient *m_xmmsc; static XMMSHandler *singleton; uint m_currentid; + QHash PropDictToQHash (XMMSResultDict *res); + QHash DictToQHash (XMMSResultDict *res); }; #endif