summary refs log tree commit diff
path: root/clients/tui
diff options
context:
space:
mode:
Diffstat (limited to 'clients/tui')
-rw-r--r--clients/tui/nm-editor-bindings.h2
-rw-r--r--clients/tui/nm-editor-utils.c40
-rw-r--r--clients/tui/nm-editor-utils.h2
-rw-r--r--clients/tui/nmt-device-entry.h2
-rw-r--r--clients/tui/nmt-edit-connection-list.c27
-rw-r--r--clients/tui/nmt-edit-connection-list.h4
-rw-r--r--clients/tui/nmt-editor-page.c17
-rw-r--r--clients/tui/nmt-editor-page.h5
-rw-r--r--clients/tui/nmt-editor.c12
-rw-r--r--clients/tui/nmt-editor.h2
-rw-r--r--clients/tui/nmt-page-bond.c10
-rw-r--r--clients/tui/nmt-page-bridge.c18
-rw-r--r--clients/tui/nmt-page-team.c10
-rw-r--r--clients/tui/nmt-route-editor.h2
-rw-r--r--clients/tui/nmtui.h2
15 files changed, 146 insertions, 9 deletions
diff --git a/clients/tui/nm-editor-bindings.h b/clients/tui/nm-editor-bindings.h
index fd4fcd30..facbf1c6 100644
--- a/clients/tui/nm-editor-bindings.h
+++ b/clients/tui/nm-editor-bindings.h
@@ -19,7 +19,7 @@
 #ifndef NM_EDITOR_BINDINGS_H
 #define NM_EDITOR_BINDINGS_H
 
-#include <NetworkManager.h>
+#include "NetworkManager.h"
 
 void nm_editor_bindings_init (void);
 
diff --git a/clients/tui/nm-editor-utils.c b/clients/tui/nm-editor-utils.c
index 90a0c83b..b71e9fbe 100644
--- a/clients/tui/nm-editor-utils.c
+++ b/clients/tui/nm-editor-utils.c
@@ -316,6 +316,33 @@ get_available_connection_name (const char *format,
 	return cname;
 }
 
