gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r25184 - in gnunet-gtk: contrib src/setup


From: gnunet
Subject: [GNUnet-SVN] r25184 - in gnunet-gtk: contrib src/setup
Date: Mon, 3 Dec 2012 11:58:53 +0100

Author: grothoff
Date: 2012-12-03 11:58:53 +0100 (Mon, 03 Dec 2012)
New Revision: 25184

Added:
   gnunet-gtk/src/setup/gnunet-setup-gns-edit.c
   gnunet-gtk/src/setup/gnunet-setup-gns-edit.h
Modified:
   gnunet-gtk/contrib/gnunet_setup_gtk_main_window.glade
   gnunet-gtk/src/setup/Makefile.am
   gnunet-gtk/src/setup/gnunet-setup-gns.c
Log:
-another step towards custom edit dialogs for records

Modified: gnunet-gtk/contrib/gnunet_setup_gtk_main_window.glade
===================================================================
--- gnunet-gtk/contrib/gnunet_setup_gtk_main_window.glade       2012-12-03 
10:08:28 UTC (rev 25183)
+++ gnunet-gtk/contrib/gnunet_setup_gtk_main_window.glade       2012-12-03 
10:58:53 UTC (rev 25184)
@@ -16,6 +16,13 @@
     <property name="step_increment">1</property>
     <property name="page_increment">10</property>
   </object>
+  <object class="GtkAdjustment" 
id="GNUNET_setup_exit_interface_mask_adjustment">
+    <property name="lower">1</property>
+    <property name="upper">127</property>
+    <property name="value">48</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
   <object class="GtkDialog" id="GNUNET_setup_dialog">
     <property name="can_focus">False</property>
     <property name="border_width">5</property>
@@ -4456,7 +4463,7 @@
                               </object>
                               <attributes>
                                 <attribute name="visible">10</attribute>
-                                <attribute name="editable">10</attribute>
+                                <attribute name="editable">14</attribute>
                                 <attribute name="text">3</attribute>
                               </attributes>
                             </child>
@@ -4578,13 +4585,6 @@
       <action-widget response="-3">GNUNET_setup_save_button</action-widget>
     </action-widgets>
   </object>
-  <object class="GtkAdjustment" 
id="GNUNET_setup_exit_interface_mask_adjustment">
-    <property name="lower">1</property>
-    <property name="upper">127</property>
-    <property name="value">48</property>
-    <property name="step_increment">1</property>
-    <property name="page_increment">10</property>
-  </object>
   <object class="GtkAdjustment" 
id="GNUNET_setup_fs_datacache_mysql_port_adjustment">
     <property name="lower">1</property>
     <property name="upper">65535</property>
@@ -4669,6 +4669,10 @@
       <column type="gchararray"/>
       <!-- column-name name_color -->
       <column type="gchararray"/>
+      <!-- column-name type_is_editable -->
+      <column type="gboolean"/>
+      <!-- column-name is_shadow -->
+      <column type="gboolean"/>
     </columns>
   </object>
   <object class="GtkListStore" id="GNUNET_setup_gns_type_liststore">

Modified: gnunet-gtk/src/setup/Makefile.am
===================================================================
--- gnunet-gtk/src/setup/Makefile.am    2012-12-03 10:08:28 UTC (rev 25183)
+++ gnunet-gtk/src/setup/Makefile.am    2012-12-03 10:58:53 UTC (rev 25184)
@@ -27,6 +27,7 @@
   gnunet-setup-namestore-plugins.c \
   gnunet-setup-namestore-config.c \
   gnunet-setup-gns.c gnunet-setup-gns.h \
+  gnunet-setup-gns-edit.c gnunet-setup-gns-edit.h \
   gnunet-setup-hostlist-editing.c \
   gnunet-setup-hostlist-server.c 
 gnunet_setup_LDADD = \

