[network-manager-applet/new-editor: 6/7] connection-editor: add WiMAX support



commit 905ef44d1e13f3f2611ca219b8d015a4c277476f
Author: Dan Winship <danw gnome org>
Date:   Mon Feb 20 14:27:05 2012 -0500

    connection-editor: add WiMAX support

 po/POTFILES.in                               |    2 +
 src/connection-editor/Makefile.am            |    3 +
 src/connection-editor/ce-page-wimax.ui       |   70 ++++++
 src/connection-editor/new-connection.c       |    7 +
 src/connection-editor/nm-connection-editor.c |    9 +
 src/connection-editor/nm-connection-list.c   |    2 +
 src/connection-editor/page-wimax.c           |  300 ++++++++++++++++++++++++++
 src/connection-editor/page-wimax.h           |   61 ++++++
 8 files changed, 454 insertions(+), 0 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 60251b4..bd8b138 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -24,6 +24,7 @@ src/connection-editor/ce-page.c
 [type: gettext/glade]src/connection-editor/ce-page-ip6.ui
 [type: gettext/glade]src/connection-editor/ce-page-mobile.ui
 [type: gettext/glade]src/connection-editor/ce-page-ppp.ui
+[type: gettext/glade]src/connection-editor/ce-page-wimax.ui
 [type: gettext/glade]src/connection-editor/ce-page-wired.ui
 [type: gettext/glade]src/connection-editor/ce-page-wireless.ui
 [type: gettext/glade]src/connection-editor/ce-page-wireless-security.ui
@@ -38,6 +39,7 @@ src/connection-editor/page-ip6.c
 src/connection-editor/page-mobile.c
 src/connection-editor/page-ppp.c
 src/connection-editor/page-vpn.c
+src/connection-editor/page-wimax.c
 src/connection-editor/page-wired.c
 src/connection-editor/page-wired-security.c
 src/connection-editor/page-wireless.c
diff --git a/src/connection-editor/Makefile.am b/src/connection-editor/Makefile.am
index df2b026..acbd9a0 100644
--- a/src/connection-editor/Makefile.am
+++ b/src/connection-editor/Makefile.am
@@ -34,6 +34,8 @@ nm_connection_editor_SOURCES = \
 	page-wireless.c \
 	page-wireless-security.h \
 	page-wireless-security.c \
+	page-wimax.h \
+	page-wimax.c \
 	page-ip4.h \
 	page-ip4.c \
 	page-ip6.h \
@@ -77,6 +79,7 @@ ui_DATA = \
 	ce-page-wired.ui \
 	ce-page-wireless.ui \
 	ce-page-wireless-security.ui \
+	ce-page-wimax.ui \
 	ce-page-ip4.ui \
 	ce-ip4-routes.ui \
 	ce-page-ip6.ui \
diff --git a/src/connection-editor/ce-page-wimax.ui b/src/connection-editor/ce-page-wimax.ui
new file mode 100644
index 0000000..7a09d2a
--- /dev/null
+++ b/src/connection-editor/ce-page-wimax.ui
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="2.16"/>
+  <object class="GtkTable" id="WimaxPage">
+    <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="GtkAlignment" id="wimax_device_mac_alignment">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="xalign">0</property>
+        <child>
+          <placeholder/>
+        </child>
+      </object>
+      <packing>
+        <property name="left_attach">1</property>
+        <property name="right_attach">2</property>
+        <property name="top_attach">1</property>
+        <property name="bottom_attach">2</property>
+        <property name="y_options"></property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkLabel" id="wimax_device_mac_label">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="xalign">0</property>
+        <property name="label" translatable="yes">_Device MAC address:</property>
+        <property name="use_underline">True</property>
+      </object>
+      <packing>
+        <property name="top_attach">1</property>
+        <property name="bottom_attach">2</property>
+        <property name="x_options">GTK_FILL</property>
+        <property name="y_options"></property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkEntry" id="wimax_name">
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+      </object>
+      <packing>
+        <property name="left_attach">1</property>
+        <property name="right_attach">2</property>
+        <property name="y_options"></property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkLabel" id="wimax_name_label">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="xalign">0</property>
+        <property name="label" translatable="yes">_Network name:</property>
+        <property name="use_underline">True</property>
+        <property name="mnemonic_widget">wimax_name</property>
+      </object>
+      <packing>
+        <property name="x_options">GTK_FILL</property>
+        <property name="y_options"></property>
+      </packing>
+    </child>
+  </object>
+</interface>
diff --git a/src/connection-editor/new-connection.c b/src/connection-editor/new-connection.c
index 38d4772..b5fbc11 100644
--- a/src/connection-editor/new-connection.c
+++ b/src/connection-editor/new-connection.c
@@ -27,6 +27,7 @@
 #include "page-wired.h"
 #include "page-wireless.h"
 #include "page-mobile.h"
