Some cleanup of the item code.

This commit is contained in:
Tobias Rundstrom 2006-03-01 21:33:09 -03:00
parent fabbfba162
commit f4c904b022

View file

@ -88,7 +88,14 @@ PlaylistList::playlistChanged (QHash<QString,QString> h)
XMMSHandler *xmmsh = XMMSHandler::getInstance (); XMMSHandler *xmmsh = XMMSHandler::getInstance ();
switch (signal) { switch (signal) {
case XMMS_PLAYLIST_CHANGED_ADD: case XMMS_PLAYLIST_CHANGED_ADD:
new PlaylistItem (this, h.value("id").toUInt()); {
uint id = h.value("id").toUInt();
if (m_itemmap->contains (id)) {
m_items->append (m_itemmap->value (id));
} else {
new PlaylistItem (this, id);
}
}
break; break;
case XMMS_PLAYLIST_CHANGED_INSERT: case XMMS_PLAYLIST_CHANGED_INSERT:
break; break;
@ -101,6 +108,14 @@ PlaylistList::playlistChanged (QHash<QString,QString> h)
} }
m_items->removeAt (pos); m_items->removeAt (pos);
m_itemmap->remove (i->getID ()); m_itemmap->remove (i->getID ());
if (m_active) {
if (m_active > pos) {
m_active --;
} else if (m_active == pos) {
m_active = 0;
}
}
delete i; delete i;
} }
break; break;
@ -166,8 +181,12 @@ void
PlaylistList::playlistList (QList<uint> l) PlaylistList::playlistList (QList<uint> l)
{ {
for (int i = 0; i < l.count(); i++) { for (int i = 0; i < l.count(); i++) {
if (m_itemmap->contains (l.value(i))) {
m_items->append (m_itemmap->value (l.value(i)));
} else {
new PlaylistItem (this, l.value(i)); new PlaylistItem (this, l.value(i));
} }
}
update (); update ();
} }
@ -379,6 +398,7 @@ PlaylistList::keyPressEvent (QKeyEvent *event)
/* Sort list and remove in reverse order */ /* Sort list and remove in reverse order */
qSort (*m_selected); qSort (*m_selected);
for (int i = m_selected->count (); i > 0; i --) { for (int i = m_selected->count (); i > 0; i --) {
qDebug ("delete pos %d", m_selected->value (i));
xmmsh->playlistRemove (m_selected->value (i)); xmmsh->playlistRemove (m_selected->value (i));
} }
m_selected->clear (); m_selected->clear ();