[MPlayer-cvslog] r36020 - in trunk/gui: app/cfg-old.c dialog/fileselect.c

ib subversion at mplayerhq.hu
Tue Mar 19 18:22:48 CET 2013


Author: ib
Date: Tue Mar 19 18:22:48 2013
New Revision: 36020

Log:
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).

Modified:
   trunk/gui/app/cfg-old.c
   trunk/gui/dialog/fileselect.c

Modified: trunk/gui/app/cfg-old.c
==============================================================================
--- trunk/gui/app/cfg-old.c	Tue Mar 19 18:18:59 2013	(r36019)
+++ trunk/gui/app/cfg-old.c	Tue Mar 19 18:22:48 2013	(r36020)
@@ -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 @@ static const gchar *cfg_old_filename_fro
     return fname;
 }
 
+#undef CFG_OLD_FILESELECT
 #undef CFG_OLD_PLAYLIST

Modified: trunk/gui/dialog/fileselect.c
==============================================================================
--- trunk/gui/dialog/fileselect.c	Tue Mar 19 18:18:59 2013	(r36019)
+++ trunk/gui/dialog/fileselect.c	Tue Mar 19 18:22:48 2013	(r36020)
@@ -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 @@ char * get_current_dir_name( void );
 #endif
 
 char          * fsSelectedFile = NULL;
-gchar         * fsSelectedDirectory = NULL;
+char          * fsSelectedDirectory = NULL;
 gchar         * fsSelectedDirectoryUtf8 = NULL;
 unsigned char * fsThatDir = ".";
 const gchar   * fsFilter = "*";
@@ -150,6 +153,7 @@ GtkWidget   * fsCombo4;
 GtkWidget   * fsPathCombo;
 GList       * fsList_items = NULL;
 GList       * fsTopList_items = NULL;
+GHashTable  * fsPathTable;
 GtkWidget   * List;
 GtkWidget   * fsFilterCombo;
 
@@ -163,8 +167,7 @@ static char * get_current_dir_name_utf8(
 {
  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 @@ void ShowFileSelect( int type,int modal 
   }
 
  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 @@ static void fs_fsPathCombo_activate( Gtk
  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 @@ static void fs_fsPathCombo_changed( GtkE
  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 @@ static void fs_Ok_released( GtkButton * 
   }
 
         fsSelectedDirectory=(unsigned char *)get_current_dir_name();
+        g_free( fsSelectedDirectoryUtf8 );
+        fsSelectedDirectoryUtf8=get_current_dir_name_utf8();
  switch ( fsType )
   {
    case fsVideoSelector:
@@ -518,7 +530,7 @@ static void fs_Ok_released( GtkButton * 
             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 @@ static void fs_Ok_released( GtkButton * 
  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 gboolean fs_fsFNameList_event( Gt
 
 static void fs_Destroy( void )
 {
- g_free( fsSelectedDirectoryUtf8 );
- fsSelectedDirectoryUtf8 = NULL;
  WidgetDestroy( fsFileSelect, &fsFileSelect );
 }
 


More information about the MPlayer-cvslog mailing list