Implemented 'Do not show this message again' checkbox for warning dialogs
[moonshot-ui.git] / src / moonshot-identity-dialog.vala
index f97fb9e..93bcdb2 100644 (file)
@@ -44,17 +44,6 @@ class IdentityDialog : Dialog
 {
     private static Gdk.Color white = make_color(65535, 65535, 65535);
     private static Gdk.Color selected_color = make_color(0xd9 << 8, 0xf7 << 8, 65535);
-    private static Gdk.Color alt_color = make_color(0xf2 << 8, 0xf2 << 8, 0xf2 << 8);
-
-    private static Gdk.Color make_color(uint16 red, uint16 green, uint16 blue)
-    {
-        Gdk.Color color = Gdk.Color();
-        color.red = red;
-        color.green = green;
-        color.blue = blue;
-
-        return color;
-    }
 
     private static MoonshotLogger logger = get_logger("IdentityDialog");
 
@@ -63,7 +52,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;
@@ -121,7 +109,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();
@@ -146,20 +133,23 @@ class IdentityDialog : Dialog
 
         password_label = new Label(@"$password_labeltext:");
         password_label.set_alignment(0, (float) 0.5);
+
+        remember_checkbutton = new CheckButton.with_label(_("Remember password"));
+        remember_checkbutton.active = card.store_password;
+
         password_entry = new Entry();
         password_entry.set_invisible_char('*');
         password_entry.set_visibility(false);
-        password_entry.set_text(card.password);
         password_entry.set_width_chars(40);
+        password_entry.set_text(card.password);
 
-        remember_checkbutton = new CheckButton.with_label(_("Remember password"));
         message_label = new Label("");
         message_label.set_visible(false);
 
         set_atk_relation(displayname_label, displayname_entry, Atk.RelationType.LABEL_FOR);
         set_atk_relation(realm_label, realm_entry, Atk.RelationType.LABEL_FOR);
         set_atk_relation(username_label, username_entry, Atk.RelationType.LABEL_FOR);
-        set_atk_relation(password_entry, password_entry, Atk.RelationType.LABEL_FOR);
+        set_atk_relation(password_label, password_entry, Atk.RelationType.LABEL_FOR);
 
         content_area.pack_start(message_label, false, false, 6);
         add_as_vbox(content_area, displayname_label, displayname_entry);
@@ -265,14 +255,6 @@ class IdentityDialog : Dialog
         }
     }
 
-    private void set_atk_relation(Widget widget, Widget target_widget, Atk.RelationType relationship)
-    {
-        var atk_widget = widget.get_accessible();
-        var atk_target_widget = target_widget.get_accessible();
-
-        atk_widget.add_relationship(relationship, atk_target_widget);
-    }
-
     private static void label_make_bold(Label label)
     {
         var font_desc = new Pango.FontDescription();
@@ -292,7 +274,6 @@ class IdentityDialog : Dialog
         logger.trace("make_services_vbox");
 
         var services_vbox_alignment = new Alignment(0, 0, 0, 1);
-        services_vbox_alignment.set_padding(6, 6, 6, 6);
         var services_vscroll = new ScrolledWindow(null, null);
         services_vscroll.set_policy(PolicyType.NEVER, PolicyType.AUTOMATIC);
         services_vscroll.set_shadow_type(ShadowType.IN);
@@ -308,7 +289,9 @@ class IdentityDialog : Dialog
 
 
         var services_table = new Table(card.services.length, 1, false);
-        services_table.set_row_spacings(5);
+        services_table.set_row_spacings(1);
+        services_table.set_col_spacings(0);
+        services_table.modify_bg(StateType.NORMAL, white);
 
         var table_button_hbox = new HBox(false, 6);
         table_button_hbox.pack_start(services_vscroll, true, true, 6);
@@ -317,7 +300,13 @@ class IdentityDialog : Dialog
         VBox fixed_height = new VBox(false, 0);
         fixed_height.pack_start(remove_button, false, false, 0);
         table_button_hbox.pack_start(fixed_height, false, false, 6);
-        services_vbox_alignment.add(services_table);
+
+        // A table doesn't have a background color, so put it in an EventBox, and
+        // set the EventBox's background color instead.
+        EventBox table_bg = new EventBox();
+        table_bg.modify_bg(StateType.NORMAL, white);
+        table_bg.add(services_table);
+        services_vbox_alignment.add(table_bg);
 
         var services_vbox_title = new Label(_("Services:"));
         label_make_bold(services_vbox_title);
@@ -331,17 +320,20 @@ class IdentityDialog : Dialog
         foreach (string service in card.services)
         {
             var label = new Label(service);
-            label.set_alignment(0, (float) 0);
+            label.set_alignment((float) 0, (float) 0);
 
             EventBox event_box = new EventBox();
+            event_box.modify_bg(StateType.NORMAL, white);
             event_box.add(label);
             event_box.button_press_event.connect(() =>
                 {
                     var state = label.get_state();
+                    logger.trace("button_press_callback: Label state=" + state.to_string() + " setting bg to " + white.to_string());
+
                     if (selected_item == label)
                     {
                         // Deselect
-                        selected_item.modify_bg(state, white);
+                        selected_item.parent.modify_bg(state, white);
                         selected_item = null;
                         remove_button.set_sensitive(false);
                     }
@@ -350,34 +342,33 @@ class IdentityDialog : Dialog
                         if (selected_item != null)
                         {
                             // Deselect
-                            selected_item.modify_bg(state, white);
+                            selected_item.parent.modify_bg(state, white);
                             selected_item = null;
                         }
 
                         // Select
                         selected_item = label;
-                        selected_item.modify_bg(state, selected_color);
+                        selected_item.parent.modify_bg(state, selected_color);
                         remove_button.set_sensitive(true);
                     }
                     return false;
                 });
 
-            services_table.attach_defaults(event_box, 0, 1, i, i+1);
+            AttachOptions opts = AttachOptions.EXPAND | AttachOptions.FILL;
+            services_table.attach(event_box, 0, 1, i, i+1, opts, opts, 3, 0);
             i++;
         }
 
         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,
+                                                   Markup.printf_escaped(
+                                                       "<span font-weight='heavy'>You are about to remove the service '%s'.</span>",
+                                                       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>();