[network-manager-applet/lr/team: 3/6] editor: spins with default value need an input handler too



commit 7b516e693eb54096e42480e480945a21709b264c
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Thu Jul 14 16:24:44 2016 +0200

    editor: spins with default value need an input handler too
    
    Otherwise the default value gets converted to a string on output, but to
    a zero on input (which is not correct when the default value is not 0).

 src/connection-editor/ce-page.c |   35 +++++++++++++++++++++++++++++++++++
 src/connection-editor/ce-page.h |    4 ++++
 2 files changed, 39 insertions(+), 0 deletions(-)
---
diff --git a/src/connection-editor/ce-page.c b/src/connection-editor/ce-page.c
index 6b7678a..a0c0ac7 100644
--- a/src/connection-editor/ce-page.c
+++ b/src/connection-editor/ce-page.c
@@ -86,6 +86,41 @@ ce_spin_output_with_default (GtkSpinButton *spin, gpointer user_data)
                                                _("default"));
 }
 
+static gint
+spin_input_with_default_string (GtkSpinButton *spin,
+                                int defvalue,
+                                gdouble *new_val,
+                                const char *defstring)
+{
+       const gchar *buf;
+
+       buf = gtk_entry_get_text (GTK_ENTRY (spin));
+       if (strcmp (buf, defstring) == 0) {
+               *new_val = defvalue;
+               return TRUE;
+       }
+
+       return FALSE;
+}
+
+gint
+ce_spin_input_with_automatic (GtkSpinButton *spin, gdouble *new_val, gpointer user_data)
+{
+       return spin_input_with_default_string (spin,
+                                              GPOINTER_TO_INT (user_data),
+                                              new_val,
+                                              _("automatic"));
+}
+
+gint
+ce_spin_input_with_default (GtkSpinButton *spin, gdouble *new_val, gpointer user_data)
+{
+       return spin_input_with_default_string (spin,
+                                              GPOINTER_TO_INT (user_data),
+                                              new_val,
+                                              _("default"));
+}
+
 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 2e9e093..b479393 100644
--- a/src/connection-editor/ce-page.h
+++ b/src/connection-editor/ce-page.h
@@ -135,6 +135,10 @@ gboolean ce_spin_output_with_automatic (GtkSpinButton *spin, gpointer user_data)
 
 gboolean ce_spin_output_with_default (GtkSpinButton *spin, gpointer user_data);
 
+gboolean ce_spin_input_with_automatic (GtkSpinButton *spin, gdouble *new_val, gpointer user_data);
+
+gboolean ce_spin_input_with_default (GtkSpinButton *spin, gdouble *new_val, gpointer user_data);
+
 int ce_get_property_default (NMSetting *setting, const char *property_name);
 
 void ce_page_complete_init (CEPage *self,


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