commit 636fbb23b385b09f1680f60453b0a0beecbd117e
parent d82a83b17f31f81d1d278686a7070e4dea7fe69d
Author: lash <dev@holbrook.no>
Date: Wed, 20 Mar 2024 12:30:53 +0000
Handle menu item enable on login
Diffstat:
6 files changed, 23 insertions(+), 28 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -3,3 +3,4 @@ src/gtk/*.ui
testdata_mdb
*\~
**/test_*
+**/*.out
diff --git a/src/gtk/main.c b/src/gtk/main.c
@@ -16,10 +16,8 @@ static void state_log(KeeUicontext *uctx, char state_hint, kee_state_t *new_stat
static void startup(GtkApplication *app, KeeUicontext *uctx) {
kee_uicontext_scaninit(uctx);
- menu_setup(app, uctx);
}
-
static void activate(GtkApplication *app, KeeUicontext *uctx) {
ui_build(app, uctx);
}
diff --git a/src/gtk/menu.c b/src/gtk/menu.c
@@ -14,9 +14,7 @@ static void act_quit(GAction *act, GVariant *param, GApplication *gapp) {
static void menu_handle_state(KeeUicontext *uctx, char state_hint, kee_state_t *new_state, kee_state_t *old_state, GObject *head) {
-// GtkApplication *gapp;
GtkWidget *widget;
-// GAction *act;
if (!(state_hint & KEE_ST_HINT_UI_MENU)) {
return;
@@ -25,10 +23,6 @@ static void menu_handle_state(KeeUicontext *uctx, char state_hint, kee_state_t *
if (new_state->ui_menu & KEE_ST_UI_HEAD_ADD) {
widget = g_object_get_data(head, KEE_W_UI_MENU_QUICK_ADD);
gtk_actionable_set_action_name(GTK_ACTIONABLE(widget), "win.import");
- gtk_widget_set_sensitive(widget, true);
-// g_object_get(uctx, "gtk_application", &gapp, NULL);
-// act = g_action_map_lookup_action(G_ACTION_MAP(gapp), "import");
-// g_simple_action_set_enabled(G_SIMPLE_ACTION(act), true);
}
}
@@ -51,7 +45,6 @@ static GtkWidget* menu_button_setup(GObject *head, GtkApplication *gapp, KeeUico
act = g_simple_action_new("quit", NULL);
g_action_map_add_action(G_ACTION_MAP(gapp), G_ACTION(act));
g_signal_connect(act, "activate", G_CALLBACK(act_quit), gapp);
-
butt = gtk_menu_button_new();
gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(butt), G_MENU_MODEL(menu));
@@ -63,7 +56,7 @@ static GtkWidget* menu_button_setup(GObject *head, GtkApplication *gapp, KeeUico
}
-static void header_setup(GtkApplication *gapp, KeeUicontext *uctx) {
+GtkWidget* header_setup(GtkApplication *gapp, KeeUicontext *uctx) {
GtkWidget *head;
GtkWidget *butt;
head = gtk_header_bar_new();
@@ -81,9 +74,9 @@ static void header_setup(GtkApplication *gapp, KeeUicontext *uctx) {
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_object_set_data(G_OBJECT(uctx), KEE_W_UI_MENU_QUICK_ADD, GTK_BUTTON(butt)); // find a way to avoid ref through set data
g_signal_connect (uctx, "state", G_CALLBACK(menu_handle_state), head);
+ return head;
}
diff --git a/src/gtk/menu.h b/src/gtk/menu.h
@@ -9,6 +9,6 @@
#define KEE_W_UI_MENU_QUICK_ADD "quick_add"
#define KEE_W_UI_MENU_ACT_IMPORT "act_import"
-void menu_setup(GtkApplication *gapp, KeeUicontext *uctx);
+GtkWidget* header_setup(GtkApplication *gapp, KeeUicontext *uctx);
#endif // _KEE_GTK_MENU_H
diff --git a/src/gtk/ui.c b/src/gtk/ui.c
@@ -15,6 +15,19 @@
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);
+ }
+}
+
static void scan_menu_handle_state(KeeUicontext *uctx, char state_hint, kee_state_t *new_state, kee_state_t *old_state, GObject *head) {
}
@@ -230,10 +243,13 @@ void ui_build(GtkApplication *app, KeeUicontext *uctx) {
GtkWidget *widget;
GtkWidget *win;
GtkWidget *stack;
+ GtkWidget *head;
GSimpleAction *act;
win = gtk_application_window_new (app);
+ head = header_setup(app, uctx);
+
gtk_window_set_title (GTK_WINDOW (win), "kee");
gtk_window_set_default_size (GTK_WINDOW (win), 720, 1440);
@@ -254,16 +270,15 @@ void ui_build(GtkApplication *app, KeeUicontext *uctx) {
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);
- widget = g_object_get_data(G_OBJECT(uctx), KEE_W_HEADER);
- gtk_window_set_titlebar(GTK_WINDOW(win), widget);
+ 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);
- gtk_widget_set_sensitive(widget, false);
- //g_signal_connect (uctx, "import", G_CALLBACK(stack_handle_import), stack;
+ g_signal_connect (uctx, "state", G_CALLBACK(win_handle_state), win);
gtk_widget_set_vexpand(stack, true);
@@ -291,17 +306,6 @@ void ui_build(GtkApplication *app, KeeUicontext *uctx) {
//
-//void ui_free(struct ui_container *ui) {
- //g_object_unref(ui->view);
- //g_object_unref(ui->unlock);
- //g_object_unref(ui->win);
-//}
-
-//int ui_state_change(struct ui_container *ui, int set, int reset) {
-// ui->state |= set;
-// return ui->state;
-//}
-//
//gboolean ui_scan_code_handler(GstBus *bus, GstMessage *msg, gpointer user_data) {
// GError *err;
// gchar *debug_info;
diff --git a/src/gtk/ui.h b/src/gtk/ui.h
@@ -12,7 +12,6 @@ enum KeeActScan {
#include "kee-uicontext.h"
void ui_build(GtkApplication *app, KeeUicontext *uctx);
-
void ui_handle_scan(KeeUicontext *uctx);
void ui_handle_unlock(KeeUicontext *uctx, gpointer user_data);