2013-02-17 [colin] 3.9.0cvs75
[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         g_stat(folder, &info);
110         mode_t perm = info.st_mode & ~(S_IFMT);
111         debug_print("%s: Old file permission: %05o\n", folder, perm);
112         if ((perm & S_IXOTH) != S_IXOTH) {
113                 perm = perm | S_IXOTH;
114                 g_chmod(folder, perm);
115         }
116         debug_print("%s: New file permission: %05o\n", folder, perm);
117 }
118
119 static void folder_permission_cb(GtkWidget *widget, gpointer data) {
120         static gchar* folders[] = {
121                         ".claws-mail",
122                         ".claws-mail/mimetmp",
123                         ".claws-mail/tmp",
124                         NULL};
125         const gchar* home = g_get_home_dir();
126         int i;
127
128         check_permission((gchar *) home);
129         for (i = 0; folders[i]; i++) {
130                 gchar* file = g_strdup_printf("%s/%s", home, folders[i]);
131                 check_permission(file);
132                 g_free(file);
133         }
134 }
135
136 static void clamav_show_config(Config* config) {
137         if (config) {
138                 if (config->ConfigType == MANUAL) {
139                         gtk_widget_hide(hbox_auto1);
140                         gtk_widget_hide(hbox_auto2);
141                         gtk_widget_show(hbox_manual1);
142                         gtk_widget_show(hbox_manual2);
143                 }
144                 else {
145                         gtk_widget_hide(hbox_manual1);
146                         gtk_widget_hide(hbox_manual2);
147                         gtk_widget_show(hbox_auto1);
148                         gtk_widget_show(hbox_auto2);
149                 }
150         }
151 }
152
153 static void setting_type_cb(GtkWidget *widget, gpointer data) {
154         gboolean state = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
155         struct ClamAvPage *page = (struct ClamAvPage *) data;
156         Config* c;
157         gint newpos = 0;
158         gboolean tmp_conf = FALSE;
159
160         if (page && page->page.widget) {
161                 /* Reset configuration */
162                 debug_print("Resetting configuration\n");
163                 gtk_editable_delete_text(GTK_EDITABLE(page->config_folder), 0, -1);
164                 gtk_editable_delete_text(GTK_EDITABLE(page->config_host), 0, -1);
165                 gtk_editable_delete_text(GTK_EDITABLE(page->config_port), 0, -1);
166                 clamav_save_config();
167         
168                 c = clamd_get_config();
169                 if (!c) {
170                         c = clamd_config_new();
171                         tmp_conf = TRUE;
172                 }
173                 if (state) {
174                         /* Automatic configuration */
175                         debug_print("Setting clamd to automatic configuration\n");
176                         if (clamd_find_socket()) {
177                                 if (tmp_conf) {
178                                         Config* clamd_conf = clamd_get_config();
179                                         if (clamd_conf->automatic.folder)
180                                                 c->automatic.folder = g_strdup(clamd_conf->automatic.folder);
181                                         else
182                                                 c->automatic.folder = g_strdup("");
183                                 }
184                                 if (c->ConfigType == AUTOMATIC) {
185                                         gtk_editable_insert_text(GTK_EDITABLE(page->config_folder),
186                                                 c->automatic.folder, strlen(c->automatic.folder), &newpos);
187                                         clamav_save_config();
188                                 }
189                         }
190                         c->ConfigType = AUTOMATIC;
191                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->config_type), TRUE);
192                 }
193                 else {
194                         /* Manual configuration */
195                         debug_print("Setting clamd to manual configuration\n");
196                         c->ConfigType = MANUAL;
197                         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->config_type), FALSE);
198                 }
199                 clamav_show_config(c);
200                 if (tmp_conf)
201                         clamd_config_free(c);
202         }
203 }
204
205 static void clamav_create_widget_func(PrefsPage * _page, GtkWindow *window, gpointer data)
206 {
207         struct ClamAvPage *page = (struct ClamAvPage *) _page;
208         ClamAvConfig *config;
209         Config           *clamd_config;
210          
211         GtkWidget *vbox1, *vbox2;
212         GtkWidget *enable_clamav;
213         GtkWidget *label1;
214 /*      GtkWidget *enable_arc;*/
215         GtkWidget *label2;
216         GtkObject *max_size_adj;
217         GtkWidget *max_size;
218         GtkWidget *hbox1;
219         GtkWidget *recv_infected;
220         GtkWidget *save_folder;
221         GtkWidget *save_folder_select;
222         GtkWidget *clamd_conf_label;
223         GtkWidget *config_folder;
224         GtkWidget *config_host;
225         GtkWidget *config_port;
226         GtkWidget *config_folder_select;
227         GtkWidget *blank;
228         GtkWidget *permission_label;
229         GtkWidget *permission_select;
230         GtkWidget *host_label;
231         GtkWidget *port_label;
232         GtkWidget *setting_type;
233         GtkTooltips *tooltips;
234
235         tooltips = gtk_tooltips_new();
236         enable_clamav = page->enable_clamav;
237
238         vbox1 = gtk_vbox_new (FALSE, VSPACING);
239         gtk_widget_show (vbox1);
240         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
241
242         vbox2 = gtk_vbox_new (FALSE, 4);
243         gtk_widget_show (vbox2);
244         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
245
246         PACK_CHECK_BUTTON (vbox2, enable_clamav, _("Enable virus scanning"));
247 /*      PACK_CHECK_BUTTON (vbox2, enable_arc, _("Scan archive contents"));
248
249         SET_TOGGLE_SENSITIVITY (enable_clamav, enable_arc);*/
250
251         hbox1 = gtk_hbox_new (FALSE, 8);
252         gtk_widget_show (hbox1);
253         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
254 /*      SET_TOGGLE_SENSITIVITY (enable_arc, hbox1);*/
255
256         label1 = gtk_label_new(_("Maximum attachment size"));
257         gtk_widget_show (label1);
258         gtk_box_pack_start (GTK_BOX (hbox1), label1, FALSE, FALSE, 0);
259         SET_TOGGLE_SENSITIVITY (enable_clamav, label1);
260
261         max_size_adj = gtk_adjustment_new (1, 1, 1024, 1, 10, 0);
262         max_size = gtk_spin_button_new (GTK_ADJUSTMENT (max_size_adj), 1, 0);
263         gtk_widget_show (max_size);
264         gtk_box_pack_start (GTK_BOX (hbox1), max_size, FALSE, FALSE, 0);
265         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (max_size), TRUE);
266         gtk_tooltips_set_tip(tooltips, max_size,
267                              _("Message attachments larger than this will not be scanned"),
268                              NULL);
269         SET_TOGGLE_SENSITIVITY (enable_clamav, max_size);
270
271         label2 = gtk_label_new(_("MB"));
272         gtk_widget_show (label2);
273         gtk_box_pack_start (GTK_BOX (hbox1), label2, FALSE, FALSE, 0);
274         SET_TOGGLE_SENSITIVITY (enable_clamav, label2);
275
276         hbox1 = gtk_hbox_new (FALSE, 8);
277         gtk_widget_show (hbox1);
278         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
279
280         recv_infected = gtk_check_button_new_with_label(_("Save infected mail in"));
281         gtk_widget_show (recv_infected);
282         gtk_box_pack_start (GTK_BOX (hbox1), recv_infected, FALSE, FALSE, 0);
283         gtk_tooltips_set_tip(tooltips, recv_infected,
284                              _("Save mail that contains viruses"),
285                              NULL);
286         SET_TOGGLE_SENSITIVITY (enable_clamav, recv_infected);
287
288         save_folder = gtk_entry_new ();
289         gtk_widget_show (save_folder);
290         gtk_box_pack_start (GTK_BOX (hbox1), save_folder, TRUE, TRUE, 0);
291         gtk_tooltips_set_tip(tooltips, save_folder,
292                              _("Folder for storing infected mail. Leave empty to use the default trash folder"),
293                              NULL);
294         SET_TOGGLE_SENSITIVITY (enable_clamav, save_folder);
295
296         save_folder_select = gtkut_get_browse_directory_btn(_("_Browse"));
297         gtk_widget_show (save_folder_select);
298         gtk_box_pack_start (GTK_BOX (hbox1), save_folder_select, FALSE, FALSE, 0);
299         gtk_tooltips_set_tip(tooltips, save_folder_select,
300                              _("Click this button to select a folder for storing infected mail"),
301                              NULL);
302         SET_TOGGLE_SENSITIVITY (enable_clamav, save_folder_select);
303
304         hbox1 = gtk_hbox_new (FALSE, 8);
305         gtk_widget_show (hbox1);
306         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
307
308         setting_type = gtk_check_button_new_with_label(_("Automatic configuration"));
309         /*gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(setting_type), TRUE);*/
310         gtk_widget_show (setting_type);
311         gtk_box_pack_start (GTK_BOX (hbox1), setting_type, FALSE, FALSE, 0);
312         gtk_tooltips_set_tip(tooltips, setting_type,
313                              _("Should configuration be done automatic or manual"),
314                              NULL);
315         SET_TOGGLE_SENSITIVITY (enable_clamav, setting_type);
316         
317         hbox_auto1 = gtk_hbox_new (FALSE, 8);
318         gtk_widget_show (hbox_auto1);
319         gtk_box_pack_start (GTK_BOX (vbox2), hbox_auto1, FALSE, FALSE, 0);
320
321         clamd_conf_label = gtk_label_new(_("Where is clamd.conf"));
322         gtk_widget_show (clamd_conf_label);
323         gtk_box_pack_start (GTK_BOX (hbox_auto1), clamd_conf_label, FALSE, FALSE, 0);
324
325         config_folder = gtk_entry_new ();
326         gtk_widget_show (config_folder);
327         gtk_box_pack_start (GTK_BOX (hbox_auto1), config_folder, TRUE, TRUE, 0);
328         gtk_tooltips_set_tip(tooltips, config_folder,
329                              _("Full path to clamd.conf. If this field is not empty then the plugin has been able to locate the file automatically"),
330                              NULL);
331         SET_TOGGLE_SENSITIVITY (enable_clamav, config_folder);
332
333         config_folder_select = gtkut_get_browse_directory_btn(_("Br_owse"));
334         gtk_widget_show (config_folder_select);
335         gtk_box_pack_start (GTK_BOX (hbox_auto1), config_folder_select, FALSE, FALSE, 0);
336         gtk_tooltips_set_tip(tooltips, config_folder_select,
337                              _("Click this button to select full path to clamd.conf"),
338                              NULL);
339         SET_TOGGLE_SENSITIVITY (enable_clamav, config_folder_select);
340
341         hbox_auto2 = gtk_hbox_new (FALSE, 8);
342         gtk_widget_show (hbox_auto2);
343         gtk_box_pack_start (GTK_BOX (vbox2), hbox_auto2, FALSE, FALSE, 0);
344
345         permission_label = gtk_label_new(_("Check permission for folders and adjust if necessary"));
346         gtk_widget_show (permission_label);
347         gtk_box_pack_start (GTK_BOX (hbox_auto2), permission_label, FALSE, FALSE, 0);
348
349         blank = gtk_label_new("");
350         gtk_widget_show (blank);
351         gtk_box_pack_start (GTK_BOX (hbox_auto2), blank, TRUE, TRUE, 0);
352
353         permission_select = gtk_button_new_from_stock(GTK_STOCK_FIND_AND_REPLACE);
354                         /*gtk_button_new_with_mnemonic(_("_Check Permission"));*/
355         gtk_widget_show (permission_select);
356         gtk_box_pack_start (GTK_BOX (hbox_auto2), permission_select, FALSE, FALSE, 0);
357         gtk_tooltips_set_tip(tooltips, permission_select,
358                              _("Click this button to check and adjust folder permissions"),
359                              NULL);
360         SET_TOGGLE_SENSITIVITY (enable_clamav, permission_select);
361
362         hbox_manual1 = gtk_hbox_new (FALSE, 8);
363         gtk_widget_show (hbox_manual1);
364         gtk_box_pack_start (GTK_BOX (vbox2), hbox_manual1, FALSE, FALSE, 0);
365
366         host_label = gtk_label_new(_("Remote Host"));
367         gtk_widget_show (host_label);
368         gtk_box_pack_start (GTK_BOX (hbox_manual1), host_label, FALSE, FALSE, 0);
369
370         config_host = gtk_entry_new ();
371         gtk_widget_show (config_host);
372         gtk_box_pack_start (GTK_BOX (hbox_manual1), config_host, FALSE, FALSE, 0);
373         gtk_tooltips_set_tip(tooltips, config_host,
374                              _("Hostname or IP for remote host running clamav daemon"),
375                              NULL);
376         SET_TOGGLE_SENSITIVITY (enable_clamav, config_host);
377
378         blank = gtk_label_new("");
379         gtk_widget_show (blank);
380         gtk_box_pack_start (GTK_BOX (hbox_manual1), blank, TRUE, TRUE, 0);
381
382         hbox_manual2 = gtk_hbox_new (FALSE, 8);
383         gtk_widget_show (hbox_manual2);
384         gtk_box_pack_start (GTK_BOX (vbox2), hbox_manual2, FALSE, FALSE, 0);
385
386         port_label = gtk_label_new(_("Port"));
387         gtk_widget_show (port_label);
388         gtk_box_pack_start (GTK_BOX (hbox_manual2), port_label, FALSE, FALSE, 0);
389
390         config_port = gtk_entry_new ();
391         gtk_entry_set_width_chars(GTK_ENTRY(config_port), 5);
392         gtk_entry_set_max_length(GTK_ENTRY(config_port), 5);
393         gtk_widget_show (config_port);
394         gtk_box_pack_start (GTK_BOX (hbox_manual2), config_port, FALSE, FALSE, 0);
395         gtk_tooltips_set_tip(tooltips, config_port,
396                              _("Port number where clamav daemon is listening"),
397                              NULL);
398
399         blank = gtk_label_new("");
400         gtk_widget_show (blank);
401         gtk_box_pack_start (GTK_BOX (hbox_manual2), blank, TRUE, TRUE, 0);
402
403         SET_TOGGLE_SENSITIVITY (enable_clamav, config_port);
404
405         g_signal_connect(G_OBJECT(save_folder_select), "clicked", 
406                          G_CALLBACK(foldersel_cb), page);
407         g_signal_connect(G_OBJECT(config_folder_select), "clicked",
408                          G_CALLBACK(clamd_folder_cb), page);
409         g_signal_connect(G_OBJECT(permission_select), "clicked",
410                          G_CALLBACK(folder_permission_cb), page);
411         g_signal_connect(G_OBJECT(setting_type), "clicked",
412                          G_CALLBACK(setting_type_cb), page);
413
414         config = clamav_get_config();
415
416         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_clamav), config->clamav_enable);
417 /*      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_arc), config->clamav_enable_arc);*/
418         gtk_spin_button_set_value(GTK_SPIN_BUTTON(max_size), (float) config->clamav_max_size);
419         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(recv_infected), config->clamav_recv_infected);
420         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(setting_type), config->clamd_config_type);
421
422         clamd_config = clamd_get_config();
423                 
424         if (config->clamav_save_folder != NULL)
425                 gtk_entry_set_text(GTK_ENTRY(save_folder), config->clamav_save_folder);
426         if (!config->clamd_config_type) {
427         /*if (config->clamd_host && strlen(config->clamd_host) > 0 && config->clamd_port > 0) {*/
428                 gtk_entry_set_text(GTK_ENTRY(config_host), config->clamd_host);
429                 gchar* s = int2char(config->clamd_port);
430                 gtk_entry_set_text(GTK_ENTRY(config_port), s);
431                 g_free(s);
432                 /* activate manual checkbox and blind folder */
433                 debug_print("Showing manual configuration and hiding automatic configuration\n");
434                 if (! clamd_config) {
435                         clamd_config = clamd_config_new();
436                         clamd_config->ConfigType = MANUAL;
437                         clamav_show_config(clamd_config);
438                         clamd_config_free(clamd_config);
439                 }
440                 else
441                         clamav_show_config(clamd_config);
442         }
443         else {
444         //else if (config->clamd_config_folder == NULL || strlen(config->clamd_config_folder) == 0) {
445                 if (clamd_find_socket()) {
446                         Config* c = clamd_get_config();
447                         if (c && c->ConfigType == AUTOMATIC) {
448                                 config->clamd_config_folder = g_strdup(c->automatic.folder);
449                                 /* deactivate manual checkbox and blind host and port */
450                                 debug_print("Showing automatic configuration and hiding manual configuration\n");
451                                 clamav_show_config(c);
452                                 gint newpos = 0;
453                                 gtk_editable_delete_text(GTK_EDITABLE(config_folder), 0, -1);
454                                 gtk_editable_insert_text(GTK_EDITABLE(config_folder), 
455                                         config->clamd_config_folder, strlen(config->clamd_config_folder), &newpos);
456                         }
457                         else if (c && c->ConfigType == MANUAL) {
458                                 /* deactivate automatic automatic configuration */
459                                 debug_print("Showing manual configuration and hiding automatic configuration\n");
460                                 clamav_show_config(c);
461                         }
462                 }
463         }
464 /*      else {
465                 gtk_entry_set_text(GTK_ENTRY(config_folder), config->clamd_config_folder);
466                 // deactivate manual checkbox and blind host and port
467                 debug_print("Showing automatic configuration and hiding manual configuration\n");
468                 if (! clamd_config) {
469                         clamd_config = clamd_config_new();
470                         clamd_config->ConfigType = AUTOMATIC;
471                         clamav_show_config(clamd_config);
472                         clamd_config_free(clamd_config);
473                 }
474                 else
475                         clamav_show_config(clamd_config);
476         }*/
477
478         page->enable_clamav = enable_clamav;
479 /*      page->enable_arc = enable_arc;*/
480         page->max_size = max_size;
481         page->recv_infected = recv_infected;
482         page->save_folder = save_folder;
483         page->config_type = setting_type;
484         page->config_folder = config_folder;
485         page->config_host = config_host;
486         page->config_port = config_port;
487         page->page.widget = vbox1;
488         
489         clamav_save_config();
490 }
491
492 static void clamav_destroy_widget_func(PrefsPage *_page)
493 {
494         debug_print("Destroying Clamd widget\n");
495 }
496
497 static void clamav_save_func(PrefsPage *_page)
498 {
499         struct ClamAvPage *page = (struct ClamAvPage *) _page;
500         ClamAvConfig *config;
501
502         debug_print("Saving Clamd Page\n");
503
504         config = clamav_get_config();
505
506         config->clamav_enable = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable_clamav));
507 /*      config->clamav_enable_arc = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->enable_arc));*/
508
509         config->clamav_max_size = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->max_size));
510         config->clamav_recv_infected = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->recv_infected));
511         g_free(config->clamav_save_folder);
512         config->clamav_save_folder = gtk_editable_get_chars(GTK_EDITABLE(page->save_folder), 0, -1);
513         config->clamd_config_type = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->config_type));
514         g_free(config->clamd_config_folder);
515         config->clamd_config_folder = gtk_editable_get_chars(GTK_EDITABLE(page->config_folder), 0, -1);
516         g_free(config->clamd_host);
517         config->clamd_host = gtk_editable_get_chars(GTK_EDITABLE(page->config_host), 0, -1);
518         config->clamd_port = atoi(gtk_entry_get_text(GTK_ENTRY(page->config_port)));
519
520         if (config->clamav_enable) {
521                 Clamd_Stat status = clamd_prepare();
522                 switch (status) {
523                         case NO_SOCKET: 
524                                 g_warning("[New config] No socket information");
525                                 alertpanel_error(_("New config\nNo socket information.\nAntivirus disabled."));
526                                 break;
527                         case NO_CONNECTION:
528                                 g_warning("[New config] Clamd does not respond to ping");
529                                 alertpanel_warning(_("New config\nClamd does not respond to ping.\nIs clamd running?"));
530                                 break;
531                         default:
532                                 break;
533                 }
534         }
535         clamav_save_config();
536 }
537
538 static struct ClamAvPage clamav_page;
539
540 static void gtk_message_callback(gchar *message)
541 {
542         statusbar_print_all("%s", message);
543 }
544
545 gint clamav_gtk_init(void)
546 {
547         static gchar *path[3];
548
549         path[0] = _("Plugins");
550         path[1] = _("Clam AntiVirus");
551         path[2] = NULL;
552
553         clamav_page.page.path = path;
554         clamav_page.page.create_widget = clamav_create_widget_func;
555         clamav_page.page.destroy_widget = clamav_destroy_widget_func;
556         clamav_page.page.save_page = clamav_save_func;
557         clamav_page.page.weight = 35.0;
558         
559         prefs_gtk_register_page((PrefsPage *) &clamav_page);
560         clamav_set_message_callback(gtk_message_callback);
561
562         debug_print("Clamd GTK plugin loaded\n");
563         return 0;       
564 }
565
566 void clamav_gtk_done(void)
567 {
568         prefs_gtk_unregister_page((PrefsPage *) &clamav_page);
569 }