[rygel] external: Translate search expression



commit 0f5abf90bbab948717fbe708a7472d2704f7ee3a
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Thu Jun 24 20:47:38 2010 +0300

    external: Translate search expression
    
    Translate search expression before sending it to external plugin as the
    names of properties are not the same in UPnP world and MediaServer2 D-Bus
    interface.

 src/plugins/external/rygel-external-container.vala |   47 +++++++++++++++++++-
 1 files changed, 46 insertions(+), 1 deletions(-)
---
diff --git a/src/plugins/external/rygel-external-container.vala b/src/plugins/external/rygel-external-container.vala
index 43eec19..54475dd 100644
--- a/src/plugins/external/rygel-external-container.vala
+++ b/src/plugins/external/rygel-external-container.vala
@@ -122,8 +122,9 @@ public class Rygel.ExternalContainer : Rygel.MediaContainer {
             filter += item_prop;
         }
 
+        var ext_expression = this.translate_expression (expression);
         var result = yield this.actual_container.search_objects (
-                                        expression.to_string (),
+                                        ext_expression.to_string (),
                                         offset,
                                         max_count,
                                         filter);
@@ -307,5 +308,49 @@ public class Rygel.ExternalContainer : Rygel.MediaContainer {
 
         return target;
     }
+
+    private SearchExpression translate_expression (
+                                        SearchExpression upnp_expression) {
+        if (upnp_expression is RelationalExpression) {
+            var expression = upnp_expression as RelationalExpression;
+            var ext_expression = new RelationalExpression ();
+            ext_expression.op = expression.op;
+            ext_expression.operand1 = this.translate_property (
+                                        expression.operand1);
+            ext_expression.operand2 = expression.operand2;
+
+            return ext_expression;
+        } else {
+            var expression = upnp_expression as LogicalExpression;
+            var ext_expression = new LogicalExpression ();
+
+            ext_expression.op = expression.op;
+            ext_expression.operand1 = this.translate_expression (
+                                        expression.operand1);
+            ext_expression.operand2 = this.translate_expression (
+                                        expression.operand2);
+
+            return ext_expression;
+        }
+    }
+
+    public string translate_property (string property) {
+        switch (property) {
+        case "@id":
+            return "Path";
+        case "@parentID":
+            return "Parent";
+        case "dc:title":
+            return "DisplayName";
+        case "dc:creator":
+        case "upnp:artist":
+        case "upnp:author":
+            return "Artist";
+        case "upnp:album":
+            return "Album";
+        default:
+            return property;
+        }
+    }
 }
 



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