+static char *
+get_available_iface_name (const char *try_name,
+                          NMClient   *client)
+{
+	const GPtrArray *connections;
+	NMConnection *connection;
+	char *new_name;
+	unsigned num = 1;
+	int i = 0;
+	const char *ifname = NULL;
+
+	connections = nm_client_get_connections (client);
+
+	new_name = g_strdup (try_name);
+	while (i < connections->len) {
+		connection = NM_CONNECTION (connections->pdata[i]);
+		ifname = nm_connection_get_interface_name (connection);
+		if (g_strcmp0 (new_name, ifname) == 0) {
+			g_free (new_name);
+			new_name = g_strdup_printf ("%s%d", try_name, num++);
+			i = 0;
+		} else
+			i++;
+	}
+	return new_name;
+}
+
 /**
  * nm_editor_utils_create_connection:
  * @type: the type of the connection's primary #NMSetting
@@ -343,7 +370,7 @@ nm_editor_utils_create_connection (GType         type,
 	NMConnection *connection;
 	NMSettingConnection *s_con;
 	NMSetting *s_hw, *s_slave;
-	char *uuid, *id;
+	char *uuid, *id, *ifname;
 	int i;
 
 	if (master) {
@@ -376,6 +403,15 @@ nm_editor_utils_create_connection (GType         type,
 	s_hw = g_object_new (type, NULL);
 	nm_connection_add_setting (connection, s_hw);
 
+	if (type == NM_TYPE_SETTING_BOND)
+		ifname = get_available_iface_name ("nm-bond", client);
+	else if (type == NM_TYPE_SETTING_TEAM)
+		ifname = get_available_iface_name ("nm-team", client);
+	else if (type == NM_TYPE_SETTING_BRIDGE)
+		ifname = get_available_iface_name ("nm-bridge", client);
+	else
+		ifname = NULL;
+
 	if (slave_setting_type != G_TYPE_INVALID) {
 		s_slave = g_object_new (slave_setting_type, NULL);
 		nm_connection_add_setting (connection, s_slave);
@@ -391,10 +427,12 @@ nm_editor_utils_create_connection (GType         type,
 	              NM_SETTING_CONNECTION_AUTOCONNECT, !type_data->no_autoconnect,
 	              NM_SETTING_CONNECTION_MASTER, master_uuid,
 	              NM_SETTING_CONNECTION_SLAVE_TYPE, master_setting_type,
+	              NM_SETTING_CONNECTION_INTERFACE_NAME, ifname,
 	              NULL);
 
 	g_free (uuid);
 	g_free (id);
+	g_free (ifname);
 
 	if (type_data->connection_setup_func)
 		type_data->connection_setup_func (connection, s_con, s_hw);
diff --git a/clients/tui/nm-editor-utils.h b/clients/tui/nm-editor-utils.h
index 15a16cd2..6f66edfe 100644
--- a/clients/tui/nm-editor-utils.h
+++ b/clients/tui/nm-editor-utils.h
@@ -19,7 +19,7 @@
 #ifndef NM_EDITOR_UTILS_H
 #define NM_EDITOR_UTILS_H
 
-#include <NetworkManager.h>
+#include "NetworkManager.h"
 
 typedef struct {
 	const char *name;
diff --git a/clients/tui/nmt-device-entry.h b/clients/tui/nmt-device-entry.h
index 4945e7c2..9278244f 100644
--- a/clients/tui/nmt-device-entry.h
+++ b/clients/tui/nmt-device-entry.h
@@ -21,7 +21,7 @@
 
 #include "nmt-editor-grid.h"
 
-#include <NetworkManager.h>
+#include "NetworkManager.h"
 
 #define NMT_TYPE_DEVICE_ENTRY            (nmt_device_entry_get_type ())
 #define NMT_DEVICE_ENTRY(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_DEVICE_ENTRY, NmtDeviceEntry))
diff --git a/clients/tui/nmt-edit-connection-list.c b/clients/tui/nmt-edit-connection-list.c
index a1a59e01..e90140b3 100644
--- a/clients/tui/nmt-edit-connection-list.c
+++ b/clients/tui/nmt-edit-connection-list.c
@@ -319,6 +319,33 @@ listbox_activated (NmtNewtWidget *listbox, gpointer list)
 	edit_clicked (NMT_NEWT_BUTTON (priv->edit), list);
 }
 
+
+static void
+connection_saved (GObject      *conn,
+                  GAsyncResult *result,
+                  gpointer      user_data)
+{
+        nm_remote_connection_save_finish (NM_REMOTE_CONNECTION (conn), result, NULL);
+}
+
+void
+nmt_edit_connection_list_recommit (NmtEditConnectionList *list)
+{
+	NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE (list);
+	NMConnection *conn;
+	GSList *iter;
+
+	for (iter = priv->connections; iter; iter = iter->next) {
+		conn = iter->data;
+
+		if (   NM_IS_REMOTE_CONNECTION (conn)
+		    && (nm_remote_connection_get_unsaved (NM_REMOTE_CONNECTION (conn)) == FALSE)) {
+			nm_remote_connection_save_async (NM_REMOTE_CONNECTION (conn),
+			                                 NULL, connection_saved, NULL);
+		}
+	}
+}
+
 static void
 nmt_edit_connection_list_finalize (GObject *object)
 {
diff --git a/clients/tui/nmt-edit-connection-list.h b/clients/tui/nmt-edit-connection-list.h
index fd492bce..9726e287 100644
--- a/clients/tui/nmt-edit-connection-list.h
+++ b/clients/tui/nmt-edit-connection-list.h
@@ -21,7 +21,7 @@
 
 #include "nmt-newt.h"
 
-#include <NetworkManager.h>
+#include "NetworkManager.h"
 
 #define NMT_TYPE_EDIT_CONNECTION_LIST            (nmt_edit_connection_list_get_type ())
 #define NMT_EDIT_CONNECTION_LIST(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_EDIT_CONNECTION_LIST, NmtEditConnectionList))
@@ -52,4 +52,6 @@ typedef gboolean (*NmtEditConnectionListFilter) (NmtEditConnectionList *list,
                                                  NMConnection          *connection,
                                                  gpointer               user_data);
 
+void nmt_edit_connection_list_recommit (NmtEditConnectionList *list);
+
 #endif /* NMT_EDIT_CONNECTION_LIST_H */
diff --git a/clients/tui/nmt-editor-page.c b/clients/tui/nmt-editor-page.c
index 44abe273..99475a91 100644
--- a/clients/tui/nmt-editor-page.c
+++ b/clients/tui/nmt-editor-page.c
@@ -112,6 +112,23 @@ nmt_editor_page_add_section (NmtEditorPage *page,
 	priv->sections = g_slist_append (priv->sections, g_object_ref_sink (section));
 }
 
