[Commits] [SCM] claws branch, litehtml, updated. 3.17.3-90-g53a7361

ticho at claws-mail.org ticho at claws-mail.org
Sat Jan 26 22:02:11 CET 2019


The branch, litehtml has been updated
       via  53a7361bf4830ae22e0872daf1ecb23e6f82d322 (commit)
      from  c67e59b216f2a0fde58c8cf3d9ebe7b869f818de (commit)

Summary of changes:
 src/plugins/litehtml_viewer/Makefile.am            |    3 +
 src/plugins/litehtml_viewer/lh_prefs.c             |  171 ++++++++++++++++++++
 .../fancy_prefs.h => litehtml_viewer/lh_prefs.h}   |   47 +++---
 src/plugins/litehtml_viewer/lh_widget.cpp          |    6 +
 src/plugins/litehtml_viewer/plugin.c               |    4 +
 5 files changed, 203 insertions(+), 28 deletions(-)
 create mode 100644 src/plugins/litehtml_viewer/lh_prefs.c
 copy src/plugins/{fancy/fancy_prefs.h => litehtml_viewer/lh_prefs.h} (54%)


- Log -----------------------------------------------------------------
commit 53a7361bf4830ae22e0872daf1ecb23e6f82d322
Author: Andrej Kacian <ticho at claws-mail.org>
Date:   Sat Jan 26 21:59:15 2019 +0100

    Added preferences page to LiteHTML plugin and make it respect the enable_remote_content pref
    
    Only "enable_remote_content" pref for now.

diff --git a/src/plugins/litehtml_viewer/Makefile.am b/src/plugins/litehtml_viewer/Makefile.am
index 648960c..ded5d58 100644
--- a/src/plugins/litehtml_viewer/Makefile.am
+++ b/src/plugins/litehtml_viewer/Makefile.am
@@ -41,9 +41,11 @@ litehtml_viewer_la_CFLAGS = -std=c99
 litehtml_viewer_la_SOURCES = \
 	container_linux.cpp \
 	plugin.c \
+	lh_prefs.c \
 	lh_viewer.c \
 	lh_widget.cpp \
 	container_linux.h \
+	lh_prefs.h \
 	lh_viewer.h \
 	lh_widget.h \
 	lh_widget_wrapped.h \
@@ -62,6 +64,7 @@ litehtml_viewer_la_CPPFLAGS = \
 	$(IFLAGS) \
 	$(GLIB_CFLAGS) \
 	$(GTK_CFLAGS) \
+	$(ENCHANT_CFLAGS) \
 	$(FONTCONFIG_CFLAGS) \
 	$(CAIRO_CFLAGS) \
 	$(CURL_FLAGS)
