Search
lxdream.org :: lxdream/src/gui/gtkcb.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/gtkcb.c
changeset 450:207461e79f21
prev447:3e095bfcb476
next455:3080881d00d4
author nkeynes
date Wed Oct 17 11:26:45 2007 +0000 (12 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@435
     1
/**
nkeynes@450
     2
 * $Id: gtkcb.c,v 1.4 2007-10-17 11:26:45 nkeynes Exp $
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@435
    23
#include "gui/gtkui.h"
nkeynes@435
    24
nkeynes@435
    25
typedef gboolean (*file_callback_t)( const gchar *filename );
nkeynes@435
    26
nkeynes@435
    27
static gboolean dreamcast_paused = FALSE;
nkeynes@435
    28
nkeynes@435
    29
void dreamcast_pause()
nkeynes@435
    30
{
nkeynes@435
    31
    if( dreamcast_is_running() ) {
nkeynes@435
    32
	dreamcast_paused = TRUE;
nkeynes@435
    33
	dreamcast_stop();
nkeynes@435
    34
    }
nkeynes@435
    35
}
nkeynes@435
    36
nkeynes@435
    37
void dreamcast_unpause()
nkeynes@435
    38
{
nkeynes@435
    39
    if( dreamcast_paused ) {
nkeynes@435
    40
	dreamcast_paused = FALSE;
nkeynes@435
    41
	if( !dreamcast_is_running() ) {
nkeynes@435
    42
	    dreamcast_run();
nkeynes@435
    43
	}
nkeynes@435
    44
    }
nkeynes@435
    45
}
nkeynes@435
    46
nkeynes@435
    47
nkeynes@435
    48
void open_file_callback(GtkWidget *btn, gint result, gpointer user_data) {
nkeynes@435
    49
    GtkFileChooser *file = GTK_FILE_CHOOSER(user_data);
nkeynes@435
    50
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@435
    51
	gchar *filename =gtk_file_chooser_get_filename(
nkeynes@435
    52
						       GTK_FILE_CHOOSER(file) );
nkeynes@435
    53
	file_callback_t action = (file_callback_t)gtk_object_get_data( GTK_OBJECT(file), "file_action" );
nkeynes@435
    54
	gtk_widget_destroy(GTK_WIDGET(file));
nkeynes@435
    55
	action( filename );
nkeynes@435
    56
	g_free(filename);
nkeynes@435
    57
    } else {
nkeynes@435
    58
	gtk_widget_destroy(GTK_WIDGET(file));
nkeynes@435
    59
    }
nkeynes@435
    60
    dreamcast_unpause();
nkeynes@435
    61
}
nkeynes@435
    62
nkeynes@435
    63
static void add_file_pattern( GtkFileChooser *chooser, char *pattern, char *patname )
nkeynes@435
    64
{
nkeynes@435
    65
    if( pattern != NULL ) {
nkeynes@435
    66
	GtkFileFilter *filter = gtk_file_filter_new();
nkeynes@435
    67
	gtk_file_filter_add_pattern( filter, pattern );
nkeynes@435
    68
	gtk_file_filter_set_name( filter, patname );
nkeynes@435
    69
	gtk_file_chooser_add_filter( chooser, filter );
nkeynes@435
    70
	filter = gtk_file_filter_new();
nkeynes@435
    71
	gtk_file_filter_set_name( filter, "All files" );
nkeynes@435
    72
	gtk_file_filter_add_pattern( filter, "*" );
nkeynes@435
    73
	gtk_file_chooser_add_filter( chooser, filter );
nkeynes@435
    74
    }
nkeynes@435
    75
}
nkeynes@435
    76
nkeynes@435
    77
void open_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
nkeynes@435
    78
		       gchar const *initial_dir )
nkeynes@435
    79
{
nkeynes@435
    80
    GtkWidget *file;
nkeynes@435
    81
    dreamcast_pause();
nkeynes@435
    82
    file = gtk_file_chooser_dialog_new( title, NULL,
nkeynes@435
    83
					GTK_FILE_CHOOSER_ACTION_OPEN,
nkeynes@435
    84
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@435
    85
					GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
nkeynes@435
    86
					NULL );
nkeynes@435
    87
    add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
nkeynes@435
    88
    g_signal_connect( GTK_OBJECT(file), "response", 
nkeynes@435
    89
		      GTK_SIGNAL_FUNC(open_file_callback), file );
nkeynes@435
    90
    gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
nkeynes@435
    91
    gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_dir );
nkeynes@435
    92
    gtk_window_set_modal( GTK_WINDOW(file), TRUE );
nkeynes@435
    93
    gtk_widget_show( file );
nkeynes@435
    94
}
nkeynes@435
    95
nkeynes@435
    96
void save_file_dialog( char *title, file_callback_t action, char *pattern, char *patname,
nkeynes@435
    97
		       gchar const *initial_dir )
nkeynes@435
    98
{
nkeynes@435
    99
    GtkWidget *file;
nkeynes@435
   100
    dreamcast_pause();
nkeynes@435
   101
    file = gtk_file_chooser_dialog_new( title, NULL,
nkeynes@435
   102
					GTK_FILE_CHOOSER_ACTION_SAVE,
nkeynes@435
   103
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
nkeynes@435
   104
					GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
nkeynes@435
   105
					NULL );
nkeynes@435
   106
    add_file_pattern( GTK_FILE_CHOOSER(file), pattern, patname );
nkeynes@435
   107
    g_signal_connect( GTK_OBJECT(file), "response", 
nkeynes@435
   108
		      GTK_SIGNAL_FUNC(open_file_callback), file );
nkeynes@435
   109
    gtk_object_set_data( GTK_OBJECT(file), "file_action", action );
nkeynes@435
   110
    gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(file), initial_dir );
nkeynes@435
   111
    gtk_window_set_modal( GTK_WINDOW(file), TRUE );
nkeynes@435
   112
    gtk_widget_show( file );
nkeynes@435
   113
}
nkeynes@435
   114
nkeynes@435
   115
void mount_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   116
{
nkeynes@450
   117
    const gchar *dir = lxdream_get_config_value(CONFIG_DEFAULT_PATH);
nkeynes@435
   118
    open_file_dialog( "Open...", gdrom_mount_image, NULL, NULL, dir );
nkeynes@435
   119
}
nkeynes@435
   120
void reset_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   121
{
nkeynes@435
   122
    dreamcast_reset();
nkeynes@435
   123
}
nkeynes@435
   124
nkeynes@435
   125
void pause_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   126
{
nkeynes@435
   127
    dreamcast_stop();
nkeynes@435
   128
}
nkeynes@435
   129
nkeynes@435
   130
void resume_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   131
{
nkeynes@435
   132
    dreamcast_run();
nkeynes@435
   133
}
nkeynes@435
   134
nkeynes@435
   135
void load_state_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   136
{
nkeynes@450
   137
    const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
nkeynes@435
   138
    open_file_dialog( "Load state...", dreamcast_load_state, "*.dst", "lxDream Save State (*.dst)", dir );
nkeynes@435
   139
}
nkeynes@435
   140
void save_state_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   141
{
nkeynes@450
   142
    const gchar *dir = lxdream_get_config_value(CONFIG_SAVE_PATH);
nkeynes@435
   143
    save_file_dialog( "Save state...", dreamcast_save_state, "*.dst", "lxDream Save State (*.dst)", dir );
nkeynes@435
   144
}
nkeynes@435
   145
void about_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   146
{
nkeynes@435
   147
    
nkeynes@435
   148
    GtkWidget *dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG,
nkeynes@435
   149
				      "name", APP_NAME, 
nkeynes@435
   150
                                     "version", APP_VERSION,
nkeynes@435
   151
			             "copyright", "(C) 2003-2007 Nathan Keynes",
nkeynes@435
   152
                                     NULL);
nkeynes@435
   153
    gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
nkeynes@447
   154
    gtk_dialog_run(GTK_DIALOG(dialog));
nkeynes@447
   155
    gtk_widget_destroy(dialog);
nkeynes@435
   156
    
nkeynes@435
   157
}
nkeynes@435
   158
nkeynes@435
   159
void exit_action_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   160
{
nkeynes@435
   161
    exit(0);
nkeynes@435
   162
}
nkeynes@435
   163
nkeynes@437
   164
void debugger_action_callback( GtkAction *action, gpointer user_data)
nkeynes@437
   165
{
nkeynes@437
   166
    gtk_gui_show_debugger();
nkeynes@437
   167
}
nkeynes@435
   168
nkeynes@447
   169
void path_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@447
   170
{
nkeynes@450
   171
    path_dialog_run();
nkeynes@447
   172
}
nkeynes@447
   173
nkeynes@435
   174
void audio_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   175
{
nkeynes@435
   176
}
nkeynes@435
   177
nkeynes@435
   178
void controller_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   179
{
nkeynes@450
   180
    controller_dialog_run( );
nkeynes@435
   181
}
nkeynes@435
   182
nkeynes@435
   183
void network_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   184
{
nkeynes@435
   185
}
nkeynes@435
   186
nkeynes@435
   187
void video_settings_callback( GtkAction *action, gpointer user_data)
nkeynes@435
   188
{
nkeynes@435
   189
}
nkeynes@435
   190
nkeynes@435
   191
void fullscreen_toggle_callback( GtkToggleAction *action, gpointer user_data)
nkeynes@435
   192
{
nkeynes@435
   193
}
.