[banshee] Playlists: refactoring, introduce new PlaylistElement class
- From: AndrÃs Aragoneses <aaragoneses src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [banshee] Playlists: refactoring, introduce new PlaylistElement class
- Date: Sat, 1 Dec 2012 17:43:10 +0000 (UTC)
commit b3a60c09e2605e03acd301bae3808f8ea3b337c4
Author: Andres G. Aragoneses <knocte gmail com>
Date: Sat Dec 1 17:13:02 2012 +0000
Playlists: refactoring, introduce new PlaylistElement class
This class just replaces the primitive type Dictionary<string, object>.
This increases readability of the code and allows easier and clearer
refactorings in case we need to change how the playlist elements are
accessed/used.
No change of behaviour in this commit.
.../Banshee.Playlist/PlaylistFileUtil.cs | 4 +-
.../AsfReferencePlaylistFormat.cs | 2 +-
.../Banshee.Playlists.Formats/AsxPlaylistFormat.cs | 4 +-
.../Banshee.Playlists.Formats/IPlaylistFormat.cs | 2 +-
.../Banshee.Playlists.Formats/M3uPlaylistFormat.cs | 4 +-
.../Banshee.Playlists.Formats/PlaylistElement.cs | 36 ++++++++++++++++++++
.../PlaylistFormatBase.cs | 10 +++---
.../Banshee.Playlists.Formats/PlaylistParser.cs | 4 +-
.../Banshee.Playlists.Formats/PlsPlaylistFormat.cs | 2 +-
.../XspfPlaylistFormat.cs | 2 +-
src/Core/Banshee.Services/Banshee.Services.csproj | 1 +
.../Banshee.Streaming/RadioTrackInfo.cs | 2 +-
src/Core/Banshee.Services/Makefile.am | 1 +
.../Banshee.Dap.MassStorage/MassStorageSource.cs | 2 +-
14 files changed, 57 insertions(+), 19 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.Playlist/PlaylistFileUtil.cs b/src/Core/Banshee.Services/Banshee.Playlist/PlaylistFileUtil.cs
index 146201d..0eb2d97 100644
--- a/src/Core/Banshee.Services/Banshee.Playlist/PlaylistFileUtil.cs
+++ b/src/Core/Banshee.Services/Banshee.Playlist/PlaylistFileUtil.cs
@@ -118,7 +118,7 @@ namespace Banshee.Playlist
IPlaylistFormat playlist = Load (playlistUri, baseUri);
List<string> uris = new List<string> ();
if (playlist != null) {
- foreach (Dictionary<string, object> element in playlist.Elements) {
+ foreach (PlaylistElement element in playlist.Elements) {
uris.Add (((Uri)element["uri"]).AbsoluteUri);
}
}
@@ -195,7 +195,7 @@ namespace Banshee.Playlist
parser.BaseUri = new Uri (relative_dir);
if (parser.Parse (uri)) {
List<string> uris = new List<string> ();
- foreach (Dictionary<string, object> element in parser.Elements) {
+ foreach (PlaylistElement element in parser.Elements) {
uris.Add (((Uri)element["uri"]).LocalPath);
}
diff --git a/src/Core/Banshee.Services/Banshee.Playlists.Formats/AsfReferencePlaylistFormat.cs b/src/Core/Banshee.Services/Banshee.Playlists.Formats/AsfReferencePlaylistFormat.cs
index 7a8b012..384503c 100644
--- a/src/Core/Banshee.Services/Banshee.Playlists.Formats/AsfReferencePlaylistFormat.cs
+++ b/src/Core/Banshee.Services/Banshee.Playlists.Formats/AsfReferencePlaylistFormat.cs
@@ -59,7 +59,7 @@ namespace Banshee.Playlists.Formats
public override void Load (StreamReader reader, bool validateHeader)
{
string line;
- Dictionary<string, object> element = AddElement ();
+ PlaylistElement element = AddElement ();
while ((line = reader.ReadLine()) != null) {
if (line.StartsWith ("ref01", StringComparison.CurrentCultureIgnoreCase) ||
diff --git a/src/Core/Banshee.Services/Banshee.Playlists.Formats/AsxPlaylistFormat.cs b/src/Core/Banshee.Services/Banshee.Playlists.Formats/AsxPlaylistFormat.cs
index 6346170..918e832 100644
--- a/src/Core/Banshee.Services/Banshee.Playlists.Formats/AsxPlaylistFormat.cs
+++ b/src/Core/Banshee.Services/Banshee.Playlists.Formats/AsxPlaylistFormat.cs
@@ -109,7 +109,7 @@ namespace Banshee.Playlists.Formats
PlaylistParser secondary = new PlaylistParser ();
if (secondary.Parse (new SafeUri (ResolveUri (href)))) {
// splice in Elements of secondary
- foreach (Dictionary<string, object> e in secondary.Elements) {
+ foreach (PlaylistElement e in secondary.Elements) {
Elements.Add (e);
}
}
@@ -121,7 +121,7 @@ namespace Banshee.Playlists.Formats
private void LoadEntry (XmlTextReader xml_reader)
{
- Dictionary<string, object> element = AddElement ();
+ PlaylistElement element = AddElement ();
do {
try {
diff --git a/src/Core/Banshee.Services/Banshee.Playlists.Formats/IPlaylistFormat.cs b/src/Core/Banshee.Services/Banshee.Playlists.Formats/IPlaylistFormat.cs
index 98d8114..c16197f 100644
--- a/src/Core/Banshee.Services/Banshee.Playlists.Formats/IPlaylistFormat.cs
+++ b/src/Core/Banshee.Services/Banshee.Playlists.Formats/IPlaylistFormat.cs
@@ -42,7 +42,7 @@ namespace Banshee.Playlists.Formats
void Save(Stream stream, ITrackModelSource source);
Dictionary<string, object> Attributes { get; }
- List<Dictionary<string, object>> Elements { get; }
+ List<PlaylistElement> Elements { get; }
Uri BaseUri { get; set; }
string Title { get; set; }
diff --git a/src/Core/Banshee.Services/Banshee.Playlists.Formats/M3uPlaylistFormat.cs b/src/Core/Banshee.Services/Banshee.Playlists.Formats/M3uPlaylistFormat.cs
index 82b66eb..77885ec 100644
--- a/src/Core/Banshee.Services/Banshee.Playlists.Formats/M3uPlaylistFormat.cs
+++ b/src/Core/Banshee.Services/Banshee.Playlists.Formats/M3uPlaylistFormat.cs
@@ -63,7 +63,7 @@ namespace Banshee.Playlists.Formats
public override void Load(StreamReader reader, bool validateHeader)
{
string line;
- Dictionary<string, object> element = null;
+ PlaylistElement element = null;
while((line = reader.ReadLine()) != null) {
line = line.Trim();
@@ -97,7 +97,7 @@ namespace Banshee.Playlists.Formats
}
}
- private void ParseExtended(Dictionary<string, object> element, string line)
+ private void ParseExtended (PlaylistElement element, string line)
{
string split = line.Substring(8).TrimStart(',');
string [] parts = split.Split(new char [] { ',' }, 2);
diff --git a/src/Core/Banshee.Services/Banshee.Playlists.Formats/PlaylistElement.cs b/src/Core/Banshee.Services/Banshee.Playlists.Formats/PlaylistElement.cs
new file mode 100644
index 0000000..7e5690d
--- /dev/null
+++ b/src/Core/Banshee.Services/Banshee.Playlists.Formats/PlaylistElement.cs
@@ -0,0 +1,36 @@
+//
+// PlaylistElement.cs
+//
+// Author:
+// Andres G. Aragoneses <knocte gmail com>
+//
+// Copyright 2012 Andres G. Aragoneses
+//
+// 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 Banshee.Playlists.Formats
+{
+ public class PlaylistElement : Dictionary<string, object>
+ {
+ }
+}
+
diff --git a/src/Core/Banshee.Services/Banshee.Playlists.Formats/PlaylistFormatBase.cs b/src/Core/Banshee.Services/Banshee.Playlists.Formats/PlaylistFormatBase.cs
index 3a5c2c1..02259e0 100644
--- a/src/Core/Banshee.Services/Banshee.Playlists.Formats/PlaylistFormatBase.cs
+++ b/src/Core/Banshee.Services/Banshee.Playlists.Formats/PlaylistFormatBase.cs
@@ -40,14 +40,14 @@ namespace Banshee.Playlists.Formats
public abstract class PlaylistFormatBase : IPlaylistFormat
{
private Dictionary<string, object> attributes = new Dictionary<string, object>();
- private List<Dictionary<string, object>> elements = new List<Dictionary<string, object>>();
+ private List<PlaylistElement> elements = new List<PlaylistElement> ();
private Uri base_uri = null;
private string title = null;
public PlaylistFormatBase()
{
attributes = new Dictionary<string, object>();
- elements = new List<Dictionary<string, object>>();
+ elements = new List<PlaylistElement> ();
if (Environment.CurrentDirectory.Equals ("/")) {
// System.Uri doesn't like / as a value
@@ -69,9 +69,9 @@ namespace Banshee.Playlists.Formats
public abstract void Save(Stream stream, ITrackModelSource source);
- protected virtual Dictionary<string, object> AddElement()
+ protected virtual PlaylistElement AddElement ()
{
- Dictionary<string, object> element = new Dictionary<string, object>();
+ var element = new PlaylistElement ();
Elements.Add(element);
return element;
}
@@ -112,7 +112,7 @@ namespace Banshee.Playlists.Formats
get { return attributes; }
}
- public virtual List<Dictionary<string, object>> Elements {
+ public virtual List<PlaylistElement> Elements {
get { return elements; }
}
diff --git a/src/Core/Banshee.Services/Banshee.Playlists.Formats/PlaylistParser.cs b/src/Core/Banshee.Services/Banshee.Playlists.Formats/PlaylistParser.cs
index 6dcad3a..9e416dc 100644
--- a/src/Core/Banshee.Services/Banshee.Playlists.Formats/PlaylistParser.cs
+++ b/src/Core/Banshee.Services/Banshee.Playlists.Formats/PlaylistParser.cs
@@ -49,7 +49,7 @@ namespace Banshee.Playlists.Formats
XspfPlaylistFormat.FormatDescription
};
- private List<Dictionary<string, object>> elements;
+ private List<PlaylistElement> elements;
private Uri base_uri = null;
private string title = null;
private readonly int HTTP_REQUEST_RETRIES = 3;
@@ -192,7 +192,7 @@ namespace Banshee.Playlists.Formats
}
}
- public List<Dictionary<string, object>> Elements {
+ public List<PlaylistElement> Elements {
get { return elements; }
}
diff --git a/src/Core/Banshee.Services/Banshee.Playlists.Formats/PlsPlaylistFormat.cs b/src/Core/Banshee.Services/Banshee.Playlists.Formats/PlsPlaylistFormat.cs
index 44ff9e9..84f8aa0 100644
--- a/src/Core/Banshee.Services/Banshee.Playlists.Formats/PlsPlaylistFormat.cs
+++ b/src/Core/Banshee.Services/Banshee.Playlists.Formats/PlsPlaylistFormat.cs
@@ -108,7 +108,7 @@ namespace Banshee.Playlists.Formats
int index = Int32.Parse(line.Substring(index_offset, eq_offset - index_offset),
ApplicationContext.InternalCultureInfo.NumberFormat) - 1;
string value_string = line.Substring(eq_offset + 1).Trim();
- Dictionary<string, object> element = index < Elements.Count
+ PlaylistElement element = index < Elements.Count
? Elements[index]
: AddElement();
diff --git a/src/Core/Banshee.Services/Banshee.Playlists.Formats/XspfPlaylistFormat.cs b/src/Core/Banshee.Services/Banshee.Playlists.Formats/XspfPlaylistFormat.cs
index 5c0fe26..58d90b7 100644
--- a/src/Core/Banshee.Services/Banshee.Playlists.Formats/XspfPlaylistFormat.cs
+++ b/src/Core/Banshee.Services/Banshee.Playlists.Formats/XspfPlaylistFormat.cs
@@ -66,7 +66,7 @@ namespace Banshee.Playlists.Formats
playlist.Load (stream);
Title = playlist.Title;
foreach (Xspf.Track track in playlist.Tracks) {
- Dictionary<string, object> element = AddElement ();
+ PlaylistElement element = AddElement ();
element["uri"] = track.GetLocationAt (0);
}
}
diff --git a/src/Core/Banshee.Services/Banshee.Services.csproj b/src/Core/Banshee.Services/Banshee.Services.csproj
index b52262f..83ae213 100644
--- a/src/Core/Banshee.Services/Banshee.Services.csproj
+++ b/src/Core/Banshee.Services/Banshee.Services.csproj
@@ -328,6 +328,7 @@
<Compile Include="Banshee.Collection.Database\DatabaseYearListModel.cs" />
<Compile Include="Banshee.Collection\InvalidFileException.cs" />
<Compile Include="Banshee.Sources\IBatchScrobblerSource.cs" />
+ <Compile Include="Banshee.Playlists.Formats\PlaylistElement.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Banshee.Services.addin.xml">
diff --git a/src/Core/Banshee.Services/Banshee.Streaming/RadioTrackInfo.cs b/src/Core/Banshee.Services/Banshee.Streaming/RadioTrackInfo.cs
index 4c5807e..e83cbaa 100644
--- a/src/Core/Banshee.Services/Banshee.Streaming/RadioTrackInfo.cs
+++ b/src/Core/Banshee.Services/Banshee.Streaming/RadioTrackInfo.cs
@@ -292,7 +292,7 @@ namespace Banshee.Streaming
try {
PlaylistParser parser = new PlaylistParser();
if (parser.Parse(new SafeUri(uri))) {
- foreach(Dictionary<string, object> element in parser.Elements) {
+ foreach (PlaylistElement element in parser.Elements) {
if(element.ContainsKey("uri")) {
// mms can be a nested link
string element_uri = element["uri"].ToString();
diff --git a/src/Core/Banshee.Services/Makefile.am b/src/Core/Banshee.Services/Makefile.am
index 3bf10ae..f73a7c4 100644
--- a/src/Core/Banshee.Services/Makefile.am
+++ b/src/Core/Banshee.Services/Makefile.am
@@ -157,6 +157,7 @@ SOURCES = \
Banshee.Playlists.Formats/InvalidPlaylistException.cs \
Banshee.Playlists.Formats/IPlaylistFormat.cs \
Banshee.Playlists.Formats/M3uPlaylistFormat.cs \
+ Banshee.Playlists.Formats/PlaylistElement.cs \
Banshee.Playlists.Formats/PlaylistFormatBase.cs \
Banshee.Playlists.Formats/PlaylistFormatDescription.cs \
Banshee.Playlists.Formats/PlaylistParser.cs \
diff --git a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs
index 79c1e3e..f142f6d 100644
--- a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs
+++ b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs
@@ -177,7 +177,7 @@ namespace Banshee.Dap.MassStorage
PlaylistSource playlist = new PlaylistSource (name, this);
playlist.Save ();
//Hyena.Data.Sqlite.HyenaSqliteCommand.LogAll = true;
- foreach (Dictionary<string, object> element in loaded_playlist.Elements) {
+ foreach (PlaylistElement element in loaded_playlist.Elements) {
string track_path = (element["uri"] as Uri).LocalPath;
int track_id = DatabaseTrackInfo.GetTrackIdForUri (new SafeUri (track_path), DbId);
if (track_id == 0) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]