File bnc-449900-display-attendees.diff of Package evolution-mono-providers

commit 4af49c561e438faaddf1caa6eb4024f2ac162c13
Author: chen <chen@linux-adcj.(none)>
Date:   Mon Jan 12 13:38:49 2009 +0530

    Added support for showing attendees and implemented interfaces for
    accepting/declining meetings.

diff --git a/calendar/backends/sharepoint/BackGroundWorker.cs b/calendar/backends/sharepoint/BackGroundWorker.cs
index f413b7a..f8db5bf 100644
--- a/calendar/backends/sharepoint/BackGroundWorker.cs
+++ b/calendar/backends/sharepoint/BackGroundWorker.cs
@@ -30,9 +30,58 @@ namespace SharePoint
 			CalComponent [] comps = new CalComponent [changes.entries.Length];
 			for (int i = 0; i < changes.entries.Length; i++)
 			{
-				ComponentEntry cEntry = new ComponentEntry (changes.entries [i]);
+				EventEntry entry = changes.entries [i];
+				ComponentEntry cEntry = new ComponentEntry (entry);
 				CalComponent comp = cEntry.EventEntryToComp ();
 				
+
+				if (entry.WorkspaceLink == 1)
+				{
+					Console.WriteLine ("Adding atttendees " + changes.entries [i].WorkspaceUrl);
+											string meetingUrl = entry.WorkspaceUrl;
+					string url = null;
+					string instanceId = null;
+
+					if (entry.Recurrence != 1)	
+					{
+						char [] splitChar = new char [1];
+						splitChar [0] = ',';
+						string [] urlSplit = meetingUrl.Split (splitChar);
+
+						splitChar [0] = '?';
+						string [] urlSplit1 = urlSplit [0].Split (splitChar);
+
+						url = urlSplit1 [0];
+
+						splitChar [0] = '=';
+						string [] splitId = urlSplit1 [1].Split (splitChar);
+
+						instanceId = splitId [1];
+					} else {
+						char [] splitChar = new char [1];
+						splitChar [0] = ',';
+						string [] urlSplit = meetingUrl.Split (splitChar);
+						
+						url = urlSplit [0];
+						DateTime start = DateTime.Parse (entry.StartDate);
+						string date = String.Format ("{0}{1}{2:d2}", start.Year, start.Month, start.Day);
+						instanceId = date;
+					}
+
+					try {
+						EventEntry mentry = deskIceDaemon.GetMeetingEvent (String.Empty, url, instanceId);
+						comp = cEntry.UpdateMeetingDetails (mentry, spBackend.emailId);
+						comp.SetXProp ("X-SP-EVENT-UID", mentry.EventUid);
+						comp.SetXProp ("X-SP-MEETING-URL", url);
+					}
+					catch (Exception ex)
+					{
+						Console.WriteLine ("Gettting meeting details failed :( ");
+						Console.WriteLine ("Exception occurred is " + ex.Message);
+						Console.WriteLine (ex.StackTrace);
+					}
+				}
+				
 				comps [i] = comp;
 			}
 
diff --git a/calendar/backends/sharepoint/ComponentEntry.cs b/calendar/backends/sharepoint/ComponentEntry.cs
index 150fe2e..20f335f 100644
--- a/calendar/backends/sharepoint/ComponentEntry.cs
+++ b/calendar/backends/sharepoint/ComponentEntry.cs
@@ -5,6 +5,7 @@
 //
 
 using System;
+using System.Runtime.InteropServices;
 using Novell.IceDesktop;
 using Evolution;
 
@@ -142,8 +143,6 @@ namespace SharePoint
 
 			comp.Location = eentry.Location;
 
-			Console.WriteLine ("All day" + eentry.AllDayEvent);
-
 			CalComponentDateTime dt = new CalComponentDateTime ();
 			Icaltimetype icalt = new Icaltimetype ();
 			DateTime eventDate = DateTime.Parse (eentry.StartDate);
@@ -171,6 +170,8 @@ namespace SharePoint
 
 				comp.RRules = rrules;
 			}
+
+			Console.WriteLine ("Workspace url " + eentry.WorkspaceLink);
 			comp.Commit ();
 
 			return comp;
@@ -230,6 +231,90 @@ namespace SharePoint
 				return TaskStatus.NotStarted;
 		}
 
