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 736:a02d1475ccfd
prev658:f5926310bfbe
author nkeynes
date Mon Jul 21 01:05:22 2008 +0000 (15 years ago)
permissions -rw-r--r--
last change Add missing include (fix warning)
view annotate diff log raw
     1 /**
     2  * $Id$
     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 "lxdream.h"
    24 #include "dreamcast.h"
    25 #include "config.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 )
    42 {
    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,
    48             NULL );
    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);
    57     }
    58     gtk_widget_destroy(file);
    59     return TRUE;
    60 }
    62 static gboolean path_dir_button_clicked( GtkWidget *button, gpointer user_data )
    63 {
    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,
    69             NULL );
    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);
    79     }
    80     gtk_widget_destroy(file);
    81     return TRUE;
    82 }
    84 GtkWidget *path_panel_new(void)
    85 {
    86     GtkWidget *table = gtk_table_new( 5, 3, FALSE );
    87     int i;
    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 );
   101         } else {
   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 );
   105         }
   106     }
   107     return table;
   109 }
   111 void path_panel_done( GtkWidget *panel, gboolean isOK )
   112 {
   113     if( isOK ) {
   114         int i;
   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 );
   118         }
   120         lxdream_save_config();
   121         dreamcast_config_changed();
   122         gtk_gui_update();
   123     }
   124 }
   126 void path_dialog_run( void )
   127 {
   128     gtk_gui_run_property_dialog( _("Path Settings"), path_panel_new(), path_panel_done );
   129 }
.