user_prefs.c

Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
00002 /*
00003  *  user_prefs.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 /**
00025  * @file user_prefs.c
00026  * Users preference may be somewhere around here
00027  */
00028 #include <libheraia.h>
00029 
00030 /* Verifying */
00031 static void verify_preference_file_path_presence(gchar *pathname);
00032 static void verify_preference_file_name_presence(gchar *filename);
00033 
00034 /* Saving */
00035 static void save_window_preferences(GKeyFile *file, gchar *name, window_prop_t *window_prop);
00036 
00037 static void save_mp_file_preferences_options(heraia_struct_t *main_struct, prefs_t *prefs);
00038 static void save_mp_display_preferences_options(heraia_struct_t *main_struct, prefs_t *prefs);
00039 static void save_mp_files_filenames(heraia_struct_t *main_struct, prefs_t *prefs);
00040 
00041 static void save_di_preferences(heraia_struct_t *main_struct, prefs_t *prefs);
00042 
00043 static void save_mpwp_preferences(heraia_struct_t *main_struct, prefs_t *prefs);
00044 
00045 /* Loading */
00046 static void load_window_preferences(GKeyFile *file, gchar *name, window_prop_t *window_prop);
00047 
00048 static void load_mp_file_preferences_options(heraia_struct_t *main_struct, prefs_t *prefs);
00049 static void load_mp_display_preferences_options(heraia_struct_t *main_struct, prefs_t *prefs);
00050 static void load_mp_files_filenames(heraia_struct_t *main_struct, prefs_t *prefs);
00051 
00052 static void load_di_preferences(heraia_struct_t *main_struct, prefs_t *prefs);
00053 
00054 static void load_mpwp_preferences(heraia_struct_t *main_struct, prefs_t *prefs);
00055 
00056 
00057 /**
00058  *  verify preference file path presence and creates it if it does
00059  *  not already exists
00060  *  @param pathname is a path to look presence for
00061  */
00062 static void verify_preference_file_path_presence(gchar *pathname)
00063 {
00064     struct stat *buf = NULL;
00065     gint result = 0;
00066 
00067     buf = (struct stat *) g_malloc0(sizeof(struct stat));
00068     result = g_stat(pathname, buf);
00069 
00070     if (result != 0)
00071         {
00072             g_mkdir_with_parents(pathname, 488);
00073         }
00074 }
00075 
00076 
00077 /**
00078  *  Verify preference file's presence and creates it if it does
00079  *  not exists already
00080  *  @param filename is a name of a file to look presence for
00081  */
00082 static void verify_preference_file_name_presence(gchar *filename)
00083 {
00084     FILE *fp = NULL;
00085 
00086     fp = g_fopen(filename, "r");
00087 
00088     if (fp == NULL)
00089         {
00090             fp = g_fopen(filename, "w");
00091             if (fp == NULL)
00092                 {
00093                     fprintf(stderr, Q_("Unable to open and create the main preference file %s\n"), filename);
00094                 }
00095             else
00096                 {
00097                     fprintf(stderr, Q_("Main preference file %s created successfully\n"), filename);
00098                     fclose(fp);
00099                 }
00100         }
00101     else
00102         {
00103             fclose(fp);
00104         }
00105 }
00106 
00107 
00108 /**
00109  *  Verify preference file presence and creates it if it does not
00110  *  already exists.
00111  * @param prefs is a 'prefs_t *' filled preference structure
00112  */
00113 void verify_preference_file(prefs_t *prefs)
00114 {
00115     if (prefs != NULL)
00116         {
00117             verify_preference_file_path_presence(prefs->pathname);
00118             verify_preference_file_name_presence(prefs->filename);
00119         }
00120 }
00121 
00122 
00123 /**
00124  * Look out if the preference structure exists or not. If not
00125  * it creates it.
00126  * @see http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
00127  * @param pathname is the pathname where the preference file is
00128  * @param filename is the filename of the preference file itself
00129  */
00130 prefs_t *init_preference_struct(gchar *pathname, gchar *filename)
00131 {
00132     prefs_t *prefs = NULL;
00133 
00134     prefs = (prefs_t *) g_malloc0(sizeof(prefs_t));
00135 
00136     prefs->file = g_key_file_new();
00137     prefs->pathname = pathname;
00138     prefs->filename = g_build_filename(prefs->pathname, filename, NULL);
00139 
00140     return prefs;
00141 }
00142 
00143 
00144 /**
00145  * Destroys a preference structure
00146  * @param prefs the preference structure to be freed
00147  */
00148 void free_preference_struct(prefs_t *prefs)
00149 {
00150     if (prefs != NULL)
00151         {
00152             g_free(prefs->filename);
00153             g_free(prefs->pathname);
00154             g_key_file_free(prefs->file);
00155         }
00156 }
00157 
00158 
00159 /**
00160  *  Window preferences
00161  *  @param file a GKeyFile where values are stored
00162  *  @param name a keyname (basically a window name)
00163  *  @param window_prop all window properties to save (structure window_prop_t)
00164  */
00165 static void save_window_preferences(GKeyFile *file, gchar *name, window_prop_t *window_prop)
00166 {
00167     gchar *keyname = NULL;
00168 
00169     keyname = g_strconcat(name, " Displayed", NULL);
00170     g_key_file_set_boolean(file, GN_GLOBAL_PREFS, keyname, window_prop->displayed);
00171     g_free(keyname);
00172 
00173     keyname = g_strconcat(name, " X_pos", NULL);
00174     g_key_file_set_integer(file, GN_GLOBAL_PREFS, keyname, window_prop->x);
00175     g_free(keyname);
00176 
00177     keyname = g_strconcat(name, " Y_pos", NULL);
00178     g_key_file_set_integer(file, GN_GLOBAL_PREFS, keyname, window_prop->y);
00179     g_free(keyname);
00180 
00181     keyname = g_strconcat(name, " Height", NULL);
00182     g_key_file_set_integer(file, GN_GLOBAL_PREFS, keyname, window_prop->height);
00183     g_free(keyname);
00184 
00185     keyname = g_strconcat(name, " Width", NULL);
00186     g_key_file_set_integer(file, GN_GLOBAL_PREFS, keyname, window_prop->width);
00187     g_free(keyname);
00188 }
00189 
00190 
00191 /**
00192  * Save only file preferences related options
00193  * @param main_struct the main structure
00194  * @param prefs is a 'prefs_t *' filled preference structure
00195  */
00196 static void save_mp_file_preferences_options(heraia_struct_t *main_struct, prefs_t *prefs)
00197 {
00198     gboolean activated = FALSE;
00199 
00200 
00201     if (main_struct != NULL && prefs != NULL)
00202         {
00203             /* Saves the position */
00204             activated = is_toggle_button_activated(main_struct->xmls->main, "save_window_position_bt");
00205             g_key_file_set_boolean(prefs->file, GN_GLOBAL_PREFS, KN_SAVE_WINDOW_PREFS, activated);
00206 
00207             /* Saving all window preferences if necessary */
00208             if (activated == TRUE)
00209                 {
00210                     save_window_preferences(prefs->file, KN_ABOUT_BOX, main_struct->win_prop->about_box);
00211                     save_window_preferences(prefs->file, KN_DATA_INTERPRETOR, main_struct->win_prop->data_interpretor);
00212                     save_window_preferences(prefs->file, KN_LOG_BOX, main_struct->win_prop->log_box);
00213                     save_window_preferences(prefs->file, KN_MAIN_DIALOG, main_struct->win_prop->main_dialog);
00214                     save_window_preferences(prefs->file, KN_PLUGIN_LIST, main_struct->win_prop->plugin_list);
00215                     save_window_preferences(prefs->file, KN_LDT, main_struct->win_prop->ldt);
00216                     save_window_preferences(prefs->file, KN_MAIN_PREFS, main_struct->win_prop->main_pref_window);
00217                     save_window_preferences(prefs->file, KN_GOTO_DIALOG, main_struct->win_prop->goto_window);
00218                     save_window_preferences(prefs->file, KN_RESULT_WINDOW, main_struct->win_prop->result_window);
00219                     save_window_preferences(prefs->file, KN_FIND_WINDOW, main_struct->win_prop->find_window);
00220                     save_window_preferences(prefs->file, KN_FR_WINDOW, main_struct->win_prop->fr_window);
00221                     save_window_preferences(prefs->file, KN_FDFT_WINDOW, main_struct->win_prop->fdft_window);
00222                 }
00223 
00224             /* Saving opened files filenames ? */
00225             activated = is_toggle_button_activated(main_struct->xmls->main, "save_filenames_bt");
00226             g_key_file_set_boolean(prefs->file, GN_GLOBAL_PREFS, KN_SAVE_OPENED_FILES_FILENAMES, activated);
00227 
00228             if (activated == TRUE)
00229                 {
00230                     save_mp_files_filenames(main_struct, prefs);
00231                 }
00232         }
00233 }
00234 
00235 /**
00236  * Saves files filenames to the config file
00237  * @param main_struct the main structure
00238  * @param prefs preference structure
00239  */
00240 static void save_mp_files_filenames(heraia_struct_t *main_struct, prefs_t *prefs)
00241 {
00242     const gchar **list = NULL;  /**< A list that will contain all the files filenames            */
00243     gchar *filename = NULL;     /**< One filename                                                */
00244     gint *pos_list = NULL;   /**< list of the current position of the cursor in the documents */
00245     gsize i = 0;
00246     gsize len = 0;
00247     gsize j = 0;
00248     gint current_tab = 0;       /**< Current selected tab in the main notebook                   */
00249     doc_t *document = NULL;     /**< One document (from the documents array in the main_struct   */
00250     GtkWidget *notebook = NULL; /**< Main notebook in the file view in the main window           */
00251 
00252     if (main_struct != NULL && prefs != NULL)
00253         {
00254             /* First initializing the list variable with the filenames of the opened documents */
00255             i = 0;
00256             j = 0;
00257             len = main_struct->documents->len;
00258             list = (const gchar **) g_malloc0 (sizeof(gchar *)*len);
00259             pos_list = (gint *) g_malloc0 (sizeof(gint)*len);
00260 
00261             while (i < len)
00262                 {
00263                     document = g_ptr_array_index(main_struct->documents, i);
00264 
00265                     if (document != NULL)
00266                         {
00267                             filename = g_strdup(doc_t_document_get_filename(document));
00268                             /* There will be some limitations here due to the guint64 to gint cast */
00269                             pos_list[j] = (gint) ghex_get_cursor_position(document->hex_widget);
00270                             list[j] = filename;
00271                             j++;
00272                         }
00273                     i++;
00274                 }
00275 
00276             /* Saving them to the preference file */
00277             g_key_file_set_string_list(prefs->file, GN_GLOBAL_PREFS, KN_FILES_FILENAMES, list, j);
00278             g_key_file_set_integer_list(prefs->file, GN_GLOBAL_PREFS, KN_FILES_CURSOR_POSITIONS, pos_list, j);
00279 
00280             /* saving current tab */
00281             notebook = heraia_get_widget(main_struct->xmls->main, "file_notebook");
00282             current_tab = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
00283             g_key_file_set_integer(prefs->file, GN_GLOBAL_PREFS, KN_CURRENT_TAB, current_tab);
00284         }
00285 }
00286 
00287 
00288 /**
00289  * Save only display related preferences
00290  * @param main_struct : main structure
00291  * @param prefs is a 'prefs_t *' filled preference structure
00292  */
00293 static void save_mp_display_preferences_options(heraia_struct_t *main_struct, prefs_t *prefs)
00294 {
00295     gboolean activated = FALSE;
00296 
00297     if (main_struct != NULL && prefs != NULL)
00298         {
00299             /* Display Thousand (or not) */
00300             activated = is_toggle_button_activated(main_struct->xmls->main, "mp_thousand_bt");
00301             g_key_file_set_boolean(prefs->file, GN_DISPLAY_PREFS, KN_DISP_THOUSAND, activated);
00302 
00303             /* Display offsets (or not) */
00304             activated = is_toggle_button_activated(main_struct->xmls->main, "mp_display_offset_bt");
00305             g_key_file_set_boolean(prefs->file, GN_DISPLAY_PREFS, KN_DISP_OFFSETS, activated);
00306         }
00307 }
00308 
00309 
00310 /**
00311  * Saves data interpretor state and preferences
00312  * @param main_struct : main structure
00313  * @param prefs is a 'prefs_t *' filled preference structure
00314  */
00315 static void save_di_preferences(heraia_struct_t *main_struct, prefs_t *prefs)
00316 {
00317     gint selected_tab = -1; /**< Selected tab in data interpretor's window */
00318     gint stream_size = -1;  /**< Stream size in data interpretor's window  */
00319     gint endianness = -1;   /**< Endianness in data interpretor's window   */
00320 
00321     if (main_struct != NULL && main_struct->current_DW != NULL && prefs != NULL)
00322         {
00323             selected_tab = di_get_selected_tab(main_struct);
00324             if (selected_tab >= 0)
00325                 {
00326                     g_key_file_set_integer(prefs->file, GN_DI_PREFS, KN_DI_SELECTED_TAB, selected_tab);
00327                 }
00328 
00329             stream_size = di_get_stream_size(main_struct);
00330             if (stream_size >= 0)
00331                 {
00332                     g_key_file_set_integer(prefs->file, GN_DI_PREFS, KN_DI_STREAM_SIZE, stream_size);
00333                 }
00334 
00335             endianness = di_get_endianness(main_struct);
00336             if (endianness >= 0)
00337                 {
00338                      g_key_file_set_integer(prefs->file, GN_DI_PREFS, KN_DI_ENDIANNESS, endianness);
00339                 }
00340         }
00341 }
00342 
00343 
00344 /**
00345  * Saves main preferences window state and preferences
00346  * @param main_struct : main structure
00347  * @param prefs is a 'prefs_t *' filled preference structure
00348  */
00349 static void save_mpwp_preferences(heraia_struct_t *main_struct, prefs_t *prefs)
00350 {
00351     GtkNotebook *notebook = NULL; /**< main preferences's notebook               */
00352     gint selected_tab = -1;       /**< Selected tab in data interpretor's window */
00353 
00354     if (main_struct != NULL && main_struct->current_DW != NULL && prefs != NULL)
00355         {
00356             notebook = GTK_NOTEBOOK(heraia_get_widget(main_struct->xmls->main, "mp_first_notebook"));
00357 
00358             if (notebook != NULL)
00359                 {
00360                     selected_tab = gtk_notebook_get_current_page(notebook);
00361 
00362                     if (selected_tab >= 0)
00363                         {
00364                             g_key_file_set_integer(prefs->file, GN_MPWP_PREFS, KN_MPWP_SELECTED_TAB, selected_tab);
00365                         }
00366                 }
00367         }
00368 }
00369 
00370 
00371 /**
00372  * Save all preferences to the user preference file
00373  * @param main_struct the main structure
00374  * @param prefs is a 'prefs_t *' filled preference structure
00375  */
00376 void save_preferences(heraia_struct_t *main_struct, prefs_t *prefs)
00377 {
00378     if (main_struct != NULL && prefs != NULL)
00379         {
00380             /* 1. Saving main Preferences */
00381             save_mp_file_preferences_options(main_struct, prefs);
00382 
00383             /* 2. Saving Display Preferences */
00384             save_mp_display_preferences_options(main_struct, prefs);
00385 
00386             /* 3. Saving Data Interpretor Preferences */
00387             save_di_preferences(main_struct, prefs);
00388 
00389             /* 4. Saving Main Preferences Window Preferences */
00390             save_mpwp_preferences(main_struct, prefs);
00391 
00392             /* 5. Saving to file */
00393             save_preferences_to_file(prefs);
00394         }
00395 }
00396 
00397 
00398 /**
00399  *  Window preferences
00400  *  @param file a GKeyFile where values are stored
00401  *  @param name a keyname (basically a window name)
00402  *  @param window_prop all window properties to save (structure window_prop_t)
00403  */
00404 static void load_window_preferences(GKeyFile *file, gchar *name, window_prop_t *window_prop)
00405 {
00406     gchar *keyname = NULL;
00407 
00408     keyname = g_strconcat(name, " Displayed", NULL);
00409     window_prop->displayed = g_key_file_get_boolean(file, GN_GLOBAL_PREFS, keyname, NULL);
00410     g_free(keyname);
00411 
00412     keyname = g_strconcat(name, " X_pos", NULL);
00413     window_prop->x = g_key_file_get_integer(file, GN_GLOBAL_PREFS, keyname, NULL);
00414     g_free(keyname);
00415 
00416     keyname = g_strconcat(name, " Y_pos", NULL);
00417     window_prop->y = g_key_file_get_integer(file, GN_GLOBAL_PREFS, keyname, NULL);
00418     g_free(keyname);
00419 
00420     keyname = g_strconcat(name, " Height", NULL);
00421     window_prop->height = g_key_file_get_integer(file, GN_GLOBAL_PREFS, keyname, NULL);
00422     g_free(keyname);
00423 
00424     keyname = g_strconcat(name, " Width", NULL);
00425     window_prop->width = g_key_file_get_integer(file, GN_GLOBAL_PREFS, keyname, NULL);
00426     g_free(keyname);
00427 
00428 }
00429 
00430 
00431 /**
00432  * Load only main preferences related options
00433  * @param main_struct the main structure
00434  * @param prefs is a 'prefs_t *' filled preference structure
00435  */
00436 static void load_mp_file_preferences_options(heraia_struct_t *main_struct, prefs_t *prefs)
00437 {
00438     GtkWidget *save_window_position_bt = NULL;
00439     GtkWidget *save_filenames_bt = NULL;
00440     gboolean activated = FALSE;
00441 
00442     if (main_struct != NULL && prefs != NULL)
00443         {
00444             log_message(main_struct, G_LOG_LEVEL_DEBUG, Q_("Loading window's positions"));
00445             /* Loading window's positions ? */
00446             activated = g_key_file_get_boolean(prefs->file, GN_GLOBAL_PREFS, KN_SAVE_WINDOW_PREFS, NULL);
00447             save_window_position_bt = heraia_get_widget(main_struct->xmls->main, "save_window_position_bt");
00448             gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(save_window_position_bt), activated);
00449 
00450             if (activated == TRUE)
00451                 {
00452                     /* window's positions */
00453                     load_window_preferences(prefs->file, KN_ABOUT_BOX, main_struct->win_prop->about_box);
00454                     load_window_preferences(prefs->file, KN_DATA_INTERPRETOR, main_struct->win_prop->data_interpretor);
00455                     load_window_preferences(prefs->file, KN_LOG_BOX, main_struct->win_prop->log_box);
00456                     load_window_preferences(prefs->file, KN_MAIN_DIALOG, main_struct->win_prop->main_dialog);
00457                     load_window_preferences(prefs->file, KN_PLUGIN_LIST, main_struct->win_prop->plugin_list);
00458                     load_window_preferences(prefs->file, KN_LDT, main_struct->win_prop->ldt);
00459                     load_window_preferences(prefs->file, KN_MAIN_PREFS, main_struct->win_prop->main_pref_window);
00460                     load_window_preferences(prefs->file, KN_GOTO_DIALOG, main_struct->win_prop->goto_window);
00461                     load_window_preferences(prefs->file, KN_RESULT_WINDOW, main_struct->win_prop->result_window);
00462                     load_window_preferences(prefs->file, KN_FIND_WINDOW, main_struct->win_prop->find_window);
00463                     load_window_preferences(prefs->file, KN_FR_WINDOW, main_struct->win_prop->fr_window);
00464                     load_window_preferences(prefs->file, KN_FDFT_WINDOW, main_struct->win_prop->fdft_window);
00465                 }
00466 
00467             /* Loading opened files filenames ? */
00468             activated = g_key_file_get_boolean(prefs->file, GN_GLOBAL_PREFS, KN_SAVE_OPENED_FILES_FILENAMES, NULL);
00469             save_filenames_bt = heraia_get_widget(main_struct->xmls->main, "save_filenames_bt");
00470             gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(save_filenames_bt), activated);
00471 
00472             if (activated == TRUE)
00473                 {
00474                     log_message(main_struct, G_LOG_LEVEL_DEBUG, Q_("Loading files..."));
00475                     load_mp_files_filenames(main_struct, prefs);
00476                 }
00477         }
00478 }
00479 
00480 
00481 /**
00482  * Load files filenames from the config file
00483  * @param main_struct the main structure
00484  * @param prefs preference structure
00485  */
00486 static void load_mp_files_filenames(heraia_struct_t *main_struct, prefs_t *prefs)
00487 {
00488     gchar **list = NULL;      /**< The list that will contain all filenames to be loaded       */
00489     gint *pos_list = NULL;    /**< list of the current position of the cursor in the documents */
00490     gsize i = 0;
00491     gsize len = 0;
00492     gsize pos_len = 0;
00493     gint current_tab = 0;
00494     GtkWidget *notebook = NULL;
00495 
00496     if (main_struct != NULL && prefs != NULL)
00497         {
00498             /* get file list */
00499             list = g_key_file_get_string_list(prefs->file, GN_GLOBAL_PREFS, KN_FILES_FILENAMES, &len, NULL);
00500             pos_list = (gint *) g_key_file_get_integer_list(prefs->file, GN_GLOBAL_PREFS, KN_FILES_CURSOR_POSITIONS, &pos_len, NULL);
00501 
00502             if (len == pos_len)
00503                 {
00504                     for (i = 0; i < len; i++)
00505                         {
00506                             if (load_file_to_analyse(main_struct, list[i]))
00507                                 {
00508                                     /* in add_new_tab_in_main_window() function, the newly */
00509                                     /* opened document becomes the current one             */
00510                                     /* There is some limitations here due to the cast from */
00511                                     /* gint to guint64                                     */
00512                                     ghex_set_cursor_position(main_struct->current_doc->hex_widget, (guint64) pos_list[i]);
00513                                 }
00514                         }
00515                 }
00516 
00517             /* get current tab */
00518             current_tab = g_key_file_get_integer(prefs->file, GN_GLOBAL_PREFS, KN_CURRENT_TAB, NULL);
00519             notebook = heraia_get_widget(main_struct->xmls->main, "file_notebook");
00520             gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), current_tab);
00521         }
00522 }
00523 
00524 
00525 /**
00526  *  Load display related preferences
00527  * @param main_struct the main structure
00528  * @param prefs is a 'prefs_t *' filled preference structure
00529  */
00530 static void load_mp_display_preferences_options(heraia_struct_t *main_struct, prefs_t *prefs)
00531 {
00532     GtkWidget *toggle_button = NULL;
00533     gboolean activated = FALSE;
00534 
00535     if (main_struct != NULL && prefs != NULL)
00536         {
00537             /* Display thousands (or not) */
00538             activated = g_key_file_get_boolean(prefs->file, GN_DISPLAY_PREFS, KN_DISP_THOUSAND, NULL);
00539             toggle_button = heraia_get_widget(main_struct->xmls->main, "mp_thousand_bt");
00540             gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_button), activated);
00541 
00542             /* Display offsets (or not) */
00543             activated = g_key_file_get_boolean(prefs->file, GN_DISPLAY_PREFS, KN_DISP_OFFSETS, NULL);
00544             toggle_button = heraia_get_widget(main_struct->xmls->main, "mp_display_offset_bt");
00545             gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_button), activated);
00546         }
00547 }
00548 
00549 
00550 /**
00551  * Load data interpretor state and preferences
00552  * @param main_struct : main structure
00553  * @param prefs is a 'prefs_t *' filled preference structure
00554  */
00555 static void load_di_preferences(heraia_struct_t *main_struct, prefs_t *prefs)
00556 {
00557     gint selected_tab = -1;   /**< Selected tab in data interpretor's window */
00558     gint stream_size = -1;    /**< Stream size in data interpretor's window  */
00559     gint endianness = -1;     /**< Endianness in data interpretor's window   */
00560 
00561     if (main_struct != NULL && main_struct->current_DW != NULL && main_struct->xmls != NULL && main_struct->xmls->main != NULL && prefs != NULL)
00562         {
00563             selected_tab = g_key_file_get_integer(prefs->file, GN_DI_PREFS, KN_DI_SELECTED_TAB, NULL);
00564             stream_size = g_key_file_get_integer(prefs->file, GN_DI_PREFS, KN_DI_STREAM_SIZE, NULL);
00565             endianness = g_key_file_get_integer(prefs->file, GN_DI_PREFS, KN_DI_ENDIANNESS, NULL);
00566 
00567             di_set_selected_tab(main_struct, selected_tab);
00568             di_set_stream_size(main_struct, stream_size);
00569             di_set_endianness(main_struct, endianness);
00570         }
00571 }
00572 
00573 
00574 /**
00575  * Load main preferences window state and preferences
00576  * @param main_struct : main structure
00577  * @param prefs is a 'prefs_t *' filled preference structure
00578  */
00579 static void load_mpwp_preferences(heraia_struct_t *main_struct, prefs_t *prefs)
00580 {
00581     GtkNotebook *notebook = NULL;  /**< main preferences's notebook               */
00582     GtkWidget *button = NULL;      /**< tool button from the toolbar              */
00583     gint selected_tab;             /**< Selected tab in data interpretor's window */
00584 
00585     if (main_struct != NULL && main_struct->current_DW != NULL && main_struct->xmls != NULL && main_struct->xmls->main != NULL && prefs != NULL)
00586         {
00587             notebook = GTK_NOTEBOOK(heraia_get_widget(main_struct->xmls->main, "mp_first_notebook"));
00588 
00589             if (notebook != NULL)
00590                 {
00591                     selected_tab = g_key_file_get_integer(prefs->file, GN_MPWP_PREFS, KN_MPWP_SELECTED_TAB, NULL);
00592 
00593                     switch (selected_tab)
00594                         {
00595                             case 0:
00596                                 gtk_notebook_set_current_page(notebook, selected_tab);
00597                                 button = heraia_get_widget(main_struct->xmls->main, "mp_tb_fp_bt");
00598                                 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(button), TRUE);
00599                                 break;
00600 
00601                             case 1:
00602                                 gtk_notebook_set_current_page(notebook, selected_tab);
00603                                 button = heraia_get_widget(main_struct->xmls->main, "mp_tb_display_bt");
00604                                 gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(button), TRUE);
00605                                 break;
00606 
00607                             default:
00608                             break;
00609                         }
00610                 }
00611         }
00612 }
00613 
00614 
00615 /**
00616  * Sets up the preferences as loaded in the preference file
00617  * @param main_struct the main structure
00618  * @param prefs is a 'prefs_t *' filled preference structure
00619  */
00620 void load_preferences(heraia_struct_t *main_struct, prefs_t *prefs)
00621 {
00622     if (main_struct != NULL && prefs != NULL)
00623         {
00624             /* 0. Loading preferences from file */
00625             if (load_preference_file(prefs) == TRUE)
00626                 {
00627                     /* 1. Loading Main Preferences */
00628                     log_message(main_struct, G_LOG_LEVEL_DEBUG, Q_("Loading main preferences"));
00629                     load_mp_file_preferences_options(main_struct, prefs);
00630 
00631                     /* 2. Loading Display preferences */
00632                     log_message(main_struct, G_LOG_LEVEL_DEBUG, Q_("Loading main display preferences"));
00633                     load_mp_display_preferences_options(main_struct, prefs);
00634 
00635                     /* 3. Loading Data Interpretor Preferences */
00636                     log_message(main_struct, G_LOG_LEVEL_DEBUG, Q_("Loading data interpretor preferences"));
00637                     load_di_preferences(main_struct, prefs);
00638 
00639                     /* 4. Loading Main Preferences Window Preferences */
00640                     log_message(main_struct, G_LOG_LEVEL_DEBUG, Q_("Loading window preference's main preferences"));
00641                     load_mpwp_preferences(main_struct, prefs);
00642                 }
00643         }
00644 }
Generated on Mon May 2 21:04:49 2011 for Heraia by  doxygen 1.6.3