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