banshee r4018 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Preferences src/Extensions/Banshee.AudioCd/Banshee.AudioCd src/Libraries/Hyena src/Libraries/Hyena/Hyena.Collections src/Libraries/Hyena/Hyena.Collections/Tests
- From: abock svn gnome org
- To: svn-commits-list gnome org
- Subject: banshee r4018 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Preferences src/Extensions/Banshee.AudioCd/Banshee.AudioCd src/Libraries/Hyena src/Libraries/Hyena/Hyena.Collections src/Libraries/Hyena/Hyena.Collections/Tests
- Date: Wed, 28 May 2008 22:35:45 +0000 (UTC)
Author: abock
Date: Wed May 28 22:35:45 2008
New Revision: 4018
URL: http://svn.gnome.org/viewvc/banshee?rev=4018&view=rev
Log:
2008-05-28 Aaron Bockover <abock gnome org>
* src/Extensions/Banshee.AudioCd/Banshee.AudioCd/AudioCdService.cs:
Split audio CD preferences into a separate tab
* src/Core/Banshee.Services/Banshee.Preferences/Collection.cs:
* src/Core/Banshee.Services/Banshee.Preferences/Root.cs:
Ensure sections and pages actually get inserted in the proper sort order
* src/Libraries/Hyena/Hyena.Collections/CollectionExtensions.cs:
* src/Libraries/Hyena/Hyena.Collections/Tests/RangeCollectionTests.cs:
Moved SortedInsert into a new CollectionExtensions helper class
Added:
trunk/banshee/src/Libraries/Hyena/Hyena.Collections/CollectionExtensions.cs
Modified:
trunk/banshee/ChangeLog
trunk/banshee/src/Core/Banshee.Services/Banshee.Preferences/Collection.cs
trunk/banshee/src/Core/Banshee.Services/Banshee.Preferences/Root.cs
trunk/banshee/src/Extensions/Banshee.AudioCd/Banshee.AudioCd/AudioCdService.cs
trunk/banshee/src/Libraries/Hyena/Hyena.Collections/Tests/RangeCollectionTests.cs
trunk/banshee/src/Libraries/Hyena/Hyena.mdp
trunk/banshee/src/Libraries/Hyena/Makefile.am
Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Preferences/Collection.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Preferences/Collection.cs (original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Preferences/Collection.cs Wed May 28 22:35:45 2008
@@ -30,6 +30,8 @@
using System.Collections;
using System.Collections.Generic;
+using Hyena.Collections;
+
namespace Banshee.Preferences
{
public class Collection<T> : Root, IList<T> where T : Root
@@ -43,7 +45,11 @@
public T Add (T item)
{
lock (this) {
- list.Add (item);
+ if (item is Page || item is Section) {
+ CollectionExtensions.SortedInsert (list, item);
+ } else {
+ list.Add (item);
+ }
return item;
}
}
Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Preferences/Root.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Preferences/Root.cs (original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Preferences/Root.cs Wed May 28 22:35:45 2008
@@ -30,7 +30,7 @@
namespace Banshee.Preferences
{
- public abstract class Root
+ public abstract class Root : IComparable
{
private string id;
private string name;
@@ -47,6 +47,16 @@
visible = true;
}
+ public int CompareTo (object o)
+ {
+ Root r = o as Root;
+ if (r == null) {
+ return -1;
+ }
+
+ return Order.CompareTo (r.Order);
+ }
+
public string Id {
get { return id; }
set { id = value; }
Modified: trunk/banshee/src/Extensions/Banshee.AudioCd/Banshee.AudioCd/AudioCdService.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.AudioCd/Banshee.AudioCd/AudioCdService.cs (original)
+++ trunk/banshee/src/Extensions/Banshee.AudioCd/Banshee.AudioCd/AudioCdService.cs Wed May 28 22:35:45 2008
@@ -43,6 +43,7 @@
public class AudioCdService : IExtensionService, IDisposable
{
private Dictionary<string, AudioCdSource> sources;
+ private Page pref_page;
private Section pref_section;
private uint global_interface_id;
@@ -152,7 +153,10 @@
service.InstallWidgetAdapters += OnPreferencesServiceInstallWidgetAdapters;
- pref_section = service["general"].Add (new Section ("audio-cd",
+ pref_page = new Page ("audio-cd", Catalog.GetString ("Audio CD"), 3);
+ service.Add (pref_page);
+
+ pref_section = pref_page.Add (new Section ("audio-cd",
Catalog.GetString ("Audio CD Importing"), 20));
pref_section.Add (new VoidPreference ("import-profile", Catalog.GetString ("_Import format")));
@@ -176,13 +180,14 @@
private void UninstallPreferences ()
{
PreferenceService service = ServiceManager.Get<PreferenceService> ();
- if (service == null || pref_section == null) {
+ if (service == null || pref_page == null) {
return;
}
service.InstallWidgetAdapters -= OnPreferencesServiceInstallWidgetAdapters;
- service["general"].Remove (pref_section);
+ service.Remove (pref_page);
+ pref_page = null;
pref_section = null;
}
Added: trunk/banshee/src/Libraries/Hyena/Hyena.Collections/CollectionExtensions.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.Collections/CollectionExtensions.cs Wed May 28 22:35:45 2008
@@ -0,0 +1,48 @@
+//
+// CollectionExtensions.cs
+//
+// Author:
+// Aaron Bockover <abockover novell com>
+//
+// Copyright (C) 2008 Novell, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Collections.Generic;
+
+namespace Hyena.Collections
+{
+ public static class CollectionExtensions
+ {
+ public static void SortedInsert<T> (List<T> list, T value) where T : IComparable
+ {
+ if (list.Count == 0 || list[list.Count - 1].CompareTo (value) < 0) {
+ list.Add (value);
+ } else if (list[0].CompareTo (value) > 0) {
+ list.Insert (0, value);
+ } else {
+ int index = list.BinarySearch (value);
+ list.Insert (index < 0 ? ~index : index, value);
+ }
+ }
+ }
+}
Modified: trunk/banshee/src/Libraries/Hyena/Hyena.Collections/Tests/RangeCollectionTests.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena.Collections/Tests/RangeCollectionTests.cs (original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.Collections/Tests/RangeCollectionTests.cs Wed May 28 22:35:45 2008
@@ -370,19 +370,6 @@
Assert.AreEqual (12, range[7]);
Assert.AreEqual (13, range[8]);
}
-
- private static void SortedInsert<T> (List<T> list, T value)
- where T : IComparable
- {
- if (list.Count == 0 || list[list.Count - 1].CompareTo (value) < 0) {
- list.Add (value);
- } else if (list[0].CompareTo (value) > 0) {
- list.Insert (0, value);
- } else {
- int index = list.BinarySearch (value);
- list.Insert (index < 0 ? ~index : index, value);
- }
- }
[Test]
public void StressForGoodIndexes ()
@@ -394,7 +381,7 @@
for (int i = 0, n = 75000; i < n; i++) {
int value = random.Next (n);
if (ranges.Add (value)) {
- SortedInsert (indexes, value);
+ CollectionExtensions.SortedInsert (indexes, value);
}
}
Modified: trunk/banshee/src/Libraries/Hyena/Hyena.mdp
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena.mdp (original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.mdp Wed May 28 22:35:45 2008
@@ -96,6 +96,7 @@
<File name="Hyena/Tests/StringUtilTests.cs" subtype="Code" buildaction="Compile" />
<File name="Hyena/Tests/TestBase.cs" subtype="Code" buildaction="Compile" />
<File name="Hyena.Data/ICacheableItem.cs" subtype="Code" buildaction="Compile" />
+ <File name="Hyena.Collections/CollectionExtensions.cs" subtype="Code" buildaction="Compile" />
</Contents>
<References>
<ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
Modified: trunk/banshee/src/Libraries/Hyena/Makefile.am
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Makefile.am (original)
+++ trunk/banshee/src/Libraries/Hyena/Makefile.am Wed May 28 22:35:45 2008
@@ -2,6 +2,7 @@
TARGET = library
LINK = $(REF_HYENA)
SOURCES = \
+ Hyena.Collections/CollectionExtensions.cs \
Hyena.Collections/IntervalHeap.cs \
Hyena.Collections/IStackProvider.cs \
Hyena.Collections/RangeCollection.cs \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]