f-spot r3914 - trunk/extensions/ChangePhotoPath



Author: sdelcroix
Date: Wed May 14 11:56:39 2008
New Revision: 3914
URL: http://svn.gnome.org/viewvc/f-spot?rev=3914&view=rev

Log:
adding bengt's ChangePhotoPath extension

Added:
   trunk/extensions/ChangePhotoPath/
   trunk/extensions/ChangePhotoPath/ChangeLog
   trunk/extensions/ChangePhotoPath/ChangePhotoPath.addin.xml
   trunk/extensions/ChangePhotoPath/ChangePhotoPath.glade   (contents, props changed)
   trunk/extensions/ChangePhotoPath/ChangePhotoPathController.cs
   trunk/extensions/ChangePhotoPath/ChangePhotoPathGui.cs
   trunk/extensions/ChangePhotoPath/IChangePhotoPathGui.cs
   trunk/extensions/ChangePhotoPath/Makefile   (contents, props changed)

Added: trunk/extensions/ChangePhotoPath/ChangePhotoPath.addin.xml
==============================================================================
--- (empty file)
+++ trunk/extensions/ChangePhotoPath/ChangePhotoPath.addin.xml	Wed May 14 11:56:39 2008
@@ -0,0 +1,15 @@
+<Addin namespace="FSpot" 
+        id="ChangePath"
+        version="0.4.3.0"
+        name="ChangePath"
+        description="UNSTABLE - Please ensure you have a backup of your photos.db before you test this extension. This extension will allow you to change the base path to the your photos. It is very handy if you move your photos from ~/Photos to /OurPhotos for instance. Just ensure you let SqLite continue to process the changes for up to a few hours after f-spot reports finished. It will only change the path to photos which are located under the Photo directory."
+        author="Bengt Thuree"
+        url="http://f-spot.org/Extensions";
+        category="Tools">
+	<Dependencies>
+		<Addin id="Core" version="0.4.3.0"/>
+	</Dependencies>
+	<Extension path = "/FSpot/Menus/Tools">
+		<Command id="FileList" _label = "Change path to photos" command_type = "ChangePhotoPath.Dump" />
+	</Extension>
+</Addin>

