Search
lxdream.org :: lxdream/src/gtkui/gdrom_menu.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gtkui/gdrom_menu.c
changeset 761:a6c73d21d670
prev755:ab873907b00e
author nkeynes
date Mon Jul 21 01:05:22 2008 +0000 (13 years ago)
permissions -rw-r--r--
last change Add missing include (fix warning)
view annotate diff log raw
     1 /**
     2  * $Id$
     3  *
     4  * Creates and manages the GD-Rom attachment menu.
     5  *
     6  * Copyright (c) 2005 Nathan Keynes.
     7  *
     8  * This program is free software; you can redistribute it and/or modify
     9  * it under the terms of the GNU General Public License as published by
    10  * the Free Software Foundation; either version 2 of the License, or
    11  * (at your option) any later version.
    12  *
    13  * This program is distributed in the hope that it will be useful,
    14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  * GNU General Public License for more details.
    17  */
    19 #include <assert.h>
    20 #include <libgen.h>
    21 #include "dream.h"
    22 #include "dreamcast.h"
    23 #include "config.h"
    24 #include "gdlist.h"
    25 #include "gdrom/gdrom.h"
    26 #include "gtkui/gtkui.h"
    28 static gboolean gdrom_menu_adjusting = FALSE;
    30 static void gdrom_menu_open_image_callback( GtkWidget *widget, gpointer user_data )
    31 {
    32     if( !gdrom_menu_adjusting ) {
    33         const gchar *dir = lxdream_get_config_value(CONFIG_DEFAULT_PATH);
    34         open_file_dialog( _("Open..."), gdrom_mount_image, NULL, NULL, dir );
    35     }
    36 }
    38 void gdrom_menu_item_callback( GtkWidget *widget, gpointer user_data )
    39 {
    40     if( !gdrom_menu_adjusting ) {
    41         gdrom_list_set_selection( GPOINTER_TO_INT(user_data) );
    42     }
    43 }
    45 void gdrom_menu_build( GtkWidget *menu ) 
    46 {
    47     unsigned int i, len;
    48     GSList *group = NULL;
    50     len = gdrom_list_size();
    51     for( i=0; i < len; i++ ) {
    52         const gchar *entry = gdrom_list_get_display_name(i);
    53         if( entry[0] == '\0' ) { // Empty string = separator
    54             gtk_menu_shell_append( GTK_MENU_SHELL(menu), gtk_separator_menu_item_new() );
    55         } else {
    56             GtkWidget *item = gtk_radio_menu_item_new_with_label( group, entry );
    57             group = gtk_radio_menu_item_get_group( GTK_RADIO_MENU_ITEM(item) );
    58             g_signal_connect_after( item, "activate", G_CALLBACK(gdrom_menu_item_callback), GINT_TO_POINTER(i) );
    59             gtk_menu_shell_append( GTK_MENU_SHELL(menu), item );
    60         }
    61     }
    63     gtk_menu_shell_append( GTK_MENU_SHELL(menu), gtk_separator_menu_item_new() );
    64     GtkWidget *open = gtk_image_menu_item_new_with_label( _("Open image file...") );
    65     g_signal_connect_after( open, "activate", G_CALLBACK(gdrom_menu_open_image_callback), NULL );
    66     gtk_menu_shell_append( GTK_MENU_SHELL(menu), open );
    67     gtk_widget_show_all(menu);
    68 }
    70 void gdrom_menu_rebuild( GtkWidget *menu )
    71 {
    72     GList *children = gtk_container_get_children( GTK_CONTAINER(menu) );
    73     GList *listptr;
    74     for( listptr = children; listptr != NULL; listptr = g_list_next(listptr) ) {
    75         gtk_widget_destroy( GTK_WIDGET(listptr->data) );
    76     }
    77     g_list_free(children);
    78     gdrom_menu_build(menu);
    79 }
    81 gboolean gdrom_menu_update( gboolean list_changed, int selection, void *user_data )
    82 {
    83     gdrom_menu_adjusting = TRUE;
    84     GtkWidget *menu = GTK_WIDGET(user_data);
    86     if( list_changed ) {
    87         gdrom_menu_rebuild(menu);
    88     }
    90     GList *children = gtk_container_get_children( GTK_CONTAINER(menu) );
    91     GList *item = g_list_nth( children, selection );
    92     assert( item != NULL );
    93     gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM(item->data), TRUE );
    94     g_list_free(children);
    96     gdrom_menu_adjusting = FALSE;
    97     return TRUE;
    98 }
   100 GtkWidget *gdrom_menu_new()
   101 {
   102     GtkWidget *menu = gtk_menu_new();
   103     gtk_menu_set_title( GTK_MENU(menu), _("GD-Rom Settings") );
   105     gdrom_menu_build(menu);
   106     register_gdrom_list_change_hook(gdrom_menu_update, menu);
   107     gdrom_menu_update( FALSE, gdrom_list_get_selection(), menu );
   108     gtk_widget_show_all(menu);
   110     return menu;
   111 }
.