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