* Filters/FilterPackage.cs, Filters/FilterRPM.cs,
[beagle.git] / Renderers / Favicons.cs
blob1641f86397d538d9fac372302b424f315bf008e0
1 //
2 // Favicons.cs: Finds Epiphany favicons.
3 //
4 // Original Author:
5 // Jonas Heylen <jonas.heylen@pandora.be>
6 //
7 // Butched by Jon Trowbridge <trow@ximian.com>
8 //
11 using System;
12 using System.IO;
13 using System.Xml;
14 using System.Collections;
16 namespace Beagle {
18 public class Favicons {
20 static XmlDocument favicondoc;
22 static DateTime lastRefresh;
23 static DateTime timestamp;
25 static private string GetPath (string fileName)
27 string home_dir = Environment.GetEnvironmentVariable ("HOME");
28 string ephy_dir = Path.Combine (home_dir, ".gnome2/epiphany");
29 return Path.Combine (ephy_dir, fileName);
32 static private bool Refresh ()
34 if ((DateTime.Now - lastRefresh).TotalMinutes < 10)
35 return true;
37 try {
38 string path = GetPath ("ephy-favicon-cache.xml");
40 if (! File.Exists (path))
41 return false;
43 DateTime lastWrite = File.GetLastWriteTime (path);
44 if (timestamp >= lastWrite)
45 return true;
47 timestamp = lastWrite;
49 favicondoc = new XmlDocument ();
50 favicondoc.Load (path);
52 return true;
53 } catch {
54 return false;
58 static public string GetIconPath (string url)
60 Refresh ();
62 if (favicondoc == null)
63 return null;
65 int index = url.IndexOf ("/", 7);
66 if (index > -1)
67 url = url.Substring (0, index);
69 string xpath = "descendant::node[starts-with(child::property[1]/child::text(), '" + url + "')]";
70 XmlNode fav_node = favicondoc.SelectSingleNode (xpath);
72 if (fav_node != null) {
73 xpath = "child::property[position()=2]";
74 XmlNode favicon = fav_node.SelectSingleNode (xpath);
75 string path = GetPath ("favicon_cache");
76 return Path.Combine (path, favicon.InnerText);
79 return null;