2 * Claws Mail -- A GTK+ based, lightweight, and fast e-mail client
3 * Copyright(C) 2019 the Claws Mail Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write tothe Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "claws-features.h"
24 #include <glib/gi18n.h>
26 #include "prefs_gtk.h"
27 #include "common/defs.h"
28 #include "common/utils.h"
29 #include "gtk/gtkutils.h"
33 #define PREFS_BLOCK_NAME "LiteHTML"
35 static void create_lh_prefs_page(PrefsPage *page, GtkWindow *window,
37 static void destroy_lh_prefs_page(PrefsPage *page);
38 static void save_lh_prefs_page(PrefsPage *page);
39 static void save_prefs(void);
45 GtkWidget *enable_remote_content;
46 GtkWidget *image_cache_size;
48 typedef struct _LHPrefsPage LHPrefsPage;
50 static PrefParam param[] = {
51 { "enable_remote_content", "FALSE", &lh_prefs.enable_remote_content, P_BOOL,
53 { "image_cache_size", "20", &lh_prefs.image_cache_size, P_INT,
55 { NULL, NULL, NULL, 0, NULL, NULL, NULL }
58 static LHPrefsPage lh_prefs_page;
60 LHPrefs *lh_prefs_get(void)
65 void lh_prefs_init(void)
67 static gchar *path[3];
70 path[0] = _("Plugins");
74 prefs_set_default(param);
75 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
76 prefs_read_config(param, PREFS_BLOCK_NAME, rcpath, NULL);
79 lh_prefs_page.page.path = path;
80 lh_prefs_page.page.create_widget = create_lh_prefs_page;
81 lh_prefs_page.page.destroy_widget = destroy_lh_prefs_page;
82 lh_prefs_page.page.save_page = save_lh_prefs_page;
83 lh_prefs_page.page.weight = 30.0;
84 prefs_gtk_register_page((PrefsPage *) &lh_prefs_page);
87 void lh_prefs_done(void)
91 static void create_lh_prefs_page(PrefsPage *page, GtkWindow *window,
94 LHPrefsPage *prefs_page = (LHPrefsPage *)page;
96 GtkWidget *vbox_remote;
100 GtkWidget *enable_remote_content;
101 GtkWidget *image_cache_size;
104 vbox = gtk_vbox_new(FALSE, 3);
105 gtk_container_set_border_width(GTK_CONTAINER(vbox), VBOX_BORDER);
106 gtk_widget_show(vbox);
108 /* Enable remote content */
109 vbox_remote = gtkut_get_options_frame(vbox, &frame, _("Remote resources"));
111 label = gtk_label_new(_("Loading remote resources can lead to some privacy issues.\n"
112 "When remote content loading is disabled, nothing will be requested\n"
113 "from the network."));
114 gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
116 enable_remote_content = gtk_check_button_new_with_label(_("Enable loading of remote content"));
117 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_remote_content),
118 lh_prefs.enable_remote_content);
120 gtk_box_pack_start(GTK_BOX(vbox_remote), label, FALSE, FALSE, 0);
121 gtk_box_pack_start(GTK_BOX(vbox_remote), enable_remote_content, FALSE, FALSE, 0);
122 gtk_widget_show_all(vbox_remote);
124 /* Image cache size */
125 hbox = gtk_hbox_new(FALSE, 8);
126 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
128 label = gtk_label_new(_("Size of image cache in megabytes"));
129 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
131 adj = gtk_adjustment_new(0, 0, 99999, 1, 10, 0);
132 image_cache_size = gtk_spin_button_new(GTK_ADJUSTMENT(adj), 1, 0);
133 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(image_cache_size), TRUE);
134 gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(image_cache_size), FALSE);
135 gtk_spin_button_set_value(GTK_SPIN_BUTTON(image_cache_size),
136 lh_prefs.image_cache_size);
137 gtk_box_pack_start(GTK_BOX(hbox), image_cache_size, FALSE, FALSE, 0);
139 gtk_widget_show_all(hbox);
141 prefs_page->enable_remote_content = enable_remote_content;
142 prefs_page->image_cache_size = image_cache_size;
143 prefs_page->page.widget = vbox;
146 static void destroy_lh_prefs_page(PrefsPage *page)
150 static void save_lh_prefs_page(PrefsPage *page)
152 LHPrefsPage *prefs_page = (LHPrefsPage *)page;
154 lh_prefs.enable_remote_content = gtk_toggle_button_get_active(
155 GTK_TOGGLE_BUTTON(prefs_page->enable_remote_content));
156 lh_prefs.image_cache_size = gtk_spin_button_get_value_as_int(
157 GTK_SPIN_BUTTON(prefs_page->image_cache_size));
162 static void save_prefs(void)
165 gchar *rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
168 pref_file = prefs_write_open(rcpath);
171 g_warning("failed to open configuration file '%s' for writing", rcpath);
175 if (prefs_set_block_label(pref_file, PREFS_BLOCK_NAME) < 0) {
176 g_warning("failed to set block label "PREFS_BLOCK_NAME);
181 if (prefs_write_param(param, pref_file->fp) < 0) {
182 g_warning("failed to write LiteHTML Viewer plugin configuration");
183 prefs_file_close_revert(pref_file);
188 if (fprintf(pref_file->fp, "\n") < 0) {
189 FILE_OP_ERROR(rcpath, "fprintf");
190 prefs_file_close_revert(pref_file);
192 debug_print("successfully saved LiteHTML Viewer plugin configuration\n");
193 prefs_file_close(pref_file);