kee

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

commit 6977e4a23643ba8cb76367c6027eeec3d8b48930
parent 6e0d456fb6ed0cad3dc8f1960527657eb1e049e1
Author: lash <dev@holbrook.no>
Date:   Sun, 24 Mar 2024 13:46:02 +0000

Add keystore and unlocked widget gobject

Diffstat:
Msrc/gtk/kee-import.c | 24+++++++++---------------
Msrc/gtk/kee-import.h | 1+
Asrc/gtk/kee-key.c | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/gtk/kee-key.h | 22++++++++++++++++++++++
Msrc/gtk/kee-menu.c | 12++++++------
Msrc/gtk/main.c | 18++++++------------
Msrc/gtk/menu.c | 4++--
Msrc/gtk/ui.c | 56+++++++++-----------------------------------------------
8 files changed, 116 insertions(+), 82 deletions(-)

diff --git a/src/gtk/kee-import.c b/src/gtk/kee-import.c @@ -223,28 +223,23 @@ static GtkWidget* kee_import_build_import_text(KeeImport *o, GtkStack *stack) { KeeImport* kee_import_new(KeeMenu *win) { KeeImport *o; - GtkWidget *box_outer; - GtkWidget *box; GtkWidget *widget; GtkWidget *chooser; - GValue v; // = G_VALUE_INIT; + GValue v = G_VALUE_INIT; o = g_object_new(KEE_TYPE_IMPORT, "orientation", GTK_ORIENTATION_VERTICAL, NULL); - g_value_init(&v, G_TYPE_OBJECT); g_value_set_object(&v, win); g_object_set_property(G_OBJECT(o), "window", &v); - box_outer = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10); + gtk_box_append(GTK_BOX(o), GTK_WIDGET(o->stack)); - box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10); + //box_outer = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10); + widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10); chooser = kee_import_build_scan_videochooser(o); - gtk_box_append(GTK_BOX(box), chooser); - - gtk_box_append(GTK_BOX(box), GTK_WIDGET(o)); - - gtk_stack_add_named(o->stack, box, KEE_ACT_SCAN_QR); + gtk_box_append(GTK_BOX(widget), chooser); + gtk_stack_add_named(o->stack, widget, KEE_ACT_SCAN_QR); widget = kee_import_build_import_text(o, o->stack); gtk_stack_add_named(o->stack, widget, KEE_ACT_SCAN_TEXT); @@ -252,11 +247,10 @@ KeeImport* kee_import_new(KeeMenu *win) { gtk_stack_set_visible_child_name(o->stack, KEE_ACT_SCAN_QR); widget = kee_import_build_scan_footer(o, o->stack); + gtk_box_append(GTK_BOX(o), widget); - gtk_box_append(GTK_BOX(box_outer), GTK_WIDGET(o->stack)); - gtk_box_append(GTK_BOX(box_outer), widget); - - return box_outer; + return o; + //return box_outer; } static void kee_import_scanadd(KeeImport *o, GtkLabel *label) { diff --git a/src/gtk/kee-import.h b/src/gtk/kee-import.h @@ -2,6 +2,7 @@ #define _GTK_KEE_IMPORT_H #include <glib-object.h> +#include <gtk/gtk.h> #include "kee-menu.h" diff --git a/src/gtk/kee-key.c b/src/gtk/kee-key.c @@ -0,0 +1,61 @@ +#include <glib-object.h> +#include <gtk/gtk.h> + +#include "kee-key.h" + +typedef struct { +} KeeKeyPrivate; + +struct _KeeKEyClass { + GtkWidget parent_class; +}; + +struct _KeeKey { + GtkWidget parent; +}; + +G_DEFINE_TYPE(KeeKey, kee_key, GTK_TYPE_BOX); + +//static GParamSpec *kee_props[KEE_N_IMPORT_PROPS] = {NULL,}; +//static guint kee_sigs[KEE_N_KEY_SIGS] = {0,}; + +static void kee_key_class_init(KeeKeyClass *kls) { +} + +static void kee_key_init(KeeKey *o) { +} + +static void kee_key_handle_unlock_click(GtkWidget *button, GObject *o) { + GtkEntryBuffer *buf; + //const char *passphrase; + + buf = g_object_get_data(o, "passphrase"); + //passphrase = gtk_entry_buffer_get_text(buf); + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "click"); + + //kee_uicontext_unlock(uctx); + + gtk_entry_buffer_delete_text(buf, 0, gtk_entry_buffer_get_length(buf)); +} + +KeeKey* kee_key_new() { + KeeKey *o; + GtkWidget *entry; + GtkWidget *button; + GtkEntryBuffer *buf; + + o = g_object_new(KEE_TYPE_KEY, "orientation", GTK_ORIENTATION_VERTICAL, NULL); + + entry = gtk_entry_new(); + gtk_box_append(GTK_BOX(o), entry); + buf = gtk_entry_get_buffer(GTK_ENTRY(entry)); + gtk_entry_set_input_purpose(GTK_ENTRY(entry), GTK_INPUT_PURPOSE_PASSWORD); + gtk_entry_set_visibility(GTK_ENTRY(entry), false); + g_object_set_data(G_OBJECT(o), "passphrase", buf); + + button = gtk_button_new_with_label("create"); + gtk_box_append(GTK_BOX(o), button); + g_signal_connect (button, "clicked", G_CALLBACK (kee_key_handle_unlock_click), o); + + return o; +} diff --git a/src/gtk/kee-key.h b/src/gtk/kee-key.h @@ -0,0 +1,22 @@ +#ifndef _GTK_KEE_KEY_H +#define _GTK_KEE_KEY_H + +#include <glib-object.h> +#include <gtk/gtk.h> + +G_BEGIN_DECLS + +#define KEE_TYPE_KEY kee_key_get_type() +G_DECLARE_FINAL_TYPE(KeeKey, kee_key, KEE, KEY, GtkBox) + +enum KEE_KEY_SIGS { + KEE_N_KEY_SIGS, +}; + +G_END_DECLS + +KeeKey* kee_key_new(); + +#endif // _GTK_KEE_KEY_H + + diff --git a/src/gtk/kee-menu.c b/src/gtk/kee-menu.c @@ -29,7 +29,7 @@ static void kee_menu_act_import(GAction *act, GVariant *param, GtkStack *stack) } //static GParamSpec *kee_props[KEE_N_MENU_PROPS] = {NULL,}; -static guint kee_sigs[KEE_N_MENU_SIGS] = {0,}; +//static guint kee_sigs[KEE_N_MENU_SIGS] = {0,}; static void kee_menu_class_init(KeeMenuClass *kls) { // GObjectClass *o = G_OBJECT_CLASS(kls); @@ -47,7 +47,7 @@ KeeMenu* kee_menu_new(GtkApplication *gapp) { GSimpleAction *act; o = g_object_new(KEE_TYPE_MENU, "application", gapp, NULL); - gtk_widget_set_vexpand(o->stack, true); + gtk_widget_set_vexpand(GTK_WIDGET(o->stack), true); gapp = gtk_window_get_application(GTK_WINDOW(o)); @@ -72,7 +72,7 @@ KeeMenu* kee_menu_new(GtkApplication *gapp) { gtk_window_set_title (GTK_WINDOW (o), "kee"); gtk_window_set_default_size (GTK_WINDOW (o), 720, 1440); - gtk_window_set_child(GTK_WINDOW(o), o->stack); + gtk_window_set_child(GTK_WINDOW(o), GTK_WIDGET(o->stack)); return o; } @@ -98,6 +98,6 @@ int kee_menu_prev(KeeMenu *o) { return ERR_OK; } -GtkWidget* kee_menu_get_stack(KeeMenu *o) { - return o->stack; -} +//GtkWidget* kee_menu_get_stack(KeeMenu *o) { +// return GTK_WIDGET(o->stack); +//} diff --git a/src/gtk/main.c b/src/gtk/main.c @@ -3,17 +3,14 @@ #include <glib-object.h> #include <gst/gst.h> -#include "kee-uicontext.h" #include "ui.h" -//#include "context.h" #include "menu.h" #include "settings.h" -//#include "camera.h" -static void state_log(KeeUicontext *uctx, char state_hint, kee_state_t *new_state, kee_state_t *old_state) { - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "new state hint: %d", state_hint); -} +//static void state_log(KeeUicontext *uctx, char state_hint, kee_state_t *new_state, kee_state_t *old_state) { +// g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "new state hint: %d", state_hint); +//} static void startup(GtkApplication *app, KeeUicontext *uctx) { // kee_uicontext_scaninit(uctx); @@ -24,16 +21,14 @@ static void activate(GtkApplication *app) { } static void deactivate(GtkApplication *app, gpointer user_data) { - g_object_unref(user_data); + //g_object_unref(user_data); } int main(int argc, char **argv) { int r; - KeeUicontext *uctx; struct kee_settings settings; struct kee_context ctx; GtkApplication *gapp; - KeeImport *import; gtk_init(); gst_init(0, NULL); @@ -44,13 +39,12 @@ int main(int argc, char **argv) { settings_init(&settings); //uctx = g_object_new(KEE_TYPE_UICONTEXT, NULL); - uctx = NULL; //db_connect(&ctx.db, "./testdata_mdb"); - g_signal_connect (gapp, "startup", G_CALLBACK (startup), uctx); + g_signal_connect (gapp, "startup", G_CALLBACK (startup), NULL); //g_signal_connect (gapp, "activate", G_CALLBACK (activate), uctx); g_signal_connect (gapp, "activate", G_CALLBACK (activate), NULL); - g_signal_connect (gapp, "shutdown", G_CALLBACK (deactivate), uctx); + g_signal_connect (gapp, "shutdown", G_CALLBACK (deactivate), NULL); //g_signal_connect (uctx, "unlock", G_CALLBACK(ui_handle_unlock), uctx); //g_signal_connect (uctx, "state", G_CALLBACK(state_log), NULL); diff --git a/src/gtk/menu.c b/src/gtk/menu.c @@ -15,8 +15,8 @@ static void act_quit(GAction *act, GVariant *param, GApplication *gapp) { } -static void menu_handle_state(KeeUicontext *uctx, char state_hint, kee_state_t *new_state, kee_state_t *old_state, GObject *head) { -} +//static void menu_handle_state(KeeUicontext *uctx, char state_hint, kee_state_t *new_state, kee_state_t *old_state, GObject *head) { +//} GtkWidget* menu_button_setup(GObject *head, GtkApplication *gapp) { diff --git a/src/gtk/ui.c b/src/gtk/ui.c @@ -13,6 +13,7 @@ #include "menu.h" #include "kee-import.h" #include "kee-menu.h" +#include "kee-key.h" static void new_item(GtkListItemFactory *factory, GtkListItem *item, gpointer user_data) { @@ -53,45 +54,6 @@ void ui_handle_unlock(KeeUicontext *uctx, gpointer user_data) { } -static void ui_handle_unlock_click(GtkWidget *button, KeeUicontext *uctx) { - GtkEntryBuffer *buf; - const char *passphrase; - - buf = g_object_get_data(G_OBJECT(uctx), "passphrase"); - passphrase = gtk_entry_buffer_get_text(buf); - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "click"); - - kee_uicontext_unlock(uctx); - - gtk_entry_buffer_delete_text(buf, 0, gtk_entry_buffer_get_length(buf)); -} - - - -GtkWidget* ui_build_unlock(KeeUicontext *uctx) { - GtkWidget *box; - GtkWidget *entry; - GtkWidget *button; - GtkEntryBuffer *buf; - - box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10); - - entry = gtk_entry_new(); - gtk_box_append(GTK_BOX(box), entry); - buf = gtk_entry_get_buffer(GTK_ENTRY(entry)); - gtk_entry_set_input_purpose(GTK_ENTRY(entry), GTK_INPUT_PURPOSE_PASSWORD); - gtk_entry_set_visibility(GTK_ENTRY(entry), false); - //g_object_set_data(G_OBJECT(uctx), "passphrase", buf); - - button = gtk_button_new_with_label("create"); - gtk_box_append(GTK_BOX(box), button); - g_signal_connect (button, "clicked", G_CALLBACK (ui_handle_unlock_click), uctx); - - return GTK_WIDGET(box); -} - - - static GtkWidget* ui_build_view(KeeUicontext *uctx) { @@ -115,22 +77,22 @@ static GtkWidget* ui_build_view(KeeUicontext *uctx) { void ui_build(GtkApplication *app) { GtkWidget *widget; - GtkWidget *win; - GtkWidget *import; + KeeMenu *win; + KeeImport *import; win = kee_menu_new(app); //g_object_new(KEE_TYPE_MENU, "application", app, NULL); - widget = ui_build_unlock(NULL); - kee_menu_add(KEE_MENU(win), "unlock", widget); + widget = GTK_WIDGET(kee_key_new()); + kee_menu_add(win, "unlock", widget); widget = ui_build_view(NULL); - kee_menu_add(KEE_MENU(win), "view", widget); + kee_menu_add(win, "view", widget); //widget = ui_build_scan(uctx); //kee_view_add(widget, "import"); - kee_menu_next(KEE_MENU(win), "view"); - kee_menu_next(KEE_MENU(win), "unlock"); + kee_menu_next(win, "view"); + kee_menu_next(win, "unlock"); //g_object_set_data(G_OBJECT(uctx), KEE_W_WINDOW, GTK_WINDOW(win)); @@ -140,7 +102,7 @@ void ui_build(GtkApplication *app) { import = kee_import_new(win); //import = g_object_new(KEE_TYPE_IMPORT, "orientation", GTK_ORIENTATION_VERTICAL, NULL); - kee_menu_add(win, "import", import); + kee_menu_add(win, "import", GTK_WIDGET(import)); gtk_window_present(GTK_WINDOW (win)); }