network-manager-applet r480 - in trunk: . src/connection-editor



Author: dcbw
Date: Sat Jan 26 03:56:31 2008
New Revision: 480
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=480&view=rev

Log:
2008-01-25  Dan Williams  <dcbw redhat com>

	* src/connection-editor/nm-connection-editor.glade
		- Fix some adjustments so the default value is valid

	* src/connection-editor/nm-connection-editor.c
		- (add_wired_page, add_wireless_page): handle showing the default value
			the correct way, using the 'output' signal rather than the asstastic
			hack that was there before



Modified:
   trunk/ChangeLog
   trunk/src/connection-editor/nm-connection-editor.c
   trunk/src/connection-editor/nm-connection-editor.glade

Modified: trunk/src/connection-editor/nm-connection-editor.c
==============================================================================
--- trunk/src/connection-editor/nm-connection-editor.c	(original)
+++ trunk/src/connection-editor/nm-connection-editor.c	Sat Jan 26 03:56:31 2008
@@ -21,6 +21,8 @@
  */
 
 #include <string.h>
+#include <math.h>
+
 #include <gtk/gtkcombobox.h>
 #include <gtk/gtkdialog.h>
 #include <gtk/gtkentry.h>
@@ -456,13 +458,39 @@
 	}
 }
 
-static void
-spin_value_changed_cb (GtkSpinButton *button, gpointer user_data)
+static gint
+adj_get_value_as_int (GtkAdjustment *adj)
+{
+  gdouble val;
+
+  g_return_val_if_fail (GTK_IS_ADJUSTMENT (adj), 0);
+
+  val = gtk_adjustment_get_value (adj);
+  if (val - floor (val) < ceil (val) - val)
+    return floor (val);
+  else
+    return ceil (val);
+}
+
+
+static gboolean
+spin_output_with_default (GtkSpinButton *spin, gpointer user_data)
 {
 	int defvalue = GPOINTER_TO_INT (user_data);
+	int val;
+	gchar *buf = NULL;
 
-	if (gtk_spin_button_get_value_as_int (button) == defvalue)
-		gtk_entry_set_text (GTK_ENTRY (button), _("default"));
+	val = adj_get_value_as_int (gtk_spin_button_get_adjustment (spin));
+	if (val == defvalue)
+		buf = g_strdup (_("default"));
+	else
+		buf = g_strdup_printf ("%d", val);
+
+	if (strcmp (buf, gtk_entry_get_text (GTK_ENTRY (spin))))
+		gtk_entry_set_text (GTK_ENTRY (spin), buf);
+
+	g_free (buf);
+	return TRUE;
 }
 
 static void
@@ -490,8 +518,8 @@
 
 	mtu = get_widget (editor, "wired_mtu");
 	mtu_def = get_property_default (NM_SETTING (s_wired), NM_SETTING_WIRED_MTU);
-	g_signal_connect (G_OBJECT (mtu), "changed",
-	                  (GCallback) spin_value_changed_cb,
+	g_signal_connect (G_OBJECT (mtu), "output",
+	                  (GCallback) spin_output_with_default,
 	                  GINT_TO_POINTER (mtu_def));
 
 	if (s_wired->port) {
@@ -532,7 +560,6 @@
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (autoneg), s_wired->auto_negotiate);
 
 	gtk_spin_button_set_value (GTK_SPIN_BUTTON (mtu), (gdouble) s_wired->mtu);
-	spin_value_changed_cb (GTK_SPIN_BUTTON (mtu), GINT_TO_POINTER (mtu_def));
 
 	/* FIXME: MAC address */
 }
@@ -651,20 +678,20 @@
 
 	rate = get_widget (editor, "wireless_rate");
 	rate_def = get_property_default (NM_SETTING (s_wireless), NM_SETTING_WIRELESS_RATE);
