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/process_singleton_dialog_linux.h"
11 #include "base/basictypes.h"
12 #include "base/message_loop/message_loop.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/ui/gtk/gtk_util.h"
15 #include "grit/chromium_strings.h"
16 #include "ui/base/gtk/gtk_signal.h"
17 #include "ui/base/l10n/l10n_util.h"
21 class ProcessSingletonDialog
{
23 ProcessSingletonDialog(const std::string
& message
,
24 const std::string
& relaunch_text
);
26 int GetResponseId() const { return response_id_
; }
29 CHROMEGTK_CALLBACK_1(ProcessSingletonDialog
, void, OnResponse
, int);
34 DISALLOW_COPY_AND_ASSIGN(ProcessSingletonDialog
);
37 ProcessSingletonDialog::ProcessSingletonDialog(
38 const std::string
& message
,
39 const std::string
& relaunch_text
) {
40 dialog_
= gtk_message_dialog_new(
42 static_cast<GtkDialogFlags
>(0),
47 gtk_util::ApplyMessageDialogQuirks(dialog_
);
48 gtk_window_set_title(GTK_WINDOW(dialog_
),
49 l10n_util::GetStringUTF8(IDS_PRODUCT_NAME
).c_str());
50 gtk_dialog_add_button(GTK_DIALOG(dialog_
), GTK_STOCK_QUIT
,
52 gtk_dialog_add_button(GTK_DIALOG(dialog_
), relaunch_text
.c_str(),
54 gtk_dialog_set_default_response(GTK_DIALOG(dialog_
), GTK_RESPONSE_ACCEPT
);
56 g_signal_connect(dialog_
, "response", G_CALLBACK(OnResponseThunk
), this);
58 gtk_widget_show_all(dialog_
);
59 base::MessageLoop::current()->Run();
62 void ProcessSingletonDialog::OnResponse(GtkWidget
* dialog
, int response_id
) {
63 response_id_
= response_id
;
64 gtk_widget_destroy(dialog_
);
65 base::MessageLoop::current()->Quit();
70 bool ShowProcessSingletonDialog(const base::string16
& message
,
71 const base::string16
& relaunch_text
) {
72 ProcessSingletonDialog
dialog(base::UTF16ToUTF8(message
),
73 base::UTF16ToUTF8(relaunch_text
));
74 return dialog
.GetResponseId() == GTK_RESPONSE_ACCEPT
;