From 0bec2b96a14da29a680aafe54895fd9cfb3bcf09 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Thu, 20 Feb 2025 22:37:10 +0100 Subject: Create a GTK widget to launch panels. --- src/gtkext/Makefile.am | 3 + src/gtkext/gresource.xml | 1 + src/gtkext/launcher-int.h | 56 +++++++++++ src/gtkext/launcher.c | 211 ++++++++++++++++++++++++++++++++++++++++ src/gtkext/launcher.h | 45 +++++++++ src/gtkext/launcher.ui | 76 +++++++++++++++ src/gui/panel-int.h | 11 ++- src/gui/panel.c | 4 +- src/gui/panel.h | 9 +- src/gui/panels/Makefile.am | 1 - src/gui/panels/binary-launch.ui | 65 ------------- src/gui/panels/binary.c | 23 +++-- src/gui/panels/gresource.xml | 1 - 13 files changed, 417 insertions(+), 89 deletions(-) create mode 100644 src/gtkext/launcher-int.h create mode 100644 src/gtkext/launcher.c create mode 100644 src/gtkext/launcher.h create mode 100644 src/gtkext/launcher.ui delete mode 100644 src/gui/panels/binary-launch.ui diff --git a/src/gtkext/Makefile.am b/src/gtkext/Makefile.am index c63a447..839ee8f 100644 --- a/src/gtkext/Makefile.am +++ b/src/gtkext/Makefile.am @@ -31,6 +31,7 @@ IMG_PATH = ../../data/images RES_FILES = \ hexview.css \ hexview.ui \ + launcher.ui \ statusstack.ui \ $(IMG_PATH)/nolock-symbolic.svg \ $(IMG_PATH)/locked-symbolic.svg \ @@ -51,6 +52,8 @@ libgtkext4_la_SOURCES = \ helpers.h \ hexview-int.h \ hexview.h hexview.c \ + launcher-int.h \ + launcher.h launcher.c \ panel-int.h \ panel.h panel.c \ resources.h resources.c \ diff --git a/src/gtkext/gresource.xml b/src/gtkext/gresource.xml index 60680b5..640985f 100644 --- a/src/gtkext/gresource.xml +++ b/src/gtkext/gresource.xml @@ -3,6 +3,7 @@ hexview.css hexview.ui + launcher.ui statusstack.ui tweak.ui diff --git a/src/gtkext/launcher-int.h b/src/gtkext/launcher-int.h new file mode 100644 index 0000000..07152f0 --- /dev/null +++ b/src/gtkext/launcher-int.h @@ -0,0 +1,56 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * tweak-int.h - définitions internes pour un lanceur de panneau majeur + * + * 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 . + */ + + +#ifndef _GTKEXT_LAUNCHER_INT_H +#define _GTKEXT_LAUNCHER_INT_H + + +#include "launcher.h" + + + +/* Elément de lancement d'un panneau majeur pour l'interface (instance) */ +struct _GtkPanelLauncher +{ + GtkListBoxRow parent; /* A laisser en premier */ + + GtkImage *icon; /* Eventuelle image */ + GtkLabel *title; /* Etiquette associée */ + GtkLabel *desc; /* Description du panneau */ + +}; + +/* Elément de lancement d'un panneau majeur pour l'interface (classe) */ +struct _GtkPanelLauncherClass +{ + GtkListBoxRowClass parent; /* A laisser en premier */ + +}; + + +/* Met en place un nouveau lanceur de panneau majeur. */ +bool gtk_panel_launcher_create(GtkPanelLauncher *, const char *, const char *, const char *); + + + +#endif /* _GTKEXT_LAUNCHER_INT_H */ diff --git a/src/gtkext/launcher.c b/src/gtkext/launcher.c new file mode 100644 index 0000000..5bb850b --- /dev/null +++ b/src/gtkext/launcher.c @@ -0,0 +1,211 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * launcher.c - lanceur de panneau majeur + * + * 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 . + */ + + +#include "launcher.h" + + +#include +#include + + +#include "helpers.h" +#include "launcher-int.h" +#include "../common/extstr.h" + + + +/* Initialise la classe des sections d'éléments paramétrables. */ +static void gtk_panel_launcher_class_init(GtkPanelLauncherClass *); + +/* Initialise une instance de lanceur de panneau majeur. */ +static void gtk_panel_launcher_init(GtkPanelLauncher *); + +/* Supprime toutes les références externes. */ +static void gtk_panel_launcher_dispose(GObject *); + +/* Procède à la libération totale de la mémoire. */ +static void gtk_panel_launcher_finalize(GObject *); + + + +/* Détermine le type du composant d'affichage générique. */ +G_DEFINE_TYPE(GtkPanelLauncher, gtk_panel_launcher, GTK_TYPE_LIST_BOX_ROW); + + +/****************************************************************************** +* * +* Paramètres : class = classe GTK à initialiser. * +* * +* Description : Initialise la classe des sections d'éléments paramétrables. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_panel_launcher_class_init(GtkPanelLauncherClass *class) +{ + GObjectClass *object; /* Plus haut niveau équivalent */ + GtkWidgetClass *widget; /* Classe de haut niveau */ + + object = G_OBJECT_CLASS(class); + + object->dispose = gtk_panel_launcher_dispose; + object->finalize = gtk_panel_launcher_finalize; + + widget = GTK_WIDGET_CLASS(class); + + gtk_widget_class_set_template_from_resource(widget, "/re/chrysalide/framework/gtkext/launcher.ui"); + + gtk_widget_class_bind_template_child(widget, GtkPanelLauncher, icon); + gtk_widget_class_bind_template_child(widget, GtkPanelLauncher, title); + gtk_widget_class_bind_template_child(widget, GtkPanelLauncher, desc); + +} + + +/****************************************************************************** +* * +* Paramètres : launcher = composant GTK à initialiser. * +* * +* Description : Initialise une instance de lanceur de panneau majeur. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_panel_launcher_init(GtkPanelLauncher *launcher) +{ + gtk_widget_init_template(GTK_WIDGET(launcher)); + +} + + +/****************************************************************************** +* * +* Paramètres : object = instance d'objet GLib à traiter. * +* * +* Description : Supprime toutes les références externes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_panel_launcher_dispose(GObject *object) +{ + gtk_widget_dispose_template(GTK_WIDGET(object), GTK_TYPE_PANEL_LAUNCHER); + + G_OBJECT_CLASS(gtk_panel_launcher_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_panel_launcher_finalize(GObject *object) +{ + G_OBJECT_CLASS(gtk_panel_launcher_parent_class)->finalize(object); + +} + + +/****************************************************************************** +* * +* Paramètres : icon = désignation de l'image de représentation. * +* title = titre principal à afficher. * +* desc = description du panneau ciblé. * +* * +* Description : Crée un nouveau lanceur de panneau majeur. * +* * +* Retour : Composant GTK mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkPanelLauncher *gtk_panel_launcher_new(const char *icon, const char *title, const char *desc) +{ + GtkPanelLauncher *result; /* Instance à retourner */ + + result = g_object_new(GTK_TYPE_PANEL_LAUNCHER, NULL); + + if (!gtk_panel_launcher_create(result, icon, title, desc)) + g_clear_object(&result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : launcher = lanceur à initialiser pleinement. * +* icon = désignation de l'image de représentation. * +* title = titre principal à afficher. * +* desc = description du panneau ciblé. * +* * +* Description : Met en place un nouveau lanceur de panneau majeur. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool gtk_panel_launcher_create(GtkPanelLauncher *launcher, const char *icon, const char *title, const char *desc) +{ + bool result; /* Bilan à retourner */ + char *bold; /* Titre sublimé */ + + result = true; + + gtk_image_set_from_icon_name(launcher->icon, icon); + + bold = strdup(title); + bold = strprep(bold, ""); + bold = stradd(bold, ""); + + gtk_label_set_label(launcher->title, bold); + + free(bold); + + gtk_label_set_label(launcher->desc, desc); + + return result; + +} diff --git a/src/gtkext/launcher.h b/src/gtkext/launcher.h new file mode 100644 index 0000000..3857216 --- /dev/null +++ b/src/gtkext/launcher.h @@ -0,0 +1,45 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * launcher.h - prototypes pour pour un lanceur de panneau majeur + * + * 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 . + */ + + +#ifndef _GTKEXT_LAUNCHER_H +#define _GTKEXT_LAUNCHER_H + + +#include + + +#include "../glibext/helpers.h" + + + +#define GTK_TYPE_PANEL_LAUNCHER (gtk_panel_launcher_get_type()) + +DECLARE_GTYPE(GtkPanelLauncher, gtk_panel_launcher, GTK, PANEL_LAUNCHER); + + +/* Crée un nouveau lanceur de panneau majeur. */ +GtkPanelLauncher *gtk_panel_launcher_new(const char *, const char *, const char *); + + + +#endif /* _GTKEXT_LAUNCHER_H */ diff --git a/src/gtkext/launcher.ui b/src/gtkext/launcher.ui new file mode 100644 index 0000000..f6f4fec --- /dev/null +++ b/src/gtkext/launcher.ui @@ -0,0 +1,76 @@ + + + + diff --git a/src/gui/panel-int.h b/src/gui/panel-int.h index 7e6f7e3..6a9fcc5 100644 --- a/src/gui/panel-int.h +++ b/src/gui/panel-int.h @@ -34,7 +34,10 @@ typedef PanelItemPersonality (* get_panel_item_personality_cb) (const GPanelItem *); /* Fournit un composant pour lancer l'activité d'un panneau. */ -typedef GtkWidget * (* get_panel_item_widget_cb) (GPanelItem *); +typedef GtkPanelLauncher * (* get_panel_item_launcher_cb) (GPanelItem *); + +/* Fournit un composant pour paramétrer l'activité d'un panneau. */ +typedef GtkWidget * (* get_panel_item_props_cb) (GPanelItem *); /* Fournit un composant représentant un panneau graphique. */ typedef GtkTiledPanel * (* get_panel_item_panel_cb) (GPanelItem *, GtkWidget *); @@ -45,7 +48,7 @@ struct _GPanelItem { GObject parent; /* A laisser en premier */ - GtkWidget *launcher; /* Eventuel lanceur associé */ + GtkPanelLauncher *launcher; /* Eventuel lanceur associé */ GtkWidget *properties; /* Propriétés de lancement */ GtkTiledPanel **panels; /* Instances complètes ouvertes*/ @@ -60,8 +63,8 @@ struct _GPanelItemClass get_panel_item_personality_cb get_personality; /* Fourniture de nature */ - get_panel_item_widget_cb get_launcher; /* Lancement d'une activité */ - get_panel_item_widget_cb get_properties;/* Préparation au lancement */ + get_panel_item_launcher_cb get_launcher;/* Lancement d'une activité */ + get_panel_item_props_cb get_properties; /* Préparation au lancement */ get_panel_item_panel_cb get_panel; /* Panneau principal */ }; diff --git a/src/gui/panel.c b/src/gui/panel.c index b361153..a704e63 100644 --- a/src/gui/panel.c +++ b/src/gui/panel.c @@ -184,9 +184,9 @@ PanelItemPersonality g_panel_item_get_personality(const GPanelItem *item) * * ******************************************************************************/ -GtkWidget *g_panel_item_get_launcher(GPanelItem *item) +GtkPanelLauncher *g_panel_item_get_launcher(GPanelItem *item) { - GtkWidget *result; /* Composant à retourner */ + GtkPanelLauncher *result; /* Composant à retourner */ GPanelItemClass *class; /* Classe à actionner */ if (item->launcher == NULL) diff --git a/src/gui/panel.h b/src/gui/panel.h index 03b67d4..b14daa8 100644 --- a/src/gui/panel.h +++ b/src/gui/panel.h @@ -26,11 +26,12 @@ #define _GUI_PANEL_H -#include "../glibext/helpers.h" -#include "../gtkext/panel.h" +#include -#include +#include "../glibext/helpers.h" +#include "../gtkext/panel.h" +#include "../gtkext/launcher.h" @@ -56,7 +57,7 @@ typedef enum _PanelItemPersonality PanelItemPersonality g_panel_item_get_personality(const GPanelItem *); /* Fournit un composant pour lancer l'activité d'un panneau. */ -GtkWidget *g_panel_item_get_launcher(GPanelItem *); +GtkPanelLauncher *g_panel_item_get_launcher(GPanelItem *); /* Fournit un composant pour paramétrer l'activité d'un panneau. */ GtkWidget *g_panel_item_get_properties(GPanelItem *); diff --git a/src/gui/panels/Makefile.am b/src/gui/panels/Makefile.am index 476a436..525b1f6 100644 --- a/src/gui/panels/Makefile.am +++ b/src/gui/panels/Makefile.am @@ -38,7 +38,6 @@ IMG_PATH = ../../../data/images RES_FILES = \ binary.ui \ - binary-launch.ui \ binary-props.ui \ $(IMG_PATH)/binfile-symbolic.svg \ welcome.ui \ diff --git a/src/gui/panels/binary-launch.ui b/src/gui/panels/binary-launch.ui deleted file mode 100644 index 553f758..0000000 --- a/src/gui/panels/binary-launch.ui +++ /dev/null @@ -1,65 +0,0 @@ - - - - - 12 - 12 - 12 - 12 - 12 - - - binfile-symbolic - 48 - - 0 - 0 - 2 - - - - - - - <b>Binary analysis</b> - TRUE - 0 - - 1 - 0 - - - - - - Load a binary content and parse its format if recognized - true - 0 - - 1 - 1 - - - - - - - go-next-symbolic - 12 - - 2 - 0 - 2 - - - - - - - diff --git a/src/gui/panels/binary.c b/src/gui/panels/binary.c index de0a4d0..23426e3 100644 --- a/src/gui/panels/binary.c +++ b/src/gui/panels/binary.c @@ -25,6 +25,9 @@ #include "binary.h" +#include + + #include "binary-int.h" #include "../window.h" #include "../../analysis/contents/file.h" @@ -81,7 +84,7 @@ static void g_binary_panel_finalize(GBinaryPanel *); static PanelItemPersonality g_binary_panel_get_personality(const GBinaryPanel *); /* Fournit un composant pour lancer l'activité d'un panneau. */ -static GtkWidget *g_binary_panel_get_launcher(GBinaryPanel *); +static GtkPanelLauncher *g_binary_panel_get_launcher(GPanelItem *); /* Fournit un composant pour paramétrer l'activité d'un panneau. */ static GtkWidget *g_binary_panel_get_properties(GBinaryPanel *); @@ -267,8 +270,8 @@ static void g_binary_panel_class_init(GBinaryPanelClass *class) panel = G_PANEL_ITEM_CLASS(class); panel->get_personality = (get_panel_item_personality_cb)g_binary_panel_get_personality; - panel->get_launcher = (get_panel_item_widget_cb)g_binary_panel_get_launcher; - panel->get_properties = (get_panel_item_widget_cb)g_binary_panel_get_properties; + panel->get_launcher = g_binary_panel_get_launcher; + panel->get_properties = (get_panel_item_props_cb)g_binary_panel_get_properties; panel->get_panel = (get_panel_item_panel_cb)g_binary_panel_get_panel; } @@ -394,17 +397,13 @@ static PanelItemPersonality g_binary_panel_get_personality(const GBinaryPanel *p * * ******************************************************************************/ -static GtkWidget *g_binary_panel_get_launcher(GBinaryPanel *panel) +static GtkPanelLauncher *g_binary_panel_get_launcher(GPanelItem *panel) { - GtkWidget *result; /* Composant à retourner */ - GtkBuilder *builder; /* Constructeur d'UI */ + GtkPanelLauncher *result; /* Composant à retourner */ - builder = gtk_builder_new_from_resource("/re/chrysalide/framework/gui/panels/binary-launch.ui"); - - result = GTK_WIDGET(gtk_builder_get_object(builder, "launcher")); - ref_object(result); - - unref_object(builder); + result = gtk_panel_launcher_new("binfile-symbolic", + _("Binary analysis"), + _("Load a binary content and parse its format if recognized")); return result; diff --git a/src/gui/panels/gresource.xml b/src/gui/panels/gresource.xml index d00953d..2fecc8c 100644 --- a/src/gui/panels/gresource.xml +++ b/src/gui/panels/gresource.xml @@ -2,7 +2,6 @@ binary.ui - binary-launch.ui binary-props.ui welcome.ui welcome-hints.txt -- cgit v0.11.2-87-g4458