Monotone-Parent: f804bb16907aea71d5d796ed9fbcb17689826e71
Monotone-Revision: 75edf160eabb9019f1da0e81ecc9323bf007c389 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2007-04-10T20:39:00 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
parent
ab92bbb4c1
commit
cafc68d11f
|
@ -1,3 +1,11 @@
|
||||||
|
2007-04-10 Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||||
|
|
||||||
|
* OGoContentStore/OCSContactFieldExtractor.m
|
||||||
|
([OCSContactFieldExtractor
|
||||||
|
-extractQuickFieldsFromContent:content]): we no longer accept
|
||||||
|
records in a format other than versit vCard so we can get rid of a
|
||||||
|
lot of code.
|
||||||
|
|
||||||
2007-04-04 Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
2007-04-04 Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||||
|
|
||||||
* UI/Contacts/UIxContactsListView.m ([UIxContactsListView
|
* UI/Contacts/UIxContactsListView.m ([UIxContactsListView
|
||||||
|
|
|
@ -19,29 +19,15 @@
|
||||||
02111-1307, USA.
|
02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <GDLContentStore/GCSFieldExtractor.h>
|
#import <GDLContentStore/GCSFieldExtractor.h>
|
||||||
|
#import <NGCards/NGVCard.h>
|
||||||
|
#import "common.h"
|
||||||
|
|
||||||
@interface OCSContactFieldExtractor : GCSFieldExtractor
|
@interface OCSContactFieldExtractor : GCSFieldExtractor
|
||||||
@end
|
@end
|
||||||
|
|
||||||
#include <NGCards/NGVCard.h>
|
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
@implementation OCSContactFieldExtractor
|
@implementation OCSContactFieldExtractor
|
||||||
|
|
||||||
static NSString *fieldNames[] = {
|
|
||||||
/* quickfield, vCard KVC path */
|
|
||||||
@"givenName", @"n.given",
|
|
||||||
@"cn", @"fn.stringValue",
|
|
||||||
@"sn", @"n.family",
|
|
||||||
@"l", @"preferredAdr.locality",
|
|
||||||
@"mail", @"preferredEMail.stringValue",
|
|
||||||
@"o", @"org.orgnam",
|
|
||||||
@"ou", @"org.orgunit",
|
|
||||||
@"telephoneNumber", @"preferredTel.stringValue",
|
|
||||||
nil, nil
|
|
||||||
};
|
|
||||||
|
|
||||||
- (NSMutableDictionary *) extractQuickFieldsFromVCard: (NGVCard *) vCard
|
- (NSMutableDictionary *) extractQuickFieldsFromVCard: (NGVCard *) vCard
|
||||||
{
|
{
|
||||||
NSMutableDictionary *fields;
|
NSMutableDictionary *fields;
|
||||||
|
@ -50,9 +36,6 @@ static NSString *fieldNames[] = {
|
||||||
NSString *value;
|
NSString *value;
|
||||||
unsigned int max;
|
unsigned int max;
|
||||||
|
|
||||||
if (vCard == nil)
|
|
||||||
return nil;
|
|
||||||
|
|
||||||
fields = [NSMutableDictionary dictionaryWithCapacity: 16];
|
fields = [NSMutableDictionary dictionaryWithCapacity: 16];
|
||||||
|
|
||||||
value = [vCard fn];
|
value = [vCard fn];
|
||||||
|
@ -93,56 +76,23 @@ static NSString *fieldNames[] = {
|
||||||
return fields;
|
return fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSMutableDictionary *)extractQuickFieldsFromVCardString:(NSString *)_str {
|
- (NSMutableDictionary *) extractQuickFieldsFromContent: (NSString *) content
|
||||||
|
{
|
||||||
|
NSMutableDictionary *fields;
|
||||||
NGVCard *vCard;
|
NGVCard *vCard;
|
||||||
|
|
||||||
if ((vCard = [NGVCard parseSingleFromSource: _str]) == nil) {
|
fields = nil;
|
||||||
[self errorWithFormat:@"Could not parse content as a vCard."];
|
if ([content length] > 0
|
||||||
return nil;
|
&& [[content uppercaseString] hasPrefix: @"BEGIN:VCARD"])
|
||||||
}
|
{
|
||||||
|
vCard = [NGVCard parseSingleFromSource: content];
|
||||||
return [self extractQuickFieldsFromVCard: vCard];
|
if (vCard)
|
||||||
}
|
fields = [self extractQuickFieldsFromVCard: vCard];
|
||||||
|
|
||||||
- (NSMutableDictionary *)extractQuickFieldsFromContent:(NSString *)_content {
|
|
||||||
NSMutableDictionary *fields;
|
|
||||||
NSDictionary *plist;
|
|
||||||
unsigned i;
|
|
||||||
|
|
||||||
if ([_content length] == 0)
|
|
||||||
return nil;
|
|
||||||
|
|
||||||
if ([_content hasPrefix:@"BEGIN:VCARD"])
|
|
||||||
return [self extractQuickFieldsFromVCardString:_content];
|
|
||||||
|
|
||||||
// TODO: we want to support vcard storage in the future?!
|
|
||||||
|
|
||||||
if ((plist = [_content propertyList]) == nil) {
|
|
||||||
[self logWithFormat:@"ERROR: could not parse property list content!"];
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (![plist isKindOfClass:[NSDictionary class]]) {
|
|
||||||
[self logWithFormat:@"ERROR: parsed property list is not a dictionary!"];
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
fields = [NSMutableDictionary dictionaryWithCapacity:16];
|
|
||||||
|
|
||||||
/* copy field values to quick record */
|
|
||||||
for (i = 0; fieldNames[i] != nil; i += 2) {
|
|
||||||
NSString *fieldName, *sqlName;
|
|
||||||
id value;
|
|
||||||
|
|
||||||
fieldName = fieldNames[i];
|
|
||||||
sqlName = [fieldName lowercaseString]; /* actually pgsql doesn't care */
|
|
||||||
|
|
||||||
value = [plist objectForKey:fieldName];
|
|
||||||
if ([value isNotNull])
|
|
||||||
[fields setObject:value forKey:sqlName];
|
|
||||||
else
|
else
|
||||||
[fields setObject:[NSNull null] forKey:sqlName];
|
[self errorWithFormat: @"Could not parse content as a vCard."];
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
[self errorWithFormat: @"Content is not a vCard"];
|
||||||
|
|
||||||
return fields;
|
return fields;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue