[f-spot] Add "remove from camera" option.



commit 6d17f97e936f65f2dbcb488575a42edef012e01b
Author: Ruben Vermeersch <ruben savanne be>
Date:   Tue Jul 13 16:56:19 2010 +0200

    Add "remove from camera" option.
    
    With an educating warning that you should not do that.

 src/Import/ImportController.cs |   24 ++++++++++++++++++-
 src/Preferences.cs             |    2 +
 src/UI.Dialog/ImportDialog.cs  |   21 ++++++++++++++++-
 src/ui/import.ui               |   48 +++++++++++++++++++++++++++++++++++++++-
 4 files changed, 91 insertions(+), 4 deletions(-)
---
diff --git a/src/Import/ImportController.cs b/src/Import/ImportController.cs
index 950ec9a..9aa072a 100644
--- a/src/Import/ImportController.cs
+++ b/src/Import/ImportController.cs
@@ -34,6 +34,7 @@ namespace FSpot.Import
 #region Import Preferences
 
         private bool copy_files;
+        private bool remove_originals;
         private bool recurse_subdirectories;
         private bool duplicate_detect;
 
@@ -42,6 +43,11 @@ namespace FSpot.Import
             set { copy_files = value; SavePreferences (); }
         }
 
+        public bool RemoveOriginals {
+            get { return remove_originals; }
+            set { remove_originals = value; SavePreferences (); }
+        }
+
         public bool RecurseSubdirectories {
             get { return recurse_subdirectories; }
             set { recurse_subdirectories = value; SavePreferences (); RescanPhotos (); }
@@ -57,6 +63,7 @@ namespace FSpot.Import
             copy_files = Preferences.Get<bool> (Preferences.IMPORT_COPY_FILES);
             recurse_subdirectories = Preferences.Get<bool> (Preferences.IMPORT_INCLUDE_SUBFOLDERS);
             duplicate_detect = Preferences.Get<bool> (Preferences.IMPORT_CHECK_DUPLICATES);
+            remove_originals = Preferences.Get<bool> (Preferences.IMPORT_REMOVE_ORIGINALS);
         }
 
         void SavePreferences ()
@@ -64,6 +71,7 @@ namespace FSpot.Import
             Preferences.Set(Preferences.IMPORT_COPY_FILES, copy_files);
             Preferences.Set(Preferences.IMPORT_INCLUDE_SUBFOLDERS, recurse_subdirectories);
             Preferences.Set(Preferences.IMPORT_CHECK_DUPLICATES, duplicate_detect);
+            Preferences.Set(Preferences.IMPORT_REMOVE_ORIGINALS, remove_originals);
         }
 
 #endregion
@@ -200,6 +208,7 @@ namespace FSpot.Import
         Stack<SafeUri> created_directories;
         List<uint> imported_photos;
         List<SafeUri> copied_files;
+        List<SafeUri> original_files;
         PhotoStore store = App.Instance.Database.Photos;
         RollStore rolls = App.Instance.Database.Rolls;
         volatile bool photo_scan_running;
@@ -217,6 +226,7 @@ namespace FSpot.Import
             created_directories = new Stack<SafeUri> ();
             imported_photos = new List<uint> ();
             copied_files = new List<SafeUri> ();
+            original_files = new List<SafeUri> ();
             metadata_importer = new MetadataImporter ();
             CreatedRoll = rolls.Create ();
 
@@ -260,6 +270,13 @@ namespace FSpot.Import
 
         void FinishImport ()
         {
+            if (RemoveOriginals) {
+                foreach (var uri in original_files) {
+                    var file = GLib.FileFactory.NewForUri (uri);
+                    file.Delete (null);
+                }
+            }
+
             ImportThread = null;
             FireEvent (ImportEvent.ImportFinished);
         }
@@ -290,7 +307,7 @@ namespace FSpot.Import
             metadata_importer.Cancel();
 
             // Remove created roll
-		    rolls.Remove (CreatedRoll);
+            rolls.Remove (CreatedRoll);
         }
 
         void ImportPhoto (IBrowsableItem item, Roll roll)
@@ -339,15 +356,18 @@ namespace FSpot.Import
             var new_file = GLib.FileFactory.NewForUri (destination);
             file.Copy (new_file, GLib.FileCopyFlags.AllMetadata, null, null);
             copied_files.Add (destination);
+            original_files.Add (item.DefaultVersion.Uri);
             item.DefaultVersion.Uri = destination;
 
             // Copy XMP sidecar
-            var xmp_file = GLib.FileFactory.NewForUri (item.DefaultVersion.Uri.ReplaceExtension(".xmp"));
+            var xmp_original = item.DefaultVersion.Uri.ReplaceExtension(".xmp");
+            var xmp_file = GLib.FileFactory.NewForUri (xmp_original);
             if (xmp_file.Exists) {
                 var xmp_destination = destination.ReplaceExtension (".xmp");
                 var new_xmp_file = GLib.FileFactory.NewForUri (xmp_destination);
                 xmp_file.Copy (new_xmp_file, GLib.FileCopyFlags.AllMetadata, null, null);
                 copied_files.Add (xmp_destination);
+                original_files.Add (xmp_original);
             }
         }
 
