gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r15475 - gnunet-setup/src
Date: Wed, 8 Jun 2011 20:09:49 +0200

Author: grothoff
Date: 2011-06-08 20:09:48 +0200 (Wed, 08 Jun 2011)
New Revision: 15475

Modified:
   gnunet-setup/src/gnunet-setup-options.c
Log:
towards editable tree views

Modified: gnunet-setup/src/gnunet-setup-options.c
===================================================================
--- gnunet-setup/src/gnunet-setup-options.c     2011-06-08 17:58:34 UTC (rev 
15474)
+++ gnunet-setup/src/gnunet-setup-options.c     2011-06-08 18:09:48 UTC (rev 
15475)
@@ -726,6 +726,49 @@
 
 
 /**
+ * Given the list store and the data in it, update the 
+ * configuration file accordingly.
+ *
+ * @param tm model to use
+ */
+static void
+update_vpn_dns_configuration (GtkTreeModel *tm)
+{
+  GtkTreeIter iter;
+  gchar *hostname;
+  guint srcport;
+  guint targetport;
+  gchar *targethost;
+  guint ttl;
+  gchar *altnames;
+  gboolean isudp;
+
+  /* FIXME: remove all existing DNS-related entries from cfg  */
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+             "Updating configuration file not implemented\n");
+  if (TRUE ==
+      gtk_tree_model_get_iter_first (tm, &iter))
+    do
+      {  
+       gtk_tree_model_get (tm, &iter,
+                           0, &hostname,
+                           1, &srcport,
+                           2, &targetport,
+                           3, &targethost,
+                           4, &ttl,
+                           5, &altnames,
+                           6, &isudp,
+                           -1);
+       /* FIXME: update cfg! */
+       g_free (hostname);
+       g_free (targethost);
+       g_free (altnames);
+      }
+    while (TRUE == gtk_tree_model_iter_next (tm, &iter));
+}
+
+
+/**
  * The user has edited the DNS name of a service we're offering.
  * Update the GtkTreeModel (at the given path) and update the
  * respective service entry in the configuration file.  Finally,
@@ -744,9 +787,52 @@
                              gchar *new_text,
                              gpointer user_data) 
 {
+  GtkTreeModel *tm;
+  GtkListStore *ls;
+  GtkTreeIter iter;
+  gchar *old;
 
-  
-  
+  tm = GTK_TREE_MODEL (gtk_builder_get_object (builder, 
+                                              "vpn_dns_config_liststore"));
+  if (NULL == tm)
+    {
+      GNUNET_break (0);
+      return;
+    }
+  ls = GTK_LIST_STORE (tm);
+  if (NULL == ls)
+    {
+      GNUNET_break (0);
+      return;
+    }
+  if (TRUE != gtk_tree_model_get_iter_from_string (tm, &iter, path))
+    {
+      GNUNET_break (0);
+      return;
+    }
+  gtk_tree_model_get (tm, &iter,
+                     0, &old,
+                     -1);
+  if ( (0 != strlen (old)) &&
+       (0 == strlen (new_text)) )
+    {
+      /* deletion */
+      gtk_list_store_remove (ls, &iter);
+      g_free (old);
+      return;
+    }
+  /* update model */
+  gtk_list_store_set (ls, &iter,
+                     0, new_text,
+                     -1);
+  /* update configuration */
+  update_vpn_dns_configuration (tm);
+  if (0 == strlen (old))
+    {
+      /* need another empty entry at the end for future expansion */
+      add_dns_entry_to_list_store (GTK_LIST_STORE (tm), "");
+    }                
+  g_free (old);
 }
 
 
@@ -765,7 +851,7 @@
                                                const char *section,
                                                const char *option,
                                                GObject *widget,
-                                               const struct 
GNUNET_CONFIGURATION_Handle *cfg)
+                                               struct 
GNUNET_CONFIGURATION_Handle *cfg)
 {
   static int once;
   GtkCellRendererText *rt;
@@ -783,10 +869,94 @@
 }
 
 
+/**
+ * The user has edited the DNS name of a service we're offering.
+ * Update the GtkTreeModel (at the given path) and update the
+ * respective service entry in the configuration file.  Finally,
+ * if the edited path is for a "fresh" entry, create another empty
+ * one at the bottom.  If the hostname was set to empty, remove
+ * the entire entry from the configuration and the model.
+ *
+ * @param renderer GtkCellRendererText that changed
+ * @param path GtkTreePath identifying where in the Model the change is
+ * @param new_text the new text that was stored in the line
+ * @param user_data NULL
+ */
+static void
+save_vpn_dns_service_targetname (GtkCellRendererText *renderer,
+                                gchar *path,
+                                gchar *new_text,
+                                gpointer user_data) 
+{
+  GtkTreeModel *tm;
+  GtkListStore *ls;
+  GtkTreeIter iter;
 
+  tm = GTK_TREE_MODEL (gtk_builder_get_object (builder, 
+                                              "vpn_dns_config_liststore"));
+  if (NULL == tm)
+    {
+      GNUNET_break (0);
+      return;
+    }
+  ls = GTK_LIST_STORE (tm);
+  if (NULL == ls)
+    {
+      GNUNET_break (0);
+      return;
+    }
+  if (TRUE != gtk_tree_model_get_iter_from_string (tm, &iter, path))
+    {
+      GNUNET_break (0);
+      return;
+    }
+  /* update model */
+  gtk_list_store_set (ls, &iter,
+                     3, new_text,
+                     -1);
+  /* update configuration */
+  update_vpn_dns_configuration (tm);
+}
 
 
 /**
+ * Initialize the GtkListModel with the VPN's DNS service specification.
+ *
+ * @param cls NULL
+ * @param section section with the value (NULL)
+ * @param option option name (NULL)
+ * @param widget widget to initialize (the GtkTreeView)
+ * @param cfg configuration handle
+ * @return GNUNET_OK on success, GNUNET_SYSERR if there was a problem
+ */
+static int
+vpn_dns_service_targetname_install_edited_handler (const void *cls,
+                                                  const char *section,
+                                                  const char *option,
+                                                  GObject *widget,
+                                                  struct 
GNUNET_CONFIGURATION_Handle *cfg)
+{
+  static int once;
+  GtkCellRendererText *rt;
+
+  rt = GTK_CELL_RENDERER_TEXT(widget);
+  if (NULL == rt)
+    return GNUNET_SYSERR;
+  if (0 != once++)
+    return GNUNET_OK;
+  g_signal_connect (rt,
+                   "edited",
+                   G_CALLBACK (&save_vpn_dns_service_targetname),
+                   NULL);
+  return GNUNET_OK;
+}
+
+
+
+
+
+
+/**
  * Hide "min connected friends" option if in F2F-only mode.
  */
 static struct GNUNET_SETUP_VisibilitySpecification 
hide_min_connected_friends[] =
@@ -1934,6 +2104,25 @@
       NULL,
       NULL
     },
+       
+    {
+      "GNUNET_setup_vpn_dns_service_targetname_cellrenderertext",
+      "editing-started",
+      NULL,
+      NULL,
+      NULL,
+      "https://gnunet.org/configuration-dns";,
+      NULL,
+      &vpn_dns_service_targetname_install_edited_handler,
+      NULL,
+      NULL
+    },
+
+    /* FIXME: create 'edited_handlers' and their
+       respective 'save_vpn' handlers for the other cell renderer's;
+       largely similar to 'targetname', except sometimes with
+       conversion of string to integer; I still need to look into
+       how to do the 'isudp' case, which may be different again. */
     
     /* END of list */
 




reply via email to

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