banshee r3879 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Library src/Core/Banshee.Services/Banshee.Sources src/Core/Banshee.ThickClient/Banshee.Query.Gui src/Core/Banshee.ThickClient/Banshee.SmartPlaylist.Gui src/Libraries/Hyena.Gui/Hyena.Query.Gui



Author: gburt
Date: Mon May  5 18:50:45 2008
New Revision: 3879
URL: http://svn.gnome.org/viewvc/banshee?rev=3879&view=rev

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

	* src/Core/Banshee.ThickClient/Banshee.Query.Gui/PlaylistQueryValueEntry.cs:
	* src/Core/Banshee.ThickClient/Banshee.Query.Gui/SmartPlaylistQueryValueEntry.cs:
	Better handle there not being any playlists or smart playlists.

	* src/Core/Banshee.ThickClient/Banshee.SmartPlaylist.Gui/Editor.cs: Fix
	loading a predefined playlist into the editor.

	* src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs: If the user
	has no smart playlists and we've never done this before, create the
	default smart playlists for a primary source.

	* src/Core/Banshee.Services/Banshee.Library/VideoLibrarySource.cs: Define
	some default smart playlists.

	* src/Core/Banshee.Services/Banshee.Library/MusicLibrarySource.cs: Tweak a
	default smart playlist.

	* src/Libraries/Hyena.Gui/Hyena.Query.Gui/QueryTermBox.cs: Fix bug with
	not setting the value of the editor entry to the value of the saved smart
	playlist.

	* src/Libraries/Hyena.Gui/Hyena.Query.Gui/QueryTermsBox.cs: When setting
	the QueryNode condition tree, clear out any old conditions that may be
	in the editor already.


Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Core/Banshee.Services/Banshee.Library/MusicLibrarySource.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Library/VideoLibrarySource.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Query.Gui/PlaylistQueryValueEntry.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Query.Gui/SmartPlaylistQueryValueEntry.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.SmartPlaylist.Gui/Editor.cs
   trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Query.Gui/QueryTermBox.cs
   trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Query.Gui/QueryTermsBox.cs

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Library/MusicLibrarySource.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Library/MusicLibrarySource.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Library/MusicLibrarySource.cs	Mon May  5 18:50:45 2008
@@ -72,7 +72,7 @@
             new SmartPlaylistDefinition (
                 Catalog.GetString ("Neglected Favorites"),
                 Catalog.GetString ("Favorites not played in over two weeks"),
-                "rating>3 played>=\"2 weeks ago\""),
+                "rating>=4 played>=\"2 weeks ago\""),
 
             new SmartPlaylistDefinition (
                 Catalog.GetString ("Least Favorite"),

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Library/VideoLibrarySource.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Library/VideoLibrarySource.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Library/VideoLibrarySource.cs	Mon May  5 18:50:45 2008
@@ -28,8 +28,12 @@
 //
 
 using System;
+using System.Collections.Generic;
+
 using Mono.Unix;
 
+using Banshee.SmartPlaylist;
+
 namespace Banshee.Library
 {
     public class VideoLibrarySource : LibrarySource
@@ -42,5 +46,21 @@
         public override bool ShowBrowser {
             get { return false; }
         }
+
+        public override IEnumerable<SmartPlaylistDefinition> DefaultSmartPlaylists {
+            get { return default_smart_playlists; }
+        }
+
+        private static SmartPlaylistDefinition [] default_smart_playlists = new SmartPlaylistDefinition [] {
+            new SmartPlaylistDefinition (
+                Catalog.GetString ("Unwatched"),
+                Catalog.GetString ("Videos that haven't been played yet"),
+                "plays=4"),
+
+            new SmartPlaylistDefinition (
+                Catalog.GetString ("Favorites"),
+                Catalog.GetString ("Videos rated four and five stars"),
+                "rating>=4"),
+        };
     }
 }

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs	Mon May  5 18:50:45 2008
@@ -38,6 +38,7 @@
 
 using Banshee.Base;
 using Banshee.ServiceStack;
+using Banshee.Configuration;
 using Banshee.Sources;
 using Banshee.Playlist;
 using Banshee.SmartPlaylist;
@@ -93,7 +94,7 @@
             DELETE FROM CoreTracks WHERE PrimarySourceId = ?
         ");
 
