File: roms.c

package info (click to toggle)
fuse-emulator 1.0.0.1a%2Bdfsg1-4
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 9,568 kB
  • sloc: ansic: 67,895; sh: 10,265; perl: 3,386; makefile: 787; yacc: 227; lex: 139
file content (157 lines) | stat: -rw-r--r-- 4,214 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* roms.c: ROM selector dialog box
   Copyright (c) 2003-2004 Philip Kendall

   $Id: roms.c 3405 2007-12-05 01:18:52Z zubzero $

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License along
   with this program; if not, write to the Free Software Foundation, Inc.,
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

   Author contact information:

   E-mail: philip-fuse@shadowmagic.org.uk

*/

#include <config.h>

#include <stdio.h>
#include <stdlib.h>

#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>

#include "compat.h"
#include "fuse.h"
#include "gtkinternals.h"
#include "menu.h"
#include "settings.h"
#include "ui/ui.h"

static void add_rom( GtkBox *parent, size_t start, gint row );
static void select_new_rom( GtkWidget *widget, gpointer data );
static void roms_done( GtkButton *button, gpointer data );

/* The labels used to display the current ROMs */
GtkWidget *rom[ SETTINGS_ROM_COUNT ];

struct callback_info {

  size_t start, n;

};

int
menu_select_roms_with_title( const char *title, size_t start, size_t n )
{
  GtkWidget *dialog;
  GtkBox *vbox;

  struct callback_info info;

  char buffer[ 256 ];
  size_t i;

  /* Firstly, stop emulation */
  fuse_emulation_pause();

  /* Give me a new dialog box */
  snprintf( buffer, 256, "Fuse - Select ROMs - %s", title );
  dialog = gtkstock_dialog_new( buffer, NULL );

  info.start = start;
  info.n = n;

  /* Create the OK and Cancel buttons */
  gtkstock_create_ok_cancel( dialog, NULL, GTK_SIGNAL_FUNC( roms_done ), &info,
			     NULL );

  /* And the current values of each of the ROMs */
  vbox = GTK_BOX( GTK_DIALOG( dialog )->vbox );

  gtk_container_set_border_width( GTK_CONTAINER( vbox ), 5 );
  for( i = 0; i < n; i++ ) add_rom( vbox, start, i );

  /* Users shouldn't be able to resize this window */
  gtk_window_set_policy( GTK_WINDOW( dialog ), FALSE, FALSE, TRUE );

  /* Display the window */
  gtk_widget_show_all( dialog );

  /* Process events until the window is done with */
  gtk_main();

  /* And then carry on with emulation again */
  fuse_emulation_unpause();

  return 0;
}

static void
add_rom( GtkBox *parent, size_t start, gint row )
{
  GtkWidget *frame, *hbox, *change_button;
  char buffer[ 80 ], **setting;

  snprintf( buffer, 80, "ROM %d", row );
  frame = gtk_frame_new( buffer );
  gtk_box_pack_start( parent, frame, FALSE, FALSE, 2 );

  hbox = gtk_hbox_new( FALSE, 4 );
  gtk_container_set_border_width( GTK_CONTAINER( hbox ), 4 );
  gtk_container_add( GTK_CONTAINER( frame ), hbox );

  setting = settings_get_rom_setting( &settings_current, start + row );
  rom[ row ] = gtk_entry_new();
  gtk_entry_set_text( GTK_ENTRY( rom[ row ] ), *setting );
  gtk_box_pack_start( GTK_BOX( hbox ), rom[ row ], FALSE, FALSE, 2 );

  change_button = gtk_button_new_with_label( "Select..." );
  gtk_signal_connect( GTK_OBJECT( change_button ), "clicked",
		      GTK_SIGNAL_FUNC( select_new_rom ),
		      rom[ row ] );
  gtk_box_pack_start( GTK_BOX( hbox ), change_button, FALSE, FALSE, 2 );
}

static void
select_new_rom( GtkWidget *widget GCC_UNUSED, gpointer data )
{
  char *filename;

  GtkWidget *entry = data;

  filename = ui_get_open_filename( "Fuse - Select ROM" );
  if( !filename ) return;

  gtk_entry_set_text( GTK_ENTRY( entry ), filename );
}

static void
roms_done( GtkButton *button GCC_UNUSED, gpointer data )
{
  size_t i;
  int error;
  
  char **setting; const char *string;

  struct callback_info *info = data;

  for( i = 0; i < info->n; i++ ) {

    setting = settings_get_rom_setting( &settings_current, info->start + i );
    string = gtk_entry_get_text( GTK_ENTRY( rom[i] ) );

    error = settings_set_string( setting, string ); if( error ) return;

  }
}