diff options
Diffstat (limited to 'src/panels/log.c')
-rw-r--r-- | src/panels/log.c | 244 |
1 files changed, 0 insertions, 244 deletions
diff --git a/src/panels/log.c b/src/panels/log.c deleted file mode 100644 index fdbda1d..0000000 --- a/src/panels/log.c +++ /dev/null @@ -1,244 +0,0 @@ - -/* OpenIDA - Outil d'analyse de fichiers binaires - * log.c - panneau d'affichage des messages système - * - * Copyright (C) 2009-2011 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 "panel.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 */ - - 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)); - g_object_set_data(G_OBJECT(result), "treeview", treeview); - 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 : type = espèce du message à ajouter. * -* 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 */ - GtkTreeView *treeview; /* Affichage de la liste */ - GtkTreePath *path; /* Chemin d'accès à la ligne */ - - 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; - - case LMT_PROCESS: - gtk_tree_store_set(store, &iter, - LGC_PICTURE, "gtk-execute", - LGC_STRING, msg, - -1); - break; - - case LMT_ERROR: - gtk_tree_store_set(store, &iter, - LGC_PICTURE, "gtk-dialog-error", - LGC_STRING, msg, - -1); - break; - - case LMT_WARNING: - gtk_tree_store_set(store, &iter, - LGC_PICTURE, "gtk-dialog-warning", - LGC_STRING, msg, - -1); - break; - - default: - gtk_tree_store_set(store, &iter, - LGC_STRING, msg, - -1); - break; - - } - - treeview = GTK_TREE_VIEW(g_object_get_data(G_OBJECT(panel), "treeview")); - path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter); - - gtk_tree_view_scroll_to_cell(treeview, path, NULL, FALSE, 0.0, 0.0); - - gtk_tree_path_free(path); - -} - - -/****************************************************************************** -* * -* Paramètres : type = espèce du message à ajouter. * -* 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); - -} |