gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis-gtk] branch master updated: add qr code logic


From: gnunet
Subject: [taler-anastasis-gtk] branch master updated: add qr code logic
Date: Fri, 12 Mar 2021 14:50:56 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository anastasis-gtk.

The following commit(s) were added to refs/heads/master by this push:
     new 3788266  add qr code logic
3788266 is described below

commit 3788266715ffc70780e08e06019eeac90b28f315
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Fri Mar 12 14:50:54 2021 +0100

    add qr code logic
---
 configure.ac                                       |  34 ++++
 contrib/Makefile.am                                |   1 +
 contrib/qr_dummy.png                               | Bin 0 -> 239 bytes
 po/POTFILES.in                                     |   6 +
 src/anastasis/Makefile.am                          |   3 +
 src/anastasis/anastasis-gtk_action.c               | 183 ++++++++++++++++++++-
 .../anastasis-gtk_handle-core-secret-changed.c     |  46 ++++++
 7 files changed, 271 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index b98502f..50faaee 100644
--- a/configure.ac
+++ b/configure.ac
@@ -215,6 +215,40 @@ AS_IF([test "x$gnunet" = "x0"],
  [AC_MSG_ERROR([anastasis-gtk requires GNUnet])])
 
 
+AC_SUBST(GNUNET_CFLAGS)
+AC_SUBST(GNUNET_CPPFLAGS)
+AC_SUBST(GNUNET_LIBS)
+
+
+# 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_qrencode])
+    AS_CASE([$with_qrencode],
+      [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)
+      ])
+   ],
+   [AC_MSG_RESULT([--with-qrencode not specified])
+    AC_CHECK_HEADERS(qrencode.h,qrencode=1)])
+
+AS_IF([test "$qrencode" != 1],
+ [AC_MSG_ERROR([anastasis-gtk requires libqrencode])])
+
+AC_SUBST(QR_CFLAGS)
+AC_SUBST(QR_LIBS)
+
+
 # test for libanastasis
 anastasis=0
 AC_MSG_CHECKING(for libanastasis)
diff --git a/contrib/Makefile.am b/contrib/Makefile.am
index 49a6b64..8d42ab6 100644
--- a/contrib/Makefile.am
+++ b/contrib/Makefile.am
@@ -6,6 +6,7 @@ SUBDIRS = .
 pkgdatadir= $(prefix)/share/anastasis/
 
 IMAGES = \
+  qr_dummy.png \
   logo.svg \
   country_selection.png \
   continent_selection.png \
diff --git a/contrib/qr_dummy.png b/contrib/qr_dummy.png
new file mode 100644
index 0000000..9c0ffb3
Binary files /dev/null and b/contrib/qr_dummy.png differ
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 188b16f..63e5aae 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -9,11 +9,17 @@ 
src/anastasis/anastasis-gtk_handle-auth-edit-provider-clicked.c
 src/anastasis/anastasis-gtk_handle-backup-button-clicked.c
 src/anastasis/anastasis-gtk_handle-continent-activated.c
 src/anastasis/anastasis-gtk_handle-continent-unselected.c
+src/anastasis/anastasis-gtk_handle-core-secret-changed.c
 src/anastasis/anastasis-gtk_handle-country-activated.c
 src/anastasis/anastasis-gtk_handle-country-unselected.c
 src/anastasis/anastasis-gtk_handle-identity-changed.c
 src/anastasis/anastasis-gtk_handle-main-window-back-clicked.c
 src/anastasis/anastasis-gtk_handle-main-window-forward-clicked.c
+src/anastasis/anastasis-gtk_handle-method-email.c
+src/anastasis/anastasis-gtk_handle-method-post.c
+src/anastasis/anastasis-gtk_handle-method-question.c
+src/anastasis/anastasis-gtk_handle-method-sms.c
+src/anastasis/anastasis-gtk_handle-method-video.c
 src/anastasis/anastasis-gtk_handle-secret-buttons.c
 src/anastasis/anastasis-gtk_helper.c
 src/anastasis/anastasis-gtk_io.c
