banshee r3839 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Query src/Core/Banshee.Services/Banshee.SmartPlaylist src/Libraries/Hyena/Hyena.Query



Author: gburt
Date: Mon Apr 28 22:53:55 2008
New Revision: 3839
URL: http://svn.gnome.org/viewvc/banshee?rev=3839&view=rev

Log:
2008-04-28  Gabriel Burt  <gabriel burt gmail com>

	* src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs:
	* src/Core/Banshee.Services/Banshee.SmartPlaylist/SmartPlaylistSource.cs:
	* src/Libraries/Hyena/Hyena.Query/QueryOrder.cs: Implement smart
	playlists limited by file size and duration.  Fixes BGO #522889.


Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.SmartPlaylist/SmartPlaylistSource.cs
   trunk/banshee/src/Libraries/Hyena/Hyena.Query/QueryOrder.cs

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs	Mon Apr 28 22:53:55 2008
@@ -67,8 +67,8 @@
 
         public static QueryLimit [] Limits = new QueryLimit [] {
             new QueryLimit ("songs",   Catalog.GetString ("items"), true),
-            new QueryLimit ("minutes", Catalog.GetString ("minutes"), "CoreTracks.Duration", (int) TimeFactor.Minute),
-            new QueryLimit ("hours",   Catalog.GetString ("hours"), "CoreTracks.Duration", (int) TimeFactor.Hour),
+            new QueryLimit ("minutes", Catalog.GetString ("minutes"), "CoreTracks.Duration/1000", (int) TimeFactor.Minute),
+            new QueryLimit ("hours",   Catalog.GetString ("hours"), "CoreTracks.Duration/1000", (int) TimeFactor.Hour),
             new QueryLimit ("MB",      Catalog.GetString ("MB"), "CoreTracks.FileSize", (int) FileSizeFactor.MB),
             new QueryLimit ("GB",      Catalog.GetString ("GB"), "CoreTracks.FileSize", (int) FileSizeFactor.GB)
         };

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.SmartPlaylist/SmartPlaylistSource.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.SmartPlaylist/SmartPlaylistSource.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.SmartPlaylist/SmartPlaylistSource.cs	Mon Apr 28 22:53:55 2008
@@ -148,14 +148,12 @@
             set { limit = value; }
         }
 
-        protected string OrderAndLimit {
-            get {
-                if (IsLimited) {
-                    return String.Format ("{0} {1}", QueryOrder.ToSql (), Limit.ToSql (LimitValue));
-                } else {
-                    return null;
-                }
-            }
+        protected string OrderSql {
+            get { return QueryOrder == null ? null : QueryOrder.ToSql (); }
+        }
+
+        protected string LimitSql {
+            get { return IsLimited ? Limit.ToSql (LimitValue) : null; }
         }
 
         public bool IsLimited {
@@ -321,15 +319,50 @@
         public void Refresh ()
         {
             // Wipe the member list clean and repopulate it 
-            ServiceManager.DbConnection.Execute (String.Format (
+            string reload_str = String.Format (
                 @"DELETE FROM CoreSmartPlaylistEntries WHERE SmartPlaylistID = {0};
                   INSERT INTO CoreSmartPlaylistEntries 
                     SELECT NULL, {0} as SmartPlaylistID, TrackId
                         FROM CoreTracks, CoreArtists, CoreAlbums
-                        WHERE CoreTracks.ArtistID = CoreArtists.ArtistID AND CoreTracks.AlbumID = CoreAlbums.AlbumID AND CoreTracks.PrimarySourceID = {3}
-                        {1} {2}",
-                DbId, PrependCondition("AND"), OrderAndLimit, PrimarySourceId
-            ));
+                        WHERE CoreTracks.ArtistID = CoreArtists.ArtistID AND CoreTracks.AlbumID = CoreAlbums.AlbumID AND CoreTracks.PrimarySourceID = {1}
+                        {2} {3} {4}",
+                DbId, PrimarySourceId, PrependCondition("AND"), OrderSql, LimitSql
+            );
+            ServiceManager.DbConnection.Execute (reload_str);
+
+            // If the smart playlist is limited by file size or media duration, limit it here
+            if (IsLimited && !Limit.RowBased) {
+                // Identify where the cut off mark is
+                HyenaSqliteCommand limit_command = new HyenaSqliteCommand (String.Format (
+                    @"SELECT EntryID, {0} 
+                      FROM CoreTracks, CoreSmartPlaylistEntries
+                      WHERE SmartPlaylistID = {1} AND CoreSmartPlaylistEntries.TrackID = CoreTracks.TrackID
+                      ORDER BY EntryID",
+                    Limit.Column, DbId
+                ));
+
+                long limit = LimitValue.IntValue *  Limit.Factor;
+                long sum = 0;
+                long? cut_off_id = null;
+                using (IDataReader reader = ServiceManager.DbConnection.Query (limit_command)) {
+                    while (reader.Read ()) {
+                        sum += Convert.ToInt64 (reader[1]);
+                        if (sum > limit) {
+                            cut_off_id = Convert.ToInt64 (reader[0]);
+                            break;
+                        }
+                    }
+                }
+
+                // Remove the playlist entries after the cut off
+                if (cut_off_id != null) {
+                    ServiceManager.DbConnection.Execute (new HyenaSqliteCommand (
+                        "DELETE FROM CoreSmartPlaylistEntries WHERE SmartPlaylistID = ? AND EntryID >= ?",
+                        DbId, cut_off_id
+                    ));
+                }
+            }
+
             refreshed = true;
         }
 

Modified: trunk/banshee/src/Libraries/Hyena/Hyena.Query/QueryOrder.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena.Query/QueryOrder.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.Query/QueryOrder.cs	Mon Apr 28 22:53:55 2008
@@ -62,26 +62,5 @@
         {
             return String.Format ("ORDER BY {0}", order_sql);
         }
-
-        public string PruneSql (QueryLimit limit, IntegerQueryValue limit_value)
-        {
-            /*"SELECT {0}, {1} FROM {2}", "OrderID", limit.Column, "CoreCache";
-
-            long limit = limit_value.IntValue *  limit.Factor;
-            long sum = 0;
-            int? limit_id = null;
-            foreach (result) {
-                sum += result[1];
-                if (sum >= limit) {
-                    limit_id = result[0];
-                    break;
-                }
-            }
-
-            if (limit_id != null) {
-                "DELETE FROM {0} WHERE {1} > {2}", "CoreCache", "OrderID", limit_id
-            }*/
-            return null;
-        }
     }
 }



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