| 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/gtk/import_dialog_gtk.h" | 5 #include "chrome/browser/gtk/import_dialog_gtk.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/gtk/accessible_widget_helper_gtk.h" | 12 #include "chrome/browser/gtk/accessible_widget_helper_gtk.h" |
| 13 #include "chrome/browser/gtk/gtk_util.h" | 13 #include "chrome/browser/gtk/gtk_util.h" |
| 14 #include "chrome/browser/importer/importer_data_types.h" | 14 #include "chrome/browser/importer/importer_data_types.h" |
| 15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
| 16 #include "grit/locale_settings.h" | 16 #include "grit/locale_settings.h" |
| 17 | 17 |
| 18 namespace { |
| 19 |
| 20 // Returns true if the checkbox is checked. |
| 21 gboolean IsChecked(GtkWidget* widget) { |
| 22 return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); |
| 23 } |
| 24 |
| 25 } // namespace |
| 26 |
| 18 // static | 27 // static |
| 19 void ImportDialogGtk::Show(GtkWindow* parent, Profile* profile, | 28 void ImportDialogGtk::Show(GtkWindow* parent, Profile* profile, |
| 20 int initial_state) { | 29 int initial_state) { |
| 21 new ImportDialogGtk(parent, profile, initial_state); | 30 new ImportDialogGtk(parent, profile, initial_state); |
| 22 } | 31 } |
| 23 | 32 |
| 24 //////////////////////////////////////////////////////////////////////////////// | 33 //////////////////////////////////////////////////////////////////////////////// |
| 25 // ImportObserver implementation: | 34 // ImportObserver implementation: |
| 26 void ImportDialogGtk::ImportCanceled() { | 35 void ImportDialogGtk::ImportCanceled() { |
| 27 ImportComplete(); | 36 ImportComplete(); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 GtkWidget* description = gtk_label_new( | 95 GtkWidget* description = gtk_label_new( |
| 87 l10n_util::GetStringUTF8(IDS_IMPORT_ITEMS_LABEL).c_str()); | 96 l10n_util::GetStringUTF8(IDS_IMPORT_ITEMS_LABEL).c_str()); |
| 88 gtk_misc_set_alignment(GTK_MISC(description), 0, 0); | 97 gtk_misc_set_alignment(GTK_MISC(description), 0, 0); |
| 89 gtk_box_pack_start(GTK_BOX(vbox), description, FALSE, FALSE, 0); | 98 gtk_box_pack_start(GTK_BOX(vbox), description, FALSE, FALSE, 0); |
| 90 | 99 |
| 91 bookmarks_ = gtk_check_button_new_with_label( | 100 bookmarks_ = gtk_check_button_new_with_label( |
| 92 l10n_util::GetStringUTF8(IDS_IMPORT_FAVORITES_CHKBOX).c_str()); | 101 l10n_util::GetStringUTF8(IDS_IMPORT_FAVORITES_CHKBOX).c_str()); |
| 93 gtk_box_pack_start(GTK_BOX(vbox), bookmarks_, FALSE, FALSE, 0); | 102 gtk_box_pack_start(GTK_BOX(vbox), bookmarks_, FALSE, FALSE, 0); |
| 94 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(bookmarks_), | 103 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(bookmarks_), |
| 95 (initial_state_ & importer::FAVORITES) != 0); | 104 (initial_state_ & importer::FAVORITES) != 0); |
| 105 g_signal_connect(bookmarks_, "toggled", |
| 106 G_CALLBACK(OnDialogWidgetClickedThunk), this); |
| 96 | 107 |
| 97 search_engines_ = gtk_check_button_new_with_label( | 108 search_engines_ = gtk_check_button_new_with_label( |
| 98 l10n_util::GetStringUTF8(IDS_IMPORT_SEARCH_ENGINES_CHKBOX).c_str()); | 109 l10n_util::GetStringUTF8(IDS_IMPORT_SEARCH_ENGINES_CHKBOX).c_str()); |
| 99 gtk_box_pack_start(GTK_BOX(vbox), search_engines_, FALSE, FALSE, 0); | 110 gtk_box_pack_start(GTK_BOX(vbox), search_engines_, FALSE, FALSE, 0); |
| 100 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(search_engines_), | 111 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(search_engines_), |
| 101 (initial_state_ & importer::SEARCH_ENGINES) != 0); | 112 (initial_state_ & importer::SEARCH_ENGINES) != 0); |
| 113 g_signal_connect(search_engines_, "toggled", |
| 114 G_CALLBACK(OnDialogWidgetClickedThunk), this); |
| 102 | 115 |
| 103 passwords_ = gtk_check_button_new_with_label( | 116 passwords_ = gtk_check_button_new_with_label( |
| 104 l10n_util::GetStringUTF8(IDS_IMPORT_PASSWORDS_CHKBOX).c_str()); | 117 l10n_util::GetStringUTF8(IDS_IMPORT_PASSWORDS_CHKBOX).c_str()); |
| 105 gtk_box_pack_start(GTK_BOX(vbox), passwords_, FALSE, FALSE, 0); | 118 gtk_box_pack_start(GTK_BOX(vbox), passwords_, FALSE, FALSE, 0); |
| 106 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(passwords_), | 119 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(passwords_), |
| 107 (initial_state_ & importer::PASSWORDS) != 0); | 120 (initial_state_ & importer::PASSWORDS) != 0); |
| 121 g_signal_connect(passwords_, "toggled", |
| 122 G_CALLBACK(OnDialogWidgetClickedThunk), this); |
| 108 | 123 |
| 109 history_ = gtk_check_button_new_with_label( | 124 history_ = gtk_check_button_new_with_label( |
| 110 l10n_util::GetStringUTF8(IDS_IMPORT_HISTORY_CHKBOX).c_str()); | 125 l10n_util::GetStringUTF8(IDS_IMPORT_HISTORY_CHKBOX).c_str()); |
| 111 gtk_box_pack_start(GTK_BOX(vbox), history_, FALSE, FALSE, 0); | 126 gtk_box_pack_start(GTK_BOX(vbox), history_, FALSE, FALSE, 0); |
| 112 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(history_), | 127 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(history_), |
| 113 (initial_state_ & importer::HISTORY) !=0); | 128 (initial_state_ & importer::HISTORY) !=0); |
| 129 g_signal_connect(history_, "toggled", |
| 130 G_CALLBACK(OnDialogWidgetClickedThunk), this); |
| 114 | 131 |
| 115 gtk_box_pack_start(GTK_BOX(content_area), vbox, FALSE, FALSE, 0); | 132 gtk_box_pack_start(GTK_BOX(content_area), vbox, FALSE, FALSE, 0); |
| 116 | 133 |
| 117 // Detect any supported browsers that we can import from and fill | 134 // Detect any supported browsers that we can import from and fill |
| 118 // up the combo box. If none found, disable all controls except cancel. | 135 // up the combo box. If none found, disable all controls except cancel. |
| 119 int profiles_count = importer_host_->GetAvailableProfileCount(); | 136 int profiles_count = importer_host_->GetAvailableProfileCount(); |
| 120 if (profiles_count > 0) { | 137 if (profiles_count > 0) { |
| 121 for (int i = 0; i < profiles_count; i++) { | 138 for (int i = 0; i < profiles_count; i++) { |
| 122 std::wstring profile = importer_host_->GetSourceProfileNameAt(i); | 139 std::wstring profile = importer_host_->GetSourceProfileNameAt(i); |
| 123 gtk_combo_box_append_text(GTK_COMBO_BOX(combo_), | 140 gtk_combo_box_append_text(GTK_COMBO_BOX(combo_), |
| 124 WideToUTF8(profile).c_str()); | 141 WideToUTF8(profile).c_str()); |
| 125 } | 142 } |
| 126 gtk_widget_grab_focus(import_button); | 143 gtk_widget_grab_focus(import_button); |
| 127 } else { | 144 } else { |
| 128 gtk_combo_box_append_text(GTK_COMBO_BOX(combo_), | 145 gtk_combo_box_append_text(GTK_COMBO_BOX(combo_), |
| 129 l10n_util::GetStringUTF8(IDS_IMPORT_NO_PROFILE_FOUND).c_str()); | 146 l10n_util::GetStringUTF8(IDS_IMPORT_NO_PROFILE_FOUND).c_str()); |
| 130 gtk_widget_set_sensitive(bookmarks_, FALSE); | 147 gtk_widget_set_sensitive(bookmarks_, FALSE); |
| 131 gtk_widget_set_sensitive(search_engines_, FALSE); | 148 gtk_widget_set_sensitive(search_engines_, FALSE); |
| 132 gtk_widget_set_sensitive(passwords_, FALSE); | 149 gtk_widget_set_sensitive(passwords_, FALSE); |
| 133 gtk_widget_set_sensitive(history_, FALSE); | 150 gtk_widget_set_sensitive(history_, FALSE); |
| 134 gtk_widget_set_sensitive(import_button, FALSE); | 151 gtk_widget_set_sensitive(import_button, FALSE); |
| 135 } | 152 } |
| 136 gtk_combo_box_set_active(GTK_COMBO_BOX(combo_), 0); | 153 gtk_combo_box_set_active(GTK_COMBO_BOX(combo_), 0); |
| 137 | 154 |
| 138 g_signal_connect(dialog_, "response", | 155 g_signal_connect(dialog_, "response", |
| 139 G_CALLBACK(HandleOnResponseDialog), this); | 156 G_CALLBACK(OnDialogResponseThunk), this); |
| 157 |
| 158 UpdateDialogButtons(); |
| 159 |
| 140 gtk_widget_show_all(dialog_); | 160 gtk_widget_show_all(dialog_); |
| 141 } | 161 } |
| 142 | 162 |
| 143 ImportDialogGtk::~ImportDialogGtk() { | 163 ImportDialogGtk::~ImportDialogGtk() { |
| 144 } | 164 } |
| 145 | 165 |
| 146 void ImportDialogGtk::OnDialogResponse(GtkWidget* widget, int response) { | 166 void ImportDialogGtk::OnDialogResponse(GtkWidget* widget, int response) { |
| 147 gtk_widget_hide_all(dialog_); | 167 gtk_widget_hide_all(dialog_); |
| 148 if (response == GTK_RESPONSE_ACCEPT) { | 168 if (response == GTK_RESPONSE_ACCEPT) { |
| 149 uint16 items = importer::NONE; | 169 uint16 items = GetCheckedItems(); |
| 150 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(bookmarks_))) | |
| 151 items |= importer::FAVORITES; | |
| 152 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(search_engines_))) | |
| 153 items |= importer::SEARCH_ENGINES; | |
| 154 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(passwords_))) | |
| 155 items |= importer::PASSWORDS; | |
| 156 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(history_))) | |
| 157 items |= importer::HISTORY; | |
| 158 | |
| 159 if (items == 0) { | 170 if (items == 0) { |
| 160 ImportComplete(); | 171 ImportComplete(); |
| 161 } else { | 172 } else { |
| 162 const ProfileInfo& source_profile = | 173 const ProfileInfo& source_profile = |
| 163 importer_host_->GetSourceProfileInfoAt( | 174 importer_host_->GetSourceProfileInfoAt( |
| 164 gtk_combo_box_get_active(GTK_COMBO_BOX(combo_))); | 175 gtk_combo_box_get_active(GTK_COMBO_BOX(combo_))); |
| 165 StartImportingWithUI(parent_, items, importer_host_.get(), | 176 StartImportingWithUI(parent_, items, importer_host_.get(), |
| 166 source_profile, profile_, this, false); | 177 source_profile, profile_, this, false); |
| 167 } | 178 } |
| 168 } else { | 179 } else { |
| 169 ImportCanceled(); | 180 ImportCanceled(); |
| 170 } | 181 } |
| 171 } | 182 } |
| 183 |
| 184 void ImportDialogGtk::OnDialogWidgetClicked(GtkWidget* widget) { |
| 185 UpdateDialogButtons(); |
| 186 } |
| 187 |
| 188 void ImportDialogGtk::UpdateDialogButtons() { |
| 189 gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog_), GTK_RESPONSE_ACCEPT, |
| 190 GetCheckedItems() != 0); |
| 191 } |
| 192 |
| 193 uint16 ImportDialogGtk::GetCheckedItems() { |
| 194 uint16 items = importer::NONE; |
| 195 if (IsChecked(bookmarks_)) |
| 196 items |= importer::FAVORITES; |
| 197 if (IsChecked(search_engines_)) |
| 198 items |= importer::SEARCH_ENGINES; |
| 199 if (IsChecked(passwords_)) |
| 200 items |= importer::PASSWORDS; |
| 201 if (IsChecked(history_)) |
| 202 items |= importer::HISTORY; |
| 203 return items; |
| 204 } |
| OLD | NEW |