Search
lxdream.org :: lxdream/src/gtkui/gtk_path.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gtkui/gtk_path.c
changeset 1036:af7b0c5905dd
prev763:b3ce4448f200
next1041:5fcc39857c5c
author nkeynes
date Wed Jun 24 06:06:40 2009 +0000 (13 years ago)
permissions -rw-r--r--
last change Support shell substitutions in config paths
Keep track of last folder in file dialogs
Fix out-of-dateness in GTK path dialog
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@658
    23
#include "lxdream.h"
nkeynes@481
    24
#include "dreamcast.h"
nkeynes@450
    25
#include "config.h"
nkeynes@537
    26
#include "gtkui/gtkui.h"
nkeynes@450
    27
nkeynes@1036
    28
static GtkWidget *path_entry[CONFIG_KEY_MAX];
nkeynes@450
    29
nkeynes@450
    30
static gboolean path_file_button_clicked( GtkWidget *button, gpointer user_data )
nkeynes@450
    31
{
nkeynes@450
    32
    GtkWidget *entry = GTK_WIDGET(user_data);
nkeynes@508
    33
    GtkWidget *file = gtk_file_chooser_dialog_new( _("Select file"), NULL,
nkeynes@736
    34
            GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@736
    35
            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@736
    36
            GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
nkeynes@736
    37
            NULL );
nkeynes@1036
    38
    gchar *filename = get_expanded_path(gtk_entry_get_text(GTK_ENTRY(entry)));
nkeynes@450
    39
    gtk_file_chooser_set_filename( GTK_FILE_CHOOSER(file), filename );
nkeynes@450
    40
    gtk_window_set_modal( GTK_WINDOW(file), TRUE );
nkeynes@450
    41
    gtk_widget_show_all( file );
nkeynes@450
    42
    gint result = gtk_dialog_run(GTK_DIALOG(file));
nkeynes@1036
    43
    g_free(filename);
nkeynes@450
    44
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@1036
    45
        filename = get_escaped_path(gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) ));
nkeynes@736
    46
        gtk_entry_set_text(GTK_ENTRY(entry), filename);
nkeynes@1036
    47
        g_free(filename);
nkeynes@450
    48
    }
nkeynes@450
    49
    gtk_widget_destroy(file);
nkeynes@481
    50
    return TRUE;
nkeynes@450
    51
}
nkeynes@450
    52
nkeynes@450
    53
static gboolean path_dir_button_clicked( GtkWidget *button, gpointer user_data )
nkeynes@450
    54
{
nkeynes@450
    55
    GtkWidget *entry = GTK_WIDGET(user_data);
nkeynes@508
    56
    GtkWidget *file = gtk_file_chooser_dialog_new( _("Select file"), NULL,
nkeynes@736
    57
            GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@736
    58
            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@736
    59
            GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
nkeynes@736
    60
            NULL );
nkeynes@1036
    61
    gchar *filename = get_expanded_path(gtk_entry_get_text(GTK_ENTRY(entry)));
nkeynes@450
    62
    gtk_file_chooser_set_action( GTK_FILE_CHOOSER(file), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER );
nkeynes@450
    63
    gtk_file_chooser_set_filename( GTK_FILE_CHOOSER(file), filename );
nkeynes@450
    64
    gtk_window_set_modal( GTK_WINDOW(file), TRUE );
nkeynes@450
    65
    gtk_widget_show_all( file );
nkeynes@450
    66
    gint result = gtk_dialog_run(GTK_DIALOG(file));
nkeynes@1036
    67
    g_free(filename);
nkeynes@450
    68
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@1036
    69
        filename = get_escaped_path(gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) ));
nkeynes@736
    70
        gtk_entry_set_text(GTK_ENTRY(entry), filename);
nkeynes@1036
    71
        g_free(filename);
nkeynes@450
    72
    }
nkeynes@450
    73
    gtk_widget_destroy(file);
nkeynes@481
    74
    return TRUE;
nkeynes@450
    75
}
nkeynes@450
    76
