]> git.sesse.net Git - vlc/blobdiff - modules/gui/pda/pda_callbacks.c
missing strdup
[vlc] / modules / gui / pda / pda_callbacks.c
index f0e8dd4afad8ce8911a9e34b26bbd9e6199d477b..0fb187ab786bdee95c17808c5fdbbdff6e07dd86 100644 (file)
  * Preamble
  *****************************************************************************/
 #include <sys/types.h>                                              /* off_t */
-#include <vlc/vlc.h>
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_input.h>
 #include <vlc_interface.h>
 #include <vlc_playlist.h>
 #include <vlc_vout.h>
 #include <pwd.h>
 #include <grp.h>
 
-#ifdef HAVE_CONFIG_H
-#  include <config.h>
-#endif
-
 #include <gtk/gtk.h>
 
 #include "pda_callbacks.h"
@@ -54,7 +56,7 @@ static char *get_file_perms(struct stat st);
 /*****************************************************************************
  * Useful function to retrieve p_intf
  ****************************************************************************/
-void * E_(__GtkGetIntf)( GtkWidget * widget )
+void * __GtkGetIntf( GtkWidget * widget )
 {
     void *p_data;
 
@@ -85,15 +87,14 @@ void * E_(__GtkGetIntf)( GtkWidget * widget )
     return p_data;
 }
 
-void PlaylistAddItem(GtkWidget *widget, gchar *name, char **ppsz_options, int i_size)
+static void PlaylistAddItem(GtkWidget *widget, gchar *name, char **ppsz_options, int i_size)
 {
     intf_thread_t *p_intf = GtkGetIntf( widget );
     playlist_t    *p_playlist;
     int           i_id , i_pos=0;
     GtkTreeView   *p_tvplaylist = NULL;
 
-    p_playlist = (playlist_t *)
-             vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
+    p_playlist = pl_Hold( p_intf );
 
     if( p_playlist ==  NULL)
     {   /* Bail out when VLC's playlist object is not found. */
@@ -118,7 +119,7 @@ void PlaylistAddItem(GtkWidget *widget, gchar *name, char **ppsz_options, int i_
             gtk_list_store_set (GTK_LIST_STORE(p_play_model), &p_play_iter,
                                     0, name,   /* Add path to it !!! */
                                     1, "no info",
-                                    2, p_playlist->i_size, /* Hidden index. */
+                                    2, playlist_CurrentSize(p_playlist), /* Hidden index. */
                                     -1 );
 
             /* Add to VLC's playlist */
@@ -135,7 +136,8 @@ void PlaylistAddItem(GtkWidget *widget, gchar *name, char **ppsz_options, int i_
                               (const char*)name,
                               PLAYLIST_APPEND, PLAYLIST_END,
                               (mtime_t) 0,
-                              (const char **) ppsz_options, i_pos );
+                              i_options, (const char **) ppsz_options, VLC_INPUT_OPTION_TRUSTED,
+                              true, pl_Unlocked );
             }
 
             /* Cleanup memory */
@@ -144,10 +146,11 @@ void PlaylistAddItem(GtkWidget *widget, gchar *name, char **ppsz_options, int i_
             free(ppsz_options);
         }
     }
-    vlc_object_release( p_playlist );
+    pl_Release( p_intf );
 }
 
-void PlaylistRebuildListStore( GtkListStore * p_list, playlist_t * p_playlist )
+void PlaylistRebuildListStore( intf_thread_t *p_intf,
+    GtkListStore * p_list, playlist_t * p_playlist )
 {
     GtkTreeIter iter;
     int         i_dummy;
@@ -158,19 +161,23 @@ void PlaylistRebuildListStore( GtkListStore * p_list, playlist_t * p_playlist )
     red.blue    = 0;
     red.green   = 0;
 #endif
-    vlc_mutex_lock( &p_playlist->object_lock );
-    for( i_dummy = 0; i_dummy < p_playlist->i_size ; i_dummy++ )
+    PL_LOCK;
+    for( i_dummy = 0; i_dummy < playlist_CurrentSize(p_playlist) ; i_dummy++ )
     {
-        ppsz_text[0] = p_playlist->pp_items[i_dummy]->input.psz_name;
-        ppsz_text[1] = "no info";
-        gtk_list_store_append (p_list, &iter);
-        gtk_list_store_set (p_list, &iter,
-                            0, ppsz_text[0],
-                            1, ppsz_text[1],
-                            2, i_dummy, /* Hidden index */
-                            -1);
+        playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_dummy );
+        if( p_item )
+        {
+            ppsz_text[0] = p_item->p_input->psz_name;
+            ppsz_text[1] = "no info";
+            gtk_list_store_append (p_list, &iter);
+            gtk_list_store_set (p_list, &iter,
+                                0, ppsz_text[0],
+                                1, ppsz_text[1],
+                                2, i_dummy, /* Hidden index */
+                                -1);
+        }
     }
