Heraia  0.1.8
main_pref_window.c
Go to the documentation of this file.
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /*
3  * main_pref_window.c
4  * heraia - an hexadecimal file editor and analyser based on ghex
5  *
6  * (C) Copyright 2008 - 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 main_pref_window.c
26  * Handles main preference window
27  */
28 
29 #include <libheraia.h>
30 
31 static gboolean pref_window_delete(GtkWidget *widget, GdkEvent *event, gpointer data);
32 static void main_pref_window_connect_signals(heraia_struct_t *main_struct);
33 
34 /* ToolBar buttons */
35 static void on_mp_tb_fp_bt_toggled(GtkToggleToolButton *tool_button, gpointer data);
36 static void on_mp_tb_display_bt_toggled(GtkToggleToolButton *tool_button, gpointer data);
37 
38 /* Toogle Buttons */
39 static void on_mp_thousand_bt_toggled(GtkToggleButton *toggle_button, gpointer data);
40 static void on_mp_display_offset_bt_toggled(GtkToggleButton *toggle_button, gpointer data);
41 
42 
43 /******************************** The Signals *********************************/
44 
45 /**
46  * @fn gboolean pref_window_delete(GtkWidget *widget, GdkEvent *event, gpointer data)
47  * Closing the window
48  * @param widget : calling widget (may be NULL as we don't use this here)
49  * @param event : event associated (may be NULL as we don't use this here)
50  * @param data : MUST be heraia_struct_t *main_struct main structure and not NULL
51  * @return Always returns TRUE in order to propagate the signal
52  */
53 static gboolean pref_window_delete(GtkWidget *widget, GdkEvent *event, gpointer data)
54 {
55  heraia_struct_t *main_struct = (heraia_struct_t *) data;
56  GtkWidget *pref_window = NULL;
57 
58  if (main_struct != NULL && main_struct->win_prop != NULL && main_struct->win_prop->main_pref_window != NULL)
59  {
60  pref_window = heraia_get_widget(main_struct->xmls->main, "main_preferences_window");
61  save_preferences(main_struct, main_struct->prefs);
62  record_and_hide_dialog_box(pref_window, main_struct->win_prop->main_pref_window);
63  }
64 
65  return TRUE;
66 }
67 
68 
69 /**
70  * @fn void main_pref_window_connect_signals(heraia_struct_t *main_struct)
71  * Connecting the window signals to the right functions
72  * @param main_struct : main structure
73  */
75 {
76  /* Closing the window */
77  g_signal_connect(G_OBJECT(heraia_get_widget(main_struct->xmls->main, "main_preferences_window")), "delete-event",
78  G_CALLBACK(pref_window_delete), main_struct);
79 
80  /* Clicking on the file preference button of the toolbar */
81  g_signal_connect(G_OBJECT(heraia_get_widget(main_struct->xmls->main, "mp_tb_fp_bt")), "toggled",
82  G_CALLBACK(on_mp_tb_fp_bt_toggled), main_struct);
83 
84  /* Clicking on the display button of the toolbar */
85  g_signal_connect(G_OBJECT(heraia_get_widget(main_struct->xmls->main, "mp_tb_display_bt")), "toggled",
86  G_CALLBACK(on_mp_tb_display_bt_toggled), main_struct);
87 
88  /* Toggling the button to choose to display with separated thousand or not */
89  g_signal_connect(G_OBJECT(heraia_get_widget(main_struct->xmls->main, "mp_thousand_bt")), "toggled",
90  G_CALLBACK(on_mp_thousand_bt_toggled), main_struct);
91 
92  /* Toggling the button to choose to display the offsets or not */
93  g_signal_connect(G_OBJECT(heraia_get_widget(main_struct->xmls->main, "mp_display_offset_bt")), "toggled",
94  G_CALLBACK(on_mp_display_offset_bt_toggled), main_struct);
95 }
96 
97 
98 /**
99  * Tool buttons
100  */
101 
102 /**
103  * @fn void on_mp_tb_fp_bt_toggled(GtkToolButton *toolbutton, gpointer data)
104  * Main Preferences, ToolBar, File Preference Button
105  * @param toolbutton : button that was clicked
106  * @param data : user data : MUST be heraia_struct_t *main_struct main structure
107  */
108 static void on_mp_tb_fp_bt_toggled(GtkToggleToolButton *tool_button, gpointer data)
109 {
110  heraia_struct_t *main_struct = (heraia_struct_t *) data;
111  GtkWidget *notebook = NULL; /* Main Preference Window's Notebook */
112 
113  if (main_struct != NULL && main_struct->xmls != NULL && main_struct->xmls->main != NULL)
114  {
115  notebook = heraia_get_widget(main_struct->xmls->main, "mp_first_notebook");
116  gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 0);
117  }
118 }
119 
120 
121 /**
122  * @fn void on_mp_tb_display_bt_toggled(GtkToolButton *toolbutton, gpointer data)
123  * Main Preferences, ToolBar, Display Button
124  * @param toolbutton : button that was clicked
125  * @param data : user data : MUST be heraia_struct_t *main_struct main structure
126  */
127 static void on_mp_tb_display_bt_toggled(GtkToggleToolButton *tool_button, gpointer data)
128 {
129  heraia_struct_t *main_struct = (heraia_struct_t *) data;
130  GtkWidget *notebook = NULL; /* Main Preference Window's Notebook */
131 
132  if (main_struct != NULL && main_struct->xmls != NULL && main_struct->xmls->main != NULL)
133  {
134 
135  notebook = heraia_get_widget(main_struct->xmls->main, "mp_first_notebook");
136  gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 1);
137  }
138 }
139 
140 
141 /**
142  * @fn void on_mp_thousand_bt_toggled(GtkToggleButton *togglebutton, gpointer data)
143  * Refreshes the file labels as an option has been sat
144  * @param togglebutton : button that was toggled
145  * @param data : user data : MUST be heraia_struct_t *main_struct main structure
146  */
147 static void on_mp_thousand_bt_toggled(GtkToggleButton *toggle_button, gpointer data)
148 {
149  heraia_struct_t *main_struct = (heraia_struct_t *) data;
150 
151  refresh_file_labels(main_struct);
152 }
153 
154 
155 /**
156  * Displays or not offsets
157  * @param togglebutton : button that was toggled
158  * @param data : user data : MUST be heraia_struct_t *main_struct main structure
159  */
160 static void on_mp_display_offset_bt_toggled(GtkToggleButton *toggle_button, gpointer data)
161 {
162  heraia_struct_t *main_struct = (heraia_struct_t *) data;
163  doc_t *document = NULL;
164  guint i = 0;
165 
166  if (toggle_button != NULL && main_struct != NULL && main_struct->documents != NULL)
167  {
168 
169  for(i = 0; i < main_struct->documents->len; i++)
170  {
171  document = g_ptr_array_index(main_struct->documents, i);
172  gtk_hex_show_offsets(GTK_HEX(document->hex_widget), gtk_toggle_button_get_active(toggle_button));
173  }
174  }
175 }
176 
177 /******************************** End Signals *********************************/
178 
179 
180 /**
181  * @fn main_pref_window_init_interface(heraia_struct_t *main_struct)
182  * Inits the main preferences window interface
183  * @param main_struct : main structure
184  */
186 {
188 }
This is the main structure.
Definition: libheraia.h:332
void main_pref_window_init_interface(heraia_struct_t *main_struct)
Inits the main preferences window interface.
void record_and_hide_dialog_box(GtkWidget *dialog_box, window_prop_t *dialog_prop)
Record position and hide a dialog box.
Definition: heraia_ui.c:314
void refresh_file_labels(heraia_struct_t *main_struct)
This function is refreshing the labels on the main window in order to reflect cursor position...
Definition: heraia_ui.c:588
all_window_prop_t * win_prop
Keeps window properties.
Definition: libheraia.h:342
window_prop_t * main_pref_window
main preference window
Definition: libheraia.h:267
Proposal for a structure that will group all informations about a single document.
Definition: libheraia.h:293
static void on_mp_display_offset_bt_toggled(GtkToggleButton *toggle_button, gpointer data)
Displays or not offsets.
static gboolean pref_window_delete(GtkWidget *widget, GdkEvent *event, gpointer data)
Closing the window.
xml_t * xmls
All the xmls used in the program, loaded at running time.
Definition: libheraia.h:337
static void on_mp_tb_fp_bt_toggled(GtkToggleToolButton *tool_button, gpointer data)
prefs_t * prefs
All datas related to main preferences.
Definition: libheraia.h:343
GtkWidget * hex_widget
hexwidget corresponding to the document
Definition: libheraia.h:296
GtkBuilder * main
the main interface xml description
Definition: libheraia.h:222
static void main_pref_window_connect_signals(heraia_struct_t *main_struct)
Connecting the window signals to the right functions.
This file contains all the definitions and includes all other .h files.
GtkWidget * heraia_get_widget(GtkBuilder *xml, gchar *widget_name)
This is a wrapper to the GtkBuilder xml get widget.
Definition: heraia_ui.c:2184
void save_preferences(heraia_struct_t *main_struct, prefs_t *prefs)
Save all preferences to the user preference file.
Definition: user_prefs.c:376
static void on_mp_tb_display_bt_toggled(GtkToggleToolButton *tool_button, gpointer data)
GPtrArray * documents
An array of doc_t in order to be able to open more than one doc.
Definition: libheraia.h:336
static void on_mp_thousand_bt_toggled(GtkToggleButton *toggle_button, gpointer data)
Refreshes the file labels as an option has been sat.