PageRenderTime 96ms CodeModel.GetById 32ms app.highlight 60ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/update-engine/externals/gdata-objectivec-client/Source/Clients/Calendar/GDataEntryEvent.m

http://macfuse.googlecode.com/
Objective C | 318 lines | 223 code | 65 blank | 30 comment | 27 complexity | a0d0337c1cfddec09601b577a760182f MD5 | raw file
  1/* Copyright (c) 2007 Google Inc.
  2*
  3* Licensed under the Apache License, Version 2.0 (the "License");
  4* you may not use this file except in compliance with the License.
  5* You may obtain a copy of the License at
  6*
  7*     http://www.apache.org/licenses/LICENSE-2.0
  8*
  9* Unless required by applicable law or agreed to in writing, software
 10* distributed under the License is distributed on an "AS IS" BASIS,
 11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12* See the License for the specific language governing permissions and
 13* limitations under the License.
 14*/
 15
 16//
 17//  GDataEntryEvent.m
 18//
 19
 20#if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_CALENDAR_SERVICE
 21
 22#define GDATAENTRYEVENT_DEFINE_GLOBALS 1
 23#import "GDataEntryEvent.h"
 24
 25#import "GDataTextConstruct.h"
 26
 27// extensions
 28
 29// EventEntry extensions
 30
 31// These extensions are just subclasses of GDataValueConstruct.
 32// We're creating them as unique subclasses so they can exist
 33// separately in the extensions list, which stores found extensions
 34// by class.
 35
 36@implementation GDataEventStatus
 37+ (NSString *)extensionElementURI       { return kGDataNamespaceGData; }
 38+ (NSString *)extensionElementPrefix    { return kGDataNamespaceGDataPrefix; }
 39+ (NSString *)extensionElementLocalName { return @"eventStatus"; }
 40@end
 41
 42@implementation GDataVisibility
 43+ (NSString *)extensionElementURI       { return kGDataNamespaceGData; }
 44+ (NSString *)extensionElementPrefix    { return kGDataNamespaceGDataPrefix; }
 45+ (NSString *)extensionElementLocalName { return @"visibility"; }
 46@end
 47
 48@implementation GDataTransparency
 49+ (NSString *)extensionElementURI       { return kGDataNamespaceGData; }
 50+ (NSString *)extensionElementPrefix    { return kGDataNamespaceGDataPrefix; }
 51+ (NSString *)extensionElementLocalName { return @"transparency"; }
 52@end
 53
 54// We're defining Reminders as extensions to When elements.
 55// This category on When elements will simpify access to those
 56// reminders that are found inside When elements.
 57
 58@implementation GDataWhen (GDataCalendarEntryEventExtensions)
 59- (NSArray *)reminders {
 60  return [self objectsForExtensionClass:[GDataReminder class]];
 61}
 62
 63- (void)setReminders:(NSArray *)arr {
 64  [self setObjects:arr forExtensionClass:[GDataReminder class]];
 65}
 66
 67- (void)addReminder:(GDataReminder *)obj {
 68  [self addObject:obj forExtensionClass:[GDataReminder class]];
 69}
 70@end
 71
 72@implementation GDataEntryEvent
 73
 74- (void)addExtensionDeclarations {
 75  
 76  [super addExtensionDeclarations];
 77  
 78  Class entryClass = [self class];
 79  
 80  // EventEntry extensions
 81  [self addExtensionDeclarationForParentClass:entryClass
 82                                 childClasses:
 83   [GDataRecurrenceException class], [GDataReminder class],
 84   [GDataRecurrence class], [GDataWhere class],
 85   [GDataEventStatus class], [GDataVisibility class],
 86   [GDataTransparency class], [GDataWho class],
 87   [GDataWhen class], [GDataOriginalEvent class],
 88   [GDataComment class], nil];  
 89  
 90  // a reminder may be at the event entry level (declared above) for
 91  // recurrence events, or inside a GDataWhen for single events
 92  [self addExtensionDeclarationForParentClass:[GDataWhen class]
 93                                   childClass:[GDataReminder class]];  
 94}
 95
 96- (NSString *)suffixAfterPoundSign:(NSString *)str {
 97  if (str != nil) {
 98    NSRange range = [str rangeOfString:@"#" options:NSBackwardsSearch];
 99    if (range.location != NSNotFound) {
100      return [str substringFromIndex:(1 + range.location)];
101    }
102  }
103  return nil;
104}
105
106#if !GDATA_SIMPLE_DESCRIPTIONS
107- (NSMutableArray *)itemsForDescription {
108  
109  NSString *visibility = [self suffixAfterPoundSign:[[self visibility] stringValue]];
110  NSString *transparency = [self suffixAfterPoundSign:[[self transparency] stringValue]];
111  NSString *eventStatus = [self suffixAfterPoundSign:[[self eventStatus] stringValue]];
112
113  NSArray *times = [self times];
114  NSUInteger numberOfTimes = [times count];
115  NSString *timesStr;
116  if (numberOfTimes == 1) {
117    GDataWhen *when = [times objectAtIndex:0];
118    timesStr = [NSString stringWithFormat:@"(%@..%@)",
119                [[when startTime] stringValue], [[when endTime] stringValue]];
120  } else {
121    // just show the number of times, pretty rare
122    timesStr = [NSString stringWithFormat:@"%lu", (unsigned long) numberOfTimes];
123  }
124
125  struct GDataDescriptionRecord descRecs[] = {
126    { @"recurrence",     @"recurrence.stringValue", kGDataDescValueLabeled },
127    { @"visibility",     visibility,                kGDataDescValueIsKeyPath },
128    { @"transparency",   transparency,              kGDataDescValueIsKeyPath },
129    { @"eventStatus",    eventStatus,               kGDataDescValueIsKeyPath },
130    { @"times",          timesStr,                  kGDataDescValueIsKeyPath },
131    { @"recExc",         @"recurrenceExceptions",   kGDataDescArrayCount },
132    { @"reminders",      @"reminders",              kGDataDescArrayCount },
133    { @"comment",        @"comment",                kGDataDescLabelIfNonNil },
134    { nil, nil, (GDataDescRecTypes)0 }
135  };
136  
137  NSMutableArray *items = [super itemsForDescription];
138  [self addDescriptionRecords:descRecs toItems:items];
139  return items;
140}
141#endif
142
143#pragma mark Actual iVars
144
145- (GDataEventStatus *)eventStatus {
146  return (GDataEventStatus *) [self objectForExtensionClass:[GDataEventStatus class]];
147}
148
149- (void)setEventStatus:(GDataEventStatus *)val {
150  [self setObject:val forExtensionClass:[GDataEventStatus class]];
151}
152
153- (GDataTransparency *)transparency {
154  return (GDataTransparency *) [self objectForExtensionClass:[GDataTransparency class]];
155}
156
157- (void)setTransparency:(GDataTransparency *)val {
158  [self setObject:val forExtensionClass:[GDataTransparency class]];
159}
160
161- (GDataVisibility *)visibility {
162  return (GDataVisibility *) [self objectForExtensionClass:[GDataVisibility class]];
163}
164
165- (void)setVisibility:(GDataVisibility *)val {
166  [self setObject:val forExtensionClass:[GDataVisibility class]];
167}
168
169- (GDataRecurrence *)recurrence {
170  return (GDataRecurrence *) [self objectForExtensionClass:[GDataRecurrence class]];
171}
172
173- (void)setRecurrence:(GDataRecurrence *)obj {
174  BOOL hadRecurrence = ([self recurrence] != nil);
175  BOOL willHaveRecurrence = (obj != nil);
176  
177  if (hadRecurrence && !willHaveRecurrence) {
178    [self setNonRecurrenceReminders:[self recurrenceReminders]];
179    [self setRecurrenceReminders:nil];
180  } else if (!hadRecurrence && willHaveRecurrence) {
181    [self setRecurrenceReminders:[self nonRecurrenceReminders]];
182    [self setNonRecurrenceReminders:nil];
183  }
184  
185  [self setObject:obj forExtensionClass:[GDataRecurrence class]];
186}
187
188- (NSArray *)recurrenceExceptions {
189  return [self objectsForExtensionClass:[GDataRecurrenceException class]];
190}
191
192- (void)setRecurrenceExceptions:(NSArray *)arr {
193  [self setObjects:arr forExtensionClass:[GDataRecurrenceException class]];
194}
195
196- (void)addRecurrenceException:(GDataRecurrenceException *)obj {
197  [self addObject:obj forExtensionClass:[obj class]];
198}
199
200- (GDataOriginalEvent *)originalEvent {
201  return (GDataOriginalEvent *) [self objectForExtensionClass:[GDataOriginalEvent class]];
202}
203
204- (void)setOriginalEvent:(GDataOriginalEvent *)obj {
205  [self setObject:obj forExtensionClass:[GDataOriginalEvent class]];
206}
207
208- (GDataComment *)comment {
209  return (GDataComment *) [self objectForExtensionClass:[GDataComment class]];
210}
211
212- (void)setComment:(GDataComment *)obj {
213  [self setObject:obj forExtensionClass:[GDataComment class]];
214}
215
216- (NSArray *)recurrenceReminders {
217    return [self objectsForExtensionClass:[GDataReminder class]];
218}
219
220- (void)setRecurrenceReminders:(NSArray *)array {
221  [self setObjects:array forExtensionClass:[GDataReminder class]];
222}
223
224- (void)addRecurrenceReminder:(GDataReminder *)obj {
225  [self addObject:obj forExtensionClass:[GDataReminder class]];
226}
227
228- (NSArray *)nonRecurrenceReminders {
229  NSArray *whens = [self times];
230  if ([whens count] > 0) {
231    GDataWhen *when = [whens objectAtIndex:0];
232    NSArray *reminders = [when objectsForExtensionClass:[GDataReminder class]];
233    return reminders;
234  }
235  return nil;
236}
237
238- (void)setNonRecurrenceReminders:(NSArray *)array {
239  NSArray *whens = [self times];
240  if ([whens count] > 0) {
241    GDataWhen *when = [whens objectAtIndex:0];
242    [when setReminders:array];
243  }
244}
245
246- (void)addNonRecurrenceReminder:(GDataReminder *)obj {
247  NSArray *whens = [self times];
248  if ([whens count] > 0) {
249    GDataWhen *when = [whens objectAtIndex:0];
250    [when addReminder:obj];
251  } 
252}
253
254- (NSArray *)reminders {
255  if ([self recurrence] != nil) {
256    return [self recurrenceReminders];
257  } else {
258    return [self nonRecurrenceReminders];
259  }
260  return nil;
261}
262
263- (void)setReminders:(NSArray *)array {
264  if ([self recurrence] != nil) {
265    [self setRecurrenceReminders:array];
266  } else {
267    [self setNonRecurrenceReminders:array];
268  }
269}
270
271- (void)addReminder:(GDataReminder *)obj {
272  if ([self recurrence] != nil) {
273    [self addRecurrenceReminder:obj];
274  } else {
275    [self addNonRecurrenceReminder:obj];
276  }
277}
278
279- (NSArray *)times {
280  return [self objectsForExtensionClass:[GDataWhen class]];
281}
282
283- (void)setTimes:(NSArray *)array {
284  [self setObjects:array forExtensionClass:[GDataWhen class]];
285}
286
287- (void)addTime:(GDataWhen *)obj {
288  [self addObject:obj forExtensionClass:[obj class]];
289}
290
291- (NSArray *)participants {
292  return [self objectsForExtensionClass:[GDataWho class]];
293}
294
295- (void)setParticipants:(NSArray *)array {
296  [self setObjects:array forExtensionClass:[GDataWho class]];
297}
298
299- (void)addParticipant:(GDataWho *)obj {
300  [self addObject:obj forExtensionClass:[obj class]];
301}
302
303- (NSArray *)locations {
304  return [self objectsForExtensionClass:[GDataWhere class]];
305}
306
307- (void)setLocations:(NSArray *)array {
308  [self setObjects:array forExtensionClass:[GDataWhere class]];
309}
310
311- (void)addLocation:(GDataWhere *)obj {
312  [self addObject:obj forExtensionClass:[obj class]];
313}
314
315
316@end
317
318#endif // !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_CALENDAR_SERVICE