Allow custom window title for the folder selection dialog.
[claws.git] / src / plugins / bogofilter / bogofilter_gtk.c
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2012 Colin Leroy <colin@colino.net> and 
4  * the Claws Mail team
5  *
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.
10  *
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.
15  *
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/>.
18  * 
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #  include "config.h"
23 #include "claws-features.h"
24 #endif
25
26 #include "defs.h"
27
28 #include <glib.h>
29 #include <glib/gi18n.h>
30 #include <gtk/gtk.h>
31 #include "gtk/gtkutils.h"
32
33 #include "common/claws.h"
34 #include "common/version.h"
35 #include "plugin.h"
36 #include "common/utils.h"
37 #include "prefs.h"
38 #include "folder.h"
39 #include "prefs_gtk.h"
40 #include "foldersel.h"
41 #include "statusbar.h"
42 #include "bogofilter.h"
43 #include "menu.h"
44 #include "addressbook.h"
45 #include "combobox.h"
46
47 struct BogofilterPage
48 {
49         PrefsPage page;
50
51         GtkWidget *process_emails;
52         GtkWidget *receive_spam;
53         GtkWidget *save_folder;
54         GtkWidget *save_folder_select;
55         GtkWidget *save_unsure;
56         GtkWidget *save_unsure_folder;
57         GtkWidget *save_unsure_folder_select;
58         GtkWidget *insert_header;
59         GtkWidget *max_size;
60         GtkWidget *bogopath;
61         GtkWidget *whitelist_ab;
62         GtkWidget *whitelist_ab_folder_combo;
63         GtkWidget *learn_from_whitelist_chkbtn;
64         GtkWidget *mark_as_read;
65 };
66
67 static void foldersel_cb(GtkWidget *widget, gpointer data)
68 {
69         GtkWidget *entry = (GtkWidget *) data;
70         FolderItem *item;
71         gchar *item_id;
72         gint newpos = 0;
73         
74         item = foldersel_folder_sel(NULL, FOLDER_SEL_MOVE, NULL, FALSE, NULL);
75         if (item && (item_id = folder_item_get_identifier(item)) != NULL) {
76                 gtk_editable_delete_text(GTK_EDITABLE(entry), 0, -1);
77                 gtk_editable_insert_text(GTK_EDITABLE(entry), item_id, strlen(item_id), &newpos);
78                 g_free(item_id);
79         }
80 }
81
82 static void spam_handle_combobox_callback(GtkWidget *widget, gpointer user_data)
83 {
84         GtkWidget *hbox = GTK_WIDGET(user_data);
85
86         if (gtk_combo_box_get_active(GTK_COMBO_BOX(widget)) == 1) {
87                 gtk_widget_set_sensitive(hbox, TRUE);
88         } else {
89                 gtk_widget_set_sensitive(hbox, FALSE);
90         }
91 }
92
93 #ifndef USE_ALT_ADDRBOOK
94 static void bogofilter_whitelist_ab_select_cb(GtkWidget *widget, gpointer data)
95 {
96         struct BogofilterPage *page = (struct BogofilterPage *) data;
97         const gchar *folderpath = NULL;
98         gchar *new_path = NULL;
99
100         folderpath = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((page->whitelist_ab_folder_combo)))));
101         new_path = addressbook_folder_selection(folderpath);
102         if (new_path) {
103                 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((page->whitelist_ab_folder_combo)))), new_path);
104                 g_free(new_path);
105         } 
106 }
107 #endif
108
109 static void bogofilter_create_widget_func(PrefsPage * _page,
110                                             GtkWindow * window,
111                                             gpointer data)
112 {
113         struct BogofilterPage *page = (struct BogofilterPage *) _page;
114         BogofilterConfig *config;
115
116         GtkWidget *vbox1, *vbox2;
117         GtkWidget *hbox_max_size;
118         GtkWidget *hbox_process_emails, *hbox_save_spam, *hbox_save_unsure;
119         GtkWidget *hbox_bogopath, *hbox_whitelist;
120         GtkWidget *hbox_mark_as_read;
121
122         GtkWidget *max_size_label;
123         GtkAdjustment *max_size_spinbtn_adj;
124         GtkWidget *max_size_spinbtn;
125         GtkWidget *max_size_kb_label;
126
127         GtkWidget *process_emails_checkbtn;
128
129         GtkWidget *spam_handle_combobox;
130         GtkWidget *save_spam_folder_entry;
131         GtkWidget *save_spam_folder_select;
132
133         GtkWidget *save_unsure_checkbtn;
134         GtkWidget *save_unsure_folder_entry;
135         GtkWidget *save_unsure_folder_select;
136
137         GtkWidget *insert_header_checkbtn;
138         GtkWidget *whitelist_ab_checkbtn;
139         GtkWidget *learn_from_whitelist_chkbtn;
140         GtkWidget *bogopath_label;
141         GtkWidget *bogopath_entry;
142
143         GtkWidget *mark_as_read_checkbtn;
144
145         GtkWidget *whitelist_ab_folder_combo;
146         GtkWidget *whitelist_ab_select_btn;
147
148         vbox1 = gtk_vbox_new (FALSE, VSPACING);
149         gtk_widget_show (vbox1);
150         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
151
152         vbox2 = gtk_vbox_new (FALSE, 4);
153         gtk_widget_show (vbox2);
154         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
155
156         hbox_process_emails = gtk_hbox_new(FALSE, 8);
157         gtk_widget_show(hbox_process_emails);
158         gtk_box_pack_start (GTK_BOX (vbox2), hbox_process_emails, TRUE, TRUE, 0);
159
160         process_emails_checkbtn = gtk_check_button_new_with_label(
161                         _("Process messages on receiving"));
162         gtk_widget_show(process_emails_checkbtn);
163         gtk_box_pack_start(GTK_BOX(hbox_process_emails), process_emails_checkbtn, TRUE, TRUE, 0);
164
165         hbox_max_size = gtk_hbox_new(FALSE, 8);
166         gtk_widget_show(hbox_max_size);
167         gtk_box_pack_start (GTK_BOX (vbox2), hbox_max_size, TRUE, TRUE, 0);
168
169         max_size_label = gtk_label_new(_("Maximum size"));
170         gtk_widget_show(max_size_label);
171         gtk_box_pack_start(GTK_BOX(hbox_max_size), max_size_label, FALSE, FALSE, 0);
172
173         max_size_spinbtn_adj = GTK_ADJUSTMENT(gtk_adjustment_new(250, 0, 10000, 10, 10, 0));
174         max_size_spinbtn = gtk_spin_button_new(GTK_ADJUSTMENT(max_size_spinbtn_adj), 1, 0);
175         gtk_widget_show(max_size_spinbtn);
176         gtk_box_pack_start(GTK_BOX(hbox_max_size), max_size_spinbtn, FALSE, FALSE, 0);
177         CLAWS_SET_TIP(max_size_spinbtn,
178                         _("Messages larger than this will not be checked"));
179         gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(max_size_spinbtn), TRUE);
180
181         max_size_kb_label = gtk_label_new(_("KB"));
182         gtk_widget_show(max_size_kb_label);
183         gtk_box_pack_start(GTK_BOX(hbox_max_size), max_size_kb_label, FALSE, FALSE, 0);
184
185         hbox_save_spam = gtk_hbox_new(FALSE, 8);
186         gtk_widget_show(hbox_save_spam);
187         gtk_box_pack_start (GTK_BOX (vbox2), hbox_save_spam, TRUE, TRUE, 0);
188
189 #if !GTK_CHECK_VERSION(2, 24, 0)
190         spam_handle_combobox = gtk_combo_box_new_text();
191 #else
192         spam_handle_combobox = gtk_combo_box_text_new();
193 #endif
194
195 #if !GTK_CHECK_VERSION(2, 24, 0)
196         gtk_combo_box_append_text(GTK_COMBO_BOX(spam_handle_combobox),
197 #else
198         gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(spam_handle_combobox),
199 #endif
200                         _("Delete spam"));
201
202 #if !GTK_CHECK_VERSION(2, 24, 0)
203         gtk_combo_box_append_text(GTK_COMBO_BOX(spam_handle_combobox),
204 #else
205         gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(spam_handle_combobox),
206 #endif
207                         _("Save spam in..."));
208
209 #if !GTK_CHECK_VERSION(2, 24, 0)
210         gtk_combo_box_append_text(GTK_COMBO_BOX(spam_handle_combobox),
211 #else
212         gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(spam_handle_combobox),
213 #endif
214                         _("Only mark as spam"));
215
216         gtk_widget_show(spam_handle_combobox);
217         gtk_box_pack_start(GTK_BOX(hbox_save_spam), spam_handle_combobox, FALSE, FALSE, 0);
218
219         GtkWidget *hbox = gtk_hbox_new(FALSE, 8);
220         gtk_widget_show(hbox);
221         gtk_box_pack_start (GTK_BOX (hbox_save_spam), hbox, TRUE, TRUE, 0);
222
223         save_spam_folder_entry = gtk_entry_new();
224         gtk_widget_show (save_spam_folder_entry);
225         gtk_box_pack_start (GTK_BOX (hbox), save_spam_folder_entry, TRUE, TRUE, 0);
226         CLAWS_SET_TIP(save_spam_folder_entry,
227                         _("Folder for storing identified spam. Leave empty to use the trash folder."));
228
229         save_spam_folder_select = gtkut_get_browse_directory_btn(_("_Browse"));
230         gtk_widget_show (save_spam_folder_select);
231         gtk_box_pack_start (GTK_BOX (hbox), save_spam_folder_select, FALSE, FALSE, 0);
232         CLAWS_SET_TIP(save_spam_folder_select,
233                         _("Click this button to select a folder for storing spam"));
234
235         g_signal_connect(G_OBJECT(spam_handle_combobox), "changed",
236                         G_CALLBACK(spam_handle_combobox_callback), (gpointer)hbox);
237
238         hbox_save_unsure = gtk_hbox_new(FALSE, 8);
239         gtk_widget_show(hbox_save_unsure);
240         gtk_box_pack_start (GTK_BOX (vbox2), hbox_save_unsure, TRUE, TRUE, 0);
241
242         save_unsure_checkbtn = gtk_check_button_new_with_label(_("When unsure, move to"));
243         gtk_widget_show(save_unsure_checkbtn);
244         gtk_box_pack_start(GTK_BOX(hbox_save_unsure), save_unsure_checkbtn, FALSE, FALSE, 0);
245
246         save_unsure_folder_entry = gtk_entry_new();
247         gtk_widget_show (save_unsure_folder_entry);
248         gtk_box_pack_start (GTK_BOX (hbox_save_unsure), save_unsure_folder_entry, TRUE, TRUE, 0);
249         CLAWS_SET_TIP(save_unsure_folder_entry,
250                         _("Folder for storing mail for which spam status is Unsure. Leave empty to use the Inbox folder."));
251
252         save_unsure_folder_select = gtkut_get_browse_directory_btn(_("_Browse"));
253         gtk_widget_show (save_unsure_folder_select);
254         gtk_box_pack_start (GTK_BOX (hbox_save_unsure), save_unsure_folder_select, FALSE, FALSE, 0);
255         CLAWS_SET_TIP(save_unsure_folder_select,
256                         _("Click this button to select a folder for storing Unsure mails."));
257
258         insert_header_checkbtn = gtk_check_button_new_with_label(_("Insert X-Bogosity header"));
259         gtk_widget_show(insert_header_checkbtn);
260         gtk_box_pack_start(GTK_BOX(vbox2), insert_header_checkbtn, FALSE, FALSE, 0);
261         CLAWS_SET_TIP(insert_header_checkbtn,
262                         _("Only done for messages in MH folders"));
263
264         hbox_whitelist = gtk_hbox_new(FALSE, 8);
265         gtk_widget_show(hbox_whitelist);
266         gtk_box_pack_start (GTK_BOX (vbox2), hbox_whitelist, TRUE, TRUE, 0);
267
268         whitelist_ab_checkbtn = gtk_check_button_new_with_label(_("Whitelist senders found in address book/folder"));
269         gtk_widget_show(whitelist_ab_checkbtn);
270         gtk_box_pack_start(GTK_BOX(hbox_whitelist), whitelist_ab_checkbtn, FALSE, FALSE, 0);
271         CLAWS_SET_TIP(whitelist_ab_checkbtn,
272                         _("Messages coming from your address book contacts will be received in the normal folder even if detected as spam"));
273
274         whitelist_ab_folder_combo = combobox_text_new(TRUE, _("Any"), NULL);
275         gtk_widget_set_size_request(whitelist_ab_folder_combo, 100, -1);
276         gtk_box_pack_start (GTK_BOX (hbox_whitelist), whitelist_ab_folder_combo, TRUE, TRUE, 0);
277
278         whitelist_ab_select_btn = gtk_button_new_with_label(_("Select..."));
279         gtk_widget_show (whitelist_ab_select_btn);
280         gtk_box_pack_start (GTK_BOX (hbox_whitelist), whitelist_ab_select_btn, FALSE, FALSE, 0);
281         CLAWS_SET_TIP(whitelist_ab_select_btn,
282                         _("Click this button to select a book or folder in the address book"));
283
284         learn_from_whitelist_chkbtn = gtk_check_button_new_with_label(_("Learn whitelisted emails as ham"));
285         CLAWS_SET_TIP(learn_from_whitelist_chkbtn,
286                         _("If Bogofilter thought an email was spam or unsure, but it was whitelisted, "
287                           "learn it as ham."));
288         gtk_widget_show(learn_from_whitelist_chkbtn);
289         gtk_box_pack_start (GTK_BOX (vbox2), learn_from_whitelist_chkbtn, TRUE, TRUE, 0);
290
291         hbox_bogopath = gtk_hbox_new(FALSE, 8);
292         gtk_widget_show(hbox_bogopath);
293         gtk_box_pack_start (GTK_BOX (vbox2), hbox_bogopath, FALSE, FALSE, 0);
294
295         bogopath_label = gtk_label_new(_("Bogofilter call"));
296         gtk_widget_show(bogopath_label);
297         gtk_box_pack_start(GTK_BOX(hbox_bogopath), bogopath_label, FALSE, FALSE, 0);
298
299         bogopath_entry = gtk_entry_new();
300         gtk_widget_show(bogopath_entry);
301         gtk_box_pack_start(GTK_BOX(hbox_bogopath), bogopath_entry, FALSE, FALSE, 0);
302         CLAWS_SET_TIP(bogopath_entry,
303                         _("Path to bogofilter executable"));
304
305         hbox_mark_as_read = gtk_hbox_new(FALSE, 8);
306         gtk_widget_show(hbox_mark_as_read);
307         gtk_box_pack_start (GTK_BOX (vbox2), hbox_mark_as_read, TRUE, TRUE, 0);
308
309         mark_as_read_checkbtn = gtk_check_button_new_with_label(_("Mark spam as read"));
310         gtk_widget_show(mark_as_read_checkbtn);
311         gtk_box_pack_start(GTK_BOX(hbox_mark_as_read), mark_as_read_checkbtn, FALSE, FALSE, 0);
312
313         SET_TOGGLE_SENSITIVITY(save_unsure_checkbtn, save_unsure_folder_entry);
314         SET_TOGGLE_SENSITIVITY(save_unsure_checkbtn, save_unsure_folder_select);
315         SET_TOGGLE_SENSITIVITY(whitelist_ab_checkbtn, whitelist_ab_folder_combo);
316 #ifndef USE_ALT_ADDRBOOK
317         SET_TOGGLE_SENSITIVITY(whitelist_ab_checkbtn, whitelist_ab_select_btn);
318 #endif
319         SET_TOGGLE_SENSITIVITY(whitelist_ab_checkbtn, learn_from_whitelist_chkbtn);
320
321         config = bogofilter_get_config();
322
323         g_signal_connect(G_OBJECT(save_spam_folder_select), "clicked",
324                         G_CALLBACK(foldersel_cb), save_spam_folder_entry);
325         g_signal_connect(G_OBJECT(save_unsure_folder_select), "clicked",
326                         G_CALLBACK(foldersel_cb), save_unsure_folder_entry);
327 #ifndef USE_ALT_ADDRBOOK
328         g_signal_connect(G_OBJECT (whitelist_ab_select_btn), "clicked",
329                          G_CALLBACK(bogofilter_whitelist_ab_select_cb), page);
330 #else
331         gtk_widget_set_sensitive(GTK_WIDGET(whitelist_ab_select_btn), FALSE);
332 #endif
333         gtk_spin_button_set_value(GTK_SPIN_BUTTON(max_size_spinbtn), (float) config->max_size);
334         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(process_emails_checkbtn), config->process_emails);
335         gtk_combo_box_set_active(GTK_COMBO_BOX(spam_handle_combobox), config->receive_spam);
336         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(save_unsure_checkbtn), config->save_unsure);
337         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(insert_header_checkbtn), config->insert_header);
338         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(whitelist_ab_checkbtn), config->whitelist_ab);
339         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(learn_from_whitelist_chkbtn), config->learn_from_whitelist);
340         if (config->whitelist_ab_folder != NULL) {
341                 /* translate "Any" (stored UNtranslated) */
342                 if (strcasecmp(config->whitelist_ab_folder, "Any") == 0)
343                         gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((whitelist_ab_folder_combo)))),
344                                         config->whitelist_ab_folder);
345                 else
346                 /* backward compatibility (when translated "Any" was stored) */
347                 if (g_utf8_collate(config->whitelist_ab_folder, _("Any")) == 0)
348                         gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((whitelist_ab_folder_combo)))),
349                                         config->whitelist_ab_folder);
350                 else
351                         gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((whitelist_ab_folder_combo)))),
352                                         config->whitelist_ab_folder);
353         }
354         if (config->save_folder != NULL)
355                 gtk_entry_set_text(GTK_ENTRY(save_spam_folder_entry), config->save_folder);
356         if (config->save_unsure_folder != NULL)
357                 gtk_entry_set_text(GTK_ENTRY(save_unsure_folder_entry), config->save_unsure_folder);
358         if (config->bogopath != NULL)
359                 gtk_entry_set_text(GTK_ENTRY(bogopath_entry), config->bogopath);
360         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mark_as_read_checkbtn), config->mark_as_read);
361
362         page->max_size = max_size_spinbtn;
363         page->process_emails = process_emails_checkbtn;
364
365         page->receive_spam = spam_handle_combobox;
366         page->save_folder = save_spam_folder_entry;
367         page->save_folder_select = save_spam_folder_select;
368
369         page->save_unsure = save_unsure_checkbtn;
370         page->save_unsure_folder = save_unsure_folder_entry;
371         page->save_unsure_folder_select = save_unsure_folder_select;
372
373         page->insert_header = insert_header_checkbtn;
374         page->whitelist_ab = whitelist_ab_checkbtn;
375         page->whitelist_ab_folder_combo = whitelist_ab_folder_combo;
376         page->learn_from_whitelist_chkbtn = learn_from_whitelist_chkbtn;
377         page->bogopath = bogopath_entry;
378
379         page->mark_as_read = mark_as_read_checkbtn;
380
381         page->page.widget = vbox1;
382 }
383
384 static void bogofilter_destroy_widget_func(PrefsPage *_page)
385 {
386         debug_print("Destroying Bogofilter widget\n");
387 }
388
389 static void bogofilter_save_func(PrefsPage *_page)
390 {
391         struct BogofilterPage *page = (struct BogofilterPage *) _page;
392         BogofilterConfig *config;
393
394         debug_print("Saving Bogofilter Page\n");
395
396         config = bogofilter_get_config();
397
398         /* process_emails */
399         config->process_emails = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->process_emails));
400
401         /* receive_spam */
402         config->receive_spam = gtk_combo_box_get_active(GTK_COMBO_BOX(page->receive_spam));
403
404         /* save_folder */
405         g_free(config->save_folder);
406         config->save_folder = gtk_editable_get_chars(GTK_EDITABLE(page->save_folder), 0, -1);
407
408         /* save_unsure */
409         config->save_unsure = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->save_unsure));
410
411         /* save_unsure_folder */
412         g_free(config->save_unsure_folder);
413         config->save_unsure_folder = gtk_editable_get_chars(GTK_EDITABLE(page->save_unsure_folder), 0, -1);
414
415         /* insert_header */
416         config->insert_header = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->insert_header));
417
418         /* whitelist_ab */
419         config->whitelist_ab = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->whitelist_ab));
420         g_free(config->whitelist_ab_folder);
421         config->whitelist_ab_folder = gtk_editable_get_chars(
422                                 GTK_EDITABLE(gtk_bin_get_child(GTK_BIN((page->whitelist_ab_folder_combo)))), 0, -1);
423         /* store UNtranslated "Any" */
424         if (g_utf8_collate(config->whitelist_ab_folder, _("Any")) == 0) {
425                 g_free(config->whitelist_ab_folder);
426                 config->whitelist_ab_folder = g_strdup("Any");
427         }
428
429         /* learn_from_whitelist_chkbtn */
430         config->learn_from_whitelist = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->learn_from_whitelist_chkbtn));
431
432         /* bogopath */
433         g_free(config->bogopath);
434         config->bogopath = gtk_editable_get_chars(GTK_EDITABLE(page->bogopath), 0, -1);
435
436         /* max_size */
437         config->max_size = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->max_size));
438
439         /* mark_as_read */
440         config->mark_as_read = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->mark_as_read));
441
442         if (config->process_emails) {
443                 bogofilter_register_hook();
444         } else {
445                 bogofilter_unregister_hook();
446         }
447
448         procmsg_register_spam_learner(bogofilter_learn);
449         procmsg_spam_set_folder(config->save_folder, bogofilter_get_spam_folder);
450
451         bogofilter_save_config();
452 }
453
454 typedef struct _BogoCbData {
455         gchar *message;
456         gint total;
457         gint done;
458 } BogoCbData;
459
460 static gboolean gtk_message_callback(gpointer data)
461 {
462         BogoCbData *cbdata = (BogoCbData *)data;
463
464         if (cbdata->message)
465                 statusbar_print_all("%s", cbdata->message);
466         else if (cbdata->total == 0) {
467                 statusbar_pop_all();
468         }
469         if (cbdata->total && cbdata->done)
470                 statusbar_progress_all(cbdata->done, cbdata->total, 10);
471         else
472                 statusbar_progress_all(0,0,0);
473         g_free(cbdata->message);
474         g_free(cbdata);
475         GTK_EVENTS_FLUSH();
476         return FALSE;
477 }
478
479 static void gtk_safe_message_callback(gchar *message, gint total, gint done, gboolean thread_safe)
480 {
481         BogoCbData *cbdata = g_new0(BogoCbData, 1);
482         if (message)
483                 cbdata->message = g_strdup(message);
484         cbdata->total = total;
485         cbdata->done = done;
486         if (thread_safe)
487                 g_timeout_add(0, gtk_message_callback, cbdata);
488         else
489                 gtk_message_callback(cbdata);
490 }
491
492 static struct BogofilterPage bogofilter_page;
493
494 gint bogofilter_gtk_init(void)
495 {
496         static gchar *path[3];
497
498         path[0] = _("Plugins");
499         path[1] = _("Bogofilter");
500         path[2] = NULL;
501
502         bogofilter_page.page.path = path;
503         bogofilter_page.page.create_widget = bogofilter_create_widget_func;
504         bogofilter_page.page.destroy_widget = bogofilter_destroy_widget_func;
505         bogofilter_page.page.save_page = bogofilter_save_func;
506         bogofilter_page.page.weight = 35.0;
507
508         prefs_gtk_register_page((PrefsPage *) &bogofilter_page);
509         bogofilter_set_message_callback(gtk_safe_message_callback);
510
511         debug_print("Bogofilter GTK plugin loaded\n");
512         return 0;       
513 }
514
515 void bogofilter_gtk_done(void)
516 {
517         prefs_gtk_unregister_page((PrefsPage *) &bogofilter_page);
518 }