Evolution Addressbook Backend



Hi - 

I have a working evolution address backend (attached as patch against
evolution-sharp, dashboard & horrible contact renderer).

Issues I see
 - You have to hardcode the path to your addressbook
 - Way too many try {} catch {} statements (evolution-sharp generates
errors when something is undefined - this behavior should probably be
changed)

Things I'd like to do
 - Write a decent renderer (I'm a horrible web designer)
 - Load contact images from e-book backend (could be difficult)
 - Allow for more dynamic contact subtypes - so a match would contain
lists of phone numbers, email address etc., at this moment I just grab
the default one

But this code seems to work pretty well (it chains and everything else).

-- Matt Jones

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 -r1.2 Contact.custom
32a33,44
> 		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));
> 			}
> 		}
> 
? EvoAddress.patch
? renderers/ContactMatchRenderer.cs
Index: backends/EvolutionAddressbookBackend.cs
===================================================================
RCS file: /cvs/gnome/dashboard/backends/EvolutionAddressbookBackend.cs,v
retrieving revision 1.9
diff -r1.9 EvolutionAddressbookBackend.cs
17c17
< 	public class EvolutionAddressbookBackend : Backend {
---
> 	public class EvolutionAddressbookBackend : BackendSimple {
20a21,22
> 		
> 		string address_book_location = "file:///home/matt/.evolution/addressbook/local/OnThisComputer/1076640723 2454 0 localhost localdomain";
45a48,64
> //		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 "";
> //			
> //		}
> 
49c68,75
< 			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);
61a88
> 			{
62a90,92
> 				foreach ( Match match in ProcessClueSimple( c ) )
> 					result.AddMatch( match );
> 			}
64c94,107
< 			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;
69a113
> 			ArrayList resultset = new ArrayList();
71c115
< 			Console.WriteLine ("Evolution 2.0 addressbook backend got clue: " + c.ToString ());
---
> 	//		Console.WriteLine ("Evolution 2.0 addressbook backend got clue: " + c.ToString ());
78c122
< 				GenerateCluesForContact (resultpoiewjfoiewjfoiewjfoiewjfoiewjfoiewjf this is broken FIXME
---
> 				GenerateCluesForContact ( resultset, contact, m );
80c124
< 			GenerateClues (resultset, contacts, c);
---
> 			GenerateClues (result, contacts, c);
85d128
< 
91,94d133
< 		private void GenerateResult (BackendResult result, ArrayList contacts, Clue c)
< 		{
< 		}
< 
100c139,142
< 				GenerateCluesForContact (clues, contact, c);
---
> 			{
> 				Match m = GenerateMatchForContact(contact, c);
> 				GenerateCluesForContact (clues, contact, m);
> 			}
107,109c149,162
< 			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 {}
> 			
111c164
< 				AddClue (clues, c, contact.ImAim [0],        "aim_name");
---
> 				AddClue (clues, triggering_match, contact.ImAim [0],        "aim_name");
114c167
< 				AddClue (clues, c, contact.ImMsn [0],        "msn_name");
---
> 				AddClue (clues, triggering_match, contact.ImMsn [0],        "msn_name");
117c170
< 				AddClue (clues, c, contact.ImIcq [0],        "icq_name");
---
> 				AddClue (clues, triggering_match, contact.ImIcq [0],        "icq_name");
120c173
< 				AddClue (clues, c, contact.ImJabber [0],     "jabber_name");
---
> 				AddClue (clues, triggering_match, contact.ImJabber [0],     "jabber_name");
123c176
< 				AddClue (clues, c, contact.ImYahoo [0],      "yahoo_name");
---
> 				AddClue (clues, triggering_match, contact.ImYahoo [0],      "yahoo_name");
125,126c178,190
< 			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 {}
135c199
< 		private BackendMatch GenerateMatchForContact (Contact contact)
---
> 		private Match GenerateMatchForContact (Contact contact, Clue c)
137c201
< 			BackendMatch result = new BackendMatch ();
---
> 			Match result = new Match ( "Contact", c );
139,140c203,215
< 			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 {}
142,143c217,226
< 			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;
> 		}
145,146c228,251
< 			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 {}
148c253,352
< 			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;
> 			
153c357
< 			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
157,163c361,367
< //				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));
167c371
< 			return BookQuery.FieldTest (MapClueTypeToField (c), BookQueryTest.Is, c.Text);
---
> 			return BookQuery.FieldTest (MapClueTypeToField (c), BookQueryTest.Contains, c.Text);
Index: renderers/Makefile.am
===================================================================
RCS file: /cvs/gnome/dashboard/renderers/Makefile.am,v
retrieving revision 1.4
diff -r1.4 Makefile.am
13c13,14
< 	DefaultMatchRenderer.dll
---
> 	DefaultMatchRenderer.dll	\
> 	ContactMatchRenderer.dll
23c24,25
< 	$(srcdir)/DefaultMatchRenderer.cs
---
> 	$(srcdir)/DefaultMatchRenderer.cs		\
> 	$(srcdir)/ContactMatchRenderer.cs


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