WebLink and compositing images



Hi Guys,

Here's a patch against CVS which adds compositing of favicon against
the glovbe icon back into the renderer.

There has been one report of it generating an X error, but that bug
hasn't been reproduced.

Kevin had problems with the patch against
EpiphanyBookmarksBackend.cs so I'll attach it raw as well in case
you have problems.

Cheers!

-- 
Andrew Ruthven
Senior Systems Engineer, Actrix Networks Ltd   -->   www.actrix.gen.nz
At Actrix puck actrix gen nz
At Home:  andrew etc gen nz

Index: dashboard/backends/EpiphanyBookmarksBackend.cs
===================================================================
RCS file: /cvs/gnome/dashboard/backends/EpiphanyBookmarksBackend.cs,v
retrieving revision 1.14
diff -u -r1.14 EpiphanyBookmarksBackend.cs
--- dashboard/backends/EpiphanyBookmarksBackend.cs	19 Feb 2004 03:01:55 -0000	1.14
+++ dashboard/backends/EpiphanyBookmarksBackend.cs	19 Feb 2004 22:46:33 -0000
@@ -7,12 +7,10 @@
 //
 
 
-using Gdk;
 using System;
 using System.IO;
 using System.Xml;
 using System.Collections;
-using System.Reflection;
 
 namespace Dashboard {
 
@@ -25,9 +23,7 @@
 		
 		public override bool Startup ()
 		{
-			this.Name = "Epiphany bookmarks";
-			this.Category = "Bookmarks";
-			this.IconPath = "internal:bookmark.png";
+			Name = "Epiphany bookmarks";
 
 			string home_dir = Environment.GetEnvironmentVariable ("HOME");
 			string path;
@@ -35,7 +31,7 @@
 			try {
 				path = Path.Combine (home_dir, ".gnome2/epiphany/bookmarks.rdf");
 
-				if (!File.Exists (path))
+				if (! File.Exists (path))
 					return false;
 
 				doc = new XmlDocument ();
@@ -46,8 +42,8 @@
 
 				items = doc.SelectNodes ("//rss:item", nsm);
 
-                                path = Path.Combine (home_dir, ".gnome2/epiphany/ephy-favicon-cache.xml");
-                                if (File.Exists (path)) {
+        path = Path.Combine (home_dir, ".gnome2/epiphany/ephy-favicon-cache.xml");
+        if (File.Exists (path)) {
 					favicondoc = new XmlDocument ();
 					favicondoc.Load (path);
 				}
@@ -94,13 +90,13 @@
 				string iconuri = this.GetIconPath (uri);
 
 				// Construct match set
-				Match match = new Match(this.Category);
-				match.AddItem(new MatchItem("Icon", iconuri, "image", "plain", uri));
-				match.AddItem(new MatchItem("Title", title, "text", "plain", uri));
-				matches.Add(match);
+				Match match = new Match ("WebLink", clue);
+				match ["emblem-icon"] = iconuri;
+				match ["title"] = title;
+				match ["url"]   = uri;
 
+				matches.Add(match);
 				match_count++;
-
 			}
 
 			if (match_count == 0) {
@@ -110,18 +106,10 @@
 			}
 		}
 
-		private Stream GetImage (string name)
-                {
-                        Assembly assembly = System.Reflection.Assembly.GetEntryAssembly ();
-                        System.IO.Stream s = assembly.GetManifestResourceStream (name);
-
-                        return s;
-                }
-
 		private string GetIconPath (string url)
 		{
 			if (favicondoc == null)
-			        return "internal:bookmark.png";
+					return null;
 
 			int index = url.IndexOf ("/", 7);
 			if (index > -1)
@@ -135,53 +123,12 @@
 				XmlNode favicon = fav_node.SelectSingleNode (xpath);
 				string home_dir = Environment.GetEnvironmentVariable ("HOME");
 				string path = Path.Combine (home_dir, ".gnome2/epiphany/favicon_cache");
-				string iconfile = Path.Combine (path, favicon.InnerText);
-
-				// Fixes bug #128935
-				if (! File.Exists (iconfile)) {
-					iconfile = "internal:bookmark.png";
-					return iconfile;
-				}
-
-				Gdk.Pixbuf icon = new Pixbuf (iconfile);
-				Gdk.Pixbuf bookmark =
-					new Pixbuf (GetImage ("bookmark.png"));
-				Gdk.Pixbuf white =
-					new Pixbuf (GetImage ("white.png"));
-
-      				white.Composite (bookmark,
-		     			0, 0, //dest x,y
-		     			48, 20, //height,width
-		     			0, 0, //offset x,y
-		     			1, 1, // scaling x,y
-		     			Gdk.InterpType.Bilinear,
-		     			127); //Alpha
-
-				// I just want to make the icon be 16x16.
-				// This does it for me!
-      				Gdk.Pixbuf small_icon = icon.ScaleSimple (
-					16, 16, //dest x,y
-					Gdk.InterpType.Bilinear);
-
-				small_icon.Composite(bookmark,
-		     			0, 0, //dest x,y
-					 48, 18, //height,width
-					 31, 2, //offset x,y
-		     			1, 1, // scaling x,y
-		     			Gdk.InterpType.Bilinear,
-		     			255); //Alpha
-
-				iconfile = Path.GetFileName (iconfile);
-				string home = Environment.GetEnvironmentVariable ("HOME");
-				iconfile = Path.Combine( Path.Combine (home,
-				String.Format (".dashboard/tmp/")),
-				iconfile.ToString());
-
-				bookmark.Savev (iconfile, "png", null, null);
-				return iconfile;
+				return Path.Combine (path, favicon.InnerText);
 			}
 
-			return "internal:bookmark.png";
+			return null;
 		}
 	}
 }
