OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/process_singleton_dialog.h" | 5 #include "chrome/browser/ui/gtk/process_singleton_dialog.h" |
6 | 6 |
7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 | 8 |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "chrome/browser/ui/gtk/gtk_util.h" | 10 #include "chrome/browser/ui/gtk/gtk_util.h" |
11 #include "grit/chromium_strings.h" | 11 #include "grit/chromium_strings.h" |
12 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
13 | 13 |
14 // static | 14 // static |
15 bool ProcessSingletonDialog::ShowAndRun(const std::string& message, | 15 void ProcessSingletonDialog::ShowAndRun(const std::string& message) { |
16 const std::string& relaunch_text) { | 16 ProcessSingletonDialog dialog(message); |
17 ProcessSingletonDialog dialog(message, relaunch_text); | |
18 return dialog.GetResponseId() == GTK_RESPONSE_ACCEPT; | |
19 } | 17 } |
20 | 18 |
21 ProcessSingletonDialog::ProcessSingletonDialog( | 19 ProcessSingletonDialog::ProcessSingletonDialog(const std::string& message) { |
22 const std::string& message, | |
23 const std::string& relaunch_text) { | |
24 dialog_ = gtk_message_dialog_new( | 20 dialog_ = gtk_message_dialog_new( |
25 NULL, | 21 NULL, |
26 static_cast<GtkDialogFlags>(0), | 22 static_cast<GtkDialogFlags>(0), |
27 GTK_MESSAGE_ERROR, | 23 GTK_MESSAGE_ERROR, |
28 GTK_BUTTONS_NONE, | 24 GTK_BUTTONS_NONE, |
29 "%s", | 25 "%s", |
30 message.c_str()); | 26 message.c_str()); |
31 gtk_util::ApplyMessageDialogQuirks(dialog_); | 27 gtk_util::ApplyMessageDialogQuirks(dialog_); |
32 gtk_window_set_title(GTK_WINDOW(dialog_), | 28 gtk_window_set_title(GTK_WINDOW(dialog_), |
33 l10n_util::GetStringUTF8(IDS_PRODUCT_NAME).c_str()); | 29 l10n_util::GetStringUTF8(IDS_PRODUCT_NAME).c_str()); |
34 gtk_dialog_add_button(GTK_DIALOG(dialog_), GTK_STOCK_QUIT, | 30 gtk_dialog_add_button(GTK_DIALOG(dialog_), GTK_STOCK_QUIT, |
35 GTK_RESPONSE_REJECT); | 31 GTK_RESPONSE_REJECT); |
36 gtk_dialog_add_button(GTK_DIALOG(dialog_), relaunch_text.c_str(), | |
37 GTK_RESPONSE_ACCEPT); | |
38 gtk_dialog_set_default_response(GTK_DIALOG(dialog_), GTK_RESPONSE_ACCEPT); | |
39 | 32 |
40 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); | 33 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); |
41 | 34 |
42 gtk_widget_show_all(dialog_); | 35 gtk_widget_show_all(dialog_); |
43 base::MessageLoop::current()->Run(); | 36 base::MessageLoop::current()->Run(); |
44 } | 37 } |
45 | 38 |
46 void ProcessSingletonDialog::OnResponse(GtkWidget* dialog, int response_id) { | 39 void ProcessSingletonDialog::OnResponse(GtkWidget* dialog, int response_id) { |
47 response_id_ = response_id; | |
48 gtk_widget_destroy(dialog_); | 40 gtk_widget_destroy(dialog_); |
49 base::MessageLoop::current()->Quit(); | 41 base::MessageLoop::current()->Quit(); |
50 } | 42 } |
OLD | NEW |