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.
5 #include "chrome/browser/ui/gtk/importer/import_lock_dialog_gtk.h"
10 #include "base/message_loop/message_loop.h"
11 #include "chrome/browser/importer/importer_lock_dialog.h"
12 #include "chrome/browser/ui/gtk/gtk_util.h"
13 #include "content/public/browser/user_metrics.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"
19 using base::UserMetricsAction
;
23 void ShowImportLockDialog(gfx::NativeWindow parent
,
24 const base::Callback
<void(bool)>& callback
) {
25 ImportLockDialogGtk::Show(parent
, callback
);
26 content::RecordAction(UserMetricsAction("ImportLockDialogGtk_Shown"));
29 } // namespace importer
32 void ImportLockDialogGtk::Show(GtkWindow
* parent
,
33 const base::Callback
<void(bool)>& callback
) {
34 new ImportLockDialogGtk(parent
, callback
);
37 ImportLockDialogGtk::ImportLockDialogGtk(
39 const base::Callback
<void(bool)>& callback
) : callback_(callback
) {
41 dialog_
= gtk_dialog_new_with_buttons(
42 l10n_util::GetStringUTF8(IDS_IMPORTER_LOCK_TITLE
).c_str(),
44 (GtkDialogFlags
) (GTK_DIALOG_MODAL
| GTK_DIALOG_NO_SEPARATOR
),
47 gtk_util::AddButtonToDialog(dialog_
,
48 l10n_util::GetStringUTF8(IDS_IMPORTER_LOCK_CANCEL
).c_str(),
49 GTK_STOCK_CANCEL
, GTK_RESPONSE_REJECT
);
50 gtk_util::AddButtonToDialog(dialog_
,
51 l10n_util::GetStringUTF8(IDS_IMPORTER_LOCK_OK
).c_str(),
52 GTK_STOCK_OK
, GTK_RESPONSE_ACCEPT
);
54 GtkWidget
* content_area
= gtk_dialog_get_content_area(GTK_DIALOG(dialog_
));
55 gtk_box_set_spacing(GTK_BOX(content_area
), ui::kContentAreaSpacing
);
56 GtkWidget
* label
= gtk_label_new(
57 l10n_util::GetStringUTF8(IDS_IMPORTER_LOCK_TEXT
).c_str());
58 gtk_label_set_line_wrap(GTK_LABEL(label
), TRUE
);
59 gtk_box_pack_start(GTK_BOX(content_area
), label
, FALSE
, FALSE
, 0);
61 g_signal_connect(dialog_
, "response", G_CALLBACK(OnResponseThunk
), this);
62 gtk_window_set_resizable(GTK_WINDOW(dialog_
), FALSE
);
63 gtk_widget_show_all(dialog_
);
66 ImportLockDialogGtk::~ImportLockDialogGtk() {}
68 void ImportLockDialogGtk::OnResponse(GtkWidget
* dialog
, int response_id
) {
69 base::MessageLoop::current()->PostTask(
71 base::Bind(callback_
, response_id
== GTK_RESPONSE_ACCEPT
));
72 gtk_widget_destroy(dialog_
);