f-spot r4210 - in trunk/dpap-sharp: . DPAPService dpap-client lib



Author: apart
Date: Mon Jul 28 19:51:22 2008
New Revision: 4210
URL: http://svn.gnome.org/viewvc/f-spot?rev=4210&view=rev

Log:
Initial code for the mono addin


Added:
   trunk/dpap-sharp/DPAPService/
   trunk/dpap-sharp/DPAPService/DPAPService.addin.xml
   trunk/dpap-sharp/DPAPService/DPAPService.cs
   trunk/dpap-sharp/DPAPService/DPAPService.mdp
   trunk/dpap-sharp/DPAPService/Makefile.am
Modified:
   trunk/dpap-sharp/ChangeLog
   trunk/dpap-sharp/Makefile.am
   trunk/dpap-sharp/dpap-client/Main.cs
   trunk/dpap-sharp/dpap-client/dpap-client.mdp
   trunk/dpap-sharp/lib/Discovery.cs
   trunk/dpap-sharp/lib/Server.cs

Added: trunk/dpap-sharp/DPAPService/DPAPService.addin.xml
==============================================================================
--- (empty file)
+++ trunk/dpap-sharp/DPAPService/DPAPService.addin.xml	Mon Jul 28 19:51:22 2008
@@ -0,0 +1,17 @@
+<Addin namespace="FSpot"
+	id="DPAPService"
+	version="0.4.4.100"
+	name="DPAP Service"
+	description="Notify Beagle on image changes"
+	author="Stephane Delcroix"
+	url="http://f-spot.org/Extensions";
+	category="Services">
+	<Dependencies>
+		<Addin id="Core" version="0.4.4.100"/>
+	</Dependencies>
+	<Extension path = "/FSpot/Services">
+		<Service class="DPAPService.DPAPService"/>
+	</Extension>
+</Addin>
+
+

