[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r22316 - in gnunet-gtk: contrib src/setup
From: |
gnunet |
Subject: |
[GNUnet-SVN] r22316 - in gnunet-gtk: contrib src/setup |
Date: |
Tue, 26 Jun 2012 21:37:49 +0200 |
Author: grothoff
Date: 2012-06-26 21:37:49 +0200 (Tue, 26 Jun 2012)
New Revision: 22316
Modified:
gnunet-gtk/contrib/gnunet_setup_gtk_main_window.glade
gnunet-gtk/src/setup/gnunet-setup-gns.c
Log:
-qr code saveas and decoding via online service work
Modified: gnunet-gtk/contrib/gnunet_setup_gtk_main_window.glade
===================================================================
--- gnunet-gtk/contrib/gnunet_setup_gtk_main_window.glade 2012-06-26
19:37:18 UTC (rev 22315)
+++ gnunet-gtk/contrib/gnunet_setup_gtk_main_window.glade 2012-06-26
19:37:49 UTC (rev 22316)
@@ -16,6 +16,21 @@
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
+ <object class="GtkAdjustment"
id="GNUNET_setup_hostlist_server_port_adjustment">
+ <property name="lower">1</property>
+ <property name="upper">65535</property>
+ <property name="value">8080</property>
+ <property name="step_increment">1</property>
+ <property name="page_increment">10</property>
+ </object>
+ <object class="GtkListStore" id="GNUNET_setup_hostlist_url_liststore">
+ <columns>
+ <!-- column-name url -->
+ <column type="gchararray"/>
+ <!-- column-name editable -->
+ <column type="gboolean"/>
+ </columns>
+ </object>
<object class="GtkDialog" id="GNUNET_setup_dialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>
@@ -4492,6 +4507,8 @@
</child>
<child>
<object class="GtkImage"
id="GNUNET_setup_gns_qr_image">
+ <property name="width_request">64</property>
+ <property name="height_request">64</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text"
translatable="yes">QR code for the selected zone</property>
@@ -4931,21 +4948,6 @@
</row>
</data>
</object>
- <object class="GtkAdjustment"
id="GNUNET_setup_hostlist_server_port_adjustment">
- <property name="lower">1</property>
- <property name="upper">65535</property>
- <property name="value">8080</property>
- <property name="step_increment">1</property>
- <property name="page_increment">10</property>
- </object>
- <object class="GtkListStore" id="GNUNET_setup_hostlist_url_liststore">
- <columns>
- <!-- column-name url -->
- <column type="gchararray"/>
- <!-- column-name editable -->
- <column type="gboolean"/>
- </columns>
- </object>
<object class="GtkAdjustment" id="GNUNET_setup_min_friends_adjustment">
<property name="upper">9999</property>
<property name="step_increment">1</property>
Modified: gnunet-gtk/src/setup/gnunet-setup-gns.c
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup-gns.c 2012-06-26 19:37:18 UTC (rev
22315)
+++ gnunet-gtk/src/setup/gnunet-setup-gns.c 2012-06-26 19:37:49 UTC (rev
22316)
@@ -61,7 +61,7 @@
#define PSEU_EMPTY_STR gettext_noop ("<not set>")
/**
- * Height and width of the QR code
+ * Height and width of the QR code we display
*/
#define QRCODE_IMAGE_SIZE 64
@@ -219,8 +219,125 @@
static int iteration;
+#if HAVE_QRENCODE_H
+#include <qrencode.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
/**
+ * Create the QR code image for our zone.
+ *
+ * @param size height and width of the image to create
+ * @return NULL on error
+ */
+static GdkPixbuf *
+create_qrcode (unsigned int size)
+{
+ QRinput * qri;
+ QRcode *qrc;
+ char *str;
+ const gchar * pseu;
+ GtkEntry * entry;
+ GdkPixbuf *pb;
+ 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 NULL;
+ }
+ 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 NULL;
+ }
+ GNUNET_free (str);
+ qrc = QRcode_encodeInput (qri);
+ if (NULL == qrc)
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "QRcode_encodeInput");
+ QRinput_free (qri);
+ return NULL;
+ }
+ /* 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,
+ size, size,
+ NULL);
+ GNUNET_free (fn);
+ if (NULL == pb)
+ {
+ QRinput_free (qri);
+ return NULL;
+ }
+ pixels = gdk_pixbuf_get_pixels (pb);
+ n_channels = gdk_pixbuf_get_n_channels (pb);
+ for (x=0;x<size;x++)
+ for (y=0;y<size;y++)
+ {
+ off = (x * qrc->width / size) +
+ (y * qrc->width / size) * qrc->width;
+ for (c = 0; c < n_channels; c++)
+ pixels[(y * size + x) * n_channels + c] = (0 == (qrc->data[off] & 1)) ?
0xFF : 0;
+ }
+ QRcode_free (qrc);
+ QRinput_free (qri);
+ return pb;
+}
+
+
+/**
+ * Create the QR code image for our zone.
+ */
+static void
+setup_qrcode ()
+{
+ GdkPixbuf *pb;
+ GtkImage *image;
+
+ pb = create_qrcode (QRCODE_IMAGE_SIZE);
+ if (NULL == pb)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to initialize QR-code
pixbuf"));
+ return;
+ }
+ image = GTK_IMAGE (GNUNET_SETUP_get_object ("GNUNET_setup_gns_qr_image"));
+ if (NULL == image)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ gtk_image_set_from_pixbuf (image, pb);
+ g_object_unref (pb);
+}
+
+#endif
+
+
+/**
* Context we use for making changes to the namestore.
* (closure for 'add_new_records_after_removing_old_records').
*/
@@ -1312,7 +1429,6 @@
gpointer user_data)
{
GtkBuilder *builder = user_data;
- GtkImage *image;
GdkPixbuf *pb;
char *filename;
@@ -1324,14 +1440,18 @@
}
filename =
GNUNET_GTK_filechooser_get_filename_utf8 (GTK_FILE_CHOOSER (dialog));
- image = GTK_IMAGE (GNUNET_SETUP_get_object ("GNUNET_setup_gns_qr_image"));
- pb = gtk_image_get_pixbuf (image);
-
+ pb = create_qrcode (512);
+ if (NULL == pb)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to initialize QR-code
pixbuf"));
+ return;
+ }
gdk_pixbuf_save (pb,
filename,
"png",
NULL, NULL);
g_free (filename);
+ g_object_unref (pb);
gtk_widget_destroy (GTK_WIDGET (dialog));
g_object_unref (G_OBJECT (builder));
}
@@ -1411,7 +1531,9 @@
iteration = GNUNET_NO;
GNUNET_free (zc_ctx->label);
GNUNET_free (zc_ctx);
-
+#if HAVE_QRENCODE_H
+ setup_qrcode ();
+#endif
gtk_widget_hide (GTK_WIDGET (GNUNET_SETUP_get_object
("GNUNET_setup_gns_status_label")));
gtk_widget_show (GTK_WIDGET (GNUNET_SETUP_get_object
("GNUNET_setup_gns_main_scrolledwindow")));
return;
@@ -1573,7 +1695,9 @@
{
gtk_entry_set_text (GTK_ENTRY(editable), PSEU_EMPTY_STR);
}
-
+#if HAVE_QRENCODE_H
+ setup_qrcode ();
+#endif
}
@@ -1595,105 +1719,7 @@
}
-#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.
*/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r22316 - in gnunet-gtk: contrib src/setup,
gnunet <=