Heraia  0.1.8
user_prefs.c
Go to the documentation of this file.
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /*
3  * user_prefs.c
4  * heraia - an hexadecimal file editor and analyser based on ghex
5  *
6  * (C) Copyright 2005 - 2011 Olivier Delhomme
7  * e-mail : heraia@delhomme.org
8  * URL : http://heraia.tuxfamily.org
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2, or (at your option)
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23  */
24 /**
25  * @file user_prefs.c
26  * Users preference may be somewhere around here
27  */
28 #include <libheraia.h>
29 
30 /* Verifying */
31 static void verify_preference_file_path_presence(gchar *pathname);
32 static void verify_preference_file_name_presence(gchar *filename);
33 
34 /* Saving */
35 static void save_window_preferences(GKeyFile *file, gchar *name, window_prop_t *window_prop);
36 
37 static void save_mp_file_preferences_options(heraia_struct_t *main_struct, prefs_t *prefs);
38 static void save_mp_display_preferences_options(heraia_struct_t *main_struct, prefs_t *prefs);
39 static void save_mp_files_filenames(heraia_struct_t *main_struct, prefs_t *prefs);
40 
41 static void save_di_preferences(heraia_struct_t *main_struct, prefs_t *prefs);
42 
43 static void save_mpwp_preferences(heraia_struct_t *main_struct, prefs_t *prefs);
44 
45 /* Loading */
46 static void load_window_preferences(GKeyFile *file, gchar *name, window_prop_t *window_prop);
47 
48 static void load_mp_file_preferences_options(heraia_struct_t *main_struct, prefs_t *prefs);
49 static void load_mp_display_preferences_options(heraia_struct_t *main_struct, prefs_t *prefs);
50 static void load_mp_files_filenames(heraia_struct_t *main_struct, prefs_t *prefs);
51 
52 static void load_di_preferences(heraia_struct_t *main_struct, prefs_t *prefs);
53 
54 static void load_mpwp_preferences(heraia_struct_t *main_struct, prefs_t *prefs);
55 
56 
57 /**
58  * verify preference file path presence and creates it if it does
59  * not already exists
60  * @param pathname is a path to look presence for
61  */
62 static void verify_preference_file_path_presence(gchar *pathname)
63 {
64  struct stat *buf = NULL;
65  gint result = 0;
66 
67  buf = (struct stat *) g_malloc0(sizeof(struct stat));
68  result = g_stat(pathname, buf);
69 
70  if (result != 0)
71  {
72  g_mkdir_with_parents(pathname, 488);
73  }
74 }
75 
76 
77 /**
78  * Verify preference file's presence and creates it if it does
79  * not exists already
80  * @param filename is a name of a file to look presence for
81  */
82 static void verify_preference_file_name_presence(gchar *filename)
83 {
84  FILE *fp = NULL;
85 
86  fp = g_fopen(filename, "r");
87 
88  if (fp == NULL)
89  {
90  fp = g_fopen(filename, "w");
91  if (fp == NULL)
92  {
93  fprintf(stderr, Q_("Unable to open and create the main preference file %s\n"), filename);
94  }
95  else
96  {
97  fprintf(stderr, Q_("Main preference file %s created successfully\n"), filename);
98  fclose(fp);
99  }
100  }
101  else
102  {
103  fclose(fp);
104  }
105 }
106 
107 
108 /**
109  * Verify preference file presence and creates it if it does not
110  * already exists.
111  * @param prefs is a 'prefs_t *' filled preference structure
112  */
114 {
115  if (prefs != NULL)
116  {
119  }
120 }
121 
122 
123 /**
124  * Look out if the preference structure exists or not. If not
125  * it creates it.
126  * @see http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
127  * @param pathname is the pathname where the preference file is
128  * @param filename is the filename of the preference file itself
129  */
130 prefs_t *init_preference_struct(gchar *pathname, gchar *filename)
131 {
132  prefs_t *prefs = NULL;
133 
134  prefs = (prefs_t *) g_malloc0(sizeof(prefs_t));
135 
136  prefs->file = g_key_file_new();
137  prefs->pathname = pathname;
138  prefs->filename = g_build_filename(prefs->pathname, filename, NULL);
139 
140  return prefs;
141 }
142 
143 
144 /**
145  * Destroys a preference structure
146  * @param prefs the preference structure to be freed
147  */
149 {
150  if (prefs != NULL)
151  {
152  g_free(prefs->filename);
153  g_free(prefs->pathname);
154  g_key_file_free(prefs->file);
155  }
156 }
157 
158 
159 /**
160  * Window preferences
161  * @param file a GKeyFile where values are stored
162  * @param name a keyname (basically a window name)
163  * @param window_prop all window properties to save (structure window_prop_t)
164  */
165 static void save_window_preferences(GKeyFile *file, gchar *name, window_prop_t *window_prop)
166 {
167  gchar *keyname = NULL;
168 
169  keyname = g_strconcat(name, " Displayed", NULL);
170  g_key_file_set_boolean(file, GN_GLOBAL_PREFS, keyname, window_prop->displayed);
171  g_free(keyname);
172 
173  keyname = g_strconcat(name, " X_pos", NULL);
174  g_key_file_set_integer(file, GN_GLOBAL_PREFS, keyname, window_prop->x);
175  g_free(keyname);
176 
177  keyname = g_strconcat(name, " Y_pos", NULL);
178  g_key_file_set_integer(file, GN_GLOBAL_PREFS, keyname, window_prop->y);
179  g_free(keyname);
180 
181  keyname = g_strconcat(name, " Height", NULL);
182  g_key_file_set_integer(file, GN_GLOBAL_PREFS, keyname, window_prop->height);
183  g_free(keyname);
184 
185  keyname = g_strconcat(name, " Width", NULL);
186  g_key_file_set_integer(file, GN_GLOBAL_PREFS, keyname, window_prop->width);
187  g_free(keyname);
188 }
189 
190 
191 /**
192  * Save only file preferences related options
193  * @param main_struct the main structure
194  * @param prefs is a 'prefs_t *' filled preference structure
195  */
197 {
198  gboolean activated = FALSE;
199 
200 
201  if (main_struct != NULL && prefs != NULL)
202  {
203  /* Saves the position */
204  activated = is_toggle_button_activated(main_struct->xmls->main, "save_window_position_bt");
205  g_key_file_set_boolean(prefs->file, GN_GLOBAL_PREFS, KN_SAVE_WINDOW_PREFS, activated);
206 
207  /* Saving all window preferences if necessary */
208  if (activated == TRUE)
209  {
212  save_window_preferences(prefs->file, KN_LOG_BOX, main_struct->win_prop->log_box);
215  save_window_preferences(prefs->file, KN_LDT, main_struct->win_prop->ldt);
222  }
223 
224  /* Saving opened files filenames ? */
225  activated = is_toggle_button_activated(main_struct->xmls->main, "save_filenames_bt");
226  g_key_file_set_boolean(prefs->file, GN_GLOBAL_PREFS, KN_SAVE_OPENED_FILES_FILENAMES, activated);
227 
228  if (activated == TRUE)
229  {
230  save_mp_files_filenames(main_struct, prefs);
231  }
232  }
233 }
234 
235 /**
236  * Saves files filenames to the config file
237  * @param main_struct the main structure
238  * @param prefs preference structure
239  */
240 static void save_mp_files_filenames(heraia_struct_t *main_struct, prefs_t *prefs)
241 {
242  const gchar **list = NULL; /**< A list that will contain all the files filenames */
243  gchar *filename = NULL; /**< One filename */
244  gint *pos_list = NULL; /**< list of the current position of the cursor in the documents */
245  gsize i = 0;
246  gsize len = 0;
247  gsize j = 0;
248  gint current_tab = 0; /**< Current selected tab in the main notebook */
249  doc_t *document = NULL; /**< One document (from the documents array in the main_struct */
250  GtkWidget *notebook = NULL; /**< Main notebook in the file view in the main window */
251 
252  if (main_struct != NULL && prefs != NULL)
253  {
254  /* First initializing the list variable with the filenames of the opened documents */
255  i = 0;
256  j = 0;
257  len = main_struct->documents->len;
258  list = (const gchar **) g_malloc0 (sizeof(gchar *)*len);
259  pos_list = (gint *) g_malloc0 (sizeof(gint)*len);
260 
261  while (i < len)
262  {
263  document = g_ptr_array_index(main_struct->documents, i);
264 
265  if (document != NULL)
266  {
267  filename = g_strdup(doc_t_document_get_filename(document));
268  /* There will be some limitations here due to the guint64 to gint cast */
269  pos_list[j] = (gint) ghex_get_cursor_position(document->hex_widget);
270  list[j] = filename;
271  j++;
272  }
273  i++;
274  }
275 
276  /* Saving them to the preference file */
277  g_key_file_set_string_list(prefs->file, GN_GLOBAL_PREFS, KN_FILES_FILENAMES, list, j);
278  g_key_file_set_integer_list(prefs->file, GN_GLOBAL_PREFS, KN_FILES_CURSOR_POSITIONS, pos_list, j);
279 
280  /* saving current tab */
281  notebook = heraia_get_widget(main_struct->xmls->main, "file_notebook");
282  current_tab = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
283  g_key_file_set_integer(prefs->file, GN_GLOBAL_PREFS, KN_CURRENT_TAB, current_tab);
284  }
285 }
286 
287 
288 /**
289  * Save only display related preferences
290  * @param main_struct : main structure
291  * @param prefs is a 'prefs_t *' filled preference structure
292  */
294 {
295  gboolean activated = FALSE;
296 
297  if (main_struct != NULL && prefs != NULL)
298  {
299  /* Display Thousand (or not) */
300  activated = is_toggle_button_activated(main_struct->xmls->main, "mp_thousand_bt");
301  g_key_file_set_boolean(prefs->file, GN_DISPLAY_PREFS, KN_DISP_THOUSAND, activated);
302 
303  /* Display offsets (or not) */
304  activated = is_toggle_button_activated(main_struct->xmls->main, "mp_display_offset_bt");
305  g_key_file_set_boolean(prefs->file, GN_DISPLAY_PREFS, KN_DISP_OFFSETS, activated);
306  }
307 }
308 
309 
310 /**
311  * Saves data interpretor state and preferences
312  * @param main_struct : main structure
313  * @param prefs is a 'prefs_t *' filled preference structure
314  */
315 static void save_di_preferences(heraia_struct_t *main_struct, prefs_t *prefs)
316 {
317  gint selected_tab = -1; /**< Selected tab in data interpretor's window */
318  gint stream_size = -1; /**< Stream size in data interpretor's window */
319  gint endianness = -1; /**< Endianness in data interpretor's window */
320 
321  if (main_struct != NULL && main_struct->current_DW != NULL && prefs != NULL)
322  {
323  selected_tab = di_get_selected_tab(main_struct);
324  if (selected_tab >= 0)
325  {
326  g_key_file_set_integer(prefs->file, GN_DI_PREFS, KN_DI_SELECTED_TAB, selected_tab);
327  }
328 
329  stream_size = di_get_stream_size(main_struct);
330  if (stream_size >= 0)
331  {
332  g_key_file_set_integer(prefs->file, GN_DI_PREFS, KN_DI_STREAM_SIZE, stream_size);
333  }
334 
335  endianness = di_get_endianness(main_struct);
336  if (endianness >= 0)
337  {
338  g_key_file_set_integer(prefs->file, GN_DI_PREFS, KN_DI_ENDIANNESS, endianness);
339  }
340  }
341 }
342 
343 
344 /**
345  * Saves main preferences window state and preferences
346  * @param main_struct : main structure
347  * @param prefs is a 'prefs_t *' filled preference structure
348  */
349 static void save_mpwp_preferences(heraia_struct_t *main_struct, prefs_t *prefs)
350 {
351  GtkNotebook *notebook = NULL; /**< main preferences's notebook */
352  gint selected_tab = -1; /**< Selected tab in data interpretor's window */
353 
354  if (main_struct != NULL && main_struct->current_DW != NULL && prefs != NULL)
355  {
356  notebook = GTK_NOTEBOOK(heraia_get_widget(main_struct->xmls->main, "mp_first_notebook"));
357 
358  if (notebook != NULL)
359  {
360  selected_tab = gtk_notebook_get_current_page(notebook);
361 
362  if (selected_tab >= 0)
363  {
364  g_key_file_set_integer(prefs->file, GN_MPWP_PREFS, KN_MPWP_SELECTED_TAB, selected_tab);
365  }
366  }
367  }
368 }
369 
370 
371 /**
372  * Save all preferences to the user preference file
373  * @param main_struct the main structure
374  * @param prefs is a 'prefs_t *' filled preference structure
375  */
376 void save_preferences(heraia_struct_t *main_struct, prefs_t *prefs)
377 {
378  if (main_struct != NULL && prefs != NULL)
379  {
380  /* 1. Saving main Preferences */
381  save_mp_file_preferences_options(main_struct, prefs);
382 
383  /* 2. Saving Display Preferences */
384  save_mp_display_preferences_options(main_struct, prefs);
385 
386  /* 3. Saving Data Interpretor Preferences */
387  save_di_preferences(main_struct, prefs);
388 
389  /* 4. Saving Main Preferences Window Preferences */
390  save_mpwp_preferences(main_struct, prefs);
391 
392  /* 5. Saving to file */
394  }
395 }
396 
397 
398 /**
399  * Window preferences
400  * @param file a GKeyFile where values are stored
401  * @param name a keyname (basically a window name)
402  * @param window_prop all window properties to save (structure window_prop_t)
403  */
404 static void load_window_preferences(GKeyFile *file, gchar *name, window_prop_t *window_prop)
405 {
406  gchar *keyname = NULL;
407 
408  keyname = g_strconcat(name, " Displayed", NULL);
409  window_prop->displayed = g_key_file_get_boolean(file, GN_GLOBAL_PREFS, keyname, NULL);
410  g_free(keyname);
411 
412  keyname = g_strconcat(name, " X_pos", NULL);
413  window_prop->x = g_key_file_get_integer(file, GN_GLOBAL_PREFS, keyname, NULL);
414  g_free(keyname);
415 
416  keyname = g_strconcat(name, " Y_pos", NULL);
417  window_prop->y = g_key_file_get_integer(file, GN_GLOBAL_PREFS, keyname, NULL);
418  g_free(keyname);
419 
420  keyname = g_strconcat(name, " Height", NULL);
421  window_prop->height = g_key_file_get_integer(file, GN_GLOBAL_PREFS, keyname, NULL);
422  g_free(keyname);
423 
424  keyname = g_strconcat(name, " Width", NULL);
425  window_prop->width = g_key_file_get_integer(file, GN_GLOBAL_PREFS, keyname, NULL);
426  g_free(keyname);
427 
428 }
429 
430 
431 /**
432  * Load only main preferences related options
433  * @param main_struct the main structure
434  * @param prefs is a 'prefs_t *' filled preference structure
435  */
437 {
438  GtkWidget *save_window_position_bt = NULL;
439  GtkWidget *save_filenames_bt = NULL;
440  gboolean activated = FALSE;
441 
442  if (main_struct != NULL && prefs != NULL)
443  {
444  log_message(main_struct, G_LOG_LEVEL_DEBUG, Q_("Loading window's positions"));
445  /* Loading window's positions ? */
446  activated = g_key_file_get_boolean(prefs->file, GN_GLOBAL_PREFS, KN_SAVE_WINDOW_PREFS, NULL);
447  save_window_position_bt = heraia_get_widget(main_struct->xmls->main, "save_window_position_bt");
448  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(save_window_position_bt), activated);
449 
450  if (activated == TRUE)
451  {
452  /* window's positions */
455  load_window_preferences(prefs->file, KN_LOG_BOX, main_struct->win_prop->log_box);
458  load_window_preferences(prefs->file, KN_LDT, main_struct->win_prop->ldt);
465  }
466 
467  /* Loading opened files filenames ? */
468  activated = g_key_file_get_boolean(prefs->file, GN_GLOBAL_PREFS, KN_SAVE_OPENED_FILES_FILENAMES, NULL);
469  save_filenames_bt = heraia_get_widget(main_struct->xmls->main, "save_filenames_bt");
470  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(save_filenames_bt), activated);
471 
472  if (activated == TRUE)
473  {
474  log_message(main_struct, G_LOG_LEVEL_DEBUG, Q_("Loading files..."));
475  load_mp_files_filenames(main_struct, prefs);
476  }
477  }
478 }
479 
480 
481 /**
482  * Load files filenames from the config file
483  * @param main_struct the main structure
484  * @param prefs preference structure
485  */
486 static void load_mp_files_filenames(heraia_struct_t *main_struct, prefs_t *prefs)
487 {
488  gchar **list = NULL; /**< The list that will contain all filenames to be loaded */
489  gint *pos_list = NULL; /**< list of the current position of the cursor in the documents */
490  gsize i = 0;
491  gsize len = 0;
492  gsize pos_len = 0;
493  gint current_tab = 0;
494  GtkWidget *notebook = NULL;
495 
496  if (main_struct != NULL && prefs != NULL)
497  {
498  /* get file list */
499  list = g_key_file_get_string_list(prefs->file, GN_GLOBAL_PREFS, KN_FILES_FILENAMES, &len, NULL);
500  pos_list = (gint *) g_key_file_get_integer_list(prefs->file, GN_GLOBAL_PREFS, KN_FILES_CURSOR_POSITIONS, &pos_len, NULL);
501 
502  if (len == pos_len)
503  {
504  for (i = 0; i < len; i++)
505  {
506  if (load_file_to_analyse(main_struct, list[i]))
507  {
508  /* in add_new_tab_in_main_window() function, the newly */
509  /* opened document becomes the current one */
510  /* There is some limitations here due to the cast from */
511  /* gint to guint64 */
512  ghex_set_cursor_position(main_struct->current_doc->hex_widget, (guint64) pos_list[i]);
513  }
514  }
515  }
516 
517  /* get current tab */
518  current_tab = g_key_file_get_integer(prefs->file, GN_GLOBAL_PREFS, KN_CURRENT_TAB, NULL);
519  notebook = heraia_get_widget(main_struct->xmls->main, "file_notebook");
520  gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), current_tab);
521  }
522 }
523 
524 
525 /**
526  * Load display related preferences
527  * @param main_struct the main structure
528  * @param prefs is a 'prefs_t *' filled preference structure
529  */
531 {
532  GtkWidget *toggle_button = NULL;
533  gboolean activated = FALSE;
534 
535  if (main_struct != NULL && prefs != NULL)
536  {
537  /* Display thousands (or not) */
538  activated = g_key_file_get_boolean(prefs->file, GN_DISPLAY_PREFS, KN_DISP_THOUSAND, NULL);
539  toggle_button = heraia_get_widget(main_struct->xmls->main, "mp_thousand_bt");
540  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_button), activated);
541 
542  /* Display offsets (or not) */
543  activated = g_key_file_get_boolean(prefs->file, GN_DISPLAY_PREFS, KN_DISP_OFFSETS, NULL);
544  toggle_button = heraia_get_widget(main_struct->xmls->main, "mp_display_offset_bt");
545  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_button), activated);
546  }
547 }
548 
549 
550 /**
551  * Load data interpretor state and preferences
552  * @param main_struct : main structure
553  * @param prefs is a 'prefs_t *' filled preference structure
554  */
555 static void load_di_preferences(heraia_struct_t *main_struct, prefs_t *prefs)
556 {
557  gint selected_tab = -1; /**< Selected tab in data interpretor's window */
558  gint stream_size = -1; /**< Stream size in data interpretor's window */
559  gint endianness = -1; /**< Endianness in data interpretor's window */
560 
561  if (main_struct != NULL && main_struct->current_DW != NULL && main_struct->xmls != NULL && main_struct->xmls->main != NULL && prefs != NULL)
562  {
563  selected_tab = g_key_file_get_integer(prefs->file, GN_DI_PREFS, KN_DI_SELECTED_TAB, NULL);
564  stream_size = g_key_file_get_integer(prefs->file, GN_DI_PREFS, KN_DI_STREAM_SIZE, NULL);
565  endianness = g_key_file_get_integer(prefs->file, GN_DI_PREFS, KN_DI_ENDIANNESS, NULL);
566 
567  di_set_selected_tab(main_struct, selected_tab);
568  di_set_stream_size(main_struct, stream_size);
569  di_set_endianness(main_struct, endianness);
570  }
571 }
572 
573 
574 /**
575  * Load main preferences window state and preferences
576  * @param main_struct : main structure
577  * @param prefs is a 'prefs_t *' filled preference structure
578  */
579 static void load_mpwp_preferences(heraia_struct_t *main_struct, prefs_t *prefs)
580 {
581  GtkNotebook *notebook = NULL; /**< main preferences's notebook */
582  GtkWidget *button = NULL; /**< tool button from the toolbar */
583  gint selected_tab; /**< Selected tab in data interpretor's window */
584 
585  if (main_struct != NULL && main_struct->current_DW != NULL && main_struct->xmls != NULL && main_struct->xmls->main != NULL && prefs != NULL)
586  {
587  notebook = GTK_NOTEBOOK(heraia_get_widget(main_struct->xmls->main, "mp_first_notebook"));
588 
589  if (notebook != NULL)
590  {
591  selected_tab = g_key_file_get_integer(prefs->file, GN_MPWP_PREFS, KN_MPWP_SELECTED_TAB, NULL);
592 
593  switch (selected_tab)
594  {
595  case 0:
596  gtk_notebook_set_current_page(notebook, selected_tab);
597  button = heraia_get_widget(main_struct->xmls->main, "mp_tb_fp_bt");
598  gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(button), TRUE);
599  break;
600 
601  case 1:
602  gtk_notebook_set_current_page(notebook, selected_tab);
603  button = heraia_get_widget(main_struct->xmls->main, "mp_tb_display_bt");
604  gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(button), TRUE);
605  break;
606 
607  default:
608  break;
609  }
610  }
611  }
612 }
613 
614 
615 /**
616  * Sets up the preferences as loaded in the preference file
617  * @param main_struct the main structure
618  * @param prefs is a 'prefs_t *' filled preference structure
619  */
620 void load_preferences(heraia_struct_t *main_struct, prefs_t *prefs)
621 {
622  if (main_struct != NULL && prefs != NULL)
623  {
624  /* 0. Loading preferences from file */
625  if (load_preference_file(prefs) == TRUE)
626  {
627  /* 1. Loading Main Preferences */
628  log_message(main_struct, G_LOG_LEVEL_DEBUG, Q_("Loading main preferences"));
629  load_mp_file_preferences_options(main_struct, prefs);
630 
631  /* 2. Loading Display preferences */
632  log_message(main_struct, G_LOG_LEVEL_DEBUG, Q_("Loading main display preferences"));
633  load_mp_display_preferences_options(main_struct, prefs);
634 
635  /* 3. Loading Data Interpretor Preferences */
636  log_message(main_struct, G_LOG_LEVEL_DEBUG, Q_("Loading data interpretor preferences"));
637  load_di_preferences(main_struct, prefs);
638 
639  /* 4. Loading Main Preferences Window Preferences */
640  log_message(main_struct, G_LOG_LEVEL_DEBUG, Q_("Loading window preference's main preferences"));
641  load_mpwp_preferences(main_struct, prefs);
642  }
643  }
644 }
window_prop_t * find_window
find window
Definition: libheraia.h:270
#define KN_DISP_OFFSETS
Definition: user_prefs.h:63
This is the main structure.
Definition: libheraia.h:332
static void load_mp_file_preferences_options(heraia_struct_t *main_struct, prefs_t *prefs)
Load only main preferences related options.
Definition: user_prefs.c:436
Window properties.
Definition: libheraia.h:243
window_prop_t * data_interpretor
data interpretor window
Definition: libheraia.h:262
gint x
x position (upper left corner)
Definition: libheraia.h:245
#define GN_MPWP_PREFS
Definition: user_prefs.h:40
window_prop_t * result_window
result window properties
Definition: libheraia.h:269
static void load_di_preferences(heraia_struct_t *main_struct, prefs_t *prefs)
Load data interpretor state and preferences.
Definition: user_prefs.c:555
#define KN_FILES_CURSOR_POSITIONS
Definition: user_prefs.h:58
gchar * doc_t_document_get_filename(doc_t *doc)
Retrieves from a doc_t * document it's filename, which ever it is.
window_prop_t * fr_window
find and replace window
Definition: libheraia.h:271
void log_message(heraia_struct_t *main_struct, GLogLevelFlags log_level, const char *format,...)
A function that helps logging a message a the specified level.
Definition: log.c:195
window_prop_t * main_dialog
heraia's main window
Definition: libheraia.h:264
gboolean displayed
TRUE if displayed, FALSE otherwise.
Definition: libheraia.h:249
#define KN_MPWP_SELECTED_TAB
Definition: user_prefs.h:69
gchar * filename
user preference file file name
Definition: libheraia.h:282
window_prop_t * plugin_list
plugin description window
Definition: libheraia.h:265
#define KN_DI_ENDIANNESS
Definition: user_prefs.h:67
#define KN_RESULT_WINDOW
Definition: user_prefs.h:51
#define KN_FR_WINDOW
Definition: user_prefs.h:53
#define KN_FDFT_WINDOW
Definition: user_prefs.h:54
all_window_prop_t * win_prop
Keeps window properties.
Definition: libheraia.h:342
gint di_get_stream_size(heraia_struct_t *main_struct)
Gets the stream_size (if any) from data interpretor's window.
window_prop_t * main_pref_window
main preference window
Definition: libheraia.h:267
window_prop_t * fdft_window
find data from type window
Definition: libheraia.h:272
#define KN_DATA_INTERPRETOR
Definition: user_prefs.h:44
Proposal for a structure that will group all informations about a single document.
Definition: libheraia.h:293
prefs_t * init_preference_struct(gchar *pathname, gchar *filename)
Look out if the preference structure exists or not.
Definition: user_prefs.c:130
#define GN_DI_PREFS
Definition: user_prefs.h:39
static void verify_preference_file_name_presence(gchar *filename)
Verify preference file's presence and creates it if it does not exists already.
Definition: user_prefs.c:82
xml_t * xmls
All the xmls used in the program, loaded at running time.
Definition: libheraia.h:337
#define KN_MAIN_PREFS
Definition: user_prefs.h:49
gchar * pathname
user preference file path name
Definition: libheraia.h:283
Data type related to preferences.
Definition: libheraia.h:280
static void save_mp_files_filenames(heraia_struct_t *main_struct, prefs_t *prefs)
Saves files filenames to the config file.
Definition: user_prefs.c:240
#define KN_SAVE_OPENED_FILES_FILENAMES
Definition: user_prefs.h:56
gboolean load_preference_file(prefs_t *prefs)
Load the preference file from the disk.
Definition: heraia_io.c:173
GKeyFile * file
preference file contents
Definition: libheraia.h:284
#define KN_SAVE_WINDOW_PREFS
Definition: user_prefs.h:42
window_prop_t * ldt
list data types window
Definition: libheraia.h:266
static void save_di_preferences(heraia_struct_t *main_struct, prefs_t *prefs)
Saves data interpretor state and preferences.
Definition: user_prefs.c:315
void di_set_selected_tab(heraia_struct_t *main_struct, gint selected_tab)
Sets the selected tab (if possible) to data interpretor's notebook.
static void save_mp_file_preferences_options(heraia_struct_t *main_struct, prefs_t *prefs)
Save only file preferences related options.
Definition: user_prefs.c:196
void verify_preference_file(prefs_t *prefs)
Verify preference file presence and creates it if it does not already exists.
Definition: user_prefs.c:113
#define KN_PLUGIN_LIST
Definition: user_prefs.h:47
#define KN_MAIN_DIALOG
Definition: user_prefs.h:46
#define KN_DI_SELECTED_TAB
Definition: user_prefs.h:65
gboolean save_preferences_to_file(prefs_t *prefs)
Saves the preferences to the file preferences.
Definition: heraia_io.c:191
window_prop_t * about_box
Definition: libheraia.h:261
#define KN_GOTO_DIALOG
Definition: user_prefs.h:50
GtkWidget * hex_widget
hexwidget corresponding to the document
Definition: libheraia.h:296
gint y
y position (upper left corner)
Definition: libheraia.h:246
#define KN_LOG_BOX
Definition: user_prefs.h:45
static void save_mp_display_preferences_options(heraia_struct_t *main_struct, prefs_t *prefs)
Save only display related preferences.
Definition: user_prefs.c:293
void free_preference_struct(prefs_t *prefs)
Destroys a preference structure.
Definition: user_prefs.c:148
static void save_window_preferences(GKeyFile *file, gchar *name, window_prop_t *window_prop)
Window preferences.
Definition: user_prefs.c:165
GtkBuilder * main
the main interface xml description
Definition: libheraia.h:222
void di_set_stream_size(heraia_struct_t *main_struct, gint stream_size)
Sets the stream size (if possible) to data interpretor's notebook.
#define KN_LDT
Definition: user_prefs.h:48
guint64 ghex_get_cursor_position(GtkWidget *hex_widget)
Retrieves the cursor's position from the current hexwidget.
data_window_t * current_DW
data_interpretor pointer
Definition: libheraia.h:338
void save_preferences(heraia_struct_t *main_struct, prefs_t *prefs)
Save all preferences to the user preference file.
Definition: user_prefs.c:376
void di_set_endianness(heraia_struct_t *main_struct, gint endianness)
Sets the endianness as stated by the second parameter.
window_prop_t * log_box
log window
Definition: libheraia.h:263
static void load_window_preferences(GKeyFile *file, gchar *name, window_prop_t *window_prop)
Window preferences.
Definition: user_prefs.c:404
#define KN_ABOUT_BOX
Definition: user_prefs.h:43
This file contains all the definitions and includes all other .h files.
guint height
y+height (bottom right corner)
Definition: libheraia.h:247
#define KN_FIND_WINDOW
Definition: user_prefs.h:52
void ghex_set_cursor_position(GtkWidget *hex_widget, guint64 position)
Sets the cursor at the defined position in the hexwidget.
static void load_mpwp_preferences(heraia_struct_t *main_struct, prefs_t *prefs)
Load main preferences window state and preferences.
Definition: user_prefs.c:579
#define KN_DI_STREAM_SIZE
Definition: user_prefs.h:66
doc_t * current_doc
This is a pointer to the current edited document.
Definition: libheraia.h:335
GtkWidget * heraia_get_widget(GtkBuilder *xml, gchar *widget_name)
This is a wrapper to the GtkBuilder xml get widget.
Definition: heraia_ui.c:2184
window_prop_t * goto_window
goto dialog window
Definition: libheraia.h:268
#define KN_CURRENT_TAB
Definition: user_prefs.h:59
gint di_get_endianness(heraia_struct_t *main_struct)
Gets the endianness as selected in the radio group button.
gboolean is_toggle_button_activated(GtkBuilder *main_xml, gchar *check_button)
returns the state of a named check button contained in the GtkBuilder XML description ...
Definition: heraia_ui.c:2161
#define GN_GLOBAL_PREFS
Definition: user_prefs.h:37
static void load_mp_display_preferences_options(heraia_struct_t *main_struct, prefs_t *prefs)
Load display related preferences.
Definition: user_prefs.c:530
guint width
x+width (bottom right corner)
Definition: libheraia.h:248
#define KN_DISP_THOUSAND
Definition: user_prefs.h:62
GPtrArray * documents
An array of doc_t in order to be able to open more than one doc.
Definition: libheraia.h:336
gint di_get_selected_tab(heraia_struct_t *main_struct)
Gets the selected tab (if any) from data interpretor's notebook.
static void load_mp_files_filenames(heraia_struct_t *main_struct, prefs_t *prefs)
Load files filenames from the config file.
Definition: user_prefs.c:486
static void save_mpwp_preferences(heraia_struct_t *main_struct, prefs_t *prefs)
Saves main preferences window state and preferences.
Definition: user_prefs.c:349
void load_preferences(heraia_struct_t *main_struct, prefs_t *prefs)
Sets up the preferences as loaded in the preference file.
Definition: user_prefs.c:620
#define GN_DISPLAY_PREFS
Definition: user_prefs.h:38
#define KN_FILES_FILENAMES
Definition: user_prefs.h:57
gboolean load_file_to_analyse(heraia_struct_t *main_struct, gchar *filename)
Loads the file 'filename' to analyse and populates the corresponfing structure 'main_struct' as neede...
Definition: heraia_io.c:40
static void verify_preference_file_path_presence(gchar *pathname)
verify preference file path presence and creates it if it does not already exists ...
Definition: user_prefs.c:62