[network-manager-applet] editor: change "Device MAC address" to combo box with an entry



commit a5b87782d833868faa1f5cb67969c3df39e05361
Author: JiÅÃ KlimeÅ <jklimes redhat com>
Date:   Mon Jul 18 22:33:09 2011 +0200

    editor: change "Device MAC address" to combo box with an entry
    
    The combo box list is pre-filled with available MAC addresses. It makes the
    input more easy. The entry still allows inserting arbitrary MAC address.

 src/connection-editor/ce-page-wired.ui         |    4 +-
 src/connection-editor/ce-page-wireless.ui      |    4 +-
 src/connection-editor/ce-page.c                |   14 ++++
 src/connection-editor/ce-page.h                |    9 ++-
 src/connection-editor/nm-connection-editor.c   |    2 +-
 src/connection-editor/page-dsl.c               |    4 +-
 src/connection-editor/page-dsl.h               |    3 +-
 src/connection-editor/page-ip4.c               |    2 +
 src/connection-editor/page-ip4.h               |    3 +-
 src/connection-editor/page-ip6.c               |    2 +
 src/connection-editor/page-ip6.h               |    3 +-
 src/connection-editor/page-mobile.c            |    2 +
 src/connection-editor/page-mobile.h            |    3 +-
 src/connection-editor/page-ppp.c               |    4 +-
 src/connection-editor/page-ppp.h               |    3 +-
 src/connection-editor/page-vpn.c               |    4 +-
 src/connection-editor/page-vpn.h               |    3 +-
 src/connection-editor/page-wired-security.c    |    2 +
 src/connection-editor/page-wired-security.h    |    3 +-
 src/connection-editor/page-wired.c             |   93 +++++++++++++++++++++---
 src/connection-editor/page-wired.h             |    3 +-
 src/connection-editor/page-wireless-security.c |    4 +-
 src/connection-editor/page-wireless-security.h |    3 +-
 src/connection-editor/page-wireless.c          |   89 ++++++++++++++++++++---
 src/connection-editor/page-wireless.h          |    3 +-
 25 files changed, 229 insertions(+), 40 deletions(-)
---
diff --git a/src/connection-editor/ce-page-wired.ui b/src/connection-editor/ce-page-wired.ui
index c7ac20e..e644d40 100644
--- a/src/connection-editor/ce-page-wired.ui
+++ b/src/connection-editor/ce-page-wired.ui
@@ -175,8 +175,10 @@
           </packing>
         </child>
         <child>
-          <object class="GtkEntry" id="wired_device_mac">
+          <object class="GtkComboBoxText" id="wired_device_mac">
             <property name="visible">True</property>
+            <property name="has_entry">True</property>
+            <property name="entry_text_column">0</property>
             <property name="can_focus">True</property>
             <property name="tooltip_text" translatable="yes">This option locks this connection to the network device specified by its permanent MAC address entered here.  Example: 00:11:22:33:44:55</property>
           </object>
diff --git a/src/connection-editor/ce-page-wireless.ui b/src/connection-editor/ce-page-wireless.ui
index f7a4768..1d00bd4 100644
--- a/src/connection-editor/ce-page-wireless.ui
+++ b/src/connection-editor/ce-page-wireless.ui
@@ -117,8 +117,10 @@
           </packing>
         </child>
         <child>
-          <object class="GtkEntry" id="wireless_device_mac">
+          <object class="GtkComboBoxText" id="wireless_device_mac">
             <property name="visible">True</property>
+            <property name="has_entry">True</property>
+            <property name="entry_text_column">0</property>
             <property name="can_focus">True</property>
             <property name="tooltip_text" translatable="yes">This option locks this connection to the network device specified by its permanent MAC address entered here.  Example: 00:11:22:33:44:55</property>
           </object>
diff --git a/src/connection-editor/ce-page.c b/src/connection-editor/ce-page.c
index 8eb76e5..25e2240 100644
--- a/src/connection-editor/ce-page.c
+++ b/src/connection-editor/ce-page.c
@@ -119,6 +119,17 @@ ce_page_validate (CEPage *self, NMConnection *connection, GError **error)
 	return TRUE;
 }
 
+char **
+ce_page_get_mac_list (CEPage *self)
+{
+	g_return_val_if_fail (CE_IS_PAGE (self), NULL);
+
+	if (CE_PAGE_GET_CLASS (self)->get_mac_list)
+		return CE_PAGE_GET_CLASS (self)->get_mac_list (self);
+
+	return NULL;
+}
+
 void
 ce_page_mac_to_entry (const GByteArray *mac, GtkEntry *entry)
 {
@@ -507,6 +518,7 @@ CEPage *
 ce_page_new (GType page_type,
              NMConnection *connection,
              GtkWindow *parent_window,
+             NMClient *client,
              const char *ui_file,
              const char *widget_name,
              const char *title)
@@ -523,6 +535,8 @@ ce_page_new (GType page_type,
 	                              CE_PAGE_PARENT_WINDOW, parent_window,
 	                              NULL));
 	self->title = g_strdup (title);
