[banshee] Add PlaybackError query field (bgo#590946)



commit c4ab4b35a6decf3a6b4df0a1fff34638915f74ad
Author: Alexander Kojevnikov <alexander kojevnikov com>
Date:   Tue Nov 10 21:03:04 2009 +1100

    Add PlaybackError query field (bgo#590946)

 .../DatabaseTrackInfo.cs                           |    3 +-
 .../Banshee.Services/Banshee.Query/BansheeQuery.cs |   10 ++-
 .../Banshee.Query/PlaybackErrorQueryValue.cs       |   74 +++++++++++++
 src/Core/Banshee.Services/Banshee.Services.csproj  |    1 +
 src/Core/Banshee.Services/Makefile.am              |    1 +
 .../Banshee.Query.Gui/BansheeQueryBox.cs           |    1 +
 .../PlaybackErrorQueryValueEntry.cs                |   89 ++++++++++++++++
 .../Banshee.ThickClient/Banshee.ThickClient.csproj |    1 +
 src/Core/Banshee.ThickClient/Makefile.am           |    1 +
 src/Libraries/Hyena/Hyena.Query/EnumQueryValue.cs  |  111 ++++++++++++++++++++
 src/Libraries/Hyena/Hyena.csproj                   |    1 +
 src/Libraries/Hyena/Makefile.am                    |    1 +
 12 files changed, 292 insertions(+), 2 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
index e78244d..6af4aa6 100644
--- a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
+++ b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
@@ -134,7 +134,8 @@ namespace Banshee.Collection.Database
             BansheeQuery.LastSkippedField,
             BansheeQuery.PlayCountField,
             BansheeQuery.LastPlayedField,
-            BansheeQuery.RatingField
+            BansheeQuery.RatingField,
+            BansheeQuery.PlaybackErrorField
         };
 
         public void Save (bool notify, params QueryField [] fields_changed)
diff --git a/src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs b/src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs
index 87abe16..abe83b5 100644
--- a/src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs
+++ b/src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs
@@ -330,13 +330,21 @@ namespace Banshee.Query
             "score"
         );
         
+        public static QueryField PlaybackErrorField = new QueryField (
+            "playbackerror", "PlaybackError",
+            Catalog.GetString ("Playback Error"), "CoreTracks.LastStreamError", typeof(PlaybackErrorQueryValue),
+            //Translators: These are unique search fields (and nouns). Please, no spaces. Blank ok.
+            Catalog.GetString ("playbackerror"),
+            "playbackerror", "error"
+        );
+
 #endregion
 
         public static QueryFieldSet FieldSet = new QueryFieldSet (
             ArtistField, AlbumField, AlbumArtistField, TitleField, TrackNumberField, TrackCountField, DiscNumberField, DiscCountField,
             YearField, GenreField, ComposerField, ConductorField, GroupingField, CommentField, LicenseUriField, RatingField, PlayCountField,
             SkipCountField, FileSizeField, UriField, DurationField, MimeTypeField, LastPlayedField, LastSkippedField,
-            BpmField, BitRateField, DateAddedField, PlaylistField, SmartPlaylistField, ScoreField
+            BpmField, BitRateField, DateAddedField, PlaylistField, SmartPlaylistField, ScoreField, PlaybackErrorField
         );
 
         // Type Initializer
