Blame src/connection-editor/page-dcb.c

Packit Service 639700
// SPDX-License-Identifier: GPL-2.0+
Packit fabffb
/* NetworkManager Connection editor -- Connection editor for NetworkManager
Packit fabffb
 *
Packit fabffb
 * Dan Williams <dcbw@redhat.com>
Packit fabffb
 *
Packit fabffb
 * Copyright 2013 - 2014 Red Hat, Inc.
Packit fabffb
 */
Packit fabffb
Packit fabffb
#include "nm-default.h"
Packit fabffb
Packit fabffb
#include <string.h>
Packit fabffb
#include <errno.h>
Packit fabffb
#include <stdlib.h>
Packit fabffb
Packit fabffb
#include "page-dcb.h"
Packit fabffb
Packit fabffb
G_DEFINE_TYPE (CEPageDcb, ce_page_dcb, CE_TYPE_PAGE)
Packit fabffb
Packit fabffb
#define CE_PAGE_DCB_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CE_TYPE_PAGE_DCB, CEPageDcbPrivate))
Packit fabffb
Packit fabffb
typedef struct {
Packit fabffb
	/* Copy of initial setting, if any; changes in the Options dialogs
Packit fabffb
	 * update this setting, which is then copied to the final setting when
Packit fabffb
	 * required.
Packit fabffb
	 */
Packit fabffb
	NMSettingDcb *options;
Packit fabffb
Packit fabffb
	GtkToggleButton *enabled;
Packit fabffb
	GtkBox *box;
Packit fabffb
Packit fabffb
	gboolean initial_have_dcb;
Packit fabffb
} CEPageDcbPrivate;
Packit fabffb
Packit fabffb
/***************************************************************************/
Packit fabffb
Packit fabffb
static char *
Packit fabffb
_strdup_printf_uint (const char *format, guint i)
Packit fabffb
{
Packit fabffb
#if NM_MORE_ASSERTS
Packit fabffb
	const char *f = format;
Packit fabffb
Packit fabffb
	g_assert (f);
Packit fabffb
	f = strchr (f, '%');
Packit fabffb
	g_assert (f);
Packit fabffb
	f++;
Packit fabffb
	g_assert (!strchr (f, '%'));
Packit fabffb
	g_assert (f[0] == 'u');
Packit fabffb
#endif
Packit fabffb
Packit fabffb
	NM_PRAGMA_WARNING_DISABLE("-Wformat-nonliteral")
Packit fabffb
	return g_strdup_printf (format, i);
Packit fabffb
	NM_PRAGMA_WARNING_REENABLE
Packit fabffb
}
Packit fabffb
Packit fabffb
static void
Packit fabffb
pfc_dialog_show (CEPageDcb *self)
Packit fabffb
{
Packit fabffb
	CEPageDcbPrivate *priv = CE_PAGE_DCB_GET_PRIVATE (self);
Packit fabffb
	CEPage *parent = CE_PAGE (self);
Packit fabffb
	GtkWidget *dialog, *toplevel;
Packit fabffb
	GtkToggleButton *check;
Packit fabffb
	gint result;
Packit fabffb
	guint i;
Packit fabffb
	gboolean active;
Packit fabffb
	char *tmp;
Packit fabffb
Packit fabffb
	dialog = GTK_WIDGET (gtk_builder_get_object (parent->builder, "pfc_dialog"));
Packit fabffb
	g_assert (dialog);
Packit fabffb
	toplevel = gtk_widget_get_toplevel (parent->page);
Packit fabffb
	if (gtk_widget_is_toplevel (toplevel))
Packit fabffb
	    gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (toplevel));
Packit fabffb
Packit fabffb
	/* Set the initial value */
Packit fabffb
	for (i = 0; i < 8; i++ ) {
Packit fabffb
		tmp = g_strdup_printf ("pfc_prio%u_checkbutton", i);
Packit fabffb
		check = GTK_TOGGLE_BUTTON (gtk_builder_get_object (parent->builder, tmp));
Packit fabffb
		g_free (tmp);
Packit fabffb
		g_assert (check);
Packit fabffb
Packit fabffb
		gtk_toggle_button_set_active (check, nm_setting_dcb_get_priority_flow_control (priv->options, i));
Packit fabffb
	}
Packit fabffb
Packit fabffb
	/* Run the dialog */
Packit fabffb
	result = gtk_dialog_run (GTK_DIALOG (dialog));
Packit fabffb
	if (result == GTK_RESPONSE_OK) {
Packit fabffb
		for (i = 0; i < 8; i++ ) {
Packit fabffb
			tmp = g_strdup_printf ("pfc_prio%u_checkbutton", i);
Packit fabffb
			check = GTK_TOGGLE_BUTTON (gtk_builder_get_object (parent->builder, tmp));
Packit fabffb
			g_free (tmp);
Packit fabffb
			g_assert (check);
Packit fabffb
Packit fabffb
			active = gtk_toggle_button_get_active (check);
Packit fabffb
			nm_setting_dcb_set_priority_flow_control (priv->options, i, active);
Packit fabffb
		}
Packit fabffb
	}
Packit fabffb
Packit fabffb
	gtk_widget_hide (dialog);
Packit fabffb
	ce_page_changed (CE_PAGE (self));
Packit fabffb
}
Packit fabffb
Packit fabffb
static gboolean
Packit fabffb
uint_entries_validate (GtkBuilder *builder, const char *fmt, gint max, gboolean sum)
Packit fabffb
{
Packit fabffb
	long int num;
Packit fabffb
	GtkEntry *entry;
Packit fabffb
	char *tmp;
Packit fabffb
	const char *text;
Packit fabffb
	guint i, total = 0;
Packit fabffb
	gboolean valid = TRUE;
Packit fabffb
	GdkRGBA bgcolor;
Packit fabffb
Packit fabffb
	gdk_rgba_parse (&bgcolor, "red3");
Packit fabffb
Packit fabffb
	for (i = 0; i < 8; i++) {
Packit fabffb
		tmp = _strdup_printf_uint (fmt, i);
Packit fabffb
		entry = GTK_ENTRY (gtk_builder_get_object (builder, tmp));
Packit fabffb
		g_free (tmp);
Packit fabffb
		g_assert (entry);
Packit fabffb
Packit fabffb
		text = gtk_entry_get_text (entry);
Packit fabffb
		if (text) {
Packit fabffb
			errno = 0;
Packit fabffb
			num = strtol (text, NULL, 10);
Packit fabffb
			if (errno || num < 0 || num > max) {
Packit fabffb
				/* FIXME: only sets highlight color? */
Packit fabffb
				utils_override_bg_color (GTK_WIDGET (entry), &bgcolor);
Packit fabffb
				valid = FALSE;
Packit fabffb
			} else
Packit fabffb
				utils_override_bg_color (GTK_WIDGET (entry), NULL);
Packit fabffb
Packit fabffb
			total += (guint) num;
Packit fabffb
			if (sum && total > 100)
Packit fabffb
				utils_override_bg_color (GTK_WIDGET (entry), &bgcolor);
Packit fabffb
		}
Packit fabffb
	}
Packit fabffb
	if (sum && total != 100) {
Packit fabffb
		utils_override_bg_color (GTK_WIDGET (entry), &bgcolor);
Packit fabffb
		valid = FALSE;
Packit fabffb
	}
Packit fabffb
Packit fabffb
	return valid;
Packit fabffb
}
Packit fabffb
Packit fabffb
static void
Packit fabffb
pg_dialog_valid_func (GtkBuilder *builder)
Packit fabffb
{
Packit fabffb
	GtkDialog *dialog;
Packit fabffb
	gboolean b1, b2, valid = FALSE;
Packit fabffb
Packit fabffb
	b1 = uint_entries_validate (builder, "pg_pgpct%u_entry", 100, TRUE);
Packit fabffb
	b2 = uint_entries_validate (builder, "pg_uppct%u_entry", 100, FALSE);
Packit fabffb
	valid = b1 && b2;
Packit fabffb
Packit fabffb
	dialog = GTK_DIALOG (gtk_builder_get_object (builder, "pg_dialog"));
Packit fabffb
	gtk_dialog_set_response_sensitive (dialog, GTK_RESPONSE_OK, valid);
Packit fabffb
}
Packit fabffb
Packit fabffb
Packit fabffb
static void
Packit fabffb
combos_handle (GtkBuilder *builder,
Packit fabffb
               NMSettingDcb *s_dcb,
Packit fabffb
               const char *fmt,
Packit fabffb
               guint max,
Packit fabffb
               gint last_idx,
Packit fabffb
               guint other_num,
Packit fabffb
               guint (*get_func) (NMSettingDcb *s_dcb, guint n),
Packit fabffb
               void (*set_func) (NMSettingDcb *s_dcb, guint n, guint val))
Packit fabffb
{
Packit fabffb
	char *tmp;
Packit fabffb
	GtkComboBox *combo;
Packit fabffb
	guint i, num;
Packit fabffb
Packit fabffb
	for (i = 0; i < 8; i++) {
Packit fabffb
		tmp = _strdup_printf_uint (fmt, i);
Packit fabffb
		combo = GTK_COMBO_BOX (gtk_builder_get_object (builder, tmp));
Packit fabffb
		g_free (tmp);
Packit fabffb
		g_assert (combo);
Packit fabffb
Packit fabffb
		if (get_func) {
Packit fabffb
			num = get_func (s_dcb, i);
Packit fabffb
			if (other_num && (num == other_num))
Packit fabffb
				gtk_combo_box_set_active (combo, last_idx);
Packit fabffb
			else if (num <= max)
Packit fabffb
				gtk_combo_box_set_active (combo, num);
Packit fabffb
			g_signal_connect_swapped (combo, "changed", (GCallback) pg_dialog_valid_func, builder);
Packit fabffb
		} else if (set_func) {
Packit fabffb
			gint idx = gtk_combo_box_get_active (combo);
Packit fabffb
Packit fabffb
			if (idx >= 0 && idx <= max)
Packit fabffb
				set_func (s_dcb, i, idx);
Packit fabffb
			else if (idx == last_idx)
Packit fabffb
				set_func (s_dcb, i, other_num);
Packit fabffb
		} else
Packit fabffb
			g_assert_not_reached ();
Packit fabffb
	}
Packit fabffb
}
Packit fabffb
Packit fabffb
static void
Packit fabffb
uint_filter_cb (GtkEditable *editable,
Packit fabffb
               gchar *text,
Packit fabffb
               gint length,
Packit fabffb
               gint *position,
Packit fabffb
               gpointer user_data)
