| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/gtk/download/download_in_progress_dialog_gtk.h" | |
| 6 | |
| 7 #include <gtk/gtk.h> | |
| 8 | |
| 9 #include "base/callback.h" | |
| 10 #include "base/strings/string16.h" | |
| 11 #include "base/strings/string_number_conversions.h" | |
| 12 #include "chrome/browser/ui/gtk/gtk_util.h" | |
| 13 #include "grit/chromium_strings.h" | |
| 14 #include "grit/generated_resources.h" | |
| 15 #include "ui/base/l10n/l10n_util.h" | |
| 16 | |
| 17 // static | |
| 18 void DownloadInProgressDialogGtk::Show( | |
| 19 gfx::NativeWindow parent_window, | |
| 20 int download_count, | |
| 21 Browser::DownloadClosePreventionType dialog_type, | |
| 22 bool app_modal, | |
| 23 const base::Callback<void(bool)>& callback) { | |
| 24 new DownloadInProgressDialogGtk(parent_window, download_count, dialog_type, | |
| 25 app_modal, callback); | |
| 26 } | |
| 27 | |
| 28 DownloadInProgressDialogGtk::DownloadInProgressDialogGtk( | |
| 29 gfx::NativeWindow parent_window, | |
| 30 int download_count, | |
| 31 Browser::DownloadClosePreventionType dialog_type, | |
| 32 bool app_modal, | |
| 33 const base::Callback<void(bool)>& callback) | |
| 34 : app_modal_(app_modal), | |
| 35 callback_(callback) { | |
| 36 std::string title_text; | |
| 37 std::string explanation_text; | |
| 38 std::string ok_button_text; | |
| 39 switch (dialog_type) { | |
| 40 case Browser::DOWNLOAD_CLOSE_BROWSER_SHUTDOWN: | |
| 41 if (download_count == 1) { | |
| 42 title_text = l10n_util::GetStringUTF8( | |
| 43 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_TITLE); | |
| 44 explanation_text = l10n_util::GetStringUTF8( | |
| 45 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_EXPLANATION); | |
| 46 } else { | |
| 47 title_text = l10n_util::GetStringUTF8( | |
| 48 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_TITLE); | |
| 49 explanation_text = l10n_util::GetStringUTF8( | |
| 50 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_EXPLANATION); | |
| 51 } | |
| 52 ok_button_text = l10n_util::GetStringUTF8( | |
| 53 IDS_DOWNLOAD_REMOVE_CONFIRM_OK_BUTTON_LABEL); | |
| 54 break; | |
| 55 case Browser::DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE: | |
| 56 if (download_count == 1) { | |
| 57 title_text = l10n_util::GetStringUTF8( | |
| 58 IDS_SINGLE_INCOGNITO_DOWNLOAD_REMOVE_CONFIRM_TITLE); | |
| 59 explanation_text = l10n_util::GetStringUTF8( | |
| 60 IDS_SINGLE_INCOGNITO_DOWNLOAD_REMOVE_CONFIRM_EXPLANATION); | |
| 61 } else { | |
| 62 title_text = l10n_util::GetStringUTF8( | |
| 63 IDS_MULTIPLE_INCOGNITO_DOWNLOADS_REMOVE_CONFIRM_TITLE); | |
| 64 explanation_text = l10n_util::GetStringUTF8( | |
| 65 IDS_MULTIPLE_INCOGNITO_DOWNLOADS_REMOVE_CONFIRM_EXPLANATION); | |
| 66 } | |
| 67 ok_button_text = l10n_util::GetStringUTF8( | |
| 68 IDS_INCOGNITO_DOWNLOAD_REMOVE_CONFIRM_OK_BUTTON_LABEL); | |
| 69 break; | |
| 70 default: | |
| 71 // This dialog should have been created within the same thread invocation | |
| 72 // as the original test that lead to us, so it should always not be ok | |
| 73 // to close. | |
| 74 NOTREACHED(); | |
| 75 } | |
| 76 std::string cancel_button_text = l10n_util::GetStringUTF8( | |
| 77 IDS_DOWNLOAD_REMOVE_CONFIRM_CANCEL_BUTTON_LABEL); | |
| 78 | |
| 79 if (app_modal_) | |
| 80 gtk_util::MakeAppModalWindowGroup(); | |
| 81 GtkWidget* dialog = gtk_message_dialog_new( | |
| 82 parent_window, | |
| 83 static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL), | |
| 84 GTK_MESSAGE_QUESTION, | |
| 85 GTK_BUTTONS_NONE, | |
| 86 "%s", | |
| 87 title_text.c_str()); | |
| 88 gtk_dialog_add_button(GTK_DIALOG(dialog), | |
| 89 cancel_button_text.c_str(), GTK_RESPONSE_REJECT); | |
| 90 gtk_dialog_add_button(GTK_DIALOG(dialog), | |
| 91 ok_button_text.c_str(), GTK_RESPONSE_ACCEPT); | |
| 92 | |
| 93 gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), | |
| 94 "%s", | |
| 95 explanation_text.c_str()); | |
| 96 | |
| 97 g_signal_connect(dialog, "response", G_CALLBACK(OnResponseThunk), this); | |
| 98 | |
| 99 gtk_widget_show_all(dialog); | |
| 100 } | |
| 101 | |
| 102 DownloadInProgressDialogGtk::~DownloadInProgressDialogGtk() { | |
| 103 } | |
| 104 | |
| 105 void DownloadInProgressDialogGtk::OnResponse(GtkWidget* dialog, | |
| 106 int response_id) { | |
| 107 gtk_widget_destroy(dialog); | |
| 108 if (app_modal_) | |
| 109 gtk_util::AppModalDismissedUngroupWindows(); | |
| 110 callback_.Run(response_id == GTK_RESPONSE_ACCEPT); | |
| 111 delete this; | |
| 112 } | |
| OLD | NEW |