Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/gtk/import_dialog_gtk.h" | |
| 6 | |
| 7 #include <gtk/gtk.h> | |
| 8 | |
| 9 #include "app/l10n_util.h" | |
| 10 #include "app/resource_bundle.h" | |
| 11 #include "chrome/browser/profile.h" | |
| 12 #include "grit/generated_resources.h" | |
| 13 | |
| 14 // static | |
| 15 void ImportDialogGtk::Show(GtkWindow* parent, Profile* profile) { | |
| 16 new ImportDialogGtk(parent, profile); | |
| 17 } | |
| 18 | |
| 19 ImportDialogGtk::ImportDialogGtk(GtkWindow* parent, Profile* profile) : | |
| 20 profile_(profile), importer_host_(new ImporterHost()) { | |
| 21 // Build the dialog. | |
| 22 GtkWidget* dialog = gtk_dialog_new_with_buttons( | |
| 23 l10n_util::GetStringUTF8(IDS_IMPORT_SETTINGS_TITLE).c_str(), | |
| 24 parent, | |
| 25 (GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), | |
| 26 l10n_util::GetStringUTF8(IDS_IMPORT_COMMIT).c_str(), | |
| 27 GTK_RESPONSE_ACCEPT, | |
| 28 l10n_util::GetStringUTF8(IDS_CANCEL).c_str(), | |
| 29 GTK_RESPONSE_REJECT, | |
| 30 NULL); | |
| 31 | |
| 32 //TODO(rahulk): find how to set size properly so that the dialog box width is | |
| 33 // atleast enough to display full title. | |
| 34 gtk_widget_set_size_request(dialog, 300, -1); | |
| 35 | |
| 36 GtkWidget* content_area = GTK_DIALOG(dialog)->vbox; | |
| 37 GtkWidget* alignment = gtk_alignment_new(0.0, 0.0, 0.0, 0.0); | |
| 38 gtk_box_pack_start(GTK_BOX(content_area), alignment, TRUE, TRUE, 0); | |
| 39 | |
| 40 GtkWidget* vbox = gtk_vbox_new(FALSE, 0); | |
| 41 gtk_container_add(GTK_CONTAINER(alignment), vbox); | |
| 42 | |
| 43 GtkWidget* combo_hbox = gtk_hbox_new(FALSE, 5); | |
| 44 GtkWidget* from = gtk_label_new( | |
| 45 l10n_util::GetStringUTF8(IDS_IMPORT_FROM_LABEL).c_str()); | |
| 46 gtk_box_pack_start(GTK_BOX(combo_hbox), from, TRUE, TRUE, 5); | |
| 47 | |
| 48 combo_ = gtk_combo_box_new_text(); | |
| 49 int profiles_count = importer_host_->GetAvailableProfileCount(); | |
| 50 for (int i = 0; i < profiles_count; i++) { | |
| 51 std::wstring profile = importer_host_->GetSourceProfileNameAt(i); | |
| 52 gtk_combo_box_append_text(GTK_COMBO_BOX(combo_), | |
| 53 WideToUTF8(profile).c_str()); | |
| 54 } | |
| 55 gtk_combo_box_set_active(GTK_COMBO_BOX(combo_), 0); | |
| 56 gtk_box_pack_start(GTK_BOX(combo_hbox), combo_, TRUE, TRUE, 5); | |
| 57 gtk_box_pack_start(GTK_BOX(vbox), combo_hbox, TRUE, TRUE, 5); | |
| 58 | |
| 59 GtkWidget* description = gtk_label_new( | |
| 60 l10n_util::GetStringUTF8(IDS_IMPORT_ITEMS_LABEL).c_str()); | |
| 61 gtk_box_pack_start(GTK_BOX(vbox), description, TRUE, TRUE, 5); | |
| 62 | |
| 63 GtkWidget* text_alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); | |
| 64 gtk_alignment_set_padding(GTK_ALIGNMENT(text_alignment), 0, 0, 25, 0); | |
| 65 GtkWidget* text_vbox = gtk_vbox_new(FALSE, 0); | |
| 66 gtk_container_add(GTK_CONTAINER(text_alignment), text_vbox); | |
| 67 gtk_box_pack_start(GTK_BOX(vbox), text_alignment, TRUE, TRUE, 0); | |
| 68 | |
| 69 bookmarks_ = gtk_check_button_new_with_label( | |
| 70 l10n_util::GetStringUTF8(IDS_IMPORT_FAVORITES_CHKBOX).c_str()); | |
| 71 gtk_box_pack_start(GTK_BOX(text_vbox), bookmarks_, TRUE, TRUE, 5); | |
| 72 | |
| 73 search_engines_ = gtk_check_button_new_with_label( | |
| 74 l10n_util::GetStringUTF8(IDS_IMPORT_SEARCH_ENGINES_CHKBOX).c_str()); | |
| 75 gtk_box_pack_start(GTK_BOX(text_vbox), search_engines_, TRUE, TRUE, 5); | |
| 76 | |
| 77 passwords_ = gtk_check_button_new_with_label( | |
| 78 l10n_util::GetStringUTF8(IDS_IMPORT_PASSWORDS_CHKBOX).c_str()); | |
| 79 gtk_box_pack_start(GTK_BOX(text_vbox), passwords_, TRUE, TRUE, 5); | |
| 80 | |
| 81 history_ = gtk_check_button_new_with_label( | |
| 82 l10n_util::GetStringUTF8(IDS_IMPORT_HISTORY_CHKBOX).c_str()); | |
| 83 gtk_box_pack_start(GTK_BOX(text_vbox), history_, TRUE, TRUE, 5); | |
| 84 | |
| 85 g_signal_connect(dialog, "response", | |
| 86 G_CALLBACK(HandleOnResponseDialog), this); | |
| 87 gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); | |
| 88 gtk_widget_show_all(dialog); | |
| 89 } | |
| 90 | |
| 91 void ImportDialogGtk::OnDialogResponse(GtkWidget* widget, int response) { | |
| 92 if (response == GTK_RESPONSE_ACCEPT) { | |
| 93 uint16 items = NONE; | |
| 94 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(bookmarks_))) | |
| 95 items |= FAVORITES; | |
| 96 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(search_engines_))) | |
| 97 items |= SEARCH_ENGINES; | |
| 98 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(passwords_))) | |
| 99 items |= PASSWORDS; | |
| 100 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(history_))) | |
| 101 items |= HISTORY; | |
| 102 | |
| 103 const ProfileInfo& source_profile = importer_host_->GetSourceProfileInfoAt( | |
| 104 gtk_combo_box_get_active(GTK_COMBO_BOX(combo_))); | |
| 105 | |
| 106 // TODO(rahulk): We should not do the import on this thread. Instead | |
|
Evan Martin
2009/05/11 23:48:13
Please don't forget about this (file a bug if you'
| |
| 107 // we need to start this asynchronously and launch a UI that shows the | |
| 108 // progress of import. | |
| 109 importer_host_->StartImportSettings(source_profile, items, | |
| 110 new ProfileWriter(profile_), false); | |
| 111 } | |
| 112 | |
| 113 delete this; | |
| 114 gtk_widget_destroy(GTK_WIDGET(widget)); | |
| 115 } | |
| OLD | NEW |