Commit 55e34f33 authored by Dan Williams's avatar Dan Williams

editor: generalize ce_spin_output_with_default()

We may want to use this for default value strings other than
"automatic" in the future, so change the name to "automatic" and
pass the string to the generic helper that does the actual work.

Also, the return value for the "output" signal for the spinbutton
should be 'gboolean' not 'gint'.
parent 0a3ec428
......@@ -55,16 +55,17 @@ enum {
static guint signals[LAST_SIGNAL] = { 0 };
gint
ce_spin_output_with_default (GtkSpinButton *spin, gpointer user_data)
static gboolean
spin_output_with_default_string (GtkSpinButton *spin,
int defvalue,
const char *defstring)
{
int defvalue = GPOINTER_TO_INT (user_data);
int val;
gchar *buf = NULL;
val = gtk_spin_button_get_value_as_int (spin);
if (val == defvalue)
buf = g_strdup (_("automatic"));
buf = g_strdup (defstring);
else
buf = g_strdup_printf ("%d", val);
......@@ -75,6 +76,14 @@ ce_spin_output_with_default (GtkSpinButton *spin, gpointer user_data)
return TRUE;
}
gboolean
ce_spin_output_with_automatic (GtkSpinButton *spin, gpointer user_data)
{
return spin_output_with_default_string (spin,
GPOINTER_TO_INT (user_data),
_("automatic"));
}
int
ce_get_property_default (NMSetting *setting, const char *property_name)
{
......
......@@ -118,7 +118,7 @@ void ce_page_mac_to_entry (const GByteArray *mac, int type, GtkEntry *entry);
GByteArray *ce_page_entry_to_mac (GtkEntry *entry, int type, gboolean *invalid);
gint ce_spin_output_with_default (GtkSpinButton *spin, gpointer user_data);
gboolean ce_spin_output_with_automatic (GtkSpinButton *spin, gpointer user_data);
int ce_get_property_default (NMSetting *setting, const char *property_name);
......
......@@ -180,7 +180,7 @@ populate_ui (CEPageEthernet *self)
/* MTU */
mtu_def = ce_get_property_default (NM_SETTING (setting), NM_SETTING_WIRED_MTU);
g_signal_connect (priv->mtu, "output",
G_CALLBACK (ce_spin_output_with_default),
G_CALLBACK (ce_spin_output_with_automatic),
GINT_TO_POINTER (mtu_def));
gtk_spin_button_set_value (priv->mtu, (gdouble) nm_setting_wired_get_mtu (setting));
......
......@@ -118,7 +118,7 @@ populate_ui (CEPageInfiniband *self)
/* MTU */
mtu_def = ce_get_property_default (NM_SETTING (setting), NM_SETTING_INFINIBAND_MTU);
g_signal_connect (priv->mtu, "output",
G_CALLBACK (ce_spin_output_with_default),
G_CALLBACK (ce_spin_output_with_automatic),
GINT_TO_POINTER (mtu_def));
gtk_spin_button_set_value (priv->mtu, (gdouble) nm_setting_infiniband_get_mtu (setting));
......
......@@ -443,7 +443,7 @@ populate_ui (CEPageVlan *self)
mtu_def = mtu_val = 1500;
}
g_signal_connect (priv->mtu, "output",
G_CALLBACK (ce_spin_output_with_default),
G_CALLBACK (ce_spin_output_with_automatic),
GINT_TO_POINTER (mtu_def));
gtk_spin_button_set_value (priv->mtu, (gdouble) mtu_val);
......
......@@ -315,19 +315,19 @@ populate_ui (CEPageWifi *self)
rate_def = ce_get_property_default (NM_SETTING (setting), NM_SETTING_WIRELESS_RATE);
g_signal_connect (priv->rate, "output",
G_CALLBACK (ce_spin_output_with_default),
G_CALLBACK (ce_spin_output_with_automatic),
GINT_TO_POINTER (rate_def));
g_signal_connect_swapped (priv->rate, "value-changed", G_CALLBACK (ce_page_changed), self);
tx_power_def = ce_get_property_default (NM_SETTING (setting), NM_SETTING_WIRELESS_TX_POWER);
g_signal_connect (priv->tx_power, "output",
G_CALLBACK (ce_spin_output_with_default),
G_CALLBACK (ce_spin_output_with_automatic),
GINT_TO_POINTER (tx_power_def));
g_signal_connect_swapped (priv->tx_power, "value-changed", G_CALLBACK (ce_page_changed), self);
mtu_def = ce_get_property_default (NM_SETTING (setting), NM_SETTING_WIRELESS_MTU);
g_signal_connect (priv->mtu, "output",
G_CALLBACK (ce_spin_output_with_default),
G_CALLBACK (ce_spin_output_with_automatic),
GINT_TO_POINTER (mtu_def));
g_signal_connect_swapped (priv->mtu, "value-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