Packit fabffb
{
Packit fabffb
	utils_filter_editable_on_insert_text (editable,
Packit fabffb
	                                      text, length, position, user_data,
Packit fabffb
	                                      utils_char_is_ascii_digit,
Packit fabffb
	                                      uint_filter_cb);
Packit fabffb
}
Packit fabffb
Packit fabffb
static void
Packit fabffb
uint_entries_handle (GtkBuilder *builder,
Packit fabffb
                     NMSettingDcb *s_dcb,
Packit fabffb
                     const char *fmt,
Packit fabffb
                     guint (*get_func) (NMSettingDcb *s_dcb, guint n),
Packit fabffb
                     void (*set_func) (NMSettingDcb *s_dcb, guint n, guint val))
Packit fabffb
{
Packit fabffb
	char *tmp;
Packit fabffb
	GtkEntry *entry;
Packit fabffb
	guint i;
Packit fabffb
	const char *text;
Packit fabffb
Packit fabffb
	for (i = 0; i < 8; i++) {
Packit fabffb
		tmp = _strdup_printf_uint (fmt, i);
Packit fabffb
		entry = GTK_ENTRY (gtk_builder_get_object (builder, tmp));
Packit fabffb
		g_free (tmp);
Packit fabffb
		g_assert (entry);
Packit fabffb
Packit fabffb
		if (get_func) {
Packit fabffb
			tmp = g_strdup_printf ("%u", get_func (s_dcb, i));
Packit fabffb
			gtk_entry_set_text (entry, tmp);
Packit fabffb
			g_free (tmp);
Packit fabffb
Packit fabffb
			g_signal_connect (entry, "insert-text", (GCallback) uint_filter_cb, NULL);
Packit fabffb
			g_signal_connect_swapped (entry, "changed", (GCallback) pg_dialog_valid_func, builder);
Packit fabffb
		} else if (set_func) {
Packit fabffb
			long int num;
Packit fabffb
Packit fabffb
			text = gtk_entry_get_text (entry);
Packit fabffb
			if (text) {
Packit fabffb
				errno = 0;
Packit fabffb
				num = strtol (text, NULL, 10);
Packit fabffb
				if (errno == 0 && num >= 0 && num <= 100)
Packit fabffb
					set_func (s_dcb, i, (guint) num);
Packit fabffb
			}
Packit fabffb
		} else
Packit fabffb
			g_assert_not_reached ();
Packit fabffb
	}
Packit fabffb
}
Packit fabffb
Packit fabffb
static void
Packit fabffb
bool_entries_handle (GtkBuilder *builder,
Packit fabffb
                     NMSettingDcb *s_dcb,
Packit fabffb
                     const char *fmt,
Packit fabffb
                     gboolean (*get_func) (NMSettingDcb *s_dcb, guint n),
Packit fabffb
                     void (*set_func) (NMSettingDcb *s_dcb, guint n, gboolean val))
Packit fabffb
{
Packit fabffb
	char *tmp;
Packit fabffb
	GtkToggleButton *toggle;
Packit fabffb
	guint i;
Packit fabffb
Packit fabffb
	for (i = 0; i < 8; i++) {
Packit fabffb
		tmp = _strdup_printf_uint (fmt, i);
Packit fabffb
		toggle = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, tmp));
Packit fabffb
		g_free (tmp);
Packit fabffb
		g_assert (toggle);
Packit fabffb
Packit fabffb
		if (get_func)
Packit fabffb
			gtk_toggle_button_set_active (toggle, get_func (s_dcb, i));
Packit fabffb
		else if (set_func)
Packit fabffb
			set_func (s_dcb, i, gtk_toggle_button_get_active (toggle));
Packit fabffb
		else
Packit fabffb
			g_assert_not_reached ();
Packit fabffb
	}
Packit fabffb
}
Packit fabffb
Packit fabffb
static void
Packit fabffb
pg_dialog_show (CEPageDcb *self)
Packit fabffb
{
Packit fabffb
	CEPageDcbPrivate *priv = CE_PAGE_DCB_GET_PRIVATE (self);
Packit fabffb
	CEPage *parent = CE_PAGE (self);
Packit fabffb
	GtkWidget *dialog, *toplevel;
Packit fabffb
	gint result;
Packit fabffb
Packit fabffb
	dialog = GTK_WIDGET (gtk_builder_get_object (parent->builder, "pg_dialog"));
Packit fabffb
	g_assert (dialog);
Packit fabffb
	toplevel = gtk_widget_get_toplevel (parent->page);
Packit fabffb
	if (gtk_widget_is_toplevel (toplevel))
Packit fabffb
	    gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (toplevel));
Packit fabffb
Packit fabffb
	combos_handle (parent->builder,
Packit fabffb
	               priv->options,
Packit fabffb
	               "pg_pgid%u_combo",
Packit fabffb
	               7,
Packit fabffb
	               8,
Packit fabffb
	               15,
Packit fabffb
	               nm_setting_dcb_get_priority_group_id,
Packit fabffb
	               NULL);
Packit fabffb
Packit fabffb
	uint_entries_handle (parent->builder,
Packit fabffb
	                     priv->options,
Packit fabffb
	                     "pg_pgpct%u_entry",
Packit fabffb
	                     nm_setting_dcb_get_priority_group_bandwidth,
Packit fabffb
	                     NULL);
Packit fabffb
Packit fabffb
	uint_entries_handle (parent->builder,
Packit fabffb
	                     priv->options,
Packit fabffb
	                     "pg_uppct%u_entry",
Packit fabffb
	                     nm_setting_dcb_get_priority_bandwidth,
Packit fabffb
	                     NULL);
