summaryrefslogtreecommitdiff
path: root/src/gui/panels/errors.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2018-02-11 15:33:56 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2018-02-11 15:33:56 (GMT)
commita11ef1ad68fdb86d4a7d75b0ddeea126aa1adb09 (patch)
treec7041d47ad78719994496c9c33400f2eeb3778a4 /src/gui/panels/errors.c
parent9d8d54a4ee29f98b475347d3bbc925d9a526c352 (diff)
Created a dedicated interface fot panel updating.
Diffstat (limited to 'src/gui/panels/errors.c')
-rw-r--r--src/gui/panels/errors.c378
1 files changed, 264 insertions, 114 deletions
diff --git a/src/gui/panels/errors.c b/src/gui/panels/errors.c
index f62e684..f27d0fc 100644
--- a/src/gui/panels/errors.c
+++ b/src/gui/panels/errors.c
@@ -34,6 +34,7 @@
#include "panel-int.h"
+#include "updating-int.h"
#include "../core/global.h"
#include "../../core/global.h"
#include "../../format/format.h"
@@ -42,6 +43,9 @@
+/* ----------------------- PRESENTATION GRAPHIQUE DES ERREURS ----------------------- */
+
+
/* Origine de la dernière ouverture/fermeture reproductible */
typedef enum _UserActionType
{
@@ -111,12 +115,19 @@ typedef struct _error_desc_t
} error_desc_t;
+/* Données utiles à la mise à jour */
+typedef struct _error_update_data error_update_data;
+
+
/* Initialise la classe des panneaux d'affichage des erreurs. */
static void g_error_panel_class_init(GErrorPanelClass *);
/* Initialise une instance de panneau d'affichage des erreurs. */
static void g_error_panel_init(GErrorPanel *);
+/* Procède à l'initialisation de l'interface de mise à jour. */
+static void g_error_panel_interface_init(GUpdatablePanelInterface *);
+
/* Supprime toutes les références externes. */
static void g_error_panel_dispose(GErrorPanel *);
@@ -130,24 +141,58 @@ static gint sort_errors_in_panel(GtkTreeModel *, GtkTreeIter *, GtkTreeIter *, g
static void update_panel_with_binary_errors(GErrorPanel *, GLoadedBinary *);
/* Effectue la mise à jour du contenu du panneau d'erreurs. */
-static void update_error_panel(GErrorPanel *, GtkStatusStack *, activity_id_t);
+static void update_error_panel(const GErrorPanel *, GtkStatusStack *, activity_id_t, error_update_data *);
/* Actualise l'affichage des erreurs sur la base des filtres. */
static void on_error_filter_toggled(GtkToggleButton *, GErrorPanel *);
/* Filtre l'affichage du contenu du panneau d'erreurs. */
-static void filter_error_panel(GErrorPanel *, GtkStatusStack *, activity_id_t);
+static void filter_error_panel(const GErrorPanel *, GtkStatusStack *, activity_id_t, error_update_data *);
/* Affiche un petit résumé concis des soucis remontés. */
-static void update_error_panel_summary(GPanelUpdate *, GErrorPanel *);
+static void update_error_panel_summary(const GErrorPanel *);
/* Réagit au changement de sélection des portions. */
static void on_error_selection_changed(GtkTreeSelection *, gpointer);
+/* ---------------------- MECANISMES DE MISE A JOUR DE PANNEAU ---------------------- */
+
+
+/* Données utiles à la mise à jour */
+struct _error_update_data
+{
+ GtkTreeModel *model; /* Source de données associée */
+
+ size_t count; /* Nombre de soucis présents */
+ size_t kept; /* Nombre d'éléments affichés */
+
+};
+
+
+/* Prépare une opération de mise à jour de panneau. */
+static const char *g_error_panel_setup(const GErrorPanel *, unsigned int, size_t *, error_update_data **);
+
+/* Bascule l'affichage d'un panneau avant mise à jour. */
+static void g_error_panel_introduce(const GErrorPanel *, unsigned int, error_update_data *);
+
+/* Réalise une opération de mise à jour de panneau. */
+static void g_error_panel_process(const GErrorPanel *, unsigned int, GtkStatusStack *, activity_id_t, error_update_data *);
+
+/* Bascule l'affichage d'un panneau après mise à jour. */
+static void g_error_panel_conclude(GErrorPanel *, unsigned int, error_update_data *);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* PRESENTATION GRAPHIQUE DES ERREURS */
+/* ---------------------------------------------------------------------------------- */
+
+
/* Indique le type défini pour un panneau d'affichage des erreurs. */
-G_DEFINE_TYPE(GErrorPanel, g_error_panel, G_TYPE_PANEL_ITEM);
+G_DEFINE_TYPE_WITH_CODE(GErrorPanel, g_error_panel, G_TYPE_PANEL_ITEM,
+ G_IMPLEMENT_INTERFACE(G_TYPE_UPDATABLE_PANEL, g_error_panel_interface_init))
/******************************************************************************
@@ -303,6 +348,28 @@ static void g_error_panel_init(GErrorPanel *panel)
/******************************************************************************
* *
+* Paramètres : iface = interface GLib à initialiser. *
+* *
+* Description : Procède à l'initialisation de l'interface de mise à jour. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_error_panel_interface_init(GUpdatablePanelInterface *iface)
+{
+ iface->setup = (setup_updatable_cb)g_error_panel_setup;
+ iface->introduce = (introduce_updatable_cb)g_error_panel_introduce;
+ iface->process = (process_updatable_cb)g_error_panel_process;
+ iface->conclude = (conclude_updatable_cb)g_error_panel_conclude;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : panel = instance d'objet GLib à traiter. *
* *
* Description : Supprime toutes les références externes. *
@@ -417,11 +484,6 @@ static gint sort_errors_in_panel(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIte
static void update_panel_with_binary_errors(GErrorPanel *panel, GLoadedBinary *binary)
{
GtkListStore *store; /* Modèle de gestion */
- GBinFormat *format; /* Format du binaire */
- size_t fcount; /* Quantité d'erreurs #1 */
- GArchProcessor *proc; /* Architecture du binaire */
- size_t pcount; /* Quantité d'erreurs #2 */
- GPanelUpdate *update; /* Procédure de mise à jour */
/* Réinitialisation */
@@ -439,41 +501,11 @@ static void update_panel_with_binary_errors(GErrorPanel *panel, GLoadedBinary *b
/* Actualisation de l'affichage */
- if (binary != NULL)
- {
- format = G_BIN_FORMAT(g_loaded_binary_get_format(binary));
-
- g_binary_format_lock_errors(format);
- fcount = g_binary_format_count_errors(format);
- g_binary_format_unlock_errors(format);
-
- g_object_unref(G_OBJECT(format));
-
- proc = g_loaded_binary_get_processor(binary);
-
- g_arch_processor_lock_errors(proc);
- pcount = g_arch_processor_count_errors(proc);
- g_arch_processor_unlock_errors(proc);
-
- g_object_unref(G_OBJECT(proc));
-
- }
-
- else
- {
- fcount = 0;
- pcount = 0;
- }
-
- update = g_panel_update_new(G_PANEL_ITEM(panel),
- _("Loading errors occurred during the disassembling process..."),
- fcount + pcount,
- (pu_fallback_cb)update_error_panel);
+ panel->count = 0;
+ panel->kept = 0;
- g_signal_connect_to_main(update, "work-completed", G_CALLBACK(update_error_panel_summary), panel,
- g_cclosure_marshal_VOID__VOID);
-
- g_work_queue_schedule_work(get_work_queue(), G_DELAYED_WORK(update), DEFAULT_WORK_GROUP);
+ if (binary != NULL)
+ run_panel_update(G_UPDATABLE_PANEL(panel), PUI_0);
}
@@ -483,6 +515,7 @@ static void update_panel_with_binary_errors(GErrorPanel *panel, GLoadedBinary *b
* Paramètres : panel = panneau à mettre à jour. *
* status = barre de statut à tenir informée. *
* id = identifiant pour le suivi de la progression. *
+* data = données complémentaire à manipuler. *
* *
* Description : Effectue la mise à jour du contenu du panneau d'erreurs. *
* *
@@ -492,10 +525,8 @@ static void update_panel_with_binary_errors(GErrorPanel *panel, GLoadedBinary *b
* *
******************************************************************************/
-static void update_error_panel(GErrorPanel *panel, GtkStatusStack *status, activity_id_t id)
+static void update_error_panel(const GErrorPanel *panel, GtkStatusStack *status, activity_id_t id, error_update_data *data)
{
- GtkTreeView *treeview; /* Arborescence graphique */
- GtkTreeModel *model; /* Source de données associée */
GtkListStore *store; /* Modèle de gestion */
GBinFormat *format; /* Format du binaire */
size_t fcount; /* Quantité d'erreurs #1 */
@@ -505,8 +536,6 @@ static void update_error_panel(GErrorPanel *panel, GtkStatusStack *status, activ
gboolean show_format; /* Affichages liés au format */
gboolean show_disass; /* Affichages liés à l'arch. */
gboolean show_output; /* Affichages liés à la sortie */
- size_t count; /* Nombre de soucis présents */
- size_t kept; /* Nombre d'éléments affichés */
GtkTreeIter iter; /* Point d'insertion */
size_t i; /* Boucle de parcours */
error_desc_t error; /* Description de soucis */
@@ -514,15 +543,6 @@ static void update_error_panel(GErrorPanel *panel, GtkStatusStack *status, activ
bool ret; /* Bilan d'une récupération */
#endif
- /* Basculement de l'affichage hors ligne */
-
- treeview = GTK_TREE_VIEW(gtk_builder_get_object(panel->builder, "treeview"));
-
- model = gtk_tree_view_get_model(treeview);
- g_object_ref(G_OBJECT(model));
-
- gtk_tree_view_set_model(treeview, NULL);
-
store = GTK_LIST_STORE(gtk_builder_get_object(panel->builder, "store"));
/* Recensement initial */
@@ -549,15 +569,12 @@ static void update_error_panel(GErrorPanel *panel, GtkStatusStack *status, activ
{
button = GTK_TOGGLE_BUTTON(gtk_builder_get_object(panel->builder, "format"));
gtk_widget_set_sensitive(GTK_WIDGET(button), FALSE);
- show_format = gtk_toggle_button_get_active(button);
button = GTK_TOGGLE_BUTTON(gtk_builder_get_object(panel->builder, "disass"));
gtk_widget_set_sensitive(GTK_WIDGET(button), FALSE);
- show_disass = gtk_toggle_button_get_active(button);
button = GTK_TOGGLE_BUTTON(gtk_builder_get_object(panel->builder, "output"));
gtk_widget_set_sensitive(GTK_WIDGET(button), FALSE);
- show_output = gtk_toggle_button_get_active(button);
gtk_list_store_append(store, &iter);
@@ -569,8 +586,8 @@ static void update_error_panel(GErrorPanel *panel, GtkStatusStack *status, activ
ETC_VISIBLE, TRUE,
-1);
- count = 0;
- kept = 0;
+ data->count = 0;
+ data->kept = 0;
}
@@ -675,17 +692,14 @@ static void update_error_panel(GErrorPanel *panel, GtkStatusStack *status, activ
ETC_ADDR, &e->addr,
-1);
- count++;
+ data->count++;
if (state)
- kept++;
+ data->kept++;
}
- count = 0;
- kept = 0;
-
for (i = 0; i < fcount; i++)
{
/* On remet à zéro tous les octets de l'union ! */
@@ -740,15 +754,6 @@ static void update_error_panel(GErrorPanel *panel, GtkStatusStack *status, activ
}
- panel->count = count;
- panel->kept = kept;
-
- /* Basculement de l'affichage en ligne */
-
- gtk_tree_view_set_model(treeview, model);
-
- g_object_unref(G_OBJECT(model));
-
}
@@ -767,17 +772,7 @@ static void update_error_panel(GErrorPanel *panel, GtkStatusStack *status, activ
static void on_error_filter_toggled(GtkToggleButton *button, GErrorPanel *panel)
{
- GPanelUpdate *update; /* Procédure de mise à jour */
-
- update = g_panel_update_new(G_PANEL_ITEM(panel),
- _("Filtering errors occurred during the disassembling process..."),
- panel->count,
- (pu_fallback_cb)filter_error_panel);
-
- g_signal_connect_to_main(update, "work-completed", G_CALLBACK(update_error_panel_summary), panel,
- g_cclosure_marshal_VOID__VOID);
-
- g_work_queue_schedule_work(get_work_queue(), G_DELAYED_WORK(update), DEFAULT_WORK_GROUP);
+ run_panel_update(G_UPDATABLE_PANEL(panel), PUI_1);
}
@@ -787,6 +782,7 @@ static void on_error_filter_toggled(GtkToggleButton *button, GErrorPanel *panel)
* Paramètres : panel = panneau à mettre à jour. *
* status = barre de statut à tenir informée. *
* id = identifiant pour le suivi de la progression. *
+* data = données complémentaire à manipuler. *
* *
* Description : Filtre l'affichage du contenu du panneau d'erreurs. *
* *
@@ -796,31 +792,19 @@ static void on_error_filter_toggled(GtkToggleButton *button, GErrorPanel *panel)
* *
******************************************************************************/
-static void filter_error_panel(GErrorPanel *panel, GtkStatusStack *status, activity_id_t id)
+static void filter_error_panel(const GErrorPanel *panel, GtkStatusStack *status, activity_id_t id, error_update_data *data)
{
- GtkTreeView *treeview; /* Arborescence graphique */
- GtkTreeModel *model; /* Source de données associée */
GtkTreeModel *store; /* Modèle de gestion */
GtkToggleButton *button; /* Bouton à manipuler */
gboolean show_format; /* Affichages liés au format */
gboolean show_disass; /* Affichages liés à l'arch. */
gboolean show_output; /* Affichages liés à la sortie */
- size_t kept; /* Nombre d'éléments affichés */
GtkTreeIter iter; /* Boucle de parcours */
gboolean valid; /* Validité du point courant */
gboolean format; /* Origine du soucis remonté */
guint errno; /* Code d'erreur associé */
gboolean state; /* Bilan d'un filtrage */
- /* Basculement de l'affichage hors ligne */
-
- treeview = GTK_TREE_VIEW(gtk_builder_get_object(panel->builder, "treeview"));
-
- model = gtk_tree_view_get_model(treeview);
- g_object_ref(G_OBJECT(model));
-
- gtk_tree_view_set_model(treeview, NULL);
-
store = GTK_TREE_MODEL(gtk_builder_get_object(panel->builder, "store"));
/* Actualisation des données */
@@ -866,8 +850,6 @@ static void filter_error_panel(GErrorPanel *panel, GtkStatusStack *status, activ
}
- kept = 0;
-
for (valid = gtk_tree_model_get_iter_first(store, &iter);
valid;
valid = gtk_tree_model_iter_next(store, &iter))
@@ -881,27 +863,18 @@ static void filter_error_panel(GErrorPanel *panel, GtkStatusStack *status, activ
-1);
if (state)
- kept++;
+ data->kept++;
gtk_status_stack_update_activity_value(status, id, 1);
}
- panel->kept = kept;
-
- /* Basculement de l'affichage en ligne */
-
- gtk_tree_view_set_model(treeview, model);
-
- g_object_unref(G_OBJECT(model));
-
}
/******************************************************************************
* *
-* Paramètres : update = tâche venant de se terminer. *
-* panel = structure contenant les informations maîtresses. *
+* Paramètres : panel = structure contenant les informations maîtresses. *
* *
* Description : Affiche un petit résumé concis des soucis remontés. *
* *
@@ -911,7 +884,7 @@ static void filter_error_panel(GErrorPanel *panel, GtkStatusStack *status, activ
* *
******************************************************************************/
-static void update_error_panel_summary(GPanelUpdate *update, GErrorPanel *panel)
+static void update_error_panel_summary(const GErrorPanel *panel)
{
GtkLabel *summary; /* Etiquette à mettre à jour */
char *msg; /* Bilan à faire afficher */
@@ -975,3 +948,180 @@ static void on_error_selection_changed(GtkTreeSelection *selection, gpointer unu
}
}
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* MECANISMES DE MISE A JOUR DE PANNEAU */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : panel = panneau ciblé par une mise à jour. *
+* uid = identifiant de la phase de traitement. *
+* count = nombre d'étapes à prévoir dans le traitement. [OUT] *
+* data = données sur lesquelles s'appuyer ensuite. [OUT] *
+* *
+* Description : Prépare une opération de mise à jour de panneau. *
+* *
+* Retour : Description du message d'information. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static const char *g_error_panel_setup(const GErrorPanel *panel, unsigned int uid, size_t *count, error_update_data **data)
+{
+ const char *result; /* Message à retourner */
+ GBinFormat *format; /* Format du binaire */
+ size_t fcount; /* Quantité d'erreurs #1 */
+ GArchProcessor *proc; /* Architecture du binaire */
+ size_t pcount; /* Quantité d'erreurs #2 */
+
+ *data = malloc(sizeof(error_update_data));
+
+ switch (uid)
+ {
+ case PUI_0:
+
+ format = G_BIN_FORMAT(g_loaded_binary_get_format(panel->binary));
+
+ g_binary_format_lock_errors(format);
+ fcount = g_binary_format_count_errors(format);
+ g_binary_format_unlock_errors(format);
+
+ g_object_unref(G_OBJECT(format));
+
+ proc = g_loaded_binary_get_processor(panel->binary);
+
+ g_arch_processor_lock_errors(proc);
+ pcount = g_arch_processor_count_errors(proc);
+ g_arch_processor_unlock_errors(proc);
+
+ g_object_unref(G_OBJECT(proc));
+
+ *count = fcount + pcount;
+
+ result = _("Loading errors occurred during the disassembling process...");
+
+ (*data)->count = *count;
+ (*data)->kept = 0;
+
+ break;
+
+ case PUI_1:
+
+ *count = panel->count;
+
+ result = _("Filtering errors occurred during the disassembling process...");
+
+ (*data)->count = panel->count;
+ (*data)->kept = 0;
+
+ break;
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : panel = panneau ciblé par une mise à jour. *
+* uid = identifiant de la phase de traitement. *
+* data = données préparées par l'appelant. *
+* *
+* Description : Bascule l'affichage d'un panneau avant mise à jour. *
+* *
+* Retour : - *
+* *
+* Remarques : Cette fonction est appelée depuis le contexte principal. *
+* *
+******************************************************************************/
+
+static void g_error_panel_introduce(const GErrorPanel *panel, unsigned int uid, error_update_data *data)
+{
+ GtkTreeView *treeview; /* Arborescence graphique */
+
+ /* Basculement de l'affichage hors ligne */
+
+ treeview = GTK_TREE_VIEW(gtk_builder_get_object(panel->builder, "treeview"));
+
+ data->model = gtk_tree_view_get_model(treeview);
+ g_object_ref(G_OBJECT(data->model));
+
+ gtk_tree_view_set_model(treeview, NULL);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : panel = panneau ciblé par une mise à jour. *
+* uid = identifiant de la phase de traitement. *
+* status = barre de statut à tenir informée. *
+* id = identifiant pour le suivi de la progression. *
+* data = données préparées par l'appelant. *
+* *
+* Description : Réalise une opération de mise à jour de panneau. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_error_panel_process(const GErrorPanel *panel, unsigned int uid, GtkStatusStack *status, activity_id_t id, error_update_data *data)
+{
+ switch (uid)
+ {
+ case PUI_0:
+ update_error_panel(panel, status, id, data);
+ break;
+
+ case PUI_1:
+ filter_error_panel(panel, status, id, data);
+ break;
+
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : panel = panneau ciblé par une mise à jour. *
+* uid = identifiant de la phase de traitement. *
+* data = données préparées par l'appelant. *
+* *
+* Description : Bascule l'affichage d'un panneau après mise à jour. *
+* *
+* Retour : - *
+* *
+* Remarques : Cette fonction est appelée depuis le contexte principal. *
+* *
+******************************************************************************/
+
+static void g_error_panel_conclude(GErrorPanel *panel, unsigned int uid, error_update_data *data)
+{
+ GtkTreeView *treeview; /* Arborescence graphique */
+
+ /* Mise à jour des statistiques */
+
+ panel->count = data->count;
+ panel->kept = data->kept;
+
+ update_error_panel_summary(panel);
+
+ /* Basculement de l'affichage en ligne */
+
+ treeview = GTK_TREE_VIEW(gtk_builder_get_object(panel->builder, "treeview"));
+
+ gtk_tree_view_set_model(treeview, data->model);
+
+ g_object_unref(G_OBJECT(data->model));
+
+}