+/**
+ * nmt_editor_page_saved:
+ * @page: the #NmtEditorPage
+ *
+ * This method is called when the user saves the connection. It gives
+ * the page a chance to do save its data outside the connections (such as
+ * recommit the slave connections).
+ */
+void
+nmt_editor_page_saved (NmtEditorPage *page)
+{
+	NmtEditorPageClass *editor_page_class = NMT_EDITOR_PAGE_GET_CLASS (page);
+
+	if (editor_page_class->saved)
+		editor_page_class->saved (page);
+}
+
 static void
 nmt_editor_page_set_property (GObject      *object,
                               guint         prop_id,
diff --git a/clients/tui/nmt-editor-page.h b/clients/tui/nmt-editor-page.h
index 8da5ea9f..93a66155 100644
--- a/clients/tui/nmt-editor-page.h
+++ b/clients/tui/nmt-editor-page.h
@@ -19,7 +19,7 @@
 #ifndef NMT_EDITOR_PAGE_H
 #define NMT_EDITOR_PAGE_H
 
-#include <NetworkManager.h>
+#include "NetworkManager.h"
 
 #include "nmt-editor-grid.h"
 #include "nmt-editor-section.h"
@@ -39,6 +39,7 @@ typedef struct {
 typedef struct {
 	GObjectClass parent;
 
+	void (*saved) (NmtEditorPage *page);
 } NmtEditorPageClass;
 
 GType nmt_editor_page_get_type (void);
@@ -47,6 +48,8 @@ NMConnection  *nmt_editor_page_get_connection    (NmtEditorPage *page);
 
 GSList        *nmt_editor_page_get_sections      (NmtEditorPage *page);
 
+void           nmt_editor_page_saved            (NmtEditorPage *page);
+
 /*< protected >*/
 void           nmt_editor_page_add_section       (NmtEditorPage *page,
                                                   NmtEditorSection *section);
diff --git a/clients/tui/nmt-editor.c b/clients/tui/nmt-editor.c
index 395e661a..515e3471 100644
--- a/clients/tui/nmt-editor.c
+++ b/clients/tui/nmt-editor.c
@@ -146,6 +146,15 @@ connection_added (GObject      *client,
 }
 
 static void
+page_saved (gpointer data, gpointer user_data)
+{
+	NmtEditorPage *page = data;
+
+	nmt_editor_page_saved (page);
+}
+
+
+static void
 save_connection_and_exit (NmtNewtButton *button,
                           gpointer       user_data)
 {
@@ -183,6 +192,9 @@ save_connection_and_exit (NmtNewtButton *button,
 		}
 	}
 
+	/* Let the page know that it was saved. */
+	g_slist_foreach (priv->pages, page_saved, NULL);
+
 	nmt_newt_form_quit (NMT_NEWT_FORM (editor));
 }
 
diff --git a/clients/tui/nmt-editor.h b/clients/tui/nmt-editor.h
index b000f64e..5620c5e8 100644
--- a/clients/tui/nmt-editor.h
+++ b/clients/tui/nmt-editor.h
@@ -19,7 +19,7 @@
 #ifndef NMT_EDITOR_H
 #define NMT_EDITOR_H
 
-#include <NetworkManager.h>
+#include "NetworkManager.h"
 
 #include "nmt-newt.h"
 
diff --git a/clients/tui/nmt-page-bond.c b/clients/tui/nmt-page-bond.c
index 259ecfc1..48070dbf 100644
--- a/clients/tui/nmt-page-bond.c
+++ b/clients/tui/nmt-page-bond.c
@@ -424,11 +424,21 @@ nmt_page_bond_constructed (GObject *object)
 }
 
 static void
+nmt_page_bond_saved (NmtEditorPage *editor_page)
+{
+	NmtPageBondPrivate *priv = NMT_PAGE_BOND_GET_PRIVATE (editor_page);
+
+	nmt_edit_connection_list_recommit (NMT_EDIT_CONNECTION_LIST (priv->slaves));
+}
+
+static void
 nmt_page_bond_class_init (NmtPageBondClass *bond_class)
 {
 	GObjectClass *object_class = G_OBJECT_CLASS (bond_class);
+	NmtEditorPageClass *editor_page_class = NMT_EDITOR_PAGE_CLASS (bond_class);
 
 	g_type_class_add_private (bond_class, sizeof (NmtPageBondPrivate));
 
 	object_class->constructed = nmt_page_bond_constructed;
+	editor_page_class->saved = nmt_page_bond_saved;
 }
diff --git a/clients/tui/nmt-page-bridge.c b/clients/tui/nmt-page-bridge.c
index b5eb9ec8..08526db4 100644
--- a/clients/tui/nmt-page-bridge.c
+++ b/clients/tui/nmt-page-bridge.c
@@ -30,6 +30,12 @@
 
 G_DEFINE_TYPE (NmtPageBridge, nmt_page_bridge, NMT_TYPE_EDITOR_PAGE_DEVICE)
 
