Search
lxdream.org :: lxdream/src/gtkui/gtkcb.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gtkui/gtkcb.c
changeset 630:50addb748df5
prev561:533f6b478071
next669:ab344e42bca9
author nkeynes
date Tue Feb 12 08:36:29 2008 +0000 (12 years ago)
permissions -rw-r--r--
last change Bug #55: Fix relative path handling
Canonicalize paths before passing to the file dialog
file annotate diff log raw
nkeynes@435
     1
/**
nkeynes@561
     2
 * $Id$
nkeynes@435
     3
 *
nkeynes@435
     4
 * Action callbacks from the main window
nkeynes@435
     5
 *
nkeynes@435
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@435
     7
 *
nkeynes@435
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@435
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@435
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@435
    11
 * (at your option) any later version.
nkeynes@435
    12
 *
nkeynes@435
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@435
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@435
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@435
    16
 * GNU General Public License for more details.
nkeynes@435
    17
 */
nkeynes@435
    18
nkeynes@435
    19
#include "dream.h"
nkeynes@450
    20
#include "config.h"
nkeynes@435
    21
#include "dreamcast.h"
nkeynes@435
    22
#include "gdrom/gdrom.h"
nkeynes@537
    23
#include "gtkui/gtkui.h"
nkeynes@455
    24
#include "pvr2/pvr2.h"
nkeynes@543
    25
#include "loader.h"
nkeynes@435
    26
nkeynes@435
    27
nkeynes@435
    28
static void add_file_pattern( GtkFileChooser *chooser, char *pattern, char *patname )
nkeynes@435
    29
{
nkeynes@435
    30
    if( pattern != NULL ) {
nkeynes@435
    31
	GtkFileFilter *filter = gtk_file_filter_new();
nkeynes@435
    32
	gtk_file_filter_add_pattern( filter, pattern );
nkeynes@435
    33
	gtk_file_filter_set_name( filter, patname );
nkeynes@435
    34
	gtk_file_chooser_add_filter( chooser, filter );
nkeynes@435
    35
	filter = gtk_file_filter_new();
nkeynes@508
    36
	gtk_file_filter_set_name( filter, _("All files") );
nkeynes@435
    37
	gtk_file_filter_add_pattern( filter, "*" );
nkeynes@435
    38
	gtk_file_chooser_add_filter( chooser, filter );
nkeynes@435
    39
    }
nkeynes@435
    40
}
nkeynes@435
    41
nkeynes@435
    42
void open_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
nkeynes@435
    43
		       gchar const *initial_dir )
nkeynes@435
    44
{
nkeynes@435
    45
    GtkWidget *file;
nkeynes@630
    46
    gchar *initial_path = get_absolute_path(initial_dir);
nkeynes@435
    47
    file = gtk_file_chooser_dialog_new( title, NULL,
nkeynes@435
    48
					GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@435
    49
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@435
    50
					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
nkeynes@435
    51
					NULL );
nkeynes@435
    52
    add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
nkeynes@630
    53
    gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_path );
nkeynes@435
    54
    gtk_window_set_modal( GTK_WINDOW(file), TRUE );
nkeynes@477
    55
    gtk_dialog_set_default_response( GTK_DIALOG(file), GTK_RESPONSE_ACCEPT );
nkeynes@477
    56
    int result = gtk_dialog_run( GTK_DIALOG(file) );
nkeynes@477
    57
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@477
    58
	gchar *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
nkeynes@477
    59
	action( filename );
nkeynes@477
    60
    }
nkeynes@477
    61
    gtk_widget_destroy(file);
nkeynes@630
    62
    g_free(initial_path);
nkeynes@435
    63
}
nkeynes@435
    64
nkeynes@435
    65
void save_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
nkeynes@435
    66
		       gchar const *initial_dir )
nkeynes@435
    67
{
nkeynes@435
    68
    GtkWidget *file;
nkeynes@630
    69
    gchar *initial_path = get_absolute_path(initial_dir);
nkeynes@435
    70
    file = gtk_file_chooser_dialog_new( title, NULL,
nkeynes@435
    71
					GTK_FILE_CHOOSER_ACTION_SAVE,
nkeynes@435
    72
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@435
    73
					GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
nkeynes@435
    74
					NULL );
nkeynes@435
    75
    add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
nkeynes@630
    76
    gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_path );
nkeynes@435
    77
    gtk_window_set_modal( GTK_WINDOW(file), TRUE );
nkeynes@477
    78
    gtk_dialog_set_default_response( GTK_DIALOG(file), GTK_RESPONSE_ACCEPT );
nkeynes@477
    79
    int result = gtk_dialog_run( GTK_DIALOG(file) );
nkeynes@477
    80
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@477
    81
	gchar *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
nkeynes@477
    82
	action( filename );
nkeynes@477
    83
    }
nkeynes@477
    84
    gtk_widget_destroy(file);
nkeynes@630
    85
    g_free(initial_path);
