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 691:ad3356543392
prev678:35eb00945316
next736:a02d1475ccfd
author nkeynes
date Thu Jun 19 04:40:37 2008 +0000 (12 years ago)
permissions -rw-r--r--
last change Refactor the gd-rom list management out of the GUI (devices, recent files, etc).
Add gd-rom list to the cocoa UI.
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 <glib/gi18n.h>
    23 #include "dream.h"
    24 #include "dreamcast.h"
    25 #include "config.h"
    26 #include "gdrom/gdrom.h"
    27 #include "gtkui/gtkui.h"
    29 static gboolean gdrom_menu_adjusting = FALSE;
    31 static void gdrom_menu_open_image_callback( GtkWidget *widget, gpointer user_data )
    32 {
    33     if( !gdrom_menu_adjusting ) {
    34         const gchar *dir = lxdream_get_config_value(CONFIG_DEFAULT_PATH);
    35         open_file_dialog( _("Open..."), gdrom_mount_image, NULL, NULL, dir );
    36     }
    37 }
    39 void gdrom_menu_item_callback( GtkWidget *widget, gpointer user_data )
    40 {
    41     if( !gdrom_menu_adjusting ) {
    42         gdrom_list_set_selection( GPOINTER_TO_INT(user_data) );
    43     }
    44 }
    46 void gdrom_menu_build( GtkWidget *menu ) 
    47 {
    48     unsigned int i, len;
    49     GSList *group = NULL;
    51     len = gdrom_list_size();
    52     for( i=0; i < len; i++ ) {
    53         const gchar *entry = gdrom_list_get_display_name(i);
    54         if( entry[0] == '\0' ) { // Empty string = separator
    55             gtk_menu_shell_append( GTK_MENU_SHELL(menu), gtk_separator_menu_item_new() );
    56         } else {
    57             GtkWidget *item = gtk_radio_menu_item_new_with_label( group, entry );
    58             group = gtk_radio_menu_item_get_group( GTK_RADIO_MENU_ITEM(item) );
    59             g_signal_connect_after( item, "activate", G_CALLBACK(gdrom_menu_item_callback), GINT_TO_POINTER(i) );
    60             gtk_menu_shell_append( GTK_MENU_SHELL(menu), item );
    61         }
    62     }
    64     gtk_menu_shell_append( GTK_MENU_SHELL(menu), gtk_separator_menu_item_new() );
    65     GtkWidget *open = gtk_image_menu_item_new_with_label( _("Open image file...") );
    66     g_signal_connect_after( open, "activate", G_CALLBACK(gdrom_menu_open_image_callback), NULL );
    67     gtk_menu_shell_append( GTK_MENU_SHELL(menu), open );
    68     gtk_widget_show_all(menu);
    69 }
    71 void gdrom_menu_rebuild( GtkWidget *menu )
    72 {
    73     GList *children = gtk_container_get_children( GTK_CONTAINER(menu) );
    74     GList *listptr;
    75     for( listptr = children; listptr != NULL; listptr = g_list_next(listptr) ) {
    76         gtk_widget_destroy( GTK_WIDGET(listptr->data) );
    77     }
    78     g_list_free(children);
    79     gdrom_menu_build(menu);
    80 }
    82 gboolean gdrom_menu_update( gboolean list_changed, int selection, void *user_data )
    83 {
    84     gdrom_menu_adjusting = TRUE;
    85     GtkWidget *menu = GTK_WIDGET(user_data);
    87     if( list_changed ) {
    88         gdrom_menu_rebuild(menu);
    89     }
    91     GList *children = gtk_container_get_children( GTK_CONTAINER(menu) );
    92     GList *item = g_list_nth( children, selection );
    93     assert( item != NULL );
    94     gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM(item->data), TRUE );
    95     g_list_free(children);
    97     gdrom_menu_adjusting = FALSE;
    98     return TRUE;
    99 }
   101 GtkWidget *gdrom_menu_new()
   102 {
   103     GtkWidget *menu = gtk_menu_new();
   104     gtk_menu_set_title( GTK_MENU(menu), _("GD-Rom Settings") );
   106     gdrom_menu_build(menu);
   107     register_gdrom_list_change_hook(gdrom_menu_update, menu);
   108     gdrom_menu_update( FALSE, gdrom_list_get_selection(), menu );
   109     gtk_widget_show_all(menu);
   111     return menu;
   112 }
.