| 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/common/gtk_util.h" | 9 #include "chrome/common/gtk_util.h" |
| 10 #include "grit/generated_resources.h" | 10 #include "grit/generated_resources.h" |
| 11 #include "grit/locale_settings.h" |
| 11 | 12 |
| 12 // static | 13 // static |
| 13 void ImportDialogGtk::Show(GtkWindow* parent, Profile* profile) { | 14 void ImportDialogGtk::Show(GtkWindow* parent, Profile* profile) { |
| 14 new ImportDialogGtk(parent, profile); | 15 new ImportDialogGtk(parent, profile); |
| 15 } | 16 } |
| 16 | 17 |
| 17 //////////////////////////////////////////////////////////////////////////////// | 18 //////////////////////////////////////////////////////////////////////////////// |
| 18 // ImportObserver implementation: | 19 // ImportObserver implementation: |
| 19 void ImportDialogGtk::ImportCanceled() { | 20 void ImportDialogGtk::ImportCanceled() { |
| 20 ImportComplete(); | 21 ImportComplete(); |
| 21 } | 22 } |
| 22 | 23 |
| 23 void ImportDialogGtk::ImportComplete() { | 24 void ImportDialogGtk::ImportComplete() { |
| 24 gtk_widget_destroy(dialog_); | 25 gtk_widget_destroy(dialog_); |
| 25 delete this; | 26 delete this; |
| 26 } | 27 } |
| 27 | 28 |
| 28 ImportDialogGtk::ImportDialogGtk(GtkWindow* parent, Profile* profile) | 29 ImportDialogGtk::ImportDialogGtk(GtkWindow* parent, Profile* profile) |
| 29 : parent_(parent), profile_(profile), importer_host_(new ImporterHost()) { | 30 : parent_(parent), profile_(profile), importer_host_(new ImporterHost()) { |
| 30 // Build the dialog. | 31 // Build the dialog. |
| 31 dialog_ = gtk_dialog_new_with_buttons( | 32 dialog_ = gtk_dialog_new_with_buttons( |
| 32 l10n_util::GetStringUTF8(IDS_IMPORT_SETTINGS_TITLE).c_str(), | 33 l10n_util::GetStringUTF8(IDS_IMPORT_SETTINGS_TITLE).c_str(), |
| 33 parent, | 34 parent, |
| 34 (GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), | 35 (GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), |
| 35 GTK_STOCK_CANCEL, | 36 GTK_STOCK_CANCEL, |
| 36 GTK_RESPONSE_REJECT, | 37 GTK_RESPONSE_REJECT, |
| 37 NULL); | 38 NULL); |
| 39 gtk_widget_realize(dialog_); |
| 40 gtk_util::SetWindowWidthFromResources(GTK_WINDOW(dialog_), |
| 41 IDS_IMPORT_DIALOG_WIDTH_CHARS, |
| 42 /* resizable */ false); |
| 38 importer_host_->set_parent_window(GTK_WINDOW(dialog_)); | 43 importer_host_->set_parent_window(GTK_WINDOW(dialog_)); |
| 39 | 44 |
| 40 // Add import button separately as we might need to disable it, if | 45 // Add import button separately as we might need to disable it, if |
| 41 // no supported browsers found. | 46 // no supported browsers found. |
| 42 GtkWidget* import_button = gtk_util::AddButtonToDialog(dialog_, | 47 GtkWidget* import_button = gtk_util::AddButtonToDialog(dialog_, |
| 43 l10n_util::GetStringUTF8(IDS_IMPORT_COMMIT).c_str(), | 48 l10n_util::GetStringUTF8(IDS_IMPORT_COMMIT).c_str(), |
| 44 GTK_STOCK_APPLY, GTK_RESPONSE_ACCEPT); | 49 GTK_STOCK_APPLY, GTK_RESPONSE_ACCEPT); |
| 45 GTK_WIDGET_SET_FLAGS(import_button, GTK_CAN_DEFAULT); | 50 GTK_WIDGET_SET_FLAGS(import_button, GTK_CAN_DEFAULT); |
| 46 gtk_dialog_set_default_response(GTK_DIALOG(dialog_), GTK_RESPONSE_ACCEPT); | 51 gtk_dialog_set_default_response(GTK_DIALOG(dialog_), GTK_RESPONSE_ACCEPT); |
| 47 | 52 |
| 48 // TODO(rahulk): find how to set size properly so that the dialog | |
| 49 // box width is at least enough to display full title. | |
| 50 gtk_widget_set_size_request(dialog_, 300, -1); | |
| 51 | |
| 52 GtkWidget* content_area = GTK_DIALOG(dialog_)->vbox; | 53 GtkWidget* content_area = GTK_DIALOG(dialog_)->vbox; |
| 53 gtk_box_set_spacing(GTK_BOX(content_area), gtk_util::kContentAreaSpacing); | 54 gtk_box_set_spacing(GTK_BOX(content_area), gtk_util::kContentAreaSpacing); |
| 54 | 55 |
| 55 GtkWidget* combo_hbox = gtk_hbox_new(FALSE, gtk_util::kLabelSpacing); | 56 GtkWidget* combo_hbox = gtk_hbox_new(FALSE, gtk_util::kLabelSpacing); |
| 56 GtkWidget* from = gtk_label_new( | 57 GtkWidget* from = gtk_label_new( |
| 57 l10n_util::GetStringUTF8(IDS_IMPORT_FROM_LABEL).c_str()); | 58 l10n_util::GetStringUTF8(IDS_IMPORT_FROM_LABEL).c_str()); |
| 58 gtk_box_pack_start(GTK_BOX(combo_hbox), from, FALSE, FALSE, 0); | 59 gtk_box_pack_start(GTK_BOX(combo_hbox), from, FALSE, FALSE, 0); |
| 59 | 60 |
| 60 combo_ = gtk_combo_box_new_text(); | 61 combo_ = gtk_combo_box_new_text(); |
| 61 gtk_box_pack_start(GTK_BOX(combo_hbox), combo_, TRUE, TRUE, 0); | 62 gtk_box_pack_start(GTK_BOX(combo_hbox), combo_, TRUE, TRUE, 0); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 gtk_widget_set_sensitive(bookmarks_, FALSE); | 108 gtk_widget_set_sensitive(bookmarks_, FALSE); |
| 108 gtk_widget_set_sensitive(search_engines_, FALSE); | 109 gtk_widget_set_sensitive(search_engines_, FALSE); |
| 109 gtk_widget_set_sensitive(passwords_, FALSE); | 110 gtk_widget_set_sensitive(passwords_, FALSE); |
| 110 gtk_widget_set_sensitive(history_, FALSE); | 111 gtk_widget_set_sensitive(history_, FALSE); |
| 111 gtk_widget_set_sensitive(import_button, FALSE); | 112 gtk_widget_set_sensitive(import_button, FALSE); |
| 112 } | 113 } |
| 113 gtk_combo_box_set_active(GTK_COMBO_BOX(combo_), 0); | 114 gtk_combo_box_set_active(GTK_COMBO_BOX(combo_), 0); |
| 114 | 115 |
| 115 g_signal_connect(dialog_, "response", | 116 g_signal_connect(dialog_, "response", |
| 116 G_CALLBACK(HandleOnResponseDialog), this); | 117 G_CALLBACK(HandleOnResponseDialog), this); |
| 117 gtk_window_set_resizable(GTK_WINDOW(dialog_), FALSE); | |
| 118 gtk_widget_show_all(dialog_); | 118 gtk_widget_show_all(dialog_); |
| 119 } | 119 } |
| 120 | 120 |
| 121 void ImportDialogGtk::OnDialogResponse(GtkWidget* widget, int response) { | 121 void ImportDialogGtk::OnDialogResponse(GtkWidget* widget, int response) { |
| 122 gtk_widget_hide_all(dialog_); | 122 gtk_widget_hide_all(dialog_); |
| 123 if (response == GTK_RESPONSE_ACCEPT) { | 123 if (response == GTK_RESPONSE_ACCEPT) { |
| 124 uint16 items = NONE; | 124 uint16 items = NONE; |
| 125 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(bookmarks_))) | 125 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(bookmarks_))) |
| 126 items |= FAVORITES; | 126 items |= FAVORITES; |
| 127 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(search_engines_))) | 127 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(search_engines_))) |
| 128 items |= SEARCH_ENGINES; | 128 items |= SEARCH_ENGINES; |
| 129 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(passwords_))) | 129 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(passwords_))) |
| 130 items |= PASSWORDS; | 130 items |= PASSWORDS; |
| 131 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(history_))) | 131 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(history_))) |
| 132 items |= HISTORY; | 132 items |= HISTORY; |
| 133 | 133 |
| 134 if (items == 0) { | 134 if (items == 0) { |
| 135 ImportComplete(); | 135 ImportComplete(); |
| 136 } else { | 136 } else { |
| 137 const ProfileInfo& source_profile = | 137 const ProfileInfo& source_profile = |
| 138 importer_host_->GetSourceProfileInfoAt( | 138 importer_host_->GetSourceProfileInfoAt( |
| 139 gtk_combo_box_get_active(GTK_COMBO_BOX(combo_))); | 139 gtk_combo_box_get_active(GTK_COMBO_BOX(combo_))); |
| 140 StartImportingWithUI(parent_, items, importer_host_.get(), | 140 StartImportingWithUI(parent_, items, importer_host_.get(), |
| 141 source_profile, profile_, this, false); | 141 source_profile, profile_, this, false); |
| 142 } | 142 } |
| 143 } else { | 143 } else { |
| 144 ImportCanceled(); | 144 ImportCanceled(); |
| 145 } | 145 } |
| 146 } | 146 } |
| OLD | NEW |