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 *auto_load_images;
59 GtkWidget *enable_inner_navigation;
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 {"auto_load_images", "FALSE", &fancy_prefs.auto_load_images, P_BOOL,
74 {"enable_inner_navigation", "FALSE", &fancy_prefs.enable_inner_navigation, 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,
101 static void destroy_fancy_prefs_page (PrefsPage *page);
102 static void save_fancy_prefs_page (PrefsPage *page);
103 static void save_fancy_prefs (PrefsPage *page);
105 void fancy_prefs_init(void)
107 static gchar *path[3];
110 path[0] = _("Plugins");
114 prefs_set_default(param);
115 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
116 prefs_read_config(param, PREFS_BLOCK_NAME, rcpath, NULL);
119 fancy_prefs_page.page.path = path;
120 fancy_prefs_page.page.create_widget = create_fancy_prefs_page;
121 fancy_prefs_page.page.destroy_widget = destroy_fancy_prefs_page;
122 fancy_prefs_page.page.save_page = save_fancy_prefs_page;
123 fancy_prefs_page.page.weight = 30.0;
124 prefs_gtk_register_page((PrefsPage *) &fancy_prefs_page);
127 void fancy_prefs_done(void)
129 save_fancy_prefs((PrefsPage *) &fancy_prefs_page);
130 prefs_gtk_unregister_page((PrefsPage *) &fancy_prefs_page);
133 static void open_external_set_label_cb(GtkWidget *button, FancyPrefsPage *prefs_page)
135 GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(prefs_page->open_external));
137 if (gtk_tree_model_get_iter_first (model, &iter)) {
138 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(prefs_page->enable_inner_navigation)))
139 gtk_list_store_set(model, &iter, COMBOBOX_TEXT, _("Open in viewer"), -1);
141 gtk_list_store_set(model, &iter, COMBOBOX_TEXT, _("Do nothing"), -1);
145 static void create_fancy_prefs_page(PrefsPage *page, GtkWindow *window,
148 FancyPrefsPage *prefs_page = (FancyPrefsPage *) page;
151 #ifdef HAVE_LIBSOUP_GNOME
152 GtkWidget *gnome_proxy_checkbox;
154 GtkWidget *proxy_checkbox;
155 GtkWidget *proxy_str;
156 GtkWidget *checkbox1;
157 GtkWidget *checkbox2;
158 GtkWidget *checkbox3;
159 GtkWidget *checkbox4;
160 GtkWidget *checkbox6;
162 vbox = gtk_vbox_new(FALSE, 3);
163 gtk_container_set_border_width(GTK_CONTAINER(vbox), VBOX_BORDER);
164 gtk_widget_show(vbox);
166 GtkWidget *block = gtk_vbox_new(FALSE, FALSE);
167 proxy_checkbox = gtk_check_button_new_with_label(_("Proxy Setting"));
168 proxy_str = gtk_entry_new();
169 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(proxy_checkbox),
170 fancy_prefs.enable_proxy);
171 prefs_set_proxy_entry_sens(proxy_checkbox, GTK_ENTRY(proxy_str));
172 g_signal_connect(G_OBJECT(proxy_checkbox), "toggled",
173 G_CALLBACK(prefs_set_proxy_entry_sens), proxy_str);
174 pref_set_entry_from_pref(GTK_ENTRY(proxy_str), fancy_prefs.proxy_str);
176 gtk_box_pack_start(GTK_BOX(block), proxy_checkbox, FALSE, FALSE, 0);
177 gtk_box_pack_start(GTK_BOX(block), proxy_str, FALSE, FALSE, 0);
178 gtk_box_pack_start(GTK_BOX(vbox), block, FALSE, FALSE, 0);
179 gtk_widget_show(proxy_checkbox);
180 gtk_widget_show(proxy_str);
181 gtk_widget_show(block);
182 #ifdef HAVE_LIBSOUP_GNOME
183 gnome_proxy_checkbox = gtk_check_button_new_with_label(_("Use GNOME proxy setting"));
184 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gnome_proxy_checkbox),
185 fancy_prefs.enable_gnome_proxy);
186 if (fancy_prefs.enable_gnome_proxy)
187 gtk_widget_set_sensitive(proxy_checkbox, FALSE);
188 gtk_box_pack_start(GTK_BOX(vbox), gnome_proxy_checkbox, FALSE, FALSE, 0);
189 gtk_widget_show(gnome_proxy_checkbox);
190 g_signal_connect(G_OBJECT(gnome_proxy_checkbox), "toggled",
191 G_CALLBACK(prefs_disable_fancy_proxy), block);
193 checkbox1 = gtk_check_button_new_with_label(_("Auto-Load images"));
194 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox1),
195 fancy_prefs.auto_load_images);
196 gtk_box_pack_start(GTK_BOX(vbox), checkbox1, FALSE, FALSE, 0);
197 gtk_widget_show(checkbox1);
199 checkbox2 = gtk_check_button_new_with_label(_("Enable inner navigation"));
200 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox2),
201 fancy_prefs.enable_inner_navigation);
202 gtk_box_pack_start(GTK_BOX(vbox), checkbox2, FALSE, FALSE, 0);
203 gtk_widget_show(checkbox2);
205 checkbox3 = gtk_check_button_new_with_label(_("Enable Javascript"));
206 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox3),
207 fancy_prefs.enable_scripts);
208 gtk_box_pack_start(GTK_BOX(vbox), checkbox3, FALSE, FALSE, 0);
209 gtk_widget_show(checkbox3);
211 checkbox4 = gtk_check_button_new_with_label(_("Enable Plugins"));
212 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox4),
213 fancy_prefs.enable_plugins);
214 gtk_box_pack_start(GTK_BOX(vbox), checkbox4, FALSE, FALSE, 0);
215 gtk_widget_show(checkbox4);
216 checkbox6 = gtk_check_button_new_with_label(_("Enable Java"));
217 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox6),
218 fancy_prefs.enable_java);
219 gtk_box_pack_start(GTK_BOX(vbox), checkbox6, FALSE, FALSE, 0);
220 gtk_widget_show(checkbox6);
222 GtkWidget *hbox_ext = gtk_hbox_new(FALSE, 8);
223 GtkWidget *open_external_label = gtk_label_new(_("When clicking on a link, by default:"));
224 GtkWidget *optmenu_open_external = gtkut_sc_combobox_create(NULL, FALSE);
225 GtkListStore *menu = GTK_LIST_STORE(gtk_combo_box_get_model(
226 GTK_COMBO_BOX(optmenu_open_external)));
227 gtk_widget_show (optmenu_open_external);
230 COMBOBOX_ADD (menu, "DEFAULT_ACTION", FALSE);
231 COMBOBOX_ADD (menu, _("Open in external browser"), TRUE);
233 gtk_box_pack_start(GTK_BOX(hbox_ext), open_external_label, FALSE, FALSE, 0);
234 gtk_box_pack_start(GTK_BOX(hbox_ext), optmenu_open_external, FALSE, FALSE, 0);
235 gtk_widget_show_all(hbox_ext);
236 gtk_box_pack_start(GTK_BOX(vbox), hbox_ext, FALSE, FALSE, 0);
238 combobox_select_by_data(GTK_COMBO_BOX(optmenu_open_external),
239 fancy_prefs.open_external);
241 #ifdef HAVE_LIBSOUP_GNOME
242 prefs_page->gnome_proxy_checkbox = gnome_proxy_checkbox;
244 prefs_page->proxy_checkbox = proxy_checkbox;
245 prefs_page->proxy_str = proxy_str;
246 prefs_page->auto_load_images = checkbox1;
247 prefs_page->enable_inner_navigation = checkbox2;
248 prefs_page->enable_scripts = checkbox3;
249 prefs_page->enable_plugins = checkbox4;
250 prefs_page->enable_java = checkbox6;
251 prefs_page->open_external = optmenu_open_external;
252 prefs_page->page.widget = vbox;
254 g_signal_connect(G_OBJECT(prefs_page->enable_inner_navigation), "toggled",
255 G_CALLBACK(open_external_set_label_cb), prefs_page);
256 open_external_set_label_cb(NULL, prefs_page);
259 static void prefs_set_proxy_entry_sens(GtkWidget *button, GtkEntry *entry_str) {
260 gtk_widget_set_sensitive(GTK_WIDGET(entry_str),
261 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)));
264 #ifdef HAVE_LIBSOUP_GNOME
265 static void prefs_disable_fancy_proxy(GtkWidget *checkbox, GtkWidget *block) {
266 gboolean toggle = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbox));
267 gtk_widget_set_sensitive(block, !toggle);
268 GList *list = g_list_first(gtk_container_get_children(GTK_CONTAINER(block)));
270 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(list->data), FALSE);
273 gtk_widget_set_sensitive(GTK_WIDGET(list->data), TRUE);
277 static void destroy_fancy_prefs_page(PrefsPage *page)
281 static void save_fancy_prefs(PrefsPage *page)
284 gchar *rc_file_path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
286 pref_file = prefs_write_open(rc_file_path);
287 g_free(rc_file_path);
289 (prefs_set_block_label(pref_file, PREFS_BLOCK_NAME) < 0))
292 if (prefs_write_param(param, pref_file->fp) < 0) {
293 g_warning("failed to write Fancy Plugin configuration\n");
294 prefs_file_close_revert(pref_file);
298 if (fprintf(pref_file->fp, "\n") < 0) {
299 FILE_OP_ERROR(rc_file_path, "fprintf");
300 prefs_file_close_revert(pref_file);
302 prefs_file_close(pref_file);
305 static void save_fancy_prefs_page(PrefsPage *page)
307 FancyPrefsPage *prefs_page = (FancyPrefsPage *) page;
309 #ifdef HAVE_LIBSOUP_GNOME
310 fancy_prefs.enable_gnome_proxy = gtk_toggle_button_get_active
311 (GTK_TOGGLE_BUTTON(prefs_page->gnome_proxy_checkbox));
313 fancy_prefs.auto_load_images = gtk_toggle_button_get_active
314 (GTK_TOGGLE_BUTTON(prefs_page->auto_load_images));
315 fancy_prefs.enable_inner_navigation = gtk_toggle_button_get_active
316 (GTK_TOGGLE_BUTTON(prefs_page->enable_inner_navigation));
317 fancy_prefs.enable_scripts = gtk_toggle_button_get_active
318 (GTK_TOGGLE_BUTTON(prefs_page->enable_scripts));
319 fancy_prefs.enable_plugins = gtk_toggle_button_get_active
320 (GTK_TOGGLE_BUTTON(prefs_page->enable_plugins));
321 fancy_prefs.enable_java = gtk_toggle_button_get_active
322 (GTK_TOGGLE_BUTTON(prefs_page->enable_java));
323 fancy_prefs.open_external = combobox_get_active_data
324 (GTK_COMBO_BOX(prefs_page->open_external));
325 fancy_prefs.enable_proxy = gtk_toggle_button_get_active
326 (GTK_TOGGLE_BUTTON(prefs_page->proxy_checkbox));
327 fancy_prefs.proxy_str = pref_get_pref_from_entry(GTK_ENTRY(prefs_page->proxy_str));
329 save_fancy_prefs(page);