[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis-gtk] branch master updated: import open button to impor
From: |
gnunet |
Subject: |
[taler-anastasis-gtk] branch master updated: import open button to import core secret |
Date: |
Mon, 15 Mar 2021 22:15:32 +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 c149b8f import open button to import core secret
c149b8f is described below
commit c149b8ffb8b2f414a0d8858e0d41401d2338b8de
Author: Christian Grothoff <grothoff@gnunet.org>
AuthorDate: Mon Mar 15 22:15:28 2021 +0100
import open button to import core secret
---
contrib/anastasis_gtk_main_window.glade | 72 ++++++++++--
src/anastasis/anastasis-gtk_action.c | 65 ++++++++---
.../anastasis-gtk_handle-secret-buttons.c | 128 ++++++++++++++++++++-
3 files changed, 235 insertions(+), 30 deletions(-)
diff --git a/contrib/anastasis_gtk_main_window.glade
b/contrib/anastasis_gtk_main_window.glade
index db9c89b..c414e81 100644
--- a/contrib/anastasis_gtk_main_window.glade
+++ b/contrib/anastasis_gtk_main_window.glade
@@ -1280,6 +1280,7 @@ Author: Christian Grothoff, Dennis Neufeld
<child>
<object class="GtkBox">
<property
name="name">anastasis_gtk_enter_secret_file_box</property>
+ <property
name="visible">True</property>
<property
name="can-focus">False</property>
<property
name="margin-top">5</property>
<property
name="margin-bottom">5</property>
@@ -1559,10 +1560,14 @@ Author: Christian Grothoff, Dennis Neufeld
<property
name="visible">True</property>
<property
name="can-focus">False</property>
<property name="label"
translatable="yes">Your secret was recovered:</property>
+ <attributes>
+ <attribute name="weight"
value="bold"/>
+ </attributes>
</object>
<packing>
- <property
name="expand">False</property>
+ <property
name="expand">True</property>
<property
name="fill">True</property>
+ <property
name="padding">15</property>
<property
name="position">0</property>
</packing>
</child>
@@ -1570,6 +1575,17 @@ Author: Christian Grothoff, Dennis Neufeld
<object class="GtkBox">
<property
name="visible">True</property>
<property
name="can-focus">False</property>
+ <child>
+ <object class="GtkSeparator">
+ <property
name="visible">True</property>
+ <property
name="can-focus">False</property>
+ </object>
+ <packing>
+ <property
name="expand">True</property>
+ <property
name="fill">True</property>
+ <property
name="position">0</property>
+ </packing>
+ </child>
<child>
<object class="GtkLabel"
id="anastasis_gtk_secret_value_label">
<property
name="visible">True</property>
@@ -1583,8 +1599,8 @@ Author: Christian Grothoff, Dennis Neufeld
<packing>
<property
name="expand">False</property>
<property
name="fill">True</property>
- <property
name="padding">5</property>
- <property
name="position">0</property>
+ <property
name="padding">10</property>
+ <property
name="position">1</property>
</packing>
</child>
<child>
@@ -1593,14 +1609,15 @@ Author: Christian Grothoff, Dennis Neufeld
<property
name="visible">True</property>
<property
name="can-focus">True</property>
<property
name="receives-default">True</property>
+ <property
name="tooltip-text" translatable="yes">Copy secret to clipboard</property>
<property
name="use-stock">True</property>
<signal name="clicked"
handler="anastasis_gtk_secret_copy_button_clicked_cb" swapped="no"/>
</object>
<packing>
<property
name="expand">False</property>
<property
name="fill">True</property>
- <property
name="padding">5</property>
- <property
name="position">1</property>
+ <property
name="padding">10</property>
+ <property
name="position">2</property>
</packing>
</child>
<child>
@@ -1609,31 +1626,62 @@ Author: Christian Grothoff, Dennis Neufeld
<property
name="visible">True</property>
<property
name="can-focus">True</property>
<property
name="receives-default">True</property>
+ <property
name="tooltip-text" translatable="yes">Save secret to file</property>
<property
name="use-stock">True</property>
<signal name="clicked"
handler="anastasis_gtk_secret_save_as_button_clicked_cb" swapped="no"/>
</object>
<packing>
<property
name="expand">False</property>
<property
name="fill">True</property>
- <property
name="padding">5</property>
- <property
name="position">2</property>
+ <property
name="padding">10</property>
+ <property
name="position">3</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSeparator">
+ <property
name="visible">True</property>
+ <property
name="can-focus">False</property>
+ </object>
+ <packing>
+ <property
name="expand">True</property>
+ <property
name="fill">True</property>
+ <property
name="position">4</property>
</packing>
</child>
</object>
<packing>
<property
name="expand">False</property>
<property
name="fill">True</property>
+ <property
name="padding">5</property>
<property
name="position">1</property>
</packing>
</child>
<child>
- <object class="GtkImage"
id="anastasis_gtk_secret_qr_image">
+ <object class="GtkViewport">
<property
name="visible">True</property>
<property
name="can-focus">False</property>
- <property
name="stock">gtk-missing-image</property>
+ <property
name="hexpand">True</property>
+ <property
name="vexpand">True</property>
+ <child>
+ <object class="GtkImage"
id="anastasis_gtk_secret_qr_image">
+ <property
name="width-request">400</property>
+ <property
name="height-request">400</property>
+ <property
name="visible">True</property>
+ <property
name="can-focus">False</property>
+ <property
name="margin-left">10</property>
+ <property
name="margin-right">10</property>
+ <property
name="margin-start">10</property>
+ <property
name="margin-end">10</property>
+ <property
name="margin-top">10</property>
+ <property
name="margin-bottom">10</property>
+ <property
name="hexpand">True</property>
+ <property
name="vexpand">True</property>
+ <property
name="stock">gtk-missing-image</property>
+ </object>
+ </child>
</object>
<packing>
- <property
name="expand">False</property>
+ <property
name="expand">True</property>
<property
name="fill">True</property>
<property
name="padding">5</property>
<property
name="position">2</property>
@@ -1641,7 +1689,7 @@ Author: Christian Grothoff, Dennis Neufeld
</child>
</object>
<packing>
- <property
name="expand">False</property>
+ <property
name="expand">True</property>
<property
name="fill">True</property>
<property
name="position">4</property>
</packing>
@@ -1666,7 +1714,7 @@ Author: Christian Grothoff, Dennis Neufeld
</child>
</object>
<packing>
- <property name="expand">False</property>
+ <property name="expand">True</property>
<property name="fill">True</property>
<property name="position">9</property>
</packing>
diff --git a/src/anastasis/anastasis-gtk_action.c
b/src/anastasis/anastasis-gtk_action.c
index 6225026..c42b5e2 100644
--- a/src/anastasis/anastasis-gtk_action.c
+++ b/src/anastasis/anastasis-gtk_action.c
@@ -845,12 +845,19 @@ action_secret_editing (void)
{
GtkEntry *entry;
const char *secret;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_string ("core_secret",
+ &secret),
+ GNUNET_JSON_spec_end ()
+ };
AG_hide_all_frames ();
entry = GTK_ENTRY (GCG_get_main_window_object (
"anastasis_gtk_enter_secret_entry"));
- secret = json_string_value (json_object_get (redux_state,
- "core_secret"));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_JSON_parse (redux_state,
+ spec,
+ NULL, NULL));
if ( (NULL != secret) &&
(0 < strlen (secret)) )
{
@@ -862,6 +869,7 @@ action_secret_editing (void)
{
AG_insensitive ("anastasis_gtk_main_window_forward_button");
}
+ GNUNET_JSON_parse_free (spec);
AG_sensitive ("anastasis_gtk_main_window_prev_button");
AG_show ("anastasis_gtk_enter_secret_frame");
AG_show ("anastasis_gtk_enter_secret_image");
@@ -880,7 +888,8 @@ action_secret_editing (void)
*/
static GdkPixbuf *
create_qrcode (unsigned int scale,
- const char *text)
+ const char *text,
+ size_t text_size)
{
QRinput *qri;
QRcode *qrc;
@@ -903,11 +912,11 @@ create_qrcode (unsigned int scale,
special characters). */
if ((0 != QRinput_append (qri,
QR_MODE_AN,
- strlen (text),
+ text_size,
(unsigned char *) text)) &&
(0 != QRinput_append (qri,
QR_MODE_8,
- strlen (text),
+ text_size,
(unsigned char *) text)))
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
@@ -968,7 +977,8 @@ create_qrcode (unsigned int scale,
*/
static GdkPixbuf *
setup_qrcode (const char *widget,
- const char *text)
+ const char *text,
+ size_t text_size)
{
GtkWidget *image;
GdkScreen *screen;
@@ -998,7 +1008,8 @@ setup_qrcode (const char *widget,
else
scale = 2;
return create_qrcode (scale,
- text);
+ text,
+ text_size);
}
@@ -1024,7 +1035,8 @@ action_truths_paying (void)
continue;
}
pb = setup_qrcode ("anastasis_gtk_pay_qrcode_image",
- payto);
+ payto,
+ strlen (payto));
if (NULL == pb)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -1052,7 +1064,7 @@ action_truths_paying (void)
json_t *args;
image = GTK_IMAGE (GCG_get_main_window_object (
- "anastasis_gtk_pay_qrcode_image"));
+
"anastasis_gtk_pay_qrcode_image"));
gtk_image_set_from_pixbuf (image,
pb);
GNUNET_assert (NULL == ra);
@@ -1108,7 +1120,8 @@ action_policies_paying (void)
continue;
}
pb = setup_qrcode ("anastasis_gtk_pay_qrcode_image",
- payto);
+ payto,
+ strlen (payto));
if (NULL == pb)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -1513,7 +1526,8 @@ action_challenge_paying (void)
continue;
}
pb = setup_qrcode ("anastasis_gtk_pay_qrcode_image",
- payto);
+ payto,
+ strlen (payto));
if (NULL == pb)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -1694,14 +1708,37 @@ action_recovery_finished (void)
{
GtkLabel *l;
const char *secret;
-
+ void *data;
+ size_t data_size;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_string ("core_secret",
+ &secret),
+ GNUNET_JSON_spec_varsize ("core_secret",
+ &data,
+ &data_size),
+ GNUNET_JSON_spec_end ()
+ };
+ GdkPixbuf *pb;
+ GtkImage *img;
+
AG_hide_all_frames ();
l = GTK_LABEL (GCG_get_main_window_object (
"anastasis_gtk_secret_value_label"));
- secret = json_string_value (json_object_get (redux_state,
- "core_secret"));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_JSON_parse (redux_state,
+ spec,
+ NULL, NULL));
gtk_label_set_text (l,
secret);
+ pb = setup_qrcode ("anastasis_gtk_secret_qr_image",
+ data,
+ data_size);
+ img = GTK_IMAGE (GCG_get_main_window_object (
+
"anastasis_gtk_secret_qr_image"));
+ gtk_image_set_from_pixbuf (img,
+ pb);
+ g_object_unref (pb);
+ GNUNET_JSON_parse_free (spec);
AG_show ("anastasis_gtk_completed_frame");
AG_hide ("anastasis_gtk_success_backup_label");
AG_show ("anastasis_gtk_success_recovery_box");
diff --git a/src/anastasis/anastasis-gtk_handle-secret-buttons.c
b/src/anastasis/anastasis-gtk_handle-secret-buttons.c
index f99b9d4..f48996f 100644
--- a/src/anastasis/anastasis-gtk_handle-secret-buttons.c
+++ b/src/anastasis/anastasis-gtk_handle-secret-buttons.c
@@ -25,10 +25,112 @@
*/
#include <gnunet/platform.h>
#include <gnunet/gnunet_util_lib.h>
+#include "anastasis-gtk_action.h"
#include "anastasis-gtk_helper.h"
#include <jansson.h>
+/**
+ * Function called from the open-file dialog upon completion.
+ *
+ * @param dialog the secret selection dialog
+ * @param response_id response code from the dialog
+ * @param user_data the builder of the dialog
+ */
+void
+open_secret_dialog_response_cb (GtkDialog *dialog,
+ gint response_id,
+ gpointer user_data)
+{
+ GtkBuilder *builder = GTK_BUILDER (user_data);
+ char *filename;
+ size_t data_size;
+ void *data;
+
+ if (GTK_RESPONSE_ACCEPT != response_id)
+ {
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+ g_object_unref (G_OBJECT (builder));
+ return;
+ }
+ filename =
+ GNUNET_GTK_filechooser_get_filename_utf8 (GTK_FILE_CHOOSER (dialog));
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+ g_object_unref (G_OBJECT (builder));
+
+ {
+ struct GNUNET_DISK_FileHandle *fh;
+ off_t size;
+ enum GNUNET_GenericReturnValue ret;
+
+ fh = GNUNET_DISK_file_open (filename,
+ GNUNET_DISK_OPEN_READ,
+ GNUNET_DISK_PERM_NONE);
+ if (NULL == fh)
+ {
+ AG_error ("Failed to open file `%s': %s",
+ filename,
+ strerror (errno));
+ GNUNET_free (filename);
+ return;
+ }
+ ret = GNUNET_DISK_file_handle_size (fh,
+ &size);
+ if (GNUNET_OK != ret)
+ {
+ AG_error ("Failed to obtain file size `%s': %s",
+ filename,
+ strerror (errno));
+ GNUNET_free (filename);
+ GNUNET_DISK_file_close (fh);
+ return;
+ }
+ data_size = (size_t) size;
+ data = GNUNET_malloc_large (data_size);
+ if (GNUNET_OK != ret)
+ {
+ AG_error ("Failed to allocate memory for file `%s': %s",
+ filename,
+ strerror (errno));
+ GNUNET_free (filename);
+ GNUNET_DISK_file_close (fh);
+ return;
+ }
+ if (size !=
+ GNUNET_DISK_file_read (fh,
+ data,
+ data_size))
+ {
+ AG_error ("Failed read file `%s': %s",
+ filename,
+ strerror (errno));
+ GNUNET_free (data);
+ GNUNET_free (filename);
+ GNUNET_DISK_file_close (fh);
+ return;
+ }
+ GNUNET_DISK_file_close (fh);
+ }
+ GNUNET_free (filename);
+ {
+ json_t *arguments;
+
+ arguments = json_pack ("{s:o}",
+ "secret",
+ GNUNET_JSON_from_data (data,
+ data_size));
+ GNUNET_free (data);
+ AG_freeze ();
+ ra = ANASTASIS_redux_action (redux_state,
+ "enter_secret",
+ arguments,
+ &AG_action_cb,
+ NULL);
+ json_decref (arguments);
+ }
+}
+
+
/**
* User clicked the "open" button in the dialog where the secret is entered.
*
@@ -39,9 +141,27 @@ void
anastasis_gtk_enter_secret_open_button_clicked_cb (GtkButton *button,
gpointer user_data)
{
- // FIXME: open dialog
- // load secret from file
- GNUNET_break (0);
+ GtkWidget *ad;
+ GtkBuilder *builder;
+
+ builder = GNUNET_GTK_get_new_builder (
+ "anastasis_gtk_open_secret_dialog.glade",
+ NULL);
+ if (NULL == builder)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ ad = GTK_WIDGET (gtk_builder_get_object (builder,
+ "open_file_dialog"));
+ {
+ GtkWidget *toplevel;
+
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (button));
+ gtk_window_set_transient_for (GTK_WINDOW (ad),
+ GTK_WINDOW (toplevel));
+ gtk_window_present (GTK_WINDOW (ad));
+ }
}
@@ -170,7 +290,7 @@ anastasis_gtk_secret_copy_button_clicked_cb (GtkButton
*button,
GNUNET_JSON_parse (redux_state,
spec,
NULL, NULL));
- cb = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
+ cb = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
GNUNET_assert (NULL != cb);
gtk_clipboard_set_text (cb,
data,
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-anastasis-gtk] branch master updated: import open button to import core secret,
gnunet <=