Search
lxdream.org :: lxdream/src/gui/path_dlg.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/path_dlg.c
changeset 461:63d4de8dcec6
prev455:3080881d00d4
next481:3b2d6c5a19ad
author nkeynes
date Sat Oct 27 05:47:21 2007 +0000 (16 years ago)
permissions -rw-r--r--
last change Fix AICA save state section to include the current audio + IO state
view annotate diff log raw
     1 /**
     2  * $Id: path_dlg.c,v 1.3 2007-10-23 10:48:24 nkeynes Exp $
     3  *
     4  * Define the main (emu) GTK window, along with its menubars,
     5  * toolbars, etc.
     6  *
     7  * Copyright (c) 2005 Nathan Keynes.
     8  *
     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.
    13  *
    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.
    18  */
    20 #include <assert.h>
    21 #include <gtk/gtk.h>
    23 #include "dream.h"
    24 #include "config.h"
    25 #include "gui/gtkui.h"
    27 static const gchar *path_label[] = { "Bios rom", "Flash rom", "Default disc path", 
    28 				     "Save state path", "Bootstrap IP.BIN" };
    29 static const int path_id[] = { CONFIG_BIOS_PATH, CONFIG_FLASH_PATH, CONFIG_DEFAULT_PATH,
    30 			       CONFIG_SAVE_PATH, CONFIG_BOOTSTRAP };
    31 static GtkFileChooserAction path_action[] = {
    32     GTK_FILE_CHOOSER_ACTION_OPEN,
    33     GTK_FILE_CHOOSER_ACTION_OPEN,
    34     GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
    35     GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
    36     GTK_FILE_CHOOSER_ACTION_OPEN };
    38 static GtkWidget *path_entry[5];
    40 static gboolean path_file_button_clicked( GtkWidget *button, gpointer user_data )
    41 {
    42     GtkWidget *entry = GTK_WIDGET(user_data);
    43     GtkWidget *file = gtk_file_chooser_dialog_new( "Select file", NULL,
    44 					GTK_FILE_CHOOSER_ACTION_OPEN,
    45 					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
    46 					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
    47 					NULL );
    48     const gchar *filename = gtk_entry_get_text(GTK_ENTRY(entry));
    49     gtk_file_chooser_set_filename( GTK_FILE_CHOOSER(file), filename );
    50     gtk_window_set_modal( GTK_WINDOW(file), TRUE );
    51     gtk_widget_show_all( file );
    52     gint result = gtk_dialog_run(GTK_DIALOG(file));
    53     if( result == GTK_RESPONSE_ACCEPT ) {
    54 	filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
    55 	gtk_entry_set_text(GTK_ENTRY(entry), filename);
    56     }
    57     gtk_widget_destroy(file);
    58 }
    60 static gboolean path_dir_button_clicked( GtkWidget *button, gpointer user_data )
    61 {
    62     GtkWidget *entry = GTK_WIDGET(user_data);
    63     GtkWidget *file = gtk_file_chooser_dialog_new( "Select file", NULL,
    64 					GTK_FILE_CHOOSER_ACTION_OPEN,
    65 					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
    66 					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
    67 					NULL );
    68     const gchar *filename = gtk_entry_get_text(GTK_ENTRY(entry));
    69     gtk_file_chooser_set_action( GTK_FILE_CHOOSER(file), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER );
    70     gtk_file_chooser_set_filename( GTK_FILE_CHOOSER(file), filename );
    71     gtk_window_set_modal( GTK_WINDOW(file), TRUE );
    72     gtk_widget_show_all( file );
    73     gint result = gtk_dialog_run(GTK_DIALOG(file));
    74     if( result == GTK_RESPONSE_ACCEPT ) {
    75 	filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
    76 	gtk_entry_set_text(GTK_ENTRY(entry), filename);
    77     }
    78     gtk_widget_destroy(file);
    79 }
    81 static gboolean path_text_changed( GtkWidget *entry, gpointer user_data )
    82 {
    83     const gchar *text = gtk_entry_get_text( GTK_ENTRY(entry) );
    84 }
    86 GtkWidget *path_panel_new(void)
    87 {
    88     GtkWidget *table = gtk_table_new( 5, 3, FALSE );
    89     GtkWidget *desc = gtk_label_new(NULL);
    90     int i;
    91     for( i=0; i<5; i++ ) {
    92 	GtkWidget *text = path_entry[i] = gtk_entry_new();
    93 	GtkWidget *button = gtk_button_new();
    94 	gtk_table_attach( GTK_TABLE(table), gtk_label_new(path_label[i]), 0, 1, i, i+1,
    95 			  GTK_SHRINK, GTK_SHRINK, 0, 0);
    96 	gtk_entry_set_text( GTK_ENTRY(text), lxdream_get_config_value(path_id[i]) );
    97 	gtk_entry_set_width_chars( GTK_ENTRY(text), 48 );
    98 	gtk_table_attach_defaults( GTK_TABLE(table), text, 1, 2, i, i+1 );
    99 	gtk_table_attach( GTK_TABLE(table), button, 2, 3, i, i+1, GTK_SHRINK, GTK_SHRINK, 0, 0 );
   100 	if( path_action[i] == GTK_FILE_CHOOSER_ACTION_OPEN ) {
   101 	    GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON);
   102 	    gtk_button_set_image( GTK_BUTTON(button), image );
   103 	    g_signal_connect( button, "clicked", G_CALLBACK(path_file_button_clicked), text );
   104 	} else {
   105 	    GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON);
   106 	    gtk_button_set_image( GTK_BUTTON(button), image );
   107 	    g_signal_connect( button, "clicked", G_CALLBACK(path_dir_button_clicked), text );
   108 	}
   109     }
   110     return table;
   112 }
   114 void path_panel_done( GtkWidget *panel, gboolean isOK )
   115 {
   116     if( isOK ) {
   117 	int i;
   118 	for(i=0; i<5; i++ ) {
   119 	    const char *filename = gtk_entry_get_text( GTK_ENTRY(path_entry[i]) );
   120 	    lxdream_set_global_config_value( path_id[i], filename );
   121 	}
   123 	lxdream_save_config();
   124 	dreamcast_config_changed();
   125     }
   126 }
   128 void path_dialog_run( void )
   129 {
   130     gtk_gui_run_property_dialog( "Path Settings", path_panel_new(), path_panel_done );
   131 }
.