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