-        protected int dbid;
+        private int dbid;
         public int DbId {
             get {
                 if (dbid > 0) {
@@ -191,17 +192,44 @@
         private void PrimarySourceInitialize ()
         {
             // Scope the tracks to this primary source
-            track_model.Condition = String.Format ("CoreTracks.PrimarySourceID = {0}", dbid);
+            track_model.Condition = String.Format ("CoreTracks.PrimarySourceID = {0}", DbId);
 
-            primary_sources[dbid] = this;
+            primary_sources[DbId] = this;
             
-            foreach (PlaylistSource pl in PlaylistSource.LoadAll (DbId))
-                if (pl.PrimarySourceId == dbid)
-                    AddChildSource (pl);
-
-            foreach (SmartPlaylistSource pl in SmartPlaylistSource.LoadAll (DbId))
-                if (pl.PrimarySourceId == dbid)
-                    AddChildSource (pl);
+            // Load our playlists and smart playlists
+            foreach (PlaylistSource pl in PlaylistSource.LoadAll (DbId)) {
+                AddChildSource (pl);
+            }
+
+            int sp_count = 0;
+            foreach (SmartPlaylistSource pl in SmartPlaylistSource.LoadAll (DbId)) {
+                AddChildSource (pl);
+                sp_count++;
+            }
+
+            // Create default smart playlists if we haven't done it ever before, and if the
+            // user has zero smart playlists.
+            if (!HaveCreatedSmartPlaylists) {
+                if (sp_count == 0) {
+                    foreach (SmartPlaylistDefinition def in DefaultSmartPlaylists) {
+                        SmartPlaylistSource pl = def.ToSmartPlaylistSource (this);
+                        pl.Save ();
+                        AddChildSource (pl);
+                        pl.RefreshAndReload ();
+                        sp_count++;
+                    }
+                }
+
+                // Only save it if we already had some smart playlists, or we actually created some (eg not
+                // if we didn't have any and the list of default ones is empty atm).
+                if (sp_count > 0)
+                    HaveCreatedSmartPlaylists = true;
+            }
+        }
+
+        private bool HaveCreatedSmartPlaylists {
+            get { return DatabaseConfigurationClient.Client.Get<bool> ("HaveCreatedSmartPlaylists", UniqueId, false); }
+            set { DatabaseConfigurationClient.Client.Set<bool> ("HaveCreatedSmartPlaylists", UniqueId, value); }
         }
 
         public override void Save ()

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Query.Gui/PlaylistQueryValueEntry.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Query.Gui/PlaylistQueryValueEntry.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Query.Gui/PlaylistQueryValueEntry.cs	Mon May  5 18:50:45 2008
@@ -80,14 +80,17 @@
                         combo.Active = playlist_id_combo_map [(int)query_value.IntValue];
                     } catch {}
                 }
-                query_value.SetValue (combo_playlist_id_map [combo.Active]);
+
+                HandleValueChanged (null, EventArgs.Empty);
                 combo.Changed += HandleValueChanged;
             }
         }
 
         protected void HandleValueChanged (object o, EventArgs args)
         {
-            query_value.SetValue (combo_playlist_id_map [combo.Active]);
+            try {
+                query_value.SetValue (combo_playlist_id_map [combo.Active]);
+            } catch {}
         }
     }
 }

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Query.Gui/SmartPlaylistQueryValueEntry.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Query.Gui/SmartPlaylistQueryValueEntry.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Query.Gui/SmartPlaylistQueryValueEntry.cs	Mon May  5 18:50:45 2008
@@ -84,17 +84,17 @@
                     } catch {}
                 }
 
-                if (combo_playlist_id_map.ContainsKey (combo.Active)) {
-                    query_value.SetValue (combo_playlist_id_map [combo.Active]);
-                }
 
+                HandleValueChanged (null, EventArgs.Empty);
                 combo.Changed += HandleValueChanged;
             }
         }
 
         protected void HandleValueChanged (object o, EventArgs args)
         {
-            query_value.SetValue (combo_playlist_id_map [combo.Active]);
+            if (combo_playlist_id_map.ContainsKey (combo.Active)) {
+                query_value.SetValue (combo_playlist_id_map [combo.Active]);
+            }
         }
     }
 }

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.SmartPlaylist.Gui/Editor.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.SmartPlaylist.Gui/Editor.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.SmartPlaylist.Gui/Editor.cs	Mon May  5 18:50:45 2008
@@ -52,20 +52,23 @@
 
             name_entry.Text = playlist.Name;
 
-            UpdateForPlaylist ();
+            UpdateForPlaylist (playlist);
         }
 