Added: gnunet-gtk/src/setup/gnunet-setup-gns-edit.c
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup-gns-edit.c                                
(rev 0)
+++ gnunet-gtk/src/setup/gnunet-setup-gns-edit.c        2012-12-03 10:58:53 UTC 
(rev 25184)
@@ -0,0 +1,41 @@
+/*
+     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/setup/gnunet-setup-gns-edit.c
+ * @author Christian Grothoff
+ * @brief editing dialogs for GNS records
+ */
+#include "gnunet-setup-gns-edit.h"
+
+/**
+ * Run an GNS Edit dialog for an 'A' Record.
+ *
+ * @param cont continuation to call when done
+ * @param edc editing context to use
+ */
+void
+GNS_edit_dialog_a (struct EditDialogContext *edc)
+{
+  GNUNET_break (0); /* not implemented */
+  edc->cont (edc, GTK_RESPONSE_CANCEL);  /* treat as 'cancel' */
+}
+
+
+/* end of gnunet-setup-gns-edit.c */

Added: gnunet-gtk/src/setup/gnunet-setup-gns-edit.h
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup-gns-edit.h                                
(rev 0)
+++ gnunet-gtk/src/setup/gnunet-setup-gns-edit.h        2012-12-03 10:58:53 UTC 
(rev 25184)
@@ -0,0 +1,127 @@
+/*
+     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/setup/gnunet-setup-gns-edit.h
+ * @author Christian Grothoff
+ * @brief editing dialogs for GNS records
+ */
+#ifndef GNUNET_SETUP_GNS_EDIT_H
+#define GNUNET_SETUP_GNS_EDIT_H
+
+#include "gnunet_gtk.h"
+#include "gnunet-setup-gns.h"
+#include <gnunet/gnunet_namestore_service.h>
+#include <gnunet/gnunet_dnsparser_lib.h>
+
+
+/**
+ * Context for edit operations.
+ */
+struct EditDialogContext;
+
+
+/**
+ * Signature of the continuation function invoked once the
+ * edit dialog is done.
+ *
+ * @param edc dialog context
+ * @param ret return code from the dialog
+ */
+typedef void (*GNS_EditContinuation)(struct EditDialogContext *edc,
+                                    GtkResponseType ret);
+
+
+
+/**
+ * Context for edit operations.
+ */
+struct EditDialogContext
+{
+
+  /**
+   * Function to call at the end.
+   */
+  GNS_EditContinuation cont;
+
+  /**
+   * Where in the tree view are we editing?
+   */
+  GtkTreeIter it;
+
+  /**
+   * Expiration time value (absolute or relative).
+   */
+  guint64 n_exp_time;
+
+  /**
+   * Old name of the record (for deletion).
+   */
+  gchar *n_name;
+
+  /**
+   * New name.
+   */
+  gchar *n_new_name;
+
+  /**
+   * Value of the record in string format.
+   */
+  gchar *n_value;
+
+  /**
+   * Zone into which the record should be placed.
+   */
+  const char *new_zone_option;
+
+  /**
+   * Flag indicating if the old record was in the namestore.
+   */
+  int old_record_in_namestore;
+
+  /**
+   * Is this record 'public'?
+   */
+  gboolean n_public;
+
+  /**
+   * Is the expiration time relative?
+   */
+  gboolean n_is_relative;
+
+  /**
+   * Is this record a shadow record?
+   */
+  gboolean n_is_shadow;
+
+};
+
+
+
+/**
+ * Run an GNS Edit dialog for an 'A' Record.
+ *
+ * @param edc editing context to use
+ */
+void
+GNS_edit_dialog_a (struct EditDialogContext *edc);
+
+
+#endif

Modified: gnunet-gtk/src/setup/gnunet-setup-gns.c
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup-gns.c     2012-12-03 10:08:28 UTC (rev 
25183)
+++ gnunet-gtk/src/setup/gnunet-setup-gns.c     2012-12-03 10:58:53 UTC (rev 
25184)
@@ -25,6 +25,7 @@
  */
 #include "gnunet_gtk.h"
 #include "gnunet-setup-gns.h"
