1 /* ************************************************************************** */
2 /*     Copyright (C)    2000-2003 Cédric Auger (cedric@grisbi.org)            */
3 /*          2003-2008 Benjamin Drieu (bdrieu@april.org)                       */
4 /*          2003-2004 Alain Portal (aportal@univ-montp2.fr)                   */
5 /*          2003-2004 Francois Terrot (francois.terrot@grisbi.org)            */
6 /*          2008-2017 Pierre Biava (grisbi@pierre.biava.name)                 */
7 /*          https://www.grisbi.org/                                           */
8 /*                                                                            */
9 /*  This program is free software; you can redistribute it and/or modify      */
10 /*  it under the terms of the GNU General Public License as published by      */
11 /*  the Free Software Foundation; either version 2 of the License, or         */
12 /*  (at your option) any later version.                                       */
13 /*                                                                            */
14 /*  This program is distributed in the hope that it will be useful,           */
15 /*  but WITHOUT ANY WARRANTY; without even the implied warranty of            */
16 /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             */
17 /*  GNU General Public License for more details.                              */
18 /*                                                                            */
19 /*  You should have received a copy of the GNU General Public License         */
20 /*  along with this program; if not, write to the Free Software               */
21 /*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
22 /*                                                                            */
23 /* ************************************************************************** */
24 
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28 
29 #include "include.h"
30 #include <stdlib.h>
31 #include <glib/gi18n.h>
32 
33 /*START_INCLUDE*/
34 #include "utils_prefs.h"
35 #include "dialog.h"
36 #include "grisbi_app.h"
37 #include "grisbi_prefs.h"
38 #include "gsb_file.h"
39 #include "gsb_dirs.h"
40 #include "parametres.h"
41 #include "structures.h"
42 #include "utils.h"
43 #include "utils_str.h"
44 #include "erreur.h"
45 /*END_INCLUDE*/
46 
47 /*START_STATIC*/
48 /*END_STATIC*/
49 
50 
51 /*START_EXTERN*/
52 /*END_EXTERN*/
53 
54 static GtkTreeIter *page_parent_iter;
55 
56 /******************************************************************************/
57 /* Private functions                                                          */
58 /******************************************************************************/
59 /**
60  *
61  *
62  * \param
63  *
64  * \return
65  **/
utils_prefs_fonts_get_css_data_for_font(gchar * fontname)66 static gchar *utils_prefs_fonts_get_css_data_for_font (gchar *fontname)
67 {
68 	gchar *data = NULL;
69 	gchar *pointer_bold = NULL;
70 	gchar *pointer_italic = NULL;
71 	gchar *tmp_name;
72 
73 	pointer_bold = g_strstr_len (fontname, -1, "Bold");
74 	if (pointer_bold)
75 	{
76 		tmp_name = g_strndup (fontname, (pointer_bold - fontname));
77 		pointer_italic = g_strstr_len (fontname, -1, "Italic");
78 		if (pointer_italic)
79 		{
80 			data = g_strconcat ("#font_label {font-family: ", tmp_name, "; font-weight: bold; font-style: italic;}",  NULL);
81 		}
82 		else
83 		{
84 			data = g_strconcat ("#font_label {font-family: ", tmp_name, "; font-weight: bold;}",  NULL);
85 		}
86 		g_free (tmp_name);
87 
88 		return data;
89 	}
90 	else
91 	{
92 		pointer_italic = g_strstr_len (fontname, -1, "Italic");
93 
94 		if (pointer_italic)
95 		{
96 			tmp_name = g_strndup (fontname, (pointer_italic - fontname));
97 			data = g_strconcat ("#font_label {font-family: ", tmp_name, "; font-style: italic;}",  NULL);
98 			g_free (tmp_name);
99 
100 			return data;
101 		}
102 		else
103 		{
104 			data = g_strconcat ("#font_label {font-family: ", fontname, "}", NULL);
105 
106 			return data;
107 		}
108 	}
109 
110 	return NULL;
111 }
112 
113 /**
114  * Update two labels according to font name, which is parsed to
115  * separate both name and size
116  *
117  * \param button	the font_button
118  * \param fontname 	a font name in the form "name, size" or "name,
119  *                 	attr, size"
120  */
utils_prefs_fonts_update_labels(GtkWidget * button,const gchar * fontname)121 static void utils_prefs_fonts_update_labels (GtkWidget *button,
122 											 const gchar *fontname)
123 {
124     GtkWidget *font_name_label;
125     GtkWidget *font_size_label;
126 	gchar *font_name;
127     gchar *font_size;
128 
129     font_name_label = g_object_get_data (G_OBJECT (button), "name_label");
130     font_size_label = g_object_get_data (G_OBJECT (button), "size_label");
131     if (fontname && strlen (fontname))
132     {
133 		GtkCssProvider *css_provider = NULL;
134 		GtkStyleContext *context;
135 		gchar *data;
136 		gchar *tmp_name;
137 		gchar *tmp_font;
138 
139 		font_name = my_strdup (fontname);
140 		tmp_name = font_name + strlen(font_name) - 1;
141 		while (g_ascii_isdigit(*tmp_name) ||
142 			   (*tmp_name) == '.')
143 			tmp_name --;
144 		tmp_font = tmp_name+1;
145 
146 		while (*tmp_name == ' ' ||
147 			   *tmp_name == ',')
148 		{
149 			*tmp_name=0;
150 			tmp_name--;
151 		}
152 
153 		font_size = g_strdup (tmp_font);
154 
155 		/* set the font for label */
156 		css_provider = g_object_get_data (G_OBJECT (button), "css_provider");
157 		if (!css_provider)
158 		{
159 			css_provider = gtk_css_provider_new ();
160 			g_object_set_data (G_OBJECT (button), "css_provider", css_provider);
161 		}
162 
163 		data = utils_prefs_fonts_get_css_data_for_font (font_name);
164 		gtk_css_provider_load_from_data (css_provider, data, -1, NULL);
165 		context = gtk_widget_get_style_context (font_name_label);
166 		gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (css_provider), GTK_STYLE_PROVIDER_PRIORITY_USER);
167 		g_free (data);
168     }
169     else
170     {
171 		GrisbiAppConf *a_conf;
172 
173 		font_name = my_strdup ("Monospace");
174 		font_size = g_strdup ("10");
175 		a_conf = (GrisbiAppConf *) grisbi_app_get_a_conf ();
176 		a_conf->custom_fonte_listes = FALSE;
177     }
178 
179     gtk_label_set_text (GTK_LABEL(font_name_label), font_name);
180 	g_free (font_name);
181 
182 	if (font_size && strlen (font_size))
183 	{
184 		gtk_label_set_text (GTK_LABEL(font_size_label), font_size);
185 		g_free (font_size);
186 	}
187 }
188 
189 /**
190  * callback called when click on the font button
191  * to change the font
192  *
193  * \param button
194  * \param fontname	a pointer to pointer to the font name to change
195  *
196  * \return FALSE
197  * */
utils_prefs_fonts_button_choose_font_clicked(GtkWidget * button,gchar ** fontname)198 static gboolean utils_prefs_fonts_button_choose_font_clicked (GtkWidget *button,
199                                                               gchar **fontname)
200 {
201     gchar *new_fontname;
202     GtkWidget *dialog;
203 	GtkWidget *prefs_dialog;
204     GCallback (*hook) (gchar *, gpointer);
205 
206 	prefs_dialog = grisbi_win_get_prefs_dialog (NULL);
207     dialog = gtk_font_chooser_dialog_new (_("Choosing font"), GTK_WINDOW (prefs_dialog));
208 
209     if (*fontname)
210 	{
211 		gtk_font_chooser_set_font (GTK_FONT_CHOOSER (dialog), *fontname);
212 	}
213     gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
214 
215     switch (gtk_dialog_run (GTK_DIALOG (dialog)))
216     {
217 		case GTK_RESPONSE_OK:
218 			new_fontname = gtk_font_chooser_get_font (GTK_FONT_CHOOSER (dialog));
219 			gtk_widget_destroy (dialog);
220 			utils_prefs_fonts_update_labels (button, new_fontname);
221 			break;
222 		default:
223 			gtk_widget_destroy (dialog);
224 			return FALSE;
225     }
226 
227     if (*fontname)
228         g_free (*fontname);
229     *fontname = new_fontname;
230 
231     hook = g_object_get_data (G_OBJECT (button), "hook");
232     if (hook)
233     {
234 		hook (new_fontname, g_object_get_data (G_OBJECT (button), "data"));
235     }
236 
237 	return FALSE;
238 }
239 
240 /******************************************************************************/
241 /* Public functions                                                           */
242 /******************************************************************************/
243 /**
244  * Function that makes a nice title with an optional icon.  It is
245  * mainly used to automate preference tabs with titles.
246  *
247  * \param title 			Title that will be displayed in window
248  * \param image_filename	Filename (relative or absolute) to an image in a file format
249  * 							recognized by gtk_image_new_from_file().  Use NULL if you don't
250  * 							want an image to be displayed
251  *
252  * \returns 				A pointer to a hbox widget that will contain the created
253  * 							widgets
254  */
utils_prefs_head_page_new_with_title_and_icon(const gchar * title,const gchar * image_filename)255 GtkWidget *utils_prefs_head_page_new_with_title_and_icon (const gchar *title,
256 														  const gchar *image_filename)
257 {
258     GtkWidget *hbox;
259 	GtkWidget*label;
260 	GtkWidget*image;
261 	GtkWidget*eb;
262 	gchar* tmp_str1;
263 	gchar* tmp_str2;
264 
265     eb = gtk_event_box_new ();
266     gtk_widget_set_name (eb, "grey_box");
267 	gtk_widget_set_margin_start (eb, MARGIN_BOX);
268 	gtk_widget_set_margin_end (eb, MARGIN_BOX);
269 	gtk_widget_set_margin_bottom (eb, MARGIN_BOTTOM);
270 
271     /* Title hbox */
272     hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, MARGIN_BOX);
273     gtk_widget_show (hbox);
274     gtk_container_add (GTK_CONTAINER (eb), hbox);
275     gtk_container_set_border_width (GTK_CONTAINER (hbox), MARGIN_BOX);
276 
277     /* Icon */
278     if (image_filename)
279     {
280 		gchar* tmp_str;
281 
282 		tmp_str = g_build_filename (gsb_dirs_get_pixmaps_dir (), image_filename, NULL);
283 		image = gtk_image_new_from_file (tmp_str);
284 		g_free (tmp_str);
285 		gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
286 		gtk_widget_show (image);
287     }
288 
289     /* Nice huge title */
290     label = gtk_label_new (title);
291     tmp_str1 = g_markup_escape_text (title, strlen (title));
292     tmp_str2 = g_strconcat ("<span size=\"x-large\" weight=\"bold\">",
293 							tmp_str1,
294 						    "</span>",
295 						    NULL);
296     gtk_label_set_markup (GTK_LABEL (label), tmp_str2);
297     g_free(tmp_str1);
298     g_free(tmp_str2);
299     gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
300     gtk_widget_show (label);
301 
302     return eb;
303 }
304 
305 /**
306  * ajoute une ligne dans le tree_model du panel de gauche de la fenêtre
307  * des préférences de grisbi ou des états
308  *
309  * \param
310  * \param
311  * \param
312  * \param
313  * \param
314  * \param
315  *
316  * \return
317  * */
utils_prefs_left_panel_add_line(GtkTreeStore * tree_model,GtkWidget * notebook,GtkWidget * child,const gchar * title,gint page)318 void utils_prefs_left_panel_add_line (GtkTreeStore *tree_model,
319 									  GtkWidget *notebook,
320 									  GtkWidget *child,
321 									  const gchar *title,
322 									  gint page)
323 {
324     GtkTreeIter iter1;
325     GtkTreeIter iter2;
326 
327     if (page == -1)
328     {
329 		if (page_parent_iter)
330 			gtk_tree_iter_free (page_parent_iter);
331 
332         /* append page groupe */
333         gtk_tree_store_append (GTK_TREE_STORE (tree_model), &iter1, NULL);
334         gtk_tree_store_set (GTK_TREE_STORE (tree_model),
335 							&iter1,
336 							LEFT_PANEL_TREE_TEXT_COLUMN, title,
337 							LEFT_PANEL_TREE_PAGE_COLUMN, -1,
338 							LEFT_PANEL_TREE_BOLD_COLUMN, 800,
339 							-1);
340 		page_parent_iter = gtk_tree_iter_copy (&iter1);
341     }
342     else
343     {
344         /* append page onglet*/
345 		gchar *tmp_title;
346 
347 		tmp_title = utils_str_break_form_name_field (title, TRUNC_FORM_FIELD);
348 		if (child)
349 		{
350             gtk_notebook_append_page (GTK_NOTEBOOK (notebook), child, gtk_label_new (tmp_title));
351 		}
352 
353         gtk_tree_store_append (GTK_TREE_STORE (tree_model), &iter2, page_parent_iter);
354         gtk_tree_store_set (GTK_TREE_STORE (tree_model),
355 							&iter2,
356 							LEFT_PANEL_TREE_TEXT_COLUMN, tmp_title,
357 							LEFT_PANEL_TREE_PAGE_COLUMN, page,
358 							LEFT_PANEL_TREE_BOLD_COLUMN, 400,
359 							-1);
360 		g_free (tmp_title);
361     }
362 }
363 
364 /**
365  * selectionne une page
366  *
367  * \param
368  * \param
369  * \param
370  *
371  * \return
372  */
utils_prefs_left_panel_tree_view_select_page(GtkWidget * tree_view,GtkWidget * notebook,gint page)373 gboolean utils_prefs_left_panel_tree_view_select_page (GtkWidget *tree_view,
374 													   GtkWidget *notebook,
375 													   gint page)
376 {
377     GtkTreeModel *model;
378     GtkTreeIter parent_iter;
379 
380     model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));
381 
382     if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &parent_iter))
383         return FALSE;
384 
385     do
386     {
387         GtkTreeIter iter;
388 
389         if (gtk_tree_model_iter_children (GTK_TREE_MODEL (model), &iter, &parent_iter))
390         {
391             do
392             {
393                 gint tmp_page;
394 
395                 gtk_tree_model_get (GTK_TREE_MODEL (model),
396 									&iter,
397 									LEFT_PANEL_TREE_PAGE_COLUMN, &tmp_page,
398 									-1);
399 
400                 if (tmp_page == page)
401                 {
402                     GtkTreeSelection *sel;
403 					GtkTreePath *path;
404 
405                     sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
406                     gtk_tree_selection_select_iter (sel, &iter);
407 					path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter);
408 					gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (tree_view), path, NULL, FALSE, 0, 0);
409                     gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), page);
410 
411                     break;
412                 }
413             }
414             while (gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter));
415         }
416     }
417     while (gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &parent_iter));
418 
419     /* return */
420     return FALSE;
421 }
422 
423 /**
424  * indique si la ligne choisie peut être sélectionnée
425  *
426  * \param selection
427  * \param model
428  * \param chemin de la ligne à tester
429  * \param TRUE si la ligne est déja sélectionnée
430  * \param data transmise à la fonction
431  *
432  * \return selectable
433  */
utils_prefs_left_panel_tree_view_selectable_func(GtkTreeSelection * selection,GtkTreeModel * model,GtkTreePath * path,gboolean path_currently_selected,gpointer data)434 gboolean utils_prefs_left_panel_tree_view_selectable_func (GtkTreeSelection *selection,
435 														   GtkTreeModel *model,
436 														   GtkTreePath *path,
437 														   gboolean path_currently_selected,
438 														   gpointer data)
439 {
440     GtkTreeIter iter;
441     gint selectable;
442 
443     gtk_tree_model_get_iter (model, &iter, path);
444     gtk_tree_model_get (model, &iter, 1, &selectable, -1);
445 
446     return (selectable != -1);
447 }
448 
449 /**
450  *
451  *
452  * \param
453  * \param
454  *
455  * \return
456  */
utils_prefs_left_panel_tree_view_selection_changed(GtkTreeSelection * selection,GtkWidget * notebook)457 gboolean utils_prefs_left_panel_tree_view_selection_changed (GtkTreeSelection *selection,
458 															 GtkWidget *notebook)
459 {
460     GtkTreeModel *model;
461     GtkTreeIter iter;
462     gint selected;
463 
464     if (! gtk_tree_selection_get_selected (selection, &model, &iter))
465 	{
466         return (FALSE);
467 	}
468 
469     gtk_tree_model_get (model, &iter, 1, &selected, -1);
470     gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), selected);
471 
472     /* return */
473     return FALSE;
474 }
475 
476 /**
477  * Create a grid with a nice bold title and content slightly indented.
478  * All content is packed vertically in a GtkGrid.  The paddingbox is
479  * also packed in its parent.
480  *
481  * \param parent Parent widget to pack paddinggrid in
482  * \param fill Give all available space to padding box or not
483  * \param title Title to display on top of the paddingbox
484  *
485  * \return
486  */
utils_prefs_paddinggrid_new_with_title(GtkWidget * parent,const gchar * title)487 GtkWidget *utils_prefs_paddinggrid_new_with_title (GtkWidget *parent,
488                                                    const gchar *title)
489 {
490     GtkWidget *vbox;
491     GtkWidget *paddinggrid;
492     GtkWidget *label;
493 	gchar* tmp_str;
494 
495     vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, MARGIN_BOX);
496 
497     if (GTK_IS_BOX (parent))
498         gtk_box_pack_start (GTK_BOX (parent), vbox, FALSE, FALSE, 0);
499 
500     /* Creating label */
501     label = gtk_label_new (NULL);
502     utils_labels_set_alignment (GTK_LABEL (label), 0, 1);
503 	gtk_widget_set_margin_start (label, MARGIN_BOX);
504     gtk_widget_show (label);
505 
506     tmp_str = g_markup_printf_escaped ("<span weight=\"bold\">%s</span>", title);
507     gtk_label_set_markup (GTK_LABEL (label), tmp_str);
508     g_free (tmp_str);
509 
510     gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
511     gtk_widget_show (label);
512 
513     /* Then make the grid itself */
514     paddinggrid = gtk_grid_new ();
515     gtk_widget_set_margin_start (paddinggrid, MARGIN_PADDING_BOX);
516     gtk_grid_set_column_spacing (GTK_GRID (paddinggrid), 5);
517     gtk_grid_set_row_spacing (GTK_GRID (paddinggrid), 5);
518 
519     gtk_box_pack_start (GTK_BOX (vbox), paddinggrid, FALSE, FALSE, 0);
520 
521     if (GTK_IS_BOX (parent))
522         gtk_box_set_spacing (GTK_BOX (parent), 18);
523 
524     return paddinggrid;
525 }
526 
527 /**
528  * Set a boolean integer to the value of a checkbutton.  Normally called
529  * via a GTK "toggled" signal handler.
530  *
531  * \param checkbutton a pointer to a checkbutton widget.
532  * \param value to change
533  *
534  * \return
535  */
utils_prefs_page_checkbutton_changed(GtkToggleButton * checkbutton,gboolean * value)536 void utils_prefs_page_checkbutton_changed (GtkToggleButton *checkbutton,
537 										   gboolean *value)
538 {
539     if (value)
540     {
541 		GtkWidget *widget = NULL;
542 
543         *value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton));
544 
545         widget = g_object_get_data (G_OBJECT (checkbutton), "widget");
546         if (widget && GTK_IS_WIDGET (widget))
547         {
548 			if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton)))
549 				gtk_widget_set_sensitive (GTK_WIDGET (widget), TRUE);
550             else
551                 gtk_widget_set_sensitive (GTK_WIDGET (widget), FALSE);
552         }
553 
554     }
555 }
556 
557 /**
558  * called when choose a new directory for the account files or backup
559  *
560  * \param button 		the GtkFileChooserButton
561  * \param dirname		new directory
562  *
563  * \return FALSE
564  * */
utils_prefs_page_dir_chosen(GtkWidget * button,gchar * dirname)565 void utils_prefs_page_dir_chosen (GtkWidget *button,
566 								  gchar *dirname)
567 {
568     gchar *tmp_dir;
569 
570     g_signal_handlers_block_by_func (button,
571 									 G_CALLBACK (utils_prefs_page_dir_chosen),
572 									 dirname);
573 
574     tmp_dir = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (button));
575 
576 	if (strcmp (dirname, "backup_path") == 0)
577 	{
578         gsb_file_set_backup_path (tmp_dir);
579 	}
580 	else if (strcmp (dirname, "import_directory") == 0)
581 	{
582 		GrisbiAppConf *a_conf;
583 
584 		a_conf = (GrisbiAppConf *) grisbi_app_get_a_conf ();
585 		if (a_conf->import_directory)
586 			g_free (a_conf->import_directory);
587 		a_conf->import_directory = my_strdup (tmp_dir);
588 	}
589 
590     g_signal_handlers_unblock_by_func (button,
591 									   G_CALLBACK (utils_prefs_page_dir_chosen),
592 									   dirname);
593 
594 	utils_prefs_gsb_file_set_modified ();
595 
596 	/* memory free */
597     g_free (tmp_dir);
598 }
599 
600 /**
601  *
602  *
603  * \param
604  *
605  * \return
606  * */
utils_prefs_gsb_file_set_modified(void)607 void utils_prefs_gsb_file_set_modified (void)
608 {
609     gsb_file_set_modified (TRUE);
610 }
611 
612 /**
613  * set nb_max_derniers_fichiers_ouverts
614  *
615  * \param spinbutton 			a pointer to a spinbutton widget.
616  * \param value 				value to change
617  * \return
618  * */
utils_prefs_spinbutton_changed(GtkSpinButton * spinbutton,gint * value)619 void utils_prefs_spinbutton_changed (GtkSpinButton *spinbutton,
620 									 gint *value)
621 {
622     if (value)
623     {
624         GtkWidget *button = NULL;
625 
626         *value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spinbutton));
627 
628         button = g_object_get_data (G_OBJECT (spinbutton), "button");
629         if (button && GTK_IS_TOGGLE_BUTTON (button))
630         {
631             if (gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spinbutton)) == 0)
632                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE);
633             else
634                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
635         }
636     }
637 }
638 
639 /**
640  * create a button displaying the name and the size of the font
641  * clicking on that button show a GtkFontSelectionDialog to change the font
642  * and update the fontname
643  * !! the fontname can be changed and freed so *fontname must not be const
644  *
645  * \param fontname	a pointer to a pointer to the name of the font
646  * 			to change with the selection of the user
647  * \param hook		An optional function to execute when the font has changed
648  * 			(hook must be func (gchar new_font_name, gpointer data))
649  * \param data		An optional pointer to pass to hooks.
650  *
651  * \return a GtkButton
652  * */
utils_prefs_fonts_create_button(gchar ** fontname,GCallback hook,gpointer data)653 GtkWidget *utils_prefs_fonts_create_button (gchar **fontname,
654 											GCallback hook,
655 											gpointer data)
656 {
657     GtkWidget *font_button;
658     GtkWidget *hbox_font;
659     GtkWidget *font_name_label;
660     GtkWidget *font_size_label;
661 
662 
663     font_button = gtk_button_new ();
664     g_signal_connect (G_OBJECT (font_button),
665 					  "clicked",
666 					  G_CALLBACK (utils_prefs_fonts_button_choose_font_clicked),
667 					  fontname);
668 
669     hbox_font = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, MARGIN_BOX);
670     gtk_container_add (GTK_CONTAINER(font_button), hbox_font);
671 
672     font_name_label = gtk_label_new (NULL);
673 	gtk_widget_set_name (font_name_label, "label_gsetting_option");
674     gtk_box_pack_start (GTK_BOX (hbox_font), font_name_label, TRUE, TRUE, 5);
675 
676     font_size_label = gtk_label_new (NULL);
677 	gtk_widget_set_name (font_size_label, "label_gsetting_option");
678     gtk_box_pack_start (GTK_BOX (hbox_font), font_size_label, FALSE, FALSE, 5);
679     g_object_set_data (G_OBJECT (font_button), "hook", hook);
680     g_object_set_data (G_OBJECT (font_button), "data", data);
681     g_object_set_data (G_OBJECT (font_button), "name_label", font_name_label);
682     g_object_set_data (G_OBJECT (font_button), "size_label", font_size_label);
683 
684     utils_prefs_fonts_update_labels (font_button, *fontname);
685 
686     return font_button;
687 }
688 
689 /**
690  *
691  *
692  * \param
693  *
694  * \return		new combobox
695  **/
utils_prefs_create_combo_list_indisponible(void)696 GtkWidget *utils_prefs_create_combo_list_indisponible (void)
697 {
698 	GtkTreeIter iter;
699     GtkListStore *store;
700     GtkCellRenderer *renderer;
701     GtkWidget *combobox;
702 
703     combobox = gtk_combo_box_new ();
704     store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
705 	gtk_list_store_append (GTK_LIST_STORE (store), &iter);
706 	gtk_list_store_set (store, &iter, 0, _("Not available"), 1, -1, -1);
707 
708     gtk_combo_box_set_model (GTK_COMBO_BOX (combobox), GTK_TREE_MODEL (store));
709     gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 0);
710 
711     renderer = gtk_cell_renderer_text_new ();
712     gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE);
713     gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "text", 0, NULL);
714 
715     return combobox;
716 }
717 
718 /**
719  *
720  *
721  * \param
722  *
723  * \return
724  **/
utils_prefs_close_prefs_from_theme(void)725 void utils_prefs_close_prefs_from_theme (void)
726 {
727 	GtkWidget *prefs;
728 
729 	prefs = grisbi_win_get_prefs_dialog (NULL);
730 	if (GRISBI_IS_PREFS (prefs))
731 	{
732 		gtk_dialog_response (GTK_DIALOG (prefs), GTK_RESPONSE_CANCEL);
733 	}
734 }
735 
736 /**
737  * Warns that there is no coming back if password is forgotten when
738  * encryption is activated.
739  *
740  * \param checkbox  Checkbox that triggered event.
741  * \param data      Unused.
742  *
743  * \return          FALSE
744  **/
utils_prefs_encryption_toggled(GtkWidget * checkbox,gpointer data)745 gboolean utils_prefs_encryption_toggled (GtkWidget *checkbox,
746 										 gpointer data)
747 {
748 #ifdef HAVE_SSL
749 	GrisbiWinRun *w_run;
750 
751 	w_run = grisbi_win_get_w_run ();
752     if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox)))
753     {
754         dialogue_message ("encryption-is-irreversible");
755         w_run->new_crypted_file = TRUE;
756     }
757 	else
758 		w_run->new_crypted_file = FALSE;
759 #else
760 	gchar *text = _("This build of Grisbi does not support encryption.\n"
761 					"Please recompile Grisbi with OpenSSL encryption enabled.");
762 	gchar *hint;
763 
764 	hint = g_strdup_printf (_("Could not encrypt file"));
765 	dialogue_error_hint (text, hint);
766 	g_signal_handlers_block_by_func (G_OBJECT (checkbox),
767 									 G_CALLBACK (utils_prefs_encryption_toggled),
768 									 data);
769 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), FALSE);
770 
771 	g_free (hint);
772 	g_signal_handlers_unblock_by_func (G_OBJECT (checkbox),
773 									   G_CALLBACK (utils_prefs_encryption_toggled),
774 									   data);
775 #endif
776     return FALSE;
777 }
778 
779 /**
780  *
781  *
782  * \param
783  *
784  * \return
785  **/
utils_prefs_page_notebook_switch_page(GtkNotebook * notebook,GtkWidget * page,guint page_num,guint * value)786 void utils_prefs_page_notebook_switch_page (GtkNotebook *notebook,
787 											GtkWidget *page,
788 											guint page_num,
789 											guint *value)
790 {
791 	if (value)
792     {
793 		*value = page_num;
794 	}
795 }
796 
797 /**
798  *
799  *
800  * \param
801  *
802  * \return
803  **/
804 /* Local Variables: */
805 /* c-basic-offset: 4 */
806 /* End: */
807