/* Chrysalide - Outil d'analyse de fichiers binaires * panels.c - gestion d'ensemble de tous les panneaux graphiques du framework * * Copyright (C) 2016-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 "panels.h" #include #include #include #include #include "../panels/binary.h" #include "../panels/binary-params.h" #include "../panels/welcome.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 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 : 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; } /****************************************************************************** * * * Paramètres : info = informations à supprimer de la mémoire. * * * * Description : Efface une définition étendue de panneau graphique. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void delete_panel_info(ext_panel_info_t *info) { 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); } /****************************************************************************** * * * 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 */ // TODO register_panel_item(G_TYPE_LOG_PANEL, config); /* Chargement du panneau de rapport au plus tôt */ // TODO panel = g_panel_item_new(G_TYPE_LOG_PANEL, NULL); 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 : info = information de base à copier. * * * * Description : Enregistre la définition d'un panneau graphique. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ bool register_framework_panel_definition(const panel_info_t *info) { 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; if (i < _panels_count) goto done; /* Enregistrement */ ext_info = copy_panel_info(info); _panels_list = realloc(_panels_list, ++_panels_count * sizeof(ext_panel_info_t *)); _panels_list[_panels_count - 1] = ext_info; result = true; done: 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++) { info = _panels_list[i]; if (info->category == NULL) continue; 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)); } } /****************************************************************************** * * * 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; }