From b1ded04912eecd8b1f4a34f9fc402c8abba574f7 Mon Sep 17 00:00:00 2001 From: "alqahira%ardisson.org" Date: Fri, 12 Dec 2008 03:15:07 +0000 Subject: [PATCH] Bug 384691 - Bookmarks from Apple Address Book should display company / organization where Company option is selected and Bug 462785 - Address Book smart folder builds 'Name' field in non-localized way. Patch by Chris Lawson , r=hendy, sr=smorgan git-svn-id: svn://10.0.0.236/trunk@255503 18797224-902f-48f8-a5cc-f745e15eee43 --- .../English.lproj/Localizable.strings.in | 6 +++ .../camino/src/bookmarks/AddressBookManager.m | 52 ++++++++++++++----- 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/mozilla/camino/resources/localized/English.lproj/Localizable.strings.in b/mozilla/camino/resources/localized/English.lproj/Localizable.strings.in index 80eebea9864..90f06a25776 100644 --- a/mozilla/camino/resources/localized/English.lproj/Localizable.strings.in +++ b/mozilla/camino/resources/localized/English.lproj/Localizable.strings.in @@ -360,6 +360,12 @@ "Updated Bookmarks" = "Updated Bookmarks"; "Rendezvous" = "Bonjour"; "Address Book" = "Address Book"; +/* Used when no person name is found for an Address Book smart bookmark */ +"" = ""; +/* Used when no company name is found for an Address Book smart bookmark based on a Company card */ +"" = ""; +/* Used for a Company card that has a person's name associated with it (e.g. "Google (John Doe)") */ +"CompanyCardWithPersonNameFormat" = "%1$@ (%2$@)"; /*Bookmark context menus*/ "Open in New Window" = "Open in New Window"; diff --git a/mozilla/camino/src/bookmarks/AddressBookManager.m b/mozilla/camino/src/bookmarks/AddressBookManager.m index 435e6a73fbf..e81aeba4de1 100644 --- a/mozilla/camino/src/bookmarks/AddressBookManager.m +++ b/mozilla/camino/src/bookmarks/AddressBookManager.m @@ -76,33 +76,61 @@ [mAddressBookFolder deleteChild:[mAddressBookFolder objectAtIndex:0]]; // fill address book with people. could probably do this smarter, // but it's a start for now. - ABAddressBook *ab = [ABAddressBook sharedAddressBook]; - NSEnumerator *peopleEnumerator = [[ab people] objectEnumerator]; + ABAddressBook* ab = [ABAddressBook sharedAddressBook]; + NSEnumerator* peopleEnumerator = [[ab people] objectEnumerator]; ABPerson* person; - NSString *name = nil, *homepage = nil; while ((person = [peopleEnumerator nextObject])) { - // |kABHomePageProperty| is depricated on Tiger, look for the new property first and then - // the old one (as the old one is present but no longer updated by ABook). + // |kABHomePageProperty| is deprecated on Tiger. Look for the new property first and then + // the old one (as the old one is still present, just no longer updated). ABMultiValue* urls = [person valueForProperty:kABURLsProperty]; - homepage = [urls valueAtIndex:[urls indexForIdentifier:[urls primaryIdentifier]]]; + NSString* homepage = [urls valueAtIndex:[urls indexForIdentifier:[urls primaryIdentifier]]]; if (!homepage) homepage = [person valueForProperty:kABHomePageProperty]; if ([homepage length] > 0) { + NSString* name = nil; NSString* firstName = [person valueForProperty:kABFirstNameProperty]; NSString* lastName = [person valueForProperty:kABLastNameProperty]; + if (firstName || lastName) { if (!firstName) name = lastName; else if (!lastName) name = firstName; - else - name = [NSString stringWithFormat:@"%@ %@", firstName, lastName]; + else { + // Build the name string in a l10n-friendly manner: respect the name ordering flag if present, + // or use the Address Book's default pref otherwise. + int nameOrderFlag = [[person valueForProperty:kABPersonFlags] intValue] & kABNameOrderingMask; + if (nameOrderFlag == kABDefaultNameOrdering) + nameOrderFlag = [ab defaultNameOrdering]; + + if (nameOrderFlag == kABLastNameFirst) + name = [NSString stringWithFormat:@"%@ %@", lastName, firstName]; + else // Default to the standard in the English-speaking world. + name = [NSString stringWithFormat:@"%@ %@", firstName, lastName]; + } } - else { - name = [person valueForProperty:kABOrganizationProperty]; - if (!name) - name = NSLocalizedString(@"", nil); + + int personShowAsFlag = [[person valueForProperty:kABPersonFlags] intValue] & kABShowAsMask; + + if (personShowAsFlag == kABShowAsCompany) { + NSString* company = [person valueForProperty:kABOrganizationProperty]; + if (!company) + company = NSLocalizedString(@"", nil); + + if (name) { + name = [NSString stringWithFormat:NSLocalizedString(@"CompanyCardWithPersonNameFormat", @""), + company, + name]; + } + else { + name = [NSString stringWithFormat:@"%@", company]; + } } + + // We ought to have something by now, but if not, use the placeholder. + if (!name) + name = NSLocalizedString(@"", nil); + [mAddressBookFolder appendChild:[Bookmark bookmarkWithTitle:name url:homepage lastVisit:nil]];