Adding upstream version 0.3.6.
[debian/lxpanel.git] / src / plugins / netstat / passwd_gui.c
CommitLineData
6cc5e1a6
DB
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 <glib.h>
24#include <glib/gi18n.h>
25#include "netstat.h"
26#include "lxnm_client.h"
27#include "wireless.h"
28#include "passwd_gui.h"
29
30struct passwd_resp {
31 ap_setting *aps;
32 GtkEntry *entry;
33};
34
35static void passwd_gui_on_response(GtkDialog* dlg, gint response, struct passwd_resp *pr)
36{
37 char *cmdargs;
38 //GtkEntry* entry = (GtkEntry*)user_data;
39
40 if(G_LIKELY(response == GTK_RESPONSE_OK)) {
41 cmdargs = lxnm_wireless_command_make(pr->aps->ifname, pr->aps->apinfo->essid,
42 pr->aps->apinfo->apaddr, gtk_entry_get_text(pr->entry),
43 pr->aps->apinfo->en_method, pr->aps->apinfo->key_mgmt,
44 pr->aps->apinfo->group, pr->aps->apinfo->pairwise);
45 lxnm_send_command(pr->aps->gio, LXNM_WIRELESS_CONNECT, cmdargs);
46 g_free(cmdargs);
47 }
48
49 g_source_remove_by_user_data(pr->entry); /* remove timeout */
50 gtk_widget_destroy((GtkWidget*)dlg);
51}
52
53void passwd_gui_set_style(struct pgui *pg, GtkStyle *style)
54{
55 gtk_widget_set_style(pg->dlg, style);
56}
57
9a3614f5
DB
58void passwd_gui_free(struct passwd_resp *pr)
59{
60 g_free(pr->aps->ifname);
61 g_free(pr->aps->apinfo->essid);
62 g_free(pr->aps->apinfo->apaddr);
63 g_free(pr->aps->apinfo);
64 g_free(pr->aps);
65 g_free(pr);
66}
67
6cc5e1a6
DB
68void passwd_gui_destroy(struct pgui *pg)
69{
70 gtk_widget_destroy((GtkWidget*)pg->dlg);
71}
72
73struct pgui *passwd_gui_new(ap_setting *aps)
74{
75 GtkWidget *msg, *inputlabel;
76 GtkWidget *inputbox;
77 struct pgui *pwdgui;
78 struct passwd_resp *pr;
79
80 pwdgui = malloc(sizeof(struct pgui));
81 pr = malloc(sizeof(struct passwd_resp));
82
83 /* create dialog */
84 pwdgui->dlg = gtk_dialog_new_with_buttons(_("Setting Encryption Key"),
85 NULL,
86 GTK_DIALOG_NO_SEPARATOR,
87 GTK_STOCK_OK, GTK_RESPONSE_OK,
88 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
89 NULL );
90 gtk_dialog_set_default_response(GTK_WINDOW(pwdgui->dlg), GTK_RESPONSE_OK);
91 gtk_window_set_position(GTK_WINDOW(pwdgui->dlg), GTK_WIN_POS_CENTER);
92
93 /* messages */
94 msg = gtk_label_new(_("This wireless network was encrypted.\nYou must have the encryption key."));
95 gtk_box_pack_start(((GtkDialog*)(pwdgui->dlg))->vbox, msg, FALSE, FALSE, 8);
96
97 /* entry Box */
98 inputbox = gtk_hbox_new(FALSE, 0);
99 inputlabel = gtk_label_new(_("Encryption Key:"));
100 gtk_box_pack_start(GTK_BOX(inputbox), inputlabel, TRUE, TRUE, 4);
101 pwdgui->pentry = gtk_entry_new();
102 gtk_entry_set_visibility(GTK_ENTRY(pwdgui->pentry), FALSE);
103 gtk_entry_set_activates_default(GTK_ENTRY(pwdgui->pentry), TRUE);
104 gtk_box_pack_start(GTK_BOX(inputbox), pwdgui->pentry, FALSE, FALSE, 4);
105 gtk_box_pack_start(((GtkDialog*)(pwdgui->dlg))->vbox, inputbox, FALSE, FALSE, 8);
106
107 /* passwd_resp structure */
108 pr->aps = aps;
109 pr->entry = pwdgui->pentry;
110
111 /* g_signal */
112 g_signal_connect(pwdgui->dlg, "response", G_CALLBACK(passwd_gui_on_response), pr);
9a3614f5 113 g_object_weak_ref(pwdgui->dlg, passwd_gui_free, pr);
6cc5e1a6
DB
114
115 gtk_widget_show_all(pwdgui->dlg);
116
117 return pwdgui;
118}