Search
lxdream.org :: lxdream/src/gtkui/gtk_gd.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gtkui/gtk_gd.c
changeset 1065:bc1cc0c54917
prev561:533f6b478071
prev1036:af7b0c5905dd
next1109:700c5ab26a63
author nkeynes
date Sun Jan 31 18:36:06 2010 +1000 (14 years ago)
permissions -rw-r--r--
last change Show '<no disc>' in the title bar when there is no cdrom disc attached
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/gtkui/gtk_gd.c Sun Jan 31 18:36:06 2010 +1000
1.3 @@ -0,0 +1,110 @@
1.4 +/**
1.5 + * $Id$
1.6 + *
1.7 + * Creates and manages the GD-Rom attachment menu.
1.8 + *
1.9 + * Copyright (c) 2005 Nathan Keynes.
1.10 + *
1.11 + * This program is free software; you can redistribute it and/or modify
1.12 + * it under the terms of the GNU General Public License as published by
1.13 + * the Free Software Foundation; either version 2 of the License, or
1.14 + * (at your option) any later version.
1.15 + *
1.16 + * This program is distributed in the hope that it will be useful,
1.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.19 + * GNU General Public License for more details.
1.20 + */
1.21 +
1.22 +#include <assert.h>
1.23 +#include <libgen.h>
1.24 +#include "dream.h"
1.25 +#include "dreamcast.h"
1.26 +#include "config.h"
1.27 +#include "gdlist.h"
1.28 +#include "gdrom/gdrom.h"
1.29 +#include "gtkui/gtkui.h"
1.30 +
1.31 +static gboolean gdrom_menu_adjusting = FALSE;
1.32 +
1.33 +static void gdrom_menu_open_image_callback( GtkWidget *widget, gpointer user_data )
1.34 +{
1.35 + if( !gdrom_menu_adjusting ) {
1.36 + open_file_dialog_cb( _("Open..."), gdrom_mount_image, NULL, NULL, CONFIG_DEFAULT_PATH );
1.37 + }
1.38 +}
1.39 +
1.40 +void gdrom_menu_item_callback( GtkWidget *widget, gpointer user_data )
1.41 +{
1.42 + if( !gdrom_menu_adjusting ) {
1.43 + gdrom_list_set_selection( GPOINTER_TO_INT(user_data) );
1.44 + }
1.45 +}
1.46 +
1.47 +void gdrom_menu_build( GtkWidget *menu )
1.48 +{
1.49 + unsigned int i, len;
1.50 + GSList *group = NULL;
1.51 +
1.52 + len = gdrom_list_size();
1.53 + for( i=0; i < len; i++ ) {
1.54 + const gchar *entry = gdrom_list_get_display_name(i);
1.55 + if( entry[0] == '\0' ) { // Empty string = separator
1.56 + gtk_menu_shell_append( GTK_MENU_SHELL(menu), gtk_separator_menu_item_new() );
1.57 + } else {
1.58 + GtkWidget *item = gtk_radio_menu_item_new_with_label( group, entry );
1.59 + group = gtk_radio_menu_item_get_group( GTK_RADIO_MENU_ITEM(item) );
1.60 + g_signal_connect_after( item, "activate", G_CALLBACK(gdrom_menu_item_callback), GINT_TO_POINTER(i) );
1.61 + gtk_menu_shell_append( GTK_MENU_SHELL(menu), item );
1.62 + }
1.63 + }
1.64 +
1.65 + gtk_menu_shell_append( GTK_MENU_SHELL(menu), gtk_separator_menu_item_new() );
1.66 + GtkWidget *open = gtk_image_menu_item_new_with_label( _("Open image file...") );
1.67 + g_signal_connect_after( open, "activate", G_CALLBACK(gdrom_menu_open_image_callback), NULL );
1.68 + gtk_menu_shell_append( GTK_MENU_SHELL(menu), open );
1.69 + gtk_widget_show_all(menu);
1.70 +}
1.71 +
1.72 +void gdrom_menu_rebuild( GtkWidget *menu )
1.73 +{
1.74 + GList *children = gtk_container_get_children( GTK_CONTAINER(menu) );
1.75 + GList *listptr;
1.76 + for( listptr = children; listptr != NULL; listptr = g_list_next(listptr) ) {
1.77 + gtk_widget_destroy( GTK_WIDGET(listptr->data) );
1.78 + }
1.79 + g_list_free(children);
1.80 + gdrom_menu_build(menu);
1.81 +}
1.82 +
1.83 +gboolean gdrom_menu_update( gboolean list_changed, int selection, void *user_data )
1.84 +{
1.85 + gdrom_menu_adjusting = TRUE;
1.86 + GtkWidget *menu = GTK_WIDGET(user_data);
1.87 +
1.88 + if( list_changed ) {
1.89 + gdrom_menu_rebuild(menu);
1.90 + }
1.91 +
1.92 + GList *children = gtk_container_get_children( GTK_CONTAINER(menu) );
1.93 + GList *item = g_list_nth( children, selection );
1.94 + assert( item != NULL );
1.95 + gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM(item->data), TRUE );
1.96 + g_list_free(children);
1.97 +
1.98 + gdrom_menu_adjusting = FALSE;
1.99 + return TRUE;
1.100 +}
1.101 +
1.102 +GtkWidget *gdrom_menu_new()
1.103 +{
1.104 + GtkWidget *menu = gtk_menu_new();
1.105 + gtk_menu_set_title( GTK_MENU(menu), _("GD-Rom Settings") );
1.106 +
1.107 + gdrom_menu_build(menu);
1.108 + register_gdrom_list_change_hook(gdrom_menu_update, menu);
1.109 + gdrom_menu_update( FALSE, gdrom_list_get_selection(), menu );
1.110 + gtk_widget_show_all(menu);
1.111 +
1.112 + return menu;
1.113 +}
.