ad9b87b775d69b66ac9c7cbaf9e0fcc4ffc35663
[debian/lxpanel.git] / plugins / netstat / passwd_gui.c
1 /**
2 * Copyright (c) 2008 LxDE Developers, see the file AUTHORS for details.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18 #if HAVE_CONFIG_H
19 #include <config.h>
20 #endif
21
22 #include <string.h>
23 #include <stdlib.h>
24 #include <glib.h>
25 #include <glib/gi18n.h>
26 #include "netstat.h"
27 #include "lxnm_client.h"
28 #include "wireless.h"
29 #include "passwd_gui.h"
30
31 struct passwd_resp {
32 ap_setting *aps;
33 GtkEntry *entry;
34 };
35
36 static void passwd_gui_on_response(GtkDialog* dlg, gint response, struct passwd_resp *pr)
37 {
38 char *cmdargs;
39 //GtkEntry* entry = (GtkEntry*)user_data;
40
41 if(G_LIKELY(response == GTK_RESPONSE_OK)) {
42 cmdargs = lxnm_wireless_command_make(pr->aps->ifname, pr->aps->apinfo->essid,
43 pr->aps->apinfo->apaddr, gtk_entry_get_text(pr->entry),
44 pr->aps->apinfo->en_method, pr->aps->apinfo->key_mgmt,
45 pr->aps->apinfo->group, pr->aps->apinfo->pairwise);
46 lxnm_send_command(pr->aps->gio, LXNM_WIRELESS_CONNECT, cmdargs);
47 g_free(cmdargs);
48 }
49
50 g_source_remove_by_user_data(pr->entry); /* remove timeout */
51 gtk_widget_destroy((GtkWidget*)dlg);
52 }
53
54 void passwd_gui_set_style(struct pgui *pg, GtkStyle *style)
55 {
56 gtk_widget_set_style(pg->dlg, style);
57 }
58
59 static void passwd_gui_free(gpointer ptr, GObject *dummy)
60 {
61 struct passwd_resp *pr = ptr;
62 g_free(pr->aps->ifname);
63 g_free(pr->aps->apinfo->essid);
64 g_free(pr->aps->apinfo->apaddr);
65 g_free(pr->aps->apinfo);
66 g_free(pr->aps);
67 g_free(pr);
68 }
69
70 void passwd_gui_destroy(struct pgui *pg)
71 {
72 gtk_widget_destroy((GtkWidget*)pg->dlg);
73 }
74
75 struct pgui *passwd_gui_new(ap_setting *aps)
76 {
77 GtkWidget *msg, *inputlabel;
78 GtkWidget *inputbox;
79 GtkBox *dialog_vbox;
80 struct pgui *pwdgui;
81 struct passwd_resp *pr;
82
83 pwdgui = malloc(sizeof(struct pgui));
84 pr = malloc(sizeof(struct passwd_resp));
85
86 /* create dialog */
87 pwdgui->dlg = gtk_dialog_new_with_buttons(_("Setting Encryption Key"),
88 NULL,
89 GTK_DIALOG_NO_SEPARATOR,
90 GTK_STOCK_OK, GTK_RESPONSE_OK,
91 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
92 NULL );
93 gtk_dialog_set_default_response(GTK_DIALOG(pwdgui->dlg), GTK_RESPONSE_OK);
94 gtk_window_set_position(GTK_WINDOW(pwdgui->dlg), GTK_WIN_POS_CENTER);
95
96 /* messages */
97 dialog_vbox = GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(pwdgui->dlg)));
98 msg = gtk_label_new(_("This wireless network was encrypted.\nYou must have the encryption key."));
99 gtk_box_pack_start(dialog_vbox, msg, FALSE, FALSE, 8);
100
101 /* entry Box */
102 inputbox = gtk_hbox_new(FALSE, 0);
103 inputlabel = gtk_label_new(_("Encryption Key:"));
104 gtk_box_pack_start(GTK_BOX(inputbox), inputlabel, TRUE, TRUE, 4);
105 pwdgui->pentry = gtk_entry_new();
106 gtk_entry_set_visibility(GTK_ENTRY(pwdgui->pentry), FALSE);
107 gtk_entry_set_activates_default(GTK_ENTRY(pwdgui->pentry), TRUE);
108 gtk_box_pack_start(GTK_BOX(inputbox), pwdgui->pentry, FALSE, FALSE, 4);
109 gtk_box_pack_start(dialog_vbox, inputbox, FALSE, FALSE, 8);
110
111 /* passwd_resp structure */
112 pr->aps = aps;
113 pr->entry = GTK_ENTRY(pwdgui->pentry);
114
115 /* g_signal */
116 g_signal_connect(pwdgui->dlg, "response", G_CALLBACK(passwd_gui_on_response), pr);
117 g_object_weak_ref(G_OBJECT(pwdgui->dlg), passwd_gui_free, pr);
118
119 gtk_widget_show_all(pwdgui->dlg);
120
121 return pwdgui;
122 }