+#include "page-wimax.h"
 #include "page-dsl.h"
 #include "page-vpn.h"
 #include "vpn-helpers.h"
@@ -101,6 +102,12 @@ get_connection_type_list (void)
 	data.setting_type = NM_TYPE_SETTING_GSM;
 	g_array_append_val (array, data);
 
+	data.name = _("WiMAX");
+	ICON_LOAD (data.icon, "nm-device-wwan");
+	data.new_connection_func = wimax_connection_new;
+	data.setting_type = NM_TYPE_SETTING_WIMAX;
+	g_array_append_val (array, data);
+
 	data.name = _("DSL");
 	ICON_LOAD (data.icon, "nm-device-wired");
 	data.new_connection_func = dsl_connection_new;
diff --git a/src/connection-editor/nm-connection-editor.c b/src/connection-editor/nm-connection-editor.c
index c921e57..0086f8e 100644
--- a/src/connection-editor/nm-connection-editor.c
+++ b/src/connection-editor/nm-connection-editor.c
@@ -45,6 +45,7 @@
 #include <nm-setting-ppp.h>
 #include <nm-setting-gsm.h>
 #include <nm-setting-cdma.h>
+#include <nm-setting-wimax.h>
 #include <nm-utils.h>
 
 #include <nm-remote-connection.h>
@@ -63,6 +64,7 @@
 #include "page-mobile.h"
 #include "page-ppp.h"
 #include "page-vpn.h"
+#include "page-wimax.h"
 #include "ce-polkit-button.h"
 #include "vpn-helpers.h"
 
@@ -774,6 +776,13 @@ nm_connection_editor_set_connection (NMConnectionEditor *editor,
 			goto out;
 		if (!add_page (editor, ce_page_ip4_new, editor->connection, error))
 			goto out;
+	} else if (!strcmp (connection_type, NM_SETTING_WIMAX_SETTING_NAME)) {
+		if (!add_page (editor, ce_page_wimax_new, editor->connection, error))
+			goto out;
+		if (!add_page (editor, ce_page_ip4_new, editor->connection, error))
+			goto out;
+		if (!add_page (editor, ce_page_ip6_new, editor->connection, error))
+			goto out;
 	} else {
 		g_warning ("Unhandled setting type '%s'", connection_type);
 	}
diff --git a/src/connection-editor/nm-connection-list.c b/src/connection-editor/nm-connection-list.c
index 7dc6be6..c83ae88 100644
--- a/src/connection-editor/nm-connection-list.c
+++ b/src/connection-editor/nm-connection-list.c
@@ -42,6 +42,7 @@
 #include <nm-setting-pppoe.h>
 #include <nm-setting-ppp.h>
 #include <nm-setting-serial.h>
+#include <nm-setting-wimax.h>
 #include <nm-utils.h>
 #include <nm-remote-settings.h>
 
@@ -51,6 +52,7 @@
 #include "page-mobile.h"
 #include "page-dsl.h"
 #include "page-vpn.h"
+#include "page-wimax.h"
 #include "nm-connection-editor.h"
 #include "nm-connection-list.h"
 #include "vpn-helpers.h"