Added: trunk/dpap-sharp/DPAPService/DPAPService.cs
==============================================================================
--- (empty file)
+++ trunk/dpap-sharp/DPAPService/DPAPService.cs	Mon Jul 28 19:51:22 2008
@@ -0,0 +1,171 @@
+// DPAPService.cs
+//
+// Author:
+// Andrzej Wytyczak-Partyka <iapart gmail com>
+// Copyright (C) 2008 Andrzej Wytyczak-Partyka
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+//
+
+using System;
+using FSpot;
+using FSpot.Extensions;
+using FSpot.Utils;
+using System.IO;
+using DPAP;
+
+namespace DPAPService {
+	public class DPAPService : IService
+	{
+		static ServiceDiscovery sd;
+		public bool Start ()
+		{
+			Console.WriteLine("Starting DPAP!");
+			uint timer = Log.InformationTimerStart ("Starting DPAP");
+		//	sd = new ServiceDiscovery();
+		//	sd.Found += OnServiceFound;			
+		//	sd.Start();
+			StartServer();
+			
+
+		/*	try {
+				Core.Database.Photos.ItemsChanged += HandleDbItemsChanged;
+			} catch {
+				Log.Warning ("unable to hook the BeagleNotifier. are you running --view mode?");
+			}*/
+		//	Log.DebugTimerPrint (timer, "BeagleService startup took {0}");
+			return true;
+		}
+		private void StartServer ()
+		{
+		Console.WriteLine("Starting DPAP server");
+			DPAP.Database database = new DPAP.Database("DPAP");
+			DPAP.Server server = new Server("f-spot photos");
+			server.Port = 8770;
+			server.AuthenticationMethod = AuthenticationMethod.None;
+			int collision_count = 0;
+			server.Collision += delegate {
+				server.Name = "f-spot photos" + " [" + ++collision_count + "]";
+			};
+            
+			
+			//FSpot.Photo photo = (FSpot.Photo) Core.Database.Photos.Get(1);			
+			
+			
+			Album a = new Album("test album");
+			FSpot.Photo [] photos = Core.Database.Photos.Query ((Tag [])null, null, null, null);
+			int i=0;
+			foreach(FSpot.Photo photo in photos)
+			{
+				string thumbnail_path = ThumbnailGenerator.ThumbnailPath (photo.DefaultVersionUri);				
+				DPAP.Photo p = new DPAP.Photo();				
+				p.FileName = thumbnail_path;				
+				FileInfo f = new FileInfo(p.FileName);
+				
+				if(!f.Exists) 
+					continue;
+				if(++i > 5) break;
+				Console.WriteLine("Found photo " + photo.DefaultVersionUri + ", thumb " + thumbnail_path);
+				p.Title = photo.Name;
+				p.Size = (int)f.Length; 
+				p.Format = "JPEG";
+				database.AddPhoto(p);
+				a.AddPhoto(p);
+			}		
+
+			database.AddAlbum(a);
+			Console.WriteLine("Album count is now " + database.Albums.Count);
+			Console.WriteLine("Photo name is " + database.Photos[0].FileName);
+			server.AddDatabase(database);
+			
+			//server.GetServerInfoNode();			
+			try {
+                server.Start();
+            } catch (System.Net.Sockets.SocketException) {
+				Console.WriteLine("Server socket exception!");
+                server.Port = 0;
+                server.Start();
+            }
+        
+			//DaapPlugin.ServerEnabledSchema.Set(true);
+            
+			//  if(!initial_db_committed) {
+                server.Commit();
+			//      initial_db_committed = true;
+			//  }
+	
+		}
+		public bool Stop ()
+		{
+			uint timer = Log.InformationTimerStart ("Stopping DPAP");
+			if(sd != null) {
+                sd.Stop();
+                sd.Found -= OnServiceFound;
+                //locator.Removed -= OnServiceRemoved;
+                sd = null;
+            }
+			//Log.DebugTimerPrint (timer, "BeagleService shutdown took {0}");	
+			return true;
+		}
+
+private static void OnServiceFound(object o, ServiceArgs args)
+		{
+			Service service = args.Service;
+			Client client;
+//			ThreadAssist.Spawn(delegate {
+        //        try {
+
+			System.Console.WriteLine("Connecting to {0} at {1}:{2}", service.Name, service.Address, service.Port);
+		    client = new Client( service );
+	
+			
+			foreach (Database d in client.Databases){
+
+				Console.WriteLine("Database " + d.Name);
+				
+				foreach (Album alb in d.Albums)
+					Console.WriteLine("\tAlbum: "+alb.Name + ", id=" + alb.getId() + " number of items:" + alb.Photos.Count);
+				Console.WriteLine(d.Photos[0].FileName);
+				foreach (DPAP.Photo ph in d.Photos)
+				{
+					if(ph != null)
+					{
+						Console.WriteLine("\t\tFile: " + ph.Title + " format = " + ph.Format + "size=" + ph.Width +"x" +ph.Height + " ID=" + ph.Id);
+						d.DownloadPhoto(ph,"./"+ph.Title);
+					}
+				}
+				
+			}
+			//client.Logout();
+		//	Console.WriteLine("Press <enter> to exit...");
+		}		
+		
+		/*private void HandleDbItemsChanged (object sender, DbItemEventArgs args)
+		{
+#if ENABLE_BEAGLE
+			Log.Debug ("Notifying beagle");
+			foreach (DbItem item in args.Items) {
+				if (item as Photo != null)
+					try {
+						BeagleNotifier.SendUpdate (item as Photo);
+					} catch (Exception e) {
+						Log.DebugFormat ("BeagleNotifier.SendUpdate failed with {0}", e.Message);
+					}
+			}
+#endif
+		}*/
+	}
+}

