]> err.no Git - scalable-opengroupware.org/blobdiff - SOGoLogic/SOGoAppointment.m
git-svn-id: http://svn.opengroupware.org/SOGo/trunk@118 d1b88da0-ebda-0310-925b-ed51d...
[scalable-opengroupware.org] / SOGoLogic / SOGoAppointment.m
index d88e1c40191f3fe1c9ea0fa95186edd425ca90b1..91c6c220ac3ecdca71b5411ab342c6895b4fd522 100644 (file)
 #include "SOGoAppointment.h"
 #include <SaxObjC/SaxObjC.h>
 #include <NGiCal/NGiCal.h>
+#include "common.h"
 
+@interface NSDate(UsedPrivates)
+- (NSString *)icalString; // declared in NGiCal
+@end
 
 @implementation SOGoAppointment
 
@@ -51,15 +55,30 @@ static SaxObjectDecoder          *sax   = nil;
 
 - (id)initWithICalString:(NSString *)_iCal {
   if ((self = [self init])) {
+    id root;
+    
     if (parser == nil || sax == nil) {
       [self release];
       return nil;
     }
-        
+
+    /* parse */
+    
     [parser parseFromSource:_iCal];
-    self->calendar = [[sax rootObject] retain];
-    self->event    = [[[self->calendar events] lastObject] retain];
+    root = [[sax rootObject] retain];
     [sax reset];
+
+    /* fill */
+    
+    [self logWithFormat:@"root is: %@", root];
+
+    if ([root isKindOfClass:[iCalEvent class]]) {
+      self->event = root;
+    }
+    else {
+      self->calendar = root;
+      self->event    = [[[self->calendar events] lastObject] retain];
+    }
   }
   return self;
 }
@@ -90,9 +109,15 @@ static SaxObjectDecoder          *sax   = nil;
     /* assume length of 1K - reasonable ? */
     s = [[NSMutableString alloc] initWithCapacity:1024];
     [s appendString:@"BEGIN:VCALENDAR\nMETHOD:REQUEST\nPRODID:"];
-    [s appendString:[self->calendar prodId]];
+    if (self->calendar == nil)
+      [s appendString:@"SOGo/0.9"];
+    else
+      [s appendString:[self->calendar prodId]];
     [s appendString:@"\nVERSION:"];
-    [s appendString:[self->calendar version]];
+    if (self->calendar == nil)
+      [s appendString:@"2.0"];
+    else
+      [s appendString:[(iCalCalendar *)self->calendar version]];
     [s appendString:@"\nBEGIN:VEVENT"];
     [s appendString:@"\nSUMMARY:"];
     [s appendString:[self summary]];