]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/playlist/playlist_model.cpp
qt4: remove totology.
[vlc] / modules / gui / qt4 / components / playlist / playlist_model.cpp
index d2e07ce351323f968ba15d738c380f7d30cb51f7..dc68a2344b446eb5f22f42ed510fe0f46113b799 100644 (file)
@@ -96,6 +96,10 @@ PLModel::PLModel( playlist_t *_p_playlist,  /* THEPL */
 #undef ADD_ICON
 
     rebuild( p_root );
+    CONNECT( THEMIM->getIM(), metaChanged( int ),
+            this, ProcessInputItemUpdate( int ) );
+    CONNECT( THEMIM, inputChanged( input_thread_t * ),
+            this, ProcessInputItemUpdate( input_thread_t* ) );
 }
 
 PLModel::~PLModel()
@@ -168,10 +172,8 @@ bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
 
             PL_LOCK;
             playlist_item_t *p_target =
-                        playlist_ItemGetById( p_playlist, targetItem->i_id,
-                                              pl_Locked );
-            playlist_item_t *p_src = playlist_ItemGetById( p_playlist, srcId,
-                                                           pl_Locked );
+                        playlist_ItemGetById( p_playlist, targetItem->i_id );
+            playlist_item_t *p_src = playlist_ItemGetById( p_playlist, srcId );
 
             if( !p_target || !p_src )
             {
@@ -183,8 +185,7 @@ bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
                 PLItem *parentItem = targetItem->parent();
                 assert( parentItem );
                 playlist_item_t *p_parent =
-                         playlist_ItemGetById( p_playlist, parentItem->i_id,
-                                               pl_Locked );
+                         playlist_ItemGetById( p_playlist, parentItem->i_id );
                 if( !p_parent )
                 {
                     PL_UNLOCK;
@@ -223,21 +224,23 @@ void PLModel::addCallbacks()
 {
     /* Some global changes happened -> Rebuild all */
     var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
-    /* We went to the next item */
-    var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );
+    /* We went to the next item 
+    var_AddCallback( p_playlist, "item-current", PlaylistNext, this );
+    */
     /* One item has been updated */
-    var_AddCallback( p_playlist, "item-change", ItemChanged, this );
-    var_AddCallback( p_playlist, "item-append", ItemAppended, this );
-    var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );
+    var_AddCallback( p_playlist, "playlist-item-append", ItemAppended, this );
+    var_AddCallback( p_playlist, "playlist-item-deleted", ItemDeleted, this );
 }
 
 void PLModel::delCallbacks()
 {
     var_DelCallback( p_playlist, "item-change", ItemChanged, this );
-    var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
+    /*
+    var_DelCallback( p_playlist, "item-current", PlaylistNext, this );
+    */
     var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
-    var_DelCallback( p_playlist, "item-append", ItemAppended, this );
-    var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this );
+    var_DelCallback( p_playlist, "playlist-item-append", ItemAppended, this );
+    var_DelCallback( p_playlist, "playlist-item-deleted", ItemDeleted, this );
 }
 
 void PLModel::activateItem( const QModelIndex &index )
@@ -246,8 +249,7 @@ 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,
-                                                    pl_Locked );
+    playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
     activateItem( p_item );
     PL_UNLOCK;
 }
@@ -392,20 +394,18 @@ QStringList PLModel::selectedURIs()
         PL_LOCK;
         PLItem *item = static_cast<PLItem*>
                     (current_selection[i].internalPointer());
-        if( !item )
-            continue;
-
-        input_item_t *p_item = NULL;
-        if( !p_item )
-            continue;
-
-        char *psz = input_item_GetURI( p_item );
-        if( !psz )
-            continue;
-        else
+        if( item )
         {
-            lst.append( QString( psz ) );
-            free( psz );
+            playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
+            if( p_item )
+            {
+                char *psz = input_item_GetURI( p_item->p_input );
+                if( psz )
+                {
+                    lst.append( QString( psz ) );
+                    free( psz );
+                }
+            }
         }
         PL_UNLOCK;
     }
