[banshee] [Daap] Connect to remote servers (bgo#407496)
- From: Alexander Kojevnikov <alexk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [banshee] [Daap] Connect to remote servers (bgo#407496)
- Date: Sun, 4 Apr 2010 03:42:47 +0000 (UTC)
commit e487bf9d99c5d66734995d931be374d4079c094e
Author: Félix Velasco <felix velasco gmail com>
Date: Sun Apr 4 13:41:54 2010 +1000
[Daap] Connect to remote servers (bgo#407496)
Signed-off-by: Alexander Kojevnikov <alexander kojevnikov com>
po/POTFILES.in | 3 +
src/Extensions/Banshee.Daap/Banshee.Daap.csproj | 5 +
.../Banshee.Daap/Banshee.Daap/DaapResolverJob.cs | 79 ++++++++++++++++++
.../Banshee.Daap/Banshee.Daap/DaapService.cs | 75 ++++++++++++++++-
.../Banshee.Daap/Banshee.Daap/OpenRemoteServer.cs | 88 ++++++++++++++++++++
src/Extensions/Banshee.Daap/Makefile.am | 5 +-
src/Extensions/Banshee.Daap/Resources/GlobalUI.xml | 9 ++
7 files changed, 260 insertions(+), 4 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 1fe7a81..7325f84 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -194,7 +194,10 @@ src/Extensions/Banshee.Daap/Banshee.Daap/DaapContainerSource.cs
src/Extensions/Banshee.Daap/Banshee.Daap/DaapErrorView.cs
src/Extensions/Banshee.Daap/Banshee.Daap/DaapLoginDialog.cs
src/Extensions/Banshee.Daap/Banshee.Daap/DaapPlaylistSource.cs
+src/Extensions/Banshee.Daap/Banshee.Daap/DaapResolverJob.cs.cs
+src/Extensions/Banshee.Daap/Banshee.Daap/DaapService.cs
src/Extensions/Banshee.Daap/Banshee.Daap/DaapSource.cs
+src/Extensions/Banshee.Daap/Banshee.Daap/OpenRemoteServer.cs
src/Extensions/Banshee.Emusic/Banshee.Emusic/DownloadManager/DownloadUserJob.cs
src/Extensions/Banshee.Emusic/Banshee.Emusic/EmusicImport.cs
src/Extensions/Banshee.FileSystemQueue/Banshee.FileSystemQueue.addin.xml
diff --git a/src/Extensions/Banshee.Daap/Banshee.Daap.csproj b/src/Extensions/Banshee.Daap/Banshee.Daap.csproj
index 7a3fe86..58a2b90 100644
--- a/src/Extensions/Banshee.Daap/Banshee.Daap.csproj
+++ b/src/Extensions/Banshee.Daap/Banshee.Daap.csproj
@@ -99,6 +99,8 @@
<Compile Include="Banshee.Daap\DaapPlaylistSource.cs" />
<Compile Include="Banshee.Daap\DaapProxyWebServer.cs" />
<Compile Include="Banshee.Daap\DaapErrorView.cs" />
+ <Compile Include="Banshee.Daap\DaapResolverJob.cs" />
+ <Compile Include="Banshee.Daap\OpenRemoteServer.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Daap\content-codes">
@@ -107,6 +109,9 @@
<EmbeddedResource Include="Banshee.Daap.addin.xml">
<LogicalName>Banshee.Daap.addin.xml</LogicalName>
</EmbeddedResource>
+ <EmbeddedResource Include="Resources\GlobalUI.xml">
+ <LogicalName>GlobalUI.xml</LogicalName>
+ </EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
diff --git a/src/Extensions/Banshee.Daap/Banshee.Daap/DaapResolverJob.cs b/src/Extensions/Banshee.Daap/Banshee.Daap/DaapResolverJob.cs
new file mode 100644
index 0000000..0fb8a2a
--- /dev/null
+++ b/src/Extensions/Banshee.Daap/Banshee.Daap/DaapResolverJob.cs
@@ -0,0 +1,79 @@
+//
+// DaapResolverJob.cs
+//
+// Authors:
+// Félix Velasco <felix velasco gmail com>
+//
+// Copyright (C) 2009 Félix Velasco
+//
+// 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.Net;
+
+using Daap;
+using NativeDaap = Daap;
+using Hyena;
+using Hyena.Jobs;
+
+using Banshee.I18n;
+using Banshee.ServiceStack;
+
+namespace Banshee.Daap
+{
+ public class DaapResolverJob : SimpleAsyncJob
+ {
+ private IPAddress address;
+ private ushort port;
+ private Service service = null;
+ private string server;
+
+ public DaapResolverJob (string server, IPAddress address, ushort port) :
+ base (String.Format (Catalog.GetString ("Connecting to {0}"), server), PriorityHints.None, null)
+ {
+ this.server = server;
+ this.address = address;
+ this.port = port;
+
+ IsBackground = false;
+ CanCancel = false;
+ DelayShow = true;
+ IconNames = new string [] { "applications-internet" };
+ }
+
+ protected override void Run ()
+ {
+ try {
+ NativeDaap.Client tmp_client = new NativeDaap.Client (address, port);
+ service = new Service (address, port, tmp_client.Name, tmp_client.AuthenticationMethod != AuthenticationMethod.None);
+ } catch (WebException) {
+ // On error, create a dummy service
+ service = new Service (address, port, server, false);
+ }
+
+ OnFinished ();
+ }
+
+ public Service DaapService {
+ get { return service; }
+ }
+ }
+}
diff --git a/src/Extensions/Banshee.Daap/Banshee.Daap/DaapService.cs b/src/Extensions/Banshee.Daap/Banshee.Daap/DaapService.cs
index e01d4a9..d6b1833 100644
--- a/src/Extensions/Banshee.Daap/Banshee.Daap/DaapService.cs
+++ b/src/Extensions/Banshee.Daap/Banshee.Daap/DaapService.cs
@@ -28,12 +28,17 @@
using System;
using System.Collections.Generic;
+using System.Net;
+using System.Net.Sockets;
using Mono.Unix;
+using NativeDaap = Daap;
using Daap;
+using Gtk;
using Hyena;
using Banshee.Collection;
+using Banshee.Gui;
using Banshee.Sources;
using Banshee.ServiceStack;
@@ -90,9 +95,14 @@ namespace Banshee.Daap
private void OnServiceFound (object o, ServiceArgs args)
{
+ AddDaapServer (args.Service);
+ }
+
+ private void AddDaapServer (Service service)
+ {
ThreadAssist.ProxyToMain (delegate {
- DaapSource source = new DaapSource (args.Service);
- string key = String.Format ("{0}:{1}", args.Service.Name, args.Service.Port);
+ DaapSource source = new DaapSource (service);
+ string key = String.Format ("{0}:{1}", service.Name, service.Port);
if (source_map.Count == 0) {
ServiceManager.SourceManager.AddSource (container);
@@ -159,8 +169,67 @@ namespace Banshee.Daap
proxy_server = new DaapProxyWebServer ();
proxy_server.Start ();
} catch (Exception e) {
- Hyena.Log.Exception ("Failed to start DAAP client", e);
+ Log.Exception ("Failed to start DAAP client", e);
+ }
+
+ var uia_service = ServiceManager.Get<InterfaceActionService> ();
+ uia_service.GlobalActions.Add (
+ new ActionEntry ("AddRemoteDaapServerAction", Stock.Add,
+ Catalog.GetString ("Add remote DAAP server"), null,
+ Catalog.GetString ("Add a new remote DAAP server"),
+ OnAddRemoteServer)
+ );
+ uia_service.UIManager.AddUiFromResource ("GlobalUI.xml");
+ }
+
+ private void OnAddRemoteServer (object o, EventArgs args)
+ {
+ ResponseType response;
+ string s_address;
+ ushort port;
+
+ using (OpenRemoteServer dialog = new OpenRemoteServer ()) {
+ response = (ResponseType) dialog.Run ();
+ s_address = dialog.Address;
+ port = (ushort) dialog.Port;
+ dialog.Destroy ();
+ }
+
+ if (response != ResponseType.Ok)
+ return;
+
+ Log.DebugFormat ("Trying to add DAAP server on {0}:{1}", s_address, port);
+ IPHostEntry hostEntry = null;
+ try {
+ hostEntry = Dns.GetHostEntry (s_address);
+ } catch (SocketException) {
+ Log.Warning ("Unable to resolve host " + s_address);
+ return;
+ }
+
+ IPAddress address = hostEntry.AddressList[0];
+ foreach (IPAddress curAdd in hostEntry.AddressList) {
+ if (curAdd.AddressFamily == AddressFamily.InterNetwork) {
+ address = curAdd;
+ }
}
+ Log.DebugFormat (String.Format("Resolved {0} to {1}", s_address, address));
+ Log.Debug ("Spawning daap resolving thread");
+
+ DaapResolverJob job = new DaapResolverJob(s_address, address, port);
+
+ job.Finished += delegate {
+ Service service = job.DaapService;
+
+ if (service != null) {
+ AddDaapServer (service);
+ Log.DebugFormat ("Created server {0}", service.Name);
+ } else {
+ Log.DebugFormat ("Unable to create service for {0}", s_address);
+ }
+ };
+
+ ServiceManager.JobScheduler.Add (job);
}
string IService.ServiceName {
diff --git a/src/Extensions/Banshee.Daap/Banshee.Daap/OpenRemoteServer.cs b/src/Extensions/Banshee.Daap/Banshee.Daap/OpenRemoteServer.cs
new file mode 100644
index 0000000..1fa7435
--- /dev/null
+++ b/src/Extensions/Banshee.Daap/Banshee.Daap/OpenRemoteServer.cs
@@ -0,0 +1,88 @@
+//
+// OpenRemoteServer.cs
+//
+// Author:
+// Félix Velasco <felix velasco gmail com>
+//
+// Copyright (C) 2009 Félix Velasco
+//
+// 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 Gtk;
+
+using Banshee.Base;
+using Banshee.Gui.Dialogs;
+using Banshee.Configuration;
+
+namespace Banshee.Daap
+{
+ public class OpenRemoteServer : BansheeDialog
+ {
+ private Entry address_entry;
+ private SpinButton port_entry;
+
+ public OpenRemoteServer () : base (Catalog.GetString ("Open remote DAAP server"), null)
+ {
+ Label label = new Label (Catalog.GetString ("Enter server name or ip:"));
+ VBox.PackStart (label, true, true, 0);
+
+ HBox box = new HBox ();
+ box.BorderWidth = 10;
+ box.Spacing = 10;
+ VBox.PackStart (box, false, false, 0);
+
+ address_entry = new Entry ();
+ address_entry.Activated += OnEntryActivated;
+ address_entry.WidthChars = 50;
+ address_entry.Show ();
+
+ port_entry = new SpinButton (1f, 65535f, 1.0f);
+ port_entry.Value = 3689;
+ port_entry.Show ();
+
+ box.PackStart (address_entry, true, true, 0);
+ box.PackEnd (port_entry, false, false, 0);
+
+ address_entry.HasFocus = true;
+
+ VBox.ShowAll ();
+
+ AddStockButton (Stock.Cancel, ResponseType.Cancel);
+ AddStockButton (Stock.Ok, ResponseType.Ok, true);
+ }
+
+ private void OnEntryActivated (object o, EventArgs args)
+ {
+ Respond (ResponseType.Ok);
+ }
+
+ public string Address {
+ get { return address_entry.Text; }
+ }
+
+ public int Port {
+ get { return port_entry.ValueAsInt; }
+ }
+ }
+}
diff --git a/src/Extensions/Banshee.Daap/Makefile.am b/src/Extensions/Banshee.Daap/Makefile.am
index d9884ca..4cb2e73 100644
--- a/src/Extensions/Banshee.Daap/Makefile.am
+++ b/src/Extensions/Banshee.Daap/Makefile.am
@@ -9,9 +9,11 @@ SOURCES = \
Banshee.Daap/DaapLoginDialog.cs \
Banshee.Daap/DaapPlaylistSource.cs \
Banshee.Daap/DaapProxyWebServer.cs \
+ Banshee.Daap/DaapResolverJob.cs \
Banshee.Daap/DaapService.cs \
Banshee.Daap/DaapSource.cs \
Banshee.Daap/DaapTrackInfo.cs \
+ Banshee.Daap/OpenRemoteServer.cs \
Daap/AuthenticationException.cs \
Daap/BrokenMD5.cs \
Daap/Client.cs \
@@ -31,7 +33,8 @@ SOURCES = \
RESOURCES = \
Banshee.Daap.addin.xml \
- Daap/content-codes
+ Daap/content-codes \
+ Resources/GlobalUI.xml
if DAAP_ENABLED
include $(top_srcdir)/build/build.mk
diff --git a/src/Extensions/Banshee.Daap/Resources/GlobalUI.xml b/src/Extensions/Banshee.Daap/Resources/GlobalUI.xml
new file mode 100644
index 0000000..08fdc78
--- /dev/null
+++ b/src/Extensions/Banshee.Daap/Resources/GlobalUI.xml
@@ -0,0 +1,9 @@
+<ui>
+ <menubar name="MainMenu" action="MainMenuAction">
+ <menu name="MediaMenu" action="MediaMenuAction">
+ <placeholder name="BelowOpenLocation">
+ <menuitem name="AddRemoteDaapServer" action="AddRemoteDaapServerAction" />
+ </placeholder>
+ </menu>
+ </menubar>
+</ui>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]