diff --git a/SOPE/NGCards/ChangeLog b/SOPE/NGCards/ChangeLog index a7eb1a4b5..077183427 100644 --- a/SOPE/NGCards/ChangeLog +++ b/SOPE/NGCards/ChangeLog @@ -1,3 +1,8 @@ +2010-07-16 Wolfgang Sourdeau + + * NGVCardPhoto.[hm]: new class module that implement facilities + for handling "PHOTO" tags in vcards. + 2010-06-08 Wolfgang Sourdeau * iCalXMLRenderer.m (-[CardGroup xmlRender]): don't append empty diff --git a/SOPE/NGCards/GNUmakefile b/SOPE/NGCards/GNUmakefile index 3691f5fff..90f75848a 100644 --- a/SOPE/NGCards/GNUmakefile +++ b/SOPE/NGCards/GNUmakefile @@ -57,6 +57,7 @@ libNGCards_HEADER_FILES = \ \ NGVCard.h \ NGVList.h \ + NGVCardPhoto.h \ NGVCardReference.h \ # NGVCardAddress.h \ # NGVCardStrArrayValue.h \ @@ -110,6 +111,7 @@ libNGCards_OBJC_FILES = \ \ NGVCard.m \ NGVList.m \ + NGVCardPhoto.m \ NGVCardReference.m \ NGCardsSaxHandler.m \ # IcalElements.m diff --git a/SOPE/NGCards/NGVCard.m b/SOPE/NGCards/NGVCard.m index 41cb7c2b9..861ef82a3 100644 --- a/SOPE/NGCards/NGVCard.m +++ b/SOPE/NGCards/NGVCard.m @@ -26,6 +26,8 @@ #import "NSArray+NGCards.h" +#import "NGVCardPhoto.h" + #import "NGVCard.h" @implementation NGVCard @@ -79,6 +81,8 @@ || [classTag isEqualToString: @"TITLE"] || [classTag isEqualToString: @"VERSION"]) tagClass = [CardElement class]; + else if ([classTag isEqualToString: @"PHOTO"]) + tagClass = [NGVCardPhoto class]; else tagClass = [super classForTag: classTag]; diff --git a/SOPE/NGCards/NGVCardPhoto.h b/SOPE/NGCards/NGVCardPhoto.h new file mode 100644 index 000000000..0b586cb52 --- /dev/null +++ b/SOPE/NGCards/NGVCardPhoto.h @@ -0,0 +1,41 @@ +/* NGVCardPhoto.h - this file is part of NGCards + * + * Copyright (C) 2010 Inverse inc. + * + * Author: Wolfgang Sourdeau + * + * NGCards is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * NGCards is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with NGCards; see the file COPYING. If not, write to the + * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#ifndef NGVCARDPHOTO_H +#define NGVCARDPHOTO_H + +#import "CardElement.h" + +@class NSData; +@class NSString; + +@interface NGVCardPhoto : CardElement + +- (BOOL) isInline; + +- (NSString *) type; + +- (NSData *) decodedContent; + +@end + +#endif /* NGVCARDPHOTO_H */ diff --git a/SOPE/NGCards/NGVCardPhoto.m b/SOPE/NGCards/NGVCardPhoto.m new file mode 100644 index 000000000..ce00238ec --- /dev/null +++ b/SOPE/NGCards/NGVCardPhoto.m @@ -0,0 +1,78 @@ +/* NGVCardPhoto.m - this file is part of NGCards + * + * Copyright (C) 2010 Inverse inc. + * + * Author: Wolfgang Sourdeau + * + * NGCards is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * NGCards is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with NGCards; see the file COPYING. If not, write to the + * Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#import +#import + +#import +#import + +#import "NGVCardPhoto.h" + +@implementation NGVCardPhoto + +- (BOOL) isInline +{ + return ![[self value: 0 ofAttribute: @"value"] isEqualToString: @"uri"]; +} + +- (NSString *) type +{ + return [[self value: 0 ofAttribute: @"type"] uppercaseString]; +} + +- (NSData *) decodedContent +{ + NSString *encoding, *value; + NSData *decodedContent; + + decodedContent = nil; + + if ([self isInline]) + { + encoding = [[self value: 0 ofAttribute: @"encoding"] uppercaseString]; + if ([encoding isEqualToString: @"B"] + || [encoding isEqualToString: @"BASE64"]) + { + /* We bypass -[values:] because we want to obtain the undecoded + value first. */ + if ([values count] > 0) + { + value = [values objectAtIndex: 0]; + decodedContent = [value dataByDecodingBase64]; + } + else + [self errorWithFormat: @"attempt to decode empty value"]; + } + else + [self errorWithFormat: + @"decoded content requested with an unknown encoding: '%@'", + encoding]; + } + else + [self errorWithFormat: + @"decoded content requested on a PHOTO of type 'uri'"]; + + return decodedContent; +} + +@end