commit 2847c27689687694f98564b7f6151eb52684a24e
parent 438a9f617a4323d01c3425b4b0d30841ccd9f9d3
Author: lash <dev@holbrook.no>
Date: Sun, 24 Mar 2024 17:58:10 +0000
Add list model implementation for database backend
Diffstat:
10 files changed, 174 insertions(+), 41 deletions(-)
diff --git a/src/context.c b/src/context.c
@@ -6,18 +6,11 @@
#include "err.h"
-int kee_context_new(struct kee_context *ctx, void *front, struct kee_settings *settings) {
- int r;
-
+int kee_context_new(struct kee_context *ctx, struct kee_settings *settings) {
memset(ctx, 0, sizeof(struct kee_context));
- ctx->front = front;
ctx->state = 1;
ctx->settings = settings;
- r = kee_camera_scan(&ctx->camera_devices);
- if (r) {
- return r;
- }
return ERR_OK;
}
@@ -26,5 +19,4 @@ int kee_context_state(struct kee_context *ctx) {
}
void kee_context_free(struct kee_context *ctx) {
- kee_camera_free(&ctx->camera_devices);
}
diff --git a/src/context.h b/src/context.h
@@ -13,7 +13,7 @@ struct kee_context {
int state;
};
-int kee_context_new(struct kee_context *ctx, void *front, struct kee_settings *settings);
+int kee_context_new(struct kee_context *ctx, struct kee_settings *settings);
int kee_context_state(struct kee_context *ctx);
void kee_context_free(struct kee_context *ctx);
diff --git a/src/gtk/kee-entry-list.c b/src/gtk/kee-entry-list.c
@@ -0,0 +1,43 @@
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+#include "kee-entry-list.h"
+#include "err.h"
+
+typedef struct {
+} KeeEntryListPrivate;
+
+struct _KeeEntryList {
+ GtkWidget parent;
+ GListModel *list;
+ GtkListItemFactory *factory;
+};
+
+G_DEFINE_TYPE(KeeEntryList, kee_entry_list, GTK_TYPE_BOX);
+
+static void kee_entry_handle_setup(KeeEntryList* o, GObject *item, gpointer user_data) {
+}
+
+static void kee_entry_list_class_init(KeeEntryListClass *kls) {
+}
+
+static void kee_entry_list_init(KeeEntryList *o) {
+ o->factory = gtk_signal_list_item_factory_new();
+ g_signal_connect(o->factory, "setup", G_CALLBACK(kee_entry_handle_setup), NULL);
+}
+
+GtkWidget* kee_entry_list_new(GListModel *model) {
+ KeeEntryList *o;
+ GtkSingleSelection *sel;
+ GtkWidget *view;
+
+ o = g_object_new(KEE_TYPE_ENTRY_LIST, "orientation", GTK_ORIENTATION_VERTICAL, "spacing", 10, NULL);
+
+ sel = gtk_single_selection_new(model);
+
+ view = gtk_list_view_new(GTK_SELECTION_MODEL(sel), o->factory);
+
+ gtk_box_append(GTK_BOX(o), view);
+
+ return GTK_WIDGET(o);
+}
diff --git a/src/gtk/kee-entry-list.h b/src/gtk/kee-entry-list.h
@@ -0,0 +1,16 @@
+#ifndef _GTK_KEE_ENTRY_LIST_H
+#define _GTK_KEE_ENTRY_LIST_H
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define KEE_TYPE_ENTRY_LIST kee_entry_list_get_type()
+G_DECLARE_FINAL_TYPE(KeeEntryList, kee_entry_list, KEE, ENTRY_LIST, GtkBox);
+
+GtkWidget* kee_entry_list_new(GListModel *model);
+
+G_END_DECLS
+
+#endif // _GTK_KEE_ENTRY_LIST_H
diff --git a/src/gtk/kee-entry-store.c b/src/gtk/kee-entry-store.c
@@ -0,0 +1,56 @@
+#include <glib-object.h>
+#include <gtk/gtk.h>
+#include <gio/gio.h>
+
+#include "kee-entry-store.h"
+
+
+typedef struct {
+} KeeEntryStorePrivate;
+
+struct _KeeEntryStore {
+ GObject parent;
+ struct db_ctx *db;
+};
+
+static void kee_entry_store_iface_init(GListModelInterface *ifc);
+G_DEFINE_TYPE_WITH_CODE(KeeEntryStore, kee_entry_store, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(G_TYPE_LIST_MODEL, kee_entry_store_iface_init));
+
+// \todo add construct pointer for db
+static void kee_entry_store_class_init(KeeEntryStoreClass *kls) {
+}
+
+
+static void kee_entry_store_init(KeeEntryStore *o) {
+}
+
+
+static GType kee_entry_store_get_item_type(GListModel *list) {
+ return GTK_TYPE_WIDGET;
+}
+
+
+static guint kee_entry_store_get_n_items(GListModel *list) {
+ return 1;
+}
+
+
+static gpointer kee_entry_store_get_item(GListModel *list, guint index) {
+ return gtk_label_new("foo");
+}
+
+
+static void kee_entry_store_iface_init(GListModelInterface *ifc) {
+ ifc->get_item_type = kee_entry_store_get_item_type;
+ ifc->get_n_items = kee_entry_store_get_n_items;
+ ifc->get_item = kee_entry_store_get_item;
+}
+
+KeeEntryStore* kee_entry_store_new(struct db_ctx *db) {
+ KeeEntryStore *o;
+
+ o = g_object_new(KEE_TYPE_ENTRY_STORE, NULL);
+ o->db = db;
+
+ return o;
+}
diff --git a/src/gtk/kee-entry-store.h b/src/gtk/kee-entry-store.h
@@ -0,0 +1,16 @@
+#ifndef _GTK_KEE_ENTRY_STORE_H
+#define _GTK_KEE_ENTRY_STORE_H
+
+#include <glib-object.h>
+#include "db.h"
+
+G_BEGIN_DECLS
+
+#define KEE_TYPE_ENTRY_STORE kee_entry_store_get_type()
+G_DECLARE_FINAL_TYPE(KeeEntryStore, kee_entry_store, KEE, ENTRY_STORE, GObject);
+
+KeeEntryStore* kee_entry_store_new(struct db_ctx *db);
+
+G_END_DECLS
+
+#endif // _GTK_KEE_ENTRY_STORE_H
diff --git a/src/gtk/kee-import.c b/src/gtk/kee-import.c
@@ -4,6 +4,7 @@
#include "kee-import.h"
#include "kee-menu.h"
+#include "kee-entry-list.h"
#include "camera.h"
#include "scan.h"
#include "err.h"
@@ -81,6 +82,7 @@ static void kee_import_class_init(KeeImportClass *kls) {
KEE_TYPE_MENU,
G_PARAM_WRITABLE);
+
g_object_class_install_properties(o, KEE_N_IMPORT_PROPS, kee_props);
}
diff --git a/src/gtk/main.c b/src/gtk/main.c
@@ -4,20 +4,21 @@
#include <gst/gst.h>
#include "ui.h"
-#include "menu.h"
+//#include "menu.h"
#include "settings.h"
+#include "context.h"
//static void state_log(KeeUicontext *uctx, char state_hint, kee_state_t *new_state, kee_state_t *old_state) {
// g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "new state hint: %d", state_hint);
//}
-static void startup(GtkApplication *app) {
+static void startup(GtkApplication *app, struct kee_context *ctx) {
// kee_uicontext_scaninit(uctx);
}
-static void activate(GtkApplication *app) {
- ui_build(app);
+static void activate(GtkApplication *app, struct kee_context *ctx) {
+ ui_build(app, ctx);
}
static void deactivate(GtkApplication *app, gpointer user_data) {
@@ -28,6 +29,7 @@ int main(int argc, char **argv) {
int r;
struct kee_settings settings;
GtkApplication *gapp;
+ struct kee_context ctx;
gtk_init();
gst_init(0, NULL);
@@ -37,10 +39,14 @@ int main(int argc, char **argv) {
settings_new_from_xdg(&settings);
settings_init(&settings);
- //db_connect(&ctx.db, "./testdata_mdb");
+ r = kee_context_new(&ctx, &settings);
+ if (r) {
+ return r;
+ }
+ db_connect(&ctx.db, "./testdata_mdb");
- g_signal_connect (gapp, "startup", G_CALLBACK (startup), NULL);
- g_signal_connect (gapp, "activate", G_CALLBACK (activate), NULL);
+ g_signal_connect (gapp, "startup", G_CALLBACK (startup), &ctx);
+ g_signal_connect (gapp, "activate", G_CALLBACK (activate), &ctx);
g_signal_connect (gapp, "shutdown", G_CALLBACK (deactivate), NULL);
//g_signal_connect (uctx, "state", G_CALLBACK(state_log), NULL);
diff --git a/src/gtk/ui.c b/src/gtk/ui.c
@@ -12,13 +12,12 @@
#include "view.h"
#include "menu.h"
#include "kee-import.h"
+#include "kee-entry-list.h"
+#include "kee-entry-store.h"
#include "kee-menu.h"
#include "kee-key.h"
-static void new_item(GtkListItemFactory *factory, GtkListItem *item, gpointer user_data) {
-}
-
static void ui_handle_unlock(GtkWidget *widget, KeeMenu *menu) {
kee_state_t state_delta;
@@ -28,29 +27,30 @@ static void ui_handle_unlock(GtkWidget *widget, KeeMenu *menu) {
kee_menu_prev(menu);
}
-
-static GtkWidget* ui_build_view(KeeMenu *menu) {
- 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);
-
- front_list = G_LIST_MODEL(gtk_string_list_new(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);
-}
+//
+//static GtkWidget* ui_build_view(KeeMenu *menu) {
+// 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);
+//
+// front_list = G_LIST_MODEL(gtk_string_list_new(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) {
+void ui_build(GtkApplication *app, struct kee_context *ctx) {
GtkWidget *widget;
KeeMenu *win;
KeeImport *import;
+ KeeEntryStore *store;
win = kee_menu_new(app);
@@ -58,7 +58,9 @@ void ui_build(GtkApplication *app) {
kee_menu_add(win, "unlock", widget);
g_signal_connect (widget, "unlock", G_CALLBACK(ui_handle_unlock), win);
- widget = ui_build_view(NULL);
+// widget = ui_build_view(NULL);
+ store = kee_entry_store_new(&ctx->db);
+ widget = kee_entry_list_new(G_LIST_MODEL(store));
kee_menu_add(win, "view", widget);
kee_menu_next(win, "view");
diff --git a/src/gtk/ui.h b/src/gtk/ui.h
@@ -2,10 +2,10 @@
#define _UI_H
#include <gtk/gtk.h>
-#include "kee-import.h"
+#include "context.h"
//void ui_build(GtkApplication *app, KeeUicontext *uctx);
-void ui_build(GtkApplication *app);
+void ui_build(GtkApplication *app, struct kee_context *ctx);
#endif // _UI_H