]> git.sesse.net Git - vlc/blobdiff - plugins/gtk/gtk_playlist.c
* ./plugins/text/logger.c: on win32 the logger interface shows up a dos
[vlc] / plugins / gtk / gtk_playlist.c
index 72fabe8b96b4fada1def0504c00b831ca2bb9a07..50ac2e5293651036c9cf92c70abd0184aa443c1f 100644 (file)
@@ -2,7 +2,7 @@
  * gtk_playlist.c : Interface for the playlist dialog
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: gtk_playlist.c,v 1.14 2001/05/23 23:08:20 stef Exp $
+ * $Id: gtk_playlist.c,v 1.31 2002/05/22 14:20:41 gbazin Exp $
  *
  * Authors: Pierre Baillet <oct@zoy.org>
  *          Stéphane Borel <stef@via.ecp.fr>
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include "defs.h"
-
 #include <stdlib.h>
-
-#include <gtk/gtk.h>
-
 #include <string.h>
 
+#include <videolan/vlc.h>
+
 #include <sys/types.h>          /* for readdir  and stat stuff */
-#include <dirent.h>
+
+#if (!defined( WIN32 ) || defined(__MINGW32__))
+/* Mingw has its own version of dirent */
+#   include <dirent.h>
+#endif
+
 #include <sys/stat.h>
 #include <unistd.h>
 
-#include "config.h"
-#include "common.h"
-#include "threads.h"
-#include "mtime.h"
+#ifdef MODULE_NAME_IS_gnome
+#   include <gnome.h>
+#else
+#   include <gtk/gtk.h>
+#endif
 
 #include "stream_control.h"
 #include "input_ext-intf.h"
 
 #include "interface.h"
 #include "intf_playlist.h"
-#include "intf_msg.h"
-#include "intf_urldecode.h"
 
 #include "gtk_callbacks.h"
 #include "gtk_interface.h"
 #include "gtk_support.h"
 #include "gtk_playlist.h"
-#include "intf_gtk.h"
-
-
-#include "main.h"
+#include "gtk_common.h"
 
 /****************************************************************************
  * Playlist window management
@@ -69,26 +67,6 @@ gboolean GtkPlaylistShow( GtkWidget       *widget,
 {
     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
 
-    if( !GTK_IS_WIDGET( p_intf->p_sys->p_playlist ) )
-    {
-        /* The data types we are allowed to receive */
-        static GtkTargetEntry target_table[] =
-        {
-            { "text/uri-list", 0, DROP_ACCEPT_TEXT_URI_LIST },
-            { "text/plain", 0, DROP_ACCEPT_TEXT_PLAIN }
-        };
-
-        p_intf->p_sys->p_playlist = create_intf_playlist();
-        gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_playlist ),
-                             "p_intf", p_intf );
-
-        /* Accept file drops on the playlist window */
-        gtk_drag_dest_set( GTK_WIDGET( lookup_widget( p_intf->p_sys->p_playlist,
-                                       "playlist_clist") ),
-                           GTK_DEST_DEFAULT_ALL, target_table,
-                           1, GDK_ACTION_COPY );
-    }
-
     if( GTK_WIDGET_VISIBLE( p_intf->p_sys->p_playlist ) )
     {
         gtk_widget_hide( p_intf->p_sys->p_playlist );
@@ -125,14 +103,12 @@ gboolean GtkPlaylistPrev( GtkWidget       *widget,
                           GdkEventButton  *event,
                           gpointer         user_data )
 {
-    intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
-
-    if( p_intf->p_input != NULL )
+    if( p_input_bank->pp_input[0] != NULL )
     {
         /* FIXME: temporary hack */
         intf_PlaylistPrev( p_main->p_playlist );
         intf_PlaylistPrev( p_main->p_playlist );
-        p_intf->p_input->b_eof = 1;
+        p_input_bank->pp_input[0]->b_eof = 1;
     }
 
     return TRUE;
@@ -143,12 +119,10 @@ gboolean GtkPlaylistNext( GtkWidget       *widget,
                           GdkEventButton  *event,
                           gpointer         user_data)
 {
-    intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
-
-    if( p_intf->p_input != NULL )
+    if( p_input_bank->pp_input[0] != NULL )
     {
         /* FIXME: temporary hack */
-        p_intf->p_input->b_eof = 1;
+        p_input_bank->pp_input[0]->b_eof = 1;
     }
 
     return TRUE;
@@ -198,7 +172,7 @@ void GtkPlaylistDeleteSelected( GtkMenuItem * menuitem, gpointer user_data )
     playlist_t *p_playlist;
     
     /* catch the thread back */
-    intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), (char*)user_data );
+    intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), /*(char*)user_data*/"intf_playlist" );
 
     p_playlist = p_main->p_playlist;
     
@@ -261,8 +235,8 @@ void GtkPlaylistInvert( GtkMenuItem * menuitem, gpointer user_data )
 
     for( i_dummy = 0 ; i_dummy < i_sel_l ; i_dummy++)
     {
-        pi_selected[i_dummy] = (int)g_list_nth_data( p_clist->selection,
-                                                     i_dummy );
+        pi_selected[i_dummy] = (long)g_list_nth_data( p_clist->selection,
+                                                      i_dummy );
     }
     
     gtk_clist_freeze( p_clist );