nkeynes@450
    77
GtkWidget *path_panel_new(void)
nkeynes@450
    78
{
nkeynes@1036
    79
    int i, y=0;
nkeynes@1036
    80
    GtkWidget *table = gtk_table_new( CONFIG_KEY_MAX, 3, FALSE );
nkeynes@1036
    81
    for( i=0; i<CONFIG_KEY_MAX; i++ ) {
nkeynes@1036
    82
        const struct lxdream_config_entry *entry = lxdream_get_global_config_entry(i);
nkeynes@1036
    83
        if( entry->label != NULL ) {
nkeynes@1036
    84
            GtkWidget *text = path_entry[i] = gtk_entry_new();
nkeynes@1036
    85
            GtkWidget *button = gtk_button_new();
nkeynes@1036
    86
            gtk_table_attach( GTK_TABLE(table), gtk_label_new(Q_(entry->label)), 0, 1, y, y+1,
nkeynes@1036
    87
                              GTK_SHRINK, GTK_SHRINK, 0, 0);
nkeynes@1036
    88
            gtk_entry_set_text( GTK_ENTRY(text), lxdream_get_global_config_value(i) );
nkeynes@1036
    89
            gtk_entry_set_width_chars( GTK_ENTRY(text), 48 );
nkeynes@1036
    90
            gtk_table_attach_defaults( GTK_TABLE(table), text, 1, 2, y, y+1 );
nkeynes@1036
    91
            gtk_table_attach( GTK_TABLE(table), button, 2, 3, y, y+1, GTK_SHRINK, GTK_SHRINK, 0, 0 );
nkeynes@1036
    92
            if( entry->type == CONFIG_TYPE_FILE ) {
nkeynes@1036
    93
                GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_FILE, GTK_ICON_SIZE_MENU);
nkeynes@1036
    94
                gtk_button_set_image( GTK_BUTTON(button), image );
nkeynes@1036
    95
                g_signal_connect( button, "clicked", G_CALLBACK(path_file_button_clicked), text );
nkeynes@1036
    96
            } else {
nkeynes@1036
    97
                GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU);
nkeynes@1036
    98
                gtk_button_set_image( GTK_BUTTON(button), image );
nkeynes@1036
    99
                g_signal_connect( button, "clicked", G_CALLBACK(path_dir_button_clicked), text );
nkeynes@1036
   100
            }
nkeynes@1036
   101
            y++;
nkeynes@736
   102
        }
nkeynes@450
   103
    }
nkeynes@1036
   104
    gtk_table_resize( GTK_TABLE(table), y, 3 );
nkeynes@450
   105
    return table;
nkeynes@450
   106
nkeynes@450
   107
}
nkeynes@450
   108
nkeynes@461
   109
void path_panel_done( GtkWidget *panel, gboolean isOK )
nkeynes@450
   110
{
nkeynes@461
   111
    if( isOK ) {
nkeynes@736
   112
        int i;
nkeynes@1036
   113
        for(i=0; i<CONFIG_KEY_MAX; i++ ) {
nkeynes@1036
   114
            if( path_entry[i] != NULL ) {
nkeynes@1036
   115
                const char *filename = gtk_entry_get_text( GTK_ENTRY(path_entry[i]) );
nkeynes@1036
   116
                lxdream_set_global_config_value( i, filename );
nkeynes@1036
   117
            }
nkeynes@736
   118
        }
nkeynes@736
   119
nkeynes@736
   120
        lxdream_save_config();
nkeynes@736
   121
        dreamcast_config_changed();
nkeynes@1036
   122
        gui_config_paths_changed();
nkeynes@736
   123
        gtk_gui_update();
nkeynes@450
   124
    }
nkeynes@450
   125
}
nkeynes@450
   126
nkeynes@450
   127
void path_dialog_run( void )
nkeynes@450
   128
{
nkeynes@508
   129
    gtk_gui_run_property_dialog( _("Path Settings"), path_panel_new(), path_panel_done );
nkeynes@450
   130
}
.