[totem/gsettings: 17/20] Convert connection-speed to an enum



commit 70ff4ca714ed037cd9c5f3542c78e2d3300b8b1b
Author: Philip Withnall <philip tecnocode co uk>
Date:   Thu Aug 19 09:35:46 2010 +0100

    Convert connection-speed to an enum

 data/org.gnome.totem.gschema.xml.in.in    |    6 ++--
 src/backend/bacon-video-widget-gst-0.10.c |    4 +-
 src/totem-preferences.c                   |   39 ++++++++++++++++++++++++++++-
 3 files changed, 43 insertions(+), 6 deletions(-)
---
diff --git a/data/org.gnome.totem.gschema.xml.in.in b/data/org.gnome.totem.gschema.xml.in.in
index 160efd4..5443366 100644
--- a/data/org.gnome.totem.gschema.xml.in.in
+++ b/data/org.gnome.totem.gschema.xml.in.in
@@ -35,10 +35,10 @@
 			<default>false</default>
 			<_summary>Resize the canvas automatically on file load</_summary>
 		</key>
-		<key name="connection-speed" type="i">
-			<default>11</default>
+		<key name="connection-speed" enum="org.gnome.totem.BvwConnectionSpeed">
+			<default>'lan'</default>
 			<_summary>Network connection speed</_summary>
-			<_description>Approximate network connection speed, used to select quality on media over the network: "0" for 14.4 Kbps Modem, "1" for 19.2 Kbps Modem, "2" for 28.8 Kbps Modem, "3" for 33.6 Kbps Modem, "4" for 34.4 Kbps Modem, "5" for 56 Kbps Modem/ISDN, "6" for 112 Kbps Dual ISDN/DSL, "7" for 256 Kbps DSL/Cable, "8" for 384 Kbps DSL/Cable, "9" for 512 Kbps DSL/Cable, "10" for 1.5 Mbps T1/Intranet/LAN, "11" for Intranet/LAN.</_description>
+			<_description>Approximate network connection speed, used to select quality on media over the network.</_description>
 		</key>
 		<key name="repeat" type="b">
 			<default>false</default>
diff --git a/src/backend/bacon-video-widget-gst-0.10.c b/src/backend/bacon-video-widget-gst-0.10.c
index f9fcfad..7e6be6d 100644
--- a/src/backend/bacon-video-widget-gst-0.10.c
+++ b/src/backend/bacon-video-widget-gst-0.10.c
@@ -3276,7 +3276,7 @@ bacon_video_widget_set_connection_speed (BaconVideoWidget * bvw, int speed)
 
   if (bvw->priv->connection_speed != speed) {
     bvw->priv->connection_speed = speed;
-    g_settings_set_int (bvw->priv->settings, "connection-speed", speed);
+    g_settings_set_enum (bvw->priv->settings, "connection-speed", speed);
     g_object_notify (G_OBJECT (bvw), "connection-speed");
   }
 
@@ -7119,7 +7119,7 @@ bacon_video_widget_new (int width, int height,
   }
 
   /* tv/conn (not used yet) */
-  value = g_settings_get_int (bvw->priv->settings, "connection-speed");
+  value = g_settings_get_enum (bvw->priv->settings, "connection-speed");
   if (value > 0) {
     bacon_video_widget_set_connection_speed (bvw, value);
   } else {
diff --git a/src/totem-preferences.c b/src/totem-preferences.c
index 667f9d4..71d6cd4 100644
--- a/src/totem-preferences.c
+++ b/src/totem-preferences.c
@@ -35,6 +35,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
+#include "bacon-video-widget-enums.h"
 #include "totem.h"
 #include "totem-private.h"
 #include "totem-preferences.h"
@@ -346,6 +347,40 @@ encoding_changed_cb (GSettings *settings, const gchar *key, TotemObject *totem)
 	g_free (encoding);
 }
 
+static gboolean
+int_enum_get_mapping (GValue *value, GVariant *variant, GEnumClass *enum_class)
+{
+	GEnumValue *enum_value;
+	const gchar *nick;
+
+	g_return_val_if_fail (G_IS_ENUM_CLASS (enum_class), FALSE);
+
+	nick = g_variant_get_string (variant, NULL);
+	enum_value = g_enum_get_value_by_nick (enum_class, nick);
+
+	if (enum_value == NULL)
+		return FALSE;
+
+	g_value_set_int (value, enum_value->value);
+
+	return TRUE;
+}
+
+static GVariant *
+int_enum_set_mapping (const GValue *value, const GVariantType *expected_type, GEnumClass *enum_class)
+{
+	GEnumValue *enum_value;
+
+	g_return_val_if_fail (G_IS_ENUM_CLASS (enum_class), NULL);
+
+	enum_value = g_enum_get_value (enum_class, g_value_get_int (value));
+
+	if (enum_value == NULL)
+		return NULL;
+
+	return g_variant_new_string (enum_value->value_nick);
+}
+
 void
 totem_setup_preferences (Totem *totem)
 {
@@ -424,8 +459,10 @@ totem_setup_preferences (Totem *totem)
 
 	/* Connection Speed */
 	item = gtk_builder_get_object (totem->xml, "tpw_speed_combobox");
-	g_settings_bind (totem->settings, "connection-speed", item, "active", G_SETTINGS_BIND_DEFAULT);
 	g_settings_bind (totem->settings, "connection-speed", bvw, "connection-speed", G_SETTINGS_BIND_DEFAULT);
+	g_settings_bind_with_mapping (totem->settings, "connection-speed", item, "active", G_SETTINGS_BIND_DEFAULT,
+	                              (GSettingsBindGetMapping) int_enum_get_mapping, (GSettingsBindSetMapping) int_enum_set_mapping,
+	                              g_type_class_ref (BVW_TYPE_CONNECTION_SPEED), (GDestroyNotify) g_type_class_unref);
 
 	/* Enable visuals */
 	item = gtk_builder_get_object (totem->xml, "tpw_visuals_checkbutton");



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