+#include "gnunet-setup-gns-edit.h"
 #include <gnunet/gnunet_namestore_service.h>
 #include <gnunet/gnunet_dnsparser_lib.h>
 
@@ -142,12 +143,16 @@
    */
   GNS_TREESTORE_COL_NAME_COLOR,
 
-
   /**
    * A gboolean; TRUE if the 'type' column can still be changed;
    * FALSE once we have edited the value.
    */
-  GNS_TREESTORE_COL_TYPE_IS_EDITABLE
+  GNS_TREESTORE_COL_TYPE_IS_EDITABLE,
+
+  /**
+   * A gboolean; TRUE if the value is a shadow record.
+   */
+  GNS_TREESTORE_COL_IS_SHADOW
 };
 
 
@@ -1021,7 +1026,7 @@
  * the namestore).   If the given path identifies an entire 'name',
  * remove all records under that name.
  * 
- * @param path identifying record(s) to remove
+ * @param path identifying record(s) to remove; FIXME: consider doing this 
with an 'iter' instead
  */
 static void
 remove_records_by_path (const gchar *path)
@@ -1089,9 +1094,89 @@
 
 
 /**
+ * The edit dialog completed; update the namestore and the 
+ * view based on the new values in 'edc'.
+ *
+ * @param edc editing context information
+ * @param ret return code of the dialog
+ */
+static void
+edit_dialog_continuation (struct EditDialogContext *edc,
+                         GtkResponseType ret)
+{
+  char *path;
+
+  /* FIXME: logic to move records between zones is missing here!
+     (#2473) */
+  switch (ret)
+  {
+  case GTK_RESPONSE_REJECT: /* code for 'delete' */
+    if (GNUNET_YES == edc->old_record_in_namestore)
+    {
+      /* remove item from tree view and namestore */
+      path = gtk_tree_model_get_string_from_iter (tm, &edc->it);
+      remove_records_by_path (path);
+      g_free (path);  
+    }
+    else
+    {
+      /* invalid choice, 'delete' should have been hidden... */
+      GNUNET_break (0);
+      gtk_tree_store_remove (ts, &edc->it);
+    }
+    break;
+  case GTK_RESPONSE_CANCEL:
+  case GTK_RESPONSE_DELETE_EVENT: /* window deletion counts as 'cancel' */
+    if (GNUNET_NO == edc->old_record_in_namestore)
+    {
+      /* re-enable type selection */
+      gtk_tree_store_set (ts, &edc->it,
+                         GNS_TREESTORE_COL_TYPE_IS_EDITABLE, TRUE,
+                         GNS_TREESTORE_COL_VAL_COLOR, "red",
+                         -1);
+    }
+    else
+    {
+      /* do nothing */    
+    }
+    break;
+  case GTK_RESPONSE_OK:
+    /* update model */
+    gtk_tree_store_set (ts, &edc->it,
+                       GNS_TREESTORE_COL_NAME, edc->n_name,
+                       GNS_TREESTORE_COL_IS_PUBLIC, edc->n_public,
+                       GNS_TREESTORE_COL_EXP_TIME, edc->n_exp_time,
+                       GNS_TREESTORE_COL_EXP_TIME_IS_REL, edc->n_is_relative,
+                       GNS_TREESTORE_COL_IS_SHADOW, edc->n_is_shadow,
+                       GNS_TREESTORE_COL_VAL_AS_STR, edc->n_value,
+                       GNS_TREESTORE_COL_VAL_COLOR, NULL,
+                       -1);    
+    if (GNUNET_YES == edc->old_record_in_namestore)
+    {
+      /* replace record in database with that from model */
+      check_name_validity_and_commit (&edc->it, edc->n_name);
+    }
+    else
+    {
+      /* add record in database based on model */
+      check_name_validity_and_commit (&edc->it, NULL);
+    }
+    break;
+  default:
+    GNUNET_break (0);
+    break;
+  }
+  g_free (edc->n_name);
+  g_free (edc->n_new_name);
+  g_free (edc->n_value);
+  GNUNET_free (edc);
+}
+
+
+/**
  * Edit the record at the currently selected row.  If the old record
  * exists, allow the user to modify or delete it; if it does not
- * exist, remove it _only_ from the model (by offering the user the
+ * exist, make the record type editable again (by offering the user the
  * 'cancel' option; hide 'delete' in this case).
  *
  * @param old_record_in_namestore GNUNET_YES if the old record exists in the 
namestore,
@@ -1101,33 +1186,52 @@
 edit_selected_row (int old_record_in_namestore)
 {
   GtkTreeSelection *sel;
-  GtkTreeIter it;
-  gchar *n_name;
   gint n_type;
-  gboolean n_public;
-  guint64 n_exp_time;
-  gboolean n_is_relative;
-  gchar *n_value;
+  struct EditDialogContext *edc;
 
   sel = gtk_tree_view_get_selection (tv);
-  if (! gtk_tree_selection_get_selected (sel, NULL, &it))
+  edc = GNUNET_malloc (sizeof (struct EditDialogContext));
+  if (! gtk_tree_selection_get_selected (sel, NULL, &edc->it))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "No row selected\n");
+    GNUNET_free (edc);
     return;
   }
-  gtk_tree_model_get (tm, &it,
-                     GNS_TREESTORE_COL_NAME, &n_name,
+  gtk_tree_model_get (tm, &edc->it,
+                     GNS_TREESTORE_COL_NAME, &edc->n_name,
                      GNS_TREESTORE_COL_RECORD_TYPE, &n_type,
-                     GNS_TREESTORE_COL_IS_PUBLIC, &n_public,
-                     GNS_TREESTORE_COL_EXP_TIME, &n_exp_time,
-                     GNS_TREESTORE_COL_EXP_TIME_IS_REL, &n_is_relative,
-                     GNS_TREESTORE_COL_VAL_AS_STR, &n_value,
+                     GNS_TREESTORE_COL_IS_PUBLIC, &edc->n_public,
+                     GNS_TREESTORE_COL_EXP_TIME, &edc->n_exp_time,
+                     GNS_TREESTORE_COL_EXP_TIME_IS_REL, &edc->n_is_relative,
+                     GNS_TREESTORE_COL_IS_SHADOW, &edc->n_is_shadow,
+                     GNS_TREESTORE_COL_VAL_AS_STR, &edc->n_value,
                      -1);
-  // FIXME - implement...
-  GNUNET_break (0);
-  g_free (n_name);
-  g_free (n_value);
+  edc->old_record_in_namestore = old_record_in_namestore;
+  edc->new_zone_option = current_zone_option;
+  edc->n_new_name = g_strdup (edc->n_name);
+  edc->cont = &edit_dialog_continuation;
+  switch (n_type)
+  {
+  case GNUNET_DNSPARSER_TYPE_A:
+    GNS_edit_dialog_a (edc);
+    break;
+  case GNUNET_DNSPARSER_TYPE_NS:
+  case GNUNET_DNSPARSER_TYPE_CNAME:
+  case GNUNET_DNSPARSER_TYPE_SOA:
+  case GNUNET_DNSPARSER_TYPE_PTR:
+  case GNUNET_DNSPARSER_TYPE_MX:
+  case GNUNET_DNSPARSER_TYPE_TXT:
+  case GNUNET_DNSPARSER_TYPE_AAAA:
+  case GNUNET_DNSPARSER_TYPE_SRV:
+  case GNUNET_DNSPARSER_TYPE_TLSA:
+  case GNUNET_NAMESTORE_TYPE_PKEY:
+  case GNUNET_NAMESTORE_TYPE_LEHO:
+  case GNUNET_NAMESTORE_TYPE_VPN:
+    GNUNET_break (0);   /* FIXME - implement (#2465) */
+    edc->cont (edc, GTK_RESPONSE_CANCEL);  /* treat as 'cancel' */
+    break;
+  }
 }
 
 




reply via email to

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