heraia_ui.c

Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
00002 /*
00003   heraia_ui.c
00004   main menus, callback and utility functions
00005  
00006   (C) Copyright 2005 - 2009 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 heraia_ui.c
00025  * This file has all the functions to manage heraia's ui
00026  * - signals definitions and functions
00027  * - widgets activations
00028  * - closing / openning windows
00029  */
00030 
00031 #include <libheraia.h>
00032 
00033 static void set_a_propos_properties(GtkWidget *about_dialog);
00034 static gboolean load_heraia_glade_xml(heraia_window_t *main_window);
00035 static void heraia_ui_connect_signals(heraia_window_t *main_window);
00036 static void record_and_hide_about_box(heraia_window_t *main_window);
00037 static void close_heraia(heraia_window_t *main_window);
00038 
00039 /**
00040  * @fn void on_quit_activate(GtkWidget *widget, gpointer data)
00041  *  Quit, file menu
00042  * @param widget : the widget that issued the signal
00043  * @param data : user data MUST be heraia_window_t *main_window main structure
00044  */
00045 void on_quit_activate(GtkWidget *widget, gpointer data)
00046 {
00047         heraia_window_t *main_window = (heraia_window_t *) data;
00048         
00049         close_heraia(main_window);
00050         gtk_main_quit();
00051 }
00052 
00053 /**
00054  * @fn void on_new_activate(GtkWidget *widget, gpointer data)
00055  *  New, file menu
00056  * @param widget : the widget that issued the signal
00057  * @param data : user data MUST be heraia_window_t *main_window main structure
00058  */
00059 void on_new_activate(GtkWidget *widget, gpointer data)
00060 {
00061         heraia_window_t *main_window = (heraia_window_t *) data;
00062         
00063         log_message(main_window, G_LOG_LEVEL_WARNING, "Not implemented Yet (Please contribute !)");
00064 }
00065 
00066 /**
00067  * @fn void on_preferences_activate(GtkWidget *widget, gpointer data)
00068  *  Preferences, file menu :
00069  *  Displays the preference window (as a modal window)
00070  * @param widget : the widget that issued the signal
00071  * @param data : user data MUST be heraia_window_t *main_window main structure
00072  */
00073 void on_preferences_activate(GtkWidget *widget, gpointer data)
00074 {
00075         heraia_window_t *main_window = (heraia_window_t *) data;
00076         GtkWidget *pref_window = NULL;
00077         
00078         pref_window = heraia_get_widget(main_window->xmls->main, "main_preferences_window");
00079         
00080         if (pref_window != NULL)
00081         {
00082                 move_and_show_dialog_box(pref_window, main_window->win_prop->main_pref_window);
00083         }
00084         
00085 }
00086 
00087 /**
00088  * @fn void set_a_propos_properties(GtkWidget *about_dialog)
00089  * Sets name and version in the dialog box
00090  * @param about_dialog the widget that contain all the about box
00091  */
00092 static void set_a_propos_properties(GtkWidget *about_dialog)
00093 {
00094         
00095         if (about_dialog != NULL)
00096         {
00097                 if (GTK_MINOR_VERSION >= 12)
00098                 {
00099                     gtk_about_dialog_set_program_name(GTK_ABOUT_DIALOG(about_dialog), PACKAGE_NAME);
00100                 }
00101                 if (GTK_MINOR_VERSION >= 6)
00102                 {
00103                         gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(about_dialog), PACKAGE_VERSION);
00104                 }
00105         }
00106 }
00107 
00108 
00109 /**
00110  * @fn void a_propos_activate(GtkWidget *widget, gpointer data)
00111  *  Shows apropos's dialog box
00112  * @param widget : the widget that issued the signal
00113  * @param data : user data MUST be heraia_window_t *main_window main structure
00114  */
00115 void a_propos_activate(GtkWidget *widget, gpointer data)
00116 {
00117         heraia_window_t *main_window = (heraia_window_t *) data;
00118         GtkWidget *about_dialog = NULL;
00119         
00120         about_dialog = heraia_get_widget(main_window->xmls->main, "about_dialog");
00121         
00122         if (about_dialog != NULL)
00123         {
00124                 set_a_propos_properties(about_dialog);
00125         
00126                 move_and_show_dialog_box(about_dialog, main_window->win_prop->about_box);
00127         }
00128 }
00129 
00130 /** 
00131  * @fn void move_and_show_dialog_box(GtkWidget *dialog_box, window_prop_t *dialog_prop)
00132  *  Move the dialog box to the wanted position, shows it and says it in the displayed prop
00133  * @param dialog_box : the dialog box we want to move and show
00134  * @param dialog_prop : window_prop_t properties structure corresponding to the dialog box
00135  */
00136 void move_and_show_dialog_box(GtkWidget *dialog_box, window_prop_t *dialog_prop)
00137 {
00138         if (dialog_prop->displayed == FALSE)
00139         {
00140                 gtk_window_move(GTK_WINDOW(dialog_box), dialog_prop->x, dialog_prop->y);
00141                 
00142                 gtk_widget_show_all(dialog_box);
00143                 dialog_prop->displayed = TRUE;
00144         }
00145 }
00146 
00147 /**
00148  * @fn void record_dialog_box_position(GtkWidget *dialog_box, window_prop_t *dialog_prop)
00149  * Records one dialog position
00150  * @param dialog_box : a dialog box from which we want to record the position
00151  * @param[in,out] dialog_prop : window_prop_t properties structure corresponding to the dialog box
00152  */
00153 void record_dialog_box_position(GtkWidget *dialog_box, window_prop_t *dialog_prop)
00154 {
00155         gint x = 0;
00156         gint y = 0;
00157         
00158         if (dialog_prop != NULL && dialog_prop->displayed == TRUE)
00159         {
00160                 if (dialog_box != NULL)
00161                 {
00162                         gtk_window_get_position(GTK_WINDOW(dialog_box), &x, &y);
00163                         dialog_prop->x = x;
00164                         dialog_prop->y = y;
00165                 }
00166         }
00167 }
00168 
00169 
00170 /**
00171  * @fn void record_all_dialog_box_positions(heraia_window_t *main_window)
00172  * Records all the positions of the displayed windows
00173  * @param[in,out] main_window : main structure
00174  */
00175 void record_all_dialog_box_positions(heraia_window_t *main_window)
00176 {
00177         GtkWidget *dialog_box = NULL;
00178 
00179         if (main_window != NULL && 
00180                 main_window->xmls != NULL && 
00181                 main_window->xmls->main != NULL &&
00182                 main_window->win_prop != NULL &&
00183                 main_window->current_DW != NULL)
00184         {
00185                 /* data interpretor */
00186                 dialog_box = main_window->current_DW->diw;
00187                 record_dialog_box_position(dialog_box, main_window->win_prop->data_interpretor);
00188         
00189                 /* About box */
00190                 dialog_box = heraia_get_widget (main_window->xmls->main, "about_dialog");
00191                 record_dialog_box_position(dialog_box, main_window->win_prop->about_box);
00192         
00193                 /* Log window */
00194                 dialog_box = heraia_get_widget (main_window->xmls->main, "log_window");
00195                 record_dialog_box_position(dialog_box, main_window->win_prop->log_box);
00196         
00197                 /* main_dialog */
00198                 dialog_box = heraia_get_widget (main_window->xmls->main, "main_window");
00199                 record_dialog_box_position(dialog_box, main_window->win_prop->main_dialog);
00200         
00201                 /* plugin_list */
00202                 dialog_box = heraia_get_widget (main_window->xmls->main, "plugin_list_window");
00203                 record_dialog_box_position(dialog_box, main_window->win_prop->plugin_list);
00204         
00205                 /* list data types */
00206                 dialog_box = heraia_get_widget (main_window->xmls->main, "list_data_types_window");
00207                 record_dialog_box_position(dialog_box, main_window->win_prop->ldt);
00208         
00209                 /* main_preferences */
00210                 dialog_box = heraia_get_widget (main_window->xmls->main, "main_preferences_window");
00211                 record_dialog_box_position(dialog_box, main_window->win_prop->main_pref_window);
00212         }
00213 }
00214         
00215         
00216 /**
00217  * @fn void record_and_hide_dialog_box(GtkWidget *dialog_box, window_prop_t *dialog_prop)
00218  *  Record position and hide a dialog box
00219  * @param dialog_box : the dialog box we want to record its position and then hide
00220  * @param dialog_prop : window_prop_t properties structure corresponding to the dialog box
00221  */
00222 void record_and_hide_dialog_box(GtkWidget *dialog_box, window_prop_t *dialog_prop)
00223 {
00224 
00225         if (dialog_prop->displayed == TRUE)
00226         {
00227                 record_dialog_box_position(dialog_box, dialog_prop);
00228                 
00229                 gtk_widget_hide(dialog_box);
00230                 dialog_prop->displayed = FALSE;
00231         }
00232 }
00233 
00234 
00235 /**
00236  * @fn static void record_and_hide_about_box(heraia_window_t *main_window)
00237  *  Record position and hide about dialog box
00238  * @param [in,out] main_window : main structure
00239  */
00240 static void record_and_hide_about_box(heraia_window_t *main_window)
00241 {
00242         GtkWidget *about_dialog = NULL; 
00243         
00244         about_dialog = heraia_get_widget(main_window->xmls->main, "about_dialog");
00245         
00246         if (about_dialog != NULL)
00247         {
00248                 record_and_hide_dialog_box(about_dialog, main_window->win_prop->about_box);
00249         }
00250 }
00251 
00252 
00253 /**
00254  * @fn void a_propos_response(GtkWidget *widget, gint response, gpointer data)
00255  *  To close the A propos dialog box (with the "close" button)
00256  * @param widget : calling widget (may be NULL as we don't use this)
00257  * @param response : may be whatever you want as we neither use this !
00258  * @param data : MUST be heraia_window_t *main_window main structure
00259  */
00260 static void a_propos_response(GtkWidget *widget, gint response, gpointer data)
00261 {
00262         heraia_window_t *main_window = (heraia_window_t *) data;
00263         record_and_hide_about_box(main_window);
00264 }
00265 
00266 /**
00267  * @fn void a_propos_close(GtkWidget *widget, gpointer data)
00268  *  To close the A propos dialog box
00269  * @param widget : calling widget (may be NULL as we don't use this)
00270  * @param data : MUST be heraia_window_t *main_window main structure
00271  */
00272 static void a_propos_close(GtkWidget *widget, gpointer data)
00273 {
00274         heraia_window_t *main_window = (heraia_window_t *) data;
00275         record_and_hide_about_box(main_window);
00276 }
00277 
00278 
00279 /**
00280  * @fn gboolean a_propos_delete(GtkWidget *widget, GdkEvent  *event, gpointer data)
00281  *  To close the A propos dialog box
00282  * @param widget : calling widget (may be NULL as we don't use this)
00283  * @param event : event associated (may be NULL as we don't use this)
00284  * @param data : MUST be heraia_window_t *main_window main structure
00285  * @return returns TRUE in order to allow other functions to do something with
00286  *         that event.
00287  */
00288 static gboolean a_propos_delete(GtkWidget *widget, GdkEvent  *event, gpointer data)
00289 {
00290         heraia_window_t *main_window = (heraia_window_t *) data;
00291         record_and_hide_about_box(main_window);
00292         
00293         return TRUE;
00294 }
00295 
00296 
00297 /**
00298  * @fn void on_delete_activate(GtkWidget *widget, gpointer data)
00299  *  Delete, edit menu
00300  * @warning Not yet implemented
00301  * @todo Write a usefull function here :)
00302  * @param widget : the widget that issued the signal
00303  * @param data : user data MUST be heraia_window_t *main_window main structure
00304  */
00305 void on_delete_activate(GtkWidget *widget, gpointer data)
00306 {
00307         heraia_window_t *main_window = (heraia_window_t *) data;
00308         
00309         log_message(main_window, G_LOG_LEVEL_WARNING, "Not implemented Yet (Please contribute !)");
00310 }
00311 
00312 /**
00313  * @fn void on_cut_activate(GtkWidget *widget, gpointer data)
00314  *  Cut, edit menu
00315  * @warning Not yet implemented
00316  * @todo Write a usefull function here :)
00317  * @param widget : the widget that issued the signal
00318  * @param data : user data MUST be heraia_window_t *main_window main structure
00319  */
00320 void on_cut_activate(GtkWidget *widget, gpointer data)
00321 {
00322         heraia_window_t *main_window = (heraia_window_t *) data;
00323         
00324         log_message(main_window, G_LOG_LEVEL_WARNING, "Not implemented Yet (Please contribute !)");
00325 }
00326 
00327 /**
00328  * @fn void on_copy_activate( GtkWidget *widget, gpointer data )
00329  *  Copy, edit menu
00330  * @warning Not yet implemented
00331  * @todo Write a usefull function here :)
00332  * @param widget : the widget that issued the signal
00333  * @param data : user data MUST be heraia_window_t *main_window main structure
00334  */
00335 void on_copy_activate(GtkWidget *widget, gpointer data)
00336 {
00337         heraia_window_t *main_window = (heraia_window_t *) data;
00338         
00339         log_message(main_window, G_LOG_LEVEL_WARNING, "Not implemented Yet (Please contribute !)");
00340 }
00341 
00342 
00343 /**
00344  * @fn void on_paste_activate( GtkWidget *widget, gpointer data )
00345  *  Paste, edit menu
00346  * @warning Not yet implemented
00347  * @todo Write a usefull function here :)
00348  * @param widget : the widget that issued the signal
00349  * @param data : user data MUST be heraia_window_t *main_window main structure
00350  */
00351 void on_paste_activate(GtkWidget *widget, gpointer data)
00352 {
00353         heraia_window_t *main_window = (heraia_window_t *) data;
00354         
00355         log_message(main_window, G_LOG_LEVEL_WARNING, "Not implemented Yet (Please contribute !)");
00356 }
00357 
00358 
00359 /**
00360  * @fn void refresh_file_labels(heraia_window_t *main_window)
00361  *  This function is refreshing the labels on the main
00362  *  window in order to reflect cursor position, selected
00363  *  positions and total selected size
00364  * @param main_window : main structure
00365  */
00366 void refresh_file_labels(heraia_window_t *main_window)
00367 {
00368         GtkWidget *label = NULL;
00369         guint64 position = 0;
00370         gchar *text = NULL;
00371         
00372         if (main_window != NULL)
00373                 {
00374                         if (main_window->current_DW != NULL && main_window->current_DW->current_hexwidget != NULL)
00375                                 {
00376                                         label = heraia_get_widget(main_window->xmls->main, "file_position_label");
00377                                         position = ghex_get_cursor_position(main_window->current_DW);
00378                                         /* position begins at 0 and this is not really human readable */
00379                                         /* it's more confusing than anything so we do + 1             */
00380                                         /* To translators : do not translate <small> and such         */
00381                                         
00382                                         if (is_toggle_button_activated(main_window->xmls->main, "mp_thousand_bt") == TRUE)
00383                                         {
00384                                                 text = g_strdup_printf("<small>%'lld</small>", position + 1);
00385                                         }
00386                                         else
00387                                         {
00388                                                 text = g_strdup_printf("<small>%lld</small>", position + 1);
00389                                         }
00390                                         gtk_label_set_markup(GTK_LABEL(label), text);
00391                                         g_free(text);
00392                                 }
00393                         else
00394                                 {
00395                                         label = heraia_get_widget(main_window->xmls->main, "file_position_label");
00396                                         gtk_label_set_text(GTK_LABEL(label), "");
00397                                 }
00398                 }
00399 }
00400 
00401 
00402 /** 
00403  * @fn void refresh_event_handler(GtkWidget *widget, gpointer data)
00404  *  This function is here to ensure that everything will be
00405  *  refreshed upon a signal event.
00406  * @warning This function is not thread safe (do not use in a thread)
00407  * @todo try to put some mutexes on main_window->event to make this
00408  *       thread safe some way
00409  * @param widget : the widget that issued the signal
00410  * @param data : user data MUST be heraia_window_t *main_window main structure
00411  */
00412 void refresh_event_handler(GtkWidget *widget, gpointer data)
00413 {
00414         heraia_window_t *main_window = (heraia_window_t *) data;
00415         
00416         if (main_window != NULL)
00417         {
00418                 /* Beware, this mechanism is not thread safe ! */
00419                 if (main_window->event == HERAIA_REFRESH_NOTHING)
00420                 {
00421                         main_window->event = HERAIA_REFRESH_CURSOR_MOVE;
00422                 }
00423                 
00424                 refresh_data_interpretor_window(widget, main_window);
00425                 refresh_all_plugins(main_window);
00426                 refresh_file_labels(main_window);
00427                 
00428                 main_window->event = HERAIA_REFRESH_NOTHING;
00429         }
00430 }
00431 
00432 
00433 /**
00434  * @fn void on_open_activate(GtkWidget *widget, gpointer data)
00435  *  This handles the menuitem "Ouvrir" to open a file
00436  * @warning This function is not thread safe (do not use in a thread)
00437  * @todo try to put some mutexes on main_window->event to make this
00438  *       thread safe some way
00439  * @param widget : the widget that issued the signal
00440  * @param data : user data MUST be heraia_window_t *main_window main structure
00441  */
00442 void on_open_activate(GtkWidget *widget, gpointer data)
00443 {
00444         heraia_window_t *main_window = (heraia_window_t *) data;
00445         
00446         if (select_file_to_load(main_window) == TRUE)
00447         {
00448                 load_file_to_analyse(main_window, main_window->filename);
00449         }
00450         
00451         /* Not thread safe here ? */
00452         main_window->event = HERAIA_REFRESH_NEW_FILE;
00453         refresh_event_handler(main_window->current_DW->current_hexwidget, main_window);
00454 }
00455 
00456 
00457 /**
00458  * @fn void on_save_activate(GtkWidget *widget, gpointer data)
00459  *  Here we attemp to save the edited file
00460  *  @todo be more accurate on error (error type, message and filename) returns
00461  *        we should return something at least ...
00462  * @param widget : the widget that issued the signal
00463  * @param data : user data MUST be heraia_window_t *main_window main structure
00464  */
00465 void on_save_activate(GtkWidget *widget, gpointer data)
00466 {
00467         heraia_window_t *main_window = (heraia_window_t *) data;        
00468         HERAIA_ERROR erreur = HERAIA_NOERR;
00469         gchar *filename = NULL;
00470         
00471         if (main_window != NULL && main_window->current_doc != NULL)
00472         {
00473                 erreur = heraia_hex_document_save(main_window); 
00474 
00475                 if (erreur != HERAIA_NOERR)
00476                 {
00477                         filename = heraia_hex_document_get_filename(main_window->current_doc);
00478                         log_message(main_window, G_LOG_LEVEL_ERROR, "Error while saving file %s !", filename);
00479                 }
00480         }
00481 }
00482 
00483 /**
00484  * @fn void on_save_as_activate(GtkWidget *widget, gpointer data)
00485  *  This handle the save_as menu entry (here the filename changes)
00486  * @param widget : the widget that issued the signal
00487  * @param data : user data MUST be heraia_window_t *main_window main structure
00488  */
00489 void on_save_as_activate(GtkWidget *widget, gpointer data)
00490 {
00491         heraia_window_t *main_window = (heraia_window_t *) data;
00492         HERAIA_ERROR erreur = HERAIA_NOERR;
00493         gchar *filename = NULL;  /* Auto malloc'ed, do not free */
00494 
00495         if (main_window != NULL && main_window->current_doc != NULL)
00496         {
00497                 filename = select_a_file_to_save(main_window);
00498                 
00499                 if (filename != NULL)
00500                 {
00501                         erreur = heraia_hex_document_save_as(main_window, filename);
00502                 }
00503                 else
00504                 {
00505                         erreur = HERAIA_CANCELLED;
00506                 }
00507                 
00508                 if (erreur != HERAIA_NOERR)
00509                 {
00510                         if (erreur == HERAIA_CANCELLED)
00511                         {
00512                                 log_message(main_window, G_LOG_LEVEL_DEBUG, "Saving file as... : operation cancelled.");
00513                         }
00514                         else
00515                         {
00516                                 log_message(main_window, G_LOG_LEVEL_ERROR, "Error while saving file as %s", main_window->current_doc->file_name);
00517                         }
00518                 }
00519                 else
00520                 {
00521                         /* updating the window name and tab's name */
00522                         update_main_window_name(main_window);
00523                         set_notebook_tab_name(main_window);
00524                         log_message(main_window, G_LOG_LEVEL_DEBUG, "File %s saved and now edited.", main_window->current_doc->file_name);
00525                 }
00526         }
00527 }
00528 
00529 
00530 /**
00531  * @fn void on_DIMenu_activate(GtkWidget *widget, gpointer data)
00532  *  This handles the menuitem "Data Interpretor" that
00533  *  shows or hides the data interpretor window     
00534  * @param widget : the widget that issued the signal
00535  * @param data : user data MUST be heraia_window_t *main_window main structure
00536  */
00537 void on_DIMenu_activate(GtkWidget *widget, gpointer data)
00538 {
00539         
00540         heraia_window_t *main_window = (heraia_window_t *) data;
00541         data_window_t *dw = NULL;      /* program structure           */
00542         GtkNotebook *notebook = NULL;  /* data interpretor's notebook */
00543         
00544         if (main_window != NULL)
00545         {
00546                 dw = main_window->current_DW;
00547                 
00548                 if (dw != NULL)
00549                 {
00550                         if (dw->diw == NULL)
00551                         {
00552                                 dw->diw = heraia_get_widget(main_window->xmls->main, "data_interpretor_window");
00553                         }
00554                         
00555                         if (dw->diw != NULL)
00556                         {
00557                                 /* dw->window_displayed = !(dw->window_displayed); */
00558                                 notebook = GTK_NOTEBOOK(heraia_get_widget(main_window->xmls->main, "diw_notebook"));
00559                                 
00560                         if (main_window->win_prop->data_interpretor->displayed == FALSE)
00561                                 {
00562                                         /* Setting the first page of the notebook as default (Numbers) */                                       
00563                                         gtk_notebook_set_current_page(notebook, dw->tab_displayed);
00564                                         
00565                                         /* moving to the right position */
00566                                         move_and_show_dialog_box(dw->diw, main_window->win_prop->data_interpretor);
00567                                         
00568                                         refresh_data_interpretor_window(widget, data);
00569                                 }
00570                                 else
00571                                 {
00572                                         /* recording some prefs from the dialog : position + opened tab */
00573                                         dw->tab_displayed = gtk_notebook_get_current_page(notebook);
00574                                         record_and_hide_dialog_box(dw->diw, main_window->win_prop->data_interpretor);
00575                                 }
00576                         }
00577                 }
00578         }
00579 }
00580 
00581 
00582 /**
00583  * @fn delete_main_window_event(GtkWidget *widget, GdkEvent  *event, gpointer data)
00584  *  When the user destroys or delete the main window
00585  * @param widget : calling widget 
00586  * @param event : event associated (may be NULL as we don't use this here)
00587  * @param data : MUST be heraia_window_t *main_window main structure
00588  */
00589 gboolean delete_main_window_event(GtkWidget *widget, GdkEvent  *event, gpointer data)
00590 {
00591                 
00592         on_quit_activate(widget, data);
00593         
00594         return FALSE;
00595 }
00596 
00597 
00598 /**
00599  * @fn gboolean delete_dt_window_event(GtkWidget *widget, GdkEvent  *event, gpointer data)
00600  *  call back function for the data interpretor window destruction
00601  * @param widget : calling widget (may be NULL as we don't use this here)
00602  * @param event : event associated (may be NULL as we don't use this here)
00603  * @param data : MUST be heraia_window_t *main_window main structure and not NULL
00604  */
00605 gboolean delete_dt_window_event(GtkWidget *widget, GdkEvent  *event, gpointer data)
00606 {       
00607         heraia_window_t *main_window = (heraia_window_t *) data;
00608         
00609         g_signal_emit_by_name(heraia_get_widget(main_window->xmls->main, "DIMenu"), "activate");
00610         
00611         return TRUE;
00612 }
00613 
00614 /**
00615  * @fn void destroy_dt_window(GtkWidget *widget, GdkEvent  *event, gpointer data)
00616  *  call back function for the data interpretor window destruction
00617  * @param widget : calling widget (may be NULL as we don't use this here)
00618  * @param event : event associated (may be NULL as we don't use this here)
00619  * @param data : MUST be heraia_window_t *main_window main structure and not NULL
00620  */
00621 void destroy_dt_window(GtkWidget *widget, GdkEvent  *event, gpointer data)
00622 {
00623         heraia_window_t *main_window = (heraia_window_t *) data;
00624         
00625         g_signal_emit_by_name(heraia_get_widget(main_window->xmls->main, "DIMenu"), "activate");
00626 }
00627 /* End of call back functions that handle the data interpretor window */
00628 
00629 
00630 /**
00631  * @fn static gchar *make_absolute_path(gchar *filename)
00632  *  Returns an absolute path to the filename
00633  *  the string should be freed when no longer needed
00634  *  very UGLy !
00635  * @todo do something without any system calls !!! 
00636  * @param filename : relative notation filename from which to extract an
00637  *        absolute path
00638  * @return returns a string with the absolute path which should be freed when
00639  *         no longer needed
00640  */
00641 static gchar *make_absolute_path(gchar *filename)
00642 {
00643         gchar *current_dir = NULL;
00644         gchar *new_dir = NULL;
00645         
00646         if (g_path_is_absolute(filename) == TRUE)
00647         {
00648                 /* if the filename is already in an absolute format */
00649                 return  g_path_get_dirname(filename);
00650         }
00651         else
00652         {
00653                 current_dir = g_get_current_dir();
00654                 new_dir = g_path_get_dirname(filename);
00655                 
00656                 if (g_chdir(new_dir) == 0)
00657                 {
00658                         g_free(new_dir);
00659                         new_dir = g_get_current_dir();
00660                         g_chdir(current_dir);
00661                         g_free(current_dir);
00662                         
00663                         return new_dir;
00664                 }
00665                 else
00666                 {
00667                         g_free(current_dir);
00668                         
00669                         return NULL;
00670                 }
00671         }
00672 }
00673 
00674 
00675 /**
00676  * @fn void set_the_working_directory(GtkFileChooser *file_chooser, gchar *filename)
00677  *  Sets the working directory for the file chooser to the directory of the
00678  *  filename (even if filename is a relative filename such as ../docs/test_file)
00679  * @param file_chooser : An initialized GtkFileChooser
00680  * @param filename : a filename (one previously openned)
00681  */
00682 static void set_the_working_directory(GtkFileChooser *file_chooser, gchar *filename)
00683 {
00684         gchar *dirname = NULL;    /* directory where we want to be, at first, in the file chooser */
00685         
00686         dirname = make_absolute_path(filename);
00687         
00688         if (dirname != NULL)
00689         {
00690                 gtk_file_chooser_set_current_folder(file_chooser, dirname);
00691                 g_free(dirname);
00692         }
00693 }
00694 
00695 
00696 /**
00697  * @fn gboolean select_file_to_load(heraia_window_t *main_window)
00698  *  This function does open a file selector dialog box and returns the selected 
00699  *  filename. 
00700  *  We do fill the main_window->filename parameter here !
00701  * @param main_window : main structure
00702  * @return returns TRUE if everything went ok, FALSE otherwise
00703  */
00704 gboolean select_file_to_load(heraia_window_t *main_window)
00705 {
00706         GtkWidget *parent = NULL; /* A parent window (we use main_window)      */
00707         GtkFileChooser *file_chooser = NULL;
00708         gboolean success = FALSE;
00709         gchar *filename = NULL;   /* filename selected (if any) to be openned  */
00710         
00711         parent = heraia_get_widget(main_window->xmls->main, "main_window");
00712         
00713         file_chooser = GTK_FILE_CHOOSER(gtk_file_chooser_dialog_new("Select a file to analyse",
00714                                                                                                                                 GTK_WINDOW(parent),
00715                                                                                                                                 GTK_FILE_CHOOSER_ACTION_OPEN, 
00716                                                                                                                                 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
00717                                                                                                                                 GTK_STOCK_OPEN, GTK_RESPONSE_OK, 
00718                                                                                                                                 NULL));
00719         
00720         /**
00721          *  for the moment we do not want to retrieve multiples selections 
00722          *  but this could be a valuable thing in the future
00723          */
00724         gtk_window_set_modal(GTK_WINDOW(file_chooser), TRUE);
00725         gtk_file_chooser_set_select_multiple(file_chooser, FALSE);
00726         
00727         /**
00728          *  We want the file selection path to be the one of the previous
00729          *  openned file if any !
00730          */
00731         if (main_window->filename != NULL)
00732            {
00733                         set_the_working_directory(file_chooser, main_window->filename);
00734            }
00735         
00736         switch (gtk_dialog_run(GTK_DIALOG(file_chooser))) 
00737           {
00738                 case GTK_RESPONSE_OK:
00739                         filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(file_chooser));
00740                         log_message(main_window, G_LOG_LEVEL_DEBUG, "filename selected : %s", filename);
00741                         
00742                         /* this should be managed with lists and not here !! */         
00743                         if (main_window->filename != NULL)
00744                        {
00745                                         g_free(main_window->filename);
00746                        }
00747                         
00748                         main_window->filename = g_strdup_printf("%s", filename);
00749                         success = TRUE;
00750                  break;
00751                 case GTK_RESPONSE_CANCEL:
00752                 default:
00753                         success = FALSE;
00754                  break;
00755            }
00756         
00757         g_free(filename);
00758         gtk_widget_destroy(GTK_WIDGET(file_chooser));
00759         
00760         return success;
00761 }
00762 
00763 /**
00764  * @fn gchar *select_a_file_to_save(heraia_window_t *main_window)
00765  *  This function opens a dialog box that allow one to choose a 
00766  *  file name to the file which is about to be saved
00767  * @param main_window : main structure
00768  * @return returns complete filename (path and filename)
00769  */
00770 gchar *select_a_file_to_save(heraia_window_t *main_window)
00771 {
00772         GtkWidget *parent = NULL;     /* A parent window (we use main_window) */
00773         GtkFileChooser *fcd = NULL;
00774         gchar *filename = NULL; 
00775 
00776         parent = heraia_get_widget(main_window->xmls->main, "main_window");
00777         
00778         /* Selection a name to the file to save */
00779         fcd = GTK_FILE_CHOOSER(gtk_file_chooser_dialog_new("Save As...",
00780                                                                                                            GTK_WINDOW(parent),
00781                                                                                                            GTK_FILE_CHOOSER_ACTION_SAVE, 
00782                                                                                                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
00783                                                                                                            GTK_STOCK_SAVE, GTK_RESPONSE_OK, 
00784                                                                                                            NULL));
00785 
00786         /* window properties : modal, without multi-selection and with confirmation */
00787         gtk_window_set_modal(GTK_WINDOW(fcd), TRUE);
00788         gtk_file_chooser_set_select_multiple(fcd, FALSE);
00789         gtk_file_chooser_set_do_overwrite_confirmation(fcd, TRUE);
00790 
00791         /* we do want to have the file's directory where to save the new file */
00792         if (main_window->filename != NULL)
00793            {
00794                         set_the_working_directory(fcd, main_window->filename);
00795            }
00796         
00797         switch(gtk_dialog_run(GTK_DIALOG(fcd)))
00798                 {
00799                 case GTK_RESPONSE_OK:
00800                         /* retrieving the filename */
00801                         filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fcd));
00802                         break;
00803                 default:
00804                         filename = NULL;
00805                         break;
00806                 }
00807 
00808         gtk_widget_destroy(GTK_WIDGET(fcd));
00809 
00810         return filename;
00811 }
00812 
00813 
00814 /**
00815  * @fn void update_main_window_name(heraia_window_t *main_window)
00816  *  Update main window heraia's name to reflect the current edited file
00817  * @param main_window : main structure
00818  */
00819 void update_main_window_name(heraia_window_t *main_window)
00820 {
00821         GtkWidget *widget = NULL;
00822         gchar *filename = NULL;
00823         
00824         if (main_window != NULL && main_window->current_doc != NULL)
00825            {
00826                         widget = heraia_get_widget(main_window->xmls->main, "main_window");
00827                     filename = g_filename_display_basename(main_window->current_doc->file_name);
00828                    
00829                         gtk_window_set_title(GTK_WINDOW(widget), filename);
00830            }
00831 }
00832 
00833 /**
00834  * @fn void set_notebook_tab_name(heraia_window_t *main_window)
00835  *  Sets notebook's tab's name. This function should only be called
00836  *  when a new filename was set (open and save as functions)
00837  * @param main_window : main structure
00838  */
00839 void set_notebook_tab_name(heraia_window_t *main_window)
00840 {
00841         GtkWidget *notebook = NULL; /* file notebook in main window       */
00842         GtkWidget *page = NULL;     /* Current page for the file notebook */
00843         GtkWidget *label = NULL;    /* tab's label                        */
00844         gchar *filename = NULL;
00845         gint current = 0;
00846         
00847         if (main_window != NULL && main_window->current_doc != NULL)
00848            {
00849                    notebook = heraia_get_widget(main_window->xmls->main, "file_notebook");
00850                    current = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
00851                    page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook), current);
00852                    label = gtk_notebook_get_tab_label(GTK_NOTEBOOK(notebook), page);
00853                    filename = g_filename_display_basename(main_window->current_doc->file_name);
00854                    gtk_label_set_text(GTK_LABEL(label), filename);
00855                    
00856                    /* gtk_widget_set_tooltip_text is available since gtk 2.12 */
00857                    if (GTK_MINOR_VERSION >= 12) 
00858                         { 
00859                                 gtk_widget_set_tooltip_text(label, g_filename_display_name(main_window->current_doc->file_name));
00860                         }
00861            }
00862 }
00863 
00864 
00865 /**
00866  * @fn init_heraia_interface(heraia_window_t *main_window)
00867  *  Here we might init some call backs and menu options
00868  *  and display the interface (main && sub-windows)
00869  *  This function should be called only once at main program's 
00870  *  init time
00871  * @param main_window : main structure
00872  */
00873 void init_heraia_interface(heraia_window_t *main_window)
00874 {
00875         GtkWidget *notebook = NULL;  /* file notebook in main window */
00876         
00877         if (main_window != NULL)
00878         {
00879                 /* inits window states (shows or hide windows) */
00880                 init_window_states(main_window);
00881                 
00882                 /* Notebook selection */
00883                 notebook = heraia_get_widget(main_window->xmls->main, "file_notebook");
00884                 gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 0);
00885                 
00886                 if (main_window->current_doc != NULL)
00887                 {
00888                         gtk_widget_show(notebook);
00889                 }
00890                 else
00891                 {
00892                         /** Hide notebook and menus @todo put these lines in a specific function */
00893                         gtk_widget_set_sensitive(heraia_get_widget(main_window->xmls->main, "save"), FALSE);
00894                         gtk_widget_set_sensitive(heraia_get_widget(main_window->xmls->main, "save_as"), FALSE);                          
00895                         gtk_widget_hide(notebook); 
00896                 }
00897                 
00898                 refresh_file_labels(main_window);
00899         }
00900 }
00901 
00902 
00903 /**
00904  * @fn gboolean load_heraia_glade_xml(heraia_window_t *main_window)
00905  *  Loads the glade xml files that describes the heraia project
00906  *  tries the following paths in that order :                 
00907  *  - /etc/heraia/heraia.glade
00908  *  - /home/[user]/.heraia/heraia.glade
00909  *  - PWD/heraia.glade
00910  * @param main_window : main structure
00911  * @return TRUE if everything went ok, FALSE otherwise
00912  */
00913 static gboolean load_heraia_glade_xml(heraia_window_t *main_window)
00914 {
00915         gchar *filename = NULL;
00916         
00917         if (main_window != NULL && main_window->xmls != NULL)
00918         {
00919                 filename = g_strdup_printf("heraia.glade"); 
00920                 main_window->xmls->main = load_glade_xml_file(main_window->location_list, filename);
00921                 g_free(filename);
00922                 
00923                 if (main_window->xmls->main == NULL)
00924                 {
00925                         return FALSE;
00926                 }
00927                 else
00928                 {
00929                         return TRUE;
00930                 }
00931         }
00932         else
00933         {
00934                 return FALSE;
00935         }
00936 }
00937 
00938 /**
00939  * @fn connect_cursor_moved_signal(heraia_window_t *main_window)
00940  *  Connects the signal that the cursor has moved to
00941  *  the refreshing function
00942  * @param main_window : main structure 
00943  */
00944 void connect_cursor_moved_signal(heraia_window_t *main_window)
00945 {
00946         g_signal_connect(G_OBJECT(main_window->current_DW->current_hexwidget), "cursor_moved",   
00947                                          G_CALLBACK(refresh_event_handler), main_window);
00948 }
00949 
00950 
00951 /**
00952  * @fn void heraia_ui_connect_signals(heraia_window_t *main_window)
00953  *  Connect the signals at the interface
00954  * @param main_window : main structure
00955  */
00956 static void heraia_ui_connect_signals(heraia_window_t *main_window)
00957 {
00958         
00959         /* the data interpretor menu */
00960         g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "DIMenu")), "activate", 
00961                                           G_CALLBACK (on_DIMenu_activate), main_window);
00962         
00963         /* Quit, file menu */
00964         g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "quit")), "activate", 
00965                                           G_CALLBACK (on_quit_activate), main_window);
00966         
00967         /* New, file menu */
00968         g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "new")), "activate",  
00969                                           G_CALLBACK (on_new_activate), main_window);
00970         
00971         /* Open, file menu */
00972         g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "open")), "activate",  
00973                                           G_CALLBACK (on_open_activate), main_window);
00974         
00975         /* Save, file menu */
00976         g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "save")), "activate",  
00977                                           G_CALLBACK (on_save_activate), main_window);
00978         
00979         /* Save As, file menu */
00980         g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "save_as")), "activate",  
00981                                           G_CALLBACK (on_save_as_activate), main_window); 
00982         
00983         /* Preferences, file menu ; See main_pref_window.c for main_pref_window's signals */
00984         g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "preferences")), "activate",  
00985                                           G_CALLBACK (on_preferences_activate), main_window);
00986         
00987         /* Cut, edit menu */
00988         g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "cut")), "activate",  
00989                                           G_CALLBACK (on_cut_activate), main_window); 
00990         
00991         /* Copy, edit menu */
00992         g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "copy")), "activate",  
00993                                           G_CALLBACK (on_copy_activate), main_window); 
00994         
00995         /* Paste, edit menu */
00996         g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "paste")), "activate",  
00997                                           G_CALLBACK (on_paste_activate), main_window); 
00998         
00999         /* Delete, edit menu */
01000         g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "delete")), "activate",  
01001                                           G_CALLBACK (on_delete_activate), main_window); 
01002         
01003         
01004         /* about dialog box */          
01005         g_signal_connect (G_OBJECT(heraia_get_widget(main_window->xmls->main, "a_propos")), "activate",  
01006                                           G_CALLBACK(a_propos_activate), main_window); 
01007         
01008         g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "about_dialog")), "close",
01009                                          G_CALLBACK(a_propos_close), main_window);
01010         
01011         g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "about_dialog")), "response",
01012                                          G_CALLBACK(a_propos_response), main_window);
01013         
01014         g_signal_connect(G_OBJECT(heraia_get_widget(main_window->xmls->main, "about_dialog")), "delete-event",
01015                                          G_CALLBACK(a_propos_delete), main_window);
01016         
01017         
01018         /* main window killed or destroyed */
01019         g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "main_window")), "delete-event", 
01020                                           G_CALLBACK (delete_main_window_event), main_window);
01021         
01022         g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "main_window")), "response", 
01023                                           G_CALLBACK (delete_main_window_event), main_window);
01024         
01025         g_signal_connect (G_OBJECT (heraia_get_widget(main_window->xmls->main, "main_window")), "close", 
01026                                           G_CALLBACK (on_quit_activate), main_window);
01027 }
01028 
01029 /** @fn int load_heraia_ui(heraia_window_t *main_window)
01030  *  Loads, if possible, the glade xml file and then connects the
01031  *  signals and inits the following windows :
01032  *  - log window
01033  *  - data_interpretor window
01034  *  - list data types
01035  * @param main_window : main structure
01036  * @return TRUE if load_heraia_glade suceeded, FALSE otherwise
01037  * @todo add more return values to init functions to detect any error while
01038  *       initializing the ui
01039  */
01040 int load_heraia_ui(heraia_window_t *main_window)
01041 {
01042         gboolean success = FALSE;
01043         
01044         /* load the XML interfaces (main & treatment) */
01045         success = load_heraia_glade_xml(main_window);
01046         
01047         if (success == TRUE)
01048         {
01049                 /* Heraia UI signals */
01050                 if (main_window->debug == TRUE)
01051                 {
01052                         fprintf(stdout, "Connecting heraia_ui signals     ");
01053                 }
01054                 
01055                 heraia_ui_connect_signals(main_window);
01056                 
01057                 if (main_window->debug == TRUE)
01058                 {
01059                         fprintf(stdout, " [Done]\n");
01060                 }
01061         
01062                 fprintf(stdout, "Loading heraia preference file   ");
01063                 
01064                 if (load_preference_file(main_window) != TRUE)
01065                 {
01066                         fprintf(stdout, " [FAILED]\n");
01067                 }
01068                 else /* Setting up preferences */
01069                 {
01070                         fprintf(stdout, " [Done]\n");
01071                         fprintf(stdout, "Setting up preferences           ");
01072                         setup_preferences(main_window);
01073                         fprintf(stdout, " [Done]\n");
01074                 }
01075                 
01076                 /* The Log window */
01077                 if (main_window->debug == TRUE)
01078                 {
01079                         fprintf(stdout, "log window init interface        ");
01080                 }
01081                 
01082                 log_window_init_interface(main_window);
01083                 
01084                 if (main_window->debug == TRUE)
01085                 {
01086                         fprintf(stdout, " [Done]\n");
01087                 }
01088                 
01089                 /* Preferences window */
01090                 if (main_window->debug == TRUE)
01091                 {
01092                         fprintf(stdout, "preferences window init interface");
01093                 }
01094                 
01095                 main_pref_window_init_interface(main_window);
01096                 
01097                 if (main_window->debug == TRUE)
01098                 {
01099                         fprintf(stdout, " [Done]\n");
01100                 }
01101                 
01102                 
01103                 /* The data interpretor window */
01104                 if (main_window->debug == TRUE)
01105                 {
01106                         fprintf(stdout, "data interpretor init interface  ");
01107                 }
01108                 
01109                 data_interpretor_init_interface(main_window);
01110                 
01111                 if (main_window->debug == TRUE)
01112                 {
01113                         fprintf(stdout, " [Done]\n");
01114                 }
01115                 
01116                 
01117                 /* The list data types window */
01118                 if (main_window->debug == TRUE)
01119                 {
01120                         fprintf(stdout, "list data types init interface   ");
01121                 }
01122                 
01123                 list_data_types_init_interface(main_window);
01124                 
01125                 if (main_window->debug == TRUE)
01126                 {
01127                         fprintf(stdout, " [Done]\n");
01128                 }
01129                 
01130                 
01131                 /* The data type window (create or edit one type) */
01132                 if (main_window->debug == TRUE)
01133                 {
01134                         fprintf(stdout, "data type init interface         ");
01135                 }
01136                 
01137                 data_type_init_interface(main_window);
01138                 
01139                 if (main_window->debug == TRUE)
01140                 {
01141                         fprintf(stdout, " [Done]\n");
01142                 }
01143         }
01144         
01145         return success;
01146 }
01147 
01148 
01149 /**
01150  * @fn void add_text_to_textview(GtkTextView *textview, const char *format, ...)
01151  *  adds a text to a textview
01152  * @param textview : the textview where to add text
01153  * @param format : printf style format
01154  * @param ... : a va_list arguments to fit format (as with printf)
01155  */
01156 void add_text_to_textview(GtkTextView *textview, const char *format, ...)
01157 {       
01158         va_list args;
01159         GtkTextBuffer *tb = NULL;
01160         GtkTextIter iEnd;
01161         gchar *display = NULL;
01162         GError *err = NULL;
01163         
01164         va_start(args, format);
01165         display = g_locale_to_utf8(g_strdup_vprintf(format, args), -1, NULL, NULL, &err);
01166         va_end(args);
01167         
01168         tb = GTK_TEXT_BUFFER(gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)));
01169         gtk_text_buffer_get_end_iter(tb, &iEnd);
01170         gtk_text_buffer_insert(tb, &iEnd, display, -1);
01171         g_free(display);
01172 }
01173 
01174 
01175 /**
01176  * @fn kill_text_from_textview(GtkTextView *textview)
01177  *  Kills the text from a textview
01178  * @param textview : the textview to kill the text from
01179  */
01180 void kill_text_from_textview(GtkTextView *textview)
01181 {
01182         GtkTextBuffer *tb = NULL;
01183         GtkTextIter iStart;
01184         GtkTextIter iEnd;
01185         
01186         tb = GTK_TEXT_BUFFER(gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)));
01187         gtk_text_buffer_get_start_iter(tb, &iStart);
01188         gtk_text_buffer_get_end_iter(tb, &iEnd);
01189         gtk_text_buffer_delete (tb, &iStart, &iEnd);
01190 }
01191 
01192 
01193 /**
01194  * @fn GtkWidget *gtk_radio_button_get_active(GSList *group)
01195  *  Try to find the active radio button widget in a group
01196  *  This does not take into account inconsistant states
01197  *  returns the first active radio button otherwise NULL
01198  * @param group : A group of GtkRadioButtons
01199  * @return returns the active widget if any (NULL if none)
01200  */
01201 GtkWidget *gtk_radio_button_get_active(GSList *group)
01202 {
01203         GSList *tmp_slist = group;
01204         
01205         while (tmp_slist)
01206         {
01207                 if (GTK_TOGGLE_BUTTON (tmp_slist->data)->active)
01208                 {
01209                         return GTK_WIDGET (tmp_slist->data);
01210                 }
01211                 tmp_slist = tmp_slist->next;
01212         }
01213         
01214         return NULL;
01215 }
01216 
01217 
01218 /**
01219  * @fn GtkWidget *gtk_radio_button_get_active_from_widget(GtkRadioButton *radio_group_member)
01220  * gets the active radio button from a radio group
01221  * @param radio_group_member : widget to get radio group from
01222  * @returns the active GtkRadioButton within the group from
01223  *          radio_group_member
01224  **/
01225 GtkWidget *gtk_radio_button_get_active_from_widget(GtkRadioButton *radio_group_member)
01226 { 
01227         if (radio_group_member)
01228         {
01229                 return gtk_radio_button_get_active(radio_group_member->group);
01230         }
01231         else
01232         {
01233                 return NULL;
01234         }
01235 }
01236 
01237 
01238 /**
01239  * @fn gboolean is_cmi_checked(GtkWidget *check_menu_item)
01240  *  Tells whether a GtkCheckMenuItem is Checked or not
01241  * @param check_menu_item : a GtkCheckMenuItem to verify
01242  * @return returns TRUE if the Check Manu Item is checked, FALSE otherwise
01243  */
01244 gboolean is_cmi_checked(GtkWidget *check_menu_item)
01245 {
01246         return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(check_menu_item));
01247 }
01248 
01249 
01250 /**
01251  * @fn gboolean is_toggle_button_activated(GladeXML *main_xml, gchar *check_button)
01252  *  returns the state of a named check button contained 
01253  *  in the Glade XML description
01254  * @param main_xml : a GladeXML definition
01255  * @param check_button : the name of an existing check_button within the glade 
01256  *        definition
01257  * @return TRUE if the button is activated / toggled , FALSE otherwise
01258  */
01259 gboolean is_toggle_button_activated(GladeXML *main_xml, gchar *check_button)
01260 {
01261         gboolean activated = FALSE;
01262         
01263         if (main_xml != NULL)
01264         {
01265                 activated = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(heraia_get_widget(main_xml, check_button)));
01266         }
01267         
01268         return activated;
01269 }
01270 
01271 
01272 /**
01273  * @fn GtkWidget *heraia_get_widget(GladeXML *xml, gchar *widget_name)
01274  *  This is a wrapper to the glade xml get widget. It is intended
01275  *  to simplify the developpers lives if they have to choose or
01276  *  propose other means to do the same thing than libglade (say,
01277  *  for example, GtkBuilder :)
01278  * @param xml : A glade XML definition 
01279  * @param widget_name : an existing widget name in the glade definition
01280  * @return returns the widget itself if it exists in the definition file (NULL
01281  *         otherwise)
01282  */
01283 GtkWidget *heraia_get_widget(GladeXML *xml, gchar *widget_name)
01284 {
01285    /** 
01286         * For debug purposes only (very verbose as this function is the main used)
01287         * fprintf(stdout, "Getting Widget named %s\n", widget_name); 
01288         */
01289         
01290         if (xml != NULL && widget_name != NULL)
01291         {
01292                 return glade_xml_get_widget(xml, widget_name);
01293         }
01294         else
01295         {
01296                 return NULL;
01297         }
01298 }
01299 
01300 
01301 /**
01302  * @fn void destroy_a_single_widget(GtkWidget *widget)
01303  *  Destroys a single widget if it exists
01304  * @param widget : the widget to destroy
01305  */
01306 void destroy_a_single_widget(GtkWidget *widget)
01307 {
01308         if (widget != NULL)
01309         {
01310                 gtk_widget_destroy(widget);
01311         }
01312 }
01313 
01314 /**
01315  * @fn void close_heraia(heraia_window_t *main_window)
01316  * Before closing heraia we need to do few things
01317  * @param main_window : main_struct
01318  */
01319 static void close_heraia(heraia_window_t *main_window)
01320 {
01321 
01322         /* recording window's position */
01323         record_all_dialog_box_positions(main_window);
01324         
01325         /* . Saving preferences */
01326         save_main_preferences(main_window);
01327 }
01328 
01329 /**
01330  * @fn void init_one_cmi_window_state(GtkWidget *dialog_box, GtkWidget *cmi, window_prop_t *dialog_prop)
01331  * init one cmi window based state
01332  * @param dialog_box : the window or dialog box we want to init its state
01333  * @param cmi : corresponding check menu item 
01334  * @param dialog_prop : corresponding window properties (should be initialized and not NULL)
01335  */
01336 static void init_one_cmi_window_state(GtkWidget *dialog_box, GtkWidget *cmi, window_prop_t *dialog_prop)
01337 {
01338         gboolean activated = FALSE;
01339         
01340         if (dialog_box != NULL && cmi != NULL && dialog_prop != NULL)
01341         {
01342                 activated = dialog_prop->displayed;
01343                 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(cmi), activated);
01344                 if (activated == TRUE)
01345                 {
01346                         /* fprintf(stdout, "x: %d\t y: %d\n", dialog_prop->x, dialog_prop->y); */
01347                         gtk_window_move(GTK_WINDOW(dialog_box), dialog_prop->x, dialog_prop->y);
01348                         gtk_widget_show_all(dialog_box);
01349                 }
01350         }
01351 }
01352 
01353 
01354 /**
01355  * @fn init_window_states(heraia_window_t *main_window)
01356  *  Inits all windows states (positions, displayed, and so on...)
01357  * @param main_window : main structure
01358  */
01359 void init_window_states(heraia_window_t *main_window)
01360 {
01361         GtkWidget *cmi = NULL;
01362         GtkWidget *dialog_box = NULL;
01363         
01364         if (main_window != NULL && main_window->xmls != NULL  && main_window->xmls->main != NULL)
01365         {
01366                 if (main_window->win_prop)
01367                 {
01368                         /* Main window (always the first one) */
01369                         dialog_box = heraia_get_widget(main_window->xmls->main, "main_window");
01370                         if (main_window->win_prop->main_dialog->displayed == TRUE)
01371                         {
01372                                 gtk_window_move(GTK_WINDOW(dialog_box), main_window->win_prop->main_dialog->x, main_window->win_prop->main_dialog->y);
01373                                 gtk_widget_show(dialog_box);
01374                         }
01375                         
01376                         /* Log Window Interface */
01377                         cmi = heraia_get_widget(main_window->xmls->main, "mw_cmi_show_logw");
01378                         dialog_box = heraia_get_widget(main_window->xmls->main, "log_window");
01379                         init_one_cmi_window_state(dialog_box, cmi, main_window->win_prop->log_box);
01380                         
01381                         /* Data Interpretor Interface */
01382                         cmi = heraia_get_widget(main_window->xmls->main, "DIMenu");
01383                         /* Emit the specific signal to activate the check_menu_item */
01384                         if (main_window->win_prop->data_interpretor->displayed == TRUE)
01385                         {
01386                                 main_window->win_prop->data_interpretor->displayed = FALSE; /* dirty trick */
01387                                 g_signal_emit_by_name(heraia_get_widget(main_window->xmls->main, "DIMenu"), "activate");
01388                         }
01389                 
01390                         /* List Data type Interface */
01391                         cmi = heraia_get_widget(main_window->xmls->main, "ldt_menu");
01392                         dialog_box = heraia_get_widget(main_window->xmls->main, "list_data_types_window");
01393                         init_one_cmi_window_state(dialog_box, cmi, main_window->win_prop->ldt);
01394                         
01395                         /* Plugin List Interface */
01396                         cmi = heraia_get_widget(main_window->xmls->main, "mw_cmi_plugin_list");
01397                         dialog_box = heraia_get_widget(main_window->xmls->main, "plugin_list_window");
01398                         init_one_cmi_window_state(dialog_box, cmi, main_window->win_prop->plugin_list);         
01399                         
01400                         /* Preferences window */
01401                         dialog_box = heraia_get_widget(main_window->xmls->main, "main_preferences_window");
01402                         if (main_window->win_prop->main_pref_window->displayed == TRUE)
01403                         {
01404                                 /* main_window->win_prop->main_pref_window->displayed = FALSE; dirty trick */
01405                                 gtk_window_move(GTK_WINDOW(dialog_box), main_window->win_prop->main_pref_window->x, main_window->win_prop->main_pref_window->y);
01406                                 gtk_widget_show_all(dialog_box);
01407                         }
01408                         
01409                         /* About Box */
01410                         dialog_box = heraia_get_widget(main_window->xmls->main, "about_dialog");
01411                         if (main_window->win_prop->about_box->displayed == TRUE)
01412                         {
01413                                 /* main_window->win_prop->main_pref_window->displayed = FALSE; dirty trick */
01414                                 gtk_window_move(GTK_WINDOW(dialog_box), main_window->win_prop->about_box->x, main_window->win_prop->about_box->y); 
01415                                 set_a_propos_properties(dialog_box);
01416                                 gtk_widget_show_all(dialog_box);
01417                         }
01418                 }
01419         }
01420 }

Generated on Sat Feb 14 11:44:16 2009 for Heraia by  doxygen 1.5.6