banshee r4511 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Collection.Indexer
- From: abock svn gnome org
- To: svn-commits-list gnome org
- Subject: banshee r4511 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Collection.Indexer
- Date: Wed, 10 Sep 2008 23:16:57 +0000 (UTC)
Author: abock
Date: Wed Sep 10 23:16:57 2008
New Revision: 4511
URL: http://svn.gnome.org/viewvc/banshee?rev=4511&view=rev
Log:
2008-09-10 Aaron Bockover <abock gnome org>
* src/Core/Banshee.Services/Banshee.Collection.Indexer/CollectionIndexerService.cs:
* src/Core/Banshee.Services/Banshee.Collection.Indexer/ICollectionIndexerService.cs:
Implemented HasCollectionChanged and a signal for listening to live
collection changes; these facilities are useful for third parties to
know whether or not they should actually create a new index
* src/Core/Banshee.Services/Banshee.Collection.Indexer/CollectionIndexer.cs:
Use LibrarySource, not DatabaseSource
Modified:
trunk/banshee/ChangeLog
trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Indexer/CollectionIndexer.cs
trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Indexer/CollectionIndexerService.cs
trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Indexer/ICollectionIndexerService.cs
Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Indexer/CollectionIndexer.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Indexer/CollectionIndexer.cs (original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Indexer/CollectionIndexer.cs Wed Sep 10 23:16:57 2008
@@ -100,10 +100,10 @@
DisposeModels ();
foreach (Source source in ServiceManager.SourceManager.Sources) {
- DatabaseSource db_source = source as DatabaseSource;
- if (db_source != null && db_source.Indexable) {
+ LibrarySource library = source as LibrarySource;
+ if (library != null && library.Indexable) {
model_caches.Add (CachedList<DatabaseTrackInfo>.CreateFromSourceModel (
- (DatabaseTrackListModel)db_source.TrackModel));
+ (DatabaseTrackListModel)library.TrackModel));
}
}
}
Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Indexer/CollectionIndexerService.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Indexer/CollectionIndexerService.cs (original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Indexer/CollectionIndexerService.cs Wed Sep 10 23:16:57 2008
@@ -31,21 +31,47 @@
using NDesk.DBus;
+using Hyena.Query;
+using Hyena.Data.Sqlite;
+
+using Banshee.Library;
+using Banshee.Sources;
using Banshee.ServiceStack;
+using Banshee.Collection.Database;
namespace Banshee.Collection.Indexer
{
- public class CollectionIndexerService : ICollectionIndexerService
+ public class CollectionIndexerService : ICollectionIndexerService, IDisposable
{
+ private List<LibrarySource> libraries = new List<LibrarySource> ();
private string [] available_export_fields;
private int open_indexers;
+ public event Action CollectionChanged;
+
private Action shutdown_handler;
public Action ShutdownHandler {
get { return shutdown_handler; }
set { shutdown_handler = value; }
}
+ public CollectionIndexerService ()
+ {
+ ServiceManager.SourceManager.SourceAdded += OnSourceAdded;
+ ServiceManager.SourceManager.SourceRemoved += OnSourceRemoved;
+
+ foreach (Source source in ServiceManager.SourceManager.Sources) {
+ MonitorLibrary (source as LibrarySource);
+ }
+ }
+
+ public void Dispose ()
+ {
+ while (libraries.Count > 0) {
+ UnmonitorLibrary (libraries[0]);
+ }
+ }
+
public void Shutdown ()
{
lock (this) {
@@ -79,6 +105,32 @@
}
}
+ public bool HasCollectionChanged (int count, long time)
+ {
+ lock (this) {
+ int total_count = 0;
+ long last_updated = 0;
+
+ foreach (LibrarySource library in libraries) {
+ total_count += library.Count;
+ }
+
+ if (count != total_count) {
+ return true;
+ }
+
+ foreach (LibrarySource library in libraries) {
+ string query = String.Format ("SELECT MAX(CoreTracks.DateUpdatedStamp) {0}",
+ ((DatabaseTrackListModel)library.TrackModel).UnfilteredQuery);
+ using (HyenaDataReader reader = new HyenaDataReader (ServiceManager.DbConnection.Query (query))) {
+ last_updated = Math.Max (last_updated, reader.Get<long> (0));
+ }
+ }
+
+ return last_updated > time;
+ }
+ }
+
public string [] GetAvailableExportFields ()
{
lock (this) {
@@ -98,6 +150,67 @@
}
}
+ private void MonitorLibrary (LibrarySource library)
+ {
+ if (library == null || !library.Indexable || libraries.Contains (library)) {
+ return;
+ }
+
+ libraries.Add (library);
+
+ library.TracksAdded += OnLibraryChanged;
+ library.TracksDeleted += OnLibraryChanged;
+ library.TracksChanged += OnLibraryChanged;
+ }
+
+ private void UnmonitorLibrary (LibrarySource library)
+ {
+ if (library == null || !libraries.Contains (library)) {
+ return;
+ }
+
+ library.TracksAdded -= OnLibraryChanged;
+ library.TracksDeleted -= OnLibraryChanged;
+ library.TracksChanged -= OnLibraryChanged;
+
+ libraries.Remove (library);
+ }
+
+ private void OnSourceAdded (SourceAddedArgs args)
+ {
+ MonitorLibrary (args.Source as LibrarySource);
+ }
+
+ private void OnSourceRemoved (SourceEventArgs args)
+ {
+ UnmonitorLibrary (args.Source as LibrarySource);
+ }
+
+ private void OnLibraryChanged (object o, TrackEventArgs args)
+ {
+ if (args.ChangedFields == null) {
+ OnCollectionChanged ();
+ return;
+ }
+
+ foreach (Hyena.Query.QueryField field in args.ChangedFields) {
+ if (field != Banshee.Query.BansheeQuery.LastPlayedField ||
+ field != Banshee.Query.BansheeQuery.LastSkippedField &&
+ field != Banshee.Query.BansheeQuery.PlayCountField &&
+ field != Banshee.Query.BansheeQuery.SkipCountField) {
+ OnCollectionChanged ();
+ }
+ }
+ }
+
+ private void OnCollectionChanged ()
+ {
+ Action handler = CollectionChanged;
+ if (handler != null) {
+ handler ();
+ }
+ }
+
IDBusExportable IDBusExportable.Parent {
get { return null; }
}
Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Indexer/ICollectionIndexerService.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Indexer/ICollectionIndexerService.cs (original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Indexer/ICollectionIndexerService.cs Wed Sep 10 23:16:57 2008
@@ -33,13 +33,14 @@
namespace Banshee.Collection.Indexer
{
- public delegate void CollectionChangedHandler ();
-
[Interface ("org.bansheeproject.Banshee.CollectionIndexerService")]
public interface ICollectionIndexerService : IService, IDBusExportable
{
+ event Action CollectionChanged;
+
void Shutdown ();
ObjectPath CreateIndexer ();
string [] GetAvailableExportFields ();
+ bool HasCollectionChanged (int count, long time);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]