+ emit dataChanged( index( item, 0 ) , index( item, 1 ) );
+}
+
+/************************* Actions ******************************/
+
+void PLModel::sendArt( QString url )
+{
+ QString arturl = url.replace( "file://",QString("" ) );
+ emit artSet( arturl );
+}
+
+void PLModel::removeArt()
+{
+ emit artSet( QString() );
+}
+
+/**
+ * Deletion, here we have to do a ugly slow hack as we retrieve the full
+ * list of indexes to delete at once: when we delete a node and all of
+ * its children, we need to update the list.
+ * Todo: investigate whethere we can use ranges to be sure to delete all items?
+ */
+void PLModel::doDelete( QModelIndexList selected )
+{
+ for( int i = selected.size() -1 ; i >= 0; i-- )
+ {
+ QModelIndex index = selected[i];
+ if( index.column() != 0 ) continue;
+ PLItem *item = static_cast<PLItem*>(index.internalPointer());
+ if( item )
+ {
+ if( item->children.size() )
+ recurseDelete( item->children, &selected );
+ doDeleteItem( item, &selected );
+ }
+ }
+}
+
+void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList)
+{
+ for( int i = children.size() - 1; i >= 0 ; i-- )
+ {
+ PLItem *item = children[i];
+ if( item->children.size() )
+ recurseDelete( item->children, fullList );
+ doDeleteItem( item, fullList );
+ }
+}
+
+void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
+{
+ QModelIndex deleteIndex = index( item, 0 );
+ fullList->removeAll( deleteIndex );
+
+ PL_LOCK;
+ playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id,
+ VLC_TRUE );
+ if( !p_item )
+ {
+ PL_UNLOCK; return;
+ }
+ if( p_item->i_children == -1 )
+ playlist_DeleteFromInput( p_playlist, item->i_input_id, VLC_TRUE );
+ else
+ playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
+ /* And finally, remove it from the tree */
+ item->remove( item );
+ PL_UNLOCK;
+}
+
+/******* Volume III: Sorting and searching ********/
+void PLModel::sort( int column, Qt::SortOrder order )
+{
+ PL_LOCK;
+ {
+ playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
+ rootItem->i_id,
+ VLC_TRUE );
+ int i_mode;
+ switch( column )
+ {
+ case 0: i_mode = SORT_TITLE_NODES_FIRST;break;
+ case 1: i_mode = SORT_ARTIST;break;
+ case 2: i_mode = SORT_DURATION; break;
+ default: i_mode = SORT_TITLE_NODES_FIRST; break;
+ }
+ if( p_root )
+ playlist_RecursiveNodeSort( p_playlist, p_root, i_mode,
+ order == Qt::AscendingOrder ?
+ ORDER_NORMAL : ORDER_REVERSE );
+ }
+ PL_UNLOCK
+ rebuild();
+}
+
+void PLModel::search( QString search_text )
+{
+ /** \todo Fire the search with a small delay ? */
+ PL_LOCK;
+ {
+ playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
+ rootItem->i_id,
+ VLC_TRUE );
+ assert( p_root );
+ char *psz_name = search_text.toUtf8().data();
+ playlist_LiveSearchUpdate( p_playlist , p_root, psz_name );
+ }
+ PL_UNLOCK;
+ rebuild();
+}
+
+/*********** Popup *********/
+void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
+{
+ assert( index.isValid() );
+ PL_LOCK;
+ playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
+ itemId( index ), VLC_TRUE );
+ if( p_item )
+ {
+ i_popup_item = p_item->i_id;
+ i_popup_parent = p_item->p_parent ? p_item->p_parent->i_id : -1;
+ PL_UNLOCK;
+ current_selection = list;
+ QMenu *menu = new QMenu;
+ menu->addAction( qfu(I_POP_PLAY), this, SLOT( popupPlay() ) );
+ menu->addAction( qfu(I_POP_DEL), this, SLOT( popupDel() ) );
+ menu->addSeparator();
+ menu->addAction( qfu(I_POP_STREAM), this, SLOT( popupStream() ) );
+ menu->addAction( qfu(I_POP_SAVE), this, SLOT( popupSave() ) );
+ menu->addSeparator();
+ menu->addAction( qfu(I_POP_INFO), this, SLOT( popupInfo() ) );
+ if( p_item->i_children > -1 )
+ {
+ menu->addSeparator();
+ menu->addAction( qfu(I_POP_SORT), this, SLOT( popupSort() ) );
+ menu->addAction( qfu(I_POP_ADD), this, SLOT( popupAdd() ) );
+ }
+#ifdef WIN32
+ menu->addSeparator();
+ menu->addAction( qfu( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
+#endif
+ menu->popup( point );