[rygel] tracker: Get rid of one level of 'if' nesting



commit e0058631526d3e1f80d87d164f12358d491dd204
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Thu Nov 12 16:35:17 2009 +0200

    tracker: Get rid of one level of 'if' nesting
    
    This makes create_query_from_expression() a bit more readable.

 .../tracker/rygel-tracker-search-container.vala    |   74 ++++++++++---------
 1 files changed, 39 insertions(+), 35 deletions(-)
---
diff --git a/src/plugins/tracker/rygel-tracker-search-container.vala b/src/plugins/tracker/rygel-tracker-search-container.vala
index e4040aa..91eafc4 100644
--- a/src/plugins/tracker/rygel-tracker-search-container.vala
+++ b/src/plugins/tracker/rygel-tracker-search-container.vala
@@ -204,58 +204,62 @@ public class Rygel.TrackerSearchContainer : Rygel.MediaContainer {
     private string? create_query_from_expression (SearchExpression expression) {
         string query = null;
 
-        if (expression != null && expression is RelationalExpression) {
-            var rel_expression = expression as RelationalExpression;
-            if (rel_expression.operand1 == "@id") {
-                string parent_id;
-                string service;
-
-                var path = this.get_item_info (rel_expression.operand2,
-                                               out parent_id,
-                                               out service);
-                if (path != null && parent_id != null && parent_id == this.id) {
-                    var dir = Path.get_dirname (path);
-                    var basename = Path.get_basename (path);
-
-                    var search_condition =
+        if (expression == null || !(expression is RelationalExpression)) {
+            return query;
+        }
+
+        var rel_expression = expression as RelationalExpression;
+        if (rel_expression.operand1 == "@id") {
+            string parent_id;
+            string service;
+
+            var path = this.get_item_info (rel_expression.operand2,
+                                           out parent_id,
+                                           out service);
+            if (path != null && parent_id != null && parent_id == this.id) {
+                var dir = Path.get_dirname (path);
+                var basename = Path.get_basename (path);
+
+                var search_condition =
                                         "<rdfq:and>\n" +
                                             "<rdfq:equals>\n" +
                                                 "<rdfq:Property " +
                                                     "name=\"File:Path\" />\n" +
-                                                    "<rdf:String>" + dir +
-                                                    "</rdf:String>\n" +
+                                                "<rdf:String>" +
+                                                    dir +
+                                                "</rdf:String>\n" +
                                             "</rdfq:equals>\n" +
                                             "<rdfq:equals>\n" +
                                                 "<rdfq:Property " +
                                                     "name=\"File:Name\" />\n" +
-                                                    "<rdf:String>" + basename +
-                                                    "</rdf:String>\n" +
+                                                "<rdf:String>" +
+                                                    basename +
+                                                "</rdf:String>\n" +
                                             "</rdfq:equals>\n" +
                                         "</rdfq:and>\n";
 
-                    if (this.query_condition != "") {
-                        query = "<rdfq:Condition>\n" +
-                                    "<rdfq:and>\n" +
-                                        search_condition +
-                                        this.query_condition +
-                                    "</rdfq:and>\n" +
-                                "</rdfq:Condition>";
-                    } else {
-                        query = "<rdfq:Condition>\n" +
-                                    search_condition +
-                                "</rdfq:Condition>";
-                    }
-                }
-            } else if (rel_expression.operand1 == "@parentID" &&
-                       rel_expression.compare_string (this.id)) {
                 if (this.query_condition != "") {
                     query = "<rdfq:Condition>\n" +
-                                this.query_condition +
+                                "<rdfq:and>\n" +
+                                    search_condition +
+                                    this.query_condition +
+                                "</rdfq:and>\n" +
                             "</rdfq:Condition>";
                 } else {
-                    query = "";
+                    query = "<rdfq:Condition>\n" +
+                                search_condition +
+                            "</rdfq:Condition>";
                 }
             }
+        } else if (rel_expression.operand1 == "@parentID" &&
+                   rel_expression.compare_string (this.id)) {
+            if (this.query_condition != "") {
+                query = "<rdfq:Condition>\n" +
+                            this.query_condition +
+                        "</rdfq:Condition>";
+            } else {
+                query = "";
+            }
         }
 
         return query;



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