]> git.armaanb.net Git - chorizo.git/commitdiff
Add toggle images option
authorArmaan Bhojwani <me@armaanb.net>
Wed, 9 Jun 2021 18:06:48 +0000 (14:06 -0400)
committerArmaan Bhojwani <me@armaanb.net>
Thu, 10 Jun 2021 01:27:33 +0000 (21:27 -0400)
man/chorizo-config.5.scd
src/browser.c

index f658d9c8311ff1c5f27d5d6bd1c9cf0e54c6f8f2..11ad7858ca4dc5928d91e7a24e1955348cfc1102 100644 (file)
@@ -183,6 +183,11 @@ All of these keybindings are bound to Control + key.
        Default: o++
        Toggle JavaScript.
 
+*toggle_img*++
+       Type: string++
+       Default: NULL++
+       Toggle image loading.
+
 *web_search*++
        Type: string++
        Default: d++
index bc4181f65ed29552afdd9a7bbc39304768bd2ee1..4542eb7c3a9f2e1290b73924bc2da564154b0584 100644 (file)
@@ -38,9 +38,8 @@ GKeyFile *get_ini(void);
 GKeyFile *config;
 
 struct Client {
-    gchar *external_handler_uri;
-    gchar *feed_html;
-    gchar *hover_uri;
+    GtkWidget *imgbutton;
+    GtkWidget *jsbutton;
     GtkWidget *location;
     GtkWidget *tabicon;
     GtkWidget *tablabel;
@@ -48,6 +47,9 @@ struct Client {
     GtkWidget *web_view;
     WebKitSettings *settings;
     gboolean focus_new_tab;
+    gchar *external_handler_uri;
+    gchar *feed_html;
+    gchar *hover_uri;
 };
 
 struct Configuration {
@@ -56,6 +58,7 @@ struct Configuration {
     gboolean cooperative_alone;
     gboolean cooperative_instances;
     gboolean enable_console_to_stdout;
+    gboolean images_disabled;
     gboolean javascript_disabled;
     gboolean private;
     gboolean spellcheck_disabled;
@@ -88,6 +91,14 @@ togglejs(GtkButton *jsbutton, gpointer data) {
     webkit_web_view_set_settings(WEBKIT_WEB_VIEW(c->web_view), c->settings);
 }
 
+void
+toggleimg(GtkButton *imgbutton, gpointer data) {
+    struct Client *c = (struct Client *)data;
+    webkit_settings_set_auto_load_images(
+        c->settings, !webkit_settings_get_auto_load_images(c->settings));
+    webkit_web_view_set_settings(WEBKIT_WEB_VIEW(c->web_view), c->settings);
+}
+
 void
 client_destroy(GtkWidget *widget, gpointer data) {
     struct Client *c = (struct Client *)data;
@@ -142,6 +153,7 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show,
                                    cfg.global_zoom);
     webkit_settings_set_enable_javascript(c->settings,
                                           !cfg.javascript_disabled);
+    webkit_settings_set_auto_load_images(c->settings, !cfg.images_disabled);
     g_signal_connect(G_OBJECT(c->web_view), "notify::favicon",
                      G_CALLBACK(changed_favicon), c);
     g_signal_connect(G_OBJECT(c->web_view), "notify::title",
@@ -187,12 +199,13 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show,
     c->imgbutton = gtk_toggle_button_new_with_label("IMG");
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(c->imgbutton),
                                  !cfg.images_disabled);
-    g_signal_connect(G_OBJECT(c->imgbutton), "toggled",
-                     G_CALLBACK(toggleimg_cb), c);
+    g_signal_connect(G_OBJECT(c->imgbutton), "toggled", G_CALLBACK(toggleimg),
+                     c);
 
     c->location = gtk_entry_new();
     gtk_box_pack_start(GTK_BOX(locbox), c->location, TRUE, TRUE, 5);
     gtk_box_pack_end(GTK_BOX(locbox), c->jsbutton, FALSE, FALSE, 0);
+    gtk_box_pack_end(GTK_BOX(locbox), c->imgbutton, FALSE, FALSE, 0);
 
     if (cfg.private) {
         GtkWidget *privindicator = gtk_label_new("Private mode");
@@ -516,6 +529,8 @@ get_config(void) {
         g_key_file_get_string(config, "browser", "user_agent", NULL);
     cfg.javascript_disabled =
         g_key_file_get_boolean(config, "browser", "javascript_disabled", NULL);
+    cfg.images_disabled =
+        g_key_file_get_boolean(config, "browser", "images_disabled", NULL);
     char *input_cookie_policy =
         g_key_file_get_string(config, "browser", "cookie_policy", NULL);
     cfg.cookie_policy = WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY;
@@ -886,6 +901,13 @@ key_common(GtkWidget *widget, GdkEvent *event, gpointer data) {
                                              c->settings);
                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(c->jsbutton),
                                              !on);
+            } else if (def_key("toggle_img", -1) == key) {
+                gboolean on = webkit_settings_get_auto_load_images(c->settings);
+                webkit_settings_set_auto_load_images(c->settings, !on);
+                webkit_web_view_set_settings(WEBKIT_WEB_VIEW(c->web_view),
+                                             c->settings);
+                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(c->imgbutton),
+                                             !on);
             } else if (def_key("web_search", GDK_KEY_d) == key) {
                 gtk_widget_grab_focus(c->location);
                 gtk_entry_set_text(GTK_ENTRY(c->location), "w/");