Fix bug #3380. Initialize widget before callback handler for 'clicked'
[claws.git] / src / plugins / clamd / clamav_plugin_gtk.c
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2003-2010 the Claws Mail Team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  * 
18  */
19
20
21 #ifdef HAVE_CONFIG_H
22 #  include "config.h"
23 #  include "claws-features.h"
24 #endif
25
26 #include <glib.h>
27 #include <glib/gi18n.h>
28
29 #include "defs.h"
30
31 #include <gtk/gtk.h>
32 #include <gtk/gtkutils.h>
33
34 #include "common/claws.h"
35 #include "common/version.h"
36 #include "plugin.h"
37 #include "utils.h"
38 #include "prefs.h"
39 #include "folder.h"
40 #include "prefs_gtk.h"
41 #include "foldersel.h"
42 #include "clamav_plugin.h"
43 #include "statusbar.h"
44 #include "alertpanel.h"
45 #include "clamd-plugin.h"
46
47 struct ClamAvPage
48 {
49         PrefsPage page;
50         
51         GtkWidget *enable_clamav;
52 /*      GtkWidget *enable_arc;*/
53         GtkWidget *max_size;
54         GtkWidget *recv_infected;
55         GtkWidget *save_folder;
56         GtkWidget *config_type;
57         GtkWidget *config_folder;
58         GtkWidget *config_host;
59         GtkWidget *config_port;
60 };
61
62 static GtkWidget *hbox_auto1, *hbox_auto2, *hbox_manual1, *hbox_manual2;
63
64 static void foldersel_cb(GtkWidget *widget, gpointer data)
65 {
66         struct ClamAvPage *page = (struct ClamAvPage *) data;
67         FolderItem *item;
68         gchar *item_id;
69         gint newpos = 0;
70         
71         item = foldersel_folder_sel(NULL, FOLDER_SEL_MOVE, NULL, FALSE);
72         if (item && (item_id = folder_item_get_identifier(item)) != NULL) {
73                 gtk_editable_delete_text(GTK_EDITABLE(page->save_folder), 0, -1);
74                 gtk_editable_insert_text(GTK_EDITABLE(page->save_folder), item_id, strlen(item_id), &newpos);
75                 g_free(item_id);
76         }
77 }
78
79 static void clamd_folder_cb(GtkWidget *widget, gpointer data)
80 {
81         GtkWidget *dialog;
82         gchar* file;
83         gint newpos = 0;
84         struct ClamAvPage *page = (struct ClamAvPage *) data;
85
86         dialog = gtk_file_chooser_dialog_new(
87                                         "Select file with clamd configuration [clamd.conf]",
88                                         NULL,
89                                         GTK_FILE_CHOOSER_ACTION_OPEN,
90                                         GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
91                                         GTK_STOCK_APPLY, GTK_RESPONSE_APPLY,
92                                         NULL);
93         gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), "/etc");
94         if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_APPLY) {
95                 file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
96                 debug_print("New clamd.conf: %s\n", file);
97                 if (file) {
98                         gtk_editable_delete_text(GTK_EDITABLE(page->config_folder), 0, -1);
99                         gtk_editable_insert_text(GTK_EDITABLE(page->config_folder), file, strlen(file), &newpos);
100                         g_free(file);
101                 }
102         }
103         gtk_widget_destroy(dialog);
104 }
105
106 static void check_permission(gchar* folder) {
107         struct stat info;
108
109         if (g_stat(folder, &info) < 0)
110                 return;
111         mode_t perm = info.st_mode & ~(S_IFMT);
112         debug_print("%s: Old file permission: %05o\n", folder, perm);
113         if ((perm & S_IXOTH) != S_IXOTH) {
114                 perm = perm | S_IXOTH;
115                 g_chmod(folder, perm);
116         }
117         debug_print("%s: New file permission: %05o\n", folder, perm);
118 }
119
120 static void folder_permission_cb(GtkWidget *widget, gpointer data) {
121         static gchar* folders[] = {
122                         ".claws-mail",
123                         ".claws-mail/mimetmp",
124                         ".claws-mail/tmp",
125                         NULL};
126         const gchar* home = g_get_home_dir();
127         int i;
128
129         check_permission((gchar *) home);
130         for (i = 0; folders[i]; i++) {
131                 gchar* file = g_strdup_printf("%s/%s", home, folders[i]);
132                 check_permission(file);
133                 g_free(file);
134         }
135 }
136
137 static void clamav_show_config(Config* config) {
138         if (config) {
139                 if (config->ConfigType == MANUAL) {
140                         gtk_widget_hide(hbox_auto1);
141                         gtk_widget_hide(hbox_auto2);
142                         gtk_widget_show(hbox_manual1);
143                         gtk_widget_show(hbox_manual2);
144                 }
145                 else {
146                         gtk_widget_hide(hbox_manual1);
147                         gtk_widget_hide(hbox_manual2);
148                         gtk_widget_show(hbox_auto1);
149                         gtk_widget_show(hbox_auto2);
150                 }
151         }
152 }
153
154 static void setting_type_cb(GtkWidget *widget, gpointer data) {
155         gboolean state = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
156         struct ClamAvPage *page = (struct ClamAvPage *) data;
157         Config* c;
158         gint newpos = 0;
159         gboolean tmp_conf = FALSE;
160
161         if (page && page->page.widget) {
162                 /* Reset configuration */
163                 debug_print("Resetting configuration\n");
164                 gtk_editable_delete_text(GTK_EDITABLE(page->config_folder), 0, -1);
165                 gtk_editable_delete_text(GTK_EDITABLE(page->config_host), 0, -1);
166                 gtk_editable_delete_text(GTK_EDITABLE(page->config_port), 0, -1);
167                 clamav_save_config();
168         
169                 c = clamd_get_config();
170                 if (!c) {
171                         c = clamd_config_new();
172                         tmp_conf = TRUE;
173                 }
174                 if (state) {
175                         /* Automatic configuration */
176                         debug_print("Setting clamd to automatic configuration\n");
177                         if (clamd_find_socket()) {
178                                 if (tmp_conf) {
179                                         Config* clamd_conf = clamd_get_config();
180                                         if (clamd_conf->automatic.folder)
181                                                 c->automatic.folder = g_strdup(clamd_conf->automatic.folder);
182                                         else
183                                                 c->automatic.folder = g_strdup("");
184                                 }
185                                 if (c->ConfigType == AUTOMATIC) {
186                                         gtk_editable_insert_text(GTK_EDITABLE(page->config_folder),
187                                                 c->automatic.folder, strlen(c->automatic.folder), &newpos);
188                                         clamav_save_config();
189                                 }
190                         }
191                         c->ConfigType = AUTOMATIC;
192                         if (page->config_type)
193                             gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->config_type), TRUE);
194                 }
195                 else {
196                         /* Manual configuration */
197                         debug_print("Setting clamd to manual configuration\n");
198                         c->ConfigType = MANUAL;
199                         if (page->config_type)
200                             gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->config_type), FALSE);
201                 }
202                 clamav_show_config(c);
203                 if (tmp_conf)
204                         clamd_config_free(c);
205         }
206 }
207
208 static void clamav_create_widget_func(PrefsPage * _page, GtkWindow *window, gpointer data)
209 {
210         struct ClamAvPage *page = (struct ClamAvPage *) _page;
211         ClamAvConfig *config;
212         Config           *clamd_config;
213          
214         GtkWidget *vbox1, *vbox2;
215         GtkWidget *enable_clamav;
216         GtkWidget *label1;
217 /*      GtkWidget *enable_arc;*/
218         GtkWidget *label2;
219         GtkObject *max_size_adj;
220         GtkWidget *max_size;
221         GtkWidget *hbox1;
222         GtkWidget *recv_infected;
223         GtkWidget *save_folder;
224         GtkWidget *save_folder_select;
225         GtkWidget *clamd_conf_label;
226         GtkWidget *config_folder;
227         GtkWidget *config_host;
228         GtkWidget *config_port;
229         GtkWidget *config_folder_select;
230         GtkWidget *blank;
231         GtkWidget *permission_label;
232         GtkWidget *permission_select;
233         GtkWidget *host_label;
234         GtkWidget *port_label;
235         GtkWidget *setting_type;
236         GtkTooltips *tooltips;
237
238         tooltips = gtk_tooltips_new();
239         enable_clamav = page->enable_clamav;
240
241         vbox1 = gtk_vbox_new (FALSE, VSPACING);
242         gtk_widget_show (vbox1);
243         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
244
245         vbox2 = gtk_vbox_new (FALSE, 4);
246         gtk_widget_show (vbox2);
247         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
248
249         PACK_CHECK_BUTTON (vbox2, enable_clamav, _("Enable virus scanning"));
250 /*      PACK_CHECK_BUTTON (vbox2, enable_arc, _("Scan archive contents"));
251
252         SET_TOGGLE_SENSITIVITY (enable_clamav, enable_arc);*/
253
254         hbox1 = gtk_hbox_new (FALSE, 8);
255         gtk_widget_show (hbox1);
256         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
257 /*      SET_TOGGLE_SENSITIVITY (enable_arc, hbox1);*/
258
259         label1 = gtk_label_new(_("Maximum attachment size"));
260         gtk_widget_show (label1);
261         gtk_box_pack_start (GTK_BOX (hbox1), label1, FALSE, FALSE, 0);
262         SET_TOGGLE_SENSITIVITY (enable_clamav, label1);
263
264         max_size_adj = gtk_adjustment_new (1, 1, 1024, 1, 10, 0);
265         max_size = gtk_spin_button_new (GTK_ADJUSTMENT (max_size_adj), 1, 0);
266         gtk_widget_show (max_size);
267         gtk_box_pack_start (GTK_BOX (hbox1), max_size, FALSE, FALSE, 0);
268         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (max_size), TRUE);
269         gtk_tooltips_set_tip(tooltips, max_size,
270                              _("Message attachments larger than this will not be scanned"),
271                              NULL);
272         SET_TOGGLE_SENSITIVITY (enable_clamav, max_size);
273
274         label2 = gtk_label_new(_("MB"));
275         gtk_widget_show (label2);
276         gtk_box_pack_start (GTK_BOX (hbox1), label2, FALSE, FALSE, 0);
277         SET_TOGGLE_SENSITIVITY (enable_clamav, label2);
278
279         hbox1 = gtk_hbox_new (FALSE, 8);
280         gtk_widget_show (hbox1);
281         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
282
283         recv_infected = gtk_check_button_new_with_label(_("Save infected mail in"));
284         gtk_widget_show (recv_infected);
285         gtk_box_pack_start (GTK_BOX (hbox1), recv_infected, FALSE, FALSE, 0);
286         gtk_tooltips_set_tip(tooltips, recv_infected,
287                              _("Save mail that contains viruses"),
288                              NULL);
289         SET_TOGGLE_SENSITIVITY (enable_clamav, recv_infected);
290
291         save_folder = gtk_entry_new ();
292         gtk_widget_show (save_folder);
293         gtk_box_pack_start (GTK_BOX (hbox1), save_folder, TRUE, TRUE, 0);
294         gtk_tooltips_set_tip(tooltips, save_folder,
295                              _("Folder for storing infected mail. Leave empty to use the default trash folder"),
296                              NULL);
297         SET_TOGGLE_SENSITIVITY (enable_clamav, save_folder);
298
299         save_folder_select = gtkut_get_browse_directory_btn(_("_Browse"));
300         gtk_widget_show (save_folder_select);
301         gtk_box_pack_start (GTK_BOX (hbox1), save_folder_select, FALSE, FALSE, 0);
302         gtk_tooltips_set_tip(tooltips, save_folder_select,
303                              _("Click this button to select a folder for storing infected mail"),
304                              NULL);
305         SET_TOGGLE_SENSITIVITY (enable_clamav, save_folder_select);
306
307         hbox1 = gtk_hbox_new (FALSE, 8);
308         gtk_widget_show (hbox1);
309         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
310
311         setting_type = gtk_check_button_new_with_label(_("Automatic configuration"));
312         /*gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(setting_type), TRUE);*/
313         gtk_widget_show (setting_type);
314         gtk_box_pack_start (GTK_BOX (hbox1), setting_type, FALSE, FALSE, 0);
315         gtk_tooltips_set_tip(tooltips, setting_type,
316                              _("Should configuration be done automatic or manual"),
317                              NULL);
318         SET_TOGGLE_SENSITIVITY (enable_clamav, setting_type);
319         
320         hbox_auto1 = gtk_hbox_new (FALSE, 8);
321         gtk_widget_show (hbox_auto1);
322         gtk_box_pack_start (GTK_BOX (vbox2), hbox_auto1, FALSE, FALSE, 0);
323
324         clamd_conf_label = gtk_label_new(_("Where is clamd.conf"));
325         gtk_widget_show (clamd_conf_label);
326         gtk_box_pack_start (GTK_BOX (hbox_auto1), clamd_conf_label, FALSE, FALSE, 0);
327
328         config_folder = gtk_entry_new ();
329         gtk_widget_show (config_folder);
330         gtk_box_pack_start (GTK_BOX (hbox_auto1), config_folder, TRUE, TRUE, 0);
331         gtk_tooltips_set_tip(tooltips, config_folder,
332                              _("Full path to clamd.conf. If this field is not empty then the plugin has been able to locate the file automatically"),
333                              NULL);
334         SET_TOGGLE_SENSITIVITY (enable_clamav, config_folder);
335
336         config_folder_select = gtkut_get_browse_directory_btn(_("Br_owse"));
337         gtk_widget_show (config_folder_select);
338         gtk_box_pack_start (GTK_BOX (hbox_auto1), config_folder_select, FALSE, FALSE, 0);
339         gtk_tooltips_set_tip(tooltips, config_folder_select,
340                              _("Click this button to select full path to clamd.conf"),
341                              NULL);
342         SET_TOGGLE_SENSITIVITY (enable_clamav, config_folder_select);
343
344         hbox_auto2 = gtk_hbox_new (FALSE, 8);
345         gtk_widget_show (hbox_auto2);
346         gtk_box_pack_start (GTK_BOX (vbox2), hbox_auto2, FALSE, FALSE, 0);
347
348         permission_label = gtk_label_new(_("Check permission for folders and adjust if necessary"));
349         gtk_widget_show (permission_label);
350         gtk_box_pack_start (GTK_BOX (hbox_auto2), permission_label, FALSE, FALSE, 0);
351
352         blank = gtk_label_new("");
353         gtk_widget_show (blank);
354         gtk_box_pack_start (GTK_BOX (hbox_auto2), blank, TRUE, TRUE, 0);
355
356         permission_select = gtk_button_new_from_stock(GTK_STOCK_FIND_AND_REPLACE);
357                         /*gtk_button_new_with_mnemonic(_("_Check Permission"));*/
358         gtk_widget_show (permission_select);
359         gtk_box_pack_start (GTK_BOX (hbox_auto2), permission_select, FALSE, FALSE, 0);
360         gtk_tooltips_set_tip(tooltips, permission_select,
361                              _("Click this button to check and adjust folder permissions"),
362                              NULL);
363         SET_TOGGLE_SENSITIVITY (enable_clamav, permission_select);
364
365         hbox_manual1 = gtk_hbox_new (FALSE, 8);
366         gtk_widget_show (hbox_manual1);
367         gtk_box_pack_start (GTK_BOX (vbox2), hbox_manual1, FALSE, FALSE, 0);
368
369         host_label = gtk_label_new(_("Remote Host"));
370         gtk_widget_show (host_label);
371         gtk_box_pack_start (GTK_BOX (hbox_manual1), host_label, FALSE, FALSE, 0);
372
373         config_host = gtk_entry_new ();
374         gtk_widget_show (config_host);
375         gtk_box_pack_start (GTK_BOX (hbox_manual1), config_host, FALSE, FALSE, 0);
376         gtk_tooltips_set_tip(tooltips, config_host,
377                              _("Hostname or IP for remote host running clamav daemon"),
378                              NULL);
379         SET_TOGGLE_SENSITIVITY (enable_clamav, config_host);
380
381         blank = gtk_label_new("");
382         gtk_widget_show (blank);
383         gtk_box_pack_start (GTK_BOX (hbox_manual1), blank, TRUE, TRUE, 0);
384
385         hbox_manual2 = gtk_hbox_new (FALSE, 8);
386         gtk_widget_show (hbox_manual2);
387         gtk_box_pack_start (GTK_BOX (vbox2), hbox_manual2, FALSE, FALSE, 0);
388
389         port_label = gtk_label_new(_("Port"));
390         gtk_widget_show (port_label);
391         gtk_box_pack_start (GTK_BOX (hbox_manual2), port_label, FALSE, FALSE, 0);
392
393         config_port = gtk_entry_new ();
394         gtk_entry_set_width_chars(GTK_ENTRY(config_port), 5);
395         gtk_entry_set_max_length(GTK_ENTRY(config_port), 5);
396         gtk_widget_show (config_port);
397         gtk_box_pack_start (GTK_BOX (hbox_manual2), config_port, FALSE, FALSE, 0);
398         gtk_tooltips_set_tip(tooltips, config_port,
399                              _("Port number where clamav daemon is listening"),
400                              NULL);
401
402         blank = gtk_label_new("");
403         gtk_widget_show (blank);
404         gtk_box_pack_start (GTK_BOX (hbox_manual2), blank, TRUE, TRUE, 0);
405
406         SET_TOGGLE_SENSITIVITY (enable_clamav, config_port);
407
408         config = clamav_get_config();
409
410         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_clamav), config->clamav_enable);
411 /*      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_arc), config->clamav_enable_arc);*/
412         gtk_spin_button_set_value(GTK_SPIN_BUTTON(max_size), (float) config->clamav_max_size);
413         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(recv_infected), config->clamav_recv_infected);
414         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(setting_type), config->clamd_config_type);
415
416         g_signal_connect(G_OBJECT(save_folder_select), "clicked",
417                          G_CALLBACK(foldersel_cb), page);
418         g_signal_connect(G_OBJECT(config_folder_select), "clicked",
419                          G_CALLBACK(clamd_folder_cb), page);
420         g_signal_connect(G_OBJECT(permission_select), "clicked",
421                          G_CALLBACK(folder_permission_cb), page);
422         g_signal_connect(G_OBJECT(setting_type), "clicked",
423                          G_CALLBACK(setting_type_cb), page);
424
425         clamd_config = clamd_get_config();
426                 
427         if (config->clamav_save_folder != NULL)
428                 gtk_entry_set_text(GTK_ENTRY(save_folder), config->clamav_save_folder);
429         if (!config->clamd_config_type) {
430         /*if (config->clamd_host && strlen(config->clamd_host) > 0 && config->clamd_port > 0) {*/
431                 gtk_entry_set_text(GTK_ENTRY(config_host), config->clamd_host);
432                 gchar* s = int2char(config->clamd_port);
433                 gtk_entry_set_text(GTK_ENTRY(config_port), s);
434                 g_free(s);
435                 /* activate manual checkbox and blind folder */
436                 debug_print("Showing manual configuration and hiding automatic configuration\n");
437                 if (! clamd_config) {
438                         clamd_config = clamd_config_new();
439                         clamd_config->ConfigType = MANUAL;
440                         clamav_show_config(clamd_config);
441                         clamd_config_free(clamd_config);
442                 }
443                 else
444                         clamav_show_config(clamd_config);
445         }
446         else {
447         //else if (config->clamd_config_folder == NULL || strlen(config->clamd_config_folder) == 0) {
448                 if (clamd_find_socket()) {
449                         Config* c = clamd_get_config();
450                         if (c && c->ConfigType == AUTOMATIC) {
451                                 config->clamd_config_folder = g_strdup(c->automatic.folder);
452                                 /* deactivate manual checkbox and blind host and port */
453                                 debug_print("Showing automatic configuration and hiding manual configuration\n");
454                                 clamav_show_config(c);
455                                 gint newpos = 0;
456                                 gtk_editable_delete_text(GTK_EDITABLE(config_folder), 0, -1);
457                                 gtk_editable_insert_text(GTK_EDITABLE(config_folder), 
458                                         config->clamd_config_folder, strlen(config->clamd_config_folder), &newpos);
459                         }
460                         else if (c && c->ConfigType == MANUAL) {
461                                 /* deactivate automatic automatic configuration */
462                                 debug_print("Showing manual configuration and hiding automatic configuration\n");
463                                 clamav_show_config(c);
464                         }
465                 }       
466         }
467 /*      else {
468                 gtk_entry_set_text(GTK_ENTRY(config_folder), config->clamd_config_folder);
469                 // deactivate manual checkbox and blind host and port
470                 debug_print("Showing automatic configuration and hiding manual configuration\n");
471                 if (! clamd_config) {
472                         clamd_config = clamd_config_new();
473                         clamd_config->ConfigType = AUTOMATIC;
474                         clamav_show_config(clamd_config);
475                         clamd_config_free(clamd_config);
476                 }
477                 else
478                         clamav_show_config(clamd_config);
479         }*/
480
481         page->enable_clamav = enable_clamav;
482 /*      page->enable_arc = enable_arc;*/
483         page->max_size = max_size;
484         page->recv_infected = recv_infected;
485         page->save_folder = save_folder;
486         page->config_type = setting_type;
487         page->config_folder = config_folder;
488         page->config_host = config_host;
489         page->config_port = config_port;
490         page->page.widget = vbox1;
491         
492         clamav_save_config();
493 }
494
495 static void clamav_destroy_widget_func(PrefsPage *_page)
496 {
497         debug_print("Destroying Clamd widget\n");
498 }
499
500 static void clamav_save_func(PrefsPage *_page)
501 {
502         struct ClamAvPage *page = (struct ClamAvPage *) _page;
503         ClamAvConfig *config;
504
505         debug_print("Saving Clamd Page\n");
506
507         config = clamav_get_config();
508
509         config->clamav_enable = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable_clamav));
510 /*      config->clamav_enable_arc = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable_arc));*/
511
512         config->clamav_max_size = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->max_size));
513         config->clamav_recv_infected = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->recv_infected));
514         g_free(config->clamav_save_folder);
515         config->clamav_save_folder = gtk_editable_get_chars(GTK_EDITABLE(page->save_folder), 0, -1);
516         config->clamd_config_type = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->config_type));
517         g_free(config->clamd_config_folder);
518         config->clamd_config_folder = gtk_editable_get_chars(GTK_EDITABLE(page->config_folder), 0, -1);
519         g_free(config->clamd_host);
520         config->clamd_host = gtk_editable_get_chars(GTK_EDITABLE(page->config_host), 0, -1);
521         config->clamd_port = atoi(gtk_entry_get_text(GTK_ENTRY(page->config_port)));
522
523         if (config->clamav_enable) {
524                 Clamd_Stat status = clamd_prepare();
525                 switch (status) {
526                         case NO_SOCKET: 
527                                 g_warning("[New config] No socket information");
528                                 alertpanel_error(_("New config\nNo socket information.\nAntivirus disabled."));
529                                 break;
530                         case NO_CONNECTION:
531                                 g_warning("[New config] Clamd does not respond to ping");
532                                 alertpanel_warning(_("New config\nClamd does not respond to ping.\nIs clamd running?"));
533                                 break;
534                         default:
535                                 break;
536                 }
537         }
538         clamav_save_config();
539 }
540
541 static struct ClamAvPage clamav_page;
542
543 static void gtk_message_callback(gchar *message)
544 {
545         statusbar_print_all("%s", message);
546 }
547
548 gint clamav_gtk_init(void)
549 {
550         static gchar *path[3];
551
552         path[0] = _("Plugins");
553         path[1] = _("Clam AntiVirus");
554         path[2] = NULL;
555
556         clamav_page.page.path = path;
557         clamav_page.page.create_widget = clamav_create_widget_func;
558         clamav_page.page.destroy_widget = clamav_destroy_widget_func;
559         clamav_page.page.save_page = clamav_save_func;
560         clamav_page.page.weight = 35.0;
561         
562         prefs_gtk_register_page((PrefsPage *) &clamav_page);
563         clamav_set_message_callback(gtk_message_callback);
564
565         debug_print("Clamd GTK plugin loaded\n");
566         return 0;       
567 }
568
569 void clamav_gtk_done(void)
570 {
571         prefs_gtk_unregister_page((PrefsPage *) &clamav_page);
572 }