Packit fabffb
Packit fabffb
	bool_entries_handle (parent->builder,
Packit fabffb
	                     priv->options,
Packit fabffb
	                     "pg_strict%u_checkbutton",
Packit fabffb
	                     nm_setting_dcb_get_priority_strict_bandwidth,
Packit fabffb
	                     NULL);
Packit fabffb
Packit fabffb
	combos_handle (parent->builder,
Packit fabffb
	               priv->options,
Packit fabffb
	               "pg_up2tc%u_combo",
Packit fabffb
	               7,
Packit fabffb
	               0,
Packit fabffb
	               0,
Packit fabffb
	               nm_setting_dcb_get_priority_traffic_class,
Packit fabffb
	               NULL);
Packit fabffb
Packit fabffb
	pg_dialog_valid_func (parent->builder);
Packit fabffb
Packit fabffb
	/* Run the dialog */
Packit fabffb
	result = gtk_dialog_run (GTK_DIALOG (dialog));
Packit fabffb
	if (result == GTK_RESPONSE_OK) {
Packit fabffb
		combos_handle (parent->builder,
Packit fabffb
		               priv->options,
Packit fabffb
		               "pg_pgid%u_combo",
Packit fabffb
		               7,
Packit fabffb
		               8,
Packit fabffb
		               15,
Packit fabffb
		               NULL,
Packit fabffb
		               nm_setting_dcb_set_priority_group_id);
Packit fabffb
Packit fabffb
		uint_entries_handle (parent->builder,
Packit fabffb
		                     priv->options,
Packit fabffb
		                     "pg_pgpct%u_entry",
Packit fabffb
		                     NULL,
Packit fabffb
		                     nm_setting_dcb_set_priority_group_bandwidth);
Packit fabffb
Packit fabffb
		uint_entries_handle (parent->builder,
Packit fabffb
		                     priv->options,
Packit fabffb
		                     "pg_uppct%u_entry",
Packit fabffb
		                     NULL,
Packit fabffb
		                     nm_setting_dcb_set_priority_bandwidth);
Packit fabffb
Packit fabffb
		bool_entries_handle (parent->builder,
Packit fabffb
		                     priv->options,
Packit fabffb
		                     "pg_strict%u_checkbutton",
Packit fabffb
		                     NULL,
Packit fabffb
		                     nm_setting_dcb_set_priority_strict_bandwidth);
Packit fabffb
Packit fabffb
		combos_handle (parent->builder,
Packit fabffb
		               priv->options,
Packit fabffb
		               "pg_up2tc%u_combo",
Packit fabffb
		               7,
Packit fabffb
		               0,
Packit fabffb
		               0,
Packit fabffb
		               NULL,
Packit fabffb
		               nm_setting_dcb_set_priority_traffic_class);
Packit fabffb
	}
Packit fabffb
Packit fabffb
	gtk_widget_hide (dialog);
Packit fabffb
	ce_page_changed (CE_PAGE (self));