+
+
Index: dashboard/backends/EpiphanyHistoryBackend.cs
===================================================================
RCS file: /cvs/gnome/dashboard/backends/EpiphanyHistoryBackend.cs,v
retrieving revision 1.14
diff -u -r1.14 EpiphanyHistoryBackend.cs
--- dashboard/backends/EpiphanyHistoryBackend.cs	16 Feb 2004 07:57:30 -0000	1.14
+++ dashboard/backends/EpiphanyHistoryBackend.cs	19 Feb 2004 22:46:33 -0000
@@ -12,8 +12,6 @@
 using System.IO;
 using System.Xml;
 using System.Collections;
-using System.Reflection;
-using Gdk;
 
 namespace Dashboard {
 
@@ -90,15 +88,13 @@
 					iconurl = GetIconPath (url);
 					
 					Match match = new Match ("WebLink", clue);
-					match ["icon"] = iconurl;
+					match ["emblem-icon"] = iconurl;
 					match ["title"] = title;
 					match ["url"] = url;
 
 					matches.Add(match);
 					match_count ++;
 				}
-
-
 			}
 
 			if (match_count == 0)
@@ -106,21 +102,11 @@
 
 			return matches;
 		}
-// Below was grabbed from backend-ephybookmarks.cs and modified a bit by 
-// <thsutton utas edu au>
-		private Stream GetImage (string name)
-		{
-			Assembly assembly = System.Reflection.Assembly.GetEntryAssembly ();
-			//Console.WriteLine ("ASSEMBLY NAMED " + assembly.FullName);
-			System.IO.Stream s = assembly.GetManifestResourceStream (name);
-			
-			return s;
-		}
 
 		private string GetIconPath (string url)
 		{
 			if (favicondoc == null)
-			        return "internal:bookmark.png";
+					return null;
 
 			int index = url.IndexOf ("/", 7);
 			//Console.WriteLine (String.Format ("url is {0}; index is {1}", url, index));
@@ -137,60 +123,10 @@
 				XmlNode favicon = fav_node.SelectSingleNode (xpath);
 				string home_dir = Environment.GetEnvironmentVariable ("HOME");
 				string path = Path.Combine (home_dir, ".gnome2/epiphany/favicon_cache");
-				string iconfile = Path.Combine (path, favicon.InnerText);
-
-				// Fixes bug #128935
-				if (! File.Exists (iconfile)) {
-					iconfile = "internal:bookmark.png";
-				} 
-				// FIXME: Need to look at Gdk.Pixbuf to make scaling nicer.
-				//      This will do till then...
-				return iconfile;
-
-				// Composite an icon...
-//				Gdk.Pixbuf icon = new Pixbuf (iconfile);
-//				Gdk.Pixbuf bookmark =
-//					new Pixbuf (GetImage ("bookmark.png"));
-//				Gdk.Pixbuf white =
-//					new Pixbuf (GetImage ("white.png"));
-//
-//				white = white.ScaleSimple (
-//					72, 30, //dest x,y
-//					Gdk.InterpType.Bilinear);
-//					
-//				white.Composite (bookmark,
-//					 0,  0, // dest x,y
-//					72, 30, // width, height
-//					20,  0, // offset x,y
-//					 1,  1, // scaling x,y
-//					Gdk.InterpType.Bilinear,
-//					127); //Alpha
-//
-//				// I just want to make the icon be 16x16.
-//				// This does it for me!
-//				Gdk.Pixbuf small_icon = icon.ScaleSimple (
-//					28, 28, //dest x,y
-//					Gdk.InterpType.Bilinear);
-//
-//				small_icon.Composite(bookmark,
-//					 0,  0, // dest x,y
-//					28, 28, // width, height
-//					 0,  0, // offset x,y
-//					 1,  1, // scaling x,y
-//					Gdk.InterpType.Bilinear,
-//					255);   //Alpha
-//
-//				iconfile = Path.GetFileName (iconfile);
-//				string home = Environment.GetEnvironmentVariable ("HOME");
-//				iconfile = Path.Combine( Path.Combine (home,
-//				String.Format (".dashboard/tmp/")),
-//				"ephyhist-"+iconfile.ToString());
-//
-//				bookmark.Savev (iconfile, "png", null, null);
-//				return iconfile;
+				return Path.Combine (path, favicon.InnerText);
 			}
 
