kee

Offline IOU signer with QR as transport
git clone https://holbrook.no/src/kee
Info | Log | Files | Refs | README | LICENSE

commit a3ad301f6ee3a58605bee993fa4f8a141579534a
parent 4cdeee84bb44871f1936e0fb3c25ed3aca996fbd
Author: lash <dev@holbrook.no>
Date:   Wed, 24 Apr 2024 17:22:35 +0100

WIP add edit handler

Diffstat:
Msrc/gpg.c | 1+
Msrc/gtk/kee-entry-list.c | 10++--------
Msrc/gtk/kee-entry.c | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
Msrc/gtk/kee-entry.h | 2--
Msrc/gtk/kee-menu.c | 27+++++++++++++++++++++++++--
Msrc/gtk/kee-menu.h | 1+
Msrc/ledger.c | 3+--
7 files changed, 92 insertions(+), 18 deletions(-)

diff --git a/src/gpg.c b/src/gpg.c @@ -334,6 +334,7 @@ int gpg_verify(gcry_sexp_t *sig, gcry_sexp_t *key, const char *v) { debug_log(DEBUG_ERROR, in); return 1; } + return 0; } char *gpg_store_get_fingerprint(struct gpg_store *gpg) { diff --git a/src/gtk/kee-entry-list.c b/src/gtk/kee-entry-list.c @@ -18,8 +18,6 @@ struct _KeeEntryList { G_DEFINE_TYPE(KeeEntryList, kee_entry_list, GTK_TYPE_BOX); static void kee_entry_list_handle_select(GtkListView *view, guint i, KeeMenu *menu) { - GtkWidget *widget; - GtkWidget *container; GtkSingleSelection *sel; KeeEntry *o; @@ -27,13 +25,9 @@ static void kee_entry_list_handle_select(GtkListView *view, guint i, KeeMenu *me o = KEE_ENTRY(gtk_single_selection_get_selected_item(sel)); g_object_take_ref(G_OBJECT(o)); - container = kee_menu_next(menu, "entry"); + kee_menu_next(menu, "entry"); if (kee_entry_modeswitch(o, KEE_ENTRY_VIEWMODE_FULL)) { - widget = gtk_widget_get_first_child(container); - if (widget) { - gtk_box_remove(GTK_BOX(container), widget); - } - gtk_box_append(GTK_BOX(container), GTK_WIDGET(o)); + kee_menu_set(menu, GTK_WIDGET(o)); } g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "list item selected %d", i); diff --git a/src/gtk/kee-entry.c b/src/gtk/kee-entry.c @@ -1,5 +1,6 @@ #include <gcrypt.h> #include <stddef.h> +#include <stdlib.h> #include <glib-object.h> #include <gtk/gtk.h> @@ -31,12 +32,18 @@ struct _KeeEntryClass { GtkWidget parent_class; }; -#define ENTRYSTATE_LOAD 1 -#define ENTRYSTATE_SHORT 2 -#define ENTRYSTATE_EDIT 4 +#define ENTRYSTATE_LOAD 0x01 +#define ENTRYSTATE_SHORT 0x02 +#define ENTRYSTATE_EDIT 0x04 extern const asn1_static_node schema_entry_asn1_tab[]; +struct kee_entry_form_t { + GtkEntry *subject; + GtkEntry *uoa; + GtkEntry *uoa_decimals; +}; + /// \todo factor out separate struct for listitem struct _KeeEntry { GtkWidget parent; @@ -51,10 +58,28 @@ struct _KeeEntry { struct kee_ledger_t ledger; struct Cadiz *resolver; struct db_ctx *db; + struct kee_entry_form_t *form; }; + G_DEFINE_TYPE(KeeEntry, kee_entry, GTK_TYPE_BOX); +static void kee_entry_handle_add(GtkButton *butt, KeeEntry *o) { + GtkEntryBuffer *buf; + char *b; + + buf = gtk_entry_get_buffer(o->form->uoa); + b = (char*)gtk_entry_buffer_get_text(buf); + strcpy(o->ledger.uoa, b); + + buf = gtk_entry_get_buffer(o->form->uoa); + b = (char*)gtk_entry_buffer_get_text(buf); + o->ledger.uoa_decimals = (char)atoi(b); + + o->state |= ENTRYSTATE_LOAD; + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "adding ledger entry"); +} + static void kee_entry_handle_item_setup(GtkListItemFactory* o, GtkListItem *item) { GtkWidget *box; @@ -100,6 +125,7 @@ static void kee_entry_init(KeeEntry *o) { o->resolver = NULL; o->showing = NULL; o->display = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);; + o->edit = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); kee_ledger_init(&o->ledger); kee_ledger_reset_cache(&o->ledger); } @@ -138,9 +164,41 @@ static int kee_entry_apply_display_widget(KeeEntry *o) { o->showing = o->display; return 1; } + +static void kee_entry_setup_edit_widget(KeeEntry *o) { + GtkWidget *widget; + + if (o->form) { + return; + } + + o->form = calloc(sizeof(struct kee_entry_form_t), 1); + + widget = gtk_label_new("subject"); + gtk_box_append(GTK_BOX(o->edit), widget); + widget = gtk_entry_new(); + o->form->subject = GTK_ENTRY(widget); + gtk_box_append(GTK_BOX(o->edit), widget); + + widget = gtk_label_new("unit of account"); + gtk_box_append(GTK_BOX(o->edit), widget); + widget = gtk_entry_new(); + o->form->uoa = GTK_ENTRY(widget); + gtk_box_append(GTK_BOX(o->edit), widget); + + widget = gtk_label_new("unit decimals"); + gtk_box_append(GTK_BOX(o->edit), widget); + widget = gtk_entry_new(); + o->form->uoa_decimals = GTK_ENTRY(widget); + gtk_box_append(GTK_BOX(o->edit), widget); + + widget = gtk_button_new_with_label("add"); + gtk_box_append(GTK_BOX(o->edit), widget); + g_signal_connect (widget, "clicked", G_CALLBACK(kee_entry_handle_add), o); +} static int kee_entry_apply_edit_widget(KeeEntry *o) { - o->edit = gtk_label_new("editing"); + kee_entry_setup_edit_widget(o); o->showing = o->edit; return 1; } diff --git a/src/gtk/kee-entry.h b/src/gtk/kee-entry.h @@ -32,8 +32,6 @@ G_DECLARE_FINAL_TYPE(KeeEntry, kee_entry, KEE, ENTRY, GtkBox); int kee_entry_load(KeeEntry *o, struct db_ctx *db, const char *id); int kee_entry_deserialize(KeeEntry *o, const char *data, size_t data_len); -//int kee_entry_apply_list_item_widget(KeeEntry *o); -//int kee_entry_apply_display_widget(KeeEntry *o); KeeEntry* kee_entry_new(struct db_ctx *db); void kee_entry_set_resolver(KeeEntry *o, struct Cadiz *resolver); int kee_entry_modeswitch(KeeEntry *o, enum kee_entry_viewmode_e); diff --git a/src/gtk/kee-menu.c b/src/gtk/kee-menu.c @@ -3,6 +3,7 @@ #include <gtk/gtk.h> #include "kee-menu.h" +#include "kee-entry.h" #include "menu.h" #include "nav.h" #include "err.h" @@ -27,15 +28,21 @@ static void kee_menu_act_back(GAction *act, GVariant *param, KeeMenu *menu) { kee_menu_prev(menu); } -static void kee_menu_act_import(GAction *act, GVariant *param, KeeMenu *menu) {//GtkStack *stack) { +static void kee_menu_act_import(GAction *act, GVariant *param, KeeMenu *menu) { //gtk_stack_set_visible_child_name(stack, "import"); kee_menu_next(menu, "import"); } -static void kee_menu_act_new_entry(GAction *act, GVariant *param, KeeMenu *menu) {//GtkStack *stack) { +static void kee_menu_act_new_entry(GAction *act, GVariant *param, KeeMenu *menu) { + KeeEntry *o; + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "act new entry"); //gtk_stack_set_visible_child_name(stack, "import"); kee_menu_next(menu, "entry"); + + o = g_object_new(KEE_TYPE_ENTRY, "orientation", GTK_ORIENTATION_VERTICAL, NULL); + kee_menu_set(menu, GTK_WIDGET(o)); + kee_entry_modeswitch(o, KEE_ENTRY_VIEWMODE_EDIT); } //static GParamSpec *kee_props[KEE_N_MENU_PROPS] = {NULL,}; @@ -114,6 +121,8 @@ static void kee_menu_header_update(KeeMenu *o, const char *label) { g_simple_action_set_enabled(G_SIMPLE_ACTION(act), true); act = g_action_map_lookup_action(G_ACTION_MAP(o), "back"); g_simple_action_set_enabled(G_SIMPLE_ACTION(act), false); + act = g_action_map_lookup_action(G_ACTION_MAP(o), "new_entry"); + g_simple_action_set_enabled(G_SIMPLE_ACTION(act), true); } else if (!(strcmp(label, "entry"))) { act = g_action_map_lookup_action(G_ACTION_MAP(o), "back"); g_simple_action_set_enabled(G_SIMPLE_ACTION(act), true); @@ -138,6 +147,20 @@ GtkWidget* kee_menu_next(KeeMenu *o, const char *label) { return widget; } +int kee_menu_set(KeeMenu *o, GtkWidget *widget) { + GtkBox *container; + GtkWidget *widget_old; + + container = GTK_BOX(o->nav.now); + + widget_old = gtk_widget_get_first_child(GTK_WIDGET(container)); + if (widget_old) { + gtk_box_remove(container, widget_old); + } + gtk_box_append(container, widget); + return 0; +} + int kee_menu_prev(KeeMenu *o) { const char *label; diff --git a/src/gtk/kee-menu.h b/src/gtk/kee-menu.h @@ -22,6 +22,7 @@ KeeMenu* kee_menu_new(GtkApplication *app); int kee_menu_add(KeeMenu *o, const char *k, GtkWidget *v); GtkWidget* kee_menu_next(KeeMenu *o, const char *k); int kee_menu_prev(KeeMenu *o); +int kee_menu_set(KeeMenu *o, GtkWidget *widget); G_END_DECLS diff --git a/src/ledger.c b/src/ledger.c @@ -14,7 +14,7 @@ extern const asn1_static_node schema_entry_asn1_tab[]; -const char zero_content[64]; +char zero_content[64]; static char *get_message(asn1_node item, char *out_digest, char *out_data, size_t *out_len) { int r; @@ -22,7 +22,6 @@ static char *get_message(asn1_node item, char *out_digest, char *out_data, size_ asn1_node root; char err[1024]; char buf[64]; - char sig[64]; memset(&root, 0, sizeof(root)); r = asn1_array2tree(schema_entry_asn1_tab, &root, err);