GnomeUI binding of the new --startup-* options.
authorshort <>
Sun, 23 May 2004 18:57:39 +0000 (18:57 +0000)
committershort <>
Sun, 23 May 2004 18:57:39 +0000 (18:57 +0000)
src/ui-gnome.c

index 79546bb..f706abc 100644 (file)
 #include <string.h>
 #include <gtk/gtkmain.h>
 #include <libgnomeui/gnome-app-util.h>
+#include <gtk/gtklabel.h>
+#include <gtk/gtkcheckbutton.h>
 
 #include "network.h"
 #include "packet.h"
+#include "startup.h"
 
 
 /* Config: */
 #define DAEMON_CHECK_INTERVAL_MS 100
+#define EXTERNAL_STARTUP_CHECK_INTERVAL_MS 1000
 #define PORT_RANGE_BEGIN 2048
 #define PORT_RANGE_END 10240
 
@@ -54,6 +58,8 @@ static GtkHBox *PortHBox;
 static GnomeAppBar *AppBar;
 static GtkEntry *PortEntry;
 static GtkEntry *HostIPEntry;
+static GtkLabel *AutostartLabel;
+static GtkCheckButton *AutostartCheckButton;
 
 
 static void state_start_stop(void)
@@ -87,6 +93,15 @@ static gboolean daemon_check_timeout_func(gpointer data /* unused */)
        return TRUE;    /* continue running */
 }
 
+static gboolean external_startup_check_timeout_func(gpointer data /* unused */)
+{
+gboolean state_startup_is_on;
+
+       if (startup_query(&state_startup_is_on))
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(AutostartCheckButton),state_startup_is_on);
+       return TRUE;    /* continue running */
+}
+
 void on_PortButtonRandom_clicked(GtkButton *button,gpointer user_data)
 {
        g_return_if_fail(GTK_IS_BUTTON(button));
@@ -101,6 +116,12 @@ void on_PortButtonRandom_clicked(GtkButton *button,gpointer user_data)
 void on_AutostartCheckButton_toggled(GtkToggleButton *togglebutton,gpointer user_data)
 {
        g_return_if_fail(GTK_IS_TOGGLE_BUTTON(togglebutton));
+
+       if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(AutostartCheckButton)))
+               startup_on();
+       else
+               startup_off();
+       external_startup_check_timeout_func(NULL);      /* data; unused */
 }
 
 void on_ButtonStart_clicked(GtkButton *button,gpointer user_data)
@@ -188,6 +209,8 @@ gboolean ui_gnome_init(void)
        AppBar=GNOME_APPBAR(lookup_widget(GTK_WIDGET(App),"AppBar"));
        PortEntry=GTK_ENTRY(lookup_widget(GTK_WIDGET(App),"PortEntry"));
        HostIPEntry=GTK_ENTRY(lookup_widget(GTK_WIDGET(App),"HostIPEntry"));
+       AutostartLabel=GTK_LABEL(lookup_widget(GTK_WIDGET(App),"AutostartLabel"));
+       AutostartCheckButton=GTK_CHECK_BUTTON(lookup_widget(GTK_WIDGET(App),"AutostartCheckButton"));
 
        /* ui_gnome_g_log_handler() needs 'App'. */
        ui_gnome_g_log_handler_handler_id=g_log_set_handler(
@@ -201,12 +224,23 @@ 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);
+               gtk_widget_set_sensitive(GTK_WIDGET(AutostartLabel),FALSE);
+               gtk_widget_set_sensitive(GTK_WIDGET(AutostartCheckButton),FALSE);
+               }
+       daemon_check_timeout_func(NULL);        /* data; unused */
+       external_startup_check_timeout_func(NULL);      /* data; unused */
 
        gtk_widget_show_all(GTK_WIDGET(App));
        g_timeout_add(
                        DAEMON_CHECK_INTERVAL_MS,       /* interval */
                        daemon_check_timeout_func,      /* function */
                        NULL);  /* data; unused */
+       g_timeout_add(
+                       EXTERNAL_STARTUP_CHECK_INTERVAL_MS,     /* interval */
+                       external_startup_check_timeout_func,    /* function */
+                       NULL);  /* data; unused */
 
        network_notify_hostip=ui_gnome_network_notify_hostip;