banshee r3949 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Collection.Database src/Core/Banshee.Services/Banshee.Database src/Core/Banshee.Services/Banshee.Query src/Core/Banshee.ThickClient/Banshee.Collection.Gui src/Extensions/Banshee.Podcasting/Banshee.Podcasting src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Gui/PodcastManager/Source src/Libraries/Hyena/Hyena.Data.Sqlite src/Libraries/Migo/Migo/Migo.Syndication



Author: gburt
Date: Wed May 21 23:52:08 2008
New Revision: 3949
URL: http://svn.gnome.org/viewvc/banshee?rev=3949&view=rev

Log:
2008-05-21  Gabriel Burt  <gabriel burt gmail com>

	* src/Extensions/Banshee.Podcasting/Banshee.Podcasting/PodcastService.cs:
	Migrate podcast feeds and items from 0.13.2 podcast plugin.

	* src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Gui/PodcastManager/Source/PodcastSource.cs:
	Allow sorting on download status and published date, make the default
	PubDate descending.

	* src/Core/Banshee.ThickClient/Banshee.Collection.Gui/XmlColumnController.cs:
	Allow defining the sort direction in addition to the default sort column.

	* src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs:
	Add an override for GetTrackForUri method.

	* src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackListModel.cs:
	Expose SortQuery via protected property, and make GenerateSortQueryPart
	virtual.

	* src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs:
	Skip items with non-local URIs.

	* src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs: Add FileSize
	sorting.

	* src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteConnection.cs: Add
	QueryEnumerable<T> methods.

	* src/Libraries/Migo/Migo/Migo.Syndication/FeedItem.cs:
	* src/Libraries/Migo/Migo/Migo.Syndication/FeedEnclosure.cs:
	* src/Libraries/Migo/Migo/Migo.Syndication/Feed.cs: Create the model
	within the Init function.


Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackListModel.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/XmlColumnController.cs
   trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Gui/PodcastManager/Source/PodcastSource.cs
   trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting/PodcastService.cs
   trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteConnection.cs
   trunk/banshee/src/Libraries/Migo/Migo/Migo.Syndication/Feed.cs
   trunk/banshee/src/Libraries/Migo/Migo/Migo.Syndication/FeedEnclosure.cs
   trunk/banshee/src/Libraries/Migo/Migo/Migo.Syndication/FeedItem.cs

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs	Wed May 21 23:52:08 2008
@@ -506,6 +506,12 @@
             "SELECT TrackID FROM CoreTracks WHERE PrimarySourceId IN (?) AND (Uri = ? OR Uri = ?) LIMIT 1"
         );
 