diff --git a/src/anastasis/Makefile.am b/src/anastasis/Makefile.am
index 27d081c..b738dd3 100644
--- a/src/anastasis/Makefile.am
+++ b/src/anastasis/Makefile.am
@@ -41,6 +41,7 @@ anastasis_gtk_SOURCES = \
 anastasis_gtk_LDADD = \
   @GTK_LIBS@ \
   @GLADE_LIBS@ @GNUNET_LIBS@ \
+  @QR_LIBS@ \
   -lgnunetgtk \
   -lgnunetutil \
   -lgnunetcurl \
@@ -51,5 +52,7 @@ anastasis_gtk_LDADD = \
   -lanastasisrest \
   -lanastasisredux \
   $(INTLLIBS)
+anastasis_gtk_CFLAGS = \
+  @QR_CFLAGS@
 anastasis_gtk_LDFLAGS = \
   -export-dynamic
diff --git a/src/anastasis/anastasis-gtk_action.c 
b/src/anastasis/anastasis-gtk_action.c
index 42ebc34..cd506cc 100644
--- a/src/anastasis/anastasis-gtk_action.c
+++ b/src/anastasis/anastasis-gtk_action.c
@@ -30,6 +30,8 @@
 #include "anastasis-gtk_helper.h"
 #include "anastasis-gtk_handle-identity-changed.h"
 #include <jansson.h>
