Fix GtkComboBoxEntry in 'netstatus' plugin.
[lxde/lxpanel.git] / plugins / netstat / passwd_gui.c
CommitLineData
62e58745 1/**
7d507fc8
FC
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 */
a002e161
HJYP
18#if HAVE_CONFIG_H
19#include <config.h>
20#endif
62e58745 21
7d507fc8 22#include <string.h>
a048055d 23#include <stdlib.h>
7d507fc8
FC
24#include <glib.h>
25#include <glib/gi18n.h>
26#include "netstat.h"
497d6b36 27#include "lxnm_client.h"
e7035c21 28#include "wireless.h"
7d507fc8 29#include "passwd_gui.h"
97088cd4 30#include "gtk-compat.h"
7d507fc8 31
e7035c21 32struct passwd_resp {
a002e161
HJYP
33 ap_setting *aps;
34 GtkEntry *entry;
e7035c21
FC
35};
36
e7035c21 37static void passwd_gui_on_response(GtkDialog* dlg, gint response, struct passwd_resp *pr)
7d507fc8 38{
a002e161
HJYP
39 char *cmdargs;
40 //GtkEntry* entry = (GtkEntry*)user_data;
41
42 if(G_LIKELY(response == GTK_RESPONSE_OK)) {
62bf0a7d
FC
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);
a002e161 47 lxnm_send_command(pr->aps->gio, LXNM_WIRELESS_CONNECT, cmdargs);
62bf0a7d 48 g_free(cmdargs);
a002e161 49 }
e7035c21 50
a002e161
HJYP
51 g_source_remove_by_user_data(pr->entry); /* remove timeout */
52 gtk_widget_destroy((GtkWidget*)dlg);
7d507fc8
FC
53}
54
55void passwd_gui_set_style(struct pgui *pg, GtkStyle *style)
56{
a002e161 57 gtk_widget_set_style(pg->dlg, style);
7d507fc8
FC
58}
59
a048055d 60static void passwd_gui_free(gpointer ptr, GObject *dummy)
bd9ae1a9 61{
a048055d 62 struct passwd_resp *pr = ptr;
bd9ae1a9
FC
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
7d507fc8
FC
71void passwd_gui_destroy(struct pgui *pg)
72{
a002e161 73 gtk_widget_destroy((GtkWidget*)pg->dlg);
7d507fc8
FC
74}
75
76struct pgui *passwd_gui_new(ap_setting *aps)
77{
a002e161
HJYP
78 GtkWidget *msg, *inputlabel;
79 GtkWidget *inputbox;
175f73d1 80 GtkBox *dialog_vbox;
a002e161
HJYP
81 struct pgui *pwdgui;
82 struct passwd_resp *pr;
7d507fc8 83
a002e161
HJYP
84 pwdgui = malloc(sizeof(struct pgui));
85 pr = malloc(sizeof(struct passwd_resp));
7d507fc8 86
a002e161
HJYP
87 /* create dialog */
88 pwdgui->dlg = gtk_dialog_new_with_buttons(_("Setting Encryption Key"),
7d507fc8
FC
89 NULL,
90 GTK_DIALOG_NO_SEPARATOR,
91 GTK_STOCK_OK, GTK_RESPONSE_OK,
92 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
93 NULL );
a048055d 94 gtk_dialog_set_default_response(GTK_DIALOG(pwdgui->dlg), GTK_RESPONSE_OK);
a002e161
HJYP
95 gtk_window_set_position(GTK_WINDOW(pwdgui->dlg), GTK_WIN_POS_CENTER);
96
97 /* messages */
175f73d1 98 dialog_vbox = GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(pwdgui->dlg)));
a002e161 99 msg = gtk_label_new(_("This wireless network was encrypted.\nYou must have the encryption key."));
175f73d1 100 gtk_box_pack_start(dialog_vbox, msg, FALSE, FALSE, 8);
a002e161
HJYP
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);
175f73d1 110 gtk_box_pack_start(dialog_vbox, inputbox, FALSE, FALSE, 8);
a002e161
HJYP
111
112 /* passwd_resp structure */
113 pr->aps = aps;
a048055d 114 pr->entry = GTK_ENTRY(pwdgui->pentry);
a002e161
HJYP
115
116 /* g_signal */
117 g_signal_connect(pwdgui->dlg, "response", G_CALLBACK(passwd_gui_on_response), pr);
a048055d 118 g_object_weak_ref(G_OBJECT(pwdgui->dlg), passwd_gui_free, pr);
a002e161
HJYP
119
120 gtk_widget_show_all(pwdgui->dlg);
121
122 return pwdgui;
7d507fc8 123}