diff --git a/src/plugins/litehtml_viewer/lh_prefs.c b/src/plugins/litehtml_viewer/lh_prefs.c
new file mode 100644
index 0000000..fec2ff5
--- /dev/null
+++ b/src/plugins/litehtml_viewer/lh_prefs.c
@@ -0,0 +1,171 @@
+/*
+ * Claws Mail -- A GTK+ based, lightweight, and fast e-mail client
+ * Copyright(C) 2019 the Claws Mail Team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write tothe Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#include "claws-features.h"
+#endif
+
+#include <glib.h>
+#include <glib/gi18n.h>
+
+#include "prefs_gtk.h"
+#include "common/defs.h"
+#include "common/utils.h"
+#include "gtk/gtkutils.h"
+
+#include "lh_prefs.h"
+
+#define PREFS_BLOCK_NAME "LiteHTML"
+
+static void create_lh_prefs_page(PrefsPage *page, GtkWindow *window,
+		gpointer data);
+static void destroy_lh_prefs_page(PrefsPage *page);
+static void save_lh_prefs_page(PrefsPage *page);
+static void save_prefs(void);
+
+LHPrefs lh_prefs;
+
+struct _LHPrefsPage {
+	PrefsPage page;
+	GtkWidget *enable_remote_content;
+};
+typedef struct _LHPrefsPage LHPrefsPage;
+
+static PrefParam param[] = {
+	{ "enable_remote_content", "FALSE", &lh_prefs.enable_remote_content, P_BOOL,
+		NULL, NULL, NULL },
+	{ NULL, NULL, NULL, 0, NULL, NULL, NULL }
+};
+
+static LHPrefsPage lh_prefs_page;
+
+LHPrefs *lh_prefs_get(void)
+{
+	return &lh_prefs;
+}
+
+void lh_prefs_init(void)
+{
+	static gchar *path[3];
+	gchar *rcpath;
+
+	path[0] = _("Plugins");
+	path[1] = "LiteHTML";
+	path[2] = NULL;
+
+	prefs_set_default(param);
+	rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
+	prefs_read_config(param, PREFS_BLOCK_NAME, rcpath, NULL);
+	g_free(rcpath);
+
+	lh_prefs_page.page.path = path;
+	lh_prefs_page.page.create_widget = create_lh_prefs_page;
+	lh_prefs_page.page.destroy_widget = destroy_lh_prefs_page;
+	lh_prefs_page.page.save_page = save_lh_prefs_page;
+	lh_prefs_page.page.weight = 30.0;
+	prefs_gtk_register_page((PrefsPage *) &lh_prefs_page);
+}
+
+void lh_prefs_done(void)
+{
+}
+
+static void create_lh_prefs_page(PrefsPage *page, GtkWindow *window,
+		gpointer data)
+{
+	LHPrefsPage *prefs_page = (LHPrefsPage *)page;
+	GtkWidget *vbox;
+	GtkWidget *vbox_remote;
+	GtkWidget *frame;
+	GtkWidget *label;
+	GtkWidget *enable_remote_content;
+
+	vbox = gtk_vbox_new(FALSE, 3);
+	gtk_container_set_border_width(GTK_CONTAINER(vbox), VBOX_BORDER);
+	gtk_widget_show(vbox);
+
+	/* Enable remote content */
+	vbox_remote = gtkut_get_options_frame(vbox, &frame, _("Remote resources"));
+
+	label = gtk_label_new(_("Loading remote resources can lead to some privacy issues.\n"
+				"When remote content loading is disabled, nothing will be requested\n"
+				"from the network."));
+	gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
+
+	enable_remote_content = gtk_check_button_new_with_label(_("Enable loading of remote content"));
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_remote_content),
+			lh_prefs.enable_remote_content);
+
+	gtk_box_pack_start(GTK_BOX(vbox_remote), label, FALSE, FALSE, 0);
+	gtk_box_pack_start(GTK_BOX(vbox_remote), enable_remote_content, FALSE, FALSE, 0);
+	gtk_widget_show_all(vbox_remote);
+
+	prefs_page->enable_remote_content = enable_remote_content;
+	prefs_page->page.widget = vbox;
+}
+
+static void destroy_lh_prefs_page(PrefsPage *page)
+{
+}
+
+static void save_lh_prefs_page(PrefsPage *page)
+{
+	LHPrefsPage *prefs_page = (LHPrefsPage *)page;
+
+	lh_prefs.enable_remote_content = gtk_toggle_button_get_active(
+			GTK_TOGGLE_BUTTON(prefs_page->enable_remote_content));
+
+	save_prefs();
+}
+
+static void save_prefs(void)
+{
+	PrefFile *pref_file;
+	gchar *rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
+			COMMON_RC, NULL);
+
+	pref_file = prefs_write_open(rcpath);
+
+	if (!pref_file) {
+		g_warning("failed to open configuration file '%s' for writing", rcpath);
+		g_free(rcpath);
+		return;
+	}
+	if (prefs_set_block_label(pref_file, PREFS_BLOCK_NAME) < 0) {
+		g_warning("failed to set block label "PREFS_BLOCK_NAME);
+		g_free(rcpath);
+		return;
+	}
+
+	if (prefs_write_param(param, pref_file->fp) < 0) {
+		g_warning("failed to write LiteHTML Viewer plugin configuration");
+		prefs_file_close_revert(pref_file);
+		g_free(rcpath);
+		return;
+	}
+
+	if (fprintf(pref_file->fp, "\n") < 0) {
+		FILE_OP_ERROR(rcpath, "fprintf");
+		prefs_file_close_revert(pref_file);
+	} else {
+		debug_print("successfully saved LiteHTML Viewer plugin configuration\n");
+		prefs_file_close(pref_file);
+	}
+
+	g_free(rcpath);
+}
diff --git a/src/plugins/litehtml_viewer/lh_prefs.h b/src/plugins/litehtml_viewer/lh_prefs.h
new file mode 100644
index 0000000..25dcbd2
--- /dev/null
+++ b/src/plugins/litehtml_viewer/lh_prefs.h
@@ -0,0 +1,42 @@
+/*
+ * Claws Mail -- A GTK+ based, lightweight, and fast e-mail client
+ * Copyright(C) 2019 the Claws Mail Team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write tothe Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef LH_PREFS_H
+#define LH_PREFS_H
+
+#include <glib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct _LHPrefs LHPrefs;
+
+struct _LHPrefs
+{
+	gboolean enable_remote_content;
+};
+
+LHPrefs *lh_prefs_get(void);
+void lh_prefs_init(void);
+void lh_prefs_done(void);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* LH_PREFS_H */
diff --git a/src/plugins/litehtml_viewer/lh_widget.cpp b/src/plugins/litehtml_viewer/lh_widget.cpp
index 4a8551a..c561e9c 100644
--- a/src/plugins/litehtml_viewer/lh_widget.cpp
+++ b/src/plugins/litehtml_viewer/lh_widget.cpp
@@ -34,6 +34,7 @@
 
 #include "litehtml/litehtml.h"
 
+#include "lh_prefs.h"
 #include "lh_widget.h"
 #include "lh_widget_wrapped.h"
 #include "http.h"
@@ -153,6 +154,11 @@ GdkPixbuf *lh_widget::get_image(const litehtml::tchar_t* url, bool redraw_on_rea
 	GError *error = NULL;
 	GdkPixbuf *pixbuf = NULL;
 
+	if (!lh_prefs_get()->enable_remote_content) {
+		debug_print("blocking download of image from '%s'\n", url);
+		return NULL;
+	}
+
 	debug_print("Loading... %s\n", url);
 	gchar *msg = g_strdup_printf("Loading %s ...", url);
         lh_widget_statusbar_push(msg);
diff --git a/src/plugins/litehtml_viewer/plugin.c b/src/plugins/litehtml_viewer/plugin.c
index 3b0dc93..bfdc48e 100644
--- a/src/plugins/litehtml_viewer/plugin.c
+++ b/src/plugins/litehtml_viewer/plugin.c
@@ -27,11 +27,14 @@
 #include <mimeview.h>
 #include <plugin.h>
 
+#include "lh_prefs.h"
+
 extern MimeViewerFactory lh_viewer_factory;
 
 gint plugin_init(gchar **error)
 {
 	debug_print("LH: plugin_init\n");
+	lh_prefs_init();
 	mimeview_register_viewer_factory(&lh_viewer_factory);
 	return 0;
 }
@@ -40,6 +43,7 @@ gboolean plugin_done(void)
 {
 	debug_print("LH: plugin_done\n");
 	mimeview_unregister_viewer_factory(&lh_viewer_factory);
+	lh_prefs_done();
 	return TRUE;
 }
 

-----------------------------------------------------------------------


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list