Added: trunk/dpap-sharp/DPAPService/DPAPService.mdp
==============================================================================
--- (empty file)
+++ trunk/dpap-sharp/DPAPService/DPAPService.mdp	Mon Jul 28 19:51:22 2008
@@ -0,0 +1,25 @@
+<Project name="DPAPService" fileversion="2.0" language="C#" clr-version="Net_2_0" ctype="DotNetProject">
+  <Configurations active="Debug">
+    <Configuration name="Debug" ctype="DotNetProjectConfiguration">
+      <Output directory="bin/Debug" assembly="DPAPService" />
+      <Build debugmode="True" target="Exe" />
+      <Execution runwithwarnings="True" consolepause="True" runtime="MsNet" clr-version="Net_2_0" />
+      <CodeGeneration compiler="Mcs" warninglevel="4" optimize="True" unsafecodeallowed="False" generateoverflowchecks="True" definesymbols="DEBUG" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
+    </Configuration>
+    <Configuration name="Release" ctype="DotNetProjectConfiguration">
+      <Output directory="bin/Release" assembly="DPAPService" />
+      <Build debugmode="False" target="Exe" />
+      <Execution runwithwarnings="True" consolepause="True" runtime="MsNet" clr-version="Net_2_0" />
+      <CodeGeneration compiler="Mcs" warninglevel="4" optimize="True" unsafecodeallowed="False" generateoverflowchecks="True" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
+    </Configuration>
+  </Configurations>
+  <Contents>
+    <File name="DPAPService.cs" subtype="Code" buildaction="Compile" />
+  </Contents>
+  <References>
+    <ProjectReference type="Project" localcopy="True" refto="dpap-sharp" />
+    <ProjectReference type="Gac" localcopy="True" refto="FSpot.Core, Version=0.0.0.0, Culture=neutral" />
+    <ProjectReference type="Gac" localcopy="True" refto="FSpot.Utils, Version=0.0.0.0, Culture=neutral" />
+    <ProjectReference type="Gac" localcopy="True" refto="f-spot, Version=0.4.3.1, Culture=neutral" />
+  </References>
+</Project>
\ No newline at end of file

Added: trunk/dpap-sharp/DPAPService/Makefile.am
==============================================================================
--- (empty file)
+++ trunk/dpap-sharp/DPAPService/Makefile.am	Mon Jul 28 19:51:22 2008
@@ -0,0 +1,46 @@
+include $(top_srcdir)/Makefile.include
+
+PLUGIN_NAME = DPAPService
+
+PLUGIN_MANIFEST = $(PLUGIN_NAME).addin.xml
+
+PLUGIN_ASSEMBLY = $(PLUGIN_NAME).dll
+
+PLUGIN_SOURCES =			\
+	$(srcdir)/DPAPService.cs	
+#	$(srcdir)/BeagleNotifier.cs
+
+
+REFS =					\
+	-r:../../src/f-spot.exe		\
+	-r:../../src/FSpot.Core.dll	\
+	-r:../../src/FSpot.Utils.dll	\
+	-r:../lib/dpap-sharp.dll	
+#	$(LINK_BEAGLE)
+
+PKGS =
+
+RESOURCES =				\
+	-resource:$(srcdir)/$(PLUGIN_MANIFEST)
+
+all: $(PLUGIN_ASSEMBLY)
+
+mpack: $(PLUGIN_ASSEMBLY)
+	mautil p $(PLUGIN_ASSEMBLY)
+
+$(PLUGIN_ASSEMBLY): $(PLUGIN_SOURCES) $(PLUGIN_MANIFEST)
+	$(CSC_LIB) -out:$@ $(CSC_DEFINES) $(PLUGIN_SOURCES) $(REFS) $(PKGS) $(ASSEMBLIES) $(RESOURCES)
+
+plugindir = $(pkglibdir)/extensions
+
+plugin_DATA =			\
+	$(PLUGIN_ASSEMBLY)
+
+EXTRA_DIST = 			\
+	$(PLUGIN_SOURCES)	\
+	$(PLUGIN_MANIFEST)
+
+CLEANFILES =			\
+	$(PLUGIN_ASSEMBLY)	\
+	$(PLUGIN_ASSEMBLY).mdb	\
+	*.mpack

Modified: trunk/dpap-sharp/Makefile.am
==============================================================================
--- trunk/dpap-sharp/Makefile.am	(original)
+++ trunk/dpap-sharp/Makefile.am	Mon Jul 28 19:51:22 2008
@@ -1,4 +1,5 @@
 SUBDIRS = 			\
 	lib		\
 	dpap-server	\
-	dpap-client
+	dpap-client	\
+	extension

Modified: trunk/dpap-sharp/dpap-client/Main.cs
==============================================================================
--- trunk/dpap-sharp/dpap-client/Main.cs	(original)
+++ trunk/dpap-sharp/dpap-client/Main.cs	Mon Jul 28 19:51:22 2008
@@ -46,6 +46,13 @@
 			
 //			sd.Services[0];
 			Console.ReadLine();
