diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-09-26 15:36:34 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-09-26 15:36:34 +0200 |
commit | c07ae7d8d5f39a94b3792c9267d8463746f79ba8 (patch) | |
tree | c8be56869f85f2581e75fbf8f9a5f527537355f2 /src/anastasis/anastasis-gtk_action.c | |
parent | c03840e32b6ac72497d317c3646304b30a9e9793 (diff) | |
download | anastasis-gtk-c07ae7d8d5f39a94b3792c9267d8463746f79ba8.tar.gz anastasis-gtk-c07ae7d8d5f39a94b3792c9267d8463746f79ba8.tar.bz2 anastasis-gtk-c07ae7d8d5f39a94b3792c9267d8463746f79ba8.zip |
preliminary totp support for anastasis-gtk
Diffstat (limited to 'src/anastasis/anastasis-gtk_action.c')
-rw-r--r-- | src/anastasis/anastasis-gtk_action.c | 197 |
1 files changed, 40 insertions, 157 deletions
diff --git a/src/anastasis/anastasis-gtk_action.c b/src/anastasis/anastasis-gtk_action.c index b3c5333..5d4b461 100644 --- a/src/anastasis/anastasis-gtk_action.c +++ b/src/anastasis/anastasis-gtk_action.c @@ -1334,143 +1334,6 @@ 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, - size_t text_size) -{ - 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, - text_size, - (unsigned char *) text)) && - (0 != QRinput_append (qri, - QR_MODE_8, - text_size, - (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 + 8) * 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 = 4 * scale; x < size - 4 * scale; x++) - for (unsigned int y = 4 * scale; y < size - 4 * scale; y++) - { - unsigned int xx = x - 4 * scale; - unsigned int yy = y - 4 * scale; - unsigned int ss = size - 8 * scale; - unsigned int off = - (xx * qrc->width / ss) + (yy * qrc->width / ss) * 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, - size_t text_size) -{ - 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 (3 * scale, - text, - text_size); -} - - static void action_truths_paying (void) { @@ -1489,15 +1352,22 @@ action_truths_paying (void) { const char *payto = json_string_value (pt); GdkPixbuf *pb; + GtkWidget *w; + w = GTK_WIDGET (GCG_get_main_window_object ("unpaid_qr_treeview")); + if (NULL == w) + { + GNUNET_break (0); + continue; + } if (NULL == payto) { GNUNET_break (0); continue; } - pb = setup_qrcode ("unpaid_qr_treeview", - payto, - strlen (payto)); + pb = AG_setup_qrcode (w, + payto, + strlen (payto)); if (NULL == pb) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, @@ -1569,7 +1439,14 @@ action_policies_paying (void) GNUNET_JSON_spec_end () }; GdkPixbuf *pb; + GtkWidget *w; + w = GTK_WIDGET (GCG_get_main_window_object ("unpaid_qr_treeview")); + if (NULL == w) + { + GNUNET_break (0); + continue; + } if (GNUNET_OK != GNUNET_JSON_parse (ppr, spec, @@ -1578,9 +1455,9 @@ action_policies_paying (void) GNUNET_break (0); continue; } - pb = setup_qrcode ("unpaid_qr_treeview", - payto, - strlen (payto)); + pb = AG_setup_qrcode (w, + payto, + strlen (payto)); if (NULL == pb) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, @@ -1978,9 +1855,13 @@ show_challenge_feedback (void) } if (NULL != taler_pay_uri) { - qr = setup_qrcode ("anastasis_gtk_challenge_status_treeview", - taler_pay_uri, - strlen (taler_pay_uri)); + GtkWidget*w; + + w = GTK_WIDGET (GCG_get_main_window_object ( + "anastasis_gtk_challenge_status_treeview")); + qr = AG_setup_qrcode (w, + taler_pay_uri, + strlen (taler_pay_uri)); } if (TALER_EC_NONE != ec) emsg = TALER_ErrorCode_get_hint (ec); @@ -2575,6 +2456,7 @@ action_challenge_paying (void) GNUNET_JSON_spec_end () }; GdkPixbuf *pb; + GtkWidget *w; if (GNUNET_OK != GNUNET_JSON_parse (ppr, @@ -2593,9 +2475,10 @@ action_challenge_paying (void) "payment")) continue; found = true; - pb = setup_qrcode ("unpaid_qr_treeview", - payto, - strlen (payto)); + w = GTK_WIDGET (GCG_get_main_window_object ("unpaid_qr_treeview")); + pb = AG_setup_qrcode (w, + payto, + strlen (payto)); if (NULL == pb) GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ ("Failed to initialize QR-code pixbuf for `%s'\n"), @@ -3179,22 +3062,22 @@ action_recovery_finished (void) AG_show ("anastasis_gtk_secret_copy_button"); } pb = NULL; + img = GTK_IMAGE (GCG_get_main_window_object ( + "anastasis_gtk_secret_qr_image")); if (NULL != text) { - pb = setup_qrcode ("anastasis_gtk_secret_qr_image", - text, - strlen (text)); + pb = AG_setup_qrcode (GTK_WIDGET (img), + text, + strlen (text)); } else { - pb = setup_qrcode ("anastasis_gtk_secret_qr_image", - data, - data_size); + pb = AG_setup_qrcode (GTK_WIDGET (img), + data, + data_size); } if (NULL != pb) { - img = GTK_IMAGE (GCG_get_main_window_object ( - "anastasis_gtk_secret_qr_image")); gtk_image_set_from_pixbuf (img, pb); g_object_unref (pb); |