Re: RFC before sending patches for a few FIXMEs



Note to self : it is generally a good idea to put the patches you are
talking about in a mail :) Sorry !

Clement

On Thu, 2004-03-04 at 20:38, Clement Moyroud wrote:
> On Tue, 2004-03-02 at 05:57, Nat Friedman wrote:
> > On Fri, 2004-02-27 at 03:46, Clement Moyroud wrote:
> > 
> > > 1/ Where should Dashbord configuration go ? GConf might be the good
> > > solution, being the Gnome standard. I have used this layout :
> > 
> > For the most part, dashboard should have as little configuration as
> > possible.  Any necessary parameters (like the path to the user's browser
> > directory) should be read from the relevant places in the system.
> > 
> > Some configuration will be necessary, and I think using GConf makes
> > perfect sense.  For all GConf keys we add, though, we need to add
> > schemas with descriptions of what they configure.
> > 
> 
> The patch for Google includes the schemas (engine/dashboard.schemas) for
> both Google and Bugzilla, as well as config.in and engine/Makefile.am
> additions to have them installed
> 
> > The big dashboard configuration problem is backend selection.  I think
> > some of this will be automatic -- figuring out which browser you use by
> > default, for example -- and some will be user-configurable.  Relevance
> > filtering may end up changing the semantics of this.
> > 
> > > 2/ the MozillaBookmarksBackend author would like to use XPath for the
> > > parsing of the html file. To my (limited !) knowledge, that is not
> > > possible. The bookmarks.html file is not well-formed XML (not being
> > > XHTML compliant). One could write a SGML parser, but I'm not sure it'll
> > > be good performance-wise compared to the regexp used actually.
> > 
> > I don't know whether it's possible or not, since I don't know the format
> > of the Mozilla bookmarks.  Since we have a working regexp now, I don't
> > see a reason to change it.
> 
> I have corrected the regex (it didn't work, see Tim Mellor's patch) and
> added code to retrieve and cache the favicons.
> 
> > > - mozilla-backend-patch.diff : adds 2 gconf keys for the choice of the
> > > mozilla flavour and the profile name
> > 
> > I think we need to autodetect the user's browser and default profile.
> 
> Done ! This removes the gconf keys, since everything should be
> autodetected.
> I have also added code to use a proxy if it is defined and set to 'on'
> in gconf. This could be a dashboard-wide piece of code, avoiding gconf
> interaction as much as possible.
> As for autodetection, I think we could have a better behaviour than :
> 1/ load the browser backend
> 2/ see if it is the default browser and unload if necessary
> 3/ repeat from step 1
> 
> Maybe we could use a backend loader that checks the default browser and
> loads only the relevant one, *if* we only want to load a single backend.
> 
> > 
> > Thanks for your patches!  Nice stuff!
> > 
> 
> You're welcome ! It's such a neat piece of work, it makes me want to
> contribute.
> 
> 
> Clement (a.k.a. Mool on IRC)
> 
> _______________________________________________
> Dashboard-hackers mailing list
> Dashboard-hackers gnome org
> http://mail.gnome.org/mailman/listinfo/dashboard-hackers
diff -Nru dashboard/backends/GoogleBackend.cs dashboard-new/backends/GoogleBackend.cs
--- dashboard/backends/GoogleBackend.cs	2004-03-04 08:59:33.000000000 +0100
+++ dashboard-new/backends/GoogleBackend.cs	2004-03-04 18:31:26.000000000 +0100
@@ -4,6 +4,7 @@
 // Authors:
 //     Don Smith <donsmith77 optonline net>
 //
+// Set gconf:/apps/dashboard/backends/google/api_key to your API Key
 
 using System;
 using System.IO;