+				private icalparameter_role GetIcalRole (RecipientRole role)
+		{
+			switch (role)
+			{
+			case RecipientRole.Optional:
+				return icalparameter_role.OptParticipant;
+			case RecipientRole.Required:
+				return icalparameter_role.ReqParticipant;
+			case RecipientRole.Organizer:
+				return icalparameter_role.Chair;
+			default:
+				return icalparameter_role.None;
+			}
+		}
+
+		private icalparameter_partstat GetIcalPartstat (RecipientStatus status)
+		{
+			switch (status)
+			{
+			case RecipientStatus.Accepted:
+				return icalparameter_partstat.Accepted;
+			case RecipientStatus.Declined:
+				return icalparameter_partstat.Declined;
+			case RecipientStatus.NeedsAction:
+				return icalparameter_partstat.NeedsAction;
+			case RecipientStatus.Tentative:
+				return icalparameter_partstat.Tentative;
+			default:
+				return icalparameter_partstat.None;
+			}
+		}
+
+		
+		private void SetAttendees (Recipient [] recipients, string emailId)
+		{
+			CalComponentAttendee [] attendees = new CalComponentAttendee [recipients.Length];
+
+			Console.WriteLine ("Recipient length " + recipients.Length);
+			int i = 0;
+			foreach (Recipient recipient in recipients)
+			{
+				CalComponentAttendee att = new CalComponentAttendee ();
+
+				att.cn = recipient.Name;
+				att.value = recipient.EmailId;
+				att.role = GetIcalRole (recipient.Role);
+				att.status = GetIcalPartstat (recipient.Status);
+
+				Console.WriteLine ("Adding attendee " + att.cn + " " + att.value);
+
+				if (recipient.Role == RecipientRole.Organizer)
+				{
+					CalComponentOrganizer org = new CalComponentOrganizer ();
+
+					org.cn = recipient.Name;
+					org.Value = recipient.EmailId;
+
+					comp.Organizer = org;
+				}
+
+				if (att.value.Contains (emailId))
+				{
+					comp.SetXProp ("X-SP-ATT-CREATION-DATE", recipient.creationDate);
+				}
+
+				attendees [i] = att;
+				i++;
+			}
+
+			comp.Attendees = attendees;
+		}
+
+		public CalComponent UpdateMeetingDetails (EventEntry mentry, string emailId)
+		{			
+			Recipient [] recipients = mentry.Recipients;
+
+			SetAttendees (recipients, emailId);
+			comp.SetXProp ("X-SP-EVENT-UID", mentry.EventUid);
+			comp.Commit ();
+			comp.Sequence = 1;
+
+			return comp;
+		}
+
 		public CalComponent TaskEntryToComp ()
 		{
 			comp.Uid = tentry.ID;
@@ -313,11 +398,19 @@ namespace SharePoint
 			Icaltimetype icalTime = dt.IcalTime;
 			icalTime.Zone = zone;
 			eentry.StartDate = icalTime.AsDateTimeUtc.ToString ();
-			
-			dt = comp.DtEnd;
-			icalTime = dt.IcalTime;
-			icalTime.Zone = zone;
-			eentry.EndDate = icalTime.AsDateTimeUtc.ToString ();
+
+			if (comp.HasRRules == false)
+			{
+				dt = comp.DtEnd;
+				icalTime = dt.IcalTime;
+				icalTime.Zone = zone;
+				if (comp.IsAllDay != true)
+					eentry.EndDate = icalTime.AsDateTimeUtc.ToString ();
+				else {
+					DateTime end = icalTime.AsDateTimeUtc.AddDays (-1);
+					eentry.EndDate = end.ToString ();
+				}
+			}
 
 			if (String.IsNullOrEmpty (comp.Summary) == false)
 				eentry.Title = comp.Summary;
@@ -344,6 +437,11 @@ namespace SharePoint
 
 				SetCalRecurrenceToEntry (rRule, ref eentry);
 				eentry.EventType = 1;
+
+				string end = comp.GetXProp ("X-SP-RECUR-ENDDATE");
+				long endt = Convert.ToInt64 (end);
+				DateTime endDate = GLibUtil.Unixtime_tToDateTime ((int) endt);
+				eentry.EndDate = endDate.ToString ();
 			}
 
 			return eentry;
