Chromium Code Reviews| 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 #include "chrome/browser/autofill/autofill_dialog.h" | 5 #include "chrome/browser/autofill/autofill_dialog.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include <string> | |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "app/l10n_util.h" | 12 #include "app/l10n_util.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 14 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/browser/autofill/autofill_manager.h" | 16 #include "chrome/browser/autofill/autofill_manager.h" |
| 16 #include "chrome/browser/autofill/autofill_profile.h" | 17 #include "chrome/browser/autofill/autofill_profile.h" |
| 17 #include "chrome/browser/autofill/credit_card.h" | 18 #include "chrome/browser/autofill/credit_card.h" |
| 18 #include "chrome/browser/autofill/form_group.h" | 19 #include "chrome/browser/autofill/form_group.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 36 // The name of the object property used to store an entry widget pointer on | 37 // The name of the object property used to store an entry widget pointer on |
| 37 // another widget. | 38 // another widget. |
| 38 const char kButtonDataKey[] = "label-entry"; | 39 const char kButtonDataKey[] = "label-entry"; |
| 39 | 40 |
| 40 // How far we indent dialog widgets, in pixels. | 41 // How far we indent dialog widgets, in pixels. |
| 41 const int kAutoFillDialogIndent = 5; | 42 const int kAutoFillDialogIndent = 5; |
| 42 | 43 |
| 43 // The resource id for the 'Learn more' link button. | 44 // The resource id for the 'Learn more' link button. |
| 44 const gint kAutoFillDialogLearnMoreLink = 1; | 45 const gint kAutoFillDialogLearnMoreLink = 1; |
| 45 | 46 |
| 46 // All of these widgets are GtkEntrys except for default_profile, which is a | 47 // All of these widgets are GtkEntrys. |
| 47 // GtkCheckButton. | |
| 48 typedef struct _AddressWidgets { | 48 typedef struct _AddressWidgets { |
| 49 GtkWidget* label; | 49 GtkWidget* label; |
| 50 GtkWidget* default_profile; | |
| 51 GtkWidget* first_name; | 50 GtkWidget* first_name; |
| 52 GtkWidget* middle_name; | 51 GtkWidget* middle_name; |
| 53 GtkWidget* last_name; | 52 GtkWidget* last_name; |
| 54 GtkWidget* email; | 53 GtkWidget* email; |
| 55 GtkWidget* company_name; | 54 GtkWidget* company_name; |
| 56 GtkWidget* address_line1; | 55 GtkWidget* address_line1; |
| 57 GtkWidget* address_line2; | 56 GtkWidget* address_line2; |
| 58 GtkWidget* city; | 57 GtkWidget* city; |
| 59 GtkWidget* state; | 58 GtkWidget* state; |
| 60 GtkWidget* zipcode; | 59 GtkWidget* zipcode; |
| 61 GtkWidget* country; | 60 GtkWidget* country; |
| 62 GtkWidget* phone; | 61 GtkWidget* phone; |
| 63 GtkWidget* fax; | 62 GtkWidget* fax; |
| 64 } AddressWidgets; | 63 } AddressWidgets; |
| 65 | 64 |
| 66 // All of these widgets are GtkEntrys except for default_profile, which is a | 65 // All of these widgets are GtkEntrys except for |billing_address|, which is |
| 67 // GtkCheckButton, and billing/shipping_address are GtkComboBoxes. | 66 // a GtkComboBox. |
| 68 typedef struct _CreditCardWidgets { | 67 typedef struct _CreditCardWidgets { |
| 69 GtkWidget* label; | 68 GtkWidget* label; |
| 70 GtkWidget* default_creditcard; | |
| 71 GtkWidget* name_on_card; | 69 GtkWidget* name_on_card; |
| 72 GtkWidget* card_number; | 70 GtkWidget* card_number; |
| 73 GtkWidget* expiration_month; | 71 GtkWidget* expiration_month; |
| 74 GtkWidget* expiration_year; | 72 GtkWidget* expiration_year; |
| 75 GtkWidget* verification_code; | 73 GtkWidget* verification_code; |
| 76 GtkWidget* billing_address; | 74 GtkWidget* billing_address; |
| 77 GtkWidget* shipping_address; | |
| 78 GtkWidget* phone; | 75 GtkWidget* phone; |
| 79 string16 original_card_number; | 76 string16 original_card_number; |
| 80 } CreditCardWidgets; | 77 } CreditCardWidgets; |
| 81 | 78 |
| 82 // Adds an alignment around |widget| which indents the widget by |offset|. | 79 // Adds an alignment around |widget| which indents the widget by |offset|. |
| 83 GtkWidget* IndentWidget(GtkWidget* widget, int offset) { | 80 GtkWidget* IndentWidget(GtkWidget* widget, int offset) { |
| 84 GtkWidget* alignment = gtk_alignment_new(0, 0, 0, 0); | 81 GtkWidget* alignment = gtk_alignment_new(0, 0, 0, 0); |
| 85 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 0, 0, | 82 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 0, 0, |
| 86 offset, 0); | 83 offset, 0); |
| 87 gtk_container_add(GTK_CONTAINER(alignment), widget); | 84 gtk_container_add(GTK_CONTAINER(alignment), widget); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 // object. | 249 // object. |
| 253 static void OnDestroy(GtkWidget* widget, AutoFillDialog* autofill_dialog); | 250 static void OnDestroy(GtkWidget* widget, AutoFillDialog* autofill_dialog); |
| 254 | 251 |
| 255 // 'response' signal handler. Notifies the AutoFillDialogObserver that new | 252 // 'response' signal handler. Notifies the AutoFillDialogObserver that new |
| 256 // data is available if the response is GTK_RESPONSE_APPLY or GTK_RESPONSE_OK. | 253 // data is available if the response is GTK_RESPONSE_APPLY or GTK_RESPONSE_OK. |
| 257 // We close the dialog if the response is GTK_RESPONSE_OK or | 254 // We close the dialog if the response is GTK_RESPONSE_OK or |
| 258 // GTK_RESPONSE_CANCEL. | 255 // GTK_RESPONSE_CANCEL. |
| 259 static void OnResponse(GtkDialog* dialog, gint response_id, | 256 static void OnResponse(GtkDialog* dialog, gint response_id, |
| 260 AutoFillDialog* autofill_dialog); | 257 AutoFillDialog* autofill_dialog); |
| 261 | 258 |
| 262 // 'clicked' signal handler. Sets the default profile. | |
| 263 static void OnDefaultProfileClicked(GtkWidget* button, | |
| 264 AutoFillDialog* dialog); | |
| 265 | |
| 266 // 'clicked' signal handler. Sets the default credit card. | |
| 267 static void OnDefaultCreditCardClicked(GtkWidget* button, | |
| 268 AutoFillDialog* dialog); | |
| 269 | |
| 270 // 'clicked' signal handler. Adds a new address. | 259 // 'clicked' signal handler. Adds a new address. |
| 271 static void OnAddAddressClicked(GtkButton* button, AutoFillDialog* dialog); | 260 static void OnAddAddressClicked(GtkButton* button, AutoFillDialog* dialog); |
| 272 | 261 |
| 273 // 'clicked' signal handler. Adds a new credit card. | 262 // 'clicked' signal handler. Adds a new credit card. |
| 274 static void OnAddCreditCardClicked(GtkButton* button, AutoFillDialog* dialog); | 263 static void OnAddCreditCardClicked(GtkButton* button, AutoFillDialog* dialog); |
| 275 | 264 |
| 276 // 'clicked' signal handler. Deletes the associated address. | 265 // 'clicked' signal handler. Deletes the associated address. |
| 277 static void OnDeleteAddressClicked(GtkButton* button, AutoFillDialog* dialog); | 266 static void OnDeleteAddressClicked(GtkButton* button, AutoFillDialog* dialog); |
| 278 | 267 |
| 279 // 'clicked' signal handler. Deletes the associated credit card. | 268 // 'clicked' signal handler. Deletes the associated credit card. |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 303 | 292 |
| 304 // Initializes the expander, frame and table widgets used to hold the address | 293 // Initializes the expander, frame and table widgets used to hold the address |
| 305 // and credit card forms. |name_id| is the resource id of the label of the | 294 // and credit card forms. |name_id| is the resource id of the label of the |
| 306 // expander widget. The content vbox widget is returned in |content_vbox|. | 295 // expander widget. The content vbox widget is returned in |content_vbox|. |
| 307 // Returns the expander widget. | 296 // Returns the expander widget. |
| 308 GtkWidget* InitGroupContentArea(int name_id, GtkWidget** content_vbox); | 297 GtkWidget* InitGroupContentArea(int name_id, GtkWidget** content_vbox); |
| 309 | 298 |
| 310 // Returns a GtkExpander that is added to the appropriate vbox. Each method | 299 // Returns a GtkExpander that is added to the appropriate vbox. Each method |
| 311 // adds the necessary widgets and layout required to fill out information | 300 // adds the necessary widgets and layout required to fill out information |
| 312 // for either an address or a credit card. The expander will be expanded by | 301 // for either an address or a credit card. The expander will be expanded by |
| 313 // default if |expand| is true. The "Default Profile/Credit Card" button will | 302 // default if |expand| is true. |
| 314 // be toggled if |is_default| is true. | 303 GtkWidget* AddNewAddress(bool expand); |
|
GeorgeY
2010/06/08 23:12:15
Do we still need an |expand|?
James Hawkins
2010/06/08 23:14:22
Yes, this is still the old implementation.
| |
| 315 GtkWidget* AddNewAddress(bool expand, bool is_default); | 304 GtkWidget* AddNewCreditCard(bool expand); |
| 316 GtkWidget* AddNewCreditCard(bool expand, bool is_default); | |
| 317 | 305 |
| 318 // Adds a new address filled out with information from |profile|. Sets the | 306 // Adds a new address filled out with information from |profile|. |
| 319 // "Default Profile" check button if |is_default| is true. | 307 void AddAddress(const AutoFillProfile& profile); |
| 320 void AddAddress(const AutoFillProfile& profile, bool is_default); | |
| 321 | 308 |
| 322 // Adds a new credit card filled out with information from |credit_card|. | 309 // Adds a new credit card filled out with information from |credit_card|. |
| 323 void AddCreditCard(const CreditCard& credit_card, bool is_default); | 310 void AddCreditCard(const CreditCard& credit_card); |
| 311 | |
| 312 // Returns the index of |billing_address| in the list of profiles. Returns -1 | |
| 313 // if the address is not found. | |
| 314 int FindIndexOfAddress(string16 billing_address); | |
| 324 | 315 |
| 325 // Our observer. May not be NULL. | 316 // Our observer. May not be NULL. |
| 326 AutoFillDialogObserver* observer_; | 317 AutoFillDialogObserver* observer_; |
| 327 | 318 |
| 328 // The personal data manager, used to load AutoFill profiles and credit cards. | 319 // The personal data manager, used to load AutoFill profiles and credit cards. |
| 329 // Unowned pointer, may not be NULL. | 320 // Unowned pointer, may not be NULL. |
| 330 PersonalDataManager* personal_data_; | 321 PersonalDataManager* personal_data_; |
| 331 | 322 |
| 332 // The preference service. Unowned pointer, may not be NULL. | 323 // The preference service. Unowned pointer, may not be NULL. |
| 333 PrefService* pref_service_; | 324 PrefService* pref_service_; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 471 // If the CC number starts with an asterisk, then we know that the user has | 462 // If the CC number starts with an asterisk, then we know that the user has |
| 472 // not modified the credit card number at the least, so use the original CC | 463 // not modified the credit card number at the least, so use the original CC |
| 473 // number in this case. | 464 // number in this case. |
| 474 string16 cc_number = GetEntryText(widgets.card_number); | 465 string16 cc_number = GetEntryText(widgets.card_number); |
| 475 if (!cc_number.empty() && cc_number[0] == '*') | 466 if (!cc_number.empty() && cc_number[0] == '*') |
| 476 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NUMBER), | 467 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NUMBER), |
| 477 widgets.original_card_number); | 468 widgets.original_card_number); |
| 478 else | 469 else |
| 479 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NUMBER), | 470 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NUMBER), |
| 480 GetEntryText(widgets.card_number)); | 471 GetEntryText(widgets.card_number)); |
| 481 // TODO(jhawkins): Billing/shipping addresses. | 472 |
| 473 std::string text = | |
| 474 gtk_combo_box_get_active_text(GTK_COMBO_BOX(widgets.billing_address)); | |
| 475 if (text != | |
| 476 l10n_util::GetStringUTF8(IDS_AUTOFILL_DIALOG_CHOOSE_EXISTING_ADDRESS)) { | |
| 477 // TODO(jhawkins): Should we validate the billing address combobox? | |
| 478 credit_card.set_billing_address(UTF8ToUTF16(text)); | |
| 479 } | |
| 480 | |
| 482 return credit_card; | 481 return credit_card; |
| 483 } | 482 } |
| 484 | 483 |
| 485 // static | 484 // static |
| 486 void AutoFillDialog::OnResponse(GtkDialog* dialog, gint response_id, | 485 void AutoFillDialog::OnResponse(GtkDialog* dialog, gint response_id, |
| 487 AutoFillDialog* autofill_dialog) { | 486 AutoFillDialog* autofill_dialog) { |
| 488 if (response_id == GTK_RESPONSE_APPLY || response_id == GTK_RESPONSE_OK) { | 487 if (response_id == GTK_RESPONSE_APPLY || response_id == GTK_RESPONSE_OK) { |
| 489 autofill_dialog->profiles_.clear(); | 488 autofill_dialog->profiles_.clear(); |
| 490 for (std::vector<AddressWidgets>::const_iterator iter = | 489 for (std::vector<AddressWidgets>::const_iterator iter = |
| 491 autofill_dialog->address_widgets_.begin(); | 490 autofill_dialog->address_widgets_.begin(); |
| 492 iter != autofill_dialog->address_widgets_.end(); | 491 iter != autofill_dialog->address_widgets_.end(); |
| 493 ++iter) { | 492 ++iter) { |
| 494 AutoFillProfile profile = AutoFillProfileFromWidgetValues(*iter); | 493 AutoFillProfile profile = AutoFillProfileFromWidgetValues(*iter); |
| 495 | |
| 496 // Set this profile as the default profile if the check button is toggled. | |
| 497 if (gtk_toggle_button_get_active( | |
| 498 GTK_TOGGLE_BUTTON(iter->default_profile))) { | |
| 499 autofill_dialog->pref_service_->SetString( | |
| 500 prefs::kAutoFillDefaultProfile, UTF16ToWideHack(profile.Label())); | |
| 501 } | |
| 502 | |
| 503 autofill_dialog->profiles_.push_back(profile); | 494 autofill_dialog->profiles_.push_back(profile); |
| 504 } | 495 } |
| 505 | 496 |
| 506 autofill_dialog->credit_cards_.clear(); | 497 autofill_dialog->credit_cards_.clear(); |
| 507 for (std::vector<CreditCardWidgets>::const_iterator iter = | 498 for (std::vector<CreditCardWidgets>::const_iterator iter = |
| 508 autofill_dialog->credit_card_widgets_.begin(); | 499 autofill_dialog->credit_card_widgets_.begin(); |
| 509 iter != autofill_dialog->credit_card_widgets_.end(); | 500 iter != autofill_dialog->credit_card_widgets_.end(); |
| 510 ++iter) { | 501 ++iter) { |
| 511 CreditCard credit_card = CreditCardFromWidgetValues(*iter); | 502 CreditCard credit_card = CreditCardFromWidgetValues(*iter); |
| 512 | |
| 513 // Set this credit card as the default profile if the check button is | |
| 514 // toggled. | |
| 515 if (gtk_toggle_button_get_active( | |
| 516 GTK_TOGGLE_BUTTON(iter->default_creditcard))) { | |
| 517 autofill_dialog->pref_service_->SetString( | |
| 518 prefs::kAutoFillDefaultCreditCard, | |
| 519 UTF16ToWideHack(credit_card.Label())); | |
| 520 } | |
| 521 | |
| 522 autofill_dialog->credit_cards_.push_back(credit_card); | 503 autofill_dialog->credit_cards_.push_back(credit_card); |
| 523 } | 504 } |
| 524 | 505 |
| 525 autofill_dialog->observer_->OnAutoFillDialogApply( | 506 autofill_dialog->observer_->OnAutoFillDialogApply( |
| 526 &autofill_dialog->profiles_, | 507 &autofill_dialog->profiles_, |
| 527 &autofill_dialog->credit_cards_); | 508 &autofill_dialog->credit_cards_); |
| 528 } | 509 } |
| 529 | 510 |
| 530 if (response_id == GTK_RESPONSE_OK || | 511 if (response_id == GTK_RESPONSE_OK || |
| 531 response_id == GTK_RESPONSE_CANCEL || | 512 response_id == GTK_RESPONSE_CANCEL || |
| 532 response_id == GTK_RESPONSE_DELETE_EVENT) { | 513 response_id == GTK_RESPONSE_DELETE_EVENT) { |
| 533 gtk_widget_destroy(GTK_WIDGET(dialog)); | 514 gtk_widget_destroy(GTK_WIDGET(dialog)); |
| 534 } | 515 } |
| 535 | 516 |
| 536 if (response_id == kAutoFillDialogLearnMoreLink) | 517 if (response_id == kAutoFillDialogLearnMoreLink) |
| 537 autofill_dialog->OnLinkActivated(); | 518 autofill_dialog->OnLinkActivated(); |
| 538 } | 519 } |
| 539 | 520 |
| 540 // static | 521 // static |
| 541 void AutoFillDialog::OnDefaultProfileClicked(GtkWidget* button, | |
| 542 AutoFillDialog* dialog) { | |
| 543 bool checked = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)); | |
| 544 | |
| 545 // The default profile defaults to the first profile if none is selected, so | |
| 546 // set that here. | |
| 547 if (!checked) { | |
| 548 if (dialog->address_widgets_.size()) { | |
| 549 GtkWidget* check_button = dialog->address_widgets_[0].default_profile; | |
| 550 | |
| 551 // Corner case: if the user is trying to untoggle the first profile, set | |
| 552 // the second profile as the default profile if there is one. If there's | |
| 553 // only one profile, the user won't be able to uncheck the default profile | |
| 554 // button. | |
| 555 // TODO(jhawkins): Verify that this is the appropriate behavior. | |
| 556 if (check_button == button && dialog->address_widgets_.size() > 1U) | |
| 557 check_button = dialog->address_widgets_[1].default_profile; | |
| 558 | |
| 559 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_button), TRUE); | |
| 560 } | |
| 561 | |
| 562 return; | |
| 563 } | |
| 564 | |
| 565 for (std::vector<AddressWidgets>::iterator iter = | |
| 566 dialog->address_widgets_.begin(); | |
| 567 iter != dialog->address_widgets_.end(); ++iter) { | |
| 568 GtkWidget* check_button = iter->default_profile; | |
| 569 | |
| 570 // Don't reset the button that was just pressed. | |
| 571 if (check_button == button) | |
| 572 continue; | |
| 573 | |
| 574 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_button))) | |
| 575 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_button), FALSE); | |
| 576 } | |
| 577 } | |
| 578 | |
| 579 // static | |
| 580 void AutoFillDialog::OnDefaultCreditCardClicked(GtkWidget* button, | |
| 581 AutoFillDialog* dialog) { | |
| 582 bool checked = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)); | |
| 583 | |
| 584 // The default profile defaults to the first profile if none is selected, so | |
| 585 // set that here. | |
| 586 if (!checked) { | |
| 587 if (dialog->credit_card_widgets_.size()) { | |
| 588 GtkWidget* check_button = | |
| 589 dialog->credit_card_widgets_[0].default_creditcard; | |
| 590 | |
| 591 // Corner case: If the user is trying to untoggle the first profile, set | |
| 592 // the second profile as the default profile if there is one. If there's | |
| 593 // only one profile, the user won't be able to uncheck the default profile | |
| 594 // button. | |
| 595 // TODO(jhawkins): Verify that this is the appropriate behavior. | |
| 596 if (check_button == button && dialog->credit_card_widgets_.size() > 1U) | |
| 597 check_button = dialog->credit_card_widgets_[1].default_creditcard; | |
| 598 | |
| 599 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_button), TRUE); | |
| 600 } | |
| 601 | |
| 602 return; | |
| 603 } | |
| 604 | |
| 605 for (std::vector<CreditCardWidgets>::iterator iter = | |
| 606 dialog->credit_card_widgets_.begin(); | |
| 607 iter != dialog->credit_card_widgets_.end(); ++iter) { | |
| 608 GtkWidget* check_button = iter->default_creditcard; | |
| 609 | |
| 610 // Don't reset the button that was just pressed. | |
| 611 if (check_button == button) | |
| 612 continue; | |
| 613 | |
| 614 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_button))) | |
| 615 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_button), FALSE); | |
| 616 } | |
| 617 } | |
| 618 | |
| 619 // static | |
| 620 void AutoFillDialog::OnAddAddressClicked(GtkButton* button, | 522 void AutoFillDialog::OnAddAddressClicked(GtkButton* button, |
| 621 AutoFillDialog* dialog) { | 523 AutoFillDialog* dialog) { |
| 622 // If this is the only address, make it the default profile. | 524 GtkWidget* new_address = dialog->AddNewAddress(true); |
| 623 GtkWidget* new_address = | |
| 624 dialog->AddNewAddress(true, !dialog->address_widgets_.size()); | |
| 625 gtk_box_pack_start(GTK_BOX(dialog->addresses_vbox_), new_address, | 525 gtk_box_pack_start(GTK_BOX(dialog->addresses_vbox_), new_address, |
| 626 FALSE, FALSE, 0); | 526 FALSE, FALSE, 0); |
| 627 gtk_widget_show_all(new_address); | 527 gtk_widget_show_all(new_address); |
| 628 } | 528 } |
| 629 | 529 |
| 630 // static | 530 // static |
| 631 void AutoFillDialog::OnAddCreditCardClicked(GtkButton* button, | 531 void AutoFillDialog::OnAddCreditCardClicked(GtkButton* button, |
| 632 AutoFillDialog* dialog) { | 532 AutoFillDialog* dialog) { |
| 633 // If this is the only credit card, make it the default credit card. | 533 GtkWidget* new_creditcard = dialog->AddNewCreditCard(true); |
| 634 GtkWidget* new_creditcard = | |
| 635 dialog->AddNewCreditCard(true, !dialog->credit_card_widgets_.size()); | |
| 636 gtk_box_pack_start(GTK_BOX(dialog->creditcards_vbox_), new_creditcard, | 534 gtk_box_pack_start(GTK_BOX(dialog->creditcards_vbox_), new_creditcard, |
| 637 FALSE, FALSE, 0); | 535 FALSE, FALSE, 0); |
| 638 gtk_widget_show_all(new_creditcard); | 536 gtk_widget_show_all(new_creditcard); |
| 639 } | 537 } |
| 640 | 538 |
| 641 // static | 539 // static |
| 642 void AutoFillDialog::OnDeleteAddressClicked(GtkButton* button, | 540 void AutoFillDialog::OnDeleteAddressClicked(GtkButton* button, |
| 643 AutoFillDialog* dialog) { | 541 AutoFillDialog* dialog) { |
| 644 GtkWidget* entry = GetButtonData(GTK_WIDGET(button)); | 542 GtkWidget* entry = GetButtonData(GTK_WIDGET(button)); |
| 645 string16 label = GetEntryText(entry); | 543 string16 label = GetEntryText(entry); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 726 } | 624 } |
| 727 | 625 |
| 728 void AutoFillDialog::LoadAutoFillData() { | 626 void AutoFillDialog::LoadAutoFillData() { |
| 729 if (!personal_data_->IsDataLoaded()) { | 627 if (!personal_data_->IsDataLoaded()) { |
| 730 personal_data_->SetObserver(this); | 628 personal_data_->SetObserver(this); |
| 731 return; | 629 return; |
| 732 } | 630 } |
| 733 | 631 |
| 734 if (imported_profile_) { | 632 if (imported_profile_) { |
| 735 profiles_.push_back(*imported_profile_); | 633 profiles_.push_back(*imported_profile_); |
| 736 AddAddress(*imported_profile_, true); | 634 AddAddress(*imported_profile_); |
| 737 } else { | 635 } else { |
| 738 string16 default_profile = WideToUTF16Hack( | |
| 739 pref_service_->GetString(prefs::kAutoFillDefaultProfile)); | |
| 740 | |
| 741 for (std::vector<AutoFillProfile*>::const_iterator iter = | 636 for (std::vector<AutoFillProfile*>::const_iterator iter = |
| 742 personal_data_->profiles().begin(); | 637 personal_data_->profiles().begin(); |
| 743 iter != personal_data_->profiles().end(); ++iter) { | 638 iter != personal_data_->profiles().end(); ++iter) { |
| 744 // The profile list is terminated by a NULL entry; | 639 // The profile list is terminated by a NULL entry; |
| 745 if (!*iter) | 640 if (!*iter) |
| 746 break; | 641 break; |
| 747 | 642 |
| 748 AutoFillProfile* profile = *iter; | 643 AutoFillProfile* profile = *iter; |
| 749 profiles_.push_back(*profile); | 644 profiles_.push_back(*profile); |
| 750 AddAddress(*profile, profile->Label() == default_profile); | 645 AddAddress(*profile); |
| 751 } | 646 } |
| 752 } | 647 } |
| 753 | 648 |
| 754 if (imported_credit_card_) { | 649 if (imported_credit_card_) { |
| 755 credit_cards_.push_back(*imported_credit_card_); | 650 credit_cards_.push_back(*imported_credit_card_); |
| 756 AddCreditCard(*imported_credit_card_, true); | 651 AddCreditCard(*imported_credit_card_); |
| 757 } else { | 652 } else { |
| 758 string16 default_creditcard = WideToUTF16Hack( | |
| 759 pref_service_->GetString(prefs::kAutoFillDefaultCreditCard)); | |
| 760 | |
| 761 for (std::vector<CreditCard*>::const_iterator iter = | 653 for (std::vector<CreditCard*>::const_iterator iter = |
| 762 personal_data_->credit_cards().begin(); | 654 personal_data_->credit_cards().begin(); |
| 763 iter != personal_data_->credit_cards().end(); ++iter) { | 655 iter != personal_data_->credit_cards().end(); ++iter) { |
| 764 // The credit card list is terminated by a NULL entry; | 656 // The credit card list is terminated by a NULL entry; |
| 765 if (!*iter) | 657 if (!*iter) |
| 766 break; | 658 break; |
| 767 | 659 |
| 768 CreditCard* credit_card = *iter; | 660 CreditCard* credit_card = *iter; |
| 769 credit_cards_.push_back(*credit_card); | 661 credit_cards_.push_back(*credit_card); |
| 770 AddCreditCard(*credit_card, credit_card->Label() == default_creditcard); | 662 AddCreditCard(*credit_card); |
| 771 } | 663 } |
| 772 } | 664 } |
| 773 } | 665 } |
| 774 | 666 |
| 775 void AutoFillDialog::InitializeWidgets() { | 667 void AutoFillDialog::InitializeWidgets() { |
| 776 dialog_ = gtk_dialog_new_with_buttons( | 668 dialog_ = gtk_dialog_new_with_buttons( |
| 777 l10n_util::GetStringUTF8(IDS_AUTOFILL_DIALOG_TITLE).c_str(), | 669 l10n_util::GetStringUTF8(IDS_AUTOFILL_DIALOG_TITLE).c_str(), |
| 778 // AutoFill dialog is shared between all browser windows. | 670 // AutoFill dialog is shared between all browser windows. |
| 779 NULL, | 671 NULL, |
| 780 // Non-modal. | 672 // Non-modal. |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 811 // The content vbox. | 703 // The content vbox. |
| 812 GtkWidget* outer_vbox = gtk_vbox_new(false, 0); | 704 GtkWidget* outer_vbox = gtk_vbox_new(false, 0); |
| 813 gtk_box_set_spacing(GTK_BOX(outer_vbox), gtk_util::kContentAreaSpacing); | 705 gtk_box_set_spacing(GTK_BOX(outer_vbox), gtk_util::kContentAreaSpacing); |
| 814 gtk_container_add(GTK_CONTAINER(frame), outer_vbox); | 706 gtk_container_add(GTK_CONTAINER(frame), outer_vbox); |
| 815 | 707 |
| 816 addresses_vbox_ = InitGroup(IDS_AUTOFILL_ADDRESSES_GROUP_NAME, | 708 addresses_vbox_ = InitGroup(IDS_AUTOFILL_ADDRESSES_GROUP_NAME, |
| 817 IDS_AUTOFILL_ADD_ADDRESS_BUTTON, | 709 IDS_AUTOFILL_ADD_ADDRESS_BUTTON, |
| 818 G_CALLBACK(OnAddAddressClicked)); | 710 G_CALLBACK(OnAddAddressClicked)); |
| 819 gtk_box_pack_start_defaults(GTK_BOX(outer_vbox), addresses_vbox_); | 711 gtk_box_pack_start_defaults(GTK_BOX(outer_vbox), addresses_vbox_); |
| 820 | 712 |
| 821 | |
| 822 | |
| 823 creditcards_vbox_ = InitGroup(IDS_AUTOFILL_CREDITCARDS_GROUP_NAME, | 713 creditcards_vbox_ = InitGroup(IDS_AUTOFILL_CREDITCARDS_GROUP_NAME, |
| 824 IDS_AUTOFILL_ADD_CREDITCARD_BUTTON, | 714 IDS_AUTOFILL_ADD_CREDITCARD_BUTTON, |
| 825 G_CALLBACK(OnAddCreditCardClicked)); | 715 G_CALLBACK(OnAddCreditCardClicked)); |
| 826 gtk_box_pack_start_defaults(GTK_BOX(outer_vbox), creditcards_vbox_); | 716 gtk_box_pack_start_defaults(GTK_BOX(outer_vbox), creditcards_vbox_); |
| 827 | 717 |
| 828 GtkWidget* link = gtk_chrome_link_button_new( | 718 GtkWidget* link = gtk_chrome_link_button_new( |
| 829 l10n_util::GetStringUTF8(IDS_AUTOFILL_LEARN_MORE).c_str()); | 719 l10n_util::GetStringUTF8(IDS_AUTOFILL_LEARN_MORE).c_str()); |
| 830 gtk_dialog_add_action_widget(GTK_DIALOG(dialog_), link, | 720 gtk_dialog_add_action_widget(GTK_DIALOG(dialog_), link, |
| 831 kAutoFillDialogLearnMoreLink); | 721 kAutoFillDialogLearnMoreLink); |
| 832 | 722 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 878 gtk_util::kControlSpacing, | 768 gtk_util::kControlSpacing, |
| 879 gtk_util::kGroupIndent, | 769 gtk_util::kGroupIndent, |
| 880 0); | 770 0); |
| 881 gtk_container_add(GTK_CONTAINER(vbox_alignment), vbox); | 771 gtk_container_add(GTK_CONTAINER(vbox_alignment), vbox); |
| 882 gtk_container_add(GTK_CONTAINER(frame), vbox_alignment); | 772 gtk_container_add(GTK_CONTAINER(frame), vbox_alignment); |
| 883 | 773 |
| 884 *content_vbox = vbox; | 774 *content_vbox = vbox; |
| 885 return expander; | 775 return expander; |
| 886 } | 776 } |
| 887 | 777 |
| 888 GtkWidget* AutoFillDialog::AddNewAddress(bool expand, bool is_default) { | 778 GtkWidget* AutoFillDialog::AddNewAddress(bool expand) { |
| 889 AddressWidgets widgets = {0}; | 779 AddressWidgets widgets = {0}; |
| 890 GtkWidget* vbox; | 780 GtkWidget* vbox; |
| 891 GtkWidget* address = InitGroupContentArea(IDS_AUTOFILL_NEW_ADDRESS, &vbox); | 781 GtkWidget* address = InitGroupContentArea(IDS_AUTOFILL_NEW_ADDRESS, &vbox); |
| 892 | 782 |
| 893 gtk_expander_set_expanded(GTK_EXPANDER(address), expand); | 783 gtk_expander_set_expanded(GTK_EXPANDER(address), expand); |
| 894 | 784 |
| 895 GtkWidget* table = InitFormTable(5, 3); | 785 GtkWidget* table = InitFormTable(5, 3); |
| 896 gtk_box_pack_start_defaults(GTK_BOX(vbox), table); | 786 gtk_box_pack_start_defaults(GTK_BOX(vbox), table); |
| 897 | 787 |
| 898 widgets.label = FormTableAddLabelEntry(table, 0, 0, 1, | 788 widgets.label = FormTableAddLabelEntry(table, 0, 0, 1, |
| 899 IDS_AUTOFILL_DIALOG_LABEL, | 789 IDS_AUTOFILL_DIALOG_LABEL, |
| 900 address, G_CALLBACK(OnLabelChanged)); | 790 address, G_CALLBACK(OnLabelChanged)); |
| 901 widgets.first_name = FormTableAddEntry(table, 1, 0, 1, | 791 widgets.first_name = FormTableAddEntry(table, 1, 0, 1, |
| 902 IDS_AUTOFILL_DIALOG_FIRST_NAME); | 792 IDS_AUTOFILL_DIALOG_FIRST_NAME); |
| 903 widgets.middle_name = FormTableAddEntry(table, 1, 1, 1, | 793 widgets.middle_name = FormTableAddEntry(table, 1, 1, 1, |
| 904 IDS_AUTOFILL_DIALOG_MIDDLE_NAME); | 794 IDS_AUTOFILL_DIALOG_MIDDLE_NAME); |
| 905 widgets.last_name = FormTableAddEntry(table, 1, 2, 1, | 795 widgets.last_name = FormTableAddEntry(table, 1, 2, 1, |
| 906 IDS_AUTOFILL_DIALOG_LAST_NAME); | 796 IDS_AUTOFILL_DIALOG_LAST_NAME); |
| 907 widgets.email = FormTableAddEntry(table, 2, 0, 1, | 797 widgets.email = FormTableAddEntry(table, 2, 0, 1, |
| 908 IDS_AUTOFILL_DIALOG_EMAIL); | 798 IDS_AUTOFILL_DIALOG_EMAIL); |
| 909 widgets.company_name = FormTableAddEntry(table, 2, 1, 1, | 799 widgets.company_name = FormTableAddEntry(table, 2, 1, 1, |
| 910 IDS_AUTOFILL_DIALOG_COMPANY_NAME); | 800 IDS_AUTOFILL_DIALOG_COMPANY_NAME); |
| 911 widgets.address_line1 = FormTableAddEntry(table, 3, 0, 2, | 801 widgets.address_line1 = FormTableAddEntry(table, 3, 0, 2, |
| 912 IDS_AUTOFILL_DIALOG_ADDRESS_LINE_1); | 802 IDS_AUTOFILL_DIALOG_ADDRESS_LINE_1); |
| 913 widgets.address_line2 = FormTableAddEntry(table, 4, 0, 2, | 803 widgets.address_line2 = FormTableAddEntry(table, 4, 0, 2, |
| 914 IDS_AUTOFILL_DIALOG_ADDRESS_LINE_2); | 804 IDS_AUTOFILL_DIALOG_ADDRESS_LINE_2); |
| 915 | 805 |
| 916 GtkWidget* default_check = gtk_check_button_new_with_label( | |
| 917 l10n_util::GetStringUTF8(IDS_AUTOFILL_DIALOG_MAKE_DEFAULT).c_str()); | |
| 918 widgets.default_profile = default_check; | |
| 919 FormTableSetWidget(table, default_check, 0, 1, 1, false); | |
| 920 g_signal_connect(default_check, "clicked", | |
| 921 G_CALLBACK(OnDefaultProfileClicked), this); | |
| 922 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(default_check), | |
| 923 is_default); | |
| 924 | |
| 925 GtkWidget* address_table = InitFormTable(1, 4); | 806 GtkWidget* address_table = InitFormTable(1, 4); |
| 926 gtk_box_pack_start_defaults(GTK_BOX(vbox), address_table); | 807 gtk_box_pack_start_defaults(GTK_BOX(vbox), address_table); |
| 927 | 808 |
| 928 widgets.city = FormTableAddEntry(address_table, 0, 0, 1, | 809 widgets.city = FormTableAddEntry(address_table, 0, 0, 1, |
| 929 IDS_AUTOFILL_DIALOG_CITY); | 810 IDS_AUTOFILL_DIALOG_CITY); |
| 930 widgets.state = FormTableAddEntry(address_table, 0, 1, 1, | 811 widgets.state = FormTableAddEntry(address_table, 0, 1, 1, |
| 931 IDS_AUTOFILL_DIALOG_STATE); | 812 IDS_AUTOFILL_DIALOG_STATE); |
| 932 widgets.zipcode = FormTableAddSizedEntry(address_table, 0, 2, 7, | 813 widgets.zipcode = FormTableAddSizedEntry(address_table, 0, 2, 7, |
| 933 IDS_AUTOFILL_DIALOG_ZIP_CODE); | 814 IDS_AUTOFILL_DIALOG_ZIP_CODE); |
| 934 widgets.country = FormTableAddSizedEntry(address_table, 0, 3, 10, | 815 widgets.country = FormTableAddSizedEntry(address_table, 0, 3, 10, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 947 g_signal_connect(button, "clicked", G_CALLBACK(OnDeleteAddressClicked), this); | 828 g_signal_connect(button, "clicked", G_CALLBACK(OnDeleteAddressClicked), this); |
| 948 SetButtonData(button, widgets.label); | 829 SetButtonData(button, widgets.label); |
| 949 GtkWidget* alignment = gtk_alignment_new(0, 0, 0, 0); | 830 GtkWidget* alignment = gtk_alignment_new(0, 0, 0, 0); |
| 950 gtk_container_add(GTK_CONTAINER(alignment), button); | 831 gtk_container_add(GTK_CONTAINER(alignment), button); |
| 951 gtk_box_pack_start_defaults(GTK_BOX(vbox), alignment); | 832 gtk_box_pack_start_defaults(GTK_BOX(vbox), alignment); |
| 952 | 833 |
| 953 address_widgets_.push_back(widgets); | 834 address_widgets_.push_back(widgets); |
| 954 return address; | 835 return address; |
| 955 } | 836 } |
| 956 | 837 |
| 957 GtkWidget* AutoFillDialog::AddNewCreditCard(bool expand, bool is_default) { | 838 GtkWidget* AutoFillDialog::AddNewCreditCard(bool expand) { |
| 958 CreditCardWidgets widgets = {0}; | 839 CreditCardWidgets widgets = {0}; |
| 959 GtkWidget* vbox; | 840 GtkWidget* vbox; |
| 960 GtkWidget* credit_card = InitGroupContentArea(IDS_AUTOFILL_NEW_CREDITCARD, | 841 GtkWidget* credit_card = InitGroupContentArea(IDS_AUTOFILL_NEW_CREDITCARD, |
| 961 &vbox); | 842 &vbox); |
| 962 | 843 |
| 963 gtk_expander_set_expanded(GTK_EXPANDER(credit_card), expand); | 844 gtk_expander_set_expanded(GTK_EXPANDER(credit_card), expand); |
| 964 | 845 |
| 965 GtkWidget* label_table = InitFormTable(1, 2); | 846 GtkWidget* label_table = InitFormTable(1, 2); |
| 966 gtk_box_pack_start_defaults(GTK_BOX(vbox), label_table); | 847 gtk_box_pack_start_defaults(GTK_BOX(vbox), label_table); |
| 967 | 848 |
| 968 widgets.label = FormTableAddLabelEntry(label_table, 0, 0, 1, | 849 widgets.label = FormTableAddLabelEntry(label_table, 0, 0, 1, |
| 969 IDS_AUTOFILL_DIALOG_LABEL, credit_card, | 850 IDS_AUTOFILL_DIALOG_LABEL, credit_card, |
| 970 G_CALLBACK(OnLabelChanged)); | 851 G_CALLBACK(OnLabelChanged)); |
| 971 | 852 |
| 972 // TODO(jhawkins): If there's not a default profile, automatically check this | |
| 973 // check button. | |
| 974 widgets.default_creditcard = gtk_check_button_new_with_label( | |
| 975 l10n_util::GetStringUTF8(IDS_AUTOFILL_DIALOG_MAKE_DEFAULT).c_str()); | |
| 976 FormTableSetWidget(label_table, widgets.default_creditcard, 0, 1, 1, true); | |
| 977 g_signal_connect(widgets.default_creditcard, "clicked", | |
| 978 G_CALLBACK(OnDefaultCreditCardClicked), this); | |
| 979 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets.default_creditcard), | |
| 980 is_default); | |
| 981 | |
| 982 GtkWidget* name_cc_table = InitFormTable(2, 6); | 853 GtkWidget* name_cc_table = InitFormTable(2, 6); |
| 983 gtk_box_pack_start_defaults(GTK_BOX(vbox), name_cc_table); | 854 gtk_box_pack_start_defaults(GTK_BOX(vbox), name_cc_table); |
| 984 | 855 |
| 985 widgets.name_on_card = FormTableAddExpandedEntry( | 856 widgets.name_on_card = FormTableAddExpandedEntry( |
| 986 name_cc_table, 0, 0, 3, IDS_AUTOFILL_DIALOG_NAME_ON_CARD); | 857 name_cc_table, 0, 0, 3, IDS_AUTOFILL_DIALOG_NAME_ON_CARD); |
| 987 widgets.card_number = FormTableAddExpandedEntry( | 858 widgets.card_number = FormTableAddExpandedEntry( |
| 988 name_cc_table, 1, 0, 3, IDS_AUTOFILL_DIALOG_CREDIT_CARD_NUMBER); | 859 name_cc_table, 1, 0, 3, IDS_AUTOFILL_DIALOG_CREDIT_CARD_NUMBER); |
| 989 widgets.expiration_month = FormTableAddSizedEntry(name_cc_table, 1, 3, 2, 0); | 860 widgets.expiration_month = FormTableAddSizedEntry(name_cc_table, 1, 3, 2, 0); |
| 990 widgets.expiration_year = FormTableAddSizedEntry(name_cc_table, 1, 4, 4, 0); | 861 widgets.expiration_year = FormTableAddSizedEntry(name_cc_table, 1, 4, 4, 0); |
| 991 widgets.verification_code = FormTableAddSizedEntry( | 862 widgets.verification_code = FormTableAddSizedEntry( |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1003 IDS_AUTOFILL_DIALOG_BILLING_ADDRESS); | 874 IDS_AUTOFILL_DIALOG_BILLING_ADDRESS); |
| 1004 | 875 |
| 1005 GtkWidget* billing = gtk_combo_box_new_text(); | 876 GtkWidget* billing = gtk_combo_box_new_text(); |
| 1006 widgets.billing_address = billing; | 877 widgets.billing_address = billing; |
| 1007 std::string combo_text = l10n_util::GetStringUTF8( | 878 std::string combo_text = l10n_util::GetStringUTF8( |
| 1008 IDS_AUTOFILL_DIALOG_CHOOSE_EXISTING_ADDRESS); | 879 IDS_AUTOFILL_DIALOG_CHOOSE_EXISTING_ADDRESS); |
| 1009 gtk_combo_box_append_text(GTK_COMBO_BOX(billing), combo_text.c_str()); | 880 gtk_combo_box_append_text(GTK_COMBO_BOX(billing), combo_text.c_str()); |
| 1010 gtk_combo_box_set_active(GTK_COMBO_BOX(billing), 0); | 881 gtk_combo_box_set_active(GTK_COMBO_BOX(billing), 0); |
| 1011 FormTableSetWidget(addresses_table, billing, 0, 0, 2, false); | 882 FormTableSetWidget(addresses_table, billing, 0, 0, 2, false); |
| 1012 | 883 |
| 1013 FormTableSetLabel(addresses_table, 1, 0, 3, | 884 for (std::vector<AddressWidgets>::const_iterator iter = |
| 1014 IDS_AUTOFILL_DIALOG_SHIPPING_ADDRESS); | 885 address_widgets_.begin(); |
| 1015 | 886 iter != address_widgets_.end(); ++iter) { |
| 1016 GtkWidget* shipping = gtk_combo_box_new_text(); | 887 // TODO(jhawkins): Validate the label and DCHECK on !empty(). |
| 1017 widgets.shipping_address = shipping; | 888 std::string text = gtk_entry_get_text(GTK_ENTRY(iter->label)); |
| 1018 combo_text = l10n_util::GetStringUTF8(IDS_AUTOFILL_DIALOG_SAME_AS_BILLING); | 889 if (!text.empty()) |
| 1019 gtk_combo_box_append_text(GTK_COMBO_BOX(shipping), combo_text.c_str()); | 890 gtk_combo_box_append_text(GTK_COMBO_BOX(widgets.billing_address), |
| 1020 gtk_combo_box_set_active(GTK_COMBO_BOX(shipping), 0); | 891 text.c_str()); |
| 1021 FormTableSetWidget(addresses_table, shipping, 1, 0, 2, false); | 892 } |
| 1022 | 893 |
| 1023 GtkWidget* phone_table = InitFormTable(1, 1); | 894 GtkWidget* phone_table = InitFormTable(1, 1); |
| 1024 gtk_box_pack_start_defaults(GTK_BOX(vbox), phone_table); | 895 gtk_box_pack_start_defaults(GTK_BOX(vbox), phone_table); |
| 1025 | 896 |
| 1026 widgets.phone = | 897 widgets.phone = |
| 1027 FormTableAddEntry(phone_table, 0, 0, 1, IDS_AUTOFILL_DIALOG_PHONE); | 898 FormTableAddEntry(phone_table, 0, 0, 1, IDS_AUTOFILL_DIALOG_PHONE); |
| 1028 | 899 |
| 1029 GtkWidget* button = gtk_button_new_with_label( | 900 GtkWidget* button = gtk_button_new_with_label( |
| 1030 l10n_util::GetStringUTF8(IDS_AUTOFILL_DELETE_BUTTON).c_str()); | 901 l10n_util::GetStringUTF8(IDS_AUTOFILL_DELETE_BUTTON).c_str()); |
| 1031 g_signal_connect(button, "clicked", | 902 g_signal_connect(button, "clicked", |
| 1032 G_CALLBACK(OnDeleteCreditCardClicked), this); | 903 G_CALLBACK(OnDeleteCreditCardClicked), this); |
| 1033 SetButtonData(button, widgets.label); | 904 SetButtonData(button, widgets.label); |
| 1034 GtkWidget* alignment = gtk_alignment_new(0, 0, 0, 0); | 905 GtkWidget* alignment = gtk_alignment_new(0, 0, 0, 0); |
| 1035 gtk_container_add(GTK_CONTAINER(alignment), button); | 906 gtk_container_add(GTK_CONTAINER(alignment), button); |
| 1036 gtk_box_pack_start_defaults(GTK_BOX(vbox), alignment); | 907 gtk_box_pack_start_defaults(GTK_BOX(vbox), alignment); |
| 1037 | 908 |
| 1038 credit_card_widgets_.push_back(widgets); | 909 credit_card_widgets_.push_back(widgets); |
| 1039 return credit_card; | 910 return credit_card; |
| 1040 } | 911 } |
| 1041 | 912 |
| 1042 void AutoFillDialog::AddAddress(const AutoFillProfile& profile, | 913 void AutoFillDialog::AddAddress(const AutoFillProfile& profile) { |
| 1043 bool is_default) { | 914 GtkWidget* address = AddNewAddress(false); |
| 1044 GtkWidget* address = AddNewAddress(false, is_default); | |
| 1045 gtk_expander_set_label(GTK_EXPANDER(address), | 915 gtk_expander_set_label(GTK_EXPANDER(address), |
| 1046 UTF16ToUTF8(profile.Label()).c_str()); | 916 UTF16ToUTF8(profile.Label()).c_str()); |
| 1047 | 917 |
| 1048 // We just pushed the widgets to the back of the vector. | 918 // We just pushed the widgets to the back of the vector. |
| 1049 const AddressWidgets& widgets = address_widgets_.back(); | 919 const AddressWidgets& widgets = address_widgets_.back(); |
| 1050 SetEntryText(widgets.label, profile.Label()); | 920 SetEntryText(widgets.label, profile.Label()); |
| 1051 SetEntryText(widgets.first_name, | 921 SetEntryText(widgets.first_name, |
| 1052 profile.GetFieldText(AutoFillType(NAME_FIRST))); | 922 profile.GetFieldText(AutoFillType(NAME_FIRST))); |
| 1053 SetEntryText(widgets.middle_name, | 923 SetEntryText(widgets.middle_name, |
| 1054 profile.GetFieldText(AutoFillType(NAME_MIDDLE))); | 924 profile.GetFieldText(AutoFillType(NAME_MIDDLE))); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1072 profile.GetFieldText(AutoFillType(ADDRESS_HOME_COUNTRY))); | 942 profile.GetFieldText(AutoFillType(ADDRESS_HOME_COUNTRY))); |
| 1073 SetEntryText(widgets.phone, | 943 SetEntryText(widgets.phone, |
| 1074 profile.GetFieldText(AutoFillType(PHONE_HOME_WHOLE_NUMBER))); | 944 profile.GetFieldText(AutoFillType(PHONE_HOME_WHOLE_NUMBER))); |
| 1075 SetEntryText(widgets.fax, | 945 SetEntryText(widgets.fax, |
| 1076 profile.GetFieldText(AutoFillType(PHONE_FAX_WHOLE_NUMBER))); | 946 profile.GetFieldText(AutoFillType(PHONE_FAX_WHOLE_NUMBER))); |
| 1077 | 947 |
| 1078 gtk_box_pack_start(GTK_BOX(addresses_vbox_), address, FALSE, FALSE, 0); | 948 gtk_box_pack_start(GTK_BOX(addresses_vbox_), address, FALSE, FALSE, 0); |
| 1079 gtk_widget_show_all(address); | 949 gtk_widget_show_all(address); |
| 1080 } | 950 } |
| 1081 | 951 |
| 1082 void AutoFillDialog::AddCreditCard(const CreditCard& credit_card, | 952 void AutoFillDialog::AddCreditCard(const CreditCard& credit_card) { |
| 1083 bool is_default) { | 953 GtkWidget* credit_card_widget = AddNewCreditCard(false); |
| 1084 GtkWidget* credit_card_widget = AddNewCreditCard(false, is_default); | |
| 1085 gtk_expander_set_label(GTK_EXPANDER(credit_card_widget), | 954 gtk_expander_set_label(GTK_EXPANDER(credit_card_widget), |
| 1086 UTF16ToUTF8(credit_card.Label()).c_str()); | 955 UTF16ToUTF8(credit_card.Label()).c_str()); |
| 1087 | 956 |
| 1088 // We just pushed the widgets to the back of the vector. | 957 // We just pushed the widgets to the back of the vector. |
| 1089 const CreditCardWidgets& widgets = credit_card_widgets_.back(); | 958 const CreditCardWidgets& widgets = credit_card_widgets_.back(); |
| 1090 SetEntryText(widgets.label, credit_card.Label()); | 959 SetEntryText(widgets.label, credit_card.Label()); |
| 1091 SetEntryText(widgets.name_on_card, | 960 SetEntryText(widgets.name_on_card, |
| 1092 credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NAME))); | 961 credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NAME))); |
| 1093 // Set obfuscated number if not empty. | 962 // Set obfuscated number if not empty. |
| 1094 credit_card_widgets_.back().original_card_number = | 963 credit_card_widgets_.back().original_card_number = |
| 1095 credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NUMBER)); | 964 credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NUMBER)); |
| 1096 string16 credit_card_number; | 965 string16 credit_card_number; |
| 1097 if (!widgets.original_card_number.empty()) | 966 if (!widgets.original_card_number.empty()) |
| 1098 credit_card_number = credit_card.ObfuscatedNumber(); | 967 credit_card_number = credit_card.ObfuscatedNumber(); |
| 1099 // TODO(jhawkins): Credit Card type? Shouldn't be necessary. | |
| 1100 SetEntryText(widgets.card_number, credit_card_number); | 968 SetEntryText(widgets.card_number, credit_card_number); |
| 1101 SetEntryText(widgets.expiration_month, | 969 SetEntryText(widgets.expiration_month, |
| 1102 credit_card.GetFieldText(AutoFillType(CREDIT_CARD_EXP_MONTH))); | 970 credit_card.GetFieldText(AutoFillType(CREDIT_CARD_EXP_MONTH))); |
| 1103 SetEntryText( | 971 SetEntryText( |
| 1104 widgets.expiration_year, | 972 widgets.expiration_year, |
| 1105 credit_card.GetFieldText(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR))); | 973 credit_card.GetFieldText(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR))); |
| 1106 SetEntryText( | 974 SetEntryText( |
| 1107 widgets.verification_code, | 975 widgets.verification_code, |
| 1108 credit_card.GetFieldText(AutoFillType(CREDIT_CARD_VERIFICATION_CODE))); | 976 credit_card.GetFieldText(AutoFillType(CREDIT_CARD_VERIFICATION_CODE))); |
| 1109 | 977 |
| 1110 // TODO(jhawkins): Set the GtkComboBox widgets. | 978 // Two cases to consider: |
| 979 // address not found - This means the address is not set and | |
| 980 // FindIndexOfAddress returns -1. -1 + 1 = 0, meaning the first item will | |
| 981 // be selected, "Choose existing address". | |
| 982 // | |
| 983 // address is found - The index returned needs to be offset by one in order | |
| 984 // to compensate for the first entry, "Choose existing address". | |
| 985 int index = FindIndexOfAddress(credit_card.billing_address()) + 1; | |
| 986 gtk_combo_box_set_active(GTK_COMBO_BOX(widgets.billing_address), index); | |
| 1111 | 987 |
| 1112 gtk_box_pack_start(GTK_BOX(creditcards_vbox_), credit_card_widget, | 988 gtk_box_pack_start(GTK_BOX(creditcards_vbox_), credit_card_widget, |
| 1113 FALSE, FALSE, 0); | 989 FALSE, FALSE, 0); |
| 1114 gtk_widget_show_all(credit_card_widget); | 990 gtk_widget_show_all(credit_card_widget); |
| 1115 } | 991 } |
| 1116 | 992 |
| 993 int AutoFillDialog::FindIndexOfAddress(string16 billing_address) { | |
| 994 int index = 0; | |
| 995 for (std::vector<AddressWidgets>::const_iterator iter = | |
| 996 address_widgets_.begin(); | |
| 997 iter != address_widgets_.end(); ++iter, ++index) { | |
| 998 std::string text = gtk_entry_get_text(GTK_ENTRY(iter->label)); | |
| 999 if (UTF8ToUTF16(text) == billing_address) | |
| 1000 return index; | |
| 1001 } | |
| 1002 | |
| 1003 return -1; | |
| 1004 } | |
| 1005 | |
| 1117 /////////////////////////////////////////////////////////////////////////////// | 1006 /////////////////////////////////////////////////////////////////////////////// |
| 1118 // Factory/finder method: | 1007 // Factory/finder method: |
| 1119 | 1008 |
| 1120 void ShowAutoFillDialog(gfx::NativeView parent, | 1009 void ShowAutoFillDialog(gfx::NativeView parent, |
| 1121 AutoFillDialogObserver* observer, | 1010 AutoFillDialogObserver* observer, |
| 1122 Profile* profile, | 1011 Profile* profile, |
| 1123 AutoFillProfile* imported_profile, | 1012 AutoFillProfile* imported_profile, |
| 1124 CreditCard* imported_credit_card) { | 1013 CreditCard* imported_credit_card) { |
| 1125 DCHECK(profile); | 1014 DCHECK(profile); |
| 1126 | 1015 |
| 1127 // It's possible we haven't shown the InfoBar yet, but if the user is in the | 1016 // It's possible we haven't shown the InfoBar yet, but if the user is in the |
| 1128 // AutoFill dialog, she doesn't need to be asked to enable or disable | 1017 // AutoFill dialog, she doesn't need to be asked to enable or disable |
| 1129 // AutoFill. | 1018 // AutoFill. |
| 1130 profile->GetPrefs()->SetBoolean(prefs::kAutoFillInfoBarShown, true); | 1019 profile->GetPrefs()->SetBoolean(prefs::kAutoFillInfoBarShown, true); |
| 1131 | 1020 |
| 1132 if (!dialog) { | 1021 if (!dialog) { |
| 1133 dialog = new AutoFillDialog(observer, | 1022 dialog = new AutoFillDialog(observer, |
| 1134 profile->GetPersonalDataManager(), | 1023 profile->GetPersonalDataManager(), |
| 1135 profile->GetPrefs(), | 1024 profile->GetPrefs(), |
| 1136 imported_profile, | 1025 imported_profile, |
| 1137 imported_credit_card); | 1026 imported_credit_card); |
| 1138 } | 1027 } |
| 1139 dialog->Show(); | 1028 dialog->Show(); |
| 1140 } | 1029 } |
| OLD | NEW |