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