/* Chrysalide - Outil d'analyse de fichiers binaires * welcome.c - 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 */ #include "welcome.h" #include #include #include "welcome-int.h" #include "../core/panels.h" #include "../../common/shuffle.h" #include "../../gtkext/helpers.h" /* ------------------------- COEUR D'UN PANNEAU D'AFFICHAGE ------------------------- */ /* Initialise la classe des panneaux d'accueil par défaut. */ static void gtk_welcome_panel_class_init(GtkWelcomePanelClass *); /* Initialise une instance de panneau d'accueil par défaut. */ static void gtk_welcome_panel_init(GtkWelcomePanel *); /* Supprime toutes les références externes. */ static void gtk_welcome_panel_dispose(GtkWelcomePanel *); /* Procède à la libération totale de la mémoire. */ static void gtk_welcome_panel_finalize(GtkWelcomePanel *); /* Intègre une définition de panneau enregistrée. */ static bool gtk_welcome_panel_add_launcher(GPanelItem *, GListStore *); /* Prépare un composant pour représenter une définition. */ static GtkWidget *gtk_welcome_panel_create_launcher_widget(GPanelItem *, gpointer); /* Réagit à un changement de sélection de la liste de panneaux. */ static void gtk_welcome_panel_on_selected_rows_changed(GtkListBox *, GtkWelcomePanel *); /* Réagit à une demande d'affichage de l'astuce précédente. */ static void gtk_welcome_panel_on_prev_hint_clicked(GtkButton *, GtkWelcomePanel *); /* Réagit à une demande d'affichage de l'astuce suivante. */ static void gtk_welcome_panel_on_next_hint_clicked(GtkButton *, GtkWelcomePanel *); /* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */ /* ---------------------- MANIPULATIONS D'UN PANNEAU GRAPHIQUE ---------------------- */ /* Initialise la classe des panneaux graphiques pour binaires. */ static void g_welcome_panel_class_init(GWelcomePanelClass *); /* Initialise une instance de panneau graphique pour binaire. */ static void g_welcome_panel_init(GWelcomePanel *); /* Supprime toutes les références externes. */ static void g_welcome_panel_dispose(GWelcomePanel *); /* Procède à la libération totale de la mémoire. */ static void g_welcome_panel_finalize(GWelcomePanel *); /* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */ /* Fournit une indication sur la personnalité du panneau. */ static PanelItemPersonality g_welcome_panel_get_personality(const GWelcomePanel *); /* Fournit un composant représentant un panneau graphique. */ static GtkTiledPanel *g_welcome_panel_get_panel(GWelcomePanel *, GtkWidget *); /* ---------------------------------------------------------------------------------- */ /* COEUR D'UN PANNEAU D'AFFICHAGE */ /* ---------------------------------------------------------------------------------- */ /* Indique le type défini pour un panneau d'accueil. */ G_DEFINE_TYPE(GtkWelcomePanel, gtk_welcome_panel, GTK_TYPE_TILED_PANEL); /****************************************************************************** * * * Paramètres : class = classe à initialiser. * * * * Description : Initialise la classe des panneaux d'accueil par défaut. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void gtk_welcome_panel_class_init(GtkWelcomePanelClass *class) { GObjectClass *object; /* Autre version de la classe */ GtkWidgetClass *widget; /* Classe de haut niveau */ object = G_OBJECT_CLASS(class); object->dispose = (GObjectFinalizeFunc/* ! */)gtk_welcome_panel_dispose; object->finalize = (GObjectFinalizeFunc)gtk_welcome_panel_finalize; widget = GTK_WIDGET_CLASS(class); gtk_widget_class_set_template_from_resource(widget, "/re/chrysalide/framework/gui/panels/welcome.ui"); 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)); 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); } /****************************************************************************** * * * Paramètres : panel = instance à initialiser. * * * * Description : Initialise une instance de panneau d'accueil par défaut. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void gtk_welcome_panel_init(GtkWelcomePanel *panel) { GBytes *bytes; /* Données brutes de ressource */ const gchar *data; /* Données brutes natives */ gtk_widget_init_template(GTK_WIDGET(panel)); panel->store = g_list_store_new(G_TYPE_PANEL_ITEM); panel->other_child = NULL; bytes = g_resources_lookup_data("/re/chrysalide/framework/gui/panels/welcome-hints.txt", G_RESOURCE_LOOKUP_FLAGS_NONE, NULL); assert(bytes != NULL); data = g_bytes_get_data(bytes, NULL); panel->raw_hints = g_strsplit(data, "\n\n\n", -1); g_bytes_unref(bytes); panel->raw_count = g_strv_length(panel->raw_hints); assert(panel->raw_count > 0); panel->cur_hint = 0; } /****************************************************************************** * * * Paramètres : panel = instance d'objet GLib à traiter. * * * * Description : Supprime toutes les références externes. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void gtk_welcome_panel_dispose(GtkWelcomePanel *panel) { gtk_widget_dispose_template(GTK_WIDGET(panel), GTK_TYPE_WELCOME_PANEL); g_clear_object(&panel->other_child); G_OBJECT_CLASS(gtk_welcome_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 gtk_welcome_panel_finalize(GtkWelcomePanel *panel) { G_OBJECT_CLASS(gtk_welcome_panel_parent_class)->finalize(G_OBJECT(panel)); g_strfreev(panel->raw_hints); } /****************************************************************************** * * * Paramètres : - * * * * Description : Crée une nouvelle instance de panneau d'accueil. * * * * Retour : Composant GTK mis en place. * * * * Remarques : - * * * ******************************************************************************/ GtkTiledPanel *gtk_welcome_panel_new(void) { GtkTiledPanel *result; /* Instance à retourner */ result = g_object_new(GTK_TYPE_WELCOME_PANEL, NULL); if (!gtk_welcome_panel_create(GTK_WELCOME_PANEL(result))) g_clear_object(&result); return result; } /****************************************************************************** * * * Paramètres : panel = panneau d'accueil à initialiser. * * * * Description : Met en place un nouveau panneau d'accueil. * * * * Retour : Bilan de l'opération. * * * * Remarques : - * * * ******************************************************************************/ bool gtk_welcome_panel_create(GtkWelcomePanel *panel) { bool result; /* Bilan à retourner */ int min; /* Taille à gauche minimale */ GtkConstraintLayout *layout; /* Disposition fixant la taille*/ GtkConstraint *constraint; /* Contrainte à considérer */ /* Constitution de la liste des démarreurs */ result = browse_all_item_panels(true, (handle_panel_item_fc)gtk_welcome_panel_add_launcher, panel->store); gtk_list_box_bind_model(panel->list, G_LIST_MODEL(panel->store), (GtkListBoxCreateWidgetFunc)gtk_welcome_panel_create_launcher_widget, NULL, NULL); /* Dimensionnement de la zone d'astuces */ gtk_widget_measure(GTK_WIDGET(panel->list), GTK_ORIENTATION_HORIZONTAL, -1, &min, NULL, NULL, NULL); if (min > 150) min -= 150; layout = GTK_CONSTRAINT_LAYOUT(gtk_widget_get_layout_manager(GTK_WIDGET(panel->hints))); gtk_constraint_layout_remove_all_constraints(layout); 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); 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); 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); /* Premier affichage */ gtk_label_set_markup(panel->hints, panel->raw_hints[panel->cur_hint]); return result; } /****************************************************************************** * * * Paramètres : item = définition de panneau à intégrer. * * store = 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 : - * * * ******************************************************************************/ static bool gtk_welcome_panel_add_launcher(GPanelItem *item, GListStore *store) { bool result; /* Poursuite du parcours */ result = true; g_list_store_append(store, G_OBJECT(item)); return result; } /****************************************************************************** * * * Paramètres : item = définition de panneau à consulter. * * unused = adresse non utilisée ici. * * * * Description : Prépare un composant pour représenter une définition. * * * * Retour : Composant de représentation de définition de panneau. * * * * Remarques : - * * * ******************************************************************************/ static GtkWidget *gtk_welcome_panel_create_launcher_widget(GPanelItem *item, gpointer unused) { GtkWidget *result; /* Composant GTK à retourner */ result = g_panel_item_get_launcher(item); return result; } /****************************************************************************** * * * Paramètres : box = liste GTK concernée par l'appel. * * panel = panneau d'accueil lié à la liste. * * * * Description : Réagit à un changement de sélection de la liste de panneaux. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void gtk_welcome_panel_on_selected_rows_changed(GtkListBox *box, GtkWelcomePanel *panel) { GtkListBoxRow *row; /* Ligne sélectionnée */ int selected; /* Indice de sélection */ GPanelItem *item; /* Elément correspondant */ GtkWidget *new; /* Nouvelles propriétés */ row = gtk_list_box_get_selected_row(box); /** * Perte de sélection : bascule sur les informations d'accueil. */ if (row == NULL) { assert(panel->other_child != NULL); gtk_stack_set_visible_child(panel->properties, panel->def_child); gtk_stack_remove(panel->properties, panel->other_child); g_clear_object(&panel->other_child); } /** * Bascule vers une nouvelle fenêtre. */ else { selected = gtk_list_box_row_get_index(row); item = g_list_model_get_item(G_LIST_MODEL(panel->store), selected); new = g_panel_item_get_properties(item); if (new == panel->other_child) unref_object(new); else { gtk_stack_add_child(panel->properties, new); gtk_stack_set_visible_child(panel->properties, new); if (panel->other_child != NULL) { gtk_stack_remove(panel->properties, panel->other_child); g_clear_object(&panel->other_child); } panel->other_child = new; } } } /****************************************************************************** * * * Paramètres : button = bouton GTK concerné par l'appel. * * panel = panneau d'accueil lié à la liste. * * * * Description : Réagit à une demande d'affichage de l'astuce précédente. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void gtk_welcome_panel_on_prev_hint_clicked(GtkButton *button, GtkWelcomePanel *panel) { if (panel->cur_hint > 0) panel->cur_hint--; else panel->cur_hint = panel->raw_count - 1; gtk_label_set_markup(panel->hints, panel->raw_hints[panel->cur_hint]); } /****************************************************************************** * * * Paramètres : button = bouton GTK concerné par l'appel. * * panel = panneau d'accueil lié à la liste. * * * * Description : Réagit à une demande d'affichage de l'astuce suivante. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void gtk_welcome_panel_on_next_hint_clicked(GtkButton *button, GtkWelcomePanel *panel) { if ((panel->cur_hint + 1) < panel->raw_count) panel->cur_hint++; else panel->cur_hint = 0; gtk_label_set_markup(panel->hints, panel->raw_hints[panel->cur_hint]); } /* ---------------------------------------------------------------------------------- */ /* IMPLEMENTATION DES FONCTIONS DE CLASSE */ /* ---------------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------------- */ /* MANIPULATIONS D'UN PANNEAU GRAPHIQUE */ /* ---------------------------------------------------------------------------------- */ /* Indique le type défini pour une manipulation de panneau de bienvenue. */ G_DEFINE_TYPE(GWelcomePanel, g_welcome_panel, G_TYPE_PANEL_ITEM); /****************************************************************************** * * * Paramètres : class = classe à initialiser. * * * * Description : Initialise la classe des panneaux graphiques pour binaires. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void g_welcome_panel_class_init(GWelcomePanelClass *class) { GObjectClass *object; /* Autre version de la classe */ GPanelItemClass *panel; /* Encore une autre vision... */ object = G_OBJECT_CLASS(class); object->dispose = (GObjectFinalizeFunc/* ! */)g_welcome_panel_dispose; object->finalize = (GObjectFinalizeFunc)g_welcome_panel_finalize; panel = G_PANEL_ITEM_CLASS(class); panel->get_personality = (get_panel_item_personality_cb)g_welcome_panel_get_personality; panel->get_panel = (get_panel_item_panel_cb)g_welcome_panel_get_panel; } /****************************************************************************** * * * Paramètres : panel = instance à initialiser. * * * * Description : Initialise une instance de panneau graphique pour binaire. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void g_welcome_panel_init(GWelcomePanel *panel) { } /****************************************************************************** * * * Paramètres : panel = instance d'objet GLib à traiter. * * * * Description : Supprime toutes les références externes. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void g_welcome_panel_dispose(GWelcomePanel *panel) { G_OBJECT_CLASS(g_welcome_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_welcome_panel_finalize(GWelcomePanel *panel) { G_OBJECT_CLASS(g_welcome_panel_parent_class)->finalize(G_OBJECT(panel)); } /****************************************************************************** * * * Paramètres : - * * * * Description : Constitue une définition de manipulation de panneau. * * * * Retour : Définition de propriétés 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; } /* ---------------------------------------------------------------------------------- */ /* IMPLEMENTATION DES FONCTIONS DE CLASSE */ /* ---------------------------------------------------------------------------------- */ /****************************************************************************** * * * Paramètres : panel = définition de panneau à consulter. * * * * Description : Fournit une indication sur la personnalité du panneau. * * * * Retour : Identifiant lié à la nature du panneau. * * * * Remarques : - * * * ******************************************************************************/ static PanelItemPersonality g_welcome_panel_get_personality(const GWelcomePanel *panel) { PanelItemPersonality result; /* Personnalité à retourner */ result = PIP_MAIN_PANEL | PIP_SINGLETON; return result; } /****************************************************************************** * * * Paramètres : panel = définition de panneau à manipuler. * * props = éventuels éléments graphiques de paramétrages. * * * * Description : Fournit un composant représentant un panneau graphique. * * * * Retour : Composant GTK (déjà ?) mis en place. * * * * Remarques : - * * * ******************************************************************************/ static GtkTiledPanel *g_welcome_panel_get_panel(GWelcomePanel *panel, GtkWidget *props) { GtkTiledPanel *result; /* Composant à retourner */ /** * Il n'existe pas de composants de paramètrage pour ce panneau. */ assert(props == NULL); result = gtk_welcome_panel_new(); return result; }