3 * Copyright 2009-2014 Roy Marples <roy@marples.name>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include "dhcpcd-gtk.h"
32 wpa_dialog(const char *title, const char *txt)
36 dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
37 GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", txt);
38 gtk_window_set_title(GTK_WINDOW(dialog), title);
39 gtk_dialog_run(GTK_DIALOG(dialog));
40 gtk_widget_destroy(dialog);
44 onEnter(_unused GtkWidget *widget, gpointer *data)
46 gtk_dialog_response(GTK_DIALOG(data), GTK_RESPONSE_ACCEPT);
50 wpa_configure(DHCPCD_WPA *wpa, DHCPCD_WI_SCAN *scan)
53 GtkWidget *dialog, *label, *psk, *vbox, *hbox;
54 const char *var, *errt;
58 /* Take a copy of scan incase it's destroyed by a scan update */
59 memcpy(&s, scan, sizeof(s));
62 dialog = gtk_dialog_new_with_buttons(s.ssid,
65 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
66 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
68 gtk_window_set_resizable(GTK_WINDOW(dialog), false);
69 gtk_window_set_icon_name(GTK_WINDOW(dialog),
70 "network-wireless-encrypted");
71 gtk_dialog_set_default_response(GTK_DIALOG(dialog),
73 vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
75 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
76 label = gtk_label_new(_("Pre Shared Key:"));
77 gtk_box_pack_start(GTK_BOX(hbox), label, false, false, 0);
78 psk = gtk_entry_new();
79 gtk_entry_set_max_length(GTK_ENTRY(psk), 130);
80 g_signal_connect(G_OBJECT(psk), "activate",
81 G_CALLBACK(onEnter), dialog);
82 gtk_box_pack_start(GTK_BOX(hbox), psk, true, true, 0);
83 gtk_container_add(GTK_CONTAINER(vbox), hbox);
85 gtk_widget_show_all(dialog);
87 result = gtk_dialog_run(GTK_DIALOG(dialog));
90 if (result == GTK_RESPONSE_ACCEPT) {
91 var = gtk_entry_get_text(GTK_ENTRY(psk));
92 switch (dhcpcd_wpa_configure_psk(wpa, &s, var)) {
93 case DHCPCD_WPA_SUCCESS:
96 case DHCPCD_WPA_ERR_SET:
97 errt = _("Failed to set key management.");
99 case DHCPCD_WPA_ERR_SET_PSK:
100 errt = _("Failed to set password, probably too short.");
102 case DHCPCD_WPA_ERR_ENABLE:
103 errt = _("Failed to enable the network.");
105 case DHCPCD_WPA_ERR_ASSOC:
106 errt = _("Failed to start association.");
108 case DHCPCD_WPA_ERR_WRITE:
109 errt =_("Failed to save wpa_supplicant configuration.\n\nYou should add update_config=1 to /etc/wpa_supplicant.conf.");
112 errt = strerror(errno);
116 wpa_dialog(_("Error enabling network"), errt);
120 gtk_widget_destroy(dialog);