aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-11-05 21:12:54 +0000
committerChristian Grothoff <christian@grothoff.org>2013-11-05 21:12:54 +0000
commit5f9b6eb999eb797d39a2389c7f991742ad58f139 (patch)
tree441ee17be078ccff3a20b88b917b443e67e47e08
parent156bad436c7163224fd71eef0a351dbf28c345b7 (diff)
downloadgnunet-gtk-5f9b6eb999eb797d39a2389c7f991742ad58f139.tar.gz
gnunet-gtk-5f9b6eb999eb797d39a2389c7f991742ad58f139.zip
-use more compact QR encoding, if possible
-rw-r--r--src/namestore/gnunet-namestore-gtk.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/src/namestore/gnunet-namestore-gtk.c b/src/namestore/gnunet-namestore-gtk.c
index e54d0972..88af45b0 100644
--- a/src/namestore/gnunet-namestore-gtk.c
+++ b/src/namestore/gnunet-namestore-gtk.c
@@ -453,33 +453,50 @@ create_qrcode (unsigned int scale)
453 const char *dir; 453 const char *dir;
454 char *fn; 454 char *fn;
455 unsigned int size; 455 unsigned int size;
456 char *upper;
456 457
457 qri = QRinput_new2 (0, QR_ECLEVEL_Q); 458 qri = QRinput_new2 (0, QR_ECLEVEL_M);
458 if (NULL == qri) 459 if (NULL == qri)
459 { 460 {
460 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "QRinput_new2"); 461 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
462 "QRinput_new2");
461 return NULL; 463 return NULL;
462 } 464 }
463 entry = GTK_ENTRY (get_object ("gnunet_namestore_gtk_pseu_entry")); 465 entry = GTK_ENTRY (get_object ("gnunet_namestore_gtk_pseu_entry"));
464 pseu = gtk_entry_get_text (GTK_ENTRY(entry)); 466 pseu = gtk_entry_get_text (GTK_ENTRY(entry));
465 GNUNET_asprintf (&str, 467 GNUNET_asprintf (&str,
466 "gnunet://gns/%s/%s\n", 468 "gnunet://gns/%s/%s",
467 GNUNET_GNSRECORD_z2s (&pubkey), 469 GNUNET_GNSRECORD_z2s (&pubkey),
468 pseu); 470 pseu);
469 if (0 != QRinput_append (qri, 471 upper = GNUNET_strdup (str);
470 QR_MODE_8, 472 GNUNET_STRINGS_utf8_toupper (str,
471 strlen (str), 473 upper);
472 (unsigned char*) str)) 474 /* first try encoding as uppercase-only alpha-numerical
473 { 475 QR code (much smaller encoding); if that fails, also
474 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "QRinput_append"); 476 try using binary encoding (in case nick contains
477 special characters). */
478 if ( (0 != QRinput_append (qri,
479 QR_MODE_AN,
480 strlen (upper),
481 (unsigned char*) upper)) &&
482 (0 != QRinput_append (qri,
483 QR_MODE_8,
484 strlen (str),
485 (unsigned char*) str)) )
486 {
487 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
488 "QRinput_append");
489 GNUNET_free (upper);
475 GNUNET_free (str); 490 GNUNET_free (str);
476 return NULL; 491 return NULL;
477 } 492 }
493 GNUNET_free (upper);
478 GNUNET_free (str); 494 GNUNET_free (str);
479 qrc = QRcode_encodeInput (qri); 495 qrc = QRcode_encodeInput (qri);
480 if (NULL == qrc) 496 if (NULL == qrc)
481 { 497 {
482 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "QRcode_encodeInput"); 498 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
499 "QRcode_encodeInput");
483 QRinput_free (qri); 500 QRinput_free (qri);
484 return NULL; 501 return NULL;
485 } 502 }
@@ -530,7 +547,8 @@ setup_qrcode ()
530 pb = create_qrcode (2); 547 pb = create_qrcode (2);
531 if (NULL == pb) 548 if (NULL == pb)
532 { 549 {
533 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to initialize QR-code pixbuf")); 550 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
551 _("Failed to initialize QR-code pixbuf\n"));
534 return; 552 return;
535 } 553 }
536 image = GTK_IMAGE (get_object ("gnunet_namestore_gtk_qr_image")); 554 image = GTK_IMAGE (get_object ("gnunet_namestore_gtk_qr_image"));