]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/playlist_model.cpp
Qt4: Some cosmetic work and design by Leo Spalteholz
[vlc] / modules / gui / qt4 / playlist_model.cpp
index be360f5bc2b0468b165f93631f5bc4b6bc36b59e..cb38d3bbd5efa97d6458fc8cccad937094a450f6 100644 (file)
@@ -133,12 +133,13 @@ void PLItem::update( playlist_item_t *p_item, bool iscurrent )
     strings[2] = QString( psz_duration );
     type = p_item->p_input->i_type;
     current = iscurrent;
+
     if( current && p_item->p_input->p_meta &&
         p_item->p_input->p_meta->psz_arturl &&
         !strncmp( p_item->p_input->p_meta->psz_arturl, "file://", 7 ) )
-    {
         model->sendArt( qfu( p_item->p_input->p_meta->psz_arturl ) );
-    }
+    else if( current )
+        model->removeArt();
 }
 
 /*************************************************************************
@@ -243,21 +244,23 @@ bool PLModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
 
             PL_LOCK;
             playlist_item_t *p_target =
-                        playlist_ItemGetById( p_playlist, targetItem->i_id );
-            playlist_item_t *p_src = playlist_ItemGetById( p_playlist, srcId );
+                        playlist_ItemGetById( p_playlist, targetItem->i_id,
+                                              VLC_TRUE );
+            playlist_item_t *p_src = playlist_ItemGetById( p_playlist, srcId,
+                                                           VLC_TRUE );
 
             if( !p_target || !p_src )
             {
                 PL_UNLOCK;
                 return false;
             }
-
             if( p_target->i_children == -1 ) /* A leaf */
             {
                 PLItem *parentItem = targetItem->parent();
                 assert( parentItem );
                 playlist_item_t *p_parent =
-                         playlist_ItemGetById( p_playlist, parentItem->i_id );
+                         playlist_ItemGetById( p_playlist, parentItem->i_id,
+                                               VLC_TRUE );
                 if( !p_parent )
                 {
                     PL_UNLOCK;
@@ -276,8 +279,16 @@ bool PLModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
                 newParentItem = targetItem;
             }
             /* Remove from source */
-            PLItem *srcItem = FindByInput( rootItem, p_src->p_input->i_id );
-            srcItem->remove( srcItem );
+            PLItem *srcItem = FindById( rootItem, p_src->i_id );
+            // We dropped on the source selector. Ask the dialog to forward
+            // to the main view
+            if( !srcItem )
+            {
+                emit shouldRemove( p_src->i_id );
+            }
+            else
+                srcItem->remove( srcItem );
+
             /* Display at new destination */
             PLItem *newItem = new PLItem( p_src, newParentItem, this );
             newParentItem->insertChild( newItem, i, true );
@@ -288,8 +299,13 @@ bool PLModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
         }
     }
     return true;
- }
+}
 
+void PLModel::removeItem( int i_id )
+{
+    PLItem *item = FindById( rootItem,i_id );
+    if( item ) item->remove( item );
+}
 
 void PLModel::addCallbacks()
 {
@@ -318,7 +334,8 @@ void PLModel::activateItem( const QModelIndex &index )
     PLItem *item = static_cast<PLItem*>(index.internalPointer());
     assert( item );
     PL_LOCK;
-    playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
+    playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id,
+                                                    VLC_TRUE);
     activateItem( p_item );
     PL_UNLOCK;
 }
@@ -333,7 +350,7 @@ void PLModel::activateItem( playlist_item_t *p_item )
         p_parent = p_parent->p_parent;
     }
     if( p_parent )
-        playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, p_parent, p_item );
+        playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, VLC_TRUE, p_parent, p_item );
 }
 
 /****************** Base model mandatory implementations *****************/
@@ -598,7 +615,7 @@ void PLModel::ProcessItemAppend( playlist_add_t *p_add )
     PL_LOCK;
     if( !nodeItem ) goto end;
 
-    p_item = playlist_ItemGetById( p_playlist, p_add->i_item );
+    p_item = playlist_ItemGetById( p_playlist, p_add->i_item, VLC_TRUE );
     if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG ) goto end;
     if( i_depth == 1 && p_item->p_parent &&
                         p_item->p_parent->i_id != rootItem->i_id )
@@ -666,7 +683,8 @@ void PLModel::rebuild( playlist_item_t *p_root )
 /* This function must be entered WITH the playlist lock */
 void PLModel::UpdateNodeChildren( PLItem *root )
 {
-    playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id );
+    playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id,
+                                                    VLC_TRUE );
     UpdateNodeChildren( p_node, root );
 }
 
@@ -687,7 +705,8 @@ void PLModel::UpdateNodeChildren( playlist_item_t *p_node, PLItem *root )
 /* This function must be entered WITH the playlist lock */
 void PLModel::UpdateTreeItem( PLItem *item, bool signal, bool force )
 {
-    playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
+    playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id,
+                                                    VLC_TRUE );
     UpdateTreeItem( p_item, item, signal, force );
 }
 
@@ -711,6 +730,11 @@ void PLModel::sendArt( QString url )
     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
@@ -750,13 +774,14 @@ void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
     fullList->removeAll( deleteIndex );
 
     PL_LOCK;
-    playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
+    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_DeleteAllFromInput( p_playlist, item->i_input_id );
+        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 */
@@ -768,19 +793,23 @@ void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
 void PLModel::sort( int column, Qt::SortOrder order )
 {
     PL_LOCK;
-    playlist_item_t *p_root = playlist_ItemGetById( p_playlist, rootItem->i_id );
-    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;
+        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 );
     }
-    if( p_root )
-        playlist_RecursiveNodeSort( p_playlist, p_root, i_mode,
-                                    order == Qt::AscendingOrder ? ORDER_NORMAL :
-                                                            ORDER_REVERSE );
     PL_UNLOCK
     rebuild();
 }
@@ -789,10 +818,14 @@ 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 );
-    assert( p_root );
-    char *psz_name = search_text.toUtf8().data();
-    playlist_LiveSearchUpdate( p_playlist , p_root, psz_name );
+    {
+        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();
 }
@@ -803,7 +836,7 @@ 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 ) );
+                                                    itemId( index ), VLC_TRUE );
     if( p_item )
     {
         i_popup_item = p_item->i_id;
@@ -837,8 +870,11 @@ void PLModel::popupDel()
 void PLModel::popupPlay()
 {
     PL_LOCK;
-    playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_popup_item );
-    activateItem( p_item );
+    {
+        playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
+                                                        i_popup_item,VLC_TRUE );
+        activateItem( p_item );
+    }
     PL_UNLOCK;
 }