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"
26 #include "gtkui/gtkui.h"
28 static const gchar *path_label[] = { N_("Bios rom"), N_("Flash rom"), N_("Default disc path"),
29 N_("Save state path"), N_("Bootstrap IP.BIN") };
30 static const int path_id[] = { CONFIG_BIOS_PATH, CONFIG_FLASH_PATH, CONFIG_DEFAULT_PATH,
31 CONFIG_SAVE_PATH, CONFIG_BOOTSTRAP };
32 static GtkFileChooserAction path_action[] = {
33 GTK_FILE_CHOOSER_ACTION_OPEN,
34 GTK_FILE_CHOOSER_ACTION_OPEN,
35 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
36 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
37 GTK_FILE_CHOOSER_ACTION_OPEN };
39 static GtkWidget *path_entry[5];
41 static gboolean path_file_button_clicked( GtkWidget *button, gpointer user_data )
43 GtkWidget *entry = GTK_WIDGET(user_data);
44 GtkWidget *file = gtk_file_chooser_dialog_new( _("Select file"), NULL,
45 GTK_FILE_CHOOSER_ACTION_OPEN,
46 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
47 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
49 const gchar *filename = gtk_entry_get_text(GTK_ENTRY(entry));
50 gtk_file_chooser_set_filename( GTK_FILE_CHOOSER(file), filename );
51 gtk_window_set_modal( GTK_WINDOW(file), TRUE );
52 gtk_widget_show_all( file );
53 gint result = gtk_dialog_run(GTK_DIALOG(file));
54 if( result == GTK_RESPONSE_ACCEPT ) {
55 filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
56 gtk_entry_set_text(GTK_ENTRY(entry), filename);
58 gtk_widget_destroy(file);
62 static gboolean path_dir_button_clicked( GtkWidget *button, gpointer user_data )
64 GtkWidget *entry = GTK_WIDGET(user_data);
65 GtkWidget *file = gtk_file_chooser_dialog_new( _("Select file"), NULL,
66 GTK_FILE_CHOOSER_ACTION_OPEN,
67 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
68 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
70 const gchar *filename = gtk_entry_get_text(GTK_ENTRY(entry));
71 gtk_file_chooser_set_action( GTK_FILE_CHOOSER(file), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER );
72 gtk_file_chooser_set_filename( GTK_FILE_CHOOSER(file), filename );
73 gtk_window_set_modal( GTK_WINDOW(file), TRUE );
74 gtk_widget_show_all( file );
75 gint result = gtk_dialog_run(GTK_DIALOG(file));
76 if( result == GTK_RESPONSE_ACCEPT ) {
77 filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
78 gtk_entry_set_text(GTK_ENTRY(entry), filename);
80 gtk_widget_destroy(file);
84 GtkWidget *path_panel_new(void)
86 GtkWidget *table = gtk_table_new( 5, 3, FALSE );
88 for( i=0; i<5; i++ ) {
89 GtkWidget *text = path_entry[i] = gtk_entry_new();
90 GtkWidget *button = gtk_button_new();
91 gtk_table_attach( GTK_TABLE(table), gtk_label_new(Q_(path_label[i])), 0, 1, i, i+1,
92 GTK_SHRINK, GTK_SHRINK, 0, 0);
93 gtk_entry_set_text( GTK_ENTRY(text), lxdream_get_config_value(path_id[i]) );
94 gtk_entry_set_width_chars( GTK_ENTRY(text), 48 );
95 gtk_table_attach_defaults( GTK_TABLE(table), text, 1, 2, i, i+1 );
96 gtk_table_attach( GTK_TABLE(table), button, 2, 3, i, i+1, GTK_SHRINK, GTK_SHRINK, 0, 0 );
97 if( path_action[i] == GTK_FILE_CHOOSER_ACTION_OPEN ) {
98 GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON);
99 gtk_button_set_image( GTK_BUTTON(button), image );
100 g_signal_connect( button, "clicked", G_CALLBACK(path_file_button_clicked), text );
102 GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON);
103 gtk_button_set_image( GTK_BUTTON(button), image );
104 g_signal_connect( button, "clicked", G_CALLBACK(path_dir_button_clicked), text );
111 void path_panel_done( GtkWidget *panel, gboolean isOK )
115 for(i=0; i<5; i++ ) {
116 const char *filename = gtk_entry_get_text( GTK_ENTRY(path_entry[i]) );
117 lxdream_set_global_config_value( path_id[i], filename );
120 lxdream_save_config();
121 dreamcast_config_changed();
126 void path_dialog_run( void )
128 gtk_gui_run_property_dialog( _("Path Settings"), path_panel_new(), path_panel_done );
.