diff --git a/src/Core/Banshee.Services/Banshee.Query/PlaybackErrorQueryValue.cs b/src/Core/Banshee.Services/Banshee.Query/PlaybackErrorQueryValue.cs
new file mode 100644
index 0000000..4146c80
--- /dev/null
+++ b/src/Core/Banshee.Services/Banshee.Query/PlaybackErrorQueryValue.cs
@@ -0,0 +1,74 @@
+//
+// PlaybackErrorQueryValue.cs
+//
+// Author:
+//   Alexander Kojevnikov <alexander kojevnikov com>
+//
+// Copyright (C) 2009 Alexander Kojevnikov
+//
+// 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;
+
+using Mono.Unix;
+
+using Hyena.Query;
+
+using Banshee.Streaming;
+
+namespace Banshee.Query
+{
+    public class PlaybackErrorQueryValue : EnumQueryValue
+    {
+        private static AliasedObjectSet<EnumQueryValueItem> items = new AliasedObjectSet<EnumQueryValueItem>(
+            new EnumQueryValueItem (
+                (int)StreamPlaybackError.None, "None", Catalog.GetString ("None"),
+                //Translators: These are unique strings for playback errors. Please, no spaces. Blank ok.
+                Catalog.GetString ("None"), Catalog.GetString ("none"), Catalog.GetString ("no"),
+                "None", "none", "no"),
+            new EnumQueryValueItem (
+                (int)StreamPlaybackError.ResourceNotFound, "ResourceNotFound", Catalog.GetString ("Resource Not Found"),
+                //Translators: These are unique strings for playback errors. Please, no spaces. Blank ok.
+                Catalog.GetString ("ResourceNotFound"), Catalog.GetString ("missing"), Catalog.GetString ("notfound"),
+                "ResourceNotFound", "missing", "notfound"),
+            new EnumQueryValueItem (
+                (int)StreamPlaybackError.CodecNotFound, "CodecNotFound", Catalog.GetString ("CodecNotFound"),
+                //Translators: These are unique strings for playback errors. Please, no spaces. Blank ok.
+                Catalog.GetString ("CodecNotFound"), Catalog.GetString ("nocodec"),
+                "CodecNotFound", "nocodec"),
+            new EnumQueryValueItem (
+                (int)StreamPlaybackError.Drm, "Drm", Catalog.GetString ("Drm"),
+                //Translators: These are unique strings for playback errors. Please, no spaces. Blank ok.
+                Catalog.GetString ("Drm"), Catalog.GetString ("drm"),
+                "Drm", "drm"),
+            new EnumQueryValueItem (
+                (int)StreamPlaybackError.Unknown, "Unknown", Catalog.GetString ("Unknown"),
+                //Translators: These are unique strings for playback errors. Please, no spaces. Blank ok.
+                Catalog.GetString ("Unknown"), Catalog.GetString ("unknown"),
+                "Unknown", "unknown")
+        );
+
+        public override IEnumerable<EnumQueryValueItem> Items {
+            get { return items; }
+        }
+    }
+}
diff --git a/src/Core/Banshee.Services/Banshee.Services.csproj b/src/Core/Banshee.Services/Banshee.Services.csproj
index 80d2974..4179155 100644
--- a/src/Core/Banshee.Services/Banshee.Services.csproj
+++ b/src/Core/Banshee.Services/Banshee.Services.csproj
@@ -299,6 +299,7 @@
     <Compile Include="Banshee.PlatformServices\IScreensaverManager.cs" />
     <Compile Include="Banshee.Collection.Database\RandomByScore.cs" />
     <Compile Include="Banshee.Collection.Database\RandomBySlot.cs" />
+    <Compile Include="Banshee.Query\PlaybackErrorQueryValue.cs" />
   </ItemGroup>
   <ItemGroup>
     <EmbeddedResource Include="Banshee.Services.addin.xml" />
diff --git a/src/Core/Banshee.Services/Makefile.am b/src/Core/Banshee.Services/Makefile.am
index 5109342..b58ef80 100644
--- a/src/Core/Banshee.Services/Makefile.am
+++ b/src/Core/Banshee.Services/Makefile.am
@@ -161,6 +161,7 @@ SOURCES =  \
 	Banshee.Query/AbstractPlaylistQueryValue.cs \
 	Banshee.Query/BansheeQuery.cs \
 	Banshee.Query/NaturalIntegerQueryValue.cs \
+	Banshee.Query/PlaybackErrorQueryValue.cs \
 	Banshee.Query/PlaylistQueryValue.cs \
 	Banshee.Query/RatingQueryValue.cs \
 	Banshee.Query/SmartPlaylistQueryValue.cs \
diff --git a/src/Core/Banshee.ThickClient/Banshee.Query.Gui/BansheeQueryBox.cs b/src/Core/Banshee.ThickClient/Banshee.Query.Gui/BansheeQueryBox.cs
index 7fa9743..6a3d292 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Query.Gui/BansheeQueryBox.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Query.Gui/BansheeQueryBox.cs
@@ -47,6 +47,7 @@ namespace Banshee.Query.Gui
             QueryValueEntry.AddSubType (typeof(RatingQueryValueEntry), typeof(RatingQueryValue));
             QueryValueEntry.AddSubType (typeof(PlaylistQueryValueEntry), typeof(PlaylistQueryValue));
             QueryValueEntry.AddSubType (typeof(SmartPlaylistQueryValueEntry), typeof(SmartPlaylistQueryValue));
