diff options
Diffstat (limited to 'src/gui')
63 files changed, 4832 insertions, 3695 deletions
diff --git a/src/gui/Makefile.am b/src/gui/Makefile.am index f4a682c..be70445 100644 --- a/src/gui/Makefile.am +++ b/src/gui/Makefile.am @@ -12,15 +12,12 @@ libgui_la_SOURCES = \ item-int.h \ item.h item.c \ menubar.h menubar.c \ - panel-int.h \ - panel.h panel.c \ resources.h resources.c \ status.h status.c \ theme.h theme.c libgui_la_LIBADD = \ core/libguicore.la \ - dialogs/libguidialogs.la \ menus/libguimenus.la \ panels/libguipanels.la \ tb/libguitb.la @@ -28,10 +25,15 @@ libgui_la_LIBADD = \ libgui_la_CFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) -libgui4_la_SOURCES = +libgui4_la_SOURCES = \ + resources.h resources.c \ + window-int.h \ + window.h window.c -libgui4_la_LIBADD = \ - core/libguicore4.la +libgui4_la_LIBADD = \ + core/libguicore4.la \ + dialogs/libguidialogs.la \ + panels/libguipanels4.la libgui4_la_CFLAGS = $(LIBGTK4_CFLAGS) @@ -41,10 +43,14 @@ devdir = $(includedir)/chrysalide/$(subdir:src/%=core/%) dev_HEADERS = $(libgui_la_SOURCES:%c=) -SUBDIRS = core # dialogs menus panels tb +SUBDIRS = core dialogs panels # menus panels tb -resources.c: gresource.xml $(UI_FILES) +RES_FILES = \ + style.css \ + window.ui + +resources.c: gresource.xml $(RES_FILES) glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-source --c-name gui gresource.xml resources.h: gresource.xml @@ -53,4 +59,4 @@ resources.h: gresource.xml CLEANFILES = resources.h resources.c -EXTRA_DIST = gresource.xml $(UI_FILES) +EXTRA_DIST = gresource.xml $(RES_FILES) diff --git a/src/gui/core/Makefile.am b/src/gui/core/Makefile.am index 96ef578..a854977 100644 --- a/src/gui/core/Makefile.am +++ b/src/gui/core/Makefile.am @@ -15,7 +15,6 @@ RES_FILES = \ libguicore_la_SOURCES = \ global.h global.c \ items.h items.c \ - panels.h panels.c \ resources.h resources.c \ theme.h theme.c @@ -24,7 +23,9 @@ libguicore_la_CFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) libguicore4_la_SOURCES = \ core.h core.c \ - logs.h logs.c + logs.h logs.c \ + nox.h nox.c \ + panels.h panels.c libguicore4_la_CFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) diff --git a/src/gui/core/core.c b/src/gui/core/core.c index 2d47dc9..57a398a 100644 --- a/src/gui/core/core.c +++ b/src/gui/core/core.c @@ -2,7 +2,7 @@ /* Chrysalide - Outil d'analyse de fichiers binaires * core.c - chargement et le déchargement du tronc commun pour l'éditeur graphique * - * Copyright (C) 2016-2019 Cyrille Bagard + * Copyright (C) 2016-2025 Cyrille Bagard * * This file is part of Chrysalide. * @@ -24,6 +24,7 @@ #include "core.h" +#include "panels.h" #include "../../glibext/linetoken.h" @@ -32,6 +33,7 @@ static AvailableGuiComponent __loaded = AGC_NONE; + /****************************************************************************** * * * Paramètres : flags = liste d'éléments à charger. * @@ -59,6 +61,15 @@ bool load_gui_components(AvailableGuiComponent flags) } + if ((flags & AGC_PANELS) != 0 && (__loaded & AGC_PANELS) == 0) + { + result = load_main_framework_panel_definitions(); + if (!result) goto done; + + __loaded |= AGC_PANELS; + + } + done: return result; @@ -80,6 +91,14 @@ bool load_gui_components(AvailableGuiComponent flags) void unload_gui_components(AvailableGuiComponent flags) { + if ((flags & AGC_PANELS) != 0 && (__loaded & AGC_PANELS) == 0) + { + unload_all_framework_panel_definitions(); + + __loaded &= ~AGC_PANELS; + + } + if ((flags & AGC_BUFFER_FEATURES) != 0 && (__loaded & AGC_BUFFER_FEATURES) == 0) { exit_segment_content_hash_table(); @@ -87,7 +106,6 @@ void unload_gui_components(AvailableGuiComponent flags) __loaded &= ~AGC_BUFFER_FEATURES; } - } diff --git a/src/gui/core/core.h b/src/gui/core/core.h index bcb5433..19647ce 100644 --- a/src/gui/core/core.h +++ b/src/gui/core/core.h @@ -34,6 +34,7 @@ typedef enum _AvailableGuiComponent { AGC_NONE = (0 << 0), /* Statut initial */ AGC_BUFFER_FEATURES = (1 << 0), /* Tampons de bribes de texte */ + AGC_PANELS = (1 << 1), /* Panneaux graphiques de base */ } AvailableGuiComponent; diff --git a/src/gui/core/logs.c b/src/gui/core/logs.c index 59910f1..cdb2a0d 100644 --- a/src/gui/core/logs.c +++ b/src/gui/core/logs.c @@ -24,6 +24,14 @@ #include "logs.h" +#include <assert.h> + + +#include "panels.h" +#include "../panels/logs.h" +#include "../../glibext/log.h" + + /****************************************************************************** * * @@ -38,26 +46,20 @@ * * ******************************************************************************/ -void do_log_message_alt2(LogMessageType type, const char *msg) +void do_log_message_alt(LogMessageType type, const char *msg) { -#if 0 - -#ifdef INCLUDE_GTK_SUPPORT - - GEditorItem *item; /* Eventuel affichage présent */ + GLogEntry *entry; /* Nouvel élément de journal */ + GtkTiledPanel *panel; /* Panneau de journalisation */ - item = find_editor_item_by_type(G_TYPE_LOG_PANEL); + entry = g_log_entry_new(type, msg); - if (item != NULL) - { - g_log_panel_add_message(G_LOG_PANEL(item), type, msg); - g_object_unref(G_OBJECT(item)); - } + panel = get_framework_panel_singleton(GTK_TYPE_LOGS_PANEL); + assert(panel != NULL); -#endif + g_log_panel_add_message(GTK_LOGS_PANEL(panel), entry); -#endif + unref_object(panel); - printf("[log GUI] [%u] %s\n", type, msg); + unref_object(entry); } diff --git a/src/gui/core/nox.c b/src/gui/core/nox.c new file mode 100644 index 0000000..7f3ae1f --- /dev/null +++ b/src/gui/core/nox.c @@ -0,0 +1,48 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * nox.c - indication de présence ou d'absence de support graphique + * + * Copyright (C) 2024 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#include "nox.h" + + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Indique la présence ou l'absence d'un affichage graphique. * +* * +* Retour : Statut à transmettre. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool _run_in_nox_mode(void) +{ + bool result; /* Statut à retournr */ + + result = false; + + return result; + +} diff --git a/src/gui/core/nox.h b/src/gui/core/nox.h new file mode 100644 index 0000000..e03b365 --- /dev/null +++ b/src/gui/core/nox.h @@ -0,0 +1,37 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * nox.h - prototypes pour l'indication de présence ou d'absence de support graphique + * + * Copyright (C) 2024 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _GUI_CORE_NOX_H +#define _GUI_CORE_NOX_H + + +#include <stdbool.h> + + + +/* Indique la présence ou l'absence d'un affichage graphique. */ +bool _run_in_nox_mode(void); + + + +#endif /* _GUI_CORE_NOX_H */ diff --git a/src/gui/core/panels.c b/src/gui/core/panels.c index 1b6f604..9fca411 100644 --- a/src/gui/core/panels.c +++ b/src/gui/core/panels.c @@ -1,8 +1,8 @@ /* Chrysalide - Outil d'analyse de fichiers binaires - * panels.c - gestion d'ensemble de tous les panneaux pour l'éditeur + * panels.c - gestion d'ensemble de tous les panneaux graphiques du framework * - * Copyright (C) 2016-2019 Cyrille Bagard + * Copyright (C) 2016-2025 Cyrille Bagard * * This file is part of Chrysalide. * @@ -27,35 +27,100 @@ #include <assert.h> #include <malloc.h> +#include <string.h> -#include "items.h" -#include "../panel-int.h" -#include "../panels/bintree.h" -#include "../panels/bookmarks.h" -#include "../panels/errors.h" -#include "../panels/glance.h" -#include "../panels/history.h" -#include "../panels/log.h" -#include "../panels/regedit.h" -#include "../panels/strings.h" -#include "../panels/symbols.h" +#include <i18n.h> + + +#include "../panels/binary.h" +#include "../panels/binary-params.h" +#include "../panels/logs.h" #include "../panels/welcome.h" -#include "../../core/params.h" +#include "../../gtkext/launcher.h" + + + +/* Définition générique complète d'un panneau */ +typedef struct _ext_panel_info_t +{ + /* Début des champs copiés de panel_info_t */ + + char *category; /* Groupe de rassemblement */ + + char *image; /* Eventuelle image associée */ + char *title; /* Désignation humaine */ + char *desc; /* Description humaine */ + + FrameworkPanelPersonality personality; /* Comportement attendu */ + + GType panel_type; /* Type du panneau représenté */ + GType params_type; /* Composant de paramètre */ + + /* Fin des champs copiés de panel_info_t */ + + GtkTiledPanel *singleton; /* Conservation des allocations*/ +} ext_panel_info_t; /* Liste des panneaux disponibles */ -static GType *_panels_list = NULL; +static ext_panel_info_t **_panels_list = NULL; static size_t _panels_count = 0; +/* Copie une définition basique de panneau graphqiue. */ +static ext_panel_info_t *copy_panel_info(const panel_info_t *); + +/* Efface une définition étendue de panneau graphique. */ +static void delete_panel_info(ext_panel_info_t *); + + /****************************************************************************** * * -* Paramètres : - * +* Paramètres : info = information de base à copier. * +* * +* Description : Copie une définition basique de panneau graphqiue. * +* * +* Retour : Structure mémorisant l'ensemble des informations. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static ext_panel_info_t *copy_panel_info(const panel_info_t *info) +{ + ext_panel_info_t *result; /* Structure à retourner */ + + result = calloc(1, sizeof(ext_panel_info_t)); + + if (info->category != NULL) + result->category = strdup(info->category); + + if (info->image != NULL) + result->image = strdup(info->image); + + result->title = strdup(info->title); + + if (info->desc != NULL) + result->desc = strdup(info->desc); + + result->personality = info->personality; + + result->panel_type = info->panel_type; + result->params_type = info->params_type; + + return result; + +} + + +/****************************************************************************** * * -* Description : Charge les principaux panneaux de l'éditeur. * +* Paramètres : info = informations à supprimer de la mémoire. * +* * +* Description : Efface une définition étendue de panneau graphique. * * * * Retour : - * * * @@ -63,38 +128,132 @@ static size_t _panels_count = 0; * * ******************************************************************************/ -void load_main_panels(void) +static void delete_panel_info(ext_panel_info_t *info) { - GGenConfig *config; /* Configuration globale */ - GPanelItem *panel; /* Panneau à précharger */ + if (info->category != NULL) + free(info->category); + + if (info->image != NULL) + free(info->image); + + free(info->title); + + if (info->desc != NULL) + free(info->desc); + + if (info->singleton != NULL) + { + assert(info->personality & FPP_SINGLETON); + unref_object(info->singleton); + } + + free(info); + +} - config = get_main_configuration(); - register_panel_item(G_TYPE_LOG_PANEL, config); +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Charge les définitions des principaux panneaux du framework. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool load_main_framework_panel_definitions(void) +{ + bool result; /* Bilan à retourner */ + panel_info_t info; /* Infos d'enregistrement */ /* Chargement du panneau de rapport au plus tôt */ - panel = g_panel_item_new(G_TYPE_LOG_PANEL, NULL); - g_object_unref(G_OBJECT(panel)); - - register_panel_item(G_TYPE_WELCOME_PANEL, config); - register_panel_item(G_TYPE_REGEDIT_PANEL, config); - register_panel_item(G_TYPE_SYMBOLS_PANEL, config); - register_panel_item(G_TYPE_HISTORY_PANEL, config); - register_panel_item(G_TYPE_STRINGS_PANEL, config); - register_panel_item(G_TYPE_GLANCE_PANEL, config); - register_panel_item(G_TYPE_BOOKMARKS_PANEL, config); - register_panel_item(G_TYPE_BINTREE_PANEL, config); - register_panel_item(G_TYPE_ERROR_PANEL, config); + + info.category = NULL; + + info.image = NULL; + info.title = _("Logs"); + info.desc = NULL; + + info.personality = FPP_SINGLETON; + + info.panel_type = GTK_TYPE_LOGS_PANEL; + info.params_type = G_TYPE_INVALID; + + result = register_framework_panel_definition(&info); + if (!result) goto done; + + /* Chargements des panneaux restants */ + + info.category = "Main"; + + info.image = "binfile-symbolic"; + info.title = _("Binary analysis"); + info.desc = _("Load a binary content and parse its format if recognized"); + + info.personality = FPP_MAIN_PANEL; + + info.panel_type = GTK_TYPE_BINARY_PANEL; + info.params_type = GTK_TYPE_BINARY_PARAMETERS; + + result = register_framework_panel_definition(&info); + if (!result) goto done; + + /* --- */ + + info.category = NULL; + + info.image = NULL; + info.title = _("Welcome"); + info.desc = NULL; + + info.personality = FPP_MAIN_PANEL | FPP_SINGLETON; + + info.panel_type = GTK_TYPE_WELCOME_PANEL; + info.params_type = G_TYPE_INVALID; + + result = register_framework_panel_definition(&info); + if (!result) goto done; + + done: + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Décharge tous les panneaux graphiques du framework. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void unload_all_framework_panel_definitions(void) +{ + size_t i; /* Boucle de parcours */ + + for (i = 0; i < _panels_count; i++) + delete_panel_info(_panels_list[i]); + + _panels_list = NULL; + _panels_count = 0; } /****************************************************************************** * * -* Paramètres : type = type du composant à présenter à l'affichage. * -* config = configuration à compléter. * +* Paramètres : info = information de base à copier. * * * -* Description : Enregistre un panneau comme partie intégrante de l'éditeur. * +* Description : Enregistre la définition d'un panneau graphique. * * * * Retour : - * * * @@ -102,71 +261,199 @@ void load_main_panels(void) * * ******************************************************************************/ -void register_panel_item(GType type, GGenConfig *config) +bool register_framework_panel_definition(const panel_info_t *info) { - GPanelItemClass *class; /* Classe associée au type */ -#ifndef NDEBUG - bool status; /* Bilan de mise en place */ -#endif + bool result; /* Bilan à retourner */ + size_t i; /* Boucle de parcours */ + ext_panel_info_t *ext_info; /* Informations conservées */ + + result = false; + + /* Validation */ + + for (i = 0; i < _panels_count; i++) + if (_panels_list[i]->panel_type == info->panel_type) + break; - _panels_list = realloc(_panels_list, ++_panels_count * sizeof(GType)); + if (i < _panels_count) + goto done; - _panels_list[_panels_count - 1] = type; + /* Enregistrement */ - class = g_type_class_ref(type); + ext_info = copy_panel_info(info); -#ifndef NDEBUG - status = gtk_panel_item_class_setup_configuration(class, config); - assert(status); -#else - gtk_panel_item_class_setup_configuration(class, config); -#endif + _panels_list = realloc(_panels_list, ++_panels_count * sizeof(ext_panel_info_t *)); - g_type_class_unref(class); + _panels_list[_panels_count - 1] = ext_info; + + result = true; + + done: + + return result; } /****************************************************************************** * * -* Paramètres : skip = saute le panneau d'accueil lors du parcours ? * -* handle = routine à appeler pour chaque panneau. * -* data = données fournies pour accompagner cet appel. * +* Paramètres : target = type de définition de panneau recherchée. * * * -* Description : Effectue le parcours de tous les panneaux chargés. * +* Description : Récupère les particularités d'un panneau graphique. * * * -* Retour : true si le parcours a été total, false sinon. * +* Retour : Détails du comportement associé au panneau visé. * * * * Remarques : - * * * ******************************************************************************/ -bool _browse_all_item_panels(bool skip, handle_panel_item_fc handle, void *data) +FrameworkPanelPersonality get_framework_panel_personality(GType target) { - bool result; /* Résultat à renvoyer */ - GType type; /* Type de panneau à traiter */ + FrameworkPanelPersonality result; /* Propriétées à retourner */ size_t i; /* Boucle de parcours */ - GPanelItemClass *class; /* Classe associée au type */ + ext_panel_info_t *info; /* Informations conservées */ - result = true; + result = FPP_NONE; + + for (i = 0; i < _panels_count; i++) + { + info = _panels_list[i]; + + if (info->panel_type == target) + { + result = info->personality; + break; + } + + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : target = type de définition de panneau recherchée. * +* * +* Description : Met en place (au besoin) un panneau graphique unique. * +* * +* Retour : Instance de définition identifiée ou NULL en cas d'échec. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkTiledPanel *get_framework_panel_singleton(GType target) +{ + GtkTiledPanel *result; /* Instance à renvoyer */ + size_t i; /* Boucle de parcours */ + ext_panel_info_t *info; /* Informations conservées */ + + result = NULL; + + for (i = 0; i < _panels_count; i++) + { + info = _panels_list[i]; + + if (info->panel_type == target) + { + if (info->singleton == NULL) + info->singleton = g_object_new(target, NULL); + + result = info->singleton; + ref_object(result); + break; + + } + + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : list = liste à compléter. * +* * +* Description : Intègre une définition de panneau enregistrée. * +* * +* Retour : true pour un parcours complet de la liste des définitions. * +* * +* Remarques : - * +* * +******************************************************************************/ + +void populate_framework_panel_launcher_list(GtkListBox *list) +{ + size_t i; /* Boucle de parcours */ + ext_panel_info_t *info; /* Informations conservées */ + GtkPanelLauncher *launcher; /* Lanceur à intégrer */ for (i = 0; i < _panels_count; i++) { - type = _panels_list[i]; + info = _panels_list[i]; - if (skip && type == G_TYPE_WELCOME_PANEL) + if (info->category == NULL) continue; - class = g_type_class_ref(type); + launcher = gtk_panel_launcher_new(info->image, info->title, info->desc); + + g_object_set_data(G_OBJECT(launcher), "panel_type", GSIZE_TO_POINTER(info->panel_type)); + + gtk_list_box_append(list, GTK_WIDGET(launcher)); - result = handle(class, data); + } + +} - g_type_class_unref(class); - if (!result) break; +/****************************************************************************** +* * +* Paramètres : row = lanceur sélectionné. * +* * +* Description : Fournit un composant d'édition de paramètres de panneau. * +* * +* Retour : Composant d'édition de paramètres ou NULL. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkWidget *get_framework_panel_parameters(GtkListBoxRow *row) +{ + GtkWidget *result; /* Composant à retourner */ + gpointer *data; /* Valeur incrustée */ + GType target; /* Type de panneau recherché */ + ext_panel_info_t *info; /* Informations conservées */ + size_t i; /* Boucle de parcours */ + + data = g_object_get_data(G_OBJECT(row), "panel_type"); + assert(data != NULL); + + target = GPOINTER_TO_SIZE(data); + + info = NULL; + + for (i = 0; i < _panels_count; i++) + { + info = _panels_list[i]; + + if (info->panel_type == target) + break; } + assert(info != NULL); + assert(i < _panels_count); + + if (info->params_type == G_TYPE_INVALID) + result = NULL; + else + result = g_object_new(info->params_type, NULL); + return result; } diff --git a/src/gui/core/panels.h b/src/gui/core/panels.h index 3846038..e17ef8a 100644 --- a/src/gui/core/panels.h +++ b/src/gui/core/panels.h @@ -1,8 +1,8 @@ /* Chrysalide - Outil d'analyse de fichiers binaires - * panels.h - prototypes pour la gestion d'ensemble de tous les panneaux pour l'éditeur + * panels.h - prototypes pour la gestion d'ensemble de tous les panneaux graphiques du framework * - * Copyright (C) 2016-2019 Cyrille Bagard + * Copyright (C) 2016-2025 Cyrille Bagard * * This file is part of Chrysalide. * @@ -26,28 +26,62 @@ #define _GUI_CORE_PANELS_H +#include <glib-object.h> #include <stdbool.h> +#include <gtk/gtk.h> -#include "../panel.h" -#include "../../glibext/configuration.h" +#include "../../gtkext/panel.h" -/* Charge les principaux panneaux de l'éditeur. */ -void load_main_panels(void); +/* Types de panneaux pour éditeur */ +typedef enum _FrameworkPanelPersonality +{ + FPP_NONE = (0 << 0), /* Pas de particularité */ -/* Enregistre un panneau comme partie intégrante de l'éditeur. */ -void register_panel_item(GType, GGenConfig *); + FPP_MAIN_PANEL = (1 << 0), /* Panneau principal */ + FPP_SINGLETON = (1 << 1), /* Instance unique */ -/* Réalise un traitement sur un panneau de l'éditeur. */ -typedef bool (* handle_panel_item_fc) (GPanelItemClass *, void *); +} FrameworkPanelPersonality; -/* Effectue le parcours de tous les panneaux chargés. */ -bool _browse_all_item_panels(bool, handle_panel_item_fc, void *); +/* Définition générique d'un panneau */ +typedef struct _panel_info_t +{ + const char *category; /* Groupe de rassemblement */ -#define browse_all_item_panels(h, d) \ - _browse_all_item_panels(false, h, d) + const char *image; /* Eventuelle image associée */ + const char *title; /* Désignation humaine */ + const char *desc; /* Description humaine */ + + FrameworkPanelPersonality personality; /* Comportement attendu */ + + GType panel_type; /* Type du panneau représenté */ + GType params_type; /* Composant de paramètre */ + +} panel_info_t; + + +/* Charge les définitions des principaux panneaux du framework. */ +bool load_main_framework_panel_definitions(void); + +/* Décharge tous les panneaux graphiques du framework. */ +void unload_all_framework_panel_definitions(void); + +/* Enregistre la définition d'un panneau graphique. */ +bool register_framework_panel_definition(const panel_info_t *); + +/* Récupère les particularités d'un panneau graphique. */ +FrameworkPanelPersonality get_framework_panel_personality(GType); + +/* Met en place (au besoin) un panneau graphique unique. */ +GtkTiledPanel *get_framework_panel_singleton(GType); + +/* Intègre une définition de panneau enregistrée. */ +void populate_framework_panel_launcher_list(GtkListBox *); + +/* Fournit un composant d'édition de paramètres de panneau. */ +GtkWidget *get_framework_panel_parameters(GtkListBoxRow *); diff --git a/src/gui/dialogs/Makefile.am b/src/gui/dialogs/Makefile.am index 5716f14..3492f63 100644 --- a/src/gui/dialogs/Makefile.am +++ b/src/gui/dialogs/Makefile.am @@ -3,35 +3,43 @@ BUILT_SOURCES = resources.h resources.c noinst_LTLIBRARIES = libguidialogs.la -UI_FILES = \ - about.ui \ - bookmark.ui \ - export_graph.ui \ - identity.ui \ - loading.ui \ - preferences.ui \ - prefs_fgraph.ui \ - prefs_labels.ui \ - snapshots.ui \ - storage.ui - -libguidialogs_la_SOURCES = \ - about.h about.c \ - bookmark.h bookmark.c \ - export_disass.h export_disass.c \ - export_graph.h export_graph.c \ - goto.h goto.c \ - gotox.h gotox.c \ - identity.h identity.c \ - loading.h loading.c \ - preferences.h preferences.c \ - prefs_fgraph.h prefs_fgraph.c \ - prefs_labels.h prefs_labels.c \ - resources.h resources.c \ - snapshots.h snapshots.c \ - storage.h storage.c - -libguidialogs_la_CFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) + +UI_FILES = \ + about.css \ + about.ui \ + preferences.ui +# bookmark.ui \ +# export_graph.ui \ +# identity.ui \ +# loading.ui \ +# prefs_fgraph.ui \ +# prefs_labels.ui \ +# snapshots.ui \ +# storage.ui + +libguidialogs_la_SOURCES = \ + about-int.h \ + about.h about.c \ + preferences-int.h \ + preferences.h preferences.c \ + resources.h resources.c +# bookmark.h bookmark.c \ +# export_disass.h export_disass.c \ +# export_graph.h export_graph.c \ +# goto.h goto.c \ +# gotox.h gotox.c \ +# identity.h identity.c \ +# loading.h loading.c \ +# \ +# prefs_fgraph.h prefs_fgraph.c \ +# prefs_labels.h prefs_labels.c \ +# snapshots.h snapshots.c \ +# storage.h storage.c + +libguidialogs_la_LIBADD = \ + prefs/libguidialogsprefs.la + +libguidialogs_la_CFLAGS = $(LIBGTK4_CFLAGS) devdir = $(includedir)/chrysalide/$(subdir:src/%=core/%) @@ -39,6 +47,9 @@ devdir = $(includedir)/chrysalide/$(subdir:src/%=core/%) dev_HEADERS = $(libguidialogs_la_SOURCES:%c=) +SUBDIRS = prefs + + resources.c: gresource.xml $(UI_FILES) glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-source --c-name gui_dialogs gresource.xml diff --git a/src/gui/dialogs/about-int.h b/src/gui/dialogs/about-int.h new file mode 100644 index 0000000..96a470e --- /dev/null +++ b/src/gui/dialogs/about-int.h @@ -0,0 +1,55 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * about-int.h - définitions internes pour la boîte de dialogue d'information sur le programme + * + * Copyright (C) 2024 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _GUI_DIALOGS_ABOUT_INT_H +#define _GUI_DIALOGS_ABOUT_INT_H + + +#include <stdbool.h> + + +#include "about.h" + + + +/* Boîte "A propos de" dédiée à l'application (instance) */ +struct _GtkAppAboutDialog +{ + GtkWindow parent; /* A laisser en premier */ + +}; + +/* Boîte "A propos de" dédiée à l'application (classe) */ +struct _GtkAppAboutDialogClass +{ + GtkWindowClass parent; /* A laisser en premier */ + +}; + + +/* Met en place la fenêtre d'informations sur le logiciel. */ +bool gtk_app_about_dialog_create(GtkAppAboutDialog *, GtkWindow *); + + + +#endif /* _GUI_DIALOGS_ABOUT_INT_H */ diff --git a/src/gui/dialogs/about.c b/src/gui/dialogs/about.c index 574c7f2..1dca752 100644 --- a/src/gui/dialogs/about.c +++ b/src/gui/dialogs/about.c @@ -2,7 +2,7 @@ /* Chrysalide - Outil d'analyse de fichiers binaires * about.h - boîte de dialogue d'information sur le programme * - * Copyright (C) 2015-2020 Cyrille Bagard + * Copyright (C) 2015-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -33,143 +33,168 @@ #include <config.h> -#include "../../gtkext/easygtk.h" +#include "about-int.h" -/* Réagit à l'appui d'une touche sur la fenêtre 'A propos'. */ -static gboolean close_about_window_on_escape(GtkWidget *, GdkEventKey *, gpointer); +/* Procède à l'initialisation de la boîte "A propos de". */ +static void gtk_app_about_dialog_class_init(GtkAppAboutDialogClass *); -/* Dessine un fond adapté pour la fenêtre sans toucher au thème. */ -static gboolean draw_black_background(GtkWidget *, cairo_t *, gpointer); +/* Procède à l'initialisation de la boîte "A propos de". */ +static void gtk_app_about_dialog_init(GtkAppAboutDialog *); +/* Supprime toutes les références externes. */ +static void gtk_app_about_dialog_dispose(GObject *); + +/* Procède à la libération totale de la mémoire. */ +static void gtk_app_about_dialog_finalize(GObject *); + + + +/* Détermine le type du composant d'affichage générique. */ +G_DEFINE_TYPE(GtkAppAboutDialog, gtk_app_about_dialog, GTK_TYPE_WINDOW); /****************************************************************************** * * -* Paramètres : parent = fenêtre parente à surpasser. * -* outb = constructeur à détruire après usage. [OUT] * +* Paramètres : class = classe GTK à initialiser. * * * -* Description : Construit la fenêtre d'informations sur le logiciel. * +* Description : Procède à l'initialisation de la boîte "A propos de". * * * -* Retour : Adresse de la fenêtre mise en place. * +* Retour : - * * * * Remarques : - * * * ******************************************************************************/ -GtkWidget *create_about_dialog(GtkWindow *parent, GtkBuilder **outb) +static void gtk_app_about_dialog_class_init(GtkAppAboutDialogClass *class) { - GtkWidget *result; /* Fenêtre à renvoyer */ - GtkBuilder *builder; /* Constructeur utilisé */ - unsigned int revision; /* Numéro de révision */ - unsigned int max; /* Nbre. de boucles à effectuer*/ - unsigned int i; /* Boucle de parcours */ - unsigned int level; /* Unité la plus importante */ - char buffer[64]; /* Nom d'image à forger */ - GtkImage *img; /* Composant d'affichage */ + GObjectClass *object; /* Plus haut niveau équivalent */ + GtkWidgetClass *widget; /* Classe de haut niveau */ - builder = gtk_builder_new_from_resource("/org/chrysalide/gui/dialogs/about.ui"); - *outb = builder; + object = G_OBJECT_CLASS(class); - result = GTK_WIDGET(gtk_builder_get_object(builder, "window")); + object->dispose = gtk_app_about_dialog_dispose; + object->finalize = gtk_app_about_dialog_finalize; - gtk_window_set_transient_for(GTK_WINDOW(result), parent); + widget = GTK_WIDGET_CLASS(class); - /* Numéro de révision */ + gtk_widget_class_set_css_name(widget, "aboutdialog"); - revision = REVISION; - max = log(revision) / log(10); + gtk_widget_class_add_binding_action(widget, GDK_KEY_Escape, 0, "window.close", NULL); - assert(max <= 6); + gtk_widget_class_set_template_from_resource(widget, "/re/chrysalide/framework/gui/dialogs/about.ui"); - for (i = 0; i <= max; i++) - { - snprintf(buffer, 64, "revision_%u", i); +} - img = GTK_IMAGE(gtk_builder_get_object(builder, buffer)); - level = pow(10, max - i); +/****************************************************************************** +* * +* Paramètres : dialog = composant GTK à initialiser. * +* * +* Description : Procède à l'initialisation de la boîte "A propos de". * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ - snprintf(buffer, 64, "/org/chrysalide/gui/dialogs/about/revision_%u.png", revision / level); +static void gtk_app_about_dialog_init(GtkAppAboutDialog *dialog) +{ + gtk_widget_init_template(GTK_WIDGET(dialog)); - gtk_image_set_from_resource(img, buffer); +} - revision %= level; - } +/****************************************************************************** +* * +* Paramètres : object = instance d'objet GLib à traiter. * +* * +* Description : Supprime toutes les références externes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ - /* Connexion des signaux */ +static void gtk_app_about_dialog_dispose(GObject *object) +{ + gtk_widget_dispose_template(GTK_WIDGET(object), GTK_TYPE_APP_ABOUT_DIALOG); - gtk_builder_add_callback_symbols(builder, - BUILDER_CALLBACK(close_about_window_on_escape), - BUILDER_CALLBACK(draw_black_background), - NULL); + G_OBJECT_CLASS(gtk_app_about_dialog_parent_class)->dispose(object); - gtk_builder_connect_signals(builder, builder); +} - return result; + +/****************************************************************************** +* * +* Paramètres : object = instance d'objet GLib à traiter. * +* * +* Description : Procède à la libération totale de la mémoire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_app_about_dialog_finalize(GObject *object) +{ + G_OBJECT_CLASS(gtk_app_about_dialog_parent_class)->finalize(object); } /****************************************************************************** * * -* Paramètres : widget = fenêtre visée par la procédure. * -* event = informations liées à l'événement. * -* dummy = donnée non utilisée ici. * +* Paramètres : parent = fenêtre parente à surpasser. * * * -* Description : Réagit à l'appui d'une touche sur la fenêtre 'A propos'. * +* Description : Construit la fenêtre d'informations sur le logiciel. * * * -* Retour : TRUE pour interrompre la propagation, FALSE autrement. * +* Retour : Adresse de la fenêtre mise en place. * * * * Remarques : - * * * ******************************************************************************/ -static gboolean close_about_window_on_escape(GtkWidget *widget, GdkEventKey *event, gpointer dummy) +GtkWindow *gtk_app_about_dialog_new(GtkWindow *parent) { - gboolean result; /* Ordre à retourner */ + GtkWindow *result; /* Boite de dialogue à renvoyer*/ + + result = g_object_new(GTK_TYPE_APP_ABOUT_DIALOG, NULL); - if (event->keyval == GDK_KEY_Escape) - { - gtk_widget_destroy(widget); - result = TRUE; - } - else result = FALSE; + if (!gtk_app_about_dialog_create(GTK_APP_ABOUT_DIALOG(result), parent)) + g_clear_object(&result); return result; } + /****************************************************************************** * * -* Paramètres : widget = fenêtre visée par la procédure. * -* event = informations liées à l'événement. * -* dummy = donnée non utilisée ici. * +* Paramètres : dialog = boîte de dialogue à initialiser pleinement. * +* parent = fenêtre parente à surpasser. * * * -* Description : Dessine un fond adapté pour la fenêtre sans toucher au thème.* +* Description : Met en place la fenêtre d'informations sur le logiciel. * * * -* Retour : TRUE pour interrompre la propagation, FALSE autrement. * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -static gboolean draw_black_background(GtkWidget *widget, cairo_t *cr, gpointer dummy) +bool gtk_app_about_dialog_create(GtkAppAboutDialog *dialog, GtkWindow *parent) { - int width; /* Largeur du composant */ - int height; /* Hauteur du composant */ + bool result; /* Bilan à retourner */ - width = gtk_widget_get_allocated_width(widget); - height = gtk_widget_get_allocated_height(widget); + result = true; - cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); + gtk_window_set_transient_for(GTK_WINDOW(dialog), parent); - cairo_rectangle(cr, 0, 0, width, height); - cairo_fill(cr); - - return FALSE; + return result; } diff --git a/src/gui/dialogs/about.css b/src/gui/dialogs/about.css new file mode 100644 index 0000000..af3fa97 --- /dev/null +++ b/src/gui/dialogs/about.css @@ -0,0 +1,9 @@ + +aboutdialog > box { + + background-color: black; + + background-image: url('resource:///re/chrysalide/framework/gui/dialogs/about/bg.png'); + background-repeat: no-repeat; + +} diff --git a/src/gui/dialogs/about.h b/src/gui/dialogs/about.h index f119f67..e569ad3 100644 --- a/src/gui/dialogs/about.h +++ b/src/gui/dialogs/about.h @@ -2,7 +2,7 @@ /* Chrysalide - Outil d'analyse de fichiers binaires * about.h - prototypes pour la boîte de dialogue d'information sur le programme * - * Copyright (C) 2015-2020 Cyrille Bagard + * Copyright (C) 2015-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -28,9 +28,17 @@ #include <gtk/gtk.h> +#include "../../glibext/helpers.h" + + + +#define GTK_TYPE_APP_ABOUT_DIALOG (gtk_app_about_dialog_get_type()) + +DECLARE_GTYPE(GtkAppAboutDialog, gtk_app_about_dialog, GTK, APP_ABOUT_DIALOG); + /* Construit la fenêtre d'informations sur le logiciel. */ -GtkWidget *create_about_dialog(GtkWindow *, GtkBuilder **); +GtkWindow *gtk_app_about_dialog_new(GtkWindow *); diff --git a/src/gui/dialogs/about.ui b/src/gui/dialogs/about.ui index 0170508..7b519d2 100644 --- a/src/gui/dialogs/about.ui +++ b/src/gui/dialogs/about.ui @@ -1,151 +1,28 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- Generated with glade 3.37.0 --> <interface> - <requires lib="gtk+" version="3.12"/> - <object class="GtkWindow" id="window"> - <property name="width-request">350</property> - <property name="height-request">430</property> - <property name="can-focus">False</property> - <property name="border-width">0</property> - <property name="title" translatable="yes">About</property> - <property name="resizable">False</property> - <property name="modal">True</property> - <property name="window-position">center-on-parent</property> - <property name="default-width">350</property> - <property name="default-height">430</property> - <property name="type-hint">dialog</property> - <signal name="key-press-event" handler="close_about_window_on_escape" swapped="no"/> - <child> - <object class="GtkFixed"> - <property name="visible">True</property> - <property name="can-focus">False</property> - <signal name="draw" handler="draw_black_background" swapped="no"/> - <child> - <object class="GtkLabel"> - <property name="width-request">350</property> - <property name="height-request">20</property> - <property name="visible">True</property> - <property name="can-focus">False</property> - <property name="margin-bottom">10</property> - <property name="label" translatable="yes"><span fgcolor='white'>Copyright (C) 2008-2020 Cyrille Bagard</span></property> - <property name="use-markup">True</property> - </object> - <packing> - <property name="y">400</property> - </packing> - </child> - <child> - <object class="GtkImage" id="logo"> - <property name="width-request">330</property> - <property name="height-request">300</property> - <property name="visible">True</property> - <property name="can-focus">False</property> - <property name="resource">/org/chrysalide/gui/dialogs/about/chrysalide-full.png</property> - </object> - <packing> - <property name="x">10</property> - <property name="y">10</property> - </packing> - </child> - <child> - <object class="GtkImage" id="text"> - <property name="width-request">253</property> - <property name="height-request">42</property> - <property name="visible">True</property> - <property name="can-focus">False</property> - <property name="resource">/org/chrysalide/gui/dialogs/about/chrysalide_text.png</property> - </object> - <packing> - <property name="x">48</property> - <property name="y">324</property> - </packing> - </child> - <child> - <object class="GtkImage" id="revision"> - <property name="width-request">14</property> - <property name="height-request">18</property> - <property name="visible">True</property> - <property name="can-focus">False</property> - <property name="resource">/org/chrysalide/gui/dialogs/about/revision.png</property> - </object> - <packing> - <property name="x">149</property> - <property name="y">360</property> - </packing> - </child> - <child> - <object class="GtkImage" id="revision_0"> - <property name="width-request">14</property> - <property name="height-request">18</property> - <property name="visible">True</property> - <property name="can-focus">False</property> - </object> - <packing> - <property name="x">163</property> - <property name="y">360</property> - </packing> - </child> - <child> - <object class="GtkImage" id="revision_1"> - <property name="width-request">14</property> - <property name="height-request">18</property> - <property name="visible">True</property> - <property name="can-focus">False</property> - </object> - <packing> - <property name="x">177</property> - <property name="y">360</property> - </packing> - </child> - <child> - <object class="GtkImage" id="revision_2"> - <property name="width-request">14</property> - <property name="height-request">18</property> - <property name="visible">True</property> - <property name="can-focus">False</property> - </object> - <packing> - <property name="x">191</property> - <property name="y">360</property> - </packing> - </child> - <child> - <object class="GtkImage" id="revision_3"> - <property name="width-request">14</property> - <property name="height-request">18</property> - <property name="visible">True</property> - <property name="can-focus">False</property> - </object> - <packing> - <property name="x">205</property> - <property name="y">360</property> - </packing> - </child> - <child> - <object class="GtkImage" id="revision_4"> - <property name="width-request">14</property> - <property name="height-request">18</property> - <property name="visible">True</property> - <property name="can-focus">False</property> - </object> - <packing> - <property name="x">219</property> - <property name="y">360</property> - </packing> - </child> - <child> - <object class="GtkImage" id="revision_5"> - <property name="width-request">14</property> - <property name="height-request">18</property> - <property name="visible">True</property> - <property name="can-focus">False</property> - </object> - <packing> - <property name="x">233</property> - <property name="y">360</property> - </packing> - </child> - </object> - </child> - </object> + + <template class="GtkAppAboutDialog" parent="GtkWindow"> + <property name="title" translatable="yes">About</property> + <property name="default-width">350</property> + <property name="default-height">430</property> + <property name="modal">true</property> + <property name="resizable">false</property> + + <child> + <object class="GtkBox"> + <property name="orientation">vertical</property> + + <child> + <object class="GtkLabel"> + <property name="margin-top">368</property> + <property name="margin-bottom">10</property> + <property name="label" translatable="yes"><span fgcolor='white'>Copyright (C) 2008-2025 Cyrille Bagard</span></property> + <property name="use-markup">True</property> + </object> + </child> + + </object> + </child> + + </template> </interface> diff --git a/src/gui/dialogs/gresource.xml b/src/gui/dialogs/gresource.xml index 0e12ef2..966d9c8 100644 --- a/src/gui/dialogs/gresource.xml +++ b/src/gui/dialogs/gresource.xml @@ -1,30 +1,8 @@ <?xml version="1.0" encoding="UTF-8"?> <gresources> - <gresource prefix="/org/chrysalide/gui/dialogs"> + <gresource prefix="/re/chrysalide/framework/gui/dialogs"> + <file compressed="true">about.css</file> <file compressed="true">about.ui</file> - <file compressed="true">bookmark.ui</file> - <file compressed="true">export_graph.ui</file> - <file compressed="true">identity.ui</file> - <file compressed="true">loading.ui</file> <file compressed="true">preferences.ui</file> - <file compressed="true">prefs_fgraph.ui</file> - <file compressed="true">prefs_labels.ui</file> - <file compressed="true">snapshots.ui</file> - <file compressed="true">storage.ui</file> - </gresource> - <gresource prefix="/org/chrysalide/gui/dialogs/about"> - <file compressed="true" alias="chrysalide-full.png">../../../pixmaps/chrysalide-full.png</file> - <file compressed="true" alias="chrysalide_text.png">../../../pixmaps/chrysalide_text.png</file> - <file compressed="true" alias="revision.png">../../../pixmaps/revision.png</file> - <file compressed="true" alias="revision_0.png">../../../pixmaps/revision_0.png</file> - <file compressed="true" alias="revision_1.png">../../../pixmaps/revision_1.png</file> - <file compressed="true" alias="revision_2.png">../../../pixmaps/revision_2.png</file> - <file compressed="true" alias="revision_3.png">../../../pixmaps/revision_3.png</file> - <file compressed="true" alias="revision_4.png">../../../pixmaps/revision_4.png</file> - <file compressed="true" alias="revision_5.png">../../../pixmaps/revision_5.png</file> - <file compressed="true" alias="revision_6.png">../../../pixmaps/revision_6.png</file> - <file compressed="true" alias="revision_7.png">../../../pixmaps/revision_7.png</file> - <file compressed="true" alias="revision_8.png">../../../pixmaps/revision_8.png</file> - <file compressed="true" alias="revision_9.png">../../../pixmaps/revision_9.png</file> </gresource> </gresources> diff --git a/src/gui/dialogs/preferences-int.h b/src/gui/dialogs/preferences-int.h new file mode 100644 index 0000000..806f5f6 --- /dev/null +++ b/src/gui/dialogs/preferences-int.h @@ -0,0 +1,62 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * preferences-int.h - définitions internes pour la boîte de dialogue d'édition des préférences de l'utilisateur + * + * Copyright (C) 2025 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _GUI_DIALOGS_PREFERENCES_INT_H +#define _GUI_DIALOGS_PREFERENCES_INT_H + + +#include <stdbool.h> + + +#include "preferences.h" + + + +/* Fenêtre d'édition générale de la configuration (instance) */ +struct _GtkPreferencesDialog +{ + GtkWindow parent; /* A laisser en premier */ + + GtkLabel *side_title; /* Titre principal */ + GtkScrolledWindow *side_content; /* Liste des sections */ + GtkLabel *main_title; /* Titre de section */ + GtkScrolledWindow *main_content; /* Page de configuration */ + + GHashTable *navigations; /* Liste de sections en place */ + +}; + +/* Fenêtre d'édition générale de la configuration (classe) */ +struct _GtkPreferencesDialogClass +{ + GtkWindowClass parent; /* A laisser en premier */ + +}; + + +/* Met en place la boîte de dialogue pour les préférences. */ +bool gtk_preferences_dialog_create(GtkPreferencesDialog *, GtkWindow *); + + + +#endif /* _GUI_DIALOGS_PREFERENCES_INT_H */ diff --git a/src/gui/dialogs/preferences.c b/src/gui/dialogs/preferences.c index 4a3fb7c..0369241 100644 --- a/src/gui/dialogs/preferences.c +++ b/src/gui/dialogs/preferences.c @@ -1,8 +1,8 @@ /* Chrysalide - Outil d'analyse de fichiers binaires - * preferences.c - (re)définition de l'identité de l'utilisateur + * preferences.c - boîte de dialogue d'édition des préférences de l'utilisateur * - * Copyright (C) 2019 Cyrille Bagard + * Copyright (C) 2019-2025 Cyrille Bagard * * This file is part of Chrysalide. * @@ -24,129 +24,105 @@ #include "preferences.h" -#include <i18n.h> +#include <assert.h> +#include <math.h> +#include <stdio.h> +#include <gdk/gdkkeysyms.h> -#include "prefs_fgraph.h" -#include "prefs_labels.h" -#include "../../core/params.h" -#include "../../gtkext/easygtk.h" +#include <config.h> +#include "preferences-int.h" +#include "prefs/appearance.h" +#include "prefs/security.h" +#include "../../common/cpp.h" +#include "../../gtkext/tweak.h" +#include "../../plugins/pglist.h" +#include "../../plugins/tweakable.h" -/* Constructeur de panneau de paramétrage */ -typedef GtkWidget * (* prefs_panel_creation_cb) (GtkBuilder **); -/* Chargement de la configuration */ -typedef void (* prefs_config_update_cb) (GtkBuilder *, GGenConfig *); -/* Description d'un noeud de préférences */ -typedef struct _pref_node_desc_t -{ - prefs_panel_creation_cb create; /* Procédure de création */ - prefs_config_update_cb load; /* Procédure de chargement */ - prefs_config_update_cb store; /* Procédure d'enregistrement */ - - const char *name; /* Désignation interne */ - const char *title; /* Désignation humaine */ - - GtkBuilder *builder; /* Constructeur GTK */ - GtkWidget *panel; /* Panneau GTK */ - - struct _pref_node_desc_t *children; /* Sous-arborescence */ - -} pref_node_desc_t; - - -#define PREF_NODE_NULL_ENTRY { .title = NULL } +/* --------------------------- BASES DE BOITE DE DIALOGUE --------------------------- */ -/* Liste des paramétrages à afficher */ -static pref_node_desc_t _prefs_nodes[] = { +/* Procède à l'initialisation de la fenêtre des paramètres. */ +static void gtk_preferences_dialog_class_init(GtkPreferencesDialogClass *); - { - .create = NULL, - - .title = "Analysis", +/* Procède à l'initialisation de la fenêtre des paramètres. */ +static void gtk_preferences_dialog_init(GtkPreferencesDialog *); - .children = (pref_node_desc_t []){ +/* Supprime toutes les références externes. */ +static void gtk_preferences_dialog_dispose(GObject *); - { - .create = create_labels_preferences, - .load = load_labels_configuration, - .store = store_labels_configuration, +/* Procède à la libération totale de la mémoire. */ +static void gtk_preferences_dialog_finalize(GObject *); - .name = "labels", - .title = "Colored labels", +/* Fournit la liste de section désignée par un nom. */ +static GtkListBox *gtk_preferences_dialog_get_navigation(GtkPreferencesDialog *, const char *, bool); - }, +/* Réagit à un changement de sélection dans les sections. */ +static void gtk_preferences_dialog_on_row_selected(GtkListBox *, GtkListBoxRow *, GtkPreferencesDialog *); - PREF_NODE_NULL_ENTRY - } - }, +/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */ - { - .create = NULL, - .title = "Editor", - .children = (pref_node_desc_t []){ - { - .create = create_fgraph_preferences, - .load = load_fgraph_configuration, - .store = store_fgraph_configuration, - .name = "fgraph", - .title = "Function graph", +/* ---------------------------------------------------------------------------------- */ +/* BASES DE BOITE DE DIALOGUE */ +/* ---------------------------------------------------------------------------------- */ - }, - - PREF_NODE_NULL_ENTRY - - } - }, +/* Détermine le type du composant d'affichage générique. */ +G_DEFINE_TYPE(GtkPreferencesDialog, gtk_preferences_dialog, GTK_TYPE_WINDOW); - PREF_NODE_NULL_ENTRY - -}; +/****************************************************************************** +* * +* Paramètres : class = classe GTK à initialiser. * +* * +* Description : Procède à l'initialisation de la fenêtre des paramètres. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ -/* Eléments de la liste de sections */ -typedef enum _PrefListItem +static void gtk_preferences_dialog_class_init(GtkPreferencesDialogClass *class) { - PLI_TITLE, /* Etiquette de la section */ - PLI_PANEL, /* Panneau graphique associé */ + GObjectClass *object; /* Plus haut niveau équivalent */ + GtkWidgetClass *widget; /* Classe de haut niveau */ -} PrefListItem; + object = G_OBJECT_CLASS(class); + object->dispose = gtk_preferences_dialog_dispose; + object->finalize = gtk_preferences_dialog_finalize; -/* Ajoute un panneau de paramétrage à la boîte de dialogue. */ -static void add_preferences_node(GtkTreeStore *, GtkTreeIter *, GGenConfig *, GtkStack *, pref_node_desc_t *); + widget = GTK_WIDGET_CLASS(class); -/* Affiche le panneau correspondant au noeud sélectionné. */ -static void on_prefs_selection_changed(GtkTreeSelection *, GtkBuilder *); + gtk_widget_class_set_template_from_resource(widget, "/re/chrysalide/framework/gui/dialogs/preferences.ui"); -/* Lance la sauvegarde d'éléments de paramétrage. */ -static void store_preferences_node(GGenConfig *, pref_node_desc_t *); + gtk_widget_class_bind_template_child(widget, GtkPreferencesDialog, side_title); + gtk_widget_class_bind_template_child(widget, GtkPreferencesDialog, side_content); + gtk_widget_class_bind_template_child(widget, GtkPreferencesDialog, main_title); + gtk_widget_class_bind_template_child(widget, GtkPreferencesDialog, main_content); -/* Sauvegarde l'ensemble des paramètres de configuration. */ -static void on_prefs_apply_button_clicked(GtkButton *, GtkBuilder *); + /* Active une action native (cf. https://docs.gtk.org/gtk4/class.Window.html#actions) */ + gtk_widget_class_add_binding_action(widget, GDK_KEY_Escape, 0 /* GDK 4.14 : GDK_NO_MODIFIER_MASK */, "window.close", NULL); +} /****************************************************************************** * * -* Paramètres : store = arborescence des sections à compléter. * -* parent = point d'insertion du parent. * -* config = configuration globale à charger. * -* stack = pile de composants GTK à constituer. * -* node = noeud de description courant à traiter. * +* Paramètres : dialog = composant GTK à initialiser. * * * -* Description : Ajoute un panneau de paramétrage à la boîte de dialogue. * +* Description : Procède à l'initialisation de la fenêtre des paramètres. * * * * Retour : - * * * @@ -154,95 +130,152 @@ static void on_prefs_apply_button_clicked(GtkButton *, GtkBuilder *); * * ******************************************************************************/ -static void add_preferences_node(GtkTreeStore *store, GtkTreeIter *parent, GGenConfig *config, GtkStack *stack, pref_node_desc_t *node) +static void gtk_preferences_dialog_init(GtkPreferencesDialog *dialog) { - GtkTreeIter iter; /* Point d'insertion */ - pref_node_desc_t *child; /* Sous-élément à traiter */ + size_t i; /* Boucle de parcours */ + const tweak_info_t *info; /* Informations à considérer */ + GtkListBox *navigation; /* Liste de sections à afficher*/ + GtkTweakSection *section; /* Nouvelle section à présenter*/ + tweak_info_t *dyn_infos; /* Informations supplémentaires*/ + size_t dyn_count; /* Quantité de ces informations*/ + + tweak_info_t infos[] = { + TWEAK_SIMPLE_DEF("root", "Basics", + "security-high-symbolic", "appearance", "Appearance", GTK_TYPE_APPEARANCE_TWEAK_PANEL), + TWEAK_SIMPLE_DEF("root", "Basics", + "security-high-symbolic", "security", "Security", GTK_TYPE_SECURITY_TWEAK_PANEL), + }; + + gtk_widget_init_template(GTK_WIDGET(dialog)); - if (node->create == NULL) + dialog->navigations = g_hash_table_new_full(g_str_hash, g_str_equal, free, g_object_unref); + + /* Chargement des sections fixes */ + + for (i = 0; i < ARRAY_SIZE(infos); i++) { - node->builder = NULL; - node->panel = NULL; + info = &infos[i]; + + navigation = gtk_preferences_dialog_get_navigation(dialog, info->parent, true); + assert(navigation != NULL); + + section = gtk_tweak_section_new(info); + + gtk_list_box_append(navigation, GTK_WIDGET(section)); + } - else + + /* Chargement des sections dynamiques */ + + dyn_infos = get_tweakable_plugins_info(&dyn_count); + + for (i = 0; i < dyn_count; i++) { - node->panel = node->create(&node->builder); + info = &dyn_infos[i]; - node->load(node->builder, config); + navigation = gtk_preferences_dialog_get_navigation(dialog, info->parent, true); + assert(navigation != NULL); - gtk_widget_show(node->panel); + section = gtk_tweak_section_new(info); - gtk_stack_add_named(stack, node->panel, node->name); + gtk_list_box_append(navigation, GTK_WIDGET(section)); } - gtk_tree_store_append(store, &iter, parent); + if (dyn_infos != NULL) + free(dyn_infos); + + /* Affichage de la liste racine */ - gtk_tree_store_set(store, &iter, - PLI_TITLE, _(node->title), - PLI_PANEL, node->panel, - -1); + navigation = gtk_preferences_dialog_get_navigation(dialog, "root", false); + assert(navigation != NULL); - if (node->children != NULL) - for (child = node->children; child->title != NULL; child++) - add_preferences_node(store, &iter, config, stack, child); + g_signal_connect(navigation, "row-selected", + G_CALLBACK(gtk_preferences_dialog_on_row_selected), dialog); + + gtk_scrolled_window_set_child(dialog->side_content, GTK_WIDGET(navigation)); + + unref_object(navigation); } /****************************************************************************** * * -* Paramètres : parent = fenêtre principale de l'éditeur. * -* outb = constructeur à détruire après usage. [OUT] * +* Paramètres : object = instance d'objet GLib à traiter. * * * -* Description : Propose une boîte de dialogue pour la configuration générale.* +* Description : Supprime toutes les références externes. * * * -* Retour : Adresse de la fenêtre mise en place. * +* Retour : - * * * * Remarques : - * * * ******************************************************************************/ -GtkWidget *create_preferences_dialog(GtkWindow *parent, GtkBuilder **outb) +static void gtk_preferences_dialog_dispose(GObject *object) { - GtkWidget *result; /* Fenêtre à renvoyer */ - GtkBuilder *builder; /* Constructeur utilisé */ - GGenConfig *config; /* Configuration globale */ - GtkStack *stack; /* Pile à mettre à jour */ - GtkTreeStore *store; /* Arborescence des sections */ - pref_node_desc_t *iter; /* Boucle de parcours */ - GtkTreeView *treeview; /* Arborescence principale */ + GtkPreferencesDialog *dialog; /* Version spécialisée */ + + dialog = GTK_PREFERENCES_DIALOG(object); - builder = gtk_builder_new_from_resource("/org/chrysalide/gui/dialogs/preferences.ui"); - *outb = builder; + if (dialog->navigations != NULL) + { + /** + * Cf. documentation de g_hash_table_new_full(). + */ + g_hash_table_remove_all(dialog->navigations); - result = GTK_WIDGET(gtk_builder_get_object(builder, "window")); + g_hash_table_unref(dialog->navigations); + dialog->navigations = NULL; - gtk_window_set_transient_for(GTK_WINDOW(result), parent); + } - /* Intégration des différentes sections */ + gtk_widget_dispose_template(GTK_WIDGET(dialog), GTK_TYPE_PREFERENCES_DIALOG); + + G_OBJECT_CLASS(gtk_preferences_dialog_parent_class)->dispose(object); + +} - config = get_main_configuration(); - stack = GTK_STACK(gtk_builder_get_object(builder, "stack")); +/****************************************************************************** +* * +* Paramètres : object = instance d'objet GLib à traiter. * +* * +* Description : Procède à la libération totale de la mémoire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ - store = GTK_TREE_STORE(gtk_builder_get_object(builder, "pref_list")); +static void gtk_preferences_dialog_finalize(GObject *object) +{ + G_OBJECT_CLASS(gtk_preferences_dialog_parent_class)->finalize(object); - for (iter = _prefs_nodes; iter->title != NULL; iter++) - add_preferences_node(store, NULL, config, stack, iter); +} - treeview = GTK_TREE_VIEW(gtk_builder_get_object(builder, "treeview")); - gtk_tree_view_expand_all(treeview); +/****************************************************************************** +* * +* Paramètres : parent = fenêtre parente à surpasser. * +* * +* Description : Construit une boîte de dialogue pour les préférences. * +* * +* Retour : Adresse de la fenêtre mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ - /* Connexion des signaux */ +GtkWindow *gtk_preferences_dialog_new(GtkWindow *parent) +{ + GtkWindow *result; /* Boite de dialogue à renvoyer*/ - gtk_builder_add_callback_symbols(builder, - BUILDER_CALLBACK(on_prefs_selection_changed), - BUILDER_CALLBACK(on_prefs_apply_button_clicked), - NULL); + result = g_object_new(GTK_TYPE_PREFERENCES_DIALOG, NULL); - gtk_builder_connect_signals(builder, builder); + if (!gtk_preferences_dialog_create(GTK_PREFERENCES_DIALOG(result), parent)) + g_clear_object(&result); return result; @@ -251,79 +284,85 @@ GtkWidget *create_preferences_dialog(GtkWindow *parent, GtkBuilder **outb) /****************************************************************************** * * -* Paramètres : selection = sélection courante de l'arborescence des options.* -* builder = constructeur GTK avec toutes les références. * +* Paramètres : dialog = boîte de dialogue à initialiser pleinement. * +* parent = fenêtre parente à surpasser. * * * -* Description : Affiche le panneau correspondant au noeud sélectionné. * +* Description : Met en place la boîte de dialogue pour les préférences. * * * -* Retour : - * +* Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ -static void on_prefs_selection_changed(GtkTreeSelection *selection, GtkBuilder *builder) +bool gtk_preferences_dialog_create(GtkPreferencesDialog *dialog, GtkWindow *parent) { - GtkTreeModel *model; /* Gestionnaire de données */ - GtkTreeIter iter; /* Position courante */ - GtkWidget *panel; /* Panneau à mettre en avant */ - GtkStack *stack; /* Pile à mettre à jour */ - - if (gtk_tree_selection_get_selected(selection, &model, &iter)) - { - gtk_tree_model_get(model, &iter, PLI_PANEL, &panel, -1); + bool result; /* Bilan à retourner */ - stack = GTK_STACK(gtk_builder_get_object(builder, "stack")); + result = true; - if (panel == NULL) - gtk_stack_set_visible_child_name(stack, "empty"); - - else - { - gtk_stack_set_visible_child(stack, panel); + gtk_window_set_transient_for(GTK_WINDOW(dialog), parent); - g_object_unref(G_OBJECT(panel)); - - } - - } + return result; } /****************************************************************************** * * -* Paramètres : config = configuration globale à actualiser. * -* node = noeud de description courant à traiter. * +* Paramètres : dialog = boîte de dialogue à initialiser pleinement. * +* key = désignation de la liste à fournir. * +* create = autorisation d'une création si besoin est. * * * -* Description : Lance la sauvegarde d'éléments de paramétrage. * +* Description : Fournit la liste de section désignée par un nom. * * * -* Retour : - * +* Retour : Composant graphique à utiliser. * * * * Remarques : - * * * ******************************************************************************/ -static void store_preferences_node(GGenConfig *config, pref_node_desc_t *node) +static GtkListBox *gtk_preferences_dialog_get_navigation(GtkPreferencesDialog *dialog, const char *key, bool create) { - pref_node_desc_t *child; /* Sous-élément à traiter */ + GtkListBox *result; /* Instance à retourner */ +#ifndef NDEBUG + gboolean status; /* Bilan d'une insertion */ +#endif - if (node->create != NULL) - node->store(node->builder, config); + result = g_hash_table_lookup(dialog->navigations, key); - if (node->children != NULL) - for (child = node->children; child->title != NULL; child++) - store_preferences_node(config, child); + if (result == NULL && create) + { + result = GTK_LIST_BOX(gtk_list_box_new()); + g_object_ref_sink(G_OBJECT(result)); + + gtk_list_box_set_selection_mode(result, GTK_SELECTION_BROWSE); + gtk_widget_add_css_class(GTK_WIDGET(result), "navigation-sidebar"); + +#ifndef NDEBUG + status = g_hash_table_insert(dialog->navigations, strdup(key), result); + assert(status); +#else + g_hash_table_insert(dialog->navigations, key, result); +#endif + + } + + if (result != NULL) + ref_object(result); + + return result; } /****************************************************************************** * * -* Paramètres : button = bouton GTK à l'origine de l'opération. * -* builder = constructeur GTK avec toutes les références. * +* Paramètres : navigation = liste concernée par l'événement. * +* selected = élément sélectionné (voire NULL). * +* dialog = boîte de dialogue à initialiser pleinement. * * * -* Description : Sauvegarde l'ensemble des paramètres de configuration. * +* Description : Réagit à un changement de sélection dans les sections. * * * * Retour : - * * * @@ -331,14 +370,41 @@ static void store_preferences_node(GGenConfig *config, pref_node_desc_t *node) * * ******************************************************************************/ -static void on_prefs_apply_button_clicked(GtkButton *button, GtkBuilder *builder) +static void gtk_preferences_dialog_on_row_selected(GtkListBox *navigation, GtkListBoxRow *selected, GtkPreferencesDialog *dialog) { - GGenConfig *config; /* Configuration globale */ - pref_node_desc_t *iter; /* Boucle de parcours */ + GtkTweakSection *section; /* Nature réelle sélectionnée */ + GType type; /* Type de panneau de config. */ + GtkWidget *panel; /* Nouveau panneau à présenter */ + + if (selected != NULL) + { + if (!gtk_tweak_section_has_sub_section(GTK_TWEAK_SECTION(selected))) + { + section = GTK_TWEAK_SECTION(selected); + + gtk_label_set_text(dialog->main_title, gtk_tweak_section_get_label(section)); + + type = gtk_tweak_section_get_panel(section); + panel = g_object_new(type, NULL); - config = get_main_configuration(); + gtk_scrolled_window_set_child(dialog->main_content, panel); - for (iter = _prefs_nodes; iter->title != NULL; iter++) - store_preferences_node(config, iter); + } + + else + { + + // TODO + + } + + } } + + + +/* ---------------------------------------------------------------------------------- */ +/* IMPLEMENTATION DES FONCTIONS DE CLASSE */ +/* ---------------------------------------------------------------------------------- */ + diff --git a/src/gui/dialogs/preferences.h b/src/gui/dialogs/preferences.h index d04af72..e291ea8 100644 --- a/src/gui/dialogs/preferences.h +++ b/src/gui/dialogs/preferences.h @@ -1,8 +1,8 @@ /* Chrysalide - Outil d'analyse de fichiers binaires - * preferences.h - prototypes pour la (re)définition de l'identité de l'utilisateur + * preferences.h - prototypes pour la boîte de dialogue d'édition des préférences de l'utilisateur * - * Copyright (C) 2019 Cyrille Bagard + * Copyright (C) 2019-2025 Cyrille Bagard * * This file is part of Chrysalide. * @@ -28,9 +28,17 @@ #include <gtk/gtk.h> +#include "../../glibext/helpers.h" -/* Propose une boîte de dialogue pour la configuration générale. */ -GtkWidget *create_preferences_dialog(GtkWindow *, GtkBuilder **); + + +#define GTK_TYPE_PREFERENCES_DIALOG (gtk_preferences_dialog_get_type()) + +DECLARE_GTYPE(GtkPreferencesDialog, gtk_preferences_dialog, GTK, PREFERENCES_DIALOG); + + +/* Construit une boîte de dialogue pour les préférences. */ +GtkWindow *gtk_preferences_dialog_new(GtkWindow *); diff --git a/src/gui/dialogs/preferences.ui b/src/gui/dialogs/preferences.ui index 251ef46..950242a 100644 --- a/src/gui/dialogs/preferences.ui +++ b/src/gui/dialogs/preferences.ui @@ -1,156 +1,111 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- Generated with glade 3.21.0 --> <interface> - <requires lib="gtk+" version="3.20"/> - <object class="GtkTreeStore" id="pref_list"> - <columns> - <!-- column-name title --> - <column type="gchararray"/> - <!-- column-name panel --> - <column type="GObject"/> - </columns> - </object> - <object class="GtkDialog" id="window"> - <property name="can_focus">False</property> - <property name="title" translatable="yes">General preferences</property> - <property name="modal">True</property> - <property name="default_width">800</property> - <property name="default_height">500</property> - <property name="type_hint">dialog</property> - <child internal-child="vbox"> - <object class="GtkBox"> - <property name="can_focus">False</property> - <property name="orientation">vertical</property> - <property name="spacing">2</property> - <child internal-child="action_area"> - <object class="GtkButtonBox"> - <property name="can_focus">False</property> - <property name="margin_left">8</property> - <property name="margin_right">8</property> - <property name="margin_top">8</property> - <property name="margin_bottom">8</property> - <property name="layout_style">end</property> - <child> - <object class="GtkButton" id="button1"> - <property name="label">gtk-cancel</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="use_stock">True</property> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkButton" id="button2"> - <property name="label">gtk-apply</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="use_stock">True</property> - <signal name="clicked" handler="on_prefs_apply_button_clicked" swapped="no"/> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">1</property> - </packing> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> + + <template class="GtkPreferencesDialog" parent="GtkWindow"> + + <property name="default-width">980</property> + <property name="default-height">640</property> + <property name="modal">true</property> + <property name="resizable">true</property> + + <child type="titlebar"> + <object class="GtkBox"> + <child> + <object class="GtkHeaderBar" id="sidebar-header"> + <property name="decoration-layout">:</property> + + <property name="title-widget"> + <object class="GtkLabel" id="side_title"> + <property name="label" translatable="yes">Parameters</property> + <property name="single-line-mode">True</property> + <property name="ellipsize">end</property> + <property name="width-chars">5</property> + <style> + <class name="title"/> + </style> + </object> + </property> + + <child type="start"> + <object class="GtkToggleButton"> + <property name="icon-name">edit-find-symbolic</property> + <property name="valign">center</property> + </object> + </child> + </object> + </child> + + <!-- Séparation centrale --> + <child> + <object class="GtkSeparator"> + <property name="orientation">vertical</property> + <property name="css-name">sidebar</property> + </object> + </child> + + <child> + <object class="GtkHeaderBar" id="main-header"> + <property name="hexpand">1</property> + + <property name="title-widget"> + <object class="GtkLabel" id="main_title"> + <property name="label" translatable="yes"></property> + <property name="single-line-mode">True</property> + <property name="ellipsize">end</property> + <property name="width-chars">5</property> + <style> + <class name="title"/> + </style> + </object> + </property> + + </object> + </child> + </object> </child> + <child> - <object class="GtkPaned"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="position">200</property> - <property name="wide_handle">True</property> - <child> - <object class="GtkScrolledWindow"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="margin_left">8</property> - <property name="margin_right">8</property> - <property name="margin_top">8</property> - <property name="shadow_type">in</property> + <object class="GtkBox"> <child> - <object class="GtkTreeView" id="treeview"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="model">pref_list</property> - <property name="headers_visible">False</property> - <child internal-child="selection"> - <object class="GtkTreeSelection"> - <signal name="changed" handler="on_prefs_selection_changed" swapped="no"/> - </object> - </child> - <child> - <object class="GtkTreeViewColumn"> - <property name="title" translatable="yes">column</property> - <child> - <object class="GtkCellRendererText"/> - <attributes> - <attribute name="text">0</attribute> - </attributes> - </child> - </object> - </child> - </object> + <object class="GtkScrolledWindow" id="side_content"> + <property name="hexpand">false</property> + <property name="vexpand">true</property> + <property name="hscrollbar-policy">never</property> + <property name="vscrollbar-policy">automatic</property> + </object> + </child> + + <!-- Séparation centrale --> + <child> + <object class="GtkSeparator"> + <property name="orientation">vertical</property> + <property name="css-name">sidebar</property> + </object> </child> - </object> - <packing> - <property name="resize">False</property> - <property name="shrink">True</property> - </packing> - </child> - <child> - <object class="GtkStack" id="stack"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="margin_left">8</property> - <property name="margin_right">8</property> - <property name="margin_top">8</property> + <child> - <object class="GtkBox"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="orientation">vertical</property> - <child> - <placeholder/> - </child> - </object> - <packing> - <property name="name">empty</property> - </packing> + <object class="GtkScrolledWindow" id="main_content"> + <property name="hexpand">1</property> + <property name="vexpand">1</property> + <property name="hscrollbar-policy">never</property> + <property name="vscrollbar-policy">automatic</property> + </object> </child> - </object> - <packing> - <property name="resize">True</property> - <property name="shrink">True</property> - </packing> - </child> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">1</property> - </packing> + </object> </child> - </object> - </child> - <action-widgets> - <action-widget response="-6">button1</action-widget> - <action-widget response="-10">button2</action-widget> - </action-widgets> - <child> - <placeholder/> - </child> - </object> + + <object class="GtkSizeGroup"> + <widgets> + <widget name="sidebar-header"/> + <widget name="side_content"/> + </widgets> + </object> + <object class="GtkSizeGroup"> + <widgets> + <widget name="main-header"/> + <widget name="main_content"/> + </widgets> + </object> + + </template> </interface> diff --git a/src/gui/dialogs/prefs/Makefile.am b/src/gui/dialogs/prefs/Makefile.am new file mode 100644 index 0000000..50bc3c8 --- /dev/null +++ b/src/gui/dialogs/prefs/Makefile.am @@ -0,0 +1,34 @@ + +BUILT_SOURCES = resources.h resources.c + +noinst_LTLIBRARIES = libguidialogsprefs.la + +UI_FILES = \ + appearance.ui \ + security.ui + +libguidialogsprefs_la_SOURCES = \ + appearance-int.h \ + appearance.h appearance.c \ + resources.h resources.c \ + security-int.h \ + security.h security.c + +libguidialogsprefs_la_CFLAGS = $(LIBGTK4_CFLAGS) + + +devdir = $(includedir)/chrysalide/$(subdir:src/%=core/%) + +dev_HEADERS = $(libguidialogsprefs_la_SOURCES:%c=) + + +resources.c: gresource.xml $(UI_FILES) + glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-source --c-name gui_dialogs_prefs gresource.xml + +resources.h: gresource.xml + glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-header --c-name gui_dialogs_prefs gresource.xml + + +CLEANFILES = resources.h resources.c + +EXTRA_DIST = gresource.xml $(UI_FILES) diff --git a/src/gui/dialogs/prefs/appearance-int.h b/src/gui/dialogs/prefs/appearance-int.h new file mode 100644 index 0000000..886a562 --- /dev/null +++ b/src/gui/dialogs/prefs/appearance-int.h @@ -0,0 +1,64 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * appearance-int.h - définitions internes pour la configuration des paramètres liés aux apparences + * + * Copyright (C) 2025 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _GUI_DIALOGS_PREFS_APPEARANCE_INT_H +#define _GUI_DIALOGS_PREFS_APPEARANCE_INT_H + + +#include "appearance.h" + + + +/* Composant d'édition des paramètres liés aux apparences (instance) */ +struct _GtkAppearanceTweakPanel +{ + GtkBox parent; /* A laisser en premier */ + + /* Disposition des panneaux */ + + GSettings *tiles_settings; /* Configuration sollicitée */ + + GtkWidget *layout_preview; /* Zone d'aperçu de dispositon*/ + + GtkWidget *top_panel; /* Composant d'aperçu #1 */ + GtkWidget *left_panel; /* Composant d'aperçu #2 */ + GtkWidget *right_panel; /* Composant d'aperçu #3 */ + GtkWidget *bottom_panel; /* Composant d'aperçu #4 */ + + GtkCheckButton *left_top_reach; /* Paramètre de disposition #1 */ + GtkCheckButton *left_bottom_reach; /* Paramètre de disposition #2 */ + GtkCheckButton *right_top_reach; /* Paramètre de disposition #3 */ + GtkCheckButton *right_bottom_reach; /* Paramètre de disposition #4 */ + +}; + +/* Composant d'édition des paramètres liés aux apparences (classe) */ +struct _GtkAppearanceTweakPanelClass +{ + GtkBoxClass parent; /* A laisser en premier */ + +}; + + + +#endif /* _GUI_DIALOGS_PREFS_APPEARANCE_INT_H */ diff --git a/src/gui/dialogs/prefs/appearance.c b/src/gui/dialogs/prefs/appearance.c new file mode 100644 index 0000000..a8585fa --- /dev/null +++ b/src/gui/dialogs/prefs/appearance.c @@ -0,0 +1,251 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * appearance.c - configuration des paramètres liés aux apparences + * + * Copyright (C) 2025 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#include "appearance.h" + + +#include "appearance-int.h" +#include "../../../gtkext/grid.h" +#include "../../../gtkext/helpers.h" + + + +/* Procède à l'initialisation de classe des configurations. */ +static void gtk_appearance_tweak_panel_class_init(GtkAppearanceTweakPanelClass *); + +/* Procède à l'initialisation des configurations de sécurité. */ +static void gtk_appearance_tweak_panel_init(GtkAppearanceTweakPanel *); + +/* Supprime toutes les références externes. */ +static void gtk_appearance_tweak_panel_dispose(GObject *); + +/* Procède à la libération totale de la mémoire. */ +static void gtk_appearance_tweak_panel_finalize(GObject *); + +/* Réagit à un changement de paramètre de configuration. */ +static void gtk_appearance_tweak_panel_on_tiles_settings_changed(GSettings *, const gchar *, GtkAppearanceTweakPanel *); + +/* Change la disposition des panneaux de la fenêtre principale. */ +static void gtk_appearance_tweak_panel_on_panel_reach_toggled(GtkCheckButton *, GtkAppearanceTweakPanel *); + + +/* Indique le type du composant de configuration des notes. */ +G_DEFINE_TYPE(GtkAppearanceTweakPanel, gtk_appearance_tweak_panel, GTK_TYPE_BOX); + + +/****************************************************************************** +* * +* Paramètres : class = classe GTK à initialiser. * +* * +* Description : Procède à l'initialisation de classe des configurations. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_appearance_tweak_panel_class_init(GtkAppearanceTweakPanelClass *class) +{ + GObjectClass *object; /* Plus haut niveau équivalent */ + GtkWidgetClass *widget; /* Classe de haut niveau */ + + object = G_OBJECT_CLASS(class); + + object->dispose = gtk_appearance_tweak_panel_dispose; + object->finalize = gtk_appearance_tweak_panel_finalize; + + widget = GTK_WIDGET_CLASS(class); + + gtk_widget_class_set_template_from_resource(widget, "/re/chrysalide/framework/gui/dialogs/prefs/appearance.ui"); + + gtk_widget_class_bind_template_callback_full(widget, BUILDER_CB(gtk_appearance_tweak_panel_on_panel_reach_toggled)); + + gtk_widget_class_bind_template_child(widget, GtkAppearanceTweakPanel, layout_preview); + + gtk_widget_class_bind_template_child(widget, GtkAppearanceTweakPanel, top_panel); + gtk_widget_class_bind_template_child(widget, GtkAppearanceTweakPanel, left_panel); + gtk_widget_class_bind_template_child(widget, GtkAppearanceTweakPanel, right_panel); + gtk_widget_class_bind_template_child(widget, GtkAppearanceTweakPanel, bottom_panel); + + gtk_widget_class_bind_template_child(widget, GtkAppearanceTweakPanel, left_top_reach); + gtk_widget_class_bind_template_child(widget, GtkAppearanceTweakPanel, left_bottom_reach); + gtk_widget_class_bind_template_child(widget, GtkAppearanceTweakPanel, right_top_reach); + gtk_widget_class_bind_template_child(widget, GtkAppearanceTweakPanel, right_bottom_reach); + +} + + +/****************************************************************************** +* * +* Paramètres : panel = composant GTK à initialiser. * +* * +* Description : Procède à l'initialisation des configurations de sécurité. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_appearance_tweak_panel_init(GtkAppearanceTweakPanel *panel) +{ + LayoutReachOptions options; /* Détails de disposition */ + + gtk_widget_init_template(GTK_WIDGET(panel)); + + panel->tiles_settings = g_settings_new_with_path("re.chrysalide.framework.tiledgrid", + "/re/chrysalide/framework/gui/tiles/"); + + options = g_settings_get_flags(panel->tiles_settings, "layout"); + + gtk_check_button_set_active(panel->left_top_reach, options & LRO_LEFT_TOP_REACH); + gtk_check_button_set_active(panel->left_bottom_reach, options & LRO_LEFT_BOTTOM_REACH); + gtk_check_button_set_active(panel->right_top_reach, options & LRO_RIGHT_TOP_REACH); + gtk_check_button_set_active(panel->right_bottom_reach, options & LRO_RIGHT_BOTTOM_REACH); + + gtk_appearance_tweak_panel_on_tiles_settings_changed(panel->tiles_settings, "layout", panel); + + g_signal_connect(panel->tiles_settings, "changed", + G_CALLBACK(gtk_appearance_tweak_panel_on_tiles_settings_changed), panel); + +} + + +/****************************************************************************** +* * +* Paramètres : object = instance d'objet GLib à traiter. * +* * +* Description : Supprime toutes les références externes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_appearance_tweak_panel_dispose(GObject *object) +{ + GtkAppearanceTweakPanel *panel; /* Version spécialisée */ + + gtk_widget_dispose_template(GTK_WIDGET(object), GTK_TYPE_APPEARANCE_TWEAK_PANEL); + + panel = GTK_APPEARANCE_TWEAK_PANEL(object); + + g_clear_object(&panel->tiles_settings); + + G_OBJECT_CLASS(gtk_appearance_tweak_panel_parent_class)->dispose(object); + +} + + +/****************************************************************************** +* * +* Paramètres : object = instance d'objet GLib à traiter. * +* * +* Description : Procède à la libération totale de la mémoire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_appearance_tweak_panel_finalize(GObject *object) +{ + G_OBJECT_CLASS(gtk_appearance_tweak_panel_parent_class)->finalize(object); + +} + + +/****************************************************************************** +* * +* Paramètres : settings = ensemble de paramètres connaissant une évolution. * +* key = identifiant du paramètre ayant changé. * +* panel = panneau de paramétrage concerné par l'appel. * +* * +* Description : Réagit à un changement de paramètre de configuration. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_appearance_tweak_panel_on_tiles_settings_changed(GSettings *settings, const gchar *key, GtkAppearanceTweakPanel *panel) +{ + LayoutReachOptions options; /* Détails de disposition */ + + if (strcmp(key, "layout") == 0) + { + options = g_settings_get_flags(panel->tiles_settings, "layout"); + + apply_tiling_grid_layout(GTK_GRID(panel->layout_preview), options, (GtkWidget *[]) { + panel->top_panel, panel->left_panel, panel->right_panel, panel->bottom_panel + }); + + } + +} + + +/****************************************************************************** +* * +* Paramètres : button = composant radio dont l'état vient de basculer. * +* panel = panneau d'édition des préférences courant. * +* * +* Description : Change la disposition des panneaux de la fenêtre principale. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_appearance_tweak_panel_on_panel_reach_toggled(GtkCheckButton *button, GtkAppearanceTweakPanel *panel) +{ + gboolean left_top_reach; /* Paramètre de disposition #1 */ + gboolean left_bottom_reach; /* Paramètre de disposition #2 */ + gboolean right_top_reach; /* Paramètre de disposition #3 */ + gboolean right_bottom_reach; /* Paramètre de disposition #4 */ + LayoutReachOptions options; /* Options à appliquer */ + + /* Récupération des indications */ + + left_top_reach = gtk_check_button_get_active(panel->left_top_reach); + left_bottom_reach = gtk_check_button_get_active(panel->left_bottom_reach); + right_top_reach = gtk_check_button_get_active(panel->right_top_reach); + right_bottom_reach = gtk_check_button_get_active(panel->right_bottom_reach); + + /* Conversion et application */ + + options = LRO_NONE; + + if (left_top_reach) options |= LRO_LEFT_TOP_REACH; + if (left_bottom_reach) options |= LRO_LEFT_BOTTOM_REACH; + if (right_top_reach) options |= LRO_RIGHT_TOP_REACH; + if (right_bottom_reach) options |= LRO_RIGHT_BOTTOM_REACH; + + g_settings_set_flags(panel->tiles_settings, "layout", options); + +} diff --git a/src/gui/dialogs/prefs/appearance.h b/src/gui/dialogs/prefs/appearance.h new file mode 100644 index 0000000..916b194 --- /dev/null +++ b/src/gui/dialogs/prefs/appearance.h @@ -0,0 +1,41 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * appearance.h - prototypes pour la configuration des paramètres liés aux apparences + * + * Copyright (C) 2025 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _GUI_DIALOGS_PREFS_APPEARANCE_H +#define _GUI_DIALOGS_PREFS_APPEARANCE_H + + +#include <gtk/gtk.h> + + +#include "../../../glibext/helpers.h" + + + +#define GTK_TYPE_APPEARANCE_TWEAK_PANEL (gtk_appearance_tweak_panel_get_type()) + +DECLARE_GTYPE(GtkAppearanceTweakPanel, gtk_appearance_tweak_panel, GTK, APPEARANCE_TWEAK_PANEL); + + + +#endif /* _GUI_DIALOGS_PREFS_APPEARANCE_H */ diff --git a/src/gui/dialogs/prefs/appearance.ui b/src/gui/dialogs/prefs/appearance.ui new file mode 100644 index 0000000..3410115 --- /dev/null +++ b/src/gui/dialogs/prefs/appearance.ui @@ -0,0 +1,184 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + + <template class="GtkAppearanceTweakPanel" parent="GtkBox"> + + <property name="orientation">vertical</property> + <property name="margin-start">20</property> + <property name="margin-end">20</property> + <property name="margin-top">20</property> + <property name="margin-bottom">20</property> + <property name="spacing">10</property> + + <!-- Disposition des panneaux --> + + <child> + <object class="GtkLabel"> + <property name="label">Layout</property> + <property name="use-markup">true</property> + <property name="xalign">0</property> + <style> + <class name="heading"/> + </style> + </object> + </child> + + <child> + <object class="GtkLabel"> + <property name="label">Layout defines the global panel organization of the main window.</property> + <property name="wrap">true</property> + <property name="use-markup">true</property> + <property name="xalign">0</property> + <style> + <class name="dim-label"/> + </style> + </object> + </child> + + + <child> + <object class="GtkBox"> + <property name="orientation">horizontal</property> + + <!-- Aperçu --> + + <child> + <object class="GtkGrid" id="layout_preview"> + <property name="margin-start">20</property> + <property name="margin-end">20</property> + <property name="margin-top">10</property> + <property name="margin-bottom">10</property> + <property name="row-spacing">5</property> + <property name="column-spacing">5</property> + <property name="hexpand">false</property> + <property name="vexpand">false</property> + <property name="height-request">200</property> + <property name="width-request">300</property> + + <child> + <object class="GtkFrame" id="top_panel"> + <property name="hexpand">true</property> + <property name="vexpand">false</property> + <property name="height-request">20</property> + <layout> + <property name="column">0</property> + <property name="row">0</property> + <property name="column-span">3</property> + </layout> + <style> + <class name="view"/> + </style> + </object> + </child> + + <child> + <object class="GtkFrame" id="left_panel"> + <property name="hexpand">false</property> + <property name="vexpand">true</property> + <property name="width-request">50</property> + <layout> + <property name="column">0</property> + <property name="row">1</property> + </layout> + <style> + <class name="view"/> + </style> + </object> + </child> + + <child> + <object class="GtkFrame"> + <property name="hexpand">true</property> + <property name="vexpand">true</property> + <layout> + <property name="column">1</property> + <property name="row">1</property> + </layout> + <style> + <class name="view"/> + </style> + </object> + </child> + + <child> + <object class="GtkFrame" id="right_panel"> + <property name="hexpand">false</property> + <property name="vexpand">true</property> + <property name="width-request">50</property> + <layout> + <property name="column">2</property> + <property name="row">1</property> + </layout> + <style> + <class name="view"/> + </style> + </object> + </child> + + <child> + <object class="GtkFrame" id="bottom_panel"> + <property name="hexpand">true</property> + <property name="vexpand">false</property> + <property name="height-request">50</property> + <layout> + <property name="column">0</property> + <property name="row">2</property> + <property name="column-span">3</property> + </layout> + <style> + <class name="view"/> + </style> + </object> + </child> + + </object> + </child> + + <!-- Options --> + + <child> + <object class="GtkBox"> + <property name="orientation">vertical</property> + <property name="valign">center</property> + <property name="spacing">10</property> + + <child> + <object class="GtkCheckButton" id="left_top_reach"> + <property name="label">Left panels reach the top of the window</property> + <property name="active">false</property> + <signal name="toggled" handler="gtk_appearance_tweak_panel_on_panel_reach_toggled"/> + </object> + </child> + + <child> + <object class="GtkCheckButton" id="left_bottom_reach"> + <property name="label">Left panels reach the bottom of the window</property> + <property name="active">false</property> + <signal name="toggled" handler="gtk_appearance_tweak_panel_on_panel_reach_toggled"/> + </object> + </child> + + <child> + <object class="GtkCheckButton" id="right_top_reach"> + <property name="label">Right panels reach the top of the window</property> + <property name="active">false</property> + <signal name="toggled" handler="gtk_appearance_tweak_panel_on_panel_reach_toggled"/> + </object> + </child> + + <child> + <object class="GtkCheckButton" id="right_bottom_reach"> + <property name="label">Right panels reach the bottom of the window</property> + <property name="active">false</property> + <signal name="toggled" handler="gtk_appearance_tweak_panel_on_panel_reach_toggled"/> + </object> + </child> + + </object> + </child> + + </object> + </child> + + </template> +</interface> diff --git a/src/gui/dialogs/prefs/gresource.xml b/src/gui/dialogs/prefs/gresource.xml new file mode 100644 index 0000000..ad0f97f --- /dev/null +++ b/src/gui/dialogs/prefs/gresource.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<gresources> + <gresource prefix="/re/chrysalide/framework/gui/dialogs/prefs"> + <file compressed="true">appearance.ui</file> + <file compressed="true">security.ui</file> + </gresource> +</gresources> diff --git a/src/gui/dialogs/prefs/security-int.h b/src/gui/dialogs/prefs/security-int.h new file mode 100644 index 0000000..be7867c --- /dev/null +++ b/src/gui/dialogs/prefs/security-int.h @@ -0,0 +1,64 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * security-int.h - définitions internes pour la configuration des paramètres liés à la sécurité + * + * Copyright (C) 2025 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _GUI_DIALOGS_PREFS_SECURITY_INT_H +#define _GUI_DIALOGS_PREFS_SECURITY_INT_H + + +#include "security.h" +#include "../../../glibext/secstorage.h" + + + +/* Composant d'édition des paramètres de sécurité (instance) */ +struct _GtkSecurityTweakPanel +{ + GtkBox parent; /* A laisser en premier */ + + /* Stockage sécurisé */ + + GSecretStorage *storage; /* Stockage des secrets */ + + GtkWidget *current_primary_passwd; /* Mot de passe courant */ + + GtkWidget *new_primary_passwd; /* Nouveau mot de passe */ + GtkWidget *new_primary_passwd_lbl; /* Etiquette associée */ + GtkWidget *new_primary_passwd_2; /* Nouveau mot de passe (#2) */ + GtkWidget *new_primary_passwd_2_lbl; /* Etiquette associée (#2) */ + + GtkWidget *set_password; /* Bouton de définition de mdp */ + GtkWidget *change_password; /* Bouton de changement de mdp */ + GtkWidget *remove_password; /* Bouton de suppression de mdp*/ + +}; + +/* Composant d'édition des paramètres de sécurité (classe) */ +struct _GtkSecurityTweakPanelClass +{ + GtkBoxClass parent; /* A laisser en premier */ + +}; + + + +#endif /* _GUI_DIALOGS_PREFS_SECURITY_INT_H */ diff --git a/src/gui/dialogs/prefs/security.c b/src/gui/dialogs/prefs/security.c new file mode 100644 index 0000000..2b82339 --- /dev/null +++ b/src/gui/dialogs/prefs/security.c @@ -0,0 +1,400 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * security.c - configuration des paramètres liés à la sécurité + * + * Copyright (C) 2025 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#include "security.h" + + +#include <i18n.h> + + +#include "security-int.h" +#include "../../../core/global.h" +#include "../../../core/logs.h" +#include "../../../gtkext/helpers.h" + + + +/* ---------------------- GESTION DE L'ENSEMBLE DES PARAMETRES ---------------------- */ + + +/* Procède à l'initialisation de classe des configurations. */ +static void gtk_security_tweak_panel_class_init(GtkSecurityTweakPanelClass *); + +/* Procède à l'initialisation des configurations de sécurité. */ +static void gtk_security_tweak_panel_init(GtkSecurityTweakPanel *); + +/* Supprime toutes les références externes. */ +static void gtk_security_tweak_panel_dispose(GObject *); + +/* Procède à la libération totale de la mémoire. */ +static void gtk_security_tweak_panel_finalize(GObject *); + + + +/* ---------------------- CONSERVATION SECURISEE DE PARAMETRES ---------------------- */ + + +/* Initalise la partie relative au stockage sécurisé. */ +static void gtk_security_tweak_panel_init_secret_storage(GtkSecurityTweakPanel *); + +/* Supprime toutes les références externes. */ +static void gtk_security_tweak_panel_dispose_secret_storage(GtkSecurityTweakPanel *); + +/* Note le changement de verrouillage du stockage sécurisé. */ +static void gtk_security_tweak_panel_on_secret_storage_lock_update(GSecretStorage *, GtkSecurityTweakPanel *); + +/* Réagit à un changement dans l'édition d'un mot de passe. */ +static void gtk_security_tweak_panel_on_new_passwords_changed(GtkEditable *, GtkSecurityTweakPanel *); + +/* Réagit à une demande de création de mot de passe. */ +static void gtk_security_tweak_panel_on_set_password_clicked(GtkButton *, GtkSecurityTweakPanel *); + +/* Réagit à une demande de changement de mot de passe. */ +static void gtk_security_tweak_panel_on_change_password_clicked(GtkButton *, GtkSecurityTweakPanel *); + +/* Réagit à une demande de suppression de mot de passe. */ +static void gtk_security_tweak_panel_on_remove_password_clicked(GtkButton *, GtkSecurityTweakPanel *); + + + +/* ---------------------------------------------------------------------------------- */ +/* GESTION DE L'ENSEMBLE DES PARAMETRES */ +/* ---------------------------------------------------------------------------------- */ + + +/* Indique le type du composant d'édition des paramètres de sécurité. */ +G_DEFINE_TYPE(GtkSecurityTweakPanel, gtk_security_tweak_panel, GTK_TYPE_BOX); + + +/****************************************************************************** +* * +* Paramètres : class = classe GTK à initialiser. * +* * +* Description : Procède à l'initialisation de classe des configurations. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_security_tweak_panel_class_init(GtkSecurityTweakPanelClass *class) +{ + GObjectClass *object; /* Plus haut niveau équivalent */ + GtkWidgetClass *widget; /* Classe de haut niveau */ + + object = G_OBJECT_CLASS(class); + + object->dispose = gtk_security_tweak_panel_dispose; + object->finalize = gtk_security_tweak_panel_finalize; + + widget = GTK_WIDGET_CLASS(class); + + gtk_widget_class_set_template_from_resource(widget, "/re/chrysalide/framework/gui/dialogs/prefs/security.ui"); + + /* Stockage sécurisé */ + + gtk_widget_class_bind_template_callback_full(widget, BUILDER_CB(gtk_security_tweak_panel_on_new_passwords_changed)); + gtk_widget_class_bind_template_callback_full(widget, BUILDER_CB(gtk_security_tweak_panel_on_set_password_clicked)); + gtk_widget_class_bind_template_callback_full(widget, BUILDER_CB(gtk_security_tweak_panel_on_change_password_clicked)); + gtk_widget_class_bind_template_callback_full(widget, BUILDER_CB(gtk_security_tweak_panel_on_remove_password_clicked)); + + gtk_widget_class_bind_template_child(widget, GtkSecurityTweakPanel, current_primary_passwd); + gtk_widget_class_bind_template_child(widget, GtkSecurityTweakPanel, new_primary_passwd); + gtk_widget_class_bind_template_child(widget, GtkSecurityTweakPanel, new_primary_passwd_lbl); + gtk_widget_class_bind_template_child(widget, GtkSecurityTweakPanel, new_primary_passwd_2); + gtk_widget_class_bind_template_child(widget, GtkSecurityTweakPanel, new_primary_passwd_2_lbl); + gtk_widget_class_bind_template_child(widget, GtkSecurityTweakPanel, set_password); + gtk_widget_class_bind_template_child(widget, GtkSecurityTweakPanel, change_password); + gtk_widget_class_bind_template_child(widget, GtkSecurityTweakPanel, remove_password); + +} + + +/****************************************************************************** +* * +* Paramètres : panel = composant GTK à initialiser. * +* * +* Description : Procède à l'initialisation des configurations de sécurité. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_security_tweak_panel_init(GtkSecurityTweakPanel *panel) +{ + gtk_widget_init_template(GTK_WIDGET(panel)); + + gtk_security_tweak_panel_init_secret_storage(panel); + +} + + +/****************************************************************************** +* * +* Paramètres : object = instance d'objet GLib à traiter. * +* * +* Description : Supprime toutes les références externes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_security_tweak_panel_dispose(GObject *object) +{ + GtkSecurityTweakPanel *panel; /* Version spécialisée */ + + panel = GTK_SECURITY_TWEAK_PANEL(object); + + gtk_security_tweak_panel_dispose_secret_storage(panel); + + gtk_widget_dispose_template(GTK_WIDGET(panel), GTK_TYPE_SECURITY_TWEAK_PANEL); + + G_OBJECT_CLASS(gtk_security_tweak_panel_parent_class)->dispose(object); + +} + + +/****************************************************************************** +* * +* Paramètres : object = instance d'objet GLib à traiter. * +* * +* Description : Procède à la libération totale de la mémoire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_security_tweak_panel_finalize(GObject *object) +{ + G_OBJECT_CLASS(gtk_security_tweak_panel_parent_class)->finalize(object); + +} + + + +/* ---------------------------------------------------------------------------------- */ +/* CONSERVATION SECURISEE DE PARAMETRES */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : panel = composant GTK à initialiser. * +* * +* Description : Initalise la partie relative au stockage sécurisé. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_security_tweak_panel_init_secret_storage(GtkSecurityTweakPanel *panel) +{ + panel->storage = get_secret_storage(); + + g_signal_connect(panel->storage, "lock-update", + G_CALLBACK(gtk_security_tweak_panel_on_secret_storage_lock_update), panel); + + gtk_security_tweak_panel_on_secret_storage_lock_update(panel->storage, panel); + +} + + +/****************************************************************************** +* * +* Paramètres : panel = instance d'objet GLib à traiter. * +* * +* Description : Supprime toutes les références externes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_security_tweak_panel_dispose_secret_storage(GtkSecurityTweakPanel *panel) +{ + if (panel->storage != NULL) + g_signal_handlers_disconnect_by_func(panel->storage, + gtk_security_tweak_panel_on_secret_storage_lock_update, panel); + + g_clear_object(&panel->storage); + +} + + +/****************************************************************************** +* * +* Paramètres : storage = gardien des secrets impliqué. * +* panel = support de la partie relative au stockage sécurisé.* +* * +* Description : Note le changement de verrouillage du stockage sécurisé. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_security_tweak_panel_on_secret_storage_lock_update(GSecretStorage *storage, GtkSecurityTweakPanel *panel) +{ + bool has_key; /* Existence d'une clef ? */ + + has_key = g_secret_storage_has_key(panel->storage); + + gtk_widget_set_visible(panel->new_primary_passwd, has_key); + gtk_widget_set_visible(panel->new_primary_passwd_lbl, has_key); + + gtk_widget_set_visible(panel->new_primary_passwd_2, has_key); + gtk_widget_set_visible(panel->new_primary_passwd_2_lbl, has_key); + + gtk_widget_set_visible(panel->set_password, !has_key); + gtk_widget_set_visible(panel->change_password, has_key); + gtk_widget_set_visible(panel->remove_password, has_key); + +} + + +/****************************************************************************** +* * +* Paramètres : editable = zone de saisie bouton GTK concerné par l'appel. * +* panel = support de la partie liée au stockage sécurisé. * +* * +* Description : Réagit à un changement dans l'édition d'un mot de passe. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_security_tweak_panel_on_new_passwords_changed(GtkEditable *editable, GtkSecurityTweakPanel *panel) +{ + const char *new_passwd; /* Nouveau mot de passe #1 */ + const char *new_passwd_2; /* Nouveau mot de passe #2 */ + bool status; /* Bilan de l'opération */ + + new_passwd = gtk_editable_get_text(GTK_EDITABLE(panel->new_primary_passwd)); + + new_passwd_2 = gtk_editable_get_text(GTK_EDITABLE(panel->new_primary_passwd_2)); + + status = (strcmp(new_passwd, new_passwd_2) == 0); + + gtk_widget_set_sensitive(panel->change_password, status); + +} + + +/****************************************************************************** +* * +* Paramètres : button = bouton GTK concerné par l'appel. * +* panel = support de la partie relative au stockage sécurisé. * +* * +* Description : Réagit à une demande de création de mot de passe. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_security_tweak_panel_on_set_password_clicked(GtkButton *button, GtkSecurityTweakPanel *panel) +{ + const char *passwd; /* Mot de passe à considérer */ + bool status; /* Bilan de l'opération */ + + passwd = gtk_editable_get_text(GTK_EDITABLE(panel->current_primary_passwd)); + + status = g_secret_storage_set_password(panel->storage, passwd); + + log_variadic_message(LMT_INFO, _("Setting password for secret storage: %s"), + status ? _("success") : _("failed")); + +} + + +/****************************************************************************** +* * +* Paramètres : button = bouton GTK concerné par l'appel. * +* panel = support de la partie relative au stockage sécurisé. * +* * +* Description : Réagit à une demande de changement de mot de passe. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_security_tweak_panel_on_change_password_clicked(GtkButton *button, GtkSecurityTweakPanel *panel) +{ + const char *old_passwd; /* Ancien mot de passe */ + const char *new_passwd; /* Nouveau mot de passe */ + bool status; /* Bilan de l'opération */ + + old_passwd = gtk_editable_get_text(GTK_EDITABLE(panel->current_primary_passwd)); + + new_passwd = gtk_editable_get_text(GTK_EDITABLE(panel->new_primary_passwd)); + + status = g_secret_storage_change_password(panel->storage, old_passwd, new_passwd); + + log_variadic_message(LMT_INFO, _("Changed password for secret storage: %s"), + status ? _("success") : _("failed")); + +} + + +/****************************************************************************** +* * +* Paramètres : button = bouton GTK concerné par l'appel. * +* panel = support de la partie relative au stockage sécurisé. * +* * +* Description : Réagit à une demande de suppression de mot de passe. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_security_tweak_panel_on_remove_password_clicked(GtkButton *button, GtkSecurityTweakPanel *panel) +{ + const char *passwd; /* Mot de passe à considérer */ + bool status; /* Bilan de l'opération */ + + passwd = gtk_editable_get_text(GTK_EDITABLE(panel->current_primary_passwd)); + + status = g_secret_storage_remove_password(panel->storage, passwd); + + log_variadic_message(LMT_INFO, _("Removed password for secret storage: %s"), + status ? _("success") : _("failed")); + +} diff --git a/src/gui/dialogs/prefs/security.h b/src/gui/dialogs/prefs/security.h new file mode 100644 index 0000000..206a123 --- /dev/null +++ b/src/gui/dialogs/prefs/security.h @@ -0,0 +1,41 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * security.h - prototypes pour la configuration des paramètres liés à la sécurité + * + * Copyright (C) 2025 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _GUI_DIALOGS_PREFS_SECURITY_H +#define _GUI_DIALOGS_PREFS_SECURITY_H + + +#include <gtk/gtk.h> + + +#include "../../../glibext/helpers.h" + + + +#define GTK_TYPE_SECURITY_TWEAK_PANEL (gtk_security_tweak_panel_get_type()) + +DECLARE_GTYPE(GtkSecurityTweakPanel, gtk_security_tweak_panel, GTK, SECURITY_TWEAK_PANEL); + + + +#endif /* _GUI_DIALOGS_PREFS_SECURITY_H */ diff --git a/src/gui/dialogs/prefs/security.ui b/src/gui/dialogs/prefs/security.ui new file mode 100644 index 0000000..ccf2d39 --- /dev/null +++ b/src/gui/dialogs/prefs/security.ui @@ -0,0 +1,170 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + + <template class="GtkSecurityTweakPanel" parent="GtkBox"> + + <property name="orientation">vertical</property> + + <!-- Conservation de paramètres sécurisée --> + <child> + <object class="GtkGrid"> + <property name="margin-start">20</property> + <property name="margin-end">20</property> + <property name="margin-top">20</property> + <property name="margin-bottom">20</property> + <property name="row-spacing">10</property> + <property name="column-spacing">10</property> + + <child> + <object class="GtkLabel"> + <property name="label">Secret storage</property> + <property name="use-markup">true</property> + <property name="xalign">0</property> + <layout> + <property name="column">0</property> + <property name="row">0</property> + <property name="column-span">2</property> + </layout> + <style> + <class name="heading"/> + </style> + </object> + </child> + + <child> + <object class="GtkLabel"> + <property name="label">Configuration may handle sensitive data (such as passwords or API keys) which can be saved in plain text or stored encrypted using a Primary Password. + +If encryption is activated, entering the Primary Password will be asked on need once per session.</property> + <property name="wrap">true</property> + <property name="xalign">0</property> + <layout> + <property name="column">0</property> + <property name="row">1</property> + <property name="column-span">2</property> + </layout> + <style> + <class name="dim-label"/> + </style> + </object> + </child> + + <!-- Mot de passe courant --> + + <child> + <object class="GtkLabel"> + <property name="label">Enter current password:</property> + <property name="xalign">0</property> + <layout> + <property name="column">0</property> + <property name="row">2</property> + </layout> + </object> + </child> + + <child> + <object class="GtkPasswordEntry" id="current_primary_passwd"> + <property name="hexpand">true</property> + <property name="show-peek-icon">true</property> + <layout> + <property name="column">1</property> + <property name="row">2</property> + </layout> + </object> + </child> + + <!-- Nouveau mot de passe --> + + <child> + <object class="GtkLabel" id="new_primary_passwd_lbl"> + <property name="label">Enter new password:</property> + <property name="xalign">0</property> + <layout> + <property name="column">0</property> + <property name="row">3</property> + </layout> + </object> + </child> + + <child> + <object class="GtkPasswordEntry" id="new_primary_passwd"> + <property name="hexpand">true</property> + <property name="show-peek-icon">true</property> + <signal name="changed" handler="gtk_security_tweak_panel_on_new_passwords_changed"/> + <layout> + <property name="column">1</property> + <property name="row">3</property> + </layout> + </object> + </child> + + <!-- Confirmation de mot de passe --> + + <child> + <object class="GtkLabel" id="new_primary_passwd_2_lbl"> + <property name="label">Re-enter new password:</property> + <property name="xalign">0</property> + <layout> + <property name="column">0</property> + <property name="row">4</property> + </layout> + </object> + </child> + + <child> + <object class="GtkPasswordEntry" id="new_primary_passwd_2"> + <property name="hexpand">true</property> + <property name="show-peek-icon">true</property> + <signal name="changed" handler="gtk_security_tweak_panel_on_new_passwords_changed"/> + <layout> + <property name="column">1</property> + <property name="row">4</property> + </layout> + </object> + </child> + + <!-- Boutons de contrôle --> + + <child> + <object class="GtkBox"> + <property name="halign">center</property> + <property name="homogeneous">true</property> + <property name="spacing">8</property> + <layout> + <property name="column">0</property> + <property name="row">5</property> + <property name="column-span">2</property> + </layout> + + <child> + <object class="GtkButton" id="set_password"> + <property name="label">Set</property> + <signal name="clicked" handler="gtk_security_tweak_panel_on_set_password_clicked"/> + </object> + </child> + + <child> + <object class="GtkButton" id="change_password"> + <property name="label">Change</property> + <signal name="clicked" handler="gtk_security_tweak_panel_on_change_password_clicked"/> + </object> + </child> + + <child> + <object class="GtkButton" id="remove_password"> + <property name="label">Remove</property> + <signal name="clicked" handler="gtk_security_tweak_panel_on_remove_password_clicked"/> + <style> + <class name="destructive-action"/> + </style> + </object> + </child> + + </object> + </child> + + </object> + </child> + + </template> +</interface> diff --git a/src/gui/gresource.xml b/src/gui/gresource.xml index 011281d..91d9bc9 100644 --- a/src/gui/gresource.xml +++ b/src/gui/gresource.xml @@ -1,6 +1,10 @@ <?xml version="1.0" encoding="UTF-8"?> <gresources> - <gresource prefix="/org/chrysalide/gui"> - <file compressed="true">editor.ui</file> + <gresource prefix="/re/chrysalide/framework/gui"> + <file compressed="true">style.css</file> + <file compressed="true">window.ui</file> + </gresource> + <gresource prefix="/re/chrysalide/framework/images"> + <file compressed="true" alias="chrysalide-logo.svg">../../pixmaps/chrysalide-logo.svg</file> </gresource> </gresources> diff --git a/src/gui/panel-int.h b/src/gui/panel-int.h deleted file mode 100644 index d54dc16..0000000 --- a/src/gui/panel-int.h +++ /dev/null @@ -1,138 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * panel-int.h - prototypes pour les définitions internes liées aux panneaux d'affichage - * - * Copyright (C) 2019 Cyrille Bagard - * - * This file is part of Chrysalide. - * - * Chrysalide is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Chrysalide is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#ifndef _GUI_PANELS_PANEL_INT_H -#define _GUI_PANELS_PANEL_INT_H - - -#include "panel.h" - - -#include <gtk/gtk.h> - - -#include "item-int.h" -#include "../glibext/delayed.h" - - - -/* ------------------------- COEUR DES PANNEAUX D'AFFICHAGE ------------------------- */ - - -/* Fournit une indication sur la personnalité du panneau. */ -typedef PanelItemPersonality (* get_panel_personality_fc) (const GPanelItemClass *); - -/* Fournit une indication d'accroche du panneau au démarrage. */ -typedef bool (* dock_panel_at_startup_fc) (const GPanelItemClass *); - -/* Détermine si un panneau peut être filtré. */ -typedef bool (* can_search_panel_fc) (const GPanelItemClass *); - -/* Indique le chemin initial de la localisation d'un panneau. */ -typedef char * (* get_panel_path_fc) (const GPanelItemClass *); - -/* Indique la définition d'un éventuel raccourci clavier. */ -typedef char * (* get_panel_bindings_fc) (const GPanelItemClass *); - -/* Place un panneau dans l'ensemble affiché. */ -typedef void (* ack_dock_process_fc) (GPanelItem *); - -/* Supprime un panneau de l'ensemble affiché. */ -typedef void (* ack_undock_process_fc) (GPanelItem *); - -/* Démarre l'actualisation du filtrage du contenu. */ -typedef void (* update_filtered_fc) (GPanelItem *); - - -/* Elément réactif pour panneaux de l'éditeur (instance) */ -struct _GPanelItem -{ - GEditorItem parent; /* A laisser en premier */ - - bool docked; /* Panneau inscrusté ? */ - - GNamedWidget *widget; /* Composant avec noms */ - GtkWidget *cached_widget; /* Composant GTK récupéré */ - - char *filter; /* Eventuel filtre textuel */ - - cairo_surface_t *surface; /* Copie d'écran préalable */ - gdouble hadj_value; /* Sauvegarde de défilement #1 */ - gdouble vadj_value; /* Sauvegarde de défilement #2 */ - gint switched; /* Mémorise l'état de bascule */ - -}; - -/* Elément réactif pour panneaux de l'éditeur (classe) */ -struct _GPanelItemClass -{ - GEditorItemClass parent; /* A laisser en premier */ - - get_panel_personality_fc get_personality; /* Fourniture de nature */ - dock_panel_at_startup_fc dock_at_startup; /* Recommandation d'accroche */ - can_search_panel_fc can_search; /* Contenu fouillable ? */ - get_panel_path_fc get_path; /* Chemin vers la place idéale */ - get_panel_bindings_fc get_bindings; /* Raccourci clavier éventuel */ - - ack_dock_process_fc ack_dock; /* Prise en compte d'accroche */ - ack_undock_process_fc ack_undock; /* Prise en compte de décroche */ - - update_filtered_fc update_filtered; /* Lancement du filtrage */ - - wgroup_id_t gid; /* Groupe de travail dédié */ - - /* Signaux */ - - void (* dock_request) (GPanelItem); - void (* undock_request) (GPanelItem); - -}; - - -/* Fournit une indication sur la personnalité du panneau. */ -PanelItemPersonality gtk_panel_item_class_get_personality_singleton(const GPanelItemClass *); - -/* Renvoie false lors d'une consultation de la classe. */ -bool gtk_panel_item_class_return_false(const GPanelItemClass *); - -/* Renvoie true lors d'une consultation de la classe. */ -bool gtk_panel_item_class_return_true(const GPanelItemClass *); - - - -/* ---------------------- MECANISMES DE MISE A JOUR DE PANNEAU ---------------------- */ - - -/* Obtient le groupe de travail dédié à une mise à jour. */ -wgroup_id_t g_panel_item_get_group(const GPanelItem *); - -/* Bascule l'affichage d'un panneau avant sa mise à jour. */ -void g_panel_item_switch_to_updating_mask(GPanelItem *); - -/* Bascule l'affichage d'un panneau après sa mise à jour. */ -void g_panel_item_switch_to_updated_content(GPanelItem *); - - - -#endif /* _GUI_PANELS_PANEL_INT_H */ diff --git a/src/gui/panel.c b/src/gui/panel.c deleted file mode 100644 index 5b21620..0000000 --- a/src/gui/panel.c +++ /dev/null @@ -1,1119 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * panel.c - gestion des éléments réactifs spécifiques aux panneaux - * - * Copyright (C) 2019 Cyrille Bagard - * - * This file is part of Chrysalide. - * - * Chrysalide is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Chrysalide is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#include "panel.h" - - -#include <assert.h> -#include <stdio.h> -#include <string.h> - - -#include "panel-int.h" -#include "core/global.h" -#include "core/items.h" -#include "../common/extstr.h" -#include "../core/params.h" -#include "../gtkext/gtkdockable-int.h" -#include "../gtkext/named.h" -#include "../plugins/dt.h" -#include "../plugins/pglist.h" - - - -/* ------------------------- COEUR DES PANNEAUX D'AFFICHAGE ------------------------- */ - - -/* Initialise la classe des panneaux graphiques de l'éditeur. */ -static void g_panel_item_class_init(GPanelItemClass *); - -/* Initialise une instance de panneau graphique pour l'éditeur. */ -static void g_panel_item_init(GPanelItem *); - -/* Procède à l'initialisation de l'interface d'incrustation. */ -static void g_panel_item_dockable_interface_init(GtkDockableInterface *); - -/* Supprime toutes les références externes. */ -static void g_panel_item_dispose(GPanelItem *); - -/* Procède à la libération totale de la mémoire. */ -static void g_panel_item_finalize(GPanelItem *); - -/* Construit la chaîne d'accès à un élément de configuration. */ -static char *gtk_panel_item_class_build_configuration_key(const GPanelItemClass *, const char *); - -/* Fournit le nom court du composant encapsulable. */ -static char *gtk_panel_item_get_name(const GPanelItem *); - -/* Fournit le nom long du composant encapsulable. */ -static char *gtk_panel_item_get_desc(const GPanelItem *); - -/* Détermine si un panneau peut être filtré. */ -static bool gtk_panel_item_can_search(const GPanelItem *); - -/* Fournit le composant graphique intégrable dans un ensemble. */ -static GtkWidget *gtk_panel_item_get_widget(GPanelItem *); - -/* Démarre l'actualisation du filtrage du contenu. */ -static void gtk_panel_item_update_filtered(GPanelItem *, const char *); - - - -/* ---------------------- MECANISMES DE MISE A JOUR DE PANNEAU ---------------------- */ - - -/* Présente une copie de l'affichage du composant rafraîchi. */ -static gboolean g_panel_item_draw_mask(GtkWidget *, cairo_t *, GPanelItem *); - - - -/* ---------------------------------------------------------------------------------- */ -/* COEUR DES PANNEAUX D'AFFICHAGE */ -/* ---------------------------------------------------------------------------------- */ - - -/* Indique le type défini pour un élément destiné à un panneau. */ -G_DEFINE_TYPE_WITH_CODE(GPanelItem, g_panel_item, G_TYPE_EDITOR_ITEM, - G_IMPLEMENT_INTERFACE(GTK_TYPE_DOCKABLE, g_panel_item_dockable_interface_init)); - - -/****************************************************************************** -* * -* Paramètres : class = classe à initialiser. * -* * -* Description : Initialise la classe des panneaux graphiques de l'éditeur. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_panel_item_class_init(GPanelItemClass *class) -{ - GObjectClass *object; /* Autre version de la classe */ - GEditorItemClass *item; /* Encore une autre vision... */ - - object = G_OBJECT_CLASS(class); - - object->dispose = (GObjectFinalizeFunc/* ! */)g_panel_item_dispose; - object->finalize = (GObjectFinalizeFunc)g_panel_item_finalize; - - item = G_EDITOR_ITEM_CLASS(class); - - item->get_widget = (get_item_widget_fc)gtk_panel_item_get_widget; - - class->get_personality = gtk_panel_item_class_get_personality_singleton; - class->dock_at_startup = gtk_panel_item_class_return_true; - class->can_search = gtk_panel_item_class_return_false; - - g_signal_new("dock-request", - G_TYPE_PANEL_ITEM, - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(GPanelItemClass, dock_request), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - g_signal_new("undock-request", - G_TYPE_PANEL_ITEM, - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(GPanelItemClass, undock_request), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - -} - - -/****************************************************************************** -* * -* Paramètres : item = instance à initialiser. * -* * -* Description : Initialise une instance de panneau graphique pour l'éditeur. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_panel_item_init(GPanelItem *item) -{ - item->docked = false; - - item->widget = NULL; - item->cached_widget = NULL; - - item->filter = NULL; - - g_atomic_int_set(&item->switched, 0); - -} - - -/****************************************************************************** -* * -* Paramètres : iface = interface GTK à initialiser. * -* * -* Description : Procède à l'initialisation de l'interface d'incrustation. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_panel_item_dockable_interface_init(GtkDockableInterface *iface) -{ - iface->get_name = (get_dockable_name_fc)gtk_panel_item_get_name; - iface->get_desc = (get_dockable_desc_fc)gtk_panel_item_get_desc; - iface->can_search = (can_dockable_search_fc)gtk_panel_item_can_search; - - iface->get_widget = (get_dockable_widget_fc)gtk_panel_item_get_widget; - iface->update_filtered = (update_filtered_data_fc)gtk_panel_item_update_filtered; - -} - - -/****************************************************************************** -* * -* Paramètres : item = instance d'objet GLib à traiter. * -* * -* Description : Supprime toutes les références externes. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_panel_item_dispose(GPanelItem *item) -{ - g_clear_object(&item->widget); - g_clear_object(&item->cached_widget); - - G_OBJECT_CLASS(g_panel_item_parent_class)->dispose(G_OBJECT(item)); - -} - - -/****************************************************************************** -* * -* Paramètres : item = instance d'objet GLib à traiter. * -* * -* Description : Procède à la libération totale de la mémoire. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_panel_item_finalize(GPanelItem *item) -{ - if (item->filter != NULL) - free(item->filter); - - if (item->surface != NULL) - cairo_surface_destroy(item->surface); - - G_OBJECT_CLASS(g_panel_item_parent_class)->finalize(G_OBJECT(item)); - -} - - -/****************************************************************************** -* * -* Paramètres : class = classe à consulter. * -* * -* Description : Fournit une indication sur la personnalité du panneau. * -* * -* Retour : Identifiant lié à la nature du panneau. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PanelItemPersonality gtk_panel_item_class_get_personality(const GPanelItemClass *class) -{ - PanelItemPersonality result; /* Personnalité à retourner */ - - result = class->get_personality(class); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : class = classe à consulter. * -* * -* Description : Fournit une indication sur la personnalité du panneau. * -* * -* Retour : Identifiant lié à la nature unique du panneau. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PanelItemPersonality gtk_panel_item_class_get_personality_singleton(const GPanelItemClass *class) -{ - PanelItemPersonality result; /* Personnalité à retourner */ - - result = PIP_SINGLETON; - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : class = classe à consulter. * -* * -* Description : Fournit une indication d'accroche du panneau au démarrage. * -* * -* Retour : true si le panneau doit être affiché de prime abord. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool gtk_panel_item_class_dock_at_startup(const GPanelItemClass *class) -{ - bool result; /* Statut à retourner */ - GGenConfig *config; /* Configuration courante */ - char *key; /* Clef d'accès à un paramètre */ -#ifndef NDEBUG - bool status; /* Bilan de consultation */ -#endif - - config = get_main_configuration(); - - key = gtk_panel_item_class_build_configuration_key(class, "dock_at_startup"); - -#ifndef NDEBUG - status = g_generic_config_get_value(config, key, &result); - assert(status); -#else - g_generic_config_get_value(config, key, &result); -#endif - - free(key); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : class = classe associée à la consultation. * -* * -* Description : Renvoie false lors d'une consultation de la classe. * -* * -* Retour : false. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool gtk_panel_item_class_return_false(const GPanelItemClass *class) -{ - bool result; /* Statut à retourner */ - - result = false; - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : class = classe associée à la consultation. * -* * -* Description : Renvoie true lors d'une consultation de la classe. * -* * -* Retour : true. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool gtk_panel_item_class_return_true(const GPanelItemClass *class) -{ - bool result; /* Statut à retourner */ - - result = true; - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : class = classe à consulter. * -* * -* Description : Détermine si un panneau peut être filtré. * -* * -* Retour : Bilan de la consultation. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool gtk_panel_item_class_can_search(const GPanelItemClass *class) -{ - bool result; /* Statut à retourner */ - - result = class->can_search(class); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : class = classe à consulter. * -* * -* Description : Indique le chemin initial de la localisation d'un panneau. * -* * -* Retour : Chemin fixé associé à la position initiale. * -* * -* Remarques : - * -* * -******************************************************************************/ - -char *gtk_panel_item_class_get_path(const GPanelItemClass *class) -{ - char *result; /* Emplacement à retourner */ - GGenConfig *config; /* Configuration courante */ - char *key; /* Clef d'accès à un paramètre */ - const char *path; /* Nouveau chemin de placement */ -#ifndef NDEBUG - bool status; /* Statut de l'encapsulation */ -#endif - - config = get_main_configuration(); - - key = gtk_panel_item_class_build_configuration_key(class, "path"); - -#ifndef NDEBUG - status = g_generic_config_get_value(config, key, &path); - assert(status); -#else - g_generic_config_get_value(config, key, &path); -#endif - - free(key); - - result = strdup(path); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : class = classe à consulter. * -* * -* Description : Indique la définition d'un éventuel raccourci clavier. * -* * -* Retour : Description d'un raccourci ou NULL si aucun de défini. * -* * -* Remarques : - * -* * -******************************************************************************/ - -char *gtk_panel_item_class_get_key_bindings(const GPanelItemClass *class) -{ - char *result; /* Emplacement à retourner */ - - if (class->get_bindings != NULL) - result = class->get_bindings(class); - - else - result = NULL; - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : class = classe du type de panneau à traiter. * -* attrib = élément de configuration à inclure dans le résultat.* -* * -* Description : Construit la chaîne d'accès à un élément de configuration. * -* * -* Retour : Chaîne de caractères à libérer après usage. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static char *gtk_panel_item_class_build_configuration_key(const GPanelItemClass *class, const char *attrib) -{ - char *result; /* Construction à renvoyer */ - const char *name; /* Nom court du panneau */ - - name = g_editor_item_class_get_key(G_EDITOR_ITEM_CLASS(class)); - - asprintf(&result, "gui.panels.%s.%s", attrib, name); - - result = strrpl(result, " ", "_"); - - result = strlower(result); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : class = classe de panneau à consulter. * -* config = configuration à compléter. * -* * -* Description : Met en place les bases de la configuration d'un panneau. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool gtk_panel_item_class_setup_configuration(const GPanelItemClass *class, GGenConfig *config) -{ - bool result; /* Bilan à retourner */ - char *key; /* Clef d'accès à un paramètre */ - bool dock_at_startup; /* Affichage dès le départ ? */ - char *path; /* Localisation du panneau */ - - key = gtk_panel_item_class_build_configuration_key(class, "dock_at_startup"); - - dock_at_startup = class->dock_at_startup(class); - - result = g_generic_config_create_param_if_not_exist(config, key, CPT_BOOLEAN, dock_at_startup); - - free(key); - - if (!result) - goto exit; - - key = gtk_panel_item_class_build_configuration_key(class, "path"); - - path = class->get_path(class); - - result = g_generic_config_create_param_if_not_exist(config, key, CPT_STRING, path); - - free(path); - - free(key); - - exit: - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : type = type de panneau à mettre en place. * -* path = emplacement d'affichage ou NULL. * -* * -* Description : Crée un élément de panneau réactif. * -* * -* Retour : Adresse de la structure mise en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GPanelItem *g_panel_item_new(GType type, const char *path) -{ - GPanelItem *result; /* Structure à retourner */ - GPanelItemClass *class; /* Classe associée au type */ - PanelItemPersonality personality; /* Caractéristique de panneau */ - GtkTiledGrid *grid; /* Composant d'affichage */ - - class = g_type_class_ref(type); - - personality = gtk_panel_item_class_get_personality(class); - assert(path != NULL || personality == PIP_PERSISTENT_SINGLETON); - - g_type_class_unref(class); - - if (personality == PIP_PERSISTENT_SINGLETON || personality == PIP_SINGLETON) - { - result = G_PANEL_ITEM(find_editor_item_by_type(type)); - - if (result != NULL) - goto singleton; - - } - - result = create_object_from_type(type); - - grid = get_tiled_grid(); - - g_signal_connect_swapped(result, "dock-request", G_CALLBACK(gtk_tiled_grid_add), grid); - g_signal_connect_swapped(result, "undock-request", G_CALLBACK(gtk_tiled_grid_remove), grid); - - gtk_dockable_setup_dnd(GTK_DOCKABLE(result)); - - register_editor_item(G_EDITOR_ITEM(result)); - - notify_panel_creation(result); - - singleton: - - if (path != NULL) - { - if (path[0] != '\0') - gtk_panel_item_set_path(result, path); - - g_panel_item_dock(result); - - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : item = instance de panneau à consulter. * -* * -* Description : Indique le composant graphique principal du panneau. * -* * -* Retour : Composant graphique avec nom constituant le panneau. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GNamedWidget *gtk_panel_item_get_named_widget(const GPanelItem *item) -{ - GNamedWidget *result; /* Composant nommé à retourner */ - - result = item->widget; - - g_object_ref(G_OBJECT(result)); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : item = instance GTK dont l'interface est à consulter. * -* * -* Description : Fournit le nom court du composant encapsulable. * -* * -* Retour : Désignation humaine pour titre d'onglet ou de fenêtre. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static char *gtk_panel_item_get_name(const GPanelItem *item) -{ - char *result; /* Désignation à retourner */ - - result = g_named_widget_get_name(G_NAMED_WIDGET(item->widget), false); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : item = instance GTK dont l'interface est à consulter. * -* * -* Description : Fournit le nom long du composant encapsulable. * -* * -* Retour : Désignation humaine pour titre d'onglet ou de fenêtre. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static char *gtk_panel_item_get_desc(const GPanelItem *item) -{ - char *result; /* Description à retourner */ - - result = g_named_widget_get_name(G_NAMED_WIDGET(item->widget), true); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : item = instance GTK dont l'interface est à consulter. * -* * -* Description : Détermine si un panneau peut être filtré. * -* * -* Retour : Bilan de la consultation. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool gtk_panel_item_can_search(const GPanelItem *item) -{ - bool result; /* Indication à retourner */ - GPanelItemClass *class; /* Classe de l'élément visé */ - - class = G_PANEL_ITEM_GET_CLASS(item); - - result = gtk_panel_item_class_can_search(class); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : item = instance GTK dont l'interface est à consulter. * -* * -* Description : Fournit le composant graphique intégrable dans un ensemble. * -* * -* Retour : Composant graphique prêt à emploi. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static GtkWidget *gtk_panel_item_get_widget(GPanelItem *item) -{ - GtkWidget *result; /* Composant à retourner */ - - if (item->cached_widget == NULL) - item->cached_widget = g_named_widget_get_widget(G_NAMED_WIDGET(item->widget)); - - result = item->cached_widget; - - g_object_ref(G_OBJECT(result)); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : item = instance GTK dont l'interface est à sollicitée. * -* * -* Description : Démarre l'actualisation du filtrage du contenu. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void gtk_panel_item_update_filtered(GPanelItem *item, const char *filter) -{ - assert(gtk_panel_item_can_search(item)); - - if (item->filter != NULL) - free(item->filter); - - item->filter = (filter ? strdup(filter) : NULL); - - G_PANEL_ITEM_GET_CLASS(item)->update_filtered(item); - -} - - -/****************************************************************************** -* * -* Paramètres : item = instance GTK à consulter. * -* path = nouvelle emplacement d'inclusion. * -* * -* Description : Définit le chemin d'accès à utiliser pour les encapsulations.* -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void gtk_panel_item_set_path(GPanelItem *item, const char *path) -{ - GGenConfig *config; /* Configuration courante */ - char *key; /* Clef d'accès à un paramètre */ - - config = get_main_configuration(); - - key = gtk_panel_item_class_build_configuration_key(G_PANEL_ITEM_GET_CLASS(item), "path"); - - g_generic_config_set_value(config, key, path); - - free(key); - -} - - -/****************************************************************************** -* * -* Paramètres : item = composant à présenter à l'affichage. * -* * -* Description : Place un panneau dans l'ensemble affiché. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void g_panel_item_dock(GPanelItem *item) -{ - assert(!item->docked); - - g_signal_emit_by_name(item, "dock-request"); - - if (G_PANEL_ITEM_GET_CLASS(item)->ack_dock != NULL) - G_PANEL_ITEM_GET_CLASS(item)->ack_dock(item); - - notify_panel_docking(item, true); - -} - - -/****************************************************************************** -* * -* Paramètres : item = composant d'affichage à mettre à jour. * -* status = nouvel état d'encapsulation. * -* * -* Description : Définit si le composant repose sur un support de l'éditeur. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void g_panel_item_set_dock_at_startup(GPanelItem *item, bool status) -{ - char *key; /* Clef d'accès à un paramètre */ - - item->docked = status; - - key = gtk_panel_item_class_build_configuration_key(G_PANEL_ITEM_GET_CLASS(item), "dock_at_startup"); - - g_generic_config_set_value(get_main_configuration(), key, status); - - free(key); - -} - - -/****************************************************************************** -* * -* Paramètres : item = composant d'affichage à consulter. * -* * -* Description : Indique si le composant repose sur un support de l'éditeur. * -* * -* Retour : true si le composant est bien incrusté quelque part. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool g_panel_item_is_docked(const GPanelItem *item) -{ - bool result; /* Status à retourner */ - - result = item->docked; - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : item = composant à retirer de l'affichage. * -* * -* Description : Supprime un panneau de l'ensemble affiché. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void g_panel_item_undock(GPanelItem *item) -{ - PanelItemPersonality personality; /* Caractéristique de panneau */ - - assert(item->docked); - - g_signal_emit_by_name(item, "undock-request"); - - if (G_PANEL_ITEM_GET_CLASS(item)->ack_undock != NULL) - G_PANEL_ITEM_GET_CLASS(item)->ack_undock(item); - - notify_panel_docking(item, false); - - personality = gtk_panel_item_class_get_personality(G_PANEL_ITEM_GET_CLASS(item)); - - if (personality != PIP_PERSISTENT_SINGLETON) - unregister_editor_item(G_EDITOR_ITEM(item)); - -} - - - -/* ---------------------------------------------------------------------------------- */ -/* MECANISMES DE MISE A JOUR DE PANNEAU */ -/* ---------------------------------------------------------------------------------- */ - - -/****************************************************************************** -* * -* Paramètres : item = panneau ciblé par une mise à jour. * -* * -* Description : Obtient le groupe de travail dédié à une mise à jour. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -wgroup_id_t g_panel_item_get_group(const GPanelItem *item) -{ - wgroup_id_t result; /* Identifiant à retourner */ - - result = G_PANEL_ITEM_GET_CLASS(item)->gid; - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : widget = composant graphique sur lequel dessiner. * -* cr = contexte graphique pour le dessin. * -* panel = panneau ciblé par une mise à jour. * -* * -* Description : Présente une copie de l'affichage du composant rafraîchi. * -* * -* Retour : FALSE afin de poursuivre les traitements. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static gboolean g_panel_item_draw_mask(GtkWidget *widget, cairo_t *cr, GPanelItem *item) -{ - int width; /* Largeur du composant actuel */ - int height; /* Hauteur du composant actuel */ - - width = gtk_widget_get_allocated_width(widget); - height = gtk_widget_get_allocated_height(widget); - - cairo_save(cr); - - cairo_set_source_surface(cr, item->surface, 0, 0); - cairo_rectangle(cr, 0, 0, width, height); - - cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); - cairo_fill(cr); - - cairo_restore(cr); - - return FALSE; - -} - - -/****************************************************************************** -* * -* Paramètres : panel = panneau ciblé par une mise à jour. * -* * -* Description : Bascule l'affichage d'un panneau avant sa mise à jour. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void g_panel_item_switch_to_updating_mask(GPanelItem *item) -{ - GtkBuilder *builder; /* Constructeur sous-jacent */ - GtkWidget *content; /* Composant à faire évoluer */ - GdkWindow *window; /* Fenêtre au contenu à copier */ - int width; /* Largeur du composant actuel */ - int height; /* Hauteur du composant actuel */ - cairo_t *cr; /* Pinceau pour les dessins */ - GtkAdjustment *adj; /* Défilement éventuel */ - GtkStack *stack; /* Pile de composants GTK */ - GtkWidget *mask; /* Masque des travaux */ - - if (g_atomic_int_add(&item->switched, 1) > 0) - return; - - /* Copie de l'affichage courant */ - - assert(item->surface == NULL); - - builder = gtk_built_named_widget_get_builder(GTK_BUILT_NAMED_WIDGET(item->widget)); - - content = GTK_WIDGET(gtk_builder_get_object(builder, "content")); - - window = gtk_widget_get_window(content); - - if (window != NULL) - { - width = gtk_widget_get_allocated_width(content); - height = gtk_widget_get_allocated_height(content); - - item->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); - - cr = cairo_create(item->surface); - - gdk_cairo_set_source_window(cr, window, 0, 0); - - cairo_paint(cr); - - cairo_destroy(cr); - - } - - /* Sauvegarde de l'éventuelle position */ - - if (GTK_IS_SCROLLED_WINDOW(content)) - { - adj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(content)); - item->hadj_value = gtk_adjustment_get_value(adj); - - adj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(content)); - item->vadj_value = gtk_adjustment_get_value(adj); - - } - - /* Opération de basculement effectif */ - - stack = GTK_STACK(gtk_builder_get_object(builder, "stack")); - - mask = GTK_WIDGET(gtk_builder_get_object(builder, "mask")); - - gtk_spinner_start(GTK_SPINNER(mask)); - - if (item->surface != NULL) - g_signal_connect(mask, "draw", G_CALLBACK(g_panel_item_draw_mask), item); - - gtk_stack_set_visible_child(stack, mask); - - g_object_unref(G_OBJECT(builder)); - -} - - -/****************************************************************************** -* * -* Paramètres : panel = panneau ciblé par une mise à jour. * -* * -* Description : Bascule l'affichage d'un panneau après sa mise à jour. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void g_panel_item_switch_to_updated_content(GPanelItem *item) -{ - GtkBuilder *builder; /* Constructeur sous-jacent */ - GtkWidget *content; /* Composant à faire évoluer */ - GtkAdjustment *adj; /* Défilement éventuel */ - GtkStack *stack; /* Pile de composants GTK */ - GtkWidget *mask; /* Masque des travaux */ - - if (g_atomic_int_get(&item->switched) > 1) - goto skip; - - /* Restauration d'une éventuelle position */ - - builder = gtk_built_named_widget_get_builder(GTK_BUILT_NAMED_WIDGET(item->widget)); - - content = GTK_WIDGET(gtk_builder_get_object(builder, "content")); - - if (GTK_IS_SCROLLED_WINDOW(content)) - { - adj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(content)); - gtk_adjustment_set_value(adj, item->hadj_value); - - adj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(content)); - gtk_adjustment_set_value(adj, item->vadj_value); - - } - - /* Opération de basculement effectif */ - - stack = GTK_STACK(gtk_builder_get_object(builder, "stack")); - - gtk_stack_set_visible_child(stack, content); - - mask = GTK_WIDGET(gtk_builder_get_object(builder, "mask")); - - g_signal_handlers_disconnect_by_func(mask, G_CALLBACK(g_panel_item_draw_mask), item); - - gtk_spinner_stop(GTK_SPINNER(mask)); - - /* Supression de la copie d'affichage */ - - if (item->surface != NULL) - { - cairo_surface_destroy(item->surface); - item->surface = NULL; - } - - g_object_unref(G_OBJECT(builder)); - - skip: - - g_atomic_int_dec_and_test(&item->switched); - -} diff --git a/src/gui/panel.h b/src/gui/panel.h deleted file mode 100644 index de8d2bf..0000000 --- a/src/gui/panel.h +++ /dev/null @@ -1,112 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * panel.h - prototypes pour la gestion des éléments réactifs spécifiques aux panneaux - * - * Copyright (C) 2019 Cyrille Bagard - * - * This file is part of Chrysalide. - * - * Chrysalide is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Chrysalide is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#ifndef _GUI_PANELS_PANEL_H -#define _GUI_PANELS_PANEL_H - - -#include <stdbool.h> -#include <gtk/gtk.h> - - -#include "../glibext/configuration.h" -#include "../glibext/named.h" - - - -#define G_TYPE_PANEL_ITEM g_panel_item_get_type() -#define G_PANEL_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_PANEL_ITEM, GPanelItem)) -#define G_IS_PANEL_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_PANEL_ITEM)) -#define G_PANEL_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_PANEL_ITEM, GPanelItemClass)) -#define G_IS_PANEL_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_PANEL_ITEM)) -#define G_PANEL_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_PANEL_ITEM, GPanelItemClass)) - - -/* Elément réactif pour panneaux de l'éditeur (instance) */ -typedef struct _GPanelItem GPanelItem; - -/* Elément réactif pour panneaux de l'éditeur (classe) */ -typedef struct _GPanelItemClass GPanelItemClass; - - -/* Types de panneaux pour éditeur */ -typedef enum _PanelItemPersonality -{ - PIP_INVALID, /* Information non initialisée */ - - PIP_SINGLETON, /* Instance unique */ - PIP_PERSISTENT_SINGLETON, /* Instance unique permanente */ - PIP_BINARY_VIEW, /* Affichage d'un binaire */ - PIP_OTHER, /* Reste du monde */ - - PIP_COUNT - -} PanelItemPersonality; - - -/* Indique le type défini pour un élément destiné à un panneau. */ -GType g_panel_item_get_type(void); - -/* Fournit une indication sur la personnalité du panneau. */ -PanelItemPersonality gtk_panel_item_class_get_personality(const GPanelItemClass *); - -/* Fournit une indication d'accroche du panneau au démarrage. */ -bool gtk_panel_item_class_dock_at_startup(const GPanelItemClass *); - -/* Détermine si un panneau peut être filtré. */ -bool gtk_panel_item_class_can_search(const GPanelItemClass *); - -/* Indique le chemin initial de la localisation d'un panneau. */ -char *gtk_panel_item_class_get_path(const GPanelItemClass *); - -/* Indique la définition d'un éventuel raccourci clavier. */ -char *gtk_panel_item_class_get_key_bindings(const GPanelItemClass *); - -/* Met en place les bases de la configuration du panneau. */ -bool gtk_panel_item_class_setup_configuration(const GPanelItemClass *, GGenConfig *); - -/* Crée un élément de panneau réactif. */ -GPanelItem *g_panel_item_new(GType, const char *); - -/* Indique le composant graphique principal du panneau. */ -GNamedWidget *gtk_panel_item_get_named_widget(const GPanelItem *); - -/* Définit le chemin d'accès à utiliser pour les encapsulations. */ -void gtk_panel_item_set_path(GPanelItem *, const char *); - -/* Place un panneau dans l'ensemble affiché. */ -void g_panel_item_dock(GPanelItem *); - -/* Définit si le composant repose sur un support de l'éditeur. */ -void g_panel_item_set_dock_at_startup(GPanelItem *, bool); - -/* Indique si le composant repose sur un support de l'éditeur. */ -bool g_panel_item_is_docked(const GPanelItem *); - -/* Supprime un panneau de l'ensemble affiché. */ -void g_panel_item_undock(GPanelItem *); - - - -#endif /* _GUI_PANELS_PANEL_H */ diff --git a/src/gui/panels/Makefile.am b/src/gui/panels/Makefile.am index 83e173b..ecff6c7 100644 --- a/src/gui/panels/Makefile.am +++ b/src/gui/panels/Makefile.am @@ -3,7 +3,7 @@ DEFAULT_INCLUDES = -idirafter. -I$(top_builddir) BUILT_SOURCES = resources.h resources.c -noinst_LTLIBRARIES = libguipanels.la +noinst_LTLIBRARIES = libguipanels4.la # libguipanels.la UI_FILES = \ bintree.ui \ @@ -11,11 +11,9 @@ UI_FILES = \ errors.ui \ glance.ui \ history.ui \ - log.ui \ regedit.ui \ strings.ui \ - symbols.ui \ - welcome.ui + symbols.ui libguipanels_la_SOURCES = \ bintree.h bintree.c \ @@ -23,25 +21,50 @@ libguipanels_la_SOURCES = \ errors.h errors.c \ glance.h glance.c \ history.h history.c \ - log.h log.c \ regedit.h regedit.c \ resources.h resources.c \ strings.h strings.c \ symbols.h symbols.c \ updating-int.h \ updating.h updating.c \ - view.h view.c \ - welcome.h welcome.c + view.h view.c libguipanels_la_CFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) +IMG_PATH = ../../../data/images + +RES_FILES = \ + binary.ui \ + binary-params.ui \ + $(IMG_PATH)/binfile-symbolic.svg \ + logs.ui \ + logs-col-icon.ui \ + logs-col-message.ui \ + welcome.ui \ + welcome-hints.txt \ + $(IMG_PATH)/tipoftheday-symbolic.svg + +libguipanels4_la_SOURCES = \ + binary-int.h \ + binary.h binary.c \ + binary-params-int.h \ + binary-params.h binary-params.c \ + logs-int.h \ + logs.h logs.c \ + resources.h resources.c \ + welcome-int.h \ + welcome.h welcome.c + +libguipanels4_la_CFLAGS = $(LIBGTK4_CFLAGS) + + devdir = $(includedir)/chrysalide/$(subdir:src/%=core/%) dev_HEADERS = $(libguipanels_la_SOURCES:%c=) -resources.c: gresource.xml $(UI_FILES) +resources.c: gresource.xml $(RES_FILES) glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-source --c-name gui_panels gresource.xml resources.h: gresource.xml @@ -50,4 +73,4 @@ resources.h: gresource.xml CLEANFILES = resources.h resources.c -EXTRA_DIST = gresource.xml $(UI_FILES) +EXTRA_DIST = gresource.xml $(RES_FILES) diff --git a/src/gui/panels/binary-int.h b/src/gui/panels/binary-int.h new file mode 100644 index 0000000..5116f5c --- /dev/null +++ b/src/gui/panels/binary-int.h @@ -0,0 +1,52 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * binary-int.h - prototypes internes pour le panneau d'affichage de contenus d'un binaire, bruts ou non + * + * Copyright (C) 2024 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _GUI_PANELS_BINARY_INT_H +#define _GUI_PANELS_BINARY_INT_H + + +#include "binary.h" +#include "../../gtkext/panel-int.h" + + + +/* Panneau d'accueil par défaut (instance) */ +struct _GtkBinaryPanel +{ + GtkTiledPanel parent; /* A laisser en premier */ + + GtkScrolledWindow *hex_scroll; /* Défilement pour contenu #0 */ + +}; + +/* Panneau d'accueil par défaut (classe) */ +struct _GtkBinaryPanelClass +{ + GtkTiledPanelClass parent; /* A laisser en premier */ + +}; + + + +#endif /* _GUI_PANELS_BINARY_INT_H */ diff --git a/src/gui/panels/binary-params-int.h b/src/gui/panels/binary-params-int.h new file mode 100644 index 0000000..0fbef24 --- /dev/null +++ b/src/gui/panels/binary-params-int.h @@ -0,0 +1,50 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * binary-params-int.h - définitions internes pour l'édition des paramètres initiaux d'un chargement de binaire + * + * Copyright (C) 2025 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _GUI_PANELS_BINARY_PARAMS_INT_H +#define _GUI_PANELS_BINARY_PARAMS_INT_H + + +#include "binary-params.h" + + + +/* Composant pour les paramètres de chargement d'un binaire (instance) */ +struct _GtkBinaryParameters +{ + GtkGrid parent; /* A laisser en premier */ + + GtkEntry *filename; /* CHemin d'un binaire */ + +}; + +/* Composant pour les paramètres de chargement d'un binaire (classe) */ +struct _GtkBinaryParametersClass +{ + GtkGridClass parent; /* A laisser en premier */ + +}; + + + +#endif /* _GUI_PANELS_BINARY_PARAMS_INT_H */ diff --git a/src/gui/panels/binary-params.c b/src/gui/panels/binary-params.c new file mode 100644 index 0000000..1059761 --- /dev/null +++ b/src/gui/panels/binary-params.c @@ -0,0 +1,178 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * binary-params.c - édition des paramètres initiaux d'un chargement de binaire + * + * Copyright (C) 2025 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#include "binary-params.h" + + +#include "binary.h" +#include "binary-params-int.h" +#include "../window.h" +#include "../../analysis/contents/file.h" +#include "../../gtkext/helpers.h" + + + +/* Initialise la classe des composants d'édition de paramètres. */ +static void gtk_binary_parameters_class_init(GtkBinaryParametersClass *); + +/* Initialise une instance de composant d'édition de paramètres. */ +static void gtk_binary_parameters_init(GtkBinaryParameters *); + +/* Supprime toutes les références externes. */ +static void gtk_binary_parameters_dispose(GObject *); + +/* Procède à la libération totale de la mémoire. */ +static void gtk_binary_parameters_finalize(GObject *); + +/* Ouvre une boîte de dialogue pour récupérer un fichier. */ +static void gtk_binary_parameters_on_new_file_entry_icon_release(GtkEntry *, GtkEntryIconPosition, GtkBinaryParameters *); + + + +/* Détermine le type du composant d'édition des paramètres de chargement. */ +G_DEFINE_TYPE(GtkBinaryParameters, gtk_binary_parameters, GTK_TYPE_GRID); + + +/****************************************************************************** +* * +* Paramètres : class = classe GTK à initialiser. * +* * +* Description : Initialise la classe des composants d'édition de paramètres. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_binary_parameters_class_init(GtkBinaryParametersClass *class) +{ + GObjectClass *object; /* Plus haut niveau équivalent */ + GtkWidgetClass *widget; /* Classe de haut niveau */ + + object = G_OBJECT_CLASS(class); + + object->dispose = gtk_binary_parameters_dispose; + object->finalize = gtk_binary_parameters_finalize; + + widget = GTK_WIDGET_CLASS(class); + + gtk_widget_class_set_template_from_resource(widget, "/re/chrysalide/framework/gui/panels/binary-params.ui"); + + gtk_widget_class_bind_template_callback_full(widget, BUILDER_CB(gtk_binary_parameters_on_new_file_entry_icon_release)); + + gtk_widget_class_bind_template_child(widget, GtkBinaryParameters, filename); + +} + + +/****************************************************************************** +* * +* Paramètres : params = composant GTK à initialiser. * +* * +* Description : Initialise une instance de composant d'édition de paramètres.* +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_binary_parameters_init(GtkBinaryParameters *params) +{ + gtk_widget_init_template(GTK_WIDGET(params)); + +} + + +/****************************************************************************** +* * +* Paramètres : object = instance d'objet GLib à traiter. * +* * +* Description : Supprime toutes les références externes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_binary_parameters_dispose(GObject *object) +{ + gtk_widget_dispose_template(GTK_WIDGET(object), GTK_TYPE_BINARY_PARAMETERS); + + G_OBJECT_CLASS(gtk_binary_parameters_parent_class)->dispose(object); + +} + + +/****************************************************************************** +* * +* Paramètres : object = instance d'objet GLib à traiter. * +* * +* Description : Procède à la libération totale de la mémoire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_binary_parameters_finalize(GObject *object) +{ + G_OBJECT_CLASS(gtk_binary_parameters_parent_class)->finalize(object); + +} + + +/****************************************************************************** +* * +* Paramètres : entry = zone de saisie concernée par l'appel. * +* icon_pos = position de l'icone incrustée dans la zone. * +* params = composant d'édition des paramètres. * +* * +* Description : Ouvre une boîte de dialogue pour récupérer un fichier. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_binary_parameters_on_new_file_entry_icon_release(GtkEntry *entry, GtkEntryIconPosition icon_pos, GtkBinaryParameters *params) +{ + GtkRoot *root; /* Racine du composant */ + GBinContent *content; /* Contenu binaire à afficher */ + GtkTiledPanel *tiled; /* Panneau d'affichage complet */ + + root = gtk_widget_get_root(GTK_WIDGET(entry)); + + content = g_file_content_new("/bin/id"); + + tiled = gtk_binary_panel_new_for_content(content); + + unref_object(content); + + gtk_framework_window_add(GTK_FRAMEWORK_WINDOW(root), tiled); + +} diff --git a/src/gui/panels/binary-params.h b/src/gui/panels/binary-params.h new file mode 100644 index 0000000..450da25 --- /dev/null +++ b/src/gui/panels/binary-params.h @@ -0,0 +1,41 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * binary-params.h - prototypes pour l'édition des paramètres initiaux d'un chargement de binaire + * + * Copyright (C) 2025 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _GUI_PANELS_BINARY_PARAMS_H +#define _GUI_PANELS_BINARY_PARAMS_H + + +#include <gtk/gtk.h> + + +#include "../../glibext/helpers.h" + + + +#define GTK_TYPE_BINARY_PARAMETERS (gtk_binary_parameters_get_type()) + +DECLARE_GTYPE(GtkBinaryParameters, gtk_binary_parameters, GTK, BINARY_PARAMETERS); + + + +#endif /* _GUI_PANELS_BINARY_PARAMS_H */ diff --git a/src/gui/panels/binary-params.ui b/src/gui/panels/binary-params.ui new file mode 100644 index 0000000..dcbaf7c --- /dev/null +++ b/src/gui/panels/binary-params.ui @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + + <template class="GtkBinaryParameters" parent="GtkGrid"> + <property name="margin-bottom">12</property> + <property name="margin-end">12</property> + <property name="margin-start">12</property> + <property name="margin-top">12</property> + <property name="column-spacing">12</property> + <property name="row-spacing">8</property> + + <child> + <object class="GtkLabel"> + <property name="label">Load and analyze a new file:</property> + <property name="xalign">0</property> + <layout> + <property name="column">0</property> + <property name="row">0</property> + </layout> + </object> + </child> + + <child> + <object class="GtkEntry" id="filename"> + <property name="secondary-icon-name">document-open-symbolic</property> + <property name="placeholder-text">File location</property> + <property name="hexpand">TRUE</property> + <property name="hexpand-set">TRUE</property> + <layout> + <property name="column">0</property> + <property name="row">1</property> + </layout> + <style> + <class name="background"/> + </style> + <signal name="icon-release" handler="gtk_binary_parameters_on_new_file_entry_icon_release"/> + </object> + </child> + + </template> + +</interface> diff --git a/src/gui/panels/binary.c b/src/gui/panels/binary.c new file mode 100644 index 0000000..f58c06b --- /dev/null +++ b/src/gui/panels/binary.c @@ -0,0 +1,195 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * binary.c - panneau d'affichage de contenus d'un binaire, bruts ou non + * + * Copyright (C) 2024 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "binary.h" + + +#include "binary-int.h" +#include "../../gtkext/helpers.h" +#include "../../gtkext/hexview.h" + + + +/* ------------------------- COEUR D'UN PANNEAU D'AFFICHAGE ------------------------- */ + + +/* Initialise la classe des panneaux pour binaires. */ +static void gtk_binary_panel_class_init(GtkBinaryPanelClass *); + +/* Initialise une instance de panneau pour binaire. */ +static void gtk_binary_panel_init(GtkBinaryPanel *); + +/* Supprime toutes les références externes. */ +static void gtk_binary_panel_dispose(GObject *); + +/* Procède à la libération totale de la mémoire. */ +static void gtk_binary_panel_finalize(GObject *); + + + +/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */ + + + + + + +/* ---------------------------------------------------------------------------------- */ +/* COEUR D'UN PANNEAU D'AFFICHAGE */ +/* ---------------------------------------------------------------------------------- */ + + +/* Indique le type défini pour un panneau d'affichage de contenus d'un binaire. */ +G_DEFINE_TYPE(GtkBinaryPanel, gtk_binary_panel, GTK_TYPE_TILED_PANEL); + + +/****************************************************************************** +* * +* Paramètres : class = classe à initialiser. * +* * +* Description : Initialise la classe des panneaux pour binaires. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_binary_panel_class_init(GtkBinaryPanelClass *class) +{ + GObjectClass *object; /* Autre version de la classe */ + GtkWidgetClass *widget; /* Classe de haut niveau */ + + object = G_OBJECT_CLASS(class); + + object->dispose = gtk_binary_panel_dispose; + object->finalize = gtk_binary_panel_finalize; + + widget = GTK_WIDGET_CLASS(class); + + gtk_widget_class_set_template_from_resource(widget, "/re/chrysalide/framework/gui/panels/binary.ui"); + + gtk_widget_class_bind_template_child(widget, GtkBinaryPanel, hex_scroll); + +} + + +/****************************************************************************** +* * +* Paramètres : panel = instance à initialiser. * +* * +* Description : Initialise une instance de panneau pour binaire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_binary_panel_init(GtkBinaryPanel *panel) +{ + gtk_widget_init_template(GTK_WIDGET(panel)); + +} + + +/****************************************************************************** +* * +* Paramètres : object = instance d'objet GLib à traiter. * +* * +* Description : Supprime toutes les références externes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_binary_panel_dispose(GObject *object) +{ + gtk_widget_dispose_template(GTK_WIDGET(object), GTK_TYPE_BINARY_PANEL); + + G_OBJECT_CLASS(gtk_binary_panel_parent_class)->dispose(object); + +} + + +/****************************************************************************** +* * +* Paramètres : object = instance d'objet GLib à traiter. * +* * +* Description : Procède à la libération totale de la mémoire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_binary_panel_finalize(GObject *object) +{ + G_OBJECT_CLASS(gtk_binary_panel_parent_class)->finalize(object); + +} + + +/****************************************************************************** +* * +* Paramètres : content = contenu brut à exposer. * +* * +* Description : Crée une nouvelle instance de panneau pour binaire. * +* * +* Retour : Composant GTK mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkTiledPanel *gtk_binary_panel_new_for_content(GBinContent *content) +{ + GtkTiledPanel *result; /* Instance à retourner */ + GtkHexView *view; /* Composant d'affichage */ + + result = g_object_new(GTK_TYPE_BINARY_PANEL, NULL); + + view = gtk_hex_view_new(content); + gtk_scrolled_window_set_child(GTK_BINARY_PANEL(result)->hex_scroll, GTK_WIDGET(view)); + + return result; + +} + + + +/* ---------------------------------------------------------------------------------- */ +/* IMPLEMENTATION DES FONCTIONS DE CLASSE */ +/* ---------------------------------------------------------------------------------- */ + + + + + + + + diff --git a/src/gui/panels/binary.h b/src/gui/panels/binary.h new file mode 100644 index 0000000..26f8a7d --- /dev/null +++ b/src/gui/panels/binary.h @@ -0,0 +1,48 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * binary.h - prototypes pour le panneau d'accueil par défaut + * + * Copyright (C) 2012-2024 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _GUI_PANELS_BINARY_H +#define _GUI_PANELS_BINARY_H + + +#include <gtk/gtk.h> + + +#include "../../analysis/content.h" +#include "../../glibext/helpers.h" +#include "../../gtkext/panel.h" + + + +#define GTK_TYPE_BINARY_PANEL (gtk_binary_panel_get_type()) + +DECLARE_GTYPE(GtkBinaryPanel, gtk_binary_panel, GTK, BINARY_PANEL); + + +/* Crée une nouvelle instance de panneau pour binaire. */ +GtkTiledPanel *gtk_binary_panel_new_for_content(GBinContent *); + + + +#endif /* _GUI_PANELS_BINARY_H */ diff --git a/src/gui/panels/binary.ui b/src/gui/panels/binary.ui new file mode 100644 index 0000000..a34c409 --- /dev/null +++ b/src/gui/panels/binary.ui @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + + <template class="GtkBinaryPanel" parent="GtkTiledPanel"> + <child> + <object class="GtkScrolledWindow" id="hex_scroll"> + <property name="hscrollbar-policy">automatic</property> + <property name="vscrollbar-policy">automatic</property> + <property name="hexpand">TRUE</property> + <property name="vexpand">TRUE</property> + <property name="has-frame">0</property> + </object> + </child> + </template> + +</interface> diff --git a/src/gui/panels/gresource.xml b/src/gui/panels/gresource.xml index d996ef1..2765b25 100644 --- a/src/gui/panels/gresource.xml +++ b/src/gui/panels/gresource.xml @@ -1,20 +1,16 @@ <?xml version="1.0" encoding="UTF-8"?> <gresources> - <gresource prefix="/org/chrysalide/gui/panels"> - <file compressed="true">../../../pixmaps/tbutton_list_view.png</file> - <file compressed="true">../../../pixmaps/tbutton_tree_view.png</file> - <file compressed="true">../../../pixmaps/tbutton_collapse.png</file> - <file compressed="true">../../../pixmaps/tbutton_expand.png</file> - <file compressed="true">../../../pixmaps/symbol_class_classic.png</file> - <file compressed="true">bintree.ui</file> - <file compressed="true">bookmarks.ui</file> - <file compressed="true">errors.ui</file> - <file compressed="true">glance.ui</file> - <file compressed="true">history.ui</file> - <file compressed="true">log.ui</file> - <file compressed="true">regedit.ui</file> - <file compressed="true">strings.ui</file> - <file compressed="true">symbols.ui</file> + <gresource prefix="/re/chrysalide/framework/gui/panels"> + <file compressed="true">binary.ui</file> + <file compressed="true">binary-params.ui</file> + <file compressed="true">logs.ui</file> + <file compressed="true">logs-col-icon.ui</file> + <file compressed="true">logs-col-message.ui</file> <file compressed="true">welcome.ui</file> + <file compressed="true">welcome-hints.txt</file> + </gresource> + <gresource prefix="/re/chrysalide/framework/gui/icons/scalable/actions"> + <file compressed="true" alias="binfile-symbolic.svg">../../../data/images/binfile-symbolic.svg</file> + <file compressed="true" alias="tipoftheday-symbolic.svg">../../../data/images/tipoftheday-symbolic.svg</file> </gresource> </gresources> diff --git a/src/gui/panels/log.c b/src/gui/panels/log.c deleted file mode 100644 index d11fbd2..0000000 --- a/src/gui/panels/log.c +++ /dev/null @@ -1,451 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * log.c - panneau d'affichage des messages système - * - * Copyright (C) 2012-2019 Cyrille Bagard - * - * This file is part of Chrysalide. - * - * Chrysalide is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Chrysalide is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#include "log.h" - - -#include <malloc.h> -#include <stdarg.h> -#include <stdio.h> -#include <string.h> -#include <gtk/gtk.h> - - -#include "../panel-int.h" -#include "../core/panels.h" -#include "../../gtkext/easygtk.h" -#include "../../gtkext/named.h" - - - -/* Colonnes de la liste des messages */ -typedef enum _LogColumn -{ - LGC_PICTURE, /* Image de représentation */ - LGC_STRING, /* Chaîne de caractères */ - - LGC_COUNT /* Nombre de colonnes */ - -} LogColumn; - - -/* Paramètres à transmettre pour un affichage */ -typedef struct _log_data -{ - GPanelItem *item; /* Intermédiaire mis en place */ - LogMessageType type; /* Type de message à afficher */ - char *msg; /* Contenu du message */ - -} log_data; - - -/* Panneau d'accueil (instance) */ -struct _GLogPanel -{ - GPanelItem parent; /* A laisser en premier */ - -}; - - -/* Panneau d'accueil (classe) */ -struct _GLogPanelClass -{ - GPanelItemClass parent; /* A laisser en premier */ - -}; - - -/* Initialise la classe des panneaux d'affichage des messages. */ -static void g_log_panel_class_init(GLogPanelClass *); - -/* Initialise une instance de panneau d'affichage des messages. */ -static void g_log_panel_init(GLogPanel *); - -/* Supprime toutes les références externes. */ -static void g_log_panel_dispose(GLogPanel *); - -/* Procède à la libération totale de la mémoire. */ -static void g_log_panel_finalize(GLogPanel *); - -/* Fournit le nom interne attribué à l'élément réactif. */ -static char *g_log_panel_class_get_key(const GLogPanelClass *); - -/* Fournit une indication sur la personnalité du panneau. */ -static PanelItemPersonality g_log_panel_class_get_personality(const GLogPanelClass *); - -/* Indique le chemin initial de la localisation d'un panneau. */ -static char *g_log_panel_class_get_path(const GLogPanelClass *); - -/* Indique la définition d'un éventuel raccourci clavier. */ -static char *g_log_panel_class_get_key_bindings(const GLogPanelClass *); - -/* Affiche un message dans le journal des messages système. */ -static gboolean log_message(log_data *); - - - -/* Indique le type défini pour un panneau d'affichage de messages. */ -G_DEFINE_TYPE(GLogPanel, g_log_panel, G_TYPE_PANEL_ITEM); - - -/****************************************************************************** -* * -* Paramètres : class = classe à initialiser. * -* * -* Description : Initialise la classe des panneaux d'affichage des messages. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_log_panel_class_init(GLogPanelClass *class) -{ - GObjectClass *object; /* Autre version de la classe */ - GEditorItemClass *item; /* Encore une autre vision... */ - GPanelItemClass *panel; /* Version parente de la classe*/ - - object = G_OBJECT_CLASS(class); - - object->dispose = (GObjectFinalizeFunc/* ! */)g_log_panel_dispose; - object->finalize = (GObjectFinalizeFunc)g_log_panel_finalize; - - item = G_EDITOR_ITEM_CLASS(class); - - item->get_key = (get_item_key_fc)g_log_panel_class_get_key; - - panel = G_PANEL_ITEM_CLASS(class); - - panel->get_personality = (get_panel_personality_fc)g_log_panel_class_get_personality; - panel->get_path = (get_panel_path_fc)g_log_panel_class_get_path; - panel->get_bindings = (get_panel_bindings_fc)g_log_panel_class_get_key_bindings; - -} - - -/****************************************************************************** -* * -* Paramètres : panel = instance à initialiser. * -* * -* Description : Initialise une instance de panneau d'affichage des messages. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_log_panel_init(GLogPanel *panel) -{ - GPanelItem *pitem; /* Version parente du panneau */ - - /* Eléments de base */ - - pitem = G_PANEL_ITEM(panel); - - pitem->widget = G_NAMED_WIDGET(gtk_built_named_widget_new_for_panel(_("Messages"), - _("Misc information"), - PANEL_LOG_ID)); - -} - - -/****************************************************************************** -* * -* Paramètres : panel = instance d'objet GLib à traiter. * -* * -* Description : Supprime toutes les références externes. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_log_panel_dispose(GLogPanel *panel) -{ - G_OBJECT_CLASS(g_log_panel_parent_class)->dispose(G_OBJECT(panel)); - -} - - -/****************************************************************************** -* * -* Paramètres : panel = instance d'objet GLib à traiter. * -* * -* Description : Procède à la libération totale de la mémoire. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_log_panel_finalize(GLogPanel *panel) -{ - G_OBJECT_CLASS(g_log_panel_parent_class)->finalize(G_OBJECT(panel)); - -} - - -/****************************************************************************** -* * -* Paramètres : class = classe à consulter. * -* * -* Description : Fournit le nom interne attribué à l'élément réactif. * -* * -* Retour : Désignation (courte) de l'élément de l'éditeur. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static char *g_log_panel_class_get_key(const GLogPanelClass *class) -{ - char *result; /* Description à renvoyer */ - - result = strdup(PANEL_LOG_ID); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : class = classe à consulter. * -* * -* Description : Fournit une indication sur la personnalité du panneau. * -* * -* Retour : Identifiant lié à la nature unique du panneau. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PanelItemPersonality g_log_panel_class_get_personality(const GLogPanelClass *class) -{ - PanelItemPersonality result; /* Personnalité à retourner */ - - result = PIP_PERSISTENT_SINGLETON; - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : class = classe à consulter. * -* * -* Description : Indique le chemin initial de la localisation d'un panneau. * -* * -* Retour : Chemin fixé associé à la position initiale. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static char *g_log_panel_class_get_path(const GLogPanelClass *class) -{ - char *result; /* Emplacement à retourner */ - - result = strdup("Ms"); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : class = classe à consulter. * -* * -* Description : Indique la définition d'un éventuel raccourci clavier. * -* * -* Retour : Description d'un raccourci ou NULL si aucun de défini. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static char *g_log_panel_class_get_key_bindings(const GLogPanelClass *class) -{ - char *result; /* Emplacement à retourner */ - - result = strdup("<Shift>F1"); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Crée un panneau d'affichage des messages système. * -* * -* Retour : Adresse de la structure mise en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GPanelItem *g_log_panel_new(void) -{ - GPanelItem *result; /* Structure à retourner */ - - result = g_object_new(G_TYPE_LOG_PANEL, NULL); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : panel = instance d'objet GLib à traiter. * -* type = espèce du message à ajouter. * -* msg = message à faire apparaître à l'écran. * -* * -* Description : Affiche un message dans le journal des messages système. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void g_log_panel_add_message(GLogPanel *panel, LogMessageType type, const char *msg) -{ - log_data *data; /* Paramètres à joindre */ - - data = calloc(1, sizeof(log_data)); - - data->item = G_PANEL_ITEM(panel); - data->type = type; - data->msg = strdup(msg); - - g_object_ref(G_OBJECT(data->item)); - - g_main_context_invoke(NULL, (GSourceFunc)log_message, data); - -} - - -/****************************************************************************** -* * -* Paramètres : data = paramètres destinés à l'affichage d'un message. * -* * -* Description : Affiche un message dans le journal des messages système. * -* * -* Retour : - * -* * -* Remarques : Cette fonction, et c'est tout son intérêt, est toujours * -* exécutée dans le contexte GTK principal. * -* * -******************************************************************************/ - -static gboolean log_message(log_data *data) -{ - GtkBuilder *builder; /* Constructeur utilisé */ - GtkListStore *store; /* Modèle de gestion */ - GtkTreeIter iter; /* Point d'insertion */ - GtkTreeView *treeview; /* Affichage de la liste */ - - builder = gtk_built_named_widget_get_builder(GTK_BUILT_NAMED_WIDGET(G_PANEL_ITEM(data->item)->widget)); - - /* Mise en place du message */ - - store = GTK_LIST_STORE(gtk_builder_get_object(builder, "store")); - - gtk_list_store_append(store, &iter); - - switch (data->type) - { - case LMT_INFO: - gtk_list_store_set(store, &iter, - LGC_PICTURE, "gtk-info", - LGC_STRING, data->msg, - -1); - break; - - case LMT_PROCESS: - gtk_list_store_set(store, &iter, - LGC_PICTURE, "gtk-execute", - LGC_STRING, data->msg, - -1); - break; - - case LMT_WARNING: - gtk_list_store_set(store, &iter, - LGC_PICTURE, "gtk-dialog-warning", - LGC_STRING, data->msg, - -1); - break; - - case LMT_BAD_BINARY: - gtk_list_store_set(store, &iter, - LGC_PICTURE, "gtk-dialog-warning", - LGC_STRING, data->msg, - -1); - break; - - case LMT_ERROR: - case LMT_EXT_ERROR: - gtk_list_store_set(store, &iter, - LGC_PICTURE, "gtk-dialog-error", - LGC_STRING, data->msg, - -1); - break; - - default: - gtk_list_store_set(store, &iter, - LGC_STRING, data->msg, - -1); - break; - - } - - /* Défilement pour pointer à l'affichage */ - - treeview = GTK_TREE_VIEW(gtk_builder_get_object(builder, "treeview")); - - scroll_to_treeview_iter(treeview, GTK_TREE_MODEL(store), &iter); - - g_object_unref(G_OBJECT(builder)); - - /* Nettoyage de la mémoire */ - - g_object_unref(G_OBJECT(data->item)); - - free(data->msg); - - free(data); - - return G_SOURCE_REMOVE; - -} diff --git a/src/gui/panels/log.h b/src/gui/panels/log.h deleted file mode 100644 index 4d155a2..0000000 --- a/src/gui/panels/log.h +++ /dev/null @@ -1,67 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * log.h - prototypes pour le panneau d'affichage des messages système - * - * Copyright (C) 2012-2019 Cyrille Bagard - * - * This file is part of Chrysalide. - * - * Chrysalide is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Chrysalide is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#ifndef _GUI_PANELS_LOG_H -#define _GUI_PANELS_LOG_H - - -#include <i18n.h> - - -#include "../panel.h" -#include "../../core/logs.h" - - - -#define PANEL_LOG_ID "log" - - -#define G_TYPE_LOG_PANEL g_log_panel_get_type() -#define G_LOG_PANEL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_log_panel_get_type(), GLogPanel)) -#define G_IS_LOG_PANEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_log_panel_get_type())) -#define G_LOG_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_LOG_PANEL, GLogPanelClass)) -#define G_IS_LOG_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_LOG_PANEL)) -#define G_LOG_PANEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_LOG_PANEL, GLogPanelClass)) - - -/* Panneau d'affichage de messages (instance) */ -typedef struct _GLogPanel GLogPanel; - -/* Panneau d'affichage de messages (classe) */ -typedef struct _GLogPanelClass GLogPanelClass; - - - -/* Indique le type défini pour un panneau d'affichage de messages. */ -GType g_log_panel_get_type(void); - -/* Crée un panneau d'affichage des messages système. */ -GPanelItem *g_log_panel_new(void); - -/* Affiche un message dans le journal des messages système. */ -void g_log_panel_add_message(GLogPanel *, LogMessageType, const char *); - - - -#endif /* _GUI_PANELS_LOG_H */ diff --git a/src/gui/panels/log.ui b/src/gui/panels/log.ui deleted file mode 100644 index 4ffe96c..0000000 --- a/src/gui/panels/log.ui +++ /dev/null @@ -1,59 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- Generated with glade 3.21.0 --> -<interface> - <requires lib="gtk+" version="3.20"/> - <object class="GtkListStore" id="store"> - <columns> - <!-- column-name picture --> - <column type="gchararray"/> - <!-- column-name string --> - <column type="gchararray"/> - </columns> - </object> - <object class="GtkOffscreenWindow"> - <property name="can_focus">False</property> - <child> - <object class="GtkScrolledWindow" id="box"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="shadow_type">in</property> - <child> - <object class="GtkTreeView" id="treeview"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="model">store</property> - <property name="headers_visible">False</property> - <child internal-child="selection"> - <object class="GtkTreeSelection"/> - </child> - <child> - <object class="GtkTreeViewColumn"> - <property name="title" translatable="yes">picture</property> - <child> - <object class="GtkCellRendererPixbuf"/> - <attributes> - <attribute name="stock-id">0</attribute> - </attributes> - </child> - </object> - </child> - <child> - <object class="GtkTreeViewColumn"> - <property name="title" translatable="yes">string</property> - <child> - <object class="GtkCellRendererText"/> - <attributes> - <attribute name="markup">1</attribute> - </attributes> - </child> - </object> - </child> - </object> - </child> - </object> - </child> - <child type="titlebar"> - <placeholder/> - </child> - </object> -</interface> diff --git a/src/gui/panels/logs-col-icon.ui b/src/gui/panels/logs-col-icon.ui new file mode 100644 index 0000000..6463e84 --- /dev/null +++ b/src/gui/panels/logs-col-icon.ui @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + + <template class="GtkListItem"> + <property name="child"> + <object class="GtkImage"> + <binding name="icon-name"> + <lookup name="icon-name" type="GLogEntry"> + <lookup name="item">GtkListItem</lookup> + </lookup> + </binding> + </object> + </property> + + </template> + +</interface> diff --git a/src/gui/panels/logs-col-message.ui b/src/gui/panels/logs-col-message.ui new file mode 100644 index 0000000..49839e4 --- /dev/null +++ b/src/gui/panels/logs-col-message.ui @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + + <template class="GtkListItem"> + <property name="child"> + <object class="GtkLabel"> + <property name="xalign">0</property> + <property name="use-markup">true</property> + <binding name="label"> + <lookup name="message" type="GLogEntry"> + <lookup name="item">GtkListItem</lookup> + </lookup> + </binding> + </object> + </property> + + </template> + +</interface> diff --git a/src/gui/panels/logs-int.h b/src/gui/panels/logs-int.h new file mode 100644 index 0000000..692c1b4 --- /dev/null +++ b/src/gui/panels/logs-int.h @@ -0,0 +1,53 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * logs-int.h - prototypes internes pour le panneau d'affichage des messages système + * + * Copyright (C) 2025 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _GUI_PANELS_LOGS_INT_H +#define _GUI_PANELS_LOGS_INT_H + + +#include "logs.h" +#include "../../gtkext/panel-int.h" + + + +/* Panneau d'affichage de messages (instance) */ +struct _GtkLogsPanel +{ + GtkTiledPanel parent; /* A laisser en premier */ + + GListStore *store; /* Liste des eléments conservés*/ + GtkWidget *list; /* Composant d'affichage */ + +}; + +/* Panneau d'affichage de messages (classe) */ +struct _GtkLogsPanelClass +{ + GtkTiledPanelClass parent; /* A laisser en premier */ + +}; + + + +#endif /* _GUI_PANELS_LOGS_INT_H */ diff --git a/src/gui/panels/logs.c b/src/gui/panels/logs.c new file mode 100644 index 0000000..399c4c0 --- /dev/null +++ b/src/gui/panels/logs.c @@ -0,0 +1,227 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * logs.c - panneau d'affichage des messages système + * + * Copyright (C) 2012-2025 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "logs.h" + + +#include <assert.h> +#include <string.h> + + +#include "logs-int.h" +#include "../../gtkext/helpers.h" + + + +/* ------------------------- COEUR D'UN PANNEAU D'AFFICHAGE ------------------------- */ + + +/* Initialise la classe des panneaux d'affichage des journaux. */ +static void gtk_logs_panel_class_init(GtkLogsPanelClass *); + +/* Initialise une instance de panneau d'affichage des journaux. */ +static void gtk_logs_panel_init(GtkLogsPanel *); + +/* Supprime toutes les références externes. */ +static void gtk_logs_panel_dispose(GObject *); + +/* Procède à la libération totale de la mémoire. */ +static void gtk_logs_panel_finalize(GObject *); + + + +/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */ + + +/* Indique l'emplacement par défaut pour un affichage. */ +static char *gtk_logs_panel_get_default_path(const GtkTiledPanel *); + + + +/* ---------------------------------------------------------------------------------- */ +/* COEUR D'UN PANNEAU D'AFFICHAGE */ +/* ---------------------------------------------------------------------------------- */ + + +/* Indique le type défini pour un panneau d'accueil. */ +G_DEFINE_TYPE(GtkLogsPanel, gtk_logs_panel, GTK_TYPE_TILED_PANEL); + + +/****************************************************************************** +* * +* Paramètres : class = classe à initialiser. * +* * +* Description : Initialise la classe des panneaux d'affichage des journaux. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_logs_panel_class_init(GtkLogsPanelClass *class) +{ + GObjectClass *object; /* Autre version de la classe */ + GtkWidgetClass *widget; /* Classe de haut niveau */ + GtkTiledPanelClass *panel; /* Classe parente */ + + object = G_OBJECT_CLASS(class); + + object->dispose = gtk_logs_panel_dispose; + object->finalize = gtk_logs_panel_finalize; + + widget = GTK_WIDGET_CLASS(class); + + g_type_ensure(G_TYPE_LOG_ENTRY); + + gtk_widget_class_set_template_from_resource(widget, "/re/chrysalide/framework/gui/panels/logs.ui"); + + //gtk_widget_class_bind_template_callback_full(widget, BUILDER_CB(gtk_logs_panel_on_selected_rows_changed)); + + gtk_widget_class_bind_template_child(widget, GtkLogsPanel, store); + gtk_widget_class_bind_template_child(widget, GtkLogsPanel, list); + + panel = GTK_TILED_PANEL_CLASS(class); + + panel->get_default_path = gtk_logs_panel_get_default_path; + +} + + +/****************************************************************************** +* * +* Paramètres : panel = instance à initialiser. * +* * +* Description : Initialise une instance de panneau d'affichage des journaux. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_logs_panel_init(GtkLogsPanel *panel) +{ + GtkWidget *headers; /* Composant à cacher */ + + gtk_widget_init_template(GTK_WIDGET(panel)); + + /** + * Retrait des entêtes de colonne de l'affichage. + */ + + headers = gtk_widget_get_first_child(panel->list); + + gtk_widget_set_visible(headers, FALSE); + +} + + +/****************************************************************************** +* * +* Paramètres : object = instance d'objet GLib à traiter. * +* * +* Description : Supprime toutes les références externes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_logs_panel_dispose(GObject *object) +{ + gtk_widget_dispose_template(GTK_WIDGET(object), GTK_TYPE_LOGS_PANEL); + + G_OBJECT_CLASS(gtk_logs_panel_parent_class)->dispose(object); + +} + + +/****************************************************************************** +* * +* Paramètres : object = instance d'objet GLib à traiter. * +* * +* Description : Procède à la libération totale de la mémoire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_logs_panel_finalize(GObject *object) +{ + G_OBJECT_CLASS(gtk_logs_panel_parent_class)->finalize(object); + +} + + +/****************************************************************************** +* * +* Paramètres : panel = instance d'objet GLib à traiter. * +* entry = élément de journalisation à intégrer. * +* * +* Description : Affiche un message dans le journal des messages système. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_log_panel_add_message(GtkLogsPanel *panel, GLogEntry *entry) +{ + g_list_store_append(panel->store, entry); + +} + + + +/* ---------------------------------------------------------------------------------- */ +/* IMPLEMENTATION DES FONCTIONS DE CLASSE */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : panel = panneau graphique à consulter. * +* * +* Description : Indique l'emplacement par défaut pour un affichage. * +* * +* Retour : Chemin représenté ou NULL pour l'emplacement "M" par défaut. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static char *gtk_logs_panel_get_default_path(const GtkTiledPanel *panel) +{ + char *result; /* Chemin à retourner */ + + result = strdup("S"); + + return result; + +} diff --git a/src/gui/panels/logs.h b/src/gui/panels/logs.h new file mode 100644 index 0000000..a8b902b --- /dev/null +++ b/src/gui/panels/logs.h @@ -0,0 +1,47 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * logs.h - prototypes pour le panneau d'affichage des messages système + * + * Copyright (C) 2012-2025 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _GUI_PANELS_LOGS_H +#define _GUI_PANELS_LOGS_H + + +#include <gtk/gtk.h> + + +#include "../../glibext/helpers.h" +#include "../../glibext/log.h" + + + +#define GTK_TYPE_LOGS_PANEL (gtk_logs_panel_get_type()) + +DECLARE_GTYPE(GtkLogsPanel, gtk_logs_panel, GTK, LOGS_PANEL); + + +/* Affiche un message dans le journal des messages système. */ +void g_log_panel_add_message(GtkLogsPanel *, GLogEntry *); + + + +#endif /* _GUI_PANELS_LOGS_H */ diff --git a/src/gui/panels/logs.ui b/src/gui/panels/logs.ui new file mode 100644 index 0000000..ba920cd --- /dev/null +++ b/src/gui/panels/logs.ui @@ -0,0 +1,58 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + + <object class="GtkNoSelection" id="noselection"> + <property name="model"> + <object class="GListStore" id="store"> + <property name="item-type">GLogEntry</property> + </object> + </property> + </object> + + <template class="GtkLogsPanel" parent="GtkTiledPanel"> + + <child> + <object class="GtkScrolledWindow"> + <property name="hscrollbar-policy">automatic</property> + <property name="vscrollbar-policy">automatic</property> + <property name="hexpand">true</property> + <property name="vexpand">true</property> + <property name="has-frame">0</property> + + <child> + <object class="GtkColumnView" id="list"> + <property name="vexpand">true</property> + <property name="model">noselection</property> + + <child> + <object class="GtkColumnViewColumn"> + <property name="title"></property> + <property name="factory"> + <object class="GtkBuilderListItemFactory"> + <property name="resource">/re/chrysalide/framework/gui/panels/logs-col-icon.ui</property> + </object> + </property> + </object> + </child> + + <child> + <object class="GtkColumnViewColumn"> + <property name="expand">true</property> + <property name="title">Message</property> + <property name="factory"> + <object class="GtkBuilderListItemFactory"> + <property name="resource">/re/chrysalide/framework/gui/panels/logs-col-message.ui</property> + </object> + </property> + </object> + </child> + + </object> + </child> + + </object> + </child> + + </template> + +</interface> diff --git a/src/gui/panels/welcome-hints.txt b/src/gui/panels/welcome-hints.txt new file mode 100644 index 0000000..a35ea64 --- /dev/null +++ b/src/gui/panels/welcome-hints.txt @@ -0,0 +1,23 @@ +Chrysalide's GUI offers launchers at startup in order to run main activities quickly. + +Once an activity is selected, options get displayed and allow some tunning before starting new processes. + +Such options are usually saved between runs. + + +There is no need to install Chrysalide on your system if you only want to give it a try. + +Just compile the source code and run the program from there. + + +Chrysalide can be used in external Python scripts by setting PYTHONPATH to the directory containing the 'pychrysalide.so' file. For instance: + + cd plugins/pychrysa/.libs/ + export PYTHONPATH=$PWD + +Then run the interpreter suitable to your configuration (debug or release): + + python3-dbg -c 'import pychrysalide ; print(pychrysalide.mod_version())' + + +All the configuration files for Chrysalide are located in $HOME/.config/chrysalide/.
\ No newline at end of file diff --git a/src/gui/panels/welcome-int.h b/src/gui/panels/welcome-int.h new file mode 100644 index 0000000..206bc2c --- /dev/null +++ b/src/gui/panels/welcome-int.h @@ -0,0 +1,61 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * welcome-int.h - prototypes internes pour le panneau d'accueil par défaut + * + * Copyright (C) 2024 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _GUI_PANELS_WELCOME_INT_H +#define _GUI_PANELS_WELCOME_INT_H + + +#include "welcome.h" +#include "../../gtkext/panel-int.h" + + + +/* Panneau d'accueil par défaut (instance) */ +struct _GtkWelcomePanel +{ + GtkTiledPanel parent; /* A laisser en premier */ + + GtkListBox *list; /* Liste de lanceurs */ + GtkStack *properties; /* Premières propriétés */ + + GtkWidget *def_child; /* Contenu par défaut */ + GtkLabel *hints; /* Affichage d'astuces du jour */ + GtkWidget *other_child; /* Autre contenu, alternatif */ + + gchar **raw_hints; /* Liste d'astuces */ + guint raw_count; /* Taille de cette liste */ + guint cur_hint; /* Position dans le parcours */ + +}; + +/* Panneau d'accueil par défaut (classe) */ +struct _GtkWelcomePanelClass +{ + GtkTiledPanelClass parent; /* A laisser en premier */ + +}; + + + +#endif /* _GUI_PANELS_WELCOME_INT_H */ diff --git a/src/gui/panels/welcome.c b/src/gui/panels/welcome.c index 60593d1..6e8763b 100644 --- a/src/gui/panels/welcome.c +++ b/src/gui/panels/welcome.c @@ -2,7 +2,7 @@ /* Chrysalide - Outil d'analyse de fichiers binaires * welcome.c - panneau d'accueil par défaut * - * Copyright (C) 2012-2019 Cyrille Bagard + * Copyright (C) 2012-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -26,130 +26,63 @@ #include <assert.h> -#include <malloc.h> -#include <stdbool.h> -#include <stdlib.h> -#include <string.h> -#include <i18n.h> - - -#include "../panel-int.h" -#include "../core/global.h" -#include "../../common/cpp.h" -#include "../../common/io.h" -#include "../../common/net.h" +#include "welcome-int.h" +#include "../core/panels.h" #include "../../common/shuffle.h" -#include "../../core/global.h" -#include "../../core/params.h" -#include "../../core/paths.h" -#include "../../gtkext/easygtk.h" -#include "../../gtkext/named.h" - - - -/* Panneau d'accueil par défaut (instance) */ -struct _GWelcomePanel -{ - GPanelItem parent; /* A laisser en premier */ +#include "../../gtkext/helpers.h" - cairo_surface_t *background; /* Fond pour astuces */ - char **tips; /* Liste de toutes les astuces */ - size_t count; /* Quantité d'astuces */ - size_t current; /* Indice de l'astuce courante */ - - bool uorigin; /* Origine de l'affichage */ - - gulong sig_id; /* Connexion par signal */ - -}; - -/* Panneau d'accueil par défaut (classe) */ -struct _GWelcomePanelClass -{ - GPanelItemClass parent; /* A laisser en premier */ -}; - - -/* Colonnes de la liste des messages */ -typedef enum _RecentProjectColumn -{ - RPC_VALID, /* Validité de l'entrée */ - RPC_FULLPATH, /* Chemin d'accès à un projet */ - - RPC_COUNT /* Nombre de colonnes */ - -} RecentProjectColumn; +/* ------------------------- COEUR D'UN PANNEAU D'AFFICHAGE ------------------------- */ /* Initialise la classe des panneaux d'accueil par défaut. */ -static void g_welcome_panel_class_init(GWelcomePanelClass *); +static void gtk_welcome_panel_class_init(GtkWelcomePanelClass *); /* Initialise une instance de panneau d'accueil par défaut. */ -static void g_welcome_panel_init(GWelcomePanel *); +static void gtk_welcome_panel_init(GtkWelcomePanel *); /* Supprime toutes les références externes. */ -static void g_welcome_panel_dispose(GWelcomePanel *); +static void gtk_welcome_panel_dispose(GObject *); /* Procède à la libération totale de la mémoire. */ -static void g_welcome_panel_finalize(GWelcomePanel *); +static void gtk_welcome_panel_finalize(GObject *); -/* Fournit le nom interne attribué à l'élément réactif. */ -static char *g_welcome_panel_class_get_key(const GWelcomePanelClass *); +/* Réagit à un changement de sélection de la liste de panneaux. */ +static void gtk_welcome_panel_on_selected_rows_changed(GtkListBox *, GtkWelcomePanel *); -/* Fournit une indication sur la personnalité du panneau. */ -static PanelItemPersonality g_welcome_panel_class_get_personality(const GWelcomePanelClass *); +/* Réagit à une demande d'affichage de l'astuce précédente. */ +static void gtk_welcome_panel_on_prev_hint_clicked(GtkButton *, GtkWelcomePanel *); -/* Indique le chemin initial de la localisation d'un panneau. */ -static char *g_welcome_panel_class_get_path(const GWelcomePanelClass *); +/* Réagit à une demande d'affichage de l'astuce suivante. */ +static void gtk_welcome_panel_on_next_hint_clicked(GtkButton *, GtkWelcomePanel *); -/* Place un panneau dans l'ensemble affiché. */ -static void g_welcome_panel_dock(GWelcomePanel *); -/* Charge l'ensemble des astuces. */ -static void g_welcome_panel_load_tips(GWelcomePanel *); -/* Assure le dessin du fond de la bulle d'astuce. */ -static gboolean on_tip_background_draw(GtkWidget *, cairo_t *, GWelcomePanel *); +/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */ -/* Réagit à la demande d'étude d'un nouveau binaire. */ -static void on_new_binary_clicked(GtkButton *, GWelcomePanel *); -/* Actualise au besoin la liste des projets récents. */ -static void on_recent_list_changed(GtkRecentManager *, GWelcomePanel *); -/* Recharge une liste à jour des projets récents. */ -static void g_welcome_panel_reload_project_list(GWelcomePanel *, GtkRecentManager *); -/* Réagit à une sélection décidée d'un projet particulier. */ -static void on_row_activated_for_projects(GtkTreeView *, GtkTreePath *, GtkTreeViewColumn *, GWelcomePanel *); -/* Enregistre les conditions d'affichage du panneau d'accueil. */ -static void on_startup_toggled(GtkToggleButton *, GWelcomePanel *); -/* Consulte les versions existantes et affiche une conclusion. */ -static void g_welcome_panel_check_version(GWelcomePanel *); -/* Affiche l'astuce précédente dans la liste globale. */ -static void on_tip_previous_clicked(GtkButton *, GWelcomePanel *); -/* Affiche l'astuce suivante dans la liste globale. */ -static void on_tip_next_clicked(GtkButton *, GWelcomePanel *); -/* Actualise l'affichage des astuces. */ -static void g_welcome_panel_refresh_tip(GWelcomePanel *); +/* ---------------------------------------------------------------------------------- */ +/* COEUR D'UN PANNEAU D'AFFICHAGE */ +/* ---------------------------------------------------------------------------------- */ /* Indique le type défini pour un panneau d'accueil. */ -G_DEFINE_TYPE(GWelcomePanel, g_welcome_panel, G_TYPE_PANEL_ITEM); +G_DEFINE_TYPE(GtkWelcomePanel, gtk_welcome_panel, GTK_TYPE_TILED_PANEL); /****************************************************************************** * * -* Paramètres : klass = classe à initialiser. * +* Paramètres : class = classe à initialiser. * * * * Description : Initialise la classe des panneaux d'accueil par défaut. * * * @@ -159,28 +92,28 @@ G_DEFINE_TYPE(GWelcomePanel, g_welcome_panel, G_TYPE_PANEL_ITEM); * * ******************************************************************************/ -static void g_welcome_panel_class_init(GWelcomePanelClass *klass) +static void gtk_welcome_panel_class_init(GtkWelcomePanelClass *class) { GObjectClass *object; /* Autre version de la classe */ - GEditorItemClass *item; /* Encore une autre vision... */ - GPanelItemClass *panel; /* Version parente de classe */ + GtkWidgetClass *widget; /* Classe de haut niveau */ - object = G_OBJECT_CLASS(klass); + object = G_OBJECT_CLASS(class); - object->dispose = (GObjectFinalizeFunc/* ! */)g_welcome_panel_dispose; - object->finalize = (GObjectFinalizeFunc)g_welcome_panel_finalize; + object->dispose = gtk_welcome_panel_dispose; + object->finalize = gtk_welcome_panel_finalize; - item = G_EDITOR_ITEM_CLASS(klass); + widget = GTK_WIDGET_CLASS(class); - item->get_key = (get_item_key_fc)g_welcome_panel_class_get_key; + gtk_widget_class_set_template_from_resource(widget, "/re/chrysalide/framework/gui/panels/welcome.ui"); - panel = G_PANEL_ITEM_CLASS(klass); + gtk_widget_class_bind_template_callback_full(widget, BUILDER_CB(gtk_welcome_panel_on_selected_rows_changed)); + gtk_widget_class_bind_template_callback_full(widget, BUILDER_CB(gtk_welcome_panel_on_prev_hint_clicked)); + gtk_widget_class_bind_template_callback_full(widget, BUILDER_CB(gtk_welcome_panel_on_next_hint_clicked)); - panel->get_personality = (get_panel_personality_fc)g_welcome_panel_class_get_personality; - panel->dock_at_startup = gtk_panel_item_class_return_false; - panel->get_path = (get_panel_path_fc)g_welcome_panel_class_get_path; - - panel->ack_dock = (ack_undock_process_fc)g_welcome_panel_dock; + gtk_widget_class_bind_template_child(widget, GtkWelcomePanel, list); + gtk_widget_class_bind_template_child(widget, GtkWelcomePanel, properties); + gtk_widget_class_bind_template_child(widget, GtkWelcomePanel, def_child); + gtk_widget_class_bind_template_child(widget, GtkWelcomePanel, hints); } @@ -197,93 +130,81 @@ static void g_welcome_panel_class_init(GWelcomePanelClass *klass) * * ******************************************************************************/ -static void g_welcome_panel_init(GWelcomePanel *panel) +static void gtk_welcome_panel_init(GtkWelcomePanel *panel) { - GPanelItem *pitem; /* Version parente du panneau */ - GtkBuilder *builder; /* Constructeur utilisé */ - GtkTreeView *treeview; /* Affichage de la liste */ - GtkCellRenderer *renderer; /* Moteur de rendu de colonne */ - GtkTreeViewColumn *column; /* Colonne de la liste */ - GtkToggleButton *button; /* Bouton à bascule à traiter */ - bool state; /* Etat de la coche à définir */ - gchar *filename; /* Chemin d'accès à une image */ - GtkRecentManager *manager; /* Gestionnaire global */ - - /* Eléments de base */ - - pitem = G_PANEL_ITEM(panel); - - pitem->widget = G_NAMED_WIDGET(gtk_built_named_widget_new_for_panel(_("Welcome"), - _("Welcome panel"), - PANEL_WELCOME_ID)); - - panel->uorigin = !gtk_panel_item_class_dock_at_startup(G_PANEL_ITEM_GET_CLASS(pitem)); + GBytes *bytes; /* Données brutes de ressource */ + const gchar *data; /* Données brutes natives */ + int min; /* Taille à gauche minimale */ + GtkConstraintLayout *layout; /* Disposition fixant la taille*/ + GtkConstraint *constraint; /* Contrainte à considérer */ - /* Représentation graphique */ + gtk_widget_init_template(GTK_WIDGET(panel)); - builder = gtk_built_named_widget_get_builder(GTK_BUILT_NAMED_WIDGET(pitem->widget)); + panel->other_child = NULL; - /* Liste des projets récents */ + /* Chargement des astuces */ - treeview = GTK_TREE_VIEW(gtk_builder_get_object(builder, "treeview")); + bytes = g_resources_lookup_data("/re/chrysalide/framework/gui/panels/welcome-hints.txt", + G_RESOURCE_LOOKUP_FLAGS_NONE, NULL); + assert(bytes != NULL); - column = gtk_tree_view_column_new(); - gtk_tree_view_append_column(treeview, column); - gtk_tree_view_set_expander_column(treeview, column); + data = g_bytes_get_data(bytes, NULL); - renderer = gtk_cell_renderer_text_new(); - gtk_tree_view_column_pack_start(column, renderer, TRUE); - gtk_tree_view_column_add_attribute(column, renderer, "markup", RPC_FULLPATH); + panel->raw_hints = g_strsplit(data, "\n\n\n", -1); - /* Affichage au démarrage ? */ + g_bytes_unref(bytes); - button = GTK_TOGGLE_BUTTON(gtk_builder_get_object(builder, "startup")); + panel->raw_count = g_strv_length(panel->raw_hints); + assert(panel->raw_count > 0); - g_generic_config_get_value(get_main_configuration(), MPK_WELCOME_STARTUP, &state); + panel->cur_hint = 0; - gtk_toggle_button_set_active(button, state); + /* Constitution de la liste des démarreurs */ - /* Chargement de l'image de fond */ + populate_framework_panel_launcher_list(panel->list); - filename = find_pixmap_file("tipoftheday.png"); + /* Dimensionnement de la zone d'astuces */ - panel->background = cairo_image_surface_create_from_png(filename); + gtk_widget_measure(GTK_WIDGET(panel->list), GTK_ORIENTATION_HORIZONTAL, -1, &min, NULL, NULL, NULL); - g_free(filename); + if (min > 150) + min -= 150; - /* Connexion des signaux */ + layout = GTK_CONSTRAINT_LAYOUT(gtk_widget_get_layout_manager(GTK_WIDGET(panel->hints))); - gtk_builder_add_callback_symbols(builder, - BUILDER_CALLBACK(on_tip_background_draw), - BUILDER_CALLBACK(on_new_binary_clicked), - BUILDER_CALLBACK(on_row_activated_for_projects), - BUILDER_CALLBACK(on_startup_toggled), - BUILDER_CALLBACK(on_tip_previous_clicked), - BUILDER_CALLBACK(on_tip_next_clicked), - NULL); + gtk_constraint_layout_remove_all_constraints(layout); - gtk_builder_connect_signals(builder, panel); + constraint = gtk_constraint_new_constant(NULL, + GTK_CONSTRAINT_ATTRIBUTE_LEFT, + GTK_CONSTRAINT_RELATION_EQ, + 0, + GTK_CONSTRAINT_STRENGTH_REQUIRED); + gtk_constraint_layout_add_constraint(layout, constraint); - g_object_unref(G_OBJECT(builder)); + constraint = gtk_constraint_new_constant(NULL, + GTK_CONSTRAINT_ATTRIBUTE_TOP, + GTK_CONSTRAINT_RELATION_EQ, + 0, + GTK_CONSTRAINT_STRENGTH_REQUIRED); + gtk_constraint_layout_add_constraint(layout, constraint); - /* Actualisation du contenu du panneau */ + constraint = gtk_constraint_new_constant(NULL, + GTK_CONSTRAINT_ATTRIBUTE_RIGHT, + GTK_CONSTRAINT_RELATION_EQ, + min, + GTK_CONSTRAINT_STRENGTH_REQUIRED); + gtk_constraint_layout_add_constraint(layout, constraint); - manager = get_project_manager(); + /* Premier affichage */ - panel->sig_id = g_signal_connect(manager, "changed", G_CALLBACK(on_recent_list_changed), panel); - - g_welcome_panel_reload_project_list(panel, manager); - - g_welcome_panel_load_tips(panel); - - g_welcome_panel_check_version(panel); + gtk_label_set_markup(panel->hints, panel->raw_hints[panel->cur_hint]); } /****************************************************************************** * * -* Paramètres : panel = instance d'objet GLib à traiter. * +* Paramètres : object = instance d'objet GLib à traiter. * * * * Description : Supprime toutes les références externes. * * * @@ -293,27 +214,24 @@ static void g_welcome_panel_init(GWelcomePanel *panel) * * ******************************************************************************/ -static void g_welcome_panel_dispose(GWelcomePanel *panel) +static void gtk_welcome_panel_dispose(GObject *object) { - GtkRecentManager *manager; /* Gestionnaire global */ + GtkWelcomePanel *panel; /* Version spécialisée */ - if (panel->sig_id > 0) - { - manager = get_project_manager(); + gtk_widget_dispose_template(GTK_WIDGET(object), GTK_TYPE_WELCOME_PANEL); - g_signal_handler_disconnect(manager, panel->sig_id); - panel->sig_id = 0; + panel = GTK_WELCOME_PANEL(object); - } + g_clear_object(&panel->other_child); - G_OBJECT_CLASS(g_welcome_panel_parent_class)->dispose(G_OBJECT(panel)); + G_OBJECT_CLASS(gtk_welcome_panel_parent_class)->dispose(object); } /****************************************************************************** * * -* Paramètres : panel = instance d'objet GLib à traiter. * +* Paramètres : object = instance d'objet GLib à traiter. * * * * Description : Procède à la libération totale de la mémoire. * * * @@ -323,133 +241,25 @@ static void g_welcome_panel_dispose(GWelcomePanel *panel) * * ******************************************************************************/ -static void g_welcome_panel_finalize(GWelcomePanel *panel) +static void gtk_welcome_panel_finalize(GObject *object) { - cairo_surface_destroy(panel->background); + GtkWelcomePanel *panel; /* Version spécialisée */ - free(panel->tips); + panel = GTK_WELCOME_PANEL(object); - G_OBJECT_CLASS(g_welcome_panel_parent_class)->finalize(G_OBJECT(panel)); + g_strfreev(panel->raw_hints); -} - - -/****************************************************************************** -* * -* Paramètres : class = classe à consulter. * -* * -* Description : Fournit le nom interne attribué à l'élément réactif. * -* * -* Retour : Désignation (courte) de l'élément de l'éditeur. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static char *g_welcome_panel_class_get_key(const GWelcomePanelClass *class) -{ - char *result; /* Description à renvoyer */ - - result = strdup(PANEL_WELCOME_ID); - - return result; + G_OBJECT_CLASS(gtk_welcome_panel_parent_class)->finalize(object); } /****************************************************************************** * * -* Paramètres : class = classe à consulter. * -* * -* Description : Fournit une indication sur la personnalité du panneau. * +* Paramètres : box = liste GTK concernée par l'appel. * +* panel = panneau d'accueil lié à la liste. * * * -* Retour : Identifiant lié à la nature unique du panneau. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PanelItemPersonality g_welcome_panel_class_get_personality(const GWelcomePanelClass *class) -{ - PanelItemPersonality result; /* Personnalité à retourner */ - - result = PIP_PERSISTENT_SINGLETON; - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : class = classe à consulter. * -* * -* Description : Indique le chemin initial de la localisation d'un panneau. * -* * -* Retour : Chemin fixé associé à la position initiale. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static char *g_welcome_panel_class_get_path(const GWelcomePanelClass *class) -{ - char *result; /* Emplacement à retourner */ - - result = strdup("M"); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Crée un panneau d'accueil par défaut. * -* * -* Retour : Adresse de la structure mise en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GPanelItem *g_welcome_panel_new(void) -{ - GPanelItem *result; /* Structure à retourner */ - - result = g_object_new(G_TYPE_WELCOME_PANEL, NULL); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : panel = composant à présenter à l'affichage. * -* * -* Description : Place un panneau dans l'ensemble affiché. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_welcome_panel_dock(GWelcomePanel *panel) -{ - g_welcome_panel_set_user_origin(panel, true); - -} - - -/****************************************************************************** -* * -* Paramètres : panel = panneau d'accueil à mettre à jour. * -* * -* Description : Charge l'ensemble des astuces. * +* Description : Réagit à un changement de sélection de la liste de panneaux. * * * * Retour : - * * * @@ -457,414 +267,58 @@ static void g_welcome_panel_dock(GWelcomePanel *panel) * * ******************************************************************************/ -static void g_welcome_panel_load_tips(GWelcomePanel *panel) +static void gtk_welcome_panel_on_selected_rows_changed(GtkListBox *box, GtkWelcomePanel *panel) { - size_t i; /* Boucle de parcours */ - - char *tips[] = { - - _("There is no need to install Chrysalide on your system if you only want to give it a try.\n\n" - "Just compile the source code and run the program from there."), - - _("Chrysalide can be used in external Python scripts by setting PYTHONPATH to the directory " - "containing the 'pychrysalide.so' file. For instance:\n\n" - " cd plugins/pychrysa/.libs/\n" - " export PYTHONPATH=$PWD\n\n" - "Then run the interpreter suitable to your configuration (debug or release):\n\n" - " python3-dbg -c 'import pychrysalide ; print(pychrysalide.mod_version())'"), - - _("All the configuration files for Chrysalide are located in $HOME/.config/chrysalide/."), - - _("The behavior of the main menu bar is copied from the one of a well known browser " - "with a fox mascot.\n\n" - "To make the menu bar appear and disappear, just press and release the Alt key.") - - }; - - panel->count = ARRAY_SIZE(tips); - - panel->tips = (char **)calloc(panel->count, sizeof(char *)); - - for (i = 0; i < panel->count; i++) - panel->tips[i] = tips[i]; - - shuffle(panel->tips, panel->count, sizeof(char *)); - - panel->current = 0; - - g_welcome_panel_refresh_tip(panel); - -} - - -/****************************************************************************** -* * -* Paramètres : widget = composant graphique à redessiner. * -* cr = contexte graphique à utiliser. * -* panel = panneau associé comportant des informations utiles. * -* * -* Description : Assure le dessin du fond de la bulle d'astuce. * -* * -* Retour : FALSE pour poursuivre la propagation de l'événement. * -* * -* Remarques : - * -* * -******************************************************************************/ + GtkListBoxRow *row; /* Ligne sélectionnée */ + GtkWidget *new; /* Nouvelles propriétés */ -static gboolean on_tip_background_draw(GtkWidget *widget, cairo_t *cr, GWelcomePanel *panel) -{ - int wgt_width; /* Largeur disponible totale */ - int wgt_height; /* Hauteur disponible totale */ - int img_width; /* Largeur de l'image de fond */ - int img_height; /* Hauteur de l'image de fond */ - double scale; /* Echelle à appliquer */ + row = gtk_list_box_get_selected_row(box); - if (cairo_surface_status(panel->background) == CAIRO_STATUS_SUCCESS) + /** + * Perte de sélection : bascule sur les informations d'accueil. + */ + if (row == NULL) { - wgt_width = gtk_widget_get_allocated_width(widget); - wgt_height = gtk_widget_get_allocated_height(widget); - - img_width = cairo_image_surface_get_width(panel->background); - img_height = cairo_image_surface_get_height(panel->background); + assert(panel->other_child != NULL); - scale = wgt_height / (2.0 * img_height); + gtk_stack_set_visible_child(panel->properties, panel->def_child); - cairo_scale(cr, scale, scale); - - cairo_set_source_surface(cr, panel->background, - (wgt_width / scale) - img_width, - ((wgt_height / scale) - img_height) / 2); - - cairo_paint(cr); + gtk_stack_remove(panel->properties, panel->other_child); + panel->other_child = NULL; } - return FALSE; - -} - - -/****************************************************************************** -* * -* Paramètres : button = bouton impliqué dans la procédure. * -* panel = panneau associé comportant des informations utiles. * -* * -* Description : Réagit à la demande d'étude d'un nouveau binaire. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void on_new_binary_clicked(GtkButton *button, GWelcomePanel *panel) -{ - GObject *ref; /* Espace de référencements */ - GtkMenuItem *item; /* Elément de menu simulé */ - - ref = G_OBJECT(get_editor_window()); - - item = GTK_MENU_ITEM(g_object_get_data(ref, "mnu_project_add_binary")); - - g_object_unref(ref); - - gtk_menu_item_activate(item); - -} - - -/****************************************************************************** -* * -* Paramètres : manager = gestion de fichiers récemment utilisés. * -* panel = panneau associé comportant des informations utiles.* -* * -* Description : Actualise au besoin la liste des projets récents. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void on_recent_list_changed(GtkRecentManager *manager, GWelcomePanel *panel) -{ - g_welcome_panel_reload_project_list(panel, manager); - -} - - -/****************************************************************************** -* * -* Paramètres : panel = panneau comportant des informations utiles. * -* manager = gestion de fichiers récemment utilisés. * -* * -* Description : Recharge une liste à jour des projets récents. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_welcome_panel_reload_project_list(GWelcomePanel *panel, GtkRecentManager *manager) -{ - GtkBuilder *builder; /* Constructeur utilisé */ - GtkListStore *store; /* Modèle de gestion */ - bool empty; /* Liste vide ? */ - GList *recents; /* Liste des fichiers récents */ - GList *recent; /* Elément à traiter */ - GtkRecentInfo *info; /* Informations sur l'élément */ - GtkTreeIter iter; /* Point d'insertion */ - - /* Réinitialisation */ - - builder = gtk_built_named_widget_get_builder(GTK_BUILT_NAMED_WIDGET(G_PANEL_ITEM(panel)->widget)); - - store = GTK_LIST_STORE(gtk_builder_get_object(builder, "store")); - - gtk_list_store_clear(store); - - empty = true; - - /* Chargement */ - - recents = gtk_recent_manager_get_items(manager); - - if (recents != NULL) - { - for (recent = g_list_first(recents); recent != NULL; recent = g_list_next(recent)) - { - info = recent->data; - - if (strcmp(gtk_recent_info_get_mime_type(info), "application/chrysalide.project") == 0) - { - gtk_list_store_append(store, &iter); - - gtk_list_store_set(store, &iter, - RPC_VALID, true, - RPC_FULLPATH, gtk_recent_info_get_uri_display(info), - -1); - - empty = false; - - } - - gtk_recent_info_unref(info); - - } - - g_list_free(recents); - - } - - /* Indication par défaut */ - if (empty) - { - gtk_list_store_append(store, &iter); - - gtk_list_store_set(store, &iter, - RPC_VALID, false, - RPC_FULLPATH, _("<i>(No recent project)</i>"), - -1); - - } - - g_object_unref(G_OBJECT(builder)); - -} - - -/****************************************************************************** -* * -* Paramètres : treeview = liste graphique concernée par la procédure. * -* path = chemin d'accès à la ligne sélectionnée. * -* column = colonne concernée par la sélection. * -* panel = panneau associé avec des informations utiles. * -* * -* Description : Réagit à une sélection décidée d'un projet particulier. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void on_row_activated_for_projects(GtkTreeView *treeview, GtkTreePath *path, GtkTreeViewColumn *column, GWelcomePanel *panel) -{ - GtkTreeModel *model; /* Modèle de gestion */ - GtkTreeIter iter; /* Point de la consultation */ - gboolean valid; /* Validité de l'entrée */ - gchar *filename; /* Chemin d'accès au projet */ - GStudyProject *project; /* Nouveau projet à ouvrir */ - - model = gtk_tree_view_get_model(treeview); - - if (gtk_tree_model_get_iter(model, &iter, path)) + /** + * Bascule vers une nouvelle fenêtre. + */ + else { - gtk_tree_model_get(model, &iter, RPC_VALID, &valid, RPC_FULLPATH, &filename, -1); + new = get_framework_panel_parameters(row); + assert(new != NULL); - if (valid) + if (new != panel->other_child) { - project = g_study_project_open(filename, true); - - if (project != NULL) - { - set_current_project(project); - - push_project_into_recent_list(project); - - } - - g_free(filename); - - } - - } - -} - - -/****************************************************************************** -* * -* Paramètres : button = bouton de défilement des astuces activé; * -* panel = panneau associé comportant des informations utiles. * -* * -* Description : Enregistre les conditions d'affichage du panneau d'accueil. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void on_startup_toggled(GtkToggleButton *button, GWelcomePanel *panel) -{ - g_generic_config_set_value(get_main_configuration(), - MPK_WELCOME_STARTUP, gtk_toggle_button_get_active(button)); - -} - - -/****************************************************************************** -* * -* Paramètres : panel = panneau d'accueil à mettre à jour. * -* * -* Description : Consulte les versions existantes et affiche une conclusion. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_welcome_panel_check_version(GWelcomePanel *panel) -{ - bool skip; /* Saut de la vérification */ - bool unknown; /* Impossibilité de comparaison*/ - int current; /* Version courante */ - int sock; /* Canal de communication */ - bool status; /* Bilan d'une communication */ - char buffer[1024]; /* Tampon de réception */ - size_t got; /* Quantité de données reçues */ - char *version; /* Version récupérée */ - int available; /* Version disponible */ - GtkBuilder *builder; /* Constructeur utilisé */ - GtkLabel *label; /* Etiquette à éditer */ - char *msg; /* Message à faire paraître */ - - g_generic_config_get_value(get_main_configuration(), MPK_WELCOME_CHECK, &skip); - skip = !skip; - - unknown = true; - - current = atoi(VERSION); - - if (skip) goto check_process; - - /* Recherche en ligne */ + gtk_stack_add_child(panel->properties, new); + gtk_stack_set_visible_child(panel->properties, new); - sock = connect_via_tcp("www.chrysalide.re", "80", NULL); - if (sock == -1) goto check_process; + if (panel->other_child != NULL) + gtk_stack_remove(panel->properties, panel->other_child); -#define REQUEST "GET /version.last HTTP/1.1\r\nHost: www.chrysalide.re\r\n\r\n" - - status = safe_send(sock, REQUEST, strlen(REQUEST), 0); - if (!status) goto check_done; - - status = recv_all(sock, buffer, sizeof(buffer), &got); - if (!status) goto check_done; - - version = strstr(buffer, "\r\n\r\n"); - - if (version != NULL) - { - available = atoi(version + 4); - - unknown = false; - - } - - check_done: - - close(sock); - - check_process: - - /* Affichage */ - - builder = gtk_built_named_widget_get_builder(GTK_BUILT_NAMED_WIDGET(G_PANEL_ITEM(panel)->widget)); - - label = GTK_LABEL(gtk_builder_get_object(builder, "version")); - - if (skip) - asprintf(&msg, - "Your version is: <b>%d</b>\n\n" \ - "Automatic version check is disabled.", - current); - - else - { - if (unknown) - asprintf(&msg, - "Your version is: <b>%d</b>\n\n" \ - "Lastest available version is unknown.", - current); - - else - { - if (current >= available) - asprintf(&msg, - "Your version is: <b>%d</b>\n\n" \ - "Lastest version is: <b>%d</b>\n\n" \ - "Your software is <span color='green'><b>up-to-date</b></span>.", - current, available); - - else - asprintf(&msg, - "Your version is: <b>%d</b>\n\n" \ - "Lastest version is: <b>%d</b>\n\n" \ - "Your software is <span color='red'><b>outdated</b></span>.", - current, available); + panel->other_child = new; } } - gtk_label_set_markup(label, msg); - - free(msg); - - g_object_unref(G_OBJECT(builder)); - } /****************************************************************************** * * -* Paramètres : button = bouton de défilement des astuces activé; * -* panel = panneau associé comportant des informations utiles. * +* Paramètres : button = bouton GTK concerné par l'appel. * +* panel = panneau d'accueil lié à la liste. * * * -* Description : Affiche l'astuce précédente dans la liste globale. * +* Description : Réagit à une demande d'affichage de l'astuce précédente. * * * * Retour : - * * * @@ -872,24 +326,24 @@ static void g_welcome_panel_check_version(GWelcomePanel *panel) * * ******************************************************************************/ -static void on_tip_previous_clicked(GtkButton *button, GWelcomePanel *panel) +static void gtk_welcome_panel_on_prev_hint_clicked(GtkButton *button, GtkWelcomePanel *panel) { - if (panel->current > 0) - panel->current--; + if (panel->cur_hint > 0) + panel->cur_hint--; else - panel->current = panel->count - 1; + panel->cur_hint = panel->raw_count - 1; - g_welcome_panel_refresh_tip(panel); + gtk_label_set_markup(panel->hints, panel->raw_hints[panel->cur_hint]); } /****************************************************************************** * * -* Paramètres : button = bouton de défilement des astuces activé; * -* panel = panneau associé comportant des informations utiles. * +* Paramètres : button = bouton GTK concerné par l'appel. * +* panel = panneau d'accueil lié à la liste. * * * -* Description : Affiche l'astuce suivante dans la liste globale. * +* Description : Réagit à une demande d'affichage de l'astuce suivante. * * * * Retour : - * * * @@ -897,82 +351,27 @@ static void on_tip_previous_clicked(GtkButton *button, GWelcomePanel *panel) * * ******************************************************************************/ -static void on_tip_next_clicked(GtkButton *button, GWelcomePanel *panel) +static void gtk_welcome_panel_on_next_hint_clicked(GtkButton *button, GtkWelcomePanel *panel) { - if ((panel->current + 1) < panel->count) - panel->current++; + if ((panel->cur_hint + 1) < panel->raw_count) + panel->cur_hint++; else - panel->current = 0; + panel->cur_hint = 0; - g_welcome_panel_refresh_tip(panel); + gtk_label_set_markup(panel->hints, panel->raw_hints[panel->cur_hint]); } -/****************************************************************************** -* * -* Paramètres : panel = panneau associé comportant des informations utiles. * -* * -* Description : Actualise l'affichage des astuces. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ -static void g_welcome_panel_refresh_tip(GWelcomePanel *panel) -{ - GtkBuilder *builder; /* Constructeur utilisé */ - GtkLabel *label; /* Etiquette de présentation */ +/* ---------------------------------------------------------------------------------- */ +/* IMPLEMENTATION DES FONCTIONS DE CLASSE */ +/* ---------------------------------------------------------------------------------- */ - assert(panel->current < panel->count); - builder = gtk_built_named_widget_get_builder(GTK_BUILT_NAMED_WIDGET(G_PANEL_ITEM(panel)->widget)); - label = GTK_LABEL(gtk_builder_get_object(builder, "tip")); - gtk_label_set_markup(label, panel->tips[panel->current]); - g_object_unref(G_OBJECT(builder)); -} -/****************************************************************************** -* * -* Paramètres : panel = panneau associé comportant des informations utiles. * -* * -* Description : Indique l'origine de l'affichage du panneau d'accueil. * -* * -* Retour : true si l'affichage est le fait de l'utilisateur. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool g_welcome_panel_get_user_origin(const GWelcomePanel *panel) -{ - return panel->uorigin; - -} - - -/****************************************************************************** -* * -* Paramètres : panel = panneau associé comportant des informations utiles.* -* uorigin = true si l'affichage est le fait de l'utilisateur. * -* * -* Description : Détermine l'origine de l'affichage du panneau d'accueil. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void g_welcome_panel_set_user_origin(GWelcomePanel *panel, bool uorigin) -{ - panel->uorigin = uorigin; - -} diff --git a/src/gui/panels/welcome.h b/src/gui/panels/welcome.h index 5cdd6a1..d9ea18d 100644 --- a/src/gui/panels/welcome.h +++ b/src/gui/panels/welcome.h @@ -2,7 +2,7 @@ /* Chrysalide - Outil d'analyse de fichiers binaires * welcome.h - prototypes pour le panneau d'accueil par défaut * - * Copyright (C) 2012-2019 Cyrille Bagard + * Copyright (C) 2012-2024 Cyrille Bagard * * This file is part of Chrysalide. * @@ -26,42 +26,17 @@ #define _GUI_PANELS_WELCOME_H -#include <i18n.h> +#include <gtk/gtk.h> -#include "../panel.h" +#include "../../glibext/helpers.h" +#include "../../gtkext/panel.h" -#define PANEL_WELCOME_ID "welcome" +#define GTK_TYPE_WELCOME_PANEL (gtk_welcome_panel_get_type()) - -#define G_TYPE_WELCOME_PANEL g_welcome_panel_get_type() -#define G_WELCOME_PANEL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_welcome_panel_get_type(), GWelcomePanel)) -#define G_IS_WELCOME_PANEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_welcome_panel_get_type())) -#define G_WELCOME_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_WELCOME_PANEL, GWelcomePanelClass)) -#define G_IS_WELCOME_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_WELCOME_PANEL)) -#define G_WELCOME_PANEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_WELCOME_PANEL, GWelcomePanelClass)) - - -/* Panneau d'accueil par défaut (instance) */ -typedef struct _GWelcomePanel GWelcomePanel; - -/* Panneau d'accueil par défaut (classe) */ -typedef struct _GWelcomePanelClass GWelcomePanelClass; - - -/* Indique le type défini pour un panneau d'accueil. */ -GType g_welcome_panel_get_type(void); - -/* Crée un panneau d'accueil par défaut. */ -GPanelItem *g_welcome_panel_new(void); - -/* Indique l'origine de l'affichage du panneau d'accueil. */ -bool g_welcome_panel_get_user_origin(const GWelcomePanel *); - -/* Détermine l'origine de l'affichage du panneau d'accueil. */ -void g_welcome_panel_set_user_origin(GWelcomePanel *, bool); +DECLARE_GTYPE(GtkWelcomePanel, gtk_welcome_panel, GTK, WELCOME_PANEL); diff --git a/src/gui/panels/welcome.ui b/src/gui/panels/welcome.ui index d016907..c545b1d 100644 --- a/src/gui/panels/welcome.ui +++ b/src/gui/panels/welcome.ui @@ -1,245 +1,168 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- Generated with glade 3.18.3 --> <interface> - <requires lib="gtk+" version="3.12"/> - <object class="GtkImage" id="image1"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="stock">gtk-new</property> - <property name="icon_size">6</property> - </object> - <object class="GtkListStore" id="store"> - <columns> - <!-- column-name valid --> - <column type="gboolean"/> - <!-- column-name fullpath --> - <column type="gchararray"/> - </columns> - </object> - <object class="GtkOffscreenWindow" id="offscreenwindow1"> - <property name="can_focus">False</property> - <child> - <object class="GtkBox" id="box"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="homogeneous">True</property> - <child> - <object class="GtkBox" id="box2"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="margin_left">8</property> - <property name="margin_right">8</property> - <property name="margin_top">8</property> - <property name="margin_bottom">8</property> - <property name="orientation">vertical</property> - <property name="spacing">8</property> - <child> - <object class="GtkAlignment" id="alignment1"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="halign">center</property> - <property name="top_padding">180</property> - <property name="bottom_padding">30</property> - <child> - <object class="GtkButton" id="button1"> - <property name="label" translatable="yes">New binary...</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="image">image1</property> - <property name="image_position">top</property> - <property name="always_show_image">True</property> - <signal name="clicked" handler="on_new_binary_clicked" swapped="no"/> - </object> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label1"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="xalign">0</property> - <property name="label" translatable="yes">Last projects:</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">1</property> - </packing> - </child> - <child> - <object class="GtkTreeView" id="treeview"> - <property name="height_request">250</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="margin_left">8</property> - <property name="hexpand">True</property> - <property name="model">store</property> - <property name="headers_visible">False</property> - <property name="rules_hint">True</property> - <signal name="row-activated" handler="on_row_activated_for_projects" swapped="no"/> - <child internal-child="selection"> - <object class="GtkTreeSelection" id="treeview-selection1"/> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">2</property> - </packing> - </child> - <child> - <object class="GtkCheckButton" id="startup"> - <property name="label" translatable="yes">Show this panel at startup.</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <property name="halign">start</property> - <property name="valign">end</property> - <property name="vexpand">True</property> - <property name="xalign">0</property> - <property name="draw_indicator">True</property> - <signal name="toggled" handler="on_startup_toggled" swapped="no"/> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">3</property> - </packing> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> + + <template class="GtkWelcomePanel" parent="GtkTiledPanel"> <child> - <object class="GtkBox" id="box3"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="margin_left">8</property> - <property name="margin_right">8</property> - <property name="margin_top">8</property> - <property name="margin_bottom">8</property> - <property name="orientation">vertical</property> - <property name="spacing">8</property> - <child> - <object class="GtkBox" id="box4"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="homogeneous">True</property> + <object class="GtkScrolledWindow"> + <property name="hscrollbar-policy">automatic</property> + <property name="vscrollbar-policy">automatic</property> + <property name="hexpand">TRUE</property> + <property name="vexpand">TRUE</property> + <property name="has-frame">0</property> <child> - <object class="GtkLabel" id="version"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="opacity">0.81999999977648264</property> - <property name="use_markup">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label3"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="opacity">0.81999999999999995</property> - <property name="label" translatable="yes">Get access to the online documentation and stay tuned by visiting the official website : <a href="http://chrysalide.re">chrysalide.re</a> - -You can also follow Chrysalide on Twitter : <a href="http://twitter.com/chrysalide_ref">@chrysalide_ref</a></property> - <property name="use_markup">True</property> - <property name="wrap">True</property> - <property name="track_visited_links">False</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">1</property> - </packing> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="tip"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="xalign">0</property> - <property name="yalign">1</property> - <property name="xpad">8</property> - <property name="ypad">8</property> - <property name="label" translatable="yes">label</property> - <property name="wrap">True</property> - <property name="selectable">True</property> - <signal name="draw" handler="on_tip_background_draw" swapped="no"/> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">1</property> - </packing> - </child> - <child> - <object class="GtkButtonBox" id="buttonbox1"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="spacing">8</property> - <property name="layout_style">end</property> - <child> - <object class="GtkButton" id="button3"> - <property name="label" translatable="yes">Previous</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <signal name="clicked" handler="on_tip_previous_clicked" swapped="no"/> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkButton" id="button2"> - <property name="label" translatable="yes">Next</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <signal name="clicked" handler="on_tip_next_clicked" swapped="no"/> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">1</property> - </packing> + <object class="GtkGrid"> + <property name="halign">center</property> + <property name="valign">center</property> + <property name="column-spacing">64</property> + <property name="column-homogeneous">TRUE</property> + <property name="margin-bottom">32</property> + <property name="margin-end">32</property> + <property name="margin-start">32</property> + <property name="margin-top">32</property> + + <!-- Launcher list --> + <child> + <object class="GtkListBox" id="list"> + <property name="halign">end</property> + <property name="valign">center</property> + <property name="selection-mode">GTK_SELECTION_SINGLE</property> + <property name="activate-on-single-click">0</property> + + <layout> + <property name="column">0</property> + <property name="row">0</property> + </layout> + + <style> + <class name="boxed-list"/> + <class name="frame"/> + </style> + + <signal name="selected-rows-changed" handler="gtk_welcome_panel_on_selected_rows_changed"/> + + </object> + </child> + + <!-- Hints / options --> + <child> + <object class="GtkStack" id="properties"> + <property name="halign">start</property> + <property name="valign">fill</property> + + <layout> + <property name="column">1</property> + <property name="row">0</property> + </layout> + + <child> + + <object class="GtkStackPage"> + <property name="name">default</property> + <property name="title">Welcome</property> + + <property name="child"> + <object class="GtkGrid" id="def_child"> + <property name="halign">start</property> + <property name="valign">fill</property> + <property name="column-spacing">16</property> + <property name="column-homogeneous">FALSE</property> + + <!-- Text --> + + <child> + <object class="GtkLabel" id="hints"> + <property name="halign">start</property> + <property name="valign">fill</property> + <property name="xalign">0</property> + <property name="yalign">1</property> + <property name="vexpand">1</property> + <property name="width-request">50</property> + <property name="wrap">TRUE</property> + + <property name="layout-manager"> + <object class="GtkConstraintLayout"> + <!-- + <constraints> + + <constraint target="super" target-attribute="left" + relation="eq" + constant="0" + strength="required"/> + + <constraint target="super" target-attribute="top" + relation="eq" + constant="0" + strength="required"/> + + <constraint target="super" target-attribute="right" + relation="eq" + constant="340" + strength="required"/> + + </constraints> + --> + </object> + </property> + + <layout> + <property name="column">0</property> + <property name="row">0</property> + </layout> + + </object> + </child> + + <!-- Prev/Next buttons --> + <child> + <object class="GtkBox"> + <property name="orientation">GTK_ORIENTATION_HORIZONTAL</property> + <property name="halign">fill</property> + <property name="valign">center</property> + <property name="homogeneous">TRUE</property> + <layout> + <property name="column">1</property> + <property name="row">1</property> + </layout> + + <child> + <object class="GtkButton"> + <property name="icon-name">go-previous-symbolic</property> + <property name="halign">end</property> + <signal name="clicked" handler="gtk_welcome_panel_on_prev_hint_clicked"/> + </object> + </child> + + <child> + <object class="GtkButton"> + <property name="icon-name">go-next-symbolic</property> + <property name="halign">start</property> + <signal name="clicked" handler="gtk_welcome_panel_on_next_hint_clicked"/> + </object> + </child> + + <style> + <class name="linked"/> + </style> + + </object> + </child> + + <style> + <class name="hints"/> + </style> + + </object> + + </property> + </object> + </child> + + </object> + </child> + </object> </child> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">2</property> - </packing> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">1</property> - </packing> + </object> </child> - </object> - </child> - </object> + </template> + </interface> diff --git a/src/gui/style.css b/src/gui/style.css new file mode 100644 index 0000000..dce41fa --- /dev/null +++ b/src/gui/style.css @@ -0,0 +1,71 @@ + +/* Extension de style */ + +.dim-label { + + margin-bottom: 4px; + +} + + +.boxed-widget { + + border-top-left-radius: 12px; + border-top-right-radius: 12px; + + border-bottom-left-radius: 12px; + border-bottom-right-radius: 12px; + +} + + +list.boxed-list, list.boxed-list > row:first-child { + + border-top-left-radius: 12px; + border-top-right-radius: 12px; + +} + +list.boxed-list, list.boxed-list > row:last-child { + + border-bottom-left-radius: 12px; + border-bottom-right-radius: 12px; + +} + + +/* about.css */ + +@import url('resource:///re/chrysalide/framework/gui/dialogs/about.css'); + + +/* welcome.css */ + +grid.hints { + + background-image: -gtk-icontheme('tipoftheday-symbolic'); + background-position: right top; + background-size: 200px auto; + background-repeat: no-repeat; + + min-height: 250px; + +} + +grid.hints > box { + + min-width: 130px; + +} + + +/* dockstation.css */ + +.control-button { + + min-height: 0; + min-width: 0; + + padding: 6px; + +} diff --git a/src/gui/window-int.h b/src/gui/window-int.h new file mode 100644 index 0000000..4f3dd57 --- /dev/null +++ b/src/gui/window-int.h @@ -0,0 +1,60 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * window.h - prototypes internes pour la construction d'une fenêtre graphique principale + * + * Copyright (C) 2024 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _GUI_WINDOW_INT_H +#define _GUI_WINDOW_INT_H + + +#include "window.h" +#include "../gtkext/grid.h" + + + +/* Définition de l'application principale graphique (instance) */ +struct _GtkFrameworkWindow +{ + GtkApplicationWindow parent; /* A laisser en premier */ + + GSettings *settings; /* Paramètres globaux */ + + GtkTilingGrid *grid; /* Réceptacle de panneaux */ + GtkStatusStack *status; /* Barre de statut */ + + GtkTiledPanel *main; /* Panneau principal courant */ + +}; + +/* Définition de l'application principale graphique (classe) */ +struct _GtkFrameworkWindowClass +{ + GtkApplicationWindowClass parent; /* A laisser en premier */ + +}; + + +/* Met en place une fenêtre principale pour Chrysalide. */ +bool gtk_framework_window_create(GtkFrameworkWindow *, GtkApplication *); + + + +#endif /* _GUI_WINDOW_INT_H */ diff --git a/src/gui/window.c b/src/gui/window.c new file mode 100644 index 0000000..e14ecf7 --- /dev/null +++ b/src/gui/window.c @@ -0,0 +1,621 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * window.c - construction d'une fenêtre graphique principale + * + * Copyright (C) 2024 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "window.h" + + +#include "window-int.h" +#include "core/panels.h" +#include "dialogs/about.h" +#include "dialogs/preferences.h" +#include "panels/logs.h" +#include "panels/welcome.h" +#include "../gtkext/grid.h" +#include "../gtkext/helpers.h" + + + +/* Initialise la classe des applications majeures de Chrysalide. */ +static void gtk_framework_window_class_init(GtkFrameworkWindowClass *); + +/* Initialise une application principale pour Chrysalide. */ +static void gtk_framework_window_init(GtkFrameworkWindow *); + +/* Supprime toutes les références externes. */ +static void gtk_framework_window_dispose(GObject *); + +/* Procède à la libération totale de la mémoire. */ +static void gtk_framework_window_finalize(GObject *); + +/* Bascule l'affichage d'un panneau de bordure. */ +static void gtk_framework_window_toggle_pannel_visibility(GtkFrameworkWindow *, TilingGridBorder); + +/* Réagit à une activation de bascule du panneau supérieur. */ +static void gtk_framework_window_activate_toggle_top(GSimpleAction *, GVariant *, gpointer); + +/* Réagit à une activation de bascule du panneau de gauche. */ +static void gtk_framework_window_activate_toggle_left(GSimpleAction *action, GVariant *, gpointer); + +/* Réagit à une activation de bascule du panneau de droite. */ +static void gtk_framework_window_activate_toggle_right(GSimpleAction *, GVariant *, gpointer); + +/* Réagit à une activation de bascule du panneau inférieur. */ +static void gtk_framework_window_activate_toggle_bottom(GSimpleAction *, GVariant *, gpointer); + +/* Réagit à une activation du menu "Préférences" de la fenetre. */ +static void gtk_framework_window_activate_preferences(GSimpleAction *, GVariant *, gpointer); + +/* Réagit à une activation du menu "A propos de" de la fenetre. */ +static void gtk_framework_window_activate_about(GSimpleAction *, GVariant *, gpointer); + + + +/* Indique le type défini pour une fenêtre graphique principale de Chrysalide. */ +G_DEFINE_TYPE(GtkFrameworkWindow, gtk_framework_window, GTK_TYPE_APPLICATION_WINDOW); + + +/****************************************************************************** +* * +* Paramètres : class = classe à initialiser. * +* * +* Description : Initialise la classe des applications majeures de Chrysalide.* +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_framework_window_class_init(GtkFrameworkWindowClass *class) +{ + GObjectClass *object; /* Plus haut niveau équivalent */ + GtkWidgetClass *widget; /* Classe de haut niveau */ + + object = G_OBJECT_CLASS(class); + + object->dispose = (GObjectFinalizeFunc/* ! */)gtk_framework_window_dispose; + object->finalize = (GObjectFinalizeFunc)gtk_framework_window_finalize; + + widget = GTK_WIDGET_CLASS(class); + + g_type_ensure(GTK_TYPE_TILING_GRID); + g_type_ensure(GTK_TYPE_STATUS_STACK); + + gtk_widget_class_set_template_from_resource(widget, "/re/chrysalide/framework/gui/window.ui"); + + gtk_widget_class_bind_template_child(widget, GtkFrameworkWindow, grid); + gtk_widget_class_bind_template_child(widget, GtkFrameworkWindow, status); + + /* Active une action native (cf. https://docs.gtk.org/gtk4/class.Window.html#actions) */ + gtk_widget_class_add_binding_action(widget, GDK_KEY_Q, GDK_CONTROL_MASK, "window.close", NULL); + + gtk_widget_class_add_binding_action(widget, GDK_KEY_comma, GDK_CONTROL_MASK, "win.preferences", NULL); + +} + + +/****************************************************************************** +* * +* Paramètres : window = instance à initialiser. * +* * +* Description : Initialise une application principale pour Chrysalide. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_framework_window_init(GtkFrameworkWindow *window) +{ + GAction *action; /* Action mise en place */ + + static GActionEntry app_entries[] = { + { "toggle-top", gtk_framework_window_activate_toggle_top, NULL, NULL, NULL }, + { "toggle-left", gtk_framework_window_activate_toggle_left, NULL, NULL, NULL }, + { "toggle-right", gtk_framework_window_activate_toggle_right, NULL, NULL, NULL }, + { "toggle-bottom", gtk_framework_window_activate_toggle_bottom, NULL, NULL, NULL }, + { "preferences", gtk_framework_window_activate_preferences, NULL, NULL, NULL }, + { "about", gtk_framework_window_activate_about, NULL, NULL, NULL }, + }; + + gtk_widget_init_template(GTK_WIDGET(window)); + + window->settings = g_settings_new(FRAMEWORK_WINDOW_ID); + + g_settings_bind(window->settings, "window-width", G_OBJECT(window), "default-width", G_SETTINGS_BIND_DEFAULT); + g_settings_bind(window->settings, "window-height", G_OBJECT(window), "default-height", G_SETTINGS_BIND_DEFAULT); + g_settings_bind(window->settings, "window-maximized", G_OBJECT(window), "maximized", G_SETTINGS_BIND_DEFAULT); + + window->main = NULL; + + g_action_map_add_action_entries(G_ACTION_MAP(window), + app_entries, G_N_ELEMENTS(app_entries), + window); + + /** + * Définition de l'accès aux actions pour obtenir un effet de bord sur + * l'accès aux boutons graphiques de déclenchement. + */ + + action = g_action_map_lookup_action(G_ACTION_MAP(window), "toggle-top"); + + g_object_bind_property(G_OBJECT(window->grid), "empty-top", + G_OBJECT(action), "enabled", + G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN); + + action = g_action_map_lookup_action(G_ACTION_MAP(window), "toggle-left"); + + g_object_bind_property(G_OBJECT(window->grid), "empty-left", + G_OBJECT(action), "enabled", + G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN); + + action = g_action_map_lookup_action(G_ACTION_MAP(window), "toggle-right"); + + g_object_bind_property(G_OBJECT(window->grid), "empty-right", + G_OBJECT(action), "enabled", + G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN); + + action = g_action_map_lookup_action(G_ACTION_MAP(window), "toggle-bottom"); + + g_object_bind_property(G_OBJECT(window->grid), "empty-bottom", + G_OBJECT(action), "enabled", + G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN); + +} + + +/****************************************************************************** +* * +* Paramètres : object = instance d'objet GLib à traiter. * +* * +* Description : Supprime toutes les références externes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_framework_window_dispose(GObject *object) +{ + GtkFrameworkWindow *window; /* Version spécialisée */ + + window = GTK_FRAMEWORK_WINDOW(object); + + gtk_widget_dispose_template(GTK_WIDGET(window), GTK_TYPE_FRAMEWORK_WINDOW); + + g_clear_object(&window->settings); + + g_clear_object(&window->main); + + G_OBJECT_CLASS(gtk_framework_window_parent_class)->dispose(object); + +} + + +/****************************************************************************** +* * +* Paramètres : object = instance d'objet GLib à traiter. * +* * +* Description : Procède à la libération totale de la mémoire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_framework_window_finalize(GObject *object) +{ + G_OBJECT_CLASS(gtk_framework_window_parent_class)->finalize(object); + +} + + +/****************************************************************************** +* * +* Paramètres : app = application GTK de rattachement. * +* * +* Description : Crée une nouvelle application principale pour Chrysalide. * +* * +* Retour : Mécanismes mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkApplicationWindow *gtk_framework_window_new(GtkApplication *app) +{ + GtkApplicationWindow *result; /* Instance à retourner */ + + result = g_object_new(GTK_TYPE_FRAMEWORK_WINDOW, NULL); + + if (!gtk_framework_window_create(GTK_FRAMEWORK_WINDOW(result), app)) + g_clear_object(&result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : window = instance de fenêtre principale à remplir. * +* app = application GTK de rattachement. * +* * +* Description : Met en place une fenêtre principale pour Chrysalide. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool gtk_framework_window_create(GtkFrameworkWindow *window, GtkApplication *app) +{ + bool result; /* Bilan à retourner */ + GtkTiledPanel *panel; /* Panneau d'affichage */ + GtkCssProvider *css; /* Feuille de style maison */ + + result = true; + + gtk_window_set_application(GTK_WINDOW(window), app); + + /* Inclusion d'un écran d'accueil */ + + panel = get_framework_panel_singleton(GTK_TYPE_WELCOME_PANEL); + + gtk_framework_window_add(window, panel); + + if (1/* FIXME : first time */) + { + panel = get_framework_panel_singleton(GTK_TYPE_LOGS_PANEL); + + gtk_framework_window_add(window, panel); + + } + + /* Chargement des extensions de thème */ + + css = gtk_css_provider_new(); + + gtk_css_provider_load_from_resource(css, "/re/chrysalide/framework/gtkext/hexview.css"); + + gtk_style_context_add_provider_for_display(gtk_widget_get_display(GTK_WIDGET(window)), + GTK_STYLE_PROVIDER(css), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + + unref_object(css); + + css = gtk_css_provider_new(); + + gtk_css_provider_load_from_resource(css, "/re/chrysalide/framework/gui/style.css"); + + gtk_style_context_add_provider_for_display(gtk_widget_get_display(GTK_WIDGET(window)), + GTK_STYLE_PROVIDER(css), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + + unref_object(css); + + /* Fin des chargements */ + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : window = instance de fenêtre principale à manipuler. * +* border = sélection de la zone à considérer. * +* * +* Description : Bascule l'affichage d'un panneau de bordure. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_framework_window_toggle_pannel_visibility(GtkFrameworkWindow *window, TilingGridBorder border) +{ + bool state; /* Etat courant à basculer */ + + state = gtk_tiling_grid_get_visible(window->grid, border); + + state = !state; + + gtk_tiling_grid_set_visible(window->grid, border, state); + +} + + +/****************************************************************************** +* * +* Paramètres : action = désignation de l'action concernée par l'appel. * +* unused = adresse non utilisée ici. * +* _window = instance de fenêtre principale à manipuler. * +* * +* Description : Réagit à une activation de bascule du panneau supérieur. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_framework_window_activate_toggle_top(GSimpleAction *action, GVariant *unused, gpointer _window) +{ + gtk_framework_window_toggle_pannel_visibility(_window, TGB_TOP); + +} + + +/****************************************************************************** +* * +* Paramètres : action = désignation de l'action concernée par l'appel. * +* unused = adresse non utilisée ici. * +* _window = instance de fenêtre principale à manipuler. * +* * +* Description : Réagit à une activation de bascule du panneau de gauche. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_framework_window_activate_toggle_left(GSimpleAction *action, GVariant *unused, gpointer _window) +{ + gtk_framework_window_toggle_pannel_visibility(_window, TGB_LEFT); + +} + + +/****************************************************************************** +* * +* Paramètres : action = désignation de l'action concernée par l'appel. * +* unused = adresse non utilisée ici. * +* _window = instance de fenêtre principale à manipuler. * +* * +* Description : Réagit à une activation de bascule du panneau de droite. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_framework_window_activate_toggle_right(GSimpleAction *action, GVariant *unused, gpointer _window) +{ + gtk_framework_window_toggle_pannel_visibility(_window, TGB_RIGHT); + +} + + +/****************************************************************************** +* * +* Paramètres : action = désignation de l'action concernée par l'appel. * +* unused = adresse non utilisée ici. * +* _window = instance de fenêtre principale à manipuler. * +* * +* Description : Réagit à une activation de bascule du panneau inférieur. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_framework_window_activate_toggle_bottom(GSimpleAction *action, GVariant *unused, gpointer _window) +{ + gtk_framework_window_toggle_pannel_visibility(_window, TGB_BOTTOM); + +} + + +/****************************************************************************** +* * +* Paramètres : action = désignation de l'action concernée par l'appel. * +* unused = adresse non utilisée ici. * +* _window = instance de fenêtre principale à manipuler. * +* * +* Description : Réagit à une activation du menu "Préférences" de la fenetre. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_framework_window_activate_preferences(GSimpleAction *action, GVariant *unused, gpointer _window) +{ + GtkFrameworkWindow *window; /* Fenêtre principale associée */ + GtkWindow *dialog; /* Boîte de dialogue à afficher*/ + + window = _window; + + dialog = gtk_preferences_dialog_new(GTK_WINDOW(window)); + + gtk_window_present(dialog); + +} + + +/****************************************************************************** +* * +* Paramètres : action = désignation de l'action concernée par l'appel. * +* unused = adresse non utilisée ici. * +* _window = instance de fenêtre principale à manipuler. * +* * +* Description : Réagit à une activation du menu "A propos de" de la fenetre. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_framework_window_activate_about(GSimpleAction *action, GVariant *unused, gpointer _window) +{ + GtkFrameworkWindow *window; /* Fenêtre principale associée */ + GtkWindow *dialog; /* Boîte de dialogue à afficher*/ + + window = _window; + + dialog = gtk_app_about_dialog_new(GTK_WINDOW(window)); + + gtk_window_present(dialog); + +} + + +/****************************************************************************** +* * +* Paramètres : window = instance de fenêtre principale à consulter. * +* * +* Description : Fournit une référence à la barre de statut intégrée. * +* * +* Retour : Composant GTK en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkStatusStack *gtk_framework_window_get_status_stack(const GtkFrameworkWindow *window) +{ + GtkStatusStack *result; /* Instance à retourner */ + + result = window->status; + ref_object(result); + + return result; + +} + + + +/****************************************************************************** +* * +* Paramètres : window = instance de fenêtre principale à remplir. * +* panel = nouveau panneau à afficher. * +* * +* Description : Ajoute un panneau à la fenêtre principale de Chrysalide. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void gtk_framework_window_add(GtkFrameworkWindow *window, /* __steal */GtkTiledPanel *panel) +{ + GtkWidget *bar; /* Barre de titre */ + GListStore *list; /* Liste éventuelle à intégrer */ + guint count; /* Nombre d'élements présents */ + guint i; /* Boucle de parcours */ + GtkWidget *widget; /* Composant à intégrer */ + FrameworkPanelPersonality personality; /* Propriétés du panneau */ + + + + gtk_tiling_grid_add_panel(window->grid, panel, G_OBJECT_TYPE(panel) == GTK_TYPE_WELCOME_PANEL); + + + + + bar = gtk_window_get_titlebar(GTK_WINDOW(window)); + + if (bar == NULL) ////////// REMME + { + bar = gtk_header_bar_new(); + gtk_window_set_titlebar(GTK_WINDOW(window), bar); + } ///////////////////////////// + + list = gtk_tiled_panel_get_title_widgets(panel, false); + + if (list != NULL) + { + count = g_list_model_get_n_items(G_LIST_MODEL(list)); + + for (i = 0; i < count; i++) + { + widget = GTK_WIDGET(g_list_model_get_item(G_LIST_MODEL(list), i)); + gtk_header_bar_pack_end(GTK_HEADER_BAR(bar), widget); + } + + unref_object(list); + + } + + /* Mise à jour des liens vers un panneau principal */ + + personality = get_framework_panel_personality(G_OBJECT_TYPE(panel)); + + if (personality & FPP_MAIN_PANEL) + gtk_framework_window_notify_new_main_panel_state(window, panel, true); + + else + { + if (window->main != NULL) + gtk_tiled_panel_notify_new_main_panel_state(panel, window->main, true); + } + +} + + +/****************************************************************************** +* * +* Paramètres : window = instance de fenêtre principale à manipuler. * +* main = panneau principal visé par l'opération. * +* activated = nature du changement de statut : ajout, retrait ?* +* * +* Description : Note un ajout ou un retrait de panneau principal. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void gtk_framework_window_notify_new_main_panel_state(GtkFrameworkWindow *window, GtkTiledPanel *main, bool activated) +{ + if (activated) + { + g_clear_object(&window->main); + + window->main = main; + ref_object(main); + + } + + else + { + if (main == window->main) + g_clear_object(&window->main); + + } + + gtk_tiling_grid_notify_new_main_panel_state(window->grid, main, activated); + +} diff --git a/src/gui/window.h b/src/gui/window.h new file mode 100644 index 0000000..077d51a --- /dev/null +++ b/src/gui/window.h @@ -0,0 +1,61 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * window.h - prototypes pour la construction d'une fenêtre graphique principale + * + * Copyright (C) 2024 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chrysalide. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _GUI_WINDOW_H +#define _GUI_WINDOW_H + + +#include <gtk/gtk.h> + + +#include "../glibext/helpers.h" +#include "../gtkext/panel.h" +#include "../gtkext/statusstack.h" + + + +/* Définition d'un identifiant unique */ +#define FRAMEWORK_WINDOW_ID "re.chrysalide.framework.gui" + + + +#define GTK_TYPE_FRAMEWORK_WINDOW (gtk_framework_window_get_type()) + +DECLARE_GTYPE(GtkFrameworkWindow, gtk_framework_window, GTK, FRAMEWORK_WINDOW); + + +/* Crée une nouvelle application principale pour Chrysalide. */ +GtkApplicationWindow *gtk_framework_window_new(GtkApplication *); + +/* Fournit une référence à la barre de statut intégrée. */ +GtkStatusStack *gtk_framework_window_get_status_stack(const GtkFrameworkWindow *); + +/* Ajoute un panneau à la fenêtre principale de Chrysalide. */ +void gtk_framework_window_add(GtkFrameworkWindow *, GtkTiledPanel *); + +/* Note un ajout ou un retrait de panneau principal. */ +void gtk_framework_window_notify_new_main_panel_state(GtkFrameworkWindow *, GtkTiledPanel *, bool); + + + +#endif /* _GUI_WINDOW_H */ diff --git a/src/gui/window.ui b/src/gui/window.ui new file mode 100644 index 0000000..1c6a89a --- /dev/null +++ b/src/gui/window.ui @@ -0,0 +1,79 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + + <menu id="main_menu_model"> + <section> + <item> + <attribute name="label" translatable="yes">Preferences</attribute> + <attribute name="action">win.preferences</attribute> + </item> + <item> + <attribute name="label" translatable="yes">About</attribute> + <attribute name="action">win.about</attribute> + </item> + </section> + </menu> + + <template class="GtkFrameworkWindow" parent="GtkApplicationWindow"> + <property name="title" translatable="no">Chrysalide</property> + <property name="default-width">800</property> + <property name="default-height">600</property> + <property name="icon-name">chrysalide-logo</property> + + <child type="titlebar"> + <object class="GtkHeaderBar"> + + <child type="start"> + <object class="GtkToggleButton"> + <property name="icon-name">dock-station-left-symbolic</property> + <property name="action-name">win.toggle-left</property> + <property name="active" bind-source="grid" bind-property="visible-left" bind-flags="sync-create"/> + </object> + </child> + + <child type="end"> + <object class="GtkToggleButton"> + <property name="icon-name">dock-station-right-symbolic</property> + <property name="action-name">win.toggle-right</property> + <property name="active" bind-source="grid" bind-property="visible-right" bind-flags="sync-create"/> + </object> + </child> + + <child type="end"> + <object class="GtkMenuButton"> + <property name="icon-name">open-menu-symbolic</property> + <property name="menu-model">main_menu_model</property> + </object> + </child> + + </object> + </child> + + <child> + <object class="GtkBox"> + <property name="orientation">vertical</property> + + <child> + <object class="GtkTilingGrid" id="grid"> + <property name="vexpand">TRUE</property> + </object> + </child> + + <child> + <object class="GtkSeparator"> + <property name="orientation">horizontal</property> + </object> + </child> + + <child> + <object class="GtkStatusStack" id="status"> + <property name="show-bottom" bind-source="grid" bind-property="visible-bottom" bind-flags="sync-create"/> + </object> + </child> + + </object> + </child> + + </template> + +</interface> |