added old and unmaintained prototype of NetworkManager applet and authenticator
[strongswan.git] / src / charon / plugins / dbus / nm_applet_gui.c
1 /*
2 * Copyright (C) 2007 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 *
15 * $Id$
16 */
17
18 #include <glade/glade.h>
19
20 #define NM_VPN_API_SUBJECT_TO_CHANGE
21 #include <nm-vpn-ui-interface.h>
22
23
24 typedef struct private_nm_applet_gui_t private_nm_applet_gui_t;
25
26 /**
27 * Private data of an nm_applet_gui_t object.
28 */
29 struct private_nm_applet_gui_t {
30
31 /**
32 * Implements NetworkManagerVpnUI interface.
33 */
34 NetworkManagerVpnUI public;
35
36 /**
37 * callback registered by NM to update validity
38 */
39 NetworkManagerVpnUIDialogValidityCallback callback;
40
41 /**
42 * loaded Glade XML interface description
43 */
44 GladeXML *xml;
45
46 /**
47 * root widget to return to druid
48 */
49 GtkWidget *widget;
50
51 /**
52 * name of the connection
53 */
54 GtkEntry *name;
55 };
56
57 static const char *get_display_name(private_nm_applet_gui_t *this)
58 {
59 return "strongSwan (IPsec/IKEv2)";
60 }
61
62 static const char *get_service_name(private_nm_applet_gui_t *this)
63 {
64 return "org.freedesktop.NetworkManager.strongswan";
65 }
66
67 static GtkWidget *get_widget(private_nm_applet_gui_t *this, GSList *properties,
68 GSList *routes, const char *connection_name)
69 {
70 GSList *i;
71
72 gtk_entry_set_text(this->name, "");
73 /*gtk_entry_set_text(this->gateway, "");*/
74
75 if (connection_name)
76 {
77 gtk_entry_set_text(this->name, connection_name);
78 }
79
80 while (properties)
81 {
82 const char *key;
83 const char *value;
84
85 key = properties->data;
86 properties = g_slist_next(properties);
87 if (properties)
88 {
89 value = properties->data;
90 /*
91 if (strcmp(key, "gateway") == 0)
92 {
93 gtk_entry_set_text(this->gateway, value);
94 }*/
95 properties = g_slist_next(properties);
96 }
97 }
98
99 return this->widget;
100 }
101
102 static GSList *get_properties(private_nm_applet_gui_t *this)
103 {
104 GSList *props = NULL;
105
106 /*props = g_slist_append(props, g_strdup("gateway"));
107 props = g_slist_append(props, g_strdup(gtk_entry_get_text(this->gateway)));*/
108
109 return props;
110 }
111
112 static GSList *get_routes(private_nm_applet_gui_t *this)
113 {
114 return NULL;
115 }
116
117 static char *get_connection_name(private_nm_applet_gui_t *this)
118 {
119 const char *name;
120
121 name = gtk_entry_get_text(this->name);
122 if (name != NULL)
123 {
124 return g_strdup(name);
125 }
126 return NULL;
127 }
128
129 static gboolean is_valid(private_nm_applet_gui_t *this)
130 {
131 return TRUE;
132 }
133
134 static void set_validity_changed_callback(private_nm_applet_gui_t *this,
135 NetworkManagerVpnUIDialogValidityCallback callback,
136 gpointer user_data)
137 {
138 this->callback = callback;
139 }
140
141 static void get_confirmation_details(private_nm_applet_gui_t *this, gchar **retval)
142 {
143 *retval = g_strdup_printf("connection %s\n", gtk_entry_get_text(this->name));
144 }
145
146 static gboolean can_export(private_nm_applet_gui_t *this)
147 {
148 return FALSE;
149 }
150
151 static gboolean import_file (private_nm_applet_gui_t *this, const char *path)
152 {
153 return FALSE;
154 }
155
156 static gboolean export(private_nm_applet_gui_t *this, GSList *properties,
157 GSList *routes, const char *connection_name)
158 {
159 return FALSE;
160 }
161
162 NetworkManagerVpnUI* nm_vpn_properties_factory(void)
163 {
164 private_nm_applet_gui_t *this = g_new0(private_nm_applet_gui_t, 1);
165
166 this->public.get_display_name = (const char *(*)(NetworkManagerVpnUI *))get_display_name;
167 this->public.get_service_name = (const char *(*) (NetworkManagerVpnUI *))get_service_name;
168 this->public.get_widget = (GtkWidget *(*) (NetworkManagerVpnUI *self, GSList *, GSList *, const char *))get_widget;
169 this->public.get_connection_name = (char *(*) (NetworkManagerVpnUI *))get_connection_name;
170 this->public.get_properties = (GSList *(*) (NetworkManagerVpnUI *))get_properties;
171 this->public.get_routes = (GSList *(*) (NetworkManagerVpnUI *))get_routes;
172 this->public.set_validity_changed_callback = (void (*) (NetworkManagerVpnUI *, NetworkManagerVpnUIDialogValidityCallback, gpointer))set_validity_changed_callback;
173 this->public.is_valid = (gboolean (*) (NetworkManagerVpnUI *))is_valid;
174 this->public.get_confirmation_details = (void (*)(NetworkManagerVpnUI *, gchar **))get_confirmation_details;
175 this->public.can_export = (gboolean (*) (NetworkManagerVpnUI *))can_export;
176 this->public.import_file = (gboolean (*) (NetworkManagerVpnUI *, const char *))import_file;
177 this->public.export = (gboolean (*) (NetworkManagerVpnUI *, GSList *, GSList *, const char *))export;
178 this->public.data = NULL;
179
180 this->callback = NULL;
181 this->xml = glade_xml_new("/home/martin/strongswan/trunk/src/networkmanager/nm_applet_gui.xml", NULL, NULL);
182
183 if (this->xml != NULL)
184 {
185 this->widget = glade_xml_get_widget(this->xml, "main");
186 this->name = GTK_ENTRY(glade_xml_get_widget(this->xml, "name"));
187
188 if (this->widget && this->name)
189 {
190 return &this->public;
191 }
192 }
193 g_free(this);
194 return NULL;
195 }