diff --git a/calendar/backends/sharepoint/Sharepoint.cs b/calendar/backends/sharepoint/Sharepoint.cs
index 0b4a3e7..e132d3f 100644
--- a/calendar/backends/sharepoint/Sharepoint.cs
+++ b/calendar/backends/sharepoint/Sharepoint.cs
@@ -26,6 +26,7 @@ namespace SharePoint {
 		public CalBackendCache cache;
 		public CalMode mode;
 		public CalBackend backend;
+		public string emailId;
 		public string hostUrl;
 		public string workspaceid;
 		public string folderid;
@@ -102,6 +103,9 @@ namespace SharePoint {
 
 							AccountInfo aInfo =  DaemonConnection.deskIceDaemon.GetDefaultAccountInfo ();
 							hostUrl = aInfo.hostUrl;
+							User user = DaemonConnection.deskIceDaemon.GetCurrentUser ();
+							emailId = user.EmailAddress;
+							Console.WriteLine ("Email id is " + emailId);
 						} catch (Exception ex) 
 						{
 							NotAuthenticatedException nax = new NotAuthenticatedException ();
@@ -130,7 +134,6 @@ namespace SharePoint {
 					return BackendStatus.OtherError;
 				
 				Evolution.Source source = backend.Source;
-				string user = source.GetSourceProperty ("username");
 				workspaceid = source.GetSourceProperty ("workspaceid");
 				folderid = source.GetSourceProperty ("Id");
 
@@ -168,6 +171,9 @@ namespace SharePoint {
 			backend.NotifyReadonly (readOnly);
 			
 			AccountInfo aInfo = DaemonConnection.deskIceDaemon.GetDefaultAccountInfo ();
+			User user = DaemonConnection.deskIceDaemon.GetCurrentUser ();
+			emailId = user.EmailAddress;
+			
 			hostUrl = aInfo.hostUrl;
 		}
 		
@@ -205,7 +211,8 @@ namespace SharePoint {
 
 		public BackendStatus BackendGetCalAddress (out string address)
 		{
-			address = "";
+			address = emailId;
+			
 			return BackendStatus.Success;
 		}
 
@@ -269,7 +276,9 @@ namespace SharePoint {
 
 		public BackendStatus BackendReceiveObjects (string calobj)
 		{
-			return 0;
+			BackendStatus status = absBackend.BackendReceiveObjects (calobj);
+			
+			return status;
 		}
 
 		public BackendStatus BackendSendObjects (string calobj, ref string [] users, out string modifiedObj)
diff --git a/calendar/backends/sharepoint/SharepointAbstractBackend.cs b/calendar/backends/sharepoint/SharepointAbstractBackend.cs
index ca4f6f9..8c94096 100644
--- a/calendar/backends/sharepoint/SharepointAbstractBackend.cs
+++ b/calendar/backends/sharepoint/SharepointAbstractBackend.cs
@@ -23,5 +23,6 @@ namespace SharePoint
 
 		public abstract BackendStatus BackendRemoveObject (string uid, string rid, CalObjModType mod, out string oldObject, 
 		                                                   out string calobj);
+		public abstract BackendStatus BackendReceiveObjects (string calobj);
 	}
 }
\ No newline at end of file
diff --git a/calendar/backends/sharepoint/SharepointCal.cs b/calendar/backends/sharepoint/SharepointCal.cs
index 03137b3..620d9bd 100644
--- a/calendar/backends/sharepoint/SharepointCal.cs
+++ b/calendar/backends/sharepoint/SharepointCal.cs
@@ -8,11 +8,88 @@ namespace SharePoint
 	public class SharePointCalBackend : SharePointAbstractBackend
 	{
 		BackendGroundWorker bgw;
+
+
+		private CalComponentAttendee GetCompAttendee (CalComponentAttendee [] attendees)
+		{
+			foreach (CalComponentAttendee attendee in attendees)
+			{
+				if (String.IsNullOrEmpty (attendee.value) || String.IsNullOrEmpty (spBackend.emailId))
+					continue;
+
+				if (attendee.value.Contains (spBackend.emailId))
+				    return attendee;
+			}
+
+			CalComponentAttendee att = new CalComponentAttendee ();
+			
+			return att;
+		}
+
+		RecipientStatus GetRecipientStatus (icalparameter_partstat stat)
+		{
+			switch (stat)
+			{
+			case icalparameter_partstat.Accepted:
+				return RecipientStatus.Accepted;
+			case icalparameter_partstat.Declined:
+				return RecipientStatus.Declined;
+			case icalparameter_partstat.Tentative:
+				return RecipientStatus.Tentative;
+			default:
+				return RecipientStatus.NeedsAction;
+			}
+		}
 			
 		public SharePointCalBackend (SharePointBackend backend) : base (backend)
 		{
 			bgw = new BackendGroundWorker (spBackend);
 		}
+		
+		public override BackendStatus BackendReceiveObjects (string calobj)
+		{
+			CalComponent comp = new CalComponent (calobj);
+
+			// Check the method and handle VCalendar events
+			
+			CalComponentAttendee [] attendees = comp.Attendees;
+
+			if (attendees.Length <= 0)
+				return BackendStatus.Success;
+
+			CalComponentAttendee att = GetCompAttendee (attendees);
+
+			if (String.IsNullOrEmpty (att.value))
+				return BackendStatus.InvalidObject;
+
+			RecipientStatus status = GetRecipientStatus (att.status);
+
+			if (status == RecipientStatus.NeedsAction)
+				return BackendStatus.Success;
+
+			string url = comp.GetXProp ("X-SP-MEETING-URL");
+			string eventUid = comp.GetXProp ("X-SP-EVENT-UID");
+			string attendeeDateChange = comp.GetXProp ("X-SP-ATT-CREATION-DATE");
+			uint sequence = (uint) comp.Sequence;
+			
+			try {
+				DaemonConnection.deskIceDaemon.SetAttendeeResponse (String.Empty, url, spBackend.emailId, 0, eventUid, sequence,
+			                                                    attendeeDateChange, attendeeDateChange, status);
+				Console.WriteLine ("Status Updated!!");
+				CalComponent cacheComp = spBackend.cache.GetComponent (comp.Uid, comp.RecurId);
+				spBackend.cache.PutComponent (comp);
+				spBackend.backend.NotifyObjectModified (cacheComp.GetAsString (), comp.GetAsString ());
+			}
+			catch (Exception ex)
+			{
+				Console.WriteLine ("Exception in Receive objects " + ex.Message);
+				Console.WriteLine (ex.StackTrace);
+				
+				return BackendStatus.OtherError;
+			}
+
+			return BackendStatus.Success;
+		}
 
 		public override void BackendStartQuery (IntPtr query, string sexp)
 		{
diff --git a/calendar/backends/sharepoint/SharepointTask.cs b/calendar/backends/sharepoint/SharepointTask.cs
index 2e74c31..debe7bb 100644
--- a/calendar/backends/sharepoint/SharepointTask.cs
+++ b/calendar/backends/sharepoint/SharepointTask.cs
@@ -14,6 +14,11 @@ namespace SharePoint
 			bgw = new BackendGroundWorker (spBackend);
 		}
 
+		public override BackendStatus BackendReceiveObjects (string calobj)
+		{
+			return BackendStatus.Success;
+		}
+		
 		public override void BackendStartQuery (IntPtr query, string sexp)
 		{
 			
diff --git a/calendar/backends/sharepoint/sharepoint.userprefs b/calendar/backends/sharepoint/sharepoint.userprefs
index 4b20245..26ddfbd 100644
--- a/calendar/backends/sharepoint/sharepoint.userprefs
+++ b/calendar/backends/sharepoint/sharepoint.userprefs
@@ -1,25 +1,20 @@
 <Properties>
-  <MonoDevelop.Ide.Workbench ActiveDocument="Sharepoint.cs" ctype="Workbench">
+  <MonoDevelop.Ide.Workbench ActiveDocument="ComponentEntry.cs" ctype="Workbench">
     <Files>
-      <File FileName="Welcome" />
-      <File FileName="SharepointTask.cs" Line="104" Column="72" />
-      <File FileName="SharepointCal.cs" Line="31" Column="57" />
-      <File FileName="DaemonConnection.cs" Line="6" Column="21" />
-      <File FileName="ComponentEntry.cs" Line="145" Column="55" />
-      <File FileName="BackGroundWorker.cs" Line="131" Column="1" />
-      <File FileName="Sharepoint.cs" Line="86" Column="6" />
+      <File FileName="BackGroundWorker.cs" Line="1" Column="1" />
+      <File FileName="SharepointCal.cs" Line="130" Column="1" />
+      <File FileName="ComponentEntry.cs" Line="411" Column="39" />
     </Files>
     <Pads>
       <Pad Id="ProjectPad">
         <State expanded="True">
           <Node name="sharepoint" expanded="True">
-            <Node name="References" expanded="True" />
-            <Node name="Sharepoint.cs" selected="True" />
+            <Node name="ComponentEntry.cs" selected="True" />
           </Node>
         </State>
       </Pad>
       <Pad Id="ClassPad">
-        <State expanded="True" />
+        <State expanded="True" selected="True" />
       </Pad>
     </Pads>
   </MonoDevelop.Ide.Workbench>
openSUSE Build Service is sponsored by