Packit fabffb
}
Packit fabffb
Packit fabffb
static void
Packit fabffb
pg_enabled (CEPageDcb *self, gboolean enabled)
Packit fabffb
{
Packit fabffb
	CEPageDcbPrivate *priv = CE_PAGE_DCB_GET_PRIVATE (self);
Packit fabffb
	guint i;
Packit fabffb
	gboolean set_default = TRUE;
Packit fabffb
Packit fabffb
	if (!enabled)
Packit fabffb
		return;
Packit fabffb
Packit fabffb
	/* If the connection did not previously have DCB enabled, and the user
Packit fabffb
	 * just enabled DCB, set a valid priority group bandwidth so that the
Packit fabffb
	 * user doesn't have to go mess with the PG options dialog.
Packit fabffb
	 */
Packit fabffb
	for (i = 0; i < 8; i++) {
Packit fabffb
		if (nm_setting_dcb_get_priority_group_bandwidth (priv->options, i)) {
Packit fabffb
			set_default = FALSE;
Packit fabffb
			break;
Packit fabffb
		}
Packit fabffb
	}
Packit fabffb
Packit fabffb
	if (set_default)
Packit fabffb
		nm_setting_dcb_set_priority_group_bandwidth (priv->options, 0, 100);
Packit fabffb
Packit fabffb
	ce_page_changed (CE_PAGE (self));
Packit fabffb
}
Packit fabffb
Packit fabffb
/***************************************************************************/
Packit fabffb
Packit fabffb
typedef void (*OptionsFunc) (CEPageDcb *self);
Packit fabffb
typedef void (*EnabledFunc) (CEPageDcb *self, gboolean enabled);
Packit fabffb
Packit fabffb
typedef struct {
Packit fabffb
	const char *prefix;
Packit fabffb
	const char *flags_prop;
Packit fabffb
	const char *priority_prop;
Packit fabffb
	const OptionsFunc options_func;
Packit fabffb
	const EnabledFunc enabled_func;
Packit fabffb
} Feature;
Packit fabffb
Packit fabffb
static const Feature features[] = {
Packit fabffb
	{ "fcoe",  NM_SETTING_DCB_APP_FCOE_FLAGS,
Packit fabffb
	           NM_SETTING_DCB_APP_FCOE_PRIORITY },
Packit fabffb
Packit fabffb
	{ "iscsi", NM_SETTING_DCB_APP_ISCSI_FLAGS,
Packit fabffb
	           NM_SETTING_DCB_APP_ISCSI_PRIORITY },
Packit fabffb
Packit fabffb
	{ "fip",   NM_SETTING_DCB_APP_FIP_FLAGS,
Packit fabffb
	           NM_SETTING_DCB_APP_FIP_PRIORITY },
Packit fabffb
Packit fabffb
	{ "pfc",   NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS,
Packit fabffb
	           NULL,
Packit fabffb
	           pfc_dialog_show },
Packit fabffb
Packit fabffb
	{ "pg",    NM_SETTING_DCB_PRIORITY_GROUP_FLAGS,
Packit fabffb
	           NULL,
Packit fabffb
	           pg_dialog_show,
Packit fabffb
	           pg_enabled },
Packit fabffb
};
Packit fabffb
Packit fabffb
typedef struct {
Packit fabffb
	CEPage *page;
Packit fabffb
	const Feature *f;
Packit fabffb
} EnableInfo;
Packit fabffb
Packit fabffb
static GtkWidget *
Packit fabffb
get_widget (GtkBuilder *builder, const char *prefix, const char *suffix)
Packit fabffb
{
Packit fabffb
	GtkWidget *widget;
Packit fabffb
	char *s;
Packit fabffb
Packit fabffb
	s = g_strdup_printf ("%s%s", prefix, suffix);
Packit fabffb
	widget = GTK_WIDGET (gtk_builder_get_object (builder, s));
Packit fabffb
	g_assert (widget);
Packit fabffb
	g_free (s);
Packit fabffb
	return widget;
Packit fabffb
}
Packit fabffb
Packit fabffb
static void
Packit fabffb
enable_toggled_cb (GtkToggleButton *button, EnableInfo *info)
Packit fabffb
{
Packit fabffb
	gboolean enabled = gtk_toggle_button_get_active (button);
Packit fabffb
	GtkWidget *widget;
Packit fabffb
Packit fabffb
	/* Set other feature widgets sensitive or not depending on enabled */
Packit fabffb
Packit fabffb
	widget = get_widget (info->page->builder, info->f->prefix, "_advertise_checkbutton");
Packit fabffb
	gtk_widget_set_sensitive (widget, enabled);
Packit fabffb
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
Packit fabffb
Packit fabffb
	widget = get_widget (info->page->builder, info->f->prefix, "_willing_checkbutton");
Packit fabffb
	gtk_widget_set_sensitive (widget, enabled);
Packit fabffb
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
Packit fabffb
Packit fabffb
	if (info->f->priority_prop) {
Packit fabffb
		widget = get_widget (info->page->builder, info->f->prefix, "_priority_combo");
Packit fabffb
		gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
Packit fabffb
		gtk_widget_set_sensitive (widget, enabled);
Packit fabffb
	}
Packit fabffb
Packit fabffb
	if (info->f->options_func) {
Packit fabffb
		widget = get_widget (info->page->builder, info->f->prefix, "_options_button");
Packit fabffb
		gtk_widget_set_sensitive (widget, enabled);
Packit fabffb
	}
Packit fabffb
Packit fabffb
	/* FCoE mode combo */
Packit fabffb
	if (!strcmp (info->f->prefix, "fcoe")) {
Packit fabffb
		widget = get_widget (info->page->builder, info->f->prefix, "_mode_combo");
Packit fabffb
		gtk_widget_set_sensitive (widget, enabled);
Packit fabffb
	}
Packit fabffb
Packit fabffb
	if (info->f->enabled_func)
Packit fabffb
		info->f->enabled_func (CE_PAGE_DCB (info->page), gtk_toggle_button_get_active (button));
Packit fabffb
Packit fabffb
	ce_page_changed (info->page);
Packit fabffb
}
Packit fabffb
Packit fabffb
static void
Packit fabffb
free_enable_info (gpointer data, GClosure *closure)
Packit fabffb
{
Packit fabffb
	g_free (data);
Packit fabffb
}
Packit fabffb
Packit fabffb
static void
Packit fabffb
feature_setup (CEPageDcb *self, NMSettingDcb *s_dcb, const Feature *f)
Packit fabffb
{
Packit fabffb
	CEPage *parent = CE_PAGE (self);
Packit fabffb
	GtkWidget *widget;
Packit fabffb
	NMSettingDcbFlags flags = NM_SETTING_DCB_FLAG_NONE;
Packit fabffb
	gboolean enabled;
Packit fabffb
	EnableInfo *info;
Packit fabffb
Packit fabffb
	if (s_dcb)
Packit fabffb
		g_object_get (G_OBJECT (s_dcb), f->flags_prop, (guint32 *) &flags, NULL);
Packit fabffb
	enabled = flags & NM_SETTING_DCB_FLAG_ENABLE;
Packit fabffb
Packit fabffb
	/* Enable */
Packit fabffb
	widget = get_widget (parent->builder, f->prefix, "_enable_checkbutton");
Packit fabffb
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), enabled);
Packit fabffb
Packit fabffb
	info = g_malloc0 (sizeof (EnableInfo));
Packit fabffb
	info->f = f;
Packit fabffb
	info->page = parent;
Packit fabffb
	g_signal_connect_data (widget, "toggled", G_CALLBACK (enable_toggled_cb), info, free_enable_info, 0);
Packit fabffb
Packit fabffb
	/* Advertise */