-    vlc_mutex_unlock( &p_playlist->object_lock );
+    PL_UNLOCK;
 }
 
 /*****************************************************************
@@ -223,7 +230,7 @@ void ReadDirectory(intf_thread_t *p_intf, GtkListStore *p_list, char *psz_dir )
                                 4, ppsz_text[3],
                                 -1);
 
-            if (ppsz_text[1]) free(ppsz_text[1]);
+            free(ppsz_text[1]);
         }
             /* kludge */
         for (i=0; i<n; i++)
@@ -252,7 +259,7 @@ void ReadDirectory(intf_thread_t *p_intf, GtkListStore *p_list, char *psz_dir )
                                     4, ppsz_text[3],
                                     -1);
 
-                if (ppsz_text[1]) free(ppsz_text[1]);
+                free(ppsz_text[1]);
             }
         }
         free(pp_namelist);
@@ -263,7 +270,7 @@ static char *get_file_perms(const struct stat st)
 {
     char  *psz_perm;
 
-    psz_perm = (char *) malloc(sizeof(char)*10);
+    psz_perm = (char *) malloc(10);
     strncpy( psz_perm, "----------", sizeof("----------"));
 
     /* determine permission modes */
@@ -340,7 +347,7 @@ gboolean onPDADeleteEvent(GtkWidget *widget, GdkEvent *event, gpointer user_data
     intf_thread_t *p_intf = GtkGetIntf( widget );
 
     vlc_mutex_lock( &p_intf->change_lock );
-    vlc_object_kill( p_intf->p_libvlc );
+    libvlc_Quit( p_intf->p_libvlc );
     vlc_mutex_unlock( &p_intf->change_lock );
     msg_Dbg( p_intf, "about to exit vlc ... signaled" );
 
@@ -371,34 +378,33 @@ void onPause(GtkButton *button, gpointer user_data)
 void onPlay(GtkButton *button, gpointer user_data)
 {
     intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET( button ) );
-    playlist_t *p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
+    playlist_t *p_playlist = pl_Hold( p_intf );
 
     if (p_playlist)
     {
-        vlc_mutex_lock( &p_playlist->object_lock );
-        if (p_playlist->i_size)
+        int s;
+
+        PL_LOCK;
+        s = playlist_CurrentSize(p_playlist);
+        PL_UNLOCK;
+        /* FIXME: This is racy... */
+        if (s)
         {
-            vlc_mutex_unlock( &p_playlist->object_lock );
             playlist_Play( p_playlist );
             gdk_window_lower( p_intf->p_sys->p_window->window );
         }
-        else
-        {
-            vlc_mutex_unlock( &p_playlist->object_lock );
-        }
-        vlc_object_release( p_playlist );
+        pl_Release( p_intf );
     }
 }
 
 void onStop(GtkButton *button, gpointer user_data)
 {
     intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET( button ) );
-    playlist_t *p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
-                                                       FIND_ANYWHERE );
+    playlist_t *p_playlist = pl_Hold( p_intf );
     if (p_playlist)
     {
         playlist_Stop( p_playlist );
-        vlc_object_release( p_playlist );
+        pl_Release( p_intf );
         gdk_window_raise( p_intf->p_sys->p_window->window );
     }
 }
@@ -457,7 +463,7 @@ void SliderMove(GtkRange *range, GtkScrollType scroll, gpointer user_data)
 }
 
 