+			if(sd != null) {
+                sd.Stop();
+                sd.Found -= OnServiceFound;
+                //locator.Removed -= OnServiceRemoved;
+                sd = null;
+            }
+			
 		}
 		private static void OnServiceFound(object o, ServiceArgs args)
 		{
@@ -75,32 +82,9 @@
 				}
 				
 			}
-			client.Logout();
-			Console.WriteLine("Press <enter> to exit...");
-			//Console.ReadLine();
-	//		});
-        /*            //client.Updated += OnClientUpdated;
-                    if(client.AuthenticationMethod == AuthenticationMethod.None) {
-                        client.Login();
+			//client.Logout();
+			//Console.WriteLine("Press <enter> to exit...");
 
-			}                        
-			*/
-                    //} else {
-                    //    ThreadAssist.ProxyToMain(PromptLogin);
-                   // }
-        /*        } catch(Exception e) {
-                    ThreadAssist.ProxyToMain(delegate {
-                        DaapErrorView error_view = new DaapErrorView(this, DaapErrorType.BrokenAuthentication);
-                        while(box.Children.Length > 0) {
-                            box.Remove(box.Children[0]);
-                        }
-                        box.PackStart(error_view, true, true, 0);
-                        error_view.Show();
-                    });
-                }*/
-               
-         //       is_activating = false;
-         //   });			
 			
 		}
 	}

Modified: trunk/dpap-sharp/dpap-client/dpap-client.mdp
==============================================================================
--- trunk/dpap-sharp/dpap-client/dpap-client.mdp	(original)
+++ trunk/dpap-sharp/dpap-client/dpap-client.mdp	Mon Jul 28 19:51:22 2008
@@ -18,12 +18,9 @@
     <File name="AssemblyInfo.cs" subtype="Code" buildaction="Compile" />
   </Contents>
   <References>
-    <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
-    <ProjectReference type="Gac" localcopy="True" refto="Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
-    <ProjectReference type="Gac" localcopy="True" refto="Banshee.Base, Version=0.13.2.20643, Culture=neutral" />
     <ProjectReference type="Gac" localcopy="True" refto="Banshee.Core, Version=1.0.0.38867, Culture=neutral" />
     <ProjectReference type="Gac" localcopy="True" refto="Banshee.Services, Version=1.0.0.38868, Culture=neutral" />
-    <ProjectReference type="Project" localcopy="True" refto="dpap-sharp" />
+    <ProjectReference type="Assembly" localcopy="True" refto="../lib/dpap-sharp.dll" />
   </References>
   <MonoDevelop.Autotools.MakefileInfo IntegrationEnabled="True" RelativeMakefileName="Makefile.am" SyncReferences="True" IsAutotoolsProject="True" RelativeConfigureInPath="../..">
     <BuildFilesVar Sync="True" Name="ASSEMBLY_SOURCES" />

Modified: trunk/dpap-sharp/lib/Discovery.cs
==============================================================================
--- trunk/dpap-sharp/lib/Discovery.cs	(original)
+++ trunk/dpap-sharp/lib/Discovery.cs	Mon Jul 28 19:51:22 2008
@@ -105,12 +105,18 @@
 		// becomes available
 		//
 		
-		public void Start(){
+		public void Start () {
 			browser = new ServiceBrowser();
 			browser.ServiceAdded += OnServiceAdded;
 			browser.Browse("_dpap._tcp","local");
 		}
 		
+	    public void Stop () {
+            browser.Dispose ();
+            browser = null;
+            services.Clear ();
+        }
+		
 		private void OnServiceAdded(object o, ServiceBrowseEventArgs args){
 			Console.WriteLine("Found Service: {0}", args.Service.Name);
 			args.Service.Resolved += OnServiceResolved;

Modified: trunk/dpap-sharp/lib/Server.cs
==============================================================================
--- trunk/dpap-sharp/lib/Server.cs	(original)
+++ trunk/dpap-sharp/lib/Server.cs	Mon Jul 28 19:51:22 2008
@@ -545,7 +545,7 @@
                 RegisterService ();
         }
 
-        public void Stop () {
+		public void Stop () {
             running = false;
 
             ws.Stop ();



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