24
24
#include <glib-object.h>
25
25
#include <glib/gi18n.h>
26
#include <NetworkManager.h>
27
28
#include "panel-common.h"
29
30
#include "net-vpn.h"
30
#include "nm-client.h"
31
#include "nm-remote-connection.h"
32
#include "nm-setting-vpn.h"
32
#include "connection-editor/net-connection-editor.h"
34
34
#define NET_VPN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NET_TYPE_VPN, NetVpnPrivate))
51
52
G_DEFINE_TYPE (NetVpn, net_vpn, NET_TYPE_OBJECT)
54
connection_vpn_state_changed_cb (NMVPNConnection *connection,
55
NMVPNConnectionState state,
56
NMVPNConnectionStateReason reason,
55
connection_vpn_state_changed_cb (NMVpnConnection *connection,
56
NMVpnConnectionState state,
57
NMVpnConnectionStateReason reason,
59
60
net_object_emit_changed (NET_OBJECT (vpn));
70
connection_removed_cb (NMConnection *connection,
71
connection_removed_cb (NMClient *client,
72
NMConnection *connection,
73
net_object_emit_removed (NET_OBJECT (vpn));
75
NetVpnPrivate *priv = vpn->priv;
77
if (priv->connection == connection)
78
net_object_emit_removed (NET_OBJECT (vpn));
99
106
* key=Xauth username, value=rhughes
101
108
priv->connection = g_object_ref (connection);
102
g_signal_connect (priv->connection,
103
NM_REMOTE_CONNECTION_REMOVED,
110
client = net_object_get_client (NET_OBJECT (vpn));
111
g_signal_connect (client,
112
NM_CLIENT_CONNECTION_REMOVED,
104
113
G_CALLBACK (connection_removed_cb),
106
g_signal_connect (priv->connection,
107
NM_REMOTE_CONNECTION_UPDATED,
115
g_signal_connect (connection,
116
NM_CONNECTION_CHANGED,
108
117
G_CALLBACK (connection_changed_cb),
110
120
if (NM_IS_VPN_CONNECTION (priv->connection)) {
111
121
g_signal_connect (priv->connection,
112
122
NM_VPN_CONNECTION_VPN_STATE,
117
127
priv->service_type = net_vpn_connection_to_type (priv->connection);
120
static NMVPNConnectionState
130
static NMVpnConnectionState
121
131
net_vpn_get_state (NetVpn *vpn)
123
133
NetVpnPrivate *priv = vpn->priv;
222
232
vpn_proxy_delete (NetObject *object)
224
234
NetVpn *vpn = NET_VPN (object);
225
nm_remote_connection_delete (NM_REMOTE_CONNECTION (vpn->priv->connection),
235
nm_remote_connection_delete_async (NM_REMOTE_CONNECTION (vpn->priv->connection),
229
239
static GtkWidget *
240
249
"heading_group_password"));
241
250
gtk_size_group_add_widget (heading_size_group, widget);
244
window = GTK_WINDOW (gtk_builder_get_object (vpn->priv->builder,
246
252
widget = GTK_WIDGET (gtk_builder_get_object (vpn->priv->builder,
248
g_object_ref (widget);
249
gtk_container_remove (GTK_CONTAINER (window), widget);
250
254
gtk_notebook_append_page (notebook, widget, NULL);
251
g_object_unref (widget);
275
276
/* update title */
276
277
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
277
278
"label_device"));
279
/* Translators: this is the title of the connection details
280
* window for vpn connections, it is also used to display
281
* vpn connections in the device list.
278
283
title = g_strdup_printf (_("%s VPN"), nm_connection_get_id (vpn->priv->connection));
279
284
net_object_set_title (NET_OBJECT (vpn), title);
280
285
gtk_label_set_label (GTK_LABEL (widget), title);
288
if (priv->active_connection) {
289
g_signal_handlers_disconnect_by_func (vpn->priv->active_connection,
290
nm_device_refresh_vpn_ui,
292
g_clear_object (&priv->active_connection);
284
297
state = net_vpn_get_state (vpn);
285
298
client = net_object_get_client (NET_OBJECT (vpn));
286
299
acs = nm_client_get_active_connections (client);
287
300
if (acs != NULL) {
288
path = nm_connection_get_path (vpn->priv->connection);
303
uuid = nm_connection_get_uuid (vpn->priv->connection);
289
304
for (i = 0; i < acs->len; i++) {
290
307
a = (NMActiveConnection*)acs->pdata[i];
292
apath = nm_active_connection_get_connection (a);
293
if (NM_IS_VPN_CONNECTION (a) && strcmp (apath, path) == 0) {
309
auuid = nm_active_connection_get_uuid (a);
310
if (NM_IS_VPN_CONNECTION (a) && strcmp (auuid, uuid) == 0) {
311
priv->active_connection = g_object_ref (a);
312
g_signal_connect_swapped (a, "notify::vpn-state",
313
G_CALLBACK (nm_device_refresh_vpn_ui),
294
315
state = nm_vpn_connection_get_vpn_state (NM_VPN_CONNECTION (a));
358
384
active = gtk_switch_get_active (sw);
360
386
client = net_object_get_client (NET_OBJECT (vpn));
361
nm_client_activate_connection (client,
362
vpn->priv->connection, NULL, NULL,
387
nm_client_activate_connection_async (client,
388
vpn->priv->connection, NULL, NULL,
365
path = nm_connection_get_path (vpn->priv->connection);
393
uuid = nm_connection_get_uuid (vpn->priv->connection);
366
394
client = net_object_get_client (NET_OBJECT (vpn));
367
395
acs = nm_client_get_active_connections (client);
368
for (i = 0; i < acs->len; i++) {
396
for (i = 0; acs && i < acs->len; i++) {
369
397
a = (NMActiveConnection*)acs->pdata[i];
370
if (strcmp (nm_active_connection_get_connection (a), path) == 0) {
371
nm_client_deactivate_connection (client, a);
398
if (strcmp (nm_active_connection_get_uuid (a), uuid) == 0) {
399
nm_client_deactivate_connection (client, a, NULL, NULL);
413
editor_done (NetConnectionEditor *editor,
417
g_object_unref (editor);
418
net_object_refresh (NET_OBJECT (vpn));
419
g_object_unref (vpn);
385
423
vpn_proxy_edit (NetObject *object)
389
GError *error = NULL;
390
425
NetVpn *vpn = NET_VPN (object);
392
uuid = nm_connection_get_uuid (vpn->priv->connection);
393
cmdline = g_strdup_printf ("nm-connection-editor --edit %s", uuid);
394
g_debug ("Launching '%s'\n", cmdline);
395
if (!g_spawn_command_line_async (cmdline, &error)) {
396
g_warning ("Failed to launch nm-connection-editor: %s", error->message);
397
g_error_free (error);
426
GtkWidget *button, *window;
427
NetConnectionEditor *editor;
431
button = GTK_WIDGET (gtk_builder_get_object (vpn->priv->builder,
433
window = gtk_widget_get_toplevel (button);
435
client = net_object_get_client (object);
437
editor = net_connection_editor_new (GTK_WINDOW (window),
438
vpn->priv->connection,
440
title = g_strdup_printf (_("%s VPN"), nm_connection_get_id (vpn->priv->connection));
441
net_connection_editor_set_title (editor, title);
444
g_signal_connect (editor, "done", G_CALLBACK (editor_done), g_object_ref (vpn));
445
net_connection_editor_run (editor);
446
492
net_vpn_constructed (GObject *object)
448
494
NetVpn *vpn = NET_VPN (object);
495
NMClient *client = net_object_get_client (NET_OBJECT (object));
450
497
G_OBJECT_CLASS (net_vpn_parent_class)->constructed (object);
452
499
nm_device_refresh_vpn_ui (vpn);
501
g_signal_connect_swapped (client,
502
"notify::active-connections",
503
G_CALLBACK (nm_active_connections_changed),
458
511
NetVpn *vpn = NET_VPN (object);
459
512
NetVpnPrivate *priv = vpn->priv;
513
NMClient *client = net_object_get_client (NET_OBJECT (object));
516
g_signal_handlers_disconnect_by_func (client,
517
nm_active_connections_changed,
521
if (priv->active_connection) {
522
g_signal_handlers_disconnect_by_func (priv->active_connection,
523
nm_device_refresh_vpn_ui,
525
g_object_unref (priv->active_connection);
528
g_signal_handlers_disconnect_by_func (priv->connection,
529
connection_vpn_state_changed_cb,
531
g_signal_handlers_disconnect_by_func (priv->connection,
532
connection_removed_cb,
534
g_signal_handlers_disconnect_by_func (priv->connection,
535
connection_changed_cb,
461
537
g_object_unref (priv->connection);
462
538
g_free (priv->service_type);
540
g_clear_object (&priv->builder);
464
542
G_OBJECT_CLASS (net_vpn_parent_class)->finalize (object);
497
575
vpn->priv = NET_VPN_GET_PRIVATE (vpn);
499
577
vpn->priv->builder = gtk_builder_new ();
500
gtk_builder_add_from_file (vpn->priv->builder,
501
GNOMECC_UI_DIR "/network-vpn.ui",
578
gtk_builder_add_from_resource (vpn->priv->builder,
579
"/org/gnome/control-center/network/network-vpn.ui",
503
581
if (error != NULL) {
504
582
g_warning ("Could not load interface file: %s", error->message);
505
583
g_error_free (error);