Search
lxdream.org :: lxdream/src/gtkui/path_dlg.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gtkui/path_dlg.c
changeset 561:533f6b478071
prev543:361ec0a70cf2
next658:f5926310bfbe
author nkeynes
date Tue Jan 01 05:08:38 2008 +0000 (12 years ago)
branchlxdream-mmu
permissions -rw-r--r--
last change Enable Id keyword on all source files
file annotate diff log raw
nkeynes@450
     1
/**
nkeynes@561
     2
 * $Id$
nkeynes@450
     3
 *
nkeynes@450
     4
 * Define the main (emu) GTK window, along with its menubars,
nkeynes@450
     5
 * toolbars, etc.
nkeynes@450
     6
 *
nkeynes@450
     7
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@450
     8
 *
nkeynes@450
     9
 * This program is free software; you can redistribute it and/or modify
nkeynes@450
    10
 * it under the terms of the GNU General Public License as published by
nkeynes@450
    11
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@450
    12
 * (at your option) any later version.
nkeynes@450
    13
 *
nkeynes@450
    14
 * This program is distributed in the hope that it will be useful,
nkeynes@450
    15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@450
    16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@450
    17
 * GNU General Public License for more details.
nkeynes@450
    18
 */
nkeynes@450
    19
nkeynes@450
    20
#include <assert.h>
nkeynes@450
    21
#include <gtk/gtk.h>
nkeynes@450
    22
nkeynes@450
    23
#include "dream.h"
nkeynes@481
    24
#include "dreamcast.h"
nkeynes@450
    25
#include "config.h"
nkeynes@537
    26
#include "gtkui/gtkui.h"
nkeynes@450
    27
nkeynes@508
    28
static const gchar *path_label[] = { N_("Bios rom"), N_("Flash rom"), N_("Default disc path"), 
nkeynes@508
    29
				     N_("Save state path"), N_("Bootstrap IP.BIN") };
nkeynes@450
    30
static const int path_id[] = { CONFIG_BIOS_PATH, CONFIG_FLASH_PATH, CONFIG_DEFAULT_PATH,
nkeynes@450
    31
			       CONFIG_SAVE_PATH, CONFIG_BOOTSTRAP };
nkeynes@450
    32
static GtkFileChooserAction path_action[] = {
nkeynes@450
    33
    GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@450
    34
    GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@450
    35
    GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
nkeynes@450
    36
    GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
nkeynes@450
    37
    GTK_FILE_CHOOSER_ACTION_OPEN };
nkeynes@450
    38
nkeynes@450
    39
static GtkWidget *path_entry[5];
nkeynes@450
    40
nkeynes@450
    41
static gboolean path_file_button_clicked( GtkWidget *button, gpointer user_data )
nkeynes@450
    42
{
nkeynes@450
    43
    GtkWidget *entry = GTK_WIDGET(user_data);
nkeynes@508
    44
    GtkWidget *file = gtk_file_chooser_dialog_new( _("Select file"), NULL,
nkeynes@450
    45
					GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@450
    46
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@450
    47
					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
nkeynes@450
    48
					NULL );
nkeynes@450
    49
    const gchar *filename = gtk_entry_get_text(GTK_ENTRY(entry));
nkeynes@450
    50
    gtk_file_chooser_set_filename( GTK_FILE_CHOOSER(file), filename );
nkeynes@450
    51
    gtk_window_set_modal( GTK_WINDOW(file), TRUE );
nkeynes@450
    52
    gtk_widget_show_all( file );
nkeynes@450
    53
    gint result = gtk_dialog_run(GTK_DIALOG(file));
nkeynes@450
    54
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@450
    55
	filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
nkeynes@450
    56
	gtk_entry_set_text(GTK_ENTRY(entry), filename);
nkeynes@450
    57
    }
nkeynes@450
    58
    gtk_widget_destroy(file);
nkeynes@481
    59
    return TRUE;
nkeynes@450
    60
}
nkeynes@450
    61
nkeynes@450
    62
