4343#include "c64cart.h"
4444#include "cartridge.h"
4545#include "log.h"
46+ #include "resources.h"
4647#include "vice_gtk3.h"
4748
4849#include "settings_mmc64.h"
@@ -74,10 +75,44 @@ static const vice_gtk3_radiogroup_entry_t card_types[] = {
7475/** \brief BIOS filename entry */
7576static GtkWidget * bios_filename = NULL ;
7677
78+ /** \brief BIOS "Flush image" button */
79+ static GtkWidget * flush_button = NULL ;
80+
81+ /** \brief BIOS "Save As" button" */
82+ static GtkWidget * save_button = NULL ;
83+
7784/** \brief SD card widget filename entry */
7885static GtkWidget * card_filename = NULL ;
7986
8087
88+ /** \brief Update sensitivity of BIOS flush and save buttons
89+ *
90+ * Set sensitivity of the "Flush" and "Save As" buttons of the BIOS file
91+ * widget, based on the presence of a BIOS image.
92+ * (Assumes the resource "MMC64BIOSfilename" is only set if a valid BIOS file
93+ * is loaded)
94+ */
95+ static void update_buttons_sensitivity (void )
96+ {
97+ const char * bios = NULL ;
98+ gboolean sensitive ;
99+
100+ resources_get_string ("MMC64BIOSfilename" , & bios );
101+ sensitive = (bios != NULL && * bios != '\0' );
102+ gtk_widget_set_sensitive (flush_button , sensitive );
103+ gtk_widget_set_sensitive (save_button , sensitive );
104+ }
105+
106+ /** \brief Custom callback for the BIOS file chooser widget
107+ *
108+ * \param[in] entry file chooser's GtkEntry widget (ignored)
109+ * \param[in] filename filename returned by the file chooser (ignored)
110+ */
111+ static void bios_callback (GtkEntry * entry , gchar * filename )
112+ {
113+ update_buttons_sensitivity ();
114+ }
115+
81116/** \brief Handler for the 'toggled' event of the "MMC64 Enabled" widget
82117 *
83118 * \param[in,out] check check button
@@ -101,6 +136,7 @@ static void on_enable_toggled(GtkWidget *check, gpointer user_data)
101136 vice_gtk3_message_error (GTK_WINDOW (parent ),
102137 CARTNAME " Error" ,
103138 "Cannot enable " CARTNAME " due to missing BIOS file." );
139+ update_buttons_sensitivity ();
104140 return ;
105141 }
106142
@@ -122,6 +158,8 @@ static void on_enable_toggled(GtkWidget *check, gpointer user_data)
122158 "Failed to disable " CARTNAME ", please set BIOS file." );
123159 }
124160 }
161+
162+ update_buttons_sensitivity ();
125163}
126164
127165/** \brief Callback for the save-dialog response handler
@@ -242,9 +280,7 @@ static int create_bios_image_layout(GtkWidget *grid, int row, int columns)
242280{
243281 GtkWidget * label ;
244282 GtkWidget * bios_write ;
245- GtkWidget * box ;
246- GtkWidget * save ;
247- GtkWidget * flush ;
283+ GtkWidget * button_box ;
248284 const char * title ;
249285
250286 /* header */
@@ -264,6 +300,7 @@ static int create_bios_image_layout(GtkWidget *grid, int row, int columns)
264300 GTK_FILE_CHOOSER_ACTION_OPEN );
265301 title = "Select " CARTRIDGE_NAME_MMC64 " BIOS file" ;
266302 vice_gtk3_resource_filechooser_set_custom_title (bios_filename , title );
303+ vice_gtk3_resource_filechooser_set_callback (bios_filename , bios_callback );
267304 gtk_grid_attach (GTK_GRID (grid ), label , 0 , row , 1 , 1 );
268305 gtk_grid_attach (GTK_GRID (grid ), bios_filename , 1 , row , columns - 1 , 1 );
269306 row ++ ;
@@ -272,25 +309,25 @@ static int create_bios_image_layout(GtkWidget *grid, int row, int columns)
272309 bios_write = vice_gtk3_resource_check_button_new ("MMC64_bios_write" ,
273310 "Enable BIOS image writes" );
274311 /* buttons */
275- box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL );
276- flush = gtk_button_new_with_label ("Flush image" );
277- save = gtk_button_new_with_label ("Save image as .." );
312+ button_box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL );
313+ flush_button = gtk_button_new_with_label ("Flush image" );
314+ save_button = gtk_button_new_with_label ("Save image as .." );
278315
279- g_signal_connect (G_OBJECT (flush ),
316+ g_signal_connect (G_OBJECT (flush_button ),
280317 "clicked" ,
281318 G_CALLBACK (on_flush_clicked ),
282319 NULL );
283- g_signal_connect (G_OBJECT (save ),
320+ g_signal_connect (G_OBJECT (save_button ),
284321 "clicked" ,
285322 G_CALLBACK (on_save_clicked ),
286323 NULL );
287324
288- gtk_box_pack_start (GTK_BOX (box ), save , FALSE, FALSE, 0 );
289- gtk_box_pack_start (GTK_BOX (box ), flush , FALSE, FALSE, 0 );
290- gtk_box_set_spacing (GTK_BOX (box ), 8 );
291- gtk_widget_set_halign (box , GTK_ALIGN_END );
292- gtk_grid_attach (GTK_GRID (grid ), bios_write , 1 , row , 1 , 1 );
293- gtk_grid_attach (GTK_GRID (grid ), box , 2 , row , columns - 2 , 1 );
325+ gtk_box_pack_start (GTK_BOX (button_box ), save_button , FALSE, FALSE, 0 );
326+ gtk_box_pack_start (GTK_BOX (button_box ), flush_button , FALSE, FALSE, 0 );
327+ gtk_box_set_spacing (GTK_BOX (button_box ), 8 );
328+ gtk_widget_set_halign (button_box , GTK_ALIGN_END );
329+ gtk_grid_attach (GTK_GRID (grid ), bios_write , 1 , row , 1 , 1 );
330+ gtk_grid_attach (GTK_GRID (grid ), button_box , 2 , row , columns - 2 , 1 );
294331 return row + 1 ;
295332}
296333
@@ -415,6 +452,8 @@ GtkWidget *settings_mmc64_widget_create(GtkWidget *parent)
415452 gtk_grid_attach (GTK_GRID (grid ), revision_widget , 1 , row , 1 , 1 );
416453#undef NUM_COLS
417454
455+ update_buttons_sensitivity ();
456+
418457 gtk_widget_show_all (grid );
419458 return grid ;
420459}
0 commit comments