Updated the appearance of two warning dialogs.
authorDan Breslau <dbreslau@painless-security.com>
Fri, 5 Aug 2016 00:46:55 +0000 (20:46 -0400)
committerDan Breslau <dbreslau@painless-security.com>
Fri, 5 Aug 2016 00:46:55 +0000 (20:46 -0400)
Also fixed (somewhat) the appearance of the menu bar in the main window.

Makefile.am
src/moonshot-identity-dialog.vala
src/moonshot-identity-management-view.vala
src/moonshot-warning-dialog.vala [new file with mode: 0644]

index 6f97610..5a537cf 100644 (file)
@@ -69,7 +69,8 @@ src_moonshot_SOURCES = \
         src/moonshot-provisioning-common.vala \
         src/moonshot-utils.vala \
         src/moonshot-futils.c \
-        src/moonshot-logger.vala
+        src/moonshot-logger.vala \
+        src/moonshot-warning-dialog.vala
 
 src_moonshot_webp_SOURCES = \
         src/moonshot-webp-parser.vala \
index ce3899f..dba74ca 100644 (file)
@@ -53,7 +53,6 @@ class IdentityDialog : Dialog
     static const string username_labeltext = _("Username");
     static const string password_labeltext = _("Password");
 
-    private IdentityManagerView parent;
     private Entry displayname_entry;
     private Label displayname_label;
     private Entry realm_entry;
@@ -111,7 +110,6 @@ class IdentityDialog : Dialog
         this.set_title(title);
         this.set_modal(true);
         this.set_transient_for(parent);
-        this.parent = parent;
 
         this.add_buttons(_("OK"), ResponseType.OK, CANCEL, ResponseType.CANCEL);
         Box content_area = (Box) this.get_content_area();
