diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2009-03-03 01:03:15 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2009-03-03 01:03:15 (GMT) |
commit | bbd04bf5f23e7dca1917247cb92824805b22a2a4 (patch) | |
tree | 548392c1c249ae5cde936f982783f192416e080c /src/panel | |
parent | c2d9948e1e67b48d1a6c8a711024d8dd3f6ac507 (diff) |
Created a system messages panel.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@50 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/panel')
-rwxr-xr-x | src/panel/Makefile.am | 17 | ||||
-rw-r--r-- | src/panel/log.c | 208 | ||||
-rw-r--r-- | src/panel/log.h | 55 | ||||
-rw-r--r-- | src/panel/panels.c | 71 | ||||
-rw-r--r-- | src/panel/panels.h | 51 |
5 files changed, 402 insertions, 0 deletions
diff --git a/src/panel/Makefile.am b/src/panel/Makefile.am new file mode 100755 index 0000000..cf70076 --- /dev/null +++ b/src/panel/Makefile.am @@ -0,0 +1,17 @@ + +lib_LIBRARIES = libpanel.a + +libpanel_a_SOURCES = \ + log.h log.c \ + panels.h panels.c + +libpanel_a_CFLAGS = $(AM_CFLAGS) + + +INCLUDES = $(LIBGTK_CFLAGS) + +AM_CPPFLAGS = + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) + +SUBDIRS = diff --git a/src/panel/log.c b/src/panel/log.c new file mode 100644 index 0000000..f98953f --- /dev/null +++ b/src/panel/log.c @@ -0,0 +1,208 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * log.c - panneau d'affichage des messages système + * + * Copyright (C) 2006-2007 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 "log.h" + + +#include <malloc.h> +#include <stdarg.h> +#include <stdio.h> + + +#include "panels.h" + + + +/* Colonnes de la liste des messages */ +typedef enum _LogColumn +{ + LGC_PICTURE, /* Image de représentation */ + LGC_STRING, /* Chaîne de caractères */ + + LGC_COUNT /* Nombre de colonnes */ + +} LogColumn; + + +#define _(str) str + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Construit le panneau d'affichage des messages système. * +* * +* Retour : Adresse du panneau mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkWidget *build_log_panel(void) +{ + GtkWidget *result; /* Panneau à retourner */ + GtkTreeStore *store; /* Modèle de gestion */ + GtkWidget *treeview; /* Affichage de la liste */ + GtkCellRenderer *renderer; /* Moteur de rendu de colonne */ + GtkTreeViewColumn *column; /* Colonne de la liste */ + GtkTreeSelection *select; /* Sélection dans la liste */ + + result = gtk_scrolled_window_new(NULL, NULL); + gtk_widget_show(result); + + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(result), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(result), GTK_SHADOW_IN); + + store = gtk_tree_store_new(LGC_COUNT, G_TYPE_STRING, G_TYPE_STRING); + g_object_set_data(G_OBJECT(result), "store", store); + + treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); + gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE); + gtk_widget_show(treeview); + gtk_container_add(GTK_CONTAINER(result), treeview); + + g_object_unref(G_OBJECT(store)); + + column = gtk_tree_view_column_new(); + gtk_tree_view_column_set_visible(column, FALSE); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); + gtk_tree_view_set_expander_column(GTK_TREE_VIEW(treeview), column); + + column = gtk_tree_view_column_new(); + + renderer = gtk_cell_renderer_pixbuf_new(); + gtk_tree_view_column_pack_start(column, renderer, FALSE); + gtk_tree_view_column_add_attribute(column, renderer, "stock-id", LGC_PICTURE); + + renderer = gtk_cell_renderer_text_new(); + gtk_tree_view_column_pack_start(column, renderer, TRUE); + gtk_tree_view_column_add_attribute(column, renderer, "text", LGC_STRING); + + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : panel = panneau à mettre à jour. * +* msg = message à faire apparaître à l'écran. * +* * +* Description : Affiche un message dans le journal des messages système. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void log_simple_message(LogMessageType type, const char *msg) +{ + GtkWidget *panel; /* Panneau à traiter */ + GtkTreeStore *store; /* Modèle de gestion */ + GtkTreeIter iter; /* Point d'insertion */ + + panel = get_panel(PNT_LOG); + store = g_object_get_data(G_OBJECT(panel), "store"); + + gtk_tree_store_append(store, &iter, NULL); + + switch (type) + { + case LMT_INFO: + gtk_tree_store_set(store, &iter, + LGC_PICTURE, "gtk-info", + LGC_STRING, msg, + -1); + break; + + case LMT_BAD_BINARY: + gtk_tree_store_set(store, &iter, + LGC_PICTURE, "gtk-dialog-warning", + LGC_STRING, msg, + -1); + break; + + } + +} + + +/****************************************************************************** +* * +* Paramètres : panel = panneau à mettre à jour. * +* fmt = format du message à faire apparaître à l'écran. * +* ... = éventuels arguments venant compléter le message. * +* * +* Description : Affiche un message dans le journal des messages système. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void log_variadic_message(LogMessageType type, const char *fmt, ...) +{ + size_t len; /* Taille tampon disponible */ + char *buffer; /* Tampon du msg reconstitué */ + int ret; /* Bilan d'une impression */ + char *ptr; /* Nouvelle allocation */ + va_list ap; /* Liste d'arguments variable */ + + len = 100; + buffer = calloc(len, sizeof(char)); + + while (buffer != NULL) + { + va_start(ap, fmt); + ret = vsnprintf(buffer, len, fmt, ap); + va_end(ap); + + if (ret >= 0 && ret < len) break; + + else + { + if (ret > -1) len += 1; /* glibc 2.1 */ + else len *= 2; /* glibc 2.0 */ + + if ((ptr = realloc(buffer, len)) == NULL) + { + free(buffer); + buffer = NULL; + } + else buffer = ptr; + + } + + } + + log_simple_message(type, buffer); + + free(buffer); + +} diff --git a/src/panel/log.h b/src/panel/log.h new file mode 100644 index 0000000..91e2c83 --- /dev/null +++ b/src/panel/log.h @@ -0,0 +1,55 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * log.h - prototypes pour le panneau d'affichage des messages système + * + * Copyright (C) 2006-2007 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 + */ + + +#ifndef _PANEL_LOG_H +#define _PANEL_LOG_H + + +#include <gtk/gtk.h> + + + +/* Type de messages disponibles */ +typedef enum _LogMessageType +{ + LMT_INFO, /* Information sur l'exécution */ + LMT_BAD_BINARY, /* Binaire malformé */ + + LMT_COUNT + +} LogMessageType; + + +/* Construit le panneau d'affichage des messages système. */ +GtkWidget *build_log_panel(void); + +/* Affiche un message dans le journal des messages système. */ +void log_simple_message(LogMessageType, const char *); + +/* Affiche un message dans le journal des messages système. */ +void log_variadic_message(LogMessageType, const char *, ...); + + + +#endif /* _PANEL_LOG_H */ diff --git a/src/panel/panels.c b/src/panel/panels.c new file mode 100644 index 0000000..a127825 --- /dev/null +++ b/src/panel/panels.c @@ -0,0 +1,71 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * panels.h - gestion des différents panneaux + * + * Copyright (C) 2006-2007 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 "log.h" + + + +static GtkWidget *panel_list[PNT_COUNT]; + + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Procède au chargement de tous les panneaux. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void init_panels(void) +{ + panel_list[PNT_LOG] = build_log_panel(); + +} + + +/****************************************************************************** +* * +* Paramètres : id = identifiant du panneau visé. * +* * +* Description : Fournit la référence d'un panneau donné. * +* * +* Retour : Adresse du composant GTK en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkWidget *get_panel(PanelType id) +{ + return panel_list[id]; + +} diff --git a/src/panel/panels.h b/src/panel/panels.h new file mode 100644 index 0000000..87ddfa6 --- /dev/null +++ b/src/panel/panels.h @@ -0,0 +1,51 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * panels.h - prototypes pour la gestion des différents panneaux + * + * Copyright (C) 2006-2007 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 + */ + + +#ifndef _PANEL_PANELS_H +#define _PANEL_PANELS_H + + +#include <gtk/gtk.h> + + + +/* Liste de tous les panneaux */ +typedef enum _PanelType +{ + PNT_LOG, /* Messages système */ + + PNT_COUNT + +} PanelType; + + +/* Procède au chargement de tous les panneaux. */ +void init_panels(void); + +/* Fournit la référence d'un panneau donné. */ +GtkWidget *get_panel(PanelType); + + + +#endif /* _PANEL_PANELS_H */ |