Example #1
0
void
QueueManager::addItems( QListViewItem *after )
{
    /*
        HACK!!!!! We can know which items where dragged since they should still be selected
        I do this, because:
        - Dragging items from the playlist provides urls
        - Providing urls, requires iterating through the entire list in order to find which
          item was selected.  Possibly a very expensive task - worst case: O(n)
        - After a drag, those items are still selected in the playlist, so we can find out
          which PlaylistItems were dragged by selectedItems();
    */

    if( !after )
        after = m_listview->lastChild();

    QPtrList<QListViewItem> list = Playlist::instance()->selectedItems();

    for( QListViewItem *item = list.first(); item; item = list.next() )
    {
#define item static_cast<PlaylistItem*>(item)
        QValueList<PlaylistItem*> current = m_map.values();

        if( current.find( item ) == current.end() ) //avoid duplication
        {
            QString title = i18n("%1 - %2").arg( item->artist(), item->title() );

            after = new QueueItem( m_listview, after, title );
            m_map[ after ] = item;
        }
#undef item
    }

}