Added: trunk/extensions/ChangePhotoPath/ChangePhotoPath.glade
==============================================================================
--- (empty file)
+++ trunk/extensions/ChangePhotoPath/ChangePhotoPath.glade	Wed May 14 11:56:39 2008
@@ -0,0 +1,170 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
+<!--*- mode: xml -*-->
+<glade-interface>
+  <widget class="GtkDialog" id="ChangePhotoPath">
+    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+    <property name="border_width">5</property>
+    <property name="title" translatable="yes">Change Photos directory</property>
+    <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
+    <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
+    <property name="has_separator">False</property>
+    <child internal-child="vbox">
+      <widget class="GtkVBox" id="dialog-vbox2">
+        <property name="visible">True</property>
+        <property name="spacing">2</property>
+        <child>
+          <widget class="GtkFrame" id="frame1">
+            <property name="visible">True</property>
+            <property name="label_xalign">0</property>
+            <property name="shadow_type">GTK_SHADOW_NONE</property>
+            <child>
+              <widget class="GtkEventBox" id="eventbox1">
+                <property name="visible">True</property>
+                <child>
+                  <widget class="GtkAlignment" id="alignment1">
+                    <property name="visible">True</property>
+                    <property name="left_padding">12</property>
+                    <child>
+                      <widget class="GtkTable" id="table1">
+                        <property name="visible">True</property>
+                        <property name="n_rows">2</property>
+                        <property name="n_columns">2</property>
+                        <child>
+                          <widget class="GtkEntry" id="old_common_uri">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                          </widget>
+                          <packing>
+                            <property name="left_attach">1</property>
+                            <property name="right_attach">2</property>
+                            <property name="y_options"></property>
+                            <property name="x_padding">5</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <widget class="GtkLabel" id="new_common_uri">
+                            <property name="visible">True</property>
+                            <property name="xalign">0</property>
+                          </widget>
+                          <packing>
+                            <property name="left_attach">1</property>
+                            <property name="right_attach">2</property>
+                            <property name="top_attach">1</property>
+                            <property name="bottom_attach">2</property>
+                            <property name="x_padding">5</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <widget class="GtkLabel" id="label2">
+                            <property name="visible">True</property>
+                            <property name="xalign">0.10000000149011612</property>
+                            <property name="label" translatable="yes">Old base path (URI) was</property>
+                          </widget>
+                        </child>
+                        <child>
+                          <widget class="GtkLabel" id="label3">
+                            <property name="visible">True</property>
+                            <property name="xalign">0.10000000149011612</property>
+                            <property name="label" translatable="yes">Change base path (URI) to</property>
+                          </widget>
+                          <packing>
+                            <property name="top_attach">1</property>
+                            <property name="bottom_attach">2</property>
+                          </packing>
+                        </child>
+                      </widget>
+                    </child>
+                  </widget>
+                </child>
+              </widget>
+            </child>
+            <child>
+              <widget class="GtkLabel" id="label1">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">&lt;b&gt;Specify the toplevel Photos directories&lt;/b&gt;</property>
+                <property name="use_markup">True</property>
+              </widget>
+              <packing>
+                <property name="type">label_item</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+        <child internal-child="action_area">
+          <widget class="GtkHButtonBox" id="dialog-action_area2">
+            <property name="visible">True</property>
+            <property name="layout_style">GTK_BUTTONBOX_END</property>
+            <child>
+              <widget class="GtkButton" id="cancel">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="label">gtk-cancel</property>
+                <property name="use_stock">True</property>
+                <property name="response_id">-6</property>
+              </widget>
+            </child>
+            <child>
+              <widget class="GtkButton" id="Apply">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="response_id">-5</property>
+                <child>
+                  <widget class="GtkAlignment" id="alignment2">
+                    <property name="visible">True</property>
+                    <property name="xscale">0</property>
+                    <property name="yscale">0</property>
+                    <child>
+                      <widget class="GtkHBox" id="hbox1">
+                        <property name="visible">True</property>
+                        <property name="spacing">2</property>
+                        <child>
+                          <widget class="GtkImage" id="image1">
+                            <property name="visible">True</property>
+                            <property name="stock">gtk-ok</property>
+                          </widget>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <widget class="GtkLabel" id="label4">
+                            <property name="visible">True</property>
+                            <property name="label">_Apply changes</property>
+                            <property name="use_underline">True</property>
+                          </widget>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                      </widget>
+                    </child>
+                  </widget>
+                </child>
+              </widget>
+              <packing>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+            <property name="pack_type">GTK_PACK_END</property>
+          </packing>
+        </child>
+      </widget>
+    </child>
+  </widget>
+</glade-interface>

