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
;
60 GtkWidget
*checkbtn_clip_filtering_log
;
61 GtkWidget
*spinbtn_filtering_log_length
;
62 GtkWidget
*checkbtn_filtering_log
;
63 GtkWidget
*checkbtn_filtering_log_inc
;
64 GtkWidget
*checkbtn_filtering_log_manual
;
65 GtkWidget
*checkbtn_filtering_log_folder_proc
;
66 GtkWidget
*checkbtn_filtering_log_pre_proc
;
67 GtkWidget
*checkbtn_filtering_log_post_proc
;
68 GtkWidget
*optmenu_filtering_log_level
;
72 static GtkWidget
*prefs_logging_create_check_buttons(GtkWidget
**checkbtn1
,
73 gchar
*label1
, GtkWidget
**checkbtn2
, gchar
*label2
)
75 GtkWidget
*hbox_checkbtn
;
77 hbox_checkbtn
= gtk_hbox_new(FALSE
, VBOX_BORDER
);
78 gtk_widget_show(hbox_checkbtn
);
80 PACK_CHECK_BUTTON (hbox_checkbtn
, *checkbtn1
, label1
);
81 gtk_label_set_line_wrap(GTK_LABEL(gtk_bin_get_child(GTK_BIN((*checkbtn1
)))), TRUE
);
83 PACK_CHECK_BUTTON (hbox_checkbtn
, *checkbtn2
, label2
);
84 gtk_label_set_line_wrap(GTK_LABEL(gtk_bin_get_child(GTK_BIN((*checkbtn2
)))), TRUE
);
89 static void prefs_logging_create_widget(PrefsPage
*_page
, GtkWindow
*window
,
92 LoggingPage
*prefs_logging
= (LoggingPage
*) _page
;
96 GtkWidget
*frame_logging
;
97 GtkWidget
*vbox_network_log
;
98 GtkWidget
*hbox_clip_network_log
;
99 GtkWidget
*checkbtn_clip_network_log
;
100 GtkWidget
*spinbtn_network_log_length
;
101 GtkAdjustment
*spinbtn_network_log_length_adj
;
102 GtkWidget
*hbox_checkbtn
;
104 GtkWidget
*vbox1_filtering_log
;
105 GtkWidget
*hbox_clip_filtering_log
;
106 GtkWidget
*checkbtn_clip_filtering_log
;
107 GtkWidget
*spinbtn_filtering_log_length
;
108 GtkAdjustment
*spinbtn_filtering_log_length_adj
;
109 GtkWidget
*hbox_filtering_log
;
110 GtkWidget
*checkbtn_filtering_log
;
111 GtkWidget
*frame_filtering_log
;
112 GtkWidget
*vbox2_filtering_log
;
113 GtkWidget
*checkbtn_filtering_log_inc
;
114 GtkWidget
*checkbtn_filtering_log_manual
;
115 GtkWidget
*checkbtn_filtering_log_folder_proc
;
116 GtkWidget
*checkbtn_filtering_log_pre_proc
;
117 GtkWidget
*checkbtn_filtering_log_post_proc
;
118 GtkWidget
*hbox_filtering_log_level
;
119 GtkWidget
*label_filtering_log_level
;
120 GtkWidget
*optmenu_filtering_log_level
;
121 GtkSizeGroup
*filter_size_group
;
125 GtkWidget
*frame_disk_log
;
126 GtkWidget
*vbox_disk_log
;
129 GtkWidget
*checkbtn_log_standard
;
130 GtkWidget
*checkbtn_log_warning
;
131 GtkWidget
*checkbtn_log_error
;
132 GtkWidget
*checkbtn_log_status
;
133 GtkSizeGroup
*log_size_group
;
135 vbox1
= gtk_vbox_new (FALSE
, VSPACING
);
136 gtk_widget_show (vbox1
);
137 gtk_container_set_border_width (GTK_CONTAINER (vbox1
), VBOX_BORDER
);
140 vbox_network_log
= gtkut_get_options_frame(vbox1
, &frame_logging
, _("Network log"));
142 hbox_clip_network_log
= gtk_hbox_new (FALSE
, 8);
143 gtk_container_add (GTK_CONTAINER (vbox_network_log
), hbox_clip_network_log
);
144 gtk_widget_show (hbox_clip_network_log
);
146 PACK_CHECK_BUTTON (hbox_clip_network_log
, checkbtn_clip_network_log
,
147 _("Restrict the log window to"));
149 spinbtn_network_log_length_adj
= GTK_ADJUSTMENT(gtk_adjustment_new (500, 0, G_MAXINT
, 1, 10, 0));
150 spinbtn_network_log_length
= gtk_spin_button_new
151 (GTK_ADJUSTMENT (spinbtn_network_log_length_adj
), 1, 0);
152 gtk_widget_show (spinbtn_network_log_length
);
153 gtk_box_pack_start (GTK_BOX (hbox_clip_network_log
), spinbtn_network_log_length
,
155 gtk_widget_set_size_request (GTK_WIDGET (spinbtn_network_log_length
), 64, -1);
156 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_network_log_length
), TRUE
);
158 CLAWS_SET_TIP(spinbtn_network_log_length
,
159 _("0 to stop logging in the log window"));
161 label
= gtk_label_new(_("lines"));
162 gtk_widget_show (label
);
163 gtk_box_pack_start(GTK_BOX(hbox_clip_network_log
), label
, FALSE
, FALSE
, 0);
165 SET_TOGGLE_SENSITIVITY(checkbtn_clip_network_log
, spinbtn_network_log_length
);
166 SET_TOGGLE_SENSITIVITY(checkbtn_clip_network_log
, label
);
169 /* Filtering/processing debug log */
170 vbox1_filtering_log
= gtkut_get_options_frame(vbox1
,
171 &frame_logging
, _("Filtering/processing log"));
173 PACK_CHECK_BUTTON (vbox1_filtering_log
, checkbtn_filtering_log
,
174 _("Enable logging of filtering/processing rules"));
175 hbox_filtering_log
= gtk_hbox_new (FALSE
, 8);
176 gtk_container_add (GTK_CONTAINER (vbox1_filtering_log
), hbox_filtering_log
);
177 gtk_widget_show (hbox_filtering_log
);
179 CLAWS_SET_TIP(checkbtn_filtering_log
,
180 _("If checked, turns on logging of filtering and processing rules.\n"
181 "The log is accessible from 'Tools/Filtering log'.\n"
182 "Caution: enabling this option will slow down the filtering/processing, "
183 "this might be critical when applying many rules upon thousands of "
186 vbox2_filtering_log
= gtkut_get_options_frame(vbox1_filtering_log
, &frame_filtering_log
,
187 _("Log filtering/processing when..."));
189 hbox_checkbtn
= prefs_logging_create_check_buttons(
190 &checkbtn_filtering_log_inc
,
191 _("filtering at incorporation"),
192 &checkbtn_filtering_log_pre_proc
,
193 _("pre-processing folders"));
194 gtk_box_pack_start(GTK_BOX(vbox2_filtering_log
), hbox_checkbtn
, FALSE
, FALSE
, 0);
196 hbox_checkbtn
= prefs_logging_create_check_buttons(
197 &checkbtn_filtering_log_manual
,
198 _("manually filtering"),
199 &checkbtn_filtering_log_post_proc
,
200 _("post-processing folders"));
201 gtk_box_pack_start(GTK_BOX(vbox2_filtering_log
), hbox_checkbtn
, FALSE
, FALSE
, 0);
203 hbox_checkbtn
= gtk_hbox_new(TRUE
, VBOX_BORDER
);
204 gtk_widget_show(hbox_checkbtn
);
205 gtk_box_pack_start(GTK_BOX(vbox2_filtering_log
), hbox_checkbtn
, FALSE
, FALSE
, 0);
206 PACK_CHECK_BUTTON (hbox_checkbtn
, checkbtn_filtering_log_folder_proc
,
207 _("processing folders"));
208 gtk_box_pack_start(GTK_BOX(hbox_checkbtn
), gtk_label_new(""),
211 filter_size_group
= gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL
);
212 gtk_size_group_add_widget(filter_size_group
, checkbtn_filtering_log_inc
);
213 gtk_size_group_add_widget(filter_size_group
, checkbtn_filtering_log_manual
);
214 gtk_size_group_add_widget(filter_size_group
, checkbtn_filtering_log_folder_proc
);
216 SET_TOGGLE_SENSITIVITY(checkbtn_filtering_log
, frame_filtering_log
);
218 hbox_filtering_log_level
= gtk_hbox_new (FALSE
, 8);
219 gtk_widget_show (hbox_filtering_log_level
);
220 gtk_box_pack_start(GTK_BOX (vbox1_filtering_log
), hbox_filtering_log_level
, FALSE
, FALSE
, 0);
222 label_filtering_log_level
= gtk_label_new (_("Log level"));
223 gtk_widget_show (label_filtering_log_level
);
224 gtk_box_pack_start(GTK_BOX(hbox_filtering_log_level
), label_filtering_log_level
, FALSE
, FALSE
, 0);
226 optmenu_filtering_log_level
= gtkut_sc_combobox_create(NULL
, FALSE
);
227 gtk_widget_show (optmenu_filtering_log_level
);
229 menu
= GTK_LIST_STORE(gtk_combo_box_get_model(
230 GTK_COMBO_BOX(optmenu_filtering_log_level
)));
231 COMBOBOX_ADD (menu
, _("Low"), 0);
232 COMBOBOX_ADD (menu
, _("Medium"), 1);
233 COMBOBOX_ADD (menu
, _("High"), 2);
235 gtk_box_pack_start(GTK_BOX(hbox_filtering_log_level
), optmenu_filtering_log_level
, FALSE
, FALSE
, 0);
237 CLAWS_SET_TIP(optmenu_filtering_log_level
,
238 _("Select the level of detail of the logging.\n"
239 "Choose Low to see when rules are applied, which "
240 "conditions match or don't match and what actions are "
242 "Choose Medium to see more details about the message "
243 "that is being processed, and why rules are skipped.\n"
244 "Choose High to explicitly show the reason why all "
245 "rules are processed or skipped, and why all conditions "
246 "are matched or not matched.\n"
247 "Caution: the higher the level, the greater the "
248 "impact on performance."));
250 hbox_clip_filtering_log
= gtk_hbox_new (FALSE
, 8);
251 gtk_container_add (GTK_CONTAINER (vbox1_filtering_log
), hbox_clip_filtering_log
);
252 gtk_widget_show (hbox_clip_filtering_log
);
253 PACK_CHECK_BUTTON (hbox_clip_filtering_log
, checkbtn_clip_filtering_log
,
254 _("Restrict the log window to"));
256 spinbtn_filtering_log_length_adj
= GTK_ADJUSTMENT(gtk_adjustment_new (500, 0, G_MAXINT
, 1, 10, 0));
257 spinbtn_filtering_log_length
= gtk_spin_button_new
258 (GTK_ADJUSTMENT (spinbtn_filtering_log_length_adj
), 1, 0);
259 gtk_widget_show (spinbtn_filtering_log_length
);
260 gtk_box_pack_start (GTK_BOX (hbox_clip_filtering_log
), spinbtn_filtering_log_length
,
262 gtk_widget_set_size_request (GTK_WIDGET (spinbtn_filtering_log_length
), 64, -1);
263 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_filtering_log_length
), TRUE
);
265 CLAWS_SET_TIP(spinbtn_filtering_log_length
,
266 _("0 to stop logging in the log window"));
268 label
= gtk_label_new(_("lines"));
269 gtk_widget_show (label
);
270 gtk_box_pack_start(GTK_BOX(hbox_clip_filtering_log
), label
, FALSE
, FALSE
, 0);
272 SET_TOGGLE_SENSITIVITY(checkbtn_clip_filtering_log
, spinbtn_filtering_log_length
);
273 SET_TOGGLE_SENSITIVITY(checkbtn_clip_filtering_log
, label
);
274 SET_TOGGLE_SENSITIVITY(checkbtn_filtering_log
, hbox_clip_filtering_log
);
275 SET_TOGGLE_SENSITIVITY(checkbtn_filtering_log
, optmenu_filtering_log_level
);
276 SET_TOGGLE_SENSITIVITY(checkbtn_filtering_log
, checkbtn_clip_filtering_log
);
277 SET_TOGGLE_SENSITIVITY(checkbtn_filtering_log
, label_filtering_log_level
);
280 vbox_disk_log
= gtkut_get_options_frame(vbox1
, &frame_disk_log
, _("Disk log"));
282 label
= gtk_label_new(_("Write the following information to disk..."));
283 gtk_widget_show(label
);
284 hbox
= gtk_hbox_new (FALSE
, 8);
285 gtk_container_add (GTK_CONTAINER (vbox_disk_log
), hbox
);
286 gtk_box_pack_start(GTK_BOX(hbox
), label
, FALSE
, FALSE
, 0);
287 gtk_widget_show (hbox
);
289 hbox_checkbtn
= prefs_logging_create_check_buttons(&checkbtn_log_warning
,
290 _("Warning messages"), &checkbtn_log_standard
,
291 _("Network protocol messages"));
292 gtk_box_pack_start(GTK_BOX(vbox_disk_log
), hbox_checkbtn
, FALSE
, FALSE
, 0);
294 hbox_checkbtn
= prefs_logging_create_check_buttons(&checkbtn_log_error
,
295 _("Error messages"), &checkbtn_log_status
,
296 _("Status messages for filtering/processing log"));
297 gtk_box_pack_start(GTK_BOX(vbox_disk_log
), hbox_checkbtn
, FALSE
, FALSE
, 0);
299 log_size_group
= gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL
);
300 gtk_size_group_add_widget(log_size_group
, checkbtn_log_warning
);
301 gtk_size_group_add_widget(log_size_group
, checkbtn_log_error
);
303 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_clip_network_log
),
304 prefs_common
.cliplog
);
306 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_clip_filtering_log
),
307 prefs_common
.filtering_debug_cliplog
);
309 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_log_standard
),
310 prefs_common
.enable_log_standard
);
311 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_log_warning
),
312 prefs_common
.enable_log_warning
);
313 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_log_error
),
314 prefs_common
.enable_log_error
);
315 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_log_status
),
316 prefs_common
.enable_log_status
);
318 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_filtering_log
),
319 prefs_common
.enable_filtering_debug
);
320 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_filtering_log_inc
),
321 prefs_common
.enable_filtering_debug_inc
);
322 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_filtering_log_manual
),
323 prefs_common
.enable_filtering_debug_manual
);
324 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_filtering_log_folder_proc
),
325 prefs_common
.enable_filtering_debug_folder_proc
);
326 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_filtering_log_pre_proc
),
327 prefs_common
.enable_filtering_debug_pre_proc
);
328 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_filtering_log_post_proc
),
329 prefs_common
.enable_filtering_debug_post_proc
);
331 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_network_log_length
),
332 prefs_common
.loglength
);
334 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_filtering_log_length
),
335 prefs_common
.filtering_debug_loglength
);
336 combobox_select_by_data(GTK_COMBO_BOX(optmenu_filtering_log_level
),
337 prefs_common
.filtering_debug_level
);
340 prefs_logging
->checkbtn_clip_network_log
= checkbtn_clip_network_log
;
341 prefs_logging
->spinbtn_network_log_length
= spinbtn_network_log_length
;
342 prefs_logging
->checkbtn_log_standard
= checkbtn_log_standard
;
343 prefs_logging
->checkbtn_log_warning
= checkbtn_log_warning
;
344 prefs_logging
->checkbtn_log_error
= checkbtn_log_error
;
345 prefs_logging
->checkbtn_log_status
= checkbtn_log_status
;
347 prefs_logging
->checkbtn_clip_filtering_log
= checkbtn_clip_filtering_log
;
348 prefs_logging
->spinbtn_filtering_log_length
= spinbtn_filtering_log_length
;
349 prefs_logging
->checkbtn_filtering_log
= checkbtn_filtering_log
;
350 prefs_logging
->checkbtn_filtering_log_inc
= checkbtn_filtering_log_inc
;
351 prefs_logging
->checkbtn_filtering_log_manual
= checkbtn_filtering_log_manual
;
352 prefs_logging
->checkbtn_filtering_log_folder_proc
= checkbtn_filtering_log_folder_proc
;
353 prefs_logging
->checkbtn_filtering_log_pre_proc
= checkbtn_filtering_log_pre_proc
;
354 prefs_logging
->checkbtn_filtering_log_post_proc
= checkbtn_filtering_log_post_proc
;
355 prefs_logging
->optmenu_filtering_log_level
= optmenu_filtering_log_level
;
357 prefs_logging
->page
.widget
= vbox1
;
360 static void prefs_logging_save(PrefsPage
*_page
)
362 LoggingPage
*page
= (LoggingPage
*) _page
;
363 MainWindow
*mainwindow
;
365 gboolean filtering_debug_enabled
;
366 prefs_common
.filtering_debug_level
=
367 combobox_get_active_data(GTK_COMBO_BOX(page
->optmenu_filtering_log_level
));
370 prefs_common
.cliplog
= gtk_toggle_button_get_active(
371 GTK_TOGGLE_BUTTON(page
->checkbtn_clip_network_log
));
372 prefs_common
.loglength
= gtk_spin_button_get_value_as_int(
373 GTK_SPIN_BUTTON(page
->spinbtn_network_log_length
));
374 prefs_common
.enable_log_standard
= gtk_toggle_button_get_active(
375 GTK_TOGGLE_BUTTON(page
->checkbtn_log_standard
));
376 prefs_common
.enable_log_warning
= gtk_toggle_button_get_active(
377 GTK_TOGGLE_BUTTON(page
->checkbtn_log_warning
));
378 prefs_common
.enable_log_error
= gtk_toggle_button_get_active(
379 GTK_TOGGLE_BUTTON(page
->checkbtn_log_error
));
380 prefs_common
.enable_log_status
= gtk_toggle_button_get_active(
381 GTK_TOGGLE_BUTTON(page
->checkbtn_log_status
));
383 prefs_common
.filtering_debug_cliplog
= gtk_toggle_button_get_active(
384 GTK_TOGGLE_BUTTON(page
->checkbtn_clip_filtering_log
));
385 prefs_common
.filtering_debug_loglength
= gtk_spin_button_get_value_as_int(
386 GTK_SPIN_BUTTON(page
->spinbtn_filtering_log_length
));
387 filtering_debug_enabled
= prefs_common
.enable_filtering_debug
;
388 prefs_common
.enable_filtering_debug
= gtk_toggle_button_get_active(
389 GTK_TOGGLE_BUTTON(page
->checkbtn_filtering_log
));
390 if (filtering_debug_enabled
!= prefs_common
.enable_filtering_debug
) {
391 if (prefs_common
.enable_filtering_debug
)
392 log_message(LOG_DEBUG_FILTERING
, _("filtering log enabled\n"));
394 log_message(LOG_DEBUG_FILTERING
, _("filtering log disabled\n"));
396 prefs_common
.enable_filtering_debug_inc
= gtk_toggle_button_get_active(
397 GTK_TOGGLE_BUTTON(page
->checkbtn_filtering_log_inc
));
398 prefs_common
.enable_filtering_debug_manual
= gtk_toggle_button_get_active(
399 GTK_TOGGLE_BUTTON(page
->checkbtn_filtering_log_manual
));
400 prefs_common
.enable_filtering_debug_folder_proc
= gtk_toggle_button_get_active(
401 GTK_TOGGLE_BUTTON(page
->checkbtn_filtering_log_folder_proc
));
402 prefs_common
.enable_filtering_debug_pre_proc
= gtk_toggle_button_get_active(
403 GTK_TOGGLE_BUTTON(page
->checkbtn_filtering_log_pre_proc
));
404 prefs_common
.enable_filtering_debug_post_proc
= gtk_toggle_button_get_active(
405 GTK_TOGGLE_BUTTON(page
->checkbtn_filtering_log_post_proc
));
407 mainwindow
= mainwindow_get_mainwindow();
408 log_window_set_clipping(mainwindow
->logwin
, prefs_common
.cliplog
,
409 prefs_common
.loglength
);
411 log_window_set_clipping(mainwindow
->filtering_debugwin
, prefs_common
.filtering_debug_cliplog
,
412 prefs_common
.filtering_debug_loglength
);
416 static void prefs_logging_destroy_widget(PrefsPage
*_page
)
420 LoggingPage
*prefs_logging
;
422 void prefs_logging_init(void)
425 static gchar
*path
[3];
427 path
[0] = _("Other");
428 path
[1] = _("Logging");
431 page
= g_new0(LoggingPage
, 1);
432 page
->page
.path
= path
;
433 page
->page
.create_widget
= prefs_logging_create_widget
;
434 page
->page
.destroy_widget
= prefs_logging_destroy_widget
;
435 page
->page
.save_page
= prefs_logging_save
;
436 page
->page
.weight
= 5.0;
437 prefs_gtk_register_page((PrefsPage
*) page
);
438 prefs_logging
= page
;
441 void prefs_logging_done(void)
443 prefs_gtk_unregister_page((PrefsPage
*) prefs_logging
);
444 g_free(prefs_logging
);