gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r33479 - in gnunet-gtk: contrib src/conversation


From: gnunet
Subject: [GNUnet-SVN] r33479 - in gnunet-gtk: contrib src/conversation
Date: Mon, 2 Jun 2014 22:09:11 +0200

Author: grothoff
Date: 2014-06-02 22:09:10 +0200 (Mon, 02 Jun 2014)
New Revision: 33479

Added:
   gnunet-gtk/contrib/gnunet_conversation_gtk_enter_label.glade
   gnunet-gtk/src/conversation/gnunet-conversation-gtk_use_current.c
Modified:
   gnunet-gtk/contrib/Makefile.am
   gnunet-gtk/src/conversation/Makefile.am
   gnunet-gtk/src/conversation/gnunet-conversation-gtk_import.c
   gnunet-gtk/src/conversation/gnunet-conversation-gtk_import.h
   gnunet-gtk/src/conversation/gnunet-conversation-gtk_phone.c
Log:
adding logic to import caller ID into our address book

Modified: gnunet-gtk/contrib/Makefile.am
===================================================================
--- gnunet-gtk/contrib/Makefile.am      2014-06-02 19:19:16 UTC (rev 33478)
+++ gnunet-gtk/contrib/Makefile.am      2014-06-02 20:09:10 UTC (rev 33479)
@@ -82,6 +82,7 @@
   gnunet_namestore_edit_txt.glade \
   gnunet_namestore_edit_vpn.glade \
   gnunet_conversation_gtk_about_window.glade \
+  gnunet_conversation_gtk_enter_label.glade \
   gnunet_conversation_gtk_main_window.glade
 
 

Added: gnunet-gtk/contrib/gnunet_conversation_gtk_enter_label.glade
===================================================================
--- gnunet-gtk/contrib/gnunet_conversation_gtk_enter_label.glade                
                (rev 0)
+++ gnunet-gtk/contrib/gnunet_conversation_gtk_enter_label.glade        
2014-06-02 20:09:10 UTC (rev 33479)
@@ -0,0 +1,115 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.3 -->
+<interface>
+  <requires lib="gtk+" version="3.0"/>
+  <object class="GtkWindow" id="gnunet_conversation_gtk_enter_label_window">
+    <property name="can_focus">False</property>
+    <property name="title" translatable="yes">Enter the label that should be 
used for the contact</property>
+    <property name="modal">True</property>
+    <property name="destroy_with_parent">True</property>
+    <property name="skip_taskbar_hint">True</property>
+    <property name="skip_pager_hint">True</property>
+    <property name="deletable">False</property>
+    <signal name="delete-event" 
handler="gnunet_conversation_gtk_enter_label_window_delete_event_cb" 
swapped="no"/>
+    <child>
+      <object class="GtkVBox" 
id="gnunet_conversation_gtk_enter_label_dialog_main_vbox">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="spacing">2</property>
+        <child>
+          <object class="GtkHBox" 
id="gnunet_conversation_gtk_enter_label_dialog_query_hbox">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <child>
+              <object class="GtkLabel" 
id="gnunet_conversation_gtk_enter_label_dialog_url_label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">_Label:</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="padding">5</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" 
id="gnunet_conversation_gtk_enter_label_entry">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="max_length">63</property>
+                <property name="max_width_chars">63</property>
+                <signal name="changed" 
handler="gnunet_conversation_gtk_enter_label_entry_changed_cb" swapped="no"/>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="padding">5</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="padding">5</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkHBox" 
id="gnunet_conversation_gtk_enter_label_dialog_button_hbox">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="has_tooltip">True</property>
+            <child>
+              <object class="GtkButton" 
id="gnunet_conversation_gtk_enter_label_dialog_add_button">
+                <property name="label">gtk-add</property>
+                <property name="use_action_appearance">False</property>
+                <property name="visible">True</property>
+                <property name="sensitive">False</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_underline">True</property>
+                <property name="use_stock">True</property>
+                <signal name="clicked" 
handler="gnunet_conversation_gtk_enter_label_dialog_add_button_clicked_cb" 
swapped="no"/>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="padding">5</property>
+                <property name="pack_type">end</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" 
id="gnunet_conversation_gtk_enter_label_dialog_cancel_button">
+                <property name="label">gtk-cancel</property>
+                <property name="use_action_appearance">False</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+                <signal name="clicked" 
handler="gnunet_conversation_gtk_enter_label_dialog_cancel_button_clicked_cb" 
swapped="no"/>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="padding">4</property>
+                <property name="pack_type">end</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="padding">4</property>
+            <property name="pack_type">end</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>