Added: trunk/extensions/ChangePhotoPath/ChangePhotoPathController.cs
==============================================================================
--- (empty file)
+++ trunk/extensions/ChangePhotoPath/ChangePhotoPathController.cs	Wed May 14 11:56:39 2008
@@ -0,0 +1,307 @@
+//
+// ChangePhotoPath.IChangePhotoPathController.cs: The logic to change the photo path in photos.db
+//
+// Author:
+//   Bengt Thuree (bengt thuree com)
+//
+// Copyright (C) 2007
+// 
+
+
+using FSpot;
+using FSpot.Query;
+using System;
+using System.IO;
+using System.Collections;
+using System.Collections.Specialized;
+
+/*
+	Need to
+		1) Find old base path, assuming starting /YYYY/MM/DD so look for /YY (/19 or /20)
+		2) Confirm old base path and display new base path
+		3) For each Photo, check each version, and change every instance of old base path to new path
+
+Consider!!!
+photo_store.Commit(photo) is using db.ExecuteNonQuery, which is not waiting for the command to finish. On my test set of 20.000 photos,
+it took SQLite another 1 hour or so to commit all rows after this extension had finished its execution.
+
+Consider 2!!!
+A bit of mixture between URI and path. Old and New base path are in String path. Rest in URI.
+
+*/
+
+namespace ChangePhotoPath
+{
+
+	public enum ProcessResult {
+		Ok, Cancelled, Error, SamePath, NoPhotosFound, Processing
+	}
+
+	public class ChangePathController
+	{		
+		PhotoStore photo_store = FSpot.Core.Database.Photos;	
+		ArrayList photo_id_array, version_id_array;
+		StringCollection old_path_array, new_path_array;
+		int total_photos;
+		string orig_base_path;
+
+		private const string BASE2000 = "/20";
+		private const string BASE1900 = "/19";
+		private const string BASE1800 = "/18";
+	
+		private IChangePhotoPathGui gui_controller;
+		
+
+		private bool user_cancelled;
+		public bool UserCancelled {
+		  get {return user_cancelled;}
+		  set {user_cancelled = value;}
+		}
+		
+		public ChangePathController (IChangePhotoPathGui gui)
+		{
+			gui_controller = gui;	
+			total_photos = photo_store.TotalPhotos;
+			orig_base_path = EnsureEndsWithOneDirectorySeparator (FindOrigBasePath());			// NOT URI
+			string new_base_path = EnsureEndsWithOneDirectorySeparator (FSpot.Global.PhotoDirectory);	// NOT URI
+			gui_controller.DisplayDefaultPaths (orig_base_path, new_base_path);
+			user_cancelled = false;
+		}
+
+		private string EnsureEndsWithOneDirectorySeparator (string tmp_str)
+		{
+			if ( (tmp_str == null) || (tmp_str.Length == 0) )
+				return String.Format ("{0}", Path.DirectorySeparatorChar);
+			while (tmp_str.EndsWith(String.Format ("{0}", Path.DirectorySeparatorChar)))
+				tmp_str = tmp_str.Remove (tmp_str.Length-1, 1);
+			return String.Format ("{0}{1}", tmp_str, Path.DirectorySeparatorChar);
+		}
+
+
+		// Should always return TRUE, since path always ends with "/"
+		public bool CanWeRun ()
+		{
+			return (orig_base_path != null);
+		}
+
+		private string IsThisPhotoOnOrigBasePath (string check_this_path)
+		{
+			int i;
+			i = check_this_path.IndexOf(BASE2000);
+			if (i > 0) 
+				return (check_this_path.Substring(0, i));
+			i = check_this_path.IndexOf(BASE1900);			
+			if (i > 0) 
+				return (check_this_path.Substring(0, i));
+			i = check_this_path.IndexOf(BASE1800);			
+			if (i > 0) 
+				return (check_this_path.Substring(0, i));
+			return null;
+		}
+
+		private string FindOrigBasePath()
+		{
+			string res_path = null;
+			
+			foreach ( IBrowsableItem photo in photo_store.Query ( "SELECT * FROM photos " ) ) {
+				string tmp_path = (photo as Photo).DefaultVersionUri.AbsolutePath;
+				res_path = IsThisPhotoOnOrigBasePath (tmp_path);
+				if (res_path != null)
+					break;			
+			}
+			return res_path;
+		}
+		
+		private void InitializeArrays()
+		{
+			photo_id_array = new ArrayList();
+			version_id_array = new ArrayList();
+			old_path_array = new StringCollection();
+			new_path_array = new StringCollection();
+		}
+
+		private void AddVersionToArrays ( uint photo_id, uint version_id, string old_path, string new_path)
+		{
+			photo_id_array.Add (photo_id);
+			version_id_array.Add (version_id);
+			old_path_array.Add (old_path);
+			new_path_array.Add (new_path);
+		}
+
+		private string CreateNewPath (string old_base, string new_base, PhotoVersion version)
+		{
+			return string.Format ("{0}{1}", new_base, version.Uri.AbsolutePath.Substring(old_base.Length));
+		}
+
+		private bool ChangeThisVersionUri (PhotoVersion version, string old_base, string new_base)
+		{
+			// Change to path from URI, since easier to compare with old_base which is not in URI format.
+			string tmp_path = System.IO.Path.GetDirectoryName (version.Uri.AbsolutePath);
+			return ( tmp_path.StartsWith (old_base) );
+		}
+
+		private void SearchVersionUriToChange (Photo photo, string old_base, string new_base)
+		{
+				foreach (uint version_id in photo.VersionIds) {
+
+					PhotoVersion version = photo.GetVersion (version_id) as PhotoVersion;
+					if ( ChangeThisVersionUri (version, old_base, new_base) ) 
+						AddVersionToArrays (	photo.Id, 
+									version_id, 
+									version.Uri.AbsolutePath, 
+									CreateNewPath (old_base, new_base, version));
+//					else
+//						System.Console.WriteLine ("L : {0}", version.Uri.AbsolutePath);
+				}
+		}
+		
+		public bool SearchUrisToChange (string old_base, string new_base)
+		{
+			int count = 0;
+
+			foreach ( IBrowsableItem ibrows in photo_store.Query ( "SELECT * FROM photos " ) ) {
+				count++;
+				if (gui_controller.UpdateProgressBar ("Scanning through database", "Checking photo", total_photos))
+				    return false;
+				SearchVersionUriToChange ((ibrows as Photo), old_base, new_base);
+			}
+			return true;
+		}
+
+		public bool StillOnSamePhotoId (int old_index, int current_index, ArrayList array)
+		{
+			try {
+				return (array[old_index] == array[current_index]);
+			} catch {
+				return true; // return true if out of index.
+			}
+		}
+	
+		public void UpdateThisUri (int index, string path, ref Photo photo)
+		{
+			if (photo == null)
+				photo = photo_store.Get ( (uint) photo_id_array[index]) as Photo;
+			PhotoVersion version = photo.GetVersion ( (uint) version_id_array[index]) as PhotoVersion;
+			version.Uri = new System.Uri ( path );
+		}
+
+/// FIXME Refactor, try to use one common method....
+		public void RevertAllUris (int last_index)
+		{
+			gui_controller.remove_progress_dialog();
+			Photo photo = null;
+			for (int k = last_index; k >= 0; k--) {
+				if (gui_controller.UpdateProgressBar ("Reverting changes to database", "Reverting photo", last_index)) 
+					{} // do nothing, ignore trying to abort the revert...
+				if ( (photo != null) && !StillOnSamePhotoId (k+1, k, photo_id_array) ) {
+					photo_store.Commit (photo);
+					photo = null;
+				}
+
+				UpdateThisUri (k, old_path_array[k], ref photo);
+				System.Console.WriteLine ("R : {0} - {1}", k, old_path_array[k]);
+			}
+			if (photo != null)
+				photo_store.Commit (photo);
+			System.Console.WriteLine ("Changing path failed due to above error. Have reverted any modification that took place.");
+		}
+
+		public ProcessResult ChangeAllUris ( ref int  last_index)
+		{
+			gui_controller.remove_progress_dialog();		
+			Photo photo = null;
+			last_index = 0;
+			try {
+				photo = null;
+				for (last_index = 0; last_index < photo_id_array.Count; last_index++) {
+
+					if (gui_controller.UpdateProgressBar ("Changing photos base path", "Changing photo", photo_id_array.Count)) {
+						Console.WriteLine("User aborted the change of paths...");
+						return ProcessResult.Cancelled;
+					}
+
+					if ( (photo != null) && !StillOnSamePhotoId (last_index-1, last_index, photo_id_array) ) {
+						photo_store.Commit (photo);
+						photo = null;
+					}
+
+					UpdateThisUri (last_index, new_path_array[last_index], ref photo);
+					System.Console.WriteLine ("U : {0} - {1}", last_index, new_path_array[last_index]);
+
+					// DEBUG ONLY
+					// Cause an TEST exception on 6'th URI to be changed.
+					// float apa = last_index / (last_index-6);
+				}
+				if (photo != null)
+					photo_store.Commit (photo);
+			} catch (Exception e) {
+				Console.WriteLine(e);
+				return ProcessResult.Error;
+			}
+			return ProcessResult.Ok;
+		}
+
+
+		public ProcessResult ProcessArrays()
+		{
+			int last_index = 0;
+			ProcessResult tmp_res;
+			tmp_res = ChangeAllUris(ref last_index);
+			if (!(tmp_res == ProcessResult.Ok))
+				RevertAllUris(last_index);
+			return tmp_res;
+		}
+
+/*
+		public void CheckIfUpdated (int test_index, StringCollection path_array)
+		{
+			Photo photo = photo_store.Get ( (uint) photo_id_array[test_index]) as Photo;
+			PhotoVersion version = photo.GetVersion ( (uint) version_id_array[test_index]) as PhotoVersion;
+			if (version.Uri.AbsolutePath.ToString() == path_array[ test_index ])
+				System.Console.WriteLine ("Test URI ({0}) matches --- Should be finished", test_index);
+			else
+				System.Console.WriteLine ("Test URI ({0}) DO NOT match --- Should NOT BE finished", test_index);
+		}
+*/
+
+/*
+Check paths are different
+If (Scan all photos) // user might cancel
+	If (Check there are photos on old path)
+		ChangePathsOnPhotos
+*/		
+
+		public bool NewOldPathSame (ref string newpath, ref string oldpath)
+		{
+			string p1 = EnsureEndsWithOneDirectorySeparator(newpath);
+			string p2 = EnsureEndsWithOneDirectorySeparator(oldpath);
+			return (p1 == p2);
+		}
+
+		public ProcessResult ChangePathOnPhotos (string old_base, string new_base)
+		{
+			ProcessResult tmp_res = ProcessResult.Processing;
+			InitializeArrays();
+			
+			if (NewOldPathSame (ref new_base, ref old_base))
+				tmp_res = ProcessResult.SamePath;
+
+			if ( (tmp_res == ProcessResult.Processing) && (!SearchUrisToChange (old_base, new_base)) )
+				tmp_res = ProcessResult.Cancelled;
+
+			if ( (tmp_res == ProcessResult.Processing) && (photo_id_array.Count == 0) )
+				tmp_res = ProcessResult.NoPhotosFound;
+
+			if (tmp_res == ProcessResult.Processing)
+				tmp_res = ProcessArrays();
+
+//			if (res)
+//				CheckIfUpdated (photo_id_array.Count-1, new_path_array);
+//			else
+//				CheckIfUpdated (0, old_path_array);
+
+			return tmp_res;
+		}
+	}
+}
+

