kee

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

commit 3eb4440343e35da66825a16b1d73885dd5286400
parent 396a76c666418fcc55ab767733cc99b494cf6a09
Author: lash <dev@holbrook.no>
Date:   Mon, 18 Mar 2024 13:21:59 +0000

Enable front and menu with ui object removed

Diffstat:
MMakefile | 7+++++++
Msrc/Makefile | 6++++++
Msrc/gtk/Makefile | 10++++++++++
Msrc/gtk/kee-uicontext.c | 247+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Msrc/gtk/kee-uicontext.h | 21+++++++++++++--------
Msrc/gtk/main.c | 44+++++++++++++++++++++++++-------------------
Msrc/gtk/menu.c | 44++++++++++++++++++++++++++++----------------
Msrc/gtk/menu.h | 2+-
Msrc/gtk/scan.c | 4++--
Msrc/gtk/ui.c | 251++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/gtk/ui.h | 35++++++++++++++++++-----------------
11 files changed, 364 insertions(+), 307 deletions(-)

diff --git a/Makefile b/Makefile @@ -24,3 +24,10 @@ debug: gtk all test: gtk all make -C src/gtk/tests + +dev: + make -C src dev + +debug_dev: dev + G_DEBUG=3 G_MESSAGES_DEBUG=all ./src/gtk/a_dev.out + diff --git a/src/Makefile b/src/Makefile @@ -17,4 +17,10 @@ aux: clean: rm -vf *.o +dev: + $(CC) $(CFLAGS) -c settings.c -o settings.o $(LDFLAGS) + $(CC) $(CFLAGS) -c context.c -o context.o $(LDFLAGS) + $(CC) $(CFLAGS) -c camera.c -o camera.o $(LDFLAGS) + make -C gtk dev + .PHONY: clean aux diff --git a/src/gtk/Makefile b/src/gtk/Makefile @@ -20,3 +20,13 @@ clean: resource: glib-compile-resources kee.gresource.xml --target=resources.c --generate-source + +dev: + $(CC) $(CFLAGS) -c debug.c -o debug.o + $(CC) $(CFLAGS) -c view.c -o view.o + $(CC) $(CFLAGS) -c nav.c -o nav.o + $(CC) $(CFLAGS) -c scan.c -o scan.o + $(CC) $(CFLAGS) -c ui.c -o ui.o + $(CC) $(CFLAGS) -c menu.c -o menu.o + $(CC) $(CFLAGS) -c kee-uicontext.c -o kee-uicontext.o + $(CC) $(CFLAGS) main.c -o a_dev.out ../settings.o ../camera.o ../context.o ./kee-uicontext.o ./debug.o ./menu.o ./scan.o ./ui.o ./view.o ./nav.o $(LDFLAGS) diff --git a/src/gtk/kee-uicontext.c b/src/gtk/kee-uicontext.c @@ -2,7 +2,7 @@ #include <gtk/gtk.h> #include "kee-uicontext.h" -#include "ui.h" +//#include "ui.h" #include "context.h" #include "state.h" #include "settings.h" @@ -16,9 +16,10 @@ typedef struct { */ struct _KeeUicontext { GObject parent; - struct ui_container *ui; + //struct ui_container *ui; struct kee_context *ctx; - GApplication *app; + GListModel *camera_list; + GtkApplication *gapp; }; G_DEFINE_TYPE(KeeUicontext, kee_uicontext, G_TYPE_OBJECT) @@ -28,39 +29,42 @@ static guint kee_sigs[KEE_N_SIGS] = {0,}; static void kee_uicontext_set_property(GObject *oo, guint property_id, const GValue *value, GParamSpec *pspec) { KeeUicontext *o = KEE_UICONTEXT(oo); - struct ui_container *ui; - GtkWidget *widget; - GtkStack *stack; + //struct ui_container *ui; + //GtkWidget *widget; + //GtkStack *stack; switch ((enum KEE_PROPS) property_id) { case CORE_CONTEXT: o->ctx = g_value_get_pointer(value); break; - case UI_CONTAINER: - ui = g_value_get_pointer(value); - o->app = (GApplication*)ui->gapp; - o->ctx->front = ui; - o->ui = (struct ui_container*)o->ctx->front; - break; - case UI_HEADER: - ui = (struct ui_container*)o->ctx->front; - ui->head = g_value_get_object(value); - break; - case UI_WINDOW: - ui = (struct ui_container*)o->ctx->front; - ui->win = g_value_get_object(value); - gtk_window_set_titlebar(GTK_WINDOW(ui->win), GTK_WIDGET(ui->head)); - break; - case UI_PUSH: - ui = (struct ui_container*)o->ctx->front; - widget = g_value_get_object(value); - stack = GTK_STACK(gtk_window_get_child(GTK_WINDOW(ui->win))); - gtk_stack_set_visible_child(stack, widget); - break; - case CAMERA_VIEW: - ui = (struct ui_container*)o->ctx->front; - widget = g_value_get_object(value); - ui->front_scan = GTK_BOX(widget); +// case UI_CONTAINER: +// ui = g_value_get_pointer(value); +// o->app = (GApplication*)ui->gapp; +// o->ctx->front = ui; +// o->ui = (struct ui_container*)o->ctx->front; +// break; +// case UI_HEADER: +// ui = (struct ui_container*)o->ctx->front; +// ui->head = g_value_get_object(value); +// break; +// case UI_WINDOW: +// ui = (struct ui_container*)o->ctx->front; +// ui->win = g_value_get_object(value); +// gtk_window_set_titlebar(GTK_WINDOW(ui->win), GTK_WIDGET(ui->head)); +// break; +// case UI_PUSH: +// ui = (struct ui_container*)o->ctx->front; +// widget = g_value_get_object(value); +// stack = GTK_STACK(gtk_window_get_child(GTK_WINDOW(ui->win))); +// gtk_stack_set_visible_child(stack, widget); +// break; +// case CAMERA_VIEW: +// ui = (struct ui_container*)o->ctx->front; +// widget = g_value_get_object(value); +// ui->front_scan = GTK_BOX(widget); +// break; + case GAPP: + o->gapp = g_value_get_object(value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(oo, property_id, pspec); @@ -71,32 +75,32 @@ static void kee_uicontext_set_property(GObject *oo, guint property_id, const GVa static void kee_uicontext_get_property(GObject *oo, guint property_id, GValue *value, GParamSpec *pspec) { KeeUicontext *o = KEE_UICONTEXT(oo); - struct ui_container *ui; + //struct ui_container *ui; switch ((enum KEE_PROPS) property_id) { case GAPP: - g_value_set_pointer(value, o->app); - break; - 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); + g_value_set_object(value, o->gapp); break; +// 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; case CAMERA_LIST: - g_value_set_object(value, o->ui->camera_list); - break; - case CAMERA_SCAN: - g_value_set_object(value, o->ui->camera_list); - break; - case CAMERA_DEVICE: - g_value_set_string(value, (char*)settings_get(o->ctx->settings, SETTINGS_VIDEO)); //;o->ui->scan); - break; - case CAMERA_VIEW: - g_value_set_object(value, o->ui->front_scan); //;o->ui->scan); + g_value_set_object(value, o->camera_list); break; +// case CAMERA_SCAN: +// g_value_set_object(value, o->ui->camera_list); +// break; +// case CAMERA_DEVICE: +// g_value_set_string(value, (char*)settings_get(o->ctx->settings, SETTINGS_VIDEO)); //;o->ui->scan); +// break; +// case CAMERA_VIEW: +// g_value_set_object(value, o->ui->front_scan); //;o->ui->scan); +// break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(oo, property_id, pspec); break; @@ -138,70 +142,72 @@ static void kee_uicontext_class_init(KeeUicontextClass *kls) { "Core context", "backend context to connect", G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE); - kee_props[UI_CONTAINER] = g_param_spec_pointer( - "ui_container", - "Ui Container", - "UI container to connect", - G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE); +// kee_props[UI_CONTAINER] = g_param_spec_pointer( +// "ui_container", +// "Ui Container", +// "UI container to connect", +// G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE); kee_props[CAMERA_LIST] = g_param_spec_object( "camera_list", "Camera device List", "List model containing current list of available camera", G_TYPE_LIST_MODEL, G_PARAM_READABLE); - kee_props[CAMERA_SCAN] = g_param_spec_pointer( - "camera_scan", - "Camera scan", - "Scan context object pointer", - G_PARAM_READABLE); - kee_props[CAMERA_DEVICE] = g_param_spec_string( - "camera_device", - "Camera Device", - "Path for current camera device", - "/dev/video0", - G_PARAM_READABLE); - kee_props[CAMERA_VIEW] = g_param_spec_object( - "camera_view", - "Camera view", - "Viewfinder widget for camera", - GTK_TYPE_BOX, - G_PARAM_READABLE | G_PARAM_WRITABLE); - kee_props[UI_HEADER] = g_param_spec_object( - "ui_header", - "UI header", - "UI header bar", - GTK_TYPE_HEADER_BAR, - G_PARAM_WRITABLE); - kee_props[UI_WINDOW] = g_param_spec_object( - "ui_window", - "UI window", - "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[UI_PUSH] = g_param_spec_object( - "ui_push", - "UI push", - "Add UI element on top of stack", - GTK_TYPE_WIDGET, - G_PARAM_WRITABLE); - - kee_props[GAPP] = g_param_spec_pointer( - "app", - "Gapplication object", - "Gapplication object attached to ui", - G_PARAM_READABLE); +// kee_props[CAMERA_SCAN] = g_param_spec_pointer( +// "camera_scan", +// "Camera scan", +// "Scan context object pointer", +// G_PARAM_READABLE); +// kee_props[CAMERA_DEVICE] = g_param_spec_string( +// "camera_device", +// "Camera Device", +// "Path for current camera device", +// "/dev/video0", +// G_PARAM_READABLE); +// kee_props[CAMERA_VIEW] = g_param_spec_object( +// "camera_view", +// "Camera view", +// "Viewfinder widget for camera", +// GTK_TYPE_BOX, +// G_PARAM_READABLE | G_PARAM_WRITABLE); +// kee_props[UI_HEADER] = g_param_spec_object( +// "ui_header", +// "UI header", +// "UI header bar", +// GTK_TYPE_HEADER_BAR, +// G_PARAM_WRITABLE); +// kee_props[UI_WINDOW] = g_param_spec_object( +// "ui_window", +// "UI window", +// "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[UI_PUSH] = g_param_spec_object( +// "ui_push", +// "UI push", +// "Add UI element on top of stack", +// GTK_TYPE_WIDGET, +// G_PARAM_WRITABLE); +// + kee_props[GAPP] = g_param_spec_object( + "gtk_application", + "Gtk application object", + "Gtk application object attached to ui", + GTK_TYPE_APPLICATION, + G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_READABLE); g_object_class_install_properties(o, KEE_N_PROPS, kee_props); } static void kee_uicontext_init(KeeUicontext *o) { //KeeUicontextPrivate *o = kee_uicontext_get_instance_private(self); + o->camera_list = G_LIST_MODEL(g_list_store_new(GTK_TYPE_LABEL)); } void kee_uicontext_scaninit(KeeUicontext *o) { @@ -220,31 +226,32 @@ void kee_uicontext_scaninit(KeeUicontext *o) { } } + void kee_uicontext_scanchange(KeeUicontext *o, const char *device) { settings_set(o->ctx->settings, SETTINGS_VIDEO, (unsigned char*)device); - ui_state_change(o->ui, KEE_ST_SCAN_SEARCH, 0); + //ui_state_change(o->ui, KEE_ST_SCAN_SEARCH, 0); g_signal_emit(o, kee_sigs[SCAN_WANT], 0); } void kee_uicontext_scanadd(KeeUicontext *o, GtkLabel *label) { - g_list_store_append(G_LIST_STORE(o->ui->camera_list), label); + g_list_store_append(G_LIST_STORE(o->camera_list), label); } void kee_uicontext_scanstart(KeeUicontext *o) { - if (KEE_IS_SCANNING(o->ui)) { - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "already in scanning state"); - return; - } - - ui_state_change(o->ui, KEE_ST_SCAN_SEARCH, 0); +// if (KEE_IS_SCANNING(o->ui)) { +// g_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "already in scanning state"); +// return; +// } +// +// ui_state_change(o->ui, KEE_ST_SCAN_SEARCH, 0); g_signal_emit(o, kee_sigs[SCAN_WANT], 0); } - -KeeState kee_uicontext_state(KeeUicontext *o) { - KeeState state; - - state.ui = o->ui->state; - state.ctx = o->ctx->state; - - return state; -} +// +//KeeState kee_uicontext_state(KeeUicontext *o) { +// KeeState state; +// +// state.ui = o->ui->state; +// state.ctx = o->ctx->state; +// +// return state; +//} diff --git a/src/gtk/kee-uicontext.h b/src/gtk/kee-uicontext.h @@ -4,6 +4,11 @@ #include <glib-object.h> #include "context.h" +#define KEE_W_FRONTLIST "frontlist" +#define KEE_W_CAMERA_VIEWFINDER "camera_view" +#define KEE_W_WINDOW "win" +#define KEE_W_HEADER "header" + G_BEGIN_DECLS typedef struct { @@ -19,15 +24,15 @@ enum KEE_SIGS { enum KEE_PROPS { CORE_CONTEXT = 1, - UI_CONTAINER, - UI_HEADER, - UI_LIST, - UI_WINDOW, - UI_PUSH, +// UI_CONTAINER, +// UI_HEADER, +// UI_LIST, +// UI_WINDOW, +// UI_PUSH, CAMERA_LIST, - CAMERA_SCAN, - CAMERA_DEVICE, - CAMERA_VIEW, +// CAMERA_SCAN, +// CAMERA_DEVICE, +// CAMERA_VIEW, GAPP, KEE_N_PROPS, }; diff --git a/src/gtk/main.c b/src/gtk/main.c @@ -4,25 +4,26 @@ #include "kee-uicontext.h" #include "ui.h" -#include "context.h" +//#include "context.h" #include "menu.h" #include "settings.h" -#include "camera.h" +//#include "camera.h" static void startup(GtkApplication *app, KeeUicontext *uctx) { kee_uicontext_scaninit(uctx); - menu_setup(uctx); - ui_setup(uctx); + header_setup(app, uctx); + //ui_setup(uctx); } + static void activate(GtkApplication *app, KeeUicontext *uctx) { ui_build(app, uctx); } static void deactivate(GtkApplication *app, gpointer user_data) { g_object_unref(user_data); - ui_free(user_data); + //ui_free(user_data); } int main(int argc, char **argv) { @@ -30,31 +31,36 @@ int main(int argc, char **argv) { KeeUicontext *uctx; struct kee_settings settings; struct kee_context ctx; - struct ui_container ui; + GtkApplication *gapp; + //struct ui_container ui; + + //r = ui_init(&ui); + //if (r) { + // return r; + //} - r = ui_init(&ui); - if (r) { - return r; - } + gapp = gtk_application_new ("org.defalsify.Kee", G_APPLICATION_DEFAULT_FLAGS); //settings_new_from_xdg(&ctx.settings); settings_new_from_xdg(&settings); //settings_init(&ctx.settings); settings_init(&settings); - kee_context_new(&ctx, &ui, &settings); - uctx = g_object_new(KEE_TYPE_UICONTEXT, "ui_container", &ui, "core_context", &ctx, NULL); + //kee_context_new(&ctx, &ui, &settings); + //uctx = g_object_new(KEE_TYPE_UICONTEXT, "ui_container", &ui, "core_context", &ctx, NULL); + uctx = g_object_new(KEE_TYPE_UICONTEXT, "gtk_application", gapp, "core_context", &ctx, NULL); //db_connect(&ctx.db, "./testdata_mdb"); - g_signal_connect (ui.gapp, "startup", G_CALLBACK (startup), uctx); - g_signal_connect (ui.gapp, "activate", G_CALLBACK (activate), uctx); - g_signal_connect (ui.gapp, "shutdown", G_CALLBACK (deactivate), uctx); - //g_signal_connect (uctx, "scan_want", G_CALLBACK( ui_handle_scan) , &ctx); - g_signal_connect (uctx, "scan_want", G_CALLBACK( ui_handle_scan) , uctx); + g_signal_connect (gapp, "startup", G_CALLBACK (startup), uctx); + g_signal_connect (gapp, "activate", G_CALLBACK (activate), uctx); + g_signal_connect (gapp, "shutdown", G_CALLBACK (deactivate), uctx); +// //g_signal_connect (uctx, "scan_want", G_CALLBACK( ui_handle_scan) , &ctx); +// g_signal_connect (uctx, "scan_want", G_CALLBACK( ui_handle_scan) , uctx); - r = g_application_run (G_APPLICATION (ui.gapp), argc, argv); +// r = g_application_run (G_APPLICATION (ui.gapp), argc, argv); + r = g_application_run (G_APPLICATION (gapp), argc, argv); - g_object_unref(ui.gapp); + g_object_unref(gapp); kee_context_free(&ctx); return r; } diff --git a/src/gtk/menu.c b/src/gtk/menu.c @@ -1,28 +1,24 @@ #include <gtk/gtk.h> #include "kee-uicontext.h" -#include "ui.h" +//#include "ui.h" #include "scan.h" #include "context.h" -static void act_quit(GSimpleAction *act, GVariant *param, KeeUicontext *ui) { +static void act_quit(GSimpleAction *act, GVariant *param, KeeUicontext *uctx) { GApplication *gapp; - g_object_get(ui, "app", &gapp, NULL); + g_object_get(uctx, "gtk_application", &gapp, NULL); g_application_quit(gapp); } -void menu_setup(KeeUicontext *ctx_ui) { + +static GtkWidget* menu_setup(GtkApplication *gapp, KeeUicontext *uctx) { GMenu *menu; GMenuItem *menu_item; GtkWidget *butt; - GtkWidget *butt_back; GSimpleAction *act; - GApplication *gapp; - GtkWidget *head; - - g_object_get(ctx_ui, "app", &gapp, NULL); menu = g_menu_new(); menu_item = g_menu_item_new("Scan", "app.scan"); @@ -35,25 +31,41 @@ void menu_setup(KeeUicontext *ctx_ui) { 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), ctx_ui); + g_signal_connect(act, "activate", G_CALLBACK(act_quit), uctx); act = g_simple_action_new("scan", 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(scan_act), ctx_ui); - - head = gtk_header_bar_new(); + g_signal_connect(act, "activate", G_CALLBACK(scan_act), uctx); 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); gtk_menu_button_set_icon_name(GTK_MENU_BUTTON(butt), "preferences-system"); - gtk_header_bar_pack_end(GTK_HEADER_BAR(head), butt); + + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "set up menus"); + return butt; +} + + +void header_setup(GtkApplication *gapp, KeeUicontext *uctx) { + GtkWidget *head; + GtkWidget *butt_back; + GtkWidget *butt_add; + GtkWidget *butt_menu; + head = gtk_header_bar_new(); butt_back = gtk_button_new_from_icon_name("go-previous"); gtk_header_bar_pack_start(GTK_HEADER_BAR(head), butt_back); gtk_widget_set_visible(butt_back, false); - g_object_set(ctx_ui, "ui_header", GTK_HEADER_BAR(head), NULL); + butt_add = gtk_button_new_from_icon_name("insert-object"); + gtk_header_bar_pack_start(GTK_HEADER_BAR(head), butt_add); + gtk_widget_set_sensitive(butt_add, false); - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "set up menus"); + butt_menu = menu_setup(gapp, uctx); + gtk_header_bar_pack_end(GTK_HEADER_BAR(head), butt_menu); + + //g_object_set(uctx, "ui_header", GTK_HEADER_BAR(head), NULL); + g_object_set_data(G_OBJECT(uctx), KEE_W_HEADER, head); } diff --git a/src/gtk/menu.h b/src/gtk/menu.h @@ -3,6 +3,6 @@ #include "kee-uicontext.h" -void menu_setup(KeeUicontext *ctx); +void header_setup(GtkApplication *gapp, KeeUicontext *uctx); #endif // _KEE_GTK_MENU_H diff --git a/src/gtk/scan.c b/src/gtk/scan.c @@ -113,11 +113,11 @@ void scan_set_handler(struct kee_scanner *scan, gboolean(*fn)(GstBus *bus, GstMe gst_bus_add_watch(scan->bus, fn, scan); } -void scan_act(GSimpleAction *act, GVariant *param, KeeUicontext *ui) { +void scan_act(GSimpleAction *act, GVariant *param, KeeUicontext *uctx) { //GDBusConnection *conn; g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "scan clicked"); - kee_uicontext_scanstart(ui); + kee_uicontext_scanstart(uctx); //conn = g_application_get_dbus_connection(app); } diff --git a/src/gtk/ui.c b/src/gtk/ui.c @@ -14,23 +14,23 @@ static void new_item(GtkListItemFactory *factory, GtkListItem *item, gpointer user_data) { } -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; -} +//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; +//} static void ui_handle_unlock_click(GtkWidget *button, gpointer user_data) { @@ -55,7 +55,7 @@ static void ui_handle_camera_change(GtkDropDown *chooser, GParamSpec *spec, KeeU kee_uicontext_scanchange(uctx, s); //ui_handle_scan(ui->gapp, ctx); - //ui_handle_scan(uctx); + ui_handle_scan(uctx); } @@ -110,7 +110,8 @@ static GtkWidget* ui_build_scan(KeeUicontext *uctx) { chooser = ui_build_scan_videochooser(uctx); gtk_box_append(GTK_BOX(box), chooser); - g_object_set(uctx, "camera_view", box, NULL); + //g_object_set(uctx, "camera_view", box, NULL); + g_object_set_data(G_OBJECT(uctx), KEE_W_CAMERA_VIEWFINDER, box); return GTK_WIDGET(box); } @@ -125,8 +126,10 @@ static GtkWidget* ui_build_view(KeeUicontext *uctx) { factory = gtk_signal_list_item_factory_new(); g_signal_connect(factory, "setup", G_CALLBACK(new_item), NULL); + + front_list = G_LIST_MODEL(gtk_string_list_new(NULL)); + g_object_set_data(G_OBJECT(uctx), KEE_W_FRONTLIST, front_list); - 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)); @@ -149,22 +152,21 @@ void ui_build(GtkApplication *app, KeeUicontext *uctx) { widget = ui_build_unlock(uctx); kee_view_add(widget, "unlock"); - //gtk_stack_add_child(GTK_STACK(stack), widget); - //gtk_stack_set_visible_child(GTK_STACK(stack), widget); widget = ui_build_view(uctx); kee_view_add(widget, "view"); - //gtk_stack_add_child(GTK_STACK(stack), widget); + widget = ui_build_scan(uctx); kee_view_add(widget, "scan"); - //gtk_stack_add_child(GTK_STACK(stack), widget); - // + kee_view_next("view"); kee_view_next("unlock"); - //g_object_get(uctx, "ui_window", win, NULL); gtk_window_set_child(GTK_WINDOW(win), GTK_WIDGET(stack)); - g_object_set(uctx, "ui_window", GTK_WINDOW(win), NULL); + + 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)); gtk_window_present(GTK_WINDOW (win)); } @@ -188,118 +190,119 @@ void ui_build(GtkApplication *app, KeeUicontext *uctx) { // -void ui_free(struct ui_container *ui) { +//void ui_free(struct ui_container *ui) { //g_object_unref(ui->view); //g_object_unref(ui->unlock); //g_object_unref(ui->win); -} - -int ui_state_change(struct ui_container *ui, int set, int reset) { - ui->state |= set; - return ui->state; -} - -gboolean ui_scan_code_handler(GstBus *bus, GstMessage *msg, gpointer user_data) { - GError *err; - gchar *debug_info; - GstState oldstate; - GstState newstate; - GstState pendingstate; - const gchar *src; - const gchar *code; - const GstStructure *strctr; - //struct _gst_data *data; - //GstStateChangeReturn rsc; - - //data = (struct _gst_data*)user_data; - - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "scan msg got"); - - switch (GST_MESSAGE_TYPE (msg)) { - case GST_MESSAGE_ERROR: - gst_message_parse_error(msg, &err, &debug_info); - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "logg %s: %s", GST_OBJECT_NAME(msg->src), err->message); - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "debug %s", debug_info ? debug_info : "none"); - g_clear_error(&err); - g_free(debug_info); - break; - case GST_MESSAGE_EOS: - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "eos"); - break; - case GST_MESSAGE_STATE_CHANGED: - gst_message_parse_state_changed(msg, &oldstate, &newstate, &pendingstate); - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "state change: %s -> %s", gst_element_state_get_name(oldstate), gst_element_state_get_name(newstate)); - break; - case GST_MESSAGE_ELEMENT: - src = gst_object_get_name(msg->src); - if (strcmp(src, "zbar")) { - break; - } - strctr = gst_message_get_structure(msg); - code = gst_structure_get_string(strctr, "symbol"); - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "message %s: %d (%s) - decoded: %s", src, msg->type, gst_message_type_get_name(msg->type), code); - break; - default: - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "unknown message (ext %d): %s", GST_MESSAGE_TYPE_IS_EXTENDED(msg), GST_MESSAGE_TYPE_NAME(msg)); - break; - } - - return true; -} +//} -//GtkWidget* ui_build_scan_attach(GtkWidget *front_scan, const char *device) { +//int ui_state_change(struct ui_container *ui, int set, int reset) { +// ui->state |= set; +// return ui->state; +//} +// +//gboolean ui_scan_code_handler(GstBus *bus, GstMessage *msg, gpointer user_data) { +// GError *err; +// gchar *debug_info; +// GstState oldstate; +// GstState newstate; +// GstState pendingstate; +// const gchar *src; +// const gchar *code; +// const GstStructure *strctr; +// //struct _gst_data *data; +// //GstStateChangeReturn rsc; +// +// //data = (struct _gst_data*)user_data; +// +// g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "scan msg got"); +// +// switch (GST_MESSAGE_TYPE (msg)) { +// case GST_MESSAGE_ERROR: +// gst_message_parse_error(msg, &err, &debug_info); +// g_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "logg %s: %s", GST_OBJECT_NAME(msg->src), err->message); +// g_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "debug %s", debug_info ? debug_info : "none"); +// g_clear_error(&err); +// g_free(debug_info); +// break; +// case GST_MESSAGE_EOS: +// g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "eos"); +// break; +// case GST_MESSAGE_STATE_CHANGED: +// gst_message_parse_state_changed(msg, &oldstate, &newstate, &pendingstate); +// g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "state change: %s -> %s", gst_element_state_get_name(oldstate), gst_element_state_get_name(newstate)); +// break; +// case GST_MESSAGE_ELEMENT: +// src = gst_object_get_name(msg->src); +// if (strcmp(src, "zbar")) { +// break; +// } +// strctr = gst_message_get_structure(msg); +// code = gst_structure_get_string(strctr, "symbol"); +// g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "message %s: %d (%s) - decoded: %s", src, msg->type, gst_message_type_get_name(msg->type), code); +// break; +// default: +// g_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "unknown message (ext %d): %s", GST_MESSAGE_TYPE_IS_EXTENDED(msg), GST_MESSAGE_TYPE_NAME(msg)); +// break; +// } +// +// return true; +//} +// +////GtkWidget* ui_build_scan_attach(GtkWidget *front_scan, const char *device) { +//// int r; +//// struct kee_scanner scan; +//// GtkWidget *view; +//// +//// //scan = &ui->scan; +//// scan_init(&scan, device); +//// r = scan_begin(&scan); +//// if (r) { +//// g_log(G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, "fail scan setup"); +//// return NULL; +//// } +//// view = GTK_WIDGET(scan.video_view); +//// gtk_box_append(GTK_BOX(front_scan), view); +//// scan_set_handler(&scan, ui_scan_code_handler); +//// return view; +////} +// +////void ui_handle_scan(GtkApplication *app, struct kee_context *ctx) { +//void ui_handle_scan(GtkApplication *app, KeeUicontext *uctx) { +void ui_handle_scan(KeeUicontext *uctx) { // int r; +// GtkWidget *front_scan; // struct kee_scanner scan; +// char *device; // GtkWidget *view; +// //struct kee_scanner *scan; // +// //ui = (struct ui_container*)ctx->front; +// //s = settings_get(ctx->settings, SETTINGS_VIDEO); // //scan = &ui->scan; +// +// g_object_get(uctx, "camera_device", &device, NULL); +// //g_object_get(uctx, "camera_scan", &scan, NULL); +// g_object_get(uctx, "camera_view", &front_scan, NULL); +// +// //if (ui->state & KEE_ST_SCAN_INIT) { +//// if (scan.video_view) { +//// gtk_box_remove(GTK_BOX(front_scan), GTK_WIDGET(scan.video_view)); +//// scan_free(&scan); +//// } +// // scan_init(&scan, device); // r = scan_begin(&scan); // if (r) { // g_log(G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, "fail scan setup"); -// return NULL; +// return; // } // view = GTK_WIDGET(scan.video_view); // gtk_box_append(GTK_BOX(front_scan), view); // scan_set_handler(&scan, ui_scan_code_handler); -// return view; -//} - -//void ui_handle_scan(GtkApplication *app, struct kee_context *ctx) { -void ui_handle_scan(GtkApplication *app, KeeUicontext *uctx) { - int r; - GtkWidget *front_scan; - struct kee_scanner scan; - char *device; - GtkWidget *view; - //struct kee_scanner *scan; - - //ui = (struct ui_container*)ctx->front; - //s = settings_get(ctx->settings, SETTINGS_VIDEO); - //scan = &ui->scan; - - g_object_get(uctx, "camera_device", &device, NULL); - //g_object_get(uctx, "camera_scan", &scan, NULL); - g_object_get(uctx, "camera_view", &front_scan, NULL); - - //if (ui->state & KEE_ST_SCAN_INIT) { -// if (scan.video_view) { -// gtk_box_remove(GTK_BOX(front_scan), GTK_WIDGET(scan.video_view)); -// scan_free(&scan); -// } - - scan_init(&scan, device); - r = scan_begin(&scan); - if (r) { - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, "fail scan setup"); - return; - } - view = GTK_WIDGET(scan.video_view); - gtk_box_append(GTK_BOX(front_scan), view); - scan_set_handler(&scan, ui_scan_code_handler); - -// ui_build_scan_attach(uctx, (const char*)s); - //ui_state_change(ui, KEE_ST_SCAN_INIT, 0); - //gtk_stack_set_visible_child(GTK_STACK(ui->stack), GTK_WIDGET(front_scan)); - g_object_set(uctx, "ui_push", GTK_BOX(front_scan), NULL); +// +//// ui_build_scan_attach(uctx, (const char*)s); +// //ui_state_change(ui, KEE_ST_SCAN_INIT, 0); +// //gtk_stack_set_visible_child(GTK_STACK(ui->stack), GTK_WIDGET(front_scan)); +// g_object_set(uctx, "ui_push", GTK_BOX(front_scan), NULL); } diff --git a/src/gtk/ui.h b/src/gtk/ui.h @@ -7,26 +7,27 @@ #include "settings.h" #include "kee-uicontext.h" -struct ui_container { - GtkApplication *gapp; - GtkApplicationWindow *win; - //GtkStack *stack; - GListModel *front_list; - GListModel *camera_list; - GtkBox *front_scan; - GtkHeaderBar *head; - //struct kee_scanner scan; - struct kee_context *ctx; - int state; -}; +//struct ui_container { +// GtkApplication *gapp; +// GtkApplicationWindow *win; +// //GtkStack *stack; +// GListModel *front_list; +// GListModel *camera_list; +// GtkBox *front_scan; +// GtkHeaderBar *head; +// //struct kee_scanner scan; +// struct kee_context *ctx; +// int state; +//}; -int ui_init(struct ui_container *ui); -int ui_setup(KeeUicontext *ctx); +//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); +//int ui_state_change(struct ui_container *ui, int set, int reset); +//void ui_free(struct ui_container *ui); //void ui_handle_scan(GtkApplication *app, struct kee_context *ctx); -void ui_handle_scan(GtkApplication *app, KeeUicontext *uctx); +//void ui_handle_scan(GtkApplication *app, KeeUicontext *uctx); +void ui_handle_scan(KeeUicontext *uctx); #endif // _UI_H