Search
lxdream.org :: lxdream :: r630:50addb748df5
lxdream 0.9.1
released Jun 29
Download Now
changeset630:50addb748df5
parent629:2811e8a2debf
child631:6e8e9ae34d09
authornkeynes
dateTue Feb 12 08:36:29 2008 +0000 (12 years ago)
Bug #55: Fix relative path handling
Canonicalize paths before passing to the file dialog
src/gtkui/gtkcb.c
src/gtkui/gtkui.c
src/gtkui/gtkui.h
1.1 --- a/src/gtkui/gtkcb.c Fri Feb 08 11:30:04 2008 +0000
1.2 +++ b/src/gtkui/gtkcb.c Tue Feb 12 08:36:29 2008 +0000
1.3 @@ -43,13 +43,14 @@
1.4 gchar const *initial_dir )
1.5 {
1.6 GtkWidget *file;
1.7 + gchar *initial_path = get_absolute_path(initial_dir);
1.8 file = gtk_file_chooser_dialog_new( title, NULL,
1.9 GTK_FILE_CHOOSER_ACTION_OPEN,
1.10 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1.11 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1.12 NULL );
1.13 add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
1.14 - gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_dir );
1.15 + gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_path );
1.16 gtk_window_set_modal( GTK_WINDOW(file), TRUE );
1.17 gtk_dialog_set_default_response( GTK_DIALOG(file), GTK_RESPONSE_ACCEPT );
1.18 int result = gtk_dialog_run( GTK_DIALOG(file) );
1.19 @@ -58,19 +59,21 @@
1.20 action( filename );
1.21 }
1.22 gtk_widget_destroy(file);
1.23 + g_free(initial_path);
1.24 }
1.25
1.26 void save_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
1.27 gchar const *initial_dir )
1.28 {
1.29 GtkWidget *file;
1.30 + gchar *initial_path = get_absolute_path(initial_dir);
1.31 file = gtk_file_chooser_dialog_new( title, NULL,
1.32 GTK_FILE_CHOOSER_ACTION_SAVE,
1.33 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1.34 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1.35 NULL );
1.36 add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
1.37 - gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_dir );
1.38 + gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_path );
1.39 gtk_window_set_modal( GTK_WINDOW(file), TRUE );
1.40 gtk_dialog_set_default_response( GTK_DIALOG(file), GTK_RESPONSE_ACCEPT );
1.41 int result = gtk_dialog_run( GTK_DIALOG(file) );
1.42 @@ -79,6 +82,7 @@
1.43 action( filename );
1.44 }
1.45 gtk_widget_destroy(file);
1.46 + g_free(initial_path);
1.47 }
1.48
1.49 void mount_action_callback( GtkAction *action, gpointer user_data)
1.50 @@ -131,6 +135,7 @@
1.51 GtkWidget *file, *preview, *frame, *align;
1.52 GtkRequisition size;
1.53 const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
1.54 + const gchar *path = get_absolute_path(dir);
1.55 file = gtk_file_chooser_dialog_new( _("Load state..."), NULL,
1.56 GTK_FILE_CHOOSER_ACTION_OPEN,
1.57 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1.58 @@ -153,7 +158,7 @@
1.59 gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(file), align);
1.60 g_signal_connect( file, "update-preview", G_CALLBACK(load_state_preview_callback),
1.61 preview );
1.62 - gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), dir );
1.63 + gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), path );
1.64 gtk_window_set_modal( GTK_WINDOW(file), TRUE );
1.65 int result = gtk_dialog_run( GTK_DIALOG(file) );
1.66 if( result == GTK_RESPONSE_ACCEPT ) {
1.67 @@ -161,6 +166,7 @@
1.68 dreamcast_load_state( filename );
1.69 }
1.70 gtk_widget_destroy(file);
1.71 + g_free(path);
1.72 }
1.73
1.74 void save_state_action_callback( GtkAction *action, gpointer user_data)
2.1 --- a/src/gtkui/gtkui.c Fri Feb 08 11:30:04 2008 +0000
2.2 +++ b/src/gtkui/gtkui.c Tue Feb 12 08:36:29 2008 +0000
2.3 @@ -515,6 +515,20 @@
2.4 return keyval;
2.5 }
2.6
2.7 +gchar *get_absolute_path( const gchar *in_path )
2.8 +{
2.9 + char tmp[PATH_MAX];
2.10 + if( in_path == NULL ) {
2.11 + return NULL;
2.12 + }
2.13 + if( in_path[0] == '/' || in_path[0] == 0 ) {
2.14 + return g_strdup(in_path);
2.15 + } else {
2.16 + getcwd(tmp, sizeof(tmp));
2.17 + return g_strdup_printf("%s%c%s", tmp, G_DIR_SEPARATOR, in_path);
2.18 + }
2.19 +}
2.20 +
2.21 /************* X11-specificness **********/
2.22 #include <gdk/gdkx.h>
2.23
3.1 --- a/src/gtkui/gtkui.h Fri Feb 08 11:30:04 2008 +0000
3.2 +++ b/src/gtkui/gtkui.h Tue Feb 12 08:36:29 2008 +0000
3.3 @@ -101,6 +101,13 @@
3.4 guint gdk_keycode_to_modifier( GdkDisplay *display, guint keycode );
3.5
3.6 /**
3.7 + * Return an absolute path for the given input path, as a newly allocated
3.8 + * string. If the input path is already absolute, the returned string will
3.9 + * be identical to the input string.
3.10 + */
3.11 +gchar *get_absolute_path( const gchar *path );
3.12 +
3.13 +/**
3.14 * Construct a new pixbuf that takes ownership of the frame buffer
3.15 */
3.16 GdkPixbuf *gdk_pixbuf_new_from_frame_buffer( frame_buffer_t buffer );
.