/* ***********************IMPORTANT *********************************************
 *  Copyright (C) 2004-2007 Thierry Lagarde <tlagarde@users.sourceforge.net>
 *  This program 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 2 of the License.
 *
 *
 *                      ********************
 *
 *
 *  This program 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 Library General Public License for more details.
 *
 *
 *                      ********************
 *
 *
 * You are highly encouraged to send your changes to <tlagarde@users.sourceforge.net>
 * for possible incorporation into the main distribution.
 * By sending these changes to <tlagarde@users.sourceforge.net>,
 * it is assumed that you are offering <tlagarde@users.sourceforge.net>
 * the unlimited, non-exclusive right to reuse, modify, and relicense the code.
 *
 *
 *                      ********************
 *
 *  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 "Snmp.h"
#include "Com/Commun.h"
#include "Com/Communication.h"
#include "Debug.h"
#include "Objet.h"
#include "Modules.h"
#include "Interface/Snmp_Interface.h"
#include "Interface/Root_Interface.h"
#include "Objet_Liste.h"
#include "Macro.h"



struct struct_Colonne_Liste_Snmp Colonne_Liste_Snmp[] = {
	{SNMP_SYSTEM_DEVICE, 2, -1, COLONNE_TEXTE, "Type"},
	{SNMP_SYSTEM_DEVICE, 3, -1, COLONNE_TEXTE, "Description"},
	{SNMP_SYSTEM_DEVICE, 5, -1, COLONNE_TEXTE, "Status"},

	{SNMP_SYSTEM_LOGICAL_STORAGE, 3, -1, COLONNE_TEXTE, "Disk"},
	{SNMP_SYSTEM_LOGICAL_STORAGE, 5, 6, COLONNE_PROGRESS, "Used"},

	{SNMP_SYSTEM_SERVICE, 1, -1, COLONNE_TEXTE, "Name"},
	{SNMP_SYSTEM_SERVICE, 2, -1, COLONNE_TEXTE, "State"},
	{SNMP_NETWORK_ARP, 1, -1, COLONNE_TEXTE, "Interface"},
	{SNMP_NETWORK_ARP, 2, -1, COLONNE_TEXTE, "PhysAddress"},
	{SNMP_NETWORK_ARP, 3, -1, COLONNE_TEXTE, "NetAddress"},
	{SNMP_NETWORK_ARP, 4, -1, COLONNE_TEXTE, "Type"},
	{SNMP_NETWORK_ROUTES, 1, -1, COLONNE_TEXTE, "RouteDest"},
	{SNMP_NETWORK_ROUTES, 11, -1, COLONNE_TEXTE, "RouteMask"},
	{SNMP_NETWORK_ROUTES, 7, -1, COLONNE_TEXTE, "Gateway"},
	{SNMP_NETWORK_ROUTES, 2, -1, COLONNE_TEXTE, "Interface"},
	{SNMP_NETWORK_ROUTES, 8, -1, COLONNE_TEXTE, "RouteType"},
	{SNMP_NETWORK_ROUTES, 9, -1, COLONNE_TEXTE, "RouteProto"},
	{SNMP_NETWORK_ROUTES, 10, -1, COLONNE_TEXTE, "RouteAge"},
	{SNMP_NETWORK_ROUTES, 3, -1, COLONNE_TEXTE, "Metric"},
	{SNMP_NETWORK_INTERFACES_BASIC, 2, -1, COLONNE_TEXTE, "Description"},
	{SNMP_NETWORK_INTERFACES_BASIC, 3, -1, COLONNE_TEXTE, "Type"},
	{SNMP_NETWORK_INTERFACES_BASIC, 4, -1, COLONNE_TEXTE, "MTU"},
	{SNMP_NETWORK_INTERFACES_BASIC, 5, -1, COLONNE_TEXTE, "Speed"},
	{SNMP_NETWORK_INTERFACES_BASIC, 6, -1, COLONNE_TEXTE, "PhysAddres"},
	{SNMP_NETWORK_INTERFACES_BASIC, 7, -1, COLONNE_TEXTE, "Status"},
	{SNMP_NETWORK_INTERFACES_BASIC, 8, -1, COLONNE_TEXTE, "Status"},
	{SNMP_NETWORK_INTERFACES_BASIC, 10, -1, COLONNE_TEXTE, "LastChange"},
	{SNMP_NETWORK_INTERFACES_BASIC, 11, -1, COLONNE_TEXTE, "InOctets"},
	{SNMP_NETWORK_INTERFACES_BASIC, 15, -1, COLONNE_TEXTE, "InErrors"},
	{SNMP_NETWORK_INTERFACES_BASIC, 16, -1, COLONNE_TEXTE, "UnknownProtos"},
	{SNMP_NETWORK_INTERFACES_BASIC, 17, -1, COLONNE_TEXTE, "OutOctets"},
	{SNMP_NETWORK_INTERFACES_BASIC, 21, -1, COLONNE_TEXTE, "OutErrors"},
	{SNMP_NETWORK_TCPIP_TCP_CONNECTIONS, 1, -1, COLONNE_TEXTE, "State"},
	{SNMP_NETWORK_TCPIP_TCP_CONNECTIONS, 2, -1, COLONNE_TEXTE, "LocalAddress"},
	{SNMP_NETWORK_TCPIP_TCP_CONNECTIONS, 3, -1, COLONNE_TEXTE, "LocalPort"},
	{SNMP_NETWORK_TCPIP_TCP_CONNECTIONS, 4, -1, COLONNE_TEXTE, "RemoteAddress"},
	{SNMP_NETWORK_TCPIP_TCP_CONNECTIONS, 5, -1, COLONNE_TEXTE, "RemotePort"},
	{SNMP_NETWORK_TCPIP_UDP_SERVICES, 1, -1, COLONNE_TEXTE, "LocalAddress"},
	{SNMP_NETWORK_TCPIP_UDP_SERVICES, 2, -1, COLONNE_TEXTE, "LocalPort"},
	{SNMP_SOFTWARE, 1, -1, COLONNE_TEXTE, "PID"},
	{SNMP_SOFTWARE, 2, -1, COLONNE_TEXTE, "Name"},
	{SNMP_SOFTWARE, 6, -1, COLONNE_TEXTE, "Type"},
	{SNMP_SOFTWARE, 7, -1, COLONNE_TEXTE, "State"},
	{SNMP_BRIDGE_FORWARDING_DATABASE, 1, -1, COLONNE_TEXTE, "MAC forwarding address"},
	{SNMP_BRIDGE_FORWARDING_DATABASE, 2, -1, COLONNE_TEXTE, "Port number"},
	{SNMP_BRIDGE_FORWARDING_DATABASE, 3, -1, COLONNE_TEXTE, "Status"},
	{SNMP_BRIDGE_STATIC_DATABASE, 1, -1, COLONNE_TEXTE, "Destination MAC address"},
	{SNMP_BRIDGE_STATIC_DATABASE, 2, -1, COLONNE_TEXTE, "Received port number"},
	{SNMP_BRIDGE_STATIC_DATABASE, 3, -1, COLONNE_TEXTE, "Allowed to go to"},
	{SNMP_BRIDGE_STATIC_DATABASE, 4, -1, COLONNE_TEXTE, "Status"}
};


void Efface_Info_Utilisation_Disque(){
GtkTreeModel *model = NULL;

	model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview_Info_Disk));
	gtk_tree_store_clear (GTK_TREE_STORE (model));
}



GtkWidget * Create_Liste_Snmp(gint ID_Snmp){
	GtkTreeStore *Store = NULL;
	GType    *column_types = NULL;
	GtkTreeModel *model = NULL;
	GtkTreeViewColumn *col = NULL;
	GtkCellRenderer *texte = NULL;
	GtkCellRenderer *progress = NULL;
	GtkWidget *view;
	gint Nb_Total_Colonne_Defini,Nb_Colonne,i,j;

	Nb_Total_Colonne_Defini = sizeof (Colonne_Liste_Snmp) / sizeof (struct struct_Colonne_Liste_Snmp);

	Nb_Colonne = 0;
	for (i = 0; i < Nb_Total_Colonne_Defini; i++)
		if (Colonne_Liste_Snmp[i].ID_Snmp == ID_Snmp)
			Nb_Colonne++;

	column_types = g_new (GType, Nb_Colonne);

	Nb_Colonne = 0;
	for (i = 0; i < Nb_Total_Colonne_Defini; i++)
		if (Colonne_Liste_Snmp[i].ID_Snmp == ID_Snmp) {
			switch (Colonne_Liste_Snmp[i].Type_Colonne) {
			    case COLONNE_TEXTE:
				    column_types[Nb_Colonne] = G_TYPE_STRING;
				    break;
			    case COLONNE_PROGRESS:
				    column_types[Nb_Colonne] = G_TYPE_INT;
				    break;
			    default:
				    debug_printf (INTERFACE, D_ERRO, __FILE__, __PRETTY_FUNCTION__, __LINE__, "Type_Colonne inconnu");
			}
			Nb_Colonne++;
		}
	Store = gtk_tree_store_newv (Nb_Colonne, column_types);
	model = GTK_TREE_MODEL (Store);

	view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));

	j = 0;
	for (i = 0; i < Nb_Total_Colonne_Defini; i++)
		if (Colonne_Liste_Snmp[i].ID_Snmp == ID_Snmp) {
			col = gtk_tree_view_column_new ();
			gtk_tree_view_column_set_title (col, Colonne_Liste_Snmp[i].Nom_Colonne);
			switch (Colonne_Liste_Snmp[i].Type_Colonne) {
			    case COLONNE_TEXTE:
				    texte = gtk_cell_renderer_text_new ();
				    gtk_tree_view_column_pack_start (col, texte, FALSE);
		    	gtk_tree_view_column_set_attributes (col, texte, "text", j, NULL);
		   		 break;
		    	case COLONNE_PROGRESS:
			    progress = gtk_cell_renderer_progress_new ();
			    gtk_tree_view_column_pack_start (col, progress, TRUE);
			    gtk_tree_view_column_set_attributes (col, progress, "value", j, NULL);
			    break;
		    default:
			    debug_printf (INTERFACE, D_ERRO, __FILE__, __PRETTY_FUNCTION__, __LINE__, "Type_Colonne inconnu");
			}
			j++;
			gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
		}
	return view;
}



void Affiche_Liste_Snmp(gint ID_Snmp,GtkWidget *treeview){
	struct struct_Liste_Snmp *Info = NULL;
	GtkTreeModel *model = NULL;
	gint      i, j, ligne, colonne, Nb_Ligne_Total, nb_Info,Nb_Total_Colonne_Defini;
	GList    *Glist_Snmp = NULL;
	GtkTreeIter Ligne;
	gchar    *Texte = NULL, *Texte2 = NULL;
	GtkTreeViewColumn *col = NULL;
	GtkCellRenderer *texte = NULL;
	GtkCellRenderer *progress = NULL;

	ERROR_if (Equipement_Selectionner->Glist_Snmp[ID_Snmp] == NULL);
	ERROR_if (treeview == NULL);
	Glist_Snmp = Equipement_Selectionner->Glist_Snmp[ID_Snmp];
	Nb_Total_Colonne_Defini = sizeof (Colonne_Liste_Snmp) / sizeof (struct struct_Colonne_Liste_Snmp);
	model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
	gtk_tree_store_clear (GTK_TREE_STORE (model));

	Nb_Ligne_Total = -1;
	nb_Info = g_list_length (Glist_Snmp);

	for (i = 0; i < nb_Info; i++) {
		Info = g_list_nth_data (Glist_Snmp, i);
		if (Nb_Ligne_Total < Info->Ligne)
			Nb_Ligne_Total = Info->Ligne;
	}



	for (ligne = 0; ligne <= Nb_Ligne_Total; ligne++) {
		gtk_tree_store_append (GTK_TREE_STORE (model), &Ligne, NULL);
		colonne = 0;
	
		for (j = 0; j < Nb_Total_Colonne_Defini; j++)
			if (Colonne_Liste_Snmp[j].ID_Snmp == ID_Snmp) {
				i = 0;
				Texte = NULL;
				while ((nb_Info > i) && (Texte == NULL)) {
					Info = g_list_nth_data (Glist_Snmp, i);
				
					if ((Info->Colonne == Colonne_Liste_Snmp[j].Colonne) && (Info->Ligne == ligne)) {
						Texte = Info->Info;
					
					}
					i++;
				}
				Texte2 = NULL;
				if (Colonne_Liste_Snmp[j].Colonne2 != -1) {
					i = 0;
					while ((nb_Info > i) && (Texte2 == NULL)) {
						Info = g_list_nth_data (Glist_Snmp, i);
						if ((Info->Colonne == Colonne_Liste_Snmp[j].Colonne2) && (Info->Ligne == ligne)) {
							Texte2 = Info->Info;
						
						}
						i++;

					}
				}
				switch (Colonne_Liste_Snmp[j].Type_Colonne) {
				    case COLONNE_TEXTE:
					    if (Texte != NULL)
						    gtk_tree_store_set (GTK_TREE_STORE (model), &Ligne, colonne, Texte, -1);
					    break;
				    case COLONNE_PROGRESS:
					    if (atoi (Texte) != 0)
						    gtk_tree_store_set (GTK_TREE_STORE (model), &Ligne, colonne, (atoi (Texte2) * 100) / atoi (Texte), -1);
					    else
						    gtk_tree_store_set (GTK_TREE_STORE (model), &Ligne, colonne, 0, -1);
					    break;
				    default:
					    debug_printf (INTERFACE, D_ERRO, __FILE__, __PRETTY_FUNCTION__, __LINE__, "Type_Colonne inconnu");
				}
				colonne++;
			}
	}

}


void Afficher_Utilisation_Disque(){
	struct struct_Liste_Snmp *Info = NULL;	
	GList    *Glist_Snmp = NULL;
	GtkTreeModel *model = NULL;
	GtkTreeIter Ligne;
	gint nb_Info,Nb_Disk,i,j;
	double taille_max,taille_utiliser,pourcentage;
	gchar *Nom_Disque = NULL,*Utiliser = NULL,*Max = NULL;
	
	model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview_Info_Disk));
	gtk_tree_store_clear (GTK_TREE_STORE (model));
	//printf("Recup info \n");
	ERROR_if (Equipement_Selectionner == NULL);
	Glist_Snmp = Equipement_Selectionner->Glist_Snmp[SNMP_SYSTEM_LOGICAL_STORAGE];
	if  (Glist_Snmp == NULL)
		return;
	//printf("Afich\n");
	nb_Info = g_list_length (Glist_Snmp);
	//printf("Nombre : %d\n",nb_Info);
	ERROR_if (nb_Info == 0);
	
	Nb_Disk = -1;
	for (i = 0; i < nb_Info; i++) {
		Info = g_list_nth_data (Glist_Snmp, i);
		//printf("--- %s\n",Info->Info);
		if (Nb_Disk < Info->Ligne)
			Nb_Disk = Info->Ligne;
	}
	//printf("Nb de disque : %d\n",Nb_Disk);
	for (i = 0; i <= Nb_Disk; i++) {
		j = 0;
		Nom_Disque = NULL;
		Utiliser = NULL;
		Max = NULL;
		while ((nb_Info > j) && ((Nom_Disque == NULL) || (Utiliser==NULL) || (Max==NULL))) {
			Info = g_list_nth_data (Glist_Snmp, j);
			ERROR_if (Info == NULL);
			if ((Info->Colonne == 3) && (Info->Ligne == i))
				Nom_Disque = Info->Info;
			if ((Info->Colonne == 6) && (Info->Ligne == i))
				Utiliser = Info->Info;
			if ((Info->Colonne == 5) && (Info->Ligne == i))
				Max = Info->Info;
			j++;
		}
		if ((Nom_Disque!=NULL) && (Max!=NULL) && (Utiliser!=NULL)){  
			//printf ("[%s]  U:%s  M:%s\n",Nom_Disque,Utiliser,Max);
			taille_max = atof (Max);    // DE CERTAINS CAS Max == NULL --> BUG
			taille_utiliser = atof (Utiliser);
			if (taille_max != 0){
				pourcentage = ((taille_utiliser * 100) / taille_max);
				//printf ("M=%f  U=%f   Pourcentage=%f \n",taille_max,taille_utiliser,pourcentage);
				if ((Nom_Disque[0]=='/')||(Nom_Disque[1]==':')){
					gtk_tree_store_append (GTK_TREE_STORE (model), &Ligne, NULL);
					gtk_tree_store_set (GTK_TREE_STORE (model), &Ligne,COL_ICON_LIST_BARRE,  Icone_treeview_Info_Disk, COLUMN_TEXT_LIST_BARRE, Nom_Disque,PROGRESSION_LIST_BARRE, (gint)pourcentage, -1);
				}
			}
		}
	}
	if (Nb_Disk==-1)
		gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow_Info_Disk), GTK_POLICY_NEVER, GTK_POLICY_NEVER);
	else
		gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow_Info_Disk), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
}




void Affiche_Snmp (gpointer * pointer)
{
	struct Struct_Modele_Objet *Objet = (struct Struct_Modele_Objet *) pointer;
	struct struct_Liste_Snmp *Info = NULL;
	GtkTreeStore *Store = NULL;
	GtkTreeModel *model = NULL;
	gint      ID_Snmp = 0, i, j, Nb_Total_Colonne_Defini, Nb_Colonne, nb_Info, ligne, colonne, Nb_Ligne_Total;
	GList    *Glist_Snmp = NULL;
	GType    *column_types = NULL;
	GtkTreeIter Ligne;
	gchar    *Texte = NULL, *Texte2 = NULL;
	GtkTreeViewColumn *col = NULL;
	GtkCellRenderer *texte = NULL;
	GtkCellRenderer *progress = NULL;

	ERROR_if (pointer == NULL);
	Initialisation_Snmp ();
	switch (Objet->ID_Modele_Objet) {
	    case INFO_SNMP_SYSTEM_DEVICE:
		    ID_Snmp = SNMP_SYSTEM_DEVICE;
		    Glist_Snmp = Equipement_Selectionner->Glist_Snmp[SNMP_SYSTEM_DEVICE];
		    break;
	    case INFO_SNMP_SYSTEM_LOGICAL_STORAGE:
		    ID_Snmp = SNMP_SYSTEM_LOGICAL_STORAGE;
		    Glist_Snmp = Equipement_Selectionner->Glist_Snmp[SNMP_SYSTEM_LOGICAL_STORAGE];
		    break;
	    case INFO_SNMP_SYSTEM_SERVICE:
		    ID_Snmp = SNMP_SYSTEM_SERVICE;
		    Glist_Snmp = Equipement_Selectionner->Glist_Snmp[SNMP_SYSTEM_SERVICE];
		    break;
	    case INFO_SNMP_NETWORK_ARP:
		    ID_Snmp = SNMP_NETWORK_ARP;
		    Glist_Snmp = Equipement_Selectionner->Glist_Snmp[SNMP_NETWORK_ARP];
		    break;
	    case INFO_SNMP_NETWORK_ROUTES:
		    ID_Snmp = SNMP_NETWORK_ROUTES;
		    Glist_Snmp = Equipement_Selectionner->Glist_Snmp[SNMP_NETWORK_ROUTES];
		    break;
	    case INFO_SNMP_NETWORK_INTERFACES_BASIC:
		    ID_Snmp = SNMP_NETWORK_INTERFACES_BASIC;
		    Glist_Snmp = Equipement_Selectionner->Glist_Snmp[SNMP_NETWORK_INTERFACES_BASIC];
		    break;
	    case INFO_SNMP_NETWORK_TCPIP_TCP_CONNECTIONS:
		    ID_Snmp = SNMP_NETWORK_TCPIP_TCP_CONNECTIONS;
		    Glist_Snmp = Equipement_Selectionner->Glist_Snmp[SNMP_NETWORK_TCPIP_TCP_CONNECTIONS];
		    break;
	    case INFO_SNMP_NETWORK_TCPIP_UDP_SERVICES:
		    ID_Snmp = SNMP_NETWORK_TCPIP_UDP_SERVICES;
		    Glist_Snmp = Equipement_Selectionner->Glist_Snmp[SNMP_NETWORK_TCPIP_UDP_SERVICES];
		    break;
	    case INFO_SNMP_RUNNING_SOFTWARE:
		    ID_Snmp = SNMP_SOFTWARE;
		    Glist_Snmp = Equipement_Selectionner->Glist_Snmp[SNMP_SOFTWARE];
		    break;

	    case INFO_SNMP_BRIDGE_FORWARDING_DATABASE:
		    ID_Snmp = SNMP_BRIDGE_FORWARDING_DATABASE;
		    Glist_Snmp = Equipement_Selectionner->Glist_Snmp[SNMP_BRIDGE_FORWARDING_DATABASE];
		    break;
	    case INFO_SNMP_BRIDGE_STATIC_DATABASE:
		    ID_Snmp = SNMP_BRIDGE_STATIC_DATABASE;
		    Glist_Snmp = Equipement_Selectionner->Glist_Snmp[SNMP_BRIDGE_STATIC_DATABASE];
		    break;
	    default:
		    debug_printf (INTERFACE, D_ERRO, __FILE__, __PRETTY_FUNCTION__, __LINE__, "ID_Snmp inconnu");
	}

	gtk_widget_destroy (scrolledwindow_Snmp_Liste);
	scrolledwindow_Snmp_Liste = gtk_scrolled_window_new (NULL, NULL);
	gtk_widget_show (scrolledwindow_Snmp_Liste);
	gtk_box_pack_start (GTK_BOX (vbox_Snmp), scrolledwindow_Snmp_Liste, TRUE, TRUE, 11);
	gtk_widget_set_size_request (scrolledwindow_Snmp_Liste, 312, 136);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow_Snmp_Liste), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
	gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow_Snmp_Liste), GTK_SHADOW_IN);

	Nb_Total_Colonne_Defini = sizeof (Colonne_Liste_Snmp) / sizeof (struct struct_Colonne_Liste_Snmp);


	Nb_Colonne = 0;
	for (i = 0; i < Nb_Total_Colonne_Defini; i++)
		if (Colonne_Liste_Snmp[i].ID_Snmp == ID_Snmp)
			Nb_Colonne++;

	column_types = g_new (GType, Nb_Colonne);

	Nb_Colonne = 0;
	for (i = 0; i < Nb_Total_Colonne_Defini; i++)
		if (Colonne_Liste_Snmp[i].ID_Snmp == ID_Snmp) {
			switch (Colonne_Liste_Snmp[i].Type_Colonne) {
			    case COLONNE_TEXTE:
				    column_types[Nb_Colonne] = G_TYPE_STRING;
				    break;
			    case COLONNE_PROGRESS:
				    column_types[Nb_Colonne] = G_TYPE_INT;
				    break;
			    default:
				    debug_printf (INTERFACE, D_ERRO, __FILE__, __PRETTY_FUNCTION__, __LINE__, "Type_Colonne inconnu");
			}
			Nb_Colonne++;
		}



	Store = gtk_tree_store_newv (Nb_Colonne, column_types);
	model = GTK_TREE_MODEL (Store);

	treeview_Snmp = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
	gtk_widget_show (treeview_Snmp);
	gtk_container_add (GTK_CONTAINER (scrolledwindow_Snmp_Liste), treeview_Snmp);
	gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview_Snmp), TRUE);

	j = 0;
	for (i = 0; i < Nb_Total_Colonne_Defini; i++)
		if (Colonne_Liste_Snmp[i].ID_Snmp == ID_Snmp) {
			col = gtk_tree_view_column_new ();
			gtk_tree_view_column_set_title (col, Colonne_Liste_Snmp[i].Nom_Colonne);
			switch (Colonne_Liste_Snmp[i].Type_Colonne) {
			    case COLONNE_TEXTE:
				    texte = gtk_cell_renderer_text_new ();
				    gtk_tree_view_column_pack_start (col, texte, FALSE);
				    gtk_tree_view_column_set_attributes (col, texte, "text", j, NULL);
				    break;
			    case COLONNE_PROGRESS:
				    progress = gtk_cell_renderer_progress_new ();
				    gtk_tree_view_column_pack_start (col, progress, TRUE);
				    gtk_tree_view_column_set_attributes (col, progress, "value", j, NULL);

				    break;
			    default:
				    debug_printf (INTERFACE, D_ERRO, __FILE__, __PRETTY_FUNCTION__, __LINE__, "Type_Colonne inconnu");
			}
			j++;
			gtk_tree_view_append_column (GTK_TREE_VIEW (treeview_Snmp), col);
		}




	Nb_Ligne_Total = -1;
	nb_Info = g_list_length (Glist_Snmp);

	for (i = 0; i < nb_Info; i++) {
		Info = g_list_nth_data (Glist_Snmp, i);
		if (Nb_Ligne_Total < Info->Ligne)
			Nb_Ligne_Total = Info->Ligne;
	}



	for (ligne = 0; ligne <= Nb_Ligne_Total; ligne++) {
		gtk_tree_store_append (GTK_TREE_STORE (model), &Ligne, NULL);
		colonne = 0;
	
		for (j = 0; j < Nb_Total_Colonne_Defini; j++)
			if (Colonne_Liste_Snmp[j].ID_Snmp == ID_Snmp) {
				i = 0;
				Texte = NULL;
				while ((nb_Info > i) && (Texte == NULL)) {
					Info = g_list_nth_data (Glist_Snmp, i);
				
					if ((Info->Colonne == Colonne_Liste_Snmp[j].Colonne) && (Info->Ligne == ligne)) {
						Texte = Info->Info;
					
					}
					i++;
				}
				Texte2 = NULL;
				if (Colonne_Liste_Snmp[j].Colonne2 != -1) {
					i = 0;
					while ((nb_Info > i) && (Texte2 == NULL)) {
						Info = g_list_nth_data (Glist_Snmp, i);
						if ((Info->Colonne == Colonne_Liste_Snmp[j].Colonne2) && (Info->Ligne == ligne)) {
							Texte2 = Info->Info;
						
						}
						i++;

					}
				}
				switch (Colonne_Liste_Snmp[j].Type_Colonne) {
				    case COLONNE_TEXTE:
					    if (Texte != NULL)
						    gtk_tree_store_set (GTK_TREE_STORE (model), &Ligne, colonne, Texte, -1);
					    break;
				    case COLONNE_PROGRESS:
					    if (atoi (Texte) != 0)
						    gtk_tree_store_set (GTK_TREE_STORE (model), &Ligne, colonne, (atoi (Texte2) * 100) / atoi (Texte), -1);
					    else
						    gtk_tree_store_set (GTK_TREE_STORE (model), &Ligne, colonne, 0, -1);
					    break;
				    default:
					    debug_printf (INTERFACE, D_ERRO, __FILE__, __PRETTY_FUNCTION__, __LINE__, "Type_Colonne inconnu");
				}
				colonne++;
			}
	}


}


void Efface_Liste_Snmp(struct Struct_Equipement *Equipement,gint ID_Snmp){
	struct struct_Liste_Snmp *Info = NULL;
	gint      i,nb_Info;

	ERROR_if (Equipement == NULL);
	if (Equipement->Glist_Snmp[ID_Snmp]!=NULL){
	
		nb_Info = g_list_length (Equipement->Glist_Snmp[ID_Snmp]);
	
		i = nb_Info -1;
		while (i>=0){
			Info = g_list_nth_data (Equipement->Glist_Snmp[ID_Snmp], i);
		
			G_LIST_REMOVE(Equipement->Glist_Snmp[ID_Snmp],Info);			
			MYFREE(Info->Info);
			MYFREE(Info);
			i--;
		}
	
		nb_Info = g_list_length (Equipement->Glist_Snmp[ID_Snmp]);
	
	}	


}


void Retour_Liste_Snmp_Scalaire(gpointer * Donnee){
	
	
}


void Retour_Efface_Liste_Snmp(gpointer * Donnee){
	struct struct_Retour_Liste_SNMP *Message = (struct struct_Retour_Liste_SNMP *) Donnee;
	struct Struct_Modele_Objet *Objet = NULL;
	struct Struct_Liste_Reseau *Reseau = NULL;
	struct Struct_Equipement *Equipement = NULL;


	ERROR_if (Donnee == NULL);
	Reseau = Recupere_Pointeur_Structure_Reseau (Message->ID_Reseau);
	Objet = Recherche_Objet_Equipement (Message->ID_Equipement, Message->ID_Reseau);
	if (Objet == NULL) {
		debug_printf (INTERFACE, D_WARN, __FILE__, __PRETTY_FUNCTION__, __LINE__, "Recuperation_Liste_Snmp (Equipment unknown)");
		return;
	}
	Equipement = (struct Struct_Equipement *) Objet->Pointeur_Attacher;
	Efface_Liste_Snmp(Equipement,Message->ID_Snmp);
	
}

void Demande_Agent_Raffraichir_Liste_Snmp(struct Struct_Modele_Objet *Objet,struct Struct_Equipement *Equipement,struct Struct_Liste_Reseau *Reseau,gint ID_Snmp){
	struct struct_Demande_Liste_SNMP Message_Snmp;


	Efface_Liste_Snmp(Equipement,ID_Snmp);
	bzero (&Message_Snmp, sizeof (struct struct_Demande_Liste_SNMP));
	Message_Snmp.ID_Reseau = Objet->ID_Reseau;
	Message_Snmp.ID_Snmp = ID_Snmp;
	memcpy (Message_Snmp.ID_Equipement, Equipement->ID_Equipement, MAC_ADDR_LEN + IP_ADDR_LEN + 1);
	Communication_Envoie_Donnee (Reseau->Pid_Agent, DEMANDE_LISTE_SNMP, (gpointer *) & Message_Snmp, sizeof (Message_Snmp), Reseau);
}


void Demande_Agent_Raffraichir_Tout_Liste_Snmp(struct Struct_Modele_Objet *Objet,struct Struct_Equipement *Equipement,struct Struct_Liste_Reseau *Reseau){
	struct struct_Demande_Liste_SNMP_All Message_Snmp;


	bzero (&Message_Snmp, sizeof (struct struct_Demande_Liste_SNMP_All));
	Message_Snmp.ID_Reseau = Objet->ID_Reseau;
	memcpy (Message_Snmp.ID_Equipement, Equipement->ID_Equipement, MAC_ADDR_LEN + IP_ADDR_LEN + 1);
	Communication_Envoie_Donnee (Reseau->Pid_Agent, DEMANDE_LISTE_SNMP_ALL, (gpointer *) & Message_Snmp, sizeof (Message_Snmp), Reseau);
}

void Demande_Agent_Raffraichir_Snmp_Scalaire(struct Struct_Modele_Objet *Objet,struct Struct_Equipement *Equipement,struct Struct_Liste_Reseau *Reseau){
	struct struct_Demande_SNMP_Scalaire Message_Snmp;

	bzero (&Message_Snmp, sizeof (struct struct_Demande_SNMP_Scalaire));
	Message_Snmp.ID_Reseau = Objet->ID_Reseau;
	memcpy (Message_Snmp.ID_Equipement, Equipement->ID_Equipement, MAC_ADDR_LEN + IP_ADDR_LEN + 1);
	Communication_Envoie_Donnee (Reseau->Pid_Agent, DEMANDE_SNMP_SCALAIRE, (gpointer *) & Message_Snmp, sizeof (Message_Snmp), Reseau);
}

void Recuperation_Liste_Snmp (gpointer * Donnee)
{
	struct struct_Retour_Liste_SNMP *Message = (struct struct_Retour_Liste_SNMP *) Donnee;
	struct Struct_Modele_Objet *Objet = NULL;
	struct Struct_Liste_Reseau *Reseau = NULL;
	struct Struct_Equipement *Equipement = NULL;
	struct struct_Liste_Snmp *Info = NULL;
	gint      i,Nb_Objet_Liste;
	gboolean Trouver;

	ERROR_if (Donnee == NULL);
	Reseau = Recupere_Pointeur_Structure_Reseau (Message->ID_Reseau);

	Objet = Recherche_Objet_Equipement (Message->ID_Equipement, Message->ID_Reseau);

	if (Objet == NULL){
		i = 0;
		Trouver = FALSE;
		Nb_Objet_Liste = g_list_length (GList_Equipement_Cours_Affichage);
		while ((!Trouver) && (i!=Nb_Objet_Liste)) {
			Equipement = g_list_nth_data (GList_Equipement_Cours_Affichage, i);
			if ((memcmp (Equipement->ID_Equipement, Message->ID_Equipement, MAC_ADDR_LEN) == 0))
					Trouver = TRUE;
			i++;
		}
		if (!Trouver)
			Equipement = NULL;
	}
	else
		Equipement = (struct Struct_Equipement *) Objet->Pointeur_Attacher;
			
	if (Equipement == NULL) {
		debug_printf (INTERFACE, D_WARN, __FILE__, __PRETTY_FUNCTION__, __LINE__, "Recuperation_Liste_Snmp (Equipment unknown)");
		return;
	}
	

	/*if (Equipement->Glist_Snmp[Message->ID_Snmp]!=NULL){
		printf("+++++++++++++++++Glist_Snmp : Pas vide   (%d)\n",Message->ID_Snmp);	
	}	
	else
		printf("++++++++++++++++++Glist_Snmp : vide   (%d)\n",Message->ID_Snmp);	*/	
	
	i = 0;
	while ((i < NB_MAX_LIGNE_LISTE_SNMP) && (Message->Liste_Donnee[i].Colonne != 0)) {
	
		Info = NULL;
		MALLOC (Info, sizeof (struct struct_Liste_Snmp));
		Info->Colonne = Message->Liste_Donnee[i].Colonne;
		Info->Ligne = Message->Liste_Donnee[i].Ligne;
		Info->Info = g_strdup (Message->Liste_Donnee[i].Info);
		G_LIST_APPEND (Equipement->Glist_Snmp[Message->ID_Snmp], Info);
		i++;
	}
	
	if ((Message->Tout_Donnee_Transferer)&&(Equipement->Glist_Snmp[Message->ID_Snmp]!=NULL)){
	
		if (Equipement==Equipement_Selectionner){
		
			switch (Message->ID_Snmp){
				case SNMP_SYSTEM_LOGICAL_STORAGE :
					Afficher_Utilisation_Disque();
					break;
				case SNMP_SOFTWARE:
					Affiche_Liste_Snmp(SNMP_SOFTWARE,treeview_Info_Software);
					gtk_widget_show(gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook_Info),3));
					gtk_widget_set_sensitive (image_notebook_Info_Software,TRUE);
					gtk_widget_set_sensitive (treeview_Info_Software,TRUE);
					break;
				case SNMP_NETWORK_TCPIP_TCP_CONNECTIONS:
					Affiche_Liste_Snmp(SNMP_NETWORK_TCPIP_TCP_CONNECTIONS,treeview_Info_Tcp);
					gtk_widget_show(gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook_Info),4));
					gtk_widget_set_sensitive (image_notebook_Info_Tcp,TRUE);	
					gtk_widget_set_sensitive (treeview_Info_Tcp,TRUE);
					break;
				case SNMP_NETWORK_ROUTES :
					Affiche_Liste_Snmp(SNMP_NETWORK_ROUTES,treeview_Info_Route);
					gtk_widget_show(gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook_Info),5));
					gtk_widget_set_sensitive (image_notebook_Info_Route,TRUE);
					gtk_widget_set_sensitive (treeview_Info_Route,TRUE);
					break;
				case SNMP_NETWORK_ARP:
					Affiche_Liste_Snmp(SNMP_NETWORK_ARP,treeview_Info_Arp);
					gtk_widget_show(gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook_Info),6));
					gtk_widget_set_sensitive (image_notebook_Info_Arp,TRUE);
					gtk_widget_set_sensitive (treeview_Info_Arp,TRUE);
					break;				
				case SNMP_SYSTEM_DEVICE:
					Affiche_Liste_Snmp(SNMP_SYSTEM_DEVICE,treeview_Info_Peripherique);
					gtk_widget_show(gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook_Info),7));
					gtk_widget_set_sensitive (image_notebook_Info_Peripherique,TRUE);	
					gtk_widget_set_sensitive (treeview_Info_Peripherique,TRUE);
					break;
				case SNMP_SYSTEM_SERVICE:
					Affiche_Liste_Snmp(SNMP_SYSTEM_SERVICE,treeview_Info_Service);
					gtk_widget_show(gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook_Info),8));
					gtk_widget_set_sensitive (image_notebook_Info_Service,TRUE);
					gtk_widget_set_sensitive (treeview_Info_Service,TRUE);
					break;
				case SNMP_NETWORK_INTERFACES_BASIC:
					Affiche_Liste_Snmp(SNMP_NETWORK_INTERFACES_BASIC,treeview_Info_Interface);
					gtk_widget_show(gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook_Info),9));
					gtk_widget_set_sensitive (image_notebook_Info_Interface,TRUE);	
					gtk_widget_set_sensitive (treeview_Info_Interface,TRUE);
					break;			
				default :
				  debug_printf (INTERFACE, D_WARN, __FILE__, __PRETTY_FUNCTION__, __LINE__, "ID_Snmp inconnu  : %d",Message->ID_Snmp);
			}
		}
	}
	Recuperation_Nb_Octet_Recu (sizeof (struct struct_Retour_Liste_SNMP), Reseau);
}
