Commit a5b87782 authored by Jiří Klimeš's avatar Jiří Klimeš
Browse files

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.
parent 123e99b0
......@@ -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>
......
......@@ -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>
......
......@@ -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);
......
......@@ -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);
......
......@@ -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,
......
......@@ -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")));
......
......@@ -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);
......
......@@ -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")));
......
......@@ -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);
......
......@@ -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")));
......
......@@ -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);
......
......@@ -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")));
......
......@@ -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);
......
......@@ -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")));
......
......@@ -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);
......
......@@ -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")));
......
......@@ -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);
......
......@@ -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")));
......
......@@ -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);
......
......@@ -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;
}
......
......@@ -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);
......
......@@ -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")));
......
......@@ -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);
......