gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r13500 - gnunet-setup/src


From: gnunet
Subject: [GNUnet-SVN] r13500 - gnunet-setup/src
Date: Tue, 2 Nov 2010 19:57:47 +0100

Author: grothoff
Date: 2010-11-02 19:57:47 +0100 (Tue, 02 Nov 2010)
New Revision: 13500

Modified:
   gnunet-setup/src/gnunet-setup-options.c
   gnunet-setup/src/gnunet-setup-options.h
   gnunet-setup/src/gnunet-setup.c
Log:
more work on setup basics

Modified: gnunet-setup/src/gnunet-setup-options.c
===================================================================
--- gnunet-setup/src/gnunet-setup-options.c     2010-11-02 17:19:35 UTC (rev 
13499)
+++ gnunet-setup/src/gnunet-setup-options.c     2010-11-02 18:57:47 UTC (rev 
13500)
@@ -24,12 +24,76 @@
  * @author Christian Grothoff
  */
 #include "gnunet-setup-options.h"
+#include <gnunet/gnunet_util_lib.h>
 
+static int
+load_yes_no (const char *section,
+            const char *option,
+            const char *value,
+            GtkWidget *widget,
+            const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  GtkToggleButton *button;
+
+  button = GTK_TOGGLE_BUTTON (widget);
+  if (button == NULL)
+    return GNUNET_SYSERR;
+  gtk_toggle_button_set_mode (button,
+                             strcasecmp (value, "YES") ? TRUE : FALSE);
+  return GNUNET_OK;
+}
+
+
+static int
+save_yes_no (const char *section,
+            const char *option,
+            GtkWidget *widget,
+            struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  GtkToggleButton *button;                    
+  gboolean mode;
+
+  button = GTK_TOGGLE_BUTTON (widget);
+  if (button == NULL)
+    return GNUNET_SYSERR;
+  mode = gtk_toggle_button_get_mode (button);
+  GNUNET_CONFIGURATION_set_value_string (cfg, 
+                                        section, option,
+                                        mode ? "YES" : "NO");
+  return GNUNET_OK;
+}
+
+
 /**
+ * Hide "min connected friends" option if in F2F-only mode.
+ */
+static struct GNUNET_SETUP_VisibilitySpecification 
hide_min_connected_friends[] =
+{
+  { "GNUNET_setup_minimum_friends_label", "YES", NULL },
+  { "GNUNET_setup_minimum_friends_spinbutton", "YES", NULL },
+  { NULL, NULL, NULL }
+};
+
+
+/**
  * Option specification data.
  */
 const struct GNUNET_SETUP_OptionSpecification option_specifications[] =
   {
-
+    { 
+      "GNUNET_setup_friends_only_checkbutton",
+      "toggled",
+      "topology",
+      "FRIENDS-ONLY",
+      gettext_noop ("Should GNUnet exclusively connect to peers in the 
`friends file'"),
+      "https://gnunet.org/configuration-f2f";,
+      NULL, NULL,
+      &load_yes_no,
+      &save_yes_no,
+      hide_min_connected_friends
+    },    
+    { NULL, NULL, NULL, NULL, NULL,
+      NULL, NULL, NULL, NULL, NULL, NULL }
   };
 
+/* end of gnunet-setup-options.c */

Modified: gnunet-setup/src/gnunet-setup-options.h
===================================================================
--- gnunet-setup/src/gnunet-setup-options.h     2010-11-02 17:19:35 UTC (rev 
13499)
+++ gnunet-setup/src/gnunet-setup-options.h     2010-11-02 18:57:47 UTC (rev 
13500)
@@ -50,7 +50,7 @@
 /**
  * Function to be called to validate option values.
  */
-typedef int (*GNUNET_SETUP_Validation)(void *cls,
+typedef int (*GNUNET_SETUP_Validation)(const void *cls,
                                       const char *section,
                                       const char *option,
                                       GtkWidget *widget,
@@ -82,15 +82,26 @@
  */
 struct GNUNET_SETUP_VisibilitySpecification
 {
-
+  /**
+   * Which widget should be changed?
+   */
   const char *widget_name;
 
+  /**
+   * If the option is set to this value, the widget should be
+   * shown.  If NULL, the "hide_value" controls visibility.
+   */
   const char *show_value;
 
+  /**
+   * If the option is set to this value, the widget should be
+   * hidden.  If NULL, the "show_value" controls visibility.
+   */  
   const char *hide_value;
 
 };
 
+
 /**
  * Structs of this type define how widgets relate to GNUnet options
  * and control visibility and special actions.
@@ -103,6 +114,11 @@
   const char *widget_name;
 
   /**
+   * Name of the signal the widget emits if its state changes.
+   */
+  const char *change_signal;
+
+  /**
    * Section in the configuration
    */
   const char *section;
@@ -130,7 +146,7 @@
   /**
    * Closure for 'validation_function'.
    */
-  void *validation_function_cls;
+  const void *validation_function_cls;
 
   /**
    * Function to call to initialize the widget from the configuration.
@@ -146,7 +162,7 @@
    * Visibility changes to apply if this option changes (NULL, or
    * NULL-terminated).
    */
-  const struct GNUNET_SETUP_VisibilitySpecification visibility[];
+  const struct GNUNET_SETUP_VisibilitySpecification *visibility;
 
 };
 

Modified: gnunet-setup/src/gnunet-setup.c
===================================================================
--- gnunet-setup/src/gnunet-setup.c     2010-11-02 17:19:35 UTC (rev 13499)
+++ gnunet-setup/src/gnunet-setup.c     2010-11-02 18:57:47 UTC (rev 13500)
@@ -26,16 +26,7 @@
 #if ENABLE_NLS
 #include <locale.h>
 #endif
-#ifndef HAVE_USED_CONFIG_H
-#define HAVE_USED_CONFIG_H
-#include "gnunet_setup_config.h"
-#endif
 #include "gnunet-setup-options.h"
-#include <gnunet/platform.h>
-#include <gnunet/gnunet_directories.h>
-#include <gnunet/gnunet_util_lib.h>
-#include <gladeui/glade.h>
-#include <gtk/gtk.h>
 
 /**
  * Builder for the main window.
@@ -154,6 +145,107 @@
 }
 
 
+static void
+widget_selected_callback (GtkWidget *widget,
+                         GtkSelectionData *data,
+                         guint info,
+                         guint time,
+                         gpointer user_data)
+{
+  const struct GNUNET_SETUP_OptionSpecification *os = user_data;
+  GtkLinkButton *help;
+
+  help = GTK_LINK_BUTTON (gtk_builder_get_object (builder, 
+                                                 "GNUNET_setup_help_text"));
+  gtk_link_button_set_uri (help, 
+                          os->help_url);
+  gtk_button_set_label (GTK_BUTTON (help),
+                       os->help_text);  
+}
+
+
+/**
+ * Change the visibility of widgets according to the 
+ * value and visibility specification given.
+ *
+ * @param os option specification
+ * @param value current value for the given option
+ */
+static void
+update_visibility (const struct GNUNET_SETUP_OptionSpecification *os,
+                  const char *value)
+{
+  unsigned int i;
+  const struct GNUNET_SETUP_VisibilitySpecification *vs;
+  GtkWidget *widget;
+
+  if (os->visibility == NULL)
+    return;
+  i = 0;
+  while (os->visibility[i].widget_name != NULL)
+    {
+      vs = &os->visibility[i];
+      widget = GTK_WIDGET (gtk_builder_get_object (builder, 
+                                                  vs->widget_name));
+      if (widget == NULL)
+       {
+         GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                     _("Widget `%s' not found\n"),
+                     vs->widget_name);
+       }
+      if (NULL != vs->show_value)
+       {
+         if (0 == strcasecmp (value,
+                              vs->show_value))
+           gtk_widget_show (widget);
+         else
+           gtk_widget_hide (widget);
+       }
+      if (NULL != vs->hide_value)
+       {
+         if (0 == strcasecmp (value,
+                              vs->hide_value))
+           gtk_widget_hide (widget);
+         else
+           gtk_widget_show (widget);
+       }
+      i++;
+    }
+}
+                  
+
+/**
+ * Function called whenever a widget changes its state.
+ */
+static void
+widget_state_change_callback (const struct GNUNET_SETUP_OptionSpecification 
*os)
+{
+  GtkWidget *widget;
+  char *value;
+
+  widget = GTK_WIDGET (gtk_builder_get_object (builder,
+                                              os->widget_name));
+  if (GNUNET_OK !=
+      os->save_function (os->section,
+                        os->option,
+                        widget,
+                        cfg))
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                 _("Failed to obtain option value from widget `%s'\n"),
+                 os->widget_name);
+      return;
+    }
+  GNUNET_assert (GNUNET_OK ==
+                GNUNET_CONFIGURATION_get_value_string (cfg,
+                                                       os->section,
+                                                       os->option,
+                                                       &value));
+  update_visibility (os, value);
+  GNUNET_free (value);
+}
+
+
 int
 main (int argc,
       char *const *argv)