+            QueryValueEntry.AddSubType (typeof(PlaybackErrorQueryValueEntry), typeof(PlaybackErrorQueryValue));
         }
     }
 }
diff --git a/src/Core/Banshee.ThickClient/Banshee.Query.Gui/PlaybackErrorQueryValueEntry.cs b/src/Core/Banshee.ThickClient/Banshee.Query.Gui/PlaybackErrorQueryValueEntry.cs
new file mode 100644
index 0000000..2fc5bde
--- /dev/null
+++ b/src/Core/Banshee.ThickClient/Banshee.Query.Gui/PlaybackErrorQueryValueEntry.cs
@@ -0,0 +1,89 @@
+//
+// PlaybackErrorQueryValueEntry.cs
+//
+// Author:
+//   Alexander Kojevnikov <alexander kojevnikov com>
+//
+// Copyright (C) 2009 Alexander Kojevnikov
+//
+// 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;
+using Gtk;
+
+using Hyena.Query;
+using Hyena.Query.Gui;
+
+using Banshee.Widgets;
+using Banshee.Query;
+
+namespace Banshee.Query.Gui
+{
+    public class PlaybackErrorQueryValueEntry : QueryValueEntry
+    {
+        protected ComboBox combo;
+        protected PlaybackErrorQueryValue query_value;
+        protected Dictionary<int, int> combo_error_id_map = new Dictionary<int, int> ();
+
+        public PlaybackErrorQueryValueEntry () : base ()
+        {
+        }
+
+        public override QueryValue QueryValue {
+            get { return query_value; }
+            set {
+                if (combo != null) {
+                    Remove (combo);
+                }
+
+                combo = ComboBox.NewText();
+                combo.WidthRequest = DefaultWidth;
+
+                Add (combo);
+                combo.Show ();
+
+                query_value = (PlaybackErrorQueryValue)value;
+                combo_error_id_map.Clear ();
+
+                int count = 0;
+                int active = 0;
+                foreach (var item in query_value.Items) {
+                    combo.AppendText (item.DisplayName);
+                    combo_error_id_map.Add (count++, item.ID);
+                    if (item.ID == (int)query_value.Value) {
+                        active = count - 1;
+                    }
+                }
+
+                combo.Changed += HandleValueChanged;
+                combo.Active = active;
+            }
+        }
+
+        protected void HandleValueChanged (object o, EventArgs args)
+        {
+            if (combo_error_id_map.ContainsKey (combo.Active)) {
+                query_value.SetValue (combo_error_id_map [combo.Active]);
+            }
+        }
+    }
+}
diff --git a/src/Core/Banshee.ThickClient/Banshee.ThickClient.csproj b/src/Core/Banshee.ThickClient/Banshee.ThickClient.csproj
index 4893796..4c8cd3f 100644
--- a/src/Core/Banshee.ThickClient/Banshee.ThickClient.csproj
+++ b/src/Core/Banshee.ThickClient/Banshee.ThickClient.csproj
@@ -276,6 +276,7 @@
     <Compile Include="Banshee.ContextPane\BaseContextPage.cs" />
     <Compile Include="Banshee.ContextPane\ContextPageManager.cs" />
     <Compile Include="Banshee.ContextPane\ContextPane.cs" />
+    <Compile Include="Banshee.Query.Gui\PlaybackErrorQueryValueEntry.cs" />
   </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
   <ProjectExtensions>
diff --git a/src/Core/Banshee.ThickClient/Makefile.am b/src/Core/Banshee.ThickClient/Makefile.am
index d53e769..037370a 100644
--- a/src/Core/Banshee.ThickClient/Makefile.am
+++ b/src/Core/Banshee.ThickClient/Makefile.am
@@ -135,6 +135,7 @@ SOURCES =  \
 	Banshee.Preferences.Gui/SectionBox.cs \
 	Banshee.Preferences.Gui/WidgetFactory.cs \
 	Banshee.Query.Gui/BansheeQueryBox.cs \
+	Banshee.Query.Gui/PlaybackErrorQueryValueEntry.cs \
 	Banshee.Query.Gui/PlaylistQueryValueEntry.cs \
 	Banshee.Query.Gui/RatingQueryValueEntry.cs \
 	Banshee.Query.Gui/SmartPlaylistQueryValueEntry.cs \
