[f-spot] Fully demolish the old import.
- From: Ruben Vermeersch <rubenv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [f-spot] Fully demolish the old import.
- Date: Sat, 5 Jun 2010 20:54:37 +0000 (UTC)
commit 297df7890adee3be5177ec86411e4a10fa9fc945
Author: Ruben Vermeersch <ruben savanne be>
Date: Sat Jun 5 18:38:48 2010 +0200
Fully demolish the old import.
Still missing some features and some extensions are broken.
extensions/Exporters/FolderExport/FolderExport.cs | 27 +-
.../ChangePhotoPath/ChangePhotoPathController.cs | 2 +-
src/FileImportBackend.cs | 131 -----
src/Import/FileImportSource.cs | 163 ++++---
src/Import/ImportController.cs | 39 ++-
src/ImportBackend.cs | 20 -
src/ImportCommand.cs | 504 --------------------
src/MainWindow.cs | 65 ++-
src/Makefile.am | 3 -
src/UI.Dialog/ImportDialog.cs | 2 +-
src/ui/main_window.ui | 1 -
11 files changed, 184 insertions(+), 773 deletions(-)
---
diff --git a/extensions/Exporters/FolderExport/FolderExport.cs b/extensions/Exporters/FolderExport/FolderExport.cs
index cb9c273..d3f3cf1 100644
--- a/extensions/Exporters/FolderExport/FolderExport.cs
+++ b/extensions/Exporters/FolderExport/FolderExport.cs
@@ -79,7 +79,6 @@ namespace FSpotFolderExport {
GLib.File dest;
Gtk.FileChooserButton uri_chooser;
- int photo_index;
bool open;
bool scale;
bool rotate;
@@ -162,8 +161,6 @@ namespace FSpotFolderExport {
{
// FIXME use mkstemp
- bool result = true;
-
try {
Gtk.Application.Invoke (delegate {Dialog.Hide ();});
@@ -252,7 +249,7 @@ namespace FSpotFolderExport {
Log.DebugFormat ("Transferring \"{0}\" to \"{1}\"", source.Path, target.Path);
progress_dialog.Message = String.Format (Catalog.GetString ("Transferring to \"{0}\""), target.Path);
progress_dialog.ProgressText = Catalog.GetString ("Transferring...");
- result = source.CopyRecursive (target, GLib.FileCopyFlags.Overwrite, new GLib.Cancellable (), Progress);
+ source.CopyRecursive (target, GLib.FileCopyFlags.Overwrite, new GLib.Cancellable (), Progress);
}
// No need to check result here as if result is not true, an Exception will be thrown before
@@ -445,7 +442,21 @@ namespace FSpotFolderExport {
protected virtual string ImageName (int image_num)
{
- return System.IO.Path.GetFileName(FileImportBackend.UniqueName(gallery_path, System.IO.Path.GetFileName (collection [image_num].DefaultVersion.Uri.LocalPath)).AbsolutePath);
+ var uri = collection [image_num].DefaultVersion.Uri;
+ var dest_uri = new SafeUri (gallery_path);
+
+ // Find an unused name
+ int i = 1;
+ var dest = dest_uri.Append (uri.GetFilename ());
+ var file = GLib.FileFactory.NewForUri (dest);
+ while (file.Exists) {
+ var filename = uri.GetFilenameWithoutExtension ();
+ var extension = uri.GetExtension ();
+ dest = dest_uri.Append (String.Format ("{0}-{1}{2}", filename, i++, extension));
+ file = GLib.FileFactory.NewForUri (dest);
+ }
+
+ return dest.GetFilename ();
}
public void ProcessImage (int image_num, FilterSet filter_set)
@@ -629,11 +640,6 @@ namespace FSpotFolderExport {
return String.Format ("img-{0}.jpg", photo_index + 1);
}
- private string AlternateName (int photo_index, string extension)
- {
- return System.IO.Path.GetFileNameWithoutExtension (ImageName (photo_index)) + extension;
- }
-
private void SetTime ()
{
try {
@@ -728,7 +734,6 @@ namespace FSpotFolderExport {
class HtmlGallery : FolderGallery
{
- int current;
int perpage = 16;
string stylesheet = "f-spot-simple.css";
string altstylesheet = "f-spot-simple-white.css";
diff --git a/extensions/Tools/ChangePhotoPath/ChangePhotoPathController.cs b/extensions/Tools/ChangePhotoPath/ChangePhotoPathController.cs
index 74f1a39..8d0378e 100644
--- a/extensions/Tools/ChangePhotoPath/ChangePhotoPathController.cs
+++ b/extensions/Tools/ChangePhotoPath/ChangePhotoPathController.cs
@@ -64,7 +64,7 @@ namespace ChangePhotoPath
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
+ string new_base_path = EnsureEndsWithOneDirectorySeparator (FSpot.Global.PhotoUri.LocalPath); // NOT URI
gui_controller.DisplayDefaultPaths (orig_base_path, new_base_path);
user_cancelled = false;
}
diff --git a/src/FileImportBackend.cs b/src/FileImportBackend.cs
index d0ab7f4..1faf3ba 100644
--- a/src/FileImportBackend.cs
+++ b/src/FileImportBackend.cs
@@ -11,12 +11,6 @@ using System.IO;
using Mono.Unix;
using Hyena;
-public class ImportException : System.Exception {
- public ImportException (string msg) : base (msg)
- {
- }
-}
-
public class FileImportBackend : ImportBackend {
PhotoStore store;
RollStore rolls = FSpot.App.Instance.Database.Rolls;
@@ -36,45 +30,6 @@ public class FileImportBackend : ImportBackend {
List<IBrowsableItem> import_info;
Stack directories;
- private class ImportInfo : IBrowsableItem {
- public ImportInfo (SafeUri original)
- {
- DefaultVersion = new ImportInfoVersion () {
- BaseUri = original.GetBaseUri (),
- Filename = original.GetFilename ()
- };
-
- try {
- using (FSpot.ImageFile img = FSpot.ImageFile.Create (original)) {
- Time = img.Date;
- }
- } catch (Exception) {
- Time = DateTime.Now;
- }
- }
-
- public IBrowsableItemVersion DefaultVersion { get; private set; }
- public SafeUri DestinationUri { get; set; }
-
- public System.DateTime Time { get; private set; }
-
- public Tag [] Tags { get { throw new NotImplementedException (); } }
- public string Description { get { throw new NotImplementedException (); } }
- public string Name { get { throw new NotImplementedException (); } }
- public uint Rating { get { return 0; } }
-
- internal uint PhotoId { get; set; }
- }
-
- private class ImportInfoVersion : IBrowsableItemVersion {
- public string Name { get { return String.Empty; } }
- public bool IsProtected { get { return true; } }
- public SafeUri BaseUri { get; set; }
- public string Filename { get; set; }
-
- public SafeUri Uri { get { return BaseUri.Append (Filename); } }
- }
-
public override List<IBrowsableItem> Prepare ()
{
if (import_info != null)
@@ -100,76 +55,6 @@ public class FileImportBackend : ImportBackend {
}
-/* public static SafeUri UniqueName (string path, string filename)
- {
- int i = 1;
- string dest = System.IO.Path.Combine (path, filename);
-
- while (System.IO.File.Exists (dest)) {
- string numbered_name = String.Format ("{0}-{1}{2}",
- System.IO.Path.GetFileNameWithoutExtension (filename),
- i++,
- System.IO.Path.GetExtension (filename));
-
- dest = System.IO.Path.Combine (path, numbered_name);
- }
-
- return new SafeUri ("file://"+dest, true);
- }*/
-
- public static SafeUri ChooseLocation (SafeUri uri)
- {
- return ChooseLocation (uri, null);
- }
-
- private static SafeUri ChooseLocation (SafeUri uri, Stack created_directories)
- {
-/* string name = uri.GetFilename ();
- DateTime time;
- using (FSpot.ImageFile img = FSpot.ImageFile.Create (uri)) {
- time = img.Date;
- }
-
- string dest_dir = String.Format ("{0}{1}{2}{1}{3:D2}{1}{4:D2}",
- FSpot.Global.PhotoUri, // FIXME broken
- System.IO.Path.DirectorySeparatorChar,
- time.Year,
- time.Month,
- time.Day);
-
- if (!System.IO.Directory.Exists (dest_dir)) {
- System.IO.DirectoryInfo info;
- // Split dest_dir into constituent parts so we can clean up each individual directory in
- // event of a cancel.
- if (created_directories != null) {
- string [] parts = dest_dir.Split (new char [] {System.IO.Path.DirectorySeparatorChar});
- string nextPath = String.Empty;
- for (int i = 0; i < parts.Length; i++) {
- if (i == 0)
- nextPath += parts [i];
- else
- nextPath += System.IO.Path.DirectorySeparatorChar + parts [i];
- if (nextPath.Length > 0) {
- info = new System.IO.DirectoryInfo (nextPath);
- // only add the directory path if it didn't already exist and we haven't already added it.
- if (!info.Exists && !created_directories.Contains (nextPath))
- created_directories.Push (nextPath);
- }
- }
- }
-
- info = System.IO.Directory.CreateDirectory (dest_dir);
- }*/
-
- // If the destination we'd like to use is the file itself return that
- //if ("file://" + Path.Combine (dest_dir, name) == uri.ToString ())
- // return uri;
-
- //var dest = UniqueName (dest_dir, name);
-
- return uri;
- }
-
public override bool Step (out StepStatusInfo status_info)
{
Photo photo = null;
@@ -339,19 +224,3 @@ public class FileImportBackend : ImportBackend {
count = duplicate_count = 0;
//rolls.EndImport(); // Clean up the imported session.
}
-
- public FileImportBackend (PhotoStore store, SafeUri [] base_paths, bool recurse, Gtk.Window parent) : this (store, base_paths, false, recurse, false, null, parent) {}
-
- public FileImportBackend (PhotoStore store, SafeUri [] base_paths, bool copy, bool recurse, Tag [] tags, Gtk.Window parent) : this (store, base_paths, copy, recurse, false, null, parent) {}
-
- public FileImportBackend (PhotoStore store, SafeUri [] base_paths, bool copy, bool recurse, bool detect_duplicates, Tag [] tags, Gtk.Window parent)
- {
- this.store = store;
- this.copy = copy;
- this.base_paths = base_paths;
- this.recurse = recurse;
- this.detect_duplicates = detect_duplicates;
- this.tags = tags;
- this.parent = parent;
- }
-}
diff --git a/src/Import/FileImportSource.cs b/src/Import/FileImportSource.cs
index 8239bb7..feade92 100644
--- a/src/Import/FileImportSource.cs
+++ b/src/Import/FileImportSource.cs
@@ -12,37 +12,48 @@ namespace FSpot.Import
public SafeUri Root { get; set; }
public Thread PhotoScanner;
+ bool run_photoscanner = false;
public FileImportSource (SafeUri root, string name, string icon_name)
{
- Log.Debug ("Added source "+Name);
Root = root;
Name = name;
- if (IsIPodPhoto) {
- IconName = "multimedia-player";
- } else if (IsCamera) {
- IconName = "media-flash";
- } else {
- IconName = icon_name;
+ if (root != null) {
+ if (IsIPodPhoto) {
+ IconName = "multimedia-player";
+ } else if (IsCamera) {
+ IconName = "media-flash";
+ } else {
+ IconName = icon_name;
+ }
}
}
public void StartPhotoScan (ImportController controller)
{
- if (PhotoScanner != null)
- PhotoScanner.Abort ();
+ if (PhotoScanner != null) {
+ run_photoscanner = false;
+ PhotoScanner.Join ();
+ }
+ run_photoscanner = true;
PhotoScanner = ThreadAssist.Spawn (() => ScanPhotos (controller));
}
- void ScanPhotos (ImportController controller)
+ protected virtual void ScanPhotos (ImportController controller)
{
+ ScanPhotoDirectory (controller, Root);
+ ThreadAssist.ProxyToMain (() => controller.PhotoScanFinished ());
+ }
+
+ protected void ScanPhotoDirectory (ImportController controller, SafeUri uri)
+ {
+ var enumerator = new RecursiveFileEnumerator (uri, controller.RecurseSubdirectories, true);
var infos = new List<FileImportInfo> ();
- var enumerator = new RecursiveFileEnumerator (Root, controller.RecurseSubdirectories, true);
- foreach (var file in enumerator) {
- if (ImageFile.HasLoader (new SafeUri (file.Uri, true))) {
- infos.Add (new FileImportInfo (new SafeUri(file.Uri, true)));
+ foreach (var file in enumerator) {
+ if (ImageFile.HasLoader (new SafeUri (file.Uri, true))) {
+ infos.Add (new FileImportInfo (new SafeUri(file.Uri, true)));
}
if (infos.Count % 10 == 0) {
@@ -50,74 +61,96 @@ namespace FSpot.Import
ThreadAssist.ProxyToMain (() => controller.Photos.Add (to_add.ToArray ()));
infos = new List<FileImportInfo> ();
}
- }
- if (infos.Count > 0) {
- ThreadAssist.ProxyToMain (() => controller.Photos.Add (infos.ToArray ()));
+ if (!run_photoscanner)
+ return;
}
- controller.PhotoScanFinished ();
+ if (infos.Count > 0) {
+ var to_add = infos; // prevents race condition
+ ThreadAssist.ProxyToMain (() => controller.Photos.Add (to_add.ToArray ()));
+ }
}
public void Deactivate ()
{
if (PhotoScanner != null) {
- PhotoScanner.Abort (); // FIXME: abort is not nice
+ run_photoscanner = false;
PhotoScanner = null;
}
}
- private bool IsCamera {
- get {
- try {
+ private bool IsCamera {
+ get {
+ try {
var file = GLib.FileFactory.NewForUri (Root.Append ("DCIM"));
return file.Exists;
- } catch {
- return false;
- }
- }
- }
-
- private bool IsIPodPhoto {
- get {
- try {
+ } catch {
+ return false;
+ }
+ }
+ }
+
+ private bool IsIPodPhoto {
+ get {
+ try {
var file = GLib.FileFactory.NewForUri (Root.Append ("Photos"));
var file2 = GLib.FileFactory.NewForUri (Root.Append ("iPod_Control"));
return file.Exists && file2.Exists;
- } catch {
- return false;
- }
- }
- }
+ } catch {
+ return false;
+ }
+ }
+ }
+ }
+
+ // Multi root version for drag and drop import.
+ internal class MultiFileImportSource : FileImportSource {
+ private IEnumerable<SafeUri> uris;
+
+ public MultiFileImportSource (IEnumerable<SafeUri> uris)
+ : base (null, String.Empty, String.Empty)
+ {
+ this.uris = uris;
+ }
+
+ protected override void ScanPhotos (ImportController controller)
+ {
+ foreach (var uri in uris) {
+ Log.Debug ("Scanning "+uri);
+ ScanPhotoDirectory (controller, uri);
+ }
+ ThreadAssist.ProxyToMain (() => controller.PhotoScanFinished ());
+ }
}
- internal class FileImportInfo : IBrowsableItem {
- public FileImportInfo (SafeUri original)
- {
- DefaultVersion = new ImportInfoVersion () {
- BaseUri = original.GetBaseUri (),
- Filename = original.GetFilename ()
- };
-
- try {
- using (FSpot.ImageFile img = FSpot.ImageFile.Create (original)) {
- Time = img.Date;
- }
- } catch (Exception) {
- Time = DateTime.Now;
- }
- }
-
- public IBrowsableItemVersion DefaultVersion { get; private set; }
- public SafeUri DestinationUri { get; set; }
-
- public System.DateTime Time { get; private set; }
-
- public Tag [] Tags { get { throw new NotImplementedException (); } }
- public string Description { get { throw new NotImplementedException (); } }
- public string Name { get { throw new NotImplementedException (); } }
- public uint Rating { get { return 0; } }
-
- internal uint PhotoId { get; set; }
- }
+ internal class FileImportInfo : IBrowsableItem {
+ public FileImportInfo (SafeUri original)
+ {
+ DefaultVersion = new ImportInfoVersion () {
+ BaseUri = original.GetBaseUri (),
+ Filename = original.GetFilename ()
+ };
+
+ try {
+ using (FSpot.ImageFile img = FSpot.ImageFile.Create (original)) {
+ Time = img.Date;
+ }
+ } catch (Exception) {
+ Time = DateTime.Now;
+ }
+ }
+
+ public IBrowsableItemVersion DefaultVersion { get; private set; }
+ public SafeUri DestinationUri { get; set; }
+
+ public System.DateTime Time { get; private set; }
+
+ public Tag [] Tags { get { throw new NotImplementedException (); } }
+ public string Description { get { throw new NotImplementedException (); } }
+ public string Name { get { throw new NotImplementedException (); } }
+ public uint Rating { get { return 0; } }
+
+ internal uint PhotoId { get; set; }
+ }
}
diff --git a/src/Import/ImportController.cs b/src/Import/ImportController.cs
index 6e04597..cfcba0a 100644
--- a/src/Import/ImportController.cs
+++ b/src/Import/ImportController.cs
@@ -102,9 +102,11 @@ namespace FSpot.Import
void FireEvent (ImportEvent evnt)
{
- var h = StatusEvent;
- if (h != null)
- h (evnt);
+ ThreadAssist.ProxyToMain (() => {
+ var h = StatusEvent;
+ if (h != null)
+ h (evnt);
+ });
}
void ReportProgress (int current, int total)
@@ -114,6 +116,9 @@ namespace FSpot.Import
h (current, total);
}
+ public int PhotosImported { get; private set; }
+ public Roll CreatedRoll { get; private set; }
+
#endregion
#region Source Switching
@@ -144,6 +149,10 @@ namespace FSpot.Import
void RescanPhotos ()
{
Photos.Clear ();
+ if (ActiveSource == null)
+ return;
+
+ photo_scan_running = true;
ActiveSource.StartPhotoScan (this);
FireEvent (ImportEvent.PhotoScanStarted);
}
@@ -156,6 +165,7 @@ namespace FSpot.Import
public void PhotoScanFinished ()
{
+ photo_scan_running = false;
FireEvent (ImportEvent.PhotoScanFinished);
}
@@ -170,25 +180,32 @@ namespace FSpot.Import
if (ImportThread != null)
throw new Exception ("Import already running!");
- FireEvent (ImportEvent.ImportStarted);
ImportThread = ThreadAssist.Spawn (() => DoImport ());
}
public void CancelImport ()
{
-
+ // FIXME
+ DeactivateSource (ActiveSource);
}
Stack<SafeUri> created_directories;
List<uint> imported_photos;
PhotoStore store = App.Instance.Database.Photos;
RollStore rolls = FSpot.App.Instance.Database.Rolls;
+ volatile bool photo_scan_running;
void DoImport ()
{
+ while (photo_scan_running) {
+ Thread.Sleep (1000); // FIXME: we can do this with a better primitive!
+ }
+
+ FireEvent (ImportEvent.ImportStarted);
+ App.Instance.Database.Sync = false;
created_directories = new Stack<SafeUri> ();
imported_photos = new List<uint> ();
- Roll roll = rolls.Create ();
+ CreatedRoll = rolls.Create ();
EnsureDirectory (Global.PhotoUri);
@@ -197,22 +214,24 @@ namespace FSpot.Import
int total = Photos.Count;
foreach (var info in Photos.Items) {
ThreadAssist.ProxyToMain (() => ReportProgress (i++, total));
- ImportPhoto (info, roll.Id);
+ ImportPhoto (info, CreatedRoll);
}
+ PhotosImported = imported_photos.Count;
FinishImport ();
} catch (Exception e) {
RollbackImport ();
throw e;
} finally {
if (imported_photos.Count == 0)
- rolls.Remove (roll);
+ rolls.Remove (CreatedRoll);
imported_photos = null;
created_directories = null;
Photo.ResetMD5Cache ();
DeactivateSource (ActiveSource);
Photos.Clear ();
System.GC.Collect ();
+ App.Instance.Database.Sync = true;
}
}
@@ -226,7 +245,7 @@ namespace FSpot.Import
{
}
- void ImportPhoto (IBrowsableItem item, uint roll_id)
+ void ImportPhoto (IBrowsableItem item, Roll roll)
{
var destination = FindImportDestination (item.DefaultVersion.Uri);
@@ -245,7 +264,7 @@ namespace FSpot.Import
// Import photo
var photo = store.Create (destination,
item.DefaultVersion.Uri,
- roll_id);
+ roll.Id);
// FIXME: Add tags, import xmp crap
imported_photos.Add (photo.Id);
diff --git a/src/ImportCommand.cs b/src/ImportCommand.cs
index 97762bd..bdb7f23 100644
--- a/src/ImportCommand.cs
+++ b/src/ImportCommand.cs
@@ -1,230 +1,5 @@
-/*
- * ImportCommand.cs
- *
- * Author(s)
- * Ettore Perazzoli
- * Larry Ewing
- * Miguel de Icaza
- * Nat Friedman
- * Gabriel Burt
- * Markus Lindqvist <markus lindqvist iki fi>
- *
- * This is free software. See COPYING for details.
- */
-
-using GLib;
-using Gdk;
-using Gtk;
-using System.Collections;
-using System.IO;
-using System;
-using Mono.Unix;
-using Hyena;
-
-using FSpot;
-using FSpot.Utils;
-using FSpot.UI.Dialog;
-using FSpot.Widgets;
-
public class ImportCommand : GladeDialog
{
- internal class SourceItem : ImageMenuItem
- {
- public ImportSource Source;
-
- public SourceItem (ImportSource source) : base (source.Name.Replace ("_", "__"))
- {
- this.Source = source;
-
- Gdk.Pixbuf icon = source.Icon;
- if (icon != null)
- this.Image = new Gtk.Image (icon);
- }
- }
-
- internal class BrowseSource : ImportSource
- {
- public BrowseSource ()
- {
- this.Name = Catalog.GetString ("Select Folder");
- this.Icon = GtkUtil.TryLoadIcon (FSpot.Global.IconTheme, "stock_folder", 32, (Gtk.IconLookupFlags)0);
- }
-
- public BrowseSource (string name, string icon)
- {
- this.Name = name;
- this.Icon = GtkUtil.TryLoadIcon (FSpot.Global.IconTheme, icon, 32, (Gtk.IconLookupFlags)0);
- }
- }
-
- internal class VfsSource : ImportSource
- {
- public SafeUri uri;
-
- public VfsSource (SafeUri uri)
- {
- string [] components = uri.ToString ().Split ('/');
- this.Name = components [components.Length - 1];
- if (this.Name == String.Empty)
- this.Name = components [components.Length - 2];
-
- this.uri = uri;
-
- this.Icon = GtkUtil.TryLoadIcon (FSpot.Global.IconTheme, "stock_folder", 32, (Gtk.IconLookupFlags)0);
- }
-
- protected VfsSource () {}
- }
-
- internal class MountSource : VfsSource
- {
- public GLib.Mount Mount;
- public string mount_point;
-
- public MountSource (GLib.Mount mount)
- {
- this.Mount = mount;
- this.Name = mount.Name;
-
- try {
- mount_point = mount.Root.Uri;
- } catch (System.Exception e) {
- Hyena.Log.Exception (e);
- }
-
- uri = new SafeUri (mount.Root.Uri, true);
-
- /* FIXME: Camera identification!
-
- this.Name = String.Format ("{0} ({1})", cam.CameraList.GetName (index), cam.CameraList.GetValue (index));
-#else
- this.Name = String.Format ("{0}", cam.CameraList.GetName (index));
-#endif
- this.Icon = GtkUtil.TryLoadIcon (FSpot.Global.IconTheme, "camera-photo", 32, (Gtk.IconLookupFlags)0);
- if (this.Icon == null)
- this.Icon = GtkUtil.TryLoadIcon (FSpot.Global.IconTheme, "media-flash", 32, (Gtk.IconLookupFlags)0);
-
-
- */
-
- if (this.IsIPodPhoto)
- this.Icon = GtkUtil.TryLoadIcon (FSpot.Global.IconTheme, "multimedia-player", 32, (Gtk.IconLookupFlags)0);
-
- if (this.Icon == null && this.IsCamera)
- this.Icon = GtkUtil.TryLoadIcon (FSpot.Global.IconTheme, "media-flash", 32, (Gtk.IconLookupFlags)0);
-
- if (this.Icon == null) {
- if (mount.Icon is GLib.ThemedIcon) {
- this.Icon = GtkUtil.TryLoadIcon (FSpot.Global.IconTheme, (mount.Icon as GLib.ThemedIcon).Names, 32, (Gtk.IconLookupFlags)0);
- } else {
- // TODO
- throw new Exception ("Unloadable icon type");
- }
- }
- }
-
- private bool IsCamera {
- get {
- try {
- return (Directory.Exists (Path.Combine (mount_point, "DCIM")));
- } catch {
- return false;
- }
- }
- }
-
- private bool IsIPodPhoto {
- get {
- try {
- return (Directory.Exists (Path.Combine (mount_point, "Photos")) &&
- Directory.Exists (Path.Combine (mount_point, "iPod_Control")));
- } catch {
- return false;
- }
- }
- }
- }
-
- internal abstract class ImportSource {
- public Gdk.Pixbuf Icon;
- public string Name;
- }
-
- private class SourceMenu : Gtk.Menu
- {
- public int source_count;
- ImportCommand command;
-
- private static GLib.VolumeMonitor monitor = GLib.VolumeMonitor.Default;
-
- public SourceMenu (ImportCommand command) {
- this.command = command;
- source_count = 0;
-
- SourceItem item = new SourceItem (new BrowseSource ());
- item.Activated += HandleActivated;
- this.Append (item);
- this.Append (new Gtk.SeparatorMenuItem ());
-
- // Add external hard drives to the menu
- foreach (GLib.Mount mount in monitor.Mounts) {
- ImportSource source = new MountSource (mount);
- item = new SourceItem (source);
- item.Activated += HandleActivated;
- this.Append (item);
- source_count++;
- }
-
- this.ShowAll ();
- }
-
- private void HandleActivated (object sender, EventArgs args)
- {
- command.Source = (SourceItem) sender;
- command.ChangeSelection ();
- }
-
- public void HandleSourceSelectionChanged (object sender, EventArgs args)
- {
- SourceMenu sm = (sender as OptionMenu).Menu as SourceMenu;
- SourceItem source = sm.Active as SourceItem;
- if (source != command.Source) {
- command.Source = source;
- command.ChangeSelection ();
- }
- }
-
- public int SourceCount {
- get {
- return source_count;
- }
- }
-
- public int FindItemPosition (SourceItem source)
- {
- Gtk.Widget [] children = this.Children;
- for (int i = 0; i < children.Length; i++) {
- if (children [i] == source) {
- return i;
- }
- }
- return -1;
- }
-
- public int FindItemPosition (SafeUri uri)
- {
- Gtk.Widget [] children = this.Children;
- Hyena.Log.DebugFormat ("looking for {0}", uri);
- for (int i = 0; i < children.Length; i++) {
- if (children [i] is SourceItem) {
- VfsSource vfs = ((SourceItem)(children [i])).Source as VfsSource;
- if (vfs != null && (vfs.uri == uri || uri.ToString () == (vfs.uri + "/dcim")))
- return i;
- }
- }
- return -1;
- }
- }
[Glade.Widget] Gtk.HBox tagentry_box;
[Glade.Widget] Gtk.OptionMenu source_option_menu;
@@ -265,92 +40,6 @@ public class ImportCommand : GladeDialog
private SourceItem Source;
- public void ChangeSelection ()
- {
- if (store == null || collection == null)
- return;
-
- SourceItem item = Source;
-
- this.Cancel ();
- this.copy = copy_check.Active;
-
- // scrolling to top
- tray.ScrollTo (0);
-
- if (!item.Sensitive)
- return;
-
- if (item.Source is BrowseSource) {
- var uri = ChooseUri ();
-
- if (uri != null) {
- SourceItem uri_item = new SourceItem (new VfsSource (uri));
- menu.Prepend (uri_item);
- uri_item.ShowAll ();
- source_option_menu.SetHistory (0);
- ImportUri = uri;
- }
- } else if (item.Source is VfsSource) {
- VfsSource vfs = item.Source as VfsSource;
- ImportUri = vfs.uri;
- }
-
- idle_start.Start ();
- }
-
- public ImportCommand (Gtk.Window mw)
- {
- main_window = mw;
- step = new FSpot.Delay (new GLib.IdleHandler (Step));
- idle_start = new FSpot.Delay (new IdleHandler (Start));
- loading_string = Catalog.GetString ("Importing {0} of {1}");
- }
-
- private void HandleDialogResponse (object obj, ResponseArgs args)
- {
- if (args.ResponseId != ResponseType.Ok) {
- this.Cancel ();
- this.Dialog.Destroy ();
- return;
- }
-
- AllowFinish = false;
- OptionsEnabled = false;
- if (total > 0) {
- UpdateProgressBar (1, total);
- step.Start ();
-
- while (total > 0 && this.Step ()) {
- System.DateTime start_time = System.DateTime.Now;
- System.TimeSpan span = start_time - start_time;
-
- while (Application.EventsPending () && span.TotalMilliseconds < 100) {
- span = System.DateTime.Now - start_time;
- Application.RunIteration ();
- }
- }
- }
- }
-
- private void UpdateProgressBar (int count, int total)
- {
-/* if (progress_bar == null)
- return;
-
- if (count > 0)
- progress_bar.Show ();
- progress_bar.Text = String.Format (loading_string, count, total);
- progress_bar.Fraction = (double) count / System.Math.Max (total, 1);*/
- }
-
- private void HandleTraySelectionChanged (FSpot.IBrowsableCollection coll)
- {
-// if (tray.Selection.Count > 0)
-// photo_view.Item.Index = tray.Selection.Ids[0];
-
- }
-
private bool Step ()
{
StepStatusInfo status_info;
@@ -386,25 +75,6 @@ public class ImportCommand : GladeDialog
}
}
- public bool AllowFinish
- {
- set {
- if (ok_button != null)
- ok_button.Sensitive = value;
- }
- }
-
- public bool OptionsEnabled
- {
- set {
- if (source_option_menu != null) source_option_menu.Sensitive = value;
- if (copy_check != null) copy_check.Sensitive = value;
- if (recurse_check != null) recurse_check.Sensitive = value;
- if (duplicate_check != null) duplicate_check.Sensitive = value;
- if (tagentry_box != null) tagentry_box.Sensitive = value;
- }
- }
-
private int DoImport (ImportBackend imp)
{
if (collection == null)
@@ -434,75 +104,6 @@ public class ImportCommand : GladeDialog
return total;
}
-
- public void Finish ()
- {
- if (idle_start.IsPending || step.IsPending) {
- AllowFinish = false;
- return;
- }
-
- if (importer != null)
- importer.Finish ();
-
- importer = null;
- }
-
- void SavePreferences ()
- {
- Preferences.Set(Preferences.IMPORT_COPY_FILES, copy_check.Active);
- Preferences.Set(Preferences.IMPORT_INCLUDE_SUBFOLDERS, recurse_check.Active);
- Preferences.Set(Preferences.IMPORT_CHECK_DUPLICATES, duplicate_check.Active);
- }
-
- public SafeUri ChooseUri ()
- {
- SafeUri uri = null;
-
- FileChooserDialog file_chooser =
- new FileChooserDialog (Catalog.GetString ("Import"), this.Dialog,
- FileChooserAction.SelectFolder,
- Stock.Cancel, ResponseType.Cancel,
- Stock.Open, ResponseType.Ok);
-
- file_chooser.SelectMultiple = false;
- file_chooser.LocalOnly = false;
-
- if (ImportUri != null)
- file_chooser.SetCurrentFolderUri (ImportUri.ToString ());
- else
- file_chooser.SetFilename (FSpot.Global.HomeDirectory);
-
- int response = file_chooser.Run ();
-
- if ((ResponseType) response == ResponseType.Ok) {
- uri = new SafeUri (file_chooser.Uri, true);
- }
-
- file_chooser.Destroy ();
- return uri;
- }
-
- private void HandleRecurseToggled (object sender, System.EventArgs args)
- {
- this.Cancel ();
- this.Dialog.Sensitive = false;
-
- idle_start.Start ();
- }
-
- private void LoadPreferences ()
- {
- /* if (FSpot.Preferences.Get<int> (FSpot.Preferences.IMPORT_WINDOW_WIDTH) > 0)
- this.Dialog.Resize (FSpot.Preferences.Get<int> (FSpot.Preferences.IMPORT_WINDOW_WIDTH), FSpot.Preferences.Get<int> (FSpot.Preferences.IMPORT_WINDOW_HEIGHT));
-
- if (FSpot.Preferences.Get<int> (FSpot.Preferences.IMPORT_WINDOW_PANE_POSITION) > 0)
- import_hpaned.Position = FSpot.Preferences.Get<int> (FSpot.Preferences.IMPORT_WINDOW_PANE_POSITION);
-
- copy_check.Active = Preferences.Get<bool> (Preferences.IMPORT_COPY_FILES);
- recurse_check.Active = Preferences.Get<bool> (Preferences.IMPORT_INCLUDE_SUBFOLDERS);
- duplicate_check.Active = Preferences.Get<bool> (Preferences.IMPORT_CHECK_DUPLICATES);*/
- }
public int ImportFromUri (PhotoStore store, SafeUri uri)
{
@@ -662,109 +263,4 @@ public class ImportCommand : GladeDialog
tagnames.Add (t.Name);
tag_entry.UpdateFromTagNames ((string [])tagnames.ToArray(typeof(string)));
}
-
- public void Cancel ()
- {
- idle_start.Stop ();
- step.Stop ();
- if (importer != null) {
- importer.Cancel ();
- importer = null;
- }
- }
-
- private bool Start ()
- {
- if (Dialog != null)
- Dialog.Sensitive = true;
-
- if (ImportUri == null)
- return false;
-
- SafeUri [] uriimport = {ImportUri};
-
- if (copy_check != null)
- copy = copy_check.Active;
-
- bool recurse = true;
- if (recurse_check != null)
- recurse = recurse_check.Active;
-
- bool detect_duplicates = false;
- if (duplicate_check != null)
- detect_duplicates = duplicate_check.Active;
-
- importer = new FileImportBackend (store, uriimport, copy, recurse, detect_duplicates, null, Dialog);
-
- collection.Clear ();
- AllowFinish = false;
-
- var info = importer.Prepare ();
- total = info.Count;
-
- AllowFinish = true;
- collection.AddAll (info);
-
- if (collection.Count == 0)
- photo_view.Pixbuf = GtkUtil.TryLoadIcon (FSpot.Global.IconTheme, "f-spot", 128, (Gtk.IconLookupFlags)0);
-
- return false;
- }
-
- public int ImportFromUris (PhotoStore store, SafeUri [] uris, bool copy)
- {
- return ImportFromUris (store, uris, null, copy);
- }
-
- public int ImportFromUris (PhotoStore store, SafeUri [] uris, Tag [] tags)
- {
- return ImportFromUris (store, uris, tags, false);
- }
-
- public int ImportFromUris (PhotoStore store, SafeUri [] uris, Tag [] tags, bool copy)
- {
- collection = new FSpot.PhotoList (new Photo [0]);
- int count = DoImport (new FileImportBackend (store, uris, copy, true, tags, main_window ));
-
- Finish ();
-
- return count;
- }
}
-
-public class StepStatusInfo {
- private Photo photo;
- private int count;
- private bool is_duplicate;
-
- public Photo Photo {
- get {
- return photo;
- }
- }
-
- public int Count {
- get {
- return count;
- }
- }
-
- public bool IsDuplicate {
- get {
- return is_duplicate;
- }
- }
-
- public StepStatusInfo (Photo photo, int count, bool is_duplicate)
- {
- this.photo = photo;
- this.count = count;
- this.is_duplicate = is_duplicate;
- }
-
- public StepStatusInfo (Photo photo, int count)
- : this (photo, count, false)
- { }
-}
-
-
diff --git a/src/MainWindow.cs b/src/MainWindow.cs
index d2f393b..19944c6 100644
--- a/src/MainWindow.cs
+++ b/src/MainWindow.cs
@@ -289,7 +289,7 @@ namespace FSpot
toolbar_vbox.PackStart (toolbar);
ToolButton import_button = GtkUtil.ToolButtonFromTheme ("gtk-add", Catalog.GetString ("Import"), true);
- import_button.Clicked += HandleImportCommand;
+ import_button.Clicked += (o, args) => StartImport (null);
import_button.SetTooltip (ToolTips, Catalog.GetString ("Import new images"), null);
toolbar.Insert (import_button, -1);
@@ -1141,21 +1141,48 @@ namespace FSpot
public void ImportUriList (UriList list, bool copy)
{
- ImportCommand command = new ImportCommand (main_window);
- if (command.ImportFromUris (Database.Photos, list.ToArray (), copy) > 0) {
- query.RollSet = new RollSet (Database.Rolls.GetRolls (1)[0]);
- UpdateQuery ();
- }
+ var controller = new ImportController ();
+ controller.StatusEvent += (evnt) => {
+ ThreadAssist.ProxyToMain (() => {
+ if (evnt == ImportEvent.ImportFinished) {
+ if (controller.PhotosImported > 0) {
+ query.RollSet = new RollSet (controller.CreatedRoll);
+ UpdateQuery ();
+ }
+ }
+ });
+ };
+
+ var source = new MultiFileImportSource (list.ToArray ());
+ controller.ActiveSource = source;
+ controller.CopyFiles = copy;
+ controller.DuplicateDetect = true;
+ controller.RecurseSubdirectories = true;
+
+ var import_window = new ImportDialog (controller);
+ import_window.Show ();
+
+ controller.StartImport ();
}
public void ImportFile (SafeUri uri)
{
- // FIXME: disabled!
- //ImportCommand command = new ImportCommand (main_window);
- //if (command.ImportFromUri (Database.Photos, uri) > 0) {
- // query.RollSet = new RollSet (Database.Rolls.GetRolls (1)[0]);
- // UpdateQuery ();
- //}
+ StartImport (uri);
+ }
+
+ void StartImport (SafeUri uri)
+ {
+ var controller = new ImportController ();
+ controller.StatusEvent += (evnt) => {
+ if (evnt == ImportEvent.ImportFinished) {
+ if (controller.PhotosImported > 0) {
+ query.RollSet = new RollSet (controller.CreatedRoll);
+ UpdateQuery ();
+ }
+ }
+ };
+ var import_window = new ImportDialog (controller);
+ import_window.Show ();
}
void HandleIconViewDragDataReceived (object sender, DragDataReceivedArgs args)
@@ -1450,20 +1477,6 @@ namespace FSpot
// Main menu commands
//
- void HandleImportCommand (object sender, EventArgs e)
- {
- /*FIXMEDatabase.Sync = false;
- ImportCommand command = new ImportCommand (main_window);
- if (command.ImportFromUri (Database.Photos, null) > 0) {
- query.RollSet = new RollSet (Database.Rolls.GetRolls (1)[0]);
- UpdateQuery ();
- }
- Database.Sync = true; */
- var controller = new ImportController ();
- var import_window = new ImportDialog (controller);
- import_window.Show ();
- }
-
void HandlePageSetupActivated (object o, EventArgs e)
{
FSpot.Global.PageSetup = Print.RunPageSetupDialog (this.Window, FSpot.Global.PageSetup, null);
diff --git a/src/Makefile.am b/src/Makefile.am
index 8d48bb5..8d28799 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -56,7 +56,6 @@ SOURCES = \
Extensions/TransitionNode.cs \
Extensions/ViewModeCondition.cs \
Fader.cs \
- FileImportBackend.cs \
FileBrowsableItem.cs \
Filters/ChmodFilter.cs \
Filters/FilterRequest.cs \
@@ -80,8 +79,6 @@ SOURCES = \
Loaders/IImageLoader.cs \
Loaders/GdkImageLoader.cs \
ImageLoaderThread.cs \
- ImportBackend.cs \
- ImportCommand.cs \
Import/ImportController.cs \
Import/ImportSource.cs \
Import/FileImportSource.cs \
diff --git a/src/UI.Dialog/ImportDialog.cs b/src/UI.Dialog/ImportDialog.cs
index 4fee53b..41c11a4 100644
--- a/src/UI.Dialog/ImportDialog.cs
+++ b/src/UI.Dialog/ImportDialog.cs
@@ -180,7 +180,7 @@ namespace FSpot.UI.Dialog
file_chooser.Destroy ();
}
- void SwitchToFolderSource (SafeUri uri)
+ public void SwitchToFolderSource (SafeUri uri)
{
ImportSource source = null;
if (!history_sources.TryGetValue (uri, out source)) {
diff --git a/src/ui/main_window.ui b/src/ui/main_window.ui
index 2e12700..fe723dc 100644
--- a/src/ui/main_window.ui
+++ b/src/ui/main_window.ui
@@ -23,7 +23,6 @@
<property name="stock_id">gtk-add</property>
<property name="name">new1</property>
<property name="label" translatable="yes">_Import...</property>
- <signal handler="HandleImportCommand" name="activate"/>
</object>
<accelerator key="n" modifiers="GDK_CONTROL_MASK"/>
</child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]