Mercurial > mplayer.hg
changeset 35926:eab9c3e8a565
Support mixed filename encodings.
This also supports falsely stated filename encodings.
Part 2 of 3: file selector path list.
In order for the filenames to look readable, it's necessary to
set G_FILENAME_ENCODING (for non-UTF8 or mixed encodings only).
author | ib |
---|---|
date | Tue, 19 Mar 2013 17:22:48 +0000 |
parents | 59c6618f384b |
children | e43fa34e33cf |
files | gui/app/cfg-old.c gui/dialog/fileselect.c |
diffstat | 2 files changed, 33 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/gui/app/cfg-old.c Tue Mar 19 17:18:59 2013 +0000 +++ b/gui/app/cfg-old.c Tue Mar 19 17:22:48 2013 +0000 @@ -32,7 +32,7 @@ */ static const gchar *cfg_old_filename_from_utf8(const gchar *fname) { -#ifdef CFG_OLD_PLAYLIST +#if defined(CFG_OLD_PLAYLIST) || defined(CFG_OLD_FILESELECT) static gchar *name; if (g_utf8_validate(fname, -1, NULL)) { @@ -45,4 +45,5 @@ return fname; } +#undef CFG_OLD_FILESELECT #undef CFG_OLD_PLAYLIST
--- a/gui/dialog/fileselect.c Tue Mar 19 17:18:59 2013 +0000 +++ b/gui/dialog/fileselect.c Tue Mar 19 17:22:48 2013 +0000 @@ -47,6 +47,9 @@ #include "preferences.h" #include "tools.h" +#define CFG_OLD_FILESELECT 1 +#include "gui/app/cfg-old.c" + #ifndef __linux__ #define get_current_dir_name() getcwd(NULL, PATH_MAX) #else @@ -54,7 +57,7 @@ #endif char * fsSelectedFile = NULL; -gchar * fsSelectedDirectory = NULL; +char * fsSelectedDirectory = NULL; gchar * fsSelectedDirectoryUtf8 = NULL; unsigned char * fsThatDir = "."; const gchar * fsFilter = "*"; @@ -150,6 +153,7 @@ GtkWidget * fsPathCombo; GList * fsList_items = NULL; GList * fsTopList_items = NULL; +GHashTable * fsPathTable; GtkWidget * List; GtkWidget * fsFilterCombo; @@ -163,8 +167,7 @@ { char * dir, * utf8dir; dir = get_current_dir_name(); - utf8dir = g_filename_to_utf8( dir, -1, NULL, NULL, NULL ); - if ( !utf8dir ) utf8dir = g_strdup( dir ); + utf8dir = g_filename_display_name( dir ); free( dir ); return utf8dir; } @@ -339,20 +342,29 @@ } if ( fsTopList_items ) g_list_free( fsTopList_items ); fsTopList_items=NULL; + if ( fsPathTable ) g_hash_table_destroy( fsPathTable ); fsPathTable=g_hash_table_new_full(g_str_hash, g_str_equal, free, free); { unsigned int i, c = 1; - + gchar *uname; if ( fsMedium ) { for ( i=0;i < FF_ARRAY_ELEMS(fsHistory);i++ ) - if ( fsHistory[i] ) { fsTopList_items=g_list_append( fsTopList_items,fsHistory[i] ); if ( c ) c=gstrcmp( dir,fsHistory[i] ); } + if ( fsHistory[i] ) + { + const gchar *fname; + fname = cfg_old_filename_from_utf8(fsHistory[i]); + uname = g_filename_display_name(fname); + fsTopList_items=g_list_append( fsTopList_items,uname ); + g_hash_table_insert(fsPathTable, strdup(uname), strdup(fname)); + if ( c ) c=gstrcmp( dir,fname ); + } } if ( c && dir ) { - g_free( fsSelectedDirectoryUtf8 ); - fsSelectedDirectoryUtf8=g_filename_to_utf8( dir, -1, NULL, NULL, NULL ); - fsTopList_items=g_list_prepend( fsTopList_items,fsSelectedDirectoryUtf8 ); + uname = g_filename_display_name( dir ); + fsTopList_items=g_list_prepend( fsTopList_items,uname ); + g_hash_table_insert(fsPathTable, strdup(uname), strdup(dir)); } } free( dir ); @@ -460,9 +472,8 @@ gchar * dirname; str=gtk_entry_get_text( GTK_ENTRY( user_data ) ); - dirname = g_filename_from_utf8( str, -1, NULL, NULL, NULL ); + dirname=g_hash_table_lookup(fsPathTable, str); if ( chdir( dirname ? (const unsigned char *)dirname : str ) != -1 ) CheckDir( fsFNameList ); - g_free( dirname ); } static void fs_fsPathCombo_changed( GtkEditable * editable, @@ -472,9 +483,8 @@ gchar * dirname; str=gtk_entry_get_text( GTK_ENTRY( user_data ) ); - dirname = g_filename_from_utf8( str, -1, NULL, NULL, NULL ); + dirname=g_hash_table_lookup(fsPathTable, str); if ( chdir( dirname ? (const unsigned char *)dirname : str ) != -1 ) CheckDir( fsFNameList ); - g_free( dirname ); } static void fs_Up_released( GtkButton * button, gpointer user_data ) @@ -504,6 +514,8 @@ } fsSelectedDirectory=(unsigned char *)get_current_dir_name(); + g_free( fsSelectedDirectoryUtf8 ); + fsSelectedDirectoryUtf8=get_current_dir_name_utf8(); switch ( fsType ) { case fsVideoSelector: @@ -518,7 +530,7 @@ g_free(selected); } guiInfo.NewPlay=GUI_FILE_NEW; sub_fps=0; - fs_PersistantHistory( get_current_dir_name_utf8() ); //totem, write into history + fs_PersistantHistory( get_current_dir_name() ); //totem, write into history break; case fsSubtitleSelector: setddup( &guiInfo.SubtitleFilename,fsSelectedDirectory,fsSelectedFile ); @@ -542,10 +554,14 @@ item=fsTopList_items; while( item ) { - if ( !strcmp( item->data,fsSelectedDirectory ) ) i=0; + if ( !strcmp( item->data,fsSelectedDirectoryUtf8 ) ) i=0; item=item->next; } - if ( i ) fsTopList_items=g_list_prepend( fsTopList_items,(gchar *)get_current_dir_name_utf8() ); + if ( i ) + { + fsTopList_items=g_list_prepend( fsTopList_items,fsSelectedDirectoryUtf8 ); + g_hash_table_insert(fsPathTable, strdup(fsSelectedDirectoryUtf8), strdup(fsSelectedDirectory)); + } if ( uiLoadPlay ) { uiLoadPlay=False; uiEvent( evPlay,0 ); } else gui( GUI_SET_STATE,(void *) GUI_STOP ); } @@ -614,8 +630,6 @@ static void fs_Destroy( void ) { - g_free( fsSelectedDirectoryUtf8 ); - fsSelectedDirectoryUtf8 = NULL; WidgetDestroy( fsFileSelect, &fsFileSelect ); }