From 110bfdcb4e7e7f4233643c34b42e0470f753d3d9 Mon Sep 17 00:00:00 2001 From: C Robert Date: Thu, 3 Sep 2009 14:18:13 +0000 Subject: [PATCH] Import completed Monotone-Parent: 3ea392b157dc9573c7f8219aa7296cf845c3b081 Monotone-Revision: 80ad9ff70fe3d4130d99bbd2590349b71c85b9f3 Monotone-Author: crobert@inverse.ca Monotone-Date: 2009-09-03T14:18:13 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 4 + .../Localizable.strings | 3 + UI/Contacts/Czech.lproj/Localizable.strings | 3 + UI/Contacts/Dutch.lproj/Localizable.strings | 3 + UI/Contacts/English.lproj/Localizable.strings | 3 + UI/Contacts/French.lproj/Localizable.strings | 3 + UI/Contacts/German.lproj/Localizable.strings | 3 + .../Hungarian.lproj/Localizable.strings | 3 + UI/Contacts/Italian.lproj/Localizable.strings | 3 + UI/Contacts/Russian.lproj/Localizable.strings | 3 + UI/Contacts/Spanish.lproj/Localizable.strings | 3 + UI/Contacts/UIxContactsListView.h | 4 + UI/Contacts/UIxContactsListView.m | 110 +++++++++++++++++- UI/Contacts/Welsh.lproj/Localizable.strings | 3 + UI/Contacts/product.plist | 5 + .../ContactsUI/UIxContactFoldersView.wox | 14 +++ UI/WebServerResources/ContactsUI.js | 32 ++++- UI/WebServerResources/SchedulerUI.css | 38 ------ UI/WebServerResources/generic.css | 38 ++++++ 19 files changed, 238 insertions(+), 40 deletions(-) diff --git a/ChangeLog b/ChangeLog index b273a66ec..e28e3bcf2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2009-09-03 Cyril Robert + + * UI/Contacts/UIxContactsListView.m: Added ldif / vcard import + 2009-09-02 Cyril Robert * UI/Contacts/UIxContactsListView.m (exportAction): Added to support export. diff --git a/UI/Contacts/BrazilianPortuguese.lproj/Localizable.strings b/UI/Contacts/BrazilianPortuguese.lproj/Localizable.strings index 75a5089ac..f17f7ac4d 100644 --- a/UI/Contacts/BrazilianPortuguese.lproj/Localizable.strings +++ b/UI/Contacts/BrazilianPortuguese.lproj/Localizable.strings @@ -180,3 +180,6 @@ "Lists can't be moved or copied." = "Lists can't be moved or copied."; "Export" = "Export"; +"Import cards" = "Import cards"; +"Select file..." = "Select file..."; +"Upload" = "Upload"; diff --git a/UI/Contacts/Czech.lproj/Localizable.strings b/UI/Contacts/Czech.lproj/Localizable.strings index 90f3fc06d..2a5183cfb 100644 --- a/UI/Contacts/Czech.lproj/Localizable.strings +++ b/UI/Contacts/Czech.lproj/Localizable.strings @@ -180,3 +180,6 @@ "Lists can't be moved or copied." = "Lists can't be moved or copied."; "Export" = "Export"; +"Import cards" = "Import cards"; +"Select file..." = "Select file..."; +"Upload" = "Upload"; diff --git a/UI/Contacts/Dutch.lproj/Localizable.strings b/UI/Contacts/Dutch.lproj/Localizable.strings index 5f2fb5eca..df8c96642 100644 --- a/UI/Contacts/Dutch.lproj/Localizable.strings +++ b/UI/Contacts/Dutch.lproj/Localizable.strings @@ -180,3 +180,6 @@ "Lists can't be moved or copied." = "Lists can't be moved or copied."; "Export" = "Export"; +"Import cards" = "Import cards"; +"Select file..." = "Select file..."; +"Upload" = "Upload"; diff --git a/UI/Contacts/English.lproj/Localizable.strings b/UI/Contacts/English.lproj/Localizable.strings index 0236bf267..b6fda56d6 100644 --- a/UI/Contacts/English.lproj/Localizable.strings +++ b/UI/Contacts/English.lproj/Localizable.strings @@ -180,3 +180,6 @@ "Lists can't be moved or copied." = "Lists can't be moved or copied."; "Export" = "Export"; +"Import cards" = "Import cards"; +"Select file..." = "Select file..."; +"Upload" = "Upload"; diff --git a/UI/Contacts/French.lproj/Localizable.strings b/UI/Contacts/French.lproj/Localizable.strings index 564bf1dd4..a56978581 100644 --- a/UI/Contacts/French.lproj/Localizable.strings +++ b/UI/Contacts/French.lproj/Localizable.strings @@ -180,3 +180,6 @@ "Lists can't be moved or copied." = "Les listes ne peuvent pas être déplacées ou copiées."; "Export" = "Exporter"; +"Import cards" = "Importer des contacts"; +"Select file..." = "Sélectionner un fichier..."; +"Upload" = "Ajouter"; diff --git a/UI/Contacts/German.lproj/Localizable.strings b/UI/Contacts/German.lproj/Localizable.strings index dff732128..acae593b8 100644 --- a/UI/Contacts/German.lproj/Localizable.strings +++ b/UI/Contacts/German.lproj/Localizable.strings @@ -180,3 +180,6 @@ "Lists can't be moved or copied." = "Lists can't be moved or copied."; "Export" = "Export"; +"Import cards" = "Import cards"; +"Select file..." = "Select file..."; +"Upload" = "Upload"; diff --git a/UI/Contacts/Hungarian.lproj/Localizable.strings b/UI/Contacts/Hungarian.lproj/Localizable.strings index 2ae8c4ba0..7d7023604 100644 --- a/UI/Contacts/Hungarian.lproj/Localizable.strings +++ b/UI/Contacts/Hungarian.lproj/Localizable.strings @@ -180,3 +180,6 @@ "Lists can't be moved or copied." = "Lists can't be moved or copied."; "Export" = "Export"; +"Import cards" = "Import cards"; +"Select file..." = "Select file..."; +"Upload" = "Upload"; diff --git a/UI/Contacts/Italian.lproj/Localizable.strings b/UI/Contacts/Italian.lproj/Localizable.strings index d4e1fcdee..5927f923d 100644 --- a/UI/Contacts/Italian.lproj/Localizable.strings +++ b/UI/Contacts/Italian.lproj/Localizable.strings @@ -180,3 +180,6 @@ "Lists can't be moved or copied." = "Lists can't be moved or copied."; "Export" = "Export"; +"Import cards" = "Import cards"; +"Select file..." = "Select file..."; +"Upload" = "Upload"; diff --git a/UI/Contacts/Russian.lproj/Localizable.strings b/UI/Contacts/Russian.lproj/Localizable.strings index 33b0838df..e610c1ae3 100644 --- a/UI/Contacts/Russian.lproj/Localizable.strings +++ b/UI/Contacts/Russian.lproj/Localizable.strings @@ -165,3 +165,6 @@ "Lists can't be moved or copied." = "Lists can't be moved or copied."; "Export" = "Export"; +"Import cards" = "Import cards"; +"Select file..." = "Select file..."; +"Upload" = "Upload"; diff --git a/UI/Contacts/Spanish.lproj/Localizable.strings b/UI/Contacts/Spanish.lproj/Localizable.strings index 330aa201c..6efb49792 100644 --- a/UI/Contacts/Spanish.lproj/Localizable.strings +++ b/UI/Contacts/Spanish.lproj/Localizable.strings @@ -180,3 +180,6 @@ "Lists can't be moved or copied." = "Lists can't be moved or copied."; "Export" = "Export"; +"Import cards" = "Import cards"; +"Select file..." = "Select file..."; +"Upload" = "Upload"; diff --git a/UI/Contacts/UIxContactsListView.h b/UI/Contacts/UIxContactsListView.h index 2f6e0bf5e..34bca4593 100644 --- a/UI/Contacts/UIxContactsListView.h +++ b/UI/Contacts/UIxContactsListView.h @@ -35,6 +35,10 @@ NSArray *contactInfos; } +- (void) importLdifData: (NSString *) ldifData; +- (void) importVcardData: (NSString *) vcardData; +- (void) importVcard: (NGVCard *) card; + @end #endif /* __UIxContactsListView_H__ */ diff --git a/UI/Contacts/UIxContactsListView.m b/UI/Contacts/UIxContactsListView.m index beb3ffc31..ff3928e58 100644 --- a/UI/Contacts/UIxContactsListView.m +++ b/UI/Contacts/UIxContactsListView.m @@ -27,6 +27,7 @@ #import #import #import +#import #import #import @@ -37,7 +38,10 @@ #import #import #import +#import #import +#import +#import #import "UIxContactsListView.h" @@ -192,7 +196,7 @@ NSEnumerator *uids; NSString *uid; id currentChild; - id sourceFolder; + SOGoContactGCSFolder *sourceFolder; NSMutableString *content; content = [NSMutableString string]; @@ -223,5 +227,109 @@ return response; } +- (id ) importAction +{ + WORequest *request; + NSData *data; + NSString *fileContent; + + + request = [context request]; + data = (NSData *)[request formValueForKey: @"contactsFile"]; + fileContent = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding]; + [fileContent autorelease]; + + if (fileContent && [fileContent length]) + { + if ([fileContent hasPrefix: @"dn:"]) + [self importLdifData: fileContent]; + else + [self importVcardData: fileContent]; + } + return [self redirectToLocation: @"../view"]; +} + +- (void) importLdifData: (NSString *) ldifData +{ + SOGoContactGCSFolder *folder; + NSString *key, *value; + NSArray *ldifContacts, *lines, *components; + NSMutableDictionary *entry; + NGVCard *vCard; + NSString *uid; + int i,j,count,linesCount; + + folder = [self clientObject]; + ldifContacts = [ldifData componentsSeparatedByString: @"\ndn"]; + count = [ldifContacts count]; + + for (i = 0; i < count; i++) + { + SOGoContactLDIFEntry *ldifEntry; + entry = [NSMutableDictionary dictionary]; + lines = [[ldifContacts objectAtIndex: i] + componentsSeparatedByString: @"\n"]; + + linesCount = [lines count]; + for (j = 0; j < linesCount; j++) + { + components = [[lines objectAtIndex: j] + componentsSeparatedByString: @": "]; + if ([components count] == 2) + { + key = [components objectAtIndex: 0]; + value = [components objectAtIndex: 1]; + + if ([key length] == 0) + key = @"dn"; + + [entry setObject: value forKey: key]; + } + else + { + break; + } + } + uid = [folder globallyUniqueObjectId]; + ldifEntry = [SOGoContactLDIFEntry contactEntryWithName: uid + withLDIFEntry: entry + inContainer: folder]; + if (ldifEntry) + { + vCard = [ldifEntry vCard]; + [self importVcard: vCard]; + + } + } +} + +- (void) importVcardData: (NSString *) vcardData +{ + NGVCard *card; + + card = [NGVCard parseSingleFromSource: vcardData]; + [self importVcard: card]; +} + +- (void) importVcard: (NGVCard *) card +{ + NSString *uid, *name; + SOGoContactGCSFolder *folder; + NSException *ex; + + if (card) + { + folder = [self clientObject]; + uid = [folder globallyUniqueObjectId]; + name = [NSString stringWithFormat: @"%@.vcf", uid]; + [card setUid: uid]; + ex = [[folder ocsFolder] writeContent: [card versitString] + toName: name + baseVersion: 0]; + if (ex) + NSLog (@"write failed: %@", ex); + } +} + @end /* UIxContactsListView */ diff --git a/UI/Contacts/Welsh.lproj/Localizable.strings b/UI/Contacts/Welsh.lproj/Localizable.strings index eeb7c0fdf..194344dc8 100644 --- a/UI/Contacts/Welsh.lproj/Localizable.strings +++ b/UI/Contacts/Welsh.lproj/Localizable.strings @@ -164,3 +164,6 @@ "Lists can't be moved or copied." = "Lists can't be moved or copied."; "Export" = "Export"; +"Import cards" = "Import cards"; +"Select file..." = "Select file..."; +"Upload" = "Upload"; diff --git a/UI/Contacts/product.plist b/UI/Contacts/product.plist index 2114a72ed..70dda492a 100644 --- a/UI/Contacts/product.plist +++ b/UI/Contacts/product.plist @@ -103,6 +103,11 @@ pageName = "UIxContactsListView"; actionName = "export"; }; + import = { + protectedBy = "View"; + pageName = "UIxContactsListView"; + actionName = "import"; + }; userRights = { protectedBy = "ReadAcls"; pageName = "UIxContactsUserRightsEditor"; diff --git a/UI/Templates/ContactsUI/UIxContactFoldersView.wox b/UI/Templates/ContactsUI/UIxContactFoldersView.wox index a6a985fe1..d25761729 100644 --- a/UI/Templates/ContactsUI/UIxContactFoldersView.wox +++ b/UI/Templates/ContactsUI/UIxContactFoldersView.wox @@ -25,6 +25,19 @@ + +