gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r22312 - in gnunet-gtk: . contrib src/setup
Date: Tue, 26 Jun 2012 21:03:44 +0200

Author: grothoff
Date: 2012-06-26 21:03:44 +0200 (Tue, 26 Jun 2012)
New Revision: 22312

Added:
   gnunet-gtk/contrib/qr_dummy.png
Modified:
   gnunet-gtk/configure.ac
   gnunet-gtk/contrib/Makefile.am
   gnunet-gtk/contrib/gnunet_setup_gtk_main_window.glade
   gnunet-gtk/src/setup/Makefile.am
   gnunet-gtk/src/setup/gnunet-setup-gns.c
Log:
-adding code to generate QR codes

Modified: gnunet-gtk/configure.ac
===================================================================
--- gnunet-gtk/configure.ac     2012-06-26 18:00:49 UTC (rev 22311)
+++ gnunet-gtk/configure.ac     2012-06-26 19:03:44 UTC (rev 22312)
@@ -175,6 +175,33 @@
 fi
 
 
+# test for libqrencode
+qrencode=0
+QR_LIBS="-lqrencode"   
+AC_MSG_CHECKING(for libqrencode)
+AC_ARG_WITH(qrencode,
+   [  --with-qrencode=PFX    Base of libqrencode installation],
+   [AC_MSG_RESULT([$with_extractor])
+    case $with_qrencode in
+      no)
+        ;;
+      yes)
+        AC_CHECK_HEADERS(qrencode.h,qrencode=1)
+        ;;
+      *)
+        CPPFLAGS="-I$with_qrencode/include $CPPFLAGS"
+        QR_CFLAGS="-I$with_qrencode/include"
+        QR_LIBS="-L$with_qrencode/lib -lqrencode"
+        AC_CHECK_HEADERS(qrencode.h,qrencode=1)
+        ;;
+    esac
+   ],
+   [AC_MSG_RESULT([--with-qrencode not specified])
+    AC_CHECK_HEADERS(qrencode.h,qrencode=1)])
+
+AC_SUBST(QR_CFLAGS)
+AC_SUBST(QR_LIBS)
+
 AC_MSG_CHECKING(for gtk)
 check_for_3=3.0.0
 check_for_2=false
@@ -482,3 +509,8 @@
 contrib/gnunet_statistics_gtk_about_window.glade
 contrib/gnunet_setup_about_window.glade
 ])
+
+if test "$qrencode" != 1 
+then
+ AC_MSG_WARN([gnunet-setup will not include QR support])
+fi

Modified: gnunet-gtk/contrib/Makefile.am
===================================================================
--- gnunet-gtk/contrib/Makefile.am      2012-06-26 18:00:49 UTC (rev 22311)
+++ gnunet-gtk/contrib/Makefile.am      2012-06-26 19:03:44 UTC (rev 22312)
@@ -15,6 +15,7 @@
   $(IMAGES)
 
 pkgdata_DATA = \
+  qr_dummy.png \
   downloading.gif \
   downloading_not_receiving.gif \
   downloaded.gif \

Modified: gnunet-gtk/contrib/gnunet_setup_gtk_main_window.glade
===================================================================
--- gnunet-gtk/contrib/gnunet_setup_gtk_main_window.glade       2012-06-26 
18:00:49 UTC (rev 22311)
+++ gnunet-gtk/contrib/gnunet_setup_gtk_main_window.glade       2012-06-26 
19:03:44 UTC (rev 22312)
@@ -4480,7 +4480,7 @@
                               </packing>
                             </child>
                             <child>
-                              <object class="GtkVSeparator" id="vseparator3">
+                              <object class="GtkVSeparator" 
id="GNUNET_setup_qr_vseparator">
                                 <property name="visible">True</property>
                                 <property name="can_focus">False</property>
                               </object>
@@ -4589,24 +4589,6 @@
                           </object>
                         </child>
                         <child>
-                          <object class="GtkTreeViewColumn" 
id="GNUNET_setup_gns_ispublic_treeviewcolumn">
-                            <property name="sizing">fixed</property>
-                            <property name="fixed_width">50</property>
-                            <property name="title">Public</property>
-                            <property name="clickable">True</property>
-                            <child>
-                              <object class="GtkCellRendererToggle" 
id="GNUNET_setup_gns_ispublic_cellrenderertoggle">
-                                <signal name="toggled" 
handler="GNUNET_setup_gns_ispublic_cellrenderertoggle_toggled_cb" swapped="no"/>
-                              </object>
-                              <attributes>
-                                <attribute name="sensitive">11</attribute>
-                                <attribute name="visible">11</attribute>
-                                <attribute name="active">1</attribute>
-                              </attributes>
-                            </child>
-                          </object>
-                        </child>
-                        <child>
                           <object class="GtkTreeViewColumn" 
id="GNUNET_setup_gns_type_treeviewcolumn">
                             <property name="sizing">autosize</property>
                             <property name="fixed_width">90</property>
@@ -4630,6 +4612,27 @@
                           </object>
                         </child>
                         <child>
+                          <object class="GtkTreeViewColumn" 
id="GNUNET_setup_gns_value_treeviewcolumn">
+                            <property name="sizing">autosize</property>
+                            <property name="title">Value</property>
+                            <property name="expand">True</property>
+                            <property name="clickable">True</property>
+                            <property name="sort_column_id">7</property>
+                            <child>
+                              <object class="GtkCellRendererText" 
id="GNUNET_setup_gns_value_cellrenderertext">
+                                <signal name="edited" 
handler="GNUNET_setup_gns_value_cellrenderertext_edited_cb" swapped="no"/>
+                              </object>
+                              <attributes>
+                                <attribute name="sensitive">11</attribute>
+                                <attribute name="visible">10</attribute>
+                                <attribute name="background">8</attribute>
+                                <attribute name="editable">11</attribute>
+                                <attribute name="text">7</attribute>
+                              </attributes>
+                            </child>
+                          </object>
+                        </child>
+                        <child>
                           <object class="GtkTreeViewColumn" 
id="GNUNET_setup_gns_expiration_treeviewcolumn">
                             <property name="title">Expiration</property>
                             <property name="clickable">True</property>
@@ -4651,22 +4654,19 @@
                           </object>
                         </child>
                         <child>
-                          <object class="GtkTreeViewColumn" 
id="GNUNET_setup_gns_value_treeviewcolumn">
-                            <property name="sizing">autosize</property>
-                            <property name="title">Value</property>
-                            <property name="expand">True</property>
+                          <object class="GtkTreeViewColumn" 
id="GNUNET_setup_gns_ispublic_treeviewcolumn">
+                            <property name="sizing">fixed</property>
+                            <property name="fixed_width">50</property>
+                            <property name="title">Public</property>
                             <property name="clickable">True</property>
-                            <property name="sort_column_id">7</property>
                             <child>
-                              <object class="GtkCellRendererText" 
id="GNUNET_setup_gns_value_cellrenderertext">
-                                <signal name="edited" 
handler="GNUNET_setup_gns_value_cellrenderertext_edited_cb" swapped="no"/>
+                              <object class="GtkCellRendererToggle" 
id="GNUNET_setup_gns_ispublic_cellrenderertoggle">
+                                <signal name="toggled" 
handler="GNUNET_setup_gns_ispublic_cellrenderertoggle_toggled_cb" swapped="no"/>
                               </object>
                               <attributes>
                                 <attribute name="sensitive">11</attribute>
-                                <attribute name="visible">10</attribute>
-                                <attribute name="background">8</attribute>
-                                <attribute name="editable">11</attribute>
-                                <attribute name="text">7</attribute>
+                                <attribute name="visible">11</attribute>
+                                <attribute name="active">1</attribute>
                               </attributes>
                             </child>
                           </object>

Added: gnunet-gtk/contrib/qr_dummy.png
===================================================================
(Binary files differ)


Property changes on: gnunet-gtk/contrib/qr_dummy.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Modified: gnunet-gtk/src/setup/Makefile.am
===================================================================
--- gnunet-gtk/src/setup/Makefile.am    2012-06-26 18:00:49 UTC (rev 22311)
+++ gnunet-gtk/src/setup/Makefile.am    2012-06-26 19:03:44 UTC (rev 22312)
@@ -34,7 +34,7 @@
   gnunet-setup-hostlist-server.c 
 gnunet_setup_LDADD = \
   $(top_builddir)/src/lib/libgnunetgtk.la \
-  @GTK_LIBS@ @GNUNET_LIBS@ @GLADE_LIBS@ \
+  @GTK_LIBS@ @GNUNET_LIBS@ @GLADE_LIBS@ @QR_CFLAGS@ @QR_LIBS@ \
   $(WINLIBS) \
   -lgnunetutil -lgnunetnat -lgnunetnamestore \
   $(INTLLIBS) 

Modified: gnunet-gtk/src/setup/gnunet-setup-gns.c
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup-gns.c     2012-06-26 18:00:49 UTC (rev 
22311)
+++ gnunet-gtk/src/setup/gnunet-setup-gns.c     2012-06-26 19:03:44 UTC (rev 
22312)
@@ -28,7 +28,6 @@
 #include <gnunet/gnunet_namestore_service.h>
 #include <gnunet/gnunet_dnsparser_lib.h>
 
-
 /**
  * Text we use for the 'name' entry for the user to select
  * for creating a new name.
@@ -61,8 +60,11 @@
  */
 #define PSEU_EMPTY_STR gettext_noop ("<not set>")
 
+/**
+ * Height and width of the QR code
+ */
+#define QRCODE_IMAGE_SIZE 64
 
-
 /**
  * Columns in the gns model.
  */
@@ -1542,7 +1544,105 @@
 }
 
 
+#if HAVE_QRENCODE_H
+#include <qrencode.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+
 /**
+ * Create the QR code image for our zone.
+ */
+static void 
+setup_qrcode ()
+{
+  QRinput * qri;
+  QRcode *qrc;
+  char *str;
+  const gchar * pseu;
+  GtkEntry * entry;
+  GdkPixbuf *pb;
+  GtkImage *image;
+  unsigned int x;
+  unsigned int y;
+  unsigned int off;
+  guchar *pixels;
+  int n_channels;
+  int c;
+  const char *dir;
+  char *fn;
+
+  qri = QRinput_new2 (0, QR_ECLEVEL_Q);
+  if (NULL == qri)
+  {
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "QRinput_new2");
+    return;
+  }
+  entry = GTK_ENTRY (GNUNET_SETUP_get_object ("GNUNET_setup_gns_pseu_entry"));
+  pseu = gtk_entry_get_text (GTK_ENTRY(entry));    
+  GNUNET_asprintf (&str,
+                  "gnunet://gns/%s/%s\n",
+                  zone_as_string,
+                  pseu);
+  if (0 != QRinput_append (qri,
+                          QR_MODE_8,
+                          strlen (str),
+                          (unsigned char*) str))
+  {
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "QRinput_append");
+    GNUNET_free (str);
+    return;
+  }
+  GNUNET_free (str);
+  qrc = QRcode_encodeInput (qri);
+  if (NULL == qrc)
+  {
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "QRcode_encodeInput");
+    QRinput_free (qri);
+    return;
+  }
+  /* We use a trick to create a pixbuf in a way that works for both Gtk2 and 
Gtk3
+     by loading a dummy file from disk; all other methods are not portable to 
both
+     Gtk2 and Gtk3. */
+  dir = GNUNET_GTK_get_data_dir ();
+  GNUNET_asprintf (&fn,
+                  "%s%s",
+                  dir,
+                  "qr_dummy.png");
+  pb = gdk_pixbuf_new_from_file_at_size (fn,
+                                        QRCODE_IMAGE_SIZE, QRCODE_IMAGE_SIZE,
+                                        NULL);
+  GNUNET_free (fn);
+  if (NULL == pb)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to initialize QR-code 
pixbuf"));
+    QRinput_free (qri);
+    return;
+  }
+  pixels = gdk_pixbuf_get_pixels (pb);
+  n_channels = gdk_pixbuf_get_n_channels (pb);
+  for (x=0;x<QRCODE_IMAGE_SIZE;x++)
+    for (y=0;y<QRCODE_IMAGE_SIZE;y++)
+    {
+      off = (x * qrc->width / QRCODE_IMAGE_SIZE) +
+       (y * qrc->width / QRCODE_IMAGE_SIZE) * qrc->width;
+      for (c = 0; c < n_channels; c++)
+       pixels[(y * QRCODE_IMAGE_SIZE + x) * n_channels + c] = (0 == 
(qrc->data[off] & 1)) ? 0 : 0xFF;
+    }
+  image = GTK_IMAGE (GNUNET_SETUP_get_object ("GNUNET_setup_gns_qr_image"));
+  if (NULL == image)
+  {
+    GNUNET_break (0);
+    QRcode_free (qrc);
+    QRinput_free (qri);
+    return;
+  }
+  gtk_image_set_from_pixbuf (image, pb);
+  QRcode_free (qrc);
+  QRinput_free (qri);
+}
+#endif
+
+
+/**
  * Connect to the namestore and initialize the main
  * GNS tree view.
  */
@@ -1615,6 +1715,13 @@
   tv =  GTK_TREE_VIEW (GNUNET_SETUP_get_object 
("GNUNET_setup_gns_main_treeview"));
   tm = GTK_TREE_MODEL(ts);  
   zone_as_string = GNUNET_strdup ((char *) &shenc);
+#if HAVE_QRENCODE_H
+  setup_qrcode ();
+#else
+  gtk_widget_hide (GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_gns_qr_image")));
+  gtk_widget_hide (GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_gns_qr_saveas_button")));
+  gtk_widget_hide (GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_gns_qr_vseparator")));
+#endif
   label = g_markup_printf_escaped (_("<b>Editing zone %s</b>"),
                                   zone_as_string);
   gtk_label_set_markup (GTK_LABEL (GNUNET_SETUP_get_object 
("GNUNET_setup_gns_zone_label")),
@@ -1622,7 +1729,6 @@
   g_free (label);
 
   /* Load zone from namestore! */
-
   /* Append a top level row and leave it empty */
   gtk_tree_store_insert_with_values (ts, &toplevel, NULL, 0,
                                      GNS_TREESTORE_COL_NAME, _(NEW_NAME_STR),




reply via email to

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