Re: [Muine] [PATCH] incomplete albums
- From: Tom Coleman <tmcol bigpond net au>
- To: Jorn Baayen <jbaayen gnome org>
- Cc: Muine List <muine-list gnome org>
- Subject: Re: [Muine] [PATCH] incomplete albums
- Date: Thu, 13 Jan 2005 00:30:24 +1100
My apologies, last patch was not quite right. Please ignore (try this
one)
diff -aur muine-0.8.0/data/muine.schemas.in muine-0.8.0-hacking/data/muine.schemas.in
--- muine-0.8.0/data/muine.schemas.in 2005-01-07 13:49:59.000000000 +1100
+++ muine-0.8.0-hacking/data/muine.schemas.in 2005-01-13 00:21:07.175999200 +1100
@@ -135,6 +135,18 @@
</locale>
</schema>
<schema>
+ <key>/schemas/apps/muine/non_album_folders</key>
+ <applyto>/apps/muine/non_album_folders</applyto>
+ <owner>muine</owner>
+ <type>list</type>
+ <list_type>string</list_type>
+ <default>[]</default>
+ <locale name="C">
+ <short>Non album folders</short>
+ <long>Folders that don't contain entire albums.</long>
+ </locale>
+ </schema>
+ <schema>
<key>/schemas/apps/muine/default_import_folder</key>
<applyto>/apps/muine/default_import_folder</applyto>
<owner>muine</owner>
diff -aur muine-0.8.0/src/AddAlbumWindow.cs muine-0.8.0-hacking/src/AddAlbumWindow.cs
--- muine-0.8.0/src/AddAlbumWindow.cs 2005-01-09 23:59:20.000000000 +1100
+++ muine-0.8.0-hacking/src/AddAlbumWindow.cs 2005-01-13 06:22:12.000000000 +1100
@@ -73,15 +73,35 @@
Global.CoverDB.DoneLoading += new CoverDatabase.DoneLoadingHandler (OnCoversDoneLoading);
- lock (Global.DB) {
- foreach (Album a in Global.DB.Albums.Values)
- base.List.Append (a.Handle);
- }
+ Search ();
if (!Global.CoverDB.Loading)
EnableDragDest ();
}
+ // Properties
+ protected override ICollection PotentialItems {
+ get { return Global.DB.Albums.Values; }
+ }
+
+ private const int fake_length = 0;
+ protected override int FakeLength {
+ get { return fake_length; }
+ }
+ private const int min_query_length = -1;
+ protected override int MinQueryLength {
+ get { return min_query_length; }
+ }
+
+ // Protected Methods
+ protected override bool IsMatch (Item item)
+ {
+ Album album = (Album) item;
+ return album.FitsCriteria (base.Entry.SearchBits) && album.Complete;
+ }
+
+
+ // Private Methods
private int SortFunc (IntPtr a_ptr,
IntPtr b_ptr)
{
@@ -124,43 +144,15 @@
false, true, false);
}
- protected override bool Search ()
- {
- List l = new List (IntPtr.Zero, typeof (int));
-
- lock (Global.DB) {
- if (base.Entry.Text.Length > 0) {
- foreach (Album a in Global.DB.Albums.Values) {
- if (a.FitsCriteria (base.Entry.SearchBits))
- l.Append (a.Handle);
- }
- } else {
- foreach (Album a in Global.DB.Albums.Values)
- l.Append (a.Handle);
- }
- }
-
- base.List.RemoveDelta (l);
-
- foreach (int i in l) {
- IntPtr ptr = new IntPtr (i);
-
- base.List.Append (ptr);
- }
-
- base.List.SelectFirst ();
-
- return false;
- }
-
+ // is there some way we can generalise these?
private void OnAlbumAdded (Album album)
{
- base.List.HandleAdded (album.Handle, album.FitsCriteria (base.Entry.SearchBits));
+ base.List.HandleAdded (album.Handle, IsMatch (album));
}
private void OnAlbumChanged (Album album)
{
- base.List.HandleChanged (album.Handle, album.FitsCriteria (base.Entry.SearchBits));
+ base.List.HandleChanged (album.Handle, IsMatch (album));
}
private void OnAlbumRemoved (Album album)
diff -aur muine-0.8.0/src/AddSongWindow.cs muine-0.8.0-hacking/src/AddSongWindow.cs
--- muine-0.8.0/src/AddSongWindow.cs 2005-01-09 23:58:48.000000000 +1100
+++ muine-0.8.0-hacking/src/AddSongWindow.cs 2005-01-13 06:22:20.000000000 +1100
@@ -30,9 +30,6 @@
public class AddSongWindow : AddWindow
{
// Constants
- private const int FakeLength = 150;
- private const int MinQueryLength = 3;
-
private const string GConfKeyWidth = "/apps/muine/add_song_window/width";
private const int GConfDefaultWidth = 500;
@@ -67,19 +64,30 @@
Global.DB.SongChanged += new SongDatabase.SongChangedHandler (OnSongChanged);
Global.DB.SongRemoved += new SongDatabase.SongRemovedHandler (OnSongRemoved);
- lock (Global.DB) {
- int i = 0;
-
- foreach (Song s in Global.DB.Songs.Values) {
- base.List.Append (s.Handle);
-
- i++;
- if (i >= FakeLength)
- break;
- }
- }
+ Search ();
}
+
+ // Properties
+ protected override ICollection PotentialItems {
+ get { return Global.DB.Songs.Values; }
+ }
+
+ private const int fake_length = 150;
+ protected override int FakeLength {
+ get { return fake_length; }
+ }
+ private const int min_query_length = 3;
+ protected override int MinQueryLength {
+ get { return min_query_length; }
+ }
+
+ // Protected Methods
+ protected override bool IsMatch (Item item)
+ {
+ return item.FitsCriteria (base.Entry.SearchBits);
+ }
+ // Private Methods
private int SortFunc (IntPtr a_ptr,
IntPtr b_ptr)
{
@@ -102,60 +110,15 @@
false, true, false);
}
- protected override bool Search ()
- {
- List l = new List (IntPtr.Zero, typeof (int));
-
- int max_len = -1;
-
- /* show max. FakeLength songs if < MinQueryLength chars are entered. this is to fake speed. */
- if (base.Entry.Text.Length < MinQueryLength)
- max_len = FakeLength;
-
- lock (Global.DB) {
- int i = 0;
- if (base.Entry.Text.Length > 0) {
- foreach (Song s in Global.DB.Songs.Values) {
- if (!s.FitsCriteria (base.Entry.SearchBits))
- continue;
-
- l.Append (s.Handle);
-
- i++;
- if (max_len > 0 && i >= max_len)
- break;
- }
- } else {
- foreach (Song s in Global.DB.Songs.Values) {
- l.Append (s.Handle);
-
- i++;
- if (max_len > 0 && i >= max_len)
- break;
- }
- }
- }
-
- base.List.RemoveDelta (l);
-
- foreach (int p in l) {
- IntPtr ptr = new IntPtr (p);
-
- base.List.Append (ptr);
- }
-
- base.List.SelectFirst ();
-
- return false;
- }
-
private void OnSongAdded (Song song)
{
+ // is this really necessary?
+ // if so it should be in AddWindow somehow
if (base.Entry.Text.Length < MinQueryLength &&
base.List.Length >= FakeLength)
return;
- base.List.HandleAdded (song.Handle, song.FitsCriteria (base.Entry.SearchBits));
+ base.List.HandleAdded (song.Handle, IsMatch (song));
}
private void OnSongChanged (Song song)
@@ -163,7 +126,7 @@
bool may_append = (base.Entry.Text.Length >= MinQueryLength ||
base.List.Length < FakeLength);
- base.List.HandleChanged (song.Handle, song.FitsCriteria (base.Entry.SearchBits),
+ base.List.HandleChanged (song.Handle, IsMatch (song),
may_append);
}
diff -aur muine-0.8.0/src/AddWindow.cs muine-0.8.0-hacking/src/AddWindow.cs
--- muine-0.8.0/src/AddWindow.cs 2005-01-10 02:11:31.000000000 +1100
+++ muine-0.8.0-hacking/src/AddWindow.cs 2005-01-12 02:10:26.000000000 +1100
@@ -19,7 +19,10 @@
*/
using System;
+using System.Collections;
+
using Gtk;
+using GLib;
namespace Muine
{
@@ -83,6 +86,8 @@
entry.Show ();
list.Show ();
+
+
}
// Properties
@@ -97,9 +102,21 @@
public CellRenderer TextRenderer {
get { return text_renderer; }
}
-
- // Abstract methods
- protected abstract bool Search ();
+
+ // Abstract Properties
+ protected abstract ICollection PotentialItems {
+ get;
+ }
+
+ protected abstract int FakeLength {
+ get;
+ }
+ protected abstract int MinQueryLength {
+ get;
+ }
+
+ // Abstract Methods
+ protected abstract bool IsMatch (Item item);
// Public Methods
public void Run ()
@@ -110,7 +127,7 @@
window.Present ();
}
-
+
// Protected Methods
protected void SetGConfSize (string key_width, string key_height,
int default_width, int default_height)
@@ -143,6 +160,44 @@
process_changes_immediately = false;
}
+
+ protected bool Search ()
+ {
+ List l = new List (IntPtr.Zero, typeof (int));
+
+ int max_len = -1;
+
+ /* show max. FakeLength songs if < MinQueryLength chars are entered. this is to fake speed. */
+ if (entry.Text.Length < MinQueryLength)
+ max_len = FakeLength;
+
+ int i = 0;
+ lock (Global.DB) {
+ foreach (Item item in PotentialItems) {
+ if (!IsMatch (item))
+ continue;
+
+ l.Append (item.Handle);
+
+ i++;
+ if (max_len != -1 && i >= max_len)
+ break;
+ }
+ }
+
+ List.RemoveDelta (l);
+
+ foreach (int p in l) {
+ IntPtr ptr = new IntPtr (p);
+
+ List.Append (ptr);
+ }
+
+ List.SelectFirst ();
+
+ return false;
+
+ }
// Private Methods
// Private Methods :: Assertions
diff -aur muine-0.8.0/src/AddWindowEntry.cs muine-0.8.0-hacking/src/AddWindowEntry.cs
--- muine-0.8.0/src/AddWindowEntry.cs 2005-01-10 02:11:12.000000000 +1100
+++ muine-0.8.0-hacking/src/AddWindowEntry.cs 2005-01-13 06:35:00.000000000 +1100
@@ -17,6 +17,8 @@
* Boston, MA 02111-1307, USA.
*/
+using System;
+
namespace Muine
{
public class AddWindowEntry : Gtk.Entry
@@ -34,7 +36,7 @@
public void Clear ()
{
- base.Text = "";
+ base.Text = "";
}
}
}
diff -aur muine-0.8.0/src/Album.cs muine-0.8.0-hacking/src/Album.cs
--- muine-0.8.0/src/Album.cs 2005-01-10 08:44:54.000000000 +1100
+++ muine-0.8.0-hacking/src/Album.cs 2005-01-13 00:24:07.381603784 +1100
@@ -35,6 +35,10 @@
private static readonly string [] prefixes =
Catalog.GetString ("the dj").Split (' ');
+ private const string GConfKeyNonAlbumFolders = "/apps/muine/non_album_folders";
+ private static readonly string [] GConfDefaultNonAlbumFolders = new string [0];
+ private static string [] non_album_folders;
+
// Properties
private string name;
public string Name {
@@ -115,6 +119,11 @@
pointers [cur_ptr] = this;
base.handle = cur_ptr;
+ // check that this is a complete album
+ foreach (string check_folder in non_album_folders)
+ if (folder.StartsWith (check_folder))
+ complete = false;
+
if (check_cover) {
cover_image = GetCover (initial_song);
@@ -122,6 +131,29 @@
}
}
+ // Static Constructor
+ static Album ()
+ {
+ non_album_folders = (string [])
+ Config.Get (GConfKeyNonAlbumFolders, GConfDefaultNonAlbumFolders);
+
+ Config.AddNotify (GConfKeyNonAlbumFolders,
+ new GConf.NotifyEventHandler (OnNonAlbumFoldersChanged));
+ }
+
+ // Properties
+ // is this album from a 'non_album_folders' directory?
+ private bool complete = true;
+ public bool Complete {
+ get { return complete; }
+ }
+
+ // Static Methods
+ private static void OnNonAlbumFoldersChanged (object o, GConf.NotifyEventArgs args)
+ {
+ non_album_folders = (string []) args.Value;
+ }
+
public static Album FromHandle (IntPtr handle)
{
return (Album) pointers [handle];
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]