@@ -304,10 +278,10 @@ gboolean GtkPlaylistEvent( GtkWidget * widget,
                     (event->button).y, &i_row, &i_col ) == 1 )
         {
             /* clicked is in range. */
-            if( p_intf->p_input != NULL )
+            if( p_input_bank->pp_input[0] != NULL )
             {
                 /* FIXME: temporary hack */
-                p_intf->p_input->b_eof = 1;
+                p_input_bank->pp_input[0]->b_eof = 1;
             }
 
             intf_PlaylistJumpto( p_main->p_playlist, i_row - 1 );
@@ -414,6 +388,7 @@ void GtkDropDataReceived( intf_thread_t * p_intf,
     /* first we'll have to split against all the '\n' we have */
     gchar *     p_protocol;
     gchar *     p_temp;
+    gchar *     p_next;
     gchar *     p_string = p_data->data ;
     GList *     p_files = NULL;
     GtkCList *  p_clist;
@@ -430,41 +405,43 @@ void GtkDropDataReceived( intf_thread_t * p_intf,
      */
     if( i_info == DROP_ACCEPT_TEXT_URI_LIST )
     {
-        urldecode_path( p_string );
+        intf_UrlDecode( p_string );
     }
     
     /* this cuts string into single file drops */
     /* this code was borrowed from xmms, thx guys :) */
     while( *p_string)
     {
-        p_temp = strchr( p_string, '\n' );
-        if( p_temp )
+        p_next = strchr( p_string, '\n' );
+        if( p_next )
         {
-            if( *( p_temp - 1 ) == '\r' )
+            if( *( p_next - 1 ) == '\r' )
             {
-                *( p_temp - 1) = '\0';
+                *( p_next - 1) = '\0';
             }
-            *p_temp = '\0';
+            *p_next = '\0';
         }
 
         /* do we have a protocol or something ? */
-        p_protocol = strstr( p_string, ":/" );
-        if( p_protocol != NULL )
+        p_temp = strstr( p_string, ":" );
+        if( p_temp != NULL && p_temp[0] != '\0' )
         {
-            p_protocol = calloc( p_protocol - p_string + 2, sizeof(char) );
-            p_protocol = strncpy( p_protocol, p_string,
-                                  strstr( p_string, ":/" ) + 1 - p_string );
+            char i_save;
 
-            intf_WarnMsg( 4, "Protocol dropped is %s", p_protocol );
-            p_string += strlen( p_protocol );
+            i_save = p_temp[0];
+            p_temp[0] = '\0';
+            p_protocol = strdup( p_string );
+            p_temp[0] = i_save;
+            p_temp++;
 
             /* Allowed things are proto: or proto:// */
-            if( p_string[0] == '/' && p_string[1] == '/')
+            if( p_temp[0] == '/' && p_temp[1] == '/')
             {
-                /* eat one '/' */
-                p_string++;
+                /* eat two '/'s */
+                p_temp += 2;
             }
-            intf_WarnMsg( 4, " Dropped %s", p_string );
+            intf_WarnMsg( 4, "playlist: protocol '%s', target '%s'",
+                          p_protocol, p_temp );
         } 
         else 
         {
@@ -480,14 +457,20 @@ void GtkDropDataReceived( intf_thread_t * p_intf,
         {
             p_files = g_list_concat( p_files, GtkReadFiles( p_string ) ); 
         }
+        else
+        {
+            p_files = g_list_concat( p_files,
+                      g_list_append( NULL, g_strdup( p_string ) ) );
+        }
        
         /* free the malloc and go on... */
         free( p_protocol );
-        if( !p_temp )
+
+        if( p_next == NULL )
         {
             break;
         }
-        p_string = p_temp + 1;
+        p_string = p_next + 1;
     }
    
     /* At this point, we have a nice big list maybe NULL */
@@ -512,7 +495,7 @@ void GtkDropDataReceived( intf_thread_t * p_intf,
 
 void GtkDeleteGListItem( gpointer data, gpointer param )
 {
-    int i_cur_row = ( int )data;
+    int i_cur_row = (long)data;
     intf_thread_t * p_intf = param;    
     
     intf_PlaylistDelete( p_main->p_playlist, i_cur_row );
@@ -521,7 +504,7 @@ void GtkDeleteGListItem( gpointer data, gpointer param )
     if( p_intf->p_sys->i_playing == i_cur_row )
     {
         /* next ! */
-        p_intf->p_input->b_eof = 1;
+        p_input_bank->pp_input[0]->b_eof = 1;
         /* this has to set the slider to 0 */
         
         /* step minus one */
@@ -706,22 +689,15 @@ void GtkRebuildCList( GtkCList * p_clist, playlist_t * p_playlist )
     gtk_clist_freeze( p_clist );
     gtk_clist_clear( p_clist );
    
-    for( i_dummy = 0; i_dummy < p_playlist->i_size ; i_dummy++ )
+    vlc_mutex_lock( &p_playlist->change_lock );
+    for( i_dummy = p_playlist->i_size ; i_dummy-- ; )
     {
-#ifdef WIN32 /* WIN32 HACK */
-        ppsz_text[0] = g_strdup( "" );
-#else
-        ppsz_text[0] = g_strdup( rindex( (char *)(p_playlist->p_item[
-                p_playlist->i_size - 1 - i_dummy].psz_name ), '/' ) + 1 );
-#endif
-        ppsz_text[1] = g_strdup( "no info");
-        
+        ppsz_text[0] = p_playlist->p_item[i_dummy].psz_name;
+        ppsz_text[1] = "no info";
         gtk_clist_insert( p_clist, 0, ppsz_text );
-        
-        free( ppsz_text[0] );
-        free( ppsz_text[1] );
     }
+    vlc_mutex_unlock( &p_playlist->change_lock );
+
     gtk_clist_set_background( p_clist, p_playlist->i_index, &red);
     gtk_clist_thaw( p_clist );
 }
-