diff --git a/lib/xclientcache.cpp b/lib/xclientcache.cpp index 3966a75..6117e5f 100644 --- a/lib/xclientcache.cpp +++ b/lib/xclientcache.cpp @@ -46,6 +46,11 @@ XClientCache::got_connection (XClient *client) client->medialib ()->broadcastEntryChanged () ( Xmms::bind (&XClientCache::handle_mlib_entry_changed, this)); + + client->playback ()->broadcastCurrentID () ( + Xmms::bind (&XClientCache::handle_current_id_changed, this)); + client->playback ()->currentID () ( + Xmms::bind (&XClientCache::handle_current_id_changed, this)); } bool @@ -60,12 +65,16 @@ XClientCache::handle_medialib_info_error (const std::string &error, uint32_t id) bool XClientCache::handle_medialib_info (const Xmms::PropDict &info) { - int32_t id = info.get ("id"); + uint32_t id = info.get ("id"); QHash hash = XClient::convert_propdict (info); m_info.insert (id, hash); emit entryChanged (id); + if (id == m_current_id) { + emit activeEntryChanged (hash); + } + return true; } @@ -165,6 +174,20 @@ XClientCache::handle_mlib_entry_changed (const uint32_t &id) return true; } +bool +XClientCache::handle_current_id_changed (const uint32_t &id) +{ + m_current_id = id; + if (!m_info.contains (id)) { + // get_info fetches the metadata from the server, and calls handle_medialib_info. + // handle_medialib_info sends the activeEntryChanged Signal + get_info (id); + return true; + } + + emit activeEntryChanged (m_info[id]); + return true; +} bool XClientCache::handle_playtime (const unsigned int &tme) diff --git a/lib/xclientcache.h b/lib/xclientcache.h index 73e74b6..bd2318a 100644 --- a/lib/xclientcache.h +++ b/lib/xclientcache.h @@ -38,6 +38,8 @@ class QIcon; class QPixmap; //#include +typedef QHash QVariantHash; + class XClientCache : public QObject { Q_OBJECT @@ -45,6 +47,7 @@ class XClientCache : public QObject XClientCache (XClient *); QHash get_info (uint32_t id); + QVariantHash get_current_info () {return get_info (m_current_id);} QIcon get_icon (uint32_t id); QPixmap get_pixmap (uint32_t id); QVariant extra_info_get (uint32_t, const QString &); @@ -65,14 +68,17 @@ class XClientCache : public QObject void entryRemoved (uint32_t); void playtime (uint32_t); + void activeEntryChanged (QVariantHash); + public slots: void got_connection (XClient *); private: bool handle_medialib_info (const Xmms::PropDict &info); bool handle_medialib_info_error (const std::string &, uint32_t); - + bool handle_mlib_entry_changed (const uint32_t &id); + bool handle_current_id_changed (const uint32_t &id); bool handle_bindata (const Xmms::bin &, const QString &); bool handle_playtime (const unsigned int &tme); @@ -82,6 +88,8 @@ class XClientCache : public QObject QHash < QString, QList > m_icon_map; QHash < int, QHash < QString, QVariant > > m_extra_info; + uint32_t m_current_id; + XClient *m_client; }; diff --git a/src/TextBar.cpp b/src/TextBar.cpp index b12c58b..06d8561 100644 --- a/src/TextBar.cpp +++ b/src/TextBar.cpp @@ -126,6 +126,8 @@ TextScroller::setText (QString text) } else { drawBitmapFont (text); } + m_x_off = 0; + m_x2_off = 0; update (); } @@ -148,6 +150,7 @@ TextScroller::drawBitmapFont (QString text) } } else { m_pixmap = QPixmap (m_w, m_h); + m_timer->stop (); } QByteArray temp2 = temp.toLatin1(); const char *t = temp2.data(); @@ -201,6 +204,7 @@ TextScroller::drawQtFont (QString text) } else { m_pixmap = QPixmap (m_w, m_h); + m_timer->stop (); } QPainter paint; diff --git a/src/XMMSHandler.cpp b/src/XMMSHandler.cpp index 2a259b0..0286d88 100644 --- a/src/XMMSHandler.cpp +++ b/src/XMMSHandler.cpp @@ -61,62 +61,18 @@ XMMSHandler::connect_handler (const char *ipcpath, const bool &sync, QWidget *pa connect(ipcpath, sync, parent); using Xmms::bind; - m_client->medialib.broadcastEntryChanged () ( - bind (&XMMSHandler::medialib_entry_changed, this)); - - m_client->playback.currentID () ( - bind (&XMMSHandler::playback_current_id, this)); - m_client->playback.broadcastCurrentID () ( - bind (&XMMSHandler::playback_current_id, this)); - m_client->playback.broadcastVolumeChanged () ( bind (&XMMSHandler::volume_changed, this)); return true; } - -Xmms::Client * -XMMSHandler::getClient () -{ - return m_client; -} - -bool -XMMSHandler::medialib_entry_changed (const unsigned int &id) -{ - if (id > 0) { - requestMediainfo (id); - } - return true; -} - void XMMSHandler::playlistAddURL (const QString &s) { m_client->playlist.addUrl (s.toAscii ().constData ()) (); } -void -XMMSHandler::requestMediainfo (uint id) -{ - m_client->medialib.getInfo (id) ( - Xmms::bind (&XMMSHandler::medialib_info, this)); -} - -bool -XMMSHandler::playback_current_id (const unsigned int &id) -{ - m_currentid = id; - - if (id > 0) { - requestMediainfo (id); - } - - return true; -} - - void XMMSHandler::DictToQHash (const std::string &key, const Xmms::Dict::Variant &value, @@ -176,18 +132,6 @@ XMMSHandler::medialib_select (XMMSResultDictList *res) } */ -bool -XMMSHandler::medialib_info (const Xmms::PropDict &propdict) -{ - unsigned int id = propdict.get("id"); - emit mediainfoChanged (id, propdict); - - if (id == m_currentid) { - emit currentSong (propdict); - } - return false; -} - bool XMMSHandler::volume_error (const std::string &error) { diff --git a/src/XMMSHandler.h b/src/XMMSHandler.h index 9477a07..f7446b3 100644 --- a/src/XMMSHandler.h +++ b/src/XMMSHandler.h @@ -36,12 +36,8 @@ class XMMSHandler : public XClient { bool connect_handler (const char *ipcpath = NULL, const bool &sync = false, QWidget *parent = NULL); - bool playback_current_id (const unsigned int &id); - bool medialib_info (const Xmms::PropDict &propdict); - bool medialib_entry_changed (const unsigned int &id); bool volume_changed (const Xmms::Dict &levels); - void requestMediainfo (uint id); void playlistAddURL (const QString& url); /* @@ -60,7 +56,7 @@ class XMMSHandler : public XClient { void updateSettings () { emit settingsSaved (); } - Xmms::Client *getClient (); + Xmms::Client *getClient () { return m_client; } PlaylistModel *getPlaylistModel () {return m_playlist_model; } @@ -69,9 +65,6 @@ class XMMSHandler : public XClient { signals: void settingsSaved (); - void mediainfoChanged (uint, const Xmms::PropDict &); - void currentSong (const Xmms::PropDict &); - void playlistChanged (const Xmms::Dict &); /* void medialibResponse (uint, const QList > &); */ @@ -91,7 +84,6 @@ class XMMSHandler : public XClient { XmmsQT4 *m_qt4; PlaylistModel *m_playlist_model; - unsigned int m_currentid; bool m_masterchan; }; diff --git a/src/mainwindow/maindisplay.cpp b/src/mainwindow/maindisplay.cpp index f79d72f..9fd42ca 100644 --- a/src/mainwindow/maindisplay.cpp +++ b/src/mainwindow/maindisplay.cpp @@ -104,8 +104,8 @@ MainDisplay::MainDisplay (QWidget *parent) : SkinDisplay(parent) m_bslider->resize (skin->getSize (Skin::SLIDER_BALANCEBAR_BGS)); m_bslider->move (skin->getPos (Skin::SLIDER_BALANCEBAR_BGS)); - connect (&client, SIGNAL(currentSong (const Xmms::PropDict &)), - this, SLOT(setMediainfo (const Xmms::PropDict &))); + connect (client.cache (), SIGNAL (activeEntryChanged (QVariantHash)), + this, SLOT (setMediainfo (const QVariantHash))); connect (client.xplayback (), SIGNAL(playbackStatusChanged(Xmms::Playback::Status)), this, SLOT(setStatus(Xmms::Playback::Status))); connect (client.cache () , SIGNAL (playtime (uint32_t)), @@ -221,46 +221,37 @@ MainDisplay::setPlaytime (uint32_t time) } void -MainDisplay::setMediainfo (const Xmms::PropDict &info) +MainDisplay::setMediainfo (const QVariantHash info) { QString n; if (info.contains ("title")) { if (info.contains ("artist")) { - n = QString::fromUtf8 (info.get ("artist").c_str ()) + " - "; + n = info["artist"].toString () + " - "; } if (info.contains ("album")) { - n += QString::fromUtf8 (info.get ("album").c_str ()) + " - "; + n += info["album"].toString () + " - "; } - n += QString::fromUtf8 (info.get ("title").c_str ()); + n += info["title"].toString (); } else if (info.contains ("channel")) { - n = QString::fromUtf8 (info.get ("channel").c_str ()) + " - " + - QString::fromUtf8 (info.get ("title").c_str ()); + n = info["channel"].toString () + " - " + info["title"].toString (); } else { - n = QString::fromUtf8 (info.get ("url").c_str ()); + n = info["url"].toString (); n = n.section ("/", -1); } m_text->setText (n); - - if (info.contains ("bitrate")) { - m_kbps->setValue (info.get ("bitrate")/1000); - } else { - m_kbps->setValue (0); - } - if (info.contains ("samplerate")) { - m_khz->setValue (info.get ("samplerate")/1000); - } else { - m_khz->setValue(0); - } + m_kbps->setValue (info.value ("bitrate", 0).toInt ()/1000); + m_khz->setValue (info.value ("samplerate", 0).toInt ()/1000); + if (info.contains ("channels") && - info.get ("channels") > 1) { + info["channels"].toInt () > 1) { m_stereo->setStereoMono (1, 0); } else { m_stereo->setStereoMono (0, 1); } if (info.contains ("duration")) { - m_posbar->setMaximum (info.get ("duration")); + m_posbar->setMaximum (info["duration"].toInt ()); m_posbar->show (); } else { m_posbar->setMaximum (0); diff --git a/src/mainwindow/maindisplay.h b/src/mainwindow/maindisplay.h index 1ce36ab..bd205f2 100644 --- a/src/mainwindow/maindisplay.h +++ b/src/mainwindow/maindisplay.h @@ -29,9 +29,13 @@ class MainDisplay; #include #include #include +#include +#include #include "Display.h" +typedef QHash QVariantHash; + class PixmapButton; class PixmapNumberDisplay; class PixmapSlider; @@ -67,7 +71,8 @@ class MainDisplay : public SkinDisplay void setPixmaps(Skin *skin); void setStatus (Xmms::Playback::Status status); void setPlaytime (uint32_t time); - void setMediainfo (const Xmms::PropDict &); +// void setMediainfo (const Xmms::PropDict &); + void setMediainfo (const QVariantHash); void updateVolume (uint volume); void setVolume (int volume); diff --git a/src/mainwindow/shadeddisplay.cpp b/src/mainwindow/shadeddisplay.cpp index 432c838..2dabc6c 100644 --- a/src/mainwindow/shadeddisplay.cpp +++ b/src/mainwindow/shadeddisplay.cpp @@ -79,8 +79,8 @@ ShadedDisplay::ShadedDisplay (QWidget *parent) : SkinDisplay (parent) this, SLOT(setStatus(Xmms::Playback::Status))); connect (client.cache (), SIGNAL (playtime (uint32_t)), this, SLOT ( setPlaytime(uint32_t))); - connect (&client, SIGNAL(currentSong (const Xmms::PropDict &)), - this, SLOT(setMediainfo (const Xmms::PropDict &))); + connect (client.cache (), SIGNAL (activeEntryChanged (QVariantHash)), + this, SLOT (setMediainfo (QVariantHash))); } void @@ -90,22 +90,20 @@ ShadedDisplay::setPixmaps (Skin *skin) } void -ShadedDisplay::setMediainfo (const Xmms::PropDict &info) +ShadedDisplay::setMediainfo (QVariantHash info) { QString n; 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 ()); + n = info["artist"].toString () + " - " + + info["album"].toString () + " - " + + info["title"].toString (); } else { - n = QString::fromUtf8 (info.get ("url").c_str ()); + n = info["url"].toString (); } if (info.contains ("duration")) { - m_duration = (info.get ("duration")); + m_duration = info["duration"].toInt (); } else { m_duration = 0; } diff --git a/src/mainwindow/shadeddisplay.h b/src/mainwindow/shadeddisplay.h index 7795152..2543fd2 100644 --- a/src/mainwindow/shadeddisplay.h +++ b/src/mainwindow/shadeddisplay.h @@ -20,6 +20,10 @@ class ShadedDisplay; #include #include "Display.h" +#include +#include + +typedef QHash QVariantHash; class MainWindow; class Skin; @@ -53,7 +57,7 @@ class ShadedDisplay : public SkinDisplay public slots: void setStatus (Xmms::Playback::Status status); void setPlaytime (uint32_t time); - void setMediainfo (const Xmms::PropDict &info); + void setMediainfo (QVariantHash info); void setPixmaps (Skin *skin); }; diff --git a/src/playlist/playlistshade.cpp b/src/playlist/playlistshade.cpp index 6166cea..9252e27 100644 --- a/src/playlist/playlistshade.cpp +++ b/src/playlist/playlistshade.cpp @@ -15,6 +15,7 @@ #include "XMMSHandler.h" #include +#include "xclientcache.h" #include "playlistshade.h" #include "playlistwindow.h" @@ -45,8 +46,8 @@ PlaylistShade::PlaylistShade (PlaylistWindow *parent) : QWidget (parent) connect (m_unshadebtn, SIGNAL (clicked ()), parent, SLOT (switchDisplay ())); - connect (&xmmsh, SIGNAL(currentSong (const Xmms::PropDict &)), - this, SLOT(setMediainfo (const Xmms::PropDict &))); + connect (xmmsh.cache (), SIGNAL (activeEntryChanged (QVariantHash)), + this, SLOT (setMediainfo (QVariantHash))); connect (&xmmsh, SIGNAL(settingsSaved ()), this, SLOT(settingsSaved ())); @@ -65,18 +66,16 @@ PlaylistShade::settingsSaved () } void -PlaylistShade::setMediainfo (const Xmms::PropDict &info) +PlaylistShade::setMediainfo (QVariantHash info) { QString n; 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 ()); + n = info["artist"].toString () + " - " + + info["album"].toString () + " - " + + info["title"].toString (); } else { - n = QString::fromUtf8 (info.get ("url").c_str ()); + n = info["url"].toString (); } m_text = (n); diff --git a/src/playlist/playlistshade.h b/src/playlist/playlistshade.h index cd92377..9d89d24 100644 --- a/src/playlist/playlistshade.h +++ b/src/playlist/playlistshade.h @@ -21,6 +21,9 @@ #include #include +#include + +typedef QHash QVariantHash; class QResizeEvent; class PixmapButton; @@ -39,7 +42,7 @@ class PlaylistShade : public QWidget { public slots: void setPixmaps (Skin *skin); - void setMediainfo (const Xmms::PropDict &info); + void setMediainfo (QVariantHash); void settingsSaved (); void resizeEvent (QResizeEvent *);