-void addSelectedToPlaylist(GtkTreeModel *model, GtkTreePath *path,
+static void addSelectedToPlaylist(GtkTreeModel *model, GtkTreePath *path,
                            GtkTreeIter *iter, gpointer *userdata)
 {
     gchar *psz_filename;
@@ -478,13 +484,13 @@ void onFileListRow(GtkTreeView *treeview, GtkTreePath *path,
         struct stat   st;
         GtkTreeModel *p_model;
         GtkTreeIter   iter;
-        gchar        *psz_filename;
+        char         *psz_filename;
 
         /* This might be a directory selection */
         p_model = gtk_tree_view_get_model(treeview);
         if (!p_model)
         {
-            msg_Err(p_intf, "PDA: Filelist model contains a NULL pointer\n" );
+            msg_Err(p_intf, "PDA: Filelist model contains a NULL pointer" );
             return;
         }
         if (!gtk_tree_model_get_iter(p_model, &iter, path))
@@ -595,7 +601,7 @@ void onAddNetworkPlaylist(GtkButton *button, gpointer user_data)
     if (b_network_transcode)
     {
         msg_Dbg( p_intf, "Network transcode option selected." );
-        onAddTranscodeToPlaylist(GTK_WIDGET(button), (gchar *)psz_mrl_name);
+        onAddTranscodeToPlaylist(button, (gchar *)psz_mrl_name);
     }
     else
     {
@@ -649,16 +655,12 @@ void onAddCameraToPlaylist(GtkButton *button, gpointer user_data)
 
     ppsz_options = (char **) malloc(11 *sizeof(char*));
     if (ppsz_options == NULL)
-    {
-        msg_Err(p_intf, "No memory to allocate for v4l options.");
         return;
-    }
     for (i=0; i<11; i++)
     {
-        ppsz_options[i] = (char *) malloc(VLC_MAX_MRL * sizeof(char));
+        ppsz_options[i] = (char *) malloc(VLC_MAX_MRL);
         if (ppsz_options[i] == NULL)
         {
-            msg_Err(p_intf, "No memory to allocate for v4l options string %i.", i);
             for (i-=1; i>=0; i--)
                 free(ppsz_options[i]);
             free(ppsz_options);
@@ -733,7 +735,7 @@ void onAddCameraToPlaylist(GtkButton *button, gpointer user_data)
     if (b_v4l_transcode)
     {
         msg_Dbg( p_intf, "Camera transcode option selected." );
-        onAddTranscodeToPlaylist(GTK_WIDGET(button), (gchar *)v4l_mrl);
+        onAddTranscodeToPlaylist(button, (gchar *)v4l_mrl);
     }
     else
     {
@@ -765,8 +767,7 @@ void onPlaylistRow(GtkTreeView *treeview, GtkTreePath *path,
 {
     intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(treeview) );
     GtkTreeSelection *p_selection = gtk_tree_view_get_selection(treeview);
-    playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
-                                                       FIND_ANYWHERE );
+    playlist_t * p_playlist = pl_Hold( p_intf );
 
     if( p_playlist == NULL )
     {
@@ -778,12 +779,13 @@ void onPlaylistRow(GtkTreeView *treeview, GtkTreePath *path,
         GtkTreeModel *p_model;
         GtkTreeIter   iter;
         int           i_row;
+        int           i_skip;
 
         /* This might be a directory selection */
         p_model = gtk_tree_view_get_model(treeview);
         if (!p_model)
         {
-            msg_Err(p_intf, "PDA: Playlist model contains a NULL pointer\n" );
+            msg_Err(p_intf, "PDA: Playlist model contains a NULL pointer" );
             return;
         }
         if (!gtk_tree_model_get_iter(p_model, &iter, path))
@@ -793,17 +795,17 @@ void onPlaylistRow(GtkTreeView *treeview, GtkTreePath *path,
         }
 
         gtk_tree_model_get(p_model, &iter, 2, &i_row, -1);
-        playlist_Goto( p_playlist, i_row );
+        i_skip = i_row - p_playlist->i_current_index;
+        playlist_Skip( p_playlist, i_skip );
     }
-    vlc_object_release( p_playlist );
+    pl_Release( p_intf );
 }
 
 
 void onUpdatePlaylist(GtkButton *button, gpointer user_data)
 {
     intf_thread_t *  p_intf = GtkGetIntf( button );
-    playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
-                                                       FIND_ANYWHERE );
+    playlist_t * p_playlist = pl_Hold( p_intf );
     GtkTreeView *p_tvplaylist = NULL;
 
     if( p_playlist == NULL )
@@ -823,15 +825,15 @@ void onUpdatePlaylist(GtkButton *button, gpointer user_data)
                     G_TYPE_UINT);  /* Hidden field */
         if (p_model)
         {
-            PlaylistRebuildListStore(p_model, p_playlist);
+            PlaylistRebuildListStore(p_intf, p_model, p_playlist);
             gtk_tree_view_set_model(GTK_TREE_VIEW(p_tvplaylist), GTK_TREE_MODEL(p_model));
             g_object_unref(p_model);
         }
     }
-    vlc_object_release( p_playlist );
+    pl_Release( p_intf );
 }
 
-void deleteItemFromPlaylist(gpointer data, gpointer user_data)
+static void deleteItemFromPlaylist(gpointer data, gpointer user_data)
 {
     gtk_tree_path_free((GtkTreePath*) data); // removing an item.
 }
@@ -839,8 +841,7 @@ void deleteItemFromPlaylist(gpointer data, gpointer user_data)
 void onDeletePlaylist(GtkButton *button, gpointer user_data)
 {
     intf_thread_t *p_intf = GtkGetIntf( button );
-    playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
-                                                       FIND_ANYWHERE );
+    playlist_t * p_playlist = pl_Hold( p_intf );
     GtkTreeView    *p_tvplaylist;
 
     /* Delete an arbitrary item from the playlist */
@@ -897,20 +898,19 @@ void onDeletePlaylist(GtkButton *button, gpointer user_data)
                     G_TYPE_UINT);  /* Hidden field */
         if (p_store)
         {
-            PlaylistRebuildListStore(p_store, p_playlist);
+            PlaylistRebuildListStore(p_intf, p_store, p_playlist);
             gtk_tree_view_set_model(GTK_TREE_VIEW(p_tvplaylist), GTK_TREE_MODEL(p_store));
             g_object_unref(p_store);
         }
     }
-    vlc_object_release( p_playlist );
+    pl_Release( p_intf );
 }
 
 
 void onClearPlaylist(GtkButton *button, gpointer user_data)
 {
     intf_thread_t *p_intf = GtkGetIntf( button );
-    playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
-                                                       FIND_ANYWHERE );
+    playlist_t * p_playlist = pl_Hold( p_intf );
     GtkTreeView    *p_tvplaylist;
     int item;
 
@@ -919,11 +919,11 @@ void onClearPlaylist(GtkButton *button, gpointer user_data)
         return;
     }
 
