Improve some sieve-related translations
[claws.git] / src / plugins / fancy / fancy_prefs.c
blob5bc07fe0a51957986fc8d205aca937c09e91a34a
1 /*
2 * == Fancy Plugin ==
3 * Claws Mail -- A GTK based, lightweight, and fast e-mail client
4 * Copyright (C) 1999-2019 Salvatore De Paolis 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; see <http://www.gnu.org/licenses/>.
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #include "claws-features.h"
23 #endif
25 #include <glib.h>
26 #include <glib/gi18n.h>
28 #include "common/version.h"
29 #include "defs.h"
30 #include "claws.h"
31 #include "plugin.h"
32 #include "gtkutils.h"
33 #include "file-utils.h"
34 #include "utils.h"
35 #include "prefs.h"
36 #include "prefs_common.h"
37 #include "prefs_gtk.h"
38 #include "prefswindow.h"
39 #include "combobox.h"
40 #include "addressbook.h"
41 #include "filesel.h"
43 #include "fancy_prefs.h"
45 #define PREFS_BLOCK_NAME "fancy"
47 FancyPrefs fancy_prefs;
49 static void prefs_set_proxy_entry_sens(GtkWidget *button, GtkEntry *entry_str);
51 #ifdef HAVE_LIBSOUP_GNOME
52 static void prefs_disable_fancy_proxy(GtkWidget *checkbox, GtkWidget *block);
53 #endif
54 typedef struct _FancyPrefsPage FancyPrefsPage;
56 struct _FancyPrefsPage {
57 PrefsPage page;
58 GtkWidget *enable_images;
59 GtkWidget *enable_remote_content;
60 GtkWidget *enable_scripts;
61 GtkWidget *enable_plugins;
62 GtkWidget *enable_java;
63 GtkWidget *open_external;
64 #ifdef HAVE_LIBSOUP_GNOME
65 GtkWidget *gnome_proxy_checkbox;
66 #endif
67 GtkWidget *proxy_checkbox;
68 GtkWidget *proxy_str;
69 GtkWidget *stylesheet;
72 static PrefParam param[] = {
73 {"enable_images", "TRUE", &fancy_prefs.enable_images, P_BOOL,
74 NULL, NULL, NULL},
75 {"enable_remote_content", "FALSE", &fancy_prefs.enable_remote_content, P_BOOL,
76 NULL, NULL, NULL},
77 {"enable_scripts", "FALSE", &fancy_prefs.enable_scripts, P_BOOL,
78 NULL, NULL, NULL},
79 {"enable_plugins", "FALSE", &fancy_prefs.enable_plugins, P_BOOL,
80 NULL, NULL, NULL},
81 {"open_external", "TRUE", &fancy_prefs.open_external, P_BOOL,
82 NULL, NULL, NULL},
83 {"zoom_level", "100", &fancy_prefs.zoom_level, P_INT,
84 NULL, NULL, NULL},
85 {"enable_java", "FALSE", &fancy_prefs.enable_java, P_BOOL,
86 NULL, NULL, NULL},
87 #ifdef HAVE_LIBSOUP_GNOME
88 {"enable_gnome_proxy","FALSE", &fancy_prefs.enable_gnome_proxy, P_BOOL,
89 NULL, NULL, NULL},
90 #endif
91 {"enable_proxy", "FALSE", &fancy_prefs.enable_proxy, P_BOOL,
92 NULL, NULL, NULL},
93 {"proxy_server", "http://SERVERNAME:PORT", &fancy_prefs.proxy_str, P_STRING,
94 NULL, NULL, NULL},
95 {"stylesheet", "", &fancy_prefs.stylesheet, P_STRING, NULL, NULL, NULL},
96 {0,0,0,0,0,0,0}
99 static FancyPrefsPage fancy_prefs_page;
101 static void fancy_prefs_stylesheet_browse_cb (GtkWidget *widget, gpointer data);
102 static void fancy_prefs_stylesheet_edit_cb (GtkWidget *widget, gpointer data);
103 static void fancy_prefs_stylesheet_changed_cb (GtkWidget *widget, gpointer data);
105 static void create_fancy_prefs_page (PrefsPage *page, GtkWindow *window, gpointer data);
106 static void destroy_fancy_prefs_page (PrefsPage *page);
107 static void save_fancy_prefs_page (PrefsPage *page);
108 static void save_fancy_prefs (PrefsPage *page);
110 void fancy_prefs_init(void)
112 static gchar *path[3];
113 gchar *rcpath;
115 path[0] = _("Plugins");
116 path[1] = "Fancy";
117 path[2] = NULL;
119 prefs_set_default(param);
120 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
121 prefs_read_config(param, PREFS_BLOCK_NAME, rcpath, NULL);
122 g_free(rcpath);
124 fancy_prefs_page.page.path = path;
125 fancy_prefs_page.page.create_widget = create_fancy_prefs_page;
126 fancy_prefs_page.page.destroy_widget = destroy_fancy_prefs_page;
127 fancy_prefs_page.page.save_page = save_fancy_prefs_page;
128 fancy_prefs_page.page.weight = 30.0;
129 prefs_gtk_register_page((PrefsPage *) &fancy_prefs_page);
132 void fancy_prefs_done(void)
134 save_fancy_prefs((PrefsPage *) &fancy_prefs_page);
135 prefs_gtk_unregister_page((PrefsPage *) &fancy_prefs_page);
138 static void remote_content_set_labels_cb(GtkWidget *button, FancyPrefsPage *prefs_page)
140 GtkTreeModel *model;
141 GtkTreeIter iter;
142 gboolean remote_enabled = gtk_toggle_button_get_active(
143 GTK_TOGGLE_BUTTON(prefs_page->enable_remote_content));
145 /* Enable images */
146 gtk_button_set_label(GTK_BUTTON(prefs_page->enable_images),
147 remote_enabled ? _("Display images")
148 : _("Display embedded images"));
150 /* Enable Javascript */
151 gtk_button_set_label(GTK_BUTTON(prefs_page->enable_scripts),
152 remote_enabled ? _("Execute javascript")
153 : _("Execute embedded javascript"));
155 /* Enable java */
156 gtk_button_set_label(GTK_BUTTON(prefs_page->enable_java),
157 remote_enabled ? _("Execute Java applets")
158 : _("Execute embedded Java applets"));
160 /* Enable plugins */
161 gtk_button_set_label(GTK_BUTTON(prefs_page->enable_plugins),
162 remote_enabled ? _("Render objects using plugins")
163 : _("Render embedded objects using plugins"));
165 /* Open links */
166 model = gtk_combo_box_get_model(GTK_COMBO_BOX(prefs_page->open_external));
167 if (gtk_tree_model_get_iter_first (model, &iter)) {
168 if (remote_enabled)
169 gtk_list_store_set(GTK_LIST_STORE(model), &iter, COMBOBOX_TEXT,
170 _("Open in Viewer (remote content is enabled)"), -1);
171 else
172 gtk_list_store_set(GTK_LIST_STORE(model), &iter, COMBOBOX_TEXT,
173 _("Do nothing (remote content is disabled)"), -1);
177 static void create_fancy_prefs_page(PrefsPage *page, GtkWindow *window,
178 gpointer data)
180 FancyPrefsPage *prefs_page = (FancyPrefsPage *) page;
182 GtkWidget *vbox;
183 #ifdef HAVE_LIBSOUP_GNOME
184 GtkWidget *gnome_proxy_checkbox;
185 #endif
186 GtkWidget *proxy_checkbox;
187 GtkWidget *proxy_str;
188 GtkWidget *vbox_proxy;
189 GtkWidget *frame_proxy;
191 GtkWidget *frame_remote;
192 GtkWidget *vbox_remote;
193 GtkWidget *remote_label;
194 GtkWidget *enable_remote_content;
195 GtkWidget *enable_images;
196 GtkWidget *enable_scripts;
197 GtkWidget *enable_plugins;
198 GtkWidget *enable_java;
199 GtkWidget *stylesheet_label;
200 GtkWidget *stylesheet;
201 GtkWidget *stylesheet_browse_button;
202 GtkWidget *stylesheet_edit_button;
204 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 3);
205 gtk_container_set_border_width(GTK_CONTAINER(vbox), VBOX_BORDER);
206 gtk_widget_show(vbox);
208 GtkWidget *block = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
210 vbox_proxy = gtkut_get_options_frame(vbox, &frame_proxy, _("Proxy"));
211 #ifdef HAVE_LIBSOUP_GNOME
212 gnome_proxy_checkbox = gtk_check_button_new_with_label(_("Use GNOME's proxy settings"));
213 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gnome_proxy_checkbox),
214 fancy_prefs.enable_gnome_proxy);
215 gtk_box_pack_start(GTK_BOX(vbox_proxy), gnome_proxy_checkbox, FALSE, FALSE, 0);
216 gtk_widget_show(gnome_proxy_checkbox);
217 g_signal_connect(G_OBJECT(gnome_proxy_checkbox), "toggled",
218 G_CALLBACK(prefs_disable_fancy_proxy), block);
219 #endif
220 proxy_checkbox = gtk_check_button_new_with_label(_("Use proxy"));
221 proxy_str = gtk_entry_new();
222 #ifdef HAVE_LIBSOUP_GNOME
223 if (fancy_prefs.enable_gnome_proxy)
224 gtk_widget_set_sensitive(proxy_checkbox, FALSE);
225 #endif
226 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(proxy_checkbox),
227 fancy_prefs.enable_proxy);
228 prefs_set_proxy_entry_sens(proxy_checkbox, GTK_ENTRY(proxy_str));
229 g_signal_connect(G_OBJECT(proxy_checkbox), "toggled",
230 G_CALLBACK(prefs_set_proxy_entry_sens), proxy_str);
231 pref_set_entry_from_pref(GTK_ENTRY(proxy_str), fancy_prefs.proxy_str);
233 gtk_box_pack_start(GTK_BOX(block), proxy_checkbox, FALSE, FALSE, 0);
234 gtk_box_pack_start(GTK_BOX(block), proxy_str, TRUE, TRUE, 0);
235 gtk_box_pack_start(GTK_BOX(vbox_proxy), block, FALSE, FALSE, 0);
236 gtk_widget_show_all(vbox_proxy);
238 vbox_remote = gtkut_get_options_frame(vbox, &frame_remote, _("Remote resources"));
239 remote_label = gtk_label_new(_("Loading remote resources can lead to some privacy issues.\n"
240 "When remote content loading is disabled, nothing will be requested\n"
241 "from the network. Rendering of images, scripts, plugin objects or\n"
242 "Java applets can still be enabled for content that is attached\n"
243 "in the email."));
244 gtk_label_set_xalign(GTK_LABEL(remote_label), 0.0);
245 gtk_label_set_yalign(GTK_LABEL(remote_label), 0.0);
246 enable_remote_content = gtk_check_button_new_with_label(_("Enable loading of remote content"));
247 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_remote_content),
248 fancy_prefs.enable_remote_content);
249 gtk_box_pack_start (GTK_BOX (vbox_remote), remote_label, FALSE, FALSE, 0);
250 gtk_box_pack_start (GTK_BOX (vbox_remote), enable_remote_content, FALSE, FALSE, 0);
251 gtk_widget_show_all(vbox_remote);
253 enable_images = gtk_check_button_new_with_label(("IMAGES"));
254 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_images),
255 fancy_prefs.enable_images);
256 gtk_box_pack_start(GTK_BOX(vbox), enable_images, FALSE, FALSE, 0);
257 gtk_widget_show(enable_images);
259 enable_scripts = gtk_check_button_new_with_label("SCRIPTS");
260 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_scripts),
261 fancy_prefs.enable_scripts);
262 gtk_box_pack_start(GTK_BOX(vbox), enable_scripts, FALSE, FALSE, 0);
263 gtk_widget_show(enable_scripts);
265 enable_java = gtk_check_button_new_with_label("JAVA");
266 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_java),
267 fancy_prefs.enable_java);
268 gtk_box_pack_start(GTK_BOX(vbox), enable_java, FALSE, FALSE, 0);
269 gtk_widget_show(enable_java);
271 enable_plugins = gtk_check_button_new_with_label("PLUGINS");
272 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_plugins),
273 fancy_prefs.enable_plugins);
274 gtk_box_pack_start(GTK_BOX(vbox), enable_plugins, FALSE, FALSE, 0);
275 gtk_widget_show(enable_plugins);
277 GtkWidget *hbox_ext = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
278 GtkWidget *open_external_label = gtk_label_new(_("When clicking on a link, by default"));
279 GtkWidget *optmenu_open_external = gtkut_sc_combobox_create(NULL, FALSE);
280 GtkListStore *menu = GTK_LIST_STORE(gtk_combo_box_get_model(
281 GTK_COMBO_BOX(optmenu_open_external)));
282 gtk_widget_show (optmenu_open_external);
283 GtkTreeIter iter;
285 COMBOBOX_ADD (menu, "DEFAULT_ACTION", FALSE);
286 COMBOBOX_ADD (menu, _("Open in External Browser"), TRUE);
288 gtk_box_pack_start(GTK_BOX(hbox_ext), open_external_label, FALSE, FALSE, 0);
289 gtk_box_pack_start(GTK_BOX(hbox_ext), optmenu_open_external, FALSE, FALSE, 0);
290 gtk_widget_show_all(hbox_ext);
291 gtk_box_pack_start(GTK_BOX(vbox), hbox_ext, FALSE, FALSE, 0);
293 combobox_select_by_data(GTK_COMBO_BOX(optmenu_open_external),
294 fancy_prefs.open_external);
296 GtkWidget *hbox_css = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
297 gtk_widget_show(hbox_css);
298 gtk_box_pack_start(GTK_BOX(vbox), hbox_css, FALSE, FALSE, 0);
300 CLAWS_SET_TIP(hbox_css, _("The CSS in this file will be applied to all HTML parts"));
302 stylesheet_label = gtk_label_new(_("Stylesheet"));
303 gtk_widget_show(stylesheet_label);
304 gtk_box_pack_start(GTK_BOX(hbox_css), stylesheet_label, FALSE, FALSE, 0);
306 stylesheet = gtk_entry_new();
307 gtk_widget_show(stylesheet);
308 gtk_box_pack_start(GTK_BOX(hbox_css), stylesheet, TRUE, TRUE, 0);
310 stylesheet_browse_button = gtkut_get_browse_file_btn(_("Bro_wse"));
311 gtk_widget_show(stylesheet_browse_button);
312 gtk_box_pack_start(GTK_BOX(hbox_css), stylesheet_browse_button, FALSE, FALSE, 0);
313 g_signal_connect(G_OBJECT(stylesheet_browse_button), "clicked",
314 G_CALLBACK(fancy_prefs_stylesheet_browse_cb), stylesheet);
316 stylesheet_edit_button = gtk_button_new_with_mnemonic("_Edit");
317 gtk_widget_show (stylesheet_edit_button);
318 gtk_box_pack_start(GTK_BOX(hbox_css), stylesheet_edit_button, FALSE, FALSE, 0);
319 g_signal_connect(G_OBJECT(stylesheet_edit_button), "clicked",
320 G_CALLBACK(fancy_prefs_stylesheet_edit_cb), stylesheet);
321 g_signal_connect(G_OBJECT(stylesheet), "changed",
322 G_CALLBACK(fancy_prefs_stylesheet_changed_cb), stylesheet_edit_button);
323 pref_set_entry_from_pref(GTK_ENTRY(stylesheet), fancy_prefs.stylesheet);
324 g_signal_emit_by_name(G_OBJECT(stylesheet), "changed", stylesheet_edit_button);
327 #ifdef HAVE_LIBSOUP_GNOME
328 prefs_page->gnome_proxy_checkbox = gnome_proxy_checkbox;
329 #endif
330 prefs_page->proxy_checkbox = proxy_checkbox;
331 prefs_page->proxy_str = proxy_str;
332 prefs_page->enable_remote_content = enable_remote_content;
333 prefs_page->enable_images = enable_images;
334 prefs_page->enable_scripts = enable_scripts;
335 prefs_page->enable_plugins = enable_plugins;
336 prefs_page->enable_java = enable_java;
337 prefs_page->open_external = optmenu_open_external;
338 prefs_page->stylesheet = stylesheet;
339 prefs_page->page.widget = vbox;
341 g_signal_connect(G_OBJECT(prefs_page->enable_remote_content), "toggled",
342 G_CALLBACK(remote_content_set_labels_cb), prefs_page);
343 remote_content_set_labels_cb(NULL, prefs_page);
346 static void fancy_prefs_stylesheet_browse_cb(GtkWidget *widget, gpointer data)
348 gchar *filename;
349 gchar *utf8_filename;
350 GtkEntry *dest = GTK_ENTRY(data);
352 filename = filesel_select_file_open(_("Select stylesheet"), NULL);
353 if (!filename) return;
355 utf8_filename = g_filename_to_utf8(filename, -1, NULL, NULL, NULL);
356 if (!utf8_filename) {
357 g_warning("fancy_prefs_stylesheet_browse_cb(): failed to convert character set");
358 utf8_filename = g_strdup(filename);
360 gtk_entry_set_text(GTK_ENTRY(dest), utf8_filename);
361 g_free(utf8_filename);
364 static void fancy_prefs_stylesheet_edit_cb(GtkWidget *widget, gpointer data)
366 const gchar *stylesheet = gtk_entry_get_text(GTK_ENTRY(data));
367 if (!is_file_exist(stylesheet))
368 str_write_to_file(stylesheet, "", TRUE);
369 open_txt_editor(stylesheet, prefs_common_get_ext_editor_cmd());
372 static void fancy_prefs_stylesheet_changed_cb(GtkWidget *widget, gpointer data)
374 const gchar *stylesheet = gtk_entry_get_text(GTK_ENTRY(widget));
375 gtk_widget_set_sensitive(GTK_WIDGET(data), (*stylesheet)? TRUE: FALSE);
378 static void prefs_set_proxy_entry_sens(GtkWidget *button, GtkEntry *entry_str) {
379 gtk_widget_set_sensitive(GTK_WIDGET(entry_str),
380 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)));
383 #ifdef HAVE_LIBSOUP_GNOME
384 static void prefs_disable_fancy_proxy(GtkWidget *checkbox, GtkWidget *block) {
385 gboolean toggle = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbox));
386 gtk_widget_set_sensitive(block, !toggle);
387 GList *list = g_list_first(gtk_container_get_children(GTK_CONTAINER(block)));
388 if (toggle) {
389 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(list->data), FALSE);
391 else {
392 gtk_widget_set_sensitive(GTK_WIDGET(list->data), TRUE);
395 #endif
396 static void destroy_fancy_prefs_page(PrefsPage *page)
398 /* Do nothing! */
400 static void save_fancy_prefs(PrefsPage *page)
402 PrefFile *pref_file;
403 gchar *rc_file_path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
404 COMMON_RC, NULL);
405 pref_file = prefs_write_open(rc_file_path);
406 g_free(rc_file_path);
407 if (!(pref_file) ||
408 (prefs_set_block_label(pref_file, PREFS_BLOCK_NAME) < 0))
409 return;
411 if (prefs_write_param(param, pref_file->fp) < 0) {
412 g_warning("failed to write Fancy plugin configuration");
413 prefs_file_close_revert(pref_file);
414 return;
417 if (fprintf(pref_file->fp, "\n") < 0) {
418 FILE_OP_ERROR(rc_file_path, "fprintf");
419 prefs_file_close_revert(pref_file);
420 } else
421 prefs_file_close(pref_file);
424 static void save_fancy_prefs_page(PrefsPage *page)
426 FancyPrefsPage *prefs_page = (FancyPrefsPage *) page;
428 #ifdef HAVE_LIBSOUP_GNOME
429 fancy_prefs.enable_gnome_proxy = gtk_toggle_button_get_active
430 (GTK_TOGGLE_BUTTON(prefs_page->gnome_proxy_checkbox));
431 #endif
432 fancy_prefs.enable_images = gtk_toggle_button_get_active
433 (GTK_TOGGLE_BUTTON(prefs_page->enable_images));
434 fancy_prefs.enable_remote_content = gtk_toggle_button_get_active
435 (GTK_TOGGLE_BUTTON(prefs_page->enable_remote_content));
436 fancy_prefs.enable_scripts = gtk_toggle_button_get_active
437 (GTK_TOGGLE_BUTTON(prefs_page->enable_scripts));
438 fancy_prefs.enable_plugins = gtk_toggle_button_get_active
439 (GTK_TOGGLE_BUTTON(prefs_page->enable_plugins));
440 fancy_prefs.enable_java = gtk_toggle_button_get_active
441 (GTK_TOGGLE_BUTTON(prefs_page->enable_java));
442 fancy_prefs.open_external = combobox_get_active_data
443 (GTK_COMBO_BOX(prefs_page->open_external));
444 fancy_prefs.enable_proxy = gtk_toggle_button_get_active
445 (GTK_TOGGLE_BUTTON(prefs_page->proxy_checkbox));
446 fancy_prefs.proxy_str = pref_get_pref_from_entry(GTK_ENTRY(prefs_page->proxy_str));
447 #ifdef G_OS_WIN32
448 /* pref_get_pref_from_entry() escapes the backslashes in strings,
449 * we do not want that, since this entry contains a Windows path.
450 * Let's just strdup it. */
451 fancy_prefs.stylesheet = g_strdup(gtk_entry_get_text(
452 GTK_ENTRY(prefs_page->stylesheet)));
453 #else
454 fancy_prefs.stylesheet = pref_get_pref_from_entry(GTK_ENTRY(prefs_page->stylesheet));
455 #endif
457 save_fancy_prefs(page);