Maemo: Added a widget to "unselect" a certificate.
[strongswan.git] / src / frontends / maemo / src / strongswan-settings.c
index 5462450..9773590 100644 (file)
@@ -35,17 +35,47 @@ struct {
 } ListDialog = { 0, };
 
 /**
+ * Callback if no certificate should be selected
+ */
+void no_certificate(HildonButton *button, gpointer user_data)
+{
+       gtk_dialog_response (GTK_DIALOG (user_data), GTK_RESPONSE_REJECT);
+}
+
+/**
  * Callback to select a certificate
  */
 void select_cert(HildonButton *button, gpointer user_data)
 {
        GtkWidget *selector = hildon_file_chooser_dialog_new (GTK_WINDOW (user_data), GTK_FILE_CHOOSER_ACTION_OPEN);
+       GtkWidget *nocert = hildon_button_new (HILDON_SIZE_FINGER_HEIGHT |
+                                                                                  HILDON_SIZE_AUTO_WIDTH,
+                                                                                  HILDON_BUTTON_ARRANGEMENT_VERTICAL);
+       hildon_button_set_text (HILDON_BUTTON (nocert),
+                                                       "No certificate",
+                                                       "Use system-wide CA certificates");
+       hildon_button_set_alignment (HILDON_BUTTON (nocert), 0, 0.5, 1, 1);
+       g_signal_connect (nocert, "clicked", G_CALLBACK (no_certificate), selector);
+       hildon_file_chooser_dialog_add_extra (HILDON_FILE_CHOOSER_DIALOG (selector),
+                                                                                 nocert);
        gtk_widget_show_all (selector);
-       if (gtk_dialog_run (GTK_DIALOG (selector)) == GTK_RESPONSE_OK)
+
+       switch (gtk_dialog_run (GTK_DIALOG (selector)))
        {
-               gchar *file = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (selector));
-               hildon_button_set_value (button, file);
-               g_free(file);
+               case GTK_RESPONSE_OK:
+               {
+                       gchar *file = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (selector));
+                       hildon_button_set_value (button, file);
+                       g_free(file);
+                       break;
+               }
+               case GTK_RESPONSE_REJECT:
+               {
+                       hildon_button_set_value (button, "None");
+                       break;
+               }
+               default:
+                       break;
        }
        gtk_widget_destroy (selector);
 }
@@ -120,44 +150,29 @@ edit_connection (gpointer *parent, StrongswanConnection *conn)
                                                                                  HILDON_CAPTION_OPTIONAL);
        gtk_box_pack_start (GTK_BOX (vbox), ucap, TRUE, TRUE, 0);
 
-       GtkWidget *pass = hildon_entry_new (HILDON_SIZE_AUTO);
-       hildon_gtk_entry_set_placeholder_text (GTK_ENTRY (pass), "Password");
-       hildon_gtk_entry_set_input_mode (GTK_ENTRY (pass),
-                                                                        HILDON_GTK_INPUT_MODE_FULL |
-                                                                        HILDON_GTK_INPUT_MODE_INVISIBLE);
-       GtkWidget *pcap = hildon_caption_new (group,
-                                                                                 "Password",
-                                                                                 pass,
-                                                                                 NULL,
-                                                                                 HILDON_CAPTION_OPTIONAL);
-       gtk_box_pack_start (GTK_BOX (vbox), pcap, TRUE, TRUE, 0);
-
        if (conn)
        {
-               gchar *c_name, *c_host, *c_cert, *c_user, *c_pass;
+               gchar *c_name, *c_host, *c_cert, *c_user;
                g_object_get (conn,
                                          "name", &c_name,
                                          "host", &c_host,
                                          "cert", &c_cert,
                                          "user", &c_user,
-                                         "pass", &c_pass,
                                          NULL);
                gtk_entry_set_text (GTK_ENTRY (name), c_name);
                gtk_entry_set_text (GTK_ENTRY (host), c_host);
                hildon_button_set_value (HILDON_BUTTON (cert),
                                                                 c_cert ? c_cert : "None");
                gtk_entry_set_text (GTK_ENTRY (user), c_user);
-               gtk_entry_set_text (GTK_ENTRY (pass), c_pass);
                g_free (c_name);
                g_free (c_host);
                g_free (c_cert);
                g_free (c_user);
-               g_free (c_pass);
        }
 
-       gtk_widget_show_all(dialog);
+       gtk_widget_show_all (dialog);
 
-       guint retval = gtk_dialog_run (GTK_DIALOG (dialog));
+       gint retval = gtk_dialog_run (GTK_DIALOG (dialog));
        if (retval == GTK_RESPONSE_OK)
        {
                const gchar *c_name, *c_cert;
@@ -173,7 +188,6 @@ edit_connection (gpointer *parent, StrongswanConnection *conn)
                                          "host", gtk_entry_get_text (GTK_ENTRY (host)),
                                          "cert", c_cert,
                                          "user", gtk_entry_get_text (GTK_ENTRY (user)),
-                                         "pass", gtk_entry_get_text (GTK_ENTRY (pass)),
                                          NULL);
                strongswan_connections_save_connection (ListDialog.conns, conn);
        }