diff --git a/src/connection-editor/page-wimax.c b/src/connection-editor/page-wimax.c
new file mode 100644
index 0000000..b378fb4
--- /dev/null
+++ b/src/connection-editor/page-wimax.c
@@ -0,0 +1,300 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager Connection editor -- Connection editor for NetworkManager
+ *
+ * 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.
+ *
+ * Copyright 2012 Red Hat, Inc.
+ */
+
+#include "config.h"
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+
+#include <nm-setting-connection.h>
+#include <nm-setting-wimax.h>
+#include <nm-device-wimax.h>
+#include <nm-utils.h>
+
+#include "page-wimax.h"
+
+G_DEFINE_TYPE (CEPageWimax, ce_page_wimax, CE_TYPE_PAGE)
+
+#define CE_PAGE_WIMAX_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CE_TYPE_PAGE_WIMAX, CEPageWimaxPrivate))
+
+typedef struct {
+	NMSettingWimax *setting;
+
+	GtkEntry *name;
+#if GTK_CHECK_VERSION (2,24,0)
+	GtkComboBoxText *device_mac;  /* Permanent MAC of the device */
+#else
+	GtkComboBoxEntry *device_mac;
+#endif
+
+	gboolean disposed;
+} CEPageWimaxPrivate;
+
+static void
+wimax_private_init (CEPageWimax *self)
+{
+	CEPageWimaxPrivate *priv = CE_PAGE_WIMAX_GET_PRIVATE (self);
+	GtkBuilder *builder;
+	GtkWidget *align;
+	GtkLabel *label;
+
+	builder = CE_PAGE (self)->builder;
+
+	priv->name = GTK_ENTRY (gtk_builder_get_object (builder, "wimax_name"));
+
+#if GTK_CHECK_VERSION(2,24,0)
+	priv->device_mac = GTK_COMBO_BOX_TEXT (gtk_combo_box_text_new_with_entry ());
+	gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX (priv->device_mac), 0);
+#else
+	priv->device_mac = GTK_COMBO_BOX_ENTRY (gtk_combo_box_entry_new_text ());
+	gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (priv->device_mac), 0);
+#endif
+	gtk_widget_set_tooltip_text (GTK_WIDGET (priv->device_mac),
+	                             _("This option locks this connection to the network device specified by its permanent MAC address entered here.  Example: 00:11:22:33:44:55"));
+
+	align = GTK_WIDGET (gtk_builder_get_object (builder, "wimax_device_mac_alignment"));
+	gtk_container_add (GTK_CONTAINER (align), GTK_WIDGET (priv->device_mac));
+	gtk_widget_show_all (GTK_WIDGET (priv->device_mac));
+
+	/* Set mnemonic widget for device MAC label */
+	label = GTK_LABEL (GTK_WIDGET (gtk_builder_get_object (builder, "wimax_device_mac_label")));
+	gtk_label_set_mnemonic_widget (label, GTK_WIDGET (priv->device_mac));
+}
+
+static void
+populate_ui (CEPageWimax *self)
+{
+	CEPageWimaxPrivate *priv = CE_PAGE_WIMAX_GET_PRIVATE (self);
+	NMSettingWimax *setting = priv->setting;
+	char **mac_list, **iter;
+	const GByteArray *s_mac;
+	char *s_mac_str;
+	char *active_mac = NULL;
+	GtkWidget *entry;
+
+	gtk_entry_set_text (priv->name, nm_setting_wimax_get_network_name (setting));
+	g_signal_connect_swapped (priv->name, "changed", G_CALLBACK (ce_page_changed), self);
+
+	/* Device MAC address */
+	mac_list = ce_page_get_mac_list (CE_PAGE (self));
+	s_mac = nm_setting_wimax_get_mac_address (setting);
+	s_mac_str = s_mac ? g_strdup_printf ("%02X:%02X:%02X:%02X:%02X:%02X",
+	                                     s_mac->data[0], s_mac->data[1], s_mac->data[2],
+	                                     s_mac->data[3], s_mac->data[4], s_mac->data[5]):
+	                    NULL;
+
+	for (iter = mac_list; iter && *iter; iter++) {
+#if GTK_CHECK_VERSION (2,24,0)
+		gtk_combo_box_text_append_text (priv->device_mac, *iter);
+#else
+		gtk_combo_box_append_text (GTK_COMBO_BOX (priv->device_mac), *iter);
+#endif
+		if (s_mac_str && g_ascii_strncasecmp (*iter, s_mac_str, 17) == 0)
+			active_mac = *iter;
+	}
+
+	if (s_mac_str) {
+		if (!active_mac) {
+#if GTK_CHECK_VERSION (2,24,0)
+			gtk_combo_box_text_prepend_text (priv->device_mac, s_mac_str);
+#else
+			gtk_combo_box_prepend_text (GTK_COMBO_BOX (priv->device_mac), s_mac_str);
+#endif
+		}
+
+		entry = gtk_bin_get_child (GTK_BIN (priv->device_mac));
+		if (entry)
+			gtk_entry_set_text (GTK_ENTRY (entry), active_mac ? active_mac : s_mac_str);
+	}
+	g_strfreev (mac_list);
+	g_signal_connect_swapped (priv->device_mac, "changed", G_CALLBACK (ce_page_changed), self);
+}
+
+static void
+finish_setup (CEPageWimax *self, gpointer unused, GError *error, gpointer user_data)
+{
+	if (error)
+		return;
+
+	populate_ui (self);
+}
+
+CEPage *
+ce_page_wimax_new (NMConnection *connection,
+                   GtkWindow *parent_window,
+                   NMClient *client,
+                   const char **out_secrets_setting_name,
+                   GError **error)
+{
+	CEPageWimax *self;
+	CEPageWimaxPrivate *priv;
+
+	g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
+
+	self = CE_PAGE_WIMAX (ce_page_new (CE_TYPE_PAGE_WIMAX,
+	                                   connection,
+	                                   parent_window,
+	                                   client,
+	                                   UIDIR "/ce-page-wimax.ui",
+	                                   "WimaxPage",
+	                                   _("WiMAX")));
+	if (!self) {
+		g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC,
+		                     _("Could not load WiMAX user interface."));
+		return NULL;
+	}
+
+	wimax_private_init (self);
+	priv = CE_PAGE_WIMAX_GET_PRIVATE (self);
+
+	priv->setting = nm_connection_get_setting_wimax (connection);
+	if (!priv->setting) {
+		priv->setting = NM_SETTING_WIMAX (nm_setting_wimax_new ());
+		nm_connection_add_setting (connection, NM_SETTING (priv->setting));
+	}
+
+	g_signal_connect (self, "initialized", G_CALLBACK (finish_setup), NULL);
+
+	return CE_PAGE (self);
+}
+
+static void
+ui_to_setting (CEPageWimax *self)
+{
+	CEPageWimaxPrivate *priv = CE_PAGE_WIMAX_GET_PRIVATE (self);
+	const char *name;
+	GByteArray *device_mac = NULL;
+	GtkWidget *entry;
+
+	name = gtk_entry_get_text (priv->name);
+
+	entry = gtk_bin_get_child (GTK_BIN (priv->device_mac));
+	if (entry)
+		device_mac = ce_page_entry_to_mac (GTK_ENTRY (entry), NULL);
+
+	g_object_set (priv->setting,
+	              NM_SETTING_WIMAX_NETWORK_NAME, name,
+	              NM_SETTING_WIMAX_MAC_ADDRESS, device_mac,
+	              NULL);
+
+	if (device_mac)
+		g_byte_array_free (device_mac, TRUE);
+}
+
+static gboolean
+validate (CEPage *page, NMConnection *connection, GError **error)
+{
+	CEPageWimax *self = CE_PAGE_WIMAX (page);
+	CEPageWimaxPrivate *priv = CE_PAGE_WIMAX_GET_PRIVATE (self);
+	const char *name;
+	gboolean invalid = FALSE;
+	GByteArray *ignore;
+	GtkWidget *entry;
+
+	name = gtk_entry_get_text (priv->name);
+	if (!*name)
+		return FALSE;
+
+	entry = gtk_bin_get_child (GTK_BIN (priv->device_mac));
+	if (entry) {
+		ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), &invalid);
+		if (invalid)
+			return FALSE;
+		if (ignore)
+			g_byte_array_free (ignore, TRUE);
+	}
+
+	ui_to_setting (self);
+	return TRUE;
+}
+
+static char **
+get_mac_list (CEPage *page)
+{
+	const GPtrArray *devices;
+	GString *mac_str;
+	char **mac_list;
+	int i;
+
+	if (!page->client)
+		return NULL;
+
+	mac_str = g_string_new (NULL);
+	devices = nm_client_get_devices (page->client);
+	for (i = 0; devices && (i < devices->len); i++) {
+		const char *mac, *iface;
+		NMDevice *dev = g_ptr_array_index (devices, i);
+
+		if (!NM_IS_DEVICE_WIMAX (dev))
+			continue;
+
+		mac = nm_device_wimax_get_hw_address (NM_DEVICE_WIMAX (dev));
+		iface = nm_device_get_iface (NM_DEVICE (dev));
+		g_string_append_printf (mac_str, "%s (%s),", mac, iface);
+	}
+	g_string_truncate (mac_str, mac_str->len-1);
+
+	mac_list = g_strsplit (mac_str->str, ",", 0);
+	g_string_free (mac_str, TRUE);
+
+	return mac_list;
+}
+
+static void
+ce_page_wimax_init (CEPageWimax *self)
+{
+}
+
+static void
+ce_page_wimax_class_init (CEPageWimaxClass *wimax_class)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (wimax_class);
+	CEPageClass *parent_class = CE_PAGE_CLASS (wimax_class);
+
+	g_type_class_add_private (object_class, sizeof (CEPageWimaxPrivate));
+
+	/* virtual methods */
+	parent_class->validate = validate;
+	parent_class->get_mac_list = get_mac_list;
+}
+
+
+void
+wimax_connection_new (GtkWindow *parent,
+                      const char *detail,
+                      PageNewConnectionResultFunc result_func,
+                      PageGetConnectionsFunc get_connections_func,
+                      gpointer user_data)
+{
+	NMConnection *connection;
+	NMSetting *s_wimax;
+
+	connection = ce_page_new_connection (_("WiMAX connection %d"),
+	                                     NM_SETTING_WIMAX_SETTING_NAME,
+	                                     TRUE,
+	                                     get_connections_func,
+	                                     user_data);
+	s_wimax = nm_setting_wimax_new ();
+	nm_connection_add_setting (connection, s_wimax);
+
+	(*result_func) (connection, FALSE, NULL, user_data);
+}
+
+
diff --git a/src/connection-editor/page-wimax.h b/src/connection-editor/page-wimax.h
new file mode 100644
index 0000000..cd31c9d
--- /dev/null
+++ b/src/connection-editor/page-wimax.h
@@ -0,0 +1,61 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager Connection editor -- Connection editor for NetworkManager
+ *
+ * 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.
+ *
+ * Copyright 2012 Red Hat, Inc.
+ */
+
+#ifndef __PAGE_WIMAX_H__
+#define __PAGE_WIMAX_H__
+
+#include <nm-connection.h>
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include "ce-page.h"
+
+#define CE_TYPE_PAGE_WIMAX            (ce_page_wimax_get_type ())
+#define CE_PAGE_WIMAX(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), CE_TYPE_PAGE_WIMAX, CEPageWimax))
+#define CE_PAGE_WIMAX_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), CE_TYPE_PAGE_WIMAX, CEPageWimaxClass))
+#define CE_IS_PAGE_WIMAX(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CE_TYPE_PAGE_WIMAX))
+#define CE_IS_PAGE_WIMAX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), CE_TYPE_PAGE_WIMAX))
+#define CE_PAGE_WIMAX_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), CE_TYPE_PAGE_WIMAX, CEPageWimaxClass))
+
+typedef struct {
+	CEPage parent;
+} CEPageWimax;
+
+typedef struct {
+	CEPageClass parent;
+} CEPageWimaxClass;
+
+GType ce_page_wimax_get_type (void);
+
+CEPage *ce_page_wimax_new (NMConnection *connection,
+                           GtkWindow *parent,
+                           NMClient *client,
+                           const char **out_secrets_setting_name,
+                           GError **error);
+
+void wimax_connection_new (GtkWindow *parent,
+                           const char *detail,
+                           PageNewConnectionResultFunc result_func,
+                           PageGetConnectionsFunc get_connections_func,
+                           gpointer user_data);
+
+#endif  /* __PAGE_WIMAX_H__ */
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]