summaryrefslogtreecommitdiff
path: root/src/gui/panels/welcome.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/panels/welcome.c')
-rw-r--r--src/gui/panels/welcome.c836
1 files changed, 274 insertions, 562 deletions
diff --git a/src/gui/panels/welcome.c b/src/gui/panels/welcome.c
index 60593d1..3cd349f 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,98 @@
#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"
+#include "../../gtkext/helpers.h"
-/* Panneau d'accueil par défaut (instance) */
-struct _GWelcomePanel
-{
- GPanelItem parent; /* A laisser en premier */
+/* ------------------------- COEUR D'UN PANNEAU D'AFFICHAGE ------------------------- */
- 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 */
+/* Initialise la classe des panneaux d'accueil par défaut. */
+static void gtk_welcome_panel_class_init(GtkWelcomePanelClass *);
- bool uorigin; /* Origine de l'affichage */
+/* Initialise une instance de panneau d'accueil par défaut. */
+static void gtk_welcome_panel_init(GtkWelcomePanel *);
- gulong sig_id; /* Connexion par signal */
+/* 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 *);
-/* Panneau d'accueil par défaut (classe) */
-struct _GWelcomePanelClass
-{
- GPanelItemClass parent; /* A laisser en premier */
+/* 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 *);
-/* Colonnes de la liste des messages */
-typedef enum _RecentProjectColumn
-{
- RPC_VALID, /* Validité de l'entrée */
- RPC_FULLPATH, /* Chemin d'accès à un projet */
+/* Réagit à une demande d'affichage de l'astuce précédente. */
+static void gtk_welcome_panel_on_prev_hint_clicked(GtkButton *, GtkWelcomePanel *);
- RPC_COUNT /* Nombre de colonnes */
+/* Réagit à une demande d'affichage de l'astuce suivante. */
+static void gtk_welcome_panel_on_next_hint_clicked(GtkButton *, GtkWelcomePanel *);
-} RecentProjectColumn;
-/* Initialise la classe des panneaux d'accueil par défaut. */
-static void g_welcome_panel_class_init(GWelcomePanelClass *);
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
-/* Initialise une instance de panneau d'accueil par défaut. */
-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 *);
-/* Fournit le nom interne attribué à l'élément réactif. */
-static char *g_welcome_panel_class_get_key(const GWelcomePanelClass *);
-/* Fournit une indication sur la personnalité du panneau. */
-static PanelItemPersonality g_welcome_panel_class_get_personality(const GWelcomePanelClass *);
-/* Indique le chemin initial de la localisation d'un panneau. */
-static char *g_welcome_panel_class_get_path(const GWelcomePanelClass *);
-/* Place un panneau dans l'ensemble affiché. */
-static void g_welcome_panel_dock(GWelcomePanel *);
+/* ---------------------- MANIPULATIONS D'UN PANNEAU GRAPHIQUE ---------------------- */
-/* 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 *);
+/* 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 *);
-/* Réagit à la demande d'étude d'un nouveau binaire. */
-static void on_new_binary_clicked(GtkButton *, GWelcomePanel *);
+/* Supprime toutes les références externes. */
+static void g_welcome_panel_dispose(GWelcomePanel *);
-/* Actualise au besoin la liste des projets récents. */
-static void on_recent_list_changed(GtkRecentManager *, GWelcomePanel *);
+/* Procède à la libération totale de la mémoire. */
+static void g_welcome_panel_finalize(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 *);
+/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */
-/* 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 *);
+/* Fournit une indication sur la personnalité du panneau. */
+static PanelItemPersonality g_welcome_panel_get_personality(const GWelcomePanel *);
-/* Affiche l'astuce suivante dans la liste globale. */
-static void on_tip_next_clicked(GtkButton *, GWelcomePanel *);
+/* Fournit un composant représentant un panneau graphique. */
+static GtkTiledPanel *g_welcome_panel_get_panel(GWelcomePanel *, GtkWidget *);
-/* 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 +127,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;
-
- item = G_EDITOR_ITEM_CLASS(klass);
+ object->dispose = (GObjectFinalizeFunc/* ! */)gtk_welcome_panel_dispose;
+ object->finalize = (GObjectFinalizeFunc)gtk_welcome_panel_finalize;
- item->get_key = (get_item_key_fc)g_welcome_panel_class_get_key;
+ widget = GTK_WIDGET_CLASS(class);
- panel = G_PANEL_ITEM_CLASS(klass);
+ gtk_widget_class_set_template_from_resource(widget, "/re/chrysalide/framework/gui/panels/welcome.ui");
- 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;
+ 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->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,86 +165,31 @@ 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 */
+ GBytes *bytes; /* Données brutes de ressource */
+ const gchar *data; /* Données brutes natives */
- /* Eléments de base */
+ gtk_widget_init_template(GTK_WIDGET(panel));
- pitem = G_PANEL_ITEM(panel);
+ panel->store = g_list_store_new(G_TYPE_PANEL_ITEM);
- pitem->widget = G_NAMED_WIDGET(gtk_built_named_widget_new_for_panel(_("Welcome"),
- _("Welcome panel"),
- PANEL_WELCOME_ID));
+ panel->other_child = NULL;
- panel->uorigin = !gtk_panel_item_class_dock_at_startup(G_PANEL_ITEM_GET_CLASS(pitem));
+ bytes = g_resources_lookup_data("/re/chrysalide/framework/gui/panels/welcome-hints.txt",
+ G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
+ assert(bytes != NULL);
- /* Représentation graphique */
+ data = g_bytes_get_data(bytes, NULL);
- builder = gtk_built_named_widget_get_builder(GTK_BUILT_NAMED_WIDGET(pitem->widget));
+ panel->raw_hints = g_strsplit(data, "\n\n\n", -1);
- /* Liste des projets récents */
+ g_bytes_unref(bytes);
- treeview = GTK_TREE_VIEW(gtk_builder_get_object(builder, "treeview"));
+ panel->raw_count = g_strv_length(panel->raw_hints);
+ assert(panel->raw_count > 0);
- column = gtk_tree_view_column_new();
- gtk_tree_view_append_column(treeview, column);
- gtk_tree_view_set_expander_column(treeview, column);
-
- 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);
-
- /* Affichage au démarrage ? */
-
- button = GTK_TOGGLE_BUTTON(gtk_builder_get_object(builder, "startup"));
-
- g_generic_config_get_value(get_main_configuration(), MPK_WELCOME_STARTUP, &state);
-
- gtk_toggle_button_set_active(button, state);
-
- /* Chargement de l'image de fond */
-
- filename = find_pixmap_file("tipoftheday.png");
-
- panel->background = cairo_image_surface_create_from_png(filename);
-
- g_free(filename);
-
- /* Connexion des signaux */
-
- 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_builder_connect_signals(builder, panel);
-
- g_object_unref(G_OBJECT(builder));
-
- /* Actualisation du contenu du panneau */
-
- manager = get_project_manager();
-
- 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);
+ panel->cur_hint = 0;
}
@@ -293,20 +206,13 @@ static void g_welcome_panel_init(GWelcomePanel *panel)
* *
******************************************************************************/
-static void g_welcome_panel_dispose(GWelcomePanel *panel)
+static void gtk_welcome_panel_dispose(GtkWelcomePanel *panel)
{
- GtkRecentManager *manager; /* Gestionnaire global */
-
- if (panel->sig_id > 0)
- {
- manager = get_project_manager();
+ gtk_widget_dispose_template(GTK_WIDGET(panel), GTK_TYPE_WELCOME_PANEL);
- g_signal_handler_disconnect(manager, panel->sig_id);
- panel->sig_id = 0;
+ 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(G_OBJECT(panel));
}
@@ -323,34 +229,35 @@ static void g_welcome_panel_dispose(GWelcomePanel *panel)
* *
******************************************************************************/
-static void g_welcome_panel_finalize(GWelcomePanel *panel)
+static void gtk_welcome_panel_finalize(GtkWelcomePanel *panel)
{
- cairo_surface_destroy(panel->background);
+ G_OBJECT_CLASS(gtk_welcome_panel_parent_class)->finalize(G_OBJECT(panel));
- free(panel->tips);
-
- G_OBJECT_CLASS(g_welcome_panel_parent_class)->finalize(G_OBJECT(panel));
+ g_strfreev(panel->raw_hints);
}
/******************************************************************************
* *
-* Paramètres : class = classe à consulter. *
+* Paramètres : - *
* *
-* Description : Fournit le nom interne attribué à l'élément réactif. *
+* Description : Crée une nouvelle instance de panneau d'accueil. *
* *
-* Retour : Désignation (courte) de l'élément de l'éditeur. *
+* Retour : Composant GTK mis en place. *
* *
* Remarques : - *
* *
******************************************************************************/
-static char *g_welcome_panel_class_get_key(const GWelcomePanelClass *class)
+GtkTiledPanel *gtk_welcome_panel_new(void)
{
- char *result; /* Description à renvoyer */
+ GtkTiledPanel *result; /* Instance à retourner */
+
+ result = g_object_new(GTK_TYPE_WELCOME_PANEL, NULL);
- result = strdup(PANEL_WELCOME_ID);
+ if (!gtk_welcome_panel_create(GTK_WELCOME_PANEL(result)))
+ g_clear_object(&result);
return result;
@@ -359,67 +266,66 @@ static char *g_welcome_panel_class_get_key(const GWelcomePanelClass *class)
/******************************************************************************
* *
-* Paramètres : class = classe à consulter. *
+* Paramètres : panel = panneau d'accueil à initialiser. *
* *
-* Description : Fournit une indication sur la personnalité du panneau. *
+* Description : Met en place un nouveau panneau d'accueil. *
* *
-* Retour : Identifiant lié à la nature unique du panneau. *
+* Retour : Bilan de l'opération. *
* *
* Remarques : - *
* *
******************************************************************************/
-static PanelItemPersonality g_welcome_panel_class_get_personality(const GWelcomePanelClass *class)
+bool gtk_welcome_panel_create(GtkWelcomePanel *panel)
{
- PanelItemPersonality result; /* Personnalité à retourner */
+ bool result; /* Bilan à retourner */
+ int min; /* Taille à gauche minimale */
+ GtkConstraintLayout *layout; /* Disposition fixant la taille*/
+ GtkConstraint *constraint; /* Contrainte à considérer */
- result = PIP_PERSISTENT_SINGLETON;
+ /* Constitution de la liste des démarreurs */
- return result;
+ 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 */
-/******************************************************************************
-* *
-* Paramètres : class = classe à consulter. *
-* *
-* Description : Indique le chemin initial de la localisation d'un panneau. *
-* *
-* Retour : Chemin fixé associé à la position initiale. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
+ gtk_widget_measure(GTK_WIDGET(panel->list), GTK_ORIENTATION_HORIZONTAL, -1, &min, NULL, NULL, NULL);
-static char *g_welcome_panel_class_get_path(const GWelcomePanelClass *class)
-{
- char *result; /* Emplacement à retourner */
+ if (min > 150)
+ min -= 150;
- result = strdup("M");
+ layout = GTK_CONSTRAINT_LAYOUT(gtk_widget_get_layout_manager(GTK_WIDGET(panel->hints)));
- return result;
+ 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);
-/******************************************************************************
-* *
-* Paramètres : - *
-* *
-* Description : Crée un panneau d'accueil par défaut. *
-* *
-* Retour : Adresse de la structure mise en place. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
+ 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);
-GPanelItem *g_welcome_panel_new(void)
-{
- GPanelItem *result; /* Structure à retourner */
+ /* Premier affichage */
- result = g_object_new(G_TYPE_WELCOME_PANEL, NULL);
+ gtk_label_set_markup(panel->hints, panel->raw_hints[panel->cur_hint]);
return result;
@@ -428,157 +334,129 @@ GPanelItem *g_welcome_panel_new(void)
/******************************************************************************
* *
-* Paramètres : panel = composant à présenter à l'affichage. *
+* Paramètres : item = définition de panneau à intégrer. *
+* store = liste à compléter. *
* *
-* Description : Place un panneau dans l'ensemble affiché. *
+* Description : Intègre une définition de panneau enregistrée. *
* *
-* Retour : - *
+* Retour : true pour un parcours complet de la liste des définitions. *
* *
* Remarques : - *
* *
******************************************************************************/
-static void g_welcome_panel_dock(GWelcomePanel *panel)
+static bool gtk_welcome_panel_add_launcher(GPanelItem *item, GListStore *store)
{
- g_welcome_panel_set_user_origin(panel, true);
+ bool result; /* Poursuite du parcours */
+
+ result = true;
+
+ g_list_store_append(store, G_OBJECT(item));
+
+ return result;
}
/******************************************************************************
* *
-* Paramètres : panel = panneau d'accueil à mettre à jour. *
+* Paramètres : item = définition de panneau à consulter. *
+* unused = adresse non utilisée ici. *
* *
-* Description : Charge l'ensemble des astuces. *
+* Description : Prépare un composant pour représenter une définition. *
* *
-* Retour : - *
+* Retour : Composant de représentation de définition de panneau. *
* *
* Remarques : - *
* *
******************************************************************************/
-static void g_welcome_panel_load_tips(GWelcomePanel *panel)
+static GtkWidget *gtk_welcome_panel_create_launcher_widget(GPanelItem *item, gpointer unused)
{
- 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/."),
+ GtkWidget *result; /* Composant GTK à retourner */
- _("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.")
+ result = g_panel_item_get_launcher(item);
- };
-
- 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);
+ return result;
}
/******************************************************************************
* *
-* Paramètres : widget = composant graphique à redessiner. *
-* cr = contexte graphique à utiliser. *
-* panel = panneau associé comportant des informations utiles. *
+* Paramètres : box = liste GTK concernée par l'appel. *
+* panel = panneau d'accueil lié à la liste. *
* *
-* Description : Assure le dessin du fond de la bulle d'astuce. *
+* Description : Réagit à un changement de sélection de la liste de panneaux. *
* *
-* Retour : FALSE pour poursuivre la propagation de l'événement. *
+* Retour : - *
* *
* Remarques : - *
* *
******************************************************************************/
-static gboolean on_tip_background_draw(GtkWidget *widget, cairo_t *cr, GWelcomePanel *panel)
+static void gtk_welcome_panel_on_selected_rows_changed(GtkListBox *box, GtkWelcomePanel *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 */
-
- if (cairo_surface_status(panel->background) == CAIRO_STATUS_SUCCESS)
- {
- 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);
+ GtkListBoxRow *row; /* Ligne sélectionnée */
+ int selected; /* Indice de sélection */
+ GPanelItem *item; /* Elément correspondant */
+ GtkWidget *new; /* Nouvelles propriétés */
- scale = wgt_height / (2.0 * img_height);
+ row = gtk_list_box_get_selected_row(box);
- cairo_scale(cr, scale, scale);
+ /**
+ * Perte de sélection : bascule sur les informations d'accueil.
+ */
+ if (row == NULL)
+ {
+ assert(panel->other_child != NULL);
- cairo_set_source_surface(cr, panel->background,
- (wgt_width / scale) - img_width,
- ((wgt_height / scale) - img_height) / 2);
+ gtk_stack_set_visible_child(panel->properties, panel->def_child);
- cairo_paint(cr);
+ gtk_stack_remove(panel->properties, panel->other_child);
+ g_clear_object(&panel->other_child);
}
- return FALSE;
-
-}
+ /**
+ * 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);
-/******************************************************************************
-* *
-* 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 : - *
-* *
-******************************************************************************/
+ if (new == panel->other_child)
+ unref_object(new);
-static void on_new_binary_clicked(GtkButton *button, GWelcomePanel *panel)
-{
- GObject *ref; /* Espace de référencements */
- GtkMenuItem *item; /* Elément de menu simulé */
+ else
+ {
+ gtk_stack_add_child(panel->properties, new);
+ gtk_stack_set_visible_child(panel->properties, new);
- ref = G_OBJECT(get_editor_window());
+ if (panel->other_child != NULL)
+ {
+ gtk_stack_remove(panel->properties, panel->other_child);
+ g_clear_object(&panel->other_child);
+ }
- item = GTK_MENU_ITEM(g_object_get_data(ref, "mnu_project_add_binary"));
+ panel->other_child = new;
- 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.*
+* Paramètres : button = bouton GTK concerné par l'appel. *
+* panel = panneau d'accueil lié à la liste. *
* *
-* Description : Actualise au besoin la liste des projets récents. *
+* Description : Réagit à une demande d'affichage de l'astuce précédente. *
* *
* Retour : - *
* *
@@ -586,19 +464,24 @@ static void on_new_binary_clicked(GtkButton *button, GWelcomePanel *panel)
* *
******************************************************************************/
-static void on_recent_list_changed(GtkRecentManager *manager, GWelcomePanel *panel)
+static void gtk_welcome_panel_on_prev_hint_clicked(GtkButton *button, GtkWelcomePanel *panel)
{
- g_welcome_panel_reload_project_list(panel, manager);
+ 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 : panel = panneau comportant des informations utiles. *
-* manager = gestion de fichiers récemment utilisés. *
+* Paramètres : button = bouton GTK concerné par l'appel. *
+* panel = panneau d'accueil lié à la liste. *
* *
-* Description : Recharge une liste à jour des projets récents. *
+* Description : Réagit à une demande d'affichage de l'astuce suivante. *
* *
* Retour : - *
* *
@@ -606,82 +489,45 @@ static void on_recent_list_changed(GtkRecentManager *manager, GWelcomePanel *pan
* *
******************************************************************************/
-static void g_welcome_panel_reload_project_list(GWelcomePanel *panel, GtkRecentManager *manager)
+static void gtk_welcome_panel_on_next_hint_clicked(GtkButton *button, GtkWelcomePanel *panel)
{
- 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);
+ if ((panel->cur_hint + 1) < panel->raw_count)
+ panel->cur_hint++;
+ else
+ panel->cur_hint = 0;
- empty = true;
+ gtk_label_set_markup(panel->hints, panel->raw_hints[panel->cur_hint]);
- /* 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);
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
- 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);
- }
+/* ---------------------------------------------------------------------------------- */
+/* MANIPULATIONS D'UN PANNEAU GRAPHIQUE */
+/* ---------------------------------------------------------------------------------- */
- g_object_unref(G_OBJECT(builder));
-}
+/* 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 : 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. *
+* Paramètres : class = classe à initialiser. *
* *
-* Description : Réagit à une sélection décidée d'un projet particulier. *
+* Description : Initialise la classe des panneaux graphiques pour binaires. *
* *
* Retour : - *
* *
@@ -689,47 +535,29 @@ static void g_welcome_panel_reload_project_list(GWelcomePanel *panel, GtkRecentM
* *
******************************************************************************/
-static void on_row_activated_for_projects(GtkTreeView *treeview, GtkTreePath *path, GtkTreeViewColumn *column, GWelcomePanel *panel)
+static void g_welcome_panel_class_init(GWelcomePanelClass *class)
{
- 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))
- {
- gtk_tree_model_get(model, &iter, RPC_VALID, &valid, RPC_FULLPATH, &filename, -1);
-
- if (valid)
- {
- project = g_study_project_open(filename, true);
-
- if (project != NULL)
- {
- set_current_project(project);
-
- push_project_into_recent_list(project);
+ GObjectClass *object; /* Autre version de la classe */
+ GPanelItemClass *panel; /* Encore une autre vision... */
- }
+ object = G_OBJECT_CLASS(class);
- g_free(filename);
+ 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 : button = bouton de défilement des astuces activé; *
-* panel = panneau associé comportant des informations utiles. *
+* Paramètres : panel = instance à initialiser. *
* *
-* Description : Enregistre les conditions d'affichage du panneau d'accueil. *
+* Description : Initialise une instance de panneau graphique pour binaire. *
* *
* Retour : - *
* *
@@ -737,19 +565,17 @@ static void on_row_activated_for_projects(GtkTreeView *treeview, GtkTreePath *pa
* *
******************************************************************************/
-static void on_startup_toggled(GtkToggleButton *button, GWelcomePanel *panel)
+static void g_welcome_panel_init(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. *
+* Paramètres : panel = instance d'objet GLib à traiter. *
* *
-* Description : Consulte les versions existantes et affiche une conclusion. *
+* Description : Supprime toutes les références externes. *
* *
* Retour : - *
* *
@@ -757,114 +583,18 @@ static void on_startup_toggled(GtkToggleButton *button, GWelcomePanel *panel)
* *
******************************************************************************/
-static void g_welcome_panel_check_version(GWelcomePanel *panel)
+static void g_welcome_panel_dispose(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 */
-
- sock = connect_via_tcp("www.chrysalide.re", "80", NULL);
- if (sock == -1) goto check_process;
-
-#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);
-
- }
-
- }
-
- gtk_label_set_markup(label, msg);
-
- free(msg);
-
- g_object_unref(G_OBJECT(builder));
+ G_OBJECT_CLASS(g_welcome_panel_parent_class)->dispose(G_OBJECT(panel));
}
/******************************************************************************
* *
-* Paramètres : button = bouton de défilement des astuces activé; *
-* panel = panneau associé comportant des informations utiles. *
+* Paramètres : panel = instance d'objet GLib à traiter. *
* *
-* Description : Affiche l'astuce précédente dans la liste globale. *
+* Description : Procède à la libération totale de la mémoire. *
* *
* Retour : - *
* *
@@ -872,107 +602,89 @@ static void g_welcome_panel_check_version(GWelcomePanel *panel)
* *
******************************************************************************/
-static void on_tip_previous_clicked(GtkButton *button, GWelcomePanel *panel)
+static void g_welcome_panel_finalize(GWelcomePanel *panel)
{
- if (panel->current > 0)
- panel->current--;
- else
- panel->current = panel->count - 1;
-
- g_welcome_panel_refresh_tip(panel);
+ G_OBJECT_CLASS(g_welcome_panel_parent_class)->finalize(G_OBJECT(panel));
}
/******************************************************************************
* *
-* Paramètres : button = bouton de défilement des astuces activé; *
-* panel = panneau associé comportant des informations utiles. *
+* Paramètres : - *
* *
-* Description : Affiche l'astuce suivante dans la liste globale. *
+* Description : Constitue une définition de manipulation de panneau. *
* *
-* Retour : - *
+* Retour : Définition de propriétés mise en place. *
* *
* Remarques : - *
* *
******************************************************************************/
-static void on_tip_next_clicked(GtkButton *button, GWelcomePanel *panel)
+GPanelItem *g_welcome_panel_new(void)
{
- if ((panel->current + 1) < panel->count)
- panel->current++;
- else
- panel->current = 0;
+ GPanelItem *result; /* Structure à retourner */
- g_welcome_panel_refresh_tip(panel);
+ result = g_object_new(G_TYPE_WELCOME_PANEL, NULL);
+
+ return result;
}
+
+/* ---------------------------------------------------------------------------------- */
+/* IMPLEMENTATION DES FONCTIONS DE CLASSE */
+/* ---------------------------------------------------------------------------------- */
+
+
/******************************************************************************
* *
-* Paramètres : panel = panneau associé comportant des informations utiles. *
+* Paramètres : panel = définition de panneau à consulter. *
* *
-* Description : Actualise l'affichage des astuces. *
+* Description : Fournit une indication sur la personnalité du panneau. *
* *
-* Retour : - *
+* Retour : Identifiant lié à la nature du panneau. *
* *
* Remarques : - *
* *
******************************************************************************/
-static void g_welcome_panel_refresh_tip(GWelcomePanel *panel)
+static PanelItemPersonality g_welcome_panel_get_personality(const GWelcomePanel *panel)
{
- GtkBuilder *builder; /* Constructeur utilisé */
- GtkLabel *label; /* Etiquette de présentation */
-
- 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"));
+ PanelItemPersonality result; /* Personnalité à retourner */
- gtk_label_set_markup(label, panel->tips[panel->current]);
+ result = PIP_MAIN_PANEL | PIP_SINGLETON;
- g_object_unref(G_OBJECT(builder));
+ return result;
}
/******************************************************************************
* *
-* Paramètres : panel = panneau associé comportant des informations utiles. *
+* Paramètres : panel = définition de panneau à manipuler. *
+* props = éventuels éléments graphiques de paramétrages. *
* *
-* Description : Indique l'origine de l'affichage du panneau d'accueil. *
+* Description : Fournit un composant représentant un panneau graphique. *
* *
-* Retour : true si l'affichage est le fait de l'utilisateur. *
+* Retour : Composant GTK (déjà ?) mis en place. *
* *
* Remarques : - *
* *
******************************************************************************/
-bool g_welcome_panel_get_user_origin(const GWelcomePanel *panel)
+static GtkTiledPanel *g_welcome_panel_get_panel(GWelcomePanel *panel, GtkWidget *props)
{
- return panel->uorigin;
+ GtkTiledPanel *result; /* Composant à retourner */
-}
+ /**
+ * Il n'existe pas de composants de paramètrage pour ce panneau.
+ */
+ assert(props == NULL);
+ result = gtk_welcome_panel_new();
-/******************************************************************************
-* *
-* 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;
+ return result;
}