commit 52782405e9a28558c4b000d47cb7a7a18518b714
parent 6977e4a23643ba8cb76367c6027eeec3d8b48930
Author: lash <dev@holbrook.no>
Date: Sun, 24 Mar 2024 15:55:42 +0000
Complete migration to gobjects for each main wigdet
Diffstat:
13 files changed, 66 insertions(+), 159 deletions(-)
diff --git a/src/gtk/kee-import.c b/src/gtk/kee-import.c
@@ -22,6 +22,8 @@ struct _KeeImport {
struct kee_camera_devices camera_device;
struct kee_scanner scan;
GtkStack *stack;
+ GtkBox *viewbox;
+ GtkWidget *toggler_text;
};
G_DEFINE_TYPE(KeeImport, kee_import, GTK_TYPE_BOX);
@@ -87,6 +89,7 @@ static void kee_import_init(KeeImport *o) {
kee_import_refresh(o);
memset(&o->scan, 0, sizeof(struct kee_scanner));
o->stack = GTK_STACK(gtk_stack_new());
+ o->viewbox = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL, 0));
}
static void kee_import_handle_camera_change(GtkDropDown *chooser, GParamSpec *spec, KeeImport *import) {
@@ -101,7 +104,8 @@ static void kee_import_handle_camera_change(GtkDropDown *chooser, GParamSpec *sp
}
static void kee_import_handle_import_data_focus(KeeImport *o, const char *data, GtkStack *stack) {
- gtk_stack_set_visible_child_name(stack, KEE_ACT_SCAN_TEXT);
+ //gtk_stack_set_visible_child_name(stack, KEE_ACT_SCAN_TEXT);
+ gtk_widget_activate(o->toggler_text);
}
static void kee_import_handle_import_data_text(KeeImport *o, const char *data, GtkTextBuffer *buf) {
@@ -109,10 +113,13 @@ static void kee_import_handle_import_data_text(KeeImport *o, const char *data, G
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "import data %s", data);
}
-static void kee_import_handle_import_data_accept(KeeImport *o, const char *data, GActionMap *am) {
+static void kee_import_handle_import_data_accept(KeeImport *o, const char *data) {
GAction *act;
+ GActionMap *am;
- g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "import accept %s", data);
+ g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "import accept");
+
+ am = G_ACTION_MAP(gtk_window_get_application(GTK_WINDOW(o->win)));
act = g_action_map_lookup_action(am, "import_data_accept");
g_simple_action_set_enabled(G_SIMPLE_ACTION(act), true);
@@ -161,6 +168,7 @@ static GtkWidget* kee_import_build_scan_footer(KeeImport *import, GtkStack *stac
gtk_action_bar_pack_start(GTK_ACTION_BAR(foot), butt);
gtk_actionable_set_action_name(GTK_ACTIONABLE(butt), "import.src");
gtk_actionable_set_action_target_value(GTK_ACTIONABLE(butt), v);
+ import->toggler_text = butt;
butt_prev = GTK_TOGGLE_BUTTON(butt);
v = g_variant_new_string(KEE_ACT_SCAN_FILE);
@@ -183,7 +191,6 @@ static GtkWidget* kee_import_build_scan_videochooser(KeeImport *o) {
exp_label = gtk_property_expression_new(GTK_TYPE_LABEL, NULL, "label");
- //camera_list = kee_import_get_camera_list(import);
chooser = gtk_drop_down_new(o->camera_list, exp_label);
g_signal_connect(chooser, "notify::selected-item", G_CALLBACK (kee_import_handle_camera_change), o);
@@ -214,9 +221,9 @@ static GtkWidget* kee_import_build_import_text(KeeImport *o, GtkStack *stack) {
gtk_box_append(GTK_BOX(box), butt);
g_signal_connect(o, "data_available", G_CALLBACK(kee_import_handle_import_data_text), gtk_text_view_get_buffer(txt));
- //g_signal_connect(import, "data_available", G_CALLBACK(ui_handle_import_data_accept), app); // replace with import
+ g_signal_connect(o, "data_available", G_CALLBACK(kee_import_handle_import_data_accept), NULL);
g_signal_connect(o, "data_available", G_CALLBACK(kee_import_handle_import_data_focus), stack);
- //g_signal_connect(import, "data_available", G_CALLBACK(ui_handle_import_data_check), butt);
+ g_signal_connect(o, "data_available", G_CALLBACK(kee_import_handle_import_data_check), butt);
return box;
}
@@ -234,11 +241,11 @@ KeeImport* kee_import_new(KeeMenu *win) {
gtk_box_append(GTK_BOX(o), GTK_WIDGET(o->stack));
- //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(widget), chooser);
+ gtk_box_append(GTK_BOX(widget), GTK_WIDGET(o->viewbox));
+
gtk_stack_add_named(o->stack, widget, KEE_ACT_SCAN_QR);
widget = kee_import_build_import_text(o, o->stack);
@@ -250,7 +257,6 @@ KeeImport* kee_import_new(KeeMenu *win) {
gtk_box_append(GTK_BOX(o), widget);
return o;
- //return box_outer;
}
static void kee_import_scanadd(KeeImport *o, GtkLabel *label) {
@@ -284,13 +290,13 @@ int kee_import_refresh(KeeImport *o) {
static void kee_import_apply_viewfinder(KeeImport *o) {
GtkWidget *p;
- p = gtk_widget_get_first_child(GTK_WIDGET(o));
+ p = gtk_widget_get_first_child(GTK_WIDGET(o->viewbox));
if (p) {
- gtk_box_remove(GTK_BOX(o), p);
+ gtk_box_remove(GTK_BOX(o->viewbox), p);
}
p = GTK_WIDGET(o->scan.video_view);
- gtk_box_append(GTK_BOX(o), p);
+ gtk_box_append(GTK_BOX(o->viewbox), p);
gtk_widget_set_visible(GTK_WIDGET(o), true);
}
@@ -360,10 +366,6 @@ int kee_import_scanchange(KeeImport *o, const char *device) {
return ERR_OK;
}
-//GListModel* kee_import_get_camera_list(KeeImport *o) {
-// return o->camera_list;
-//}
-
void kee_import_free(KeeImport *o) {
kee_camera_free(&o->camera_device);
scan_free(&o->scan);
diff --git a/src/gtk/kee-key.c b/src/gtk/kee-key.c
@@ -17,9 +17,21 @@ struct _KeeKey {
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 guint kee_sigs[KEE_N_KEY_SIGS] = {0,};
static void kee_key_class_init(KeeKeyClass *kls) {
+ GObjectClass *o = G_OBJECT_CLASS(kls);
+
+ kee_sigs[KEE_S_KEY_UNLOCKED] = g_signal_new("unlock",
+ 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);
}
static void kee_key_init(KeeKey *o) {
@@ -34,6 +46,7 @@ static void kee_key_handle_unlock_click(GtkWidget *button, GObject *o) {
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "click");
//kee_uicontext_unlock(uctx);
+ g_signal_emit(o, kee_sigs[KEE_S_KEY_UNLOCKED], 0);
gtk_entry_buffer_delete_text(buf, 0, gtk_entry_buffer_get_length(buf));
}
diff --git a/src/gtk/kee-key.h b/src/gtk/kee-key.h
@@ -10,6 +10,7 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE(KeeKey, kee_key, KEE, KEY, GtkBox)
enum KEE_KEY_SIGS {
+ KEE_S_KEY_UNLOCKED,
KEE_N_KEY_SIGS,
};
diff --git a/src/gtk/kee-menu.c b/src/gtk/kee-menu.c
@@ -78,6 +78,20 @@ KeeMenu* kee_menu_new(GtkApplication *gapp) {
}
+/// \todo less strcmp
+static void kee_menu_header_update(KeeMenu *o, const char *label) {
+ GAction *act;
+
+ if (!(strcmp(label, "unlock"))) {
+ } else if (!(strcmp(label, "view"))) {
+ act = g_action_map_lookup_action(G_ACTION_MAP(o), "import");
+ g_simple_action_set_enabled(G_SIMPLE_ACTION(act), true);
+ } else if (!(strcmp(label, "import"))) {
+ } else {
+ g_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "unknown nav label: %s", label);
+ }
+}
+
int kee_menu_add(KeeMenu *o, const char *label, GtkWidget *widget) {
gtk_stack_add_named(o->stack, widget, label);
return ERR_OK;
@@ -93,11 +107,13 @@ int kee_menu_next(KeeMenu *o, const char *label) {
}
int kee_menu_prev(KeeMenu *o) {
+ const char *label;
+
kee_nav_pop(&o->nav);
gtk_stack_set_visible_child(o->stack, o->nav.now);
+ label = gtk_stack_get_visible_child_name(o->stack);
+
+ kee_menu_header_update(o, label);
+
return ERR_OK;
}
-
-//GtkWidget* kee_menu_get_stack(KeeMenu *o) {
-// return GTK_WIDGET(o->stack);
-//}
diff --git a/src/gtk/kee-uicontext.c b/src/gtk/kee-uicontext.c
@@ -1,73 +0,0 @@
-#include <glib-object.h>
-#include <gtk/gtk.h>
-
-#include "kee-uicontext.h"
-//#include "ui.h"
-#include "context.h"
-#include "state.h"
-#include "settings.h"
-
-
-typedef struct {
-} KeeUicontextPrivate;
-
-struct _KeeUicontext {
- GObject parent;
- kee_state_t state;
-};
-
-G_DEFINE_TYPE(KeeUicontext, kee_uicontext, G_TYPE_OBJECT)
-
-static guint kee_sigs[KEE_N_SIGS] = {0,};
-
-static void kee_uicontext_class_init(KeeUicontextClass *kls) {
- GObjectClass *o = G_OBJECT_CLASS(kls);
-
- kee_sigs[KEE_S_STATE_CHANGE] = 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,
- 3,
- G_TYPE_CHAR,
- G_TYPE_POINTER,
- G_TYPE_POINTER
- );
-
- kee_sigs[KEE_S_KEY_UNLOCKED] = g_signal_new("unlock",
- 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
- );
-}
-
-static void kee_uicontext_init(KeeUicontext *o) {
- //KeeUicontextPrivate *o = kee_uicontext_get_instance_private(self);
-}
-
-void kee_uicontext_unlock(KeeUicontext *o) {
- g_signal_emit(o, kee_sigs[KEE_S_KEY_UNLOCKED], 0);
-}
-
-void kee_uicontext_state_change(KeeUicontext *o, kee_state_t *add, kee_state_t *sub) {
- kee_state_t old_state;
- char hint;
-
- hint = 0;
-
- if (add) {
- hint = kee_state_add(&o->state, add);
- }
- memcpy(&old_state, &o->state, sizeof(kee_state_t));
- g_signal_emit(o, kee_sigs[KEE_S_STATE_CHANGE], 0, hint, &o->state, &old_state);
-}
-
diff --git a/src/gtk/kee-uicontext.h b/src/gtk/kee-uicontext.h
@@ -8,12 +8,12 @@
G_BEGIN_DECLS
-
-enum KEE_SIGS {
- KEE_S_STATE_CHANGE,
- KEE_S_KEY_UNLOCKED,
- KEE_N_SIGS,
-};
+//
+//enum KEE_SIGS {
+// KEE_S_STATE_CHANGE,
+// KEE_S_KEY_UNLOCKED,
+// KEE_N_SIGS,
+//};
#define KEE_TYPE_UICONTEXT kee_uicontext_get_type()
G_DECLARE_FINAL_TYPE(KeeUicontext, kee_uicontext, KEE, UICONTEXT, GObject)
diff --git a/src/gtk/main.c b/src/gtk/main.c
@@ -12,7 +12,7 @@
// g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "new state hint: %d", state_hint);
//}
-static void startup(GtkApplication *app, KeeUicontext *uctx) {
+static void startup(GtkApplication *app) {
// kee_uicontext_scaninit(uctx);
}
@@ -27,7 +27,6 @@ static void deactivate(GtkApplication *app, gpointer user_data) {
int main(int argc, char **argv) {
int r;
struct kee_settings settings;
- struct kee_context ctx;
GtkApplication *gapp;
gtk_init();
@@ -38,19 +37,15 @@ int main(int argc, char **argv) {
settings_new_from_xdg(&settings);
settings_init(&settings);
- //uctx = g_object_new(KEE_TYPE_UICONTEXT, NULL);
//db_connect(&ctx.db, "./testdata_mdb");
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), NULL);
- //g_signal_connect (uctx, "unlock", G_CALLBACK(ui_handle_unlock), uctx);
//g_signal_connect (uctx, "state", G_CALLBACK(state_log), NULL);
r = g_application_run (G_APPLICATION (gapp), argc, argv);
g_object_unref(gapp);
- kee_context_free(&ctx);
return r;
}
diff --git a/src/gtk/menu.c b/src/gtk/menu.c
@@ -1,9 +1,7 @@
#include <glib-object.h>
#include <gtk/gtk.h>
-#include "kee-uicontext.h"
#include "kee-menu.h"
-//#include "ui.h"
#include "scan.h"
#include "context.h"
#include "state.h"
diff --git a/src/gtk/menu.h b/src/gtk/menu.h
@@ -1,15 +1,12 @@
#ifndef _KEE_GTK_MENU_H
#define _KEE_GTK_MENU_H
-#include "kee-uicontext.h"
-
#define KEE_W_HEADER "header"
#define KEE_W_FOOTER "footer"
#define KEE_W_UI_MENU_QUICK_ADD "quick_add"
#define KEE_W_UI_MENU_ACT_IMPORT "act_import"
-GtkWidget* header_setup(GtkApplication *gapp, KeeUicontext *uctx);
GtkWidget* menu_button_setup(GObject *head, GtkApplication *gapp);
#endif // _KEE_GTK_MENU_H
diff --git a/src/gtk/scan.c b/src/gtk/scan.c
@@ -5,7 +5,6 @@
#include "scan.h"
#include "err.h"
-#include "kee-uicontext.h"
void scan_init(struct kee_scanner *scan, const char *device) {
diff --git a/src/gtk/scan.h b/src/gtk/scan.h
@@ -4,8 +4,6 @@
#include <gst/gst.h>
#include <gtk/gtk.h>
-#include "kee-uicontext.h"
-
struct kee_scanner {
GtkPicture *video_view;
@@ -21,6 +19,6 @@ void scan_init(struct kee_scanner *scan, const char *device);
int scan_begin(struct kee_scanner *scan);
void scan_free(struct kee_scanner *scan);
void scan_set_handler(struct kee_scanner *scan, gboolean(*fn)(GstBus *bus, GstMessage *msg, gpointer user_data));
-void scan_act(GSimpleAction *act, GVariant *param, KeeUicontext *ui);
+//void scan_act(GSimpleAction *act, GVariant *param, KeeUicontext *ui);
#endif // _KEE_GTK_SCAN_H
diff --git a/src/gtk/ui.c b/src/gtk/ui.c
@@ -19,44 +19,17 @@
static void new_item(GtkListItemFactory *factory, GtkListItem *item, gpointer user_data) {
}
-
-//
-//static void win_handle_state(KeeUicontext *uctx, char state_hint, kee_state_t *new_state, kee_state_t *old_state, GtkWindow *win) {
-// GAction *act;
-//
-// if (!(state_hint & KEE_ST_HINT_UI_MENU)) {
-// return;
-// }
-//
-// if (new_state->ui_menu & KEE_ST_UI_HEAD_ADD) {
-// act = g_action_map_lookup_action(G_ACTION_MAP(win), "import");
-// g_simple_action_set_enabled(G_SIMPLE_ACTION(act), true);
-// }
-//}
-
-
-
-
-// \todo why is there user_data in addition to pointer
-
-
-
-void ui_handle_unlock(KeeUicontext *uctx, gpointer user_data) {
+static void ui_handle_unlock(GtkWidget *widget, KeeMenu *menu) {
kee_state_t state_delta;
kee_state_zero(&state_delta);
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "key is unlocked");
- kee_view_prev();
-
- //state_delta.ui_menu |= KEE_ST_UI_HEAD_ADD;
- //kee_uicontext_state_change(uctx, &state_delta, NULL);
+ kee_menu_prev(menu);
}
-
-
-static GtkWidget* ui_build_view(KeeUicontext *uctx) {
+static GtkWidget* ui_build_view(KeeMenu *menu) {
GtkListItemFactory *factory;
GtkSelectionModel *sel;
GListModel *front_list;
@@ -66,7 +39,6 @@ static GtkWidget* ui_build_view(KeeUicontext *uctx) {
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);
sel = GTK_SELECTION_MODEL(gtk_single_selection_new(front_list));
front_view = GTK_LIST_VIEW(gtk_list_view_new(GTK_SELECTION_MODEL(sel), factory));
@@ -80,28 +52,19 @@ void ui_build(GtkApplication *app) {
KeeMenu *win;
KeeImport *import;
- win = kee_menu_new(app); //g_object_new(KEE_TYPE_MENU, "application", app, NULL);
+ win = kee_menu_new(app);
widget = GTK_WIDGET(kee_key_new());
kee_menu_add(win, "unlock", widget);
+ g_signal_connect (widget, "unlock", G_CALLBACK(ui_handle_unlock), win);
widget = ui_build_view(NULL);
kee_menu_add(win, "view", widget);
- //widget = ui_build_scan(uctx);
- //kee_view_add(widget, "import");
-
kee_menu_next(win, "view");
kee_menu_next(win, "unlock");
-
- //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);
-
- //g_signal_connect (uctx, "state", G_CALLBACK(win_handle_state), win);
import = kee_import_new(win);
- //import = g_object_new(KEE_TYPE_IMPORT, "orientation", GTK_ORIENTATION_VERTICAL, NULL);
kee_menu_add(win, "import", GTK_WIDGET(import));
gtk_window_present(GTK_WINDOW (win));
diff --git a/src/gtk/ui.h b/src/gtk/ui.h
@@ -2,12 +2,10 @@
#define _UI_H
#include <gtk/gtk.h>
-#include "kee-uicontext.h"
#include "kee-import.h"
//void ui_build(GtkApplication *app, KeeUicontext *uctx);
void ui_build(GtkApplication *app);
-void ui_handle_unlock(KeeUicontext *uctx, gpointer user_data);
#endif // _UI_H