kee

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

commit d82a83b17f31f81d1d278686a7070e4dea7fe69d
parent 6986873a6c61cb43cef09af526dee7a5c2aa1dfb
Author: lash <dev@holbrook.no>
Date:   Tue, 19 Mar 2024 23:45:48 +0000

Enable quick action for import to change view to scan

Diffstat:
Msrc/gtk/kee-uicontext.c | 16++++++++++++++++
Msrc/gtk/kee-uicontext.h | 1+
Msrc/gtk/menu.c | 32++++++++++++--------------------
Msrc/gtk/ui.c | 44+++++++++++++++++++++-----------------------
4 files changed, 50 insertions(+), 43 deletions(-)

diff --git a/src/gtk/kee-uicontext.c b/src/gtk/kee-uicontext.c @@ -125,6 +125,18 @@ static void kee_uicontext_class_init(KeeUicontextClass *kls) { G_TYPE_POINTER ); +// kee_sigs[KEE_S_IMPORT] = g_signal_new("state", +// G_TYPE_FROM_CLASS(o), +// G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, +// 0, +// NULL, +// NULL, +// NULL, +// G_TYPE_NONE, +// 0, +// NULL +// ); + kee_sigs[KEE_S_SCAN_CHANGE] = g_signal_newv("scan", G_TYPE_FROM_CLASS(o), G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, @@ -279,6 +291,10 @@ void kee_uicontext_scanstart(KeeUicontext *o) { // ui_state_change(o->ui, KEE_ST_SCAN_SEARCH, 0); g_signal_emit(o, kee_sigs[KEE_S_SCAN_CHANGE], 0); } + +void kee_uicontext_import(KeeUicontext *o) { + g_signal_emit(o, kee_sigs[KEE_S_IMPORT], 0); +} // //KeeState kee_uicontext_state(KeeUicontext *o) { // KeeState state; diff --git a/src/gtk/kee-uicontext.h b/src/gtk/kee-uicontext.h @@ -19,6 +19,7 @@ G_BEGIN_DECLS enum KEE_SIGS { KEE_S_STATE_CHANGE, + KEE_S_IMPORT, KEE_S_SCAN_CHANGE, KEE_S_KEY_UNLOCKED, KEE_N_SIGS, diff --git a/src/gtk/menu.c b/src/gtk/menu.c @@ -8,21 +8,15 @@ #include "menu.h" -static void act_quit(GSimpleAction *act, GVariant *param, KeeUicontext *uctx) { - GApplication *gapp; - g_object_get(uctx, "gtk_application", &gapp, NULL); - +static void act_quit(GAction *act, GVariant *param, GApplication *gapp) { g_application_quit(gapp); } -static void act_import(GSimpleAction *act, GVariant *param, KeeUicontext *uctx) { - scan_act(act, param, uctx); -} static void menu_handle_state(KeeUicontext *uctx, char state_hint, kee_state_t *new_state, kee_state_t *old_state, GObject *head) { - GtkApplication *gapp; +// GtkApplication *gapp; GtkWidget *widget; - GAction *act; +// GAction *act; if (!(state_hint & KEE_ST_HINT_UI_MENU)) { return; @@ -30,10 +24,11 @@ static void menu_handle_state(KeeUicontext *uctx, char state_hint, kee_state_t * if (new_state->ui_menu & KEE_ST_UI_HEAD_ADD) { widget = g_object_get_data(head, KEE_W_UI_MENU_QUICK_ADD); + gtk_actionable_set_action_name(GTK_ACTIONABLE(widget), "win.import"); gtk_widget_set_sensitive(widget, true); - g_object_get(uctx, "gtk_application", &gapp, NULL); - act = g_action_map_lookup_action(G_ACTION_MAP(gapp), "import"); - g_simple_action_set_enabled(G_SIMPLE_ACTION(act), true); +// g_object_get(uctx, "gtk_application", &gapp, NULL); +// act = g_action_map_lookup_action(G_ACTION_MAP(gapp), "import"); +// g_simple_action_set_enabled(G_SIMPLE_ACTION(act), true); } } @@ -45,7 +40,7 @@ static GtkWidget* menu_button_setup(GObject *head, GtkApplication *gapp, KeeUico GSimpleAction *act; menu = g_menu_new(); - menu_item = g_menu_item_new("Import", "app.import"); + menu_item = g_menu_item_new("Import", "win.import"); g_menu_append_item(menu, menu_item); g_object_unref(menu_item); @@ -55,13 +50,9 @@ static GtkWidget* menu_button_setup(GObject *head, GtkApplication *gapp, KeeUico act = g_simple_action_new("quit", NULL); g_action_map_add_action(G_ACTION_MAP(gapp), G_ACTION(act)); - g_signal_connect(act, "activate", G_CALLBACK(act_quit), uctx); - - act = g_simple_action_new("import", NULL); - g_simple_action_set_enabled(act, false); - g_action_map_add_action(G_ACTION_MAP(gapp), G_ACTION(act)); - g_signal_connect(act, "activate", G_CALLBACK(act_import), uctx); + g_signal_connect(act, "activate", G_CALLBACK(act_quit), gapp); + butt = gtk_menu_button_new(); gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(butt), G_MENU_MODEL(menu)); gtk_menu_button_set_primary(GTK_MENU_BUTTON(butt), true); @@ -86,10 +77,11 @@ static void header_setup(GtkApplication *gapp, KeeUicontext *uctx) { butt = gtk_button_new_from_icon_name("insert-object"); gtk_header_bar_pack_start(GTK_HEADER_BAR(head), butt); - gtk_widget_set_sensitive(butt, false); + gtk_actionable_set_action_name(GTK_ACTIONABLE(butt), "win.import"); g_object_set_data(G_OBJECT(head), KEE_W_UI_MENU_QUICK_ADD, butt); g_object_set_data(G_OBJECT(uctx), KEE_W_HEADER, GTK_HEADER_BAR(head)); + g_object_set_data(G_OBJECT(uctx), KEE_W_UI_MENU_QUICK_ADD, GTK_BUTTON(butt)); // find a way to avoid ref through set data g_signal_connect (uctx, "state", G_CALLBACK(menu_handle_state), head); } diff --git a/src/gtk/ui.c b/src/gtk/ui.c @@ -19,6 +19,11 @@ static void new_item(GtkListItemFactory *factory, GtkListItem *item, gpointer us static void scan_menu_handle_state(KeeUicontext *uctx, char state_hint, kee_state_t *new_state, kee_state_t *old_state, GObject *head) { } +static void act_import(GAction *act, GVariant *param, GtkStack *stack) { + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "act impot"); + gtk_stack_set_visible_child_name(stack, "import"); +} + static void act_scan_select(GActionGroup *act, GtkActionBar *foot) { GVariant *v; @@ -26,25 +31,6 @@ static void act_scan_select(GActionGroup *act, GtkActionBar *foot) { g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "have act select: %d", g_variant_get_uint32(v)); } -//int ui_init(struct ui_container *ui) { -// gtk_init(); -// gst_init(0, NULL); -// ui->gapp = gtk_application_new ("org.defalsify.Kee", G_APPLICATION_DEFAULT_FLAGS); -// if (ui->gapp == NULL) { -// return ERR_FAIL; -// } -// ui->state = 0; -// ui->front_list = G_LIST_MODEL(gtk_string_list_new(NULL)); -// ui->front_scan = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL, 10)); -// ui->camera_list = G_LIST_MODEL(g_list_store_new(GTK_TYPE_LABEL)); -// return ERR_OK; -//} -// -//int ui_setup(KeeUicontext *ctx) { -// return ERR_OK; -//} - - void ui_handle_unlock(KeeUicontext *uctx, gpointer user_data) { kee_state_t state_delta; @@ -194,8 +180,11 @@ static GtkWidget* ui_build_scan(KeeUicontext *uctx) { GtkWidget *chooser; GtkWidget *box; GtkWidget *widget; + GtkWidget *stack; //struct ui_container *ui; + stack = gtk_stack_new(); + //ui = (struct ui_container*)ctx->front; box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10); @@ -208,11 +197,12 @@ static GtkWidget* ui_build_scan(KeeUicontext *uctx) { //widget = g_object_get_data(G_OBJECT(uctx), KEE_W_FOOTER); widget = ui_build_scan_footer(uctx); gtk_box_append(GTK_BOX(box), widget); + gtk_stack_add_child(GTK_STACK(stack), box); //g_object_set(uctx, "camera_view", box, NULL); g_object_set_data(G_OBJECT(uctx), KEE_W_CAMERA_SCAN, box); // replace with state listen - return GTK_WIDGET(box); + return GTK_WIDGET(stack); } @@ -240,6 +230,7 @@ void ui_build(GtkApplication *app, KeeUicontext *uctx) { GtkWidget *widget; GtkWidget *win; GtkWidget *stack; + GSimpleAction *act; win = gtk_application_window_new (app); @@ -256,17 +247,24 @@ void ui_build(GtkApplication *app, KeeUicontext *uctx) { kee_view_add(widget, "view"); widget = ui_build_scan(uctx); - kee_view_add(widget, "scan"); + kee_view_add(widget, "import"); - //kee_view_next("view"); - kee_view_next("scan"); + kee_view_next("view"); kee_view_next("unlock"); + act = g_simple_action_new("import", NULL); + g_action_map_add_action(G_ACTION_MAP(win), G_ACTION(act)); + g_signal_connect(act, "activate", G_CALLBACK(act_import), stack); widget = g_object_get_data(G_OBJECT(uctx), KEE_W_HEADER); gtk_window_set_titlebar(GTK_WINDOW(win), widget); g_object_set_data(G_OBJECT(uctx), KEE_W_WINDOW, GTK_WINDOW(win)); + widget = g_object_get_data(G_OBJECT(uctx), KEE_W_UI_MENU_QUICK_ADD); + gtk_widget_set_sensitive(widget, false); + + //g_signal_connect (uctx, "import", G_CALLBACK(stack_handle_import), stack; + gtk_widget_set_vexpand(stack, true); gtk_window_set_child(GTK_WINDOW(win), stack);