data_interpretor.c

Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
00002 /*
00003   data_interpretor.c
00004   heraia - an hexadecimal file editor and analyser based on ghex
00005 
00006   (C) Copyright 2005 - 2010 Olivier Delhomme
00007   e-mail : heraia@delhomme.org
00008   URL    : http://heraia.tuxfamily.org
00009 
00010   This program is free software; you can redistribute it and/or modify
00011   it under the terms of the GNU General Public License as published by
00012   the Free Software Foundation; either version 2, or  (at your option)
00013   any later version.
00014 
00015   This program is distributed in the hope that it will be useful,
00016   but WITHOUT ANY WARRANTY;  without even the implied warranty of
00017   MERCHANTABILITY  or  FITNESS FOR A PARTICULAR PURPOSE.  See the
00018   GNU General Public License for more details.
00019 
00020   You should have received a copy of the GNU General Public License
00021   along with this program; if not, write to the Free Software
00022   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
00023 /**
00024  * @file data_interpretor.c
00025  * Here one may find tools to manage the data_interpretor window
00026  */
00027 #include <libheraia.h>
00028 
00029 static guint which_endianness(heraia_struct_t *main_struct);
00030 static guint which_stream_size(heraia_struct_t *main_struct);
00031 static void interpret(doc_t *doc, decode_t *decode_struct, decode_parameters_t *decode_parameters, guint length);
00032 static void connect_data_interpretor_signals(heraia_struct_t *main_struct);
00033 static void refresh_one_row(doc_t *doc, decode_generic_t *row,  guint nb_cols, decode_parameters_t *decode_parameters);
00034 static void refresh_one_tab(doc_t *doc, data_window_t *dw, tab_t *tab, decode_parameters_t *decode_parameters);
00035 static void refresh_all_tabs(doc_t *doc, data_window_t *dw, decode_parameters_t *decode_parameters);
00036 static void add_default_tabs(heraia_struct_t *main_struct);
00037 
00038 
00039 /**
00040  * @fn guint which_endianness(heraia_struct_t *main_struct)
00041  *  Determines which endianness is selected that is to say
00042  *  which radio button is active in the window
00043  * @param main_struct : main structure
00044  * @return Something of the following, depending on what selected the user :
00045  *         - H_DI_LITTLE_ENDIAN for little endian encoding (default answer)
00046  *         - H_DI_BIG_ENDIAN for big endian encoding
00047  *         - H_DI_MIDDLE_ENDIAN for middle endian encoding
00048  */
00049 static guint which_endianness(heraia_struct_t *main_struct)
00050 {
00051     gint endianness = -1;
00052 
00053     endianness  = di_get_endianness(main_struct);
00054 
00055     if (endianness > 0)
00056         {
00057             return endianness;           /* Here everything went ok */
00058         }
00059     else
00060         {
00061             return H_DI_LITTLE_ENDIAN;   /* default interpretation case */
00062         }
00063 }
00064 
00065 
00066 /**
00067  * returns stream size as selected in the spin button
00068  * @param main_struct : main structure
00069  * @return returns the value of the spin button or 1 if this value is not valid
00070  */
00071 static guint which_stream_size(heraia_struct_t *main_struct)
00072 {
00073     guint stream_size = 1;
00074 
00075     stream_size = di_get_stream_size(main_struct);
00076 
00077     if (stream_size >= 1)
00078         {
00079             return stream_size;
00080         }
00081     else
00082         {
00083             return 1;   /* Minimum stream_size */
00084         }
00085 }
00086 
00087 
00088 /**
00089  *   Here we do interpret a something according to the decode_it function and we
00090  *   write down the result in a widget designated "entry"
00091  *  @warning We are assuming that main_struct != NULL and main_struct->xml != NULL
00092  *
00093  *  @param main_struct : main structure
00094  *  @param decode : a decode_t structure that contains function, entry and error message
00095  *  @param decode_parameters : structure that passes some arguments to the
00096  *            decoding functions
00097  *  @param length : the length of the data to be decoded (guint)
00098  */
00099 static void interpret(doc_t *doc, decode_t *decode_struct, decode_parameters_t *decode_parameters, guint length)
00100 {
00101     gint result = 0;    /** used to test different results of function calls                            */
00102     guchar *c = NULL;   /** the character under the cursor                                              */
00103     gchar *text = NULL; /** decoded text                                                                */
00104     DecodeFunc decode_it = NULL; /** A DecodeFunc which is a function to be called to decode the stream */
00105 
00106     c = (guchar *) g_malloc0(sizeof(guchar) * length);
00107 
00108     result = ghex_get_data(doc->hex_widget, length, decode_parameters->endianness, c);
00109 
00110     if (result == TRUE)
00111         {
00112             decode_it = decode_struct->func;
00113 
00114             text = decode_it(c, (gpointer) decode_parameters);
00115 
00116             if (text != NULL)
00117                 {
00118                     gtk_entry_set_text(GTK_ENTRY(decode_struct->entry), text);
00119                 }
00120             else
00121                 {
00122                     text = g_strdup_printf(Q_("Something's wrong!"));
00123                     gtk_entry_set_text(GTK_ENTRY(decode_struct->entry), text);
00124                 }
00125         }
00126     else
00127         {
00128             if (decode_struct->err_msg != NULL)
00129                 {
00130                     text = g_strdup_printf(decode_struct->err_msg, length);
00131                 }
00132             else
00133                 {
00134                     text = g_strdup_printf(Q_("Cannot interpret as a %d byte(s)"), length);
00135                 }
00136 
00137             gtk_entry_set_text(GTK_ENTRY(decode_struct->entry), text);
00138         }
00139 
00140     g_free(c);
00141     g_free(text);
00142 }
00143 
00144 
00145 /**
00146  * This function refreshes one row of the tab
00147  * @param dw : current data window
00148  * @param row : the row that we want to refresh
00149  * @param nb_cols : number of columns in this particular row (this IS the same
00150  *                  for all rows in that tab
00151  * @param decode_parameters : structure that passes some arguments to the
00152  *        decoding functions
00153  */
00154 static void refresh_one_row(doc_t *doc, decode_generic_t *row,  guint nb_cols, decode_parameters_t *decode_parameters)
00155 {
00156     decode_t *decode = NULL;   /**< entry, function and message */
00157     guint i = 0 ;
00158 
00159     while ( i < nb_cols)
00160         {
00161             decode = g_ptr_array_index(row->decode_array, i);
00162 
00163             if (row->fixed_size == FALSE)
00164                 {
00165                     row->data_size = decode_parameters->stream_size;
00166                 }
00167 
00168             interpret(doc, decode, decode_parameters, row->data_size);
00169             i++;
00170         }
00171 }
00172 
00173 
00174 /**
00175  * This function refreshes one entire tab (row by row)
00176  * @param dw : current data window
00177  * @param tab : the tab to refresh
00178  * @param decode_parameters : structure that passes some arguments to the
00179  *        decoding functions
00180  */
00181 static void refresh_one_tab(doc_t *doc, data_window_t *dw, tab_t *tab, decode_parameters_t *decode_parameters)
00182 {
00183     decode_generic_t *row = NULL; /**< the row we want to refresh */
00184     guint i = 0;
00185 
00186     while (i < tab->nb_rows)
00187         {
00188             row = g_ptr_array_index(tab->rows, i);
00189             refresh_one_row(doc, row, tab->nb_cols - 1, decode_parameters);
00190             i++;
00191         }
00192 }
00193 
00194 
00195 /**
00196  * Refreshes all tabs
00197  * @param dw : current data window
00198  * @param decode_parameters : structure that passes some arguments to the
00199  *        decoding functions
00200  */
00201 static void refresh_all_tabs(doc_t *doc, data_window_t *dw, decode_parameters_t *decode_parameters)
00202 {
00203     tab_t *tab = NULL;
00204     guint i = 0;
00205 
00206     while (i < dw->nb_tabs)
00207         {
00208             tab = g_ptr_array_index(dw->tabs, i);
00209             refresh_one_tab(doc, dw, tab, decode_parameters);
00210             i++;
00211         }
00212 
00213 }
00214 
00215 
00216 /**
00217  * @fn void refresh_data_interpretor_window(GtkWidget *widget, gpointer data)
00218  *  Refreshes the data interpretor window with the new values
00219  * @param widget : the widget caller (may be NULL here)
00220  * @param data : a gpointer to the main structure : main_struct, this must NOT
00221  *        be NULL !
00222  * @todo if speed is a matter, think about taking off this decode_parameters
00223  *       structure from here.
00224  */
00225 void refresh_data_interpretor_window(GtkWidget *widget, gpointer data)
00226 {
00227     heraia_struct_t *main_struct = (heraia_struct_t *) data;  /** data interpretor window structure */
00228     decode_parameters_t *decode_parameters = NULL;
00229     guint endianness = 0;
00230     guint stream_size = 0;
00231 
00232     if (main_struct != NULL &&
00233         main_struct->current_doc != NULL &&
00234         main_struct->current_DW != NULL &&
00235         main_struct->win_prop->main_dialog->displayed == TRUE)
00236         {
00237             endianness = which_endianness(main_struct);    /** Endianness is computed only once here  */
00238             stream_size =  which_stream_size(main_struct); /** stream size is computed only once here */
00239 
00240             decode_parameters = new_decode_parameters_t(endianness, stream_size);
00241 
00242             refresh_all_tabs(main_struct->current_doc, main_struct->current_DW, decode_parameters);
00243 
00244             g_free(decode_parameters);
00245         }
00246 }
00247 
00248 
00249 /**
00250  * @fn void connect_data_interpretor_signals(heraia_struct_t *main_struct)
00251  *  Connects data interpretor window's signals to the
00252  *  right functions
00253  * @param main_struct : main structure
00254  */
00255 static void connect_data_interpretor_signals(heraia_struct_t *main_struct)
00256 {
00257     /* When data interpretor's window is killed or destroyed */
00258     g_signal_connect(G_OBJECT(heraia_get_widget(main_struct->xmls->main, "data_interpretor_window")), "delete_event",
00259                      G_CALLBACK(delete_dt_window_event), main_struct);
00260 
00261     g_signal_connect(G_OBJECT(heraia_get_widget(main_struct->xmls->main, "data_interpretor_window")), "destroy",
00262                      G_CALLBACK(destroy_dt_window), main_struct);
00263 
00264     /* Radio Button "Little Endian" */
00265     g_signal_connect(G_OBJECT(heraia_get_widget(main_struct->xmls->main, "diw_rb_little_endian")), "toggled",
00266                      G_CALLBACK(refresh_data_interpretor_window), main_struct);
00267 
00268     /* Radio Button "Big Endian" */
00269     g_signal_connect(G_OBJECT(heraia_get_widget(main_struct->xmls->main, "diw_rb_big_endian")), "toggled",
00270                      G_CALLBACK(refresh_data_interpretor_window), main_struct);
00271 
00272     /* Radio Button "Middle Endian" */
00273     g_signal_connect(G_OBJECT(heraia_get_widget(main_struct->xmls->main, "diw_rb_middle_endian")), "toggled",
00274                      G_CALLBACK(refresh_data_interpretor_window), main_struct);
00275 
00276     /* Spin button */
00277     g_signal_connect(G_OBJECT(heraia_get_widget(main_struct->xmls->main, "stream_size_spin_button")), "value-changed",
00278                      G_CALLBACK(refresh_data_interpretor_window), main_struct);
00279 }
00280 
00281 
00282 /**
00283  * @fn void data_interpretor_init_interface(heraia_struct_t *main_struct)
00284  *  Inits the data interpretor structure and window with default values
00285  *  @warning Should be called only once at program's beginning
00286  */
00287 void data_interpretor_init_interface(heraia_struct_t *main_struct)
00288 {
00289     data_window_t *dw = NULL;
00290 
00291     if (main_struct != NULL)
00292         {
00293             /* Signals connections */
00294             connect_data_interpretor_signals(main_struct);
00295 
00296             dw = main_struct->current_DW;
00297 
00298             if (dw != NULL)
00299                 {
00300                     dw->diw = heraia_get_widget(main_struct->xmls->main, "data_interpretor_window");
00301 
00302                     /* Here init all defaults tabs */
00303                     add_default_tabs(main_struct);
00304                 }
00305         }
00306 }
00307 
00308 
00309 /**
00310  * Adds a new tab in the data interpretor window
00311  * @param notebook : the notebook to which we want to add this new tab
00312  * @param index : index of this new tab. If you rely on this make sure it's
00313  *                a primary key !
00314  * @param label : label of the tab
00315  * @param nb_cols : number of columns (including the first column of labels)
00316  * @param ... : nb_cols arguments that will be the labels of the columns
00317  * @return a newly malloced tab_t variable that remember everything about that
00318  *         new tab.
00319  */
00320 tab_t *add_new_tab_in_data_interpretor(GtkNotebook *notebook, guint index, const gchar *label, guint nb_cols, ...)
00321 {
00322     tab_t *tab = NULL;            /**< tab structure that will remember everything !                     */
00323     va_list args;                 /**< va_list arguments passed to create a new tab with those columns   */
00324     guint i = 0;
00325     gchar *va_label = NULL;       /**< used to fetch arguments                                           */
00326     GPtrArray *col_labels = NULL; /**< used to remember the columns labels (the arguments in GtkWidgets) */
00327     GPtrArray *vboxes = NULL;     /**< used to remember vboxes (in order to be able to pack things later */
00328     GtkWidget *child = NULL;      /**< notebook tab's child container                                    */
00329     GtkWidget *hpaned = NULL;     /**< used for hpaned creation                                          */
00330     GtkWidget *hpaned2 = NULL;    /**< in case that we have more than 2 arguments                        */
00331     GtkWidget *vbox = NULL;       /**< used for vbox creation                                            */
00332     GtkWidget *vbox_label = NULL; /**< used for label creation in the new vboxes                         */
00333 
00334     col_labels = g_ptr_array_new();
00335     vboxes = g_ptr_array_new();
00336 
00337     va_start(args, nb_cols);
00338     for (i = 0 ; i < nb_cols ; i++)
00339         {
00340             va_label = va_arg(args, gchar *);
00341             if (va_label != NULL)
00342                 {
00343                     vbox_label = gtk_label_new(va_label);
00344                     gtk_misc_set_padding(GTK_MISC(vbox_label), 3, 3);       /* properties for the labels */
00345                     gtk_misc_set_alignment(GTK_MISC(vbox_label), 0.5, 0.5);
00346                     g_ptr_array_add(col_labels, (gpointer) vbox_label);     /* Keeping a pointer to the label */
00347                 }
00348         }
00349     va_end(args);
00350 
00351     tab = (tab_t *) g_malloc0(sizeof(tab_t));
00352 
00353     i = 0;
00354     hpaned = gtk_hpaned_new();
00355     gtk_container_set_border_width(GTK_CONTAINER(hpaned), 2); /* properties for the hpaned */
00356     child = hpaned;
00357     vbox = gtk_vbox_new(FALSE, 2);
00358     gtk_box_set_homogeneous(GTK_BOX(vbox), FALSE);
00359     g_ptr_array_add(vboxes, vbox);
00360     gtk_paned_add1(GTK_PANED(hpaned), (gpointer) vbox);
00361     vbox_label = g_ptr_array_index(col_labels, i);
00362     gtk_box_pack_start(GTK_BOX(vbox), vbox_label, FALSE, FALSE, 3);
00363 
00364     i++;
00365     while (i < nb_cols-1)
00366         {
00367             hpaned2 = gtk_hpaned_new();
00368             gtk_container_set_border_width(GTK_CONTAINER(hpaned2), 2); /* properties for the hpaned */
00369             gtk_paned_add2(GTK_PANED(hpaned), hpaned2);
00370             hpaned = hpaned2;                  /* translation */
00371             vbox = gtk_vbox_new(FALSE, 2);
00372             gtk_box_set_homogeneous(GTK_BOX(vbox), FALSE);
00373             g_ptr_array_add(vboxes, (gpointer) vbox);
00374             gtk_paned_add1(GTK_PANED(hpaned), vbox);
00375             vbox_label = g_ptr_array_index(col_labels, i);
00376             gtk_box_pack_start(GTK_BOX(vbox), vbox_label, FALSE, FALSE, 3);
00377             i++;
00378         }
00379 
00380     vbox = gtk_vbox_new(FALSE, 2);
00381     g_ptr_array_add(vboxes, (gpointer) vbox);
00382     gtk_paned_add2(GTK_PANED(hpaned), vbox);
00383     gtk_box_set_homogeneous(GTK_BOX(vbox), FALSE);
00384     vbox_label = g_ptr_array_index(col_labels, i);
00385     gtk_box_pack_start(GTK_BOX(vbox), vbox_label, FALSE, FALSE, 3);
00386 
00387     tab->index = index;
00388     tab->nb_cols = nb_cols;
00389     tab->nb_rows = 0;
00390     tab->label = gtk_label_new(label);   /* tab's label */
00391     gtk_misc_set_padding(GTK_MISC(tab->label), 2, 2);
00392     gtk_misc_set_alignment(GTK_MISC(tab->label), 0.5, 0.5);
00393     tab->col_labels = col_labels;
00394     tab->vboxes = vboxes;
00395     tab->rows = NULL;
00396 
00397     gtk_widget_show_all(child);
00398     gtk_notebook_append_page(notebook, child, tab->label);
00399 
00400     return tab;
00401 }
00402 
00403 
00404 /**
00405  * Adds a row to a particular tab
00406  * @param tab : the tab to which we want to add the row
00407  * @param row : the row we want to add (make sure it has been initialized)
00408  */
00409 void add_new_row_to_tab(tab_t *tab, decode_generic_t *row)
00410 {
00411     GtkWidget *vbox = NULL;  /**< the vbox to which we want to pack           */
00412     decode_t *couple = NULL; /**< couple from which we want to pack the entry */
00413     guint i = 0;
00414     guint j = 0;
00415 
00416     if (tab != NULL && row != NULL)
00417         {
00418 
00419             if (tab->rows == NULL)
00420                 {
00421                     tab->rows = g_ptr_array_new();
00422                 }
00423 
00424             g_ptr_array_add(tab->rows, (gpointer) row);
00425             tab->nb_rows++;
00426 
00427             /* label packing */
00428             vbox = g_ptr_array_index(tab->vboxes, 0);
00429             gtk_box_pack_start(GTK_BOX(vbox), row->label, FALSE, FALSE, 3);
00430 
00431             j = 0;
00432             i = 1;
00433 
00434             while (i <  tab->nb_cols)
00435                 {
00436                     vbox = g_ptr_array_index(tab->vboxes, i);
00437                     couple = g_ptr_array_index(row->decode_array, j);
00438                     gtk_box_pack_start(GTK_BOX(vbox), couple->entry, FALSE, FALSE, 1);
00439                     gtk_widget_show(couple->entry);
00440                     j++;
00441                     i++;
00442                 }
00443         }
00444 }
00445 
00446 
00447 /**
00448  * Inits data interpretor with default tabs
00449  * Must be called only once at bootime
00450  * @param main_struct : main structure
00451  * */
00452 static void add_default_tabs(heraia_struct_t *main_struct)
00453 {
00454     GtkWidget *notebook = NULL;
00455     tab_t *tab = NULL;
00456     decode_generic_t *row = NULL;
00457     data_window_t *dw = NULL;
00458 
00459     dw = main_struct->current_DW;
00460     notebook = heraia_get_widget(main_struct->xmls->main, "diw_notebook");
00461 
00462     dw->tabs = g_ptr_array_new();
00463 
00464     /** Adding a tab for numbers */
00465     tab = add_new_tab_in_data_interpretor(GTK_NOTEBOOK(notebook), 0, Q_("Numbers"), 3, Q_("Length"), Q_("Value unsigned"), Q_("Value signed"));
00466 
00467     if (tab != NULL)
00468         {
00469             g_ptr_array_add(dw->tabs, (gpointer) tab);
00470             dw->nb_tabs++;
00471             row = new_decode_generic_t("8 bits", 1, TRUE, Q_("Can not interpret %d byte as a 8 bits number"), 2,  decode_8bits_unsigned, decode_8bits_signed);
00472             add_new_row_to_tab(tab, row);
00473             row = new_decode_generic_t("16 bits", 2, TRUE, Q_("Can not interpret %d bytes as a 16 bits number"), 2, decode_16bits_unsigned, decode_16bits_signed);
00474             add_new_row_to_tab(tab, row);
00475             row = new_decode_generic_t("32 bits", 4, TRUE, Q_("Can not interpret %d bytes as a 32 bits number"), 2, decode_32bits_unsigned, decode_32bits_signed);
00476             add_new_row_to_tab(tab, row);
00477             row = new_decode_generic_t("64 bits", 8, TRUE, Q_("Can not interpret %d bytes as a 64 bits number"), 2, decode_64bits_unsigned, decode_64bits_signed);
00478             add_new_row_to_tab(tab, row);
00479         }
00480 
00481     /** Adding a tab for floting numbers */
00482     tab = add_new_tab_in_data_interpretor(GTK_NOTEBOOK(notebook), 1, Q_("Floats"), 3, Q_("Length"), Q_("Normal Notation"), Q_("Exponential notation"));
00483 
00484     if (tab != NULL)
00485         {
00486             g_ptr_array_add(dw->tabs, (gpointer) tab);
00487             dw->nb_tabs++;
00488             row = new_decode_generic_t(Q_("Float (32 bits)"), 4, TRUE, Q_("Can not interpret %d bytes as a float number"), 2, decode_float_normal, decode_float_scientific);
00489             add_new_row_to_tab(tab, row);
00490             row = new_decode_generic_t(Q_("Double (64 bits)"), 8, TRUE, Q_("Can not interpret %d bytes as a double number"), 2, decode_double_normal, decode_double_scientific);
00491             add_new_row_to_tab(tab, row);
00492         }
00493 
00494     /** Adding a tab for date and time */
00495     tab = add_new_tab_in_data_interpretor(GTK_NOTEBOOK(notebook), 2, Q_("Dates and Times"), 2, Q_("Type"), Q_("Value"));
00496 
00497     if (tab != NULL)
00498         {
00499             g_ptr_array_add(dw->tabs, (gpointer) tab);
00500             dw->nb_tabs++;
00501             row = new_decode_generic_t("MS-DOS", 4, TRUE, Q_("Can not interpret %d bytes as a DOS date"), 1, decode_dos_date);
00502             add_new_row_to_tab(tab, row);
00503             row = new_decode_generic_t("Filetime", 8, TRUE,  Q_("Can not interpret %d bytes as a filetime date"), 1, decode_filetime_date);
00504             add_new_row_to_tab(tab, row);
00505             row = new_decode_generic_t("C", 4, TRUE, Q_("Can not interpret %d bytes as a C date"), 1, decode_C_date);
00506             add_new_row_to_tab(tab, row);
00507             row = new_decode_generic_t("HFS", 4, TRUE, Q_("Can not interpret %d bytes as a HFS date"),  1, decode_HFS_date);
00508             add_new_row_to_tab(tab, row);
00509         }
00510 
00511     /** Adding a tab for binary based conversions */
00512     tab = add_new_tab_in_data_interpretor(GTK_NOTEBOOK(notebook), 3, Q_("Binary based"), 2, Q_("Type"), Q_("Value"));
00513 
00514     if (tab != NULL)
00515         {
00516             g_ptr_array_add(dw->tabs, (gpointer) tab);
00517             dw->nb_tabs++;
00518             row = new_decode_generic_t("Bits", 1, FALSE, Q_("Can not decode %d byte(s) to bits"), 1, decode_to_bits);
00519             add_new_row_to_tab(tab, row);
00520             row = new_decode_generic_t(Q_("Packed BCD"), 1, FALSE, Q_("Can not interpret %d byte(s) as packed BCD string"),  1, decode_packed_BCD);
00521             add_new_row_to_tab(tab, row);
00522         }
00523 }
00524 
00525 
00526 /**
00527  * Gets the selected tab (if any) from data interpretor's notebook
00528  * @param main_struct : main structure
00529  * @return A gint that represents the selected tab : >=0 if any < 0 otherwise
00530  */
00531 gint di_get_selected_tab(heraia_struct_t *main_struct)
00532 {
00533     GtkNotebook *notebook = NULL;  /**< data interpretor's notebook               */
00534     gint selected_tab = -1;        /**< Selected tab in data interpretor's window */
00535 
00536     notebook = GTK_NOTEBOOK(heraia_get_widget(main_struct->xmls->main, "diw_notebook"));
00537 
00538     if (notebook != NULL)
00539         {
00540             selected_tab = gtk_notebook_get_current_page(notebook);
00541         }
00542 
00543     return selected_tab;
00544 }
00545 
00546 
00547 /**
00548  * Sets the selected tab (if possible) to data interpretor's notebook
00549  * @param main_struct : main structure
00550  * @param selected_tab : the saved selected tab
00551  */
00552 void di_set_selected_tab(heraia_struct_t *main_struct, gint selected_tab)
00553 {
00554     GtkNotebook *notebook = NULL;  /**< data interpretor's notebook               */
00555 
00556     if (selected_tab >= 0)
00557         {
00558             notebook = GTK_NOTEBOOK(heraia_get_widget(main_struct->xmls->main, "diw_notebook"));
00559 
00560             if (notebook != NULL)
00561                 {
00562                     gtk_notebook_set_current_page(notebook, selected_tab);
00563                     main_struct->current_DW->tab_displayed = selected_tab;
00564                 }
00565         }
00566 }
00567 
00568 
00569 /**
00570  * Gets the stream_size (if any) from data interpretor's window
00571  * @param main_struct : main structure
00572  * @return A gint that represents the stream size : >=0 if any < 0 otherwise
00573  */
00574 gint di_get_stream_size(heraia_struct_t *main_struct)
00575 {
00576     GtkSpinButton *spin_button = NULL;  /**< data interpretor's spin button */
00577     gint stream_size = -1;              /**< stream size sat by the user    */
00578 
00579     spin_button = GTK_SPIN_BUTTON(heraia_get_widget(main_struct->xmls->main, "stream_size_spin_button"));
00580 
00581     if (spin_button != NULL)
00582         {
00583             stream_size = gtk_spin_button_get_value_as_int(spin_button);
00584         }
00585 
00586     return stream_size;
00587 }
00588 
00589 
00590 /**
00591  * Sets the stream size (if possible) to data interpretor's notebook
00592  * @param main_struct : main structure
00593  * @param stream_size : the saved stream_size
00594  */
00595 void di_set_stream_size(heraia_struct_t *main_struct, gint stream_size)
00596 {
00597     GtkSpinButton *spin_button = NULL;  /**< data interpretor's spin button */
00598 
00599     if (stream_size >= 0)
00600         {
00601             spin_button = GTK_SPIN_BUTTON(heraia_get_widget(main_struct->xmls->main, "stream_size_spin_button"));
00602 
00603             if (spin_button != NULL)
00604                 {
00605                     gtk_spin_button_set_value(spin_button, (gdouble) stream_size);
00606                 }
00607         }
00608 }
00609 
00610 
00611 /**
00612  * Gets the endianness as selected in the radio group button
00613  * @param main_struct : main structure
00614  * @return a gint that represents the endianness (H_DI_LITTLE_ENDIAN,
00615  *         H_DI_MIDDLE_ENDIAN, H_DI_BIG_ENDIAN) or -1 if nothing was correct
00616  */
00617 gint di_get_endianness(heraia_struct_t *main_struct)
00618 {
00619     GtkWidget *rb = NULL;
00620     GtkWidget *activated = NULL;
00621     const gchar *widget_name = NULL;
00622 
00623     rb =  heraia_get_widget(main_struct->xmls->main, "diw_rb_little_endian");
00624 
00625     if (rb != NULL)
00626         {
00627             activated = gtk_radio_button_get_active_from_widget(GTK_RADIO_BUTTON(rb));
00628 
00629             if (activated != NULL)
00630                 {
00631                     widget_name = gtk_buildable_get_name(GTK_BUILDABLE(activated));
00632                 }
00633         }
00634 
00635     if (widget_name != NULL)
00636         {
00637             if (g_ascii_strcasecmp(widget_name, "diw_rb_little_endian") == 0)
00638                 {
00639                     return H_DI_LITTLE_ENDIAN;
00640                 }
00641             else if (g_ascii_strcasecmp(widget_name, "diw_rb_big_endian") == 0)
00642                 {
00643                     return H_DI_BIG_ENDIAN;
00644                 }
00645             else if (g_ascii_strcasecmp(widget_name, "diw_rb_middle_endian") == 0)
00646                 {
00647                     return H_DI_MIDDLE_ENDIAN;
00648                 }
00649             else
00650                 {
00651                     return -1;
00652                 }
00653         }
00654     else
00655         {
00656             return -1;
00657         }
00658 }
00659 
00660 
00661 /**
00662  * Sets the endianness as stated by the second parameter
00663  * @param main_struct : main structure
00664  * @param endianness : the endianness to be sat. Must be one of the following :
00665  *                     (H_DI_LITTLE_ENDIAN, H_DI_MIDDLE_ENDIAN, H_DI_BIG_ENDIAN)
00666  */
00667 extern void di_set_endianness(heraia_struct_t *main_struct, gint endianness)
00668 {
00669     GtkWidget *rb = NULL;
00670 
00671     switch (endianness)
00672         {
00673             case H_DI_BIG_ENDIAN:
00674                 rb = heraia_get_widget(main_struct->xmls->main, "diw_rb_big_endian");
00675                 gtk_radio_button_set_active(GTK_RADIO_BUTTON(rb));
00676             break;
00677 
00678             case H_DI_MIDDLE_ENDIAN:
00679                 rb = heraia_get_widget(main_struct->xmls->main, "diw_rb_middle_endian");
00680                 gtk_radio_button_set_active(GTK_RADIO_BUTTON(rb));
00681             break;
00682 
00683             case H_DI_LITTLE_ENDIAN:
00684             default:
00685                 rb = heraia_get_widget(main_struct->xmls->main, "diw_rb_little_endian");
00686                 gtk_radio_button_set_active(GTK_RADIO_BUTTON(rb));
00687         }
00688 
00689 }
Generated on Fri Aug 20 09:15:18 2010 for Heraia by  doxygen 1.6.3