2 // Favicons.cs: Finds Epiphany favicons.
5 // Jonas Heylen <jonas.heylen@pandora.be>
7 // Butched by Jon Trowbridge <trow@ximian.com>
14 using System
.Collections
;
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)
38 string path
= GetPath ("ephy-favicon-cache.xml");
40 if (! File
.Exists (path
))
43 DateTime lastWrite
= File
.GetLastWriteTime (path
);
44 if (timestamp
>= lastWrite
)
47 timestamp
= lastWrite
;
49 favicondoc
= new XmlDocument ();
50 favicondoc
.Load (path
);
58 static public string GetIconPath (string url
)
62 if (favicondoc
== null)
65 int index
= url
.IndexOf ("/", 7);
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
);