2 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2007 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 2 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, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31 #include <glib/gi18n.h>
34 #include "prefs_common.h"
35 #include "prefs_gtk.h"
37 #include "gtk/gtkutils.h"
38 #include "gtk/prefswindow.h"
41 #include "manage_window.h"
45 typedef struct _LoggingPage
51 GtkWidget *checkbtn_cliplog;
52 GtkWidget *spinbtn_loglength;
53 GtkWidget *checkbtn_debug_cliplog;
54 GtkWidget *spinbtn_debug_loglength;
55 GtkWidget *checkbtn_filteringdebug;
56 GtkWidget *checkbtn_filteringdebug_inc;
57 GtkWidget *checkbtn_filteringdebug_manual;
58 GtkWidget *checkbtn_filteringdebug_folder_proc;
59 GtkWidget *checkbtn_filteringdebug_pre_proc;
60 GtkWidget *checkbtn_filteringdebug_post_proc;
61 GtkWidget *optmenu_filteringdebug_level;
64 static void prefs_logging_create_widget(PrefsPage *_page, GtkWindow *window,
67 LoggingPage *prefs_logging = (LoggingPage *) _page;
71 GtkWidget *frame_logging;
72 GtkWidget *vbox_logging;
73 GtkWidget *hbox_cliplog;
74 GtkWidget *checkbtn_cliplog;
75 GtkWidget *loglength_label;
76 GtkWidget *spinbtn_loglength;
77 GtkObject *spinbtn_loglength_adj;
78 GtkTooltips *loglength_tooltip;
80 GtkWidget *vbox_filteringdebug_log;
81 GtkWidget *hbox_debug_cliplog;
82 GtkWidget *checkbtn_debug_cliplog;
83 GtkWidget *debug_loglength_label;
84 GtkWidget *spinbtn_debug_loglength;
85 GtkObject *spinbtn_debug_loglength_adj;
86 GtkTooltips *debug_loglength_tooltip;
87 GtkWidget *hbox_filteringdebug;
88 GtkWidget *checkbtn_filteringdebug;
89 GtkWidget *frame_filteringdebug;
90 GtkWidget *vbox_filteringdebug;
91 GtkWidget *hbox_filteringdebug_inc;
92 GtkWidget *checkbtn_filteringdebug_inc;
93 GtkWidget *hbox_filteringdebug_manual;
94 GtkWidget *checkbtn_filteringdebug_manual;
95 GtkWidget *hbox_filteringdebug_folder_proc;
96 GtkWidget *checkbtn_filteringdebug_folder_proc;
97 GtkWidget *hbox_filteringdebug_pre_proc;
98 GtkWidget *checkbtn_filteringdebug_pre_proc;
99 GtkWidget *hbox_filteringdebug_post_proc;
100 GtkWidget *checkbtn_filteringdebug_post_proc;
101 GtkTooltips *filteringdebug_tooltip;
102 GtkWidget *hbox_filteringdebug_level;
103 GtkWidget *label_debug_level;
104 GtkWidget *optmenu_filteringdebug_level;
107 GtkTooltips *filteringdebug_level_tooltip;
109 vbox1 = gtk_vbox_new (FALSE, VSPACING);
110 gtk_widget_show (vbox1);
111 gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
114 vbox_logging = gtkut_get_options_frame(vbox1, &frame_logging, _("Protocol log"));
116 PACK_CHECK_BUTTON (vbox_logging, checkbtn_cliplog,
117 _("Restrict the log size"));
118 hbox_cliplog = gtk_hbox_new (FALSE, 8);
119 gtk_container_add (GTK_CONTAINER (vbox_logging), hbox_cliplog);
120 gtk_widget_show (hbox_cliplog);
122 loglength_label = gtk_label_new (_("Log window length"));
123 gtk_box_pack_start (GTK_BOX (hbox_cliplog), loglength_label,
125 gtk_widget_show (GTK_WIDGET (loglength_label));
127 loglength_tooltip = gtk_tooltips_new();
129 spinbtn_loglength_adj = gtk_adjustment_new (500, 0, G_MAXINT, 1, 10, 10);
130 spinbtn_loglength = gtk_spin_button_new
131 (GTK_ADJUSTMENT (spinbtn_loglength_adj), 1, 0);
132 gtk_widget_show (spinbtn_loglength);
133 gtk_box_pack_start (GTK_BOX (hbox_cliplog), spinbtn_loglength,
135 gtk_widget_set_size_request (GTK_WIDGET (spinbtn_loglength), 64, -1);
136 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_loglength), TRUE);
138 gtk_tooltips_set_tip(GTK_TOOLTIPS(loglength_tooltip), spinbtn_loglength,
139 _("0 to stop logging in the log window"),
142 label = gtk_label_new(_("lines"));
143 gtk_widget_show (label);
144 gtk_box_pack_start(GTK_BOX(hbox_cliplog), label, FALSE, FALSE, 0);
146 SET_TOGGLE_SENSITIVITY(checkbtn_cliplog, loglength_label);
147 SET_TOGGLE_SENSITIVITY(checkbtn_cliplog, spinbtn_loglength);
148 SET_TOGGLE_SENSITIVITY(checkbtn_cliplog, label);
150 /* Filtering/processing debug log */
151 vbox_filteringdebug_log = gtkut_get_options_frame(vbox1,
152 &frame_logging, _("Filtering/processing log"));
154 PACK_CHECK_BUTTON (vbox_filteringdebug_log, checkbtn_filteringdebug,
155 _("Enable logging of filtering/processing rules"));
156 hbox_filteringdebug = gtk_hbox_new (FALSE, 8);
157 gtk_container_add (GTK_CONTAINER (vbox_filteringdebug_log), hbox_filteringdebug);
158 gtk_widget_show (hbox_filteringdebug);
160 filteringdebug_tooltip = gtk_tooltips_new();
161 gtk_tooltips_set_tip(GTK_TOOLTIPS(filteringdebug_tooltip),
162 checkbtn_filteringdebug,
163 _("If checked, turns on logging of filtering and processing rules.\n"
164 "The log is accessible from 'Tools/Filtering log'.\n"
165 "Caution: enabling this option will slow down the filtering/processing, "
166 "this might be critical when applying many rules upon thousands of "
170 vbox_filteringdebug = gtkut_get_options_frame(vbox_filteringdebug_log, &frame_filteringdebug,
171 _("Log filtering/processing when..."));
173 PACK_CHECK_BUTTON (vbox_filteringdebug, checkbtn_filteringdebug_inc,
174 _("filtering at incorporation"));
175 hbox_filteringdebug_inc = gtk_hbox_new (FALSE, 8);
176 gtk_container_add (GTK_CONTAINER (vbox_filteringdebug), hbox_filteringdebug_inc);
177 gtk_widget_show (hbox_filteringdebug_inc);
179 PACK_CHECK_BUTTON (vbox_filteringdebug, checkbtn_filteringdebug_manual,
180 _("manually filtering"));
181 hbox_filteringdebug_manual = gtk_hbox_new (FALSE, 8);
182 gtk_container_add (GTK_CONTAINER (vbox_filteringdebug), hbox_filteringdebug_manual);
183 gtk_widget_show (hbox_filteringdebug_manual);
185 PACK_CHECK_BUTTON (vbox_filteringdebug, checkbtn_filteringdebug_folder_proc,
186 _("processing folders"));
187 hbox_filteringdebug_folder_proc = gtk_hbox_new (FALSE, 8);
188 gtk_container_add (GTK_CONTAINER (vbox_filteringdebug), hbox_filteringdebug_folder_proc);
189 gtk_widget_show (hbox_filteringdebug_folder_proc);
191 PACK_CHECK_BUTTON (vbox_filteringdebug, checkbtn_filteringdebug_pre_proc,
192 _("pre-processing folders"));
193 hbox_filteringdebug_pre_proc = gtk_hbox_new (FALSE, 8);
194 gtk_container_add (GTK_CONTAINER (vbox_filteringdebug), hbox_filteringdebug_pre_proc);
195 gtk_widget_show (hbox_filteringdebug_pre_proc);
197 PACK_CHECK_BUTTON (vbox_filteringdebug, checkbtn_filteringdebug_post_proc,
198 _("post-processing folders"));
199 hbox_filteringdebug_post_proc = gtk_hbox_new (FALSE, 8);
200 gtk_container_add (GTK_CONTAINER (vbox_filteringdebug), hbox_filteringdebug_post_proc);
201 gtk_widget_show (hbox_filteringdebug_post_proc);
203 SET_TOGGLE_SENSITIVITY(checkbtn_filteringdebug, checkbtn_filteringdebug_inc);
204 SET_TOGGLE_SENSITIVITY(checkbtn_filteringdebug, checkbtn_filteringdebug_manual);
205 SET_TOGGLE_SENSITIVITY(checkbtn_filteringdebug, checkbtn_filteringdebug_folder_proc);
206 SET_TOGGLE_SENSITIVITY(checkbtn_filteringdebug, checkbtn_filteringdebug_pre_proc);
207 SET_TOGGLE_SENSITIVITY(checkbtn_filteringdebug, checkbtn_filteringdebug_post_proc);
209 hbox_filteringdebug_level = gtk_hbox_new (FALSE, 8);
210 gtk_widget_show (hbox_filteringdebug_level);
211 gtk_box_pack_start(GTK_BOX (vbox_filteringdebug_log), hbox_filteringdebug_level, FALSE, FALSE, 0);
213 label_debug_level = gtk_label_new (_("Log level"));
214 gtk_widget_show (label_debug_level);
215 gtk_box_pack_start(GTK_BOX(hbox_filteringdebug_level), label_debug_level, FALSE, FALSE, 0);
217 optmenu_filteringdebug_level = gtk_option_menu_new ();
218 gtk_widget_show (optmenu_filteringdebug_level);
220 menu = gtk_menu_new ();
221 MENUITEM_ADD (menu, menuitem, _("Low"), 0);
222 MENUITEM_ADD (menu, menuitem, _("Medium"), 1);
223 MENUITEM_ADD (menu, menuitem, _("High"), 2);
225 gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu_filteringdebug_level), menu);
226 gtk_box_pack_start(GTK_BOX(hbox_filteringdebug_level), optmenu_filteringdebug_level, FALSE, FALSE, 0);
228 filteringdebug_level_tooltip = gtk_tooltips_new();
229 gtk_tooltips_set_tip(GTK_TOOLTIPS(filteringdebug_level_tooltip),
230 optmenu_filteringdebug_level,
231 _("Select the level of detail of the logging.\n"
232 "Choose Low to see when rules are applied, which "
233 "conditions match or don't match and what actions are "
235 "Choose Medium to see more details about the message "
236 "that is being processed, and why rules are skipped.\n"
237 "Choose High to explicitly show the reason why all "
238 "rules are processed or skipped, and why all conditions "
239 "are matched or not matched.\n"
240 "Caution: the higher the level, the greater the "
241 "impact on performance."),
244 PACK_CHECK_BUTTON (vbox_filteringdebug_log, checkbtn_debug_cliplog,
245 _("Restrict the log size"));
246 hbox_debug_cliplog = gtk_hbox_new (FALSE, 8);
247 gtk_container_add (GTK_CONTAINER (vbox_filteringdebug_log), hbox_debug_cliplog);
248 gtk_widget_show (hbox_debug_cliplog);
250 debug_loglength_label = gtk_label_new (_("Log window length"));
251 gtk_box_pack_start (GTK_BOX (hbox_debug_cliplog), debug_loglength_label,
253 gtk_widget_show (GTK_WIDGET (debug_loglength_label));
255 debug_loglength_tooltip = gtk_tooltips_new();
257 spinbtn_debug_loglength_adj = gtk_adjustment_new (500, 0, G_MAXINT, 1, 10, 10);
258 spinbtn_debug_loglength = gtk_spin_button_new
259 (GTK_ADJUSTMENT (spinbtn_debug_loglength_adj), 1, 0);
260 gtk_widget_show (spinbtn_debug_loglength);
261 gtk_box_pack_start (GTK_BOX (hbox_debug_cliplog), spinbtn_debug_loglength,
263 gtk_widget_set_size_request (GTK_WIDGET (spinbtn_debug_loglength), 64, -1);
264 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_debug_loglength), TRUE);
266 gtk_tooltips_set_tip(GTK_TOOLTIPS(debug_loglength_tooltip), spinbtn_debug_loglength,
267 _("0 to stop logging in the log window"),
270 label = gtk_label_new(_("lines"));
271 gtk_widget_show (label);
272 gtk_box_pack_start(GTK_BOX(hbox_debug_cliplog), label, FALSE, FALSE, 0);
274 SET_TOGGLE_SENSITIVITY(checkbtn_debug_cliplog, debug_loglength_label);
275 SET_TOGGLE_SENSITIVITY(checkbtn_debug_cliplog, spinbtn_debug_loglength);
276 SET_TOGGLE_SENSITIVITY(checkbtn_debug_cliplog, label);
278 SET_TOGGLE_SENSITIVITY(checkbtn_filteringdebug, optmenu_filteringdebug_level);
279 SET_TOGGLE_SENSITIVITY(checkbtn_filteringdebug, checkbtn_debug_cliplog);
280 SET_TOGGLE_SENSITIVITY(checkbtn_filteringdebug, label_debug_level);
282 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_cliplog),
283 prefs_common.cliplog);
284 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_debug_cliplog),
285 prefs_common.filtering_debug_cliplog);
286 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_filteringdebug),
287 prefs_common.enable_filtering_debug);
288 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_filteringdebug_inc),
289 prefs_common.enable_filtering_debug_inc);
290 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_filteringdebug_manual),
291 prefs_common.enable_filtering_debug_manual);
292 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_filteringdebug_folder_proc),
293 prefs_common.enable_filtering_debug_folder_proc);
294 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_filteringdebug_pre_proc),
295 prefs_common.enable_filtering_debug_pre_proc);
296 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_filteringdebug_post_proc),
297 prefs_common.enable_filtering_debug_post_proc);
299 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_loglength),
300 prefs_common.loglength);
301 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_debug_loglength),
302 prefs_common.filtering_debug_loglength);
304 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu_filteringdebug_level),
305 prefs_common.filtering_debug_level);
307 prefs_logging->checkbtn_cliplog = checkbtn_cliplog;
308 prefs_logging->spinbtn_loglength = spinbtn_loglength;
309 prefs_logging->checkbtn_debug_cliplog = checkbtn_debug_cliplog;
310 prefs_logging->spinbtn_debug_loglength = spinbtn_debug_loglength;
311 prefs_logging->checkbtn_filteringdebug = checkbtn_filteringdebug;
312 prefs_logging->checkbtn_filteringdebug_inc = checkbtn_filteringdebug_inc;
313 prefs_logging->checkbtn_filteringdebug_manual = checkbtn_filteringdebug_manual;
314 prefs_logging->checkbtn_filteringdebug_folder_proc = checkbtn_filteringdebug_folder_proc;
315 prefs_logging->checkbtn_filteringdebug_pre_proc = checkbtn_filteringdebug_pre_proc;
316 prefs_logging->checkbtn_filteringdebug_post_proc = checkbtn_filteringdebug_post_proc;
317 prefs_logging->optmenu_filteringdebug_level = optmenu_filteringdebug_level;
319 prefs_logging->page.widget = vbox1;
322 static void prefs_logging_save(PrefsPage *_page)
324 LoggingPage *page = (LoggingPage *) _page;
325 MainWindow *mainwindow;
326 gboolean filtering_debug_enabled;
330 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->optmenu_filteringdebug_level));
331 menuitem = gtk_menu_get_active(GTK_MENU(menu));
332 prefs_common.filtering_debug_level = GPOINTER_TO_INT
333 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
335 prefs_common.cliplog = gtk_toggle_button_get_active(
336 GTK_TOGGLE_BUTTON(page->checkbtn_cliplog));
337 prefs_common.loglength = gtk_spin_button_get_value_as_int(
338 GTK_SPIN_BUTTON(page->spinbtn_loglength));
339 prefs_common.filtering_debug_cliplog = gtk_toggle_button_get_active(
340 GTK_TOGGLE_BUTTON(page->checkbtn_debug_cliplog));
341 prefs_common.filtering_debug_loglength = gtk_spin_button_get_value_as_int(
342 GTK_SPIN_BUTTON(page->spinbtn_debug_loglength));
343 filtering_debug_enabled = prefs_common.enable_filtering_debug;
344 prefs_common.enable_filtering_debug = gtk_toggle_button_get_active(
345 GTK_TOGGLE_BUTTON(page->checkbtn_filteringdebug));
346 if (filtering_debug_enabled != prefs_common.enable_filtering_debug) {
347 if (prefs_common.enable_filtering_debug)
348 log_message(LOG_DEBUG_FILTERING, _("filtering log enabled\n"));
350 log_message(LOG_DEBUG_FILTERING, _("filtering log disabled\n"));
352 prefs_common.enable_filtering_debug_inc = gtk_toggle_button_get_active(
353 GTK_TOGGLE_BUTTON(page->checkbtn_filteringdebug_inc));
354 prefs_common.enable_filtering_debug_manual = gtk_toggle_button_get_active(
355 GTK_TOGGLE_BUTTON(page->checkbtn_filteringdebug_manual));
356 prefs_common.enable_filtering_debug_folder_proc = gtk_toggle_button_get_active(
357 GTK_TOGGLE_BUTTON(page->checkbtn_filteringdebug_folder_proc));
358 prefs_common.enable_filtering_debug_pre_proc = gtk_toggle_button_get_active(
359 GTK_TOGGLE_BUTTON(page->checkbtn_filteringdebug_pre_proc));
360 prefs_common.enable_filtering_debug_post_proc = gtk_toggle_button_get_active(
361 GTK_TOGGLE_BUTTON(page->checkbtn_filteringdebug_post_proc));
363 mainwindow = mainwindow_get_mainwindow();
364 log_window_set_clipping(mainwindow->logwin, prefs_common.cliplog,
365 prefs_common.loglength);
366 log_window_set_clipping(mainwindow->filtering_debugwin, prefs_common.filtering_debug_cliplog,
367 prefs_common.filtering_debug_loglength);
370 static void prefs_logging_destroy_widget(PrefsPage *_page)
374 LoggingPage *prefs_logging;
376 void prefs_logging_init(void)
379 static gchar *path[3];
381 path[0] = _("Other");
382 path[1] = _("Logging");
385 page = g_new0(LoggingPage, 1);
386 page->page.path = path;
387 page->page.create_widget = prefs_logging_create_widget;
388 page->page.destroy_widget = prefs_logging_destroy_widget;
389 page->page.save_page = prefs_logging_save;
390 page->page.weight = 5.0;
391 prefs_gtk_register_page((PrefsPage *) page);
392 prefs_logging = page;
395 void prefs_logging_done(void)
397 prefs_gtk_unregister_page((PrefsPage *) prefs_logging);
398 g_free(prefs_logging);