static void parse_option(install_info *info, const char *component, xmlNodePtr node, OptionsBox *box, int level, OptionsButton *parent, int exclusive, RadioGroup **radio) { xmlNodePtr child; char text[1024] = ""; const char *help; const char *wanted; char *name; int i; OptionsButton *button = NULL; /* See if this node matches the current architecture */ wanted = xmlGetProp(node, "arch"); if ( ! match_arch(info, wanted) ) { return; } wanted = xmlGetProp(node, "libc"); if ( ! match_libc(info, wanted) ) { return; } wanted = xmlGetProp(node, "distro"); if ( ! match_distro(info, wanted) ) { return; } if ( ! get_option_displayed(info, node) ) { return; } /* See if the user wants this option */ if ( node->type == XML_TEXT_NODE ) { //name = g_strdup(node->content); name = strdup(node->content); //!!!TODO - Strip name //g_strstrip(name); if( *name ) { //button = gtk_label_new(name); //gtk_widget_show(button); //gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(button), FALSE, FALSE, 0); button = carbon_OptionsNewLabel(box, name); } //!!!TODO - Free name //g_free(name); return; } else { name = get_option_name(info, node, NULL, 0); for(i=0; i < (level*5); i++) text[i] = ' '; text[i] = '\0'; strncat(text, name, sizeof(text)-strlen(text)); } if ( GetProductIsMeta(info) ) { //button = gtk_radio_button_new_with_label(radio_list, text); //radio_list = gtk_radio_button_group(GTK_RADIO_BUTTON(button)); button = carbon_OptionsNewRadioButton(box, text, &radio_list); } else if ( exclusive ) { //button = gtk_radio_button_new_with_label(*radio, text); //*radio = gtk_radio_button_group(GTK_RADIO_BUTTON(button)); button = carbon_OptionsNewRadioButton(box, text, radio); } else { //button = gtk_check_button_new_with_label(text); button = carbon_OptionsNewCheckButton(box, text); } /* Add tooltip help, if available */ help = get_option_help(info, node); if ( help ) { //GtkTooltipsData* group; //group = gtk_tooltips_data_get(window); //if ( group ) { //gtk_tooltips_set_tip( group->tooltips, button, help, 0); //} else { //gtk_tooltips_set_tip( gtk_tooltips_new(), button, help, 0); //} carbon_OptionsSetTooltip(button, help); } /* Set the data associated with the button */ if ( button ) { //gtk_object_set_data(GTK_OBJECT(button), "data", (gpointer)node); button->Data = (void *)node; /* Register the button in the window's private data */ //window = glade_xml_get_widget(setup_glade, "setup_window"); //gtk_object_set_data(GTK_OBJECT(window), name, (gpointer)button); if(strlen(name) >= MAX_BUTTON_NAME) carbon_debug("parse_option() - Button name exceeeded length! This will cause problems with selecting options!\n"); else strcpy(button->Name, name); } /* Check for required option */ if ( xmlGetProp(node, "required") ) { xmlSetProp(node, "install", "true"); //gtk_widget_set_sensitive(GTK_WIDGET(button), FALSE); DisableControl(button->Control); } /* If this is a sub-option and parent is not active, then disable option */ wanted = xmlGetProp(node, "install"); //if( level>0 && GTK_IS_TOGGLE_BUTTON(parent) && !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(parent)) ) { if( level>0 && parent->Type == ButtonType_Radio && !carbon_OptionsGetValue(parent)) { wanted = "false"; //gtk_widget_set_sensitive(GTK_WIDGET(button), FALSE); DisableControl(button->Control); } //***This functionality is implemented automatically when creating no option*** // buttons and labels //if ( button ) { // gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(button), FALSE, FALSE, 0); // gtk_signal_connect(GTK_OBJECT(button), "toggled", // GTK_SIGNAL_FUNC(setup_checkbox_option_slot), (gpointer)node); // gtk_widget_show(button); //} if ( wanted && (strcmp(wanted, "true") == 0) ) { //gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); carbon_OptionsSetValue(button, true); } else { /* Unmark this option for installation */ mark_option(info, node, "false", 1); } /* Recurse down any other options */ child = node->childs; while ( child ) { if ( !strcmp(child->name, "option") ) { //parse_option(info, component, child, window, box, level+1, button, 0, NULL); parse_option(info, component, child, box, level+1, button, 0, NULL); } else if ( !strcmp(child->name, "exclusive") ) { xmlNodePtr exchild; //GSList *list = NULL; RadioGroup *list = NULL; for ( exchild = child->childs; exchild; exchild = exchild->next) { //parse_option(info, component, exchild, window, box, level+1, button, 1, &list); parse_option(info, component, exchild, box, level+1, button, 1, &list); } } child = child->next; } /* Disable any options that are already installed */ if ( info->product && ! GetProductReinstall(info) ) { product_component_t *comp; if ( component ) { comp = loki_find_component(info->product, component); } else { comp = loki_getdefault_component(info->product); } if ( comp && loki_find_option(comp, name) ) { /* Unmark this option for installation */ //gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), FALSE); //gtk_widget_set_sensitive(button, FALSE); carbon_OptionsSetValue(button, FALSE); DisableControl(button->Control); mark_option(info, node, "false", 1); } } }
/* Run a GUI to select and uninstall products */ int uninstall_ui(int argc, char *argv[]) { GtkWidget *window; GtkWidget *widget; GtkWidget *frame; GtkWidget *vbox; GtkWidget *button; GtkWidget *label; const char *product_name; product_t *product; product_info_t *product_info; product_component_t *component; component_list *component_list, *addon_list; char text[1024]; #ifdef ENABLE_GTK2 // Turn off any themes setenv("GTK2_RC_FILES", "", 1); setenv("GTK_DATA_PREFIX", "", 1); #endif gtk_init(&argc,&argv); /* Disable GLib warnings that may be triggered by libglade */ g_log_set_handler ("libglade", G_LOG_LEVEL_WARNING | G_LOG_FLAG_RECURSION, log_handler, NULL); /* Initialize Glade */ glade_init(); uninstall_glade = GLADE_XML_NEW(DATADIR "/" UNINSTALL_GLADE, "loki_uninstall"); /* Add all signal handlers defined in glade file */ glade_xml_signal_autoconnect(uninstall_glade); /* Make sure the window is visible */ widget = glade_xml_get_widget(uninstall_glade, "uninstall_button"); if ( widget ) { gtk_button_set_sensitive(widget, FALSE); } window = glade_xml_get_widget(uninstall_glade, "loki_uninstall"); gtk_widget_realize(window); while( gtk_events_pending() ) { gtk_main_iteration(); } /* Add emergency signal handlers */ signal(SIGHUP, main_signal_abort); signal(SIGINT, main_signal_abort); signal(SIGQUIT, main_signal_abort); signal(SIGTERM, main_signal_abort); /* Fill in the list of products and components */ widget = glade_xml_get_widget(uninstall_glade, "uninstall_vbox"); if ( ! widget ) { fprintf(stderr, _("No uninstall_vbox in glade file!\n")); return(-1); } gtk_container_foreach(GTK_CONTAINER(widget), empty_container, widget); for ( product_name=loki_getfirstproduct(); product_name; product_name=loki_getnextproduct() ) { /* See if we can open the product */ product = loki_openproduct(product_name); if ( ! product ) { continue; } /* See if we have permissions to remove the product */ product_info = loki_getinfo_product(product); if ( ! check_permissions(product_info, 0) ) { loki_closeproduct(product); continue; } /* Add the product and components to our list */ strncpy(text, product_info->description, sizeof(text)); frame = gtk_frame_new(text); gtk_container_set_border_width(GTK_CONTAINER(frame), 4); gtk_box_pack_start(GTK_BOX(widget), frame, FALSE, TRUE, 0); gtk_widget_show(frame); vbox = gtk_vbox_new(FALSE, 0); gtk_container_add (GTK_CONTAINER (frame), vbox); gtk_widget_show(vbox); component = loki_getdefault_component(product); component_list = NULL; if ( component ) { component_list = create_component_list(product, product_info, component); strncpy(text, _("Complete uninstall"), sizeof(text)); button = gtk_check_button_new_with_label(text); gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0); gtk_signal_connect(GTK_OBJECT(button), "toggled", GTK_SIGNAL_FUNC(component_toggled_slot), (gpointer)component_list); gtk_object_set_data(GTK_OBJECT(button), "data", (gpointer)component_list); gtk_widget_show(button); } for ( component = loki_getfirst_component(product); component; component = loki_getnext_component(component) ) { if ( loki_isdefault_component(component) ) { continue; } addon_list = create_component_list(product, product_info, component); strncpy(text, loki_getname_component(component), sizeof(text)); button = gtk_check_button_new_with_label(text); gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0); gtk_signal_connect(GTK_OBJECT(button), "toggled", GTK_SIGNAL_FUNC(component_toggled_slot), (gpointer)addon_list); gtk_object_set_data(GTK_OBJECT(button), "data", (gpointer)addon_list); gtk_widget_show(button); add_component_list(component_list, button); } /* Add this product to our list of open products */ add_product(product); } /* Check to make sure there's something to uninstall */ if ( ! product_list ) { label = gtk_label_new( _("No products were installed by this user.\n" "You may need to run this tool as an administrator.")); gtk_box_pack_start(GTK_BOX(widget), label, FALSE, TRUE, 0); gtk_widget_show(label); } /* Run the UI.. */ gtk_main(); /* Close all the products and return */ close_products(0); return 0; }