@@ -17,21 +18,31 @@
 
 	class GoogleBackend : BackendSimple {
 
-		// Set your key below.  You can get a Google API key
-		// at http://www.google.com/apis/.
-		string google_api_key = "INSERT DEVTAG HERE"; 
+		string google_api_key = "DEVTAG"; 
 		
 		public override bool Startup ()
 		{
 			Name = "Google";
 
-			if (google_api_key.Length == 0)
-				return false;
+			GConf.Client client = new GConf.Client ();
+			try {
+				string api_key = (string) client.Get ("/apps/dashboard/backends/google/api_key");
+				if (api_key != "")
+					google_api_key = api_key;
+				else {
+                    Console.WriteLine ("Please put in a Google Dev Tag");
+					return false;
+				}
+			}
+			catch (GConf.NoSuchKeyException) {
+                    Console.WriteLine ("Please put in a Google Dev Tag");
+					return false;
+            }
 
-			if (google_api_key == "INSERT DEVTAG HERE"){
-                                Console.WriteLine ("Please put in a Google Dev Tag");
+			if (google_api_key == "DEVTAG"){
+				Console.WriteLine ("Please put in a Google Dev Tag");
 				return false;
-                        }
+			}
 
 			try {
 				// Subscribe to artist clues
diff -Nru dashboard/configure.in dashboard-new/configure.in
--- dashboard/configure.in	2004-02-14 10:16:59.000000000 +0100
+++ dashboard-new/configure.in	2004-03-04 18:25:40.000000000 +0100
@@ -8,6 +8,7 @@
 AC_PROG_INSTALL
 AC_HEADER_STDC
 AM_PROG_LIBTOOL
+AM_GCONF_SOURCE_2
 
 CFLAGS='-ggdb -Wall -Wunused -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Wshadow -Wpointer-arith -Wno-cast-qual -Wcast-align -Wwrite-strings'
 
diff -Nru dashboard/engine/Makefile.am dashboard-new/engine/Makefile.am
--- dashboard/engine/Makefile.am	2004-03-04 08:59:34.000000000 +0100
+++ dashboard-new/engine/Makefile.am	2004-03-04 18:39:36.000000000 +0100
@@ -64,7 +64,11 @@
 
 dashboardlibdir = $(prefix)/lib/dashboard
 
-install-data-local: dashboard.exe
+install-schemas:
+	      GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) \
+		  	      gconftool --makefile-install-rule dashboard.schemas
+
+install-data-local: dashboard.exe install-schemas
 	$(mkinstalldirs) $(DESTDIR)$(dashboardlibdir)
 	$(INSTALL_DATA) dashboard.exe $(DESTDIR)$(dashboardlibdir)/dashboard.exe
 
diff -Nru dashboard/engine/dashboard.schemas dashboard-new/engine/dashboard.schemas
--- dashboard/engine/dashboard.schemas	1970-01-01 01:00:00.000000000 +0100
+++ dashboard-new/engine/dashboard.schemas	2004-03-04 18:26:25.000000000 +0100
@@ -0,0 +1,34 @@
+<gconfschemafile>
+	<schemalist>
+		<schema>
+			<key>/schemas/apps/dashboard/backends/bugzilla/host</key>
+			<applyto>/apps/dashboard/backends/bugzilla/host</applyto>
+			<owner>Dashboard</owner>
+			<type>string</type>
+			<locale name="C">
+				<default>http://bugzilla.ximian.com</default>
+				<short>Bugzilla host URL</short>
+			</locale>
+			<locale name="fr">
+				<default>http://bugzilla.ximian.com</default>
+				<short>URL du serveur Bugzilla</short>
+			</locale>
+		</schema>
+		<schema>
+			<key>/schemas/apps/dashboard/backends/google/api_key</key>
+			<applyto>/apps/dashboard/backends/google/api_key</applyto>
+			<owner>Dashboard</owner>
+			<type>string</type>
+			<locale name="C">
+				<default>DEVTAG</default>
+				<short>Google API key</short>
+				<long>Set this to your Google developer key. You can get a Google API key at http://www.google.com/apis/</long>
+			</locale>
+			<locale name="fr">
+				<default>DEVTAG</default>
+				<short>Clé pour l'API Google</short>
+				<long>Mettez ici votre clé de développeur Google. Vous pouvez obtenir une clé pour l'API Google à l'adresse suivante : http://www.google.com/apis/</long>
+			</locale>
+		</schema>
+	</schemalist>
+</gconfschemafile>
diff -Nru dashboard/backends/Makefile.am dashboard-new/backends/Makefile.am
--- dashboard/backends/Makefile.am	2004-03-02 05:59:35.000000000 +0100
+++ dashboard-new/backends/Makefile.am	2004-03-04 18:43:37.000000000 +0100
@@ -89,6 +89,9 @@
 BugzillaBackend.dll: BugzillaBackend.cs $(dashboard_exe)
 	$(CSC) $(LIBFLAGS) -out:BugzillaBackend.dll $(srcdir)/BugzillaBackend.cs -r:gconf-sharp
 
+MozillaBookmarksBackend.dll: MozillaBookmarksBackend.cs $(dashboard_exe)
+	$(CSC) $(LIBFLAGS) -out:MozillaBookmarksBackend.dll $(srcdir)/MozillaBookmarksBackend.cs -r:gconf-sharp
+
 GoogleBackend.dll: GoogleBackend.cs $(dashboard_exe)
 	$(CSC) $(LIBFLAGS) -out:GoogleBackend.dll $(srcdir)/GoogleBackend.cs -r:../util/webservices/GoogleSearchService.dll
 
diff -Nru dashboard/backends/MozillaBookmarksBackend.cs dashboard-new/backends/MozillaBookmarksBackend.cs
--- dashboard/backends/MozillaBookmarksBackend.cs	2004-03-04 08:59:33.000000000 +0100
+++ dashboard-new/backends/MozillaBookmarksBackend.cs	2004-03-04 18:56:24.000000000 +0100
@@ -27,13 +27,13 @@
 //
 //read the Mozilla or Thunderbird bookmarks
 
-//FIXME: application directory and profile should not be "hard coded".
-
 using System;
 using System.IO;
 using System.Web;
 using System.Collections;
+using System.Text;
 using System.Text.RegularExpressions;
+using System.Net;
 
 [assembly:Dashboard.BackendFactory ("Dashboard.MozillaBookmarks")]
 
@@ -41,8 +41,9 @@
 
 	class MozillaBookmarks : BackendSimple {
 
-		const string browser_dirname = ".phoenix";
-		const string profile_name = "default";
+		private string browser_dirname;
+		private string profile_name;
+		private WebProxy proxy = null;
 
 		ArrayList bookmarks = new ArrayList (); 
 
@@ -53,6 +54,81 @@
 			string home_dir = Environment.GetEnvironmentVariable ("HOME");
 			string path;
 
+			GConf.Client client = new GConf.Client ();
+			
+			try {
+				string browser = (string) client.Get ("/desktop/gnome/applications/browser/exec");
+				if (browser != "")
+				{
+					switch (browser) {
+						case "mozilla":
+						case "phoenix":
+						case "firebird":
+						case "firefox":
+										browser_dirname = "." + browser;
+										break;
+						default:
+										Console.WriteLine ("Bookmarks-mozilla: don't know how to handle '{0}'.", browser);
+										return false;
+					}
+				}
+				else {
+					Console.WriteLine ("Bookmarks-Mozilla: the Gnome browser preference is empty !");
+					return false;
+				}
+			}
+			catch (GConf.NoSuchKeyException) {
+				Console.WriteLine ("Bookmarks-Mozilla: the Gnome browser preference does not exist.");
+				return false;
+            }
+			
+			try {
+				bool use_proxy = (bool) client.Get ("/system/http_proxy/use_http_proxy");
+				if (use_proxy) {
+					string host = (string) client.Get ("/system/http_proxy/host");
+					string port = (string) client.Get ("/system/http_proxy/port");
+					if (host != "")	{
+						string prox_str = "http://"; + host + (port == "" ? "/" : ":" + port + "/");
+						proxy = new WebProxy (prox_str,true);
+						bool use_auth = (bool) client.Get ("/system/http_proxy/use_authentication");
+						if (use_auth) {
+							string user = (string) client.Get ("/system/http_proxy/authentication_user");
+							string pass = (string) client.Get ("/system/http_proxy/authentication_password");
+							proxy.Credentials = new NetworkCredential (user,pass);
+						}
+					}
+				}
+			}
+			catch(GConf.NoSuchKeyException) {}
+						
+			try {
+					path = Path.Combine (Path.Combine (home_dir, browser_dirname), "appreg");
+					FileStream fs_appreg = new FileStream (path, FileMode.Open);
+					BinaryReader br = new BinaryReader (fs_appreg);
+ 
+					StringBuilder str = new StringBuilder ("");
+					int length = (int)fs_appreg.Length - 64;
+					for (int i = 0; i<length; i++)
+						str.Append(br.ReadChar ().ToString ());
+					fs_appreg.Close ();
+					
+					string reg = "CurrentProfile\x00([^\x00]+)\x00";
+ 					Regex re = new Regex (reg, RegexOptions.None);
+					RegularExpressions.Match m = re.Match (str.ToString ());
+ 
+					Console.WriteLine (path);
+					if (m.Success)
+						profile_name = m.Groups [1].Captures [0].ToString ();
+					else {
+						Console.WriteLine ("Bookmarks-Mozilla: could not find the default profile");
+						return false;
+					}	
+			}
+			catch (System.IO.FileNotFoundException) {
+				Console.WriteLine ("Bookmarks-Mozilla: could not find the preferences file.");
+				return false;
+			}
+
 			try {
 				path = Path.Combine (Path.Combine (home_dir, browser_dirname), profile_name);
 
@@ -73,7 +149,6 @@
 				}
 
 				ExtractBookmarks (path);
-		
 
 				this.SubscribeToClues ("textblock", "keyword", "word_at_point");
 		
@@ -87,20 +162,53 @@
 			}
 		}
 
-		// FIXME - should use xpath, should get icon if possible
 		private void ExtractBookmarks (string path) {
-			string pat = "<A HREF=\" ([^\"]+)\"[^>]*> ([^<]*)</A>";
+			//FIXME Find a catch-em-all regexp
+			string pat = "<A HREF=\"([^\"]+)\"([^>]*)>([^<]*)</A>";
 			string text = File.OpenText (path).ReadToEnd ();
 	  
-
 			Regex re = new Regex (pat, RegexOptions.None);
-			int[] gnums = re.GetGroupNumbers ();
-			System.Text.RegularExpressions.Match m = re.Match (text);
+			RegularExpressions.Match m = re.Match (text);
 			while (m.Success) {
 				Bookmark bk = new Bookmark ();
-				bk.name = m.Groups[2].Captures[0].ToString ();
-				bk.lname = m.Groups[2].Captures[0].ToString ().ToLower ();
-				bk.url = m.Groups[1].Captures[0].ToString ();
+				bk.name = m.Groups [3].Captures [0].ToString ();
+				bk.lname = m.Groups [3].Captures [0].ToString ().ToLower ();
+				bk.url = m.Groups [1].Captures [0].ToString ();
+
+				string fav_finder = "ICON=\"([^{>,\"}]+)\"";
+				Regex fav_rex = new Regex (fav_finder);
+				RegularExpressions.Match fav_m = fav_rex.Match(m.Groups [2].ToString ());
+				if (fav_m.Success)
+				{
+						string fav_url = fav_m.Groups [1].ToString ();
+						
+						string home_dir = Environment.GetEnvironmentVariable ("HOME");
+						string fav_name = fav_url.Replace ('/','-');
+						string moz_path = ".dashboard/backend-data/mozilla/" + fav_name;
+						string fav_path = Path.Combine (home_dir, moz_path);
+				
+						if(!File.Exists(fav_path))
+						{
+							HttpWebRequest fav_req = (HttpWebRequest)WebRequest.Create (fav_url);
+							if(proxy != null)
+								fav_req.Proxy = proxy;
+							HttpWebResponse fav_res = (HttpWebResponse)fav_req.GetResponse ();
+							Stream rec_str = fav_res.GetResponseStream ();
+
+							FileStream fs = new FileStream (fav_path, FileMode.Create);
+							BinaryWriter bw = new BinaryWriter(fs);
+							byte[] data  = new Byte[1024];
+							
+							int count = rec_str.Read(data,0,1024);
+							bw.Write(data,0,count);
+
+							bw.Close ();
+							fs.Close ();
+						}
+
+						bk.icon = fav_path;
+				}
+				
 				bookmarks.Add (bk);
 		  
 				m = m.NextMatch ();
@@ -124,7 +232,9 @@
 
 				Match match = new Match ("WebLink", clue);
 				match ["Title"] = bk.name;
-				match ["Url"]   = bk.url;
+				match ["URL"]   = bk.url;
+				if(bk.icon.Length != 0)
+					match["Emblem-Icon"] = bk.icon;
 
 				matches.Add (match);
 			}
@@ -136,6 +246,7 @@
 			public string name;
 			public string lname;
 			public string url;
+			public string icon;
 		}
 
 	}


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