diff --git a/MainDisplay.cpp b/MainDisplay.cpp index b117b43..51d5c5c 100644 --- a/MainDisplay.cpp +++ b/MainDisplay.cpp @@ -43,8 +43,8 @@ MainDisplay::MainDisplay (QWidget *parent) : SkinDisplay(parent) m_playstatus = new PlayStatus (this); m_playstatus->move (24, 28); - connect (xmmsh, SIGNAL(mediainfoChanged(QString,int,int,int,int)), - this, SLOT(setMediainfo(QString,int,int,int,int))); + connect (xmmsh, SIGNAL(currentSong (QHash)), + this, SLOT(setMediainfo (QHash))); connect (xmmsh, SIGNAL(playbackStatusChanged(uint)), this, SLOT(setStatus(uint))); connect (xmmsh, SIGNAL(playtimeChanged(uint)), @@ -91,22 +91,27 @@ MainDisplay::setPlaytime (uint time) } void -MainDisplay::setMediainfo (QString str, int bitrate, int samplerate, - int channels, int duration) +MainDisplay::setMediainfo (QHash h) { - m_text->setText (str); - m_kbps->setNumber (bitrate/1000, 3); - m_khz->setNumber (samplerate/1000, 2); - if (channels > 1) { + QString n; + if (h.contains ("artist") && h.contains ("album") && h.contains ("title")) { + n = h.value("artist") + " - " + h.value("album") + " - " + h.value("title"); + } else { + n = h.value("url"); + } + 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_stereo->setStereoMono (1, 0); } else { m_stereo->setStereoMono (0, 1); } - m_slider->setMax (duration); + m_slider->setMax (h.value("duration").toUInt()); m_slider->hideBar (false); } - void MainDisplay::SetupToggleButtons (void) { diff --git a/MainDisplay.h b/MainDisplay.h index 0fcd4f9..7ea0d6c 100644 --- a/MainDisplay.h +++ b/MainDisplay.h @@ -50,8 +50,7 @@ class MainDisplay : public SkinDisplay void setPixmaps(Skin *skin); void setStatus (uint status); void setPlaytime (uint time); - void setMediainfo (QString str, int bitrate, int samplerate, - int channels, int duration); + void setMediainfo (QHash); protected: void SetupPushButtons (void); diff --git a/PlayStatus.cpp b/PlayStatus.cpp index 16c0345..3b103bb 100644 --- a/PlayStatus.cpp +++ b/PlayStatus.cpp @@ -26,7 +26,6 @@ PlayStatus::setPixmaps (Skin *skin) void PlayStatus::setStatus (uint status) { - qDebug("funkar"); if (status == XMMS_PLAYBACK_STATUS_STOP) { m_pixmap = m_pixmap_stop; } else if (status == XMMS_PLAYBACK_STATUS_PLAY) { diff --git a/PlaylistList.cpp b/PlaylistList.cpp index bebf466..9db6c90 100644 --- a/PlaylistList.cpp +++ b/PlaylistList.cpp @@ -1,3 +1,5 @@ +#include "XMMSHandler.h" + #include "PlaylistList.h" #include "Playlist.h" @@ -7,23 +9,146 @@ PlaylistItem::PlaylistItem (PlaylistList *pl, uint id) { m_pl = pl; m_id = id; + m_isactive = false; + m_isselected = false; + m_req = false; + if (getSelected ()) { + qDebug ("trasigt!"); + } pl->addItem (this); } QString PlaylistItem::text (void) { - return QString::fromUtf8 ("Entry entry entry"); + XMMSHandler *xmmsh = XMMSHandler::getInstance (); + + if (m_text.count() < 1) { + + if (!m_req) { + xmmsh->requestMediainfo (m_id); + m_req = true; + } + + QString q; + q.setNum (m_id); + return q; + } else { + m_req = false; + return m_text; + } } PlaylistList::PlaylistList (QWidget *parent) : QWidget (parent) { + XMMSHandler *xmmsh = XMMSHandler::getInstance (); + PlaylistWindow *pl = dynamic_cast(window ()); connect (pl->getSkin (), SIGNAL (skinChanged (Skin *)), this, SLOT (setPixmaps(Skin *))); m_font = NULL; m_fontmetrics = NULL; m_items = new QList; + m_selected = new QList; + m_itemmap = new QHash; m_offset = 0; + + connect (xmmsh, SIGNAL(playlistList(QList)), this, SLOT(playlistList(QList))); + connect (xmmsh, SIGNAL(currentID(uint)), this, SLOT(currentID(uint))); + connect (xmmsh, SIGNAL(mediainfoChanged(uint, QHash)), + this, SLOT(mediainfoChanged(uint, QHash))); +} + +void +PlaylistList::currentID (uint id) +{ + PlaylistItem *i = m_itemmap->value (id); + if (!i) { + return; + } + i->setActive (true); + + i = m_itemmap->value (m_active); + if (!i) { + update (); + m_active = id; + return; + } + i->setActive (false); + + m_active = id; + update (); +} + +void +PlaylistList::mediainfoChanged (uint id, QHash h) +{ + 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"); + } else { + n = h.value("url"); + } + i->setText (n); + } + + update (); +} + +void +PlaylistList::playlistList (QList l) +{ + for (int i = 0; i < l.count(); i++) { + new PlaylistItem (this, l.value(i)); + } + + update (); +} + +void +PlaylistList::mousePressEvent (QMouseEvent *event) +{ + if (m_items->count() < 1) { + return; + } + int i = ((event->pos().y()+m_offset) / getFontH()); + if (i < 0) { + i = 0; + } + + if (event->modifiers() & Qt::ShiftModifier) { + if (m_selected->count () > 0) { + int o = m_selected->last (); + if (o < i) { + for (int y = o; y <= i; y++) { + m_selected->append (y); + m_items->value(y)->setSelected (true); + } + } else { + for (int y = i; y <= o; y++) { + m_selected->append (y); + m_items->value(y)->setSelected (true); + } + } + } else { + m_selected->append (i); + m_items->value(i)->setSelected (true); + } + } else if (event->modifiers () & Qt::ControlModifier) { + m_items->value(i)->setSelected (true); + m_selected->append (i); + } else { + for (int y = 0; y < m_selected->count(); y++) { + m_items->value(m_selected->value(y))->setSelected (false); + } + m_selected->clear(); + + m_items->value(i)->setSelected (true); + m_selected->append(i); + } + + update (); } void @@ -34,6 +159,7 @@ PlaylistList::paintEvent (QPaintEvent *event) paint.begin (this); paint.setFont (*m_font); paint.setClipping (false); + paint.setPen (QPen (m_color_normal)); int cy = event->rect().y () + m_offset; int ch = event->rect().height(); @@ -46,11 +172,25 @@ PlaylistList::paintEvent (QPaintEvent *event) for (i = sitem; i < eitem; i++) { QRect r (3, getFontH()*(i-sitem), size().width(), getFontH()); if (event->region().contains (r)) { + PlaylistItem *item = m_items->value (i); QString q; q.sprintf ("%d. ", i+1); - q += m_items->value(i)->text (); - paint.eraseRect (r); - paint.drawText (r, q); + q += item->text (); + + if (item->getSelected ()) { + paint.fillRect (r, QBrush (m_color_selected)); + } else { + paint.eraseRect (r); + } + + if (item->getActive ()) { + paint.setPen (QPen (m_color_active)); + paint.drawText (r, q); + paint.setPen (QPen (m_color_normal)); + } else { + paint.drawText (r, q); + } + } } @@ -67,6 +207,7 @@ void PlaylistList::addItem (PlaylistItem *i) { m_items->append (i); + m_itemmap->insert (i->getID(), i); if (m_items->count()*getFontH () > size().height()) { resize (size().width(), m_items->count ()*getFontH ()); } @@ -102,10 +243,11 @@ PlaylistList::setPixmaps (Skin *skin) } m_fontmetrics = new QFontMetrics (*m_font); - for (int i = 0; i < 100; i++) { - PlaylistItem (this, i); - } - + m_color_active.setNamedColor (skin->getPLeditValue ("current")); + m_color_selected.setNamedColor (skin->getPLeditValue ("selectedbg")); + m_color_normal.setNamedColor (skin->getPLeditValue ("normal")); + + update (); } void @@ -123,6 +265,7 @@ PlaylistList::setSize (int width, int height) ny = size().height(); } resize (nx, ny); + } diff --git a/PlaylistList.h b/PlaylistList.h index 752d7a2..eb49cab 100644 --- a/PlaylistList.h +++ b/PlaylistList.h @@ -3,6 +3,7 @@ #include "Skin.h" #include +#include class PlaylistItem; @@ -19,15 +20,28 @@ class PlaylistList : public QWidget { public slots: void setPixmaps (Skin *skin); + void playlistList (QList); + void mediainfoChanged (uint, QHash); + void currentID (uint); private: void paintEvent (QPaintEvent *event); + void mousePressEvent (QMouseEvent *event); + void mouseMoveEvent (QMouseEvent *event) {} + QList *m_items; + QList *m_selected; + QHash *m_itemmap; + QFont *m_font; QFontMetrics *m_fontmetrics; + QColor m_color_active; + QColor m_color_selected; + QColor m_color_normal; int getFontH (void); int m_offset; + int m_active; }; class PlaylistItem { @@ -37,9 +51,24 @@ class PlaylistItem { QString text (void); + void setActive (bool b) { m_isactive = b; } + bool getActive (void) { return m_isactive; } + + void setSelected (bool b) { m_isselected = b; } + bool getSelected (void) { return m_isselected; } + + uint getID (void) { return m_id; } + + void setText (QString s) { m_text = s; } + private: uint m_id; PlaylistList *m_pl; + + bool m_isactive; + bool m_isselected; + bool m_req; + QString m_text; }; diff --git a/XMMSHandler.cpp b/XMMSHandler.cpp index 7a280c0..f7c6af5 100644 --- a/XMMSHandler.cpp +++ b/XMMSHandler.cpp @@ -4,6 +4,7 @@ #include "XMMSHandler.h" #include +#include XMMSHandler *XMMSHandler::singleton = NULL; @@ -28,6 +29,9 @@ XMMSHandler::XMMSHandler (void) : sigc::trackable () } m_qt4 = new XmmsQT4 (m_xmmsc->getConn (), qApp); + XMMSResultValueList *l = m_xmmsc->playlist_list (); + l->connect (sigc::mem_fun (this, &XMMSHandler::playlist_list)); + XMMSResultValue *r = m_xmmsc->signal_playback_playtime (); r->connect (sigc::mem_fun (this, &XMMSHandler::playback_playtime)); @@ -39,14 +43,27 @@ XMMSHandler::XMMSHandler (void) : sigc::trackable () r = m_xmmsc->broadcast_playback_status (); r->connect (sigc::mem_fun (this, &XMMSHandler::playback_status)); +} - XMMSResultValueList *l = m_xmmsc->playlist_list (); - l->connect (sigc::mem_fun (this, &XMMSHandler::playlist_list)); +void +XMMSHandler::requestMediainfo (uint id) +{ + XMMSResultDict *r = m_xmmsc->medialib_get_info (id); + r->connect (sigc::mem_fun (this, &XMMSHandler::medialib_info)); } void XMMSHandler::playlist_list (XMMSResultValueList *res) { + QList list; + for (;res->listValid (); res->listNext()) { + uint i; + if (res->getValue (&i)) { + list.append (i); + } + } + emit playlistList (list); + delete res; } @@ -76,11 +93,15 @@ XMMSHandler::playback_current_id (XMMSResultValue *res) uint i; res->getValue (&i); + m_currentid = i; + if (i > 0) { XMMSResultDict *r = m_xmmsc->medialib_get_info (i); r->connect (sigc::mem_fun (this, &XMMSHandler::medialib_info)); } + emit currentID(i); + if (res->getClass() == XMMSC_RESULT_CLASS_DEFAULT) { delete res; } @@ -100,20 +121,39 @@ XMMSHandler::setPlaytime (void) void XMMSHandler::medialib_info (XMMSResultDict *res) { - int bitrate, samplerate, channels, duration; - char str[4096]; + int id; + QHash h; + std::list l = res->getPropDictKeys (); - // Make this NICER! - res->entryFormat (str, 4096, "${artist} - ${album} - ${title}"); + 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)); + } + } + res->getValue ("id", &id); - res->getValue ("bitrate", &bitrate); - res->getValue ("samplerate", &samplerate); - res->getValue ("channels:out", &channels); - res->getValue ("duration", &duration); + emit mediainfoChanged (id, h); - emit mediainfoChanged (QString::fromUtf8 (str), bitrate, - samplerate, channels, duration); + if (id == m_currentid) { + emit currentSong (h); + } delete res; } diff --git a/XMMSHandler.h b/XMMSHandler.h index e4c9095..9e6046b 100644 --- a/XMMSHandler.h +++ b/XMMSHandler.h @@ -6,6 +6,7 @@ #include "XmmsQT4.h" #include +#include class XMMSHandler : public QObject, public sigc::trackable { Q_OBJECT @@ -19,6 +20,8 @@ class XMMSHandler : public QObject, public sigc::trackable { void playback_status (XMMSResultValue *res); void playlist_list (XMMSResultValueList *res); + void requestMediainfo (uint id); + const XMMSClient *getXMMS () { return m_xmmsc; } public slots: @@ -39,13 +42,16 @@ class XMMSHandler : public QObject, public sigc::trackable { signals: void playbackStatusChanged (uint status); void playtimeChanged (uint time); - void mediainfoChanged (QString str, int bitrate, int samplerate, - int channels, int duration); + void mediainfoChanged (uint, QHash); + void currentSong (QHash); + void playlistList (QList); + void currentID (uint); private: XmmsQT4 *m_qt4; XMMSClient *m_xmmsc; static XMMSHandler *singleton; + uint m_currentid; }; #endif