Home | History | Annotate | Download | only in gtk
      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/instant_confirm_dialog_gtk.h"
      6 
      7 #include <gtk/gtk.h>
      8 
      9 #include "chrome/browser/instant/instant_confirm_dialog.h"
     10 #include "chrome/browser/instant/instant_controller.h"
     11 #include "chrome/browser/profiles/profile.h"
     12 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h"
     13 #include "chrome/browser/ui/gtk/gtk_util.h"
     14 #include "chrome/browser/ui/options/show_options_url.h"
     15 #include "googleurl/src/gurl.h"
     16 #include "grit/chromium_strings.h"
     17 #include "grit/generated_resources.h"
     18 #include "ui/base/l10n/l10n_util.h"
     19 
     20 namespace browser {
     21 
     22 void ShowInstantConfirmDialog(GtkWindow* parent, Profile* profile) {
     23   new InstantConfirmDialogGtk(parent, profile);
     24 }
     25 
     26 }  // namespace browser
     27 
     28 InstantConfirmDialogGtk::InstantConfirmDialogGtk(
     29     GtkWindow* parent, Profile* profile) : profile_(profile) {
     30   dialog_ = gtk_dialog_new_with_buttons(
     31       l10n_util::GetStringUTF8(IDS_INSTANT_OPT_IN_TITLE).c_str(),
     32       parent,
     33       static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR),
     34       GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
     35       GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
     36       NULL);
     37   g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this);
     38 
     39   GtkBox* vbox = GTK_BOX(GTK_DIALOG(dialog_)->vbox);
     40   gtk_box_set_spacing(vbox, gtk_util::kControlSpacing);
     41 
     42   GtkWidget* label = gtk_label_new(
     43       l10n_util::GetStringUTF8(IDS_INSTANT_OPT_IN_MESSAGE).c_str());
     44   gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
     45   gtk_box_pack_start(vbox, label, FALSE, FALSE, 0);
     46 
     47   GtkWidget* link_button = gtk_chrome_link_button_new(
     48       l10n_util::GetStringUTF8(IDS_LEARN_MORE).c_str());
     49   g_signal_connect(link_button, "clicked",
     50                    G_CALLBACK(OnLinkButtonClickedThunk), this);
     51 
     52   GtkWidget* action_area = GTK_DIALOG(dialog_)->action_area;
     53   gtk_container_add(GTK_CONTAINER(action_area), link_button);
     54   gtk_button_box_set_child_secondary(GTK_BUTTON_BOX(action_area),
     55                                      link_button,
     56                                      TRUE);
     57 
     58   gtk_dialog_set_default_response(GTK_DIALOG(dialog_), GTK_RESPONSE_ACCEPT);
     59   gtk_widget_show_all(dialog_);
     60 }
     61 
     62 InstantConfirmDialogGtk::~InstantConfirmDialogGtk() {
     63   gtk_widget_destroy(dialog_);
     64 }
     65 
     66 void InstantConfirmDialogGtk::OnResponse(GtkWidget* dialog, int response_id) {
     67   if (response_id == GTK_RESPONSE_ACCEPT)
     68     InstantController::Enable(profile_);
     69 
     70   delete this;
     71 }
     72 
     73 void InstantConfirmDialogGtk::OnLinkButtonClicked(GtkWidget* button) {
     74   browser::ShowOptionsURL(profile_, browser::InstantLearnMoreURL());
     75 }
     76