commit 29e22e17ac5259663822bf4d0f10a44e13951ad6
parent cb01d701ed18968d4a1c96d4f33e01d0aed6a011
Author: lash <dev@holbrook.no>
Date: Thu, 14 Mar 2024 14:49:24 +0000
Implement camera change handler
Diffstat:
5 files changed, 37 insertions(+), 21 deletions(-)
diff --git a/src/gtk/menu.c b/src/gtk/menu.c
@@ -1,17 +1,9 @@
#include <gtk/gtk.h>
#include "kee-uicontext.h"
+#include "scan.h"
-static void act_scan(GSimpleAction *act, GVariant *param, KeeUicontext *ui) {
- //GDBusConnection *conn;
-
- g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "scan clicked");
- kee_uicontext_scanstart(ui);
- //conn = g_application_get_dbus_connection(app);
-
-}
-
static void act_quit(GSimpleAction *act, GVariant *param, KeeUicontext *ui) {
GApplication *gapp;
g_object_get(ui, "app", &gapp, NULL);
@@ -47,7 +39,7 @@ void menu_setup(KeeUicontext *ui) {
act = g_simple_action_new("scan", NULL);
g_action_map_add_action(G_ACTION_MAP(gapp), G_ACTION(act));
- g_signal_connect(act, "activate", G_CALLBACK(act_scan), ui);
+ g_signal_connect(act, "activate", G_CALLBACK(scan_act), ui);
g_menu_item_set_submenu(menu_item_menu, G_MENU_MODEL(menu));
g_object_unref(menu);
diff --git a/src/gtk/scan.c b/src/gtk/scan.c
@@ -5,6 +5,7 @@
#include "scan.h"
#include "err.h"
+#include "kee-uicontext.h"
void scan_init(struct kee_scanner *scan, const char *device) {
@@ -13,10 +14,6 @@ void scan_init(struct kee_scanner *scan, const char *device) {
strcpy(scan->device, device);
}
-void scan_free(struct kee_scanner *scan) {
- free(scan->device);
-}
-
int scan_begin(struct kee_scanner *scan) {
GstElement *tee;
GstElement *zbar;
@@ -112,8 +109,21 @@ int scan_begin(struct kee_scanner *scan) {
}
void scan_set_handler(struct kee_scanner *scan, gboolean(*fn)(GstBus *bus, GstMessage *msg, gpointer user_data)) {
- GstBus *bus;
+ scan->bus = gst_element_get_bus(scan->pipeline);
+ gst_bus_add_watch(scan->bus, fn, scan);
+}
- bus = gst_element_get_bus(scan->pipeline);
- gst_bus_add_watch(bus, fn, scan);
+void scan_act(GSimpleAction *act, GVariant *param, KeeUicontext *ui) {
+ //GDBusConnection *conn;
+
+ g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "scan clicked");
+ kee_uicontext_scanstart(ui);
+ //conn = g_application_get_dbus_connection(app);
+}
+
+void scan_free(struct kee_scanner *scan) {
+ gst_object_unref(scan->bus);
+ gst_element_set_state(scan->pipeline, GST_STATE_NULL);
+ gst_object_unref(scan->pipeline);
+ free(scan->device);
}
diff --git a/src/gtk/scan.h b/src/gtk/scan.h
@@ -4,12 +4,16 @@
#include <gst/gst.h>
#include <gtk/gtk.h>
+#include "kee-uicontext.h"
+
+
struct kee_scanner {
GtkPicture *video_view;
GstElement *pipeline;
GstElement *source;
GstElement *video_sink;
GtkImage *snap;
+ GstBus *bus;
char *device;
};
@@ -17,5 +21,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);
#endif // _KEE_GTK_SCAN_H
diff --git a/src/gtk/ui.c b/src/gtk/ui.c
@@ -35,10 +35,15 @@ static void ui_handle_unlock_click(GtkWidget *button, gpointer user_data) {
static void ui_handle_camera_change(GtkDropDown *chooser, GParamSpec *spec, struct kee_context *ctx) {
GtkLabel *label;
char *s;
+ struct ui_container *ui;
+
+ ui = (struct ui_container*)ctx->front;
label = gtk_drop_down_get_selected_item(chooser);
s = g_object_get_data(G_OBJECT(label), "devpath");
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "dropdown changed: %s -> %s", spec->name, s);
+ settings_set(ctx->settings, SETTINGS_VIDEO, (unsigned char*)s);
+ ui_handle_scan(ui->gapp, ctx);
}
@@ -243,7 +248,6 @@ GtkWidget* ui_build_scan_attach(struct ui_container *ui, const char *device) {
return view;
}
-//void ui_handle_scan(GtkApplication *app, struct ui_container *ui) {
void ui_handle_scan(GtkApplication *app, struct kee_context *ctx) {
struct ui_container *ui;
unsigned char *s;
@@ -251,10 +255,11 @@ void ui_handle_scan(GtkApplication *app, struct kee_context *ctx) {
ui = (struct ui_container*)ctx->front;
s = settings_get(ctx->settings, SETTINGS_VIDEO);
- if (!(ui->state & KEE_UI_STATE_SCAN_INIT)) {
- ui_build_scan_attach(ui, (const char*)s);
-
+ if (ui->state & KEE_UI_STATE_SCAN_INIT) {
+ scan_free(&ui->scan);
}
+
+ ui_build_scan_attach(ui, (const char*)s);
ui_state_change(ui, KEE_UI_STATE_SCANNING | KEE_UI_STATE_SCAN_INIT, 0);
gtk_stack_set_visible_child(GTK_STACK(ui->stack), GTK_WIDGET(ui->front_scan));
}
diff --git a/src/settings.c b/src/settings.c
@@ -100,6 +100,10 @@ int settings_set(struct kee_settings *z, enum SettingsType typ, unsigned char* v
case SETTINGS_LOCKTIME:
z->locktime = v;
break;
+ case SETTINGS_VIDEO:
+ z->video_device = v;
+ break;
+
default:
return ERR_FAIL;
}