From ec397b39b04e232fbb02039f0a4f9e835fd76e60 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Tue, 30 May 2017 10:38:31 -0400 Subject: [PATCH] (feat) added custom fields support from Thunderbird's address book --- NEWS | 1 + SoObjects/Contacts/NGVCard+SOGo.h | 6 +- SoObjects/Contacts/NGVCard+SOGo.m | 81 +++++++++++++++++++- UI/Contacts/UIxContactEditor.m | 2 +- UI/Contacts/UIxContactView.m | 48 +++++++++++- UI/Templates/ContactsUI/UIxContactEditor.wox | 36 +++++++++ UI/Templates/ContactsUI/UIxContactView.wox | 4 + 7 files changed, 173 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index ed85d7afb..e54b8a6af 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,7 @@ Enhancements - [core] improved event initation for all day events (#4145) - [core] now possible to {un}subscribe to folders using sogo-tool - [eas] added photo support for GAL search operations + - [web] added custom fields support from Thunderbird's address book Bug fixes - [core] fixed calendar component move across collections (#4116) diff --git a/SoObjects/Contacts/NGVCard+SOGo.h b/SoObjects/Contacts/NGVCard+SOGo.h index 512037888..b4025e9c4 100644 --- a/SoObjects/Contacts/NGVCard+SOGo.h +++ b/SoObjects/Contacts/NGVCard+SOGo.h @@ -1,6 +1,6 @@ /* NGVCard+SOGo.h - this file is part of SOGo * - * Copyright (C) 2009-2014 Inverse inc. + * Copyright (C) 2009-2017 Inverse inc. * * 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 @@ -45,6 +45,10 @@ - (NSString *) pager; - (NSCalendarDate *) birthday; +- (void) addElementWithTag: (NSString *) elementTag + ofType: (NSString *) type + withValue: (id) value; + @end #endif /* NGVCARD_SOGO_H */ diff --git a/SoObjects/Contacts/NGVCard+SOGo.m b/SoObjects/Contacts/NGVCard+SOGo.m index d59d91798..e69b6dd17 100644 --- a/SoObjects/Contacts/NGVCard+SOGo.m +++ b/SoObjects/Contacts/NGVCard+SOGo.m @@ -217,9 +217,9 @@ convention: - (void) updateFromLDIFRecord: (NSDictionary *) ldifRecord { NSInteger year, yearOfToday, month, day; + NSArray *units, *elements; CardElement *element; NSCalendarDate *now; - NSArray *units; NSString *fn, *ou; id o; @@ -320,6 +320,43 @@ convention: else [self setCategories: [o componentsSeparatedByString: @","]]; + // Custom fields from Thunderbird + if ((o = [ldifRecord objectForKey: @"custom1"])) + { + elements = [self childrenWithTag: @"custom1"]; + [self removeChildren: elements]; + + if ([o length]) + [self addElementWithTag: @"custom1" ofType: nil withValue: o]; + } + + if ((o = [ldifRecord objectForKey: @"custom2"])) + { + elements = [self childrenWithTag: @"custom2"]; + [self removeChildren: elements]; + + if ([o length]) + [self addElementWithTag: @"custom2" ofType: nil withValue: o]; + } + + if ((o = [ldifRecord objectForKey: @"custom3"])) + { + elements = [self childrenWithTag: @"custom3"]; + [self removeChildren: elements]; + + if ([o length]) + [self addElementWithTag: @"custom3" ofType: nil withValue: o]; + } + + if ((o = [ldifRecord objectForKey: @"custom4"])) + { + elements = [self childrenWithTag: @"custom4"]; + [self removeChildren: elements]; + + if ([o length]) + [self addElementWithTag: @"custom4" ofType: nil withValue: o]; + } + [self cleanupEmptyChildren]; } @@ -646,6 +683,19 @@ convention: dn = @""; [ldifRecord setObject: dn forKey: @"dn"]; + // Custom fields from Thunderbird + if ((stringValue = [[self uniqueChildWithTag: @"custom1"] flattenedValuesForKey: @""]) && [stringValue length]) + [ldifRecord setObject: stringValue forKey: @"custom1"]; + + if ((stringValue = [[self uniqueChildWithTag: @"custom2"] flattenedValuesForKey: @""]) && [stringValue length]) + [ldifRecord setObject: stringValue forKey: @"custom2"]; + + if ((stringValue = [[self uniqueChildWithTag: @"custom3"] flattenedValuesForKey: @""]) && [stringValue length]) + [ldifRecord setObject: stringValue forKey: @"custom3"]; + + if ((stringValue = [[self uniqueChildWithTag: @"custom4"] flattenedValuesForKey: @""]) && [stringValue length]) + [ldifRecord setObject: stringValue forKey: @"custom4"]; + return ldifRecord; } @@ -871,4 +921,33 @@ convention: return fields; } +- (void) addElementWithTag: (NSString *) elementTag + ofType: (NSString *) type + withValue: (id) value +{ + NSArray *allValues; + NSEnumerator *list; + CardElement *element; + + // value is either an array or a string + if ([value isKindOfClass: [NSString class]]) + allValues = [NSArray arrayWithObject: value]; + else + allValues = value; + + // Add all values as separate elements + list = [allValues objectEnumerator]; + while ((value = [list nextObject])) + { + if ([type length]) + element = [CardElement simpleElementWithTag: elementTag + singleType: type + value: value]; + else + element = [CardElement simpleElementWithTag: elementTag + value: value]; + [self addChild: element]; + } +} + @end /* NGVCard */ diff --git a/UI/Contacts/UIxContactEditor.m b/UI/Contacts/UIxContactEditor.m index 418945337..12603e982 100644 --- a/UI/Contacts/UIxContactEditor.m +++ b/UI/Contacts/UIxContactEditor.m @@ -1,6 +1,6 @@ /* Copyright (C) 2004-2005 SKYRIX Software AG - Copyright (C) 2005-2015 Inverse inc. + Copyright (C) 2005-2017 Inverse inc. This file is part of SOGo diff --git a/UI/Contacts/UIxContactView.m b/UI/Contacts/UIxContactView.m index 10fd1725a..9f8b7e181 100644 --- a/UI/Contacts/UIxContactView.m +++ b/UI/Contacts/UIxContactView.m @@ -1,6 +1,6 @@ /* Copyright (C) 2004 SKYRIX Software AG - Copyright (C) 2005-2015 Inverse inc. + Copyright (C) 2005-2017 Inverse inc. This file is part of SOGo. @@ -573,11 +573,55 @@ return [self _urlOfType: @"work"]; } +- (NSString *) custom1 +{ + NSString *value; + + value = [[card uniqueChildWithTag: @"custom1"] flattenedValuesForKey: @""]; + value = [value stringByEscapingHTMLString]; + + return [self _cardStringWithLabel: @"Custom 1" value: value]; +} + +- (NSString *) custom2 +{ + NSString *value; + + value = [[card uniqueChildWithTag: @"custom2"] flattenedValuesForKey: @""]; + value = [value stringByEscapingHTMLString]; + + return [self _cardStringWithLabel: @"Custom 2" value: value]; +} + +- (NSString *) custom3 +{ + NSString *value; + + value = [[card uniqueChildWithTag: @"custom3"] flattenedValuesForKey: @""]; + value = [value stringByEscapingHTMLString]; + + return [self _cardStringWithLabel: @"Custom 3" value: value]; +} + +- (NSString *) custom4 +{ + NSString *value; + + value = [[card uniqueChildWithTag: @"custom4"] flattenedValuesForKey: @""]; + value = [value stringByEscapingHTMLString]; + + return [self _cardStringWithLabel: @"Custom 4" value: value]; +} + - (BOOL) hasOtherInfos { return ([[card note] length] > 0 || [[card bday] length] > 0 - || [[card tz] length] > 0); + || [[card tz] length] > 0 + || [[[card uniqueChildWithTag: @"custom1"] flattenedValuesForKey: @""] length] > 0 + || [[[card uniqueChildWithTag: @"custom1"] flattenedValuesForKey: @""] length] > 0 + || [[[card uniqueChildWithTag: @"custom1"] flattenedValuesForKey: @""] length] > 0 + || [[[card uniqueChildWithTag: @"custom1"] flattenedValuesForKey: @""] length] > 0); } - (NSString *) bday diff --git a/UI/Templates/ContactsUI/UIxContactEditor.wox b/UI/Templates/ContactsUI/UIxContactEditor.wox index 5032708fc..7510db633 100644 --- a/UI/Templates/ContactsUI/UIxContactEditor.wox +++ b/UI/Templates/ContactsUI/UIxContactEditor.wox @@ -377,6 +377,42 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/UI/Templates/ContactsUI/UIxContactView.wox b/UI/Templates/ContactsUI/UIxContactView.wox index 9f216b09b..fa2337592 100644 --- a/UI/Templates/ContactsUI/UIxContactView.wox +++ b/UI/Templates/ContactsUI/UIxContactView.wox @@ -48,6 +48,10 @@