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_progress_dialog_gtk.h" |
| 6 |
| 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" |
| 9 #include "grit/chromium_strings.h" |
| 10 #include "grit/generated_resources.h" |
| 11 |
| 12 namespace { |
| 13 void SetItemImportStatus(GtkWidget* chkbox, int res_id, bool is_done) { |
| 14 std::string status = l10n_util::GetStringUTF8(res_id); |
| 15 // Windows version of this has fancy throbbers to indicate progress. Here |
| 16 // we rely on text until we can have something equivalent on Linux. |
| 17 if (is_done) |
| 18 status.append(" done."); |
| 19 else |
| 20 status.append(" importing..."); |
| 21 gtk_button_set_label(GTK_BUTTON(chkbox), status.c_str()); |
| 22 } |
| 23 } // namespace |
| 24 |
| 25 // static |
| 26 void ImportProgressDialogGtk::StartImport(GtkWindow* parent, |
| 27 int16 items, |
| 28 ImporterHost* importer_host, |
| 29 const ProfileInfo& browser_profile, |
| 30 Profile* profile, |
| 31 ImportObserver* observer, |
| 32 bool first_run) { |
| 33 ImportProgressDialogGtk* v = new ImportProgressDialogGtk( |
| 34 WideToUTF16(browser_profile.description), items, importer_host, observer, |
| 35 parent, browser_profile.browser_type == BOOKMARKS_HTML); |
| 36 |
| 37 // In headless mode it means that we don't show the progress window, but it |
| 38 // still need it to exist. No user interaction will be required. |
| 39 if (!importer_host->is_headless()) |
| 40 v->ShowDialog(); |
| 41 |
| 42 importer_host->StartImportSettings(browser_profile, profile, items, |
| 43 new ProfileWriter(profile), |
| 44 first_run); |
| 45 } |
| 46 |
| 47 //////////////////////////////////////////////////////////////////////////////// |
| 48 // ImporterHost::Observer implementation: |
| 49 void ImportProgressDialogGtk::ImportItemStarted(ImportItem item) { |
| 50 DCHECK(items_ & item); |
| 51 switch (item) { |
| 52 case FAVORITES: |
| 53 SetItemImportStatus(bookmarks_, |
| 54 IDS_IMPORT_PROGRESS_STATUS_BOOKMARKS, false); |
| 55 break; |
| 56 case SEARCH_ENGINES: |
| 57 SetItemImportStatus(search_engines_, |
| 58 IDS_IMPORT_PROGRESS_STATUS_SEARCH, false); |
| 59 break; |
| 60 case PASSWORDS: |
| 61 SetItemImportStatus(passwords_, |
| 62 IDS_IMPORT_PROGRESS_STATUS_PASSWORDS, false); |
| 63 break; |
| 64 case HISTORY: |
| 65 SetItemImportStatus(history_, |
| 66 IDS_IMPORT_PROGRESS_STATUS_HISTORY, false); |
| 67 break; |
| 68 default: |
| 69 break; |
| 70 } |
| 71 } |
| 72 |
| 73 void ImportProgressDialogGtk::ImportItemEnded(ImportItem item) { |
| 74 DCHECK(items_ & item); |
| 75 switch (item) { |
| 76 case FAVORITES: |
| 77 SetItemImportStatus(bookmarks_, |
| 78 IDS_IMPORT_PROGRESS_STATUS_BOOKMARKS, true); |
| 79 break; |
| 80 case SEARCH_ENGINES: |
| 81 SetItemImportStatus(search_engines_, |
| 82 IDS_IMPORT_PROGRESS_STATUS_SEARCH, true); |
| 83 break; |
| 84 case PASSWORDS: |
| 85 SetItemImportStatus(passwords_, |
| 86 IDS_IMPORT_PROGRESS_STATUS_PASSWORDS, true); |
| 87 break; |
| 88 case HISTORY: |
| 89 SetItemImportStatus(history_, |
| 90 IDS_IMPORT_PROGRESS_STATUS_HISTORY, true); |
| 91 break; |
| 92 default: |
| 93 break; |
| 94 } |
| 95 } |
| 96 |
| 97 void ImportProgressDialogGtk::ImportStarted() { |
| 98 importing_ = true; |
| 99 } |
| 100 |
| 101 void ImportProgressDialogGtk::ImportEnded() { |
| 102 importing_ = false; |
| 103 importer_host_->SetObserver(NULL); |
| 104 if (observer_) |
| 105 observer_->ImportComplete(); |
| 106 CloseDialog(); |
| 107 } |
| 108 |
| 109 ImportProgressDialogGtk::ImportProgressDialogGtk(const string16& source_profile, |
| 110 int16 items, ImporterHost* importer_host, ImportObserver* observer, |
| 111 GtkWindow* parent, bool bookmarks_import) : |
| 112 parent_(parent), importing_(true), observer_(observer), |
| 113 items_(items), importer_host_(importer_host) { |
| 114 importer_host_->SetObserver(this); |
| 115 |
| 116 // Build the dialog. |
| 117 dialog_ = gtk_dialog_new_with_buttons( |
| 118 l10n_util::GetStringUTF8(IDS_IMPORT_PROGRESS_TITLE).c_str(), |
| 119 parent_, |
| 120 (GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), |
| 121 GTK_STOCK_CANCEL, |
| 122 GTK_RESPONSE_REJECT, |
| 123 NULL); |
| 124 |
| 125 GtkWidget* content_area = GTK_DIALOG(dialog_)->vbox; |
| 126 gtk_box_set_spacing(GTK_BOX(content_area), 18); |
| 127 |
| 128 GtkWidget* import_info = gtk_label_new( |
| 129 l10n_util::GetStringFUTF8(IDS_IMPORT_PROGRESS_INFO, |
| 130 source_profile).c_str()); |
| 131 gtk_label_set_single_line_mode(GTK_LABEL(import_info), FALSE); |
| 132 gtk_box_pack_start(GTK_BOX(content_area), import_info, FALSE, FALSE, 0); |
| 133 |
| 134 bookmarks_ = gtk_check_button_new_with_label( |
| 135 l10n_util::GetStringUTF8(IDS_IMPORT_PROGRESS_STATUS_BOOKMARKS).c_str()); |
| 136 gtk_box_pack_start(GTK_BOX(content_area), bookmarks_, FALSE, FALSE, 0); |
| 137 gtk_widget_set_sensitive(bookmarks_, FALSE); |
| 138 if (items_ & FAVORITES) |
| 139 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(bookmarks_), TRUE); |
| 140 |
| 141 search_engines_ = gtk_check_button_new_with_label( |
| 142 l10n_util::GetStringUTF8(IDS_IMPORT_PROGRESS_STATUS_SEARCH).c_str()); |
| 143 gtk_box_pack_start(GTK_BOX(content_area), search_engines_, FALSE, FALSE, 0); |
| 144 gtk_widget_set_sensitive(search_engines_, FALSE); |
| 145 if (items_ & SEARCH_ENGINES) |
| 146 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(search_engines_), TRUE); |
| 147 |
| 148 passwords_ = gtk_check_button_new_with_label( |
| 149 l10n_util::GetStringUTF8(IDS_IMPORT_PROGRESS_STATUS_PASSWORDS).c_str()); |
| 150 gtk_box_pack_start(GTK_BOX(content_area), passwords_, FALSE, FALSE, 0); |
| 151 gtk_widget_set_sensitive(passwords_, FALSE); |
| 152 if (items_ & PASSWORDS) |
| 153 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(passwords_), TRUE); |
| 154 |
| 155 history_ = gtk_check_button_new_with_label( |
| 156 l10n_util::GetStringUTF8(IDS_IMPORT_PROGRESS_STATUS_HISTORY).c_str()); |
| 157 gtk_box_pack_start(GTK_BOX(content_area), history_, FALSE, FALSE, 0); |
| 158 gtk_widget_set_sensitive(history_, FALSE); |
| 159 if (items_ & HISTORY) |
| 160 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(history_), TRUE); |
| 161 |
| 162 g_signal_connect(dialog_, "response", |
| 163 G_CALLBACK(HandleOnResponseDialog), this); |
| 164 gtk_window_set_resizable(GTK_WINDOW(dialog_), FALSE); |
| 165 } |
| 166 |
| 167 void ImportProgressDialogGtk::CloseDialog() { |
| 168 gtk_widget_destroy(dialog_); |
| 169 dialog_ = NULL; |
| 170 delete this; |
| 171 } |
| 172 |
| 173 void ImportProgressDialogGtk::OnDialogResponse(GtkWidget* widget, |
| 174 int response) { |
| 175 if (!importing_) { |
| 176 CloseDialog(); |
| 177 return; |
| 178 } |
| 179 |
| 180 // Only response to the dialog is to close it so we hide immediately. |
| 181 gtk_widget_hide_all(dialog_); |
| 182 if (response == GTK_RESPONSE_REJECT) |
| 183 importer_host_->Cancel(); |
| 184 } |
| 185 |
| 186 void ImportProgressDialogGtk::ShowDialog() { |
| 187 gtk_widget_show_all(dialog_); |
| 188 } |
| 189 |
| 190 |
| 191 void StartImportingWithUI(GtkWindow* parent, |
| 192 int16 items, |
| 193 ImporterHost* importer_host, |
| 194 const ProfileInfo& browser_profile, |
| 195 Profile* profile, |
| 196 ImportObserver* observer, |
| 197 bool first_run) { |
| 198 DCHECK(items != 0); |
| 199 ImportProgressDialogGtk::StartImport(parent, items, importer_host, |
| 200 browser_profile, profile, observer, |
| 201 first_run); |
| 202 } |
OLD | NEW |