+        public static int GetTrackIdForUri (SafeUri uri, string relative_path, int [] primary_sources)
+        {
+            return ServiceManager.DbConnection.Query<int> (check_command,
+                primary_sources, relative_path, uri.AbsoluteUri);
+        }
+
         public static int GetTrackIdForUri (string relative_path, int [] primary_sources)
         {
             return ServiceManager.DbConnection.Query<int> (check_command,

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackListModel.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackListModel.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackListModel.cs	Wed May 21 23:52:08 2008
@@ -117,11 +117,16 @@
             get { return query_tree; }
         }
 
-        private void GenerateSortQueryPart ()
+        protected string SortQuery {
+            get { return sort_query; }
+            set { sort_query = value; }
+        }
+
+        protected virtual void GenerateSortQueryPart ()
         {
-            sort_query = (sort_column == null)
+            SortQuery = (SortColumn == null)
                 ? BansheeQuery.GetSort ("Artist", true)
-                : BansheeQuery.GetSort (sort_column.SortKey, sort_column.SortType == SortType.Ascending);
+                : BansheeQuery.GetSort (SortColumn.SortKey, SortColumn.SortType == SortType.Ascending);
         }
 
         public void Sort (ISortableColumn column)

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs	Wed May 21 23:52:08 2008
@@ -742,6 +742,9 @@
                     DatabaseTrackInfo track = null;
                     try {
                         track = DatabaseTrackInfo.Provider.Load (reader);
+
+                        if (!track.Uri.IsFile)
+                            continue;
                         
                         try {
                             TagLib.File file = StreamTagger.ProcessUri (track.Uri);

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	Wed May 21 23:52:08 2008
@@ -262,6 +262,7 @@
                 case "Rating":
                 case "PlayCount":
                 case "SkipCount":
+                case "FileSize":
                 case "LastPlayedStamp":
                 case "LastSkippedStamp":
                 case "DateAddedStamp":

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/XmlColumnController.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/XmlColumnController.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/XmlColumnController.cs	Wed May 21 23:52:08 2008
@@ -55,11 +55,15 @@
         private void ReadColumnController (XmlTextReader reader, int depth)
         {
             string sort_column = null;
+            bool sort_asc = true;
             
             while (reader.Read ()) {
                 if (reader.NodeType == XmlNodeType.Element) {
                     switch (reader.Name) {
-                        case "sort-column": sort_column = reader.ReadString (); break;
+                        case "sort-column":
+                            sort_asc = (reader.GetAttribute ("direction") != "desc");
+                            sort_column = reader.ReadString ();
+                            break;
                         case "column": ReadColumn (reader, reader.Depth); break;
                         case "add-all-defaults": AddDefaultColumns (); break;
                         case "add-default":
@@ -89,6 +93,7 @@
                     if (col.Id == sort_column) {
                         if (col is SortableColumn) {
                             DefaultSortColumn = col as SortableColumn;
+                            DefaultSortColumn.SortType = sort_asc ? SortType.Ascending : SortType.Descending;
                         } else {
                             Hyena.Log.WarningFormat ("Defined default sort column {0} is not a SortableColumn", sort_column);
                         }

Modified: trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Gui/PodcastManager/Source/PodcastSource.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Gui/PodcastManager/Source/PodcastSource.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Gui/PodcastManager/Source/PodcastSource.cs	Wed May 21 23:52:08 2008
@@ -58,10 +58,39 @@
     {
         public PodcastListModel (BansheeDbConnection conn, IDatabaseTrackModelProvider provider, DatabaseSource source) : base (conn, provider, source)
         {
-            JoinTable = String.Format ("{0}, {1}", Feed.Provider.TableName, FeedItem.Provider.TableName);
+            JoinTable = String.Format ("{0}, {1}, {2}", Feed.Provider.TableName, FeedItem.Provider.TableName, FeedEnclosure.Provider.TableName);
             JoinPrimaryKey = FeedItem.Provider.PrimaryKey;
             JoinColumn = "ExternalID";
-            AddCondition (String.Format ("{0}.FeedID = {1}.FeedID AND CoreTracks.ExternalID = {1}.ItemID", Feed.Provider.TableName, FeedItem.Provider.TableName));
+            AddCondition (String.Format (
+                "{0}.FeedID = {1}.FeedID AND CoreTracks.ExternalID = {1}.ItemID AND {1}.ItemID = {2}.ItemID",
+                Feed.Provider.TableName, FeedItem.Provider.TableName, FeedEnclosure.Provider.TableName
+            ));
+        }
+
+        protected override void GenerateSortQueryPart ()
+        {
+            SortQuery = (SortColumn == null)
+                ? GetSort ("Published", false)
+                : GetSort (SortColumn.SortKey, SortColumn.SortType == Hyena.Data.SortType.Ascending);
+        }
+
+        public static string GetSort (string key, bool asc)
+        {
+            string ascDesc = asc ? "ASC" : "DESC";
+            string sort_query = null;
+            switch(key) {
+                case "PublishedDate":
+                    sort_query = String.Format (@"
+                        PodcastItems.PubDate {0}", ascDesc);
+                    break;
+
+                case "DownloadStatus":
+                    sort_query = String.Format (@"
+                        PodcastEnclosures.DownloadStatus {0}", ascDesc);
+                    break;
+            }
+
+            return sort_query ?? Banshee.Query.BansheeQuery.GetSort (key, asc);
         }
         
         public new PodcastTrackInfo this[int index] {
@@ -122,11 +151,10 @@
             Properties.SetString ("TrackView.ColumnControllerXml", String.Format (@"
                     <column-controller>
                       <column>
-                          <title>Activity</title>
                           <visible>true</visible>
                           <renderer type=""Banshee.Podcasting.Gui.PodcastItemActivityColumn"" property=""Activity"" />
                           <sort-key>DownloadStatus</sort-key>
-                          <width>.05</width>
+                          <width>.025</width>
                           <max-width>30</max-width>
                           <min-width>30</min-width>
                       </column>
@@ -147,7 +175,7 @@
                           <renderer type=""Banshee.Podcasting.Gui.ColumnCellPublished"" property=""PublishedDate"" />
                           <sort-key>PublishedDate</sort-key>
                       </column>
-                      <sort-column>published_date</sort-column>
+                      <sort-column direction=""desc"">published_date</sort-column>
                     </column-controller>
                 ",
                 Catalog.GetString ("Podcast")

Modified: trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting/PodcastService.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting/PodcastService.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting/PodcastService.cs	Wed May 21 23:52:08 2008
@@ -46,6 +46,7 @@
 using Banshee.Podcasting.Gui;
 using Banshee.Podcasting.Data;
 using Banshee.Collection.Database;
+using Banshee.Configuration;
 
 namespace Banshee.Podcasting
 {
@@ -82,13 +83,93 @@
             feeds_manager.FeedManager.ItemAdded += OnItemAdded;
             feeds_manager.FeedManager.ItemChanged += OnItemChanged;
             feeds_manager.FeedManager.ItemRemoved += OnItemRemoved;
-            
             feeds_manager.FeedManager.FeedsChanged += OnFeedsChanged;
-              
+
             ServiceManager.PlayerEngine.ConnectEvent (OnPlayerEvent, PlayerEvent.StateChange);
 
             InitializeInterface ();
         }
+
+        private void MigrateIfPossible ()
+        {
+            if (DatabaseConfigurationClient.Client.Get<int> ("Podcast", "Version", 0) == 0) {
+                if (ServiceManager.DbConnection.TableExists ("Podcasts") &&
+                        ServiceManager.DbConnection.Query<int> ("select count(*) from podcastsyndications") == 0) {
+                    Hyena.Log.Information ("Migrating Podcast Feeds and Items");
+                    ServiceManager.DbConnection.Execute(@"
+                        INSERT INTO PodcastSyndications (FeedID, Title, Url, Link,
+                            Description, ImageUrl, LastBuildDate, SyncSetting)
+                            SELECT 
+                                PodcastFeedID,
+                                Title,
+                                FeedUrl,
+                                Link,
+                                Description,
+                                Image,
+                                strftime(""%s"", LastUpdated),
+                                SyncPreference
+                            FROM PodcastFeeds
+                    ");
+
+                    ServiceManager.DbConnection.Execute(@"
+                        INSERT INTO PodcastItems (ItemID, FeedID, Title, Link, PubDate,
+                            Description, Author, Active, Guid)
+                            SELECT 
+                                PodcastID,
+                                PodcastFeedID,
+                                Title,
+                                Link,
+                                strftime(""%s"", PubDate),
+                                Description,
+                                Author,
+                                Active,
+                                Url
+                            FROM Podcasts
+                    ");
+
+                    // Note: downloaded*3 is because the value was 0 or 1, but is now 0 or 3 (FeedDownloadStatus.None/Downloaded)
+                    ServiceManager.DbConnection.Execute(@"
+                        INSERT INTO PodcastEnclosures (ItemID, LocalPath, Url, MimeType, FileSize, DownloadStatus)
+                            SELECT 
+                                PodcastID,
+                                LocalPath,
+                                Url,
+                                MimeType,
+                                Length,
+                                Downloaded*3
+                            FROM Podcasts
+                    ");
+
+                    // Finally, move podcast items from the Music Library to the Podcast source
+                    int [] primary_source_ids = new int [] { ServiceManager.SourceManager.MusicLibrary.DbId };
+                    int moved = 0;
+                    foreach (FeedEnclosure enclosure in FeedEnclosure.Provider.FetchAllMatching ("LocalPath IS NOT NULL AND LocalPath != ''")) {
+                        SafeUri uri = new SafeUri (enclosure.LocalPath);
+                        int track_id = DatabaseTrackInfo.GetTrackIdForUri (
+                            uri, Paths.MakePathRelative (uri.LocalPath, tmp_enclosure_path),
+                            primary_source_ids
+                        );
+
+                        if (track_id > 0) {
+                            PodcastTrackInfo track = PodcastTrackInfo.Provider.FetchSingle (track_id);
+                            track.Item = enclosure.Item;
+                            track.PrimarySourceId = source.DbId;
+                            track.Save (false);
+                            moved++;
+                        }
+                    }
+
+                    if (moved > 0) {
+                        ServiceManager.SourceManager.MusicLibrary.Reload ();
+                        source.Reload ();
+                    }
+
+                    Hyena.Log.Information ("Done Migrating Podcast Feeds and Items");
+                }
+                DatabaseConfigurationClient.Client.Set<int> ("Podcast", "Version", 1);
+            }
+
+        }
         
         public void Initialize ()
         {
@@ -96,6 +177,9 @@
         
         public void DelayedInitialize ()
         {
+            // Migrate data from 0.13.2 podcast tables, if they exist
+            MigrateIfPossible ();
+              
             foreach (Feed feed in Feed.Provider.FetchAll ()) {
                 feed.Update ();
                 RefreshArtworkFor (feed);

Modified: trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteConnection.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteConnection.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteConnection.cs	Wed May 21 23:52:08 2008
@@ -113,8 +113,35 @@
         {
             return Query (new HyenaSqliteCommand (command.ToString ()));
         }
+
+        // SELECT single column, multiple rows queries
+        public IEnumerable<T> QueryEnumerable<T> (HyenaSqliteCommand command)
+        {
+            using (IDataReader reader = Query (command)) {
+                while (reader.Read ()) {
+                    yield return (T)SqliteUtils.FromDbFormat (typeof (T), reader[0]);
+                }
+            }
+        }
+
+        public IEnumerable<T> QueryEnumerable<T> (HyenaSqliteCommand command, params object [] param_values)
+        {
+            lock (command) {
+                return QueryEnumerable<T> (command.ApplyValues (param_values));
+            }
+        }
+
+        public IEnumerable<T> QueryEnumerable<T> (string command_str, params object [] param_values)
+        {
+            return QueryEnumerable<T> (new HyenaSqliteCommand (command_str, param_values));
+        }
         
-        // SELECT single column queries
+        public IEnumerable<T> QueryEnumerable<T> (object command)
+        {
+            return QueryEnumerable<T> (new HyenaSqliteCommand (command.ToString ()));
+        }
+
+        // SELECT single column, single row queries
         public T Query<T> (HyenaSqliteCommand command)
         {
             object result = null;

Modified: trunk/banshee/src/Libraries/Migo/Migo/Migo.Syndication/Feed.cs
==============================================================================
--- trunk/banshee/src/Libraries/Migo/Migo/Migo.Syndication/Feed.cs	(original)
+++ trunk/banshee/src/Libraries/Migo/Migo/Migo.Syndication/Feed.cs	Wed May 21 23:52:08 2008
@@ -67,10 +67,12 @@
     {
         private static SqliteModelProvider<Feed> provider;
         public static SqliteModelProvider<Feed> Provider {
-            get { return provider ?? provider = new MigoModelProvider<Feed> (FeedsManager.Instance.Connection, "PodcastSyndications"); }
+            get { return provider; }
         }
         
-        public static void Init () {}
+        public static void Init () {
+            provider = new MigoModelProvider<Feed> (FeedsManager.Instance.Connection, "PodcastSyndications");
+        }
 
         public static bool Exists (string url)
         {

Modified: trunk/banshee/src/Libraries/Migo/Migo/Migo.Syndication/FeedEnclosure.cs
==============================================================================
--- trunk/banshee/src/Libraries/Migo/Migo/Migo.Syndication/FeedEnclosure.cs	(original)
+++ trunk/banshee/src/Libraries/Migo/Migo/Migo.Syndication/FeedEnclosure.cs	Wed May 21 23:52:08 2008
@@ -40,10 +40,12 @@
     {
         private static SqliteModelProvider<FeedEnclosure> provider;
         public static SqliteModelProvider<FeedEnclosure> Provider {
-            get { return provider ?? provider = new MigoModelProvider<FeedEnclosure> (FeedsManager.Instance.Connection, "PodcastEnclosures"); }
+            get { return provider; }
         }
         
-        public static void Init () {}
+        public static void Init () {
+            provider = new MigoModelProvider<FeedEnclosure> (FeedsManager.Instance.Connection, "PodcastEnclosures");
+        }
         
         private string mimetype;
         private FeedDownloadStatus download_status;        

Modified: trunk/banshee/src/Libraries/Migo/Migo/Migo.Syndication/FeedItem.cs
==============================================================================
--- trunk/banshee/src/Libraries/Migo/Migo/Migo.Syndication/FeedItem.cs	(original)
+++ trunk/banshee/src/Libraries/Migo/Migo/Migo.Syndication/FeedItem.cs	Wed May 21 23:52:08 2008
@@ -40,7 +40,7 @@
     {
         private static SqliteModelProvider<FeedItem> provider;
         public static SqliteModelProvider<FeedItem> Provider {
-            get { return provider ?? provider = new MigoModelProvider<FeedItem> (FeedsManager.Instance.Connection, "PodcastItems"); }
+            get { return provider; }
         }
         
         public static bool Exists (string guid)
@@ -48,7 +48,9 @@
             return Provider.Connection.Query<int> (String.Format ("select count(*) from {0} where Guid = ?", Provider.TableName), guid) != 0;
         }
         
-        public static void Init () {}
+        public static void Init () {
+            provider = new MigoModelProvider<FeedItem> (FeedsManager.Instance.Connection, "PodcastItems");
+        }
 
         private bool active = true;
         private string author;



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