@@ -416,18 +416,15 @@ QStringList PLModel::selectedURIs()
 
 bool PLModel::hasRandom()
 {
-    if( var_GetBool( p_playlist, "random" ) ) return true;
-    return false;
+    return var_GetBool( p_playlist, "random" );
 }
 bool PLModel::hasRepeat()
 {
-    if( var_GetBool( p_playlist, "repeat" ) ) return true;
-    return false;
+    return var_GetBool( p_playlist, "repeat" );
 }
 bool PLModel::hasLoop()
 {
-    if( var_GetBool( p_playlist, "loop" ) ) return true;
-    return false;
+    return var_GetBool( p_playlist, "loop" );
 }
 void PLModel::setLoop( bool on )
 {
@@ -516,16 +513,14 @@ PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input )
 void PLModel::customEvent( QEvent *event )
 {
     int type = event->type();
-    if( type != ItemUpdate_Type && type != ItemAppend_Type &&
+    if( type != ItemAppend_Type &&
         type != ItemDelete_Type && type != PLUpdate_Type )
         return;
 
     PLEvent *ple = static_cast<PLEvent *>(event);
 
-    if( type == ItemUpdate_Type )
-        ProcessInputItemUpdate( ple->i_id );
-    else if( type == ItemAppend_Type )
-        ProcessItemAppend( ple->p_add );
+    if( type == ItemAppend_Type )
+        ProcessItemAppend( &ple->add );
     else if( type == ItemDelete_Type )
         ProcessItemRemoval( ple->i_id );
     else
@@ -533,6 +528,11 @@ void PLModel::customEvent( QEvent *event )
 }
 
 /**** Events processing ****/
+void PLModel::ProcessInputItemUpdate( input_thread_t *p_input )
+{
+    if( !p_input ) return;
+    ProcessInputItemUpdate( input_GetItem( p_input )->i_id );
+}
 void PLModel::ProcessInputItemUpdate( int i_input_id )
 {
     if( i_input_id <= 0 ) return;
@@ -554,7 +554,7 @@ void PLModel::ProcessItemRemoval( int i_id )
     removeItem( i_id );
 }
 
-void PLModel::ProcessItemAppend( playlist_add_t *p_add )
+void PLModel::ProcessItemAppend( const playlist_add_t *p_add )
 {
     playlist_item_t *p_item = NULL;
     PLItem *newItem = NULL;
@@ -563,7 +563,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, pl_Locked );
+    p_item = playlist_ItemGetById( p_playlist, p_add->i_item );
     if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG ) goto end;
     if( i_depth == DEPTH_SEL && p_item->p_parent &&
                         p_item->p_parent->i_id != rootItem->i_id )
@@ -632,8 +632,7 @@ 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,
-                                                    pl_Locked );
+    playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id );
     UpdateNodeChildren( p_node, root );
 }
 
@@ -654,8 +653,7 @@ 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,
-                                                    pl_Locked );
+    playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
     UpdateTreeItem( p_item, item, signal, force );
 }
 
@@ -714,11 +712,11 @@ void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
     fullList->removeAll( deleteIndex );
 
     PL_LOCK;
-    playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id,
-                                                    pl_Locked );
+    playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
     if( !p_item )
     {
-        PL_UNLOCK; return;
+        PL_UNLOCK;
+        return;
     }
     if( p_item->i_children == -1 )
         playlist_DeleteFromInput( p_playlist, item->i_input_id, pl_Locked );
