filename | src/gtkui/gtk_gd.c |
changeset | 763:b3ce4448f200 |
prev | 761:a6c73d21d670 |
next | 1034:7044e01148f0 |
author | nkeynes |
date | Wed Feb 25 09:00:05 2009 +0000 (15 years ago) |
permissions | -rw-r--r-- |
last change | Argh. Apparently we still do really need _BSD_SOURCE and _GNU_SOURCE I think that's everything now... |
file | annotate | diff | log | raw |
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +00001.2 +++ b/src/gtkui/gtk_gd.c Wed Feb 25 09:00:05 2009 +00001.3 @@ -0,0 +1,111 @@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 modify1.12 + * it under the terms of the GNU General Public License as published by1.13 + * the Free Software Foundation; either version 2 of the License, or1.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 of1.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1.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 + const gchar *dir = lxdream_get_config_value(CONFIG_DEFAULT_PATH);1.37 + open_file_dialog( _("Open..."), gdrom_mount_image, NULL, NULL, dir );1.38 + }1.39 +}1.40 +1.41 +void gdrom_menu_item_callback( GtkWidget *widget, gpointer user_data )1.42 +{1.43 + if( !gdrom_menu_adjusting ) {1.44 + gdrom_list_set_selection( GPOINTER_TO_INT(user_data) );1.45 + }1.46 +}1.47 +1.48 +void gdrom_menu_build( GtkWidget *menu )1.49 +{1.50 + unsigned int i, len;1.51 + GSList *group = NULL;1.52 +1.53 + len = gdrom_list_size();1.54 + for( i=0; i < len; i++ ) {1.55 + const gchar *entry = gdrom_list_get_display_name(i);1.56 + if( entry[0] == '\0' ) { // Empty string = separator1.57 + gtk_menu_shell_append( GTK_MENU_SHELL(menu), gtk_separator_menu_item_new() );1.58 + } else {1.59 + GtkWidget *item = gtk_radio_menu_item_new_with_label( group, entry );1.60 + group = gtk_radio_menu_item_get_group( GTK_RADIO_MENU_ITEM(item) );1.61 + g_signal_connect_after( item, "activate", G_CALLBACK(gdrom_menu_item_callback), GINT_TO_POINTER(i) );1.62 + gtk_menu_shell_append( GTK_MENU_SHELL(menu), item );1.63 + }1.64 + }1.65 +1.66 + gtk_menu_shell_append( GTK_MENU_SHELL(menu), gtk_separator_menu_item_new() );1.67 + GtkWidget *open = gtk_image_menu_item_new_with_label( _("Open image file...") );1.68 + g_signal_connect_after( open, "activate", G_CALLBACK(gdrom_menu_open_image_callback), NULL );1.69 + gtk_menu_shell_append( GTK_MENU_SHELL(menu), open );1.70 + gtk_widget_show_all(menu);1.71 +}1.72 +1.73 +void gdrom_menu_rebuild( GtkWidget *menu )1.74 +{1.75 + GList *children = gtk_container_get_children( GTK_CONTAINER(menu) );1.76 + GList *listptr;1.77 + for( listptr = children; listptr != NULL; listptr = g_list_next(listptr) ) {1.78 + gtk_widget_destroy( GTK_WIDGET(listptr->data) );1.79 + }1.80 + g_list_free(children);1.81 + gdrom_menu_build(menu);1.82 +}1.83 +1.84 +gboolean gdrom_menu_update( gboolean list_changed, int selection, void *user_data )1.85 +{1.86 + gdrom_menu_adjusting = TRUE;1.87 + GtkWidget *menu = GTK_WIDGET(user_data);1.88 +1.89 + if( list_changed ) {1.90 + gdrom_menu_rebuild(menu);1.91 + }1.92 +1.93 + GList *children = gtk_container_get_children( GTK_CONTAINER(menu) );1.94 + GList *item = g_list_nth( children, selection );1.95 + assert( item != NULL );1.96 + gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM(item->data), TRUE );1.97 + g_list_free(children);1.98 +1.99 + gdrom_menu_adjusting = FALSE;1.100 + return TRUE;1.101 +}1.102 +1.103 +GtkWidget *gdrom_menu_new()1.104 +{1.105 + GtkWidget *menu = gtk_menu_new();1.106 + gtk_menu_set_title( GTK_MENU(menu), _("GD-Rom Settings") );1.107 +1.108 + gdrom_menu_build(menu);1.109 + register_gdrom_list_change_hook(gdrom_menu_update, menu);1.110 + gdrom_menu_update( FALSE, gdrom_list_get_selection(), menu );1.111 + gtk_widget_show_all(menu);1.112 +1.113 + return menu;1.114 +}
.