2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2012 Tristan Chabredier <wwp@claws-mail.org> and
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "claws-features.h"
32 #include <glib/gi18n.h>
35 #include "prefs_common.h"
36 #include "prefs_gtk.h"
38 #include "gtk/gtkutils.h"
39 #include "gtk/prefswindow.h"
42 #include "manage_window.h"
47 typedef struct _LoggingPage
53 GtkWidget
*checkbtn_clip_network_log
;
54 GtkWidget
*spinbtn_network_log_length
;
55 GtkWidget
*checkbtn_log_standard
;
56 GtkWidget
*checkbtn_log_warning
;
57 GtkWidget
*checkbtn_log_error
;
58 GtkWidget
*checkbtn_log_status
;
59 GtkWidget
*checkbtn_clip_filtering_log
;
60 GtkWidget
*spinbtn_filtering_log_length
;
61 GtkWidget
*checkbtn_filtering_log
;
62 GtkWidget
*checkbtn_filtering_log_inc
;
63 GtkWidget
*checkbtn_filtering_log_manual
;
64 GtkWidget
*checkbtn_filtering_log_folder_proc
;
65 GtkWidget
*checkbtn_filtering_log_pre_proc
;
66 GtkWidget
*checkbtn_filtering_log_post_proc
;
67 GtkWidget
*optmenu_filtering_log_level
;
70 static GtkWidget
*prefs_logging_create_check_buttons(GtkWidget
**checkbtn1
,
71 gchar
*label1
, GtkWidget
**checkbtn2
, gchar
*label2
)
73 GtkWidget
*hbox_checkbtn
;
75 hbox_checkbtn
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, VBOX_BORDER
);
76 gtk_widget_show(hbox_checkbtn
);
78 PACK_CHECK_BUTTON (hbox_checkbtn
, *checkbtn1
, label1
);
79 gtk_label_set_line_wrap(GTK_LABEL(gtk_bin_get_child(GTK_BIN((*checkbtn1
)))), TRUE
);
81 PACK_CHECK_BUTTON (hbox_checkbtn
, *checkbtn2
, label2
);
82 gtk_label_set_line_wrap(GTK_LABEL(gtk_bin_get_child(GTK_BIN((*checkbtn2
)))), TRUE
);
87 static void prefs_logging_create_widget(PrefsPage
*_page
, GtkWindow
*window
,
90 LoggingPage
*prefs_logging
= (LoggingPage
*) _page
;
94 GtkWidget
*frame_logging
;
95 GtkWidget
*vbox_network_log
;
96 GtkWidget
*hbox_clip_network_log
;
97 GtkWidget
*checkbtn_clip_network_log
;
98 GtkWidget
*spinbtn_network_log_length
;
99 GtkAdjustment
*spinbtn_network_log_length_adj
;
100 GtkWidget
*hbox_checkbtn
;
101 GtkWidget
*vbox1_filtering_log
;
102 GtkWidget
*hbox_clip_filtering_log
;
103 GtkWidget
*checkbtn_clip_filtering_log
;
104 GtkWidget
*spinbtn_filtering_log_length
;
105 GtkAdjustment
*spinbtn_filtering_log_length_adj
;
106 GtkWidget
*hbox_filtering_log
;
107 GtkWidget
*checkbtn_filtering_log
;
108 GtkWidget
*frame_filtering_log
;
109 GtkWidget
*vbox2_filtering_log
;
110 GtkWidget
*checkbtn_filtering_log_inc
;
111 GtkWidget
*checkbtn_filtering_log_manual
;
112 GtkWidget
*checkbtn_filtering_log_folder_proc
;
113 GtkWidget
*checkbtn_filtering_log_pre_proc
;
114 GtkWidget
*checkbtn_filtering_log_post_proc
;
115 GtkWidget
*hbox_filtering_log_level
;
116 GtkWidget
*label_filtering_log_level
;
117 GtkWidget
*optmenu_filtering_log_level
;
118 GtkSizeGroup
*filter_size_group
;
121 GtkWidget
*frame_disk_log
;
122 GtkWidget
*vbox_disk_log
;
125 GtkWidget
*checkbtn_log_standard
;
126 GtkWidget
*checkbtn_log_warning
;
127 GtkWidget
*checkbtn_log_error
;
128 GtkWidget
*checkbtn_log_status
;
129 GtkSizeGroup
*log_size_group
;
131 vbox1
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, VSPACING
);
132 gtk_widget_show (vbox1
);
133 gtk_container_set_border_width (GTK_CONTAINER (vbox1
), VBOX_BORDER
);
136 vbox_network_log
= gtkut_get_options_frame(vbox1
, &frame_logging
, _("Network log"));
138 hbox_clip_network_log
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 8);
139 gtk_container_add (GTK_CONTAINER (vbox_network_log
), hbox_clip_network_log
);
140 gtk_widget_show (hbox_clip_network_log
);
142 PACK_CHECK_BUTTON (hbox_clip_network_log
, checkbtn_clip_network_log
,
143 _("Restrict the log window to"));
145 spinbtn_network_log_length_adj
= GTK_ADJUSTMENT(gtk_adjustment_new (500, 0, G_MAXINT
, 1, 10, 0));
146 spinbtn_network_log_length
= gtk_spin_button_new
147 (GTK_ADJUSTMENT (spinbtn_network_log_length_adj
), 1, 0);
148 gtk_widget_show (spinbtn_network_log_length
);
149 gtk_box_pack_start (GTK_BOX (hbox_clip_network_log
), spinbtn_network_log_length
,
151 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_network_log_length
), TRUE
);
153 CLAWS_SET_TIP(spinbtn_network_log_length
,
154 _("0 to stop logging in the log window"));
156 label
= gtk_label_new(_("lines"));
157 gtk_widget_show (label
);
158 gtk_box_pack_start(GTK_BOX(hbox_clip_network_log
), label
, FALSE
, FALSE
, 0);
160 SET_TOGGLE_SENSITIVITY(checkbtn_clip_network_log
, spinbtn_network_log_length
);
161 SET_TOGGLE_SENSITIVITY(checkbtn_clip_network_log
, label
);
163 /* Filtering/processing debug log */
164 vbox1_filtering_log
= gtkut_get_options_frame(vbox1
,
165 &frame_logging
, _("Filtering/processing log"));
167 PACK_CHECK_BUTTON (vbox1_filtering_log
, checkbtn_filtering_log
,
168 _("Enable logging of filtering/processing rules"));
169 hbox_filtering_log
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 8);
170 gtk_container_add (GTK_CONTAINER (vbox1_filtering_log
), hbox_filtering_log
);
171 gtk_widget_show (hbox_filtering_log
);
173 CLAWS_SET_TIP(checkbtn_filtering_log
,
174 _("If checked, turns on logging of filtering and processing rules.\n"
175 "The log is accessible from 'Tools/Filtering log'.\n"
176 "Caution: enabling this option will slow down the filtering/processing, "
177 "this might be critical when applying many rules upon thousands of "
180 vbox2_filtering_log
= gtkut_get_options_frame(vbox1_filtering_log
, &frame_filtering_log
,
181 _("Log filtering/processing when..."));
183 hbox_checkbtn
= prefs_logging_create_check_buttons(
184 &checkbtn_filtering_log_inc
,
185 _("filtering at incorporation"),
186 &checkbtn_filtering_log_pre_proc
,
187 _("pre-processing folders"));
188 gtk_box_pack_start(GTK_BOX(vbox2_filtering_log
), hbox_checkbtn
, FALSE
, FALSE
, 0);
190 hbox_checkbtn
= prefs_logging_create_check_buttons(
191 &checkbtn_filtering_log_manual
,
192 _("manually filtering"),
193 &checkbtn_filtering_log_post_proc
,
194 _("post-processing folders"));
195 gtk_box_pack_start(GTK_BOX(vbox2_filtering_log
), hbox_checkbtn
, FALSE
, FALSE
, 0);
197 hbox_checkbtn
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, VBOX_BORDER
);
198 gtk_widget_show(hbox_checkbtn
);
199 gtk_box_pack_start(GTK_BOX(vbox2_filtering_log
), hbox_checkbtn
, FALSE
, FALSE
, 0);
200 PACK_CHECK_BUTTON (hbox_checkbtn
, checkbtn_filtering_log_folder_proc
,
201 _("processing folders"));
202 gtk_box_pack_start(GTK_BOX(hbox_checkbtn
), gtk_label_new(""),
205 filter_size_group
= gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL
);
206 gtk_size_group_add_widget(filter_size_group
, checkbtn_filtering_log_inc
);
207 gtk_size_group_add_widget(filter_size_group
, checkbtn_filtering_log_manual
);
208 gtk_size_group_add_widget(filter_size_group
, checkbtn_filtering_log_folder_proc
);
209 g_object_unref(G_OBJECT(filter_size_group
));
211 SET_TOGGLE_SENSITIVITY(checkbtn_filtering_log
, frame_filtering_log
);
213 hbox_filtering_log_level
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 8);
214 gtk_widget_show (hbox_filtering_log_level
);
215 gtk_box_pack_start(GTK_BOX (vbox1_filtering_log
), hbox_filtering_log_level
, FALSE
, FALSE
, 0);
217 label_filtering_log_level
= gtk_label_new (_("Log level"));
218 gtk_widget_show (label_filtering_log_level
);
219 gtk_box_pack_start(GTK_BOX(hbox_filtering_log_level
), label_filtering_log_level
, FALSE
, FALSE
, 0);
221 optmenu_filtering_log_level
= gtkut_sc_combobox_create(NULL
, FALSE
);
222 gtk_widget_show (optmenu_filtering_log_level
);
224 menu
= GTK_LIST_STORE(gtk_combo_box_get_model(
225 GTK_COMBO_BOX(optmenu_filtering_log_level
)));
226 COMBOBOX_ADD (menu
, _("Low"), 0);
227 COMBOBOX_ADD (menu
, _("Medium"), 1);
228 COMBOBOX_ADD (menu
, _("High"), 2);
230 gtk_box_pack_start(GTK_BOX(hbox_filtering_log_level
), optmenu_filtering_log_level
, FALSE
, FALSE
, 0);
232 CLAWS_SET_TIP(optmenu_filtering_log_level
,
233 _("Select the level of detail of the logging.\n"
234 "Choose Low to see when rules are applied, which "
235 "conditions match or don't match and what actions are "
237 "Choose Medium to see more details about the message "
238 "that is being processed, and why rules are skipped.\n"
239 "Choose High to explicitly show the reason why all "
240 "rules are processed or skipped, and why all conditions "
241 "are matched or not matched.\n"
242 "Caution: the higher the level, the greater the "
243 "impact on performance."));
245 hbox_clip_filtering_log
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 8);
246 gtk_container_add (GTK_CONTAINER (vbox1_filtering_log
), hbox_clip_filtering_log
);
247 gtk_widget_show (hbox_clip_filtering_log
);
248 PACK_CHECK_BUTTON (hbox_clip_filtering_log
, checkbtn_clip_filtering_log
,
249 _("Restrict the log window to"));
251 spinbtn_filtering_log_length_adj
= GTK_ADJUSTMENT(gtk_adjustment_new (500, 0, G_MAXINT
, 1, 10, 0));
252 spinbtn_filtering_log_length
= gtk_spin_button_new
253 (GTK_ADJUSTMENT (spinbtn_filtering_log_length_adj
), 1, 0);
254 gtk_widget_show (spinbtn_filtering_log_length
);
255 gtk_box_pack_start (GTK_BOX (hbox_clip_filtering_log
), spinbtn_filtering_log_length
,
257 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_filtering_log_length
), TRUE
);
259 CLAWS_SET_TIP(spinbtn_filtering_log_length
,
260 _("0 to stop logging in the log window"));
262 label
= gtk_label_new(_("lines"));
263 gtk_widget_show (label
);
264 gtk_box_pack_start(GTK_BOX(hbox_clip_filtering_log
), label
, FALSE
, FALSE
, 0);
266 SET_TOGGLE_SENSITIVITY(checkbtn_clip_filtering_log
, spinbtn_filtering_log_length
);
267 SET_TOGGLE_SENSITIVITY(checkbtn_clip_filtering_log
, label
);
268 SET_TOGGLE_SENSITIVITY(checkbtn_filtering_log
, hbox_clip_filtering_log
);
269 SET_TOGGLE_SENSITIVITY(checkbtn_filtering_log
, optmenu_filtering_log_level
);
270 SET_TOGGLE_SENSITIVITY(checkbtn_filtering_log
, checkbtn_clip_filtering_log
);
271 SET_TOGGLE_SENSITIVITY(checkbtn_filtering_log
, label_filtering_log_level
);
274 vbox_disk_log
= gtkut_get_options_frame(vbox1
, &frame_disk_log
, _("Disk log"));
276 label
= gtk_label_new(_("Write the following information to disk..."));
277 gtk_widget_show(label
);
278 hbox
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 8);
279 gtk_container_add (GTK_CONTAINER (vbox_disk_log
), hbox
);
280 gtk_box_pack_start(GTK_BOX(hbox
), label
, FALSE
, FALSE
, 0);
281 gtk_widget_show (hbox
);
283 hbox_checkbtn
= prefs_logging_create_check_buttons(&checkbtn_log_warning
,
284 _("Warning messages"), &checkbtn_log_standard
,
285 _("Network protocol messages"));
286 gtk_box_pack_start(GTK_BOX(vbox_disk_log
), hbox_checkbtn
, FALSE
, FALSE
, 0);
288 hbox_checkbtn
= prefs_logging_create_check_buttons(&checkbtn_log_error
,
289 _("Error messages"), &checkbtn_log_status
,
290 _("Status messages for filtering/processing log"));
291 gtk_box_pack_start(GTK_BOX(vbox_disk_log
), hbox_checkbtn
, FALSE
, FALSE
, 0);
293 log_size_group
= gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL
);
294 gtk_size_group_add_widget(log_size_group
, checkbtn_log_warning
);
295 gtk_size_group_add_widget(log_size_group
, checkbtn_log_error
);
296 g_object_unref(G_OBJECT(log_size_group
));
298 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_clip_network_log
),
299 prefs_common
.cliplog
);
300 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_clip_filtering_log
),
301 prefs_common
.filtering_debug_cliplog
);
302 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_log_standard
),
303 prefs_common
.enable_log_standard
);
304 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_log_warning
),
305 prefs_common
.enable_log_warning
);
306 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_log_error
),
307 prefs_common
.enable_log_error
);
308 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_log_status
),
309 prefs_common
.enable_log_status
);
310 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_filtering_log
),
311 prefs_common
.enable_filtering_debug
);
312 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_filtering_log_inc
),
313 prefs_common
.enable_filtering_debug_inc
);
314 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_filtering_log_manual
),
315 prefs_common
.enable_filtering_debug_manual
);
316 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_filtering_log_folder_proc
),
317 prefs_common
.enable_filtering_debug_folder_proc
);
318 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_filtering_log_pre_proc
),
319 prefs_common
.enable_filtering_debug_pre_proc
);
320 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_filtering_log_post_proc
),
321 prefs_common
.enable_filtering_debug_post_proc
);
323 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_network_log_length
),
324 prefs_common
.loglength
);
325 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_filtering_log_length
),
326 prefs_common
.filtering_debug_loglength
);
327 combobox_select_by_data(GTK_COMBO_BOX(optmenu_filtering_log_level
),
328 prefs_common
.filtering_debug_level
);
330 prefs_logging
->checkbtn_clip_network_log
= checkbtn_clip_network_log
;
331 prefs_logging
->spinbtn_network_log_length
= spinbtn_network_log_length
;
332 prefs_logging
->checkbtn_log_standard
= checkbtn_log_standard
;
333 prefs_logging
->checkbtn_log_warning
= checkbtn_log_warning
;
334 prefs_logging
->checkbtn_log_error
= checkbtn_log_error
;
335 prefs_logging
->checkbtn_log_status
= checkbtn_log_status
;
336 prefs_logging
->checkbtn_clip_filtering_log
= checkbtn_clip_filtering_log
;
337 prefs_logging
->spinbtn_filtering_log_length
= spinbtn_filtering_log_length
;
338 prefs_logging
->checkbtn_filtering_log
= checkbtn_filtering_log
;
339 prefs_logging
->checkbtn_filtering_log_inc
= checkbtn_filtering_log_inc
;
340 prefs_logging
->checkbtn_filtering_log_manual
= checkbtn_filtering_log_manual
;
341 prefs_logging
->checkbtn_filtering_log_folder_proc
= checkbtn_filtering_log_folder_proc
;
342 prefs_logging
->checkbtn_filtering_log_pre_proc
= checkbtn_filtering_log_pre_proc
;
343 prefs_logging
->checkbtn_filtering_log_post_proc
= checkbtn_filtering_log_post_proc
;
344 prefs_logging
->optmenu_filtering_log_level
= optmenu_filtering_log_level
;
345 prefs_logging
->page
.widget
= vbox1
;
348 static void prefs_logging_save(PrefsPage
*_page
)
350 LoggingPage
*page
= (LoggingPage
*) _page
;
351 MainWindow
*mainwindow
;
353 gboolean filtering_debug_enabled
;
354 prefs_common
.filtering_debug_level
=
355 combobox_get_active_data(GTK_COMBO_BOX(page
->optmenu_filtering_log_level
));
357 prefs_common
.cliplog
= gtk_toggle_button_get_active(
358 GTK_TOGGLE_BUTTON(page
->checkbtn_clip_network_log
));
359 prefs_common
.loglength
= gtk_spin_button_get_value_as_int(
360 GTK_SPIN_BUTTON(page
->spinbtn_network_log_length
));
361 prefs_common
.enable_log_standard
= gtk_toggle_button_get_active(
362 GTK_TOGGLE_BUTTON(page
->checkbtn_log_standard
));
363 prefs_common
.enable_log_warning
= gtk_toggle_button_get_active(
364 GTK_TOGGLE_BUTTON(page
->checkbtn_log_warning
));
365 prefs_common
.enable_log_error
= gtk_toggle_button_get_active(
366 GTK_TOGGLE_BUTTON(page
->checkbtn_log_error
));
367 prefs_common
.enable_log_status
= gtk_toggle_button_get_active(
368 GTK_TOGGLE_BUTTON(page
->checkbtn_log_status
));
369 prefs_common
.filtering_debug_cliplog
= gtk_toggle_button_get_active(
370 GTK_TOGGLE_BUTTON(page
->checkbtn_clip_filtering_log
));
371 prefs_common
.filtering_debug_loglength
= gtk_spin_button_get_value_as_int(
372 GTK_SPIN_BUTTON(page
->spinbtn_filtering_log_length
));
373 filtering_debug_enabled
= prefs_common
.enable_filtering_debug
;
374 prefs_common
.enable_filtering_debug
= gtk_toggle_button_get_active(
375 GTK_TOGGLE_BUTTON(page
->checkbtn_filtering_log
));
376 if (filtering_debug_enabled
!= prefs_common
.enable_filtering_debug
) {
377 if (prefs_common
.enable_filtering_debug
)
378 log_message(LOG_DEBUG_FILTERING
, _("filtering log enabled\n"));
380 log_message(LOG_DEBUG_FILTERING
, _("filtering log disabled\n"));
382 prefs_common
.enable_filtering_debug_inc
= gtk_toggle_button_get_active(
383 GTK_TOGGLE_BUTTON(page
->checkbtn_filtering_log_inc
));
384 prefs_common
.enable_filtering_debug_manual
= gtk_toggle_button_get_active(
385 GTK_TOGGLE_BUTTON(page
->checkbtn_filtering_log_manual
));
386 prefs_common
.enable_filtering_debug_folder_proc
= gtk_toggle_button_get_active(
387 GTK_TOGGLE_BUTTON(page
->checkbtn_filtering_log_folder_proc
));
388 prefs_common
.enable_filtering_debug_pre_proc
= gtk_toggle_button_get_active(
389 GTK_TOGGLE_BUTTON(page
->checkbtn_filtering_log_pre_proc
));
390 prefs_common
.enable_filtering_debug_post_proc
= gtk_toggle_button_get_active(
391 GTK_TOGGLE_BUTTON(page
->checkbtn_filtering_log_post_proc
));
392 mainwindow
= mainwindow_get_mainwindow();
393 log_window_set_clipping(mainwindow
->logwin
, prefs_common
.cliplog
,
394 prefs_common
.loglength
);
395 log_window_set_clipping(mainwindow
->filtering_debugwin
, prefs_common
.filtering_debug_cliplog
,
396 prefs_common
.filtering_debug_loglength
);
399 static void prefs_logging_destroy_widget(PrefsPage
*_page
)
403 LoggingPage
*prefs_logging
;
405 void prefs_logging_init(void)
408 static gchar
*path
[3];
410 path
[0] = _("Other");
411 path
[1] = _("Logging");
414 page
= g_new0(LoggingPage
, 1);
415 page
->page
.path
= path
;
416 page
->page
.create_widget
= prefs_logging_create_widget
;
417 page
->page
.destroy_widget
= prefs_logging_destroy_widget
;
418 page
->page
.save_page
= prefs_logging_save
;
419 page
->page
.weight
= 5.0;
420 prefs_gtk_register_page((PrefsPage
*) page
);
421 prefs_logging
= page
;
424 void prefs_logging_done(void)
426 prefs_gtk_unregister_page((PrefsPage
*) prefs_logging
);
427 g_free(prefs_logging
);