From cf9dec176c06e45da676071dcaedb6f972b34109 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Sat, 2 Jan 2010 21:34:17 +0100 Subject: [PATCH] Refactor adblock_reload_rules to handle filters versus only custom --- extensions/adblock.c | 83 +++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/extensions/adblock.c b/extensions/adblock.c index 81fe401f..200dfbc4 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* folder; - 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); + gchar* folder; + gchar** filters; + guint i = 0; 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;