From f4475e7c75affb503be0da3bae997034bdb6c09b Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Mon, 5 Jul 2010 02:06:01 +0000 Subject: [PATCH] See ChangeLog Monotone-Parent: b552fe5364e08d96c08f86ef6b0a3adad28f6b28 Monotone-Revision: b4016357467b1b77091ccbf1b0179dcad63f8843 Monotone-Author: ludovic@Sophos.ca Monotone-Date: 2010-07-05T02:06:01 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 6 +++++ UI/Contacts/UIxContactEditor.m | 47 ++++++++++++++++++++++++---------- UI/Contacts/UIxContactView.m | 34 ++++++++++++++++++------ 3 files changed, 65 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 45c9763cb..ed60d605e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-07-04 Ludovic Marcotte + + * In the Contacts module, we prioritize the + WORK number while excluding the FAX one in case + we see the latter before the former. + 2010-07-01 Ludovic Marcotte * In the Contacts module, improved the label diff --git a/UI/Contacts/UIxContactEditor.m b/UI/Contacts/UIxContactEditor.m index 73b8c8d07..8702f268d 100644 --- a/UI/Contacts/UIxContactEditor.m +++ b/UI/Contacts/UIxContactEditor.m @@ -257,16 +257,33 @@ - (NSString *) _simpleValueForType: (NSString *) aType inArray: (NSArray *) anArray + excluding: (NSString *) aTypeToExclude { NSArray *elements; NSString *value; elements = [anArray cardElementsWithAttribute: @"type" havingValue: aType]; + + value = nil; + if ([elements count] > 0) - value = [[elements objectAtIndex: 0] value: 0]; - else - value = nil; + { + CardElement *ce; + int i; + + for (i = 0; i < [elements count]; i++) + { + ce = [elements objectAtIndex: i]; + value = [ce value: 0]; + + if (!aTypeToExclude) + break; + + if (![ce hasAttribute: @"type" havingValue: aTypeToExclude]) + break; + } + } return value; } @@ -280,11 +297,11 @@ elements = [card childrenWithTag: @"email"]; max = [elements count]; workMail = [self _simpleValueForType: @"work" - inArray: elements]; + inArray: elements excluding: nil]; homeMail = [self _simpleValueForType: @"home" - inArray: elements]; + inArray: elements excluding: nil]; prefMail = [self _simpleValueForType: @"pref" - inArray: elements]; + inArray: elements excluding: nil]; if (max > 0) { @@ -390,16 +407,18 @@ [self _setSnapshotValue: @"nickname" to: [card nickname]]; elements = [card childrenWithTag: @"tel"]; + // We do this (exclude FAX) in order to avoid setting the WORK number as the FAX + // one if we do see the FAX field BEFORE the WORK number. [self _setSnapshotValue: @"telephoneNumber" - to: [self _simpleValueForType: @"work" inArray: elements]]; + to: [self _simpleValueForType: @"work" inArray: elements excluding: @"fax"]]; [self _setSnapshotValue: @"homeTelephoneNumber" - to: [self _simpleValueForType: @"home" inArray: elements]]; + to: [self _simpleValueForType: @"home" inArray: elements excluding: nil]]; [self _setSnapshotValue: @"mobile" - to: [self _simpleValueForType: @"cell" inArray: elements]]; + to: [self _simpleValueForType: @"cell" inArray: elements excluding: nil]]; [self _setSnapshotValue: @"facsimileTelephoneNumber" - to: [self _simpleValueForType: @"fax" inArray: elements]]; + to: [self _simpleValueForType: @"fax" inArray: elements excluding: nil]]; [self _setSnapshotValue: @"pager" - to: [self _simpleValueForType: @"pager" inArray: elements]]; + to: [self _simpleValueForType: @"pager" inArray: elements excluding: nil]]; // If we don't have a "home" and "work" phone number but // we have a "voice" one defined, we set it to the "work" value @@ -420,7 +439,7 @@ [elements count] > 0) { [self _setSnapshotValue: @"telephoneNumber" - to: [self _simpleValueForType: @"voice" inArray: elements]]; + to: [self _simpleValueForType: @"voice" inArray: elements excluding: nil]]; } [self _setupEmailFields]; @@ -468,9 +487,9 @@ elements = [card childrenWithTag: @"url"]; [self _setSnapshotValue: @"workURL" - to: [self _simpleValueForType: @"work" inArray: elements]]; + to: [self _simpleValueForType: @"work" inArray: elements excluding: nil]]; [self _setSnapshotValue: @"homeURL" - to: [self _simpleValueForType: @"home" inArray: elements]]; + to: [self _simpleValueForType: @"home" inArray: elements excluding: nil]]; // If we don't have a "work" or "home" URL but we still have // an URL field present, let's add it to the "home" value diff --git a/UI/Contacts/UIxContactView.m b/UI/Contacts/UIxContactView.m index de7f8c3b1..dde492ca3 100644 --- a/UI/Contacts/UIxContactView.m +++ b/UI/Contacts/UIxContactView.m @@ -189,6 +189,7 @@ - (NSString *) _phoneOfType: (NSString *) aType withLabel: (NSString *) aLabel + excluding: (NSString *) aTypeToExclude { NSArray *elements; NSString *phone; @@ -196,37 +197,54 @@ elements = [phones cardElementsWithAttribute: @"type" havingValue: aType]; + phone = nil; + if ([elements count] > 0) - phone = [[elements objectAtIndex: 0] value: 0]; - else - phone = nil; + { + CardElement *ce; + int i; + + for (i = 0; i < [elements count]; i++) + { + ce = [elements objectAtIndex: i]; + phone = [ce value: 0]; + + if (!aTypeToExclude) + break; + + if (![ce hasAttribute: @"type" havingValue: aTypeToExclude]) + break; + } + } return [self _cardStringWithLabel: aLabel value: phone]; } - (NSString *) workPhone { - return [self _phoneOfType: @"work" withLabel: @"Work:"]; + // We do this (exclude FAX) in order to avoid setting the WORK number as the FAX + // one if we do see the FAX field BEFORE the WORK number. + return [self _phoneOfType: @"work" withLabel: @"Work:" excluding: @"fax"]; } - (NSString *) homePhone { - return [self _phoneOfType: @"home" withLabel: @"Home:"]; + return [self _phoneOfType: @"home" withLabel: @"Home:" excluding: nil]; } - (NSString *) fax { - return [self _phoneOfType: @"fax" withLabel: @"Fax:"]; + return [self _phoneOfType: @"fax" withLabel: @"Fax:" excluding: nil]; } - (NSString *) mobile { - return [self _phoneOfType: @"cell" withLabel: @"Mobile:"]; + return [self _phoneOfType: @"cell" withLabel: @"Mobile:" excluding: nil]; } - (NSString *) pager { - return [self _phoneOfType: @"pager" withLabel: @"Pager:"]; + return [self _phoneOfType: @"pager" withLabel: @"Pager:" excluding: nil]; } - (BOOL) hasHomeInfos