[network-manager-applet/dcbw/dcb: 4/4] editor: add DCB page
- From: Dan Williams <dcbw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet/dcbw/dcb: 4/4] editor: add DCB page
- Date: Fri, 11 Oct 2013 17:16:30 +0000 (UTC)
commit 6c967f5d654409a5b0888578b2da26df739da578
Author: Dan Williams <dcbw redhat com>
Date: Wed Oct 9 10:35:44 2013 -0500
editor: add DCB page
src/connection-editor/Makefile.am | 5 +-
src/connection-editor/ce-page-dcb.ui | 189 ++++++++++
src/connection-editor/nm-connection-editor.c | 3 +
src/connection-editor/page-dcb.c | 515 ++++++++++++++++++++++++++
src/connection-editor/page-dcb.h | 59 +++
5 files changed, 770 insertions(+), 1 deletions(-)
---
diff --git a/src/connection-editor/Makefile.am b/src/connection-editor/Makefile.am
index 09d1719..bdee98c 100644
--- a/src/connection-editor/Makefile.am
+++ b/src/connection-editor/Makefile.am
@@ -65,6 +65,8 @@ nm_connection_editor_SOURCES = \
page-bridge-port.c \
page-vlan.h \
page-vlan.c \
+ page-dcb.c \
+ page-dcb.h \
vpn-helpers.h \
vpn-helpers.c \
ip4-routes-dialog.h \
@@ -113,7 +115,8 @@ ui_DATA = \
ce-page-mobile.ui \
ce-page-ppp.ui \
ce-ppp-auth-methods.ui \
- ce-page-vlan.ui
+ ce-page-vlan.ui \
+ ce-page-dcb.ui
BUILT_SOURCES = nm-connection-editor-service-glue.h
diff --git a/src/connection-editor/ce-page-dcb.ui b/src/connection-editor/ce-page-dcb.ui
new file mode 100644
index 0000000..0888a1c
--- /dev/null
+++ b/src/connection-editor/ce-page-dcb.ui
@@ -0,0 +1,189 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.0 -->
+ <object class="GtkListStore" id="app_liststore">
+ <columns>
+ <!-- column-name Application -->
+ <column type="gchararray"/>
+ <!-- column-name Enable -->
+ <column type="gboolean"/>
+ <!-- column-name Advertise -->
+ <column type="gboolean"/>
+ <!-- column-name Willing -->
+ <column type="gboolean"/>
+ <!-- column-name Priority -->
+ <column type="gint"/>
+ <!-- column-name Mode -->
+ <column type="gint"/>
+ <!-- column-name ModeVisible -->
+ <column type="gboolean"/>
+ </columns>
+ </object>
+ <object class="GtkListStore" id="mode_liststore">
+ <columns>
+ <!-- column-name Name -->
+ <column type="gchararray"/>
+ <!-- column-name Value -->
+ <column type="gint"/>
+ </columns>
+ </object>
+ <object class="GtkAdjustment" id="prio_adjustment">
+ <property name="lower">-1</property>
+ <property name="upper">7</property>
+ <property name="value">-1</property>
+ <property name="step_increment">1</property>
+ <property name="page_increment">1</property>
+ </object>
+ <object class="GtkTable" id="DcbPage">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="border_width">12</property>
+ <property name="n_rows">2</property>
+ <property name="n_columns">2</property>
+ <property name="column_spacing">12</property>
+ <property name="row_spacing">6</property>
+ <child>
+ <object class="GtkCheckButton" id="dcb_enabled_checkbutton">
+ <property name="label" translatable="yes">Use Data Center Bridging (DCB) for this
connection</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="xalign">0</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="right_attach">2</property>
+ <property name="y_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkAlignment" id="alignment1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="left_padding">6</property>
+ <child>
+ <object class="GtkBox" id="dcb_box">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkTreeView" id="dcb_app_treeview">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="model">app_liststore</property>
+ <property name="enable_search">False</property>
+ <property name="show_expanders">False</property>
+ <property name="enable_grid_lines">horizontal</property>
+ <child>
+ <object class="GtkTreeViewColumn" id="dcb_app_column">
+ <property name="sizing">autosize</property>
+ <property name="title" translatable="yes">Application</property>
+ <child>
+ <object class="GtkCellRendererText" id="dcb_app_cell"/>
+ <attributes>
+ <attribute name="text">0</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkTreeViewColumn" id="dcb_enable_column">
+ <property name="sizing">autosize</property>
+ <property name="title" translatable="yes">Enable</property>
+ <child>
+ <object class="GtkCellRendererToggle" id="dcb_enable_cell"/>
+ <attributes>
+ <attribute name="active">1</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkTreeViewColumn" id="dcb_advertise_column">
+ <property name="sizing">autosize</property>
+ <property name="title" translatable="yes">Advertise</property>
+ <child>
+ <object class="GtkCellRendererToggle" id="dcb_advertise_cell"/>
+ <attributes>
+ <attribute name="sensitive">1</attribute>
+ <attribute name="active">2</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkTreeViewColumn" id="dcb_willing_column">
+ <property name="sizing">autosize</property>
+ <property name="title" translatable="yes">Willing</property>
+ <child>
+ <object class="GtkCellRendererToggle" id="dcb_willing_cell"/>
+ <attributes>
+ <attribute name="sensitive">1</attribute>
+ <attribute name="active">3</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkTreeViewColumn" id="dcb_priority_column">
+ <property name="sizing">autosize</property>
+ <property name="title" translatable="yes">Priority</property>
+ <child>
+ <object class="GtkCellRendererSpin" id="dcb_priority_cell">
+ <property name="editable">True</property>
+ <property name="adjustment">prio_adjustment</property>
+ <property name="climb_rate">1</property>
+ <property name="placeholder_text">default</property>
+ </object>
+ <attributes>
+ <attribute name="sensitive">1</attribute>
+ <attribute name="text">4</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkTreeViewColumn" id="dcb_mode_column">
+ <property name="sizing">autosize</property>
+ <property name="title" translatable="yes">Mode</property>
+ <child>
+ <object class="GtkCellRendererCombo" id="dcb_mode_cell">
+ <property name="editable">True</property>
+ <property name="model">mode_liststore</property>
+ <property name="text_column">0</property>
+ </object>
+ <attributes>
+ <attribute name="sensitive">1</attribute>
+ <attribute name="visible">6</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="right_attach">2</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ </packing>
+ </child>
+ </object>
+</interface>
diff --git a/src/connection-editor/nm-connection-editor.c b/src/connection-editor/nm-connection-editor.c
index 2752b00..8fb1e4f 100644
--- a/src/connection-editor/nm-connection-editor.c
+++ b/src/connection-editor/nm-connection-editor.c
@@ -77,6 +77,7 @@
#include "page-bridge.h"
#include "page-bridge-port.h"
#include "page-vlan.h"
+#include "page-dcb.h"
#include "ce-polkit-button.h"
#include "vpn-helpers.h"
#include "eap-method.h"
@@ -791,6 +792,8 @@ nm_connection_editor_set_connection (NMConnectionEditor *editor,
goto out;
if (!add_page (editor, ce_page_8021x_security_new, editor->connection, error))
goto out;
+ if (!add_page (editor, ce_page_dcb_new, editor->connection, error))
+ goto out;
} else if (!strcmp (connection_type, NM_SETTING_WIRELESS_SETTING_NAME)) {
if (!add_page (editor, ce_page_wifi_new, editor->connection, error))
goto out;
diff --git a/src/connection-editor/page-dcb.c b/src/connection-editor/page-dcb.c
new file mode 100644
index 0000000..ea668c5
--- /dev/null
+++ b/src/connection-editor/page-dcb.c
@@ -0,0 +1,515 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager Connection editor -- Connection editor for NetworkManager
+ *
+ * Dan Williams <dcbw redhat com>
+ *
+ * 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.
+ *
+ * (C) Copyright 2013 Red Hat, Inc.
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+
+#include <NetworkManager.h>
+#include <nm-setting-connection.h>
+#include <nm-setting-dcb.h>
+#include <nm-utils.h>
+
+#include "page-dcb.h"
+
+G_DEFINE_TYPE (CEPageDcb, ce_page_dcb, CE_TYPE_PAGE)
+
+#define CE_PAGE_DCB_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CE_TYPE_PAGE_DCB, CEPageDcbPrivate))
+
+#define COL_APPLICATION 0
+#define COL_ENABLE 1
+#define COL_ADVERTISE 2
+#define COL_WILLING 3
+#define COL_PRIORITY 4
+#define COL_MODE 5
+#define COL_MODE_VISIBLE 6
+
+#define MODE_FABRIC 0
+#define MODE_VN2VN 1
+
+typedef struct {
+ GtkToggleButton *enabled;
+ GtkBox *box;
+ GtkTreeView *apps_view;
+
+ gboolean initial_have_dcb;
+} CEPageDcbPrivate;
+
+static void
+enable_toggled (GtkToggleButton *button, gpointer user_data)
+{
+ CEPageDcbPrivate *priv = CE_PAGE_DCB_GET_PRIVATE (user_data);
+
+ gtk_widget_set_sensitive (GTK_WIDGET (priv->box), gtk_toggle_button_get_active (button));
+ ce_page_changed (CE_PAGE (user_data));
+}
+
+static void
+priority_editing_started (GtkCellRenderer *cell,
+ GtkCellEditable *editable,
+ const gchar *path,
+ gpointer data)
+{
+ /* Print "default" whenever the value is the default value (-1) */
+ if (GTK_IS_SPIN_BUTTON (editable)) {
+ g_signal_connect (editable, "output",
+ G_CALLBACK (ce_spin_output_with_default),
+ GINT_TO_POINTER (-1));
+ }
+}
+
+static void
+priority_edited (GtkCellRendererText *cell,
+ const gchar *path_string,
+ const gchar *new_text,
+ gpointer user_data)
+{
+ CEPageDcb *self = CE_PAGE_DCB (user_data);
+ CEPageDcbPrivate *priv = CE_PAGE_DCB_GET_PRIVATE (self);
+ GtkListStore *store = GTK_LIST_STORE (gtk_tree_view_get_model (priv->apps_view));
+ GtkTreeIter iter;
+ long int tmp = -1;
+
+ /* default = -1; convert other values */
+ if (g_strcmp0 (new_text, _("default")) != 0) {
+ errno = 0;
+ tmp = strtol (new_text, NULL, 10);
+ if (errno != 0 || tmp < -1 || tmp > 7)
+ tmp = -1;
+ }
+
+ g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (store), &iter, path_string));
+ gtk_list_store_set (store, &iter, COL_PRIORITY, (gint) tmp, -1);
+}
+
+static void
+flag_toggled (GtkCellRendererToggle *cell,
+ const gchar *path_string,
+ gpointer user_data)
+{
+ CEPageDcb *self = CE_PAGE_DCB (user_data);
+ CEPageDcbPrivate *priv = CE_PAGE_DCB_GET_PRIVATE (self);
+ GtkListStore *store = GTK_LIST_STORE (gtk_tree_view_get_model (priv->apps_view));
+ GtkTreeIter iter;
+ guint column;
+ gboolean val;
+
+ g_assert (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (store), &iter, path_string));
+ column = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (cell), "column"));
+ gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, column, &val, -1);
+ val = !val;
+ gtk_list_store_set (store, &iter, column, val, -1);
+
+ /* If the Enable flag was toggled, reset other columns to defaults */
+ if (column == COL_ENABLE && val == FALSE) {
+ gtk_list_store_set (store, &iter,
+ COL_ADVERTISE, FALSE,
+ COL_WILLING, FALSE,
+ COL_PRIORITY, -1,
+ COL_MODE, MODE_FABRIC,
+ -1);
+ }
+}
+
+static void
+prio_cell_data_func (GtkTreeViewColumn *tree_column,
+ GtkCellRenderer *cell,
+ GtkTreeModel *tree_model,
+ GtkTreeIter *iter,
+ gpointer data)
+{
+ int val;
+ char *buf;
+
+ gtk_tree_model_get (tree_model, iter, COL_PRIORITY, &val, -1);
+ if (val == -1)
+ buf = g_strdup (_("default"));
+ else
+ buf = g_strdup_printf ("%d", val);
+
+ g_object_set (G_OBJECT (cell), "text", buf, NULL);
+ g_free (buf);
+}
+
+static void
+mode_cell_data_func (GtkTreeViewColumn *tree_column,
+ GtkCellRenderer *cell,
+ GtkTreeModel *tree_model,
+ GtkTreeIter *iter,
+ gpointer data)
+{
+ GtkTreeModel *combo_model;
+ GtkTreeIter combo_iter;
+ gint mode_val, tmp;
+ char *mode_str = NULL;
+
+ gtk_tree_model_get (tree_model, iter, COL_MODE, &mode_val, -1);
+ g_return_if_fail (mode_val >= -1 && mode_val <= 1);
+ if (mode_val == -1)
+ return;
+
+ /* Grab the "mode" value from the TreeView's model, and then find the
+ * text string associated with that mode value so that we can set it
+ * on the Combo cell renderer. The Combo cell renderer then uses that
+ * value to initialize the combo box when the cell is edited.
+ */
+ g_object_get (G_OBJECT (cell), "model", &combo_model, NULL);
+ g_assert (gtk_tree_model_get_iter_first (combo_model, &combo_iter));
+ do {
+ gtk_tree_model_get (combo_model, &combo_iter, 1, &tmp, -1);
+ if (tmp == mode_val) {
+ gtk_tree_model_get (combo_model, &combo_iter, 0, &mode_str, -1);
+ break;
+ }
+ } while (gtk_tree_model_iter_next (combo_model, &combo_iter));
+
+ g_return_if_fail (mode_str != NULL);
+ g_object_set (G_OBJECT (cell), "text", mode_str, NULL);
+ g_free (mode_str);
+ g_object_unref (combo_model);
+}
+
+static void
+mode_changed (GtkCellRendererCombo *renderer,
+ gchar *path_string,
+ GtkTreeIter *new_iter,
+ gpointer user_data)
+{
+ CEPageDcb *self = CE_PAGE_DCB (user_data);
+ GtkTreeModel *combo_model, *model;
+ GtkTreeIter iter;
+ gint new_mode;
+ gboolean mode_visible;
+
+ /* Grab the integer mode out of the Cell's combo model and update the
+ * TreeView's model with that number.
+ */
+ g_object_get (G_OBJECT (renderer), "model", &combo_model, NULL);
+ gtk_tree_model_get (combo_model, new_iter, 1, &new_mode, -1);
+ g_object_unref (combo_model);
+
+ model = gtk_tree_view_get_model (CE_PAGE_DCB_GET_PRIVATE (self)->apps_view);
+ gtk_tree_model_get_iter_from_string (model, &iter, path_string);
+ gtk_tree_model_get (model, &iter, COL_MODE_VISIBLE, &mode_visible, -1);
+ if (mode_visible)
+ gtk_list_store_set (GTK_LIST_STORE (model), &iter, COL_MODE, new_mode, -1);
+}
+
+static GtkCellRenderer *
+get_renderer (GtkTreeView *view, guint idx, GtkTreeViewColumn **out_col)
+{
+ GtkTreeViewColumn *col;
+ GList *renderers;
+ GtkCellRenderer *renderer;
+
+ /* Set up the Priority spinner */
+ col = gtk_tree_view_get_column (view, idx);
+ renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (col));
+ g_assert (renderers);
+
+ /* The renderer we care about should be first item in the list */
+ renderer = GTK_CELL_RENDERER (renderers->data);
+ g_list_free (renderers);
+
+ if (out_col)
+ *out_col = col;
+ return renderer;
+}
+
+static void
+finish_setup (CEPageDcb *self, gpointer unused, GError *error, gpointer user_data)
+{
+ CEPage *parent = CE_PAGE (self);
+ CEPageDcbPrivate *priv = CE_PAGE_DCB_GET_PRIVATE (self);
+ GtkTreeViewColumn *col;
+ GtkCellRenderer *renderer;
+ GtkListStore *model;
+ GtkTreeIter iter;
+ gboolean app_fcoe_enable = FALSE, app_fcoe_adv = FALSE, app_fcoe_will = FALSE;
+ gboolean app_iscsi_enable = FALSE, app_iscsi_adv = FALSE, app_iscsi_will = FALSE;
+ gboolean app_fip_enable = FALSE, app_fip_adv = FALSE, app_fip_will = FALSE;
+ int app_fcoe_prio = -1, app_iscsi_prio = -1, app_fip_prio = -1;
+ guint i;
+ const char *fmode = NM_SETTING_DCB_FCOE_MODE_FABRIC;
+
+ if (error)
+ return;
+
+ gtk_toggle_button_set_active (priv->enabled, priv->initial_have_dcb);
+ g_signal_connect (priv->enabled, "toggled", G_CALLBACK (enable_toggled), self);
+ gtk_widget_set_sensitive (GTK_WIDGET (priv->box), priv->initial_have_dcb);
+
+ if (priv->initial_have_dcb) {
+ NMSettingDcb *s_dcb = nm_connection_get_setting_dcb (parent->connection);
+ NMSettingDcbFlags flags;
+
+ /* FCoE */
+ flags = nm_setting_dcb_get_app_fcoe_flags (s_dcb);
+ app_fcoe_enable = flags & NM_SETTING_DCB_FLAG_ENABLE;
+ app_fcoe_adv = flags & NM_SETTING_DCB_FLAG_ADVERTISE;
+ app_fcoe_will = flags & NM_SETTING_DCB_FLAG_WILLING;
+ app_fcoe_prio = nm_setting_dcb_get_app_fcoe_priority (s_dcb);
+ fmode = nm_setting_dcb_get_app_fcoe_mode (s_dcb);
+
+ /* iSCSI */
+ flags = nm_setting_dcb_get_app_iscsi_flags (s_dcb);
+ app_iscsi_enable = flags & NM_SETTING_DCB_FLAG_ENABLE;
+ app_iscsi_adv = flags & NM_SETTING_DCB_FLAG_ADVERTISE;
+ app_iscsi_will = flags & NM_SETTING_DCB_FLAG_WILLING;
+ app_iscsi_prio = nm_setting_dcb_get_app_iscsi_priority (s_dcb);
+
+ /* FIP */
+ flags = nm_setting_dcb_get_app_fip_flags (s_dcb);
+ app_fip_enable = flags & NM_SETTING_DCB_FLAG_ENABLE;
+ app_fip_adv = flags & NM_SETTING_DCB_FLAG_ADVERTISE;
+ app_fip_will = flags & NM_SETTING_DCB_FLAG_WILLING;
+ app_fip_prio = nm_setting_dcb_get_app_fip_priority (s_dcb);
+ }
+
+ /* Flags renderers */
+ for (i = COL_ENABLE; i <= COL_WILLING; i++) {
+ renderer = get_renderer (priv->apps_view, i, &col);
+ g_assert (GTK_IS_CELL_RENDERER_TOGGLE (renderer));
+ g_object_set_data (G_OBJECT (renderer), "column", GUINT_TO_POINTER (i));
+ g_signal_connect (renderer, "toggled", G_CALLBACK (flag_toggled), self);
+ }
+
+ /* Priority renderer */
+ renderer = get_renderer (priv->apps_view, COL_PRIORITY, &col);
+ g_assert (GTK_IS_CELL_RENDERER_SPIN (renderer));
+ g_signal_connect (renderer, "editing-started", G_CALLBACK (priority_editing_started), NULL);
+ g_signal_connect (renderer, "edited", G_CALLBACK (priority_edited), self);
+ gtk_tree_view_column_set_cell_data_func (col, renderer, prio_cell_data_func, NULL, NULL);
+
+ /* Mode renderer */
+ renderer = get_renderer (priv->apps_view, COL_MODE, &col);
+ g_assert (GTK_IS_CELL_RENDERER_COMBO (renderer));
+ g_object_set (G_OBJECT (renderer), "has-entry", FALSE, NULL);
+ g_object_set (G_OBJECT (renderer), "editable", TRUE, NULL);
+
+ g_object_get (G_OBJECT (renderer), "model", &model, NULL);
+ g_assert (GTK_IS_LIST_STORE (model));
+ gtk_list_store_append (model, &iter);
+ gtk_list_store_set (model, &iter,
+ 0, _("Fabric"),
+ 1, 0,
+ -1);
+ gtk_list_store_append (model, &iter);
+ gtk_list_store_set (model, &iter,
+ 0, _("VN2VN"),
+ 1, 1,
+ -1);
+
+ g_signal_connect (renderer, "changed", G_CALLBACK (mode_changed), self);
+ gtk_tree_view_column_set_cell_data_func (col, renderer, mode_cell_data_func, NULL, NULL);
+
+ /* Set up the Apps treeview model */
+ model = GTK_LIST_STORE (gtk_tree_view_get_model (priv->apps_view));
+ gtk_list_store_append (model, &iter);
+ gtk_list_store_set (model, &iter,
+ COL_APPLICATION, _("FCoE"),
+ COL_ENABLE, app_fcoe_enable,
+ COL_ADVERTISE, app_fcoe_adv,
+ COL_WILLING, app_fcoe_will,
+ COL_PRIORITY, app_fcoe_prio,
+ COL_MODE, g_strcmp0 (fmode, NM_SETTING_DCB_FCOE_MODE_FABRIC) == 0 ? 0 : 1,
+ COL_MODE_VISIBLE, TRUE,
+ -1);
+
+ gtk_list_store_append (model, &iter);
+ gtk_list_store_set (model, &iter,
+ COL_APPLICATION, _("iSCSI"),
+ COL_ENABLE, app_iscsi_enable,
+ COL_ADVERTISE, app_iscsi_adv,
+ COL_WILLING, app_iscsi_will,
+ COL_PRIORITY, app_iscsi_prio,
+ COL_MODE, -1,
+ COL_MODE_VISIBLE, FALSE,
+ -1);
+
+ gtk_list_store_append (model, &iter);
+ gtk_list_store_set (model, &iter,
+ COL_APPLICATION, _("FIP"),
+ COL_ENABLE, app_fip_enable,
+ COL_ADVERTISE, app_fip_adv,
+ COL_WILLING, app_fip_will,
+ COL_PRIORITY, app_fip_prio,
+ COL_MODE, -1,
+ COL_MODE_VISIBLE, FALSE,
+ -1);
+}
+
+static void
+dcb_private_init (CEPageDcb *self)
+{
+ CEPageDcbPrivate *priv = CE_PAGE_DCB_GET_PRIVATE (self);
+ GtkBuilder *builder = CE_PAGE (self)->builder;
+
+ priv->enabled = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "dcb_enabled_checkbutton"));
+ priv->box = GTK_BOX (gtk_builder_get_object (builder, "dcb_box"));
+ priv->apps_view = GTK_TREE_VIEW (gtk_builder_get_object (builder, "dcb_app_treeview"));
+}
+
+CEPage *
+ce_page_dcb_new (NMConnection *connection,
+ GtkWindow *parent_window,
+ NMClient *client,
+ NMRemoteSettings *settings,
+ const char **out_secrets_setting_name,
+ GError **error)
+{
+ CEPageDcb *self;
+
+ self = CE_PAGE_DCB (ce_page_new (CE_TYPE_PAGE_DCB,
+ connection,
+ parent_window,
+ client,
+ settings,
+ UIDIR "/ce-page-dcb.ui",
+ "DcbPage",
+ _("DCB")));
+ if (!self) {
+ g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("Could not load DCB user
interface."));
+ return NULL;
+ }
+
+ dcb_private_init (self);
+
+ if (nm_connection_get_setting_dcb (connection))
+ CE_PAGE_DCB_GET_PRIVATE (self)->initial_have_dcb = TRUE;
+
+ g_signal_connect (self, "initialized", G_CALLBACK (finish_setup), NULL);
+
+ return CE_PAGE (self);
+}
+
+typedef struct {
+ const char *flags_prop;
+ const char *prio_prop;
+} Apps;
+
+static const Apps dcb_apps[] = {
+ { NM_SETTING_DCB_APP_FCOE_FLAGS, NM_SETTING_DCB_APP_FCOE_PRIORITY },
+ { NM_SETTING_DCB_APP_ISCSI_FLAGS, NM_SETTING_DCB_APP_ISCSI_PRIORITY },
+ { NM_SETTING_DCB_APP_FIP_FLAGS, NM_SETTING_DCB_APP_FIP_PRIORITY },
+};
+
+static void
+ui_to_setting (CEPageDcb *self, NMSettingDcb *s_dcb)
+{
+ CEPageDcbPrivate *priv = CE_PAGE_DCB_GET_PRIVATE (self);
+ GtkTreeModel *model;
+ GtkTreeIter tree_iter;
+ gboolean iter_valid;
+ guint i = 0;
+
+ model = gtk_tree_view_get_model (priv->apps_view);
+ iter_valid = gtk_tree_model_get_iter_first (model, &tree_iter);
+ while (iter_valid) {
+ const Apps *app = &dcb_apps[i++];
+ gboolean bval;
+ gint priority = -1;
+ guint modeval = MODE_FABRIC;
+ NMSettingDcbFlags flags = NM_SETTING_DCB_FLAG_NONE;
+
+ gtk_tree_model_get (model, &tree_iter, COL_ENABLE, &bval, -1);
+ if (bval) {
+ flags |= NM_SETTING_DCB_FLAG_ENABLE;
+ gtk_tree_model_get (model, &tree_iter, COL_ADVERTISE, &bval, -1);
+ if (bval)
+ flags |= NM_SETTING_DCB_FLAG_ADVERTISE;
+ gtk_tree_model_get (model, &tree_iter, COL_WILLING, &bval, -1);
+ if (bval)
+ flags |= NM_SETTING_DCB_FLAG_WILLING;
+ }
+ g_object_set (G_OBJECT (s_dcb),
+ app->flags_prop, flags,
+ app->prio_prop, priority,
+ NULL);
+
+ gtk_tree_model_get (model, &tree_iter, COL_MODE, &modeval, COL_MODE_VISIBLE, &bval, -1);
+ if (bval) {
+ g_object_set (G_OBJECT (s_dcb),
+ NM_SETTING_DCB_APP_FCOE_MODE,
+ modeval == 0 ? NM_SETTING_DCB_FCOE_MODE_FABRIC :
NM_SETTING_DCB_FCOE_MODE_VN2VN,
+ NULL);
+ }
+
+ iter_valid = gtk_tree_model_iter_next (model, &tree_iter);
+ }
+
+}
+
+static gboolean
+validate (CEPage *page, NMConnection *connection, GError **error)
+{
+ CEPageDcb *self = CE_PAGE_DCB (page);
+ CEPageDcbPrivate *priv = CE_PAGE_DCB_GET_PRIVATE (self);
+ gboolean new_setting = FALSE;
+ NMSettingDcb *s_dcb;
+
+ if (!gtk_toggle_button_get_active (priv->enabled)) {
+ nm_connection_remove_setting (connection, NM_TYPE_SETTING_DCB);
+ return TRUE;
+ }
+
+ s_dcb = nm_connection_get_setting_dcb (page->connection);
+ if (!s_dcb) {
+ s_dcb = (NMSettingDcb *) nm_setting_dcb_new ();
+ nm_connection_add_setting (page->connection, NM_SETTING (s_dcb));
+ new_setting = TRUE;
+ }
+ ui_to_setting (self, s_dcb);
+ return nm_setting_verify (NM_SETTING (s_dcb), NULL, error);
+}
+
+static void
+ce_page_dcb_init (CEPageDcb *self)
+{
+}
+
+static void
+dispose (GObject *object)
+{
+// CEPageDcbPrivate *priv = CE_PAGE_DCB_GET_PRIVATE (object);
+
+ G_OBJECT_CLASS (ce_page_dcb_parent_class)->dispose (object);
+}
+
+static void
+ce_page_dcb_class_init (CEPageDcbClass *security_class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (security_class);
+ CEPageClass *parent_class = CE_PAGE_CLASS (security_class);
+
+ g_type_class_add_private (object_class, sizeof (CEPageDcbPrivate));
+
+ /* virtual methods */
+ object_class->dispose = dispose;
+
+ parent_class->validate = validate;
+}
diff --git a/src/connection-editor/page-dcb.h b/src/connection-editor/page-dcb.h
new file mode 100644
index 0000000..2420b26
--- /dev/null
+++ b/src/connection-editor/page-dcb.h
@@ -0,0 +1,59 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager Connection editor -- Connection editor for NetworkManager
+ *
+ * Dan Williams <dcbw redhat com>
+ *
+ * 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.
+ *
+ * (C) Copyright 2013 Red Hat, Inc.
+ */
+
+#ifndef __PAGE_DCB_H__
+#define __PAGE_DCB_H__
+
+#include "nm-connection-editor.h"
+
+#include <nm-connection.h>
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include "ce-page.h"
+
+#define CE_TYPE_PAGE_DCB (ce_page_dcb_get_type ())
+#define CE_PAGE_DCB(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CE_TYPE_PAGE_DCB, CEPageDcb))
+#define CE_PAGE_DCB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CE_TYPE_PAGE_DCB, CEPageDcbClass))
+#define CE_IS_PAGE_DCB(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CE_TYPE_PAGE_DCB))
+#define CE_IS_PAGE_DCB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CE_TYPE_PAGE_DCB))
+#define CE_PAGE_DCB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CE_TYPE_PAGE_DCB, CEPageDcbClass))
+
+typedef struct {
+ CEPage parent;
+} CEPageDcb;
+
+typedef struct {
+ CEPageClass parent;
+} CEPageDcbClass;
+
+GType ce_page_dcb_get_type (void);
+
+CEPage *ce_page_dcb_new (NMConnection *connection,
+ GtkWindow *parent,
+ NMClient *client,
+ NMRemoteSettings *settings,
+ const char **out_secrets_setting_name,
+ GError **error);
+
+#endif /* __PAGE_DCB_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]