kee

Offline IOU signer with QR as transport
git clone https://holbrook.no/src/kee
Info | Log | Files | Refs | README | LICENSE

commit 6e0d456fb6ed0cad3dc8f1960527657eb1e049e1
parent d18def1163d407a9385151528d166b9d1edcac71
Author: lash <dev@holbrook.no>
Date:   Sun, 24 Mar 2024 12:39:38 +0000

Factor out application window to custom widget

Diffstat:
Msrc/gtk/kee-import.c | 204+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Msrc/gtk/kee-import.h | 14+++++++++++++-
Asrc/gtk/kee-menu.c | 103+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/gtk/kee-menu.h | 28++++++++++++++++++++++++++++
Msrc/gtk/main.c | 20++++++++------------
Msrc/gtk/menu.c | 36++++--------------------------------
Msrc/gtk/menu.h | 1+
Msrc/gtk/ui.c | 242+++++++++++--------------------------------------------------------------------
Msrc/gtk/ui.h | 8++------
9 files changed, 393 insertions(+), 263 deletions(-)

diff --git a/src/gtk/kee-import.c b/src/gtk/kee-import.c @@ -3,6 +3,7 @@ #include <gst/gst.h> #include "kee-import.h" +#include "kee-menu.h" #include "camera.h" #include "scan.h" #include "err.h" @@ -16,6 +17,7 @@ struct _KeeImportClass { struct _KeeImport { GtkWidget parent; + KeeMenu *win; GListModel *camera_list; struct kee_camera_devices camera_device; struct kee_scanner scan; @@ -24,8 +26,23 @@ struct _KeeImport { G_DEFINE_TYPE(KeeImport, kee_import, GTK_TYPE_BOX); + +static GParamSpec *kee_props[KEE_N_IMPORT_PROPS] = {NULL,}; static guint kee_sigs[KEE_N_IMPORT_SIGS] = {0,}; +static void kee_import_set_property(GObject *oo, guint property_id, const GValue *value, GParamSpec *pspec) { + KeeImport *o = KEE_IMPORT(oo); + + switch((enum KEE_IMPORT_PROPS)property_id) { + case KEE_P_IMPORT_WIN: + o->win = g_value_get_object(value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(oo, property_id, pspec); + } + +} + static void kee_import_class_init(KeeImportClass *kls) { GObjectClass *o = G_OBJECT_CLASS(kls); @@ -52,6 +69,17 @@ static void kee_import_class_init(KeeImportClass *kls) { 1, G_TYPE_STRING ); + + o->set_property = kee_import_set_property; + + kee_props[KEE_P_IMPORT_WIN] = g_param_spec_object( + "window", + "Window", + "Application window", + KEE_TYPE_MENU, + G_PARAM_WRITABLE); + + g_object_class_install_properties(o, KEE_N_IMPORT_PROPS, kee_props); } static void kee_import_init(KeeImport *o) { @@ -61,6 +89,176 @@ static void kee_import_init(KeeImport *o) { o->stack = GTK_STACK(gtk_stack_new()); } +static void kee_import_handle_camera_change(GtkDropDown *chooser, GParamSpec *spec, KeeImport *import) { + GtkLabel *label; + char *s; + + 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); + + kee_import_scanchange(import, s); +} + +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); +} + +static void kee_import_handle_import_data_text(KeeImport *o, const char *data, GtkTextBuffer *buf) { + gtk_text_buffer_set_text(buf, data, strlen(data)); + 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) { + GAction *act; + + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "import accept %s", data); + + act = g_action_map_lookup_action(am, "import_data_accept"); + g_simple_action_set_enabled(G_SIMPLE_ACTION(act), true); +} + +static void kee_import_handle_import_data_check(KeeImport *o, const char *data, GtkActionable *act) { + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "accept click"); +} +static void kee_import_handle_scan_select(GActionGroup *act, char *action_name, gpointer user_data, GtkStack *stack) { + GVariant *v; + const char *s; + + v = g_action_group_get_action_state(act, action_name); + s = g_variant_get_string(v, NULL); + gtk_stack_set_visible_child_name(stack, s); +} + +static GtkWidget* kee_import_build_scan_footer(KeeImport *import, GtkStack *stack) { + GtkWidget *foot; + GtkWidget *butt; + GtkToggleButton *butt_prev; + GActionGroup *ag; + GAction *act; + GVariant *v; + + foot = gtk_action_bar_new(); + + v = g_variant_new_string(""); + ag = G_ACTION_GROUP(g_simple_action_group_new()); + act = G_ACTION(g_simple_action_new_stateful("src", G_VARIANT_TYPE_STRING, v)); + g_action_map_add_action(G_ACTION_MAP(ag), act); + + v = g_variant_new_string(KEE_ACT_SCAN_QR); + butt = gtk_toggle_button_new(); + gtk_button_set_icon_name(GTK_BUTTON(butt), "insert-image"); + 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); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(butt), true); + + butt_prev = GTK_TOGGLE_BUTTON(butt); + v = g_variant_new_string(KEE_ACT_SCAN_TEXT); + butt = gtk_toggle_button_new(); + gtk_toggle_button_set_group(GTK_TOGGLE_BUTTON(butt), butt_prev); + gtk_button_set_icon_name(GTK_BUTTON(butt), "document-new"); + 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); + + butt_prev = GTK_TOGGLE_BUTTON(butt); + v = g_variant_new_string(KEE_ACT_SCAN_FILE); + butt = gtk_toggle_button_new(); + gtk_toggle_button_set_group(GTK_TOGGLE_BUTTON(butt), butt_prev); + gtk_button_set_icon_name(GTK_BUTTON(butt), "document-save"); + 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); + + g_signal_connect(ag, "action-state-changed", G_CALLBACK(kee_import_handle_scan_select), stack); + + gtk_widget_insert_action_group(foot, "import", ag); + + return foot; +} +static GtkWidget* kee_import_build_scan_videochooser(KeeImport *o) { + GtkWidget *chooser; + GtkExpression *exp_label; + + 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); + return chooser; +} + +static GtkWidget* kee_import_build_import_text(KeeImport *o, GtkStack *stack) { + GtkWidget *box; + GtkTextView *txt; + GtkWidget *butt; + GAction *act; + GtkApplication *gapp; + + box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); + + gapp = gtk_window_get_application(GTK_WINDOW(o->win)); + + txt = GTK_TEXT_VIEW(gtk_text_view_new()); + gtk_widget_set_vexpand(GTK_WIDGET(txt), true); + gtk_box_append(GTK_BOX(box), GTK_WIDGET(txt)); + + act = G_ACTION(g_simple_action_new("import_data_accept", NULL)); + g_simple_action_set_enabled(G_SIMPLE_ACTION(act), false); + g_action_map_add_action(G_ACTION_MAP(gapp), act); + + butt = gtk_button_new_with_label("import"); + gtk_actionable_set_action_name(GTK_ACTIONABLE(butt), "app.import_data_accept"); + 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_focus), stack); + //g_signal_connect(import, "data_available", G_CALLBACK(ui_handle_import_data_check), butt); + + return box; +} + +KeeImport* kee_import_new(KeeMenu *win) { + KeeImport *o; + GtkWidget *box_outer; + GtkWidget *box; + GtkWidget *widget; + GtkWidget *chooser; + GValue v; // = G_VALUE_INIT; + + o = g_object_new(KEE_TYPE_IMPORT, "orientation", GTK_ORIENTATION_VERTICAL, NULL); + + g_value_init(&v, G_TYPE_OBJECT); + g_value_set_object(&v, win); + g_object_set_property(G_OBJECT(o), "window", &v); + + box_outer = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10); + + box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10); + + chooser = kee_import_build_scan_videochooser(o); + gtk_box_append(GTK_BOX(box), chooser); + + gtk_box_append(GTK_BOX(box), GTK_WIDGET(o)); + + gtk_stack_add_named(o->stack, box, KEE_ACT_SCAN_QR); + + widget = kee_import_build_import_text(o, o->stack); + gtk_stack_add_named(o->stack, widget, KEE_ACT_SCAN_TEXT); + + gtk_stack_set_visible_child_name(o->stack, KEE_ACT_SCAN_QR); + + widget = kee_import_build_scan_footer(o, o->stack); + + gtk_box_append(GTK_BOX(box_outer), GTK_WIDGET(o->stack)); + gtk_box_append(GTK_BOX(box_outer), widget); + + return box_outer; +} + static void kee_import_scanadd(KeeImport *o, GtkLabel *label) { g_list_store_append(G_LIST_STORE(o->camera_list), label); } @@ -168,9 +366,9 @@ int kee_import_scanchange(KeeImport *o, const char *device) { return ERR_OK; } -GListModel* kee_import_get_camera_list(KeeImport *o) { - return o->camera_list; -} +//GListModel* kee_import_get_camera_list(KeeImport *o) { +// return o->camera_list; +//} void kee_import_free(KeeImport *o) { kee_camera_free(&o->camera_device); diff --git a/src/gtk/kee-import.h b/src/gtk/kee-import.h @@ -3,18 +3,30 @@ #include <glib-object.h> +#include "kee-menu.h" + G_BEGIN_DECLS #define KEE_TYPE_IMPORT kee_import_get_type() G_DECLARE_FINAL_TYPE(KeeImport, kee_import, KEE, IMPORT, GtkBox) +#define KEE_ACT_SCAN_QR "import_scan" +#define KEE_ACT_SCAN_FILE "import_file" +#define KEE_ACT_SCAN_TEXT "import_text" + + +enum KEE_IMPORT_PROPS { + KEE_P_IMPORT_WIN = 1, + KEE_N_IMPORT_PROPS, +}; + enum KEE_IMPORT_SIGS { KEE_S_IMPORT_SCAN_CHANGE, KEE_S_IMPORT_DATA, KEE_N_IMPORT_SIGS, }; -KeeImport* kee_import_new(void); +KeeImport* kee_import_new(KeeMenu *win); int kee_import_refresh(KeeImport *im); GListModel* kee_import_get_camera_list(KeeImport *o); int kee_import_scanchange(KeeImport *o, const char *device); diff --git a/src/gtk/kee-menu.c b/src/gtk/kee-menu.c @@ -0,0 +1,103 @@ +#include <string.h> +#include <glib-object.h> +#include <gtk/gtk.h> + +#include "kee-menu.h" +#include "menu.h" +#include "nav.h" +#include "err.h" + +typedef struct { +} KeeMenuPrivate; + +struct _KeeMenu { + GtkApplicationWindow parent; + GtkHeaderBar *head; + GtkStack *stack; + struct KeeNav nav; +}; + +struct _KeeMenuClass { + GtkApplicationWindowClass parent_class; +}; + +G_DEFINE_TYPE(KeeMenu, kee_menu, GTK_TYPE_APPLICATION_WINDOW); + +static void kee_menu_act_import(GAction *act, GVariant *param, GtkStack *stack) { + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "act impot"); + gtk_stack_set_visible_child_name(stack, "import"); +} + +//static GParamSpec *kee_props[KEE_N_MENU_PROPS] = {NULL,}; +static guint kee_sigs[KEE_N_MENU_SIGS] = {0,}; + +static void kee_menu_class_init(KeeMenuClass *kls) { +// GObjectClass *o = G_OBJECT_CLASS(kls); +} + +static void kee_menu_init(KeeMenu *o) { + memset(&o->nav, 0, sizeof(struct KeeNav)); + o->head = GTK_HEADER_BAR(gtk_header_bar_new()); + o->stack = GTK_STACK(gtk_stack_new()); +} + +KeeMenu* kee_menu_new(GtkApplication *gapp) { + KeeMenu *o; + GtkWidget *butt; + GSimpleAction *act; + + o = g_object_new(KEE_TYPE_MENU, "application", gapp, NULL); + gtk_widget_set_vexpand(o->stack, true); + + gapp = gtk_window_get_application(GTK_WINDOW(o)); + + butt = menu_button_setup(G_OBJECT(o->head), gapp); + gtk_header_bar_pack_end(GTK_HEADER_BAR(o->head), butt); + + butt = gtk_button_new_from_icon_name("go-previous"); + gtk_header_bar_pack_start(GTK_HEADER_BAR(o->head), butt); + gtk_widget_set_visible(butt, false); + + act = g_simple_action_new("import", NULL); + g_action_map_add_action(G_ACTION_MAP(o), G_ACTION(act)); + g_simple_action_set_enabled(act, false); + + butt = gtk_button_new_from_icon_name("insert-object"); + gtk_header_bar_pack_start(GTK_HEADER_BAR(o->head), butt); + gtk_actionable_set_action_name(GTK_ACTIONABLE(butt), "win.import"); + g_signal_connect(act, "activate", G_CALLBACK(kee_menu_act_import), o->stack); + + gtk_window_set_titlebar(GTK_WINDOW(o), GTK_WIDGET(o->head)); + + gtk_window_set_title (GTK_WINDOW (o), "kee"); + gtk_window_set_default_size (GTK_WINDOW (o), 720, 1440); + + gtk_window_set_child(GTK_WINDOW(o), o->stack); + + return o; +} + + +int kee_menu_add(KeeMenu *o, const char *label, GtkWidget *widget) { + gtk_stack_add_named(o->stack, widget, label); + return ERR_OK; +} + +int kee_menu_next(KeeMenu *o, const char *label) { + GtkWidget *widget; + + widget = gtk_stack_get_child_by_name(o->stack, label); + kee_nav_push(&o->nav, widget); + gtk_stack_set_visible_child(o->stack, widget); + return ERR_OK; +} + +int kee_menu_prev(KeeMenu *o) { + kee_nav_pop(&o->nav); + gtk_stack_set_visible_child(o->stack, o->nav.now); + return ERR_OK; +} + +GtkWidget* kee_menu_get_stack(KeeMenu *o) { + return o->stack; +} diff --git a/src/gtk/kee-menu.h b/src/gtk/kee-menu.h @@ -0,0 +1,28 @@ +#ifndef _GTK_KEE_MENU_H +#define _GTK_KEE_MENU_H + +#include <glib-object.h> +#include <gtk/gtk.h> + +enum KEE_MENU_PROPS { + KEE_N_MENU_PROPS, +}; + +enum KEE_MENU_SIGS { + KEE_N_MENU_CHANGE, + KEE_N_MENU_SIGS, +}; + +G_BEGIN_DECLS + +#define KEE_TYPE_MENU kee_menu_get_type() +G_DECLARE_FINAL_TYPE(KeeMenu, kee_menu, KEE, MENU, GtkApplicationWindow); + +KeeMenu* kee_menu_new(GtkApplication *app); +int kee_menu_add(KeeMenu *o, const char *k, GtkWidget *v); +int kee_menu_next(KeeMenu *o, const char *k); +int kee_menu_prev(KeeMenu *o); + +G_END_DECLS + +#endif //_GTK_KEE_MENU_H diff --git a/src/gtk/main.c b/src/gtk/main.c @@ -4,7 +4,6 @@ #include <gst/gst.h> #include "kee-uicontext.h" -#include "kee-import.h" #include "ui.h" //#include "context.h" #include "menu.h" @@ -20,11 +19,8 @@ static void startup(GtkApplication *app, KeeUicontext *uctx) { // kee_uicontext_scaninit(uctx); } -static void activate(GtkApplication *app, KeeUicontext *uctx) { - ui_build(app, uctx); -} -static void activate_scan(GtkApplication *app, KeeImport *import) { - ui_build_scan(app, import); +static void activate(GtkApplication *app) { + ui_build(app); } static void deactivate(GtkApplication *app, gpointer user_data) { @@ -47,16 +43,16 @@ int main(int argc, char **argv) { settings_new_from_xdg(&settings); settings_init(&settings); - uctx = g_object_new(KEE_TYPE_UICONTEXT, NULL); - import = g_object_new(KEE_TYPE_IMPORT, "orientation", GTK_ORIENTATION_VERTICAL, NULL); + //uctx = g_object_new(KEE_TYPE_UICONTEXT, NULL); + uctx = NULL; //db_connect(&ctx.db, "./testdata_mdb"); g_signal_connect (gapp, "startup", G_CALLBACK (startup), uctx); - g_signal_connect (gapp, "activate", G_CALLBACK (activate), uctx); - g_signal_connect (gapp, "activate", G_CALLBACK (activate_scan), import); + //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), uctx); - g_signal_connect (uctx, "unlock", G_CALLBACK(ui_handle_unlock), uctx); - g_signal_connect (uctx, "state", G_CALLBACK(state_log), 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); diff --git a/src/gtk/menu.c b/src/gtk/menu.c @@ -1,6 +1,8 @@ +#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" @@ -17,14 +19,14 @@ static void menu_handle_state(KeeUicontext *uctx, char state_hint, kee_state_t * } -static GtkWidget* menu_button_setup(GObject *head, GtkApplication *gapp, KeeUicontext *uctx) { +GtkWidget* menu_button_setup(GObject *head, GtkApplication *gapp) { GMenu *menu; GMenuItem *menu_item; GtkWidget *butt; GSimpleAction *act; menu = g_menu_new(); - menu_item = g_menu_item_new("Import", "win.import"); + menu_item = g_menu_item_new("Import", "app.import"); g_menu_append_item(menu, menu_item); g_object_unref(menu_item); @@ -44,33 +46,3 @@ static GtkWidget* menu_button_setup(GObject *head, GtkApplication *gapp, KeeUico g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "set up menus"); return butt; } - - -GtkWidget* header_setup(GtkApplication *gapp, KeeUicontext *uctx) { - GtkWidget *head; - GtkWidget *butt; - head = gtk_header_bar_new(); - - butt = menu_button_setup(G_OBJECT(head), gapp, uctx); - gtk_header_bar_pack_end(GTK_HEADER_BAR(head), butt); - - butt = gtk_button_new_from_icon_name("go-previous"); - gtk_header_bar_pack_start(GTK_HEADER_BAR(head), butt); - gtk_widget_set_visible(butt, false); - - butt = gtk_button_new_from_icon_name("insert-object"); - gtk_header_bar_pack_start(GTK_HEADER_BAR(head), butt); - gtk_actionable_set_action_name(GTK_ACTIONABLE(butt), "win.import"); - g_object_set_data(G_OBJECT(head), KEE_W_UI_MENU_QUICK_ADD, butt); - - g_object_set_data(G_OBJECT(uctx), KEE_W_HEADER, GTK_HEADER_BAR(head)); - - - g_signal_connect (uctx, "state", G_CALLBACK(menu_handle_state), head); - return head; -} - - -void menu_setup(GtkApplication *gapp, KeeUicontext *uctx) { - header_setup(gapp, uctx); -} diff --git a/src/gtk/menu.h b/src/gtk/menu.h @@ -10,5 +10,6 @@ #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/ui.c b/src/gtk/ui.c @@ -12,58 +12,32 @@ #include "view.h" #include "menu.h" #include "kee-import.h" +#include "kee-menu.h" static void new_item(GtkListItemFactory *factory, GtkListItem *item, gpointer user_data) { } -void ui_handle_import_data_focus(KeeImport *o, const char *data, GtkStack *stack) { - gtk_stack_set_visible_child_name(stack, KEE_ACT_SCAN_TEXT); -} - -void ui_handle_import_data_text(KeeImport *o, const char *data, GtkTextBuffer *buf) { - gtk_text_buffer_set_text(buf, data, strlen(data)); - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "import data %s", data); -} - -void ui_handle_import_data_accept(KeeImport *o, const char *data, GActionMap *am) { - GAction *act; - - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "import accept %s", data); - - act = g_action_map_lookup_action(am, "import_data_accept"); - g_simple_action_set_enabled(G_SIMPLE_ACTION(act), true); -} - -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); - } -} +// +//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); +// } +//} -static void act_import(GAction *act, GVariant *param, GtkStack *stack) { - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "act impot"); - gtk_stack_set_visible_child_name(stack, "import"); -} // \todo why is there user_data in addition to pointer -static void act_scan_select(GActionGroup *act, char *action_name, gpointer user_data, GtkStack *stack) { - GVariant *v; - const char *s; - v = g_action_group_get_action_state(act, action_name); - s = g_variant_get_string(v, NULL); - gtk_stack_set_visible_child_name(stack, s); -} void ui_handle_unlock(KeeUicontext *uctx, gpointer user_data) { @@ -74,8 +48,8 @@ void ui_handle_unlock(KeeUicontext *uctx, gpointer user_data) { 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); + //state_delta.ui_menu |= KEE_ST_UI_HEAD_ADD; + //kee_uicontext_state_change(uctx, &state_delta, NULL); } @@ -92,17 +66,6 @@ static void ui_handle_unlock_click(GtkWidget *button, KeeUicontext *uctx) { gtk_entry_buffer_delete_text(buf, 0, gtk_entry_buffer_get_length(buf)); } -static void ui_handle_camera_change(GtkDropDown *chooser, GParamSpec *spec, KeeImport *import) { - GtkLabel *label; - char *s; - - 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); - - kee_import_scanchange(import, s); - -} GtkWidget* ui_build_unlock(KeeUicontext *uctx) { @@ -118,7 +81,7 @@ GtkWidget* ui_build_unlock(KeeUicontext *uctx) { buf = gtk_entry_get_buffer(GTK_ENTRY(entry)); gtk_entry_set_input_purpose(GTK_ENTRY(entry), GTK_INPUT_PURPOSE_PASSWORD); gtk_entry_set_visibility(GTK_ENTRY(entry), false); - g_object_set_data(G_OBJECT(uctx), "passphrase", buf); + //g_object_set_data(G_OBJECT(uctx), "passphrase", buf); button = gtk_button_new_with_label("create"); gtk_box_append(GTK_BOX(box), button); @@ -128,130 +91,7 @@ GtkWidget* ui_build_unlock(KeeUicontext *uctx) { } -static GtkWidget* ui_build_scan_videochooser(KeeImport *import) { - GtkWidget *chooser; - GtkExpression *exp_label; - GListModel *camera_list; - - exp_label = gtk_property_expression_new(GTK_TYPE_LABEL, NULL, "label"); - - camera_list = kee_import_get_camera_list(import); - chooser = gtk_drop_down_new(camera_list, exp_label); - - g_signal_connect(chooser, "notify::selected-item", G_CALLBACK (ui_handle_camera_change), import); - return chooser; -} - - -static GtkWidget* ui_build_scan_footer(KeeImport *import, GtkStack *stack) { - GtkWidget *foot; - GtkWidget *butt; - GtkToggleButton *butt_prev; - GActionGroup *ag; - GAction *act; - GVariant *v; - - foot = gtk_action_bar_new(); - - v = g_variant_new_string(""); - ag = G_ACTION_GROUP(g_simple_action_group_new()); - act = G_ACTION(g_simple_action_new_stateful("src", G_VARIANT_TYPE_STRING, v)); - g_action_map_add_action(G_ACTION_MAP(ag), act); - - v = g_variant_new_string(KEE_ACT_SCAN_QR); - butt = gtk_toggle_button_new(); - gtk_button_set_icon_name(GTK_BUTTON(butt), "insert-image"); - 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); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(butt), true); - - butt_prev = GTK_TOGGLE_BUTTON(butt); - v = g_variant_new_string(KEE_ACT_SCAN_TEXT); - butt = gtk_toggle_button_new(); - gtk_toggle_button_set_group(GTK_TOGGLE_BUTTON(butt), butt_prev); - gtk_button_set_icon_name(GTK_BUTTON(butt), "document-new"); - 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); - - butt_prev = GTK_TOGGLE_BUTTON(butt); - v = g_variant_new_string(KEE_ACT_SCAN_FILE); - butt = gtk_toggle_button_new(); - gtk_toggle_button_set_group(GTK_TOGGLE_BUTTON(butt), butt_prev); - gtk_button_set_icon_name(GTK_BUTTON(butt), "document-save"); - 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); - - g_signal_connect(ag, "action-state-changed", G_CALLBACK(act_scan_select), stack); - - gtk_widget_insert_action_group(foot, "import", ag); - - return foot; -} - - -static GtkWidget* ui_build_import_text(GtkApplication *app, KeeImport *import, GtkStack *stack) { - GtkWidget *box; - GtkTextView *txt; - GtkWidget *butt; - GAction *act; - - box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); - - txt = GTK_TEXT_VIEW(gtk_text_view_new()); - gtk_widget_set_vexpand(GTK_WIDGET(txt), true); - gtk_box_append(GTK_BOX(box), GTK_WIDGET(txt)); - - act = G_ACTION(g_simple_action_new("import_data_accept", NULL)); - g_simple_action_set_enabled(G_SIMPLE_ACTION(act), false); - g_action_map_add_action(G_ACTION_MAP(app), act); - - butt = gtk_button_new_with_label("import"); - gtk_actionable_set_action_name(GTK_ACTIONABLE(butt), "app.import_data_accept"); - gtk_box_append(GTK_BOX(box), butt); - - g_signal_connect(import, "data_available", G_CALLBACK(ui_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(import, "data_available", G_CALLBACK(ui_handle_import_data_focus), stack); - - return box; -} - - -void ui_build_scan(GtkApplication *app, KeeImport *import) { - GtkWidget *chooser; - GtkWidget *box_outer; - GtkWidget *box; - GtkWidget *widget; - GtkStack *stack; - - box_outer = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10); - - stack = kee_import_get_stack(import); - box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10); - - chooser = ui_build_scan_videochooser(import); - gtk_box_append(GTK_BOX(box), chooser); - - gtk_box_append(GTK_BOX(box), GTK_WIDGET(import)); - - gtk_stack_add_named(stack, box, KEE_ACT_SCAN_QR); - - widget = ui_build_import_text(app, import, stack); - gtk_stack_add_named(stack, widget, KEE_ACT_SCAN_TEXT); - - gtk_stack_set_visible_child_name(stack, KEE_ACT_SCAN_QR); - - widget = ui_build_scan_footer(import, stack); - - gtk_box_append(GTK_BOX(box_outer), GTK_WIDGET(stack)); - gtk_box_append(GTK_BOX(box_outer), widget); - - kee_view_add(box_outer, "import"); -} static GtkWidget* ui_build_view(KeeUicontext *uctx) { @@ -264,7 +104,7 @@ 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); + //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)); @@ -273,50 +113,34 @@ static GtkWidget* ui_build_view(KeeUicontext *uctx) { } -void ui_build(GtkApplication *app, KeeUicontext *uctx) { +void ui_build(GtkApplication *app) { GtkWidget *widget; GtkWidget *win; - GtkWidget *stack; - GtkWidget *head; - GSimpleAction *act; - - win = gtk_application_window_new (app); - - head = header_setup(app, uctx); + GtkWidget *import; - gtk_window_set_title (GTK_WINDOW (win), "kee"); - gtk_window_set_default_size (GTK_WINDOW (win), 720, 1440); + win = kee_menu_new(app); //g_object_new(KEE_TYPE_MENU, "application", app, NULL); - stack = gtk_stack_new(); - kee_view_init(GTK_STACK(stack)); + widget = ui_build_unlock(NULL); + kee_menu_add(KEE_MENU(win), "unlock", widget); - widget = ui_build_unlock(uctx); - kee_view_add(widget, "unlock"); - - widget = ui_build_view(uctx); - kee_view_add(widget, "view"); + widget = ui_build_view(NULL); + kee_menu_add(KEE_MENU(win), "view", widget); //widget = ui_build_scan(uctx); //kee_view_add(widget, "import"); - kee_view_next("view"); - kee_view_next("unlock"); - - act = g_simple_action_new("import", NULL); - g_action_map_add_action(G_ACTION_MAP(win), G_ACTION(act)); - g_simple_action_set_enabled(act, false); - g_signal_connect(act, "activate", G_CALLBACK(act_import), stack); + kee_menu_next(KEE_MENU(win), "view"); + kee_menu_next(KEE_MENU(win), "unlock"); - gtk_window_set_titlebar(GTK_WINDOW(win), head); - 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_object_set_data(G_OBJECT(uctx), KEE_W_WINDOW, GTK_WINDOW(win)); - g_signal_connect (uctx, "state", G_CALLBACK(win_handle_state), win); + //widget = g_object_get_data(G_OBJECT(uctx), KEE_W_UI_MENU_QUICK_ADD); - gtk_widget_set_vexpand(stack, true); + //g_signal_connect (uctx, "state", G_CALLBACK(win_handle_state), win); - gtk_window_set_child(GTK_WINDOW(win), stack); + import = kee_import_new(win); + //import = g_object_new(KEE_TYPE_IMPORT, "orientation", GTK_ORIENTATION_VERTICAL, NULL); + kee_menu_add(win, "import", import); gtk_window_present(GTK_WINDOW (win)); } diff --git a/src/gtk/ui.h b/src/gtk/ui.h @@ -5,13 +5,9 @@ #include "kee-uicontext.h" #include "kee-import.h" -#define KEE_ACT_SCAN_QR "import_scan" -#define KEE_ACT_SCAN_FILE "import_file" -#define KEE_ACT_SCAN_TEXT "import_text" - -void ui_build(GtkApplication *app, KeeUicontext *uctx); -void ui_build_scan(GtkApplication *app, KeeImport *imp); +//void ui_build(GtkApplication *app, KeeUicontext *uctx); +void ui_build(GtkApplication *app); void ui_handle_unlock(KeeUicontext *uctx, gpointer user_data); #endif // _UI_H