[PATCH] GTK GUI, Correct use filenames on non-utf8 localized systems
Hello. There is trouble using gmplayer on non-utf8 localized systems, filenames are not handled correctly. This patch fixes it. --------------------- diff -ur mplayer.orig/Gui/mplayer/gtk/fs.c mplayer/Gui/mplayer/gtk/fs.c --- mplayer.orig/Gui/mplayer/gtk/fs.c 2007-03-21 08:15:03.000000000 +0300 +++ mplayer/Gui/mplayer/gtk/fs.c 2007-05-30 21:28:47.000000000 +0400 @@ -175,10 +175,11 @@ stat( gg.gl_pathv[i],&fs ); if( !S_ISDIR( fs.st_mode ) ) continue; - str[0][1]=gg.gl_pathv[i]; + str[0][1]=g_filename_to_utf8( gg.gl_pathv[i],-1,NULL,NULL,NULL ); pixmap=dpixmap; mask=dmask; gtk_clist_append( GTK_CLIST( list ),str[0] ); gtk_clist_set_pixmap( GTK_CLIST( list ),c++,0,pixmap,mask ); + g_free(str[0][1]); } globfree( &gg ); @@ -223,9 +224,10 @@ stat( gg.gl_pathv[i],&fs ); if( S_ISDIR( fs.st_mode ) ) continue; - str[0][1]=gg.gl_pathv[i]; + str[0][1]=g_filename_to_utf8( gg.gl_pathv[i],-1,NULL,NULL,NULL ); gtk_clist_append( GTK_CLIST( list ),str[0] ); gtk_clist_set_pixmap( GTK_CLIST( list ),c++,0,pixmap,mask ); + g_free(str[0][1]); } globfree( &gg ); @@ -321,21 +323,32 @@ free( dir ); } - if ( fsTopList_items ) g_list_free( fsTopList_items ); fsTopList_items=NULL; + if ( fsTopList_items ) + { + GList *item; + item=fsTopList_items; + while( item ) + { + g_free( item->data ); + item=item->next; + } + g_list_free( fsTopList_items ); + } + fsTopList_items=NULL; { int i, c = 1; if ( fsType == fsVideoSelector ) { for ( i=0;i < fsPersistant_MaxPos;i++ ) - if ( fsHistory[i] ) { fsTopList_items=g_list_append( fsTopList_items,fsHistory[i] ); c=0; } + if ( fsHistory[i] ) { fsTopList_items=g_list_append( fsTopList_items,g_filename_to_utf8( fsHistory[i],-1,NULL,NULL,NULL ) ); c=0; } } - if ( c ) fsTopList_items=g_list_append( fsTopList_items,(gchar *)get_current_dir_name() ); + if ( c ) {fsTopList_items=g_list_append( fsTopList_items,g_filename_to_utf8 ( get_current_dir_name(),-1,NULL,NULL,NULL ) ); } } - if ( getenv( "HOME" ) ) fsTopList_items=g_list_append( fsTopList_items,getenv( "HOME" ) ); - fsTopList_items=g_list_append( fsTopList_items,"/home" ); - fsTopList_items=g_list_append( fsTopList_items,"/mnt" ); - fsTopList_items=g_list_append( fsTopList_items,"/" ); + if ( getenv( "HOME" ) ) fsTopList_items=g_list_append( fsTopList_items,g_filename_to_utf8( getenv( "HOME" ),-1,NULL,NULL,NULL ) ); + fsTopList_items=g_list_append( fsTopList_items,g_filename_to_utf8 ("/home",-1,NULL,NULL,NULL) ); + fsTopList_items=g_list_append( fsTopList_items,g_filename_to_utf8 ("/mnt",-1,NULL,NULL,NULL) ); + fsTopList_items=g_list_append( fsTopList_items,g_filename_to_utf8 ("/",-1,NULL,NULL,NULL) ); gtk_combo_set_popdown_strings( GTK_COMBO( fsCombo4 ),fsTopList_items ); gtk_window_set_modal( GTK_WINDOW( fsFileSelect ),modal ); @@ -418,25 +431,36 @@ { unsigned char * str; - str=gtk_entry_get_text( GTK_ENTRY( user_data ) ); + str=g_filename_from_utf8( gtk_entry_get_text( GTK_ENTRY( user_data ) ),-1,NULL,NULL,NULL ); if ( chdir( str ) != -1 ) CheckDir( fsFNameList,get_current_dir_name() ); + g_free(str); } void fs_fsPathCombo_changed( GtkEditable * editable,gpointer user_data ) { unsigned char * str; - str=gtk_entry_get_text( GTK_ENTRY( user_data ) ); + str=g_filename_from_utf8( gtk_entry_get_text( GTK_ENTRY( user_data ) ),-1,NULL,NULL,NULL ); fsPressed=2; if ( chdir( str ) != -1 ) CheckDir( fsFNameList,get_current_dir_name() ); + g_free(str); +} + +static void set_selected_file(const gchar *str) +{ + if (fsSelectedFile) g_free(fsSelectedFile); + fsSelectedFile=g_filename_from_utf8(str,-1,NULL,NULL,NULL); } void fs_Up_released( GtkButton * button,gpointer user_data ) { + gchar *str; chdir( ".." ); - fsSelectedFile=fsThatDir; + set_selected_file(fsThatDir); CheckDir( fsFNameList,get_current_dir_name() ); - gtk_entry_set_text( GTK_ENTRY( fsPathCombo ),(unsigned char *)get_current_dir_name() ); + str=g_filename_to_utf8( (unsigned char *)get_current_dir_name(),-1,NULL,NULL,NULL ); + gtk_entry_set_text( GTK_ENTRY( fsPathCombo ),str ); + g_free(str); return; } @@ -459,9 +483,11 @@ if( S_ISDIR(fs.st_mode ) ) { chdir( fctedFile ); - fsSelectedFile=fsThatDir; + set_selected_file(fsThatDir); + str=g_filename_to_utf8( get_current_dir_name(),-1,NULL,NULL,NULL ); CheckDir( fsFNameList,get_current_dir_name() ); - gtk_entry_set_text( GTK_ENTRY( fsPathCombo ),(unsigned char *)get_current_dir_name() ); + gtk_entry_set_text( GTK_ENTRY( fsPathCombo ),str ); + g_free(str); return; } @@ -472,7 +498,7 @@ break; case 2: str=gtk_entry_get_text( GTK_ENTRY( fsPathCombo ) ); - fsSelectedFile=str; + set_selected_file(str); if ( !fsFileExist( fsSelectedFile ) ) { HideFileSelect(); return; } fsSelectedDirectory=fsSelectedFile; size=strlen( fsSelectedDirectory ); @@ -522,7 +548,8 @@ if ( !strcmp( item->data,fsSelectedDirectory ) ) i=0; item=item->next; } - if ( i ) fsTopList_items=g_list_prepend( fsTopList_items,(gchar *)get_current_dir_name() ); + if ( i ) fsTopList_items=g_list_prepend( fsTopList_items,g_filename_to_utf8( get_current_dir_name(),-1,NULL,NULL,NULL ) ); + if ( mplMainAutoPlay ) { mplMainAutoPlay=0; mplEventHandling( evPlay,0 ); } else guiGetEvent( guiCEvent,guiSetStop ); } @@ -535,7 +562,9 @@ void fs_fsFNameList_select_row( GtkWidget * widget,gint row,gint column,GdkEventButton *bevent,gpointer user_data ) { - gtk_clist_get_text( GTK_CLIST(widget ),row,1,&fsSelectedFile ); + gchar *str; + gtk_clist_get_text( GTK_CLIST(widget ),row,1,&str ); + set_selected_file(str); fsPressed=1; if( bevent && bevent->type == GDK_BUTTON_PRESS ) gtk_button_released( GTK_BUTTON( fsOk ) ); } diff -ur mplayer.orig/Gui/mplayer/gtk/pl.c mplayer/Gui/mplayer/gtk/pl.c --- mplayer.orig/Gui/mplayer/gtk/pl.c 2007-03-21 08:15:03.000000000 +0300 +++ mplayer/Gui/mplayer/gtk/pl.c 2007-05-30 18:54:22.000000000 +0400 @@ -160,9 +160,10 @@ while ( next || next->next ) { char * text[1][3]; text[0][2]=""; - text[0][0]=next->name; + text[0][0]=g_filename_to_utf8( next->name,-1,NULL,NULL,NULL ); text[0][1]=next->path; gtk_clist_append( GTK_CLIST( CLSelected ),text[0] ); + g_free(text[0][0]); NrOfSelected++; if ( next->next ) next=next->next; else break; } @@ -217,7 +218,7 @@ item=calloc( 1,sizeof( plItem ) ); gtk_clist_get_text( GTK_CLIST( CLSelected ),i,0,&text[0] ); gtk_clist_get_text( GTK_CLIST( CLSelected ),i,1,&text[1] ); - item->name=strdup( text[0] ); + item->name=g_filename_from_utf8( text[0],-1,NULL,NULL,NULL ); item->path=strdup( text[1] ); gtkSet( gtkAddPlItem,0,(void*)item ); } @@ -332,7 +333,7 @@ path=calloc( 1,strlen( DirNode->path ) + strlen( dirent->d_name ) + 2 ); if ( !strcmp( current_path,"/" ) ) sprintf( path,"/%s",dirent->d_name ); else sprintf( path,"%s/%s",current_path,dirent->d_name ); - text=dirent->d_name; + text=g_filename_to_utf8( dirent->d_name,-1,NULL,NULL,NULL ); if ( stat( path,&statbuf ) != -1 && S_ISDIR( statbuf.st_mode ) && dirent->d_name[0] != '.' ) { @@ -342,6 +343,7 @@ gtk_ctree_node_set_row_data_full( ctree,node,DirNode,NULL ); if ( subdir ) node=gtk_ctree_insert_node( ctree,node,NULL,&dummy,4,NULL,NULL,NULL,NULL,FALSE,FALSE ); } + g_free( text ); free( path ); path=NULL; } closedir( dir ); @@ -369,9 +371,10 @@ curr=calloc( 1,strlen( path ) + strlen( dirent->d_name ) + 3 ); sprintf( curr,"%s/%s",path,dirent->d_name ); if ( stat( curr,&statbuf ) != -1 && ( S_ISREG( statbuf.st_mode ) || S_ISLNK( statbuf.st_mode ) ) ) { - text[0][0]=dirent->d_name; + text[0][0]=g_filename_to_utf8( dirent->d_name,-1,NULL,NULL,NULL ); gtk_clist_append( GTK_CLIST( CLFiles ),text[0] ); NrOfEntrys++; + g_free(text[0][0]); } free( curr ); }
Hello, On Thu, May 31, 2007 at 12:54:24AM +0400, xeb@mail.ru wrote:
There is trouble using gmplayer on non-utf8 localized systems, filenames are not handled correctly. This patch fixes it.
Please use filename_recode, if necessary combine it with strdup. Greetings, Reimar Doeffinger
participants (2)
-
Reimar Doeffinger -
xeb@mail.ru