Modified: gnunet-gtk/src/conversation/Makefile.am
===================================================================
--- gnunet-gtk/src/conversation/Makefile.am     2014-06-02 19:19:16 UTC (rev 
33478)
+++ gnunet-gtk/src/conversation/Makefile.am     2014-06-02 20:09:10 UTC (rev 
33479)
@@ -24,6 +24,7 @@
   gnunet-conversation-gtk_import.h \
   gnunet-conversation-gtk_log.c \
   gnunet-conversation-gtk_log.h \
+  gnunet-conversation-gtk_use_current.c \
   gnunet-conversation-gtk_phone.c \
   gnunet-conversation-gtk_phone.h \
   gnunet-conversation-gtk_visibility.c \

Modified: gnunet-gtk/src/conversation/gnunet-conversation-gtk_import.c
===================================================================
--- gnunet-gtk/src/conversation/gnunet-conversation-gtk_import.c        
2014-06-02 19:19:16 UTC (rev 33478)
+++ gnunet-gtk/src/conversation/gnunet-conversation-gtk_import.c        
2014-06-02 20:09:10 UTC (rev 33479)
@@ -29,7 +29,9 @@
 #include "gnunet-conversation-gtk_contacts.h"
 #include "gnunet-conversation-gtk_egos.h"
 #include "gnunet-conversation-gtk_import.h"
+#include "gnunet-conversation-gtk_zones.h"
 
+
 /**
  * Handle to the namestore.
  */
@@ -81,8 +83,18 @@
  */
 static char *my_rd_data;
 
+/**
+ * When does our phone record expire?
+ */
+static struct GNUNET_TIME_Relative expiration_time;
 
 /**
+ * Is our phone record private?
+ */
+static int private_record;
+
+
+/**
  * Continuation called to notify client about result of the
  * operation.
  *
@@ -115,9 +127,12 @@
                  const gchar *address)
 {
   struct GNUNET_GNSRECORD_Data rd;
-  struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
+  struct GNUNET_CRYPTO_EcdsaPublicKey rvalue;
+  const void *value;
   struct GNUNET_IDENTITY_Ego *ego;
-  const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_pkey;
+  size_t value_size;
+  const struct GNUNET_CRYPTO_EcdsaPrivateKey *zkey;
+  uint32_t type;
 
   if (NULL != add_contact_qe)
   {
@@ -126,32 +141,35 @@
     return;
   }
 
-  // FIXME: what should really be the preferred address format here?
-  // (CNAME? PKEY? PHONE?)
-  if (GNUNET_OK !=
-      GNUNET_CRYPTO_ecdsa_public_key_from_string (address,
-                                                  strlen (address),
-                                                  &pkey))
+  /* if we got a .zkey address, we create a PKEY record,
+     otherwise a CNAME record */
+  if (GNUNET_OK ==
+      GNUNET_GNSRECORD_zkey_to_pkey (address,
+                                     &rvalue))
   {
-    GCG_log (_("Adding contact failed: %s\n"),
-             _("invalid address"));
-    return;
+    type = GNUNET_GNSRECORD_TYPE_PKEY;
+    value = &rvalue;
+    value_size = sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey);
   }
-  rd.data = &pkey;
-  rd.data_size = sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey);
-  rd.record_type = GNUNET_GNSRECORD_TYPE_PKEY;
+  else
+  {
+    type = GNUNET_DNSPARSER_TYPE_CNAME;
+    value = address;
+    value_size = strlen (address) + 1;
+  }
+  rd.data = value;
+  rd.data_size = value_size;
+  rd.record_type = type;
   rd.flags
     = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION
     | GNUNET_GNSRECORD_RF_PRIVATE;
   rd.expiration_time
     = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
