2012-08-29 14:39:52 -04:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011-2012 Richard Hughes <richard@hughsie.com>
|
|
|
|
*
|
|
|
|
* Licensed under the GNU General Public License Version 2
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib-object.h>
|
|
|
|
#include <glib/gi18n.h>
|
2016-04-29 16:05:54 +02:00
|
|
|
#include <NetworkManager.h>
|
2012-08-29 14:39:52 -04:00
|
|
|
|
|
|
|
#include "panel-common.h"
|
|
|
|
|
2012-12-17 14:17:42 -05:00
|
|
|
#include "connection-editor/net-connection-editor.h"
|
|
|
|
#include "connection-editor/ce-page.h"
|
|
|
|
|
2012-08-29 14:39:52 -04:00
|
|
|
#include "net-device-ethernet.h"
|
|
|
|
|
2018-10-31 21:58:34 -03:00
|
|
|
struct _NetDeviceEthernet
|
|
|
|
{
|
2022-01-27 14:52:21 -08:00
|
|
|
AdwPreferencesGroup parent;
|
|
|
|
|
|
|
|
GtkListBox *connection_list;
|
|
|
|
GtkStack *connection_stack;
|
|
|
|
GtkButton *details_button;
|
|
|
|
GtkListBox *details_listbox;
|
|
|
|
AdwActionRow *details_row;
|
|
|
|
GtkSwitch *device_off_switch;
|
|
|
|
|
|
|
|
NMClient *client;
|
|
|
|
NMDevice *device;
|
|
|
|
gboolean updating_device;
|
|
|
|
GHashTable *connections;
|
2018-10-31 21:58:34 -03:00
|
|
|
};
|
|
|
|
|
2022-01-27 14:52:21 -08:00
|
|
|
G_DEFINE_TYPE (NetDeviceEthernet, net_device_ethernet, ADW_TYPE_PREFERENCES_GROUP)
|
2012-12-17 14:17:42 -05:00
|
|
|
|
|
|
|
static void
|
|
|
|
add_details_row (GtkWidget *details, gint top, const gchar *heading, const gchar *value)
|
|
|
|
{
|
2013-12-06 14:45:34 +01:00
|
|
|
GtkWidget *heading_label;
|
|
|
|
GtkWidget *value_label;
|
2012-12-17 14:17:42 -05:00
|
|
|
|
2013-12-06 14:45:34 +01:00
|
|
|
heading_label = gtk_label_new (heading);
|
|
|
|
gtk_style_context_add_class (gtk_widget_get_style_context (heading_label), "dim-label");
|
|
|
|
gtk_widget_set_halign (heading_label, GTK_ALIGN_END);
|
2021-03-22 14:58:39 +01:00
|
|
|
gtk_widget_set_valign (heading_label, GTK_ALIGN_START);
|
2013-12-06 14:45:34 +01:00
|
|
|
gtk_widget_set_hexpand (heading_label, TRUE);
|
2012-12-17 14:17:42 -05:00
|
|
|
|
2013-12-06 14:45:34 +01:00
|
|
|
gtk_grid_attach (GTK_GRID (details), heading_label, 0, top, 1, 1);
|
2012-12-17 14:17:42 -05:00
|
|
|
|
2013-12-06 14:45:34 +01:00
|
|
|
value_label = gtk_label_new (value);
|
|
|
|
gtk_widget_set_halign (value_label, GTK_ALIGN_START);
|
|
|
|
gtk_widget_set_hexpand (value_label, TRUE);
|
2017-03-28 14:35:10 +08:00
|
|
|
gtk_label_set_selectable (GTK_LABEL (value_label), TRUE);
|
2012-12-17 14:17:42 -05:00
|
|
|
|
2013-12-12 13:09:53 +01:00
|
|
|
gtk_label_set_mnemonic_widget (GTK_LABEL (heading_label), value_label);
|
2013-12-06 14:45:34 +01:00
|
|
|
|
|
|
|
gtk_grid_attach (GTK_GRID (details), value_label, 1, top, 1, 1);
|
2012-12-17 14:17:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
get_last_used_string (NMConnection *connection)
|
|
|
|
{
|
2019-09-12 11:53:42 +12:00
|
|
|
g_autoptr(GDateTime) now = NULL;
|
|
|
|
g_autoptr(GDateTime) then = NULL;
|
2012-12-17 14:17:42 -05:00
|
|
|
gint days;
|
|
|
|
GTimeSpan diff;
|
|
|
|
guint64 timestamp;
|
|
|
|
NMSettingConnection *s_con;
|
|
|
|
|
|
|
|
s_con = nm_connection_get_setting_connection (connection);
|
|
|
|
if (s_con == NULL)
|
2019-09-12 11:53:42 +12:00
|
|
|
return NULL;
|
2012-12-17 14:17:42 -05:00
|
|
|
timestamp = nm_setting_connection_get_timestamp (s_con);
|
2019-09-12 11:53:42 +12:00
|
|
|
if (timestamp == 0)
|
|
|
|
return g_strdup (_("never"));
|
2012-12-17 14:17:42 -05:00
|
|
|
|
|
|
|
/* calculate the amount of time that has elapsed */
|
|
|
|
now = g_date_time_new_now_utc ();
|
|
|
|
then = g_date_time_new_from_unix_utc (timestamp);
|
|
|
|
diff = g_date_time_difference (now, then);
|
|
|
|
days = diff / G_TIME_SPAN_DAY;
|
|
|
|
if (days == 0)
|
2019-09-12 11:53:42 +12:00
|
|
|
return g_strdup (_("today"));
|
2012-12-17 14:17:42 -05:00
|
|
|
else if (days == 1)
|
2019-09-12 11:53:42 +12:00
|
|
|
return g_strdup (_("yesterday"));
|
2012-12-17 14:17:42 -05:00
|
|
|
else
|
2019-09-12 11:53:42 +12:00
|
|
|
return g_strdup_printf (ngettext ("%i day ago", "%i days ago", days), days);
|
2012-12-17 14:17:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_details (GtkWidget *details, NMDevice *device, NMConnection *connection)
|
|
|
|
{
|
2016-04-29 16:05:54 +02:00
|
|
|
NMIPConfig *ip4_config = NULL;
|
|
|
|
NMIPConfig *ip6_config = NULL;
|
2019-10-18 15:13:55 +13:00
|
|
|
const gchar *ip4_address = NULL;
|
2019-10-18 15:03:20 +13:00
|
|
|
const gchar *ip4_route = NULL;
|
2019-09-12 11:40:48 +12:00
|
|
|
g_autofree gchar *ip4_dns = NULL;
|
2021-03-22 14:58:39 +01:00
|
|
|
g_autofree gchar *ip6_addresses = NULL;
|
2021-05-19 02:43:39 +00:00
|
|
|
const gchar *ip6_route = NULL;
|
2021-01-11 22:13:18 +01:00
|
|
|
g_autofree gchar *ip6_dns = NULL;
|
2012-12-17 14:17:42 -05:00
|
|
|
gint i = 0;
|
|
|
|
|
|
|
|
ip4_config = nm_device_get_ip4_config (device);
|
|
|
|
if (ip4_config) {
|
2019-10-18 15:13:55 +13:00
|
|
|
GPtrArray *addresses;
|
|
|
|
|
|
|
|
addresses = nm_ip_config_get_addresses (ip4_config);
|
|
|
|
if (addresses->len > 0)
|
|
|
|
ip4_address = nm_ip_address_get_address (g_ptr_array_index (addresses, 0));
|
|
|
|
|
2019-10-18 15:03:20 +13:00
|
|
|
ip4_route = nm_ip_config_get_gateway (ip4_config);
|
2019-10-18 15:13:55 +13:00
|
|
|
ip4_dns = g_strjoinv (" ", (char **) nm_ip_config_get_nameservers (ip4_config));
|
2021-01-11 22:13:18 +01:00
|
|
|
if (!*ip4_dns)
|
|
|
|
ip4_dns = NULL;
|
2012-12-17 14:17:42 -05:00
|
|
|
}
|
|
|
|
ip6_config = nm_device_get_ip6_config (device);
|
|
|
|
if (ip6_config) {
|
2021-03-22 14:58:39 +01:00
|
|
|
ip6_addresses = net_device_get_ip6_addresses (ip6_config);
|
2021-05-19 02:43:39 +00:00
|
|
|
ip6_route = nm_ip_config_get_gateway (ip6_config);
|
2021-01-11 22:13:18 +01:00
|
|
|
ip6_dns = g_strjoinv (" ", (char **) nm_ip_config_get_nameservers (ip6_config));
|
|
|
|
if (!*ip6_dns)
|
|
|
|
ip6_dns = NULL;
|
2012-12-17 14:17:42 -05:00
|
|
|
}
|
|
|
|
|
2021-03-22 14:58:39 +01:00
|
|
|
if (ip4_address && ip6_addresses) {
|
2012-12-17 14:17:42 -05:00
|
|
|
add_details_row (details, i++, _("IPv4 Address"), ip4_address);
|
2021-03-22 14:58:39 +01:00
|
|
|
gtk_widget_set_valign (details, GTK_ALIGN_START);
|
|
|
|
add_details_row (details, i++, _("IPv6 Address"), ip6_addresses);
|
|
|
|
gtk_widget_set_valign (details, GTK_ALIGN_START);
|
2012-12-17 14:17:42 -05:00
|
|
|
} else if (ip4_address) {
|
|
|
|
add_details_row (details, i++, _("IP Address"), ip4_address);
|
2021-03-22 14:58:39 +01:00
|
|
|
} else if (ip6_addresses) {
|
|
|
|
add_details_row (details, i++, _("IP Address"), ip6_addresses);
|
2012-12-17 14:17:42 -05:00
|
|
|
}
|
|
|
|
|
2020-11-05 12:32:06 +13:00
|
|
|
add_details_row (details, i++, _("Hardware Address"), nm_device_get_hw_address (device));
|
2012-12-17 14:17:42 -05:00
|
|
|
|
2021-05-19 02:43:39 +00:00
|
|
|
if (ip4_route && ip6_route) {
|
|
|
|
g_autofree gchar *ip_routes = g_strjoin ("\n", ip4_route, ip6_route, NULL);
|
|
|
|
add_details_row (details, i++, _("Default Route"), ip_routes);
|
|
|
|
} else if (ip4_route) {
|
2012-12-17 14:17:42 -05:00
|
|
|
add_details_row (details, i++, _("Default Route"), ip4_route);
|
2021-05-19 02:43:39 +00:00
|
|
|
} else if (ip6_route) {
|
|
|
|
add_details_row (details, i++, _("Default Route"), ip6_route);
|
|
|
|
}
|
2021-01-11 22:13:18 +01:00
|
|
|
|
|
|
|
if (ip4_dns && ip6_dns) {
|
|
|
|
add_details_row (details, i++, _("DNS4"), ip4_dns);
|
|
|
|
add_details_row (details, i++, _("DNS6"), ip6_dns);
|
|
|
|
} else if (ip4_dns) {
|
2012-12-17 14:17:42 -05:00
|
|
|
add_details_row (details, i++, _("DNS"), ip4_dns);
|
2021-01-11 22:13:18 +01:00
|
|
|
} else if (ip6_dns) {
|
|
|
|
add_details_row (details, i++, _("DNS"), ip6_dns);
|
|
|
|
}
|
2012-12-17 14:17:42 -05:00
|
|
|
|
|
|
|
if (nm_device_get_state (device) != NM_DEVICE_STATE_ACTIVATED) {
|
2019-09-12 11:40:48 +12:00
|
|
|
g_autofree gchar *last_used = NULL;
|
2012-12-17 14:17:42 -05:00
|
|
|
last_used = get_last_used_string (connection);
|
|
|
|
add_details_row (details, i++, _("Last used"), last_used);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
static void populate_ui (NetDeviceEthernet *self);
|
2012-12-17 14:17:42 -05:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
device_state_to_off_switch (NMDeviceState state)
|
|
|
|
{
|
|
|
|
switch (state) {
|
|
|
|
case NM_DEVICE_STATE_UNMANAGED:
|
|
|
|
case NM_DEVICE_STATE_UNAVAILABLE:
|
|
|
|
case NM_DEVICE_STATE_DISCONNECTED:
|
|
|
|
case NM_DEVICE_STATE_DEACTIVATING:
|
|
|
|
case NM_DEVICE_STATE_FAILED:
|
|
|
|
return FALSE;
|
|
|
|
default:
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-10-18 11:47:17 +13:00
|
|
|
device_ethernet_refresh_ui (NetDeviceEthernet *self)
|
2012-12-17 14:17:42 -05:00
|
|
|
{
|
|
|
|
NMDeviceState state;
|
2019-10-23 10:54:03 +13:00
|
|
|
g_autofree gchar *speed_text = NULL;
|
2019-10-01 12:50:30 +13:00
|
|
|
g_autofree gchar *status = NULL;
|
2012-12-17 14:17:42 -05:00
|
|
|
|
2019-10-24 13:04:14 +13:00
|
|
|
state = nm_device_get_state (self->device);
|
2019-10-18 11:47:17 +13:00
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (self->device_off_switch),
|
2017-07-17 23:21:08 -03:00
|
|
|
state != NM_DEVICE_STATE_UNAVAILABLE
|
|
|
|
&& state != NM_DEVICE_STATE_UNMANAGED);
|
2019-10-18 11:47:17 +13:00
|
|
|
self->updating_device = TRUE;
|
|
|
|
gtk_switch_set_active (self->device_off_switch, device_state_to_off_switch (state));
|
|
|
|
self->updating_device = FALSE;
|
2012-12-17 14:17:42 -05:00
|
|
|
|
2019-10-23 10:54:03 +13:00
|
|
|
if (state != NM_DEVICE_STATE_UNAVAILABLE) {
|
2019-10-24 13:04:14 +13:00
|
|
|
guint speed = nm_device_ethernet_get_speed (NM_DEVICE_ETHERNET (self->device));
|
2019-10-23 10:54:03 +13:00
|
|
|
if (speed > 0) {
|
|
|
|
/* Translators: network device speed */
|
|
|
|
speed_text = g_strdup_printf (_("%d Mb/s"), speed);
|
|
|
|
}
|
|
|
|
}
|
2019-10-24 13:04:14 +13:00
|
|
|
status = panel_device_status_to_localized_string (self->device, speed_text);
|
2021-11-29 10:37:01 -03:00
|
|
|
adw_preferences_row_set_title (ADW_PREFERENCES_ROW (self->details_row), status);
|
2012-12-17 14:17:42 -05:00
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
populate_ui (self);
|
2012-12-17 14:17:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-10-18 11:47:17 +13:00
|
|
|
editor_done (NetDeviceEthernet *self)
|
2012-12-17 14:17:42 -05:00
|
|
|
{
|
2019-10-18 11:47:17 +13:00
|
|
|
device_ethernet_refresh_ui (self);
|
2012-12-17 14:17:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-10-18 11:47:17 +13:00
|
|
|
show_details (NetDeviceEthernet *self, GtkButton *button, const gchar *title)
|
2012-12-17 14:17:42 -05:00
|
|
|
{
|
|
|
|
GtkWidget *row;
|
|
|
|
NMConnection *connection;
|
|
|
|
NetConnectionEditor *editor;
|
|
|
|
|
2017-07-17 23:21:08 -03:00
|
|
|
row = g_object_get_data (G_OBJECT (button), "row");
|
2012-12-17 14:17:42 -05:00
|
|
|
connection = NM_CONNECTION (g_object_get_data (G_OBJECT (row), "connection"));
|
|
|
|
|
2020-11-19 11:17:22 +13:00
|
|
|
editor = net_connection_editor_new (connection, self->device, NULL, self->client);
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_window_set_transient_for (GTK_WINDOW (editor), GTK_WINDOW (gtk_widget_get_native (GTK_WIDGET (self))));
|
2013-04-12 22:03:56 -04:00
|
|
|
if (title)
|
|
|
|
net_connection_editor_set_title (editor, title);
|
2019-11-22 16:21:43 +13:00
|
|
|
g_signal_connect_object (editor, "done", G_CALLBACK (editor_done), self, G_CONNECT_SWAPPED);
|
2020-11-19 11:43:16 +13:00
|
|
|
gtk_window_present (GTK_WINDOW (editor));
|
2012-12-17 14:17:42 -05:00
|
|
|
}
|
|
|
|
|
2013-04-12 22:03:56 -04:00
|
|
|
static void
|
2019-10-18 11:47:17 +13:00
|
|
|
show_details_for_row (NetDeviceEthernet *self, GtkButton *button)
|
2013-04-12 22:03:56 -04:00
|
|
|
{
|
2019-10-18 11:47:17 +13:00
|
|
|
show_details (self, button, NULL);
|
2013-04-12 22:03:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-10-24 20:29:35 +13:00
|
|
|
details_button_clicked_cb (NetDeviceEthernet *self)
|
2013-04-12 22:03:56 -04:00
|
|
|
{
|
|
|
|
/* Translators: This is used as the title of the connection
|
|
|
|
* details window for ethernet, if there is only a single
|
|
|
|
* profile. It is also used to display ethernet in the
|
|
|
|
* device list.
|
|
|
|
*/
|
2019-10-18 11:47:17 +13:00
|
|
|
show_details (self, self->details_button, _("Wired"));
|
2013-04-12 22:03:56 -04:00
|
|
|
}
|
|
|
|
|
2012-12-17 14:17:42 -05:00
|
|
|
static void
|
2019-10-18 11:47:17 +13:00
|
|
|
add_row (NetDeviceEthernet *self, NMConnection *connection)
|
2012-12-17 14:17:42 -05:00
|
|
|
{
|
|
|
|
GtkWidget *row;
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkWidget *box;
|
|
|
|
GtkWidget *details;
|
|
|
|
NMActiveConnection *aconn;
|
|
|
|
gboolean active;
|
|
|
|
|
|
|
|
active = FALSE;
|
|
|
|
|
2019-10-24 13:04:14 +13:00
|
|
|
aconn = nm_device_get_active_connection (self->device);
|
2012-12-17 14:17:42 -05:00
|
|
|
if (aconn) {
|
2016-04-29 16:05:54 +02:00
|
|
|
const gchar *uuid1, *uuid2;
|
|
|
|
uuid1 = nm_active_connection_get_uuid (aconn);
|
|
|
|
uuid2 = nm_connection_get_uuid (connection);
|
|
|
|
active = g_strcmp0 (uuid1, uuid2) == 0;
|
2012-12-17 14:17:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
row = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_box_append (GTK_BOX (row), box);
|
2012-12-17 14:17:42 -05:00
|
|
|
widget = gtk_label_new (nm_connection_get_id (connection));
|
2013-11-19 22:26:49 +02:00
|
|
|
gtk_widget_set_margin_start (widget, 12);
|
|
|
|
gtk_widget_set_margin_end (widget, 12);
|
2019-01-27 18:06:05 +01:00
|
|
|
gtk_widget_set_margin_top (widget, 8);
|
|
|
|
gtk_widget_set_margin_bottom (widget, 8);
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_box_append (GTK_BOX (box), widget);
|
2012-12-17 14:17:42 -05:00
|
|
|
|
|
|
|
if (active) {
|
2021-11-29 10:37:01 -03:00
|
|
|
widget = gtk_image_new_from_icon_name ("object-select-symbolic");
|
2012-12-17 14:17:42 -05:00
|
|
|
gtk_widget_set_halign (widget, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_box_append (GTK_BOX (box), widget);
|
2012-12-17 14:17:42 -05:00
|
|
|
|
|
|
|
details = gtk_grid_new ();
|
|
|
|
gtk_grid_set_row_spacing (GTK_GRID (details), 10);
|
|
|
|
gtk_grid_set_column_spacing (GTK_GRID (details), 10);
|
|
|
|
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_box_append (GTK_BOX (row), details);
|
2012-12-17 14:17:42 -05:00
|
|
|
|
2019-10-24 13:04:14 +13:00
|
|
|
add_details (details, self->device, connection);
|
2012-12-17 14:17:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* filler */
|
|
|
|
widget = gtk_label_new ("");
|
|
|
|
gtk_widget_set_hexpand (widget, TRUE);
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_box_append (GTK_BOX (box), widget);
|
2012-12-17 14:17:42 -05:00
|
|
|
|
2021-11-29 10:37:01 -03:00
|
|
|
widget = gtk_button_new_from_icon_name ("emblem-system-symbolic");
|
2013-11-19 22:26:49 +02:00
|
|
|
gtk_widget_set_margin_start (widget, 12);
|
|
|
|
gtk_widget_set_margin_end (widget, 12);
|
2019-01-27 18:06:05 +01:00
|
|
|
gtk_widget_set_margin_top (widget, 8);
|
|
|
|
gtk_widget_set_margin_bottom (widget, 8);
|
2012-12-17 14:17:42 -05:00
|
|
|
gtk_widget_set_halign (widget, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_accessible_update_property (GTK_ACCESSIBLE (widget),
|
|
|
|
GTK_ACCESSIBLE_PROPERTY_LABEL, _("Options…"),
|
|
|
|
-1);
|
|
|
|
gtk_box_append (GTK_BOX (box), widget);
|
2017-07-17 23:21:08 -03:00
|
|
|
g_object_set_data (G_OBJECT (widget), "edit", widget);
|
2012-12-17 14:17:42 -05:00
|
|
|
g_object_set_data (G_OBJECT (widget), "row", row);
|
2019-11-22 16:21:43 +13:00
|
|
|
g_signal_connect_object (widget, "clicked", G_CALLBACK (show_details_for_row), self, G_CONNECT_SWAPPED);
|
2012-12-17 14:17:42 -05:00
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (row), "connection", connection);
|
|
|
|
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_list_box_append (self->connection_list, row);
|
2012-12-17 14:17:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-10-18 11:47:17 +13:00
|
|
|
connection_removed (NetDeviceEthernet *self, NMRemoteConnection *connection)
|
2012-12-17 14:17:42 -05:00
|
|
|
{
|
2019-10-18 11:47:17 +13:00
|
|
|
if (g_hash_table_remove (self->connections, connection))
|
|
|
|
device_ethernet_refresh_ui (self);
|
2012-12-17 14:17:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-10-18 11:47:17 +13:00
|
|
|
populate_ui (NetDeviceEthernet *self)
|
2012-12-17 14:17:42 -05:00
|
|
|
{
|
|
|
|
GSList *connections, *l;
|
|
|
|
NMConnection *connection;
|
2021-11-29 10:37:01 -03:00
|
|
|
GtkWidget *child;
|
2012-12-17 14:17:42 -05:00
|
|
|
gint n_connections;
|
|
|
|
|
2021-11-29 10:37:01 -03:00
|
|
|
while ((child = gtk_widget_get_first_child (GTK_WIDGET (self->connection_list))) != NULL)
|
|
|
|
gtk_list_box_remove (self->connection_list, child);
|
2012-12-17 14:17:42 -05:00
|
|
|
|
2019-10-24 13:04:14 +13:00
|
|
|
connections = net_device_get_valid_connections (self->client, self->device);
|
2012-12-17 14:17:42 -05:00
|
|
|
for (l = connections; l; l = l->next) {
|
|
|
|
NMConnection *connection = l->data;
|
2019-10-18 11:47:17 +13:00
|
|
|
if (!g_hash_table_contains (self->connections, connection)) {
|
|
|
|
g_hash_table_add (self->connections, connection);
|
2012-12-17 14:17:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
n_connections = g_slist_length (connections);
|
|
|
|
|
|
|
|
if (n_connections > 1) {
|
|
|
|
for (l = connections; l; l = l->next) {
|
|
|
|
NMConnection *connection = l->data;
|
2019-10-18 11:47:17 +13:00
|
|
|
add_row (self, connection);
|
2012-12-17 14:17:42 -05:00
|
|
|
}
|
2022-01-27 14:07:58 -08:00
|
|
|
gtk_stack_set_visible_child (self->connection_stack,
|
|
|
|
GTK_WIDGET (self->connection_list));
|
2012-12-17 14:17:42 -05:00
|
|
|
} else if (n_connections == 1) {
|
|
|
|
connection = connections->data;
|
2022-01-27 14:07:58 -08:00
|
|
|
gtk_stack_set_visible_child (self->connection_stack,
|
|
|
|
GTK_WIDGET (self->details_listbox));
|
2019-10-18 11:47:17 +13:00
|
|
|
g_object_set_data (G_OBJECT (self->details_button), "row", self->details_button);
|
|
|
|
g_object_set_data (G_OBJECT (self->details_button), "connection", connection);
|
2012-12-17 14:17:42 -05:00
|
|
|
|
|
|
|
}
|
2013-02-15 13:22:07 +01:00
|
|
|
|
2022-01-27 14:07:58 -08:00
|
|
|
gtk_widget_set_visible (GTK_WIDGET (self->connection_stack), n_connections >= 1);
|
|
|
|
|
2013-02-15 13:22:07 +01:00
|
|
|
g_slist_free (connections);
|
2012-12-17 14:17:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-10-18 11:47:17 +13:00
|
|
|
client_connection_added_cb (NetDeviceEthernet *self)
|
2012-12-17 14:17:42 -05:00
|
|
|
{
|
2019-10-18 11:47:17 +13:00
|
|
|
device_ethernet_refresh_ui (self);
|
2012-12-17 14:17:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-10-24 20:29:35 +13:00
|
|
|
add_profile_button_clicked_cb (NetDeviceEthernet *self)
|
2012-12-17 14:17:42 -05:00
|
|
|
{
|
|
|
|
NMConnection *connection;
|
|
|
|
NMSettingConnection *sc;
|
2019-09-12 11:40:48 +12:00
|
|
|
g_autofree gchar *uuid = NULL;
|
|
|
|
g_autofree gchar *id = NULL;
|
2012-12-17 14:17:42 -05:00
|
|
|
NetConnectionEditor *editor;
|
2016-04-29 16:05:54 +02:00
|
|
|
const GPtrArray *connections;
|
2012-12-17 14:17:42 -05:00
|
|
|
|
2016-04-29 16:05:54 +02:00
|
|
|
connection = nm_simple_connection_new ();
|
2012-12-17 14:17:42 -05:00
|
|
|
sc = NM_SETTING_CONNECTION (nm_setting_connection_new ());
|
|
|
|
nm_connection_add_setting (connection, NM_SETTING (sc));
|
|
|
|
|
|
|
|
uuid = nm_utils_uuid_generate ();
|
|
|
|
|
2019-10-23 14:45:52 +13:00
|
|
|
connections = nm_client_get_connections (self->client);
|
2016-04-07 15:07:36 +02:00
|
|
|
id = ce_page_get_next_available_name (connections, NAME_FORMAT_PROFILE, NULL);
|
2012-12-17 14:17:42 -05:00
|
|
|
|
|
|
|
g_object_set (sc,
|
|
|
|
NM_SETTING_CONNECTION_UUID, uuid,
|
|
|
|
NM_SETTING_CONNECTION_ID, id,
|
|
|
|
NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME,
|
|
|
|
NM_SETTING_CONNECTION_AUTOCONNECT, TRUE,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
nm_connection_add_setting (connection, nm_setting_wired_new ());
|
|
|
|
|
2020-11-19 11:17:22 +13:00
|
|
|
editor = net_connection_editor_new (connection, self->device, NULL, self->client);
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_window_set_transient_for (GTK_WINDOW (editor), GTK_WINDOW (gtk_widget_get_native (GTK_WIDGET (self))));
|
2019-11-22 16:21:43 +13:00
|
|
|
g_signal_connect_object (editor, "done", G_CALLBACK (editor_done), self, G_CONNECT_SWAPPED);
|
2020-11-19 11:43:16 +13:00
|
|
|
gtk_window_present (GTK_WINDOW (editor));
|
2012-12-17 14:17:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-10-24 20:29:35 +13:00
|
|
|
device_off_switch_changed_cb (NetDeviceEthernet *self)
|
2012-12-17 14:17:42 -05:00
|
|
|
{
|
|
|
|
NMConnection *connection;
|
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
if (self->updating_device)
|
2012-12-17 14:17:42 -05:00
|
|
|
return;
|
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
if (gtk_switch_get_active (self->device_off_switch)) {
|
2019-10-24 13:04:14 +13:00
|
|
|
connection = net_device_get_find_connection (self->client, self->device);
|
2012-12-17 14:17:42 -05:00
|
|
|
if (connection != NULL) {
|
2019-10-23 14:45:52 +13:00
|
|
|
nm_client_activate_connection_async (self->client,
|
2016-04-29 16:05:54 +02:00
|
|
|
connection,
|
2019-10-24 13:04:14 +13:00
|
|
|
self->device,
|
2016-04-29 16:05:54 +02:00
|
|
|
NULL, NULL, NULL, NULL);
|
2012-12-17 14:17:42 -05:00
|
|
|
}
|
|
|
|
} else {
|
2019-10-24 13:04:14 +13:00
|
|
|
nm_device_disconnect (self->device, NULL, NULL);
|
2012-12-17 14:17:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-16 10:30:58 -04:00
|
|
|
static void
|
2019-10-24 20:45:05 +13:00
|
|
|
connection_list_row_activated_cb (NetDeviceEthernet *self, GtkListBoxRow *row)
|
2013-08-16 10:30:58 -04:00
|
|
|
{
|
|
|
|
NMConnection *connection;
|
2021-11-29 10:37:01 -03:00
|
|
|
GtkWidget *child;
|
2013-08-16 10:30:58 -04:00
|
|
|
|
2019-10-24 13:04:14 +13:00
|
|
|
if (!NM_IS_DEVICE_ETHERNET (self->device) ||
|
|
|
|
!nm_device_ethernet_get_carrier (NM_DEVICE_ETHERNET (self->device)))
|
2013-08-16 10:30:58 -04:00
|
|
|
return;
|
|
|
|
|
2021-11-29 10:37:01 -03:00
|
|
|
child = gtk_list_box_row_get_child (GTK_LIST_BOX_ROW (row));
|
|
|
|
connection = NM_CONNECTION (g_object_get_data (G_OBJECT (child), "connection"));
|
2013-08-16 10:30:58 -04:00
|
|
|
|
2019-10-23 14:45:52 +13:00
|
|
|
nm_client_activate_connection_async (self->client,
|
2016-04-29 16:05:54 +02:00
|
|
|
connection,
|
2019-10-24 13:04:14 +13:00
|
|
|
self->device,
|
2016-04-29 16:05:54 +02:00
|
|
|
NULL, NULL, NULL, NULL);
|
2013-08-16 10:30:58 -04:00
|
|
|
}
|
|
|
|
|
2012-12-17 14:17:42 -05:00
|
|
|
static void
|
|
|
|
device_ethernet_finalize (GObject *object)
|
|
|
|
{
|
2019-10-18 11:47:17 +13:00
|
|
|
NetDeviceEthernet *self = NET_DEVICE_ETHERNET (object);
|
2012-12-17 14:17:42 -05:00
|
|
|
|
2019-10-23 14:45:52 +13:00
|
|
|
g_clear_object (&self->client);
|
2019-10-24 13:04:14 +13:00
|
|
|
g_clear_object (&self->device);
|
2019-10-18 11:47:17 +13:00
|
|
|
g_hash_table_destroy (self->connections);
|
2013-09-20 17:23:06 +02:00
|
|
|
|
2012-12-17 14:17:42 -05:00
|
|
|
G_OBJECT_CLASS (net_device_ethernet_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2012-08-29 14:39:52 -04:00
|
|
|
static void
|
|
|
|
net_device_ethernet_class_init (NetDeviceEthernetClass *klass)
|
|
|
|
{
|
2012-12-17 14:17:42 -05:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2019-10-24 14:30:28 +13:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2012-08-29 14:39:52 -04:00
|
|
|
|
2012-12-17 14:17:42 -05:00
|
|
|
object_class->finalize = device_ethernet_finalize;
|
2019-10-24 14:30:28 +13:00
|
|
|
|
|
|
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/network/network-ethernet.ui");
|
|
|
|
|
2019-10-24 20:45:05 +13:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, NetDeviceEthernet, connection_list);
|
2022-01-27 14:07:58 -08:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, NetDeviceEthernet, connection_stack);
|
2019-10-24 14:30:28 +13:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, NetDeviceEthernet, details_button);
|
2021-11-29 10:37:01 -03:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, NetDeviceEthernet, details_listbox);
|
2019-10-24 14:30:28 +13:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, NetDeviceEthernet, details_row);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, NetDeviceEthernet, device_off_switch);
|
2019-10-24 20:29:35 +13:00
|
|
|
|
2019-10-24 20:45:05 +13:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, connection_list_row_activated_cb);
|
2019-10-24 20:29:35 +13:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, device_off_switch_changed_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, details_button_clicked_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, add_profile_button_clicked_cb);
|
2012-08-29 14:39:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-10-18 11:47:17 +13:00
|
|
|
net_device_ethernet_init (NetDeviceEthernet *self)
|
2012-08-29 14:39:52 -04:00
|
|
|
{
|
2019-10-24 14:30:28 +13:00
|
|
|
gtk_widget_init_template (GTK_WIDGET (self));
|
2019-10-15 12:25:48 +13:00
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
self->connections = g_hash_table_new (NULL, NULL);
|
2012-08-29 14:39:52 -04:00
|
|
|
}
|
2019-10-23 10:49:03 +13:00
|
|
|
|
|
|
|
NetDeviceEthernet *
|
2019-10-23 13:51:47 +13:00
|
|
|
net_device_ethernet_new (NMClient *client, NMDevice *device)
|
2019-10-23 10:49:03 +13:00
|
|
|
{
|
2019-10-23 14:45:52 +13:00
|
|
|
NetDeviceEthernet *self;
|
|
|
|
|
2019-10-24 14:30:28 +13:00
|
|
|
self = g_object_new (net_device_ethernet_get_type (), NULL);
|
2019-10-23 14:45:52 +13:00
|
|
|
self->client = g_object_ref (client);
|
2019-10-24 13:04:14 +13:00
|
|
|
self->device = g_object_ref (device);
|
2019-10-23 14:45:52 +13:00
|
|
|
|
|
|
|
g_signal_connect_object (client, NM_CLIENT_CONNECTION_ADDED,
|
|
|
|
G_CALLBACK (client_connection_added_cb), self, G_CONNECT_SWAPPED);
|
|
|
|
g_signal_connect_object (client, NM_CLIENT_CONNECTION_REMOVED,
|
|
|
|
G_CALLBACK (connection_removed), self, G_CONNECT_SWAPPED);
|
|
|
|
|
2019-10-24 13:48:25 +13:00
|
|
|
g_signal_connect_object (device, "state-changed", G_CALLBACK (device_ethernet_refresh_ui), self, G_CONNECT_SWAPPED);
|
2019-10-24 12:13:40 +13:00
|
|
|
|
2019-10-23 14:45:52 +13:00
|
|
|
device_ethernet_refresh_ui (self);
|
|
|
|
|
|
|
|
return self;
|
2019-10-23 10:49:03 +13:00
|
|
|
}
|
2019-10-24 13:04:14 +13:00
|
|
|
|
|
|
|
NMDevice *
|
|
|
|
net_device_ethernet_get_device (NetDeviceEthernet *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (NET_IS_DEVICE_ETHERNET (self), NULL);
|
|
|
|
return self->device;
|
|
|
|
}
|