-			return "internal:bookmark.png";
+			return null;
 		}
 	} // Class
 } // Namespace
Index: dashboard/backends/Makefile.am
===================================================================
RCS file: /cvs/gnome/dashboard/backends/Makefile.am,v
retrieving revision 1.64
diff -u -r1.64 Makefile.am
--- dashboard/backends/Makefile.am	17 Feb 2004 00:32:06 -0000	1.64
+++ dashboard/backends/Makefile.am	19 Feb 2004 22:46:33 -0000
@@ -7,6 +7,7 @@
 # The backends to build by default.
 backends =                              \
 	BugzillaBackend.dll		\
+	EpiphanyBookmarksBackend.dll	\
 	EpiphanyHistoryBackend.dll	\
 	EvolutionMailBackend.dll	\
 	GaimLogBackend.dll		\
Index: dashboard/renderers/Makefile.am
===================================================================
RCS file: /cvs/gnome/dashboard/renderers/Makefile.am,v
retrieving revision 1.3
diff -u -r1.3 Makefile.am
--- dashboard/renderers/Makefile.am	19 Feb 2004 04:30:24 -0000	1.3
+++ dashboard/renderers/Makefile.am	19 Feb 2004 22:46:33 -0000
@@ -1,6 +1,6 @@
 CSC=mcs -g -warnaserror
 dashboard_exe=../engine/dashboard.exe
-DLLDEPS= -r:$(dashboard_exe)
+DLLDEPS= -r:$(dashboard_exe) -r:gdk-sharp.dll
 LIBFLAGS=-target:library $(DLLDEPS)
 EXEFLAGS=$(DLLDEPS)
 
Index: dashboard/renderers/WebLinkMatchRenderer.cs
===================================================================
RCS file: /cvs/gnome/dashboard/renderers/WebLinkMatchRenderer.cs,v
retrieving revision 1.6
diff -u -r1.6 WebLinkMatchRenderer.cs
--- dashboard/renderers/WebLinkMatchRenderer.cs	16 Feb 2004 09:36:56 -0000	1.6
+++ dashboard/renderers/WebLinkMatchRenderer.cs	19 Feb 2004 22:46:33 -0000
@@ -7,8 +7,11 @@
 //   Nat Friedman <nat nat org>
 //
 
+using Gdk;
 using System;
+using System.IO;
 using System.Collections;
+using System.Reflection;
 
 namespace Dashboard {
 
@@ -36,6 +39,16 @@
 		private string HTMLRenderSingleWebLink (Match m)
 		{
 			string html;
+			string icon;
+
+			// Allow the caller to overwide the compositing of the icon by setting
+			// icon.
+			if (m ["icon"] != null) {
+				icon = m ["icon"].ToString();
+			} else {
+				icon = CompositeEmblemIcon ((string)m ["emblem-icon"]);
+			}
+									
 
 			html = String.Format
 				("<tr>" +
@@ -50,10 +63,66 @@
 				 "</tr>",
 
 				 m ["url"],
-				 m ["icon"],
+				 icon,
 				 m ["title"]);
 
 			return html;
 		}
+
+		private Stream GetImage (string name)
+    {
+      Assembly assembly = System.Reflection.Assembly.GetEntryAssembly ();
+      System.IO.Stream s = assembly.GetManifestResourceStream (name);
+      return s;
+    }
+
+		private string CompositeEmblemIcon (String emblem) 
+		{
+			if (emblem == null)
+				return "internal:bookmark.png";
+			
+			if (! File.Exists (emblem)) {
+				return "internal:bookmark.png";
+  		} 
+
+			// Composite an icon...
+			Gdk.Pixbuf icon = new Pixbuf (emblem);
+			Gdk.Pixbuf bookmark =
+				new Pixbuf (GetImage ("bookmark.png"));
+			Gdk.Pixbuf white =
+				new Pixbuf (GetImage ("white.png"));
+
+      white.Composite (bookmark,
+        0,   0,   // dest x,y
+        48, 20,   // height,width
+        0,   0,   // offset x,y
+        1,   1,   // scaling x,y
+        Gdk.InterpType.Bilinear,
+        127);     // Alpha
+
+			// I just want to make the icon be 16x16.
+			// This does it for me!
+     	Gdk.Pixbuf small_icon = icon.ScaleSimple (
+        16, 16,   // dest x,y
+        Gdk.InterpType.Bilinear);
+
+			small_icon.Composite(bookmark,
+        0,   0,   // dest x,y
+        48, 18,   // height,width
+        31,  2,   // offset x,y
+        1,   1,   // scaling x,y
+        Gdk.InterpType.Bilinear,
+        255);     // Alpha
+
+			emblem = Path.GetFileName (emblem);
+			string home = Environment.GetEnvironmentVariable ("HOME");
+			emblem = Path.Combine (Path.Combine (home,
+			  String.Format (".dashboard/tmp/")),
+			 "emblem-" + emblem.ToString());
+
+			bookmark.Savev (emblem, "png", null, null);
+			return emblem;
+		}
 	}
 }
