Commit d12d4073 authored by Dan Winship's avatar Dan Winship

connection-editor: further simplify MAC combos

Move more duplicated code into CEPage, for setting up the "Device MAC"
combo boxes.
parent 2bc96579
......@@ -157,6 +157,46 @@ ce_page_get_mac_list (CEPage *self, GType device_type, const char *mac_property)
return (char **)g_ptr_array_free (macs, FALSE);
}
void
ce_page_setup_mac_combo (CEPage *self, GtkComboBox *combo,
const char *current_mac, char **mac_list)
{
char **iter, *active_mac = NULL;
int current_mac_len;
GtkWidget *entry;
if (current_mac)
current_mac_len = strlen (current_mac);
else
current_mac_len = -1;
for (iter = mac_list; iter && *iter; iter++) {
#if GTK_CHECK_VERSION (2,24,0)
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), *iter);
#else
gtk_combo_box_append_text (combo, *iter);
#endif
if ( current_mac
&& g_ascii_strncasecmp (*iter, current_mac, current_mac_len) == 0
&& ((*iter)[current_mac_len] == '\0' || (*iter)[current_mac_len] == ' '))
active_mac = *iter;
}
if (current_mac) {
if (!active_mac) {
#if GTK_CHECK_VERSION (2,24,0)
gtk_combo_box_text_prepend_text (GTK_COMBO_BOX_TEXT (combo), current_mac);
#else
gtk_combo_box_prepend_text (combo, current_mac_str);
#endif
}
entry = gtk_bin_get_child (GTK_BIN (combo));
if (entry)
gtk_entry_set_text (GTK_ENTRY (entry), active_mac ? active_mac : current_mac);
}
}
void
ce_page_mac_to_entry (const GByteArray *mac, int type, GtkEntry *entry)
{
......
......@@ -110,6 +110,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, GType device_type, const char *mac_property);
void ce_page_setup_mac_combo (CEPage *self, GtkComboBox *combo,
const char *current_mac, char **mac_list);
void ce_page_changed (CEPage *self);
......
......@@ -121,11 +121,9 @@ populate_ui (CEPageEthernet *self)
int port_idx = PORT_DEFAULT;
int speed_idx;
int mtu_def;
char **mac_list, **iter;
char **mac_list;
const GByteArray *s_mac;
char *s_mac_str;
char *active_mac = NULL;
GtkWidget *entry;
/* Port */
port = nm_setting_wired_get_port (setting);
......@@ -177,29 +175,8 @@ populate_ui (CEPageEthernet *self)
NM_DEVICE_ETHERNET_PERMANENT_HW_ADDRESS);
s_mac = nm_setting_wired_get_mac_address (setting);
s_mac_str = s_mac ? nm_utils_hwaddr_ntoa (s_mac->data, ARPHRD_ETHER) : 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);
}
ce_page_setup_mac_combo (CE_PAGE (self), GTK_COMBO_BOX (priv->device_mac),
s_mac_str, mac_list);
g_free (s_mac_str);
g_strfreev (mac_list);
g_signal_connect (priv->device_mac, "changed", G_CALLBACK (stuff_changed), self);
......
......@@ -99,11 +99,9 @@ populate_ui (CEPageInfiniband *self)
const char *mode;
int mode_idx = TRANSPORT_MODE_DATAGRAM;
int mtu_def;
char **mac_list, **iter;
char **mac_list;
const GByteArray *s_mac;
char *s_mac_str;
char *active_mac = NULL;
GtkWidget *entry;
/* Port */
mode = nm_setting_infiniband_get_transport_mode (setting);
......@@ -119,32 +117,9 @@ populate_ui (CEPageInfiniband *self)
mac_list = ce_page_get_mac_list (CE_PAGE (self), NM_TYPE_DEVICE_INFINIBAND,
NM_DEVICE_INFINIBAND_HW_ADDRESS);
s_mac = nm_setting_infiniband_get_mac_address (setting);
s_mac_str = s_mac ? nm_utils_hwaddr_ntoa (s_mac->data, ARPHRD_INFINIBAND):
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, 59) == 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);
}
s_mac_str = s_mac ? nm_utils_hwaddr_ntoa (s_mac->data, ARPHRD_INFINIBAND) : NULL;
ce_page_setup_mac_combo (CE_PAGE (self), GTK_COMBO_BOX (priv->device_mac),
s_mac_str, mac_list);
g_free (s_mac_str);
g_strfreev (mac_list);
g_signal_connect (priv->device_mac, "changed", G_CALLBACK (stuff_changed), self);
......
......@@ -293,11 +293,9 @@ populate_ui (CEPageWifi *self)
int tx_power_def;
int mtu_def;
char *utf8_ssid;
char **mac_list, **iter;
char **mac_list;
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",
......@@ -380,29 +378,8 @@ populate_ui (CEPageWifi *self)
NM_DEVICE_WIFI_PERMANENT_HW_ADDRESS);
s_mac = nm_setting_wireless_get_mac_address (setting);
s_mac_str = s_mac ? nm_utils_hwaddr_ntoa (s_mac->data, ARPHRD_ETHER) : 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);
}
ce_page_setup_mac_combo (CE_PAGE (self), GTK_COMBO_BOX (priv->device_mac),
s_mac_str, mac_list);
g_free (s_mac_str);
g_strfreev (mac_list);
g_signal_connect_swapped (priv->device_mac, "changed", G_CALLBACK (ce_page_changed), self);
......
......@@ -83,11 +83,9 @@ populate_ui (CEPageWimax *self)
{
CEPageWimaxPrivate *priv = CE_PAGE_WIMAX_GET_PRIVATE (self);
NMSettingWimax *setting = priv->setting;
char **mac_list, **iter;
char **mac_list;
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);
......@@ -97,29 +95,8 @@ populate_ui (CEPageWimax *self)
NM_DEVICE_WIMAX_HW_ADDRESS);
s_mac = nm_setting_wimax_get_mac_address (setting);
s_mac_str = s_mac ? nm_utils_hwaddr_ntoa (s_mac->data, ARPHRD_ETHER) : 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);
}
ce_page_setup_mac_combo (CE_PAGE (self), GTK_COMBO_BOX (priv->device_mac),
s_mac_str, mac_list);
g_free (s_mac_str);
g_strfreev (mac_list);
g_signal_connect_swapped (priv->device_mac, "changed", G_CALLBACK (ce_page_changed), self);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment