We don't use this param
[dhcpcd-ui] / wpa.c
diff --git a/wpa.c b/wpa.c
index 6a0a0609624a0fff5eea50ac8e8aa3dd2fd9ee48..ed68f18ed473f1e6dc46933d7eacb43a370e3d84 100644 (file)
--- a/wpa.c
+++ b/wpa.c
@@ -96,37 +96,62 @@ find_network(const char *ifname, const char *ssid)
 }
 
 static int
-configure_network(const char *ifname, int id, const char *var, const char *val)
+configure_network(const char *ifname, int id, const char *mgmt,
+               const char *var, const char *val,
+               gboolean quote)
 {
        GError *error;
        char *str;
        static gboolean warned = FALSE;
        GtkWidget *dialog;
 
+       if (id == -1)
+               return -1;
+
+       dbus_g_proxy_call(dbus, "SetNetwork", &error,
+                              G_TYPE_STRING, ifname,
+                              G_TYPE_INT, id,
+                              G_TYPE_STRING, "key_mgmt",
+                              G_TYPE_STRING, mgmt,
+                              G_TYPE_INVALID,
+                              G_TYPE_INVALID);
+
        error = NULL;
-       str = g_strconcat("\"", val, "\"", NULL);
+       if (quote)
+               str = g_strconcat("\"", val, "\"", NULL);
+       else
+               str = NULL;
        if (!dbus_g_proxy_call(dbus, "SetNetwork", &error,
                               G_TYPE_STRING, ifname,
                               G_TYPE_INT, id,
                               G_TYPE_STRING, var,
-                              G_TYPE_STRING, str,
+                              G_TYPE_STRING, quote ? str : val,
                               G_TYPE_INVALID,
                               G_TYPE_INVALID))
        {
                g_warning("SetNetwork: %s", error->message);
                g_free(str);
                g_error_free(error);
+               dialog = gtk_message_dialog_new(NULL,
+                               GTK_DIALOG_MODAL,
+                               GTK_MESSAGE_ERROR,
+                               GTK_BUTTONS_OK,
+                               _("Failed to set password, probably too short."));
+               gtk_window_set_title(GTK_WINDOW(dialog),
+                               _("Error setting password"));
+               gtk_dialog_run(GTK_DIALOG(dialog));
+               gtk_widget_destroy(dialog);
                return -1;
        }
        g_free(str);
 
-       if (!dbus_g_proxy_call(dbus, "SelectNetwork", &error,
+       if (!dbus_g_proxy_call(dbus, "EnableNetwork", &error,
                               G_TYPE_STRING, ifname,
                               G_TYPE_INT, id,
                               G_TYPE_INVALID,
                               G_TYPE_INVALID))
        {
-               g_warning("SelectNetwork: %s", error->message);
+               g_warning("EnableNetwork: %s", error->message);
                g_error_free(error);
                return -1;
        }
@@ -151,27 +176,51 @@ configure_network(const char *ifname, int id, const char *var, const char *val)
                }
                g_error_free(error);
        }
+/*
+       if (!dbus_g_proxy_call(dbus, "Disconnect", &error,
+                              G_TYPE_STRING, ifname,
+                              G_TYPE_INVALID,
+                              G_TYPE_INVALID))
+       {
+               g_warning("Disconnect: %s", error->message);
+               g_error_free(error);
+       }
+*/
+       if (!dbus_g_proxy_call(dbus, "Reassociate", &error,
+                              G_TYPE_STRING, ifname,
+                              G_TYPE_INVALID,
+                              G_TYPE_INVALID))
+       {
+               g_warning("Reassociate: %s", error->message);
+               g_error_free(error);
+       }
+       
        return 0;
 }
 
+static void
+onEnter(_unused GtkWidget *widget, gpointer *data)
+{
+       gtk_dialog_response(GTK_DIALOG(data), GTK_RESPONSE_ACCEPT);
+}
+
 gboolean
 wpa_configure(const struct if_ap *ifa)
 {
        GtkWidget *dialog, *label, *psk, *vbox, *hbox;
-       char *title;
-       const char *var;
-       gint result, id;
+       const char *var, *mgt;
+       gint result, id, retval;
 
-       title = g_strdup_printf(_("Configuration for %s"), ifa->ssid);
-       dialog = gtk_dialog_new_with_buttons(title,
+       dialog = gtk_dialog_new_with_buttons(ifa->ssid,
                NULL,
                GTK_DIALOG_MODAL,
                GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
                GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
                NULL);
-       g_free(title);
        gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE);
        gtk_window_set_icon_name(GTK_WINDOW(dialog), "config-users");
+       gtk_dialog_set_default_response(GTK_DIALOG(dialog),
+                                       GTK_RESPONSE_ACCEPT);
        vbox = GTK_DIALOG(dialog)->vbox;
 
        hbox = gtk_hbox_new(FALSE, 2);
@@ -179,6 +228,7 @@ wpa_configure(const struct if_ap *ifa)
        gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
        psk = gtk_entry_new();
        gtk_entry_set_max_length(GTK_ENTRY(psk), 130);
+       g_signal_connect(G_OBJECT(psk), "activate", G_CALLBACK(onEnter), dialog);
        gtk_box_pack_start(GTK_BOX(hbox), psk, TRUE, TRUE, 0);
        gtk_container_add(GTK_CONTAINER(vbox), hbox);
 
@@ -186,16 +236,21 @@ wpa_configure(const struct if_ap *ifa)
        result = gtk_dialog_run(GTK_DIALOG(dialog));
        
        id = -1;
+       retval = -1;
        if (result == GTK_RESPONSE_ACCEPT) {
                id = find_network(ifa->ifname, ifa->ssid);
-               if (g_strcmp0(ifa->flags, "[WEP]") == 0)
+               if (g_strcmp0(ifa->flags, "[WEP]") == 0) {
+                       mgt = "NONE";
                        var = "wep_key0";
-               else
+               } else {
+                       mgt = "WPA-PSK";
                        var = "psk";
-               if (id != -1)
-                       id = configure_network(ifa->ifname, id, var,
-                                              gtk_entry_get_text(GTK_ENTRY(psk)));
+               }
+               if (id != -1) {
+                       retval = configure_network(ifa->ifname, id, mgt, var,
+                                       gtk_entry_get_text(GTK_ENTRY(psk)), TRUE);
+               }
        }
        gtk_widget_destroy(dialog);
-       return id == -1 ? FALSE : TRUE;
+       return retval == -1 ? FALSE : TRUE;
 }