[guillomovitch feat] allow that deletion also deletes orig files
authorgc <gc>
Sun, 18 Sep 2005 19:36:06 +0000 (19:36 +0000)
committergc <gc>
Sun, 18 Sep 2005 19:36:06 +0000 (19:36 +0000)
bin/booh

index b828e11f6f1914784a78852302290fd039b89e83..6cc4b466ca96259c7021a81a2d2fae770fb2370e 100755 (executable)
--- a/bin/booh
+++ b/bin/booh
@@ -103,6 +103,7 @@ def read_config
     end
 
     $tempfiles = []
+    $todelete = []
 end
 
 def write_config
@@ -710,9 +711,10 @@ def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
 
     img = nil
     frame1 = Gtk::Frame.new
+    fullpath = from_utf8("#{$current_path}/#{filename}")
 
     my_gen_real_thumbnail = proc {
-        gen_real_thumbnail('element', from_utf8("#{$current_path}/#{filename}"), thumbnail_img, $xmldir, $default_size['thumbnails'], img, '')
+        gen_real_thumbnail('element', fullpath, thumbnail_img, $xmldir, $default_size['thumbnails'], img, '')
     }
 
     #- generate the thumbnail if missing (if image was rotated but booh was not relaunched)
@@ -726,7 +728,7 @@ def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
 
     tooltips = Gtk::Tooltips.new
     tipname = from_utf8(File.basename(filename).gsub(/\.[^\.]+$/, ''))
-    tooltips.set_tip(evtbox, utf8(type == 'video' ? (_("%s (video - %s KB)") % [tipname, commify(file_size(from_utf8("#{$current_path}/#{filename}"))/1024)]) : tipname), nil)
+    tooltips.set_tip(evtbox, utf8(type == 'video' ? (_("%s (video - %s KB)") % [tipname, commify(file_size(fullpath)/1024)]) : tipname), nil)
 
     frame2, textview = create_editzone($autotable_sw, 1, img)
     textview.buffer.text = utf8(caption)
@@ -835,11 +837,11 @@ def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
     }
 
     whitebalance_and_cleanup = Proc.new {
-        if values = ask_whitebalance(from_utf8("#{$current_path}/#{filename}"), thumbnail_img, img,
+        if values = ask_whitebalance(fullpath, thumbnail_img, img,
                                      $xmldir.elements["*[@filename='#{filename}']"], '', $default_thumbnails[:x], $default_thumbnails[:y], '')
             perform_change_whitebalance_and_cleanup = Proc.new { |val|
                 change_whitebalance($xmldir.elements["*[@filename='#{filename}']"], '', val)
-                recalc_whitebalance(val, from_utf8("#{$current_path}/#{filename}"), thumbnail_img, img,
+                recalc_whitebalance(val, fullpath, thumbnail_img, img,
                                     $xmldir.elements["*[@filename='#{filename}']"], '', $default_thumbnails[:x], $default_thumbnails[:y], '')
                 cleanup_all_thumbnails.call
             }
@@ -885,7 +887,7 @@ def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
                   })
     }
 
-    delete = Proc.new {
+    delete = Proc.new { |isacut|
         if autotable.current_order.size > 1 || show_popup($main_window, utf8(_("Do you confirm this subalbum needs to be completely removed?")), { :okcancel => true })
             $modified = true
             after = nil
@@ -894,6 +896,10 @@ def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
                 if !after
                     after = autotable.get_previous_widget(vbox)
                 end
+                if $config['deleteondisk'] && !isacut
+                    msg 3, "scheduling for delete: #{fullpath}"
+                    $todelete << fullpath
+                end
                 autotable.remove(vbox)
                 if after
                     $vbox2widgets[after][:textview].grab_focus
@@ -929,6 +935,8 @@ def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
                               $notebook.set_page(1)
                               autotable.queue_draws << proc { textview.grab_focus; autoscroll_if_needed($autotable_sw, img, textview) }
                               $cuts = []
+                              msg 3, "removing deletion schedule of: #{fullpath}"
+                              $todelete.delete(fullpath)  #- unconditional because deleteondisk option could have been modified
                               Proc.new {
                                   perform_delete.call
                                   $notebook.set_page(1)
@@ -939,7 +947,7 @@ def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
     }
 
     cut = Proc.new {
-        delete.call
+        delete.call(true)
         $cuts << { :vbox => vbox, :filename => filename }
         $statusbar.push(0, utf8(_("%s elements in the clipboard.") % $cuts.size ))
     }
@@ -1317,6 +1325,11 @@ def save_current_file_user
     $modified = false
     $generated_outofline = false
     $filename = save_tempfilename
+
+    msg 3, "performing actual deletion of: " + $todelete.join(', ')
+    $todelete.each { |f|
+        system("rm -f #{f}")
+    }
 end
 
 def mark_document_as_dirty
@@ -1371,6 +1384,7 @@ def ask_save_modifications(msg1, msg2, *options)
             if response == Gtk::Dialog::RESPONSE_CANCEL
                 ret = false
             end
+            $todelete = []  #- unconditionally clear the list of images/videos to delete
         }
     end
     return ret
@@ -2650,6 +2664,9 @@ def preferences
     tbl.attach(emptycomments_check = Gtk::CheckButton.new(utf8(_("Use empty comments for new albums"))),
                0, 2, 3, 4, Gtk::FILL, Gtk::SHRINK, 2, 2)
     tooltips.set_tip(emptycomments_check, utf8(_("Normally, filenames are used as comments for new albums. Check this if you prefer empty comments.")), nil)
+    tbl.attach(deleteondisk_check = Gtk::CheckButton.new(utf8(_("Delete original images/videos as well"))),
+               0, 2, 4, 5, Gtk::FILL, Gtk::SHRINK, 2, 2)
+    tooltips.set_tip(deleteondisk_check, utf8(_("Normally, deleting an image or video in booh only removes it from the web-album. If you check this option, the original file in source directory will be removed as well. Undo is possible, since actual deletion is performed only when web-album is saved.")), nil)
     smp_check.signal_connect('toggled') {
         if smp_check.active?
             smp_hbox.sensitive = true
@@ -2663,6 +2680,7 @@ def preferences
     end
     nogestures_check.active = $config['nogestures']
     emptycomments_check.active = $config['emptycomments']
+    deleteondisk_check.active = $config['deleteondisk']
 
     notebook.append_page(tbl = Gtk::Table.new(0, 0, false), Gtk::Label.new(utf8(_("Advanced"))))
     tbl.attach(Gtk::Label.new.set_markup(utf8(_("Options to pass to <i>convert</i> when\nperforming 'enhance contrast': "))),
@@ -2681,6 +2699,7 @@ def preferences
             end
             $config['nogestures'] = nogestures_check.active?
             $config['emptycomments'] = emptycomments_check.active?
+            $config['deleteondisk'] = deleteondisk_check.active?
 
             $config['convert-enhance'] = enhance_entry.text
         end