-  ego = GCG_EGOS_get_selected_ego ();
-  zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
-  /* FIXME: we should check if the 'name' already exists,
-     and not do this if it does... */
+  ego = GCG_ZONES_get_selected_zone ();
+  zkey = GNUNET_IDENTITY_ego_get_private_key (ego);
   add_contact_qe
     =  GNUNET_NAMESTORE_records_store (ns,
-                                       zone_pkey,
+                                       zkey,
                                        name,
                                        1, &rd,
                                        &add_contact_continuation, NULL);
@@ -170,8 +188,8 @@
  */
 static void
 add_phone_continuation (void *cls,
-                           int32_t success,
-                           const char *emsg)
+                        int32_t success,
+                        const char *emsg)
 {
   add_phone_qe = NULL;
   if (GNUNET_SYSERR == success)
@@ -256,6 +274,11 @@
   GNUNET_free_non_null (my_rd_data);
   phone_label = GNUNET_strdup (label);
   my_rd = *rd;
+  my_rd.expiration_time = expiration_time.rel_value_us;
+  my_rd.flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
+  if (GNUNET_YES == private_record)
+    my_rd.flags |= GNUNET_GNSRECORD_RF_PRIVATE;
+
   my_rd.data = my_rd_data = GNUNET_malloc (rd->data_size);
   memcpy (my_rd_data, rd->data, rd->data_size);
   add_waiting = GNUNET_YES;
@@ -367,13 +390,42 @@
 }
 
 
+
 /**
+ * Obtain namestore handle.
+ *
+ * @return handle to the namestore.
+ */
+struct GNUNET_NAMESTORE_Handle *
+GCG_IMPORT_get_namestore ()
+{
+  return ns;
+}
+
+
+/**
  * Initialize the import subsystem.
  */
 void
 GCG_IMPORT_init ()
 {
-  ns = GNUNET_NAMESTORE_connect (GCG_get_configuration ());
+  const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+  cfg = GCG_get_configuration ();
+  ns = GNUNET_NAMESTORE_connect (cfg);
+  private_record = GNUNET_CONFIGURATION_get_value_yesno (cfg,
+                                                         "CONVERSATION",
+                                                         "RECORD_IS_PRIVATE");
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_time (cfg,
+                                           "CONVERSATION",
+                                           "RECORD_EXPIRATION",
+                                           &expiration_time))
+  {
+    GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+                               "CONVERSATION",
+                               "RECORD_EXPIRATION");
+  }
 }
 
 

Modified: gnunet-gtk/src/conversation/gnunet-conversation-gtk_import.h
===================================================================
--- gnunet-gtk/src/conversation/gnunet-conversation-gtk_import.h        
2014-06-02 19:19:16 UTC (rev 33478)
+++ gnunet-gtk/src/conversation/gnunet-conversation-gtk_import.h        
2014-06-02 20:09:10 UTC (rev 33479)
@@ -59,6 +59,15 @@
 
 
 /**
+ * Obtain namestore handle.
+ *
+ * @return handle to the namestore.
+ */
+struct GNUNET_NAMESTORE_Handle *
+GCG_IMPORT_get_namestore (void);
+
+
+/**
  * Initialize the import subsystem.
  */
 void

