2 * Copyright (c) 2011-2016, JANET(UK)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of JANET(UK) nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 static const string GROUP_NAME="WarningDialogs";
36 // MessageDialog doesn't allow subclassing, so we merely wrap the
37 // constructor for it the dialog, and then run it, returning the result.
40 private static MoonshotLogger _logger = null;
41 private static MoonshotLogger logger()
43 if (_logger == null) {
44 _logger = get_logger("WarningDialog");
49 public static bool confirm(Window parent, string message, string dialog_name)
52 if (get_bool_setting(GROUP_NAME, dialog_name, false))
54 logger().trace(@"confirm: Settings group $GROUP_NAME has 'true' for key $dialog_name; skipping dialog and returning true.");
58 Gdk.Color white = make_color(65535, 65535, 65535);
60 MessageDialog dialog = new Gtk.MessageDialog(parent,
61 Gtk.DialogFlags.DESTROY_WITH_PARENT,
62 Gtk.MessageType.WARNING,
63 Gtk.ButtonsType.YES_NO,
66 var content_area = dialog.get_content_area();
67 CheckButton remember_checkbutton = null;
69 if (dialog_name != null && dialog_name != "")
71 remember_checkbutton = new CheckButton.with_label(_("Do not show this message again"));
72 remember_checkbutton.set_focus_on_click(false);
73 remember_checkbutton.has_focus = false;
74 content_area.has_focus = true;
76 // Not sure if 0.26 is the minimum for MessageDialog.get_message_area. 0.16 sure isn't :-(
78 var message_area = dialog.get_message_area();
79 ((Box)message_area).pack_start(remember_checkbutton, false, false, 12);
81 HBox hbox = new HBox(false, 0);
82 hbox.pack_start(new HBox(false, 0), true, true, 20);
83 hbox.pack_start(remember_checkbutton, false, false, 12);
84 ((Box)content_area).pack_start(hbox, true, true, 12);
88 // dialog.set_modal(true);
89 dialog.set_title(_("Warning"));
90 dialog.modify_bg(StateType.NORMAL, white);
92 // ((Box) content_area).set_spacing(12);
93 content_area.modify_bg(StateType.NORMAL, white);
95 content_area.show_all();
97 dialog.set_markup(message);
99 var ret = dialog.run();
101 if (ret == Gtk.ResponseType.YES && remember_checkbutton != null && remember_checkbutton.active)
103 set_bool_setting(GROUP_NAME, dialog_name, true);
107 return (ret == Gtk.ResponseType.YES);