Packit fabffb
	widget = get_widget (parent->builder, f->prefix, "_advertise_checkbutton");
Packit fabffb
	gtk_widget_set_sensitive (widget, enabled);
Packit fabffb
	if (enabled)
Packit fabffb
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), flags & NM_SETTING_DCB_FLAG_ADVERTISE);
Packit fabffb
	g_signal_connect_swapped (widget, "toggled", G_CALLBACK (ce_page_changed), self);
Packit fabffb
Packit fabffb
	/* Willing */
Packit fabffb
	widget = get_widget (parent->builder, f->prefix, "_willing_checkbutton");
Packit fabffb
	gtk_widget_set_sensitive (widget, enabled);
Packit fabffb
	if (enabled)
Packit fabffb
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), flags & NM_SETTING_DCB_FLAG_WILLING);
Packit fabffb
	g_signal_connect_swapped (widget, "toggled", G_CALLBACK (ce_page_changed), self);
Packit fabffb
Packit fabffb
	if (f->priority_prop) {
Packit fabffb
		gint priority = -1;
Packit fabffb
Packit fabffb
		if (s_dcb)
Packit fabffb
			g_object_get (G_OBJECT (s_dcb), f->priority_prop, &priority, NULL);
Packit fabffb
		priority = CLAMP (priority, -1, 7);
Packit fabffb
Packit fabffb
		widget = get_widget (parent->builder, f->prefix, "_priority_combo");
Packit fabffb
		gtk_widget_set_sensitive (widget, enabled);
Packit fabffb
		gtk_combo_box_set_active (GTK_COMBO_BOX (widget), priority + 1);
Packit fabffb
		g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), self);
Packit fabffb
	}
Packit fabffb
Packit fabffb
	if (f->options_func) {
Packit fabffb
		widget = get_widget (parent->builder, f->prefix, "_options_button");
Packit fabffb
		gtk_widget_set_sensitive (widget, enabled);
Packit fabffb
		g_signal_connect_swapped (widget, "clicked", G_CALLBACK (f->options_func), self);
Packit fabffb
	}
Packit fabffb
Packit fabffb
	/* Set up the FCoE mode combo */
Packit fabffb
	if (!strcmp (f->prefix, "fcoe")) {
Packit fabffb
		const char *mode = s_dcb ? nm_setting_dcb_get_app_fcoe_mode (s_dcb) : NULL;
Packit fabffb
		guint idx = 0;
Packit fabffb
Packit fabffb
		widget = get_widget (info->page->builder, info->f->prefix, "_mode_combo");
Packit fabffb
		if (g_strcmp0 (mode, NM_SETTING_DCB_FCOE_MODE_VN2VN) == 0)
Packit fabffb
			idx = 1;
Packit fabffb
		gtk_combo_box_set_active (GTK_COMBO_BOX (widget), idx);
Packit fabffb
		gtk_widget_set_sensitive (widget, enabled);
Packit fabffb
		g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), self);
Packit fabffb
	}
Packit fabffb
}
Packit fabffb
Packit fabffb
static void
Packit fabffb
enable_toggled (GtkToggleButton *button, gpointer user_data)
Packit fabffb
{
Packit fabffb
	CEPageDcbPrivate *priv = CE_PAGE_DCB_GET_PRIVATE (user_data);
Packit fabffb
Packit fabffb
	gtk_widget_set_sensitive (GTK_WIDGET (priv->box), gtk_toggle_button_get_active (button));
Packit fabffb
	ce_page_changed (CE_PAGE (user_data));
Packit fabffb
}
Packit fabffb
Packit fabffb
static void
Packit fabffb
finish_setup (CEPageDcb *self, gpointer user_data)
Packit fabffb
{
Packit fabffb
	CEPage *parent = CE_PAGE (self);
Packit fabffb
	CEPageDcbPrivate *priv = CE_PAGE_DCB_GET_PRIVATE (self);
Packit fabffb
	NMSettingDcb *s_dcb = nm_connection_get_setting_dcb (parent->connection);
Packit fabffb
	guint i;
Packit fabffb
Packit fabffb
	gtk_toggle_button_set_active (priv->enabled, priv->initial_have_dcb);
Packit fabffb
	g_signal_connect (priv->enabled, "toggled", G_CALLBACK (enable_toggled), self);
Packit fabffb
	gtk_widget_set_sensitive (GTK_WIDGET (priv->box), priv->initial_have_dcb);
Packit fabffb
Packit fabffb
	for (i = 0; i < G_N_ELEMENTS (features); i++)
Packit fabffb
		feature_setup (self, s_dcb, &features[i]);
Packit fabffb
}
Packit fabffb
Packit fabffb
CEPage *
Packit fabffb
ce_page_dcb_new (NMConnectionEditor *editor,
Packit fabffb
                 NMConnection *connection,
Packit fabffb
                 GtkWindow *parent_window,
Packit fabffb
                 NMClient *client,
Packit fabffb
                 const char **out_secrets_setting_name,
Packit fabffb
                 GError **error)
