static void
device_off_toggled (GtkSwitch         *sw,
                    GParamSpec        *pspec,
                    NetDeviceEthernet *device)
{
        NMClient *client;
        NMDevice *nm_device;
        NMConnection *connection;
        NMActiveConnection *a;

        if (device->updating_device)
                return;

        client = net_object_get_client (NET_OBJECT (device));
        nm_device = net_device_get_nm_device (NET_DEVICE (device));

        if (gtk_switch_get_active (sw)) {
                connection = net_device_get_find_connection (NET_DEVICE (device));
                if (connection != NULL) {
                        nm_client_activate_connection (client,
                                                       connection,
                                                       nm_device,
                                                       NULL, NULL, NULL);
                }
        } else {
                a = nm_device_get_active_connection (nm_device);
                if (a) {
                        nm_client_deactivate_connection (client, a);
                }
        }
}
static void
show_details (GtkButton *button, NetDeviceEthernet *device, const gchar *title)
{
        GtkWidget *row;
        NMConnection *connection;
        GtkWidget *window;
        NetConnectionEditor *editor;
        NMClient *client;
        NMRemoteSettings *settings;
        NMDevice *nmdev;

        window = gtk_widget_get_toplevel (GTK_WIDGET (button));

        row = GTK_WIDGET (g_object_get_data (G_OBJECT (button), "row"));
        connection = NM_CONNECTION (g_object_get_data (G_OBJECT (row), "connection"));

        nmdev = net_device_get_nm_device (NET_DEVICE (device));
        client = net_object_get_client (NET_OBJECT (device));
        settings = net_object_get_remote_settings (NET_OBJECT (device));
        editor = net_connection_editor_new (GTK_WINDOW (window), connection, nmdev, NULL, client, settings);
        if (title)
                net_connection_editor_set_title (editor, title);
        g_signal_connect (editor, "done", G_CALLBACK (editor_done), device);
        net_connection_editor_run (editor);
}
static void
add_profile (GtkButton *button, NetDeviceEthernet *device)
{
        NMRemoteSettings *settings;
        NMConnection *connection;
        NMSettingConnection *sc;
        gchar *uuid, *id;
        NetConnectionEditor *editor;
        GtkWidget *window;
        NMClient *client;
        NMDevice *nmdev;
        GSList *connections;

        connection = nm_connection_new ();
        sc = NM_SETTING_CONNECTION (nm_setting_connection_new ());
        nm_connection_add_setting (connection, NM_SETTING (sc));

        uuid = nm_utils_uuid_generate ();

        settings = net_object_get_remote_settings (NET_OBJECT (device));
        connections = nm_remote_settings_list_connections (settings);
        id = ce_page_get_next_available_name (connections, _("Profile %d"));
        g_slist_free (connections);

        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 ());

        g_free (uuid);
        g_free (id);

        window = gtk_widget_get_toplevel (GTK_WIDGET (button));

        nmdev = net_device_get_nm_device (NET_DEVICE (device));
        client = net_object_get_client (NET_OBJECT (device));
        editor = net_connection_editor_new (GTK_WINDOW (window), connection, nmdev, NULL, client, settings);
        g_signal_connect (editor, "done", G_CALLBACK (editor_done), device);
        net_connection_editor_run (editor);
}
static void
device_ethernet_constructed (GObject *object)
{
        NetDeviceEthernet *device = NET_DEVICE_ETHERNET (object);
        NMClient *client;
        GtkWidget *list;
        GtkWidget *swin;
        GtkWidget *widget;

        widget = GTK_WIDGET (gtk_builder_get_object (device->builder,
                                                     "device_off_switch"));
        g_signal_connect (widget, "notify::active",
                          G_CALLBACK (device_off_toggled), device);

        device->scrolled_window = swin = GTK_WIDGET (gtk_builder_get_object (device->builder, "list"));
        device->list = list = GTK_WIDGET (gtk_list_box_new ());
        gtk_list_box_set_selection_mode (GTK_LIST_BOX (list), GTK_SELECTION_NONE);
        gtk_list_box_set_header_func (GTK_LIST_BOX (list), cc_list_box_update_header_func, NULL, NULL);
        gtk_container_add (GTK_CONTAINER (swin), list);
        g_signal_connect (list, "row-activated",
                          G_CALLBACK (connection_activated), device);
        gtk_widget_show (list);

        device->details = GTK_WIDGET (gtk_builder_get_object (device->builder, "details"));

        device->details_button = GTK_WIDGET (gtk_builder_get_object (device->builder, "details_button"));
        g_signal_connect (device->details_button, "clicked",
                          G_CALLBACK (show_details_for_wired), device);

        device->add_profile_button = GTK_WIDGET (gtk_builder_get_object (device->builder, "add_profile_button"));
        g_signal_connect (device->add_profile_button, "clicked",
                          G_CALLBACK (add_profile), device);

        client = net_object_get_client (NET_OBJECT (object));
        g_signal_connect (client, NM_CLIENT_CONNECTION_ADDED,
                          G_CALLBACK (client_connection_added_cb), object);
        g_signal_connect_object (client, NM_CLIENT_CONNECTION_REMOVED,
                                 G_CALLBACK (connection_removed), device, 0);

        device_ethernet_refresh_ui (device);
}
static void
connection_activated (GtkListBox *list, GtkListBoxRow *row, NetDeviceEthernet *device)
{
        NMClient *client;
        NMDevice *nm_device;
        NMConnection *connection;

        client = net_object_get_client (NET_OBJECT (device));
        nm_device = net_device_get_nm_device (NET_DEVICE (device));

        if (!NM_IS_DEVICE_ETHERNET (nm_device) ||
            !nm_device_ethernet_get_carrier (NM_DEVICE_ETHERNET (nm_device)))
                return;

        connection = NM_CONNECTION (g_object_get_data (G_OBJECT (gtk_bin_get_child (GTK_BIN (row))), "connection"));

        nm_client_activate_connection (client,
                                       connection,
                                       nm_device,
                                       NULL, NULL, NULL);
}