From ae2563772fb8c3e3ffb2a980e5c2663da06e31a2 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Sun, 5 May 2024 23:28:18 +0200 Subject: Save and restore the application state from global settings. --- .gitignore | 3 +++ configure.ac | 3 +++ src/Makefile.am | 2 +- src/framework.c | 19 ++++++++++++++++++- src/schemas/Makefile.am | 5 +++++ src/schemas/re.chrysalide.framework.gschema.xml | 19 +++++++++++++++++++ tools/maint/gsettings.inc | 8 ++++++++ 7 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 src/schemas/Makefile.am create mode 100644 src/schemas/re.chrysalide.framework.gschema.xml create mode 100644 tools/maint/gsettings.inc diff --git a/.gitignore b/.gitignore index 23045d5..d43ca32 100644 --- a/.gitignore +++ b/.gitignore @@ -76,6 +76,9 @@ tools/d2c/d2c tools/fuzzing/rost/fast-rost tools/yara2rost/yara2rost +# Schemas +src/schemas/gschemas.compiled +src/schemas/*.valid # Misc plugins/python/androperms/androperms.db diff --git a/configure.ac b/configure.ac index 25077fe..790ff74 100644 --- a/configure.ac +++ b/configure.ac @@ -369,6 +369,8 @@ else libgobj_version='-' fi +GLIB_GSETTINGS + PKG_CHECK_MODULES(LIBGTHREAD,gthread-2.0 >= 2.66.8,[libgthread_found=yes],[libgthread_found=no]) if test "$libgthread_found" = "yes"; then @@ -808,6 +810,7 @@ AC_CONFIG_FILES([Makefile src/gui/tb/Makefile src/mangling/Makefile src/plugins/Makefile + src/schemas/Makefile tools/Makefile tools/d2c/Makefile tools/d2c/args/Makefile diff --git a/src/Makefile.am b/src/Makefile.am index c4227b8..a1912b0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -145,4 +145,4 @@ rost_LDFLAGS = $(LIBGOBJ_LIBS) -L.libs -lchrysacore # glibext doit être traité en premier, à cause des marshals GLib -SUBDIRS = core glibext $(GTKEXT_SUBDIR) analysis arch format common debug $(GUI_SUBDIR) mangling plugins +SUBDIRS = core glibext $(GTKEXT_SUBDIR) analysis arch format common debug $(GUI_SUBDIR) mangling plugins schemas diff --git a/src/framework.c b/src/framework.c index 47e93a0..dfd0bfa 100644 --- a/src/framework.c +++ b/src/framework.c @@ -38,6 +38,8 @@ struct _GtkChrysalideFramework { GtkApplication parent; /* A laisser en premier */ + GSettings *settings; /* Paramètres globaux */ + GtkApplicationWindow *main_window; /* Fenêtre principale */ }; @@ -125,6 +127,8 @@ static void gtk_chrysalide_framework_class_init(GtkChrysalideFrameworkClass *kla static void gtk_chrysalide_framework_init(GtkChrysalideFramework *app) { + app->settings = NULL; + app->main_window = NULL; } @@ -144,6 +148,8 @@ static void gtk_chrysalide_framework_init(GtkChrysalideFramework *app) static void gtk_chrysalide_framework_dispose(GtkChrysalideFramework *app) { + g_clear_object(&app->settings); + g_clear_object(&app->main_window); G_OBJECT_CLASS(gtk_chrysalide_framework_parent_class)->dispose(G_OBJECT(app)); @@ -217,17 +223,28 @@ GtkChrysalideFramework *gtk_chrysalide_framework_new(void) static void gtk_chrysalide_framework_activate(GApplication *app) { GtkChrysalideFramework *real_app; /* Version réelle de l'instance*/ + GSettings *settings; /* Paramètres globaux */ GtkWindow *window; /* Fenêtre mise en place */ real_app = GTK_CHRYSALIDE_FRAMEWORK(app); + /* Paramètres globaux */ + + settings = g_settings_new("re.chrysalide.framework.mainapp"); + real_app->settings = settings; + + /* Fenêtre principale */ + window = GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(app))); real_app->main_window = GTK_APPLICATION_WINDOW(window); g_object_ref(G_OBJECT(window)); + g_settings_bind(settings, "window-width", G_OBJECT(window), "default-width", G_SETTINGS_BIND_DEFAULT); + g_settings_bind(settings, "window-height", G_OBJECT(window), "default-height", G_SETTINGS_BIND_DEFAULT); + g_settings_bind(settings, "window-maximized", G_OBJECT(window), "maximized", G_SETTINGS_BIND_DEFAULT); + gtk_window_set_title(window, "Chrysalide"); - gtk_window_set_default_size(window, 400, 300); gtk_window_present(window); } diff --git a/src/schemas/Makefile.am b/src/schemas/Makefile.am new file mode 100644 index 0000000..a67aa0b --- /dev/null +++ b/src/schemas/Makefile.am @@ -0,0 +1,5 @@ + +gsettings_SCHEMAS = \ + re.chrysalide.framework.gschema.xml + +@GSETTINGS_RULES@ diff --git a/src/schemas/re.chrysalide.framework.gschema.xml b/src/schemas/re.chrysalide.framework.gschema.xml new file mode 100644 index 0000000..4a16f12 --- /dev/null +++ b/src/schemas/re.chrysalide.framework.gschema.xml @@ -0,0 +1,19 @@ + + + + + + + + + 600 + + + 400 + + + false + + + + diff --git a/tools/maint/gsettings.inc b/tools/maint/gsettings.inc new file mode 100644 index 0000000..40941b4 --- /dev/null +++ b/tools/maint/gsettings.inc @@ -0,0 +1,8 @@ + +# Produce and export schemas needed by GSettings + +# source tools/maint/gsettings.inc + +glib-compile-schemas src/schemas/ + +export GSETTINGS_SCHEMA_DIR=$PWD/src/schemas -- cgit v0.11.2-87-g4458