hal: Branch 'master'

Danny Kukawka dkukawka at kemper.freedesktop.org
Mon Mar 5 03:14:13 PST 2007


 doc/spec/hal-spec-fdi-files.xml |    4 +-
 hald/device.c                   |   64 ++++++++++++++++++++++++++++++++++++++++
 hald/device.h                   |    3 +
 3 files changed, 70 insertions(+), 1 deletion(-)

New commits:
diff-tree 6a82c2e0e1d1cf52fd812a26ceafc571c38aa4e0 (from 0c16761e61064979daa7b39ce0083f064676e578)
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Mon Mar 5 12:14:06 2007 +0100

    add copy_property FDI directive for stringlist properties
    
    This adds support of the copy_property FDI directive for stringlist
    properties. This would allow to copy/overwrite a stringlist with
    values from e.g. an other device.

diff --git a/doc/spec/hal-spec-fdi-files.xml b/doc/spec/hal-spec-fdi-files.xml
index 667171a..81656bc 100644
--- a/doc/spec/hal-spec-fdi-files.xml
+++ b/doc/spec/hal-spec-fdi-files.xml
@@ -166,7 +166,9 @@
           <literal>strlist</literal> - For <literal>&#60;merge&#62;</literal> the value is
           copied to the property and the current property will be overwritten. For
           <literal>&#60;append&#62;</literal> and <literal>&#60;prepend&#62;</literal> the
-          value is append or prepend to the list as new item.
+          value is append or prepend to the list as new item. Usage of 
+	  <literal>&#60;copy_property&#62;</literal> overwrite the complete list with the 
+	  value of the given property to copy from.
         </para>
       </listitem>
       <listitem>
diff --git a/hald/device.c b/hald/device.c
index a28eb80..a9b67f8 100644
--- a/hald/device.c
+++ b/hald/device.c
@@ -1146,6 +1146,65 @@ hal_device_property_set_double (HalDevic
 }
 
 gboolean
+hal_device_property_set_strlist (HalDevice *device, const char *key,
+			 	 GSList *value)
+{
+	HalProperty *prop;
+	GSList *l;
+
+	/* check if property already exists */
+	prop = hal_device_property_find (device, key);
+
+	if (prop != NULL) {
+		GSList *current;
+
+		if (hal_property_get_type (prop) != HAL_PROPERTY_TYPE_STRLIST) 
+			return FALSE;
+
+		/* don't bother setting the same value */
+		current = hal_property_get_strlist (prop);
+		if (g_slist_length (value) == g_slist_length (current)) {
+			gboolean equal = TRUE;		
+			for (l = value; l != NULL; l = l->next, current = current->next) {
+				if (strcmp (l->data, current->data) != 0) {
+ 					equal = FALSE;
+					break;
+				} 
+			}
+			if (equal) return TRUE;
+		}
+
+		/* TODO: check why  hal_property_strlist_clear (prop) not work and why
+		 *       we need to remove the key and a new one to get this running:
+		 *	 - multiple copy calls mixed with e.g. append rules   
+		 */
+
+		g_hash_table_remove (device->private->props, key);
+		prop = hal_property_new (HAL_PROPERTY_TYPE_STRLIST);
+		for (l = value ; l != NULL; l = l->next) {
+			hal_property_strlist_append (prop, l->data);
+		}
+		g_hash_table_insert (device->private->props, g_strdup (key), prop);
+
+		g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
+			       key, FALSE, FALSE);
+
+	} else {
+		prop = hal_property_new (HAL_PROPERTY_TYPE_STRLIST);
+		for (l = value ; l != NULL; l = l->next) {
+			hal_property_strlist_append (prop, l->data);
+		}
+		g_hash_table_insert (device->private->props, g_strdup (key), prop);
+
+		g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
+			       key, FALSE, TRUE);
+	}
+
+	return TRUE;
+}
+
+
+gboolean
 hal_device_copy_property (HalDevice *from_device, const char *from, HalDevice *to_device, const char *to)
 {
 	gboolean rc;
@@ -1174,6 +1233,11 @@ hal_device_copy_property (HalDevice *fro
 			rc = hal_device_property_set_double (
 				to_device, to, hal_device_property_get_double (from_device, from));
 			break;
+		case HAL_PROPERTY_TYPE_STRLIST:
+			rc = hal_device_property_set_strlist(
+				to_device, to, hal_device_property_get_strlist (from_device, from));
+			break;
+		break;
 		}
 	}
 
diff --git a/hald/device.h b/hald/device.h
index da7a0f8..5bab299 100644
--- a/hald/device.h
+++ b/hald/device.h
@@ -163,6 +163,9 @@ gboolean      hal_device_property_set_bo
 gboolean      hal_device_property_set_double (HalDevice    *device,
 					      const char   *key,
 					      double        value);
+gboolean      hal_device_property_set_strlist (HalDevice *device, 
+					       const char *key,
+                                 	       GSList *value);
 gboolean      hal_device_property_strlist_append (HalDevice    *device,
 						  const char   *key,
 						  const char *value);


More information about the hal-commit mailing list