コード例 #1
0
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);
                }
        }
}
コード例 #2
0
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);
}
コード例 #3
0
static void
device_ethernet_refresh_ui (NetDeviceEthernet *device)
{
        NMDevice *nm_device;
        NMDeviceState state;
        GtkWidget *widget;
        gchar *speed = NULL;

        nm_device = net_device_get_nm_device (NET_DEVICE (device));

        widget = GTK_WIDGET (gtk_builder_get_object (device->builder, "label_device"));
        gtk_label_set_label (GTK_LABEL (widget), net_object_get_title (NET_OBJECT (device)));

        widget = GTK_WIDGET (gtk_builder_get_object (device->builder, "image_device"));
        gtk_image_set_from_icon_name (GTK_IMAGE (widget),
                                      panel_device_to_icon_name (nm_device, FALSE),
                                      GTK_ICON_SIZE_DIALOG);

        widget = GTK_WIDGET (gtk_builder_get_object (device->builder, "device_off_switch"));
        state = nm_device_get_state (nm_device);
        gtk_widget_set_visible (widget,
                                state != NM_DEVICE_STATE_UNAVAILABLE
                                && state != NM_DEVICE_STATE_UNMANAGED);
        device->updating_device = TRUE;
        gtk_switch_set_active (GTK_SWITCH (widget), device_state_to_off_switch (state));
        device->updating_device = FALSE;

        if (state != NM_DEVICE_STATE_UNAVAILABLE)
                speed = net_device_simple_get_speed (NET_DEVICE_SIMPLE (device));
        panel_set_device_status (device->builder, "label_status", nm_device, speed);

        populate_ui (device);
}
コード例 #4
0
static char *
device_ethernet_get_speed (NetDeviceSimple *device_simple)
{
        NMDevice *nm_device;
        guint speed;

        nm_device = net_device_get_nm_device (NET_DEVICE (device_simple));

        speed = nm_device_ethernet_get_speed (NM_DEVICE_ETHERNET (nm_device));
        if (speed > 0) {
                /* Translators: network device speed */
                return g_strdup_printf (_("%d Mb/s"), speed);
        } else
                return NULL;
}
コード例 #5
0
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);
}
コード例 #6
0
static void
device_ethernet_finalize (GObject *object)
{
        NetDeviceEthernet *device = NET_DEVICE_ETHERNET (object);
        GSList *connections, *l;

        g_object_unref (device->builder);

        connections = net_device_get_valid_connections (NET_DEVICE (device));
        for (l = connections; l; l = l->next) {
                NMConnection *connection = l->data;
                if (g_object_get_data (G_OBJECT (connection), "removed_signal_handler")) {
                        g_signal_handlers_disconnect_by_func (connection, connection_removed, device);
                        g_object_set_data (G_OBJECT (connection), "removed_signal_handler", NULL);
                }
        }
        g_slist_free (connections);

        G_OBJECT_CLASS (net_device_ethernet_parent_class)->finalize (object);
}
コード例 #7
0
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);
}
コード例 #8
0
static void
populate_ui (NetDeviceEthernet *device)
{
        GList *children, *c;
        GSList *connections, *l;
        NMConnection *connection;
        gint n_connections;

        children = gtk_container_get_children (GTK_CONTAINER (device->list));
        for (c = children; c; c = c->next) {
                gtk_container_remove (GTK_CONTAINER (device->list), c->data);
        }
        g_list_free (children);

        children = gtk_container_get_children (GTK_CONTAINER (device->details));
        for (c = children; c; c = c->next) {
                gtk_container_remove (GTK_CONTAINER (device->details), c->data);
        }
        g_list_free (children);

        connections = net_device_get_valid_connections (NET_DEVICE (device));
        for (l = connections; l; l = l->next) {
                NMConnection *connection = l->data;
                if (!g_object_get_data (G_OBJECT (connection), "removed_signal_handler")) {
                        g_signal_connect (connection, "removed",
                                          G_CALLBACK (connection_removed), device);
                        g_object_set_data (G_OBJECT (connection), "removed_signal_handler", GINT_TO_POINTER (TRUE));
                }
        }
        n_connections = g_slist_length (connections);

        if (n_connections > 4) {
                gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (device->scrolled_window),
                                                GTK_POLICY_NEVER,
                                                GTK_POLICY_AUTOMATIC);
                gtk_widget_set_vexpand (device->scrolled_window, TRUE);
        } else {
                gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (device->scrolled_window),
                                                GTK_POLICY_NEVER,
                                                GTK_POLICY_NEVER);
                gtk_widget_set_vexpand (device->scrolled_window, FALSE);
        }

        if (n_connections > 1) {
                gtk_widget_hide (device->details);
                gtk_widget_hide (device->details_button);
                for (l = connections; l; l = l->next) {
                        NMConnection *connection = l->data;
                        add_row (device, connection);
                }
                gtk_widget_show (device->scrolled_window);
        } else if (n_connections == 1) {
                connection = connections->data;
                gtk_widget_hide (device->scrolled_window);
                add_details (device->details, net_device_get_nm_device (NET_DEVICE (device)), connection);
                gtk_widget_show_all (device->details);
                gtk_widget_show (device->details_button);
                g_object_set_data (G_OBJECT (device->details_button), "row", device->details_button);
                g_object_set_data (G_OBJECT (device->details_button), "connection", connection);

        } else {
                gtk_widget_hide (device->scrolled_window);
                gtk_widget_hide (device->details);
                gtk_widget_hide (device->details_button);
        }

        g_slist_free (connections);
}
コード例 #9
0
static void
add_row (NetDeviceEthernet *device, NMConnection *connection)
{
        GtkWidget *row;
        GtkWidget *widget;
        GtkWidget *box;
        GtkWidget *details;
        NMDevice *nmdev;
        NMActiveConnection *aconn;
        gboolean active;
        GtkWidget *image;

        active = FALSE;

        nmdev = net_device_get_nm_device (NET_DEVICE (device));
        aconn = nm_device_get_active_connection (nmdev);
        if (aconn) {
                const gchar *path1, *path2;
                path1 = nm_active_connection_get_connection (aconn);
                path2 = nm_connection_get_path (connection);
                active = g_strcmp0 (path1, path2) == 0;
        }

        row = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
        box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
        gtk_box_pack_start (GTK_BOX (row), box, FALSE, TRUE, 0);
        widget = gtk_label_new (nm_connection_get_id (connection));
        gtk_widget_set_margin_left (widget, 12);
        gtk_widget_set_margin_right (widget, 12);
        gtk_widget_set_margin_top (widget, 12);
        gtk_widget_set_margin_bottom (widget, 12);
        gtk_box_pack_start (GTK_BOX (box), widget, FALSE, TRUE, 0);

        if (active) {
                widget = gtk_image_new_from_icon_name ("object-select-symbolic", GTK_ICON_SIZE_MENU);
                gtk_widget_set_halign (widget, GTK_ALIGN_CENTER);
                gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
                gtk_box_pack_start (GTK_BOX (box), widget, FALSE, TRUE, 0);

                details = gtk_grid_new ();
                gtk_grid_set_row_spacing (GTK_GRID (details), 10);
                gtk_grid_set_column_spacing (GTK_GRID (details), 10);

                gtk_box_pack_start (GTK_BOX (row), details, FALSE, TRUE, 0);

                add_details (details, nmdev, connection);
        }

        /* filler */
        widget = gtk_label_new ("");
        gtk_widget_set_hexpand (widget, TRUE);
        gtk_box_pack_start (GTK_BOX (box), widget, TRUE, TRUE, 0);

        image = gtk_image_new_from_icon_name ("emblem-system-symbolic", GTK_ICON_SIZE_MENU);
        gtk_widget_show (image);
        widget = gtk_button_new ();
        gtk_style_context_add_class (gtk_widget_get_style_context (widget), "image-button");
        gtk_widget_set_margin_left (widget, 12);
        gtk_widget_set_margin_right (widget, 12);
        gtk_widget_set_margin_top (widget, 12);
        gtk_widget_set_margin_bottom (widget, 12);
        gtk_widget_show (widget);
        gtk_container_add (GTK_CONTAINER (widget), image);
        gtk_widget_set_halign (widget, GTK_ALIGN_CENTER);
        gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
        atk_object_set_name (gtk_widget_get_accessible (widget), _("Options…"));
        gtk_box_pack_start (GTK_BOX (box), widget, FALSE, TRUE, 0);
        g_object_set_data (G_OBJECT (row), "edit", widget);
        g_object_set_data (G_OBJECT (widget), "row", row);
        g_signal_connect (widget, "clicked",
                          G_CALLBACK (show_details_for_row), device);

        gtk_widget_show_all (row);

        g_object_set_data (G_OBJECT (row), "connection", connection);

        gtk_container_add (GTK_CONTAINER (device->list), row);
}