f-spot r3612 - in trunk/src: . Editors Filters Imaging Jobs Query
- From: sdelcroix svn gnome org
- To: svn-commits-list gnome org
- Subject: f-spot r3612 - in trunk/src: . Editors Filters Imaging Jobs Query
- Date: Wed, 30 Jan 2008 11:23:59 +0000 (GMT)
Author: sdelcroix
Date: Wed Jan 30 11:23:58 2008
New Revision: 3612
URL: http://svn.gnome.org/viewvc/f-spot?rev=3612&view=rev
Log:
refactoring, again and again
Modified:
trunk/src/Db.cs
trunk/src/Editors/SoftFocus.cs
trunk/src/FileBrowsableItem.cs
trunk/src/FileImportBackend.cs
trunk/src/Filters/FilterRequest.cs
trunk/src/Filters/UniqueNameFilter.cs
trunk/src/FolderExport.cs
trunk/src/Imaging/ImageFile.cs
trunk/src/ImportBackend.cs
trunk/src/JobStore.cs
trunk/src/Jobs/SyncMetadataJob.cs
trunk/src/Makefile.am
trunk/src/PhotoLoader.cs
trunk/src/PhotoStore.cs
trunk/src/PhotoVersion.cs
trunk/src/PhotoVersionMenu.cs
trunk/src/Query/DateRange.cs
trunk/src/RollStore.cs
trunk/src/SingleView.cs
trunk/src/ThumbnailCommand.cs
trunk/src/ThumbnailGenerator.cs
trunk/src/Util.cs
Modified: trunk/src/Db.cs
==============================================================================
--- trunk/src/Db.cs (original)
+++ trunk/src/Db.cs Wed Jan 30 11:23:58 2008
@@ -321,28 +321,3 @@
}
-public class DbUtils {
-#if USE_CORRECT_FUNCTION
- public static DateTime DateTimeFromUnixTime (long unix_time)
- {
- DateTime date_time = new DateTime (1970, 1, 1);
- return date_time.AddSeconds (unix_time).ToLocalTime ();
- }
-
- public static long UnixTimeFromDateTime (DateTime date_time)
- {
- return (long) (date_time.ToUniversalTime () - new DateTime (1970, 1, 1)).TotalSeconds;
- }
-#else
- public static DateTime DateTimeFromUnixTime (long unix_time)
- {
- DateTime date_time = new DateTime (1970, 1, 1).ToLocalTime ();
- return date_time.AddSeconds (unix_time);
- }
-
- public static long UnixTimeFromDateTime (DateTime date_time)
- {
- return (long) (date_time - new DateTime (1970, 1, 1).ToLocalTime ()).TotalSeconds;
- }
-#endif
-}
Modified: trunk/src/Editors/SoftFocus.cs
==============================================================================
--- trunk/src/Editors/SoftFocus.cs (original)
+++ trunk/src/Editors/SoftFocus.cs Wed Jan 30 11:23:58 2008
@@ -15,7 +15,7 @@
using Mono.Unix;
using FSpot.UI.Dialog;
-
+using FSpot.Utils;
namespace FSpot.Editors {
public class SoftFocus : EffectEditor {
Widgets.SoftFocus soft;
@@ -102,7 +102,7 @@
// goodies we'll need.
//Gnome.Vfs.Result result = Gnome.Vfs.Result.Ok;
//result = Gnome.Vfs.Xfer.XferUri (new Gnome.Vfs.Uri (UriList.PathToFileUri (tmp).ToString ()),
- Gnome.Vfs.Xfer.XferUri (new Gnome.Vfs.Uri (UriList.PathToFileUri (tmp).ToString ()),
+ Gnome.Vfs.Xfer.XferUri (new Gnome.Vfs.Uri (UriUtils.PathToFileUri (tmp).ToString ()),
new Gnome.Vfs.Uri (target.Uri.ToString ()),
Gnome.Vfs.XferOptions.Default,
Gnome.Vfs.XferErrorMode.Abort,
Modified: trunk/src/FileBrowsableItem.cs
==============================================================================
--- trunk/src/FileBrowsableItem.cs (original)
+++ trunk/src/FileBrowsableItem.cs Wed Jan 30 11:23:58 2008
@@ -14,6 +14,7 @@
using System.Collections;
using System.Xml;
+using FSpot.Utils;
namespace FSpot {
public class FileBrowsableItem : IBrowsableItem, IDisposable
{
@@ -28,7 +29,7 @@
public FileBrowsableItem (string path)
{
- this.uri = UriList.PathToFileUri (path);
+ this.uri = UriUtils.PathToFileUri (path);
}
protected ImageFile Image {
Modified: trunk/src/FileImportBackend.cs
==============================================================================
--- trunk/src/FileImportBackend.cs (original)
+++ trunk/src/FileImportBackend.cs Wed Jan 30 11:23:58 2008
@@ -8,6 +8,7 @@
using FSpot.UI.Dialog;
using System.IO;
using Mono.Unix;
+using FSpot;
public class ImportException : System.Exception {
public ImportException (string msg) : base (msg)
Modified: trunk/src/Filters/FilterRequest.cs
==============================================================================
--- trunk/src/Filters/FilterRequest.cs (original)
+++ trunk/src/Filters/FilterRequest.cs Wed Jan 30 11:23:58 2008
@@ -12,6 +12,8 @@
using System;
using System.Collections;
+using FSpot.Utils;
+
namespace FSpot.Filters {
public class FilterRequest : IDisposable
@@ -28,7 +30,7 @@
temp_uris = new ArrayList ();
}
- public FilterRequest (string path) : this (UriList.PathToFileUri (path))
+ public FilterRequest (string path) : this (UriUtils.PathToFileUri (path))
{
}
@@ -83,7 +85,7 @@
} else
imgtemp = System.IO.Path.GetTempFileName ();
- Uri uri = UriList.PathToFileUri (imgtemp);
+ Uri uri = UriUtils.PathToFileUri (imgtemp);
if (!temp_uris.Contains (uri))
temp_uris.Add (uri);
return uri;
Modified: trunk/src/Filters/UniqueNameFilter.cs
==============================================================================
--- trunk/src/Filters/UniqueNameFilter.cs (original)
+++ trunk/src/Filters/UniqueNameFilter.cs Wed Jan 30 11:23:58 2008
@@ -9,13 +9,14 @@
*/
using System;
+using FSpot.Utils;
namespace FSpot.Filters {
public class UniqueNameFilter : IFilter
{
Uri destination;
- public UniqueNameFilter (string destination) : this (UriList.PathToFileUri (destination))
+ public UniqueNameFilter (string destination) : this (UriUtils.PathToFileUri (destination))
{}
public UniqueNameFilter (Uri destination)
@@ -39,7 +40,7 @@
}
System.IO.File.Copy (request.Current.LocalPath, dest);
- request.Current = UriList.PathToFileUri (dest);
+ request.Current = UriUtils.PathToFileUri (dest);
return true;
}
}
Modified: trunk/src/FolderExport.cs
==============================================================================
--- trunk/src/FolderExport.cs (original)
+++ trunk/src/FolderExport.cs Wed Jan 30 11:23:58 2008
@@ -464,7 +464,7 @@
ExportStore.FolderExportType,
// FIXME this is wrong, the final path is the one
// after the Xfer.
- UriList.PathToFileUriEscaped (path).ToString ());
+ UriUtils.PathToFileUriEscaped (path).ToString ());
}
using (Exif.ExifData data = new Exif.ExifData (photo_path)) {
Modified: trunk/src/Imaging/ImageFile.cs
==============================================================================
--- trunk/src/Imaging/ImageFile.cs (original)
+++ trunk/src/Imaging/ImageFile.cs Wed Jan 30 11:23:58 2008
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using FSpot.Utils;
namespace FSpot {
public class ImageFormatException : ApplicationException {
@@ -15,7 +16,7 @@
public ImageFile (string path)
{
- this.uri = UriList.PathToFileUri (path);
+ this.uri = UriUtils.PathToFileUri (path);
}
public ImageFile (Uri uri)
@@ -152,7 +153,7 @@
public static bool HasLoader (string path)
{
- return HasLoader (UriList.PathToFileUri (path));
+ return HasLoader (UriUtils.PathToFileUri (path));
}
public static bool HasLoader (Uri uri)
@@ -166,7 +167,7 @@
public static ImageFile Create (string path)
{
- return Create (UriList.PathToFileUri (path));
+ return Create (UriUtils.PathToFileUri (path));
}
public static ImageFile Create (Uri uri)
Modified: trunk/src/ImportBackend.cs
==============================================================================
--- trunk/src/ImportBackend.cs (original)
+++ trunk/src/ImportBackend.cs Wed Jan 30 11:23:58 2008
@@ -1,3 +1,4 @@
+using FSpot;
using Gdk;
public abstract class ImportBackend {
Modified: trunk/src/JobStore.cs
==============================================================================
--- trunk/src/JobStore.cs (original)
+++ trunk/src/JobStore.cs Wed Jan 30 11:23:58 2008
@@ -15,6 +15,7 @@
using Banshee.Database;
using Banshee.Kernel;
using FSpot.Jobs;
+using FSpot.Utils;
public abstract class Job : DbItem, IJob
{
Modified: trunk/src/Jobs/SyncMetadataJob.cs
==============================================================================
--- trunk/src/Jobs/SyncMetadataJob.cs (original)
+++ trunk/src/Jobs/SyncMetadataJob.cs Wed Jan 30 11:23:58 2008
@@ -9,6 +9,7 @@
using System;
using Banshee.Kernel;
+using FSpot.Utils;
namespace FSpot.Jobs {
public class SyncMetadataJob : Job
@@ -34,12 +35,64 @@
Console.WriteLine ("Syncing metadata to file...");
try {
Photo photo = FSpot.Core.Database.Photos.Get (Convert.ToUInt32 (JobOptions)) as Photo;
- photo.WriteMetadataToImage ();
+ WriteMetadataToImage (photo);
return true;
} catch (System.Exception e) {
Console.WriteLine ("Error syncing metadata to file\n{0}", e);
}
return false;
}
+
+ //FIXME: Won't work on non-file uris
+ void WriteMetadataToImage (Photo photo)
+ {
+ string path = photo.DefaultVersionUri.LocalPath;
+
+ using (FSpot.ImageFile img = FSpot.ImageFile.Create (photo.DefaultVersionUri)) {
+ if (img is FSpot.JpegFile) {
+ FSpot.JpegFile jimg = img as FSpot.JpegFile;
+
+ jimg.SetDescription (photo.Description);
+ jimg.SetDateTimeOriginal (photo.Time.ToLocalTime ());
+ jimg.SetXmp (UpdateXmp (photo, jimg.Header.GetXmp ()));
+
+ jimg.SaveMetaData (path);
+ } else if (img is FSpot.Png.PngFile) {
+ FSpot.Png.PngFile png = img as FSpot.Png.PngFile;
+
+ if (img.Description != photo.Description)
+ png.SetDescription (photo.Description);
+
+ png.SetXmp (UpdateXmp (photo, png.GetXmp ()));
+
+ png.Save (path);
+ }
+ }
+ }
+
+ private static FSpot.Xmp.XmpFile UpdateXmp (FSpot.IBrowsableItem item, FSpot.Xmp.XmpFile xmp)
+ {
+ if (xmp == null)
+ xmp = new FSpot.Xmp.XmpFile ();
+
+ Tag [] tags = item.Tags;
+ string [] names = new string [tags.Length];
+
+ for (int i = 0; i < tags.Length; i++)
+ names [i] = tags [i].Name;
+
+ xmp.Store.Update ("dc:subject", "rdf:Bag", names);
+ try {
+ xmp.Store.Update ("xmp:Rating", (item as Photo).Rating.ToString());
+ // FIXME - Should we also store/overwrite the Urgency field?
+ // uint urgency_value = (item as Photo).Rating + 1; // Urgency valid values 1 - 8
+ // xmp.Store.Update ("photoshop:Urgency", urgency_value.ToString());
+ } catch (NotRatedException) {
+ xmp.Store.Delete ("xmp:Rating");
+ }
+ xmp.Dump ();
+
+ return xmp;
+ }
}
}
Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Wed Jan 30 11:23:58 2008
@@ -2,8 +2,10 @@
EXTRAFLAGS = -unsafe -nowarn:0169 -nowarn:0612 -nowarn:0414 -d:TEST_METADATA -d:BROKEN_RSVG $(NUNIT_DEFINES) $(BEAGLE_DEFINES) $(CSC_DEFINES)
UTILS_CSDISTFILES = \
+ $(srcdir)/Utils/DbUtils.cs \
$(srcdir)/Utils/GnomeUtil.cs \
$(srcdir)/Utils/GtkUtil.cs \
+ $(srcdir)/Utils/UriUtils.cs \
$(srcdir)/Utils/ScreenSaver.cs
CMS_CSDISTFILES = \
@@ -76,6 +78,8 @@
$(srcdir)/CompatFileChooser.cs \
$(srcdir)/ControlOverlay.cs \
$(srcdir)/Core.cs \
+ $(srcdir)/Core/Photo.cs \
+ $(srcdir)/Core/PhotoVersion.cs \
$(srcdir)/DateCommands.cs \
$(srcdir)/Db.cs \
$(srcdir)/DBusProxy.cs \
@@ -176,7 +180,6 @@
$(srcdir)/PhotoQuery.cs \
$(srcdir)/PhotoStore.cs \
$(srcdir)/PhotoTagMenu.cs \
- $(srcdir)/PhotoVersion.cs \
$(srcdir)/PhotoVersionCommands.cs \
$(srcdir)/PhotoVersionMenu.cs \
$(srcdir)/PhotoView.cs \
@@ -282,7 +285,9 @@
CORE_ASSEMBLIES = \
-pkg:gtk-sharp-2.0 \
+ -pkg:gnome-vfs-sharp-2.0 \
-r:Cms.dll \
+ -r:Mono.Posix \
-r:FSpot.Utils.dll
F_SPOT_ASSEMBLIES = \
Modified: trunk/src/PhotoLoader.cs
==============================================================================
--- trunk/src/PhotoLoader.cs (original)
+++ trunk/src/PhotoLoader.cs Wed Jan 30 11:23:58 2008
@@ -1,3 +1,5 @@
+using FSpot.Utils;
+
namespace FSpot {
public class PhotoLoader {
public PhotoQuery query;
@@ -42,7 +44,7 @@
static public Gdk.Pixbuf ValidateThumbnail (string photo_path, Gdk.Pixbuf pixbuf)
{
- System.Uri uri = UriList.PathToFileUri (photo_path);
+ System.Uri uri = UriUtils.PathToFileUri (photo_path);
return ValidateThumbnail (uri, pixbuf);
}
Modified: trunk/src/PhotoStore.cs
==============================================================================
--- trunk/src/PhotoStore.cs (original)
+++ trunk/src/PhotoStore.cs Wed Jan 30 11:23:58 2008
@@ -22,650 +22,13 @@
using System.IO;
using System.Text;
using System;
+
using FSpot;
using FSpot.Query;
+using FSpot.Utils;
using Banshee.Database;
-namespace FSpot{
- public class NotRatedException : System.ApplicationException
- {
- public NotRatedException (string message) : base (message)
- {}
- }
-}
-
-public class Photo : DbItem, IComparable, FSpot.IBrowsableItem {
- // IComparable
- public int CompareTo (object obj) {
- if (this.GetType () == obj.GetType ()) {
- // FIXME this is way under powered for a real compare in the
- // equal case but for now it should do.
-
- return Compare (this, (Photo)obj);
- } else if (obj is DateTime) {
- return this.time.CompareTo ((DateTime)obj);
- } else {
- throw new Exception ("Object must be of type Photo");
- }
- }
-
- public int CompareTo (Photo photo)
- {
- return Compare (this, photo);
- }
-
- public static int Compare (Photo photo1, Photo photo2)
- {
- int result = photo1.Id.CompareTo (photo2.Id);
-
- if (result == 0)
- return 0;
- else
- result = CompareDate (photo1, photo2);
-
- if (result == 0)
- result = CompareCurrentDir (photo1, photo2);
-
- if (result == 0)
- result = CompareName (photo1, photo2);
-
- if (result == 0)
- result = photo1.Id.CompareTo (photo2.Id);
-
- return result;
- }
-
- private static int CompareDate (Photo photo1, Photo photo2)
- {
- return DateTime.Compare (photo1.time, photo2.time);
- }
-
- private static int CompareCurrentDir (Photo photo1, Photo photo2)
- {
- return string.Compare (photo1.DirectoryPath, photo2.DirectoryPath);
- }
-
- private static int CompareName (Photo photo1, Photo photo2)
- {
- return string.Compare (photo1.Name, photo2.Name);
- }
-
- public class CompareDateName : IComparer
- {
- public int Compare (object obj1, object obj2)
- {
- Photo p1 = (Photo)obj1;
- Photo p2 = (Photo)obj2;
-
- int result = Photo.CompareDate (p1, p2);
-
- if (result == 0)
- result = CompareName (p1, p2);
-
- return result;
- }
- }
-
- public class CompareDirectory : IComparer
- {
- public int Compare (object obj1, object obj2)
- {
- Photo p1 = (Photo)obj1;
- Photo p2 = (Photo)obj2;
-
- int result = Photo.CompareCurrentDir (p1, p2);
-
- if (result == 0)
- result = CompareName (p1, p2);
-
- return result;
- }
- }
-
- public class RandomSort : IComparer
- {
- Random random = new Random ();
-
- public int Compare (object obj1, object obj2)
- {
- return random.Next (-5, 5);
- }
- }
-
- // The time is always in UTC.
- private DateTime time;
- public DateTime Time {
- get { return time; }
- set { time = value; }
- }
-
- public string Name {
- get { return System.IO.Path.GetFileName (VersionUri (OriginalVersionId).AbsolutePath); }
- }
-
- //This property no longer keeps a 'directory' path, but the logical container for the image, like:
- // file:///home/bob/Photos/2007/08/23 or
- // http://www.google.com/logos
- [Obsolete ("MARKED FOR REMOVAL. no longer makes sense with versions in different Directories. Any way to get rid of this ?")]
- public string DirectoryPath {
- get {
- System.Uri uri = VersionUri (OriginalVersionId);
- return uri.Scheme + "://" + uri.Host + System.IO.Path.GetDirectoryName (uri.AbsolutePath);
- }
- }
-
- private ArrayList tags;
- public Tag [] Tags {
- get {
- if (tags == null)
- return new Tag [0];
-
- return (Tag []) tags.ToArray (typeof (Tag));
- }
- }
-
- private bool loaded = false;
- public bool Loaded {
- get { return loaded; }
- set { loaded = value; }
- }
-
- private string description;
- public string Description {
- get { return description; }
- set { description = value; }
- }
-
- private uint roll_id = 0;
- public uint RollId {
- get { return roll_id; }
- set { roll_id = value; }
- }
-
- private uint rating;
- private bool rated = false;
- public uint Rating {
- get {
- if (!rated)
- throw new NotRatedException ("This photo is not rated yet");
- else
- return rating;
- }
- set {
- if (value >= 0 && value <= 5) {
- rating = value;
- rated = true;
- } else
- rated = false;
- }
- }
-
- public void RemoveRating ()
- {
- rated = false;
- }
-
- // Version management
- public const int OriginalVersionId = 1;
- private uint highest_version_id;
-
- private Dictionary<uint, PhotoVersion> versions;
- private Dictionary<uint, PhotoVersion> Versions {
- get {
- if (versions == null)
- versions = new Dictionary<uint, PhotoVersion> ();
- return versions;
- }
- }
-
- public uint [] VersionIds {
- get {
- if (versions == null)
- return new uint [0];
-
- uint [] ids = new uint [versions.Count];
- versions.Keys.CopyTo (ids, 0);
- Array.Sort (ids);
- return ids;
- }
- }
-
- public IBrowsableItem GetVersion (uint version_id)
- {
- if (versions == null)
- return null;
-
- return versions [version_id];
- }
-
- private uint default_version_id = OriginalVersionId;
- public uint DefaultVersionId {
- get { return default_version_id; }
- set { default_version_id = value; }
- }
-
- // This doesn't check if a version of that name already exists,
- // it's supposed to be used only within the Photo and PhotoStore classes.
- internal void AddVersionUnsafely (uint version_id, System.Uri uri, string name, bool is_protected)
- {
- Versions [version_id] = new PhotoVersion (this, version_id, uri, name, is_protected);
-
- highest_version_id = Math.Max (version_id, highest_version_id);
- }
-
- public uint AddVersion (System.Uri uri, string name)
- {
- return AddVersion (uri, name, false);
- }
-
- public uint AddVersion (System.Uri uri, string name, bool is_protected)
- {
- if (VersionNameExists (name))
- throw new ApplicationException ("A version with that name already exists");
- highest_version_id ++;
- Versions [highest_version_id] = new PhotoVersion (this, highest_version_id, uri, name, is_protected);
- return highest_version_id;
- }
-
- //FIXME: store versions next to originals. will crash on ro locations.
- private System.Uri GetUriForVersionName (string version_name, string extension)
- {
- string name_without_extension = System.IO.Path.GetFileNameWithoutExtension (Name);
-
- return new System.Uri (System.IO.Path.Combine (DirectoryPath, name_without_extension
- + " (" + version_name + ")" + extension));
- }
-
- public bool VersionNameExists (string version_name)
- {
- foreach (PhotoVersion v in Versions.Values)
- if (v.Name == version_name)
- return true;
-
- return false;
- }
-
- [Obsolete ("use GetVersion (uint).Name")]
- public string GetVersionName (uint version_id)
- {
- PhotoVersion v = GetVersion (version_id) as PhotoVersion;
- if (v != null)
- return v.Name;
- return null;
- }
-
- [Obsolete ("Use VersionUri (uint) instead")]
- public string GetVersionPath (uint version_id)
- {
- return VersionUri (version_id).LocalPath;
- }
-
- public System.Uri VersionUri (uint version_id)
- {
- if (!Versions.ContainsKey (version_id))
- return null;
-
- PhotoVersion v = Versions [version_id];
- if (v != null)
- return v.Uri;
-
- return null;
- }
-
- public System.Uri DefaultVersionUri {
- get { return VersionUri (DefaultVersionId); }
- }
-
- public PhotoVersion DefaultVersion {
- get {
- if (!Versions.ContainsKey (DefaultVersionId))
- return null;
- return Versions [DefaultVersionId];
- }
- }
- public void DeleteVersion (uint version_id)
- {
- DeleteVersion (version_id, false, false);
- }
-
- public void DeleteVersion (uint version_id, bool remove_original)
- {
- DeleteVersion (version_id, remove_original, false);
- }
-
- public void DeleteVersion (uint version_id, bool remove_original, bool keep_file)
- {
- if (version_id == OriginalVersionId && !remove_original)
- throw new Exception ("Cannot delete original version");
-
- System.Uri uri = VersionUri (version_id);
-
- if (!keep_file) {
- if ((new Gnome.Vfs.Uri (uri.ToString ())).Exists) {
- if ((new Gnome.Vfs.Uri (uri.ToString ()).Unlink()) != Result.Ok)
- throw new System.UnauthorizedAccessException();
- }
-
- try {
- string thumb_path = ThumbnailGenerator.ThumbnailPath (uri);
- System.IO.File.Delete (thumb_path);
- } catch (System.Exception) {
- //ignore an error here we don't really care.
- }
- PhotoStore.DeleteThumbnail (uri);
- }
- Versions.Remove (version_id);
-
- do {
- version_id --;
- if (Versions.ContainsKey (version_id)) {
- DefaultVersionId = version_id;
- break;
- }
- } while (version_id > OriginalVersionId);
- }
-
- public uint CreateProtectedVersion (string name, uint base_version_id, bool create)
- {
- return CreateVersion (name, base_version_id, create, true);
- }
-
- public uint CreateVersion (string name, uint base_version_id, bool create)
- {
- return CreateVersion (name, base_version_id, create, false);
- }
-
- private uint CreateVersion (string name, uint base_version_id, bool create, bool is_protected)
- {
- System.Uri new_uri = GetUriForVersionName (name, System.IO.Path.GetExtension (VersionUri (base_version_id).AbsolutePath));
- System.Uri original_uri = VersionUri (base_version_id);
-
- if (VersionNameExists (name))
- throw new Exception ("This version name already exists");
-
- if (create) {
- if ((new Gnome.Vfs.Uri (new_uri.ToString ())).Exists)
- throw new Exception (String.Format ("An object at this uri {0} already exists", new_uri.ToString ()));
-
- Xfer.XferUri (
- new Gnome.Vfs.Uri (original_uri.ToString ()),
- new Gnome.Vfs.Uri (new_uri.ToString ()),
- XferOptions.Default, XferErrorMode.Abort,
- XferOverwriteMode.Abort,
- delegate (Gnome.Vfs.XferProgressInfo info) {return 1;});
-
-// Mono.Unix.Native.Stat stat;
-// int stat_err = Mono.Unix.Native.Syscall.stat (original_path, out stat);
-// File.Copy (original_path, new_path);
- FSpot.ThumbnailGenerator.Create (new_uri).Dispose ();
-//
-// if (stat_err == 0)
-// try {
-// Mono.Unix.Native.Syscall.chown(new_path, Mono.Unix.Native.Syscall.getuid (), stat.st_gid);
-// } catch (Exception) {}
- }
- highest_version_id ++;
- Versions [highest_version_id] = new PhotoVersion (this, highest_version_id, new_uri, name, is_protected);
-
- return highest_version_id;
- }
-
- public uint CreateReparentedVersion (PhotoVersion version)
- {
- return CreateReparentedVersion (version, false);
- }
-
- public uint CreateReparentedVersion (PhotoVersion version, bool is_protected)
- {
- int num = 0;
- while (true) {
- num++;
- string name = Catalog.GetPluralString ("Reparented", "Reparented ({0})", num);
- name = String.Format (name, num);
- if (VersionNameExists (name))
- continue;
-
- highest_version_id ++;
- Versions [highest_version_id] = new PhotoVersion (this, highest_version_id, version.Uri, name, is_protected);
-
- return highest_version_id;
- }
- }
-
- public uint CreateDefaultModifiedVersion (uint base_version_id, bool create_file)
- {
- int num = 1;
-
- while (true) {
- string name = Catalog.GetPluralString ("Modified",
- "Modified ({0})",
- num);
- name = String.Format (name, num);
-
- if (! VersionNameExists (name))
- return CreateVersion (name, base_version_id, create_file);
-
- num ++;
- }
- }
-
- public uint CreateNamedVersion (string name, uint base_version_id, bool create_file)
- {
- int num = 1;
-
- string final_name;
- while (true) {
- final_name = String.Format (
- Catalog.GetPluralString ("Modified in {1}", "Modified in {1} ({0})", num),
- num, name);
-
- if (num > 1)
- final_name = name + String.Format(" ({0})", num);
-
- if (! VersionNameExists (final_name))
- return CreateVersion (final_name, base_version_id, create_file);
-
- num ++;
- }
- }
-
- public void RenameVersion (uint version_id, string new_name)
- {
- if (version_id == OriginalVersionId)
- throw new Exception ("Cannot rename original version");
-
- if (VersionNameExists (new_name))
- throw new Exception ("This name already exists");
-
- (GetVersion (version_id) as PhotoVersion).Name = new_name;
-
- //TODO: rename file too ???
-
-// if (System.IO.File.Exists (new_path))
-// throw new Exception ("File with this name already exists");
-//
-// File.Move (old_path, new_path);
-// PhotoStore.MoveThumbnail (old_path, new_path);
- }
-
-
- // Tag management.
-
- // This doesn't check if the tag is already there, use with caution.
- public void AddTagUnsafely (Tag tag)
- {
- if (tags == null)
- tags = new ArrayList ();
-
- tags.Add (tag);
- }
-
- // This on the other hand does, but is O(n) with n being the number of existing tags.
- public void AddTag (Tag tag)
- {
- if (!HasTag (tag))
- AddTagUnsafely (tag);
- }
-
- public void AddTag (Tag []taglist)
- {
- /*
- * FIXME need a better naming convention here, perhaps just
- * plain Add.
- */
- foreach (Tag tag in taglist)
- AddTag (tag);
- }
-
- public void RemoveTag (Tag tag)
- {
- if (HasTag (tag))
- tags.Remove (tag);
- }
-
- public void RemoveTag (Tag []taglist)
- {
- foreach (Tag tag in taglist)
- RemoveTag (tag);
- }
-
- public void RemoveCategory (Tag []taglist)
- {
- foreach (Tag tag in taglist) {
- Category cat = tag as Category;
-
- if (cat != null)
- RemoveCategory (cat.Children);
-
- RemoveTag (tag);
- }
- }
-
- public bool HasTag (Tag tag)
- {
- if (tags == null)
- return false;
-
- return tags.Contains (tag);
- }
-
- private static FSpot.Xmp.XmpFile UpdateXmp (FSpot.IBrowsableItem item, FSpot.Xmp.XmpFile xmp)
- {
- if (xmp == null)
- xmp = new FSpot.Xmp.XmpFile ();
-
- Tag [] tags = item.Tags;
- string [] names = new string [tags.Length];
-
- for (int i = 0; i < tags.Length; i++)
- names [i] = tags [i].Name;
-
- xmp.Store.Update ("dc:subject", "rdf:Bag", names);
- try {
- xmp.Store.Update ("xmp:Rating", (item as Photo).Rating.ToString());
-// FIXME - Should we also store/overwrite the Urgency field?
-// uint urgency_value = (item as Photo).Rating + 1; // Urgency valid values 1 - 8
-// xmp.Store.Update ("photoshop:Urgency", urgency_value.ToString());
- } catch (NotRatedException) {
- xmp.Store.Delete ("xmp:Rating");
- }
- xmp.Dump ();
-
- return xmp;
- }
-
- //FIXME: Won't work on non-file uris
- public void WriteMetadataToImage ()
- {
- string path = this.DefaultVersionUri.LocalPath;
-
- using (FSpot.ImageFile img = FSpot.ImageFile.Create (DefaultVersionUri)) {
- if (img is FSpot.JpegFile) {
- FSpot.JpegFile jimg = img as FSpot.JpegFile;
-
- jimg.SetDescription (this.Description);
- jimg.SetDateTimeOriginal (this.Time.ToLocalTime ());
- jimg.SetXmp (UpdateXmp (this, jimg.Header.GetXmp ()));
-
- jimg.SaveMetaData (path);
- } else if (img is FSpot.Png.PngFile) {
- FSpot.Png.PngFile png = img as FSpot.Png.PngFile;
-
- if (img.Description != this.Description)
- png.SetDescription (this.Description);
-
- png.SetXmp (UpdateXmp (this, png.GetXmp ()));
-
- png.Save (path);
- }
- }
- }
-
- //FIXME: won't work on non file uris
- public uint SaveVersion (Gdk.Pixbuf buffer, bool create_version)
- {
- uint version = DefaultVersionId;
- using (ImageFile img = ImageFile.Create (DefaultVersionUri)) {
- // Always create a version if the source is not a jpeg for now.
- create_version = create_version || !(img is FSpot.JpegFile);
-
- if (buffer == null)
- throw new ApplicationException ("invalid (null) image");
-
- if (create_version)
- version = CreateDefaultModifiedVersion (DefaultVersionId, false);
-
- try {
- string version_path = GetVersionPath (version);
-
- using (Stream stream = System.IO.File.OpenWrite (version_path)) {
- img.Save (buffer, stream);
- }
- FSpot.ThumbnailGenerator.Create (version_path).Dispose ();
- DefaultVersionId = version;
- } catch (System.Exception e) {
- System.Console.WriteLine (e);
- if (create_version)
- DeleteVersion (version);
-
- throw e;
- }
- }
-
- return version;
- }
-
- // Constructor
- public Photo (uint id, long unix_time, System.Uri uri)
- : base (id)
- {
- if (uri == null)
- throw new System.ArgumentNullException ("uri");
-
- time = DbUtils.DateTimeFromUnixTime (unix_time);
-
- description = String.Empty;
- rated = false;
-
- // Note that the original version is never stored in the photo_versions table in the
- // database.
- AddVersionUnsafely (OriginalVersionId, uri, Catalog.GetString ("Original"), true);
- }
-
- [Obsolete ("Use Photo (uint, long, Uri) instead")]
- public Photo (uint id, long unix_time, string directory_path, string name)
- : this (id, unix_time, System.IO.Path.Combine (directory_path, name))
- {
- }
-
- [Obsolete ("Use Photo (uint, long, Uri) instead")]
- public Photo (uint id, long unix_time, string path)
- : this (id, unix_time, UriList.PathToFileUri (path))
- {
- }
-
-}
public class PhotoStore : DbStore {
public int TotalPhotos {
@@ -725,12 +88,6 @@
return thumbnail;
}
-// [Obsolete ("use DeleteThumbnail (System.Uri) instead")]
-// public static void DeleteThumbnail (string path)
-// {
-// DeleteThumbnail (UriList.PathToFileUri (path));
-// }
-
public static void DeleteThumbnail (System.Uri uri)
{
string path = Thumbnail.PathForUri (uri.ToString (), ThumbnailSize.Large);
@@ -740,11 +97,10 @@
public static void MoveThumbnail (string old_path, string new_path)
{
- System.IO.File.Move (ThumbnailGenerator.ThumbnailPath (UriList.PathToFileUri (old_path)),
- ThumbnailGenerator.ThumbnailPath(UriList.PathToFileUri (new_path)));
+ System.IO.File.Move (ThumbnailGenerator.ThumbnailPath (UriUtils.PathToFileUri (old_path)),
+ ThumbnailGenerator.ThumbnailPath(UriUtils.PathToFileUri (new_path)));
}
-
// Constructor
public PhotoStore (QueuedSqliteDatabase database, bool is_new)
@@ -798,7 +154,7 @@
[Obsolete ("Use Create (Uri, Uri, uint, out Pixbuf) instead")]
public Photo Create (string new_path, string orig_path, uint roll_id, out Pixbuf thumbnail)
{
- return Create (UriList.PathToFileUri (new_path), UriList.PathToFileUri (orig_path), roll_id, out thumbnail);
+ return Create (UriUtils.PathToFileUri (new_path), UriUtils.PathToFileUri (orig_path), roll_id, out thumbnail);
}
public Photo Create (System.Uri uri, uint roll_id, out Pixbuf thumbnail)
@@ -982,7 +338,7 @@
[Obsolete ("Use GetByUri instead")]
public Photo GetByPath (string path)
{
- return GetByUri (UriList.PathToFileUri (path));
+ return GetByUri (UriUtils.PathToFileUri (path));
}
public Photo GetByUri (System.Uri uri)
Modified: trunk/src/PhotoVersion.cs
==============================================================================
--- trunk/src/PhotoVersion.cs (original)
+++ trunk/src/PhotoVersion.cs Wed Jan 30 11:23:58 2008
@@ -1,77 +0,0 @@
-/*
- * PhotoStore.cs
- *
- * Author(s):
- * Ettore Perazzoli <ettore perazzoli org>
- * Larry Ewing <lewing gnome org>
- * Stephane Delcroix <stephane delcroix org>
- *
- * This is free software. See COPYING for details.
- */
-
-namespace FSpot
-{
- public class PhotoVersion : FSpot.IBrowsableItem
- {
- Photo photo;
- uint version_id;
- System.Uri uri;
- string name;
- bool is_protected;
-
- public System.DateTime Time {
- get { return photo.Time; }
- }
-
- public Tag [] Tags {
- get { return photo.Tags; }
- }
-
- public System.Uri DefaultVersionUri {
- get { return uri; }
- }
-
- public string Description {
- get { return photo.Description; }
- }
-
- public string Name {
- get { return name; }
- set { name = value; }
- }
-
- public Photo Photo {
- get { return photo; }
- }
-
- public System.Uri Uri {
- get { return uri; }
- set {
- if (value == null)
- throw new System.ArgumentNullException ("uri");
- uri = value;
- }
- }
-
- public uint VersionId {
- get { return version_id; }
- }
-
- public bool IsProtected {
- get { return is_protected; }
- }
-
- public uint Rating {
- get { return photo.Rating; }
- }
-
- public PhotoVersion (Photo photo, uint version_id, System.Uri uri, string name, bool is_protected)
- {
- this.photo = photo;
- this.version_id = version_id;
- this.uri = uri;
- this.name = name;
- this.is_protected = is_protected;
- }
- }
-}
Modified: trunk/src/PhotoVersionMenu.cs
==============================================================================
--- trunk/src/PhotoVersionMenu.cs (original)
+++ trunk/src/PhotoVersionMenu.cs Wed Jan 30 11:23:58 2008
@@ -1,7 +1,7 @@
using Gtk;
using GtkSharp;
using System;
-
+using FSpot;
public class PhotoVersionMenu : Menu {
private uint version_id;
public uint VersionId {
Modified: trunk/src/Query/DateRange.cs
==============================================================================
--- trunk/src/Query/DateRange.cs (original)
+++ trunk/src/Query/DateRange.cs Wed Jan 30 11:23:58 2008
@@ -9,6 +9,7 @@
*/
using System;
+using FSpot.Utils;
namespace FSpot.Query {
public class DateRange : IQueryCondition
Modified: trunk/src/RollStore.cs
==============================================================================
--- trunk/src/RollStore.cs (original)
+++ trunk/src/RollStore.cs Wed Jan 30 11:23:58 2008
@@ -14,7 +14,7 @@
using System.IO;
using System;
using Banshee.Database;
-
+using FSpot.Utils;
public class Roll : DbItem
{
// The time is always in UTC.
Modified: trunk/src/SingleView.cs
==============================================================================
--- trunk/src/SingleView.cs (original)
+++ trunk/src/SingleView.cs Wed Jan 30 11:23:58 2008
@@ -43,7 +43,7 @@
public SingleView () : this (FSpot.Global.HomeDirectory) {}
- public SingleView (string path) : this (UriList.PathToFileUri (path))
+ public SingleView (string path) : this (UriUtils.PathToFileUri (path))
{
}
Modified: trunk/src/ThumbnailCommand.cs
==============================================================================
--- trunk/src/ThumbnailCommand.cs (original)
+++ trunk/src/ThumbnailCommand.cs Wed Jan 30 11:23:58 2008
@@ -1,5 +1,6 @@
using System;
using Gtk;
+using FSpot;
public class ThumbnailCommand {
Modified: trunk/src/ThumbnailGenerator.cs
==============================================================================
--- trunk/src/ThumbnailGenerator.cs (original)
+++ trunk/src/ThumbnailGenerator.cs Wed Jan 30 11:23:58 2008
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using FSpot.Utils;
#if ENABLE_NUNIT
using NUnit.Framework;
@@ -17,7 +18,7 @@
public static Gdk.Pixbuf Create (string path)
{
- return Create (UriList.PathToFileUri (path));
+ return Create (UriUtils.PathToFileUri (path));
}
public static Gdk.Pixbuf Create (Uri uri)
@@ -42,7 +43,7 @@
try {
Gnome.Vfs.FileInfo vfs = new Gnome.Vfs.FileInfo (uri.ToString ());
DateTime mtime = vfs.Mtime;
- valid = Gnome.Thumbnail.IsValid (thumbnail, UriList.UriToStringEscaped (uri), mtime);
+ valid = Gnome.Thumbnail.IsValid (thumbnail, UriUtils.UriToStringEscaped (uri), mtime);
} catch (System.IO.FileNotFoundException) {
// If the original file is not on disk, the thumbnail is as valid as it's going to get
valid = true;
@@ -56,18 +57,18 @@
public static string ThumbnailPath (System.Uri uri)
{
- string large_path = Gnome.Thumbnail.PathForUri (UriList.UriToStringEscaped (uri), Gnome.ThumbnailSize.Large);
+ string large_path = Gnome.Thumbnail.PathForUri (UriUtils.UriToStringEscaped (uri), Gnome.ThumbnailSize.Large);
return large_path;
}
public static string ThumbnailPath (string path)
{
- return ThumbnailPath (UriList.PathToFileUri (path));
+ return ThumbnailPath (UriUtils.PathToFileUri (path));
}
public static void Save (Gdk.Pixbuf image, Uri dest)
{
- string uri = UriList.UriToStringEscaped (dest);
+ string uri = UriUtils.UriToStringEscaped (dest);
System.DateTime mtime = DateTime.Now;
// Use Gnome.Vfs
@@ -114,7 +115,7 @@
if (image != null) {
Uri uri;
if (File.Exists (request.path))
- uri = UriList.PathToFileUri (request.path);
+ uri = UriUtils.PathToFileUri (request.path);
else
uri = new Uri (request.path);
@@ -169,10 +170,10 @@
public void BadNames (string name)
{
string path = CreateFile (name, 512);
- System.Uri uri = UriList.PathToFileUri (path);
+ System.Uri uri = UriUtils.PathToFileUri (path);
Gnome.ThumbnailFactory factory = new Gnome.ThumbnailFactory (Gnome.ThumbnailSize.Large);
- string escaped = UriList.PathToFileUriEscaped (path);
+ string escaped = UriUtils.PathToFileUriEscaped (path);
string large_path = Gnome.Thumbnail.PathForUri (escaped,
Gnome.ThumbnailSize.Large);
@@ -206,9 +207,9 @@
Assert.IsTrue (File.Exists (thumb_path), String.Format ("Missing: {0} created from {1}", thumb_path, path));
using (Gdk.Pixbuf thumb = new Gdk.Pixbuf (thumb_path)) {
Assert.IsNotNull (thumb);
- Assert.AreEqual (thumb.GetOption (ThumbUri), UriList.PathToFileUriEscaped (path));
- Assert.AreEqual (new Uri (thumb.GetOption (ThumbUri)), UriList.PathToFileUri (path));
- Assert.IsTrue (ThumbnailGenerator.ThumbnailIsValid (thumb, UriList.PathToFileUri (path)));
+ Assert.AreEqual (thumb.GetOption (ThumbUri), UriUtils.PathToFileUriEscaped (path));
+ Assert.AreEqual (new Uri (thumb.GetOption (ThumbUri)), UriUtils.PathToFileUri (path));
+ Assert.IsTrue (ThumbnailGenerator.ThumbnailIsValid (thumb, UriUtils.PathToFileUri (path)));
}
File.Delete (path);
@@ -237,7 +238,7 @@
Assert.IsTrue (File.Exists (thumb_path), String.Format ("Missing: {0} created from {1}", thumb_path, uri));
using (Gdk.Pixbuf thumb = new Gdk.Pixbuf (thumb_path)) {
Assert.IsNotNull (thumb);
- Assert.AreEqual (thumb.GetOption (ThumbUri), UriList.UriToStringEscaped (uri));
+ Assert.AreEqual (thumb.GetOption (ThumbUri), UriUtils.UriToStringEscaped (uri));
Assert.AreEqual (new Uri (thumb.GetOption (ThumbUri)), uri);
Assert.IsTrue (ThumbnailGenerator.ThumbnailIsValid (thumb, uri));
}
Modified: trunk/src/Util.cs
==============================================================================
--- trunk/src/Util.cs (original)
+++ trunk/src/Util.cs Wed Jan 30 11:23:58 2008
@@ -14,6 +14,8 @@
using System.Text;
using System;
+using FSpot.Utils;
+
public class UriList : ArrayList {
public UriList (FSpot.IBrowsableItem [] photos) {
foreach (FSpot.IBrowsableItem p in photos) {
@@ -68,85 +70,6 @@
}
}
- // NOTE: this was copied from mono's System.Uri where it is protected.
- public static string EscapeString (string str, bool escapeReserved, bool escapeHex, bool escapeBrackets)
- {
- if (str == null)
- return String.Empty;
-
- byte [] data = Encoding.UTF8.GetBytes (str);
- StringBuilder s = new StringBuilder ();
- int len = data.Length;
- for (int i = 0; i < len; i++) {
- char c = (char) data [i];
- // reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" | "$" | ","
- // mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")"
- // control = <US-ASCII coded characters 00-1F and 7F hexadecimal>
- // space = <US-ASCII coded character 20 hexadecimal>
- // delims = "<" | ">" | "#" | "%" | <">
- // unwise = "{" | "}" | "|" | "\" | "^" | "[" | "]" | "`"
-
- // check for escape code already placed in str,
- // i.e. for encoding that follows the pattern
- // "%hexhex" in a string, where "hex" is a digit from 0-9
- // or a letter from A-F (case-insensitive).
- if('%' == c && Uri.IsHexEncoding(str,i))
- {
- // if ,yes , copy it as is
- s.Append(c);
- s.Append(str[++i]);
- s.Append(str[++i]);
- continue;
- }
-
- if ((c <= 0x20) || (c >= 0x7f) ||
- ("<>%\"{}|\\^`".IndexOf (c) != -1) ||
- (escapeHex && (c == '#')) ||
- (escapeBrackets && (c == '[' || c == ']')) ||
- (escapeReserved && (";/?:@&=+$,".IndexOf (c) != -1))) {
- s.Append (Uri.HexEscape (c));
- continue;
- }
-
-
- s.Append (c);
- }
-
- return s.ToString ();
- }
-
- static char[] CharsToQuote = { ';', '?', ':', '@', '&', '=', '$', ',', '#' };
-
- public static string UriToStringEscaped (Uri uri)
- {
- return EscapeString (uri.ToString (), false, true, false);
- }
-
- public static string PathToFileUriEscaped (string path)
- {
- return UriToStringEscaped (PathToFileUri (path));
- }
-
- public static Uri PathToFileUri (string path)
- {
- path = Path.GetFullPath (path);
-
- StringBuilder builder = new StringBuilder ();
- builder.Append (Uri.UriSchemeFile);
- builder.Append (Uri.SchemeDelimiter);
-
- int i;
- while ((i = path.IndexOfAny (CharsToQuote)) != -1) {
- if (i > 0)
- builder.Append (path.Substring (0, i));
- builder.Append (Uri.HexEscape (path [i]));
- path = path.Substring (i+1);
- }
- builder.Append (path);
-
- return new Uri (builder.ToString (), true);
- }
-
public UriList (string [] uris)
{
// FIXME this is so lame do real chacking at some point
@@ -160,7 +83,7 @@
Uri uri;
if (File.Exists (unknown) || Directory.Exists (unknown))
- uri = PathToFileUri (unknown);
+ uri = UriUtils.PathToFileUri (unknown);
else
uri = new Uri (unknown);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]