Added: trunk/extensions/ChangePhotoPath/ChangePhotoPathGui.cs
==============================================================================
--- (empty file)
+++ trunk/extensions/ChangePhotoPath/ChangePhotoPathGui.cs	Wed May 14 11:56:39 2008
@@ -0,0 +1,204 @@
+//
+// ChangePhotoPath.IChangePhotoPathGui.cs: The Gui to change the photo path in photos.db
+//
+// Author:
+//   Bengt Thuree (bengt thuree com)
+//
+// Copyright (C) 2007
+// 
+
+using FSpot.Extensions;
+using FSpot.UI.Dialog;
+using System;
+//using Gnome.Vfs;
+using Gtk;
+
+namespace ChangePhotoPath
+{
+
+	public class Dump : Gtk.Dialog, ICommand, IChangePhotoPathGui
+	{
+		private string dialog_name = "ChangePhotoPath";
+		private Glade.XML xml;
+		private Gtk.Dialog dialog;
+		private ChangePathController contr;
+
+		private ProgressDialog progress_dialog;
+		private int progress_dialog_total = 0;
+		
+		[Glade.Widget] Gtk.Entry old_common_uri;
+		[Glade.Widget] Gtk.Label new_common_uri;
+//		[Glade.Widget] Gtk.ProgressBar progress_bar;
+
+		private bool LaunchController()
+		{		
+			try {
+				contr = new ChangePathController ( this );
+			} catch (Exception e) {
+				Console.WriteLine(e);
+				return false;
+			}
+			return true;	
+		}
+
+		public void create_progress_dialog(string txt, int total)
+		{
+			progress_dialog = new ProgressDialog (txt,
+							      ProgressDialog.CancelButtonType.Stop,
+							      total, 
+							      dialog);
+		}
+		
+		
+		public void LaunchDialog()
+		{
+			CreateDialog();
+			Dialog.Modal = false;
+			Dialog.TransientFor = null;
+			if (LaunchController() && contr.CanWeRun())
+			{	
+				DisplayDoNotStopFSpotMsg();
+				Dialog.ShowAll();
+				Dialog.Response += HandleResponse;
+			} else {
+				DisplayOrigBasePathNotFoundMsg();
+				Dialog.Destroy();
+			}
+		}
+
+		private void CreateDialog()
+		{
+			xml = new Glade.XML (null, "ChangePhotoPath.glade", dialog_name, "f-spot");
+			xml.Autoconnect (this);
+		}
+
+		private Gtk.Dialog Dialog {
+			get {
+				if (dialog == null)
+					dialog = (Gtk.Dialog) xml.GetWidget (dialog_name);
+				return dialog;
+			}
+		}
+
+		private void DisplayMsg(Gtk.MessageType MessageType, string msg)
+		{
+
+			HigMessageDialog.RunHigMessageDialog (	null,  
+								Gtk.DialogFlags.Modal | Gtk.DialogFlags.DestroyWithParent,
+								MessageType, 
+								Gtk.ButtonsType.Ok,
+								msg, 
+								null);
+		}
+
+		private void DisplayDoNotStopFSpotMsg()
+		{
+			DisplayMsg (Gtk.MessageType.Info, "It will take a long time for SqLite to update the database if you have many photos." +
+							  "\nWe recommend you to let F-Spot be running during the night to ensure everything is written to disk."+
+							  "\nChanging path on 23000 photos took 2 hours until sqlite had updated all photos in the database.");
+		}
+		
+		private void DisplayOrigBasePathNotFoundMsg()
+		{
+			DisplayMsg (Gtk.MessageType.Error, "Could not find an old base path. /YYYY/MM/DD need to start with /20, /19 or /18.");
+		}
+		
+		private void DisplayCancelledMsg()
+		{
+			DisplayMsg (Gtk.MessageType.Warning, "Operation aborted. Database has not been modified.");
+		}
+		
+		private void DisplaySamePathMsg()
+		{
+			DisplayMsg (Gtk.MessageType.Warning, "New and Old base path are the same.");
+		}
+		
+		private void DisplayNoPhotosFoundMsg()
+		{
+			DisplayMsg (Gtk.MessageType.Warning, "Did not find any photos with the old base path.");
+		}
+
+		private void DisplayExecutionOkMsg()
+		{
+			DisplayMsg (Gtk.MessageType.Info, "Completed successfully. Please ensure you wait 1-2 hour before you exit f-spot. This to ensure the database cache is written to disk.");
+		}
+
+		private void DisplayExecutionNotOkMsg()
+		{
+			DisplayMsg (Gtk.MessageType.Error, "An error occured. Reverted all changes to the database.");
+		}
+
+
+		private void HandleResponse (object sender, Gtk.ResponseArgs args)
+		{
+			bool destroy_dialog = false;
+			ChangePhotoPath.ProcessResult tmp_res;
+			if (args.ResponseId == Gtk.ResponseType.Ok) {
+
+				tmp_res = contr.ChangePathOnPhotos (old_common_uri.Text, new_common_uri.Text);
+				switch (tmp_res) {
+				case ProcessResult.Ok 			: 	DisplayExecutionOkMsg(); 
+										destroy_dialog=true; 
+										break;
+				case ProcessResult.Cancelled 		: 	DisplayCancelledMsg(); 
+										break;
+				case ProcessResult.Error 		: 	DisplayExecutionNotOkMsg(); 
+										break;
+				case ProcessResult.SamePath 		: 	DisplaySamePathMsg(); 
+										break;
+				case ProcessResult.NoPhotosFound 	: 	DisplayNoPhotosFoundMsg(); 
+										break;
+				case ProcessResult.Processing 		: 	System.Console.WriteLine ("processing"); 
+										break;
+				}
+			} else
+				destroy_dialog = true;
+
+			remove_progress_dialog();
+			if (destroy_dialog) 
+				Dialog.Destroy();
+				
+			return;
+		}
+
+		public void DisplayDefaultPaths (string oldpath, string newpath)
+		{
+			old_common_uri.Text = oldpath;
+			new_common_uri.Text = newpath;
+		}
+
+		public void remove_progress_dialog ()
+		{
+			if (progress_dialog != null) {
+				progress_dialog.Destroy();
+				progress_dialog = null;
+			}
+		}
+		
+		public void check_if_remove_progress_dialog (int total)
+		{
+			if (total != progress_dialog_total) 
+				remove_progress_dialog();
+		}
+		
+
+		public bool UpdateProgressBar (string hdr_txt, string txt, int total)
+		{
+			if (progress_dialog != null)
+				check_if_remove_progress_dialog(total);
+			if (progress_dialog == null)
+				create_progress_dialog(hdr_txt, total);				
+			progress_dialog_total = total;
+			return progress_dialog.Update (String.Format ("{0} ", txt));
+		}
+
+		public void Run (object sender, EventArgs args)
+		{
+			try {
+				LaunchDialog( );
+			} catch (Exception e) {
+				Console.WriteLine(e);
+			}
+		}
+	}
+}

