LTP GCOV extension - code coverage report
Current view: directory - trunk/src - list_data_types.c
Test: coverage.info
Date: 2008-08-24 Instrumented lines: 96
Code covered: 14.6 % Executed lines: 14

       1                 : /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
       2                 : /*
       3                 :   list_data_types.c
       4                 :   Window allowing the user to manage his data types (add, remove, edit,
       5                 :   save and load them)
       6                 :   
       7                 :   (C) Copyright 2007 - 2007 Olivier Delhomme
       8                 :   e-mail : heraia@delhomme.org
       9                 :   URL    : http://heraia.tuxfamily.org
      10                 :  
      11                 :   This program is free software; you can redistribute it and/or modify
      12                 :   it under the terms of the GNU General Public License as published by
      13                 :   the Free Software Foundation; either version 2, or  (at your option) 
      14                 :   any later version.
      15                 :  
      16                 :   This program is distributed in the hope that it will be useful,
      17                 :   but WITHOUT ANY WARRANTY;  without even the implied warranty of
      18                 :   MERCHANTABILITY  or  FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :   GNU General Public License for more details.
      20                 :  
      21                 :   You should have received a copy of the GNU General Public License
      22                 :   along with this program; if not, write to the Free Software
      23                 :   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
      24                 : */
      25                 : 
      26                 : #include "heraia_types.h"
      27                 : 
      28                 : static gboolean delete_ldt_window_event(GtkWidget *widget, GdkEvent  *event, gpointer data);
      29                 : static void destroy_ldt_window(GtkWidget *widget, GdkEvent  *event, gpointer data);
      30                 : static void ldt_add_button_clicked(GtkWidget *widget, gpointer data);
      31                 : static void ldt_remove_button_clicked(GtkWidget *widget, gpointer data);
      32                 : static void ldt_edit_button_clicked(GtkWidget *widget, gpointer data);
      33                 : static void ldt_save_button_clicked(GtkWidget *widget, gpointer data);
      34                 : static void connect_list_data_types_signals(heraia_window_t *main_window);
      35                 : 
      36                 : /**
      37                 :  *  Shows or hide the list data type window
      38                 :  */
      39                 : void on_ldt_menu_activate(GtkWidget *widget, gpointer data)
      40               0 : {
      41               0 :         heraia_window_t *main_window = (heraia_window_t *) data;
      42               0 :         GtkWidget *check_menu_item = NULL;
      43                 : 
      44               0 :         if (main_window != NULL)
      45                 :                 {
      46               0 :                         check_menu_item = heraia_get_widget(main_window->xmls->main, "ldt_menu");
      47                 : 
      48               0 :                         if (is_cmi_checked(check_menu_item) == TRUE)
      49                 :                                 {  /* if the menu is checked, shows the window */
      50               0 :                                         move_and_show_dialog_box(heraia_get_widget(main_window->xmls->main, "list_data_types_window"), main_window->win_prop->ldt);
      51                 :                                 }
      52                 :                         else
      53                 :                                 {
      54               0 :                                         record_and_hide_dialog_box(heraia_get_widget(main_window->xmls->main, "list_data_types_window"), main_window->win_prop->ldt);
      55                 :                                 }
      56                 :                 }
      57               0 : }
      58                 : 
      59                 : 
      60                 : /**
      61                 :  *  Adds the data type name to the treeview
      62                 :  */
      63                 : void add_data_type_name_to_treeview(heraia_window_t *main_window, gchar *name)
      64               0 : {
      65               0 :         GtkListStore *list_store = NULL;  /* Treeview Stuff for rendering */
      66                 :         GtkTreeIter iter;                 /* the text in it.              */
      67               0 :         GtkCellRenderer *renderer = NULL; 
      68               0 :         GtkTreeViewColumn *column = NULL;  
      69               0 :         GtkTreeView *treeview = NULL;     /* Treeview where data type name will be displayed */
      70                 : 
      71               0 :         treeview = GTK_TREE_VIEW(heraia_get_widget(main_window->xmls->main, "ldt_treeview"));
      72                 : 
      73               0 :         list_store = GTK_LIST_STORE(gtk_tree_view_get_model(treeview));
      74                 : 
      75               0 :         if (list_store == NULL)
      76                 :                 {
      77               0 :                         list_store = gtk_list_store_new(LDT_TV_N_COLUMNS, G_TYPE_STRING);
      78               0 :                         renderer = gtk_cell_renderer_text_new();
      79               0 :                         column = gtk_tree_view_column_new_with_attributes("Name", renderer, "text", LDT_TV_COLUMN_NAME, NULL);
      80               0 :                         gtk_tree_view_append_column(treeview, column);
      81                 :                 }
      82                 : 
      83               0 :         gtk_list_store_append(list_store, &iter);
      84               0 :         gtk_list_store_set(list_store, &iter, LDT_TV_COLUMN_NAME, name, -1);
      85               0 :         gtk_tree_view_set_model(treeview, GTK_TREE_MODEL(list_store));
      86               0 : }
      87                 : 
      88                 : 
      89                 : /**
      90                 :  *  Called when the list data types is killed or closed
      91                 :  *  !! Not to be confused with delete_dt_window_event !!
      92                 :  */
      93                 : static gboolean delete_ldt_window_event(GtkWidget *widget, GdkEvent  *event, gpointer data)
      94               0 : {       
      95               0 :         heraia_window_t *main_window = (heraia_window_t *) data;
      96                 : 
      97               0 :         g_signal_emit_by_name(heraia_get_widget(main_window->xmls->main, "ldt_menu"), "activate");
      98                 : 
      99               0 :         return TRUE;
     100                 : }
     101                 : 
     102                 : 
     103                 : /**
     104                 :  *  Called when the list data types is killed or closed
     105                 :  *  !! Not to be confused with destroy_dt_window !!
     106                 :  */
     107                 : static void destroy_ldt_window(GtkWidget *widget, GdkEvent  *event, gpointer data)
     108               0 : {
     109               0 :         heraia_window_t *main_window = (heraia_window_t *) data;
     110                 : 
     111               0 :         g_signal_emit_by_name(heraia_get_widget(main_window->xmls->main, "ldt_menu"), "activate");
     112               0 : }
     113                 : 
     114                 : 
     115                 : /**
     116                 :  *  When the add button (+) is clicked
     117                 :  */
     118                 : static void ldt_add_button_clicked(GtkWidget *widget, gpointer data)
     119               0 : {
     120               0 :         heraia_window_t *main_window = (heraia_window_t *) data;
     121                 : 
     122               0 :         main_window->current_data_type = new_data_type("", DT_SPIN_MIN);
     123                 : 
     124                 :         /* data interpretor widget creation */
     125               0 :         create_ud_data_interpretor_widgets(main_window, main_window->current_data_type);
     126                 : 
     127               0 :         show_data_type_window(main_window, main_window->current_data_type);
     128               0 : }
     129                 : 
     130                 : 
     131                 : /**
     132                 :  *  When the remove (-) button is clicked
     133                 :  */
     134                 : static void ldt_remove_button_clicked(GtkWidget *widget, gpointer data)
     135               0 : {
     136               0 :         heraia_window_t *main_window = (heraia_window_t *) data;
     137               0 :         GList *data_type_list = main_window->data_type_list;
     138               0 :         GtkTreeView *treeview = NULL; 
     139               0 :         GtkTreeSelection *selection = NULL;
     140                 :         GtkTreeIter iter;
     141               0 :         GtkTreeModel *model = NULL;
     142               0 :         GtkListStore *list_store = NULL;
     143               0 :         gchar *name = NULL;
     144               0 :         data_type_t *a_data_type = NULL;
     145                 : 
     146               0 :         treeview = GTK_TREE_VIEW(heraia_get_widget(main_window->xmls->main, "ldt_treeview"));
     147                 : 
     148                 :         /* gets the selection of the treeview (if any) */
     149               0 :         selection = gtk_tree_view_get_selection(treeview);
     150                 : 
     151               0 :         if (gtk_tree_selection_get_selected(selection, &model, &iter))
     152                 :                 {    
     153               0 :                         gtk_tree_model_get(model, &iter, LDT_TV_COLUMN_NAME, &name, -1);
     154               0 :                         data_type_list = is_data_type_name_already_used(data_type_list, name);
     155                 :                         
     156               0 :                         if (data_type_list != NULL)
     157                 :                                 {
     158                 :                                         /* frees internal structure */
     159               0 :                                         a_data_type = (data_type_t *) data_type_list->data;
     160                 :                                         
     161                 :                                         /* the data interpretor part */
     162               0 :                                         destroy_a_single_widget(a_data_type->di_label);
     163               0 :                                         destroy_a_single_widget(a_data_type->di_entry);
     164               0 :                                         free_data_type(a_data_type);
     165                 : 
     166               0 :                                         main_window->data_type_list = g_list_delete_link(main_window->data_type_list, data_type_list);
     167                 : 
     168                 :                                         /* frees the treeview accordingly */
     169               0 :                                         list_store = GTK_LIST_STORE(model);
     170               0 :                                         if (list_store != NULL)
     171                 :                                                 {
     172               0 :                                                         gtk_list_store_remove(list_store, &iter);
     173               0 :                                                         gtk_tree_view_set_model(treeview, GTK_TREE_MODEL(list_store));
     174                 :                                                 }
     175                 :                                 }
     176                 :                 }
     177               0 : }
     178                 : 
     179                 : 
     180                 : /**
     181                 :  *  When the edit button is clicked
     182                 :  */
     183                 : static void ldt_edit_button_clicked(GtkWidget *widget, gpointer data)
     184               0 : {
     185               0 :         heraia_window_t *main_window = (heraia_window_t *) data;
     186                 : 
     187               0 :         GList *data_type_list = main_window->data_type_list;
     188               0 :         GtkTreeSelection *selection = NULL;
     189                 :         GtkTreeIter iter;
     190               0 :         GtkTreeModel *model = NULL;
     191               0 :         gchar *name = NULL;
     192                 : 
     193                 :         /* gets the selection of the treeview (if any) */
     194               0 :         selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(heraia_get_widget(main_window->xmls->main, "ldt_treeview")));
     195                 : 
     196               0 :         if (gtk_tree_selection_get_selected(selection, &model, &iter))
     197                 :                 {    
     198               0 :                         gtk_tree_model_get(model, &iter, LDT_TV_COLUMN_NAME, &name, -1);
     199               0 :                         data_type_list = is_data_type_name_already_used(data_type_list, name);
     200                 :                         
     201               0 :                         if (data_type_list != NULL)
     202                 :                                 {               
     203                 :                                         /** 
     204                 :                                          *  We use a copy because we want to be able to be in edit mode even if
     205                 :                                          *  the user clicked add(+) button.
     206                 :                                          */
     207               0 :                                         main_window->current_data_type = copy_data_type_struct(main_window, data_type_list->data);
     208                 :                                         
     209               0 :                                         show_data_type_window(main_window, main_window->current_data_type);
     210                 :                                 }
     211                 :                 }
     212               0 : }
     213                 : 
     214                 : 
     215                 : /**
     216                 :  *  When the save button is clicked
     217                 :  */
     218                 : static void ldt_save_button_clicked(GtkWidget *widget, gpointer data)
     219               0 : {
     220               0 :         heraia_window_t *main_window = (heraia_window_t *) data;
     221                 :         /* GList *data_type_list = main_window->data_type_list; */
     222                 : 
     223                 :         /**
     224                 :          *  I'll do this later ...
     225                 :          *  I first have to understand XML !
     226                 :          */
     227               0 :         log_message(main_window, G_LOG_LEVEL_WARNING, "This function is not yet implemented. Please Contribute :)");
     228                 : 
     229               0 : }
     230                 : 
     231                 : 
     232                 : /**
     233                 :  *  Connects list_data_types's window signals.
     234                 :  */
     235                 : static void connect_list_data_types_signals(heraia_window_t *main_window)
     236               1 : {
     237                 : 
     238               1 :         if (main_window != NULL && main_window->xmls != NULL && main_window->xmls->main != NULL)
     239                 :                 {
     240                 :                         /* list data types menu */
     241               1 :                         g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "ldt_menu")), "activate", 
     242                 :                                                          G_CALLBACK(on_ldt_menu_activate), main_window);
     243                 :       
     244                 :                         /* list data types window killed or destroyed */
     245               1 :                         g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "list_data_types_window")), "delete_event", 
     246                 :                                                          G_CALLBACK(delete_ldt_window_event), main_window);
     247                 : 
     248               1 :                         g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "list_data_types_window")), "destroy", 
     249                 :                                                          G_CALLBACK(destroy_ldt_window), main_window);
     250                 : 
     251                 :                         /* Add button    */
     252               1 :                         g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "ldt_add_button")), "clicked", 
     253                 :                                                          G_CALLBACK(ldt_add_button_clicked), main_window);
     254                 : 
     255                 :                         /* Remove button */
     256               1 :                         g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "ldt_remove_button")), "clicked", 
     257                 :                                                          G_CALLBACK(ldt_remove_button_clicked), main_window);
     258                 : 
     259                 :                         /* Edit button   */
     260               1 :                         g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "ldt_edit_button")), "clicked", 
     261                 :                                                          G_CALLBACK(ldt_edit_button_clicked), main_window);
     262                 : 
     263                 :                         /* Save button   */
     264               1 :                         g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "ldt_save_button")), "clicked", 
     265                 :                                                          G_CALLBACK(ldt_save_button_clicked), main_window);
     266                 :                 }
     267               1 : }
     268                 : 
     269                 : 
     270                 : /**
     271                 :  *  Inits the list data type window
     272                 :  *  with default values
     273                 :  *  Should be called only once
     274                 :  */
     275                 : void list_data_types_init_interface(heraia_window_t *main_window)
     276               1 : {
     277                 : 
     278               1 :         if (main_window != NULL)
     279                 :                 {
     280               1 :                         connect_list_data_types_signals(main_window);
     281                 :                 }
     282               1 : }

Generated by: LTP GCOV extension version 1.6