Re: [Banshee-List] Help get us to a release/Last steps in portingsmartplaylists



More than likely missing something, but here goes.
There's also some debug spew uncommented in here - I'll remove it prior to
commit.

Index: src/Core/Banshee.Services/Banshee.SmartPlaylist/SmartPlaylistCore.cs
===================================================================
---
src/Core/Banshee.Services/Banshee.SmartPlaylist/SmartPlaylistCore.cs	(revision
3365)
+++
src/Core/Banshee.Services/Banshee.SmartPlaylist/SmartPlaylistCore.cs	(working
copy)
@@ -287,12 +287,12 @@
     // Class used for timing different operations.  Commented out for
normal operation.
     public class Timer
     {
-        //DateTime time;
-        //string name;
-        //string details;
+        DateTime time;
+        string name;
+        string details;
 
-        //static Dictionary<string, double> running_totals = new
Dictionary<string, double>();
-        //static Dictionary<string, int> running_counts = new
Dictionary<string, int>();
+        static Dictionary<string, double> running_totals = new
Dictionary<string, double>();
+        static Dictionary<string, int> running_counts = new
Dictionary<string, int>();
 
         public Timer () : this ("Timer") {}
 
@@ -300,7 +300,7 @@
 
         public Timer (string name, string details)
         {
-            /*this.name = name;
+            this.name = name;
             this.details = (details == null) ? "" : " (" + details + ")";
 
             if (!running_totals.ContainsKey(name)) {
@@ -308,29 +308,29 @@
                 running_counts.Add(name, 0);
             }
 
-            time = DateTime.Now;*/
+            time = DateTime.Now;
 
-            //System.Console.WriteLine ("{0} started", name);
+            System.Console.WriteLine ("{0} started", name);
         }
 
         public void Stop ()
         {
-            /*double elapsed = (DateTime.Now - time).TotalSeconds;
+            double elapsed = (DateTime.Now - time).TotalSeconds;
             System.Console.WriteLine ("{0}{1} stopped: {2} seconds
elapsed", name, details, elapsed);
             running_totals[name] += elapsed;
             //running_totals[name+details] += elapsed;
             running_counts[name]++;
-            //running_counts[name+details]++;*/
+            //running_counts[name+details]++;
         }
 
         public static void PrintRunningTotals ()
         {
-            /*Console.WriteLine("Running totals:");
+            Console.WriteLine("Running totals:");
             foreach (string k in running_totals.Keys) {
                 //if (running_totals[k] > .1) {
                     Console.WriteLine("{0}, {1}, {2}", k,
running_counts[k], running_totals[k]);
                 //}
-            }*/
+            }
         }
     }
 
Index:
src/Core/Banshee.Services/Banshee.SmartPlaylist/SmartPlaylistSource.cs
===================================================================
---
src/Core/Banshee.Services/Banshee.SmartPlaylist/SmartPlaylistSource.cs	(revision
3365)
+++
src/Core/Banshee.Services/Banshee.SmartPlaylist/SmartPlaylistSource.cs	(working
copy)
@@ -147,9 +147,8 @@
             get { return dependencies.Count > 0; }
         }
 
-        // FIXME scan ConditionTree for date fields
         public bool TimeDependent {
-            get { return false; }
+            get { return IsTimeDependent (ConditionTree); }
         }
 
 #endregion
@@ -366,5 +365,47 @@
                 }
             }
         }
+        
+        private bool IsTimeDependent (QueryNode node) {
+            if (node == null) {
+                return false;
+            }
+            
+            // See if the QueryNode is capable of having babies.
+            QueryListNode parent = node as QueryListNode;
+            
+            if (parent != null) {
+                // Loop through the children and run the function
recursively.
+                foreach (QueryNode child in parent.Children) {
+                    QueryTermNode term = child as QueryTermNode;
+                    if (IsTimeDependent (term)) {
+                        return true;
+                    }
+                }
+            } else {
+                // Was a poor lonely QueryTerm on its own.
+                QueryTermNode term = node as QueryTermNode;
+                return IsTimeDependent (term);
+            }
+            
+            // If we get here, we were a QueryListNode with no children.
+            return false;
+        }
+        
+        private bool IsTimeDependent (QueryTermNode term)
+        {
+            if (term != null && (term.Field ==
BansheeQuery.LastPlayedField ||
+                                 term.Field ==
BansheeQuery.DateAddedField)) {
+                return true;
+            } else if (term != null && this.QueryOrder != null) {
+                if (this.QueryOrder.OrderSql.Contains
(BansheeQuery.LastPlayedField.Column) ||
+                    this.QueryOrder.OrderSql.Contains
(BansheeQuery.DateAddedField.Column)) {
+                    
+                    return true;
+                }
+            }
+            
+            return false;
+        }
     }
 }

Attachment: cdiff
Description: Binary data



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