+#define NMT_PAGE_BRIDGE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_PAGE_BRIDGE, NmtPageBridgePrivate))
+
+typedef struct {
+        NmtSlaveList *slaves;
+} NmtPageBridgePrivate;
+
 NmtEditorPage *
 nmt_page_bridge_new (NMConnection   *conn,
                      NmtDeviceEntry *deventry)
@@ -58,6 +64,7 @@ static void
 nmt_page_bridge_constructed (GObject *object)
 {
 	NmtPageBridge *bridge = NMT_PAGE_BRIDGE (object);
+	NmtPageBridgePrivate *priv = NMT_PAGE_BRIDGE_GET_PRIVATE (bridge);
 	NmtEditorSection *section;
 	NmtEditorGrid *grid;
 	NMSettingBridge *s_bridge;
@@ -80,6 +87,7 @@ nmt_page_bridge_constructed (GObject *object)
 
 	widget = nmt_slave_list_new (conn, bridge_connection_type_filter, bridge);
 	nmt_editor_grid_append (grid, NULL, widget, NULL);
+	priv->slaves = NMT_SLAVE_LIST (widget);
 
 	widget = nmt_newt_entry_numeric_new (10, 0, 1000000);
 	g_object_bind_property (s_bridge, NM_SETTING_BRIDGE_AGEING_TIME,
@@ -145,9 +153,19 @@ nmt_page_bridge_constructed (GObject *object)
 }
 
 static void
+nmt_page_bridge_saved (NmtEditorPage *editor_page)
+{
+	NmtPageBridgePrivate *priv = NMT_PAGE_BRIDGE_GET_PRIVATE (editor_page);
+
+	nmt_edit_connection_list_recommit (NMT_EDIT_CONNECTION_LIST (priv->slaves));
+}
+
+static void
 nmt_page_bridge_class_init (NmtPageBridgeClass *bridge_class)
 {
 	GObjectClass *object_class = G_OBJECT_CLASS (bridge_class);
+	NmtEditorPageClass *editor_page_class = NMT_EDITOR_PAGE_CLASS (bridge_class);
 
 	object_class->constructed = nmt_page_bridge_constructed;
+	editor_page_class->saved = nmt_page_bridge_saved;
 }
diff --git a/clients/tui/nmt-page-team.c b/clients/tui/nmt-page-team.c
index d7c4c425..2523bd85 100644
--- a/clients/tui/nmt-page-team.c
+++ b/clients/tui/nmt-page-team.c
@@ -180,11 +180,21 @@ nmt_page_team_constructed (GObject *object)
 }
 
 static void
+nmt_page_team_saved (NmtEditorPage *editor_page)
+{
+	NmtPageTeamPrivate *priv = NMT_PAGE_TEAM_GET_PRIVATE (editor_page);
+
+	nmt_edit_connection_list_recommit (NMT_EDIT_CONNECTION_LIST (priv->slaves));
+}
+
+static void
 nmt_page_team_class_init (NmtPageTeamClass *team_class)
 {
 	GObjectClass *object_class = G_OBJECT_CLASS (team_class);
+	NmtEditorPageClass *editor_page_class = NMT_EDITOR_PAGE_CLASS (team_class);
 
 	g_type_class_add_private (team_class, sizeof (NmtPageTeamPrivate));
 
 	object_class->constructed = nmt_page_team_constructed;
+	editor_page_class->saved = nmt_page_team_saved;
 }
diff --git a/clients/tui/nmt-route-editor.h b/clients/tui/nmt-route-editor.h
index febcb402..8e63830e 100644
--- a/clients/tui/nmt-route-editor.h
+++ b/clients/tui/nmt-route-editor.h
@@ -19,7 +19,7 @@
 #ifndef NMT_ROUTE_EDITOR_H
 #define NMT_ROUTE_EDITOR_H
 
-#include <NetworkManager.h>
+#include "NetworkManager.h"
 
 #include "nmt-newt.h"
 
diff --git a/clients/tui/nmtui.h b/clients/tui/nmtui.h
index 53c20cb4..efb59622 100644
--- a/clients/tui/nmtui.h
+++ b/clients/tui/nmtui.h
@@ -19,7 +19,7 @@
 #ifndef NMTUI_H
 #define NMTUI_H
 
-#include <NetworkManager.h>
+#include "NetworkManager.h"
 
 extern NMClient *nm_client;