OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "chrome/browser/autofill/autofill_address_model_mac.h" | 5 #import "chrome/browser/autofill/autofill_address_model_mac.h" |
6 #include "app/l10n_util.h" | 6 #include "app/l10n_util.h" |
7 #include "base/sys_string_conversions.h" | 7 #include "base/sys_string_conversions.h" |
8 #include "chrome/browser/autofill/autofill_profile.h" | 8 #include "chrome/browser/autofill/autofill_profile.h" |
9 #include "grit/generated_resources.h" | 9 #include "grit/generated_resources.h" |
10 | 10 |
11 @implementation AutoFillAddressModel | 11 @implementation AutoFillAddressModel |
12 | 12 |
13 @dynamic summary; | |
14 @synthesize label = label_; | 13 @synthesize label = label_; |
15 @synthesize firstName = firstName_; | 14 @synthesize fullName = fullName_; |
16 @synthesize middleName = middleName_; | |
17 @synthesize lastName = lastName_; | |
18 @synthesize email = email_; | 15 @synthesize email = email_; |
19 @synthesize companyName = companyName_; | 16 @synthesize companyName = companyName_; |
20 @synthesize addressLine1 = addressLine1_; | 17 @synthesize addressLine1 = addressLine1_; |
21 @synthesize addressLine2 = addressLine2_; | 18 @synthesize addressLine2 = addressLine2_; |
22 @synthesize addressCity = addressCity_; | 19 @synthesize addressCity = addressCity_; |
23 @synthesize addressState = addressState_; | 20 @synthesize addressState = addressState_; |
24 @synthesize addressZip = addressZip_; | 21 @synthesize addressZip = addressZip_; |
25 @synthesize addressCountry = addressCountry_; | 22 @synthesize addressCountry = addressCountry_; |
26 @synthesize phoneWholeNumber = phoneWholeNumber_; | 23 @synthesize phoneWholeNumber = phoneWholeNumber_; |
27 @synthesize faxWholeNumber = faxWholeNumber_; | 24 @synthesize faxWholeNumber = faxWholeNumber_; |
28 | 25 |
29 // Sets up the KVO dependency between "summary" and dependent fields. | |
30 + (NSSet*)keyPathsForValuesAffectingValueForKey:(NSString*)key { | |
31 NSSet* keyPaths = [super keyPathsForValuesAffectingValueForKey:key]; | |
32 | |
33 if ([key isEqualToString:@"summary"]) { | |
34 NSSet* affectingKeys = | |
35 [NSSet setWithObjects:@"firstName", @"lastName", @"addressLine1", nil]; | |
36 keyPaths = [keyPaths setByAddingObjectsFromSet:affectingKeys]; | |
37 } | |
38 return keyPaths; | |
39 } | |
40 | |
41 - (id)initWithProfile:(const AutoFillProfile&)profile { | 26 - (id)initWithProfile:(const AutoFillProfile&)profile { |
42 if ((self = [super init])) { | 27 if ((self = [super init])) { |
43 [self setLabel:SysUTF16ToNSString(profile.Label())]; | 28 [self setLabel:SysUTF16ToNSString(profile.Label())]; |
44 [self setFirstName:SysUTF16ToNSString( | 29 [self setFullName:SysUTF16ToNSString( |
45 profile.GetFieldText(AutoFillType(NAME_FIRST)))]; | 30 profile.GetFieldText(AutoFillType(NAME_FULL)))]; |
46 [self setMiddleName:SysUTF16ToNSString( | |
47 profile.GetFieldText(AutoFillType(NAME_MIDDLE)))]; | |
48 [self setLastName:SysUTF16ToNSString( | |
49 profile.GetFieldText(AutoFillType(NAME_LAST)))]; | |
50 [self setEmail:SysUTF16ToNSString( | 31 [self setEmail:SysUTF16ToNSString( |
51 profile.GetFieldText(AutoFillType(EMAIL_ADDRESS)))]; | 32 profile.GetFieldText(AutoFillType(EMAIL_ADDRESS)))]; |
52 [self setCompanyName:SysUTF16ToNSString( | 33 [self setCompanyName:SysUTF16ToNSString( |
53 profile.GetFieldText(AutoFillType(COMPANY_NAME)))]; | 34 profile.GetFieldText(AutoFillType(COMPANY_NAME)))]; |
54 [self setAddressLine1:SysUTF16ToNSString( | 35 [self setAddressLine1:SysUTF16ToNSString( |
55 profile.GetFieldText(AutoFillType(ADDRESS_HOME_LINE1)))]; | 36 profile.GetFieldText(AutoFillType(ADDRESS_HOME_LINE1)))]; |
56 [self setAddressLine2:SysUTF16ToNSString( | 37 [self setAddressLine2:SysUTF16ToNSString( |
57 profile.GetFieldText(AutoFillType(ADDRESS_HOME_LINE2)))]; | 38 profile.GetFieldText(AutoFillType(ADDRESS_HOME_LINE2)))]; |
58 [self setAddressCity:SysUTF16ToNSString( | 39 [self setAddressCity:SysUTF16ToNSString( |
59 profile.GetFieldText(AutoFillType(ADDRESS_HOME_CITY)))]; | 40 profile.GetFieldText(AutoFillType(ADDRESS_HOME_CITY)))]; |
60 [self setAddressState:SysUTF16ToNSString( | 41 [self setAddressState:SysUTF16ToNSString( |
61 profile.GetFieldText(AutoFillType(ADDRESS_HOME_STATE)))]; | 42 profile.GetFieldText(AutoFillType(ADDRESS_HOME_STATE)))]; |
62 [self setAddressZip:SysUTF16ToNSString( | 43 [self setAddressZip:SysUTF16ToNSString( |
63 profile.GetFieldText(AutoFillType(ADDRESS_HOME_ZIP)))]; | 44 profile.GetFieldText(AutoFillType(ADDRESS_HOME_ZIP)))]; |
64 [self setAddressCountry:SysUTF16ToNSString( | 45 [self setAddressCountry:SysUTF16ToNSString( |
65 profile.GetFieldText(AutoFillType(ADDRESS_HOME_COUNTRY)))]; | 46 profile.GetFieldText(AutoFillType(ADDRESS_HOME_COUNTRY)))]; |
66 [self setPhoneWholeNumber:SysUTF16ToNSString( | 47 [self setPhoneWholeNumber:SysUTF16ToNSString( |
67 profile.GetFieldText(AutoFillType(PHONE_HOME_WHOLE_NUMBER)))]; | 48 profile.GetFieldText(AutoFillType(PHONE_HOME_WHOLE_NUMBER)))]; |
68 [self setFaxWholeNumber:SysUTF16ToNSString( | 49 [self setFaxWholeNumber:SysUTF16ToNSString( |
69 profile.GetFieldText(AutoFillType(PHONE_FAX_WHOLE_NUMBER)))]; | 50 profile.GetFieldText(AutoFillType(PHONE_FAX_WHOLE_NUMBER)))]; |
70 } | 51 } |
71 return self; | 52 return self; |
72 } | 53 } |
73 | 54 |
74 - (void)dealloc { | 55 - (void)dealloc { |
75 [label_ release]; | 56 [label_ release]; |
76 [firstName_ release]; | 57 [fullName_ release]; |
77 [middleName_ release]; | |
78 [lastName_ release]; | |
79 [email_ release]; | 58 [email_ release]; |
80 [companyName_ release]; | 59 [companyName_ release]; |
81 [addressLine1_ release]; | 60 [addressLine1_ release]; |
82 [addressLine2_ release]; | 61 [addressLine2_ release]; |
83 [addressCity_ release]; | 62 [addressCity_ release]; |
84 [addressState_ release]; | 63 [addressState_ release]; |
85 [addressZip_ release]; | 64 [addressZip_ release]; |
86 [addressCountry_ release]; | 65 [addressCountry_ release]; |
87 [phoneWholeNumber_ release]; | 66 [phoneWholeNumber_ release]; |
88 [faxWholeNumber_ release]; | 67 [faxWholeNumber_ release]; |
89 [super dealloc]; | 68 [super dealloc]; |
90 } | 69 } |
91 | 70 |
92 - (NSString*)summary { | |
93 // Create a temporary |profile| to generate summary string. | |
94 AutoFillProfile profile(string16(), 0); | |
95 [self copyModelToProfile:&profile]; | |
96 return SysUTF16ToNSString(profile.PreviewSummary()); | |
97 } | |
98 | |
99 - (void)copyModelToProfile:(AutoFillProfile*)profile { | 71 - (void)copyModelToProfile:(AutoFillProfile*)profile { |
100 DCHECK(profile); | 72 DCHECK(profile); |
101 profile->set_label(base::SysNSStringToUTF16([self label])); | 73 profile->set_label(base::SysNSStringToUTF16([self label])); |
102 profile->SetInfo(AutoFillType(NAME_FIRST), | 74 profile->SetInfo(AutoFillType(NAME_FULL), |
103 base::SysNSStringToUTF16([self firstName])); | 75 base::SysNSStringToUTF16([self fullName])); |
104 profile->SetInfo(AutoFillType(NAME_MIDDLE), | |
105 base::SysNSStringToUTF16([self middleName])); | |
106 profile->SetInfo(AutoFillType(NAME_LAST), | |
107 base::SysNSStringToUTF16([self lastName])); | |
108 profile->SetInfo(AutoFillType(EMAIL_ADDRESS), | 76 profile->SetInfo(AutoFillType(EMAIL_ADDRESS), |
109 base::SysNSStringToUTF16([self email])); | 77 base::SysNSStringToUTF16([self email])); |
110 profile->SetInfo(AutoFillType(COMPANY_NAME), | 78 profile->SetInfo(AutoFillType(COMPANY_NAME), |
111 base::SysNSStringToUTF16([self companyName])); | 79 base::SysNSStringToUTF16([self companyName])); |
112 profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE1), | 80 profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE1), |
113 base::SysNSStringToUTF16([self addressLine1])); | 81 base::SysNSStringToUTF16([self addressLine1])); |
114 profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE2), | 82 profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE2), |
115 base::SysNSStringToUTF16([self addressLine2])); | 83 base::SysNSStringToUTF16([self addressLine2])); |
116 profile->SetInfo(AutoFillType(ADDRESS_HOME_CITY), | 84 profile->SetInfo(AutoFillType(ADDRESS_HOME_CITY), |
117 base::SysNSStringToUTF16([self addressCity])); | 85 base::SysNSStringToUTF16([self addressCity])); |
118 profile->SetInfo(AutoFillType(ADDRESS_HOME_STATE), | 86 profile->SetInfo(AutoFillType(ADDRESS_HOME_STATE), |
119 base::SysNSStringToUTF16([self addressState])); | 87 base::SysNSStringToUTF16([self addressState])); |
120 profile->SetInfo(AutoFillType(ADDRESS_HOME_ZIP), | 88 profile->SetInfo(AutoFillType(ADDRESS_HOME_ZIP), |
121 base::SysNSStringToUTF16([self addressZip])); | 89 base::SysNSStringToUTF16([self addressZip])); |
122 profile->SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY), | 90 profile->SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY), |
123 base::SysNSStringToUTF16([self addressCountry])); | 91 base::SysNSStringToUTF16([self addressCountry])); |
124 profile->SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER), | 92 profile->SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER), |
125 base::SysNSStringToUTF16([self phoneWholeNumber])); | 93 base::SysNSStringToUTF16([self phoneWholeNumber])); |
126 profile->SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER), | 94 profile->SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER), |
127 base::SysNSStringToUTF16([self faxWholeNumber])); | 95 base::SysNSStringToUTF16([self faxWholeNumber])); |
128 } | 96 } |
129 | 97 |
130 @end | 98 @end |
OLD | NEW |