Search
lxdream.org :: lxdream/src/gtkui/gtk_path.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gtkui/gtk_path.c
changeset 1065:bc1cc0c54917
prev561:533f6b478071
prev1041:5fcc39857c5c
author nkeynes
date Sun Jul 05 13:52:50 2009 +1000 (12 years ago)
permissions -rw-r--r--
last change No-op merge lxdream-mmu to remove head (actually merged long ago)
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/gtkui/gtk_path.c Sun Jul 05 13:52:50 2009 +1000
1.3 @@ -0,0 +1,130 @@
1.4 +/**
1.5 + * $Id$
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 "lxdream.h"
1.27 +#include "dreamcast.h"
1.28 +#include "config.h"
1.29 +#include "lxpaths.h"
1.30 +#include "gtkui/gtkui.h"
1.31 +
1.32 +static GtkWidget *path_entry[CONFIG_KEY_MAX];
1.33 +
1.34 +static gboolean path_file_button_clicked( GtkWidget *button, gpointer user_data )
1.35 +{
1.36 + GtkWidget *entry = GTK_WIDGET(user_data);
1.37 + GtkWidget *file = gtk_file_chooser_dialog_new( _("Select file"), NULL,
1.38 + GTK_FILE_CHOOSER_ACTION_OPEN,
1.39 + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1.40 + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1.41 + NULL );
1.42 + gchar *filename = get_expanded_path(gtk_entry_get_text(GTK_ENTRY(entry)));
1.43 + gtk_file_chooser_set_filename( GTK_FILE_CHOOSER(file), filename );
1.44 + gtk_window_set_modal( GTK_WINDOW(file), TRUE );
1.45 + gtk_widget_show_all( file );
1.46 + gint result = gtk_dialog_run(GTK_DIALOG(file));
1.47 + g_free(filename);
1.48 + if( result == GTK_RESPONSE_ACCEPT ) {
1.49 + filename = get_escaped_path(gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) ));
1.50 + gtk_entry_set_text(GTK_ENTRY(entry), filename);
1.51 + g_free(filename);
1.52 + }
1.53 + gtk_widget_destroy(file);
1.54 + return TRUE;
1.55 +}
1.56 +
1.57 +static gboolean path_dir_button_clicked( GtkWidget *button, gpointer user_data )
1.58 +{
1.59 + GtkWidget *entry = GTK_WIDGET(user_data);
1.60 + GtkWidget *file = gtk_file_chooser_dialog_new( _("Select file"), NULL,
1.61 + GTK_FILE_CHOOSER_ACTION_OPEN,
1.62 + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1.63 + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1.64 + NULL );
1.65 + gchar *filename = get_expanded_path(gtk_entry_get_text(GTK_ENTRY(entry)));
1.66 + gtk_file_chooser_set_action( GTK_FILE_CHOOSER(file), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER );
1.67 + gtk_file_chooser_set_filename( GTK_FILE_CHOOSER(file), filename );
1.68 + gtk_window_set_modal( GTK_WINDOW(file), TRUE );
1.69 + gtk_widget_show_all( file );
1.70 + gint result = gtk_dialog_run(GTK_DIALOG(file));
1.71 + g_free(filename);
1.72 + if( result == GTK_RESPONSE_ACCEPT ) {
1.73 + filename = get_escaped_path(gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) ));
1.74 + gtk_entry_set_text(GTK_ENTRY(entry), filename);
1.75 + g_free(filename);
1.76 + }
1.77 + gtk_widget_destroy(file);
1.78 + return TRUE;
1.79 +}
1.80 +
1.81 +GtkWidget *path_panel_new(void)
1.82 +{
1.83 + int i, y=0;
1.84 + GtkWidget *table = gtk_table_new( CONFIG_KEY_MAX, 3, FALSE );
1.85 + for( i=0; i<CONFIG_KEY_MAX; i++ ) {
1.86 + const struct lxdream_config_entry *entry = lxdream_get_global_config_entry(i);
1.87 + if( entry->label != NULL ) {
1.88 + GtkWidget *text = path_entry[i] = gtk_entry_new();
1.89 + GtkWidget *button = gtk_button_new();
1.90 + gtk_table_attach( GTK_TABLE(table), gtk_label_new(Q_(entry->label)), 0, 1, y, y+1,
1.91 + GTK_SHRINK, GTK_SHRINK, 0, 0);
1.92 + gtk_entry_set_text( GTK_ENTRY(text), lxdream_get_global_config_value(i) );
1.93 + gtk_entry_set_width_chars( GTK_ENTRY(text), 48 );
1.94 + gtk_table_attach_defaults( GTK_TABLE(table), text, 1, 2, y, y+1 );
1.95 + gtk_table_attach( GTK_TABLE(table), button, 2, 3, y, y+1, GTK_SHRINK, GTK_SHRINK, 0, 0 );
1.96 + if( entry->type == CONFIG_TYPE_FILE ) {
1.97 + GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_FILE, GTK_ICON_SIZE_MENU);
1.98 + gtk_button_set_image( GTK_BUTTON(button), image );
1.99 + g_signal_connect( button, "clicked", G_CALLBACK(path_file_button_clicked), text );
1.100 + } else {
1.101 + GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU);
1.102 + gtk_button_set_image( GTK_BUTTON(button), image );
1.103 + g_signal_connect( button, "clicked", G_CALLBACK(path_dir_button_clicked), text );
1.104 + }
1.105 + y++;
1.106 + }
1.107 + }
1.108 + gtk_table_resize( GTK_TABLE(table), y, 3 );
1.109 + return table;
1.110 +
1.111 +}
1.112 +
1.113 +void path_panel_done( GtkWidget *panel, gboolean isOK )
1.114 +{
1.115 + if( isOK ) {
1.116 + int i;
1.117 + for(i=0; i<CONFIG_KEY_MAX; i++ ) {
1.118 + if( path_entry[i] != NULL ) {
1.119 + const char *filename = gtk_entry_get_text( GTK_ENTRY(path_entry[i]) );
1.120 + lxdream_set_global_config_value( i, filename );
1.121 + }
1.122 + }
1.123 +
1.124 + lxdream_save_config();
1.125 + dreamcast_config_changed();
1.126 + gtk_gui_update();
1.127 + }
1.128 +}
1.129 +
1.130 +void path_dialog_run( void )
1.131 +{
1.132 + gtk_gui_run_property_dialog( _("Path Settings"), path_panel_new(), path_panel_done );
1.133 +}
.