1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
3
* Copyright (C) 2011-2012 Richard Hughes <richard@hughsie.com>
5
* Licensed under the GNU General Public License Version 2
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.
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.
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.
24
#include <glib-object.h>
25
#include <glib/gi18n.h>
27
#include <nm-client.h>
28
#include <nm-device.h>
29
#include <nm-device-ethernet.h>
30
#include <nm-remote-connection.h>
32
#include "panel-common.h"
34
#include "net-device-wired.h"
36
#define NET_DEVICE_WIRED_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NET_TYPE_DEVICE_WIRED, NetDeviceWiredPrivate))
38
struct _NetDeviceWiredPrivate
41
gboolean updating_device;
44
G_DEFINE_TYPE (NetDeviceWired, net_device_wired, NET_TYPE_DEVICE)
47
device_wired_proxy_add_to_notebook (NetObject *object,
48
GtkNotebook *notebook,
49
GtkSizeGroup *heading_size_group)
53
NetDeviceWired *device_wired = NET_DEVICE_WIRED (object);
55
/* add widgets to size group */
56
widget = GTK_WIDGET (gtk_builder_get_object (device_wired->priv->builder,
58
gtk_size_group_add_widget (heading_size_group, widget);
61
window = GTK_WINDOW (gtk_builder_get_object (device_wired->priv->builder,
63
widget = GTK_WIDGET (gtk_builder_get_object (device_wired->priv->builder,
65
g_object_ref (widget);
66
gtk_container_remove (GTK_CONTAINER (window), widget);
67
gtk_notebook_append_page (notebook, widget, NULL);
68
g_object_unref (widget);
73
update_off_switch_from_device_state (GtkSwitch *sw,
75
NetDeviceWired *device_wired)
77
device_wired->priv->updating_device = TRUE;
79
case NM_DEVICE_STATE_UNMANAGED:
80
case NM_DEVICE_STATE_UNAVAILABLE:
81
case NM_DEVICE_STATE_DISCONNECTED:
82
case NM_DEVICE_STATE_DEACTIVATING:
83
case NM_DEVICE_STATE_FAILED:
84
gtk_switch_set_active (sw, FALSE);
87
gtk_switch_set_active (sw, TRUE);
90
device_wired->priv->updating_device = FALSE;
94
nm_device_wired_refresh_ui (NetDeviceWired *device_wired)
102
NetDeviceWiredPrivate *priv = device_wired->priv;
104
/* set device kind */
105
nm_device = net_device_get_nm_device (NET_DEVICE (device_wired));
106
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "label_device"));
107
gtk_label_set_label (GTK_LABEL (widget),
108
panel_device_to_localized_string (nm_device));
110
/* set up the device on/off switch */
111
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "device_off_switch"));
112
state = nm_device_get_state (nm_device);
113
gtk_widget_set_visible (widget,
114
state != NM_DEVICE_STATE_UNAVAILABLE
115
&& state != NM_DEVICE_STATE_UNMANAGED);
116
update_off_switch_from_device_state (GTK_SWITCH (widget), state, device_wired);
118
/* set device state, with status and optionally speed */
119
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "label_status"));
120
status = g_string_new (panel_device_state_to_localized_string (nm_device));
121
if (state != NM_DEVICE_STATE_UNAVAILABLE)
122
speed = nm_device_ethernet_get_speed (NM_DEVICE_ETHERNET (nm_device));
124
g_string_append (status, " - ");
125
/* Translators: network device speed */
126
g_string_append_printf (status, _("%d Mb/s"), speed);
128
gtk_label_set_label (GTK_LABEL (widget), status->str);
129
g_string_free (status, TRUE);
130
gtk_widget_set_tooltip_text (widget,
131
panel_device_state_reason_to_localized_string (nm_device));
134
str = nm_device_ethernet_get_hw_address (NM_DEVICE_ETHERNET (nm_device));
135
panel_set_device_widget_details (priv->builder, "mac", str);
138
panel_set_device_widgets (priv->builder, nm_device);
142
device_wired_refresh (NetObject *object)
144
NetDeviceWired *device_wired = NET_DEVICE_WIRED (object);
145
nm_device_wired_refresh_ui (device_wired);
149
device_off_toggled (GtkSwitch *sw,
151
NetDeviceWired *device_wired)
154
const GPtrArray *acs;
157
NMActiveConnection *a;
158
NMConnection *connection;
161
if (device_wired->priv->updating_device)
164
active = gtk_switch_get_active (sw);
166
client = net_object_get_client (NET_OBJECT (device_wired));
167
connection = net_device_get_find_connection (NET_DEVICE (device_wired));
168
if (connection == NULL)
170
nm_client_activate_connection (client,
172
net_device_get_nm_device (NET_DEVICE (device_wired)),
175
connection = net_device_get_find_connection (NET_DEVICE (device_wired));
176
if (connection == NULL)
178
path = nm_connection_get_path (connection);
179
client = net_object_get_client (NET_OBJECT (device_wired));
180
acs = nm_client_get_active_connections (client);
181
for (i = 0; i < acs->len; i++) {
182
a = (NMActiveConnection*)acs->pdata[i];
183
if (strcmp (nm_active_connection_get_connection (a), path) == 0) {
184
nm_client_deactivate_connection (client, a);
192
edit_connection (GtkButton *button, NetDeviceWired *device_wired)
194
net_object_edit (NET_OBJECT (device_wired));
198
net_device_wired_constructed (GObject *object)
200
NetDeviceWired *device_wired = NET_DEVICE_WIRED (object);
202
G_OBJECT_CLASS (net_device_wired_parent_class)->constructed (object);
204
nm_device_wired_refresh_ui (device_wired);
208
net_device_wired_finalize (GObject *object)
210
NetDeviceWired *device_wired = NET_DEVICE_WIRED (object);
211
NetDeviceWiredPrivate *priv = device_wired->priv;
213
g_object_unref (priv->builder);
215
G_OBJECT_CLASS (net_device_wired_parent_class)->finalize (object);
219
net_device_wired_class_init (NetDeviceWiredClass *klass)
221
GObjectClass *object_class = G_OBJECT_CLASS (klass);
222
NetObjectClass *parent_class = NET_OBJECT_CLASS (klass);
224
object_class->finalize = net_device_wired_finalize;
225
object_class->constructed = net_device_wired_constructed;
226
parent_class->add_to_notebook = device_wired_proxy_add_to_notebook;
227
parent_class->refresh = device_wired_refresh;
228
g_type_class_add_private (klass, sizeof (NetDeviceWiredPrivate));
232
net_device_wired_init (NetDeviceWired *device_wired)
234
GError *error = NULL;
237
device_wired->priv = NET_DEVICE_WIRED_GET_PRIVATE (device_wired);
239
device_wired->priv->builder = gtk_builder_new ();
240
gtk_builder_add_from_file (device_wired->priv->builder,
241
GNOMECC_UI_DIR "/network-wired.ui",
244
g_warning ("Could not load interface file: %s", error->message);
245
g_error_free (error);
249
/* setup wired combobox model */
250
widget = GTK_WIDGET (gtk_builder_get_object (device_wired->priv->builder,
251
"device_off_switch"));
252
g_signal_connect (widget, "notify::active",
253
G_CALLBACK (device_off_toggled), device_wired);
255
widget = GTK_WIDGET (gtk_builder_get_object (device_wired->priv->builder,
257
g_signal_connect (widget, "clicked",
258
G_CALLBACK (edit_connection), device_wired);