diff options
author | Christian Persch <chpe@cvs.gnome.org> | 2005-08-08 05:47:11 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2005-08-08 05:47:11 +0800 |
commit | ec9060610c40fef18534b414d1979f4359f59a5e (patch) | |
tree | 59b34aaff789053cae2ab90bf7eb3331936fd4cc | |
parent | 8a5ef09c4435869dc39736d6c77c7d135f976223 (diff) | |
download | gsoc2013-epiphany-ec9060610c40fef18534b414d1979f4359f59a5e.tar.gz gsoc2013-epiphany-ec9060610c40fef18534b414d1979f4359f59a5e.tar.zst gsoc2013-epiphany-ec9060610c40fef18534b414d1979f4359f59a5e.zip |
Add way to clear the favicon cache. Also removes any extraneous files from
2005-08-07 Christian Persch <chpe@cvs.gnome.org>
* embed/ephy-favicon-cache.c: (icons_removed_cb),
(remove_obsolete_icons), (delete_file),
(ephy_favicon_cache_finalize), (ephy_favicon_cache_get),
(ephy_favicon_cache_clear):
* embed/ephy-favicon-cache.h:
Add way to clear the favicon cache. Also removes any extraneous files
from favicon cache directory. Fix a crash which I wonder why we never
experienced it!
* src/prefs-dialog.c: (prefs_clear_cache_button_clicked_cb):
Also clear favicon cache when clearing the cache.
-rw-r--r-- | ChangeLog | 16 | ||||
-rw-r--r-- | embed/ephy-favicon-cache.c | 74 | ||||
-rw-r--r-- | embed/ephy-favicon-cache.h | 4 | ||||
-rw-r--r-- | src/prefs-dialog.c | 11 |
4 files changed, 93 insertions, 12 deletions
@@ -1,3 +1,19 @@ +2005-08-07 Christian Persch <chpe@cvs.gnome.org> + + * embed/ephy-favicon-cache.c: (icons_removed_cb), + (remove_obsolete_icons), (delete_file), + (ephy_favicon_cache_finalize), (ephy_favicon_cache_get), + (ephy_favicon_cache_clear): + * embed/ephy-favicon-cache.h: + + Add way to clear the favicon cache. Also removes any extraneous files + from favicon cache directory. Fix a crash which I wonder why we never + experienced it! + + * src/prefs-dialog.c: (prefs_clear_cache_button_clicked_cb): + + Also clear favicon cache when clearing the cache. + 2005-08-07 Crispin Flowerday <gnome@flowerday.cx> * embed/mozilla/GtkNSSDialogs.cpp (ConfirmUnknownIssuer): diff --git a/embed/ephy-favicon-cache.c b/embed/ephy-favicon-cache.c index a9ab3b3ff..48535fd04 100644 --- a/embed/ephy-favicon-cache.c +++ b/embed/ephy-favicon-cache.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2002 Jorn Baayen <jorn@nl.linux.org> * Copyright (C) 2003-2004 Marco Pesenti Gritti - * Copyright (C) 2004 Christian Persch + * Copyright (C) 2004, 2005 Christian Persch * * 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 @@ -39,6 +39,7 @@ #include <glib/gstdio.h> #include <libgnomeui/libgnomeui.h> #include <libgnomevfs/gnome-vfs-ops.h> +#include <libgnomevfs/gnome-vfs-directory.h> #define EPHY_FAVICON_CACHE_XML_ROOT (const xmlChar *)"ephy_favicons_cache" #define EPHY_FAVICON_CACHE_XML_VERSION (const xmlChar *)"1.1" @@ -87,6 +88,8 @@ typedef struct guint load_failed : 1; } PixbufCacheEntry; +typedef gboolean (* FilterFunc) (EphyNode*, GDate *); + enum { CHANGED, @@ -216,6 +219,7 @@ icons_added_cb (EphyNode *node, static void icons_removed_cb (EphyNode *node, EphyNode *child, + guint old_index, EphyFaviconCache *eb) { g_hash_table_remove (eb->priv->icons_hash, @@ -223,39 +227,41 @@ icons_removed_cb (EphyNode *node, } static void -remove_obsolete_icons (EphyFaviconCache *eb) +remove_obsolete_icons (EphyFaviconCache *cache, + FilterFunc filter) { + EphyFaviconCachePrivate *priv = cache->priv; GPtrArray *children; int i; - GTime now; GDate current_date; - now = time (NULL); g_date_clear (¤t_date, 1); g_date_set_time (¤t_date, time (NULL)); - children = ephy_node_get_children (eb->priv->icons); - for (i = 0; i < children->len; i++) + children = ephy_node_get_children (priv->icons); + for (i = (int) children->len - 1; i >= 0; i--) { EphyNode *kid; kid = g_ptr_array_index (children, i); - if (icon_is_obsolete (kid, ¤t_date)) + if (!filter || filter (kid, ¤t_date)) { const char *filename; char *path; filename = ephy_node_get_property_string (kid, EPHY_NODE_FAVICON_PROP_FILENAME); - path = g_build_filename (eb->priv->directory, + path = g_build_filename (priv->directory, filename, NULL); + g_print ("Removing kid %d, deleting %s\n", i, path); gnome_vfs_unlink (path); g_free (path); ephy_node_unref (kid); } } + g_print ("Now %d children\n", children->len); } static void @@ -412,6 +418,31 @@ kill_download (const char *key, return TRUE; } +static gboolean +delete_file (const char *rel_path, + GnomeVFSFileInfo *info, + gboolean rec_will_loop, + EphyFaviconCache *cache, + gboolean *recurse) +{ + EphyFaviconCachePrivate *priv = cache->priv; + char *path; + + *recurse = FALSE; + + g_return_val_if_fail (info != NULL, TRUE); + + if ((info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_TYPE) == 0 || + info->type != GNOME_VFS_FILE_TYPE_REGULAR) return TRUE; + + path = g_build_filename (priv->directory, rel_path, NULL); + gnome_vfs_unlink (path); + g_free (path); + + /* continue with the visit */ + return TRUE; +} + static void ephy_favicon_cache_finalize (GObject *object) { @@ -433,7 +464,7 @@ ephy_favicon_cache_finalize (GObject *object) g_source_remove (priv->cleanup_timeout); } - remove_obsolete_icons (cache); + remove_obsolete_icons (cache, icon_is_obsolete); ephy_favicon_cache_save (cache); @@ -795,3 +826,28 @@ ephy_favicon_cache_get (EphyFaviconCache *cache, return pixbuf; } + +/** + * ephy_favicons_cache_clear: + * @cache: + * + * Clears the favicon cache and removes any stored icon files from disk. + */ +void +ephy_favicon_cache_clear (EphyFaviconCache *cache) +{ + EphyFaviconCachePrivate *priv = cache->priv; + + g_return_if_fail (EPHY_IS_FAVICON_CACHE (cache)); + + remove_obsolete_icons (cache, NULL); + ephy_favicon_cache_save (cache); + + /* Now remove any remaining files from the cache directory */ + gnome_vfs_directory_visit (priv->directory, + GNOME_VFS_FILE_INFO_DEFAULT, + GNOME_VFS_DIRECTORY_VISIT_SAMEFS | + GNOME_VFS_DIRECTORY_VISIT_LOOPCHECK, + (GnomeVFSDirectoryVisitFunc) delete_file, + cache); +} diff --git a/embed/ephy-favicon-cache.h b/embed/ephy-favicon-cache.h index a2d211821..f2161e6f9 100644 --- a/embed/ephy-favicon-cache.h +++ b/embed/ephy-favicon-cache.h @@ -1,7 +1,7 @@ /* * Copyright (C) 2002 Jorn Baayen * Copyright (C) 2003-2004 Marco Pesenti Gritti - * Copyright (C) 2004 Christian Persch + * Copyright (C) 2004, 2005 Christian Persch * * 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 @@ -63,6 +63,8 @@ EphyFaviconCache *ephy_favicon_cache_new (void); GdkPixbuf *ephy_favicon_cache_get (EphyFaviconCache *cache, const char *url); +void ephy_favicon_cache_clear (EphyFaviconCache *cache); + G_END_DECLS #endif /* EPHY_FAVICON_CACHE_H */ diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c index 42b71f257..c8e7187b0 100644 --- a/src/prefs-dialog.c +++ b/src/prefs-dialog.c @@ -25,7 +25,7 @@ #include "ephy-dialog.h" #include "ephy-prefs.h" #include "ephy-embed-shell.h" -#include "ephy-shell.h" +#include "ephy-favicon-cache.h" #include "ephy-session.h" #include "ephy-embed-prefs.h" #include "ephy-embed-single.h" @@ -1272,10 +1272,17 @@ void prefs_clear_cache_button_clicked_cb (GtkWidget *button, gpointer data) { + EphyEmbedShell *shell; EphyEmbedSingle *single; + EphyFaviconCache *cache; - single = EPHY_EMBED_SINGLE (ephy_embed_shell_get_embed_single (embed_shell)); + shell = ephy_embed_shell_get_default (); + + single = EPHY_EMBED_SINGLE (ephy_embed_shell_get_embed_single (shell)); ephy_embed_single_clear_cache (single); + + cache = EPHY_FAVICON_CACHE (ephy_embed_shell_get_favicon_cache (shell)); + ephy_favicon_cache_clear (cache); } static void |