/*****************************************************************************
- * playlist_interface.c : Interface for the playlist dialog
+ * gtk_playlist.c : Interface for the playlist dialog
*****************************************************************************
- * Copyright (C) 2000, 2001 VideoLAN
+ * Copyright (C) 2001 VideoLAN
*
- * Authors: .Pierre Baillet <oct@zoy.org>
+ * Authors: Pierre Baillet <oct@zoy.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "input_ext-intf.h"
#include "interface.h"
-#include "intf_plst.h"
+#include "intf_playlist.h"
#include "intf_msg.h"
#include "intf_urldecode.h"
-#include "gtk_sys.h"
#include "gtk_callbacks.h"
#include "gtk_interface.h"
#include "gtk_support.h"
+#include "intf_gtk.h"
#include "main.h"
void on_generic_drop_data_received( intf_thread_t * p_intf,
GtkSelectionData *data, guint info, int position);
-
-static __inline__ intf_thread_t * GetIntf( GtkWidget *item, char * psz_parent )
-{
- return( gtk_object_get_data( GTK_OBJECT( lookup_widget(item, psz_parent) ),
- "p_intf" ) );
-}
-
-
-
void
on_menubar_playlist_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
+
intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), "intf_window" );
playlist_t * p_playlist ;
GtkCList * list;
if( !GTK_IS_WIDGET( p_intf->p_sys->p_playlist ) )
{
+ /* this shoud never happen */
+ intf_ErrMsgImm("intf_playlist is not a widget !");
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 );
}
-
vlc_mutex_lock( &p_main->p_playlist->change_lock );
if(p_main->p_playlist->i_size > 0 )
{
p_playlist = p_main->p_playlist;
-
- list = GTK_CLIST(lookup_widget( p_intf->p_sys->p_playlist, "clist1" )) ;
+ list = GTK_CLIST(lookup_widget( p_intf->p_sys->p_playlist, "playlist_clist" )) ;
rebuildCList( list, p_playlist );
-
-
}
vlc_mutex_unlock( &p_main->p_playlist->change_lock );
if( !GTK_IS_WIDGET( p_intf->p_sys->p_playlist ) )
{
+ /* this shoud never happen */
+ intf_ErrMsgImm("intf_playlist is not a widget !");
+
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 );
}
if( GTK_WIDGET_VISIBLE(p_intf->p_sys->p_playlist) ) {
gtk_widget_hide( p_intf->p_sys->p_playlist);
- } else {
+ }
+ else
+ {
+ GtkCList * clist;
gtk_widget_show( p_intf->p_sys->p_playlist );
+ clist = GTK_CLIST(lookup_widget( p_intf->p_sys->p_playlist,"playlist_clist" ));
gdk_window_raise( p_intf->p_sys->p_playlist->window );
+ rebuildCList( clist , p_main->p_playlist );
}
}
int curRow = ( int )data;
intf_thread_t * p_intf = param;
- intf_PlstDelete( p_main->p_playlist, curRow );
+ intf_PlaylistDelete( p_main->p_playlist, curRow );
/* are we deleting the current played stream */
if( p_intf->p_sys->i_playing == curRow )
gtk_clist_thaw( clist );
}
+void
+on_invertselection_clicked (GtkMenuItem *item, gpointer user_data)
+{
+ int * selected, sel_l;
+ GtkCList * clist;
+ playlist_t * playlist_p;
+ int dummy;
+
+ /* catch the thread back */
+ intf_thread_t *p_intf = GetIntf( GTK_WIDGET(item), "intf_playlist" );
+ playlist_p = p_main->p_playlist;
+
+ /* lock the struct */
+ vlc_mutex_lock( &p_intf->change_lock );
+ clist = GTK_CLIST( lookup_widget(p_intf->p_sys->p_playlist,"playlist_clist") );
+
+ /* have to copy the selection to an int *
+ I wasn't able to copy the g_list to another g_list
+ glib only does pointer copies, not real copies :( */
+
+ selected = malloc(sizeof(int)* g_list_length(clist->selection));
+ sel_l = g_list_length(clist->selection);
+ for(dummy=0; dummy < sel_l; dummy++)
+ {
+ selected[dummy] = (int)g_list_nth_data(clist->selection,dummy);
+ }
+
+ gtk_clist_freeze( clist );
+ gtk_clist_select_all( clist );
+ for(dummy=0; dummy < sel_l; dummy++)
+ {
+ gtk_clist_unselect_row( clist, selected[dummy],0);
+ gtk_clist_unselect_row( clist, selected[dummy],1);
+ }
+ free( selected );
+ gtk_clist_thaw( clist );
+ vlc_mutex_unlock( &p_intf->change_lock );
+}
+
+void
+on_crop_activate (GtkMenuItem *menuitem,
+ gpointer user_data)
+{
+ /* Ok, this is a really small thing, but, hey, it works and
+ might be useful, who knows ? */
+
+ on_invertselection_clicked (menuitem, user_data);
+ on_delete_clicked(menuitem, user_data);
+}
+
+
void
on_delete_clicked (GtkMenuItem *item,
gpointer user_data)
playlist_p = p_main->p_playlist;
/* lock the struct */
- vlc_mutex_lock( &p_intf->p_sys->change_lock );
- clist = GTK_CLIST( lookup_widget(p_intf->p_sys->p_playlist,"clist1") );
+ vlc_mutex_lock( &p_intf->change_lock );
+ clist = GTK_CLIST( lookup_widget(p_intf->p_sys->p_playlist,"playlist_clist") );
/* I use UNDOCUMENTED features to retrieve the selection... */
selection = clist->selection;
if( g_list_length(selection)>0 )
{
+ /* reverse-sort so that we can delete from the furthest to the
+ closest item to delete...
+ */
selection = g_list_sort( selection, compareItems );
g_list_foreach( selection,
deleteGListItem,
rebuildCList( clist, playlist_p );
}
- vlc_mutex_unlock( &p_intf->p_sys->change_lock );
+ vlc_mutex_unlock( &p_intf->change_lock );
}
gboolean
GdkEvent *event,
gpointer user_data)
{
- gtk_widget_hide(widget);
-
- return TRUE;
+ /* hide ! */
+ gtk_widget_hide(widget);
+ return TRUE;
}
void
GtkCList * clist;
gint row, col;
- clist = GTK_CLIST(lookup_widget( p_intf->p_sys->p_playlist,"clist1" ));
-
+ clist = GTK_CLIST(lookup_widget( p_intf->p_sys->p_playlist,"playlist_clist" ));
+
+ /* are we dropping somewhere into the clist items ? */
if( gtk_clist_get_selection_info( clist,
x,
y,
&row,
&col )== 1)
{
- on_generic_drop_data_received( p_intf, data, info, row);
- } else {
- on_generic_drop_data_received( p_intf, data, info, 0);
+ on_generic_drop_data_received( p_intf, data, info, row );
+ }
+ /* else, put that at the end of the playlist */
+ else
+ {
+ on_generic_drop_data_received( p_intf, data, info, PLAYLIST_END);
}
}
}
/* this cuts string into single file drops */
+ /* this code was borrowed from xmms, thx guys :) */
while(*string)
{
temp = strchr(string, '\n');
}
intf_WarnMsg(1,"Dropped %s",string);
- } else {
+ }
+ else
+ {
protocol = strdup("");
}
if(files != NULL)
{
/* lock the interface */
- vlc_mutex_lock( &p_intf->p_sys->change_lock );
- intf_WarnMsg(1, "List has %d elements",g_list_length(files));
+ vlc_mutex_lock( &p_intf->change_lock );
+ intf_WarnMsg( 1, "List has %d elements",g_list_length( files ) );
intf_AppendList( p_playlist, position, files );
+
/* get the CList and rebuild it. */
- clist = GTK_CLIST(lookup_widget( p_intf->p_sys->p_playlist,"clist1" ));
+ clist = GTK_CLIST(
+ lookup_widget( p_intf->p_sys->p_playlist,
+ "playlist_clist" ) );
rebuildCList( clist , p_playlist );
/* unlock the interface */
- vlc_mutex_unlock( &p_intf->p_sys->change_lock );
+ vlc_mutex_unlock( &p_intf->change_lock );
}
}
/* check a file (string) against supposed valid extension */
int
-hasValidExtension(gchar * filename)
+hasValidExtension( gchar * filename )
{
char * ext[6] = {"mpg","mpeg","vob","mp2","ts","ps"};
int i_ext = 6;
int dummy;
- gchar * p_filename = strrchr( filename, '.') + sizeof( char );
- for(dummy=0; dummy<i_ext;dummy++)
+ gchar * p_filename = strrchr( filename, '.' ) + sizeof( char );
+ for( dummy=0; dummy<i_ext;dummy++ )
{
- if(strcmp(p_filename,ext[dummy])==0)
+ if( strcmp( p_filename,ext[dummy] )==0 )
return 1;
}
return 0;
/* recursive function: descend into folders and build a list of valid filenames */
GList *
-intf_readFiles(gchar * fsname )
+intf_readFiles( gchar * fsname )
{
struct stat statbuf;
GList * current = NULL;
+ /* get the attributes of this file */
stat(fsname, &statbuf);
/* is it a regular file ? */
{
intf_WarnMsg( 3, "%s is a valid file. Stacking on the playlist", fsname );
return g_list_append( NULL, g_strdup(fsname) );
- } else
+ }
+ else
+ {
return NULL;
+ }
}
/* is it a directory (should we check for symlinks ?) */
else if( S_ISDIR( statbuf.st_mode ) )
strlen( dirContent->d_name ) * sizeof( char ) );
strcpy( newfs, fsname );
strcpy( newfs + strlen( fsname )+1, dirContent->d_name);
- newfs[strlen(fsname)] = '/';
+ newfs[strlen( fsname )] = '/';
current = g_list_concat( current, intf_readFiles( newfs ) );
return NULL;
}
-/* add items in a playlist */
+/* add items in a playlist
+ when i_pos==-1 add to the end of the list...
+ */
int intf_AppendList( playlist_t * p_playlist, int i_pos, GList * list )
{
guint length, dummy;
length = g_list_length( list );
- for(dummy=0; dummy<length; dummy++)
+ for( dummy=0; dummy<length; dummy++ )
{
- intf_WarnMsg(1,"Adding: %s@%d",g_list_nth_data(list, dummy), i_pos + dummy);
- intf_PlstAdd( p_playlist, i_pos + dummy, g_list_nth_data(list, dummy));
+ intf_PlaylistAdd( p_playlist,
+ /* ok; this is a really nasty trick to insert
+ the item where they are suppose to go but, hey
+ this works :P (btw, you are really nasty too) */
+ i_pos==PLAYLIST_END?PLAYLIST_END:( i_pos + dummy ),
+ g_list_nth_data(list, dummy));
}
return 0;
}
gboolean
-on_clist1_event (GtkWidget *widget,
- GdkEvent *event,
- gpointer user_data)
+on_playlist_clist_event (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer user_data)
{
- intf_thread_t * p_intf = GetIntf( GTK_WIDGET(widget), "intf_playlist" );
+ intf_thread_t * p_intf = GetIntf( GTK_WIDGET( widget ), "intf_playlist" );
- if( (event->button).type == GDK_2BUTTON_PRESS )
+ if( ( event->button ).type == GDK_2BUTTON_PRESS )
{
GtkCList * clist;
gint row, col;
- clist = GTK_CLIST(lookup_widget( p_intf->p_sys->p_playlist,"clist1" ));
+ clist = GTK_CLIST(
+ lookup_widget(
+ p_intf->p_sys->p_playlist,
+ "playlist_clist" ) );
+
if( gtk_clist_get_selection_info( clist,
(event->button).x,
(event->button).y,
&row,
- &col )== 1)
+ &col )== 1 )
{
/* clicked is in range. */
/* FIXME: temporary hack */
p_intf->p_input->b_eof = 1;
}
- intf_PlstJumpto( p_main->p_playlist, row-1 );
+ intf_PlaylistJumpto( p_main->p_playlist, row-1 );
}
return TRUE;
}
/* statis timeouted function */
void GtkPlayListManage( gpointer p_data )
{
-
/* this thing really sucks for now :( */
- /* TODO speak more with interface/intf_plst.c */
+ /* TODO speak more with interface/intf_playlist.c */
intf_thread_t *p_intf = (void *)p_data;
playlist_t * p_playlist = p_main->p_playlist ;
- vlc_mutex_lock( &p_intf->p_sys->change_lock );
+ vlc_mutex_lock( &p_intf->change_lock );
- if(p_intf->p_sys->i_playing != p_playlist->i_index)
+ if( p_intf->p_sys->i_playing != p_playlist->i_index )
{
GdkColor color;
- color.red = 65535;
+ color.red = 0xffff;
color.green = 0;
color.blue = 0;
- gtk_clist_set_background (
- GTK_CLIST(lookup_widget( p_intf->p_sys->p_playlist, "clist1" ) ),
- p_playlist->i_index,
- &color);
+ gtk_clist_set_background ( GTK_CLIST(
+ lookup_widget( p_intf->p_sys->p_playlist,
+ "playlist_clist" ) ),
+ p_playlist->i_index,
+ &color );
+
if( p_intf->p_sys->i_playing != -1 )
{
- color.red = 65535;
- color.green = 65535;
- color.blue = 65535;
+ color.red = 0xffff;
+ color.green = 0xffff;
+ color.blue = 0xffff;
gtk_clist_set_background (
- GTK_CLIST(lookup_widget( p_intf->p_sys->p_playlist, "clist1" ) ),
+ GTK_CLIST(lookup_widget( p_intf->p_sys->p_playlist, "playlist_clist" ) ),
p_intf->p_sys->i_playing,
&color);
}
p_intf->p_sys->i_playing = p_playlist->i_index;
}
- vlc_mutex_unlock( &p_intf->p_sys->change_lock );
+ vlc_mutex_unlock( &p_intf->change_lock );
}