2 * Claws Mail -- A GTK+ based, lightweight, and fast e-mail client
3 * Copyright(C) 1999-2013 the Claws Mail Team
5 * This file Copyright (C) 2009-2013 Salvatore De Paolis
6 * <iwkse@claws-mail.org> and the Claws Mail Team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write tothe Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include "claws-features.h"
26 #include <glib/gi18n.h>
37 #include "prefs_common.h"
38 #include "prefs_gtk.h"
39 #include "prefswindow.h"
41 #include "addressbook.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);
54 typedef struct _FancyPrefsPage FancyPrefsPage;
56 struct _FancyPrefsPage {
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;
67 GtkWidget *proxy_checkbox;
71 static PrefParam param[] = {
72 {"enable_images", "TRUE", &fancy_prefs.enable_images, P_BOOL,
74 {"enable_remote_content", "FALSE", &fancy_prefs.enable_remote_content, P_BOOL,
76 {"enable_scripts", "FALSE", &fancy_prefs.enable_scripts, P_BOOL,
78 {"enable_plugins", "FALSE", &fancy_prefs.enable_plugins, P_BOOL,
80 {"open_external", "TRUE", &fancy_prefs.open_external, P_BOOL,
82 {"zoom_level", "100", &fancy_prefs.zoom_level, P_INT,
84 {"enable_java", "FALSE", &fancy_prefs.enable_java, P_BOOL,
86 #ifdef HAVE_LIBSOUP_GNOME
87 {"enable_gnome_proxy","FALSE", &fancy_prefs.enable_gnome_proxy, P_BOOL,
90 {"enable_proxy", "FALSE", &fancy_prefs.enable_proxy, P_BOOL,
92 {"proxy_server", "http://SERVERNAME:PORT", &fancy_prefs.proxy_str, P_STRING,
97 static FancyPrefsPage fancy_prefs_page;
99 static void create_fancy_prefs_page (PrefsPage *page, GtkWindow *window, gpointer data);
100 static void destroy_fancy_prefs_page (PrefsPage *page);
101 static void save_fancy_prefs_page (PrefsPage *page);
102 static void save_fancy_prefs (PrefsPage *page);
104 void fancy_prefs_init(void)
106 static gchar *path[3];
109 path[0] = _("Plugins");
113 prefs_set_default(param);
114 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
115 prefs_read_config(param, PREFS_BLOCK_NAME, rcpath, NULL);
118 fancy_prefs_page.page.path = path;
119 fancy_prefs_page.page.create_widget = create_fancy_prefs_page;
120 fancy_prefs_page.page.destroy_widget = destroy_fancy_prefs_page;
121 fancy_prefs_page.page.save_page = save_fancy_prefs_page;
122 fancy_prefs_page.page.weight = 30.0;
123 prefs_gtk_register_page((PrefsPage *) &fancy_prefs_page);
126 void fancy_prefs_done(void)
128 save_fancy_prefs((PrefsPage *) &fancy_prefs_page);
129 prefs_gtk_unregister_page((PrefsPage *) &fancy_prefs_page);
132 static void remote_content_set_labels_cb(GtkWidget *button, FancyPrefsPage *prefs_page)
136 gboolean remote_enabled = gtk_toggle_button_get_active(
137 GTK_TOGGLE_BUTTON(prefs_page->enable_remote_content));
140 gtk_button_set_label(GTK_BUTTON(prefs_page->enable_images),
141 remote_enabled ? _("Display images")
142 : _("Display embedded images"));
144 /* Enable Javascript */
145 gtk_button_set_label(GTK_BUTTON(prefs_page->enable_scripts),
146 remote_enabled ? _("Execute javascript")
147 : _("Execute embedded javascript"));
150 gtk_button_set_label(GTK_BUTTON(prefs_page->enable_java),
151 remote_enabled ? _("Execute Java applets")
152 : _("Execute embedded Java applets"));
155 gtk_button_set_label(GTK_BUTTON(prefs_page->enable_plugins),
156 remote_enabled ? _("Render objects using plugins")
157 : _("Render embedded objects using plugins"));
160 model = gtk_combo_box_get_model(GTK_COMBO_BOX(prefs_page->open_external));
161 if (gtk_tree_model_get_iter_first (model, &iter)) {
163 gtk_list_store_set(GTK_LIST_STORE(model), &iter, COMBOBOX_TEXT,
164 _("Open in viewer (remote content is enabled)"), -1);
166 gtk_list_store_set(GTK_LIST_STORE(model), &iter, COMBOBOX_TEXT,
167 _("Do nothing (remote content is disabled)"), -1);
171 static void create_fancy_prefs_page(PrefsPage *page, GtkWindow *window,
174 FancyPrefsPage *prefs_page = (FancyPrefsPage *) page;
177 #ifdef HAVE_LIBSOUP_GNOME
178 GtkWidget *gnome_proxy_checkbox;
180 GtkWidget *proxy_checkbox;
181 GtkWidget *proxy_str;
182 GtkWidget *vbox_proxy;
183 GtkWidget *frame_proxy;
185 GtkWidget *frame_remote;
186 GtkWidget *vbox_remote;
187 GtkWidget *remote_label;
188 GtkWidget *enable_remote_content;
189 GtkWidget *enable_images;
190 GtkWidget *enable_scripts;
191 GtkWidget *enable_plugins;
192 GtkWidget *enable_java;
194 vbox = gtk_vbox_new(FALSE, 3);
195 gtk_container_set_border_width(GTK_CONTAINER(vbox), VBOX_BORDER);
196 gtk_widget_show(vbox);
198 GtkWidget *block = gtk_hbox_new(FALSE, FALSE);
200 vbox_proxy = gtkut_get_options_frame(vbox, &frame_proxy, _("Proxy"));
201 #ifdef HAVE_LIBSOUP_GNOME
202 gnome_proxy_checkbox = gtk_check_button_new_with_label(_("Use GNOME's proxy settings"));
203 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gnome_proxy_checkbox),
204 fancy_prefs.enable_gnome_proxy);
205 gtk_box_pack_start(GTK_BOX(vbox_proxy), gnome_proxy_checkbox, FALSE, FALSE, 0);
206 gtk_widget_show(gnome_proxy_checkbox);
207 g_signal_connect(G_OBJECT(gnome_proxy_checkbox), "toggled",
208 G_CALLBACK(prefs_disable_fancy_proxy), block);
210 proxy_checkbox = gtk_check_button_new_with_label(_("Use proxy:"));
211 proxy_str = gtk_entry_new();
212 #ifdef HAVE_LIBSOUP_GNOME
213 if (fancy_prefs.enable_gnome_proxy)
214 gtk_widget_set_sensitive(proxy_checkbox, FALSE);
216 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(proxy_checkbox),
217 fancy_prefs.enable_proxy);
218 prefs_set_proxy_entry_sens(proxy_checkbox, GTK_ENTRY(proxy_str));
219 g_signal_connect(G_OBJECT(proxy_checkbox), "toggled",
220 G_CALLBACK(prefs_set_proxy_entry_sens), proxy_str);
221 pref_set_entry_from_pref(GTK_ENTRY(proxy_str), fancy_prefs.proxy_str);
223 gtk_box_pack_start(GTK_BOX(block), proxy_checkbox, FALSE, FALSE, 0);
224 gtk_box_pack_start(GTK_BOX(block), proxy_str, FALSE, TRUE, 0);
225 gtk_box_pack_start(GTK_BOX(vbox_proxy), block, FALSE, FALSE, 0);
226 gtk_widget_show_all(vbox_proxy);
228 vbox_remote = gtkut_get_options_frame(vbox, &frame_remote, _("Remote resources"));
229 remote_label = gtk_label_new(_("Loading remote resources can lead to some privacy issues.\n"
230 "When remote content loading is disabled, nothing will be requested\n"
231 "from the network. Rendering of images, scripts, plugin objects or\n"
232 "Java applets can still be enabled for content that is attached\n"
234 gtk_misc_set_alignment(GTK_MISC(remote_label), 0, 0);
235 enable_remote_content = gtk_check_button_new_with_label(_("Enable loading of remote content"));
236 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_remote_content),
237 fancy_prefs.enable_remote_content);
238 gtk_box_pack_start (GTK_BOX (vbox_remote), remote_label, FALSE, FALSE, 0);
239 gtk_box_pack_start (GTK_BOX (vbox_remote), enable_remote_content, FALSE, FALSE, 0);
240 gtk_widget_show_all(vbox_remote);
242 enable_images = gtk_check_button_new_with_label(("IMAGES"));
243 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_images),
244 fancy_prefs.enable_images);
245 gtk_box_pack_start(GTK_BOX(vbox), enable_images, FALSE, FALSE, 0);
246 gtk_widget_show(enable_images);
248 enable_scripts = gtk_check_button_new_with_label("SCRIPTS");
249 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_scripts),
250 fancy_prefs.enable_scripts);
251 gtk_box_pack_start(GTK_BOX(vbox), enable_scripts, FALSE, FALSE, 0);
252 gtk_widget_show(enable_scripts);
254 enable_java = gtk_check_button_new_with_label("JAVA");
255 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_java),
256 fancy_prefs.enable_java);
257 gtk_box_pack_start(GTK_BOX(vbox), enable_java, FALSE, FALSE, 0);
258 gtk_widget_show(enable_java);
260 enable_plugins = gtk_check_button_new_with_label("PLUGINS");
261 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_plugins),
262 fancy_prefs.enable_plugins);
263 gtk_box_pack_start(GTK_BOX(vbox), enable_plugins, FALSE, FALSE, 0);
264 gtk_widget_show(enable_plugins);
266 GtkWidget *hbox_ext = gtk_hbox_new(FALSE, 8);
267 GtkWidget *open_external_label = gtk_label_new(_("When clicking on a link, by default:"));
268 GtkWidget *optmenu_open_external = gtkut_sc_combobox_create(NULL, FALSE);
269 GtkListStore *menu = GTK_LIST_STORE(gtk_combo_box_get_model(
270 GTK_COMBO_BOX(optmenu_open_external)));
271 gtk_widget_show (optmenu_open_external);
274 COMBOBOX_ADD (menu, "DEFAULT_ACTION", FALSE);
275 COMBOBOX_ADD (menu, _("Open in external browser"), TRUE);
277 gtk_box_pack_start(GTK_BOX(hbox_ext), open_external_label, FALSE, FALSE, 0);
278 gtk_box_pack_start(GTK_BOX(hbox_ext), optmenu_open_external, FALSE, FALSE, 0);
279 gtk_widget_show_all(hbox_ext);
280 gtk_box_pack_start(GTK_BOX(vbox), hbox_ext, FALSE, FALSE, 0);
282 combobox_select_by_data(GTK_COMBO_BOX(optmenu_open_external),
283 fancy_prefs.open_external);
285 #ifdef HAVE_LIBSOUP_GNOME
286 prefs_page->gnome_proxy_checkbox = gnome_proxy_checkbox;
288 prefs_page->proxy_checkbox = proxy_checkbox;
289 prefs_page->proxy_str = proxy_str;
290 prefs_page->enable_remote_content = enable_remote_content;
291 prefs_page->enable_images = enable_images;
292 prefs_page->enable_scripts = enable_scripts;
293 prefs_page->enable_plugins = enable_plugins;
294 prefs_page->enable_java = enable_java;
295 prefs_page->open_external = optmenu_open_external;
296 prefs_page->page.widget = vbox;
298 g_signal_connect(G_OBJECT(prefs_page->enable_remote_content), "toggled",
299 G_CALLBACK(remote_content_set_labels_cb), prefs_page);
300 remote_content_set_labels_cb(NULL, prefs_page);
303 static void prefs_set_proxy_entry_sens(GtkWidget *button, GtkEntry *entry_str) {
304 gtk_widget_set_sensitive(GTK_WIDGET(entry_str),
305 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)));
308 #ifdef HAVE_LIBSOUP_GNOME
309 static void prefs_disable_fancy_proxy(GtkWidget *checkbox, GtkWidget *block) {
310 gboolean toggle = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbox));
311 gtk_widget_set_sensitive(block, !toggle);
312 GList *list = g_list_first(gtk_container_get_children(GTK_CONTAINER(block)));
314 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(list->data), FALSE);
317 gtk_widget_set_sensitive(GTK_WIDGET(list->data), TRUE);
321 static void destroy_fancy_prefs_page(PrefsPage *page)
325 static void save_fancy_prefs(PrefsPage *page)
328 gchar *rc_file_path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
330 pref_file = prefs_write_open(rc_file_path);
331 g_free(rc_file_path);
333 (prefs_set_block_label(pref_file, PREFS_BLOCK_NAME) < 0))
336 if (prefs_write_param(param, pref_file->fp) < 0) {
337 g_warning("failed to write Fancy Plugin configuration\n");
338 prefs_file_close_revert(pref_file);
342 if (fprintf(pref_file->fp, "\n") < 0) {
343 FILE_OP_ERROR(rc_file_path, "fprintf");
344 prefs_file_close_revert(pref_file);
346 prefs_file_close(pref_file);
349 static void save_fancy_prefs_page(PrefsPage *page)
351 FancyPrefsPage *prefs_page = (FancyPrefsPage *) page;
353 #ifdef HAVE_LIBSOUP_GNOME
354 fancy_prefs.enable_gnome_proxy = gtk_toggle_button_get_active
355 (GTK_TOGGLE_BUTTON(prefs_page->gnome_proxy_checkbox));
357 fancy_prefs.enable_images = gtk_toggle_button_get_active
358 (GTK_TOGGLE_BUTTON(prefs_page->enable_images));
359 fancy_prefs.enable_remote_content = gtk_toggle_button_get_active
360 (GTK_TOGGLE_BUTTON(prefs_page->enable_remote_content));
361 fancy_prefs.enable_scripts = gtk_toggle_button_get_active
362 (GTK_TOGGLE_BUTTON(prefs_page->enable_scripts));
363 fancy_prefs.enable_plugins = gtk_toggle_button_get_active
364 (GTK_TOGGLE_BUTTON(prefs_page->enable_plugins));
365 fancy_prefs.enable_java = gtk_toggle_button_get_active
366 (GTK_TOGGLE_BUTTON(prefs_page->enable_java));
367 fancy_prefs.open_external = combobox_get_active_data
368 (GTK_COMBO_BOX(prefs_page->open_external));
369 fancy_prefs.enable_proxy = gtk_toggle_button_get_active
370 (GTK_TOGGLE_BUTTON(prefs_page->proxy_checkbox));
371 fancy_prefs.proxy_str = pref_get_pref_from_entry(GTK_ENTRY(prefs_page->proxy_str));
373 save_fancy_prefs(page);