- table.attach_defaults (displayname_label, 0, 1, 0, 1);
- table.attach_defaults (displayname_entry, 1, 2, 0, 1);
- table.attach_defaults (issuer_label, 0, 1, 1, 2);
- table.attach_defaults (issuer_entry, 1, 2, 1, 2);
- table.attach_defaults (username_label, 0, 1, 2, 3);
- table.attach_defaults (username_entry, 1, 2, 2, 3);
- table.attach_defaults (password_label, 0, 1, 3, 4);
- table.attach_defaults (password_entry, 1, 2, 3, 4);
- table.attach_defaults (remember_checkbutton, 1, 2, 4, 5);
-
- var vbox = new VBox (false, 0);
- vbox.set_border_width (6);
- vbox.pack_start (table, false, false, 0);
-
- ((Container) content_area).add (vbox);
-
- this.set_border_width (6);
- this.set_resizable (false);
- this.show_all ();
+ table.attach_defaults(message_label, 0, 2, 0, 1);
+ table.attach_defaults(displayname_label, 0, 1, 1, 2);
+ table.attach_defaults(displayname_entry, 1, 2, 1, 2);
+ table.attach_defaults(issuer_label, 0, 1, 2, 3);
+ table.attach_defaults(issuer_entry, 1, 2, 2, 3);
+ table.attach_defaults(username_label, 0, 1, 3, 4);
+ table.attach_defaults(username_entry, 1, 2, 3, 4);
+ table.attach_defaults(password_label, 0, 1, 4, 5);
+ table.attach_defaults(password_entry, 1, 2, 4, 5);
+ table.attach_defaults(remember_checkbutton, 1, 2, 5, 6);
+
+ this.response.connect(on_response);
+ var vbox = new VBox(false, 0);
+ vbox.set_border_width(6);
+ vbox.pack_start(table, false, false, 0);
+
+ ((Container) content_area).add(vbox);
+
+ this.set_border_width(6);
+ this.set_resizable(false);
+ this.show_all();
+ }
+
+ private static string update_preamble(string preamble)
+ {
+ if (preamble == "")
+ return _("Missing required field: ");
+ return _("Missing required fields: ");
+ }
+
+ private static string update_message(string old_message, string new_item)
+ {
+ string message;
+ if (old_message == "")
+ message = new_item;
+ else
+ message = old_message + ", " + new_item;
+ return message;
+ }
+
+ private static void check_field(string field, Label label, string fieldname, ref string preamble, ref string message)
+ {
+ if (field != "") {
+ label.set_markup(@"$fieldname:");
+ return;
+ }
+ label.set_markup(@"<span foreground=\"red\">$fieldname:</span>");
+ preamble = update_preamble(preamble);
+ message = update_message(message, fieldname);
+ }
+
+ private bool check_fields()
+ {
+ string preamble = "";
+ string message = "";
+ string password_test = store_password ? password : "not required";
+ check_field(display_name, displayname_label, displayname_labeltext, ref preamble, ref message);
+ check_field(issuer, issuer_label, issuer_labeltext, ref preamble, ref message);
+ check_field(username, username_label, username_labeltext, ref preamble, ref message);
+ check_field(password_test, password_label, password_labeltext, ref preamble, ref message);
+ if (message != "") {
+ message_label.set_visible(true);
+ message_label.set_markup(@"<span foreground=\"red\">$preamble$message</span>");
+ return false;
+ }
+ return true;
+ }
+
+ private void on_response(Dialog source, int response_id)
+ {
+ switch (response_id) {
+ case ResponseType.OK:
+ complete = check_fields();
+ break;
+ case ResponseType.CANCEL:
+ complete = true;
+ break;
+ }