-        private void UpdateForPlaylist ()
+        private void UpdateForPlaylist (SmartPlaylistSource playlist)
         {
-            currently_editing = playlist;
-            this.primary_source = playlist.PrimarySource;
-
             PlaylistName = playlist.Name;
             Condition = playlist.ConditionTree;
             LimitEnabled = playlist.IsLimited;
             LimitValue = playlist.LimitValue;
             Limit = playlist.Limit;
             Order = playlist.QueryOrder;
+
+            if (playlist.DbId > 0) {
+                this.playlist = playlist;
+                this.primary_source = playlist.PrimarySource;
+                currently_editing = playlist;
+            }
         }
     
         public Editor (PrimarySource primary_source) : base ("SmartPlaylistEditorDialog")
@@ -216,7 +219,7 @@
                         playlist.LimitValue = limit_value;
 
                         playlist.Save ();
-                        playlist.PrimarySource.AddChildSource (playlist);
+                        primary_source.AddChildSource (playlist);
                         playlist.RefreshAndReload ();
                         //SmartPlaylistCore.Instance.StartTimer (playlist);
                     } else {
@@ -225,7 +228,7 @@
                         playlist.LimitValue = limit_value;
                         playlist.Limit = limit;
 
-                        playlist.Rename (name);
+                        playlist.Name = name;
                         playlist.Save ();
                         playlist.RefreshAndReload ();
 
@@ -286,8 +289,7 @@
             TreeIter iter;
             if (adv_tree_view.Model.GetIter (out iter, paths[0])) {
                 SmartPlaylistDefinition def = ((SmartPlaylistDefinition)adv_tree_view.Model.GetValue (iter, 1));
-                this.playlist = def.ToSmartPlaylistSource (primary_source);
-                UpdateForPlaylist ();
+                UpdateForPlaylist (def.ToSmartPlaylistSource (primary_source));
             }
         }
 

Modified: trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Query.Gui/QueryTermBox.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Query.Gui/QueryTermBox.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Query.Gui/QueryTermBox.cs	Mon May  5 18:50:45 2008
@@ -228,21 +228,24 @@
             }
 
             set {
-                if (value == null) {
+                QueryTermNode node = value;
+                if (node == null) {
                     return;
                 }
 
-                field_chooser.Active = Array.IndexOf (sorted_fields, value.Field);
+                field_chooser.Active = Array.IndexOf (sorted_fields, node.Field);
 
-                foreach (QueryValueEntry entry in value_entries) {
-                    if (QueryValueEntry.GetValueType (entry) == value.Value.GetType ()) {
-                        entry.QueryValue = value.Value;
+                current_value_entry.QueryValue = node.Value;
+                /*foreach (QueryValueEntry entry in value_entries) {
+                    if (QueryValueEntry.GetValueType (entry) == node.Value.GetType ()) {
+                        Console.WriteLine ("In QueryTermBox, setting QueryNode, got matching value types, value is {0}, empty? {1}", node.Value.ToString (), node.Value.IsEmpty);
+                        entry.QueryValue = node.Value;
                         SetValueEntry (entry);
                         break;
                     }
-                }
+                }*/
 
-                op_chooser.Active = operators.IndexOf (value.Operator);
+                op_chooser.Active = operators.IndexOf (node.Operator);
             }
         }
     }

Modified: trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Query.Gui/QueryTermsBox.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Query.Gui/QueryTermsBox.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Query.Gui/QueryTermsBox.cs	Mon May  5 18:50:45 2008
@@ -83,17 +83,19 @@
                 return nodes;
             }
             set {
+                ClearRows ();
+                first_add_node = true;
                 foreach (QueryNode child in value) {
                     AddNode (child);
                 }
             }
         }
 
-        private bool first_add_node = true;
+        private bool first_add_node;
         protected void AddNode (QueryNode node)
         {
             if (node is QueryTermNode) {
-                QueryTermBox box = first_add_node ? FirstRow : CreateRow (false);
+                QueryTermBox box = first_add_node ? FirstRow : CreateRow (true);
                 box.QueryNode = node as QueryTermNode;
                 first_add_node = false;
             } else {
@@ -141,8 +143,18 @@
         
         protected void OnRowRemoveRequest (object o, EventArgs args)
         {
-            QueryTermBox row = o as QueryTermBox;
+            RemoveRow (o as QueryTermBox);
+        }
 
+        private void ClearRows ()
+        {
+            while (terms.Count > 1) {
+                RemoveRow (terms[1]);
+            }
+        }
+
+        private void RemoveRow (QueryTermBox row)
+        {
             field_box.Remove (row.FieldChooser);
             op_box.Remove (row.OpChooser);
             entry_box.Remove (row.ValueEntry);
@@ -154,7 +166,9 @@
         
         protected void UpdateCanDelete ()
         {
-            FirstRow.CanDelete = terms.Count > 1;
+            if (FirstRow != null) {
+                FirstRow.CanDelete = terms.Count > 1;
+            }
         }
     }
 }



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