@@ -170,10 +262,14 @@
   gint ret;
   GtkWidget *main_window;
   GtkWidget *dialog;
+  GtkWidget *widget;
   int arg_off;
   int iret;
   char *const *argp;
+  char *value;
   struct GNUNET_CONFIGURATION_Handle *cfgDefault;
+  const struct GNUNET_SETUP_OptionSpecification *os;
+  unsigned int i;
  
   arg_off = GNUNET_GETOPT_run ("gnunet-setup",
                               options,
@@ -204,6 +300,64 @@
   (void) GNUNET_CONFIGURATION_load (cfg, cfgName);
   main_window = GTK_WIDGET (gtk_builder_get_object (builder, 
                                                    "GNUNET_setup_dialog"));
+  /* load options into dialog */
+  i = 0;
+  while (option_specifications[i].widget_name != NULL)
+    {
+      os = &option_specifications[i];
+      widget = GTK_WIDGET (gtk_builder_get_object (builder,
+                                                  os->widget_name));
+      if (NULL == widget)
+       {
+         GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                     _("Widget `%s' not found\n"),
+                     os->widget_name);
+         i++;
+         continue;
+       }
+      if (GNUNET_OK !=
+         GNUNET_CONFIGURATION_get_value_string (cfg,
+                                                os->section,
+                                                os->option,
+                                                &value))
+       {
+         GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                     "No default value known for option `%s' in section 
`%s'\n",
+                     os->option,
+                     os->section);
+         i++;
+         continue;
+       }
+      if (GNUNET_OK != 
+         os->load_function (os->section, os->option,
+                            value,
+                            widget,
+                            cfg))
+       {
+         GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                     "Failed to initialize widget `%s' with value `%s'\n",
+                     os->widget_name,
+                     value);
+         GNUNET_free (value);
+         i++;
+         continue;
+       }
+      if (os->help_text != NULL)
+       {
+         g_signal_connect (widget,
+                           "selection-get",
+                           G_CALLBACK (&widget_selected_callback),
+                           (void*) os);
+       }
+      g_signal_connect_swapped (widget,
+                               os->change_signal,
+                               G_CALLBACK (&widget_state_change_callback),
+                               (void*) os);
+      update_visibility (os, value);
+      GNUNET_free (value);       
+      i++;
+    }
+
  RESTART:
   ret = gtk_dialog_run (GTK_DIALOG (main_window));
   gtk_widget_hide (main_window);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]