Home | History | Annotate | Download | only in download
      1 // Copyright (c) 2011 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/string16.h"
     10 #include "base/string_number_conversions.h"
     11 #include "chrome/browser/download/download_manager.h"
     12 #include "chrome/browser/profiles/profile.h"
     13 #include "chrome/browser/ui/browser.h"
     14 #include "chrome/browser/ui/browser_window.h"
     15 #include "chrome/browser/ui/gtk/gtk_util.h"
     16 #include "grit/chromium_strings.h"
     17 #include "grit/generated_resources.h"
     18 #include "ui/base/l10n/l10n_util.h"
     19 
     20 DownloadInProgressDialogGtk::DownloadInProgressDialogGtk(Browser* browser)
     21     : browser_(browser) {
     22   int download_count = browser->profile()->GetDownloadManager()->
     23       in_progress_count();
     24 
     25   std::string warning_text;
     26   std::string explanation_text;
     27   std::string ok_button_text;
     28   std::string cancel_button_text;
     29   string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
     30   if (download_count == 1) {
     31     warning_text =
     32         l10n_util::GetStringFUTF8(IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_WARNING,
     33                                   product_name);
     34     explanation_text =
     35         l10n_util::GetStringFUTF8(
     36             IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_EXPLANATION,
     37             product_name);
     38     ok_button_text = l10n_util::GetStringUTF8(
     39         IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_OK_BUTTON_LABEL);
     40     cancel_button_text = l10n_util::GetStringUTF8(
     41         IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_CANCEL_BUTTON_LABEL);
     42   } else {
     43     warning_text =
     44         l10n_util::GetStringFUTF8(IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_WARNING,
     45                                   product_name,
     46                                   base::IntToString16(download_count));
     47     explanation_text =
     48         l10n_util::GetStringFUTF8(
     49             IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_EXPLANATION, product_name);
     50     ok_button_text = l10n_util::GetStringUTF8(
     51         IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_OK_BUTTON_LABEL);
     52     cancel_button_text = l10n_util::GetStringUTF8(
     53         IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_CANCEL_BUTTON_LABEL);
     54   }
     55 
     56   GtkWidget* dialog = gtk_message_dialog_new(
     57       browser_->window()->GetNativeHandle(),
     58       static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL),
     59       GTK_MESSAGE_QUESTION,
     60       GTK_BUTTONS_NONE,
     61       "%s",
     62       warning_text.c_str());
     63   gtk_util::AddButtonToDialog(dialog,
     64       cancel_button_text.c_str(),
     65       GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
     66   gtk_util::AddButtonToDialog(dialog,
     67       ok_button_text.c_str(),
     68       GTK_STOCK_OK, GTK_RESPONSE_ACCEPT);
     69 
     70   gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
     71                                            "%s",
     72                                            explanation_text.c_str());
     73 
     74   g_signal_connect(dialog, "response", G_CALLBACK(OnResponseThunk), this);
     75 
     76   gtk_widget_show_all(dialog);
     77 }
     78 
     79 void DownloadInProgressDialogGtk::OnResponse(GtkWidget* dialog,
     80                                              int response_id) {
     81   gtk_widget_destroy(dialog);
     82   browser_->InProgressDownloadResponse(response_id == GTK_RESPONSE_ACCEPT);
     83   delete this;
     84 }
     85