+	self->client = client;
+
 	if (ui_file) {
 		if (!gtk_builder_add_from_file (self->builder, ui_file, &error)) {
 			g_warning ("Couldn't load builder file: %s", error->message);
diff --git a/src/connection-editor/ce-page.h b/src/connection-editor/ce-page.h
index 5ce79c9..692790d 100644
--- a/src/connection-editor/ce-page.h
+++ b/src/connection-editor/ce-page.h
@@ -30,6 +30,7 @@
 
 #include <dbus/dbus-glib.h>
 #include <nm-connection.h>
+#include <nm-client.h>
 
 typedef void (*PageNewConnectionResultFunc) (NMConnection *connection,
                                              gboolean canceled,
@@ -67,6 +68,7 @@ typedef struct {
 
 	NMConnection *connection;
 	GtkWindow *parent_window;
+	NMClient *client;
 
 	gboolean disposed;
 } CEPage;
@@ -75,7 +77,8 @@ typedef struct {
 	GObjectClass parent;
 
 	/* Virtual functions */
-	gboolean    (*validate)    (CEPage *self, NMConnection *connection, GError **error);
+	gboolean    (*validate)     (CEPage *self, NMConnection *connection, GError **error);
+	char **     (*get_mac_list) (CEPage *self);
 
 	/* Signals */
 	void        (*changed)     (CEPage *self);
@@ -85,6 +88,7 @@ typedef struct {
 
 typedef CEPage* (*CEPageNewFunc)(NMConnection *connection,
                                  GtkWindow *parent,
+                                 NMClient *client,
                                  const char **out_secrets_setting_name,
                                  GError **error);
 
@@ -97,6 +101,8 @@ const char * ce_page_get_title (CEPage *self);
 
 gboolean ce_page_validate (CEPage *self, NMConnection *connection, GError **error);
 
+char **ce_page_get_mac_list (CEPage *self);
+
 void ce_page_changed (CEPage *self);
 
 void ce_page_mac_to_entry (const GByteArray *mac, GtkEntry *entry);
@@ -126,6 +132,7 @@ NMConnection *ce_page_new_connection (const char *format,
 CEPage *ce_page_new (GType page_type,
                      NMConnection *connection,
                      GtkWindow *parent_window,
+                     NMClient *client,
                      const char *ui_file,
                      const char *widget_name,
                      const char *title);
diff --git a/src/connection-editor/nm-connection-editor.c b/src/connection-editor/nm-connection-editor.c
index 6132330..2a58561 100644
--- a/src/connection-editor/nm-connection-editor.c
+++ b/src/connection-editor/nm-connection-editor.c
@@ -686,7 +686,7 @@ add_page (NMConnectionEditor *editor,
 	g_return_val_if_fail (func != NULL, FALSE);
 	g_return_val_if_fail (connection != NULL, FALSE);
 
-	page = (*func) (connection, GTK_WINDOW (editor->window), &secrets_setting_name, error);
+	page = (*func) (connection, GTK_WINDOW (editor->window), editor->client, &secrets_setting_name, error);
 	if (page) {
 		g_object_set_data_full (G_OBJECT (page),
 		                        SECRETS_TAG,
diff --git a/src/connection-editor/page-dsl.c b/src/connection-editor/page-dsl.c
index 6f21eda..cb741f9 100644
--- a/src/connection-editor/page-dsl.c
+++ b/src/connection-editor/page-dsl.c
@@ -17,7 +17,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * (C) Copyright 2008 - 2010 Red Hat, Inc.
+ * (C) Copyright 2008 - 2011 Red Hat, Inc.
  */
 
 #include "config.h"
@@ -123,6 +123,7 @@ finish_setup (CEPageDsl *self, gpointer unused, GError *error, gpointer user_dat
 CEPage *
 ce_page_dsl_new (NMConnection *connection,
                  GtkWindow *parent_window,
+                 NMClient *client,
                  const char **out_secrets_setting_name,
                  GError **error)
 {
@@ -132,6 +133,7 @@ ce_page_dsl_new (NMConnection *connection,
 	self = CE_PAGE_DSL (ce_page_new (CE_TYPE_PAGE_DSL,
 	                                 connection,
 	                                 parent_window,
+	                                 client,
 	                                 UIDIR "/ce-page-dsl.ui",
 	                                 "DslPage",
 	                                 _("DSL")));
diff --git a/src/connection-editor/page-dsl.h b/src/connection-editor/page-dsl.h
index e373645..2679939 100644
--- a/src/connection-editor/page-dsl.h
+++ b/src/connection-editor/page-dsl.h
@@ -17,7 +17,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * (C) Copyright 2008 Red Hat, Inc.
+ * (C) Copyright 2008 - 2011 Red Hat, Inc.
  */
 
 #ifndef __PAGE_DSL_H__
@@ -49,6 +49,7 @@ GType ce_page_dsl_get_type (void);
 
 CEPage *ce_page_dsl_new (NMConnection *connection,
                          GtkWindow *parent,
+                         NMClient *client,
                          const char **out_secrets_setting_name,
                          GError **error);
 
diff --git a/src/connection-editor/page-ip4.c b/src/connection-editor/page-ip4.c
index f230c73..34f91c5 100644
--- a/src/connection-editor/page-ip4.c
+++ b/src/connection-editor/page-ip4.c
@@ -965,6 +965,7 @@ finish_setup (CEPageIP4 *self, gpointer unused, GError *error, gpointer user_dat
 CEPage *
 ce_page_ip4_new (NMConnection *connection,
                  GtkWindow *parent_window,
+                 NMClient *client,
                  const char **out_secrets_setting_name,
                  GError **error)
 {
@@ -975,6 +976,7 @@ ce_page_ip4_new (NMConnection *connection,
 	self = CE_PAGE_IP4 (ce_page_new (CE_TYPE_PAGE_IP4,
 	                                 connection,
 	                                 parent_window,
+	                                 client,
 	                                 UIDIR "/ce-page-ip4.ui",
 	                                 "IP4Page",
 	                                 _("IPv4 Settings")));
diff --git a/src/connection-editor/page-ip4.h b/src/connection-editor/page-ip4.h
index 034ec60..9a99729 100644
--- a/src/connection-editor/page-ip4.h
+++ b/src/connection-editor/page-ip4.h
@@ -17,7 +17,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * (C) Copyright 2008 Red Hat, Inc.
+ * (C) Copyright 2008 - 2011 Red Hat, Inc.
  */
 
 #ifndef __PAGE_IP4_H__
@@ -49,6 +49,7 @@ GType ce_page_ip4_get_type (void);
 
 CEPage *ce_page_ip4_new (NMConnection *connection,
                          GtkWindow *parent,
+                         NMClient *client,
                          const char **out_secrets_setting_name,
                          GError **error);
 
diff --git a/src/connection-editor/page-ip6.c b/src/connection-editor/page-ip6.c
index 0d6831a..97bebed 100644
--- a/src/connection-editor/page-ip6.c
+++ b/src/connection-editor/page-ip6.c
@@ -929,6 +929,7 @@ finish_setup (CEPageIP6 *self, gpointer unused, GError *error, gpointer user_dat
 CEPage *
 ce_page_ip6_new (NMConnection *connection,
                  GtkWindow *parent_window,
+                 NMClient *client,
                  const char **out_secrets_setting_name,
                  GError **error)
 {
@@ -939,6 +940,7 @@ ce_page_ip6_new (NMConnection *connection,
 	self = CE_PAGE_IP6 (ce_page_new (CE_TYPE_PAGE_IP6,
 	                                 connection,
 	                                 parent_window,
+	                                 client,
 	                                 UIDIR "/ce-page-ip6.ui",
 	                                 "IP6Page",
 	                                 _("IPv6 Settings")));
diff --git a/src/connection-editor/page-ip6.h b/src/connection-editor/page-ip6.h
index fd73a87..cbd93f0 100644
--- a/src/connection-editor/page-ip6.h
+++ b/src/connection-editor/page-ip6.h
@@ -17,7 +17,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * (C) Copyright 2008 Red Hat, Inc.
+ * (C) Copyright 2008 - 2011 Red Hat, Inc.
  */
 
 #ifndef __PAGE_IP6_H__
@@ -49,6 +49,7 @@ GType ce_page_ip6_get_type (void);
 
 CEPage *ce_page_ip6_new (NMConnection *connection,
                          GtkWindow *parent,
+                         NMClient *client,
                          const char **out_secrets_setting_name,
                          GError **error);
 
diff --git a/src/connection-editor/page-mobile.c b/src/connection-editor/page-mobile.c
index e27b9e1..042264d 100644
--- a/src/connection-editor/page-mobile.c
+++ b/src/connection-editor/page-mobile.c
@@ -363,6 +363,7 @@ finish_setup (CEPageMobile *self, gpointer unused, GError *error, gpointer user_
 CEPage *
 ce_page_mobile_new (NMConnection *connection,
                     GtkWindow *parent_window,
+                    NMClient *client,
                     const char **out_secrets_setting_name,
                     GError **error)
 {
@@ -372,6 +373,7 @@ ce_page_mobile_new (NMConnection *connection,
 	self = CE_PAGE_MOBILE (ce_page_new (CE_TYPE_PAGE_MOBILE,
 	                                    connection,
 	                                    parent_window,
+	                                    client,
 	                                    UIDIR "/ce-page-mobile.ui",
 	                                    "MobilePage",
 	                                    _("Mobile Broadband")));
diff --git a/src/connection-editor/page-mobile.h b/src/connection-editor/page-mobile.h
index 5db4b67..19d449e 100644
--- a/src/connection-editor/page-mobile.h
+++ b/src/connection-editor/page-mobile.h
@@ -17,7 +17,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * (C) Copyright 2008 Red Hat, Inc.
+ * (C) Copyright 2008 - 2011 Red Hat, Inc.
  */
 
 #ifndef __PAGE_MOBILE_H__
@@ -49,6 +49,7 @@ GType ce_page_mobile_get_type (void);
 
 CEPage *ce_page_mobile_new (NMConnection *connection,
                             GtkWindow *parent,
+                            NMClient *client,
                             const char **out_secrets_setting_name,
                             GError **error);
 
diff --git a/src/connection-editor/page-ppp.c b/src/connection-editor/page-ppp.c
index 9148dd6..a17ee8f 100644
--- a/src/connection-editor/page-ppp.c
+++ b/src/connection-editor/page-ppp.c
@@ -17,7 +17,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * (C) Copyright 2008 - 2010 Red Hat, Inc.
+ * (C) Copyright 2008 - 2011 Red Hat, Inc.
  */
 
 #include "config.h"
@@ -266,6 +266,7 @@ finish_setup (CEPagePpp *self, gpointer unused, GError *error, gpointer user_dat
 CEPage *
 ce_page_ppp_new (NMConnection *connection,
                  GtkWindow *parent_window,
+                 NMClient *client,
                  const char **out_secrets_setting_name,
                  GError **error)
 {
@@ -276,6 +277,7 @@ ce_page_ppp_new (NMConnection *connection,
 	self = CE_PAGE_PPP (ce_page_new (CE_TYPE_PAGE_PPP,
 	                                 connection,
 	                                 parent_window,
+	                                 client,
 	                                 UIDIR "/ce-page-ppp.ui",
 	                                 "PppPage",
 	                                 _("PPP Settings")));
diff --git a/src/connection-editor/page-ppp.h b/src/connection-editor/page-ppp.h
index 6960a36..ea9951e 100644
--- a/src/connection-editor/page-ppp.h
+++ b/src/connection-editor/page-ppp.h
@@ -17,7 +17,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * (C) Copyright 2008 Red Hat, Inc.
+ * (C) Copyright 2008 - 2011 Red Hat, Inc.
  */
 
 #ifndef __PAGE_PPP_H__
@@ -49,6 +49,7 @@ GType ce_page_ppp_get_type (void);
 
 CEPage *ce_page_ppp_new (NMConnection *connection,
                          GtkWindow *parent,
+                         NMClient *client,
                          const char **out_secrets_setting_name,
                          GError **error);
 
diff --git a/src/connection-editor/page-vpn.c b/src/connection-editor/page-vpn.c
index 0096def..19324c9 100644
--- a/src/connection-editor/page-vpn.c
+++ b/src/connection-editor/page-vpn.c
@@ -17,7 +17,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * (C) Copyright 2008 - 2010 Red Hat, Inc.
+ * (C) Copyright 2008 - 2011 Red Hat, Inc.
  */
 
 #include "config.h"
@@ -92,6 +92,7 @@ finish_setup (CEPageVpn *self, gpointer unused, GError *error, gpointer user_dat
 CEPage *
 ce_page_vpn_new (NMConnection *connection,
                  GtkWindow *parent_window,
+                 NMClient *client,
                  const char **out_secrets_setting_name,
                  GError **error)
 {
@@ -102,6 +103,7 @@ ce_page_vpn_new (NMConnection *connection,
 	self = CE_PAGE_VPN (ce_page_new (CE_TYPE_PAGE_VPN,
 	                                 connection,
 	                                 parent_window,
+	                                 client,
 	                                 NULL,
 	                                 NULL,
 	                                 _("VPN")));
diff --git a/src/connection-editor/page-vpn.h b/src/connection-editor/page-vpn.h
index 2173541..dad5ca4 100644
--- a/src/connection-editor/page-vpn.h
+++ b/src/connection-editor/page-vpn.h
@@ -17,7 +17,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * (C) Copyright 2008 Red Hat, Inc.
+ * (C) Copyright 2008 - 2011 Red Hat, Inc.
  */
 
 #ifndef __PAGE_VPN_H__
@@ -49,6 +49,7 @@ GType ce_page_vpn_get_type (void);
 
 CEPage *ce_page_vpn_new (NMConnection *connection,
                          GtkWindow *parent,
+                         NMClient *client,
                          const char **out_secrets_setting_name,
                          GError **error);
 
diff --git a/src/connection-editor/page-wired-security.c b/src/connection-editor/page-wired-security.c
index 30ee72b..1787087 100644
--- a/src/connection-editor/page-wired-security.c
+++ b/src/connection-editor/page-wired-security.c
@@ -99,6 +99,7 @@ finish_setup (CEPageWiredSecurity *self, gpointer unused, GError *error, gpointe
 CEPage *
 ce_page_wired_security_new (NMConnection *connection,
                             GtkWindow *parent_window,
+                            NMClient *client,
                             const char **out_secrets_setting_name,
                             GError **error)
 {
@@ -109,6 +110,7 @@ ce_page_wired_security_new (NMConnection *connection,
 	self = CE_PAGE_WIRED_SECURITY (ce_page_new (CE_TYPE_PAGE_WIRED_SECURITY,
 	                                            connection,
 	                                            parent_window,
+	                                            client,
 	                                            NULL,
 	                                            NULL,
 	                                            _("802.1x Security")));
diff --git a/src/connection-editor/page-wired-security.h b/src/connection-editor/page-wired-security.h
index 80bce08..38638c8 100644
--- a/src/connection-editor/page-wired-security.h
+++ b/src/connection-editor/page-wired-security.h
@@ -17,7 +17,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * (C) Copyright 2008 Red Hat, Inc.
+ * (C) Copyright 2008 - 2011 Red Hat, Inc.
  */
 
 #ifndef __PAGE_WIRED_SECURITY_H__
@@ -51,6 +51,7 @@ GType ce_page_wired_security_get_type (void);
 
 CEPage *ce_page_wired_security_new (NMConnection *connection,
                                     GtkWindow *parent,
+                                    NMClient *client,
                                     const char **out_secrets_setting_name,
                                     GError **error);
 
diff --git a/src/connection-editor/page-wired.c b/src/connection-editor/page-wired.c
index a225ee1..ba9345f 100644
--- a/src/connection-editor/page-wired.c
+++ b/src/connection-editor/page-wired.c
@@ -17,7 +17,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * (C) Copyright 2008 - 2010 Red Hat, Inc.
+ * (C) Copyright 2008 - 2011 Red Hat, Inc.
  */
 
 #include "config.h"
@@ -30,6 +30,7 @@
 
 #include <nm-setting-connection.h>
 #include <nm-setting-wired.h>
+#include <nm-device-ethernet.h>
 
 #include "page-wired.h"
 
@@ -40,8 +41,8 @@ G_DEFINE_TYPE (CEPageWired, ce_page_wired, CE_TYPE_PAGE)
 typedef struct {
 	NMSettingWired *setting;
 
-	GtkEntry *device_mac;  /* Permanent MAC of the device */
-	GtkEntry *cloned_mac;  /* Cloned MAC - used for MAC spoofing */
+	GtkComboBoxText *device_mac;  /* Permanent MAC of the device */
+	GtkEntry *cloned_mac;         /* Cloned MAC - used for MAC spoofing */
 	GtkComboBox *port;
 	GtkComboBox *speed;
 	GtkToggleButton *duplex;
@@ -71,7 +72,7 @@ wired_private_init (CEPageWired *self)
 
 	builder = CE_PAGE (self)->builder;
 
-	priv->device_mac = GTK_ENTRY (GTK_WIDGET (gtk_builder_get_object (builder, "wired_device_mac")));
+	priv->device_mac = GTK_COMBO_BOX_TEXT (GTK_WIDGET (gtk_builder_get_object (builder, "wired_device_mac")));
 	priv->cloned_mac = GTK_ENTRY (GTK_WIDGET (gtk_builder_get_object (builder, "wired_cloned_mac")));
 	priv->port = GTK_COMBO_BOX (GTK_WIDGET (gtk_builder_get_object (builder, "wired_port")));
 	priv->speed = GTK_COMBO_BOX (GTK_WIDGET (gtk_builder_get_object (builder, "wired_speed")));
@@ -96,6 +97,11 @@ populate_ui (CEPageWired *self)
 	int port_idx = PORT_DEFAULT;
 	int speed_idx;
 	int mtu_def;
+	char **mac_list, **iter;
+	const GByteArray *s_mac;
+	char *s_mac_str;
+	char *active_mac = NULL;
+	GtkWidget *entry;
 
 	/* Port */
 	port = nm_setting_wired_get_port (setting);
@@ -143,7 +149,28 @@ populate_ui (CEPageWired *self)
 	                              nm_setting_wired_get_auto_negotiate (setting));
 
 	/* Device MAC address */
-	ce_page_mac_to_entry (nm_setting_wired_get_mac_address (setting), priv->device_mac);
+	mac_list = ce_page_get_mac_list (CE_PAGE (self));
+	s_mac = nm_setting_wired_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++) {
+		gtk_combo_box_text_append_text (priv->device_mac, *iter);
+		if (s_mac_str && g_ascii_strncasecmp (*iter, s_mac_str, 17) == 0)
+			active_mac = *iter;
+	}
+
+	if (s_mac_str) {
+		if (!active_mac)
+			gtk_combo_box_text_prepend_text (priv->device_mac, s_mac_str);
+
+		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 (priv->device_mac, "changed", G_CALLBACK (stuff_changed), self);
 
 	/* Cloned MAC address */
@@ -197,6 +224,7 @@ finish_setup (CEPageWired *self, gpointer unused, GError *error, gpointer user_d
 CEPage *
 ce_page_wired_new (NMConnection *connection,
                    GtkWindow *parent_window,
+                   NMClient *client,
                    const char **out_secrets_setting_name,
                    GError **error)
 {
@@ -206,6 +234,7 @@ ce_page_wired_new (NMConnection *connection,
 	self = CE_PAGE_WIRED (ce_page_new (CE_TYPE_PAGE_WIRED,
 	                                   connection,
 	                                   parent_window,
+	                                   client,
 	                                   UIDIR "/ce-page-wired.ui",
 	                                   "WiredPage",
 	                                   _("Wired")));
@@ -236,6 +265,7 @@ ui_to_setting (CEPageWired *self)
 	guint32 speed;
 	GByteArray *device_mac = NULL;
 	GByteArray *cloned_mac = NULL;
+	GtkWidget *entry;
 
 	/* Port */
 	switch (gtk_combo_box_get_active (priv->port)) {
@@ -275,7 +305,9 @@ ui_to_setting (CEPageWired *self)
 		break;
 	}
 
-	device_mac = ce_page_entry_to_mac (priv->device_mac, NULL);
+	entry = gtk_bin_get_child (GTK_BIN (priv->device_mac));
+	if (entry)
+		device_mac = ce_page_entry_to_mac (GTK_ENTRY (entry), NULL);
 	cloned_mac = ce_page_entry_to_mac (priv->cloned_mac, NULL);
 
 	g_object_set (priv->setting,
@@ -302,12 +334,16 @@ validate (CEPage *page, NMConnection *connection, GError **error)
 	CEPageWiredPrivate *priv = CE_PAGE_WIRED_GET_PRIVATE (self);
 	gboolean invalid = FALSE;
 	GByteArray *ignore;
-
-	ignore = ce_page_entry_to_mac (priv->device_mac, &invalid);
-	if (invalid)
-		return FALSE;
-	if (ignore)
-		g_byte_array_free (ignore, TRUE);
+	GtkWidget *entry;
+
+	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);
+	}
 
 	ignore = ce_page_entry_to_mac (priv->cloned_mac, &invalid);
 	if (invalid)
@@ -319,6 +355,38 @@ validate (CEPage *page, NMConnection *connection, GError **error)
 	return nm_setting_verify (NM_SETTING (priv->setting), NULL, error);
 }
 
+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_ETHERNET (dev))
+			continue;
+
+		mac = nm_device_ethernet_get_permanent_hw_address (NM_DEVICE_ETHERNET (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_wired_init (CEPageWired *self)
 {
@@ -334,6 +402,7 @@ ce_page_wired_class_init (CEPageWiredClass *wired_class)
 
 	/* virtual methods */
 	parent_class->validate = validate;
+	parent_class->get_mac_list = get_mac_list;
 }
 
 
diff --git a/src/connection-editor/page-wired.h b/src/connection-editor/page-wired.h
index 6a6fd57..4a38568 100644
--- a/src/connection-editor/page-wired.h
+++ b/src/connection-editor/page-wired.h
@@ -17,7 +17,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * (C) Copyright 2008 Red Hat, Inc.
+ * (C) Copyright 2008 - 2011 Red Hat, Inc.
  */
 
 #ifndef __PAGE_WIRED_H__
@@ -49,6 +49,7 @@ GType ce_page_wired_get_type (void);
 
 CEPage *ce_page_wired_new (NMConnection *connection,
                            GtkWindow *parent,
+                           NMClient *client,
                            const char **out_secrets_setting_name,
                            GError **error);
 
diff --git a/src/connection-editor/page-wireless-security.c b/src/connection-editor/page-wireless-security.c
index 59d3578..eae0d93 100644
--- a/src/connection-editor/page-wireless-security.c
+++ b/src/connection-editor/page-wireless-security.c
@@ -17,7 +17,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * (C) Copyright 2008 - 2010 Red Hat, Inc.
+ * (C) Copyright 2008 - 2011 Red Hat, Inc.
  */
 
 #include "config.h"
@@ -345,6 +345,7 @@ finish_setup (CEPageWirelessSecurity *self, gpointer unused, GError *error, gpoi
 CEPage *
 ce_page_wireless_security_new (NMConnection *connection,
                                GtkWindow *parent_window,
+                               NMClient *client,
                                const char **out_secrets_setting_name,
                                GError **error)
 {
@@ -363,6 +364,7 @@ ce_page_wireless_security_new (NMConnection *connection,
 	self = CE_PAGE_WIRELESS_SECURITY (ce_page_new (CE_TYPE_PAGE_WIRELESS_SECURITY,
 	                                               connection,
 	                                               parent_window,
+	                                               client,
 	                                               UIDIR "/ce-page-wireless-security.ui",
 	                                               "WirelessSecurityPage",
 	                                               _("Wireless Security")));
diff --git a/src/connection-editor/page-wireless-security.h b/src/connection-editor/page-wireless-security.h
index d1cc529..6b099d3 100644
--- a/src/connection-editor/page-wireless-security.h
+++ b/src/connection-editor/page-wireless-security.h
@@ -17,7 +17,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * (C) Copyright 2008 Red Hat, Inc.
+ * (C) Copyright 2008 - 2011 Red Hat, Inc.
  */
 
 #ifndef __PAGE_WIRELESS_SECURITY_H__
@@ -56,6 +56,7 @@ GType ce_page_wireless_security_get_type (void);
 
 CEPage *ce_page_wireless_security_new (NMConnection *connection,
                                        GtkWindow *parent,
+                                       NMClient *client,
                                        const char **out_secrets_setting_name,
                                        GError **error);
 
diff --git a/src/connection-editor/page-wireless.c b/src/connection-editor/page-wireless.c
index d9c39a8..21ac5b1 100644
--- a/src/connection-editor/page-wireless.c
+++ b/src/connection-editor/page-wireless.c
@@ -30,6 +30,7 @@
 
 #include <nm-setting-connection.h>
 #include <nm-setting-wireless.h>
+#include <nm-device-wifi.h>
 #include <nm-utils.h>
 
 #include "page-wireless.h"
@@ -43,8 +44,8 @@ typedef struct {
 
 	GtkEntry *ssid;
 	GtkEntry *bssid;
-	GtkEntry *device_mac;    /* Permanent MAC of the device */
-	GtkEntry *cloned_mac;    /* Cloned MAC - used for MAC spoofing */
+	GtkComboBoxText *device_mac;  /* Permanent MAC of the device */
+	GtkEntry *cloned_mac;         /* Cloned MAC - used for MAC spoofing */
 	GtkComboBox *mode;
 	GtkComboBox *band;
 	GtkSpinButton *channel;
@@ -71,7 +72,7 @@ wireless_private_init (CEPageWireless *self)
 
 	priv->ssid     = GTK_ENTRY (GTK_WIDGET (gtk_builder_get_object (builder, "wireless_ssid")));
 	priv->bssid    = GTK_ENTRY (GTK_WIDGET (gtk_builder_get_object (builder, "wireless_bssid")));
-	priv->device_mac = GTK_ENTRY (GTK_WIDGET (gtk_builder_get_object (builder, "wireless_device_mac")));
+	priv->device_mac = GTK_COMBO_BOX_TEXT (GTK_WIDGET (gtk_builder_get_object (builder, "wireless_device_mac")));
 	priv->cloned_mac = GTK_ENTRY (GTK_WIDGET (gtk_builder_get_object (builder, "wireless_cloned_mac")));
 	priv->mode     = GTK_COMBO_BOX (GTK_WIDGET (gtk_builder_get_object (builder, "wireless_mode")));
 	priv->band     = GTK_COMBO_BOX (GTK_WIDGET (gtk_builder_get_object (builder, "wireless_band")));
@@ -269,6 +270,11 @@ populate_ui (CEPageWireless *self)
 	int tx_power_def;
 	int mtu_def;
 	char *utf8_ssid;
+	char **mac_list, **iter;
+	const GByteArray *s_mac;
+	char *s_mac_str;
+	char *active_mac = NULL;
+	GtkWidget *entry;
 
 	rate_def = ce_get_property_default (NM_SETTING (setting), NM_SETTING_WIRELESS_RATE);
 	g_signal_connect (priv->rate, "output",
@@ -343,7 +349,28 @@ populate_ui (CEPageWireless *self)
 	g_signal_connect_swapped (priv->bssid, "changed", G_CALLBACK (ce_page_changed), self);
 
 	/* Device MAC address */
-	ce_page_mac_to_entry (nm_setting_wireless_get_mac_address (setting), priv->device_mac);
+	mac_list = ce_page_get_mac_list (CE_PAGE (self));
+	s_mac = nm_setting_wireless_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++) {
+		gtk_combo_box_text_append_text (priv->device_mac, *iter);
+		if (s_mac_str && g_ascii_strncasecmp (*iter, s_mac_str, 17) == 0)
+			active_mac = *iter;
+	}
+
+	if (s_mac_str) {
+		if (!active_mac)
+			gtk_combo_box_text_prepend_text (priv->device_mac, s_mac_str);
+
+		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);
 
 	/* Cloned MAC address */
@@ -380,6 +407,7 @@ finish_setup (CEPageWireless *self, gpointer unused, GError *error, gpointer use
 CEPage *
 ce_page_wireless_new (NMConnection *connection,
                       GtkWindow *parent_window,
+                      NMClient *client,
                       const char **out_secrets_setting_name,
                       GError **error)
 {
@@ -391,6 +419,7 @@ ce_page_wireless_new (NMConnection *connection,
 	self = CE_PAGE_WIRELESS (ce_page_new (CE_TYPE_PAGE_WIRELESS,
 	                                      connection,
 	                                      parent_window,
+	                                      client,
 	                                      UIDIR "/ce-page-wireless.ui",
 	                                      "WirelessPage",
 	                                      _("Wireless")));
@@ -443,6 +472,7 @@ ui_to_setting (CEPageWireless *self)
 	GByteArray *cloned_mac = NULL;
 	const char *mode;
 	const char *band;
+	GtkWidget *entry;
 
 	ssid = ce_page_wireless_get_ssid (self);
 
@@ -465,7 +495,9 @@ ui_to_setting (CEPageWireless *self)
 	}
 
 	bssid = ce_page_entry_to_mac (priv->bssid, NULL);
-	device_mac = ce_page_entry_to_mac (priv->device_mac, NULL);
+	entry = gtk_bin_get_child (GTK_BIN (priv->device_mac));
+	if (entry)
+		device_mac = ce_page_entry_to_mac (GTK_ENTRY (entry), NULL);
 	cloned_mac = ce_page_entry_to_mac (priv->cloned_mac, NULL);
 
 	g_object_set (priv->setting,
@@ -500,6 +532,7 @@ validate (CEPage *page, NMConnection *connection, GError **error)
 	gboolean success;
 	gboolean invalid = FALSE;
 	GByteArray *ignore;
+	GtkWidget *entry;
 
 	ignore = ce_page_entry_to_mac (priv->bssid, &invalid);
 	if (invalid)
@@ -507,11 +540,14 @@ validate (CEPage *page, NMConnection *connection, GError **error)
 	if (ignore)
 		g_byte_array_free (ignore, TRUE);
 
-	ignore = ce_page_entry_to_mac (priv->device_mac, &invalid);
-	if (invalid)
-		return FALSE;
-	if (ignore)
-		g_byte_array_free (ignore, TRUE);
+	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);
+	}
 
 	ignore = ce_page_entry_to_mac (priv->cloned_mac, &invalid);
 	if (invalid)
@@ -532,6 +568,38 @@ validate (CEPage *page, NMConnection *connection, GError **error)
 	return success;
 }
 
+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_WIFI (dev))
+			continue;
+
+		mac = nm_device_wifi_get_permanent_hw_address (NM_DEVICE_WIFI (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_wireless_init (CEPageWireless *self)
 {
@@ -547,6 +615,7 @@ ce_page_wireless_class_init (CEPageWirelessClass *wireless_class)
 
 	/* virtual methods */
 	parent_class->validate = validate;
+	parent_class->get_mac_list = get_mac_list;
 }
 
 
diff --git a/src/connection-editor/page-wireless.h b/src/connection-editor/page-wireless.h
index 9010161..5ddb696 100644
--- a/src/connection-editor/page-wireless.h
+++ b/src/connection-editor/page-wireless.h
@@ -17,7 +17,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * (C) Copyright 2008 Red Hat, Inc.
+ * (C) Copyright 2008 - 2011 Red Hat, Inc.
  */
 
 #ifndef __PAGE_WIRELESS_H__
@@ -49,6 +49,7 @@ GType ce_page_wireless_get_type (void);
 
 CEPage *ce_page_wireless_new (NMConnection *connection,
                               GtkWindow *parent,
+                              NMClient *client,
                               const char **out_secrets_setting_name,
                               GError **error);
 



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