@@ -364,16 +362,13 @@ class IdentityDialog : Dialog
 
         remove_button.clicked.connect((remove_button) =>
             {
-                var dialog = new Gtk.MessageDialog(this,
-                                                   Gtk.DialogFlags.DESTROY_WITH_PARENT,
-                                                   Gtk.MessageType.QUESTION,
-                                                   Gtk.ButtonsType.YES_NO,
-                                                   _("You are about to remove the service '%s'. Are you sure you want to do this?"),
-                                                   selected_item.label);
-                var ret = dialog.run();
-                dialog.destroy();
-
-                if (ret == Gtk.ResponseType.YES)
+                var result = WarningDialog.confirm(this,
+                                                   "<span font-weight='heavy'>You are about to remove the service '%s'.</span>"
+                                                   .printf(selected_item.label)
+                                                   + "\n\nAre you sure you want to do this?",
+                                                   "delete_service");
+
+                if (result)
                 {
                     if (card != null) {
                         SList<string> services = new SList<string>();
index c888762..8033d75 100644 (file)
@@ -311,8 +311,10 @@ public class IdentityManagerView : Window {
         #else
         Gtk.MessageDialog dialog;
         IdCard? prev_id = identities_manager.find_id_card(id_card.nai, force_flat_file_store);
+        logger.trace("add_identity: find_id_card returned " + (prev_id != null ? "non-null" : "null"));
         if (prev_id!=null) {
             int flags = prev_id.Compare(id_card);
+            logger.trace("add_identity: compare returned " + flags.to_string());
             if (flags == 0) {
                 return false; // no changes, no need to update
             } else if ((flags & (1 << IdCard.DiffFlags.DISPLAY_NAME)) != 0) {
@@ -426,20 +428,13 @@ public class IdentityManagerView : Window {
     {
         var id_card = id_card_widget.id_card;
 
-        var dialog = new MessageDialog(this,
-                                       DialogFlags.DESTROY_WITH_PARENT,
-                                       MessageType.QUESTION,
-                                       Gtk.ButtonsType.YES_NO,
-                                       _("Are you sure you want to delete %s ID Card?"), id_card.issuer);
-        var result = dialog.run();
-        switch (result) {
-        case ResponseType.YES:
+        bool remove = WarningDialog.confirm(this, 
+                                            "<span font-weight='heavy'>You are about to remove the identity '%s'.</span>"
+                                            .printf(id_card.display_name)
+                                            + "\n\nAre you sure you want to do this?",
+                                            "delete_idcard");
+        if (remove) 
             remove_identity(id_card_widget);
-            break;
-        default:
-            break;
-        }
-        dialog.destroy();
     }
 
     private void set_prompting_service(string service)
@@ -769,15 +764,20 @@ SUCH DAMAGE.
         vbox_right.pack_start(send_button, false, false, 24);
 
         id_and_button_box.pack_start(vbox_right, false, false, 0);
+
         var main_vbox = new VBox(false, 0);
+
+        // Note: This places a border above the menubar. Is that what we want?
         main_vbox.set_border_width(12);
 
 #if OS_MACOS
         // hide the  File | Quit menu item which is now on the Mac Menu
-        Gtk.Widget quit_item =  this.ui_manager.get_widget("/MenuBar/FileMenu/Quit");
-        quit_item.hide();
+//        Gtk.Widget quit_item =  this.ui_manager.get_widget("/MenuBar/FileMenu/Quit");
+//        quit_item.hide();
         
         Gtk.MenuShell menushell = this.ui_manager.get_widget("/MenuBar") as Gtk.MenuShell;
+        menushell.modify_bg(StateType.NORMAL, white);
+
         osxApp.set_menu_bar(menushell);
         osxApp.set_use_quartz_accelerators(true);
         osxApp.sync_menu_bar();
@@ -785,6 +785,7 @@ SUCH DAMAGE.
 #else
         var menubar = this.ui_manager.get_widget("/MenuBar");
         main_vbox.pack_start(menubar, false, false, 0);
+        menubar.modify_bg(StateType.NORMAL, white);
 #endif
         main_vbox.pack_start(vbox_left, true, true, 0);
         add(main_vbox);
diff --git a/src/moonshot-warning-dialog.vala b/src/moonshot-warning-dialog.vala
new file mode 100644 (file)
index 0000000..8ec583a
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2011-2016, JANET(UK)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of JANET(UK) nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+*/
+using Gtk;
+
+// MessageDialog doesn't allow subclassing, so we merely wrap the
+// constructor for it the dialog, and then run it, returning the result.
+class WarningDialog 
+{
+    public static bool confirm(Window parent, string message, string dialog_name)
+    {
+        Gdk.Color white = make_color(65535, 65535, 65535);
+
+        MessageDialog dialog = new Gtk.MessageDialog(parent,
+                                                     Gtk.DialogFlags.DESTROY_WITH_PARENT,
+                                                     Gtk.MessageType.WARNING,
+                                                     Gtk.ButtonsType.YES_NO,
+                                                     "");
+
+        var content_area = dialog.get_content_area();
+        CheckButton remember_checkbutton;
+
+        if (dialog_name != null && dialog_name != "")
+        {
+            remember_checkbutton = new CheckButton.with_label(_("Do not show this message again"));
+            remember_checkbutton.set_focus_on_click(false);
+            remember_checkbutton.has_focus = false;
+            content_area.has_focus = true;
+
+// Not sure if 0.26 is the minimum for MessageDialog.get_message_area. 0.16 sure isn't :-(
+#if VALA_0_26
+            var message_area = dialog.get_message_area();
+            ((Box)message_area).pack_start(remember_checkbutton, false, false, 12);
+#else
+            HBox hbox = new HBox(false, 0);
+            hbox.pack_start(new HBox(false, 0), true, true, 20);
+            hbox.pack_start(remember_checkbutton, false, false, 12);
+            ((Box)content_area).pack_start(hbox, true, true, 12);
+#endif
+        }
+
+        // dialog.set_modal(true);
+        dialog.set_title(_("Warning"));
+        dialog.modify_bg(StateType.NORMAL, white);
+
+        // ((Box) content_area).set_spacing(12);
+        content_area.modify_bg(StateType.NORMAL, white);
+
+        content_area.show_all();
+
+        dialog.set_markup(message);
+
+        var ret = dialog.run();
+        dialog.destroy();
+        return (ret == Gtk.ResponseType.YES);
+    }
+}