From a9ef1fd0b8c5889245012518e1579ed68a265b7f Mon Sep 17 00:00:00 2001 From: helge Date: Wed, 13 Jul 2005 12:29:35 +0000 Subject: [PATCH] added some convenience methods git-svn-id: http://svn.opengroupware.org/SOPE/trunk@894 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-ical/NGiCal/ChangeLog | 9 +++++++++ sope-ical/NGiCal/NGVCard.h | 9 ++++++++- sope-ical/NGiCal/NGVCard.m | 29 +++++++++++++++++++++++++++++ sope-ical/NGiCal/NGVCardOrg.h | 4 ++++ sope-ical/NGiCal/NGVCardOrg.m | 4 ++++ 5 files changed, 54 insertions(+), 1 deletion(-) diff --git a/sope-ical/NGiCal/ChangeLog b/sope-ical/NGiCal/ChangeLog index 4c0c9e00..0a896ae3 100644 --- a/sope-ical/NGiCal/ChangeLog +++ b/sope-ical/NGiCal/ChangeLog @@ -1,3 +1,12 @@ +2005-07-13 Helge Hess + + * v4.5.48 + + * NGVCard.m: added some convenience methods to access the preferred + email, tel and adr + + * NGVCardOrg.m: added a convenience method to access the first orgunit + 2005-07-05 Marcus Mueller * NSCalendarDate+ICal.m: fixed 'gmtcalfmt' which removed seconds from diff --git a/sope-ical/NGiCal/NGVCard.h b/sope-ical/NGiCal/NGVCard.h index 82e689e1..3f66ff07 100644 --- a/sope-ical/NGiCal/NGVCard.h +++ b/sope-ical/NGiCal/NGVCard.h @@ -56,7 +56,8 @@ */ @class NSString, NSArray, NSDictionary; -@class NGVCardStrArrayValue, NGVCardOrg, NGVCardName; +@class NGVCardStrArrayValue, NGVCardOrg, NGVCardName, NGVCardSimpleValue; +@class NGVCardPhone, NGVCardAddress; @interface NGVCard : NSObject { @@ -153,6 +154,12 @@ - (void)setX:(NSDictionary *)_dict; - (NSDictionary *)x; +/* convenience */ + +- (NGVCardSimpleValue *)preferredEMail; +- (NGVCardPhone *)preferredTel; +- (NGVCardAddress *)preferredAdr; + @end #endif /* __NGiCal_NGVCard_H__ */ diff --git a/sope-ical/NGiCal/NGVCard.m b/sope-ical/NGiCal/NGVCard.m index 783918cf..04849d1c 100644 --- a/sope-ical/NGiCal/NGVCard.m +++ b/sope-ical/NGiCal/NGVCard.m @@ -281,6 +281,35 @@ static NGVCardSaxHandler *sax = nil; // THREAD return self->x; } +/* convenience */ + +- (id)preferredValueInArray:(NSArray *)_values { + unsigned i, count; + + if ((count = [_values count]) == 0) + return nil; + if (count == 1) + return [_values objectAtIndex:0]; + + /* scan for preferred value */ + for (i = 0; i < count; i++) { +#warning COMPLETE ME + } + + /* just take first in sequence */ + return [_values objectAtIndex:0]; +} + +- (NGVCardSimpleValue *)preferredEMail { + return [self preferredValueInArray:self->email]; +} +- (NGVCardPhone *)preferredTel { + return [self preferredValueInArray:self->tel]; +} +- (NGVCardAddress *)preferredAdr { + return [self preferredValueInArray:self->adr]; +} + /* description */ - (void)appendAttributesToDescription:(NSMutableString *)_ms { diff --git a/sope-ical/NGiCal/NGVCardOrg.h b/sope-ical/NGiCal/NGVCardOrg.h index 0dbdfcf5..0f476f47 100644 --- a/sope-ical/NGiCal/NGVCardOrg.h +++ b/sope-ical/NGiCal/NGVCardOrg.h @@ -48,6 +48,10 @@ - (NSString *)orgnam; - (NSArray *)orgunits; +/* convenience */ + +- (NSString *)orgunit; /* returns the first orgunit when available */ + /* values */ - (NSDictionary *)asDictionary; diff --git a/sope-ical/NGiCal/NGVCardOrg.m b/sope-ical/NGiCal/NGVCardOrg.m index fb06c9e8..4acb83e1 100644 --- a/sope-ical/NGiCal/NGVCardOrg.m +++ b/sope-ical/NGiCal/NGVCardOrg.m @@ -59,6 +59,10 @@ return self->orgunits; } +- (NSString *)orgunit { + return [self->orgunits count] > 0 ? [self->orgunits objectAtIndex:0] : nil; +} + /* fake being an array */ - (id)objectAtIndex:(unsigned)_idx { -- 2.39.5