[banshee] [Bookmarks] Add a Type column, and lazy load



commit ea91a038f01a8af5841a8bfebba5055672250639
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Fri May 14 19:02:39 2010 -0700

    [Bookmarks] Add a Type column, and lazy load

 .../Banshee.Bookmarks/Bookmark.cs                  |   13 +++++++------
 .../Banshee.Bookmarks/BookmarkUI.cs                |   15 ++++++++++++---
 2 files changed, 19 insertions(+), 9 deletions(-)
---
diff --git a/src/Extensions/Banshee.Bookmarks/Banshee.Bookmarks/Bookmark.cs b/src/Extensions/Banshee.Bookmarks/Banshee.Bookmarks/Bookmark.cs
index c63c22f..2a65f6f 100644
--- a/src/Extensions/Banshee.Bookmarks/Banshee.Bookmarks/Bookmark.cs
+++ b/src/Extensions/Banshee.Bookmarks/Banshee.Bookmarks/Bookmark.cs
@@ -72,6 +72,9 @@ namespace Banshee.Bookmarks
         [DatabaseColumn]
         public DateTime CreatedAt { get; private set; }
 
+        [DatabaseColumn]
+        public string Type { get; private set; }
+
         public string Name {
             get {
                 int position_seconds = (int)Position.TotalSeconds;
@@ -85,11 +88,14 @@ namespace Banshee.Bookmarks
 
         public Bookmark () {}
 
-        public Bookmark (DatabaseTrackInfo track, int position_ms)
+        public Bookmark (DatabaseTrackInfo track, int position_ms) : this (track, position_ms, null) {}
+
+        public Bookmark (DatabaseTrackInfo track, int position_ms, string type)
         {
             Track = track;
             Position = TimeSpan.FromMilliseconds (position_ms);
             CreatedAt = DateTime.Now;
+            Type = type;
 
             Provider.Save (this);
         }
@@ -148,11 +154,6 @@ namespace Banshee.Bookmarks
             }
         }
 
-        public static List<Bookmark> LoadAll ()
-        {
-            return Provider.FetchAll ().ToList ();
-        }
-
         // Translators: This is used to generate bookmark names. {0} is track title, {1} is minutes
         // (possibly more than two digits) and {2} is seconds (between 00 and 60).
         private static readonly string NAME_FMT = Catalog.GetString ("{0} ({1}:{2:00})");
diff --git a/src/Extensions/Banshee.Bookmarks/Banshee.Bookmarks/BookmarkUI.cs b/src/Extensions/Banshee.Bookmarks/Banshee.Bookmarks/BookmarkUI.cs
index 1cc8f64..e66eafd 100644
--- a/src/Extensions/Banshee.Bookmarks/Banshee.Bookmarks/BookmarkUI.cs
+++ b/src/Extensions/Banshee.Bookmarks/Banshee.Bookmarks/BookmarkUI.cs
@@ -62,6 +62,7 @@ namespace Banshee.Bookmarks
         private InterfaceActionService action_service;
         private ActionGroup actions;
         private uint ui_manager_id;
+        private bool loaded;
 
         private static BookmarkUI instance = null;
         public static BookmarkUI Instance {
@@ -107,7 +108,12 @@ namespace Banshee.Bookmarks
             remove_item.Submenu = remove_menu = new Menu ();
             bookmark_menu.Append (remove_item);
 
-            LoadBookmarks ();
+            actions["BookmarksAction"].Activated += (o, a) => {
+                if (!loaded) {
+                    LoadBookmarks ();
+                    loaded = true;
+                }
+            };
         }
 
         private void HandleMenuShown (object sender, EventArgs args)
@@ -120,7 +126,10 @@ namespace Banshee.Bookmarks
             var track = ServiceManager.PlayerEngine.CurrentTrack as DatabaseTrackInfo;
             if (track != null) {
                 try {
-                    AddBookmark (new Bookmark (track, (int)ServiceManager.PlayerEngine.Position));
+                    var bookmark = new Bookmark (track, (int)ServiceManager.PlayerEngine.Position);
+                    if (loaded) {
+                        AddBookmark (bookmark);
+                    }
                 } catch (Exception e) {
                     Log.Exception ("Unable to Add New Bookmark", e);
                 }
@@ -131,7 +140,7 @@ namespace Banshee.Bookmarks
         {
             separator = new SeparatorMenuItem ();
 
-            foreach (Bookmark bookmark in Bookmark.LoadAll ()) {
+            foreach (var bookmark in Bookmark.Provider.FetchAllMatching ("Type IS NULL")) {
                 AddBookmark (bookmark);
             }
 



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