Allow custom window title for the folder selection dialog.
[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                         _("Select folder to store infected messages in"));
73         if (item && (item_id = folder_item_get_identifier(item)) != NULL) {
74                 gtk_editable_delete_text(GTK_EDITABLE(page->save_folder), 0, -1);
75                 gtk_editable_insert_text(GTK_EDITABLE(page->save_folder), item_id, strlen(item_id), &newpos);
76                 g_free(item_id);
77         }
78 }
79
80 static void clamd_folder_cb(GtkWidget *widget, gpointer data)
81 {
82         GtkWidget *dialog;
83         gchar* file;
84         gint newpos = 0;
85         struct ClamAvPage *page = (struct ClamAvPage *) data;
86
87         dialog = gtk_file_chooser_dialog_new(
88                                         "Select file with clamd configuration [clamd.conf]",
89                                         NULL,
90                                         GTK_FILE_CHOOSER_ACTION_OPEN,
91                                         GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
92                                         GTK_STOCK_APPLY, GTK_RESPONSE_APPLY,
93                                         NULL);
94         gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), "/etc");
95         if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_APPLY) {
96                 file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
97                 debug_print("New clamd.conf: %s\n", file);
98                 if (file) {
99                         gtk_editable_delete_text(GTK_EDITABLE(page->config_folder), 0, -1);
100                         gtk_editable_insert_text(GTK_EDITABLE(page->config_folder), file, strlen(file), &newpos);
101                         g_free(file);
102                 }
103         }
104         gtk_widget_destroy(dialog);
105 }
106
107 static void check_permission(gchar* folder) {
108         GStatBuf info;
109
110         if (g_stat(folder, &info) < 0)
111                 return;
112         mode_t perm = info.st_mode & ~(S_IFMT);
113         debug_print("%s: Old file permission: %05o\n", folder, perm);
114         if ((perm & S_IXOTH) != S_IXOTH) {
115                 perm = perm | S_IXOTH;
116                 g_chmod(folder, perm);
117         }
118         debug_print("%s: New file permission: %05o\n", folder, perm);
119 }
120
121 static void folder_permission_cb(GtkWidget *widget, gpointer data) {
122         static gchar* folders[] = {
123                         ".claws-mail",
124                         ".claws-mail/mimetmp",
125                         ".claws-mail/tmp",
126                         NULL};
127         const gchar* home = g_get_home_dir();
128         int i;
129
130         check_permission((gchar *) home);
131         for (i = 0; folders[i]; i++) {
132                 gchar* file = g_strdup_printf("%s/%s", home, folders[i]);
133                 check_permission(file);
134                 g_free(file);
135         }
136 }
137
138 static void clamav_show_config(Config* config) {
139         if (config) {
140                 if (config->ConfigType == MANUAL) {
141                         gtk_widget_hide(hbox_auto1);
142                         gtk_widget_hide(hbox_auto2);
143                         gtk_widget_show(hbox_manual1);
144                         gtk_widget_show(hbox_manual2);
145                 }
146                 else {
147                         gtk_widget_hide(hbox_manual1);
148                         gtk_widget_hide(hbox_manual2);
149                         gtk_widget_show(hbox_auto1);
150                         gtk_widget_show(hbox_auto2);
151                 }
152         }
153 }
154
155 static void setting_type_cb(GtkWidget *widget, gpointer data) {
156         gboolean state = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
157         struct ClamAvPage *page = (struct ClamAvPage *) data;
158         Config* c;
159         gint newpos = 0;
160         gboolean tmp_conf = FALSE;
161
162         if (page && page->page.widget) {
163                 /* Reset configuration */
164                 debug_print("Resetting configuration\n");
165                 gtk_editable_delete_text(GTK_EDITABLE(page->config_folder), 0, -1);
166                 gtk_editable_delete_text(GTK_EDITABLE(page->config_host), 0, -1);
167                 gtk_spin_button_set_value(GTK_SPIN_BUTTON(page->config_port), (gdouble) 0);
168                 clamav_save_config();
169         
170                 c = clamd_get_config();
171                 if (!c) {
172                         c = clamd_config_new();
173                         tmp_conf = TRUE;
174                 }
175                 if (state) {
176                         /* Automatic configuration */
177                         debug_print("Setting clamd to automatic configuration\n");
178                         if (clamd_find_socket()) {
179                                 if (tmp_conf) {
180                                         Config* clamd_conf = clamd_get_config();
181                                         if (clamd_conf->automatic.folder)
182                                                 c->automatic.folder = g_strdup(clamd_conf->automatic.folder);
183                                         else
184                                                 c->automatic.folder = g_strdup("");
185                                 }
186                                 if (c->ConfigType == AUTOMATIC) {
187                                         gtk_editable_insert_text(GTK_EDITABLE(page->config_folder),
188                                                 c->automatic.folder, strlen(c->automatic.folder), &newpos);
189                                         clamav_save_config();
190                                 }
191                         }
192                         c->ConfigType = AUTOMATIC;
193                         if (page->config_type)
194                             gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->config_type), TRUE);
195                 }
196                 else {
197                         /* Manual configuration */
198                         debug_print("Setting clamd to manual configuration\n");
199                         c->ConfigType = MANUAL;
200                         if (page->config_type)
201                             gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(page->config_type), FALSE);
202                 }
203                 clamav_show_config(c);
204                 if (tmp_conf)
205                         clamd_config_free(c);
206         }
207 }
208
209 static void clamav_create_widget_func(PrefsPage * _page, GtkWindow *window, gpointer data)
210 {
211         struct ClamAvPage *page = (struct ClamAvPage *) _page;
212         ClamAvConfig *config;
213         Config           *clamd_config;
214          
215         GtkWidget *vbox1, *vbox2;
216         GtkWidget *enable_clamav;
217         GtkWidget *label1;
218 /*      GtkWidget *enable_arc;*/
219         GtkWidget *label2;
220         GtkObject *max_size_adj;
221         GtkWidget *max_size;
222         GtkWidget *hbox1;
223         GtkWidget *recv_infected;
224         GtkWidget *save_folder;
225         GtkWidget *save_folder_select;
226         GtkWidget *clamd_conf_label;
227         GtkWidget *config_folder;
228         GtkWidget *config_host;
229         GtkWidget *config_port;
230         GtkWidget *config_folder_select;
231         GtkWidget *blank;
232         GtkWidget *permission_label;
233         GtkWidget *permission_select;
234         GtkWidget *host_label;
235         GtkWidget *port_label;
236         GtkWidget *setting_type;
237         GtkTooltips *tooltips;
238
239         tooltips = gtk_tooltips_new();
240         enable_clamav = page->enable_clamav;
241
242         vbox1 = gtk_vbox_new (FALSE, VSPACING);
243         gtk_widget_show (vbox1);
244         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
245
246         vbox2 = gtk_vbox_new (FALSE, 4);
247         gtk_widget_show (vbox2);
248         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
249
250         PACK_CHECK_BUTTON (vbox2, enable_clamav, _("Enable virus scanning"));
251 /*      PACK_CHECK_BUTTON (vbox2, enable_arc, _("Scan archive contents"));
252
253         SET_TOGGLE_SENSITIVITY (enable_clamav, enable_arc);*/
254
255         hbox1 = gtk_hbox_new (FALSE, 8);
256         gtk_widget_show (hbox1);
257         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
258 /*      SET_TOGGLE_SENSITIVITY (enable_arc, hbox1);*/
259
260         label1 = gtk_label_new(_("Maximum attachment size"));
261         gtk_widget_show (label1);
262         gtk_box_pack_start (GTK_BOX (hbox1), label1, FALSE, FALSE, 0);
263         SET_TOGGLE_SENSITIVITY (enable_clamav, label1);
264
265         max_size_adj = gtk_adjustment_new (1, 1, 1024, 1, 10, 0);
266         max_size = gtk_spin_button_new (GTK_ADJUSTMENT (max_size_adj), 1, 0);
267         gtk_widget_show (max_size);
268         gtk_box_pack_start (GTK_BOX (hbox1), max_size, FALSE, FALSE, 0);
269         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (max_size), TRUE);
270         gtk_tooltips_set_tip(tooltips, max_size,
271                              _("Message attachments larger than this will not be scanned"),
272                              NULL);
273         SET_TOGGLE_SENSITIVITY (enable_clamav, max_size);
274
275         label2 = gtk_label_new(_("MB"));
276         gtk_widget_show (label2);
277         gtk_box_pack_start (GTK_BOX (hbox1), label2, FALSE, FALSE, 0);
278         SET_TOGGLE_SENSITIVITY (enable_clamav, label2);
279
280         hbox1 = gtk_hbox_new (FALSE, 8);
281         gtk_widget_show (hbox1);
282         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
283
284         recv_infected = gtk_check_button_new_with_label(_("Save infected mail in"));
285         gtk_widget_show (recv_infected);
286         gtk_box_pack_start (GTK_BOX (hbox1), recv_infected, FALSE, FALSE, 0);
287         gtk_tooltips_set_tip(tooltips, recv_infected,
288                              _("Save mail that contains viruses"),
289                              NULL);
290         SET_TOGGLE_SENSITIVITY (enable_clamav, recv_infected);
291
292         save_folder = gtk_entry_new ();
293         gtk_widget_show (save_folder);
294         gtk_box_pack_start (GTK_BOX (hbox1), save_folder, TRUE, TRUE, 0);
295         gtk_tooltips_set_tip(tooltips, save_folder,
296                              _("Folder for storing infected mail. Leave empty to use the default trash folder"),
297                              NULL);
298         SET_TOGGLE_SENSITIVITY (enable_clamav, save_folder);
299
300         save_folder_select = gtkut_get_browse_directory_btn(_("_Browse"));
301         gtk_widget_show (save_folder_select);
302         gtk_box_pack_start (GTK_BOX (hbox1), save_folder_select, FALSE, FALSE, 0);
303         gtk_tooltips_set_tip(tooltips, save_folder_select,
304                              _("Click this button to select a folder for storing infected mail"),
305                              NULL);
306         SET_TOGGLE_SENSITIVITY (enable_clamav, save_folder_select);
307
308         hbox1 = gtk_hbox_new (FALSE, 8);
309         gtk_widget_show (hbox1);
310         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
311
312         setting_type = gtk_check_button_new_with_label(_("Automatic configuration"));
313         /*gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(setting_type), TRUE);*/
314         gtk_widget_show (setting_type);
315         gtk_box_pack_start (GTK_BOX (hbox1), setting_type, FALSE, FALSE, 0);
316         gtk_tooltips_set_tip(tooltips, setting_type,
317                              _("Should configuration be done automatic or manual"),
318                              NULL);
319         SET_TOGGLE_SENSITIVITY (enable_clamav, setting_type);
320         
321         hbox_auto1 = gtk_hbox_new (FALSE, 8);
322         gtk_widget_show (hbox_auto1);
323         gtk_box_pack_start (GTK_BOX (vbox2), hbox_auto1, FALSE, FALSE, 0);
324
325         clamd_conf_label = gtk_label_new(_("Where is clamd.conf"));
326         gtk_widget_show (clamd_conf_label);
327         gtk_box_pack_start (GTK_BOX (hbox_auto1), clamd_conf_label, FALSE, FALSE, 0);
328
329         config_folder = gtk_entry_new ();
330         gtk_widget_show (config_folder);
331         gtk_box_pack_start (GTK_BOX (hbox_auto1), config_folder, TRUE, TRUE, 0);
332         gtk_tooltips_set_tip(tooltips, config_folder,
333                              _("Full path to clamd.conf. If this field is not empty then the plugin has been able to locate the file automatically"),
334                              NULL);
335         SET_TOGGLE_SENSITIVITY (enable_clamav, config_folder);
336
337         config_folder_select = gtkut_get_browse_directory_btn(_("Br_owse"));
338         gtk_widget_show (config_folder_select);
339         gtk_box_pack_start (GTK_BOX (hbox_auto1), config_folder_select, FALSE, FALSE, 0);
340         gtk_tooltips_set_tip(tooltips, config_folder_select,
341                              _("Click this button to select full path to clamd.conf"),
342                              NULL);
343         SET_TOGGLE_SENSITIVITY (enable_clamav, config_folder_select);
344
345         hbox_auto2 = gtk_hbox_new (FALSE, 8);
346         gtk_widget_show (hbox_auto2);
347         gtk_box_pack_start (GTK_BOX (vbox2), hbox_auto2, FALSE, FALSE, 0);
348
349         permission_label = gtk_label_new(_("Check permission for folders and adjust if necessary"));
350         gtk_widget_show (permission_label);
351         gtk_box_pack_start (GTK_BOX (hbox_auto2), permission_label, FALSE, FALSE, 0);
352
353         blank = gtk_label_new("");
354         gtk_widget_show (blank);
355         gtk_box_pack_start (GTK_BOX (hbox_auto2), blank, TRUE, TRUE, 0);
356
357         permission_select = gtk_button_new_from_stock(GTK_STOCK_FIND_AND_REPLACE);
358                         /*gtk_button_new_with_mnemonic(_("_Check Permission"));*/
359         gtk_widget_show (permission_select);
360         gtk_box_pack_start (GTK_BOX (hbox_auto2), permission_select, FALSE, FALSE, 0);
361         gtk_tooltips_set_tip(tooltips, permission_select,
362                              _("Click this button to check and adjust folder permissions"),
363                              NULL);
364         SET_TOGGLE_SENSITIVITY (enable_clamav, permission_select);
365
366         hbox_manual1 = gtk_hbox_new (FALSE, 8);
367         gtk_widget_show (hbox_manual1);
368         gtk_box_pack_start (GTK_BOX (vbox2), hbox_manual1, FALSE, FALSE, 0);
369
370         host_label = gtk_label_new(_("Remote Host"));
371         gtk_widget_show (host_label);
372         gtk_box_pack_start (GTK_BOX (hbox_manual1), host_label, FALSE, FALSE, 0);
373
374         config_host = gtk_entry_new ();
375         gtk_widget_show (config_host);
376         gtk_box_pack_start (GTK_BOX (hbox_manual1), config_host, FALSE, FALSE, 0);
377         gtk_tooltips_set_tip(tooltips, config_host,
378                              _("Hostname or IP for remote host running clamav daemon"),
379                              NULL);
380         SET_TOGGLE_SENSITIVITY (enable_clamav, config_host);
381
382         blank = gtk_label_new("");
383         gtk_widget_show (blank);
384         gtk_box_pack_start (GTK_BOX (hbox_manual1), blank, TRUE, TRUE, 0);
385
386         hbox_manual2 = gtk_hbox_new (FALSE, 8);
387         gtk_widget_show (hbox_manual2);
388         gtk_box_pack_start (GTK_BOX (vbox2), hbox_manual2, FALSE, FALSE, 0);
389
390         port_label = gtk_label_new(_("Port"));
391         gtk_widget_show (port_label);
392         gtk_box_pack_start (GTK_BOX (hbox_manual2), port_label, FALSE, FALSE, 0);
393
394         config_port = gtk_spin_button_new_with_range(0, 65535, 1);
395         gtk_widget_show (config_port);
396         gtk_box_pack_start (GTK_BOX (hbox_manual2), config_port, FALSE, FALSE, 0);
397         gtk_tooltips_set_tip(tooltips, config_port,
398                              _("Port number where clamav daemon is listening"),
399                              NULL);
400
401         blank = gtk_label_new("");
402         gtk_widget_show (blank);
403         gtk_box_pack_start (GTK_BOX (hbox_manual2), blank, TRUE, TRUE, 0);
404
405         SET_TOGGLE_SENSITIVITY (enable_clamav, config_port);
406
407         config = clamav_get_config();
408
409         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_clamav), config->clamav_enable);
410 /*      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_arc), config->clamav_enable_arc);*/
411         gtk_spin_button_set_value(GTK_SPIN_BUTTON(max_size), (float) config->clamav_max_size);
412         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(recv_infected), config->clamav_recv_infected);
413         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(setting_type), config->clamd_config_type);
414
415         g_signal_connect(G_OBJECT(save_folder_select), "clicked",
416                          G_CALLBACK(foldersel_cb), page);
417         g_signal_connect(G_OBJECT(config_folder_select), "clicked",
418                          G_CALLBACK(clamd_folder_cb), page);
419         g_signal_connect(G_OBJECT(permission_select), "clicked",
420                          G_CALLBACK(folder_permission_cb), page);
421         g_signal_connect(G_OBJECT(setting_type), "clicked",
422                          G_CALLBACK(setting_type_cb), page);
423
424         clamd_config = clamd_get_config();
425                 
426         if (config->clamav_save_folder != NULL)
427                 gtk_entry_set_text(GTK_ENTRY(save_folder), config->clamav_save_folder);
428         if (!config->clamd_config_type) {
429         /*if (config->clamd_host && strlen(config->clamd_host) > 0 && config->clamd_port > 0) {*/
430                 gtk_entry_set_text(GTK_ENTRY(config_host), config->clamd_host);
431                 gtk_spin_button_set_value(GTK_SPIN_BUTTON(config_port), (gdouble) config->clamd_port);
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 = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(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 }