nkeynes@435
    86
}
nkeynes@435
    87
nkeynes@435
    88
void mount_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
    89
{
nkeynes@450
    90
    const gchar *dir = lxdream_get_config_value(CONFIG_DEFAULT_PATH);
nkeynes@435
    91
    open_file_dialog( "Open...", gdrom_mount_image, NULL, NULL, dir );
nkeynes@435
    92
}
nkeynes@435
    93
void reset_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
    94
{
nkeynes@435
    95
    dreamcast_reset();
nkeynes@435
    96
}
nkeynes@435
    97
nkeynes@435
    98
void pause_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
    99
{
nkeynes@435
   100
    dreamcast_stop();
nkeynes@435
   101
}
nkeynes@435
   102
nkeynes@435
   103
void resume_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   104
{
nkeynes@435
   105
    dreamcast_run();
nkeynes@435
   106
}
nkeynes@435
   107
nkeynes@543
   108
void load_binary_action_callback( GtkAction *action, gpointer user_data)
nkeynes@543
   109
{
nkeynes@543
   110
    const gchar *dir = lxdream_get_config_value(CONFIG_DEFAULT_PATH);
nkeynes@543
   111
    open_file_dialog( "Open Binary...", file_load_magic, NULL, NULL, dir );
nkeynes@543
   112
}
nkeynes@543
   113
nkeynes@477
   114
void load_state_preview_callback( GtkFileChooser *chooser, gpointer user_data )
nkeynes@477
   115
{
nkeynes@477
   116
    GtkWidget *preview = GTK_WIDGET(user_data);
nkeynes@477
   117
    gchar *filename = gtk_file_chooser_get_preview_filename(chooser);
nkeynes@477
   118
    
nkeynes@477
   119
    frame_buffer_t data = dreamcast_load_preview(filename);
nkeynes@477
   120
    if( data != NULL ) {
nkeynes@477
   121
	GdkPixbuf *pixbuf = gdk_pixbuf_new_from_frame_buffer(data);
nkeynes@477
   122
	GdkPixbuf *scaled = gdk_pixbuf_scale_simple(pixbuf, 320, 240,
nkeynes@477
   123
						    GDK_INTERP_BILINEAR);
nkeynes@477
   124
	g_object_unref(pixbuf);
nkeynes@477
   125
	gtk_image_set_from_pixbuf( GTK_IMAGE(preview), scaled );
nkeynes@477
   126
	g_object_unref(scaled);
nkeynes@477
   127
	gtk_widget_show(preview);
nkeynes@477
   128
    } else {
nkeynes@477
   129
	gtk_widget_hide(preview);
nkeynes@477
   130
    }
nkeynes@477
   131
}
nkeynes@477
   132
nkeynes@435
   133
void load_state_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   134
{
nkeynes@477
   135
    GtkWidget *file, *preview, *frame, *align;
nkeynes@477
   136
    GtkRequisition size;
nkeynes@450
   137
    const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
nkeynes@630
   138
    const gchar *path = get_absolute_path(dir);
nkeynes@508
   139
    file = gtk_file_chooser_dialog_new( _("Load state..."), NULL,
nkeynes@477
   140
					GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@477
   141
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@477
   142
					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
nkeynes@477
   143
					NULL );
nkeynes@508
   144
    add_file_pattern( GTK_FILE_CHOOSER(file), "*.dst", _("lxDream Save State (*.dst)") );
nkeynes@477
   145
    gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
nkeynes@477
   146
nkeynes@477
   147
    preview = gtk_image_new( );
nkeynes@477
   148
nkeynes@477
   149
    frame = gtk_frame_new(NULL);
nkeynes@477
   150
    gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_IN );
nkeynes@477
   151
    gtk_container_add( GTK_CONTAINER(frame), preview );
nkeynes@477
   152
    gtk_widget_show(frame);
nkeynes@477
   153
    gtk_widget_size_request(frame, &size);
nkeynes@477
   154
    gtk_widget_set_size_request(frame, size.width + 320, size.height + 240);
nkeynes@477
   155
    align = gtk_alignment_new(0.5, 0.5, 0, 0 );
nkeynes@477
   156
    gtk_container_add( GTK_CONTAINER(align), frame );
nkeynes@477
   157
    gtk_widget_show( align );
nkeynes@477
   158
    gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(file), align);
nkeynes@477
   159
    g_signal_connect( file, "update-preview", G_CALLBACK(load_state_preview_callback),
nkeynes@477
   160
		      preview );
nkeynes@630
   161
    gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), path );
nkeynes@477
   162
    gtk_window_set_modal( GTK_WINDOW(file), TRUE );
nkeynes@477
   163
    int result = gtk_dialog_run( GTK_DIALOG(file) );
nkeynes@477
   164
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@477
   165
	gchar *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(file) );
nkeynes@477
   166
	dreamcast_load_state( filename );
nkeynes@477
   167
    }