Modified: gnunet-gtk/src/conversation/gnunet-conversation-gtk_phone.c
===================================================================
--- gnunet-gtk/src/conversation/gnunet-conversation-gtk_phone.c 2014-06-02 
19:19:16 UTC (rev 33478)
+++ gnunet-gtk/src/conversation/gnunet-conversation-gtk_phone.c 2014-06-02 
20:09:10 UTC (rev 33479)
@@ -1099,29 +1099,6 @@
 
 
 /**
- * User clicked the '> contact' button to move the selected
- * caller's information into our address book.
- *
- * @param button the button
- * @param user_data builder (unused)
- */
-void
-gnunet_conversation_gtk_use_current_button_clicked (GtkButton *button,
-                                                    gpointer *user_data)
-{
-  GNUNET_break (0); // FIXME: implement!
-  // need to determine desired label for the contact!
-  // => prompt user!?
-#if 0
-  const gchar *target;
-
-  target = gtk_entry_get_text (address_entry);
-  GSC_add_contact (label, address);
-#endif
-}
-
-
-/**
  * The "resume" button was clicked.  Resume a call!
  *
  * @param button the button

Added: gnunet-gtk/src/conversation/gnunet-conversation-gtk_use_current.c
===================================================================
--- gnunet-gtk/src/conversation/gnunet-conversation-gtk_use_current.c           
                (rev 0)
+++ gnunet-gtk/src/conversation/gnunet-conversation-gtk_use_current.c   
2014-06-02 20:09:10 UTC (rev 33479)
@@ -0,0 +1,233 @@
+/*
+     This file is part of GNUnet.
+     (C) 2014 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 3, 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/conversation/gnunet-conversation-gtk_use_current.c
+ * @brief logic to import caller ID into address book
+ * @author Christian Grothoff
+ */
+#include "gnunet-conversation-gtk.h"
+#include "gnunet-conversation-gtk_egos.h"
+#include "gnunet-conversation-gtk_history.h"
+#include "gnunet-conversation-gtk_import.h"
+#include "gnunet-conversation-gtk_log.h"
+#include "gnunet-conversation-gtk_phone.h"
+#include "gnunet-conversation-gtk_zones.h"
+
+
+/**
+ * Queue entry for the 'check exists' operation.
+ */
+static struct GNUNET_NAMESTORE_QueueEntry *qe;
+
+
+/**
+ * Process a record that was stored in the namestore.
+ *
+ * @param cls closure, NULL
+ * @param zone private key of the zone; NULL on disconnect
+ * @param label label of the records; NULL on disconnect
+ * @param rd_count number of entries in @a rd array, 0 if label was deleted
+ * @param rd array of records with data to store
+ */
+static void
+handle_existing_records (void *cls,
+                         const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
+                         const char *label,
+                         unsigned int rd_count,
+                         const struct GNUNET_GNSRECORD_Data *rd)
+{
+  GtkBuilder *builder = GTK_BUILDER (cls);
+  GtkWidget *b_add;
+
+  qe = NULL;
+  if (0 != rd_count)
+  {
+    GCG_log (_("Label `%s' in use\n"),
+             label);
+    return;
+  }
+  b_add = GTK_WIDGET (gtk_builder_get_object
+                      (builder,
+                       
"gnunet_conversation_gtk_enter_label_dialog_add_button"));
+  gtk_widget_set_sensitive (b_add, TRUE);
+}
+
+
+/**
+ * The user has edited the label; check if the new label
+ * is valid and available and update the sensitivity of
+ * the "add" button.
+ *
+ * @param editable the entry that changed
+ * @param user_data our builder
+ */
+void
+gnunet_conversation_gtk_enter_label_entry_changed_cb (GtkEditable *editable,
+                                                      gpointer user_data)
+{
+  GtkBuilder *builder = GTK_BUILDER (user_data);
+  GtkEntry *label_entry;
+  const gchar *label;
+  GtkWidget *b_add;
+  struct GNUNET_IDENTITY_Ego *ego;
+  const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey;
+
+  if (NULL != qe)
+  {
+    GNUNET_NAMESTORE_cancel (qe);
+    qe = NULL;
+  }
+  label_entry = GTK_ENTRY (gtk_builder_get_object
+                           (builder,
+                            ("gnunet_conversation_gtk_enter_label_entry")));
+  label = gtk_entry_get_text (label_entry);
+  b_add = GTK_WIDGET (gtk_builder_get_object
+                      (builder,
+                       
"gnunet_conversation_gtk_enter_label_dialog_add_button"));
+  gtk_widget_set_sensitive (b_add, FALSE);
+  if (GNUNET_OK !=
+      GNUNET_DNSPARSER_check_label (label))
+  {
+    GCG_log (_("Invalid label `%s'\n"),
+             label);
+    return;
+  }
+  ego = GCG_ZONES_get_selected_zone ();
+  pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
+  qe = GNUNET_NAMESTORE_records_lookup (GCG_IMPORT_get_namestore (),
+                                        pkey,
+                                        label,
+                                        &handle_existing_records,
+                                        builder);
+}
+
+
+/**
+ * The user has clicked the "add" button, close the dialog and
+ * complete the "add contact" operation.
+ *
+ * @param button the button
+ * @param user_data our builder
+ */
+void
+gnunet_conversation_gtk_enter_label_dialog_add_button_clicked_cb (GtkButton 
*button,
+                                                                  gpointer 
*user_data)
+{
+  GtkBuilder *builder = GTK_BUILDER (user_data);
+  GtkWidget *dialog;
+  const gchar *target;
+  const gchar *label;
+  GtkEntry *address_entry;
+  GtkEntry *label_entry;
+
+  address_entry = GTK_ENTRY (GCG_get_main_window_object
+                             ("gnunet_conversation_gtk_address_entry"));
+  target = gtk_entry_get_text (address_entry);
+  label_entry = GTK_ENTRY (gtk_builder_get_object
+                           (builder,
+                            ("gnunet_conversation_gtk_enter_label_entry")));
+  label = gtk_entry_get_text (label_entry);
+  GSC_add_contact (label, target);
+  dialog = GTK_WIDGET (gtk_builder_get_object
+                      (builder,
+                       "gnunet_conversation_gtk_enter_label_window"));
+  gtk_widget_destroy (GTK_WIDGET (dialog));
+  g_object_unref (G_OBJECT (builder));
+}
+
+
+/**
+ * The user has clicked the "cancel" button, close the dialog and
+ * abort the "add contact" operation.
+ *
+ * @param button the button
+ * @param user_data our builder
+ */
+void
+gnunet_conversation_gtk_enter_label_dialog_cancel_button_clicked_cb (GtkButton 
*button,
+                                                                     gpointer 
*user_data)
+{
+  GtkBuilder *builder = GTK_BUILDER (user_data);
+  GtkWidget *dialog;
+
+  dialog = GTK_WIDGET (gtk_builder_get_object
+                      (builder,
+                       "gnunet_conversation_gtk_enter_label_window"));
+  gtk_widget_destroy (GTK_WIDGET (dialog));
+  g_object_unref (G_OBJECT (builder));
+}
+
+
+/**
+ * User closed the window of the enter label dialog.
+ *
+ * @param widget the window
+ * @param event the deletion event
+ * @param user_data the 'GtkBuilder' of the URI dialog
+ * @return FALSE (allow destruction)
+ */
+gboolean
+gnunet_conversation_gtk_enter_label_window_delete_event_cb (GtkWidget *widget,
+                                                            GdkEvent *event,
+                                                            gpointer user_data)
+{
+  GtkBuilder *builder = GTK_BUILDER (user_data);
+
+  g_object_unref (G_OBJECT (builder));
+  return FALSE;
+}
+
+
+/**
+ * User clicked the '> contact' button to move the selected
+ * caller's information into our address book.
+ *
+ * @param button the button
+ * @param user_data main loop context (unused)
+ */
+void
+gnunet_conversation_gtk_use_current_button_clicked (GtkButton *button,
+                                                    gpointer *user_data)
+{
+  GtkBuilder *builder;
+  GtkWidget *dialog;
+  GtkWidget *toplevel;
+
+  builder =
+    GNUNET_GTK_get_new_builder ("gnunet_conversation_gtk_enter_label.glade",
+                                NULL);
+  if (NULL == builder)
+  {
+    GNUNET_break (0);
+    return;
+  }
+  dialog = GTK_WIDGET (gtk_builder_get_object
+                      (builder,
+                       "gnunet_conversation_gtk_enter_label_window"));
+  toplevel = gtk_widget_get_toplevel (GTK_WIDGET (button));
+  if (GTK_IS_WINDOW (toplevel))
+    gtk_window_set_transient_for (GTK_WINDOW (dialog),
+                                  GTK_WINDOW (toplevel));
+  gtk_widget_show (dialog);
+}
+
+
+/* end of gnunet-conversation-gtk_use_current.c */




reply via email to

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