commit 396a76c666418fcc55ab767733cc99b494cf6a09
parent a987217d660e5da50f2626b3e1783dbe66956ee1
Author: lash <dev@holbrook.no>
Date: Mon, 18 Mar 2024 01:19:25 +0000
Add page stack and navigation
Diffstat:
10 files changed, 128 insertions(+), 22 deletions(-)
diff --git a/Makefile b/Makefile
@@ -21,3 +21,6 @@ run: gtk all
debug: gtk all
G_DEBUG=3 G_MESSAGES_DEBUG=all ./src/gtk/a.out
+
+test: gtk all
+ make -C src/gtk/tests
diff --git a/src/gtk/kee-uicontext.c b/src/gtk/kee-uicontext.c
@@ -200,10 +200,26 @@ static void kee_uicontext_class_init(KeeUicontextClass *kls) {
g_object_class_install_properties(o, KEE_N_PROPS, kee_props);
}
-static void kee_uicontext_init(KeeUicontext *self) {
+static void kee_uicontext_init(KeeUicontext *o) {
//KeeUicontextPrivate *o = kee_uicontext_get_instance_private(self);
}
+void kee_uicontext_scaninit(KeeUicontext *o) {
+ struct kee_camera_devices *camera_device;
+ GtkWidget *label;
+
+ camera_device = &o->ctx->camera_devices;
+ while(1) {
+ label = gtk_label_new(camera_device->label);
+ g_object_set_data(G_OBJECT(label), "devpath", camera_device->path);
+ kee_uicontext_scanadd(o, GTK_LABEL(label));
+ if (camera_device->next == NULL) {
+ break;
+ }
+ camera_device = camera_device->next;
+ }
+}
+
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);
@@ -215,25 +231,11 @@ void kee_uicontext_scanadd(KeeUicontext *o, GtkLabel *label) {
}
void kee_uicontext_scanstart(KeeUicontext *o) {
- GtkWidget *label;
- struct kee_camera_devices *camera_device;
-
if (KEE_IS_SCANNING(o->ui)) {
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "already in scanning state");
return;
}
- camera_device = &o->ctx->camera_devices;
- while(1) {
- label = gtk_label_new(camera_device->label);
- g_object_set_data(G_OBJECT(label), "devpath", camera_device->path);
- g_list_store_append(G_LIST_STORE(o->ui->camera_list), GTK_LABEL(label));
- kee_uicontext_scanadd(o, GTK_LABEL(label));
- if (camera_device->next == NULL) {
- break;
- }
- camera_device = camera_device->next;
- }
ui_state_change(o->ui, KEE_ST_SCAN_SEARCH, 0);
g_signal_emit(o, kee_sigs[SCAN_WANT], 0);
}
diff --git a/src/gtk/kee-uicontext.h b/src/gtk/kee-uicontext.h
@@ -36,6 +36,7 @@ enum KEE_PROPS {
G_DECLARE_FINAL_TYPE(KeeUicontext, kee_uicontext, KEE, UICONTEXT, GObject)
KeeUicontext* kee_uicontext_new(void);
+void kee_uicontext_scaninit(KeeUicontext *o);
void kee_uicontext_scanstart(KeeUicontext *o);
void kee_uicontext_scanadd(KeeUicontext *o, GtkLabel *label);
void kee_uicontext_scanchange(KeeUicontext *o, const char *devices);
diff --git a/src/gtk/main.c b/src/gtk/main.c
@@ -11,6 +11,7 @@
static void startup(GtkApplication *app, KeeUicontext *uctx) {
+ kee_uicontext_scaninit(uctx);
menu_setup(uctx);
ui_setup(uctx);
}
diff --git a/src/gtk/nav.c b/src/gtk/nav.c
@@ -0,0 +1,30 @@
+#include <gtk/gtk.h>
+
+#include "nav.h"
+
+
+void kee_nav_push(struct KeeNav *nav, GtkWidget *page) {
+ struct KeeNav *nav_old;
+
+ nav_old = malloc(sizeof(struct KeeNav));
+ nav_old->prev = nav->prev;
+ nav_old->now = nav->now;
+ nav->prev = nav_old;
+ nav->now = page;
+}
+
+GtkWidget* kee_nav_pop(struct KeeNav *nav) {
+ struct KeeNav *nav_old;
+ GtkWidget *r;
+
+ if (!nav->prev) {
+ return NULL;
+ }
+
+ r = nav->now;
+ nav_old = nav->prev->prev;
+ nav->now = nav->prev->now;
+ free(nav->prev);
+ nav->prev = nav_old;
+ return r;
+}
diff --git a/src/gtk/nav.h b/src/gtk/nav.h
@@ -0,0 +1,14 @@
+#ifndef _KEE_NAV_H
+#define _KEE_NAV_H
+
+#include <gtk/gtk.h>
+
+struct KeeNav {
+ GtkWidget *now;
+ struct KeeNav *prev;
+};
+
+void kee_nav_push(struct KeeNav *nav, GtkWidget *page);
+GtkWidget* kee_nav_pop(struct KeeNav *nav);
+
+#endif // _KEE_NAV_H
diff --git a/src/gtk/ui.c b/src/gtk/ui.c
@@ -8,6 +8,7 @@
#include "settings.h"
#include "context.h"
#include "state.h"
+#include "view.h"
static void new_item(GtkListItemFactory *factory, GtkListItem *item, gpointer user_data) {
@@ -109,7 +110,7 @@ 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);
return GTK_WIDGET(box);
}
@@ -139,19 +140,27 @@ void ui_build(GtkApplication *app, KeeUicontext *uctx) {
GtkWidget *stack;
win = gtk_application_window_new (app);
- stack = gtk_stack_new();
gtk_window_set_title (GTK_WINDOW (win), "kee");
gtk_window_set_default_size (GTK_WINDOW (win), 800, 600);
+ stack = gtk_stack_new();
+ kee_view_init(GTK_STACK(stack));
+
widget = ui_build_unlock(uctx);
- gtk_stack_add_child(GTK_STACK(stack), widget);
- gtk_stack_set_visible_child(GTK_STACK(stack), widget);
+ 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);
- gtk_stack_add_child(GTK_STACK(stack), widget);
+ kee_view_add(widget, "view");
+ //gtk_stack_add_child(GTK_STACK(stack), widget);
widget = ui_build_scan(uctx);
- gtk_stack_add_child(GTK_STACK(stack), widget);
+ 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));
diff --git a/src/gtk/ui.h b/src/gtk/ui.h
@@ -10,7 +10,7 @@
struct ui_container {
GtkApplication *gapp;
GtkApplicationWindow *win;
- GtkStack *stack;
+ //GtkStack *stack;
GListModel *front_list;
GListModel *camera_list;
GtkBox *front_scan;
diff --git a/src/gtk/view.c b/src/gtk/view.c
@@ -0,0 +1,28 @@
+#include <gtk/gtk.h>
+
+#include "view.h"
+#include "nav.h"
+#include "err.h"
+
+static struct KeeView view;
+
+void kee_view_init(GtkStack *stack) {
+ if (view.stack != NULL) {
+ return;
+ }
+ view.stack = stack;
+}
+
+int kee_view_add(GtkWidget *widget, const char *label) {
+ gtk_stack_add_named(view.stack, widget, label);
+ return ERR_OK;
+}
+
+int kee_view_next(const char *label) {
+ GtkWidget *widget;
+
+ widget = gtk_stack_get_child_by_name(view.stack, label);
+ kee_nav_push(&view.nav, widget);
+ gtk_stack_set_visible_child(view.stack, widget);
+ return ERR_OK;
+}
diff --git a/src/gtk/view.h b/src/gtk/view.h
@@ -0,0 +1,18 @@
+#ifndef _KEE_VIEW_H
+#define _KEE_VIEW_H
+
+#include <gtk/gtk.h>
+
+#include "nav.h"
+
+struct KeeView {
+ GtkStack *stack;
+ struct KeeNav nav;
+};
+
+void kee_view_init(GtkStack *stack);
+int kee_view_add(GtkWidget *widget, const char *label);
+int kee_view_next(const char *label);
+int kee_view_prev();
+
+#endif // _KEE_VIEW_H