diff --git a/src/Preferences.cs b/src/Preferences.cs
index 8d7d5d1..795c6fe 100644
--- a/src/Preferences.cs
+++ b/src/Preferences.cs
@@ -28,6 +28,7 @@ namespace FSpot
 		public const string IMPORT_COPY_FILES = "/apps/f-spot/import/copy_files";
 		public const string IMPORT_INCLUDE_SUBFOLDERS = "/apps/f-spot/import/include_subfolders";
 		public const string IMPORT_CHECK_DUPLICATES = "/apps/f-spot/import/check_duplicates";
+		public const string IMPORT_REMOVE_ORIGINALS = "/apps/f-spot/import/remove_originals";
 		
 		public const string VIEWER_WIDTH = APP_FSPOT + "ui/viewer_width";
 		public const string VIEWER_HEIGHT = APP_FSPOT + "ui/viewer_height";
@@ -118,6 +119,7 @@ namespace FSpot
 			case METADATA_ALWAYS_USE_SIDECAR:
 			case MAIN_WINDOW_MAXIMIZED:
 			case GROUP_ADAPTOR_ORDER_ASC:
+			case IMPORT_REMOVE_ORIGINALS:
 				return false;
 
 			case GLASS_POSITION:
diff --git a/src/UI.Dialog/ImportDialog.cs b/src/UI.Dialog/ImportDialog.cs
index e46fb5d..e59ca96 100644
--- a/src/UI.Dialog/ImportDialog.cs
+++ b/src/UI.Dialog/ImportDialog.cs
@@ -23,6 +23,8 @@ namespace FSpot.UI.Dialog
         [GtkBeans.Builder.Object] CheckButton copy_check;
         [GtkBeans.Builder.Object] CheckButton duplicate_check;
         [GtkBeans.Builder.Object] CheckButton recurse_check;
+        [GtkBeans.Builder.Object] CheckButton remove_check;
+        [GtkBeans.Builder.Object] Button remove_warning_button;
         [GtkBeans.Builder.Object] ComboBox sources_combo;
         [GtkBeans.Builder.Object] HBox tagentry_box;
         [GtkBeans.Builder.Object] HPaned import_hpaned;
@@ -94,6 +96,9 @@ namespace FSpot.UI.Dialog
             copy_check.Active = Controller.CopyFiles;
             recurse_check.Active = Controller.RecurseSubdirectories;
             duplicate_check.Active = Controller.DuplicateDetect;
+            remove_check.Active = Controller.RemoveOriginals;
+            remove_check.Sensitive = copy_check.Active;
+            remove_warning_button.Sensitive = copy_check.Active;
         }
 
         void ScanSources ()
@@ -153,11 +158,25 @@ namespace FSpot.UI.Dialog
         {
             Controller.StatusEvent += OnControllerStatusEvent;
             Controller.ProgressUpdated += OnControllerProgressUpdated;
-            copy_check.Toggled += (o, args) => { Controller.CopyFiles = copy_check.Active; };
+            copy_check.Toggled += (o, args) => {
+                Controller.CopyFiles = copy_check.Active;
+                remove_check.Sensitive = copy_check.Active;
+                remove_warning_button.Sensitive = copy_check.Active;
+            };
             recurse_check.Toggled += (o, args) => { Controller.RecurseSubdirectories = recurse_check.Active; };
             duplicate_check.Toggled += (o, args) => { Controller.DuplicateDetect = duplicate_check.Active; };
+            remove_check.Toggled += (o, args) => { Controller.RemoveOriginals = remove_check.Active; };
             import_button.Clicked += (o, args) => StartImport ();
             cancel_button.Clicked += (o, args) => CancelImport ();
+            remove_warning_button.Clicked += (o, args) => {
+                var dialog = new MessageDialog (this, DialogFlags.Modal, MessageType.Warning, ButtonsType.Ok, true,
+                        Catalog.GetString ("Checking this box will remove the imported photos from the camera after the import finished successfully.\n\nIt is generally recommended to backup your photos before removing them from the camera. <b>Use this option at your own risk!</b>"));
+                dialog.Title = Catalog.GetString ("Warning");
+                dialog.Response += (s, arg) => {
+                    dialog.Destroy ();
+                };
+                dialog.Run ();
+            };
             Response += (o, args) => {
                 if (args.ResponseId == ResponseType.DeleteEvent) {
                     CancelImport ();
diff --git a/src/ui/import.ui b/src/ui/import.ui
index e46f071..49ff912 100644
--- a/src/ui/import.ui
+++ b/src/ui/import.ui
@@ -199,7 +199,53 @@
                   </packing>
                 </child>
                 <child>
-                  <placeholder/>
+                  <object class="GtkHBox" id="hbox2">
+                    <property name="visible">True</property>
+                    <property name="spacing">2</property>
+                    <child>
+                      <object class="GtkCheckButton" id="remove_check">
+                        <property name="label" translatable="yes">Remove original files after import</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="draw_indicator">True</property>
+                      </object>
+                      <packing>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkAlignment" id="alignment1">
+                        <property name="visible">True</property>
+                        <property name="xalign">1</property>
+                        <child>
+                          <object class="GtkButton" id="remove_warning_button">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">True</property>
+                            <child>
+                              <object class="GtkImage" id="image1">
+                                <property name="visible">True</property>
+                                <property name="stock">gtk-dialog-warning</property>
+                                <property name="icon-size">1</property>
+                              </object>
+                            </child>
+                          </object>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <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>
+                  </packing>
                 </child>
               </object>
               <packing>



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