3 * Claws Mail -- A GTK based, lightweight, and fast e-mail client
4 * Copyright (C) 1999-2024 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/>.
22 #include "claws-features.h"
26 #include <glib/gi18n.h>
28 #include "common/version.h"
33 #include "file-utils.h"
36 #include "prefs_common.h"
37 #include "prefs_gtk.h"
38 #include "prefswindow.h"
40 #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 typedef struct _FancyPrefsPage FancyPrefsPage
;
53 struct _FancyPrefsPage
{
55 GtkWidget
*enable_images
;
56 GtkWidget
*enable_remote_content
;
57 GtkWidget
*enable_scripts
;
58 GtkWidget
*enable_plugins
;
59 GtkWidget
*enable_java
;
60 GtkWidget
*open_external
;
61 /* GtkWidget *proxy_checkbox;
62 GtkWidget *proxy_str; */
63 GtkWidget
*stylesheet
;
66 static PrefParam param
[] = {
67 {"enable_images", "TRUE", &fancy_prefs
.enable_images
, P_BOOL
,
69 {"enable_remote_content", "FALSE", &fancy_prefs
.enable_remote_content
, P_BOOL
,
71 {"enable_scripts", "FALSE", &fancy_prefs
.enable_scripts
, P_BOOL
,
73 {"enable_plugins", "FALSE", &fancy_prefs
.enable_plugins
, P_BOOL
,
75 {"open_external", "TRUE", &fancy_prefs
.open_external
, P_BOOL
,
77 {"zoom_level", "100", &fancy_prefs
.zoom_level
, P_INT
,
79 {"enable_java", "FALSE", &fancy_prefs
.enable_java
, P_BOOL
,
81 /* {"enable_proxy", "FALSE", &fancy_prefs.enable_proxy, P_BOOL,
83 {"proxy_server", "http://SERVERNAME:PORT", &fancy_prefs.proxy_str, P_STRING,
85 {"stylesheet", "", &fancy_prefs
.stylesheet
, P_STRING
, NULL
, NULL
, NULL
},
89 static FancyPrefsPage fancy_prefs_page
;
91 static void fancy_prefs_stylesheet_browse_cb (GtkWidget
*widget
, gpointer data
);
92 static void fancy_prefs_stylesheet_edit_cb (GtkWidget
*widget
, gpointer data
);
93 static void fancy_prefs_stylesheet_changed_cb (GtkWidget
*widget
, gpointer data
);
95 static void create_fancy_prefs_page (PrefsPage
*page
, GtkWindow
*window
, gpointer data
);
96 static void destroy_fancy_prefs_page (PrefsPage
*page
);
97 static void save_fancy_prefs_page (PrefsPage
*page
);
98 static void save_fancy_prefs (PrefsPage
*page
);
100 void fancy_prefs_init(void)
102 static gchar
*path
[3];
105 path
[0] = _("Plugins");
109 prefs_set_default(param
);
110 rcpath
= g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S
, COMMON_RC
, NULL
);
111 prefs_read_config(param
, PREFS_BLOCK_NAME
, rcpath
, NULL
);
114 fancy_prefs_page
.page
.path
= path
;
115 fancy_prefs_page
.page
.create_widget
= create_fancy_prefs_page
;
116 fancy_prefs_page
.page
.destroy_widget
= destroy_fancy_prefs_page
;
117 fancy_prefs_page
.page
.save_page
= save_fancy_prefs_page
;
118 fancy_prefs_page
.page
.weight
= 30.0;
119 prefs_gtk_register_page((PrefsPage
*) &fancy_prefs_page
);
122 void fancy_prefs_done(void)
124 save_fancy_prefs((PrefsPage
*) &fancy_prefs_page
);
125 prefs_gtk_unregister_page((PrefsPage
*) &fancy_prefs_page
);
128 static void remote_content_set_labels_cb(GtkWidget
*button
, FancyPrefsPage
*prefs_page
)
132 gboolean remote_enabled
= gtk_toggle_button_get_active(
133 GTK_TOGGLE_BUTTON(prefs_page
->enable_remote_content
));
136 gtk_button_set_label(GTK_BUTTON(prefs_page
->enable_images
),
137 remote_enabled
? _("Display images")
138 : _("Display embedded images"));
140 /* Enable Javascript */
141 gtk_button_set_label(GTK_BUTTON(prefs_page
->enable_scripts
),
142 remote_enabled
? _("Execute javascript")
143 : _("Execute embedded javascript"));
146 gtk_button_set_label(GTK_BUTTON(prefs_page
->enable_java
),
147 remote_enabled
? _("Execute Java applets")
148 : _("Execute embedded Java applets"));
151 gtk_button_set_label(GTK_BUTTON(prefs_page
->enable_plugins
),
152 remote_enabled
? _("Render objects using plugins")
153 : _("Render embedded objects using plugins"));
156 model
= gtk_combo_box_get_model(GTK_COMBO_BOX(prefs_page
->open_external
));
157 if (gtk_tree_model_get_iter_first (model
, &iter
)) {
159 gtk_list_store_set(GTK_LIST_STORE(model
), &iter
, COMBOBOX_TEXT
,
160 _("Open in Viewer (remote content is enabled)"), -1);
162 gtk_list_store_set(GTK_LIST_STORE(model
), &iter
, COMBOBOX_TEXT
,
163 _("Do nothing (remote content is disabled)"), -1);
167 static void create_fancy_prefs_page(PrefsPage
*page
, GtkWindow
*window
,
170 FancyPrefsPage
*prefs_page
= (FancyPrefsPage
*) page
;
173 /* GtkWidget *proxy_checkbox;
174 GtkWidget *proxy_str;
175 GtkWidget *vbox_proxy;
176 GtkWidget *frame_proxy;
178 GtkWidget
*frame_remote
;
179 GtkWidget
*vbox_remote
;
180 GtkWidget
*remote_label
;
181 GtkWidget
*enable_remote_content
;
182 GtkWidget
*enable_images
;
183 GtkWidget
*enable_scripts
;
184 GtkWidget
*enable_plugins
;
185 GtkWidget
*enable_java
;
186 GtkWidget
*stylesheet_label
;
187 GtkWidget
*stylesheet
;
188 GtkWidget
*stylesheet_browse_button
;
189 GtkWidget
*stylesheet_edit_button
;
191 vbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, 3);
192 gtk_container_set_border_width(GTK_CONTAINER(vbox
), VBOX_BORDER
);
193 gtk_widget_show(vbox
);
195 GtkWidget *block = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
197 vbox_proxy = gtkut_get_options_frame(vbox, &frame_proxy, _("Proxy"));
198 proxy_checkbox = gtk_check_button_new_with_label(_("Use proxy"));
199 proxy_str = gtk_entry_new();
200 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(proxy_checkbox),
201 fancy_prefs.enable_proxy);
202 prefs_set_proxy_entry_sens(proxy_checkbox, GTK_ENTRY(proxy_str));
203 g_signal_connect(G_OBJECT(proxy_checkbox), "toggled",
204 G_CALLBACK(prefs_set_proxy_entry_sens), proxy_str);
205 pref_set_entry_from_pref(GTK_ENTRY(proxy_str), fancy_prefs.proxy_str);
207 gtk_box_pack_start(GTK_BOX(block), proxy_checkbox, FALSE, FALSE, 0);
208 gtk_box_pack_start(GTK_BOX(block), proxy_str, TRUE, TRUE, 0);
209 gtk_box_pack_start(GTK_BOX(vbox_proxy), block, FALSE, FALSE, 0);
210 gtk_widget_show_all(vbox_proxy);
212 vbox_remote
= gtkut_get_options_frame(vbox
, &frame_remote
, _("Remote resources"));
213 remote_label
= gtk_label_new(_("Loading remote resources can lead to some privacy issues.\n"
214 "When remote content loading is disabled, nothing will be requested\n"
215 "from the network. Rendering of images, scripts, plugin objects or\n"
216 "Java applets can still be enabled for content that is attached\n"
218 gtk_label_set_xalign(GTK_LABEL(remote_label
), 0.0);
219 gtk_label_set_yalign(GTK_LABEL(remote_label
), 0.0);
220 enable_remote_content
= gtk_check_button_new_with_label(_("Enable loading of remote content"));
221 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_remote_content
),
222 fancy_prefs
.enable_remote_content
);
223 gtk_box_pack_start (GTK_BOX (vbox_remote
), remote_label
, FALSE
, FALSE
, 0);
224 gtk_box_pack_start (GTK_BOX (vbox_remote
), enable_remote_content
, FALSE
, FALSE
, 0);
225 gtk_widget_show_all(vbox_remote
);
227 enable_images
= gtk_check_button_new_with_label(("IMAGES"));
228 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_images
),
229 fancy_prefs
.enable_images
);
230 gtk_box_pack_start(GTK_BOX(vbox
), enable_images
, FALSE
, FALSE
, 0);
231 gtk_widget_show(enable_images
);
233 enable_scripts
= gtk_check_button_new_with_label("SCRIPTS");
234 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_scripts
),
235 fancy_prefs
.enable_scripts
);
236 gtk_box_pack_start(GTK_BOX(vbox
), enable_scripts
, FALSE
, FALSE
, 0);
237 gtk_widget_show(enable_scripts
);
239 enable_java
= gtk_check_button_new_with_label("JAVA");
240 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_java
),
241 fancy_prefs
.enable_java
);
242 gtk_box_pack_start(GTK_BOX(vbox
), enable_java
, FALSE
, FALSE
, 0);
243 gtk_widget_show(enable_java
);
245 enable_plugins
= gtk_check_button_new_with_label("PLUGINS");
246 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_plugins
),
247 fancy_prefs
.enable_plugins
);
248 gtk_box_pack_start(GTK_BOX(vbox
), enable_plugins
, FALSE
, FALSE
, 0);
249 gtk_widget_show(enable_plugins
);
251 GtkWidget
*hbox_ext
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 8);
252 GtkWidget
*open_external_label
= gtk_label_new(_("When clicking on a link, by default"));
253 GtkWidget
*optmenu_open_external
= gtkut_sc_combobox_create(NULL
, FALSE
);
254 GtkListStore
*menu
= GTK_LIST_STORE(gtk_combo_box_get_model(
255 GTK_COMBO_BOX(optmenu_open_external
)));
256 gtk_widget_show (optmenu_open_external
);
259 COMBOBOX_ADD (menu
, "DEFAULT_ACTION", FALSE
);
260 COMBOBOX_ADD (menu
, _("Open in External Browser"), TRUE
);
262 gtk_box_pack_start(GTK_BOX(hbox_ext
), open_external_label
, FALSE
, FALSE
, 0);
263 gtk_box_pack_start(GTK_BOX(hbox_ext
), optmenu_open_external
, FALSE
, FALSE
, 0);
264 gtk_widget_show_all(hbox_ext
);
265 gtk_box_pack_start(GTK_BOX(vbox
), hbox_ext
, FALSE
, FALSE
, 0);
267 combobox_select_by_data(GTK_COMBO_BOX(optmenu_open_external
),
268 fancy_prefs
.open_external
);
270 GtkWidget
*hbox_css
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 8);
271 gtk_widget_show(hbox_css
);
272 gtk_box_pack_start(GTK_BOX(vbox
), hbox_css
, FALSE
, FALSE
, 0);
274 CLAWS_SET_TIP(hbox_css
, _("The CSS in this file will be applied to all HTML parts"));
276 stylesheet_label
= gtk_label_new(_("Stylesheet"));
277 gtk_widget_show(stylesheet_label
);
278 gtk_box_pack_start(GTK_BOX(hbox_css
), stylesheet_label
, FALSE
, FALSE
, 0);
280 stylesheet
= gtk_entry_new();
281 gtk_widget_show(stylesheet
);
282 gtk_box_pack_start(GTK_BOX(hbox_css
), stylesheet
, TRUE
, TRUE
, 0);
284 stylesheet_browse_button
= gtkut_get_browse_file_btn(_("Bro_wse"));
285 gtk_widget_show(stylesheet_browse_button
);
286 gtk_box_pack_start(GTK_BOX(hbox_css
), stylesheet_browse_button
, FALSE
, FALSE
, 0);
287 g_signal_connect(G_OBJECT(stylesheet_browse_button
), "clicked",
288 G_CALLBACK(fancy_prefs_stylesheet_browse_cb
), stylesheet
);
290 stylesheet_edit_button
= gtk_button_new_with_mnemonic(_("_Edit"));
291 gtk_widget_show (stylesheet_edit_button
);
292 gtk_box_pack_start(GTK_BOX(hbox_css
), stylesheet_edit_button
, FALSE
, FALSE
, 0);
293 g_signal_connect(G_OBJECT(stylesheet_edit_button
), "clicked",
294 G_CALLBACK(fancy_prefs_stylesheet_edit_cb
), stylesheet
);
295 g_signal_connect(G_OBJECT(stylesheet
), "changed",
296 G_CALLBACK(fancy_prefs_stylesheet_changed_cb
), stylesheet_edit_button
);
297 pref_set_entry_from_pref(GTK_ENTRY(stylesheet
), fancy_prefs
.stylesheet
);
298 g_signal_emit_by_name(G_OBJECT(stylesheet
), "changed", stylesheet_edit_button
);
300 /* prefs_page->proxy_checkbox = proxy_checkbox;
301 prefs_page->proxy_str = proxy_str; */
302 prefs_page
->enable_remote_content
= enable_remote_content
;
303 prefs_page
->enable_images
= enable_images
;
304 prefs_page
->enable_scripts
= enable_scripts
;
305 prefs_page
->enable_plugins
= enable_plugins
;
306 prefs_page
->enable_java
= enable_java
;
307 prefs_page
->open_external
= optmenu_open_external
;
308 prefs_page
->stylesheet
= stylesheet
;
309 prefs_page
->page
.widget
= vbox
;
311 g_signal_connect(G_OBJECT(prefs_page
->enable_remote_content
), "toggled",
312 G_CALLBACK(remote_content_set_labels_cb
), prefs_page
);
313 remote_content_set_labels_cb(NULL
, prefs_page
);
316 static void fancy_prefs_stylesheet_browse_cb(GtkWidget
*widget
, gpointer data
)
319 gchar
*utf8_filename
;
320 GtkEntry
*dest
= GTK_ENTRY(data
);
322 filename
= filesel_select_file_open(_("Select stylesheet"), NULL
);
323 if (!filename
) return;
325 utf8_filename
= g_filename_to_utf8(filename
, -1, NULL
, NULL
, NULL
);
326 if (!utf8_filename
) {
327 g_warning("fancy_prefs_stylesheet_browse_cb(): failed to convert character set");
328 utf8_filename
= g_strdup(filename
);
330 gtk_entry_set_text(GTK_ENTRY(dest
), utf8_filename
);
331 g_free(utf8_filename
);
334 static void fancy_prefs_stylesheet_edit_cb(GtkWidget
*widget
, gpointer data
)
336 const gchar
*stylesheet
= gtk_entry_get_text(GTK_ENTRY(data
));
337 if (!is_file_exist(stylesheet
))
338 str_write_to_file(stylesheet
, "", TRUE
);
339 open_txt_editor(stylesheet
, prefs_common_get_ext_editor_cmd());
342 static void fancy_prefs_stylesheet_changed_cb(GtkWidget
*widget
, gpointer data
)
344 const gchar
*stylesheet
= gtk_entry_get_text(GTK_ENTRY(widget
));
345 gtk_widget_set_sensitive(GTK_WIDGET(data
), (*stylesheet
)? TRUE
: FALSE
);
348 static void prefs_set_proxy_entry_sens(GtkWidget *button, GtkEntry *entry_str) {
349 gtk_widget_set_sensitive(GTK_WIDGET(entry_str),
350 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)));
353 static void destroy_fancy_prefs_page(PrefsPage
*page
)
357 static void save_fancy_prefs(PrefsPage
*page
)
360 gchar
*rc_file_path
= g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S
,
362 pref_file
= prefs_write_open(rc_file_path
);
363 g_free(rc_file_path
);
365 (prefs_set_block_label(pref_file
, PREFS_BLOCK_NAME
) < 0))
368 if (prefs_write_param(param
, pref_file
->fp
) < 0) {
369 g_warning("failed to write Fancy plugin configuration");
370 prefs_file_close_revert(pref_file
);
374 if (fprintf(pref_file
->fp
, "\n") < 0) {
375 FILE_OP_ERROR(rc_file_path
, "fprintf");
376 prefs_file_close_revert(pref_file
);
378 prefs_file_close(pref_file
);
381 static void save_fancy_prefs_page(PrefsPage
*page
)
383 FancyPrefsPage
*prefs_page
= (FancyPrefsPage
*) page
;
385 fancy_prefs
.enable_images
= gtk_toggle_button_get_active
386 (GTK_TOGGLE_BUTTON(prefs_page
->enable_images
));
387 fancy_prefs
.enable_remote_content
= gtk_toggle_button_get_active
388 (GTK_TOGGLE_BUTTON(prefs_page
->enable_remote_content
));
389 fancy_prefs
.enable_scripts
= gtk_toggle_button_get_active
390 (GTK_TOGGLE_BUTTON(prefs_page
->enable_scripts
));
391 fancy_prefs
.enable_plugins
= gtk_toggle_button_get_active
392 (GTK_TOGGLE_BUTTON(prefs_page
->enable_plugins
));
393 fancy_prefs
.enable_java
= gtk_toggle_button_get_active
394 (GTK_TOGGLE_BUTTON(prefs_page
->enable_java
));
395 fancy_prefs
.open_external
= combobox_get_active_data
396 (GTK_COMBO_BOX(prefs_page
->open_external
));
397 /* fancy_prefs.enable_proxy = gtk_toggle_button_get_active
398 (GTK_TOGGLE_BUTTON(prefs_page->proxy_checkbox));
399 fancy_prefs.proxy_str = pref_get_pref_from_entry(GTK_ENTRY(prefs_page->proxy_str)); */
401 /* pref_get_pref_from_entry() escapes the backslashes in strings,
402 * we do not want that, since this entry contains a Windows path.
403 * Let's just strdup it. */
404 fancy_prefs
.stylesheet
= g_strdup(gtk_entry_get_text(
405 GTK_ENTRY(prefs_page
->stylesheet
)));
407 fancy_prefs
.stylesheet
= pref_get_pref_from_entry(GTK_ENTRY(prefs_page
->stylesheet
));
410 save_fancy_prefs(page
);