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 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
nkeynes@450
     1
/**
nkeynes@450
     2
 * $Id: path_dlg.c,v 1.1 2007-10-17 11:26:45 nkeynes Exp $
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@450
    24
#include "config.h"
nkeynes@450
    25
#include "gui/gtkui.h"
nkeynes@450
    26
nkeynes@450
    27
static const gchar *path_label[] = { "Bios rom", "Flash rom", "Default disc path", 
nkeynes@450
    28
				     "Save state path", "Bootstrap IP.BIN" };
nkeynes@450
    29
static const int path_id[] = { CONFIG_BIOS_PATH, CONFIG_FLASH_PATH, CONFIG_DEFAULT_PATH,
nkeynes@450
    30
			       CONFIG_SAVE_PATH, CONFIG_BOOTSTRAP };
nkeynes@450
    31
static GtkFileChooserAction path_action[] = {
nkeynes@450
    32
    GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@450
    33
    GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@450
    34
    GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
nkeynes@450
    35
    GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
nkeynes@450
    36
    GTK_FILE_CHOOSER_ACTION_OPEN };
nkeynes@450
    37
nkeynes@450
    38
static GtkWidget *path_entry[5];
nkeynes@450
    39
nkeynes@450
    40
static gboolean path_file_button_clicked( GtkWidget *button, gpointer user_data )
nkeynes@450
    41
{
nkeynes@450
    42
    GtkWidget *entry = GTK_WIDGET(user_data);
nkeynes@450
    43
    GtkWidget *file = gtk_file_chooser_dialog_new( "Select file", NULL,
nkeynes@450
    44
					GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@450
    45
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@450
    46
					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
nkeynes@450
    47
					NULL );
nkeynes@450
    48
    const gchar *filename = gtk_entry_get_text(GTK_ENTRY(entry));
nkeynes@450
    49
    gtk_file_chooser_set_filename( GTK_FILE_CHOOSER(file), filename );
nkeynes@450
    50
    gtk_window_set_modal( GTK_WINDOW(file), TRUE );
nkeynes@450
    51
    gtk_widget_show_all( file );
nkeynes@450
    52
    gint result = gtk_dialog_run(GTK_DIALOG(file));
nkeynes@450
    53
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@450
    54
	filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
nkeynes@450
    55
	gtk_entry_set_text(GTK_ENTRY(entry), filename);
nkeynes@450
    56
    }
nkeynes@450
    57
    gtk_widget_destroy(file);
nkeynes@450
    58
}
nkeynes@450
    59
nkeynes@450
    60
static gboolean path_dir_button_clicked( GtkWidget *button, gpointer user_data )
nkeynes@450
    61
{
nkeynes@450
    62
    GtkWidget *entry = GTK_WIDGET(user_data);
nkeynes@450
    63
    GtkWidget *file = gtk_file_chooser_dialog_new( "Select file", NULL,
nkeynes@450
    64
					GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@450
    65
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@450
    66
					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
nkeynes@450
    67
					NULL );
nkeynes@450
    68
    const gchar *filename = gtk_entry_get_text(GTK_ENTRY(entry));
nkeynes@450
    69
    gtk_file_chooser_set_action( GTK_FILE_CHOOSER(file), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER );
nkeynes@450
    70
    gtk_file_chooser_set_filename( GTK_FILE_CHOOSER(file), filename );
nkeynes@450
    71
    gtk_window_set_modal( GTK_WINDOW(file), TRUE );
nkeynes@450
    72
    gtk_widget_show_all( file );
nkeynes@450
    73
    gint result = gtk_dialog_run(GTK_DIALOG(file));
nkeynes@450
    74
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@450
    75
	filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
nkeynes@450
    76
	gtk_entry_set_text(GTK_ENTRY(entry), filename);
nkeynes@450
    77
    }
nkeynes@450
    78
    gtk_widget_destroy(file);
nkeynes@450
    79
}
nkeynes@450
    80
nkeynes@450
    81
static gboolean path_text_changed( GtkWidget *entry, gpointer user_data )
nkeynes@450
    82
{
nkeynes@450
    83
    const gchar *text = gtk_entry_get_text( GTK_ENTRY(entry) );
nkeynes@450
    84
}
nkeynes@450
    85
nkeynes@450
    86
GtkWidget *path_panel_new(void)
nkeynes@450
    87
{
nkeynes@450
    88
    GtkWidget *table = gtk_table_new( 5, 3, FALSE );
nkeynes@450
    89
    GtkWidget *desc = gtk_label_new(NULL);
nkeynes@450
    90
    int i;
nkeynes@450
    91
    for( i=0; i<5; i++ ) {
nkeynes@450
    92
	GtkWidget *text = path_entry[i] = gtk_entry_new();
nkeynes@450
    93
	GtkWidget *button = gtk_button_new();
nkeynes@450
    94
	gtk_table_attach( GTK_TABLE(table), gtk_label_new(path_label[i]), 0, 1, i, i+1,
nkeynes@450
    95
			  GTK_SHRINK, GTK_SHRINK, 0, 0);
nkeynes@450
    96
	gtk_entry_set_text( GTK_ENTRY(text), lxdream_get_config_value(path_id[i]) );
nkeynes@450
    97
	gtk_table_attach_defaults( GTK_TABLE(table), text, 1, 2, i, i+1 );
nkeynes@450
    98
	gtk_table_attach( GTK_TABLE(table), button, 2, 3, i, i+1, GTK_SHRINK, GTK_SHRINK, 0, 0 );
nkeynes@450
    99
	if( path_action[i] == GTK_FILE_CHOOSER_ACTION_OPEN ) {
nkeynes@450
   100
	    GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON);
nkeynes@450
   101
	    gtk_button_set_image( GTK_BUTTON(button), image );
nkeynes@450
   102
	    g_signal_connect( button, "clicked", G_CALLBACK(path_file_button_clicked), text );
nkeynes@450
   103
	} else {
nkeynes@450
   104
	    GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_BUTTON);
nkeynes@450
   105
	    gtk_button_set_image( GTK_BUTTON(button), image );
nkeynes@450
   106
	    g_signal_connect( button, "clicked", G_CALLBACK(path_dir_button_clicked), text );
nkeynes@450
   107
	}
nkeynes@450
   108
    }
nkeynes@450
   109
    return table;
nkeynes@450
   110
nkeynes@450
   111
}
nkeynes@450
   112
nkeynes@450
   113
void path_panel_commit_changes()
nkeynes@450
   114
{
nkeynes@450
   115
    int i;
nkeynes@450
   116
    for(i=0; i<5; i++ ) {
nkeynes@450
   117
	const char *filename = gtk_entry_get_text( GTK_ENTRY(path_entry[i]) );
nkeynes@450
   118
	lxdream_set_config_value( path_id[i], filename );
nkeynes@450
   119
    }
nkeynes@450
   120
nkeynes@450
   121
    lxdream_save_config();
nkeynes@450
   122
}
nkeynes@450
   123
nkeynes@450
   124
void path_dialog_run( void )
nkeynes@450
   125
{
nkeynes@450
   126
    GtkWidget *dialog =
nkeynes@450
   127
	gtk_dialog_new_with_buttons("Path Settings", NULL, 
nkeynes@450
   128
				    GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
nkeynes@450
   129
				    GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
nkeynes@450
   130
				    GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
nkeynes@450
   131
				    NULL);
nkeynes@450
   132
    gint result;
nkeynes@450
   133
    GtkWidget *panel = path_panel_new();
nkeynes@450
   134
    gtk_widget_show_all(panel);
nkeynes@450
   135
    gtk_container_add( GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), panel );
nkeynes@450
   136
    result = gtk_dialog_run( GTK_DIALOG(dialog) );
nkeynes@450
   137
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@450
   138
	path_panel_commit_changes();
nkeynes@450
   139
    }
nkeynes@450
   140
    gtk_widget_destroy( dialog );
nkeynes@450
   141
}
.