Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Side by Side Diff: chrome/browser/autofill/autofill_address_model_mac.mm

Issue 558066: Autofill dialog for the Mac. This is UI only at this point. The UI is not h... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "chrome/browser/autofill/autofill_address_model_mac.h"
6 #include "app/l10n_util.h"
7 #include "base/sys_string_conversions.h"
8 #include "chrome/browser/autofill/autofill_profile.h"
9 #include "grit/generated_resources.h"
10
11 @implementation AutoFillAddressModel
12
13 @dynamic summary;
14 @synthesize label = label_;
15 @synthesize firstName = firstName_;
16 @synthesize middleName = middleName_;
17 @synthesize lastName = lastName_;
18 @synthesize email = email_;
19 @synthesize companyName = companyName_;
20 @synthesize addressLine1 = addressLine1_;
21 @synthesize addressLine2 = addressLine2_;
22 @synthesize city = city_;
23 @synthesize state = state_;
24 @synthesize zip = zip_;
25 @synthesize country = country_;
26 @synthesize phoneCountryCode = phoneCountryCode_;
27 @synthesize phoneAreaCode = phoneAreaCode_;
28 @synthesize phoneNumber = phoneNumber_;
29 @synthesize faxCountryCode = faxCountryCode_;
30 @synthesize faxAreaCode = faxAreaCode_;
31 @synthesize faxNumber = faxNumber_;
32
33 // Sets up the KVO dependency between "summary" and dependent fields.
34 + (NSSet*)keyPathsForValuesAffectingValueForKey:(NSString*)key {
35 NSSet* keyPaths = [super keyPathsForValuesAffectingValueForKey:key];
36
37 if ([key isEqualToString:@"summary"]) {
38 NSSet* affectingKeys =
39 [NSSet setWithObjects:@"firstName", @"lastName", @"addressLine1", nil];
40 keyPaths = [keyPaths setByAddingObjectsFromSet:affectingKeys];
41 }
42 return keyPaths;
43 }
44
45 - (id)initWithProfile:(const AutoFillProfile&)profile {
46 if ((self = [super init])) {
47 [self setLabel:SysUTF16ToNSString(profile.Label())];
48 [self setFirstName:SysUTF16ToNSString(
49 profile.GetFieldText(AutoFillType(NAME_FIRST)))];
50 [self setMiddleName:SysUTF16ToNSString(
51 profile.GetFieldText(AutoFillType(NAME_MIDDLE)))];
52 [self setLastName:SysUTF16ToNSString(
53 profile.GetFieldText(AutoFillType(NAME_LAST)))];
54 [self setEmail:SysUTF16ToNSString(
55 profile.GetFieldText(AutoFillType(EMAIL_ADDRESS)))];
56 [self setCompanyName:SysUTF16ToNSString(
57 profile.GetFieldText(AutoFillType(COMPANY_NAME)))];
58 [self setAddressLine1:SysUTF16ToNSString(
59 profile.GetFieldText(AutoFillType(ADDRESS_HOME_LINE1)))];
60 [self setAddressLine2:SysUTF16ToNSString(
61 profile.GetFieldText(AutoFillType(ADDRESS_HOME_LINE2)))];
62 [self setCity:SysUTF16ToNSString(
63 profile.GetFieldText(AutoFillType(ADDRESS_HOME_CITY)))];
64 [self setState:SysUTF16ToNSString(
65 profile.GetFieldText(AutoFillType(ADDRESS_HOME_STATE)))];
66 [self setZip:SysUTF16ToNSString(
67 profile.GetFieldText(AutoFillType(ADDRESS_HOME_ZIP)))];
68 [self setCountry:SysUTF16ToNSString(
69 profile.GetFieldText(AutoFillType(ADDRESS_HOME_COUNTRY)))];
70 [self setPhoneCountryCode:SysUTF16ToNSString(
71 profile.GetFieldText(AutoFillType(PHONE_HOME_COUNTRY_CODE)))];
72 [self setPhoneAreaCode:SysUTF16ToNSString(
73 profile.GetFieldText(AutoFillType(PHONE_HOME_CITY_CODE)))];
74 [self setPhoneNumber:SysUTF16ToNSString(
75 profile.GetFieldText(AutoFillType(PHONE_HOME_NUMBER)))];
76 [self setFaxCountryCode:SysUTF16ToNSString(
77 profile.GetFieldText(AutoFillType(PHONE_FAX_COUNTRY_CODE)))];
78 [self setFaxAreaCode:SysUTF16ToNSString(
79 profile.GetFieldText(AutoFillType(PHONE_FAX_CITY_CODE)))];
80 [self setFaxNumber:SysUTF16ToNSString(
81 profile.GetFieldText(AutoFillType(PHONE_FAX_NUMBER)))];
82 }
83 return self;
84 }
85
86 - (void)dealloc {
87 [label_ release];
88 [firstName_ release];
89 [middleName_ release];
90 [lastName_ release];
91 [email_ release];
92 [companyName_ release];
93 [addressLine1_ release];
94 [addressLine2_ release];
95 [city_ release];
96 [state_ release];
97 [zip_ release];
98 [country_ release];
99 [phoneCountryCode_ release];
100 [phoneAreaCode_ release];
101 [phoneNumber_ release];
102 [faxCountryCode_ release];
103 [faxAreaCode_ release];
104 [faxNumber_ release];
105 [super dealloc];
106 }
107
108 - (NSString*)summary {
109 // Bindings may set these to nil. We normalize here to @"".
110 if (firstName_ == nil)
111 firstName_ = @"";
112 if (lastName_ == nil)
113 lastName_ = @"";
114 if (addressLine1_ == nil)
115 addressLine1_ = @"";
116
117 BOOL haveFirstName = [firstName_ length] > 0;
118 BOOL haveLastName = [lastName_ length] > 0;
119 BOOL haveAddress = [addressLine1_ length] > 0;
120
121 NSString* nameSeparator = (haveFirstName && haveLastName) ?
122 l10n_util::GetNSString(IDS_AUTOFILL_DIALOG_ADDRESS_NAME_SEPARATOR) :
123 @"";
124 NSString* nameFormat =
125 l10n_util::GetNSStringF(IDS_AUTOFILL_DIALOG_ADDRESS_SUMMARY_NAME_FORMAT,
126 base::SysNSStringToUTF16(firstName_),
127 base::SysNSStringToUTF16(nameSeparator),
128 base::SysNSStringToUTF16(lastName_));
129 NSString* summarySeparator = (haveFirstName || haveLastName) && haveAddress ?
130 l10n_util::GetNSString(IDS_AUTOFILL_DIALOG_ADDRESS_SUMMARY_SEPARATOR) :
131 @"";
132 NSString* summaryFormat =
133 l10n_util::GetNSStringF(IDS_AUTOFILL_DIALOG_ADDRESS_SUMMARY_FORMAT,
134 base::SysNSStringToUTF16(nameFormat),
135 base::SysNSStringToUTF16(summarySeparator),
136 base::SysNSStringToUTF16(addressLine1_));
137
138 return summaryFormat;
139 }
140
141 - (void)copyModelToProfile:(AutoFillProfile*)profile {
142 DCHECK(profile);
143 profile->set_label(base::SysNSStringToUTF16([self label]));
144
145 profile->SetInfo(AutoFillType(NAME_FIRST),
146 base::SysNSStringToUTF16([self firstName]));
147 profile->SetInfo(AutoFillType(NAME_MIDDLE),
148 base::SysNSStringToUTF16([self middleName]));
149 profile->SetInfo(AutoFillType(NAME_LAST),
150 base::SysNSStringToUTF16([self lastName]));
151 profile->SetInfo(AutoFillType(EMAIL_ADDRESS),
152 base::SysNSStringToUTF16([self email]));
153 profile->SetInfo(AutoFillType(COMPANY_NAME),
154 base::SysNSStringToUTF16([self companyName]));
155 profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE1),
156 base::SysNSStringToUTF16([self addressLine1]));
157 profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE2),
158 base::SysNSStringToUTF16([self addressLine2]));
159 profile->SetInfo(AutoFillType(ADDRESS_HOME_CITY),
160 base::SysNSStringToUTF16([self city]));
161 profile->SetInfo(AutoFillType(ADDRESS_HOME_STATE),
162 base::SysNSStringToUTF16([self state]));
163 profile->SetInfo(AutoFillType(ADDRESS_HOME_ZIP),
164 base::SysNSStringToUTF16([self zip]));
165 profile->SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY),
166 base::SysNSStringToUTF16([self country]));
167 profile->SetInfo(AutoFillType(PHONE_HOME_COUNTRY_CODE),
168 base::SysNSStringToUTF16([self phoneCountryCode]));
169 profile->SetInfo(AutoFillType(PHONE_HOME_CITY_CODE),
170 base::SysNSStringToUTF16([self phoneAreaCode]));
171 profile->SetInfo(AutoFillType(PHONE_HOME_NUMBER),
172 base::SysNSStringToUTF16([self phoneNumber]));
173 profile->SetInfo(AutoFillType(PHONE_FAX_COUNTRY_CODE),
174 base::SysNSStringToUTF16([self faxCountryCode]));
175 profile->SetInfo(AutoFillType(PHONE_FAX_CITY_CODE),
176 base::SysNSStringToUTF16([self faxAreaCode]));
177 profile->SetInfo(AutoFillType(PHONE_FAX_NUMBER),
178 base::SysNSStringToUTF16([self faxNumber]));
179 }
180
181 @end
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_address_model_mac.h ('k') | chrome/browser/autofill/autofill_address_view_controller_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698