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 /* http://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_msg_warning.h"
41 #include "dialog.h"
42 #include "grisbi_app.h"
43 #include "gsb_file.h"
44 #include "mouse.h"
45 #include "structures.h"
46 #include "utils.h"
47 #include "utils_prefs.h"
48 #include "erreur.h"
49 /*END_INCLUDE*/
50
51 /*START_EXTERN*/
52 /*END_EXTERN*/
53
54 typedef struct _PrefsPageMsgWarningPrivate PrefsPageMsgWarningPrivate;
55
56 struct _PrefsPageMsgWarningPrivate
57 {
58 GtkWidget * vbox_msg_warning;
59
60 GtkWidget * checkbutton_show_tip;
61 //~ GtkWidget * grid_display_msg;
62 GtkWidget * sw_display_msg;
63 GtkWidget * treeview_display_msg;
64
65 };
66
G_DEFINE_TYPE_WITH_PRIVATE(PrefsPageMsgWarning,prefs_page_msg_warning,GTK_TYPE_BOX)67 G_DEFINE_TYPE_WITH_PRIVATE (PrefsPageMsgWarning, prefs_page_msg_warning, GTK_TYPE_BOX)
68
69 /******************************************************************************/
70 /* Private functions */
71 /******************************************************************************/
72 /**
73 * called when we press a button on the list
74 *
75 * \param tree_view
76 * \param ev
77 *
78 * \return FALSE
79 **/
80 static gboolean prefs_page_msg_warning_list_button_press (GtkWidget *tree_view,
81 GdkEventButton *ev)
82 {
83 if (ev->button == LEFT_BUTTON)
84 {
85 GtkTreePath *path = NULL;
86
87 g_signal_handlers_block_by_func (tree_view, prefs_page_msg_warning_list_button_press, NULL);
88 if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (tree_view), ev->x, ev->y, &path, NULL, NULL, NULL))
89 {
90 GtkTreeModel *model;
91 GtkTreeIter iter;
92 gint position;
93 ConditionalMsg *warning;
94
95 warning = (ConditionalMsg*) dialogue_get_tab_warning_msg ();
96
97 /* Get toggled iter */
98 model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));
99 gtk_tree_model_get_iter (model, &iter, path);
100
101 gtk_tree_model_get (GTK_TREE_MODEL(model), &iter, 2, &position, -1);
102 (warning+position)->hidden = !(warning+position)->hidden;
103
104 /* Set new value */
105 gtk_tree_store_set (GTK_TREE_STORE (model), &iter, 0, !(warning+position)->hidden, -1);
106 }
107 gtk_tree_path_free (path);
108 g_signal_handlers_unblock_by_func (tree_view, prefs_page_msg_warning_list_button_press, NULL);
109 }
110 return FALSE;
111 }
112
113 /**
114 *
115 *
116 * \param
117 *
118 * \return
119 **/
prefs_page_msg_warning_fill_model(GtkTreeModel * model)120 static void prefs_page_msg_warning_fill_model (GtkTreeModel *model)
121 {
122 gchar *tmp_str;
123 gint i;
124 gboolean is_loading;
125 ConditionalMsg *warning;
126
127 warning = (ConditionalMsg*) dialogue_get_tab_warning_msg ();
128 is_loading = grisbi_win_file_is_loading ();
129
130 for (i = 0; (warning+i)->name; i++)
131 {
132 GtkTreeIter iter;
133
134 if (g_utf8_collate ((warning+i)->name, "account-already-opened") == 0)
135 {
136 /* on récupère le nom du fichier si un fichier est chargé */
137 if (is_loading)
138 {
139 gchar *filename;
140
141 filename = g_path_get_basename (grisbi_win_get_filename (NULL));
142 tmp_str = g_strdup_printf (_((warning+i)->hint), filename);
143 g_free (filename);
144 }
145 else
146 {
147 tmp_str = g_strdup (_("No file loading"));
148 }
149 }
150 else if (g_utf8_collate ((warning+i)->name, "development-version") == 0)
151 tmp_str = g_strdup_printf (_((warning+i)->hint), VERSION);
152 else
153 tmp_str = g_strdup (_((warning+i)->hint));
154
155 gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
156 gtk_tree_store_set (GTK_TREE_STORE (model),
157 &iter,
158 0, !(warning+i)->hidden,
159 1, tmp_str,
160 2, i,
161 -1);
162
163 g_free (tmp_str);
164 }
165 }
166
167 /**
168 *
169 *
170 * \param
171 *
172 * \return
173 **/
prefs_page_msg_warning_create_tree_view(PrefsPageMsgWarning * page)174 static GtkWidget *prefs_page_msg_warning_create_tree_view (PrefsPageMsgWarning *page)
175 {
176 GtkWidget *treeview;
177 GtkTreeModel *model;
178 GtkCellRenderer *cell;
179 GtkTreeViewColumn *column;
180
181 /* create the model */
182 model = GTK_TREE_MODEL(gtk_tree_store_new (4, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INT, GDK_TYPE_RGBA));
183
184 /* create the treeview */
185 treeview = gtk_tree_view_new();
186 gtk_widget_set_name (treeview, "gsettings_tree_view");
187 gtk_widget_set_hexpand (treeview, TRUE);
188 gtk_widget_set_vexpand (treeview, TRUE);
189
190 gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), GTK_TREE_MODEL (model));
191 g_object_unref (G_OBJECT(model));
192
193 /* toggled column*/
194 cell = gtk_cell_renderer_toggle_new ();
195 column = gtk_tree_view_column_new_with_attributes ("", cell, "active", 0, "cell-background-rgba", 3, NULL);
196 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), GTK_TREE_VIEW_COLUMN (column));
197
198 /* name column */
199 cell = gtk_cell_renderer_text_new ();
200 column = gtk_tree_view_column_new_with_attributes (_("Message"),
201 cell,
202 "text", 1,
203 "cell-background-rgba", 3,
204 NULL);
205 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), GTK_TREE_VIEW_COLUMN (column));
206
207 /* set and fill the model */
208 prefs_page_msg_warning_fill_model (model);
209
210 /* signal of tree_view */
211 g_signal_connect (G_OBJECT (treeview),
212 "button-press-event",
213 G_CALLBACK (prefs_page_msg_warning_list_button_press),
214 NULL);
215
216 /* set column color */
217 utils_set_tree_store_background_color (treeview, 3);
218
219 return treeview;
220 }
221
222 /**
223 * Création de la page de gestion des msg_warning
224 *
225 * \param prefs
226 *
227 * \return
228 **/
prefs_page_msg_warning_setup_page(PrefsPageMsgWarning * page)229 static void prefs_page_msg_warning_setup_page (PrefsPageMsgWarning *page)
230 {
231 GtkWidget *head_page;
232 GrisbiAppConf *a_conf;
233 PrefsPageMsgWarningPrivate *priv;
234
235 devel_debug (NULL);
236 priv = prefs_page_msg_warning_get_instance_private (page);
237 a_conf = (GrisbiAppConf *) grisbi_app_get_a_conf ();
238
239 /* On récupère le nom de la page */
240 head_page = utils_prefs_head_page_new_with_title_and_icon (_("Messages & warnings"), "gsb-warnings-32.png");
241 gtk_box_pack_start (GTK_BOX (priv->vbox_msg_warning), head_page, FALSE, FALSE, 0);
242 gtk_box_reorder_child (GTK_BOX (priv->vbox_msg_warning), head_page, 0);
243
244 /* set variable for checkbutton_show_tip */
245 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbutton_show_tip), a_conf->show_tip);
246
247 /* set treeview */
248 priv->treeview_display_msg = prefs_page_msg_warning_create_tree_view (page);
249 gtk_container_add (GTK_CONTAINER (priv->sw_display_msg), priv->treeview_display_msg);
250
251 /* Connect signal */
252 g_signal_connect (priv->checkbutton_show_tip,
253 "toggled",
254 G_CALLBACK (utils_prefs_page_checkbutton_changed),
255 &a_conf->show_tip);
256 }
257
258 /******************************************************************************/
259 /* Fonctions propres à l'initialisation des fenêtres */
260 /******************************************************************************/
prefs_page_msg_warning_init(PrefsPageMsgWarning * page)261 static void prefs_page_msg_warning_init (PrefsPageMsgWarning *page)
262 {
263 gtk_widget_init_template (GTK_WIDGET (page));
264
265 prefs_page_msg_warning_setup_page (page);
266 }
267
prefs_page_msg_warning_dispose(GObject * object)268 static void prefs_page_msg_warning_dispose (GObject *object)
269 {
270 G_OBJECT_CLASS (prefs_page_msg_warning_parent_class)->dispose (object);
271 }
272
prefs_page_msg_warning_class_init(PrefsPageMsgWarningClass * klass)273 static void prefs_page_msg_warning_class_init (PrefsPageMsgWarningClass *klass)
274 {
275 G_OBJECT_CLASS (klass)->dispose = prefs_page_msg_warning_dispose;
276
277 gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass),
278 "/org/gtk/grisbi/ui/prefs_page_msg_warning.ui");
279
280 gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), PrefsPageMsgWarning, vbox_msg_warning);
281 gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), PrefsPageMsgWarning, checkbutton_show_tip);
282 gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), PrefsPageMsgWarning, sw_display_msg);
283 }
284
285 /******************************************************************************/
286 /* Public functions */
287 /******************************************************************************/
288 /**
289 *
290 *
291 * \param
292 *
293 * \return
294 **/
prefs_page_msg_warning_new(GrisbiPrefs * win)295 PrefsPageMsgWarning *prefs_page_msg_warning_new (GrisbiPrefs *win)
296 {
297 return g_object_new (PREFS_PAGE_MSG_WARNING_TYPE, NULL);
298 }
299
300 /**
301 *
302 *
303 * \param
304 *
305 * \return
306 **/
307 /* Local Variables: */
308 /* c-basic-offset: 4 */
309 /* End: */
310
311