Added: trunk/extensions/ChangePhotoPath/IChangePhotoPathGui.cs
==============================================================================
--- (empty file)
+++ trunk/extensions/ChangePhotoPath/IChangePhotoPathGui.cs	Wed May 14 11:56:39 2008
@@ -0,0 +1,18 @@
+//
+// ChangePhotoPath.IChangePhotoPathGui.cs: Interfaces to ChangePhotoPathGui
+//
+// Author:
+//   Bengt Thuree (bengt thuree com)
+//
+// Copyright (C) 2007
+// 
+
+namespace ChangePhotoPath
+{
+	public interface IChangePhotoPathGui
+	{
+		void remove_progress_dialog(); 
+		bool UpdateProgressBar (string hdr_txt, string text, int total_photos);
+		void DisplayDefaultPaths (string oldpath, string newpath);
+	}
+}

Added: trunk/extensions/ChangePhotoPath/Makefile
==============================================================================
--- (empty file)
+++ trunk/extensions/ChangePhotoPath/Makefile	Wed May 14 11:56:39 2008
@@ -0,0 +1,34 @@
+ADDIN = ChangePhotoPath
+
+all: $(ADDIN).dll
+
+PACKAGES = \
+	-pkg:glade-sharp-2.0 \
+	-pkg:gtk-sharp-2.0 \
+	-pkg:f-spot
+
+ASSEMBLIES = 
+
+RESOURCES = \
+	-resource:ChangePhotoPath.glade \
+	-resource:ChangePhotoPath.addin.xml
+
+SOURCES = \
+	ChangePhotoPathController.cs \
+	ChangePhotoPathGui.cs \
+	IChangePhotoPathGui.cs
+
+$(ADDIN).dll: $(SOURCES) $(ADDIN).addin.xml $(ADDIN).glade
+	gmcs -target:library -out:$@ $(SOURCES) $(PACKAGES) $(ASSEMBLIES) $(RESOURCES)
+
+install: all
+	cp $(ADDIN).dll ~/.gnome2/f-spot/addins/
+
+mpack: $(ADDIN).dll
+	mautil p $(ADDIN).dll
+
+clean:
+	rm -f *.dll *~ *.bak *.gladep *.mpack
+
+PHONY:
+	install clean all mpack



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