From: short <> Date: Sun, 26 Jun 2005 01:58:47 +0000 (+0000) Subject: "Try random port" now also automatically starts the daemon. X-Git-Tag: udpgate-1_0_2~27 X-Git-Url: https://git.jankratochvil.net/?p=udpgate.git;a=commitdiff_plain;h=35bf1dea80e8e3007ad127c1d5c0fc4fc3f80476 "Try random port" now also automatically starts the daemon. Fixed race on shutting down the Gnome UI. Improved startup "inconsistent"/"sensitive" behavior. Implemented crossplatform automatic startup management. --- diff --git a/src/ui-gnome.c b/src/ui-gnome.c index 88ecfe1..595c633 100644 --- a/src/ui-gnome.c +++ b/src/ui-gnome.c @@ -41,7 +41,7 @@ #include "network.h" #include "packet.h" -#include "startup.h" +#include "static-startup.h" /* Config: */ @@ -104,11 +104,18 @@ gboolean state_startup_is_on; if (!App) /* Quitting? */ return FALSE; /* stop running */ - if (startup_query(&state_startup_is_on)) + if (static_startup_query(&state_startup_is_on)) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(AutostartCheckButton),state_startup_is_on); return TRUE; /* continue running */ } +static void buttonstart(void) +{ + if (!optarg_port_set_string(gtk_entry_get_text(PortEntry))) + return; + network_start(optarg_port); +} + void on_PortButtonRandom_clicked(GtkButton *button,gpointer user_data) { g_return_if_fail(GTK_IS_BUTTON(button)); @@ -118,6 +125,7 @@ void on_PortButtonRandom_clicked(GtkButton *button,gpointer user_data) return; gtk_entry_set_text(PortEntry, udpgate_printf_alloca("%d",(int)g_random_int_range(PORT_RANGE_BEGIN,PORT_RANGE_END))); + buttonstart(); } void on_AutostartCheckButton_toggled(GtkToggleButton *togglebutton,gpointer user_data) @@ -135,9 +143,9 @@ static gint inside=0; inside++; if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(AutostartCheckButton))) - startup_on(); + static_startup_on(); else - startup_off(); + static_startup_off(); external_startup_check_timeout_func(NULL); /* data; unused */ g_assert(inside==1); @@ -148,9 +156,7 @@ void on_ButtonStart_clicked(GtkButton *button,gpointer user_data) { g_return_if_fail(GTK_IS_BUTTON(button)); - if (!optarg_port_set_string(gtk_entry_get_text(PortEntry))) - return; - network_start(optarg_port); + buttonstart(); } void on_ButtonStop_clicked(GtkButton *button,gpointer user_data) @@ -162,6 +168,8 @@ void on_ButtonStop_clicked(GtkButton *button,gpointer user_data) void on_ButtonHide_clicked(GtkButton *button,gpointer user_data) { +GnomeApp *App_local; + g_return_if_fail(GTK_IS_BUTTON(button)); /* update config file */ @@ -170,8 +178,13 @@ void on_ButtonHide_clicked(GtkButton *button,gpointer user_data) /* Do not: gtk_main_quit(); * as 'App' widget will quit our gtk_main() automatically. */ - gtk_widget_destroy(GTK_WIDGET(App)); + /* Do not: gtk_widget_destroy(App); App=NULL; + * as it would race with g_timeout_add()ed function which check + * 'if (!App)' first and expect there fully valid tree afterwards. + */ + App_local=App; App=NULL; + gtk_widget_destroy(GTK_WIDGET(App)); } static void ui_gnome_network_notify_hostip(guint32 hostip_guint32) @@ -257,11 +270,12 @@ gboolean ui_gnome_init(void) ui_gnome_network_notify_hostip(0); gtk_entry_set_text(PortEntry,udpgate_printf_alloca("%d",(int)optarg_port)); - if (!startup_init()) { - gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON(AutostartCheckButton),TRUE); + if (!static_startup_supported()) { gtk_widget_set_sensitive(GTK_WIDGET(AutostartLabel),FALSE); gtk_widget_set_sensitive(GTK_WIDGET(AutostartCheckButton),FALSE); } + if (!static_startup_query(NULL)) + gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON(AutostartCheckButton),TRUE); daemon_check_timeout_func(NULL); /* data; unused */ external_startup_check_timeout_func(NULL); /* data; unused */