Search
lxdream.org :: lxdream/src/gui/path_dlg.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/path_dlg.c
changeset 450:207461e79f21
next455:3080881d00d4
author nkeynes
date Wed Oct 17 11:26:45 2007 +0000 (14 years ago)
permissions -rw-r--r--
last change Split config management out to config.[ch]
Manage config filename
Check home dir + sysconfdir for conf file
Initial work on a path settings dialog
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/gui/path_dlg.c Wed Oct 17 11:26:45 2007 +0000
1.3 @@ -0,0 +1,141 @@
1.4 +/**
1.5 + * $Id: path_dlg.c,v 1.1 2007-10-17 11:26:45 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 "config.h"
1.28 +#include "gui/gtkui.h"
1.29 +
1.30 +static const gchar *path_label[] = { "Bios rom", "Flash rom", "Default disc path",
1.31 + "Save state path", "Bootstrap IP.BIN" };
1.32 +static const int path_id[] = { CONFIG_BIOS_PATH, CONFIG_FLASH_PATH, CONFIG_DEFAULT_PATH,
1.33 + CONFIG_SAVE_PATH, CONFIG_BOOTSTRAP };
1.34 +static GtkFileChooserAction path_action[] = {
1.35 + GTK_FILE_CHOOSER_ACTION_OPEN,
1.36 + GTK_FILE_CHOOSER_ACTION_OPEN,
1.37 + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1.38 + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
1.39 + GTK_FILE_CHOOSER_ACTION_OPEN };
1.40 +
1.41 +static GtkWidget *path_entry[5];
1.42 +
1.43 +static gboolean path_file_button_clicked( GtkWidget *button, gpointer user_data )
1.44 +{
1.45 + GtkWidget *entry = GTK_WIDGET(user_data);
1.46 + GtkWidget *file = gtk_file_chooser_dialog_new( "Select file", NULL,
1.47 + GTK_FILE_CHOOSER_ACTION_OPEN,
1.48 + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1.49 + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1.50 + NULL );
1.51 + const gchar *filename = gtk_entry_get_text(GTK_ENTRY(entry));
1.52 + gtk_file_chooser_set_filename( GTK_FILE_CHOOSER(file), filename );
1.53 + gtk_window_set_modal( GTK_WINDOW(file), TRUE );
1.54 + gtk_widget_show_all( file );
1.55 + gint result = gtk_dialog_run(GTK_DIALOG(file));
1.56 + if( result == GTK_RESPONSE_ACCEPT ) {
1.57 + filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
1.58 + gtk_entry_set_text(GTK_ENTRY(entry), filename);
1.59 + }
1.60 + gtk_widget_destroy(file);
1.61 +}
1.62 +
1.63 +static gboolean path_dir_button_clicked( GtkWidget *button, gpointer user_data )
1.64 +{
1.65 + GtkWidget *entry = GTK_WIDGET(user_data);
1.66 + GtkWidget *file = gtk_file_chooser_dialog_new( "Select file", NULL,
1.67 + GTK_FILE_CHOOSER_ACTION_OPEN,
1.68 + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1.69 + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1.70 + NULL );
1.71 + const gchar *filename = gtk_entry_get_text(GTK_ENTRY(entry));
1.72 + gtk_file_chooser_set_action( GTK_FILE_CHOOSER(file), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER );
1.73 + gtk_file_chooser_set_filename( GTK_FILE_CHOOSER(file), filename );
1.74 + gtk_window_set_modal( GTK_WINDOW(file), TRUE );
1.75 + gtk_widget_show_all( file );
1.76 + gint result = gtk_dialog_run(GTK_DIALOG(file));
1.77 + if( result == GTK_RESPONSE_ACCEPT ) {
1.78 + filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
1.79 + gtk_entry_set_text(GTK_ENTRY(entry), filename);
1.80 + }
1.81 + gtk_widget_destroy(file);
1.82 +}
1.83 +
1.84 +static gboolean path_text_changed( GtkWidget *entry, gpointer user_data )
1.85 +{
1.86 + const gchar *text = gtk_entry_get_text( GTK_ENTRY(entry) );
1.87 +}
1.88 +
1.89 +GtkWidget *path_panel_new(void)
1.90 +{
1.91 + GtkWidget *table = gtk_table_new( 5, 3, FALSE );
1.92 + GtkWidget *desc = gtk_label_new(NULL);
1.93 + int i;
1.94 + for( i=0; i<5; i++ ) {
1.95 + GtkWidget *text = path_entry[i] = gtk_entry_new();
1.96 + GtkWidget *button = gtk_button_new();
1.97 + gtk_table_attach( GTK_TABLE(table), gtk_label_new(path_label[i]), 0, 1, i, i+1,
1.98 + GTK_SHRINK, GTK_SHRINK, 0, 0);
1.99 + gtk_entry_set_text( GTK_ENTRY(text), lxdream_get_config_value(path_id[i]) );
1.100 + gtk_table_attach_defaults( GTK_TABLE(table), text, 1, 2, i, i+1 );
1.101 + gtk_table_attach( GTK_TABLE(table), button, 2, 3, i, i+1, GTK_SHRINK, GTK_SHRINK, 0, 0 );
1.102 + if( path_action[i] == GTK_FILE_CHOOSER_ACTION_OPEN ) {
1.103 + GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON);
1.104 + gtk_button_set_image( GTK_BUTTON(button), image );
1.105 + g_signal_connect( button, "clicked", G_CALLBACK(path_file_button_clicked), text );
1.106 + } else {
1.107 + GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_BUTTON);
1.108 + gtk_button_set_image( GTK_BUTTON(button), image );
1.109 + g_signal_connect( button, "clicked", G_CALLBACK(path_dir_button_clicked), text );
1.110 + }
1.111 + }
1.112 + return table;
1.113 +
1.114 +}
1.115 +
1.116 +void path_panel_commit_changes()
1.117 +{
1.118 + int i;
1.119 + for(i=0; i<5; i++ ) {
1.120 + const char *filename = gtk_entry_get_text( GTK_ENTRY(path_entry[i]) );
1.121 + lxdream_set_config_value( path_id[i], filename );
1.122 + }
1.123 +
1.124 + lxdream_save_config();
1.125 +}
1.126 +
1.127 +void path_dialog_run( void )
1.128 +{
1.129 + GtkWidget *dialog =
1.130 + gtk_dialog_new_with_buttons("Path Settings", NULL,
1.131 + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
1.132 + GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
1.133 + GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
1.134 + NULL);
1.135 + gint result;
1.136 + GtkWidget *panel = path_panel_new();
1.137 + gtk_widget_show_all(panel);
1.138 + gtk_container_add( GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), panel );
1.139 + result = gtk_dialog_run( GTK_DIALOG(dialog) );
1.140 + if( result == GTK_RESPONSE_ACCEPT ) {
1.141 + path_panel_commit_changes();
1.142 + }
1.143 + gtk_widget_destroy( dialog );
1.144 +}
.