Packit fabffb
{
Packit fabffb
	CEPageDcb *self;
Packit fabffb
	CEPageDcbPrivate *priv;
Packit fabffb
	CEPage *parent;
Packit fabffb
	NMSettingDcb *s_dcb;
Packit fabffb
Packit fabffb
	self = CE_PAGE_DCB (ce_page_new (CE_TYPE_PAGE_DCB,
Packit fabffb
	                                 editor,
Packit fabffb
	                                 connection,
Packit fabffb
	                                 parent_window,
Packit fabffb
	                                 client,
Packit fabffb
	                                 "/org/gnome/nm_connection_editor/ce-page-dcb.ui",
Packit fabffb
	                                 "DcbPage",
Packit fabffb
	                                 _("DCB")));
Packit fabffb
	if (!self) {
Packit fabffb
		g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("Could not load DCB user interface."));
Packit fabffb
		return NULL;
Packit fabffb
	}
Packit fabffb
Packit fabffb
	priv = CE_PAGE_DCB_GET_PRIVATE (self);
Packit fabffb
	parent = CE_PAGE (self);
Packit fabffb
Packit fabffb
	priv->enabled = GTK_TOGGLE_BUTTON (gtk_builder_get_object (parent->builder, "dcb_enabled_checkbutton"));
Packit fabffb
	priv->box = GTK_BOX (gtk_builder_get_object (parent->builder, "dcb_box"));
Packit fabffb
Packit fabffb
	s_dcb = nm_connection_get_setting_dcb (connection);
Packit fabffb
	if (s_dcb) {
Packit fabffb
		priv->initial_have_dcb = TRUE;
Packit fabffb
		priv->options = (NMSettingDcb *) nm_setting_duplicate (NM_SETTING (s_dcb));
Packit fabffb
	} else
Packit fabffb
		priv->options = (NMSettingDcb *) nm_setting_dcb_new ();
Packit fabffb
Packit fabffb
	g_signal_connect (self, CE_PAGE_INITIALIZED, G_CALLBACK (finish_setup), NULL);
Packit fabffb
Packit fabffb
	return CE_PAGE (self);
