4 * Define the main (emu) GTK window, along with its menubars,
7 * Copyright (c) 2005 Nathan Keynes.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
24 #include "dreamcast.h"
27 #include "gtkui/gtkui.h"
29 static GtkWidget *path_entry[CONFIG_KEY_MAX];
31 static gboolean path_file_button_clicked( GtkWidget *button, gpointer user_data )
33 GtkWidget *entry = GTK_WIDGET(user_data);
34 GtkWidget *file = gtk_file_chooser_dialog_new( _("Select file"), NULL,
35 GTK_FILE_CHOOSER_ACTION_OPEN,
36 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
37 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
39 gchar *filename = get_expanded_path(gtk_entry_get_text(GTK_ENTRY(entry)));
40 gtk_file_chooser_set_filename( GTK_FILE_CHOOSER(file), filename );
41 gtk_window_set_modal( GTK_WINDOW(file), TRUE );
42 gtk_widget_show_all( file );
43 gint result = gtk_dialog_run(GTK_DIALOG(file));
45 if( result == GTK_RESPONSE_ACCEPT ) {
46 filename = get_escaped_path(gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) ));
47 gtk_entry_set_text(GTK_ENTRY(entry), filename);
50 gtk_widget_destroy(file);
54 static gboolean path_dir_button_clicked( GtkWidget *button, gpointer user_data )
56 GtkWidget *entry = GTK_WIDGET(user_data);
57 GtkWidget *file = gtk_file_chooser_dialog_new( _("Select file"), NULL,
58 GTK_FILE_CHOOSER_ACTION_OPEN,
59 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
60 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
62 gchar *filename = get_expanded_path(gtk_entry_get_text(GTK_ENTRY(entry)));
63 gtk_file_chooser_set_action( GTK_FILE_CHOOSER(file), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER );
64 gtk_file_chooser_set_filename( GTK_FILE_CHOOSER(file), filename );
65 gtk_window_set_modal( GTK_WINDOW(file), TRUE );
66 gtk_widget_show_all( file );
67 gint result = gtk_dialog_run(GTK_DIALOG(file));
69 if( result == GTK_RESPONSE_ACCEPT ) {
70 filename = get_escaped_path(gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) ));
71 gtk_entry_set_text(GTK_ENTRY(entry), filename);
74 gtk_widget_destroy(file);
78 GtkWidget *path_panel_new(void)
81 GtkWidget *table = gtk_table_new( CONFIG_KEY_MAX, 3, FALSE );
82 for( i=0; i<CONFIG_KEY_MAX; i++ ) {
83 const struct lxdream_config_entry *entry = lxdream_get_global_config_entry(i);
84 if( entry->label != NULL ) {
85 GtkWidget *text = path_entry[i] = gtk_entry_new();
86 GtkWidget *button = gtk_button_new();
87 gtk_table_attach( GTK_TABLE(table), gtk_label_new(Q_(entry->label)), 0, 1, y, y+1,
88 GTK_SHRINK, GTK_SHRINK, 0, 0);
89 gtk_entry_set_text( GTK_ENTRY(text), lxdream_get_global_config_value(i) );
90 gtk_entry_set_width_chars( GTK_ENTRY(text), 48 );
91 gtk_table_attach_defaults( GTK_TABLE(table), text, 1, 2, y, y+1 );
92 gtk_table_attach( GTK_TABLE(table), button, 2, 3, y, y+1, GTK_SHRINK, GTK_SHRINK, 0, 0 );
93 if( entry->type == CONFIG_TYPE_FILE ) {
94 GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_FILE, GTK_ICON_SIZE_MENU);
95 gtk_button_set_image( GTK_BUTTON(button), image );
96 g_signal_connect( button, "clicked", G_CALLBACK(path_file_button_clicked), text );
98 GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU);
99 gtk_button_set_image( GTK_BUTTON(button), image );
100 g_signal_connect( button, "clicked", G_CALLBACK(path_dir_button_clicked), text );
105 gtk_table_resize( GTK_TABLE(table), y, 3 );
110 void path_panel_done( GtkWidget *panel, gboolean isOK )
114 for(i=0; i<CONFIG_KEY_MAX; i++ ) {
115 if( path_entry[i] != NULL ) {
116 const char *filename = gtk_entry_get_text( GTK_ENTRY(path_entry[i]) );
117 lxdream_set_global_config_value( i, filename );
121 lxdream_save_config();
122 dreamcast_config_changed();
127 void path_dialog_run( void )
129 gtk_gui_run_property_dialog( _("Path Settings"), path_panel_new(), path_panel_done );
.