?? wizard.c
字號:
label = gtk_label_new (_("Highest IP address to assign:")); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_table_attach (GTK_TABLE (table3), label, 0, 1, 3, 4, GTK_FILL, GTK_FILL, GNOME_PAD, 0); dhcp_highest_ip = gtk_entry_new (); gtk_entry_set_text (GTK_ENTRY (dhcp_highest_ip), preferences_get_string (PREFS_FW_DHCP_HIGHEST_IP)); gtk_table_attach (GTK_TABLE (table3), dhcp_highest_ip, 1, 2, 3, 4, GTK_FILL, GTK_FILL, GNOME_PAD, 0); label = gtk_label_new (_("Name server:")); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_table_attach (GTK_TABLE (table3), label, 0, 1, 4, 5, GTK_FILL, GTK_FILL, GNOME_PAD, 0); dhcp_nameserver = gtk_entry_new (); gtk_entry_set_text (GTK_ENTRY (dhcp_nameserver), preferences_get_string (PREFS_FW_DHCP_NAMESERVER)); gtk_table_attach (GTK_TABLE (table3), dhcp_nameserver, 1, 2, 4, 5, GTK_FILL, GTK_FILL, GNOME_PAD, 0); /* Bind controls we need later to wizard struct */ data->dhcp_server = dhcp_server; data->dhcp_new_config = dhcp_new_config; data->dhcp_lowest_ip = dhcp_lowest_ip; data->dhcp_highest_ip = dhcp_highest_ip; data->dhcp_nameserver = dhcp_nameserver; return table;}/* [ create_welcome_page ] * Create the contents of the welcoming screen */static GtkWidget*create_welcome_page (Wizard *data){ GtkWidget *label; GtkWidget *image; GtkWidget *hbox; GtkWidget *vbox; GdkPixbuf *pixbuf; hbox = gtk_hbox_new (FALSE, GNOME_PAD_BIG); pixbuf = gdk_pixbuf_new_from_inline (-1, pengo, FALSE, NULL); image = gtk_image_new_from_pixbuf (pixbuf); g_object_unref (G_OBJECT(pixbuf)); gtk_box_pack_start (GTK_BOX(hbox), image, FALSE, FALSE, 0); vbox = gtk_vbox_new (FALSE, GNOME_PAD_SMALL); gtk_box_pack_start (GTK_BOX(hbox), vbox, FALSE, FALSE, 0); label = gtk_label_new (NULL); gtk_label_set_markup (GTK_LABEL (label), g_strconcat (_( "This wizard will help you to set up a firewall for your\n" "Linux machine. You will be asked some questions\n" "about your network setup in order to customize the\n" "firewall for your system.\n\n"), "<small>", _( "Tip: If you are uncertain of how to answer a question it is\n" "best to use the default value supplied.\n\n" ), "</small>", _("Please press the forward button to continue.\n"), NULL) ); gtk_box_pack_start (GTK_BOX(vbox), label, FALSE, FALSE, 0); return hbox;}/* [ create_finish_page ] * Create the contents of the final wizard screen */static GtkWidget*create_finish_page (Wizard *data){ FirewallStatus state; GtkWidget *label; GtkWidget *vbox; GtkWidget *check_start_now; vbox = gtk_vbox_new (FALSE, GNOME_PAD_SMALL); label = gtk_label_new (NULL); gtk_label_set_markup (GTK_LABEL (label), g_strconcat ( "<b>", _("The wizard is now ready to start your firewall."), "</b>", "\n\n", _("Press the save button to continue, or the back button to review your choices."), NULL) ); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0); gtk_box_pack_start (GTK_BOX(vbox), label, FALSE, FALSE, GNOME_PAD_SMALL); check_start_now = gtk_check_button_new_with_label (_("Start firewall now")); gtk_box_pack_start (GTK_BOX(vbox), check_start_now, FALSE, FALSE, GNOME_PAD_SMALL); label = gtk_label_new (NULL); gtk_label_set_markup (GTK_LABEL (label), g_strconcat ( "<small>", _( "Tip: If you are connecting to the firewall host remotely you might want to\n" "defer starting the firewall until you have created additional policy."), "</small>", NULL) ); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0); gtk_box_pack_start (GTK_BOX(vbox), label, FALSE, FALSE, GNOME_PAD_SMALL); state = status_get_state (); /* Default to starting firewall on the first run, or if the firewall was already started */ if (preferences_get_bool (PREFS_FIRST_RUN) || !script_exists () || state == STATUS_RUNNING || state == STATUS_HIT) { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_start_now), TRUE); } data->start_firewall = check_start_now; return vbox;}/* [ create_page ] * Create the default wizard page layout container */static GtkWidget *create_page (const char *title){ GtkWidget *label; GtkWidget *vbox; GtkWidget *hbox; GtkWidget *alignment; GtkWidget *image; GdkPixbuf *pixbuf; gchar *title_string; /* create vbox */ vbox = gtk_vbox_new (FALSE, GNOME_PAD); /* create the titlebar */ hbox = gtk_hbox_new (FALSE, GNOME_PAD_BIG); pixbuf = gdk_pixbuf_new_from_inline (-1, logo, FALSE, NULL); image = gtk_image_new_from_pixbuf (pixbuf); g_object_unref (G_OBJECT(pixbuf)); gtk_box_pack_start (GTK_BOX(hbox), image, FALSE, FALSE, 0); alignment = gtk_alignment_new (1.0, 1.0, 1.0, 1.0); gtk_box_pack_start (GTK_BOX(hbox), alignment, TRUE, TRUE, 0); title_string = g_strconcat ("<span size=\"xx-large\" weight=\"ultrabold\">", title ? title : "", "</span>", NULL); label = gtk_label_new (title_string); gtk_label_set_use_markup (GTK_LABEL(label), TRUE); g_free (title_string); gtk_container_add (GTK_CONTAINER(alignment), label); //gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0); /* pack the titlebar */ gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0); /* pack the separator */ gtk_box_pack_start (GTK_BOX(vbox), gtk_hseparator_new(), FALSE, FALSE, 0); return vbox;}/* [ dialog_response_cb ] * Controls what happens when one of the wizard buttons are pressed * Possible page flow control code would go here */static voiddialog_response_cb (GtkDialog *dialog, int response, gpointer data){ Wizard *wizard = (Wizard *)data; int current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK(wizard->notebook)); if (response == RESPONSE_QUIT) { if (preferences_get_bool (PREFS_FIRST_RUN) || !script_exists ()) exit_firestarter (); g_free (wizard); gtk_widget_destroy (GTK_WIDGET(dialog)); } else if (response == RESPONSE_GO_FORWARD && current_page == WIZARD_NAT_PAGE) { /* Validate the choices made on the NAT page */ gboolean validates = TRUE; if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (wizard->masq)) && g_str_equal (wizard->extdevice, wizard->intdevice)) { gchar *message; message = g_strconcat ("<span weight=\"bold\" size=\"larger\">", _("Please review your choices"), "\n\n</span>", _("The local area and the Internet connected devices can not be the same."), NULL); show_error (message); g_free (message); validates = FALSE; } else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (wizard->dhcp_server)) && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (wizard->dhcp_new_config))) { const gchar *nameserver = gtk_entry_get_text (GTK_ENTRY (wizard->dhcp_nameserver)); validates = (is_a_valid_host (gtk_entry_get_text (GTK_ENTRY (wizard->dhcp_highest_ip))) && is_a_valid_host (gtk_entry_get_text (GTK_ENTRY (wizard->dhcp_lowest_ip))) && (is_a_valid_host (nameserver) || g_ascii_strcasecmp (nameserver, "<dynamic>") == 0)); if (!validates) { gchar *message; message = g_strconcat ("<span weight=\"bold\" size=\"larger\">", _("Please review your choices"), "\n\n</span>", _("The supplied DHCP configuration is not valid."), NULL); show_error (message); g_free (message); } } if (validates) { gtk_notebook_set_current_page (GTK_NOTEBOOK(wizard->notebook), ++current_page); gtk_dialog_set_response_sensitive (dialog, RESPONSE_GO_FORWARD, current_page < WIZARD_FINISHED_PAGE); gtk_dialog_set_response_sensitive (dialog, RESPONSE_FINISHED, current_page == WIZARD_FINISHED_PAGE); } } else if (response == RESPONSE_FINISHED) { save_choices (wizard); scriptwriter_output_scripts (); /* Write DHCP configuration */ if (preferences_get_bool (PREFS_FW_NAT) && preferences_get_bool (PREFS_FW_DHCP_ENABLE) && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (wizard->dhcp_new_config))) dhcp_server_create_configuration (); if (preferences_get_bool (PREFS_FIRST_RUN)) { /* Mark that the wizard has been run at least once */ preferences_set_bool (PREFS_FIRST_RUN, FALSE); } /* Finally, start the firewall */ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (wizard->start_firewall))) start_firewall (); g_free (wizard); gtk_widget_destroy (GTK_WIDGET(dialog)); /* Show the main interface */ gui_set_visibility (TRUE); } else { if (response == RESPONSE_GO_BACK) { gtk_notebook_set_current_page (GTK_NOTEBOOK(wizard->notebook), --current_page); } else if (response == RESPONSE_GO_FORWARD) { gtk_notebook_set_current_page (GTK_NOTEBOOK(wizard->notebook), ++current_page); } gtk_dialog_set_response_sensitive (dialog, RESPONSE_GO_BACK, current_page > 0); gtk_dialog_set_response_sensitive (dialog, RESPONSE_GO_FORWARD, current_page < WIZARD_FINISHED_PAGE); gtk_dialog_set_response_sensitive (dialog, RESPONSE_FINISHED, current_page == WIZARD_FINISHED_PAGE); }}/* [ run_wizard ] * Run the firewall wizard */voidrun_wizard (void){ Wizard *wizard; GtkWidget *dialog; GtkWidget *notebook; GtkWidget *page; GtkWidget *alignment; gint i; wizard = g_new (Wizard, 1); dialog = gtk_dialog_new_with_buttons (_("Firewall Wizard"), NULL, 0, GTK_STOCK_GO_BACK, RESPONSE_GO_BACK, GTK_STOCK_GO_FORWARD, RESPONSE_GO_FORWARD, GTK_STOCK_SAVE, RESPONSE_FINISHED, GTK_STOCK_QUIT, RESPONSE_QUIT, NULL); g_signal_connect (dialog, "response", G_CALLBACK(dialog_response_cb), wizard); gtk_dialog_set_default_response (GTK_DIALOG(dialog), RESPONSE_GO_FORWARD); gtk_dialog_set_response_sensitive (GTK_DIALOG(dialog), RESPONSE_GO_BACK, FALSE); gtk_dialog_set_response_sensitive (GTK_DIALOG(dialog), RESPONSE_GO_FORWARD, TRUE); gtk_dialog_set_response_sensitive (GTK_DIALOG(dialog), RESPONSE_FINISHED, FALSE); /* The wizard is a notebook widget without tabs */ notebook = wizard->notebook = gtk_notebook_new (); gtk_notebook_set_show_tabs (GTK_NOTEBOOK(notebook), FALSE); gtk_notebook_set_show_border (GTK_NOTEBOOK(notebook), FALSE); gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), notebook, TRUE, TRUE, 0); /* Create the basic wizard pages */ wizard->pages = g_ptr_array_new (); page = create_page (_("Welcome to Firestarter")); alignment = gtk_alignment_new (0.5, 0.5, 0.5, 0.5); gtk_box_pack_start (GTK_BOX(page), alignment, TRUE, TRUE, 0); gtk_container_add (GTK_CONTAINER(alignment), create_welcome_page (wizard)); g_ptr_array_add (wizard->pages, page); page = create_page (_("Network device setup")); alignment = gtk_alignment_new (0.5, 0.5, 0.5, 0.5); gtk_box_pack_start (GTK_BOX(page), alignment, TRUE, TRUE, 0); gtk_container_add (GTK_CONTAINER(alignment), create_device_page (wizard)); g_ptr_array_add (wizard->pages, page); page = create_page (_("Internet connection sharing setup")); alignment = gtk_alignment_new (0.5, 0.5, 0.5, 0.5); gtk_box_pack_start (GTK_BOX(page), alignment, TRUE, TRUE, 0); gtk_container_add (GTK_CONTAINER(alignment), create_masq_page (wizard)); g_ptr_array_add (wizard->pages, page); /* Final page */ page = create_page (_("Ready to start your firewall")); alignment = gtk_alignment_new (0.5, 0.5, 0.5, 0.5); gtk_box_pack_start (GTK_BOX(page), alignment, TRUE, TRUE, 0); gtk_container_add (GTK_CONTAINER(alignment), create_finish_page (wizard)); g_ptr_array_add (wizard->pages, page); /* Load pages into notebook */ for (i = 0; i < wizard->pages->len; i++) { gtk_notebook_append_page (GTK_NOTEBOOK(notebook), GTK_WIDGET(g_ptr_array_index (wizard->pages,i)), NULL); } /* Set some simple defaults when run for the first time, otherwise load previous choices */ if (!preferences_get_bool (PREFS_FIRST_RUN)) { load_choices (wizard); } gtk_window_set_default_size (GTK_WINDOW (dialog), -1, 350); gtk_widget_show_all (dialog);}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -