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 if (fancy_prefs.enable_gnome_proxy)
206 gtk_widget_set_sensitive(proxy_checkbox, FALSE);
207 gtk_box_pack_start(GTK_BOX(vbox_proxy), gnome_proxy_checkbox, FALSE, FALSE, 0);
208 gtk_widget_show(gnome_proxy_checkbox);
209 g_signal_connect(G_OBJECT(gnome_proxy_checkbox), "toggled",
210 G_CALLBACK(prefs_disable_fancy_proxy), block);
212 proxy_checkbox = gtk_check_button_new_with_label(_("Use proxy:"));
213 proxy_str = gtk_entry_new();
214 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(proxy_checkbox),
215 fancy_prefs.enable_proxy);
216 prefs_set_proxy_entry_sens(proxy_checkbox, GTK_ENTRY(proxy_str));
217 g_signal_connect(G_OBJECT(proxy_checkbox), "toggled",
218 G_CALLBACK(prefs_set_proxy_entry_sens), proxy_str);
219 pref_set_entry_from_pref(GTK_ENTRY(proxy_str), fancy_prefs.proxy_str);
221 gtk_box_pack_start(GTK_BOX(block), proxy_checkbox, FALSE, FALSE, 0);
222 gtk_box_pack_start(GTK_BOX(block), proxy_str, FALSE, TRUE, 0);
223 gtk_box_pack_start(GTK_BOX(vbox_proxy), block, FALSE, FALSE, 0);
224 gtk_widget_show_all(vbox_proxy);
226 vbox_remote = gtkut_get_options_frame(vbox, &frame_remote, _("Remote resources"));
227 remote_label = gtk_label_new(_("Loading remote resources can lead to some privacy issues.\n"
228 "When remote content loading is disabled, nothing will be requested\n"
229 "from the network. Rendering of images, scripts, plugin objects or\n"
230 "Java applets can still be enabled for content that is attached\n"
232 gtk_misc_set_alignment(GTK_MISC(remote_label), 0, 0);
233 enable_remote_content = gtk_check_button_new_with_label(_("Enable loading of remote content"));
234 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_remote_content),
235 fancy_prefs.enable_remote_content);
236 gtk_box_pack_start (GTK_BOX (vbox_remote), remote_label, FALSE, FALSE, 0);
237 gtk_box_pack_start (GTK_BOX (vbox_remote), enable_remote_content, FALSE, FALSE, 0);
238 gtk_widget_show_all(vbox_remote);
240 enable_images = gtk_check_button_new_with_label(("IMAGES"));
241 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_images),
242 fancy_prefs.enable_images);
243 gtk_box_pack_start(GTK_BOX(vbox), enable_images, FALSE, FALSE, 0);
244 gtk_widget_show(enable_images);
246 enable_scripts = gtk_check_button_new_with_label("SCRIPTS");
247 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_scripts),
248 fancy_prefs.enable_scripts);
249 gtk_box_pack_start(GTK_BOX(vbox), enable_scripts, FALSE, FALSE, 0);
250 gtk_widget_show(enable_scripts);
252 enable_java = gtk_check_button_new_with_label("JAVA");
253 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_java),
254 fancy_prefs.enable_java);
255 gtk_box_pack_start(GTK_BOX(vbox), enable_java, FALSE, FALSE, 0);
256 gtk_widget_show(enable_java);
258 enable_plugins = gtk_check_button_new_with_label("PLUGINS");
259 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_plugins),
260 fancy_prefs.enable_plugins);
261 gtk_box_pack_start(GTK_BOX(vbox), enable_plugins, FALSE, FALSE, 0);
262 gtk_widget_show(enable_plugins);
264 GtkWidget *hbox_ext = gtk_hbox_new(FALSE, 8);
265 GtkWidget *open_external_label = gtk_label_new(_("When clicking on a link, by default:"));
266 GtkWidget *optmenu_open_external = gtkut_sc_combobox_create(NULL, FALSE);
267 GtkListStore *menu = GTK_LIST_STORE(gtk_combo_box_get_model(
268 GTK_COMBO_BOX(optmenu_open_external)));
269 gtk_widget_show (optmenu_open_external);
272 COMBOBOX_ADD (menu, "DEFAULT_ACTION", FALSE);
273 COMBOBOX_ADD (menu, _("Open in external browser"), TRUE);
275 gtk_box_pack_start(GTK_BOX(hbox_ext), open_external_label, FALSE, FALSE, 0);
276 gtk_box_pack_start(GTK_BOX(hbox_ext), optmenu_open_external, FALSE, FALSE, 0);
277 gtk_widget_show_all(hbox_ext);
278 gtk_box_pack_start(GTK_BOX(vbox), hbox_ext, FALSE, FALSE, 0);
280 combobox_select_by_data(GTK_COMBO_BOX(optmenu_open_external),
281 fancy_prefs.open_external);
283 #ifdef HAVE_LIBSOUP_GNOME
284 prefs_page->gnome_proxy_checkbox = gnome_proxy_checkbox;
286 prefs_page->proxy_checkbox = proxy_checkbox;
287 prefs_page->proxy_str = proxy_str;
288 prefs_page->enable_remote_content = enable_remote_content;
289 prefs_page->enable_images = enable_images;
290 prefs_page->enable_scripts = enable_scripts;
291 prefs_page->enable_plugins = enable_plugins;
292 prefs_page->enable_java = enable_java;
293 prefs_page->open_external = optmenu_open_external;
294 prefs_page->page.widget = vbox;
296 g_signal_connect(G_OBJECT(prefs_page->enable_remote_content), "toggled",
297 G_CALLBACK(remote_content_set_labels_cb), prefs_page);
298 remote_content_set_labels_cb(NULL, prefs_page);
301 static void prefs_set_proxy_entry_sens(GtkWidget *button, GtkEntry *entry_str) {
302 gtk_widget_set_sensitive(GTK_WIDGET(entry_str),
303 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)));
306 #ifdef HAVE_LIBSOUP_GNOME
307 static void prefs_disable_fancy_proxy(GtkWidget *checkbox, GtkWidget *block) {
308 gboolean toggle = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbox));
309 gtk_widget_set_sensitive(block, !toggle);
310 GList *list = g_list_first(gtk_container_get_children(GTK_CONTAINER(block)));
312 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(list->data), FALSE);
315 gtk_widget_set_sensitive(GTK_WIDGET(list->data), TRUE);
319 static void destroy_fancy_prefs_page(PrefsPage *page)
323 static void save_fancy_prefs(PrefsPage *page)
326 gchar *rc_file_path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
328 pref_file = prefs_write_open(rc_file_path);
329 g_free(rc_file_path);
331 (prefs_set_block_label(pref_file, PREFS_BLOCK_NAME) < 0))
334 if (prefs_write_param(param, pref_file->fp) < 0) {
335 g_warning("failed to write Fancy Plugin configuration\n");
336 prefs_file_close_revert(pref_file);
340 if (fprintf(pref_file->fp, "\n") < 0) {
341 FILE_OP_ERROR(rc_file_path, "fprintf");
342 prefs_file_close_revert(pref_file);
344 prefs_file_close(pref_file);
347 static void save_fancy_prefs_page(PrefsPage *page)
349 FancyPrefsPage *prefs_page = (FancyPrefsPage *) page;
351 #ifdef HAVE_LIBSOUP_GNOME
352 fancy_prefs.enable_gnome_proxy = gtk_toggle_button_get_active
353 (GTK_TOGGLE_BUTTON(prefs_page->gnome_proxy_checkbox));
355 fancy_prefs.enable_images = gtk_toggle_button_get_active
356 (GTK_TOGGLE_BUTTON(prefs_page->enable_images));
357 fancy_prefs.enable_remote_content = gtk_toggle_button_get_active
358 (GTK_TOGGLE_BUTTON(prefs_page->enable_remote_content));
359 fancy_prefs.enable_scripts = gtk_toggle_button_get_active
360 (GTK_TOGGLE_BUTTON(prefs_page->enable_scripts));
361 fancy_prefs.enable_plugins = gtk_toggle_button_get_active
362 (GTK_TOGGLE_BUTTON(prefs_page->enable_plugins));
363 fancy_prefs.enable_java = gtk_toggle_button_get_active
364 (GTK_TOGGLE_BUTTON(prefs_page->enable_java));
365 fancy_prefs.open_external = combobox_get_active_data
366 (GTK_COMBO_BOX(prefs_page->open_external));
367 fancy_prefs.enable_proxy = gtk_toggle_button_get_active
368 (GTK_TOGGLE_BUTTON(prefs_page->proxy_checkbox));
369 fancy_prefs.proxy_str = pref_get_pref_from_entry(GTK_ENTRY(prefs_page->proxy_str));
371 save_fancy_prefs(page);