generalsettingsview: add an option to disable images loading in the chatview
Displaying images in the chatview can lead to unwanted requests, the
user must be able to disable this functionnality.
Change-Id: I522b22fc603ff6adb36bcb7a560fa8d7a1b9bdb7
Reviewed-by: Philippe Gorley <philippe.gorley@savoirfairelinux.com>
diff --git a/src/chatview.cpp b/src/chatview.cpp
index 3785a26..6b528fe 100644
--- a/src/chatview.cpp
+++ b/src/chatview.cpp
@@ -34,6 +34,7 @@
#include "numbercategory.h"
#include <QtCore/QDateTime>
#include "utils/calling.h"
+#include "utils/files.h"
#include "webkitchatcontainer.h"
// LRC
@@ -67,6 +68,8 @@
GtkWidget *button_placecall;
GtkWidget *button_send_invitation;
+ GSettings *settings;
+
/* only one of the three following pointers should be non void;
* either this is an in-call chat (and so the in-call chat APIs will be used)
* or it is an out of call chat (and so the account chat APIs will be used) */
@@ -158,6 +161,18 @@
}
static void
+display_links_toggled(ChatView *self)
+{
+ auto priv = CHAT_VIEW_GET_PRIVATE(self);
+ if (priv->webkit_chat_container) {
+ webkit_chat_container_set_display_links(
+ WEBKIT_CHAT_CONTAINER(priv->webkit_chat_container),
+ g_settings_get_boolean(priv->settings, "enable-display-links")
+ );
+ }
+}
+
+static void
placecall_clicked(ChatView *self)
{
auto priv = CHAT_VIEW_GET_PRIVATE(self);
@@ -249,6 +264,7 @@
gtk_widget_init_template(GTK_WIDGET(view));
ChatViewPrivate *priv = CHAT_VIEW_GET_PRIVATE(view);
+ priv->settings = g_settings_new_full(get_ring_schema(), NULL, NULL);
g_signal_connect(priv->button_close_chatview, "clicked", G_CALLBACK(hide_chat_view), view);
g_signal_connect_swapped(priv->button_placecall, "clicked", G_CALLBACK(placecall_clicked), view);
@@ -597,6 +613,8 @@
WEBKIT_CHAT_CONTAINER(priv->webkit_chat_container)
);
+ display_links_toggled(self);
+
/* print the text recordings */
if (priv->call) {
print_text_recording(priv->call->peerContactMethod()->textRecording(), self);
diff --git a/src/generalsettingsview.cpp b/src/generalsettingsview.cpp
index 4eea6f2..fbf9a8e 100644
--- a/src/generalsettingsview.cpp
+++ b/src/generalsettingsview.cpp
@@ -56,6 +56,7 @@
GtkWidget *checkbutton_bringtofront;
GtkWidget *checkbutton_callnotifications;
GtkWidget *checkbutton_chatnotifications;
+ GtkWidget *checkbutton_chatdisplaylinks;
GtkWidget *checkbutton_searchentryplacescall;
GtkWidget *radiobutton_chatright;
GtkWidget *radiobutton_chatbottom;
@@ -157,6 +158,9 @@
g_settings_bind(priv->settings, "enable-call-notifications",
priv->checkbutton_callnotifications, "active",
G_SETTINGS_BIND_DEFAULT);
+ g_settings_bind(priv->settings, "enable-display-links",
+ priv->checkbutton_chatdisplaylinks, "active",
+ G_SETTINGS_BIND_DEFAULT);
g_settings_bind(priv->settings, "enable-chat-notifications",
priv->checkbutton_chatnotifications, "active",
G_SETTINGS_BIND_DEFAULT);
@@ -192,6 +196,7 @@
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, checkbutton_showstatusicon);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, checkbutton_bringtofront);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, checkbutton_callnotifications);
+ gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, checkbutton_chatdisplaylinks);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, checkbutton_chatnotifications);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, checkbutton_searchentryplacescall);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, radiobutton_chatright);
diff --git a/src/webkitchatcontainer.cpp b/src/webkitchatcontainer.cpp
index 2b6062a..1663729 100644
--- a/src/webkitchatcontainer.cpp
+++ b/src/webkitchatcontainer.cpp
@@ -486,6 +486,22 @@
}
void
+webkit_chat_container_set_display_links(WebKitChatContainer *view, bool display)
+{
+ WebKitChatContainerPrivate *priv = WEBKIT_CHAT_CONTAINER_GET_PRIVATE(view);
+ gchar* function_call = g_strdup_printf("ring.chatview.setDisplayLinks(%s);",
+ display ? "true" : "false");
+
+ webkit_web_view_run_javascript(
+ WEBKIT_WEB_VIEW(priv->webview_chat),
+ function_call,
+ NULL,
+ NULL,
+ NULL
+ );
+}
+
+void
webkit_chat_container_clear_sender_images(WebKitChatContainer *view)
{
WebKitChatContainerPrivate *priv = WEBKIT_CHAT_CONTAINER_GET_PRIVATE(view);
diff --git a/src/webkitchatcontainer.h b/src/webkitchatcontainer.h
index 76766c6..3a36ba3 100644
--- a/src/webkitchatcontainer.h
+++ b/src/webkitchatcontainer.h
@@ -45,5 +45,6 @@
void webkit_chat_container_update_message (WebKitChatContainer *view, const QModelIndex &idx);
void webkit_chat_container_set_sender_image (WebKitChatContainer *view, ContactMethod *sender_contact_method, QVariant sender_image);
gboolean webkit_chat_container_is_ready (WebKitChatContainer *view);
+void webkit_chat_container_set_display_links (WebKitChatContainer *view, bool display);
G_END_DECLS