+
//
// backend-ephybookmarks.cs: Epiphany bookmarks backend.  Reads from
// ~/.gnome2/epiphany/bookmarks.rdf.
//
// Authors:
//     Jonas Heylen <jonas heylen pandora be> 
//


using System;
using System.IO;
using System.Xml;
using System.Collections;

namespace Dashboard {

	class EpiphanyBookmarks : BackendSimple {
		XmlDocument         doc;
		XmlNodeList         items;
		XmlNamespaceManager nsm;

		XmlDocument         favicondoc;
		
		public override bool Startup ()
		{
			Name = "Epiphany bookmarks";

			string home_dir = Environment.GetEnvironmentVariable ("HOME");
			string path;

			try {
				path = Path.Combine (home_dir, ".gnome2/epiphany/bookmarks.rdf");

				if (! File.Exists (path))
					return false;

				doc = new XmlDocument ();
				doc.Load (path);

				nsm = new XmlNamespaceManager (doc.NameTable);
				nsm.AddNamespace ("rss", "http://purl.org/rss/1.0/";);

				items = doc.SelectNodes ("//rss:item", nsm);

        path = Path.Combine (home_dir, ".gnome2/epiphany/ephy-favicon-cache.xml");
        if (File.Exists (path)) {
					favicondoc = new XmlDocument ();
					favicondoc.Load (path);
				}

				// FIXME: need to subscribe to clues that we
				// should try matching against. Probably
				// textblock and sentence_at_point:
				// this.SubscribeToClues ("textblock", "sentence_at_point");

				this.Initialized = true;

				return true;
			} catch {
				return false;
			}
		}

		protected override ArrayList ProcessClueSimple (Clue clue)
		{

			if (! this.Initialized)
				return null;

			if (clue.Text.Length == 0)
				return null;

			string clue_text = clue.Text.ToLower ();

			// Match list
			ArrayList matches = new ArrayList();

			int match_count = 0;

			foreach (XmlNode node in items) {

				string title = node.SelectSingleNode ("rss:title", nsm).InnerText;
				string lower = title.ToLower();
				
				if (lower.IndexOf (clue_text) == -1)
					continue;
				
				string uri = node.SelectSingleNode ("rss:link", nsm).InnerText;

				string iconuri = this.GetIconPath (uri);

				// Construct match set
				Match match = new Match ("WebLink", clue);
				match ["emblem-icon"] = iconuri;
				match ["title"] = title;
				match ["url"]   = uri;

				matches.Add(match);
				match_count++;
			}

			if (match_count == 0) {
				return null;
			} else {
				return matches;
			}
		}

		private string GetIconPath (string url)
		{
			if (favicondoc == null)
					return null;

			int index = url.IndexOf ("/", 7);
			if (index > -1)
			   url = url.Substring (0, index);

			string xpath = "descendant::node[starts-with(child::property[1]/child::text(), '" + url + "')]";
			XmlNode fav_node = favicondoc.SelectSingleNode (xpath);

			if (fav_node != null) {
				xpath = "child::property[position()=2]";
				XmlNode favicon = fav_node.SelectSingleNode (xpath);
				string home_dir = Environment.GetEnvironmentVariable ("HOME");
				string path = Path.Combine (home_dir, ".gnome2/epiphany/favicon_cache");
				return Path.Combine (path, favicon.InnerText);
			}

			return null;
		}
	}
}




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]