Add yacos_scanner object

This commit is contained in:
Markus Koch 2019-07-23 18:33:44 +02:00
parent 795bc1a4e5
commit c7dbe01c22
3 changed files with 103 additions and 9 deletions

View File

@ -1,27 +1,46 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "main_window.h" #include "main_window.h"
#include "scanner.h"
// TODO: For testing only
#include "cart_item.h" #include "cart_item.h"
struct app_state { struct app_state {
struct mainWindow *mainWindow; struct mainWindow *mainWindow;
}; };
static void newtag(YacosScanner *scanner, struct mainWindow *mainWindow)
{
// TODO: For testing only
gtk_stack_set_visible_child(mainWindow->stack_main, mainWindow->page_cart.box);
GtkWidget *le = yacos_cart_item_new();
gtk_list_box_insert(mainWindow->page_cart.list, le, -1);
gtk_widget_show(le);
}
static void activate(GtkApplication* app, gpointer user_data) static void activate(GtkApplication* app, gpointer user_data)
{ {
struct app_state *app_state = user_data; struct app_state *app_state = user_data;
struct mainWindow **mainWindow = &(app_state->mainWindow); struct mainWindow **mainWindow = &(app_state->mainWindow);
YacosScanner *scanner;
*mainWindow = mainWindow_new(app); *mainWindow = mainWindow_new(app);
if (*mainWindow) { if (!(*mainWindow)) {
g_error("Error initializing mainWindow.");
return;
}
gtk_application_add_window(GTK_APPLICATION(app), GTK_WINDOW((*mainWindow)->main_window)); gtk_application_add_window(GTK_APPLICATION(app), GTK_WINDOW((*mainWindow)->main_window));
gtk_widget_show_all((*mainWindow)->main_window); gtk_widget_show_all((*mainWindow)->main_window);
// For testing only scanner = yacos_scanner_new();
gtk_stack_set_visible_child((*mainWindow)->stack_main, (*mainWindow)->page_cart.box); if (!scanner) {
GtkWidget *le = yacos_cart_item_new(); g_error("Error initializing scanner.");
gtk_list_box_insert((*mainWindow)->page_cart.list, le, -1);
gtk_widget_show(le);
} }
g_signal_connect(scanner, "newtag",
(GCallback) newtag, (*mainWindow));
} }

60
src/scanner.c Normal file
View File

@ -0,0 +1,60 @@
#include "scanner.h"
struct _YacosScanner {
GObject parent_instance;
// TODO: Private data goes here
};
G_DEFINE_TYPE(YacosScanner, yacos_scanner, G_TYPE_OBJECT)
enum {
SIGNAL_NEWTAG = 0,
SIGNAL_COUNT
};
guint yacos_scanner_signals[SIGNAL_COUNT];
static gboolean *yacos_scanner_read (gpointer user_data)
{
YacosScanner *self = YACOS_SCANNER(user_data);
// TODO: Scan for tags
g_signal_emit(self, yacos_scanner_signals[SIGNAL_NEWTAG], 0);
return G_SOURCE_CONTINUE;
}
static void yacos_scanner_finalize(GObject *gobject)
{
YacosScanner *obj = yacos_scanner_get_instance_private(YACOS_SCANNER(gobject));
// TODO: clean up
G_OBJECT_CLASS(yacos_scanner_parent_class)->finalize(gobject);
}
static void yacos_scanner_class_init(YacosScannerClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS(klass);
yacos_scanner_signals[SIGNAL_NEWTAG] =
g_signal_newv("newtag",
G_TYPE_FROM_CLASS(object_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
NULL, NULL, NULL, NULL,
G_TYPE_NONE,
0,
NULL);
object_class->finalize = yacos_scanner_finalize;
}
static void yacos_scanner_init(YacosScanner *self)
{
g_timeout_add(1000, G_SOURCE_FUNC(yacos_scanner_read), self);
}
YacosScanner *yacos_scanner_new(void)
{
return g_object_new(YACOS_TYPE_SCANNER, 0);
}

15
src/scanner.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef SCANNER_H
#define SCANNER_H
#include <glib-object.h>
G_BEGIN_DECLS
#define YACOS_TYPE_SCANNER yacos_scanner_get_type()
G_DECLARE_FINAL_TYPE(YacosScanner, yacos_scanner, YACOS, SCANNER, GObject)
YacosScanner *yacos_scanner_new(void);
G_END_DECLS
#endif // SCANNER_H