-	g_signal_connect (G_OBJECT (rate), "changed",
-	                  (GCallback) spin_value_changed_cb,
+	g_signal_connect (G_OBJECT (rate), "output",
+	                  (GCallback) spin_output_with_default,
 	                  GINT_TO_POINTER (rate_def));
 
 	tx_power = get_widget (editor, "wireless_tx_power");
 	tx_power_def = get_property_default (NM_SETTING (s_wireless), NM_SETTING_WIRELESS_TX_POWER);
-	g_signal_connect (G_OBJECT (tx_power), "changed",
-	                  (GCallback) spin_value_changed_cb,
+	g_signal_connect (G_OBJECT (tx_power), "output",
+	                  (GCallback) spin_output_with_default,
 	                  GINT_TO_POINTER (tx_power_def));
 
 	mtu = get_widget (editor, "wireless_mtu");
 	mtu_def = get_property_default (NM_SETTING (s_wireless), NM_SETTING_WIRELESS_MTU);
-	g_signal_connect (G_OBJECT (mtu), "changed",
-	                  (GCallback) spin_value_changed_cb,
+	g_signal_connect (G_OBJECT (mtu), "output",
+	                  (GCallback) spin_output_with_default,
 	                  GINT_TO_POINTER (mtu_def));
 
 	/* FIXME: SSID */
@@ -695,13 +722,8 @@
 	/* FIXME: MAC address */
 
 	gtk_spin_button_set_value (GTK_SPIN_BUTTON (rate), (gdouble) s_wireless->rate);
-	spin_value_changed_cb (GTK_SPIN_BUTTON (rate), GINT_TO_POINTER (rate_def));
-
 	gtk_spin_button_set_value (GTK_SPIN_BUTTON (tx_power), (gdouble) s_wireless->tx_power);
-	spin_value_changed_cb (GTK_SPIN_BUTTON (tx_power), GINT_TO_POINTER (tx_power_def));
-
 	gtk_spin_button_set_value (GTK_SPIN_BUTTON (mtu), (gdouble) s_wireless->mtu);
-	spin_value_changed_cb (GTK_SPIN_BUTTON (mtu), GINT_TO_POINTER (mtu_def));
 }
 
 static void

Modified: trunk/src/connection-editor/nm-connection-editor.glade
==============================================================================
--- trunk/src/connection-editor/nm-connection-editor.glade	(original)
+++ trunk/src/connection-editor/nm-connection-editor.glade	Sat Jan 26 03:56:31 2008
@@ -560,7 +560,7 @@
 	  <property name="update_policy">GTK_UPDATE_ALWAYS</property>
 	  <property name="snap_to_ticks">False</property>
 	  <property name="wrap">False</property>
-	  <property name="adjustment">0 1 100 1 10 10</property>
+	  <property name="adjustment">0 0 100 1 10 10</property>
 	</widget>
 	<packing>
 	  <property name="left_attach">1</property>
@@ -888,7 +888,7 @@
 	  <property name="update_policy">GTK_UPDATE_ALWAYS</property>
 	  <property name="snap_to_ticks">False</property>
 	  <property name="wrap">False</property>
-	  <property name="adjustment">0 1 100 1 10 10</property>
+	  <property name="adjustment">0 0 100 1 10 10</property>
 	</widget>
 	<packing>
 	  <property name="left_attach">1</property>
@@ -909,7 +909,7 @@
 	  <property name="update_policy">GTK_UPDATE_ALWAYS</property>
 	  <property name="snap_to_ticks">False</property>
 	  <property name="wrap">False</property>
-	  <property name="adjustment">0 1 100 1 10 10</property>
+	  <property name="adjustment">0 0 100 1 10 10</property>
 	</widget>
 	<packing>
 	  <property name="left_attach">1</property>
@@ -988,7 +988,7 @@
 	  <property name="update_policy">GTK_UPDATE_ALWAYS</property>
 	  <property name="snap_to_ticks">False</property>
 	  <property name="wrap">False</property>
-	  <property name="adjustment">0 1 100 1 10 10</property>
+	  <property name="adjustment">0 0 100 1 10 10</property>
 	</widget>
 	<packing>
 	  <property name="left_attach">1</property>



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