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