[Xfce4-commits] <midori:master> Refactor adblock_reload_rules to handle filters versus only custom

Christian Dywan noreply at xfce.org
Sat Jan 2 21:40:02 CET 2010


Updating branch refs/heads/master
         to cf9dec176c06e45da676071dcaedb6f972b34109 (commit)
       from b0de3f35df3a74ecd136b1f9d1b56985e1fd1d95 (commit)

commit cf9dec176c06e45da676071dcaedb6f972b34109
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sat Jan 2 21:34:17 2010 +0100

    Refactor adblock_reload_rules to handle filters versus only custom

 extensions/adblock.c |   81 ++++++++++++++++++++++++++------------------------
 1 files changed, 42 insertions(+), 39 deletions(-)

diff --git a/extensions/adblock.c b/extensions/adblock.c
index 81fe401..200dfbc 100644
--- a/extensions/adblock.c
+++ b/extensions/adblock.c
@@ -96,53 +96,56 @@ adblock_download_notify_status_cb (WebKitDownload* download,
 }
 
 static void
-adblock_reload_rules (MidoriExtension* extension)
+adblock_reload_rules (MidoriExtension* extension,
+                      gboolean         custom_only)
 {
-    gchar** filters;
+    gchar* custom_list;
     gchar* folder;
+    gchar** filters;
     guint i = 0;
-    filters = midori_extension_get_string_list (extension, "filters", NULL);
-    gchar* custom_list;
-
-    if (!filters)
-        return;
-
-    folder = g_build_filename (g_get_user_cache_dir (), PACKAGE_NAME,
-                               "adblock", NULL);
-    katze_mkdir_with_parents (folder, 0700);
 
     adblock_init_db ();
 
-    while (filters[i++] != NULL)
-    {
-        gchar* filename = g_compute_checksum_for_string (G_CHECKSUM_MD5,
-                                                         filters[i - 1], -1);
-        gchar* path = g_build_filename (folder, filename, NULL);
-        if (!adblock_parse_file (path))
-        {
-            WebKitNetworkRequest* request;
-            WebKitDownload* download;
-            gchar* destination = g_filename_to_uri (path, NULL, NULL);
-            request = webkit_network_request_new (filters[i -1]);
-            download = webkit_download_new (request);
-            g_object_unref (request);
-            webkit_download_set_destination_uri (download, destination);
-            g_free (destination);
-            g_signal_connect (download, "notify::status",
-                G_CALLBACK (adblock_download_notify_status_cb), path);
-            webkit_download_start (download);
-        }
-        else
-            g_free (path);
-        g_free (filename);
-    }
     custom_list = g_build_filename (midori_extension_get_config_dir (extension),
                                     CUSTOM_LIST_NAME, NULL);
     adblock_parse_file (custom_list);
     g_free (custom_list);
-    katze_assign (blockscript, adblock_build_js (blockcss, blockcssprivate));
+
+    filters = midori_extension_get_string_list (extension, "filters", NULL);
+    if (!custom_only && filters && *filters)
+    {
+        folder = g_build_filename (g_get_user_cache_dir (), PACKAGE_NAME,
+                                   "adblock", NULL);
+        katze_mkdir_with_parents (folder, 0700);
+        while (filters[i++] != NULL)
+        {
+            gchar* filename = g_compute_checksum_for_string (G_CHECKSUM_MD5,
+                                                             filters[i - 1], -1);
+            gchar* path = g_build_filename (folder, filename, NULL);
+            if (!adblock_parse_file (path))
+            {
+                WebKitNetworkRequest* request;
+                WebKitDownload* download;
+                gchar* destination = g_filename_to_uri (path, NULL, NULL);
+
+                request = webkit_network_request_new (filters[i -1]);
+                download = webkit_download_new (request);
+                g_object_unref (request);
+                webkit_download_set_destination_uri (download, destination);
+                g_free (destination);
+                g_signal_connect (download, "notify::status",
+                    G_CALLBACK (adblock_download_notify_status_cb), path);
+                webkit_download_start (download);
+            }
+            else
+                g_free (path);
+            g_free (filename);
+        }
+        g_free (folder);
+    }
     g_strfreev (filters);
-    g_free (folder);
+
+    katze_assign (blockscript, adblock_build_js (blockcss, blockcssprivate));
 }
 
 static void
@@ -254,7 +257,7 @@ adblock_preferences_model_row_changed_cb (GtkTreeModel*    model,
     midori_extension_set_string_list (extension, "filters", filters, i);
     g_free (filters);
     if (need_reload)
-        adblock_reload_rules (extension);
+        adblock_reload_rules (extension, FALSE);
 }
 
 static void
@@ -730,7 +733,7 @@ adblock_custom_block_image_cb (GtkWidget*       widget,
     g_fprintf (list, "%s\n", uri);
     g_fprintf (list, "%s##img[src*=\"%s\"]\n", s_req_domain->host, s_uri->path);
     fclose (list);
-    adblock_reload_rules (extension);
+    adblock_reload_rules (extension, TRUE);
 
     soup_uri_free (s_req_domain);
     soup_uri_free (s_uri);
@@ -1159,7 +1162,7 @@ adblock_activate_cb (MidoriExtension* extension,
                       G_CALLBACK (adblock_session_request_queued_cb), NULL);
     #endif
 
-    adblock_reload_rules (extension);
+    adblock_reload_rules (extension, FALSE);
 
     browsers = katze_object_get_object (app, "browsers");
     i = 0;



More information about the Xfce4-commits mailing list