Packit fabffb
}
Packit fabffb
Packit fabffb
static void
Packit fabffb
ui_to_setting (CEPageDcb *self, NMSettingDcb *s_dcb)
Packit fabffb
{
Packit fabffb
	CEPage *parent = CE_PAGE (self);
Packit fabffb
	CEPageDcbPrivate *priv = CE_PAGE_DCB_GET_PRIVATE (self);
Packit fabffb
	NMSettingDcbFlags flags = NM_SETTING_DCB_FLAG_NONE;
Packit fabffb
	GtkWidget *widget;
Packit fabffb
	gboolean enabled, b;
Packit fabffb
	const char *tmp;
Packit fabffb
	guint i, num;
Packit fabffb
Packit fabffb
	enabled = gtk_toggle_button_get_active (priv->enabled);
Packit fabffb
	for (i = 0; i < G_N_ELEMENTS (features); i++) {
Packit fabffb
		const Feature *f = &features[i];
Packit fabffb
Packit fabffb
		flags = NM_SETTING_DCB_FLAG_NONE;
Packit fabffb
Packit fabffb
		/* Enable */
Packit fabffb
		widget = get_widget (parent->builder, f->prefix, "_enable_checkbutton");
Packit fabffb
		if (enabled && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
Packit fabffb
			flags |= NM_SETTING_DCB_FLAG_ENABLE;
Packit fabffb
Packit fabffb
		/* Advertise */
Packit fabffb
		widget = get_widget (parent->builder, f->prefix, "_advertise_checkbutton");
Packit fabffb
		if (enabled && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
Packit fabffb
			flags |= NM_SETTING_DCB_FLAG_ADVERTISE;
Packit fabffb
Packit fabffb
		/* Willing */
Packit fabffb
		widget = get_widget (parent->builder, f->prefix, "_willing_checkbutton");
Packit fabffb
		if (enabled && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
Packit fabffb
			flags |= NM_SETTING_DCB_FLAG_WILLING;
Packit fabffb
Packit fabffb
		g_object_set (G_OBJECT (s_dcb), f->flags_prop, flags, NULL);
Packit fabffb
Packit fabffb
		if (f->priority_prop) {
Packit fabffb
			gint idx = 0;
Packit fabffb
Packit fabffb
			widget = get_widget (parent->builder, f->prefix, "_priority_combo");
Packit fabffb
			if (enabled)
Packit fabffb
				idx = gtk_combo_box_get_active (GTK_COMBO_BOX (widget));
Packit fabffb
			g_object_set (G_OBJECT (s_dcb), f->priority_prop, (gint) (idx - 1), NULL);
Packit fabffb
		}
Packit fabffb
	}
Packit fabffb
Packit fabffb
	/* FCoE Mode */
Packit fabffb
	flags = nm_setting_dcb_get_app_fcoe_flags (s_dcb);
Packit fabffb
	tmp = NM_SETTING_DCB_FCOE_MODE_FABRIC;
Packit fabffb
	if (flags & NM_SETTING_DCB_FLAG_ENABLE) {
Packit fabffb
		widget = get_widget (parent->builder, "fcoe", "_mode_combo");
Packit fabffb
		num = gtk_combo_box_get_active (GTK_COMBO_BOX (widget));
Packit fabffb
		if (num == 0)
Packit fabffb
			tmp = NM_SETTING_DCB_FCOE_MODE_FABRIC;
Packit fabffb
		else if (num == 1)
Packit fabffb
			tmp = NM_SETTING_DCB_FCOE_MODE_VN2VN;
Packit fabffb
		else
Packit fabffb
			g_assert_not_reached ();
Packit fabffb
	}
Packit fabffb
	g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_APP_FCOE_MODE, tmp, NULL);
Packit fabffb
Packit fabffb
	/* Priority Flow Control */
Packit fabffb
	flags = nm_setting_dcb_get_priority_flow_control_flags (s_dcb);
Packit fabffb
	for (i = 0; i < 8; i++) {
Packit fabffb
		b = FALSE;
Packit fabffb
		if (flags & NM_SETTING_DCB_FLAG_ENABLE)
Packit fabffb
			b = nm_setting_dcb_get_priority_flow_control (priv->options, i);
Packit fabffb
		nm_setting_dcb_set_priority_flow_control (s_dcb, i, b);
Packit fabffb
	}
Packit fabffb
Packit fabffb
	/* Priority Groups */
Packit fabffb
	flags = nm_setting_dcb_get_priority_group_flags (s_dcb);
Packit fabffb
	for (i = 0; i < 8; i++) {
Packit fabffb
		/* Group ID */
Packit fabffb
		num = 0;
Packit fabffb
		if (flags & NM_SETTING_DCB_FLAG_ENABLE)
Packit fabffb
			num = nm_setting_dcb_get_priority_group_id (priv->options, i);
Packit fabffb
		nm_setting_dcb_set_priority_group_id (s_dcb, i, num);
Packit fabffb
Packit fabffb
		num = 0;
Packit fabffb
		if (flags & NM_SETTING_DCB_FLAG_ENABLE)
Packit fabffb
			num = nm_setting_dcb_get_priority_group_bandwidth (priv->options, i);
Packit fabffb
		nm_setting_dcb_set_priority_group_bandwidth (s_dcb, i, num);
Packit fabffb
Packit fabffb
		num = 0;
Packit fabffb
		if (flags & NM_SETTING_DCB_FLAG_ENABLE)
Packit fabffb
			num = nm_setting_dcb_get_priority_bandwidth (priv->options, i);
Packit fabffb
		nm_setting_dcb_set_priority_bandwidth (s_dcb, i, num);
Packit fabffb
Packit fabffb
		b = 0;
Packit fabffb
		if (flags & NM_SETTING_DCB_FLAG_ENABLE)
Packit fabffb
			b = nm_setting_dcb_get_priority_strict_bandwidth (priv->options, i);
Packit fabffb
		nm_setting_dcb_set_priority_strict_bandwidth (s_dcb, i, b);
Packit fabffb
Packit fabffb
		num = 0;
Packit fabffb
		if (flags & NM_SETTING_DCB_FLAG_ENABLE)
Packit fabffb
			num = nm_setting_dcb_get_priority_traffic_class (priv->options, i);
Packit fabffb
		nm_setting_dcb_set_priority_traffic_class (s_dcb, i, num);
Packit fabffb
	}
Packit fabffb
Packit fabffb
}
Packit fabffb
Packit fabffb
static gboolean
Packit fabffb
ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error)
Packit fabffb
{
Packit fabffb
	CEPageDcb *self = CE_PAGE_DCB (page);
Packit fabffb
	CEPageDcbPrivate *priv = CE_PAGE_DCB_GET_PRIVATE (self);
Packit fabffb
	NMSettingDcb *s_dcb;
Packit fabffb
Packit fabffb
	if (!gtk_toggle_button_get_active (priv->enabled)) {
Packit fabffb
		nm_connection_remove_setting (connection, NM_TYPE_SETTING_DCB);
Packit fabffb
		return TRUE;
Packit fabffb
	}
Packit fabffb
Packit fabffb
	s_dcb = nm_connection_get_setting_dcb (connection);
Packit fabffb
	if (!s_dcb) {
Packit fabffb
		s_dcb = (NMSettingDcb *) nm_setting_dcb_new ();
Packit fabffb
		nm_connection_add_setting (connection, NM_SETTING (s_dcb));
Packit fabffb
	}
Packit fabffb
	ui_to_setting (self, s_dcb);
Packit fabffb
Packit fabffb
	return nm_setting_verify (NM_SETTING (s_dcb), NULL, error);
Packit fabffb
}
Packit fabffb
Packit fabffb
static void
Packit fabffb
ce_page_dcb_init (CEPageDcb *self)
Packit fabffb
{
Packit fabffb
}
Packit fabffb
Packit fabffb
static void
Packit fabffb
dispose (GObject *object)
Packit fabffb
{
Packit fabffb
	CEPageDcbPrivate *priv = CE_PAGE_DCB_GET_PRIVATE (object);
Packit fabffb
Packit fabffb
	g_clear_object (&priv->options);
Packit fabffb
Packit fabffb
	G_OBJECT_CLASS (ce_page_dcb_parent_class)->dispose (object);
Packit fabffb
}
Packit fabffb
Packit fabffb
static void
Packit fabffb
ce_page_dcb_class_init (CEPageDcbClass *security_class)
Packit fabffb
{
Packit fabffb
	GObjectClass *object_class = G_OBJECT_CLASS (security_class);
Packit fabffb
	CEPageClass *parent_class = CE_PAGE_CLASS (security_class);
Packit fabffb
Packit fabffb
	g_type_class_add_private (object_class, sizeof (CEPageDcbPrivate));
Packit fabffb
Packit fabffb
	/* virtual methods */
Packit fabffb
	object_class->dispose = dispose;
Packit fabffb
Packit fabffb
	parent_class->ce_page_validate_v = ce_page_validate_v;
Packit fabffb
}