Search
lxdream.org :: lxdream/src/gui/ctrl_dlg.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/ctrl_dlg.c
changeset 450:207461e79f21
prev447:3e095bfcb476
next455:3080881d00d4
author nkeynes
date Wed Oct 17 11:26:45 2007 +0000 (14 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@447
     1
/**
nkeynes@450
     2
 * $Id: ctrl_dlg.c,v 1.2 2007-10-17 11:26:45 nkeynes Exp $
nkeynes@447
     3
 *
nkeynes@447
     4
 * Define the main (emu) GTK window, along with its menubars,
nkeynes@447
     5
 * toolbars, etc.
nkeynes@447
     6
 *
nkeynes@447
     7
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@447
     8
 *
nkeynes@447
     9
 * This program is free software; you can redistribute it and/or modify
nkeynes@447
    10
 * it under the terms of the GNU General Public License as published by
nkeynes@447
    11
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@447
    12
 * (at your option) any later version.
nkeynes@447
    13
 *
nkeynes@447
    14
 * This program is distributed in the hope that it will be useful,
nkeynes@447
    15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@447
    16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@447
    17
 * GNU General Public License for more details.
nkeynes@447
    18
 */
nkeynes@447
    19
nkeynes@447
    20
#include <assert.h>
nkeynes@447
    21
#include <gtk/gtk.h>
nkeynes@447
    22
nkeynes@447
    23
#include "dream.h"
nkeynes@447
    24
#include "gui/gtkui.h"
nkeynes@447
    25
#include "maple/maple.h"
nkeynes@447
    26
nkeynes@447
    27
#define MAX_DEVICES 4
nkeynes@447
    28
nkeynes@447
    29
typedef struct maple_slot_data {
nkeynes@447
    30
    maple_device_t old_device;
nkeynes@447
    31
    maple_device_t new_device;
nkeynes@447
    32
    GtkWidget *button;
nkeynes@447
    33
    GtkWidget *combo;
nkeynes@447
    34
} *maple_slot_data_t;
nkeynes@447
    35
nkeynes@447
    36
static struct maple_slot_data maple_data[MAX_DEVICES];
nkeynes@447
    37
nkeynes@447
    38
nkeynes@447
    39
gboolean controller_properties_activated( GtkButton *button, gpointer user_data )
nkeynes@447
    40
{
nkeynes@447
    41
    maple_slot_data_t data = (maple_slot_data_t)user_data;
nkeynes@447
    42
}
nkeynes@447
    43
nkeynes@447
    44
gboolean controller_device_changed( GtkComboBox *combo, gpointer user_data )
nkeynes@447
    45
{
nkeynes@447
    46
    maple_slot_data_t data = (maple_slot_data_t)user_data;
nkeynes@447
    47
    int active = gtk_combo_box_get_active(combo);
nkeynes@447
    48
    gtk_widget_set_sensitive(data->button, active != 0);
nkeynes@447
    49
    if( active != 0 ) {
nkeynes@447
    50
	gchar *devname = gtk_combo_box_get_active_text(combo);
nkeynes@447
    51
	const maple_device_class_t devclz = maple_get_device_class(devname);
nkeynes@447
    52
	assert(devclz != NULL);
nkeynes@447
    53
	if( data->new_device != NULL ) {
nkeynes@447
    54
	    if( data->new_device->device_class != devclz ) {
nkeynes@447
    55
		data->new_device->destroy(data->new_device);
nkeynes@447
    56
		data->new_device = maple_new_device(devname);
nkeynes@447
    57
	    }
nkeynes@447
    58
	} else {
nkeynes@447
    59
	    data->new_device = maple_new_device(devname);
nkeynes@447
    60
	}
nkeynes@447
    61
    } else {
nkeynes@447
    62
	if( data->new_device != NULL && data->new_device != data->old_device ) {
nkeynes@447
    63
	    data->new_device->destroy(data->new_device);
nkeynes@447
    64
	}
nkeynes@447
    65
	data->new_device = NULL;
nkeynes@447
    66
    }
nkeynes@447
    67
}
nkeynes@447
    68
nkeynes@447
    69
void controller_commit_changes( )
nkeynes@447
    70
{
nkeynes@447
    71
    int i;
nkeynes@447
    72
    for( i=0; i<MAX_DEVICES; i++ ) {
nkeynes@447
    73
	if( maple_data[i].new_device != maple_data[i].old_device ) {
nkeynes@447
    74
	    if( maple_data[i].old_device != NULL ) {
nkeynes@447
    75
		maple_detach_device(i,0);
nkeynes@447
    76
	    }
nkeynes@447
    77
	    if( maple_data[i].new_device != NULL ) {
nkeynes@447
    78
		maple_attach_device(maple_data[i].new_device, i, 0 );
nkeynes@447
    79
	    }
nkeynes@447
    80
	}
nkeynes@447
    81
    }
nkeynes@450
    82
    lxdream_save_config();
nkeynes@447
    83
}
nkeynes@447
    84
nkeynes@447
    85
void controller_cancel_changes( )
nkeynes@447
    86
{
nkeynes@447
    87
    int i;
nkeynes@447
    88
    for( i=0; i<MAX_DEVICES; i++ ) {
nkeynes@447
    89
	if( maple_data[i].new_device != NULL && 
nkeynes@447
    90
	    maple_data[i].new_device != maple_data[i].old_device ) {
nkeynes@447
    91
	    maple_data[i].new_device->destroy(maple_data[i].new_device);
nkeynes@447
    92
	}
nkeynes@447
    93
    }
nkeynes@447
    94
}
nkeynes@447
    95
nkeynes@450
    96
GtkWidget *controller_panel_new()
nkeynes@447
    97
{
nkeynes@447
    98
    GtkWidget *table = gtk_table_new(4, 3, TRUE);
nkeynes@447
    99
    GtkTreeIter iter;
nkeynes@447
   100
    int i,j;
nkeynes@447
   101
    const struct maple_device_class **devices = maple_get_device_classes();
nkeynes@447
   102
nkeynes@447
   103
    for( i=0; i< MAX_DEVICES; i++ ) {
nkeynes@447
   104
	char buf[12];
nkeynes@447
   105
	GtkWidget *combo, *button;
nkeynes@447
   106
	int active = 0;
nkeynes@447
   107
	maple_device_t device = maple_get_device(i,0);
nkeynes@447
   108
	sprintf( buf, "Slot %d.", i );
nkeynes@447
   109
	gtk_table_attach_defaults( GTK_TABLE(table), gtk_label_new(buf), 0, 1, i, i+1 );
nkeynes@447
   110
	combo = gtk_combo_box_new_text();
nkeynes@447
   111
	gtk_combo_box_append_text( GTK_COMBO_BOX(combo), "<empty>" );
nkeynes@447
   112
	for( j=0; devices[j] != NULL; j++ ) {
nkeynes@447
   113
	    gtk_combo_box_append_text(GTK_COMBO_BOX(combo), devices[j]->name);
nkeynes@447
   114
	    if( device != NULL && device->device_class == devices[j] ) {
nkeynes@447
   115
		active = j+1;
nkeynes@447
   116
	    }
nkeynes@447
   117
	}
nkeynes@447
   118
	gtk_combo_box_set_active(GTK_COMBO_BOX(combo), active);
nkeynes@447
   119
	gtk_table_attach_defaults( GTK_TABLE(table), combo, 1, 2, i, i+1 );
nkeynes@447
   120
	button = gtk_button_new_from_stock( GTK_STOCK_PROPERTIES );
nkeynes@447
   121
	gtk_widget_set_sensitive(button, active != 0);
nkeynes@447
   122
	gtk_table_attach_defaults( GTK_TABLE(table), button, 2, 3, i, i+1 );
nkeynes@447
   123
nkeynes@447
   124
	maple_data[i].old_device = device;
nkeynes@447
   125
	maple_data[i].new_device = device;
nkeynes@447
   126
	maple_data[i].combo = combo;
nkeynes@447
   127
	maple_data[i].button = button;
nkeynes@450
   128
	g_signal_connect( button, "clicked", 
nkeynes@447
   129
			  G_CALLBACK( controller_properties_activated ), &maple_data[i] );
nkeynes@447
   130
	g_signal_connect( combo, "changed", 
nkeynes@447
   131
			  G_CALLBACK( controller_device_changed ), &maple_data[i] );
nkeynes@447
   132
nkeynes@447
   133
    }
nkeynes@447
   134
    return table;
nkeynes@447
   135
}
nkeynes@447
   136
nkeynes@447
   137
void controller_dialog_run( GtkWindow *parent )
nkeynes@447
   138
{
nkeynes@450
   139
    gint result = gtk_gui_run_property_dialog( "Controller Settings", controller_panel_new() );
nkeynes@447
   140
    if( result == GTK_RESPONSE_ACCEPT ) {
nkeynes@447
   141
	controller_commit_changes();
nkeynes@447
   142
    } else {
nkeynes@447
   143
	controller_cancel_changes();
nkeynes@447
   144
    }
nkeynes@447
   145
}
.