[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r19100 - in gnunet-gtk: contrib src/setup
From: |
gnunet |
Subject: |
[GNUnet-SVN] r19100 - in gnunet-gtk: contrib src/setup |
Date: |
Thu, 12 Jan 2012 09:35:20 +0100 |
Author: grothoff
Date: 2012-01-12 09:35:20 +0100 (Thu, 12 Jan 2012)
New Revision: 19100
Added:
gnunet-gtk/src/setup/gnunet-setup-hostlist-server.c
Modified:
gnunet-gtk/contrib/gnunet_setup_gtk_main_window.glade
gnunet-gtk/src/setup/Makefile.am
Log:
vminko: fixing #1782: only show hostlist server options if hostlist server is
actually supported
Modified: gnunet-gtk/contrib/gnunet_setup_gtk_main_window.glade
===================================================================
--- gnunet-gtk/contrib/gnunet_setup_gtk_main_window.glade 2012-01-12
08:33:45 UTC (rev 19099)
+++ gnunet-gtk/contrib/gnunet_setup_gtk_main_window.glade 2012-01-12
08:35:20 UTC (rev 19100)
@@ -421,6 +421,7 @@
<property
name="use_action_appearance">False</property>
<property name="xalign">0</property>
<property
name="draw_indicator">True</property>
+ <signal name="realize"
handler="GNUNET_setup_hostlist_offer_hostlist_checkbutton_realize_cb"
swapped="no"/>
</object>
<packing>
<property
name="expand">False</property>
@@ -437,6 +438,7 @@
<property
name="use_action_appearance">False</property>
<property name="xalign">0</property>
<property
name="draw_indicator">True</property>
+ <signal name="realize"
handler="GNUNET_setup_hostlist_advertise_checkbutton_realize_cb" swapped="no"/>
</object>
<packing>
<property
name="expand">False</property>
@@ -473,6 +475,7 @@
<property
name="secondary_icon_sensitive">True</property>
<property
name="adjustment">GNUNET_setup_hostlist_server_port_adjustment</property>
<property
name="numeric">True</property>
+ <signal name="realize"
handler="GNUNET_setup_hostlist_server_port_spin_button_realize_cb"
swapped="no"/>
</object>
<packing>
<property
name="expand">False</property>
Modified: gnunet-gtk/src/setup/Makefile.am
===================================================================
--- gnunet-gtk/src/setup/Makefile.am 2012-01-12 08:33:45 UTC (rev 19099)
+++ gnunet-gtk/src/setup/Makefile.am 2012-01-12 08:35:20 UTC (rev 19100)
@@ -27,7 +27,8 @@
gnunet-setup-datastore-config.c \
gnunet-setup-datacache-plugins.c \
gnunet-setup-datacache-config.c \
- gnunet-setup-hostlist-editing.c
+ gnunet-setup-hostlist-editing.c \
+ gnunet-setup-hostlist-server.c
gnunet_setup_LDADD = \
$(top_builddir)/src/lib/libgnunetgtk.la \
@GTK_LIBS@ @GNUNET_LIBS@ @GLADE_LIBS@ \
@@ -35,4 +36,4 @@
-lgnunetutil -lgnunetnat \
$(INTLLIBS)
gnunet_setup_LDFLAGS = \
- -export-dynamic
\ No newline at end of file
+ -export-dynamic
Added: gnunet-gtk/src/setup/gnunet-setup-hostlist-server.c
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup-hostlist-server.c
(rev 0)
+++ gnunet-gtk/src/setup/gnunet-setup-hostlist-server.c 2012-01-12 08:35:20 UTC
(rev 19100)
@@ -0,0 +1,205 @@
+/*
+ This file is part of GNUnet.
+ (C) 2012 Christian Grothoff (and other contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 2, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file src/gnunet-setup-hostlist-server.c
+ * @brief (de)sensitize UI elements related to hostlist server configuration
+ * based on the build configuration of the hostlist daemon
+ * @author Christian Grothoff
+ */
+#include "gnunet-setup.h"
+#include <gnunet/gnunet_util_lib.h>
+
+
+/**
+ * Timeout for hostlist daemon to print help information
+ */
+#define CMD_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
+
+
+/**
+ * Function called to report the result of testing the hostlist daemon.
+ *
+ * @param cls closure
+ * @param result GNUNET_YES if the hostlist daemon has an integrated hostlist
+ * server, GNUNET_NO otherwise
+ */
+typedef void (*TestHostlistDaemonCallback) (void *cls,
+ int result);
+
+
+/**
+ * Context for running hostlist daemon and processing its output.
+ */
+struct CommandContext
+{
+ /**
+ * Handle to the command.
+ */
+ struct GNUNET_OS_CommandHandle *cmd;
+
+ /**
+ * Where to pass the result.
+ */
+ TestHostlistDaemonCallback callback;
+
+ /**
+ * Closure for the callback.
+ */
+ void *callback_cls;
+
+ /**
+ * GNUNET_YES if the target argument was found, GNUNET_NO otherwise.
+ */
+ int found;
+
+};
+
+
+static void
+set_checkbutton_status (void *cls,
+ int result)
+{
+ GtkWidget * widget = cls;
+ GtkToggleButton *button;
+
+ if (GNUNET_YES != result)
+ {
+ gtk_widget_set_sensitive (widget, FALSE);
+ button = GTK_TOGGLE_BUTTON (widget);
+ if (button == NULL)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ /* also deactivate the checkbutton since this option could be enabled
+ by editing the config file manually */
+ gtk_toggle_button_set_active (button, FALSE);
+ }
+}
+
+
+static void
+set_spinbutton_status (void *cls,
+ int result)
+{
+ GtkWidget * widget = cls;
+
+ if (GNUNET_YES != result)
+ gtk_widget_set_sensitive (widget, FALSE);
+}
+
+
+/**
+ * Process the output from the 'gnunet-daemon-hostlist -h' command
+ * to find out whether the hostlist daemon can provide a hostlist server.
+ *
+ * @param cls the 'struct CommandContext'
+ * @param line line of output, NULL at the end
+ */
+static void
+process_hostlist_daemon_output (void *cls, const char *line)
+{
+ struct CommandContext *ctx = cls;
+ char *t;
+ char *w;
+
+ if (NULL == line)
+ {
+ ctx->callback (ctx->callback_cls, ctx->found);
+ GNUNET_OS_command_stop (ctx->cmd);
+ GNUNET_free (ctx);
+ return;
+ }
+
+ t = GNUNET_strdup (line);
+ w = strtok (t, " ");
+ while (w != NULL)
+ {
+ if (0 == strcmp (w, "--provide-hostlist"))
+ {
+ ctx->found = GNUNET_YES;
+ break;
+ }
+ w = strtok (NULL, " ");
+ }
+ GNUNET_free (t);
+}
+
+
+/**
+ * Run 'gnunet-daemon-hostlist -h'. Output of this command will let us
+ * know whether the hostlist daemon can provide a hostlist server.
+ *
+ * @param callback function to call with the result
+ * @param cls closure for the callback
+ */
+static void
+test_hostlist_daemon (TestHostlistDaemonCallback callback,
+ void *cls)
+{
+ struct CommandContext *ctx;
+
+ ctx = GNUNET_malloc (sizeof (struct CommandContext));
+ ctx->callback = callback;
+ ctx->callback_cls = cls;
+ ctx->found = GNUNET_NO;
+ ctx->cmd = GNUNET_OS_command_run (&process_hostlist_daemon_output,
+ ctx,
+ CMD_TIMEOUT,
+ "gnunet-daemon-hostlist",
+ "gnunet-daemon-hostlist",
+ "-h",
+ NULL);
+ if (NULL == ctx->cmd)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Could not determine whether the hostlist daemon has"
+ " an integrated hostlist server!\n"));
+ GNUNET_free (ctx);
+ }
+}
+
+
+void
+GNUNET_setup_hostlist_offer_hostlist_checkbutton_realize_cb (GtkWidget *
widget,
+ gpointer
user_data)
+{
+ test_hostlist_daemon (&set_checkbutton_status, widget);
+}
+
+
+void
+GNUNET_setup_hostlist_advertise_checkbutton_realize_cb (GtkWidget * widget,
+ gpointer user_data)
+{
+ test_hostlist_daemon (&set_checkbutton_status, widget);
+}
+
+
+void
+GNUNET_setup_hostlist_server_port_spin_button_realize_cb (GtkWidget * widget,
+ gpointer user_data)
+{
+ test_hostlist_daemon (&set_spinbutton_status, widget);
+}
+
+
+/* end of gnunet-setup-hostlist-server.c */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r19100 - in gnunet-gtk: contrib src/setup,
gnunet <=