[network-manager-applet/dcbw/dcb: 1/4] editor: generalize ce_spin_output_with_default()



commit 7e405363cc635dc9e513e0f29b76bf1c238d4742
Author: Dan Williams <dcbw redhat com>
Date:   Thu Oct 10 11:16:23 2013 -0500

    editor: generalize ce_spin_output_with_default()
    
    We'll use it for default value strings other than "automatic" soon,
    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'.

 src/connection-editor/ce-page.c         |   17 +++++++++++++----
 src/connection-editor/ce-page.h         |    2 +-
 src/connection-editor/page-ethernet.c   |    2 +-
 src/connection-editor/page-infiniband.c |    2 +-
 src/connection-editor/page-vlan.c       |    2 +-
 src/connection-editor/page-wifi.c       |    6 +++---
 6 files changed, 20 insertions(+), 11 deletions(-)
---
diff --git a/src/connection-editor/ce-page.c b/src/connection-editor/ce-page.c
index da5a429..7065db6 100644
--- a/src/connection-editor/ce-page.c
+++ b/src/connection-editor/ce-page.c
@@ -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)
 {
diff --git a/src/connection-editor/ce-page.h b/src/connection-editor/ce-page.h
index f5e96d6..794d20d 100644
--- a/src/connection-editor/ce-page.h
+++ b/src/connection-editor/ce-page.h
@@ -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);
 
diff --git a/src/connection-editor/page-ethernet.c b/src/connection-editor/page-ethernet.c
index 5c69572..d24a10f 100644
--- a/src/connection-editor/page-ethernet.c
+++ b/src/connection-editor/page-ethernet.c
@@ -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));
diff --git a/src/connection-editor/page-infiniband.c b/src/connection-editor/page-infiniband.c
index bcd01a4..937da39 100644
--- a/src/connection-editor/page-infiniband.c
+++ b/src/connection-editor/page-infiniband.c
@@ -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));
diff --git a/src/connection-editor/page-vlan.c b/src/connection-editor/page-vlan.c
index ff13387..c6aecce 100644
--- a/src/connection-editor/page-vlan.c
+++ b/src/connection-editor/page-vlan.c
@@ -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);
diff --git a/src/connection-editor/page-wifi.c b/src/connection-editor/page-wifi.c
index bf6c47d..d0a5617 100644
--- a/src/connection-editor/page-wifi.c
+++ b/src/connection-editor/page-wifi.c
@@ -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);
 


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