diff --git a/ChangeLog b/ChangeLog index ff2d45f2d..0c19e1db1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,21 @@ 2010-07-16 Wolfgang Sourdeau + * UI/Contacts/UIxContactEditor.m (-photosURL): copy of the method + below. + + * UI/Contacts/UIxContactView.m (-photosURL): new access that + returns the URL to the photos contained in the VCARD, whether + inline or not. + (-tabSelection): removed unused method. + + * SoObjects/Contacts/SOGoContactGCSEntry.m + (-lookupName:inContext:acquire:): new overriden method to handle + "photoX" lookups and return the corrsponding SOGoContactEntryPhoto + instance, if exists. + + * SoObjects/Contacts/SOGoContactEntryPhoto.[hm]: new controller + class for VCARD PHOTO objects. + * SoObjects/SOGo/SOGoContentObject.m (-davContentLength): fixed a crash occurring with certain versions of GNUstep by using NSISOLatin1StringEncoding instead of UTF8. This is actually the diff --git a/SoObjects/Contacts/GNUmakefile b/SoObjects/Contacts/GNUmakefile index d1d357e47..cbbfa2e0a 100644 --- a/SoObjects/Contacts/GNUmakefile +++ b/SoObjects/Contacts/GNUmakefile @@ -19,6 +19,7 @@ Contacts_OBJC_FILES = \ SOGoContactLDIFEntry.m \ SOGoContactSourceFolder.m \ SOGoUserFolder+Contacts.m \ + SOGoContactEntryPhoto.m \ Contacts_RESOURCE_FILES += \ Version \ diff --git a/SoObjects/Contacts/SOGoContactEntryPhoto.h b/SoObjects/Contacts/SOGoContactEntryPhoto.h new file mode 100644 index 000000000..e35eb2cd7 --- /dev/null +++ b/SoObjects/Contacts/SOGoContactEntryPhoto.h @@ -0,0 +1,42 @@ +/* SOGoContactEntryPhoto.h - this file is part of SOGo + * + * Copyright (C) 2010 Inverse inc. + * + * Author: Wolfgang Sourdeau + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef SOGOCONTACTENTRYPHOTO_H +#define SOGOCONTACTENTRYPHOTO_H + +#import + +@interface SOGoContactEntryPhoto : SOGoObject +{ + int photoID; +} + ++ (id) entryPhotoWithID: (int) photoId + inContainer: (id) container; + +- (void) setPhotoID: (int) newPhotoID; + +- (NSString *) davContentType; + +@end + +#endif /* SOGOCONTACTENTRYPHOTO_H */ diff --git a/SoObjects/Contacts/SOGoContactEntryPhoto.m b/SoObjects/Contacts/SOGoContactEntryPhoto.m new file mode 100644 index 000000000..850ce59f5 --- /dev/null +++ b/SoObjects/Contacts/SOGoContactEntryPhoto.m @@ -0,0 +1,114 @@ +/* SOGoContactEntryPhoto.m - this file is part of SOGo + * + * Copyright (C) 2010 Inverse inc. + * + * Author: Wolfgang Sourdeau + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#import +#import + +#import +#import + +#import +#import + +#import "SOGoContactObject.h" + +#import "SOGoContactEntryPhoto.h" + +@implementation SOGoContactEntryPhoto + ++ (id) entryPhotoWithID: (int) photoID + inContainer: (id) container +{ + id photo; + + photo + = [super objectWithName: [NSString stringWithFormat: @"photo%d", photoID] + inContainer: container]; + [photo setPhotoID: photoID]; + + return photo; +} + +- (void) setPhotoID: (int) newPhotoID +{ + photoID = newPhotoID; +} + +- (NGVCardPhoto *) photo +{ + NGVCardPhoto *photo; + NSArray *photoElements; + + photoElements = [[container vCard] childrenWithTag: @"photo"]; + if ([photoElements count] > photoID) + photo = [photoElements objectAtIndex: photoID]; + else + photo = nil; + + return photo; +} + +- (id) GETAction: (WOContext *) localContext +{ + NGVCardPhoto *photo; + NSData *data; + id response; + + photo = [self photo]; + if ([photo isInline]) + data = [photo decodedContent]; + else + data = [[photo value: 0] dataUsingEncoding: NSISOLatin1StringEncoding]; + if (data) + { + response = [localContext response]; + + [response setHeader: [self davContentType] forKey: @"content-type"]; + [response setHeader: [NSString stringWithFormat:@" %d", + [data length]] + forKey: @"content-length"]; + [response setContent: data]; + } + else + response = nil; + + return response; +} + +- (NSString *) davContentType +{ + NGVCardPhoto *photo; + NSString *type, *contentType; + + photo = [self photo]; + if ([photo isInline]) + { + type = [[photo type] lowercaseString]; + contentType = [NSString stringWithFormat: @"image/%@", type]; + } + else + contentType = @"text/plain"; + + return contentType; +} + +@end diff --git a/SoObjects/Contacts/SOGoContactGCSEntry.m b/SoObjects/Contacts/SOGoContactGCSEntry.m index 73bca8969..22ee70bc0 100644 --- a/SoObjects/Contacts/SOGoContactGCSEntry.m +++ b/SoObjects/Contacts/SOGoContactGCSEntry.m @@ -24,6 +24,8 @@ #import +#import "SOGoContactEntryPhoto.h" + #import "SOGoContactGCSEntry.h" @implementation SOGoContactGCSEntry @@ -62,6 +64,31 @@ /* actions */ +- (id) lookupName: (NSString *) lookupName + inContext: (id) localContext + acquire: (BOOL) acquire +{ + id obj; + int photoIndex; + NSArray *photoElements; + + if ([lookupName hasPrefix: @"photo"]) + { + photoElements = [[self vCard] childrenWithTag: @"photo"]; + photoIndex = [[lookupName substringFromIndex: 5] intValue]; + if (photoIndex > -1 && photoIndex < [photoElements count]) + obj = [SOGoContactEntryPhoto entryPhotoWithID: photoIndex + inContainer: self]; + else + obj = nil; + } + else + obj = [super lookupName: lookupName inContext: localContext + acquire: acquire]; + + return obj; +} + - (NSException *) copyToFolder: (SOGoGCSFolder *) newFolder { NGVCard *newCard; diff --git a/UI/Contacts/BrazilianPortuguese.lproj/Localizable.strings b/UI/Contacts/BrazilianPortuguese.lproj/Localizable.strings index a92fd2183..6391d8dbb 100644 --- a/UI/Contacts/BrazilianPortuguese.lproj/Localizable.strings +++ b/UI/Contacts/BrazilianPortuguese.lproj/Localizable.strings @@ -2,6 +2,7 @@ "Contact" = "Contact"; "Address" = "Address"; +"Photos" = "Photos"; "Other" = "Other"; "Address Books" = "Addressbooks"; diff --git a/UI/Contacts/Czech.lproj/Localizable.strings b/UI/Contacts/Czech.lproj/Localizable.strings index d255bcd6c..e48aded25 100644 --- a/UI/Contacts/Czech.lproj/Localizable.strings +++ b/UI/Contacts/Czech.lproj/Localizable.strings @@ -2,6 +2,7 @@ "Contact" = "Kontakt"; "Address" = "Adresa"; +"Photos" = "Photos"; "Other" = "Ostatní"; "Address Books" = "Složky kontaktů"; diff --git a/UI/Contacts/Dutch.lproj/Localizable.strings b/UI/Contacts/Dutch.lproj/Localizable.strings index 443ba52e1..91c107c8f 100644 --- a/UI/Contacts/Dutch.lproj/Localizable.strings +++ b/UI/Contacts/Dutch.lproj/Localizable.strings @@ -2,6 +2,7 @@ "Contact" = "Contactpersoon"; "Address" = "Adres"; +"Photos" = "Fotos"; "Other" = "Overige"; "Address Books" = "Addressbooks"; diff --git a/UI/Contacts/English.lproj/Localizable.strings b/UI/Contacts/English.lproj/Localizable.strings index 21f365e0d..a7eb56eff 100644 --- a/UI/Contacts/English.lproj/Localizable.strings +++ b/UI/Contacts/English.lproj/Localizable.strings @@ -2,6 +2,7 @@ "Contact" = "Contact"; "Address" = "Address"; +"Photos" = "Photos"; "Other" = "Other"; "Address Books" = "Address Books"; diff --git a/UI/Contacts/French.lproj/Localizable.strings b/UI/Contacts/French.lproj/Localizable.strings index 54638c801..57127b264 100644 --- a/UI/Contacts/French.lproj/Localizable.strings +++ b/UI/Contacts/French.lproj/Localizable.strings @@ -2,6 +2,7 @@ "Contact" = "Contact"; "Address" = "Adresses"; +"Photos" = "Photos"; "Other" = "Informations complémentaires"; "Address Books" = "Carnet d'adresses"; diff --git a/UI/Contacts/German.lproj/Localizable.strings b/UI/Contacts/German.lproj/Localizable.strings index 577a689c8..206cf5a66 100644 --- a/UI/Contacts/German.lproj/Localizable.strings +++ b/UI/Contacts/German.lproj/Localizable.strings @@ -2,6 +2,7 @@ "Contact" = "Kontakt"; "Address" = "Adresse"; +"Photos" = "Fotos"; "Other" = "Sonstiges"; "Address Books" = "Adressbücher"; diff --git a/UI/Contacts/Hungarian.lproj/Localizable.strings b/UI/Contacts/Hungarian.lproj/Localizable.strings index 9f50e784e..c5a87aaca 100644 --- a/UI/Contacts/Hungarian.lproj/Localizable.strings +++ b/UI/Contacts/Hungarian.lproj/Localizable.strings @@ -2,6 +2,7 @@ "Contact" = "Contact"; "Address" = "Address"; +"Photos" = "Photos"; "Other" = "Other"; "Address Books" = "Addressbooks"; diff --git a/UI/Contacts/Italian.lproj/Localizable.strings b/UI/Contacts/Italian.lproj/Localizable.strings index 9af75b49c..16e3d74bd 100644 --- a/UI/Contacts/Italian.lproj/Localizable.strings +++ b/UI/Contacts/Italian.lproj/Localizable.strings @@ -2,6 +2,7 @@ "Contact" = "Contatto"; "Address" = "Indirizzo"; +"Photos" = "Photos"; "Other" = "Altro"; "Address Books" = "Rubrica"; diff --git a/UI/Contacts/Russian.lproj/Localizable.strings b/UI/Contacts/Russian.lproj/Localizable.strings index d3a3de694..41e431a1c 100644 --- a/UI/Contacts/Russian.lproj/Localizable.strings +++ b/UI/Contacts/Russian.lproj/Localizable.strings @@ -1,5 +1,10 @@ /* this file is in UTF-8 format! */ +"Contact" = "Contact"; +"Address" = "Address"; +"Photos" = "Photos"; +"Other" = "Other"; + "Addressbook" = "Адресная книга"; "Addresses" = "Адреса"; "Update" = "Обновить"; diff --git a/UI/Contacts/Spanish.lproj/Localizable.strings b/UI/Contacts/Spanish.lproj/Localizable.strings index 63f440265..ec4787009 100644 --- a/UI/Contacts/Spanish.lproj/Localizable.strings +++ b/UI/Contacts/Spanish.lproj/Localizable.strings @@ -2,6 +2,7 @@ "Contact" = "Contacto"; "Address" = "Dirección"; +"Photos" = "Photos"; "Other" = "Otros datos"; "Address Books" = "Libretas de direcciones"; diff --git a/UI/Contacts/Swedish.lproj/Localizable.strings b/UI/Contacts/Swedish.lproj/Localizable.strings index 2e229fd7d..355a7fc5d 100644 --- a/UI/Contacts/Swedish.lproj/Localizable.strings +++ b/UI/Contacts/Swedish.lproj/Localizable.strings @@ -2,6 +2,7 @@ "Contact" = "Kontakt"; "Address" = "Adress"; +"Photos" = "Photos"; "Other" = "Annat"; "Address Books" = "Adressböcker"; diff --git a/UI/Contacts/UIxContactEditor.h b/UI/Contacts/UIxContactEditor.h index 0d6269818..c66acdc49 100644 --- a/UI/Contacts/UIxContactEditor.h +++ b/UI/Contacts/UIxContactEditor.h @@ -37,6 +37,7 @@ NSString *preferredEmail; NSString *item; NGVCard *card; + NSMutableArray *photosURL; NSMutableDictionary *snapshot; /* contains the values for editing */ SOGoContactFolder *componentAddressBook; } diff --git a/UI/Contacts/UIxContactEditor.m b/UI/Contacts/UIxContactEditor.m index fda3af0d9..43dbd4734 100644 --- a/UI/Contacts/UIxContactEditor.m +++ b/UI/Contacts/UIxContactEditor.m @@ -22,6 +22,7 @@ #import #import +#import #import #import @@ -33,6 +34,7 @@ #import #import +#import #import #import @@ -51,6 +53,7 @@ { snapshot = [[NSMutableDictionary alloc] initWithCapacity: 16]; preferredEmail = nil; + photosURL = nil; } return self; @@ -60,6 +63,7 @@ { [snapshot release]; [preferredEmail release]; + [photosURL release]; [super dealloc]; } @@ -573,6 +577,36 @@ && [super canCreateOrModify]); } +- (NSArray *) photosURL +{ + NSArray *photoElements; + NSURL *soURL; + NSString *baseInlineURL, *photoURL; + NGVCardPhoto *photo; + int count, max; + + if (!photosURL) + { + soURL = [[self clientObject] soURL]; + baseInlineURL = [soURL absoluteString]; + photoElements = [card childrenWithTag: @"photo"]; + max = [photoElements count]; + photosURL = [[NSMutableArray alloc] initWithCapacity: max]; + for (count = 0; count < max; count++) + { + photo = [photoElements objectAtIndex: count]; + if ([photo isInline]) + photoURL = [NSString stringWithFormat: @"%@/photo%d", + baseInlineURL, count]; + else + photoURL = [photo value: 0]; + [photosURL addObject: photoURL]; + } + } + + return photosURL; +} + - (CardElement *) _elementWithTag: (NSString *) tag ofType: (NSString *) type { diff --git a/UI/Contacts/UIxContactView.h b/UI/Contacts/UIxContactView.h index e617b43ad..9f59c49b0 100644 --- a/UI/Contacts/UIxContactView.h +++ b/UI/Contacts/UIxContactView.h @@ -32,6 +32,7 @@ NSArray *phones; CardElement *homeAdr; CardElement *workAdr; + NSMutableArray *photosURL; } - (NSString *) fullName; diff --git a/UI/Contacts/UIxContactView.m b/UI/Contacts/UIxContactView.m index d052c46c6..4a93c16ab 100644 --- a/UI/Contacts/UIxContactView.m +++ b/UI/Contacts/UIxContactView.m @@ -20,30 +20,40 @@ 02111-1307, USA. */ +#import + #import #import #import +#import #import #import #import -#import +#import #import "UIxContactView.h" @implementation UIxContactView -/* accessors */ +- (id) init +{ + if ((self = [super init])) + { + photosURL = nil; + } -- (NSString *)tabSelection { - NSString *selection; - - selection = [self queryParameterForKey:@"tab"]; - if (selection == nil) - selection = @"attributes"; - return selection; + return self; } +- (void) dealloc +{ + [photosURL release]; + [super dealloc]; +} + +/* accessors */ + - (NSString *) _cardStringWithLabel: (NSString *) label value: (NSString *) value { @@ -630,4 +640,34 @@ return self; } +- (NSArray *) photosURL +{ + NSArray *photoElements; + NSURL *soURL; + NSString *baseInlineURL, *photoURL; + NGVCardPhoto *photo; + int count, max; + + if (!photosURL) + { + soURL = [[self clientObject] soURL]; + baseInlineURL = [soURL absoluteString]; + photoElements = [card childrenWithTag: @"photo"]; + max = [photoElements count]; + photosURL = [[NSMutableArray alloc] initWithCapacity: max]; + for (count = 0; count < max; count++) + { + photo = [photoElements objectAtIndex: count]; + if ([photo isInline]) + photoURL = [NSString stringWithFormat: @"%@/photo%d", + baseInlineURL, count]; + else + photoURL = [photo value: 0]; + [photosURL addObject: photoURL]; + } + } + + return photosURL; +} + @end /* UIxContactView */ diff --git a/UI/Contacts/Ukrainian.lproj/Localizable.strings b/UI/Contacts/Ukrainian.lproj/Localizable.strings index fd713fbb5..e6a20b400 100644 --- a/UI/Contacts/Ukrainian.lproj/Localizable.strings +++ b/UI/Contacts/Ukrainian.lproj/Localizable.strings @@ -2,6 +2,7 @@ "Contact" = "Контакт"; "Address" = "Адреса"; +"Photos" = "Photos"; "Other" = "Інше"; "Address Books" = "Адресні книги"; diff --git a/UI/Contacts/Welsh.lproj/Localizable.strings b/UI/Contacts/Welsh.lproj/Localizable.strings index 61cb476e6..c22616c2c 100644 --- a/UI/Contacts/Welsh.lproj/Localizable.strings +++ b/UI/Contacts/Welsh.lproj/Localizable.strings @@ -1,5 +1,10 @@ /* this file is in UTF-8 format! */ +"Contact" = "Contact"; +"Address" = "Address"; +"Photos" = "Photos"; +"Other" = "Other"; + "Addressbook" = "Llyfr cyfeiriadau"; "Addresses" = "Cyfeiriadau"; "Update" = "Diweddaru"; diff --git a/UI/Templates/ContactsUI/UIxContactEditor.wox b/UI/Templates/ContactsUI/UIxContactEditor.wox index ff2b535f5..91360ae76 100644 --- a/UI/Templates/ContactsUI/UIxContactEditor.wox +++ b/UI/Templates/ContactsUI/UIxContactEditor.wox @@ -29,6 +29,8 @@
  • +
  • +
  • @@ -332,6 +334,12 @@ +
    + +
    +
    +
    diff --git a/UI/Templates/ContactsUI/UIxContactView.wox b/UI/Templates/ContactsUI/UIxContactView.wox index 9584b86de..3fe014d9c 100644 --- a/UI/Templates/ContactsUI/UIxContactView.wox +++ b/UI/Templates/ContactsUI/UIxContactView.wox @@ -18,8 +18,10 @@ />
    +