+#include <qrencode.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
 
 
 /**
@@ -859,6 +861,137 @@ action_secret_editing (void)
 }
 
 
+/**
+ * Create the QR code image for our zone.
+ *
+ * @param scale factor for scaling up the size of the image to create
+ * @param text text to encode
+ * @return NULL on error
+ */
+static GdkPixbuf *
+create_qrcode (unsigned int scale,
+               const char *text)
+{
+  QRinput *qri;
+  QRcode *qrc;
+  GdkPixbuf *pb;
+  guchar *pixels;
+  int n_channels;
+  const char *dir;
+  char *fn;
+  unsigned int size;
+
+  qri = QRinput_new2 (0, QR_ECLEVEL_M);
+  if (NULL == qri)
+  {
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "QRinput_new2");
+    return NULL;
+  }
+  /* first try encoding as uppercase-only alpha-numerical
+     QR code (much smaller encoding); if that fails, also
+     try using binary encoding (in case nick contains
+     special characters). */
+  if ((0 != QRinput_append (qri,
+                            QR_MODE_AN,
+                            strlen (text),
+                            (unsigned char *) text)) &&
+      (0 != QRinput_append (qri,
+                            QR_MODE_8,
+                            strlen (text),
+                            (unsigned char *) text)))
+  {
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
+                         "QRinput_append");
+    return NULL;
+  }
+  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");
+  size = qrc->width * scale;
+  size += 8 - (size % 8);
+  pb = gdk_pixbuf_new_from_file_at_size (fn,
+                                         size,
+                                         size,
+                                         NULL);
+  GNUNET_free (fn);
+  if (NULL == pb)
+  {
+    QRcode_free (qrc);
+    QRinput_free (qri);
+    return NULL;
+  }
+  pixels = gdk_pixbuf_get_pixels (pb);
+  n_channels = gdk_pixbuf_get_n_channels (pb);
+  for (unsigned int x = 0; x < size; x++)
+    for (unsigned int y = 0; y < size; y++)
+    {
+      unsigned int off =
+        (x * qrc->width / size) + (y * qrc->width / size) * qrc->width;
+      for (int 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.
+ *
+ * @param text text to encode
+ * @return NULL on error
+ */
+static GdkPixbuf *
+setup_qrcode (const char *widget,
+              const char *text)
+{
+  GtkWidget *image;
+  GdkScreen *screen;
+  GtkSettings *settings;
+  gint dpi;
+  int scale;
+
+  image = GTK_WIDGET (GCG_get_main_window_object (widget));
+  if (NULL == image)
+  {
+    GNUNET_break (0);
+    return NULL;
+  }
+  /* adjust scale to screen resolution */
+  screen = gtk_widget_get_screen (GTK_WIDGET (image));
+  settings = gtk_settings_get_for_screen (screen);
+  g_object_get (G_OBJECT (settings),
+                "gtk-xft-dpi",
+                &dpi,
+                NULL);
+  if (-1 == dpi)
+    scale = 2;
+  else if (dpi >= 122800)
+    scale = 4;
+  else if (dpi >= 98304)
+    scale = 3;
+  else
+    scale = 2;
+  return create_qrcode (scale,
+                        text);
+}
+
+
 static void
 action_truths_paying (void)
 {
@@ -878,9 +1011,55 @@ action_truths_paying (void)
 static void
 action_policies_paying (void)
 {
+  json_t *pprs;
+  size_t index;
+  json_t *ppr;
+
   AG_hide_all_frames ();
-  GNUNET_break (0);
-  // FIXME: show payment QR codes!
+  pprs = json_object_get (redux_state,
+                          "policy_payment_requests");
+  json_array_foreach (pprs, index, ppr)
+  {
+    const char *provider;
+    const char *payto;
+    struct GNUNET_JSON_Specification spec[] = {
+      GNUNET_JSON_spec_string ("provider",
+                               &provider),
+      GNUNET_JSON_spec_string ("payto",
+                               &payto),
+      GNUNET_JSON_spec_end ()
+    };
+    GdkPixbuf *pb;
+
+    if (GNUNET_OK !=
+        GNUNET_JSON_parse (ppr,
+                           spec,
+                           NULL, NULL))
+    {
+      GNUNET_break (0);
+      continue;
+    }
+    // FIXME: show payment QR codes!
+
+    pb = setup_qrcode ("wiget_name",
+                       payto);
+    if (NULL == pb)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                  _ ("Failed to initialize QR-code pixbuf for `%s'\n"),
+                  payto);
+      continue;
+    }
+
+    {
+      GtkImage *image;
+
+      image = NULL; // FIXME!
+      gtk_image_set_from_pixbuf (image,
+                                 pb);
+      g_object_unref (pb);
+    }
+  }
   AG_sensitive ("anastasis_gtk_main_window_prev_button");
 
   AG_show ("anastasis_gtk_pay_frame");
diff --git a/src/anastasis/anastasis-gtk_handle-core-secret-changed.c 
b/src/anastasis/anastasis-gtk_handle-core-secret-changed.c
new file mode 100644
index 0000000..9d0d93e
--- /dev/null
+++ b/src/anastasis/anastasis-gtk_handle-core-secret-changed.c
@@ -0,0 +1,46 @@
+/*
+     This file is part of anastasis-gtk.
+     Copyright (C) 2020 Anastasis SARL
+
+     Anastasis 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.
+
+     Anastasis 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 Anastasis; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
+*/
+/**
+ * @file src/anastasis/anastasis-gtk_handle-core-secret.c
+ * @brief
+ * @author Christian Grothoff
+ */
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_util_lib.h>
+#include "anastasis-gtk_helper.h"
+#include "anastasis-gtk_action.h"
+#include "anastasis-gtk_attributes.h"
+#include "anastasis-gtk_handle-identity-changed.h"
+#include <jansson.h>
+
+
+void
+anastasis_gtk_enter_secret_entry_changed_cb (GtkEditable *entry,
+                                             gpointer user_data)
+{
+  GtkEntry *e = GTK_ENTRY (entry);
+  const char *text = gtk_entry_get_text (e);
+
+  if ( (NULL != text) &&
+       (strlen (text) > 0) )
+    AG_sensitive ("anastasis_gtk_main_window_forward_button");
+  else
+    AG_insensitive ("anastasis_gtk_main_window_forward_button");
+}

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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