@@ -752,8 +750,7 @@ next:
     PL_LOCK;
     {
         playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
-                                                        rootItem->i_id,
-                                                        pl_Locked );
+                                                        rootItem->i_id );
         if( p_root )
         {
             playlist_RecursiveNodeSort( p_playlist, p_root,
@@ -772,8 +769,7 @@ void PLModel::search( QString search_text )
     PL_LOCK;
     {
         playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
-                                                        rootItem->i_id,
-                                                        pl_Locked );
+                                                        rootItem->i_id );
         assert( p_root );
         char *psz_name = search_text.toUtf8().data();
         playlist_LiveSearchUpdate( p_playlist , p_root, psz_name );
@@ -787,8 +783,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 ), pl_Locked );
+    playlist_item_t *p_item = playlist_ItemGetById( p_playlist, itemId( index ) );
     if( p_item )
     {
         i_popup_item = p_item->i_id;
@@ -796,21 +791,21 @@ void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
         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->addAction( qtr(I_POP_PLAY), this, SLOT( popupPlay() ) );
+        menu->addAction( qtr(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->addAction( qtr(I_POP_STREAM), this, SLOT( popupStream() ) );
+        menu->addAction( qtr(I_POP_SAVE), this, SLOT( popupSave() ) );
         menu->addSeparator();
-        menu->addAction( qfu(I_POP_INFO), this, SLOT( popupInfo() ) );
+        menu->addAction( qtr(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() ) );
+            menu->addAction( qtr(I_POP_SORT), this, SLOT( popupSort() ) );
+            menu->addAction( qtr(I_POP_ADD), this, SLOT( popupAdd() ) );
         }
         menu->addSeparator();
-        menu->addAction( qfu( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
+        menu->addAction( qtr( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
         menu->popup( point );
     }
     else
@@ -867,8 +862,7 @@ void PLModel::popupPlay()
     PL_LOCK;
     {
         playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
-                                                        i_popup_item,
-                                                        pl_Locked );
+                                                        i_popup_item );
         activateItem( p_item );
     }
     PL_UNLOCK;
@@ -876,12 +870,16 @@ void PLModel::popupPlay()
 
 void PLModel::popupInfo()
 {
+    PL_LOCK;
     playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
-                                                    i_popup_item,
-                                                    pl_Unlocked );
+                                                    i_popup_item );
     if( p_item )
     {
-        MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_item->p_input );
+        input_item_t* p_input = p_item->p_input;
+        vlc_gc_incref( p_input );
+        PL_UNLOCK;
+        MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_input );
+        vlc_gc_decref( p_input );
         mid->setParent( PlaylistDialog::getInstance( p_intf ),
                         Qt::Dialog );
         mid->show();
@@ -900,7 +898,7 @@ void PLModel::popupSave()
 {
     QStringList mrls = selectedURIs();
     if( !mrls.isEmpty() )
-        THEDP->streamingDialog( NULL, mrls[0], true );
+        THEDP->streamingDialog( NULL, mrls[0] );
 }
 
 #include <QUrl>
@@ -908,13 +906,14 @@ void PLModel::popupSave()
 #include <QDesktopServices>
 void PLModel::popupExplore()
 {
+    PL_LOCK;
     playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
-                                                    i_popup_item,
-                                                    pl_Unlocked );
+                                                    i_popup_item );
     if( p_item )
     {
        input_item_t *p_input = p_item->p_input;
        char *psz_meta = input_item_GetURI( p_input );
+       PL_UNLOCK;
        if( psz_meta )
        {
            const char *psz_access;
@@ -933,6 +932,8 @@ void PLModel::popupExplore()
            free( psz_meta );
        }
     }
+    else
+        PL_UNLOCK;
 }
 
 /**********************************************************************
@@ -980,9 +981,7 @@ static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
                          vlc_value_t oval, vlc_value_t nval, void *param )
 {
     PLModel *p_model = (PLModel *) param;
-    playlist_add_t *p_add = (playlist_add_t *)malloc( sizeof( playlist_add_t));
-    memcpy( p_add, nval.p_address, sizeof( playlist_add_t ) );
-
+    const playlist_add_t *p_add = (playlist_add_t *)nval.p_address;
     PLEvent *event = new PLEvent( p_add );
     QApplication::postEvent( p_model, event );
     return VLC_SUCCESS;