Re: Galeon Bookmarks Backend



A couple of minor fixes and another version :)  Basically just fixed
some minor formatting issues.

Also, a suggestion was made on IRC that we should probably rename this
to be galeon specific.

Skadz

On Sun, 2003-12-07 at 02:34, Ryan P Skadberg wrote:
> A couple of things:
> 
> a) Loading Galeon Bookmarks failed for me until I upgraded to Mono
> 0.29.  Something you may want to include in the Release Notes.
> b) Attached is a new version of backend-bookmarks.cs.  This version does
> the following:
> 
>   * Cleaned up Output to a much nicer table
>   * Hack Around FavIcon Cache not using trailing slash
>   * Changed any instances of Bookmarks to Galeon Bookmarks
>   * Probably Added Some Debug that can eventually come out
> 
> Skadz
-- 
-----------------------------------------------------------------------
 Ryan P Skadberg                          E: skadz stigmata org
 The Stigmata Organization                U: http://www.stigmata.org/
-----------------------------------------------------------------------
  GPG fingerprint = 0B97 F771 E7D2 69B2 FF5C  5693 4E25 7E77 DEF0 CA4B
-----------------------------------------------------------------------

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

namespace Dashboard {

	class GaleonBookmarks : BackendSimple {
		XmlDocument         doc;
		XmlNodeList         titles;
		XmlDocument         favicondoc;
		
		public override bool Startup ()
		{
			Name = "Galeon Bookmarks";

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

			try {
				path = Path.Combine (home_dir, ".galeon/bookmarks.xbel");

				if (!File.Exists (path)){
					path = Path.Combine (home_dir, ".galeon/bookmarks.xml");
					Console.WriteLine ("Galeon Bookmarks Path: " + path);
					if (!File.Exists (path))
						return false;
				}

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

				titles = doc.SelectNodes ("//bookmark/title");
				Console.WriteLine ("Galeon Bookmarks backend loaded {0} bookmarks.", titles.Count);

				path = Path.Combine (home_dir, ".galeon/favicon_cache.xml");
				Console.WriteLine ("Galeon FavIcon Path: " + path);
				if (!File.Exists (path)) {
					Console.WriteLine ("Galeon FavIcon Not Found: " + path);
					return false;
				}


				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 Match ProcessClueSimple (Clue clue)
		{

			if (! this.Initialized)
				return null;

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

			string clue_text = clue.Text.ToLower ();
	
			// Start Outer Table
			string html = String.Format("<table width=\"100%\" bgcolor=\"#003366\" border=0 cellpadding=1><tr><td>");
			// Start Inner Table
			html += String.Format ("<table bgcolor=\"#003366\" cellpadding=4 cellspacing=1 width=100%>");
			// Show Header
			html += String.Format ("<tr><td bgcolor=\"#aecce2\" align=\"center\" valign=center><img height=\"48\" width=\"48\" src=\"internal:bookmark.png\" border=0></td><td bgcolor=\"#aecce2\">&nbsp;&nbsp;</td><td bgcolor=\"#aecce2\"><h2><u>Galeon Bookmarks</u></h2></td></tr>");

			int match_count = 0;
			string bgcolor = "#dddddd";

			foreach (XmlNode node in titles) {
				string t = node.InnerText;
				string lower = t.ToLower ();

				if (lower.IndexOf (clue_text) == -1)
					continue;

				if (node.ParentNode == null)
					throw new Exception ("Null found");
				if (node.ParentNode.Attributes ["href"] == null) {
					throw new Exception ("Null found222");
				}

                                string uri = node.ParentNode.Attributes ["href"].InnerText;

				// Galeon Saves FavIcon Cache without 
				// Trailing Slash.  Code Around.
				string myurl = uri;
				if (myurl.EndsWith("/")) {
					myurl = myurl.Substring(0,myurl.Length - 1);
				}
				// End Code Around

                                string xpath = "descendant::entry[ url=\"" + myurl + "\"]";
                                Console.WriteLine ("Galeon Xpath: " + xpath);
                                XmlNode favicon = favicondoc.SelectSingleNode (xpath);
                                Console.WriteLine ("Galeon FavIcon: " + favicon);
                                string iconuri;
                                if (favicon != null)
                                        iconuri = favicon.Attributes ["favicon"].InnerText;
                                else
                                        iconuri ="internal:bookmark.png";
	
				html += String.Format (
"<tr>" +
"    <td valign=center align=center bgcolor=\"" + bgcolor + "\">" +
"        <a href=\"{1}\"><img height=\"24\" width=\"24\" src=\"{2}\" border=0></a>" +
"    </td>" +
"<td bgcolor=\"" + bgcolor + "\">&nbsp;&nbsp;</td>" +
"    <td valign=top bgcolor=\"" + bgcolor + "\">" +
"        <a href=\"{1}\" style=\"text-decoration: none;\">{0}<br>" +
"        <font size=-1 color=#666666>{1}</font></a>" +
"    </td>" +
"</tr>", t, uri, iconuri);

				if (bgcolor == "#dddddd")
					bgcolor = "#ffffff";
				else
					bgcolor = "#dddddd";

				match_count ++;
			}

			if (match_count == 0)
				return null;

			html += String.Format ("</table></td></tr></table>");
			return new Match (this, html, 0, String.Format ("bookmark:{0}", clue_text));
		}
	}
}

Attachment: signature.asc
Description: This is a digitally signed message part



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