Search
lxdream.org :: lxdream/src/gtkui/gtk_path.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gtkui/gtk_path.c
changeset 1036:af7b0c5905dd
prev763:b3ce4448f200
next1041:5fcc39857c5c
author nkeynes
date Wed Jun 24 06:06:40 2009 +0000 (13 years ago)
permissions -rw-r--r--
last change Support shell substitutions in config paths
Keep track of last folder in file dialogs
Fix out-of-dateness in GTK path dialog
file annotate diff log raw
1.1 --- a/src/gtkui/gtk_path.c Tue Jul 22 04:40:55 2008 +0000
1.2 +++ b/src/gtkui/gtk_path.c Wed Jun 24 06:06:40 2009 +0000
1.3 @@ -25,18 +25,7 @@
1.4 #include "config.h"
1.5 #include "gtkui/gtkui.h"
1.6
1.7 -static const gchar *path_label[] = { N_("Bios rom"), N_("Flash rom"), N_("Default disc path"),
1.8 - N_("Save state path"), N_("Bootstrap IP.BIN") };
1.9 -static const int path_id[] = { CONFIG_BIOS_PATH, CONFIG_FLASH_PATH, CONFIG_DEFAULT_PATH,
1.10 - CONFIG_SAVE_PATH, CONFIG_BOOTSTRAP };
1.11 -static GtkFileChooserAction path_action[] = {
1.12 - GTK_FILE_CHOOSER_ACTION_OPEN,
1.13 - GTK_FILE_CHOOSER_ACTION_OPEN,
1.14 - GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1.15 - GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1.16 - GTK_FILE_CHOOSER_ACTION_OPEN };
1.17 -
1.18 -static GtkWidget *path_entry[5];
1.19 +static GtkWidget *path_entry[CONFIG_KEY_MAX];
1.20
1.21 static gboolean path_file_button_clicked( GtkWidget *button, gpointer user_data )
1.22 {
1.23 @@ -46,14 +35,16 @@
1.24 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1.25 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1.26 NULL );
1.27 - const gchar *filename = gtk_entry_get_text(GTK_ENTRY(entry));
1.28 + gchar *filename = get_expanded_path(gtk_entry_get_text(GTK_ENTRY(entry)));
1.29 gtk_file_chooser_set_filename( GTK_FILE_CHOOSER(file), filename );
1.30 gtk_window_set_modal( GTK_WINDOW(file), TRUE );
1.31 gtk_widget_show_all( file );
1.32 gint result = gtk_dialog_run(GTK_DIALOG(file));
1.33 + g_free(filename);
1.34 if( result == GTK_RESPONSE_ACCEPT ) {
1.35 - filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
1.36 + filename = get_escaped_path(gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) ));
1.37 gtk_entry_set_text(GTK_ENTRY(entry), filename);
1.38 + g_free(filename);
1.39 }
1.40 gtk_widget_destroy(file);
1.41 return TRUE;
1.42 @@ -67,15 +58,17 @@
1.43 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1.44 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1.45 NULL );
1.46 - const gchar *filename = gtk_entry_get_text(GTK_ENTRY(entry));
1.47 + gchar *filename = get_expanded_path(gtk_entry_get_text(GTK_ENTRY(entry)));
1.48 gtk_file_chooser_set_action( GTK_FILE_CHOOSER(file), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER );
1.49 gtk_file_chooser_set_filename( GTK_FILE_CHOOSER(file), filename );
1.50 gtk_window_set_modal( GTK_WINDOW(file), TRUE );
1.51 gtk_widget_show_all( file );
1.52 gint result = gtk_dialog_run(GTK_DIALOG(file));
1.53 + g_free(filename);
1.54 if( result == GTK_RESPONSE_ACCEPT ) {
1.55 - filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
1.56 + filename = get_escaped_path(gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) ));
1.57 gtk_entry_set_text(GTK_ENTRY(entry), filename);
1.58 + g_free(filename);
1.59 }
1.60 gtk_widget_destroy(file);
1.61 return TRUE;
1.62 @@ -83,27 +76,32 @@
1.63
1.64 GtkWidget *path_panel_new(void)
1.65 {
1.66 - GtkWidget *table = gtk_table_new( 5, 3, FALSE );
1.67 - int i;
1.68 - for( i=0; i<5; i++ ) {
1.69 - GtkWidget *text = path_entry[i] = gtk_entry_new();
1.70 - GtkWidget *button = gtk_button_new();
1.71 - gtk_table_attach( GTK_TABLE(table), gtk_label_new(Q_(path_label[i])), 0, 1, i, i+1,
1.72 - GTK_SHRINK, GTK_SHRINK, 0, 0);
1.73 - gtk_entry_set_text( GTK_ENTRY(text), lxdream_get_config_value(path_id[i]) );
1.74 - gtk_entry_set_width_chars( GTK_ENTRY(text), 48 );
1.75 - gtk_table_attach_defaults( GTK_TABLE(table), text, 1, 2, i, i+1 );
1.76 - gtk_table_attach( GTK_TABLE(table), button, 2, 3, i, i+1, GTK_SHRINK, GTK_SHRINK, 0, 0 );
1.77 - if( path_action[i] == GTK_FILE_CHOOSER_ACTION_OPEN ) {
1.78 - GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON);
1.79 - gtk_button_set_image( GTK_BUTTON(button), image );
1.80 - g_signal_connect( button, "clicked", G_CALLBACK(path_file_button_clicked), text );
1.81 - } else {
1.82 - GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON);
1.83 - gtk_button_set_image( GTK_BUTTON(button), image );
1.84 - g_signal_connect( button, "clicked", G_CALLBACK(path_dir_button_clicked), text );
1.85 + int i, y=0;
1.86 + GtkWidget *table = gtk_table_new( CONFIG_KEY_MAX, 3, FALSE );
1.87 + for( i=0; i<CONFIG_KEY_MAX; i++ ) {
1.88 + const struct lxdream_config_entry *entry = lxdream_get_global_config_entry(i);
1.89 + if( entry->label != NULL ) {
1.90 + GtkWidget *text = path_entry[i] = gtk_entry_new();
1.91 + GtkWidget *button = gtk_button_new();
1.92 + gtk_table_attach( GTK_TABLE(table), gtk_label_new(Q_(entry->label)), 0, 1, y, y+1,
1.93 + GTK_SHRINK, GTK_SHRINK, 0, 0);
1.94 + gtk_entry_set_text( GTK_ENTRY(text), lxdream_get_global_config_value(i) );
1.95 + gtk_entry_set_width_chars( GTK_ENTRY(text), 48 );
1.96 + gtk_table_attach_defaults( GTK_TABLE(table), text, 1, 2, y, y+1 );
1.97 + gtk_table_attach( GTK_TABLE(table), button, 2, 3, y, y+1, GTK_SHRINK, GTK_SHRINK, 0, 0 );
1.98 + if( entry->type == CONFIG_TYPE_FILE ) {
1.99 + GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_FILE, GTK_ICON_SIZE_MENU);
1.100 + gtk_button_set_image( GTK_BUTTON(button), image );
1.101 + g_signal_connect( button, "clicked", G_CALLBACK(path_file_button_clicked), text );
1.102 + } else {
1.103 + GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU);
1.104 + gtk_button_set_image( GTK_BUTTON(button), image );
1.105 + g_signal_connect( button, "clicked", G_CALLBACK(path_dir_button_clicked), text );
1.106 + }
1.107 + y++;
1.108 }
1.109 }
1.110 + gtk_table_resize( GTK_TABLE(table), y, 3 );
1.111 return table;
1.112
1.113 }
1.114 @@ -112,13 +110,16 @@
1.115 {
1.116 if( isOK ) {
1.117 int i;
1.118 - for(i=0; i<5; i++ ) {
1.119 - const char *filename = gtk_entry_get_text( GTK_ENTRY(path_entry[i]) );
1.120 - lxdream_set_global_config_value( path_id[i], filename );
1.121 + for(i=0; i<CONFIG_KEY_MAX; i++ ) {
1.122 + if( path_entry[i] != NULL ) {
1.123 + const char *filename = gtk_entry_get_text( GTK_ENTRY(path_entry[i]) );
1.124 + lxdream_set_global_config_value( i, filename );
1.125 + }
1.126 }
1.127
1.128 lxdream_save_config();
1.129 dreamcast_config_changed();
1.130 + gui_config_paths_changed();
1.131 gtk_gui_update();
1.132 }
1.133 }
.