| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/gtk/import_dialog_gtk.h" | 5 #include "chrome/browser/gtk/import_dialog_gtk.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "chrome/browser/profile.h" | |
| 10 #include "grit/generated_resources.h" | 9 #include "grit/generated_resources.h" |
| 11 | 10 |
| 12 // static | 11 // static |
| 13 void ImportDialogGtk::Show(GtkWindow* parent, Profile* profile) { | 12 void ImportDialogGtk::Show(GtkWindow* parent, Profile* profile) { |
| 14 new ImportDialogGtk(parent, profile); | 13 new ImportDialogGtk(parent, profile); |
| 15 } | 14 } |
| 16 | 15 |
| 16 //////////////////////////////////////////////////////////////////////////////// |
| 17 // ImportObserver implementation: |
| 18 void ImportDialogGtk::ImportCanceled() { |
| 19 ImportComplete(); |
| 20 } |
| 21 |
| 22 void ImportDialogGtk::ImportComplete() { |
| 23 gtk_widget_destroy(dialog_); |
| 24 delete this; |
| 25 } |
| 26 |
| 17 ImportDialogGtk::ImportDialogGtk(GtkWindow* parent, Profile* profile) : | 27 ImportDialogGtk::ImportDialogGtk(GtkWindow* parent, Profile* profile) : |
| 18 profile_(profile), importer_host_(new ImporterHost()) { | 28 parent_(parent), profile_(profile), importer_host_(new ImporterHost()) { |
| 19 // Build the dialog. | 29 // Build the dialog. |
| 20 GtkWidget* dialog = gtk_dialog_new_with_buttons( | 30 dialog_ = gtk_dialog_new_with_buttons( |
| 21 l10n_util::GetStringUTF8(IDS_IMPORT_SETTINGS_TITLE).c_str(), | 31 l10n_util::GetStringUTF8(IDS_IMPORT_SETTINGS_TITLE).c_str(), |
| 22 parent, | 32 parent, |
| 23 (GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), | 33 (GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), |
| 24 GTK_STOCK_CANCEL, | 34 GTK_STOCK_CANCEL, |
| 25 GTK_RESPONSE_REJECT, | 35 GTK_RESPONSE_REJECT, |
| 26 l10n_util::GetStringUTF8(IDS_IMPORT_COMMIT).c_str(), | 36 l10n_util::GetStringUTF8(IDS_IMPORT_COMMIT).c_str(), |
| 27 GTK_RESPONSE_ACCEPT, | 37 GTK_RESPONSE_ACCEPT, |
| 28 NULL); | 38 NULL); |
| 29 | 39 |
| 30 // TODO(rahulk): find how to set size properly so that the dialog | 40 // TODO(rahulk): find how to set size properly so that the dialog |
| 31 // box width is at least enough to display full title. | 41 // box width is at least enough to display full title. |
| 32 gtk_widget_set_size_request(dialog, 300, -1); | 42 gtk_widget_set_size_request(dialog_, 300, -1); |
| 33 | 43 |
| 34 GtkWidget* content_area = GTK_DIALOG(dialog)->vbox; | 44 GtkWidget* content_area = GTK_DIALOG(dialog_)->vbox; |
| 35 gtk_box_set_spacing(GTK_BOX(content_area), 18); | 45 gtk_box_set_spacing(GTK_BOX(content_area), 18); |
| 36 | 46 |
| 37 GtkWidget* combo_hbox = gtk_hbox_new(FALSE, 12); | 47 GtkWidget* combo_hbox = gtk_hbox_new(FALSE, 12); |
| 38 GtkWidget* from = gtk_label_new( | 48 GtkWidget* from = gtk_label_new( |
| 39 l10n_util::GetStringUTF8(IDS_IMPORT_FROM_LABEL).c_str()); | 49 l10n_util::GetStringUTF8(IDS_IMPORT_FROM_LABEL).c_str()); |
| 40 gtk_box_pack_start(GTK_BOX(combo_hbox), from, FALSE, FALSE, 0); | 50 gtk_box_pack_start(GTK_BOX(combo_hbox), from, FALSE, FALSE, 0); |
| 41 | 51 |
| 42 combo_ = gtk_combo_box_new_text(); | 52 combo_ = gtk_combo_box_new_text(); |
| 43 int profiles_count = importer_host_->GetAvailableProfileCount(); | 53 int profiles_count = importer_host_->GetAvailableProfileCount(); |
| 44 for (int i = 0; i < profiles_count; i++) { | 54 for (int i = 0; i < profiles_count; i++) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 68 | 78 |
| 69 passwords_ = gtk_check_button_new_with_label( | 79 passwords_ = gtk_check_button_new_with_label( |
| 70 l10n_util::GetStringUTF8(IDS_IMPORT_PASSWORDS_CHKBOX).c_str()); | 80 l10n_util::GetStringUTF8(IDS_IMPORT_PASSWORDS_CHKBOX).c_str()); |
| 71 gtk_box_pack_start(GTK_BOX(vbox), passwords_, FALSE, FALSE, 0); | 81 gtk_box_pack_start(GTK_BOX(vbox), passwords_, FALSE, FALSE, 0); |
| 72 | 82 |
| 73 history_ = gtk_check_button_new_with_label( | 83 history_ = gtk_check_button_new_with_label( |
| 74 l10n_util::GetStringUTF8(IDS_IMPORT_HISTORY_CHKBOX).c_str()); | 84 l10n_util::GetStringUTF8(IDS_IMPORT_HISTORY_CHKBOX).c_str()); |
| 75 gtk_box_pack_start(GTK_BOX(vbox), history_, FALSE, FALSE, 0); | 85 gtk_box_pack_start(GTK_BOX(vbox), history_, FALSE, FALSE, 0); |
| 76 gtk_box_pack_start(GTK_BOX(content_area), vbox, FALSE, FALSE, 0); | 86 gtk_box_pack_start(GTK_BOX(content_area), vbox, FALSE, FALSE, 0); |
| 77 | 87 |
| 78 g_signal_connect(dialog, "response", | 88 g_signal_connect(dialog_, "response", |
| 79 G_CALLBACK(HandleOnResponseDialog), this); | 89 G_CALLBACK(HandleOnResponseDialog), this); |
| 80 gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); | 90 gtk_window_set_resizable(GTK_WINDOW(dialog_), FALSE); |
| 81 gtk_widget_show_all(dialog); | 91 gtk_widget_show_all(dialog_); |
| 82 } | 92 } |
| 83 | 93 |
| 84 void ImportDialogGtk::OnDialogResponse(GtkWidget* widget, int response) { | 94 void ImportDialogGtk::OnDialogResponse(GtkWidget* widget, int response) { |
| 95 gtk_widget_hide_all(dialog_); |
| 85 if (response == GTK_RESPONSE_ACCEPT) { | 96 if (response == GTK_RESPONSE_ACCEPT) { |
| 86 uint16 items = NONE; | 97 uint16 items = NONE; |
| 87 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(bookmarks_))) | 98 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(bookmarks_))) |
| 88 items |= FAVORITES; | 99 items |= FAVORITES; |
| 89 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(search_engines_))) | 100 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(search_engines_))) |
| 90 items |= SEARCH_ENGINES; | 101 items |= SEARCH_ENGINES; |
| 91 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(passwords_))) | 102 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(passwords_))) |
| 92 items |= PASSWORDS; | 103 items |= PASSWORDS; |
| 93 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(history_))) | 104 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(history_))) |
| 94 items |= HISTORY; | 105 items |= HISTORY; |
| 95 | 106 |
| 96 const ProfileInfo& source_profile = importer_host_->GetSourceProfileInfoAt( | 107 const ProfileInfo& source_profile = importer_host_->GetSourceProfileInfoAt( |
| 97 gtk_combo_box_get_active(GTK_COMBO_BOX(combo_))); | 108 gtk_combo_box_get_active(GTK_COMBO_BOX(combo_))); |
| 98 | 109 StartImportingWithUI(parent_, items, importer_host_.get(), |
| 99 // TODO(rahulk): We should not do the import on this thread. Instead | 110 source_profile, profile_, this, false); |
| 100 // we need to start this asynchronously and launch a UI that shows the | 111 } else { |
| 101 // progress of import. | 112 ImportCanceled(); |
| 102 importer_host_->StartImportSettings(source_profile, profile_, items, | |
| 103 new ProfileWriter(profile_), false); | |
| 104 } | 113 } |
| 105 | |
| 106 delete this; | |
| 107 gtk_widget_destroy(GTK_WIDGET(widget)); | |
| 108 } | 114 } |
| OLD | NEW |