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/one_click_signin_dialog_gtk.h" | 5 #include "chrome/browser/ui/sync/one_click_signin_dialog.h" |
6 | 6 |
7 #include <gtk/gtk.h> | |
8 | |
9 #include "base/basictypes.h" | |
10 #include "base/callback.h" | |
11 #include "base/compiler_specific.h" | |
12 #include "base/logging.h" | 7 #include "base/logging.h" |
13 #include "chrome/browser/ui/gtk/gtk_util.h" | |
14 #include "grit/chromium_strings.h" | |
15 #include "grit/generated_resources.h" | |
16 #include "ui/base/gtk/gtk_hig_constants.h" | |
17 #include "ui/base/l10n/l10n_util.h" | |
18 | |
19 OneClickSigninDialogGtk::OneClickSigninDialogGtk( | |
20 GtkWindow* parent_window, | |
21 const OneClickAcceptCallback& accept_callback) | |
22 : dialog_(NULL), | |
23 use_default_settings_checkbox_(NULL), | |
24 accept_callback_(accept_callback) { | |
25 // Lay out the dialog. | |
26 | |
27 dialog_ = gtk_dialog_new_with_buttons( | |
28 l10n_util::GetStringUTF8(IDS_ONE_CLICK_SIGNIN_DIALOG_TITLE).c_str(), | |
29 parent_window, | |
30 GTK_DIALOG_MODAL, | |
31 NULL); | |
32 | |
33 ignore_result(gtk_dialog_add_button( | |
34 GTK_DIALOG(dialog_), | |
35 l10n_util::GetStringUTF8(IDS_CANCEL).c_str(), | |
36 GTK_RESPONSE_CLOSE)); | |
37 GtkWidget* ok_button = gtk_dialog_add_button( | |
38 GTK_DIALOG(dialog_), | |
39 l10n_util::GetStringUTF8(IDS_ONE_CLICK_SIGNIN_DIALOG_OK_BUTTON).c_str(), | |
40 GTK_RESPONSE_ACCEPT); | |
41 #if !GTK_CHECK_VERSION(2, 22, 0) | |
42 gtk_dialog_set_has_separator(GTK_DIALOG(dialog_), FALSE); | |
43 #endif | |
44 | |
45 GtkWidget* const content_area = | |
46 gtk_dialog_get_content_area(GTK_DIALOG(dialog_)); | |
47 gtk_box_set_spacing(GTK_BOX(content_area), ui::kContentAreaSpacing); | |
48 | |
49 // Heading. | |
50 GtkWidget* heading_label = gtk_util::CreateBoldLabel( | |
51 l10n_util::GetStringUTF8(IDS_ONE_CLICK_SIGNIN_DIALOG_HEADING).c_str()); | |
52 gtk_label_set_line_wrap(GTK_LABEL(heading_label), TRUE); | |
53 gtk_misc_set_alignment(GTK_MISC(heading_label), 0.0, 0.5); | |
54 gtk_box_pack_start(GTK_BOX(content_area), heading_label, FALSE, FALSE, 0); | |
55 | |
56 // Message. | |
57 GtkWidget* message_label = gtk_label_new( | |
58 l10n_util::GetStringUTF8(IDS_ONE_CLICK_SIGNIN_DIALOG_MESSAGE).c_str()); | |
59 gtk_label_set_line_wrap(GTK_LABEL(message_label), TRUE); | |
60 gtk_misc_set_alignment(GTK_MISC(message_label), 0.0, 0.5); | |
61 gtk_box_pack_start(GTK_BOX(content_area), message_label, FALSE, FALSE, 0); | |
62 | |
63 // Checkbox. | |
64 use_default_settings_checkbox_ = gtk_check_button_new_with_label( | |
65 l10n_util::GetStringUTF8( | |
66 IDS_ONE_CLICK_SIGNIN_DIALOG_CHECKBOX).c_str()); | |
67 gtk_toggle_button_set_active( | |
68 GTK_TOGGLE_BUTTON(use_default_settings_checkbox_), TRUE); | |
69 gtk_box_pack_start(GTK_BOX(content_area), | |
70 use_default_settings_checkbox_, FALSE, FALSE, 0); | |
71 | |
72 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); | |
73 gtk_window_set_resizable(GTK_WINDOW(dialog_), FALSE); | |
74 | |
75 gtk_dialog_set_default_response(GTK_DIALOG(dialog_), GTK_RESPONSE_ACCEPT); | |
76 gtk_widget_show_all(dialog_); | |
77 gtk_widget_grab_focus(ok_button); | |
78 } | |
79 | |
80 void OneClickSigninDialogGtk::SetUseDefaultSettingsForTest( | |
81 bool use_default_settings) { | |
82 gtk_toggle_button_set_active( | |
83 GTK_TOGGLE_BUTTON(use_default_settings_checkbox_), FALSE); | |
84 } | |
85 | |
86 void OneClickSigninDialogGtk::SendResponseForTest(int response_id) { | |
87 OnResponse(dialog_, response_id); | |
88 } | |
89 | |
90 OneClickSigninDialogGtk::~OneClickSigninDialogGtk() {} | |
91 | |
92 void OneClickSigninDialogGtk::OnResponse(GtkWidget* dialog, int response_id) { | |
93 if (response_id == GTK_RESPONSE_ACCEPT) { | |
94 const bool use_default_settings = | |
95 gtk_toggle_button_get_active( | |
96 GTK_TOGGLE_BUTTON(use_default_settings_checkbox_)); | |
97 accept_callback_.Run(use_default_settings); | |
98 } | |
99 | |
100 gtk_widget_destroy(dialog_); | |
101 delete this; | |
102 } | |
103 | 8 |
104 void ShowOneClickSigninDialog( | 9 void ShowOneClickSigninDialog( |
105 gfx::NativeWindow parent_window, | 10 gfx::NativeWindow parent_window, |
106 const OneClickAcceptCallback& accept_callback) { | 11 const OneClickAcceptCallback& accept_callback) { |
107 ignore_result( | 12 // TODO(rogerta): gtk dialog not yet implemented. See |
108 new OneClickSigninDialogGtk(parent_window, accept_callback)); | 13 // one_click_signin_dialog_view.cc for what needs to be done here. |
| 14 NOTREACHED(); |
109 } | 15 } |
OLD | NEW |