Improve some sieve-related translations
[claws.git] / src / plugins / spam_report / spam_report_prefs.c
blobe87430bd7b4b45435aab35f877c05137105b26e1
1 /*
2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2007 Colin Leroy <colin@colino.net>
4 * and the Claws Mail Team
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.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #include "claws-features.h"
24 #endif
26 #include "defs.h"
28 #include <glib.h>
29 #include <glib/gi18n.h>
30 #include <gtk/gtk.h>
32 #include "gtkutils.h"
33 #include "password.h"
34 #include "prefs.h"
35 #include "prefs_gtk.h"
36 #include "prefswindow.h"
37 #include "alertpanel.h"
38 #include "utils.h"
40 #include "spam_report_prefs.h"
42 #define PREFS_BLOCK_NAME "SpamReport"
44 SpamReportPrefs spamreport_prefs;
45 void spamreport_clear_cache(void);
47 typedef struct _SpamReportPage SpamReportPage;
49 struct _SpamReportPage {
50 PrefsPage page;
51 GtkWidget *frame[INTF_LAST];
52 GtkWidget *enabled_chkbtn[INTF_LAST];
53 GtkWidget *user_entry[INTF_LAST];
54 GtkWidget *pass_entry[INTF_LAST];
57 static PrefParam param[] = {
58 {"signalspam_enabled", "FALSE", &spamreport_prefs.enabled[INTF_SIGNALSPAM], P_BOOL, NULL, NULL, NULL},
59 {"signalspam_user", "", &spamreport_prefs.user[INTF_SIGNALSPAM], P_STRING, NULL, NULL, NULL},
60 {"signalspam_pass", "", &spamreport_prefs.pass[INTF_SIGNALSPAM], P_PASSWORD, NULL, NULL, NULL},
61 {"spamcop_enabled", "FALSE", &spamreport_prefs.enabled[INTF_SPAMCOP], P_BOOL, NULL, NULL, NULL},
62 {"spamcop_user", "", &spamreport_prefs.user[INTF_SPAMCOP], P_STRING, NULL, NULL, NULL},
63 {"debianspam_enabled", "FALSE", &spamreport_prefs.enabled[INTF_DEBIANSPAM], P_BOOL, NULL, NULL, NULL},
64 {0,0,0,0,0,0,0}
67 static SpamReportPage spamreport_prefs_page;
69 static void create_spamreport_prefs_page (PrefsPage *page,
70 GtkWindow *window,
71 gpointer data);
72 static void destroy_spamreport_prefs_page (PrefsPage *page);
73 static void save_spamreport_prefs (PrefsPage *page);
75 void spamreport_prefs_init(void)
77 static gchar *path[3];
78 gchar *rcpath;
79 guint i;
80 gboolean passwords_migrated = FALSE;
82 path[0] = _("Plugins");
83 path[1] = _("SpamReport");
84 path[2] = NULL;
86 prefs_set_default(param);
87 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
88 prefs_read_config(param, PREFS_BLOCK_NAME, rcpath, NULL);
89 g_free(rcpath);
91 /* Move passwords that are still in main config to password store. */
92 for (i = 0; i < INTF_LAST; i++) {
93 if (spamreport_prefs.pass[i] != NULL) {
94 passwd_store_set(PWS_PLUGIN, "SpamReport",
95 spam_interfaces[i].name, spamreport_prefs.pass[i], TRUE);
96 passwords_migrated = TRUE;
99 if (passwords_migrated)
100 passwd_store_write_config();
102 spamreport_prefs_page.page.path = path;
103 spamreport_prefs_page.page.create_widget = create_spamreport_prefs_page;
104 spamreport_prefs_page.page.destroy_widget = destroy_spamreport_prefs_page;
105 spamreport_prefs_page.page.save_page = save_spamreport_prefs;
106 spamreport_prefs_page.page.weight = 30.0;
108 prefs_gtk_register_page((PrefsPage *) &spamreport_prefs_page);
111 void spamreport_prefs_done(void)
113 prefs_gtk_unregister_page((PrefsPage *) &spamreport_prefs_page);
116 static void create_spamreport_prefs_page(PrefsPage *page,
117 GtkWindow *window,
118 gpointer data)
120 SpamReportPage *prefs_page = (SpamReportPage *) page;
122 GtkWidget *vbox, *table;
123 GtkWidget *tmp;
124 int i = 0;
126 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING_NARROW);
127 gtk_container_set_border_width(GTK_CONTAINER(vbox), VBOX_BORDER);
128 gtk_widget_show(vbox);
130 for (i = 0; i < INTF_LAST; i++) {
131 gchar *pass;
132 prefs_page->frame[i] = gtk_frame_new(spam_interfaces[i].name);
133 gtk_box_pack_start(GTK_BOX(vbox), prefs_page->frame[i], FALSE, FALSE, 6);
135 prefs_page->user_entry[i] = gtk_entry_new();
136 prefs_page->pass_entry[i] = gtk_entry_new();
137 prefs_page->enabled_chkbtn[i] = gtk_check_button_new_with_label(_("Enabled"));
139 gtk_entry_set_visibility(GTK_ENTRY(prefs_page->pass_entry[i]), FALSE);
141 gtk_entry_set_text(GTK_ENTRY(prefs_page->user_entry[i]),
142 spamreport_prefs.user[i] ? spamreport_prefs.user[i]:"");
144 pass = spamreport_passwd_get(spam_interfaces[i].name);
145 gtk_entry_set_text(GTK_ENTRY(prefs_page->pass_entry[i]), pass ? pass:"");
146 if (pass != NULL) {
147 memset(pass, 0, strlen(pass));
149 g_free(pass);
150 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_page->enabled_chkbtn[i]),
151 spamreport_prefs.enabled[i]);
153 table = gtk_grid_new();
154 gtk_container_set_border_width(GTK_CONTAINER(table), 8);
155 gtk_grid_set_row_spacing(GTK_GRID(table), 4);
156 gtk_grid_set_column_spacing(GTK_GRID(table), 8);
158 gtk_container_add(GTK_CONTAINER(prefs_page->frame[i]), table);
159 gtk_widget_show(prefs_page->frame[i]);
160 gtk_widget_show(table);
162 gtk_grid_attach(GTK_GRID(table), prefs_page->enabled_chkbtn[i], 0, 0, 1, 1);
163 gtk_widget_show(prefs_page->enabled_chkbtn[i]);
165 switch(spam_interfaces[i].type) {
166 case INTF_MAIL:
167 tmp = gtk_label_new(_("Forward to:"));
168 break;
169 default:
170 tmp = gtk_label_new(_("Username:"));
172 gtk_grid_attach(GTK_GRID(table), tmp, 0, 1, 1, 1);
173 gtk_grid_attach(GTK_GRID(table), prefs_page->user_entry[i], 1, 1, 1, 1);
174 gtk_widget_set_hexpand(prefs_page->user_entry[i], TRUE);
175 gtk_widget_set_halign(prefs_page->user_entry[i], GTK_ALIGN_FILL);
176 if (spam_interfaces[i].type != INTF_HTTP_GET) {
177 gtk_widget_show(tmp);
178 gtk_widget_show(prefs_page->user_entry[i]);
181 tmp = gtk_label_new(_("Password:"));
182 gtk_grid_attach(GTK_GRID(table), tmp, 0, 2, 1, 1);
183 gtk_grid_attach(GTK_GRID(table), prefs_page->pass_entry[i], 1, 2, 1, 1);
184 gtk_widget_set_hexpand(prefs_page->pass_entry[i], TRUE);
185 gtk_widget_set_halign(prefs_page->pass_entry[i], GTK_ALIGN_FILL);
187 if (spam_interfaces[i].type != INTF_MAIL && spam_interfaces[i].type != INTF_HTTP_GET) {
188 gtk_widget_show(tmp);
189 gtk_widget_show(prefs_page->pass_entry[i]);
192 prefs_page->page.widget = vbox;
195 static void destroy_spamreport_prefs_page(PrefsPage *page)
197 /* Do nothing! */
200 static void save_spamreport_prefs(PrefsPage *page)
202 SpamReportPage *prefs_page = (SpamReportPage *) page;
203 PrefFile *pref_file;
204 gchar *rc_file_path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
205 COMMON_RC, NULL);
206 int i = 0;
208 for (i = 0; i < INTF_LAST; i++) {
209 gchar *pass;
211 g_free(spamreport_prefs.user[i]);
212 g_free(spamreport_prefs.pass[i]);
214 spamreport_prefs.enabled[i] = gtk_toggle_button_get_active(
215 GTK_TOGGLE_BUTTON(prefs_page->enabled_chkbtn[i]));
216 spamreport_prefs.user[i] = gtk_editable_get_chars(
217 GTK_EDITABLE(prefs_page->user_entry[i]), 0, -1);
219 pass = gtk_editable_get_chars(GTK_EDITABLE(prefs_page->pass_entry[i]), 0, -1);
220 spamreport_passwd_set(spam_interfaces[i].name, pass);
221 memset(pass, 0, strlen(pass));
222 g_free(pass);
225 pref_file = prefs_write_open(rc_file_path);
226 g_free(rc_file_path);
228 if (!(pref_file) ||
229 (prefs_set_block_label(pref_file, PREFS_BLOCK_NAME) < 0))
230 return;
232 if (prefs_write_param(param, pref_file->fp) < 0) {
233 g_warning("failed to write SpamReport plugin configuration");
234 prefs_file_close_revert(pref_file);
235 return;
237 if (fprintf(pref_file->fp, "\n") < 0) {
238 FILE_OP_ERROR(rc_file_path, "fprintf");
239 prefs_file_close_revert(pref_file);
240 } else
241 prefs_file_close(pref_file);
243 passwd_store_write_config();