| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/gtk/download/download_in_progress_dialog_gtk.h" | 5 #include "chrome/browser/ui/gtk/download/download_in_progress_dialog_gtk.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include "base/string16.h" | 9 #include "base/string16.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| 11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/gtk/gtk_util.h" | 12 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 13 #include "grit/chromium_strings.h" | 13 #include "grit/chromium_strings.h" |
| 14 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 16 | 16 |
| 17 // static | 17 // static |
| 18 void DownloadInProgressDialogGtk::Show(Browser* browser, | 18 void DownloadInProgressDialogGtk::Show(Browser* browser, |
| 19 gfx::NativeWindow parent_window) { | 19 gfx::NativeWindow parent_window) { |
| 20 new DownloadInProgressDialogGtk(browser, parent_window); | 20 new DownloadInProgressDialogGtk(browser, parent_window); |
| 21 } | 21 } |
| 22 | 22 |
| 23 DownloadInProgressDialogGtk::DownloadInProgressDialogGtk( | 23 DownloadInProgressDialogGtk::DownloadInProgressDialogGtk( |
| 24 Browser* browser, | 24 Browser* browser, |
| 25 gfx::NativeWindow parent_window) | 25 gfx::NativeWindow parent_window) |
| 26 : browser_(browser) { | 26 : browser_(browser) { |
| 27 int download_count; | 27 int download_count; |
| 28 Browser::DownloadClosePreventionType type = | 28 Browser::DownloadClosePreventionType dialog_type = |
| 29 browser_->OkToCloseWithInProgressDownloads(&download_count); | 29 browser_->OkToCloseWithInProgressDownloads(&download_count); |
| 30 | 30 |
| 31 // This dialog should have been created within the same thread invocation | 31 std::string title_text; |
| 32 // as the original test that lead to us, so it should always not be ok | |
| 33 // to close. | |
| 34 DCHECK_NE(Browser::DOWNLOAD_CLOSE_OK, type); | |
| 35 | |
| 36 // TODO(rdsmith): This dialog should be different depending on whether we're | |
| 37 // closing the last incognito window of a profile or doing browser shutdown. | |
| 38 // See http://crbug.com/88421. | |
| 39 | |
| 40 std::string warning_text; | |
| 41 std::string explanation_text; | 32 std::string explanation_text; |
| 42 std::string ok_button_text; | 33 std::string ok_button_text; |
| 43 std::string cancel_button_text; | 34 switch (dialog_type) { |
| 44 if (download_count == 1) { | 35 case Browser::DOWNLOAD_CLOSE_BROWSER_SHUTDOWN: |
| 45 warning_text = l10n_util::GetStringUTF8( | 36 if (download_count == 1) { |
| 46 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_WARNING); | 37 title_text = l10n_util::GetStringUTF8( |
| 47 explanation_text = l10n_util::GetStringUTF8( | 38 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_TITLE); |
| 48 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_EXPLANATION); | 39 explanation_text = l10n_util::GetStringUTF8( |
| 49 ok_button_text = l10n_util::GetStringUTF8( | 40 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_EXPLANATION); |
| 50 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_OK_BUTTON_LABEL); | 41 } else { |
| 51 cancel_button_text = l10n_util::GetStringUTF8( | 42 title_text = l10n_util::GetStringUTF8( |
| 52 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_CANCEL_BUTTON_LABEL); | 43 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_TITLE); |
| 53 } else { | 44 explanation_text = l10n_util::GetStringUTF8( |
| 54 warning_text = l10n_util::GetStringFUTF8( | 45 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_EXPLANATION); |
| 55 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_WARNING, | 46 } |
| 56 base::IntToString16(download_count)); | 47 ok_button_text = l10n_util::GetStringUTF8( |
| 57 explanation_text = l10n_util::GetStringUTF8( | 48 IDS_DOWNLOAD_REMOVE_CONFIRM_OK_BUTTON_LABEL); |
| 58 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_EXPLANATION); | 49 break; |
| 59 ok_button_text = l10n_util::GetStringUTF8( | 50 case Browser::DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE: |
| 60 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_OK_BUTTON_LABEL); | 51 if (download_count == 1) { |
| 61 cancel_button_text = l10n_util::GetStringUTF8( | 52 title_text = l10n_util::GetStringUTF8( |
| 62 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_CANCEL_BUTTON_LABEL); | 53 IDS_SINGLE_INCOGNITO_DOWNLOAD_REMOVE_CONFIRM_TITLE); |
| 54 explanation_text = l10n_util::GetStringUTF8( |
| 55 IDS_SINGLE_INCOGNITO_DOWNLOAD_REMOVE_CONFIRM_EXPLANATION); |
| 56 } else { |
| 57 title_text = l10n_util::GetStringUTF8( |
| 58 IDS_MULTIPLE_INCOGNITO_DOWNLOADS_REMOVE_CONFIRM_TITLE); |
| 59 explanation_text = l10n_util::GetStringUTF8( |
| 60 IDS_MULTIPLE_INCOGNITO_DOWNLOADS_REMOVE_CONFIRM_EXPLANATION); |
| 61 } |
| 62 ok_button_text = l10n_util::GetStringUTF8( |
| 63 IDS_INCOGNITO_DOWNLOAD_REMOVE_CONFIRM_OK_BUTTON_LABEL); |
| 64 break; |
| 65 default: |
| 66 // This dialog should have been created within the same thread invocation |
| 67 // as the original test that lead to us, so it should always not be ok |
| 68 // to close. |
| 69 NOTREACHED(); |
| 63 } | 70 } |
| 71 std::string cancel_button_text = l10n_util::GetStringUTF8( |
| 72 IDS_DOWNLOAD_REMOVE_CONFIRM_CANCEL_BUTTON_LABEL); |
| 64 | 73 |
| 65 GtkWidget* dialog = gtk_message_dialog_new( | 74 GtkWidget* dialog = gtk_message_dialog_new( |
| 66 parent_window, | 75 parent_window, |
| 67 static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL), | 76 static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL), |
| 68 GTK_MESSAGE_QUESTION, | 77 GTK_MESSAGE_QUESTION, |
| 69 GTK_BUTTONS_NONE, | 78 GTK_BUTTONS_NONE, |
| 70 "%s", | 79 "%s", |
| 71 warning_text.c_str()); | 80 title_text.c_str()); |
| 72 gtk_util::AddButtonToDialog(dialog, cancel_button_text.c_str(), | 81 gtk_dialog_add_button(GTK_DIALOG(dialog), |
| 73 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT); | 82 cancel_button_text.c_str(), GTK_RESPONSE_REJECT); |
| 74 gtk_util::AddButtonToDialog(dialog, ok_button_text.c_str(), | 83 gtk_dialog_add_button(GTK_DIALOG(dialog), |
| 75 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT); | 84 ok_button_text.c_str(), GTK_RESPONSE_ACCEPT); |
| 76 | 85 |
| 77 gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), | 86 gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), |
| 78 "%s", | 87 "%s", |
| 79 explanation_text.c_str()); | 88 explanation_text.c_str()); |
| 80 | 89 |
| 81 g_signal_connect(dialog, "response", G_CALLBACK(OnResponseThunk), this); | 90 g_signal_connect(dialog, "response", G_CALLBACK(OnResponseThunk), this); |
| 82 | 91 |
| 83 gtk_widget_show_all(dialog); | 92 gtk_widget_show_all(dialog); |
| 84 } | 93 } |
| 85 | 94 |
| 86 DownloadInProgressDialogGtk::~DownloadInProgressDialogGtk() { | 95 DownloadInProgressDialogGtk::~DownloadInProgressDialogGtk() { |
| 87 } | 96 } |
| 88 | 97 |
| 89 void DownloadInProgressDialogGtk::OnResponse(GtkWidget* dialog, | 98 void DownloadInProgressDialogGtk::OnResponse(GtkWidget* dialog, |
| 90 int response_id) { | 99 int response_id) { |
| 91 gtk_widget_destroy(dialog); | 100 gtk_widget_destroy(dialog); |
| 92 browser_->InProgressDownloadResponse(response_id == GTK_RESPONSE_ACCEPT); | 101 browser_->InProgressDownloadResponse(response_id == GTK_RESPONSE_ACCEPT); |
| 93 delete this; | 102 delete this; |
| 94 } | 103 } |
| OLD | NEW |