1 /* *******************************************************************************/
2 /*                                 GRISBI                                        */
3 /*              Programme de gestion financière personnelle                      */
4 /*                              license : GPLv2                                  */
5 /*                                                                               */
6 /*     Copyright (C)    2000-2008 Cédric Auger (cedric@grisbi.org)               */
7 /*                      2003-2008 Benjamin Drieu (bdrieu@april.org)              */
8 /*          2008-2020 Pierre Biava (grisbi@pierre.biava.name)                    */
9 /*          https://www.grisbi.org                                               */
10 /*                                                                               */
11 /*     This program is free software; you can redistribute it and/or modify      */
12 /*     it under the terms of the GNU General Public License as published by      */
13 /*     the Free Software Foundation; either version 2 of the License, or         */
14 /*     (at your option) any later version.                                       */
15 /*                                                                               */
16 /*     This program is distributed in the hope that it will be useful,           */
17 /*     but WITHOUT ANY WARRANTY; without even the implied warranty of            */
18 /*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             */
19 /*     GNU General Public License for more details.                              */
20 /*                                                                               */
21 /*     You should have received a copy of the GNU General Public License         */
22 /*     along with this program; if not, write to the Free Software               */
23 /*     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
24 /*                                                                               */
25 /* *******************************************************************************/
26 
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30 
31 #ifdef HAVE_CONFIG_H
32 #include "config.h"
33 #endif
34 
35 #include <errno.h>
36 #include <glib/gstdio.h>
37 #include <glib/gi18n.h>
38 
39 /*START_INCLUDE*/
40 #include "prefs_page_options_ope.h"
41 #include "grisbi_app.h"
42 #include "gsb_file.h"
43 #include "gsb_rgba.h"
44 #include "gsb_transactions_list.h"
45 #include "navigation.h"
46 #include "structures.h"
47 #include "utils_prefs.h"
48 #include "erreur.h"
49 
50 /*END_INCLUDE*/
51 
52 /*START_EXTERN*/
53 /*END_EXTERN*/
54 
55 typedef struct _PrefsPageOptionsOpePrivate   PrefsPageOptionsOpePrivate;
56 
57 struct _PrefsPageOptionsOpePrivate
58 {
59 	GtkWidget *			vbox_options_ope;
60 
61 	GtkWidget *			checkbutton_retient_affichage_par_compte;
62     GtkWidget *			checkbutton_show_transaction_gives_balance;
63     GtkWidget *			checkbutton_show_transaction_selected_in_form;
64 	GtkWidget *			combo_display_one_line;
65 	GtkWidget *			combo_display_two_lines;
66 	GtkWidget *			combo_display_three_lines;
67 	GtkWidget *			combo_transactions_list_primary_sorting;
68 	GtkWidget *			combo_transactions_list_secondary_sorting;
69     GtkWidget *         grid_display_modes;
70 
71 };
72 
G_DEFINE_TYPE_WITH_PRIVATE(PrefsPageOptionsOpe,prefs_page_options_ope,GTK_TYPE_BOX)73 G_DEFINE_TYPE_WITH_PRIVATE (PrefsPageOptionsOpe, prefs_page_options_ope, GTK_TYPE_BOX)
74 
75 /******************************************************************************/
76 /* Private functions                                                          */
77 /******************************************************************************/
78 /**
79  * called when we change a button for the display mode
80  *
81  * \param button 	the combo box which changed
82  * \param line_ptr	a gint* which is the line of the button (ie 1 line mode, 2 lines or 3 lines)
83  *
84  * \return FALSE
85  **/
86 static gboolean prefs_page_options_ope_display_mode_button_changed (GtkWidget *button,
87 																	gint *line_ptr)
88 {
89     gint line = GPOINTER_TO_INT (line_ptr);
90 	GrisbiWinRun *w_run;
91 
92 	w_run = (GrisbiWinRun *) grisbi_win_get_w_run ();
93 
94     switch (line)
95     {
96 	case 0:
97 	    /* 1 line visible mode */
98 	    w_run->display_one_line = gtk_combo_box_get_active (GTK_COMBO_BOX (button));
99 	    break;
100 	case 1:
101 	    /* 2 lines visibles mode */
102 	    w_run->display_two_lines = gtk_combo_box_get_active (GTK_COMBO_BOX (button));
103 	    break;
104 	case 2:
105 	    /* 3 lines visibles mode */
106 	    w_run->display_three_lines = gtk_combo_box_get_active (GTK_COMBO_BOX (button));
107 	    break;
108     }
109 
110     /* update the visible account */
111     gsb_transactions_list_update_tree_view (gsb_gui_navigation_get_current_account (), TRUE);
112 
113     gsb_file_set_modified (TRUE);
114 
115     return FALSE;
116 }
117 
118 /**
119  *
120  *
121  * \param
122  *
123  * \return
124  **/
prefs_page_options_ope_display_sort_changed(GtkComboBox * widget,gint * pointeur)125 static gboolean prefs_page_options_ope_display_sort_changed (GtkComboBox *widget,
126 															 gint *pointeur)
127 {
128     gint page_number;
129     gint account_nb;
130     gint value = 0;
131     gint sort_type = 0;
132 	GrisbiAppConf *a_conf;
133 
134 	a_conf = (GrisbiAppConf *) grisbi_app_get_a_conf ();
135 
136     page_number = gsb_gui_navigation_get_current_page ();
137     value = gtk_combo_box_get_active (widget);
138     sort_type = GPOINTER_TO_INT (pointeur);
139 
140     switch (sort_type)
141     {
142         case PRIMARY_SORT:
143             a_conf->transactions_list_primary_sorting = value;
144             break;
145         case SECONDARY_SORT:
146             a_conf->transactions_list_secondary_sorting = value;
147             break;
148     }
149     gsb_file_set_modified (TRUE);
150 
151     switch (page_number)
152     {
153         case GSB_ACCOUNT_PAGE:
154             account_nb = gsb_gui_navigation_get_current_account ();
155             if (account_nb != -1)
156                 gsb_transactions_list_update_tree_view (account_nb, TRUE);
157             break;
158     }
159 
160     return FALSE;
161 }
162 
163 /**
164  *
165  *
166  * \param
167  *
168  * \return
169  **/
prefs_page_options_ope_init_combo_sorting(PrefsPageOptionsOpe * page,GrisbiAppConf * a_conf)170 static void prefs_page_options_ope_init_combo_sorting (PrefsPageOptionsOpe *page,
171 													   GrisbiAppConf *a_conf)
172 {
173 	GtkListStore *store = NULL;
174 	GtkTreeIter iter;
175 	GtkCellRenderer *renderer;
176 	const gchar *str_color;
177     gchar *options_tri_primaire[] = {
178 		_("Sort by value date (if fail, try with the date)"),
179 		_("Sort by value date and then by date"),
180 		_("Forced sort by transaction date"),
181 		NULL
182     };
183     gchar *options_tri_secondaire[] = {
184 		_("Sort by transaction number"),
185 		_("Sort by type of amount (credit debit)"),
186 		_("Sort by payee name (if fail, by transaction number)"),
187 		_("Sort by date and then by transaction number"),
188 		NULL
189     };
190 	gint i = 0;
191 	PrefsPageOptionsOpePrivate *priv;
192 
193 	devel_debug (NULL);
194 	priv = prefs_page_options_ope_get_instance_private (page);
195 
196 	str_color = gsb_rgba_get_couleur_to_string ("text_gsetting_option_normal");
197 
198 	/* Primary sorting option for the transactions */
199 	store = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING);
200 	for (i = 0; i < 3; i++)
201 	{
202         gtk_list_store_append (store, &iter);
203         gtk_list_store_set (store, &iter, 0, options_tri_primaire[i], 1, i, 2, str_color, -1);
204     }
205 
206 	gtk_combo_box_set_model (GTK_COMBO_BOX (priv->combo_transactions_list_primary_sorting),
207 							 GTK_TREE_MODEL (store));
208 	renderer = gtk_cell_renderer_text_new ();
209 	gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->combo_transactions_list_primary_sorting), renderer, FALSE);
210 	gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (priv->combo_transactions_list_primary_sorting),
211 									renderer,
212 									"text", 0,
213 									"foreground", 2,
214 									NULL);
215 	gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combo_transactions_list_primary_sorting),
216 							  a_conf->transactions_list_primary_sorting);
217 
218 	g_signal_connect (G_OBJECT (priv->combo_transactions_list_primary_sorting),
219 					  "changed",
220 					  G_CALLBACK (prefs_page_options_ope_display_sort_changed),
221 					  GINT_TO_POINTER (PRIMARY_SORT));
222 
223 	/* Secondary sorting option for the transactions */
224 	store = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING);
225 	for (i = 0; i < 4; i++)
226 	{
227         gtk_list_store_append (store, &iter);
228         gtk_list_store_set (store, &iter, 0, options_tri_secondaire[i], 1, i, 2, str_color, -1);
229     }
230 
231 	gtk_combo_box_set_model (GTK_COMBO_BOX (priv->combo_transactions_list_secondary_sorting),
232 							 GTK_TREE_MODEL (store));
233 	renderer = gtk_cell_renderer_text_new ();
234 	gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->combo_transactions_list_secondary_sorting), renderer, FALSE);
235 	gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (priv->combo_transactions_list_secondary_sorting),
236 									renderer,
237 									"text", 0,
238 									"foreground", 2,
239 									NULL);
240 	gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combo_transactions_list_secondary_sorting),
241 							  a_conf->transactions_list_secondary_sorting);
242 
243 	g_signal_connect (G_OBJECT (priv->combo_transactions_list_secondary_sorting),
244 					  "changed",
245 					  G_CALLBACK (prefs_page_options_ope_display_sort_changed),
246 					  GINT_TO_POINTER (SECONDARY_SORT));
247 
248 	g_free ((gpointer)str_color);
249 }
250 
251 /**
252  * Création de la page de gestion des options_ope
253  *
254  * \param prefs
255  *
256  * \return
257  */
prefs_page_options_ope_setup_options_ope_page(PrefsPageOptionsOpe * page)258 static void prefs_page_options_ope_setup_options_ope_page (PrefsPageOptionsOpe *page)
259 {
260 	GtkWidget *head_page;
261 	gboolean is_loading;
262 	GrisbiAppConf *a_conf;
263 	GrisbiWinEtat *w_etat;
264 	GrisbiWinRun *w_run;
265 	PrefsPageOptionsOpePrivate *priv;
266 
267 	devel_debug (NULL);
268 	priv = prefs_page_options_ope_get_instance_private (page);
269 	a_conf = (GrisbiAppConf *) grisbi_app_get_a_conf ();
270 	w_etat = (GrisbiWinEtat *) grisbi_win_get_w_etat ();
271 	w_run = (GrisbiWinRun *) grisbi_win_get_w_run ();
272 	is_loading = grisbi_win_file_is_loading ();
273 
274 	/* On récupère le nom de la page */
275 	head_page = utils_prefs_head_page_new_with_title_and_icon (_("Transaction list behavior"),
276 															   "gsb-transaction-list-32.png");
277 	gtk_box_pack_start (GTK_BOX (priv->vbox_options_ope), head_page, FALSE, FALSE, 0);
278 	gtk_box_reorder_child (GTK_BOX (priv->vbox_options_ope), head_page, 0);
279 
280     /* set checkbuttons */
281     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbutton_retient_affichage_par_compte),
282 								  w_etat->retient_affichage_par_compte);
283     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbutton_show_transaction_gives_balance),
284 								  a_conf->show_transaction_gives_balance);
285     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbutton_show_transaction_selected_in_form),
286 								  a_conf->show_transaction_selected_in_form);
287 
288 	/* set combos sorting */
289 	prefs_page_options_ope_init_combo_sorting (page, a_conf);
290 
291 	/* set combo display lines */
292 	gtk_combo_box_set_active ( GTK_COMBO_BOX (priv->combo_display_one_line), w_run->display_one_line);
293 	gtk_combo_box_set_active ( GTK_COMBO_BOX (priv->combo_display_two_lines), w_run->display_two_lines);
294 	gtk_combo_box_set_active ( GTK_COMBO_BOX (priv->combo_display_three_lines), w_run->display_three_lines);
295 
296 
297 	if (!is_loading)
298 	{
299 		gtk_widget_set_sensitive (priv->checkbutton_retient_affichage_par_compte, FALSE);
300 		gtk_widget_set_sensitive (priv->grid_display_modes, FALSE);
301 	}
302 
303     /* Connect signal */
304     g_signal_connect (G_OBJECT (priv->combo_display_one_line),
305 					  "changed",
306 					  G_CALLBACK (prefs_page_options_ope_display_mode_button_changed),
307 					  GINT_TO_POINTER (0));
308     g_signal_connect (G_OBJECT (priv->combo_display_two_lines),
309 					  "changed",
310 					  G_CALLBACK (prefs_page_options_ope_display_mode_button_changed),
311 					  GINT_TO_POINTER (1));
312     g_signal_connect (G_OBJECT (priv->combo_display_three_lines),
313 					  "changed",
314 					  G_CALLBACK (prefs_page_options_ope_display_mode_button_changed),
315 					  GINT_TO_POINTER (2));
316 
317     g_signal_connect (priv->checkbutton_retient_affichage_par_compte,
318 					  "toggled",
319 					  G_CALLBACK (utils_prefs_page_checkbutton_changed),
320 					  &w_etat->retient_affichage_par_compte);
321     g_signal_connect (priv->checkbutton_show_transaction_gives_balance,
322 					  "toggled",
323 					  G_CALLBACK (utils_prefs_page_checkbutton_changed),
324 					  &a_conf->show_transaction_gives_balance);
325     g_signal_connect (priv->checkbutton_show_transaction_selected_in_form,
326 					  "toggled",
327 					  G_CALLBACK (utils_prefs_page_checkbutton_changed),
328 					  &a_conf->show_transaction_selected_in_form);
329 }
330 
331 /******************************************************************************/
332 /* Fonctions propres à l'initialisation des fenêtres                          */
333 /******************************************************************************/
prefs_page_options_ope_init(PrefsPageOptionsOpe * page)334 static void prefs_page_options_ope_init (PrefsPageOptionsOpe *page)
335 {
336 	gtk_widget_init_template (GTK_WIDGET (page));
337 
338 	prefs_page_options_ope_setup_options_ope_page (page);
339 }
340 
prefs_page_options_ope_dispose(GObject * object)341 static void prefs_page_options_ope_dispose (GObject *object)
342 {
343 	G_OBJECT_CLASS (prefs_page_options_ope_parent_class)->dispose (object);
344 }
345 
prefs_page_options_ope_class_init(PrefsPageOptionsOpeClass * klass)346 static void prefs_page_options_ope_class_init (PrefsPageOptionsOpeClass *klass)
347 {
348 	G_OBJECT_CLASS (klass)->dispose = prefs_page_options_ope_dispose;
349 
350 	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass),
351 												 "/org/gtk/grisbi/ui/prefs_page_options_ope.ui");
352 
353 	gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), PrefsPageOptionsOpe, vbox_options_ope);
354 	gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass),
355 												  PrefsPageOptionsOpe,
356 												  checkbutton_retient_affichage_par_compte);
357 	gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass),
358 												  PrefsPageOptionsOpe,
359 												  checkbutton_show_transaction_gives_balance);
360 	gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass),
361 												  PrefsPageOptionsOpe,
362 												  checkbutton_show_transaction_selected_in_form);
363 	gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass),
364 												  PrefsPageOptionsOpe,
365 												  combo_display_one_line);
366 	gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass),
367 												  PrefsPageOptionsOpe,
368 												  combo_display_two_lines);
369 	gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass),
370 												  PrefsPageOptionsOpe,
371 												  combo_display_three_lines);
372 	gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass),
373 												  PrefsPageOptionsOpe,
374 												  combo_transactions_list_primary_sorting);
375 	gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass),
376 												  PrefsPageOptionsOpe,
377 												  combo_transactions_list_secondary_sorting);
378 	gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), PrefsPageOptionsOpe, grid_display_modes);
379 }
380 
381 /******************************************************************************/
382 /* Public functions                                                           */
383 /******************************************************************************/
384 /**
385  *
386  *
387  * \param
388  *
389  * \return
390  **/
prefs_page_options_ope_new(GrisbiPrefs * win)391 PrefsPageOptionsOpe *prefs_page_options_ope_new (GrisbiPrefs *win)
392 {
393   return g_object_new (PREFS_PAGE_OPTIONS_OPE_TYPE, NULL);
394 }
395 
396 /**
397  *
398  *
399  * \param
400  *
401  * \return
402  **/
403 /* Local Variables: */
404 /* c-basic-offset: 4 */
405 /* End: */
406 
407