Re: Evolution Addressbook Backend



> Can you resend your patches in GNU diff unified format?  (diff -u)  It
> makes them much easier to read.

Attached.

> If you check out dashboard from a few months ago, there's a contact
> renderer in the old addressbook backend.  If you were interested you
> could look at this and create a renderer from it.  (There's a screenshot
> of it in http://nat.org/dashboard/rewrite.png)

Okay. Thanks, I'll look at this.

-- Matt Jones
Index: backends/EvolutionAddressbookBackend.cs
===================================================================
RCS file: /cvs/gnome/dashboard/backends/EvolutionAddressbookBackend.cs,v
retrieving revision 1.9
diff -u -r1.9 EvolutionAddressbookBackend.cs
--- backends/EvolutionAddressbookBackend.cs	16 Feb 2004 09:21:22 -0000	1.9
+++ backends/EvolutionAddressbookBackend.cs	22 Feb 2004 18:47:43 -0000
@@ -14,10 +14,12 @@
 using Evolution;
 
 namespace Dashboard {
-	public class EvolutionAddressbookBackend : Backend {
+	public class EvolutionAddressbookBackend : BackendSimple {
 
 		Evolution.Book addressbook;
 		bool lazy_initted = false;
+		
+		string address_book_location = "file:///home/matt/.evolution/addressbook/local/OnThisComputer/1076640723 2454 0 localhost localdomain";
 
 		public override bool Startup ()
 		{
@@ -43,10 +45,34 @@
 			
 		}
 
+//		private string GetAddressbookUri()
+//		{
+//			GConf.Client client = new GConf.Client ();
+//			string uri;
+//			
+//			ArrayList rawxml = (ArrayList)client.Get ("/apps/evolution/addressbook/sources" );
+//			
+//			foreach (string temp in rawxml )
+//				Console.WriteLine( temp );
+//			temp = (string)rawxml[0];
+//			
+//			Console.WriteLine( "Got key " + temp );
+//			
+//			return "";
+//			
+//		}
+
 		private void LazyInit ()
 		{
 			addressbook = new Evolution.Book ();
-			addressbook.LoadLocalAddressbook ();
+	//		addressbook.LoadLocalAddressbook ();
+
+	//		string temp = GetAddressbookUri();
+
+//			public static unsafe bool GetAddressbooks(Evolution.SourceList addressbook_sources) 
+//			public Source(string xml)
+
+			addressbook.LoadUri(address_book_location, true);
 
 			lazy_initted = true;
 		}
@@ -59,71 +85,109 @@
 				LazyInit ();
 
 			foreach (Clue c in cp.Clues)
+			{
 				this.ProcessClue (result, c);
+				foreach ( Match match in ProcessClueSimple( c ) )
+					result.AddMatch( match );
+			}
 
-			return resultset;
+			return result;
+		}
+
+		protected override ArrayList ProcessClueSimple( Clue clue )
+		{
+			ArrayList contacts;
+			ArrayList matches = new ArrayList();
+			
+			contacts = FindContacts ( clue );
+			
+			foreach (Contact contact in contacts )
+				matches.Add(GenerateMatchForContact( contact, clue ));
+	
+			return matches;
 		}
 
 		private void ProcessClue (BackendResult result, Clue c)
 		{
 			ArrayList contacts;
+			ArrayList resultset = new ArrayList();
 
-			Console.WriteLine ("Evolution 2.0 addressbook backend got clue: " + c.ToString ());
+	//		Console.WriteLine ("Evolution 2.0 addressbook backend got clue: " + c.ToString ());
 
 			contacts = FindContacts (c);
 
 			foreach (Contact contact in contacts) {
 				Match m = GenerateMatchForContact (contact, c);
 
-				GenerateCluesForContact (resultpoiewjfoiewjfoiewjfoiewjfoiewjfoiewjf this is broken FIXME
+				GenerateCluesForContact ( resultset, contact, m );
 			}
-			GenerateClues (resultset, contacts, c);
+			GenerateClues (result, contacts, c);
 		}
 
 		private ArrayList FindContacts (Clue c)
 		{
-
 			BookQuery query = BuildQuery (c);
 
 			return new ArrayList (addressbook.GetContacts (query));
 		}
 
-		private void GenerateResult (BackendResult result, ArrayList contacts, Clue c)
-		{
-		}
-
 		private void GenerateClues (BackendResult result, ArrayList contacts, Clue c)
 		{
 			ArrayList clues = new ArrayList ();
 
 			foreach (Contact contact in contacts)
-				GenerateCluesForContact (clues, contact, c);
+			{
+				Match m = GenerateMatchForContact(contact, c);
+				GenerateCluesForContact (clues, contact, m);
+			}
 
 			result.AddChainedClues (clues);
 		}
 
 		private void GenerateCluesForContact (ArrayList clues, Contact contact, Match triggering_match)
 		{
-			AddClue (clues, c, contact.FullName,     "full_name");
-			AddClue (clues, c, contact.Email1,       "email");
-
+		
+		  try
+		  {
+				AddClue (clues, triggering_match, contact.FullName,     "full_name");
+			}
+			catch {}
+		
+			try
+			{
+				if ( contact.Email1.Length > 0 )
+					AddClue (clues, triggering_match, contact.Email1,       "email");
+			}
+			catch {}
+			
 			if (contact.ImAim.Length > 0)
-				AddClue (clues, c, contact.ImAim [0],        "aim_name");
+				AddClue (clues, triggering_match, contact.ImAim [0],        "aim_name");
 
 			if (contact.ImMsn.Length > 0)
-				AddClue (clues, c, contact.ImMsn [0],        "msn_name");
+				AddClue (clues, triggering_match, contact.ImMsn [0],        "msn_name");
 
 			if (contact.ImIcq.Length > 0)
-				AddClue (clues, c, contact.ImIcq [0],        "icq_name");
+				AddClue (clues, triggering_match, contact.ImIcq [0],        "icq_name");
 
 			if (contact.ImJabber.Length > 0)
-				AddClue (clues, c, contact.ImJabber [0],     "jabber_name");
+				AddClue (clues, triggering_match, contact.ImJabber [0],     "jabber_name");
 
 			if (contact.ImYahoo.Length > 0)
-				AddClue (clues, c, contact.ImYahoo [0],      "yahoo_name");
+				AddClue (clues, triggering_match, contact.ImYahoo [0],      "yahoo_name");
 			
-			AddClue (clues, c, contact.HomepageUrl,  "url");
-			AddClue (clues, c, contact.BlogUrl,      "rss");
+			try
+			{
+				if ( contact.HomepageUrl.Length > 0)
+					AddClue (clues, triggering_match, contact.HomepageUrl,  "url");
+			} 
+			catch {}
+
+			try
+			{	
+				if ( contact.BlogUrl.Length > 0 )
+					AddClue (clues, triggering_match, contact.BlogUrl,      "rss");
+			}
+			catch {}
 		}
 
 		private void AddClue (ArrayList clues, Match triggering_match, string field, string field_name)
@@ -132,39 +196,179 @@
 				clues.Add (new Clue (field_name, field, 10, triggering_match));
 		}
 
-		private BackendMatch GenerateMatchForContact (Contact contact)
+		private Match GenerateMatchForContact (Contact contact, Clue c)
 		{
-			BackendMatch result = new BackendMatch ();
+			Match result = new Match ( "Contact", c );
 
-			if (contact.FullName != null && contact.FullName != "")
-				result.AddItem (new BackendMatchItem ("Name", contact.FullName, "text", "xml"));
+			try
+			{
+				if (contact.FullName != null && contact.FullName != "")
+					result["Name"] = contact.FullName;
+			}
+			catch {}
+			
+			try
+			{
+				if (contact.Email1 != null && contact.Email1 != "")
+				result["EMail"] = contact.Email1;
+			}
+			catch {}
 
-			if (contact.Email1 != null && contact.Email1 != "")
-				result.AddItem (new BackendMatchItem ("EMail", contact.Email1, "text", "xml"));
+			ArrayList phonenumbers = GetContactPhoneNumbers( contact );
+			try
+			{
+				if ( phonenumbers[0] != null)
+					result["Phone"] = phonenumbers[0];
+			}
+			catch {}
+			
+			return result;
+		}
 
-			if (contact.PrimaryPhone != null && contact.PrimaryPhone != "")
-				result.AddItem (new BackendMatchItem ("Phone", contact.PrimaryPhone, "text", "xml"));
+		private ArrayList GetContactPhoneNumbers( Contact contact )
+		{
+			ArrayList numbers = new ArrayList();
+			
+			try
+			{
+				if (contact.PrimaryPhone != null && contact.PrimaryPhone != "")
+					numbers.Add( contact.PrimaryPhone );
+			}
+			catch {}
+			
+			try
+			{
+				if (contact.AssistantPhone != null && contact.AssistantPhone != "")
+					numbers.Add( contact.AssistantPhone );
+			}
+			catch {}
+			
+			try
+			{
+				if (contact.BusinessPhone != null && contact.BusinessPhone != "")
+					numbers.Add( contact.BusinessPhone );
+			}
+			catch {}
 
-			return result;
+			try
+			{
+				if (contact.BusinessPhone2 != null && contact.BusinessPhone2 != "")
+					numbers.Add( contact.BusinessPhone );
+			}
+			catch {}
+			
+			try
+			{
+				if (contact.BusinessFax != null && contact.BusinessFax != "")
+					numbers.Add( contact.BusinessFax );
+			}
+			catch {}
+			
+			try
+			{
+				if (contact.CallbackPhone != null && contact.CallbackPhone != "")
+					numbers.Add( contact.CallbackPhone );
+			}
+			catch {}
+			
+			try
+			{
+				if (contact.CarPhone != null && contact.CarPhone != "")
+					numbers.Add( contact.CarPhone );
+			}
+			catch {}
+			
+			try
+			{
+				if (contact.CompanyPhone != null && contact.CompanyPhone != "")
+					numbers.Add( contact.CompanyPhone );
+			}
+			catch {}
+			
+			try
+			{
+				if (contact.CallbackPhone != null && contact.CallbackPhone != "")
+					numbers.Add( contact.CallbackPhone );
+			}
+			catch {}
+			
+			try
+			{
+				if (contact.CallbackPhone != null && contact.CallbackPhone != "")
+					numbers.Add( contact.CallbackPhone );
+			}
+			catch {}
+					
+			try
+			{
+				if (contact.HomePhone != null && contact.HomePhone != "")
+					numbers.Add( contact.HomePhone );
+			}
+			catch {}
+			
+			try
+			{
+				if (contact.HomePhone2 != null && contact.HomePhone2 != "")
+					numbers.Add( contact.HomePhone2 );
+			}
+			catch {}
+			
+			try
+			{
+				if (contact.IsdnPhone != null && contact.IsdnPhone != "")
+					numbers.Add( contact.IsdnPhone );
+			}
+			catch {}
+			
+			try
+			{
+				if (contact.MobilePhone != null && contact.MobilePhone != "")
+					numbers.Add( contact.MobilePhone );
+			}
+			catch {}
+			
+			try
+			{
+				if (contact.OtherPhone != null && contact.OtherPhone != "")
+					numbers.Add( contact.OtherPhone );
+			}
+			catch {}
+			
+			try
+			{
+				if (contact.OtherFax != null && contact.OtherFax != "")
+					numbers.Add( contact.OtherFax );
+			}
+			catch {}
+			
+			try
+			{
+				if (contact.Pager != null && contact.Pager != "")
+					numbers.Add( contact.Pager );
+			}
+			catch {}
+			
+			return numbers;
+			
 		}
 
 		private BookQuery BuildQuery (Clue c)
 		{
-			if (c.Type == "*" || c.Type == "keyword")
+			if (c.Type == "*" || c.Type == "keyword" || c.Type == "aim_name") // FIXME: frontend should be passing in a wildcard clue type, not an aim_name clue type
 				return BookQuery.AnyFieldContains (c.Text);
 
 //			if (c.Type == "phone")
-//				return BookQuery.Andv (BookQuery.FieldTest (ContactField.PhonePrimary, BookQueryTest.Is, Clue.Text),
-//						       BookQuery.FieldTest (ContactField.PhoneBusiness, BookQueryTest.Is, Clue.Text),
-//						       BookQuery.FieldTest (ContactField.PhoneHome, BookQueryTest.Is, Clue.Text),
-//						       BookQuery.FieldTest (ContactField.PhoneHome2, BookQueryTest.Is, Clue.Text),
-//						       BookQuery.FieldTest (ContactField.PhoneHomeFax, BookQueryTest.Is, Clue.Text),
-//						       BookQuery.FieldTest (ContactField.PhoneMobile, BookQueryTest.Is, Clue.Text),
-//						       BookQuery.FieldTest (ContactField.PhonePager, BookQueryTest.Is, Clue.Text));
+//				return BookQuery.Or (BookQuery.FieldTest (ContactField.PhonePrimary, BookQueryTest.Contains, Clue.Text),
+//						       BookQuery.FieldTest (ContactField.PhoneBusiness, BookQueryTest.Contains, Clue.Text),
+//						       BookQuery.FieldTest (ContactField.PhoneHome, BookQueryTest.Contains, Clue.Text),
+//						       BookQuery.FieldTest (ContactField.PhoneHome2, BookQueryTest.Contains, Clue.Text),
+//						       BookQuery.FieldTest (ContactField.PhoneHomeFax, BookQueryTest.Contains, Clue.Text),
+//						       BookQuery.FieldTest (ContactField.PhoneMobile, BookQueryTest.Contains, Clue.Text),
+//						       BookQuery.FieldTest (ContactField.PhonePager, BookQueryTest.Contains, Clue.Text));
 
 			ContactField field = MapClueTypeToField (c);
 
-			return BookQuery.FieldTest (MapClueTypeToField (c), BookQueryTest.Is, c.Text);
+			return BookQuery.FieldTest (MapClueTypeToField (c), BookQueryTest.Contains, c.Text);
 		}
 
 		private ContactField MapClueTypeToField (Clue c)
Index: renderers/Makefile.am
===================================================================
RCS file: /cvs/gnome/dashboard/renderers/Makefile.am,v
retrieving revision 1.4
diff -u -r1.4 Makefile.am
--- renderers/Makefile.am	20 Feb 2004 01:44:02 -0000	1.4
+++ renderers/Makefile.am	22 Feb 2004 18:47:43 -0000
@@ -10,7 +10,8 @@
 	IMLogMatchRenderer.dll		\
 	MailMessageMatchRenderer.dll	\
 	BugzillaBugMatchRenderer.dll	\
-	DefaultMatchRenderer.dll
+	DefaultMatchRenderer.dll	\
+	ContactMatchRenderer.dll
 
 # These do not work.
 broken_renderers =
@@ -20,7 +21,8 @@
 	$(srcdir)/IMLogMatchRenderer.cs			\
 	$(srcdir)/MailMessageMatchRenderer.cs		\
 	$(srcdir)/BugzillaBugMatchRenderer.cs		\
-	$(srcdir)/DefaultMatchRenderer.cs
+	$(srcdir)/DefaultMatchRenderer.cs		\
+	$(srcdir)/ContactMatchRenderer.cs
 
 all: $(renderers)
 

Attachment: ContactMatchRenderer.cs
Description: Binary data

Index: evolution/Contact.custom
===================================================================
RCS file: /cvs/gnome/evolution-sharp/evolution/Contact.custom,v
retrieving revision 1.2
diff -u -r1.2 Contact.custom
--- evolution/Contact.custom	4 Feb 2004 18:17:31 -0000	1.2
+++ evolution/Contact.custom	22 Feb 2004 18:51:09 -0000
@@ -30,6 +30,18 @@
 			}
 		}
 
+		public string FullName {
+			get {
+				GLib.Value val = new GLib.Value (Handle, "full_name");
+				GetProperty("full_name", val);
+				string ret = (string) val;
+				return ret;
+			}
+			set {
+				SetProperty("full_name", new GLib.Value(value));
+			}
+		}
+
 		public string GivenName {
 			get {
 				GLib.Value val = new GLib.Value (Handle, "given_name");


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