static gboolean path_dir_button_clicked( GtkWidget *button, gpointer user_data )
nkeynes@450
    63
{
nkeynes@450
    64
    GtkWidget *entry = GTK_WIDGET(user_data);
nkeynes@508
    65
    GtkWidget *file = gtk_file_chooser_dialog_new( _("Select file"), NULL,
nkeynes@450
    66
					GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@450
    67
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@450
    68
					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
nkeynes@450
    69
					NULL );
nkeynes@450
    70
    const gchar *filename = gtk_entry_get_text(GTK_ENTRY(entry));
nkeynes@450
    71
    gtk_file_chooser_set_action( GTK_FILE_CHOOSER(file), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER );
nkeynes@450
    72
    gtk_file_chooser_set_filename( GTK_FILE_CHOOSER(file), filename );
nkeynes@450
    73
    gtk_window_set_modal( GTK_WINDOW(file), TRUE );
nkeynes@450
    74
    gtk_widget_show_all( file );
nkeynes@450
    75
    gint result = gtk_dialog_run(GTK_DIALOG(file));
nkeynes@450
    76
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@450
    77
	filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
nkeynes@450
    78
	gtk_entry_set_text(GTK_ENTRY(entry), filename);
nkeynes@450
    79
    }
nkeynes@450
    80
    gtk_widget_destroy(file);
nkeynes@481
    81
    return TRUE;
nkeynes@450
    82
}
nkeynes@450
    83
nkeynes@450
    84
GtkWidget *path_panel_new(void)
nkeynes@450
    85
{
nkeynes@450
    86
    GtkWidget *table = gtk_table_new( 5, 3, FALSE );
nkeynes@450
    87
    int i;
nkeynes@450
    88
    for( i=0; i<5; i++ ) {
nkeynes@450
    89
	GtkWidget *text = path_entry[i] = gtk_entry_new();
nkeynes@450
    90
	GtkWidget *button = gtk_button_new();
nkeynes@508
    91
	gtk_table_attach( GTK_TABLE(table), gtk_label_new(Q_(path_label[i])), 0, 1, i, i+1,
nkeynes@450
    92
			  GTK_SHRINK, GTK_SHRINK, 0, 0);
nkeynes@450
    93
	gtk_entry_set_text( GTK_ENTRY(text), lxdream_get_config_value(path_id[i]) );
nkeynes@461
    94
	gtk_entry_set_width_chars( GTK_ENTRY(text), 48 );
nkeynes@450
    95
	gtk_table_attach_defaults( GTK_TABLE(table), text, 1, 2, i, i+1 );
nkeynes@450
    96
	gtk_table_attach( GTK_TABLE(table), button, 2, 3, i, i+1, GTK_SHRINK, GTK_SHRINK, 0, 0 );
nkeynes@450
    97
	if( path_action[i] == GTK_FILE_CHOOSER_ACTION_OPEN ) {
nkeynes@450
    98
	    GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON);
nkeynes@450
    99
	    gtk_button_set_image( GTK_BUTTON(button), image );
nkeynes@450
   100
	    g_signal_connect( button, "clicked", G_CALLBACK(path_file_button_clicked), text );
nkeynes@450
   101
	} else {
nkeynes@455
   102
	    GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON);
nkeynes@450
   103
	    gtk_button_set_image( GTK_BUTTON(button), image );
nkeynes@450
   104
	    g_signal_connect( button, "clicked", G_CALLBACK(path_dir_button_clicked), text );
nkeynes@450
   105
	}
nkeynes@450
   106
    }
nkeynes@450
   107
    return table;
nkeynes@450
   108
nkeynes@450
   109
}
nkeynes@450
   110
nkeynes@461
   111
void path_panel_done( GtkWidget *panel, gboolean isOK )
nkeynes@450
   112
{
nkeynes@461
   113
    if( isOK ) {
nkeynes@461
   114
	int i;
nkeynes@461
   115
	for(i=0; i<5; i++ ) {
nkeynes@461
   116
	    const char *filename = gtk_entry_get_text( GTK_ENTRY(path_entry[i]) );
nkeynes@461
   117
	    lxdream_set_global_config_value( path_id[i], filename );
nkeynes@461
   118
	}
nkeynes@461
   119
	
nkeynes@461
   120
	lxdream_save_config();
nkeynes@461
   121
	dreamcast_config_changed();
nkeynes@543
   122
	gtk_gui_update();
nkeynes@450
   123
    }
nkeynes@450
   124
}
nkeynes@450
   125
nkeynes@450
   126
void path_dialog_run( void )
nkeynes@450
   127
{
nkeynes@508
   128
    gtk_gui_run_property_dialog( _("Path Settings"), path_panel_new(), path_panel_done );
nkeynes@450
   129
}
.