Line |
Branch |
Exec |
Source |
1 |
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- |
2 |
|
|
* |
3 |
|
|
* Copyright (C) 2013 Red Hat, Inc |
4 |
|
|
* |
5 |
|
|
* Licensed under the GNU General Public License Version 2 |
6 |
|
|
* |
7 |
|
|
* This program is free software; you can redistribute it and/or modify |
8 |
|
|
* it under the terms of the GNU General Public License as published by |
9 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
10 |
|
|
* (at your option) any later version. |
11 |
|
|
* |
12 |
|
|
* This program is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
* GNU General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License |
18 |
|
|
* along with this program; if not, write to the Free Software |
19 |
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
#include "config.h" |
23 |
|
|
|
24 |
|
|
#include <glib/gi18n.h> |
25 |
|
|
|
26 |
|
|
#include <NetworkManager.h> |
27 |
|
|
|
28 |
|
|
#include "ce-page.h" |
29 |
|
|
#include "ce-page-vpn.h" |
30 |
|
|
#include "vpn-helpers.h" |
31 |
|
|
|
32 |
|
|
struct _CEPageVpn |
33 |
|
|
{ |
34 |
|
|
GtkBox parent; |
35 |
|
|
|
36 |
|
|
GtkBox *box; |
37 |
|
|
GtkLabel *failure_label; |
38 |
|
|
GtkEntry *name_entry; |
39 |
|
|
|
40 |
|
|
NMConnection *connection; |
41 |
|
|
NMSettingConnection *setting_connection; |
42 |
|
|
NMSettingVpn *setting_vpn; |
43 |
|
|
|
44 |
|
|
NMVpnEditorPlugin *plugin; |
45 |
|
|
NMVpnEditor *editor; |
46 |
|
|
}; |
47 |
|
|
|
48 |
|
|
static void ce_page_iface_init (CEPageInterface *); |
49 |
|
|
|
50 |
|
✗ |
G_DEFINE_TYPE_WITH_CODE (CEPageVpn, ce_page_vpn, GTK_TYPE_BOX, |
51 |
|
|
G_IMPLEMENT_INTERFACE (ce_page_get_type (), ce_page_iface_init)) |
52 |
|
|
|
53 |
|
|
/* Hack to make the plugin-provided editor widget fit in better with |
54 |
|
|
* the control center by changing |
55 |
|
|
* |
56 |
|
|
* Foo: [__________] |
57 |
|
|
* Bar baz: [__________] |
58 |
|
|
* |
59 |
|
|
* to |
60 |
|
|
* |
61 |
|
|
* Foo [__________] |
62 |
|
|
* Bar baz [__________] |
63 |
|
|
*/ |
64 |
|
|
static void |
65 |
|
✗ |
vpn_gnome3ify_editor (GtkWidget *widget) |
66 |
|
|
{ |
67 |
|
✗ |
if (GTK_IS_LABEL (widget)) { |
68 |
|
|
const char *text; |
69 |
|
|
gfloat xalign; |
70 |
|
✗ |
g_autofree gchar *newtext = NULL; |
71 |
|
|
int len; |
72 |
|
|
|
73 |
|
✗ |
xalign = gtk_label_get_xalign (GTK_LABEL (widget)); |
74 |
|
✗ |
if (xalign != 0.0) |
75 |
|
✗ |
return; |
76 |
|
✗ |
text = gtk_label_get_text (GTK_LABEL (widget)); |
77 |
|
✗ |
len = strlen (text); |
78 |
|
✗ |
if (len < 2 || text[len - 1] != ':') |
79 |
|
✗ |
return; |
80 |
|
|
|
81 |
|
✗ |
newtext = g_strndup (text, len - 1); |
82 |
|
✗ |
gtk_label_set_text (GTK_LABEL (widget), newtext); |
83 |
|
✗ |
gtk_label_set_xalign (GTK_LABEL (widget), 1.0); |
84 |
|
✗ |
} else if (GTK_IS_WIDGET (widget)) { |
85 |
|
|
GtkWidget *child; |
86 |
|
|
|
87 |
|
✗ |
for (child = gtk_widget_get_first_child (widget); |
88 |
|
✗ |
child; |
89 |
|
✗ |
child = gtk_widget_get_next_sibling (child)) |
90 |
|
✗ |
vpn_gnome3ify_editor (child); |
91 |
|
|
} |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
static void |
95 |
|
✗ |
load_vpn_plugin (CEPageVpn *self) |
96 |
|
|
{ |
97 |
|
|
GtkWidget *ui_widget; |
98 |
|
|
|
99 |
|
✗ |
self->editor = nm_vpn_editor_plugin_get_editor (self->plugin, |
100 |
|
|
self->connection, |
101 |
|
|
NULL); |
102 |
|
✗ |
ui_widget = NULL; |
103 |
|
✗ |
if (self->editor) |
104 |
|
✗ |
ui_widget = GTK_WIDGET (nm_vpn_editor_get_widget (self->editor)); |
105 |
|
|
|
106 |
|
✗ |
if (!ui_widget) { |
107 |
|
✗ |
g_clear_object (&self->editor); |
108 |
|
✗ |
self->plugin = NULL; |
109 |
|
✗ |
return; |
110 |
|
|
} |
111 |
|
✗ |
vpn_gnome3ify_editor (ui_widget); |
112 |
|
|
|
113 |
|
✗ |
gtk_box_remove (self->box, GTK_WIDGET (self->failure_label)); |
114 |
|
✗ |
gtk_box_append (self->box, ui_widget); |
115 |
|
|
|
116 |
|
✗ |
g_signal_connect_object (self->editor, "changed", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED); |
117 |
|
|
} |
118 |
|
|
|
119 |
|
|
static void |
120 |
|
✗ |
connect_vpn_page (CEPageVpn *self) |
121 |
|
|
{ |
122 |
|
|
const gchar *name; |
123 |
|
|
|
124 |
|
✗ |
name = nm_setting_connection_get_id (self->setting_connection); |
125 |
|
✗ |
gtk_editable_set_text (GTK_EDITABLE (self->name_entry), name); |
126 |
|
✗ |
g_signal_connect_object (self->name_entry, "changed", G_CALLBACK (ce_page_changed), self, G_CONNECT_SWAPPED); |
127 |
|
✗ |
} |
128 |
|
|
|
129 |
|
|
static void |
130 |
|
✗ |
ce_page_vpn_dispose (GObject *object) |
131 |
|
|
{ |
132 |
|
✗ |
CEPageVpn *self = CE_PAGE_VPN (object); |
133 |
|
|
|
134 |
|
✗ |
g_clear_object (&self->connection); |
135 |
|
✗ |
g_clear_object (&self->editor); |
136 |
|
|
|
137 |
|
✗ |
G_OBJECT_CLASS (ce_page_vpn_parent_class)->dispose (object); |
138 |
|
✗ |
} |
139 |
|
|
|
140 |
|
|
static const gchar * |
141 |
|
✗ |
ce_page_vpn_get_security_setting (CEPage *page) |
142 |
|
|
{ |
143 |
|
✗ |
return NM_SETTING_VPN_SETTING_NAME; |
144 |
|
|
} |
145 |
|
|
|
146 |
|
|
static const gchar * |
147 |
|
✗ |
ce_page_vpn_get_title (CEPage *page) |
148 |
|
|
{ |
149 |
|
✗ |
return _("Identity"); |
150 |
|
|
} |
151 |
|
|
|
152 |
|
|
static gboolean |
153 |
|
✗ |
ce_page_vpn_validate (CEPage *page, |
154 |
|
|
NMConnection *connection, |
155 |
|
|
GError **error) |
156 |
|
|
{ |
157 |
|
✗ |
CEPageVpn *self = CE_PAGE_VPN (page); |
158 |
|
|
|
159 |
|
✗ |
g_object_set (self->setting_connection, |
160 |
|
✗ |
NM_SETTING_CONNECTION_ID, gtk_editable_get_text (GTK_EDITABLE (self->name_entry)), |
161 |
|
|
NULL); |
162 |
|
|
|
163 |
|
✗ |
if (!nm_setting_verify (NM_SETTING (self->setting_connection), NULL, error)) |
164 |
|
✗ |
return FALSE; |
165 |
|
|
|
166 |
|
✗ |
if (!self->editor) |
167 |
|
✗ |
return TRUE; |
168 |
|
|
|
169 |
|
✗ |
return nm_vpn_editor_update_connection (self->editor, connection, error); |
170 |
|
|
} |
171 |
|
|
|
172 |
|
|
static void |
173 |
|
✗ |
ce_page_vpn_init (CEPageVpn *self) |
174 |
|
|
{ |
175 |
|
✗ |
gtk_widget_init_template (GTK_WIDGET (self)); |
176 |
|
✗ |
} |
177 |
|
|
|
178 |
|
|
static void |
179 |
|
✗ |
ce_page_vpn_class_init (CEPageVpnClass *class) |
180 |
|
|
{ |
181 |
|
✗ |
GObjectClass *object_class = G_OBJECT_CLASS (class); |
182 |
|
✗ |
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); |
183 |
|
|
|
184 |
|
✗ |
object_class->dispose = ce_page_vpn_dispose; |
185 |
|
|
|
186 |
|
✗ |
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/network/vpn-page.ui"); |
187 |
|
|
|
188 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageVpn, box); |
189 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageVpn, failure_label); |
190 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CEPageVpn, name_entry); |
191 |
|
✗ |
} |
192 |
|
|
|
193 |
|
|
static void |
194 |
|
✗ |
ce_page_iface_init (CEPageInterface *iface) |
195 |
|
|
{ |
196 |
|
✗ |
iface->get_security_setting = ce_page_vpn_get_security_setting; |
197 |
|
✗ |
iface->get_title = ce_page_vpn_get_title; |
198 |
|
✗ |
iface->validate = ce_page_vpn_validate; |
199 |
|
✗ |
} |
200 |
|
|
|
201 |
|
|
static void |
202 |
|
✗ |
finish_setup (CEPageVpn *self, gpointer unused, GError *error, gpointer user_data) |
203 |
|
|
{ |
204 |
|
|
const char *vpn_type; |
205 |
|
|
|
206 |
|
✗ |
self->setting_connection = nm_connection_get_setting_connection (self->connection); |
207 |
|
✗ |
self->setting_vpn = nm_connection_get_setting_vpn (self->connection); |
208 |
|
✗ |
vpn_type = nm_setting_vpn_get_service_type (self->setting_vpn); |
209 |
|
|
|
210 |
|
✗ |
self->plugin = vpn_get_plugin_by_service (vpn_type); |
211 |
|
✗ |
if (self->plugin) |
212 |
|
✗ |
load_vpn_plugin (self); |
213 |
|
|
|
214 |
|
✗ |
connect_vpn_page (self); |
215 |
|
✗ |
} |
216 |
|
|
|
217 |
|
|
CEPageVpn * |
218 |
|
✗ |
ce_page_vpn_new (NMConnection *connection) |
219 |
|
|
{ |
220 |
|
|
CEPageVpn *self; |
221 |
|
|
|
222 |
|
✗ |
self = CE_PAGE_VPN (g_object_new (ce_page_vpn_get_type (), NULL)); |
223 |
|
|
|
224 |
|
✗ |
self->connection = g_object_ref (connection); |
225 |
|
|
|
226 |
|
✗ |
g_signal_connect (self, "initialized", G_CALLBACK (finish_setup), NULL); |
227 |
|
|
|
228 |
|
✗ |
return self; |
229 |
|
|
} |
230 |
|
|
|