kee

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

commit bf4aae9e5e340ad28d08840c1fec83738cba3100
parent 61e705e4a0867077565b07d7cccfd38cbda52ee1
Author: lash <dev@holbrook.no>
Date:   Sun, 17 Mar 2024 05:49:22 +0000

WIP move list view storage and selector to gobject

Diffstat:
Msrc/gtk/kee-uicontext.c | 11+++++++++++
Msrc/gtk/kee-uicontext.h | 1+
Msrc/gtk/main.c | 1+
Msrc/gtk/ui.c | 52++++++++++++++++++++++++++++++----------------------
Msrc/gtk/ui.h | 2+-
5 files changed, 44 insertions(+), 23 deletions(-)

diff --git a/src/gtk/kee-uicontext.c b/src/gtk/kee-uicontext.c @@ -65,6 +65,11 @@ static void kee_uicontext_get_property(GObject *oo, guint property_id, GValue *v case UI_WINDOW: ui = (struct ui_container*)o->ctx->front; g_value_set_pointer(value, ui->win); + break; + case UI_LIST: + ui = (struct ui_container*)o->ctx->front; + g_value_set_object(value, ui->front_list); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(oo, property_id, pspec); break; @@ -111,6 +116,12 @@ static void kee_uicontext_class_init(KeeUicontextClass *kls) { "UI application window", GTK_TYPE_WINDOW, G_PARAM_WRITABLE | G_PARAM_READABLE); + kee_props[UI_LIST] = g_param_spec_object( + "ui_list", + "UI item list", + "UI item list", + G_TYPE_LIST_MODEL, + G_PARAM_READABLE); kee_props[GAPP] = g_param_spec_pointer( "app", "Gapplication object", diff --git a/src/gtk/kee-uicontext.h b/src/gtk/kee-uicontext.h @@ -20,6 +20,7 @@ enum KEE_PROPS { CORE_CONTEXT = 1, UI_CONTAINER, UI_HEADER, + UI_LIST, UI_WINDOW, GAPP, KEE_N_PROPS, diff --git a/src/gtk/main.c b/src/gtk/main.c @@ -12,6 +12,7 @@ static void startup(GtkApplication *app, KeeUicontext *uctx) { menu_setup(uctx); + ui_setup(uctx); } static void activate(GtkApplication *app, KeeUicontext *uctx) { diff --git a/src/gtk/ui.c b/src/gtk/ui.c @@ -10,6 +10,9 @@ #include "state.h" +static void new_item(GtkListItemFactory *factory, GtkListItem *item, gpointer user_data) { +} + int ui_init(struct ui_container *ui) { gtk_init(); gst_init(0, NULL); @@ -18,19 +21,20 @@ int ui_init(struct ui_container *ui) { return ERR_FAIL; } ui->state = 0; + ui->front_list = G_LIST_MODEL(gtk_string_list_new(NULL)); return ERR_OK; } -//static void new_item(GtkListItemFactory *factory, GtkListItem *item, gpointer user_data) { -//} +int ui_setup(KeeUicontext *ctx) { + return ERR_OK; +} -static void ui_handle_unlock_click(GtkWidget *button, gpointer user_data) { - struct ui_container *ui; +static void ui_handle_unlock_click(GtkWidget *button, gpointer user_data) { g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "click"); - ui = (struct ui_container*)user_data; - gtk_stack_set_visible_child(ui->stack, GTK_WIDGET(ui->front_view)); + //ui = (struct ui_container*)user_data; + //gtk_stack_set_visible_child(ui->stack, GTK_WIDGET(ui->front_view)); } static void ui_handle_camera_change(GtkDropDown *chooser, GParamSpec *spec, struct kee_context *ctx) { @@ -112,19 +116,22 @@ static GtkWidget* ui_build_scan_videochooser(struct kee_context *ctx) { //} // // -////static GtkWidget* ui_build_view(struct ui_container *ui) { -//static GtkWidget* ui_build_view(KeeUicontext *uctx) { -// GtkSelectionModel *sel; -// GtkListItemFactory *factory; -// -// ui->front_list = G_LIST_MODEL(gtk_string_list_new(NULL)); -// sel = GTK_SELECTION_MODEL(gtk_single_selection_new(ui->front_list)); -// factory = gtk_signal_list_item_factory_new(); -// g_signal_connect(factory, "setup", G_CALLBACK(new_item), NULL); -// ui->front_view = GTK_LIST_VIEW(gtk_list_view_new(GTK_SELECTION_MODEL(sel), factory)); -// -// return GTK_WIDGET(ui->front_view); -//} +//static GtkWidget* ui_build_view(struct ui_container *ui) { +static GtkWidget* ui_build_view(KeeUicontext *uctx) { + GtkListItemFactory *factory; + GtkSelectionModel *sel; + GListModel *front_list; + GtkListView *front_view; + + factory = gtk_signal_list_item_factory_new(); + g_signal_connect(factory, "setup", G_CALLBACK(new_item), NULL); + + g_object_get(uctx, "ui_list", &front_list, NULL); + sel = GTK_SELECTION_MODEL(gtk_single_selection_new(front_list)); + front_view = GTK_LIST_VIEW(gtk_list_view_new(GTK_SELECTION_MODEL(sel), factory)); + + return GTK_WIDGET(front_view); +} void ui_build(GtkApplication *app, KeeUicontext *uctx) { @@ -140,13 +147,14 @@ void ui_build(GtkApplication *app, KeeUicontext *uctx) { widget = ui_build_unlock(uctx); gtk_stack_add_child(GTK_STACK(stack), widget); - //widget = ui_build_view(uctx); - //gtk_stack_add_child(GTK_STACK(stack), widget); + gtk_stack_set_visible_child(GTK_STACK(stack), widget); + + widget = ui_build_view(uctx); + gtk_stack_add_child(GTK_STACK(stack), widget); //widget = ui_build_scan(uctx); //gtk_stack_add_child(stack, widget); //g_object_get(uctx, "ui_window", win, NULL); - gtk_stack_set_visible_child(GTK_STACK(stack), widget); gtk_window_set_child(GTK_WINDOW(win), GTK_WIDGET(stack)); g_object_set(uctx, "ui_window", GTK_WINDOW(win), NULL); diff --git a/src/gtk/ui.h b/src/gtk/ui.h @@ -13,7 +13,6 @@ struct ui_container { GtkStack *stack; GListModel *front_list; GListModel *camera_list; - GtkListView *front_view; GtkBox *front_scan; GtkHeaderBar *head; struct kee_scanner scan; @@ -22,6 +21,7 @@ struct ui_container { }; int ui_init(struct ui_container *ui); +int ui_setup(KeeUicontext *ctx); void ui_build(GtkApplication *app, KeeUicontext *uctx); int ui_state_change(struct ui_container *ui, int set, int reset); void ui_free(struct ui_container *ui);