nkeynes@477
   168
    gtk_widget_destroy(file);
nkeynes@630
   169
    g_free(path);
nkeynes@435
   170
}
nkeynes@477
   171
nkeynes@435
   172
void save_state_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   173
{
nkeynes@450
   174
    const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
nkeynes@508
   175
    save_file_dialog( "Save state...", dreamcast_save_state, "*.dst", _("lxDream Save State (*.dst)"), dir );
nkeynes@435
   176
}
nkeynes@435
   177
void about_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   178
{
nkeynes@435
   179
    
nkeynes@435
   180
    GtkWidget *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG,
nkeynes@435
   181
				      "name", APP_NAME, 
nkeynes@435
   182
                                     "version", APP_VERSION,
nkeynes@435
   183
			             "copyright", "(C) 2003-2007 Nathan Keynes",
nkeynes@435
   184
                                     NULL);
nkeynes@435
   185
    gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
nkeynes@447
   186
    gtk_dialog_run(GTK_DIALOG(dialog));
nkeynes@447
   187
    gtk_widget_destroy(dialog);
nkeynes@435
   188
    
nkeynes@435
   189
}
nkeynes@435
   190
nkeynes@435
   191
void exit_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   192
{
nkeynes@435
   193
    exit(0);
nkeynes@435
   194
}
nkeynes@435
   195
nkeynes@447
   196
void path_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@447
   197
{
nkeynes@450
   198
    path_dialog_run();
nkeynes@447
   199
}
nkeynes@447
   200
nkeynes@435
   201
void audio_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   202
{
nkeynes@435
   203
}
nkeynes@435
   204
nkeynes@455
   205
void maple_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   206
{
nkeynes@455
   207
    maple_dialog_run( );
nkeynes@435
   208
}
nkeynes@435
   209
nkeynes@435
   210
void network_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   211
{
nkeynes@435
   212
}
nkeynes@435
   213
nkeynes@435
   214
void video_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   215
{
nkeynes@435
   216
}
nkeynes@435
   217
nkeynes@435
   218
void fullscreen_toggle_callback( GtkToggleAction *action, gpointer user_data)
nkeynes@435
   219
{
nkeynes@486
   220
    main_window_set_fullscreen(gtk_gui_get_main(), gtk_toggle_action_get_active(action));
nkeynes@435
   221
}
nkeynes@455
   222
nkeynes@455
   223
void debugger_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   224
{
nkeynes@455
   225
    gtk_gui_show_debugger();
nkeynes@455
   226
}
nkeynes@455
   227
nkeynes@455
   228
void debug_memory_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   229
{
nkeynes@508
   230
    gchar *title = g_strdup_printf( APP_NAME " " APP_VERSION " :: %s", _("Memory dump") );
nkeynes@508
   231
    dump_window_new( title );
nkeynes@508
   232
    g_free(title);
nkeynes@455
   233
}
nkeynes@455
   234
nkeynes@455
   235
void debug_mmio_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   236
{
nkeynes@455
   237
    gtk_gui_show_mmio();
nkeynes@455
   238
}
nkeynes@455
   239
nkeynes@455
   240
void save_scene_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   241
{
nkeynes@455
   242
    const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
nkeynes@508
   243
    save_file_dialog( _("Save next scene..."), pvr2_save_next_scene, "*.dsc", _("lxdream scene file (*.dsc)"), dir );
nkeynes@455
   244
}
nkeynes@455
   245
nkeynes@480
   246
int debug_window_get_selected_row( debug_window_t data );
nkeynes@480
   247
nkeynes@455
   248
void debug_step_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   249
{
nkeynes@455
   250
    debug_window_single_step(gtk_gui_get_debugger());
nkeynes@455
   251
}
nkeynes@455
   252
nkeynes@455
   253
void debug_runto_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   254
{
nkeynes@455
   255
    debug_window_t debug = gtk_gui_get_debugger();
nkeynes@455
   256
    int selected_row = debug_window_get_selected_row(debug);
nkeynes@455
   257
    if( selected_row == -1 ) {
nkeynes@508
   258
        WARN( _("No address selected, so can't run to it"), NULL );
nkeynes@455
   259
    } else {
nkeynes@455
   260
	debug_window_set_oneshot_breakpoint( debug, selected_row );
nkeynes@455
   261
	dreamcast_run();
nkeynes@455
   262
    }
nkeynes@455
   263
}
nkeynes@455
   264
nkeynes@455
   265
void debug_breakpoint_action_callback( GtkAction *action, gpointer user_data)
nkeynes@455
   266
{
nkeynes@455
   267
    debug_window_t debug = gtk_gui_get_debugger();
nkeynes@455
   268
    int selected_row = debug_window_get_selected_row(debug);
nkeynes@455
   269
    if( selected_row != -1 ) {
nkeynes@455
   270
	debug_window_toggle_breakpoint( debug, selected_row );
nkeynes@455
   271
    }
nkeynes@455
   272
}
.