diff --git a/src/Libraries/Hyena/Hyena.Query/EnumQueryValue.cs b/src/Libraries/Hyena/Hyena.Query/EnumQueryValue.cs
new file mode 100644
index 0000000..6b83945
--- /dev/null
+++ b/src/Libraries/Hyena/Hyena.Query/EnumQueryValue.cs
@@ -0,0 +1,111 @@
+//
+// EnumQueryValue.cs
+//
+// Author:
+//   Alexander Kojevnikov <alexander kojevnikov com>
+//
+// Copyright (C) 2009 Alexander Kojevnikov
+//
+// 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;
+using System.Linq;
+using System.Xml;
+using System.Text;
+
+using Mono.Unix;
+
+using Hyena;
+
+namespace Hyena.Query
+{
+    public abstract class EnumQueryValue : QueryValue
+    {
+        public static readonly Operator Equal    = new Operator ("equals", Catalog.GetString ("is"), "= {0}", "=", "==", ":");
+        public static readonly Operator NotEqual = new Operator ("notEqual", Catalog.GetString ("is not"), "!= {0}", true, "!=", "!:");
+
+        protected int value;
+
+        public abstract IEnumerable<EnumQueryValueItem> Items { get; }
+
+        public override string XmlElementName {
+            get { return "int"; }
+        }
+
+        public override object Value {
+            get { return value; }
+        }
+
+        public void SetValue (int value)
+        {
+            this.value = value;
+            IsEmpty = false;
+        }
+
+        protected static AliasedObjectSet<Operator> operators = new AliasedObjectSet<Operator> (Equal, NotEqual);
+        public override AliasedObjectSet<Operator> OperatorSet {
+            get { return operators; }
+        }
+
+        public override void ParseUserQuery (string input)
+        {
+            foreach (var item in Items) {
+                if (input == item.ID.ToString () || input == item.Name || item.Aliases.Contains (input)) {
+                    value = item.ID;
+                    IsEmpty = false;
+                    break;
+                }
+            }
+        }
+
+        public override void ParseXml (XmlElement node)
+        {
+            IsEmpty = !Int32.TryParse (node.InnerText, out value);
+        }
+
+        public override void LoadString (string str)
+        {
+            ParseUserQuery (str);
+        }
+
+        public override string ToSql (Operator op)
+        {
+            return Convert.ToString (value, System.Globalization.CultureInfo.InvariantCulture);
+        }
+    }
+
+    public sealed class EnumQueryValueItem : IAliasedObject
+    {
+        public int ID { get; private set; }
+        public string Name { get; private set; }
+        public string DisplayName { get; private set; }
+        public string[] Aliases { get; private set; }
+
+        public EnumQueryValueItem (int id, string name, string display_name, params string[] aliases)
+        {
+            ID = id;
+            Name = name;
+            DisplayName = display_name;
+            Aliases = aliases;
+        }
+    }
+}
diff --git a/src/Libraries/Hyena/Hyena.csproj b/src/Libraries/Hyena/Hyena.csproj
index a752b38..675a713 100644
--- a/src/Libraries/Hyena/Hyena.csproj
+++ b/src/Libraries/Hyena/Hyena.csproj
@@ -153,6 +153,7 @@
     <Compile Include="Hyena.Jobs\Scheduler.cs" />
     <Compile Include="Hyena.Jobs\SimpleAsyncJob.cs" />
     <Compile Include="Hyena.Jobs\Tests\SchedulerTests.cs" />
+    <Compile Include="Hyena.Query\EnumQueryValue.cs" />
   </ItemGroup>
   <ItemGroup>
     <Reference Include="Mono.Posix">
diff --git a/src/Libraries/Hyena/Makefile.am b/src/Libraries/Hyena/Makefile.am
index e58a3ab..061f239 100644
--- a/src/Libraries/Hyena/Makefile.am
+++ b/src/Libraries/Hyena/Makefile.am
@@ -68,6 +68,7 @@ SOURCES =  \
 	Hyena.Json/TokenType.cs \
 	Hyena.Query/AliasedObjectSet.cs \
 	Hyena.Query/DateQueryValue.cs \
+	Hyena.Query/EnumQueryValue.cs \
 	Hyena.Query/ExactStringQueryValue.cs \
 	Hyena.Query/FileSizeQueryValue.cs \
 	Hyena.Query/IntegerKeyedObjectQueryValue.cs \



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