-    for(item = p_playlist->i_size - 1; item >= 0 ;item-- )
+    for(item = playlist_CurrentSize(p_playlist) - 1; item >= 0 ;item-- )
     {
-        msg_Err( p_playlist "fix pda delete");
+        msg_Err( p_playlist, "fix pda delete" );
     }
-    vlc_object_release( p_playlist );
+    pl_Release( p_intf );
 
     // Remove all entries from the Playlist widget.
     p_tvplaylist = (GtkTreeView*) lookup_widget( GTK_WIDGET(button), "tvPlaylist");
@@ -1017,16 +1017,12 @@ void onAddTranscodeToPlaylist(GtkButton *button, gpointer user_data)
 
     ppsz_options = (char **) malloc(3 *sizeof(char*));
     if (ppsz_options == NULL)
-    {
-        msg_Err(p_intf, "No memory to allocate for v4l options.");
         return;
-    }
     for (i=0; i<3; i++)
     {
-        ppsz_options[i] = (char *) malloc(VLC_MAX_MRL * sizeof(char));
+        ppsz_options[i] = (char *) malloc(VLC_MAX_MRL);
         if (ppsz_options[i] == NULL)
         {
-            msg_Err(p_intf, "No memory to allocate for v4l options string %i.", i);
             for (i-=1; i>=0; i--)
                 free(ppsz_options[i]);
             free(ppsz_options);
@@ -1035,7 +1031,7 @@ void onAddTranscodeToPlaylist(GtkButton *button, gpointer user_data)
     }
 
     /* Update the playlist */
-    playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
+    playlist_t *p_playlist = pl_Hold( p_intf );
     if( p_playlist == NULL ) return;
 
     /* Get all the options. */