[banshee: 25/57] Moved the parsing code into a UPnP Device container which can later hold many sources
- From: Bertrand Lorentz <blorentz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [banshee: 25/57] Moved the parsing code into a UPnP Device container which can later hold many sources
- Date: Mon, 13 Feb 2012 20:29:55 +0000 (UTC)
commit 03c03e42dced504f2bc7fb2691dd3a120418b311
Author: Tobias Arrskog <topfs2 xbmc org>
Date: Tue Jul 5 21:56:30 2011 +0200
Moved the parsing code into a UPnP Device container which can later hold many sources
.../Banshee.UPnPClient/Banshee.UPnPClient.csproj | 1 +
.../Banshee.UPnPClient/UPnPMusicSource.cs | 6 +-
.../Banshee.UPnPClient/UPnPServerSource.cs | 178 ++++++++++++++++++++
.../Banshee.UPnPClient/UPnPService.cs | 99 +-----------
src/Extensions/Banshee.UPnPClient/Makefile.am | 1 +
5 files changed, 183 insertions(+), 102 deletions(-)
---
diff --git a/src/Extensions/Banshee.UPnPClient/Banshee.UPnPClient.csproj b/src/Extensions/Banshee.UPnPClient/Banshee.UPnPClient.csproj
index 776ae30..e13cfd1 100644
--- a/src/Extensions/Banshee.UPnPClient/Banshee.UPnPClient.csproj
+++ b/src/Extensions/Banshee.UPnPClient/Banshee.UPnPClient.csproj
@@ -84,6 +84,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Banshee.UPnPClient\UPnPMusicSource.cs" />
+ <Compile Include="Banshee.UPnPClient\UPnPServerSource.cs" />
<Compile Include="Banshee.UPnPClient\UPnPService.cs" />
<Compile Include="Banshee.UPnPClient\UPnPContainerSource.cs" />
<Compile Include="Banshee.UPnPClient\UPnPTrackInfo.cs" />
diff --git a/src/Extensions/Banshee.UPnPClient/Banshee.UPnPClient/UPnPMusicSource.cs b/src/Extensions/Banshee.UPnPClient/Banshee.UPnPClient/UPnPMusicSource.cs
index 1955597..8bc8f03 100644
--- a/src/Extensions/Banshee.UPnPClient/Banshee.UPnPClient/UPnPMusicSource.cs
+++ b/src/Extensions/Banshee.UPnPClient/Banshee.UPnPClient/UPnPMusicSource.cs
@@ -54,10 +54,8 @@ namespace Banshee.UPnPClient
const int sort_order = 190;
private Dictionary<string, UPnPTrackInfo> music_tracks;
- public UPnPMusicSource (Device device) : base (Catalog.GetString ("Music Share"), device.FriendlyName, device.Udn, sort_order)
+ public UPnPMusicSource (string udn) : base (Catalog.GetString ("Music"), Catalog.GetString ("Music"), udn + "-music", sort_order)
{
- Hyena.Log.Information ("UPnPSource.Added(\"" + this.Name + "\", \"" + this.UniqueId + "\")");
-
Properties.SetStringList ("Icon.Name", "computer", "network-server");
music_tracks = new Dictionary<string, UPnPTrackInfo>();
@@ -81,8 +79,6 @@ namespace Banshee.UPnPClient
public void Disconnect ()
{
- Hyena.Log.Information ("UPnPSource.Disconnect(\"" + this.Name + "\", \"" + this.UniqueId + "\")");
-
// Stop currently playing track if its from us.
try {
if (ServiceManager.PlayerEngine.CurrentState == Banshee.MediaEngine.PlayerState.Playing) {
diff --git a/src/Extensions/Banshee.UPnPClient/Banshee.UPnPClient/UPnPServerSource.cs b/src/Extensions/Banshee.UPnPClient/Banshee.UPnPClient/UPnPServerSource.cs
new file mode 100644
index 0000000..fd50c0f
--- /dev/null
+++ b/src/Extensions/Banshee.UPnPClient/Banshee.UPnPClient/UPnPServerSource.cs
@@ -0,0 +1,178 @@
+//
+// UPnPContainerSource.cs
+//
+// Authors:
+// Tobias 'topfs2' Arrskog <tobias arrskog gmail com>
+//
+// Copyright (C) 2011 Tobias 'topfs2' Arrskog
+//
+// 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 Mono.Upnp;
+using Mono.Upnp.Dcp.MediaServer1.ContentDirectory1;
+using Mono.Upnp.Dcp.MediaServer1.ContentDirectory1.AV;
+
+using Banshee.Base;
+using Banshee.Collection;
+using Banshee.Configuration;
+using Banshee.Sources;
+using Banshee.ServiceStack;
+
+namespace Banshee.UPnPClient
+{
+ public class UPnPServerSource : Source
+ {
+ UPnPMusicSource music_source;
+ private SchemaEntry<bool> expanded_schema;
+
+ public UPnPServerSource (Device device) : base (Catalog.GetString ("UPnP Share"), device.FriendlyName, 300)
+ {
+ Properties.SetStringList ("Icon.Name", "applications-internet", "network-server");
+ TypeUniqueId = "upnp-container";
+ expanded_schema = new SchemaEntry<bool> ("plugins.upnp." + device.Udn, "expanded", true, "UPnP Share expanded", "UPnP Share expanded" );
+
+ ContentDirectoryController contentDirectory = null;
+
+ foreach (Service service in device.Services) {
+ Hyena.Log.Debug ("UPnPService \"" + device.FriendlyName + "\" Implements " + service.Type);
+ if (service.Type.Equals (Mono.Upnp.Dcp.MediaServer1.ContentDirectory1.ContentDirectory.ServiceType))
+ contentDirectory = new ContentDirectoryController (service.GetController());
+ }
+
+ if (contentDirectory == null)
+ throw new ArgumentNullException("contentDirectory");
+
+ music_source = new UPnPMusicSource(device.Udn);
+ AddChildSource (music_source);
+
+ Parse (contentDirectory);
+ }
+
+ void Parse (ContentDirectoryController contentDirectory)
+ {
+ RemoteContentDirectory remoteContentDirectory = new RemoteContentDirectory (contentDirectory);
+ List<MusicTrack> musicTracks = new List<MusicTrack>();
+ DateTime begin = DateTime.Now;
+ Container root = remoteContentDirectory.GetRootObject();
+ bool recursiveBrowse = !contentDirectory.CanSearch;
+
+ if (!recursiveBrowse) {
+ try {
+ Hyena.Log.Debug ("Searchable, lets search");
+ Results<MusicTrack> results = remoteContentDirectory.Search<MusicTrack>(root, visitor => visitor.VisitDerivedFrom("upnp:class", "object.item.audioItem.musicTrack"), new ResultsSettings());
+ bool hasresults = results.Count > 0;
+
+ while (hasresults) {
+ foreach (var item in results) {
+ musicTracks.Add(item as MusicTrack);
+ }
+
+ if (results.HasMoreResults) {
+ results = results.GetMoreResults(remoteContentDirectory);
+ music_source.AddTracks (musicTracks);
+ musicTracks.Clear();
+ }
+ else
+ hasresults = false;
+ }
+ } catch (Exception exception) {
+ Hyena.Log.Exception (exception);
+ recursiveBrowse = true;
+ }
+ }
+ if (recursiveBrowse) {
+ try {
+ Hyena.Log.Debug ("Not searchable, lets recursive browse");
+ ParseContainer (remoteContentDirectory, root, 0, musicTracks);
+ } catch (Exception exception) {
+ Hyena.Log.Exception (exception);
+ }
+ }
+
+ if (musicTracks.Count > 0)
+ music_source.AddTracks (musicTracks);
+
+ Hyena.Log.Debug ("Found all items on the service, took " + (DateTime.Now - begin).ToString());
+ }
+
+ void ParseContainer (RemoteContentDirectory remoteContentDirectory, Container container, int depth, List<MusicTrack> musicTracks)
+ {
+ if (depth > 10 || (container.ChildCount != null && container.ChildCount == 0))
+ return;
+ Results<Mono.Upnp.Dcp.MediaServer1.ContentDirectory1.Object> results = remoteContentDirectory.GetChildren<Mono.Upnp.Dcp.MediaServer1.ContentDirectory1.Object>(container);
+ bool hasresults = results.Count > 0;
+ while (hasresults) {
+ foreach (var upnp_object in results) {
+ if (upnp_object is Item) {
+ Item item = upnp_object as Item;
+
+ if (item.IsReference || item.Resources.Count == 0)
+ continue;
+
+ if (item is MusicTrack) {
+ musicTracks.Add(item as MusicTrack);
+ }
+ }
+ else if (upnp_object is Container) {
+ ParseContainer (remoteContentDirectory, upnp_object as Container, depth + 1, musicTracks);
+ }
+
+ if (musicTracks.Count > 500) {
+ music_source.AddTracks (musicTracks);
+ musicTracks.Clear();
+ }
+ }
+
+ if (results.HasMoreResults)
+ results = results.GetMoreResults(remoteContentDirectory);
+ else
+ hasresults = false;
+ }
+ }
+
+ public void Disconnect ()
+ {
+ music_source.Disconnect ();
+ }
+
+ public override bool? AutoExpand {
+ get { return expanded_schema.Get (); }
+ }
+
+ public override bool Expanded {
+ get { return expanded_schema.Get (); }
+ set { expanded_schema.Set (value); }
+ }
+
+ public override bool CanActivate {
+ get { return false; }
+ }
+
+ public override bool CanRename {
+ get { return false; }
+ }
+ }
+}
diff --git a/src/Extensions/Banshee.UPnPClient/Banshee.UPnPClient/UPnPService.cs b/src/Extensions/Banshee.UPnPClient/Banshee.UPnPClient/UPnPService.cs
index 7eb2337..9247e43 100644
--- a/src/Extensions/Banshee.UPnPClient/Banshee.UPnPClient/UPnPService.cs
+++ b/src/Extensions/Banshee.UPnPClient/Banshee.UPnPClient/UPnPService.cs
@@ -77,105 +77,10 @@ namespace Banshee.UPnPClient
Hyena.Log.Debug ("UPnPService.DeviceAdded (" + e.Device.ToString() + ") (" + e.Device.Type + ")");
Device device = e.Device.GetDevice();
- ContentDirectoryController contentDirectory = null;
-
- foreach (Service service in device.Services) {
- Hyena.Log.Debug ("UPnPService \"" + device.FriendlyName + "\" Implements " + service.Type);
- if (service.Type.Equals (Mono.Upnp.Dcp.MediaServer1.ContentDirectory1.ContentDirectory.ServiceType))
- contentDirectory = new ContentDirectoryController (service.GetController());
- }
-
- if (contentDirectory != null)
- {
- UPnPMusicSource source = new UPnPMusicSource(device);
- container.AddChildSource (source);
- Parse(source, contentDirectory);
- }
- }
-
-
- static void Parse (UPnPMusicSource source, ContentDirectoryController contentDirectory)
- {
- RemoteContentDirectory remoteContentDirectory = new RemoteContentDirectory (contentDirectory);
- List<MusicTrack> musicTracks = new List<MusicTrack>();
- DateTime begin = DateTime.Now;
- Container root = remoteContentDirectory.GetRootObject();
- bool recursiveBrowse = !contentDirectory.CanSearch;
-
- if (!recursiveBrowse) {
- try {
- Hyena.Log.Debug ("Searchable, lets search");
- Results<MusicTrack> results = remoteContentDirectory.Search<MusicTrack>(root, visitor => visitor.VisitDerivedFrom("upnp:class", "object.item.audioItem.musicTrack"), new ResultsSettings());
- bool hasresults = results.Count > 0;
-
- while (hasresults) {
- foreach (var item in results) {
- musicTracks.Add(item as MusicTrack);
- }
-
- if (results.HasMoreResults) {
- results = results.GetMoreResults(remoteContentDirectory);
- source.AddTracks (musicTracks);
- musicTracks.Clear();
- }
- else
- hasresults = false;
- }
- } catch (Exception exception) {
- Hyena.Log.Exception (exception);
- recursiveBrowse = true;
- }
- }
- if (recursiveBrowse) {
- try {
- Hyena.Log.Debug ("Not searchable, lets recursive browse");
- ParseContainer (source, remoteContentDirectory, root, 0, musicTracks);
- } catch (Exception exception) {
- Hyena.Log.Exception (exception);
- }
- }
-
- if (musicTracks.Count > 0)
- source.AddTracks (musicTracks);
-
- Hyena.Log.Debug ("Found all items on the service, took " + (DateTime.Now - begin).ToString());
+ UPnPServerSource source = new UPnPServerSource(device);
+ container.AddChildSource (source);
}
- static void ParseContainer (UPnPMusicSource source, RemoteContentDirectory remoteContentDirectory, Container container, int depth, List<MusicTrack> musicTracks)
- {
- if (depth > 10 || (container.ChildCount != null && container.ChildCount == 0))
- return;
- Results<Mono.Upnp.Dcp.MediaServer1.ContentDirectory1.Object> results = remoteContentDirectory.GetChildren<Mono.Upnp.Dcp.MediaServer1.ContentDirectory1.Object>(container);
- bool hasresults = results.Count > 0;
- while (hasresults) {
- foreach (var upnp_object in results) {
- if (upnp_object is Item) {
- Item item = upnp_object as Item;
-
- if (item.IsReference || item.Resources.Count == 0)
- continue;
-
- if (item is MusicTrack) {
- musicTracks.Add(item as MusicTrack);
- }
- }
- else if (upnp_object is Container) {
- ParseContainer (source, remoteContentDirectory, upnp_object as Container, depth + 1, musicTracks);
- }
-
- if (musicTracks.Count > 500) {
- source.AddTracks (musicTracks);
- musicTracks.Clear();
- }
- }
-
- if (results.HasMoreResults)
- results = results.GetMoreResults(remoteContentDirectory);
- else
- hasresults = false;
- }
- }
-
string IService.ServiceName {
get { return "uPnP Client service"; }
}
diff --git a/src/Extensions/Banshee.UPnPClient/Makefile.am b/src/Extensions/Banshee.UPnPClient/Makefile.am
index 98700b0..2749aa8 100644
--- a/src/Extensions/Banshee.UPnPClient/Makefile.am
+++ b/src/Extensions/Banshee.UPnPClient/Makefile.am
@@ -6,6 +6,7 @@ INSTALL_DIR = $(EXTENSIONS_INSTALL_DIR)
SOURCES = \
Banshee.UPnPClient/UPnPContainerSource.cs \
Banshee.UPnPClient/UPnPService.cs \
+ Banshee.UPnPClient/UPnPServerSource.cs \
Banshee.UPnPClient/UPnPMusicSource.cs \
Banshee.UPnPClient/UPnPTrackInfo.cs
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]