Search
lxdream.org :: lxdream/src/gtkui/path_dlg.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gtkui/path_dlg.c
changeset 537:d924be49e192
prev508:ccd2c10edfe6
next543:361ec0a70cf2
author nkeynes
date Tue Nov 20 10:27:58 2007 +0000 (14 years ago)
permissions -rw-r--r--
last change Move gtk UI into gtkui subdir (prep for non-gtk builds), and protect with
an automake conditional
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/gtkui/path_dlg.c Tue Nov 20 10:27:58 2007 +0000
1.3 @@ -0,0 +1,128 @@
1.4 +/**
1.5 + * $Id: path_dlg.c,v 1.5 2007-11-10 04:45:29 nkeynes Exp $
1.6 + *
1.7 + * Define the main (emu) GTK window, along with its menubars,
1.8 + * toolbars, etc.
1.9 + *
1.10 + * Copyright (c) 2005 Nathan Keynes.
1.11 + *
1.12 + * This program is free software; you can redistribute it and/or modify
1.13 + * it under the terms of the GNU General Public License as published by
1.14 + * the Free Software Foundation; either version 2 of the License, or
1.15 + * (at your option) any later version.
1.16 + *
1.17 + * This program is distributed in the hope that it will be useful,
1.18 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.19 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.20 + * GNU General Public License for more details.
1.21 + */
1.22 +
1.23 +#include <assert.h>
1.24 +#include <gtk/gtk.h>
1.25 +
1.26 +#include "dream.h"
1.27 +#include "dreamcast.h"
1.28 +#include "config.h"
1.29 +#include "gtkui/gtkui.h"
1.30 +
1.31 +static const gchar *path_label[] = { N_("Bios rom"), N_("Flash rom"), N_("Default disc path"),
1.32 + N_("Save state path"), N_("Bootstrap IP.BIN") };
1.33 +static const int path_id[] = { CONFIG_BIOS_PATH, CONFIG_FLASH_PATH, CONFIG_DEFAULT_PATH,
1.34 + CONFIG_SAVE_PATH, CONFIG_BOOTSTRAP };
1.35 +static GtkFileChooserAction path_action[] = {
1.36 + GTK_FILE_CHOOSER_ACTION_OPEN,
1.37 + GTK_FILE_CHOOSER_ACTION_OPEN,
1.38 + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1.39 + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1.40 + GTK_FILE_CHOOSER_ACTION_OPEN };
1.41 +
1.42 +static GtkWidget *path_entry[5];
1.43 +
1.44 +static gboolean path_file_button_clicked( GtkWidget *button, gpointer user_data )
1.45 +{
1.46 + GtkWidget *entry = GTK_WIDGET(user_data);
1.47 + GtkWidget *file = gtk_file_chooser_dialog_new( _("Select file"), NULL,
1.48 + GTK_FILE_CHOOSER_ACTION_OPEN,
1.49 + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1.50 + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1.51 + NULL );
1.52 + const gchar *filename = gtk_entry_get_text(GTK_ENTRY(entry));
1.53 + gtk_file_chooser_set_filename( GTK_FILE_CHOOSER(file), filename );
1.54 + gtk_window_set_modal( GTK_WINDOW(file), TRUE );
1.55 + gtk_widget_show_all( file );
1.56 + gint result = gtk_dialog_run(GTK_DIALOG(file));
1.57 + if( result == GTK_RESPONSE_ACCEPT ) {
1.58 + filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
1.59 + gtk_entry_set_text(GTK_ENTRY(entry), filename);
1.60 + }
1.61 + gtk_widget_destroy(file);
1.62 + return TRUE;
1.63 +}
1.64 +
1.65 +static gboolean path_dir_button_clicked( GtkWidget *button, gpointer user_data )
1.66 +{
1.67 + GtkWidget *entry = GTK_WIDGET(user_data);
1.68 + GtkWidget *file = gtk_file_chooser_dialog_new( _("Select file"), NULL,
1.69 + GTK_FILE_CHOOSER_ACTION_OPEN,
1.70 + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1.71 + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1.72 + NULL );
1.73 + const gchar *filename = gtk_entry_get_text(GTK_ENTRY(entry));
1.74 + gtk_file_chooser_set_action( GTK_FILE_CHOOSER(file), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER );
1.75 + gtk_file_chooser_set_filename( GTK_FILE_CHOOSER(file), filename );
1.76 + gtk_window_set_modal( GTK_WINDOW(file), TRUE );
1.77 + gtk_widget_show_all( file );
1.78 + gint result = gtk_dialog_run(GTK_DIALOG(file));
1.79 + if( result == GTK_RESPONSE_ACCEPT ) {
1.80 + filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
1.81 + gtk_entry_set_text(GTK_ENTRY(entry), filename);
1.82 + }
1.83 + gtk_widget_destroy(file);
1.84 + return TRUE;
1.85 +}
1.86 +
1.87 +GtkWidget *path_panel_new(void)
1.88 +{
1.89 + GtkWidget *table = gtk_table_new( 5, 3, FALSE );
1.90 + int i;
1.91 + for( i=0; i<5; i++ ) {
1.92 + GtkWidget *text = path_entry[i] = gtk_entry_new();
1.93 + GtkWidget *button = gtk_button_new();
1.94 + gtk_table_attach( GTK_TABLE(table), gtk_label_new(Q_(path_label[i])), 0, 1, i, i+1,
1.95 + GTK_SHRINK, GTK_SHRINK, 0, 0);
1.96 + gtk_entry_set_text( GTK_ENTRY(text), lxdream_get_config_value(path_id[i]) );
1.97 + gtk_entry_set_width_chars( GTK_ENTRY(text), 48 );
1.98 + gtk_table_attach_defaults( GTK_TABLE(table), text, 1, 2, i, i+1 );
1.99 + gtk_table_attach( GTK_TABLE(table), button, 2, 3, i, i+1, GTK_SHRINK, GTK_SHRINK, 0, 0 );
1.100 + if( path_action[i] == GTK_FILE_CHOOSER_ACTION_OPEN ) {
1.101 + GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON);
1.102 + gtk_button_set_image( GTK_BUTTON(button), image );
1.103 + g_signal_connect( button, "clicked", G_CALLBACK(path_file_button_clicked), text );
1.104 + } else {
1.105 + GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON);
1.106 + gtk_button_set_image( GTK_BUTTON(button), image );
1.107 + g_signal_connect( button, "clicked", G_CALLBACK(path_dir_button_clicked), text );
1.108 + }
1.109 + }
1.110 + return table;
1.111 +
1.112 +}
1.113 +
1.114 +void path_panel_done( GtkWidget *panel, gboolean isOK )
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 + }
1.122 +
1.123 + lxdream_save_config();
1.124 + dreamcast_config_changed();
1.125 + }
1.126 +}
1.127 +
1.128 +void path_dialog_run( void )
1.129 +{
1.130 + gtk_gui_run_property_dialog( _("Path Settings"), path_panel_new(), path_panel_done );
1.131 +}
.