]> git.sesse.net Git - vlc/blobdiff - plugins/gtk/gtk_playlist.c
* ./BUGS: added a list of known bugs. Please add your findings!
[vlc] / plugins / gtk / gtk_playlist.c
index f36f286a31f2bf2673d942cc8984ceb70a33bbcb..cdd3be5fd23bba61dc92b527d71483babe1bab7f 100644 (file)
@@ -2,7 +2,7 @@
  * gtk_playlist.c : Interface for the playlist dialog
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: gtk_playlist.c,v 1.16 2001/05/30 23:02:04 stef Exp $
+ * $Id: gtk_playlist.c,v 1.25 2002/01/04 14:01:34 sam 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>
+
+#ifndef WIN32
+#   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 "gtk_callbacks.h"
 #include "gtk_interface.h"
 #include "gtk_support.h"
 #include "gtk_playlist.h"
-#include "intf_gtk.h"
-
-#include "main.h"
-
-#include "modules_export.h"
+#include "gtk_common.h"
 
 /****************************************************************************
  * Playlist window management
@@ -69,26 +66,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 );
@@ -261,8 +238,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 );
@@ -414,6 +391,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;
@@ -437,34 +415,36 @@ void GtkDropDataReceived( intf_thread_t * p_intf,
     /* 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 +460,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 +498,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 );
@@ -709,17 +695,24 @@ void GtkRebuildCList( GtkCList * p_clist, playlist_t * p_playlist )
     for( i_dummy = 0; i_dummy < p_playlist->i_size ; i_dummy++ )
     {
 #ifdef WIN32 /* WIN32 HACK */
-        ppsz_text[0] = g_strdup( "" );
+        ppsz_text[0] = "";
 #else
-        ppsz_text[0] = g_strdup( rindex( (char *)(p_playlist->p_item[
-                p_playlist->i_size - 1 - i_dummy].psz_name ), '/' ) + 1 );
+        ppsz_text[0] = rindex( p_playlist->p_item[
+                p_playlist->i_size - 1 - i_dummy].psz_name, '/' );
+        if ( ppsz_text[0] == NULL )
+        {
+            ppsz_text[0] =
+              p_playlist->p_item[ p_playlist->i_size - 1 - i_dummy ].psz_name;
+        }
+        else
+        {
+            /* Skip leading '/' */
+            ppsz_text[0]++;
+        }
 #endif
-        ppsz_text[1] = g_strdup( "no info");
+        ppsz_text[1] = "no info";
         
         gtk_clist_insert( p_clist, 0, ppsz_text );
-        
-        free( ppsz_text[0] );
-        free( ppsz_text[1] );
     }
     gtk_clist_set_background( p_clist, p_playlist->i_index, &red);
     gtk_clist_thaw( p_clist );