remember deleted elements to not merge them back when using "merge new/removed images...
authorgc <gc>
Sun, 12 Jun 2005 13:34:04 +0000 (13:34 +0000)
committergc <gc>
Sun, 12 Jun 2005 13:34:04 +0000 (13:34 +0000)
bin/booh
bin/booh-backend
lib/booh/booh-lib.rb

index 7cb580ffe5b6ef4551b07f5d99bd68938d30b1d4..79bb17e9bd39ceea1ac308e502c5d2166e658825 100755 (executable)
--- a/bin/booh
+++ b/bin/booh
@@ -798,7 +798,7 @@ def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
                     $xmldir.delete_attribute('thumbnails-caption')
                     $xmldir.delete_attribute('thumbnails-captionfile')
                 else
-                    $xmldir.remove
+                    $xmldir.add_attribute('deleted', 'true')
                 end
                 save_changes('forced')
                 populate_subalbums_treeview
@@ -1200,44 +1200,48 @@ def save_changes(*forced)
 
     $xmldir.delete_attribute('already-generated')
 
-    if $xmldir.elements['dir']
+    if $xmldir.child_byname_notattr('dir', 'deleted')
         $xmldir.add_attribute('subdirs-caption', $subalbums_title.buffer.text)
         $xmldir.elements.each('dir') { |element|
-            path = element.attributes['path']
-            if element.attributes['subdirs-caption']
-                element.add_attribute('subdirs-caption',     $subalbums_edits[path][:editzone].buffer.text)
-                element.add_attribute('subdirs-captionfile', utf8($subalbums_edits[path][:captionfile]))
-            else
-                element.add_attribute('thumbnails-caption',     $subalbums_edits[path][:editzone].buffer.text)
-                element.add_attribute('thumbnails-captionfile', utf8($subalbums_edits[path][:captionfile]))
+            if !element.attributes['deleted']
+                path = element.attributes['path']
+                if element.attributes['subdirs-caption']
+                    element.add_attribute('subdirs-caption',     $subalbums_edits[path][:editzone].buffer.text)
+                    element.add_attribute('subdirs-captionfile', utf8($subalbums_edits[path][:captionfile]))
+                else
+                    element.add_attribute('thumbnails-caption',     $subalbums_edits[path][:editzone].buffer.text)
+                    element.add_attribute('thumbnails-captionfile', utf8($subalbums_edits[path][:captionfile]))
+                end
             end
         }
     end
 
-    if $notebook.page == 0 && $xmldir.elements['dir']
+    if $notebook.page == 0 && $xmldir.child_byname_notattr('dir', 'deleted')
         if $xmldir.attributes['thumbnails-caption']
             path = $xmldir.attributes['path']
             $xmldir.add_attribute('thumbnails-caption', $subalbums_edits[path][:editzone].buffer.text)
         end
-    else
+    elsif $xmldir.attributes['thumbnails-caption']
         $xmldir.add_attribute('thumbnails-caption', $thumbnails_title.buffer.text)
     end
 
     #- remove and reinsert elements to reflect new ordering
-    save_attributes = {}
-    save_types = {}
+    saves = {}
     cpt = 0
     $xmldir.elements.each { |element|
         if element.name == 'image' || element.name == 'video'
-            save_types[element.attributes['filename']] = element.name
-            save_attributes[element.attributes['filename']] = element.attributes
-            element.remove
+            saves[element.attributes['filename']] = element.remove
             cpt += 1
         end
     }
     $autotable.current_order.each { |path|
-        chld = $xmldir.add_element save_types[path], save_attributes[path]
+        chld = $xmldir.add_element(saves[path].name, saves[path].attributes)
         chld.add_attribute('caption', $name2widgets[File.basename(path)][:textview].buffer.text)
+        saves.delete(path)
+    }
+    saves.each_key { |path|
+        chld = $xmldir.add_element(saves[path].name, saves[path].attributes)
+        chld.add_attribute('deleted', 'true')
     }
 end
 
@@ -1539,7 +1543,7 @@ def change_dir
         current_y_sub_albums += 1
     }
 
-    if $xmldir.elements['dir']
+    if $xmldir.child_byname_notattr('dir', 'deleted')
         #- title edition
         frame, $subalbums_title = create_editzone($subalbums_sw, 0, nil)
         $subalbums_title.buffer.text = $xmldir.attributes['subdirs-caption']
@@ -1551,13 +1555,13 @@ def change_dir
         end
     end
     $xmldir.elements.each { |element|
-        if element.name == 'image' || element.name == 'video'
+        if (element.name == 'image' || element.name == 'video') && !element.attributes['deleted']
             #- element (image or video) of this album
             dest_img = build_full_dest_filename(element.attributes['filename']).sub(/\.[^\.]+$/, '') + "-#{$default_size['thumbnails']}.jpg"
             msg 3, "dest_img: #{dest_img}"
             add_thumbnail($autotable, element.attributes['filename'], element.name, dest_img, from_utf8(element.attributes['caption']))
         end
-        if element.name == 'dir'
+        if element.name == 'dir' && !element.attributes['deleted']
             #- sub-album image/caption
             add_subalbum.call(element, subalbums_counter += 1)
         end
@@ -1565,7 +1569,7 @@ def change_dir
     $subalbums_vb.add($subalbums)
     $subalbums_vb.show_all
 
-    if !$xmldir.elements['image'] && !$xmldir.elements['video']
+    if !$xmldir.child_byname_notattr('image', 'deleted') && !$xmldir.child_byname_notattr('video', 'deleted')
         $notebook.get_tab_label($autotable_sw).sensitive = false
         $notebook.set_page(0)
         $thumbnails_title.buffer.text = ''
@@ -1574,7 +1578,7 @@ def change_dir
         $thumbnails_title.buffer.text = $xmldir.attributes['thumbnails-caption']
     end
 
-    if !$xmldir.elements['dir']
+    if !$xmldir.child_byname_notattr('dir', 'deleted')
         $notebook.get_tab_label($subalbums_sw).sensitive = false
         $notebook.set_page(1)
     else
@@ -1646,22 +1650,24 @@ def populate_subalbums_treeview
     source = $xmldoc.root.attributes['source']
     msg 3, "source: #{source}"
 
-    xmldir = $xmldoc.elements["//dir[@path='#{source}']"]
-    if !xmldir
+    xmldir = $xmldoc.elements['//dir']
+    if !xmldir || xmldir.attributes['path'] != source
         msg 1, _("Corrupted booh file...")
         return
     end
 
-    append_dir_elem = Proc.new { |parent_iter, location|
+    append_dir_elem = Proc.new { |parent_iter, xmldir|
         child_iter = $albums_ts.append(parent_iter)
-        child_iter[0] = File.basename(location)
-        child_iter[1] = location
-        msg 3, "puttin location: #{location}"
-        $xmldoc.elements.each("//dir[@path='#{location}']/dir") { |elem|
-            append_dir_elem.call(child_iter, elem.attributes['path'])
+        child_iter[0] = File.basename(xmldir.attributes['path'])
+        child_iter[1] = xmldir.attributes['path']
+        msg 3, "puttin location: #{xmldir.attributes['path']}"
+        xmldir.elements.each('dir') { |elem|
+            if !elem.attributes['deleted']
+                append_dir_elem.call(child_iter, elem)
+            end
         }
     }
-    append_dir_elem.call(nil, source)
+    append_dir_elem.call(nil, xmldir)
 
     $albums_tv.expand_all
     $albums_tv.selection.select_iter($albums_ts.iter_first)
@@ -1724,7 +1730,7 @@ def open_file(filename)
     if $config['last-opens'][-1] != utf8(filename)
         $config['last-opens'] << utf8(filename)
     end
-    $save.sensitive = $save_as.sensitive = $merge_current.sensitive = $merge.sensitive = $merge_subalbums.sensitive = $generate.sensitive = $properties.sensitive = $remove_all_captions.sensitive = true
+    $save.sensitive = $save_as.sensitive = $merge_current.sensitive = $merge.sensitive = $generate.sensitive = $properties.sensitive = $remove_all_captions.sensitive = true
     return nil
 end
 
@@ -2129,16 +2135,6 @@ def merge
                  { :closure_after => proc { open_file($filename) } })
 end
 
-def merge_subalbums
-    save_current_file
-
-    call_backend("booh-backend --merge-config-newdirs '#{$filename}' --for-gui " +
-                 "--verbose-level #{$verbose_level} #{additional_booh_options}",
-                 utf8(_("Please wait while scanning source directory...")),
-                 'full scan',
-                 { :closure_after => proc { open_file($filename) } })
-end
-
 def save_as_do
     fc = Gtk::FileChooserDialog.new(utf8(_("Select a new filename to store this album's properties")),
                                     nil,
@@ -2226,9 +2222,6 @@ def create_menu_and_toolbar
     filesubmenu.append($merge_current = Gtk::ImageMenuItem.new(utf8(_("Merge new/removed images/videos in current subalbum"))).set_sensitive(false))
     $merge_current.image = Gtk::Image.new("#{$FPATH}/images/stock-reset-16.png")
     tooltips.set_tip($merge_current, utf8(_("Take into account new/removed images/videos in currently viewed subalbum")), nil)
-    filesubmenu.append($merge_subalbums = Gtk::ImageMenuItem.new(utf8(_("Scan source directory to merge new subalbums"))).set_sensitive(false))
-    $merge_subalbums.image = Gtk::Image.new("#{$FPATH}/images/stock-reset-16.png")
-    tooltips.set_tip($merge_subalbums, utf8(_("Take into account new/removed subalbums (subdirectories) in the source directory (but don't touch existing subalbums)")), nil)
     filesubmenu.append($merge    = Gtk::ImageMenuItem.new(utf8(_("Scan source directory to merge new subalbums and new/removed images/videos"))).set_sensitive(false))
     $merge.image = Gtk::Image.new("#{$FPATH}/images/stock-reset-16.png")
     tooltips.set_tip($merge, utf8(_("Take into account new/removed subalbums (subdirectories) and new/removed images/videos in existing subalbums")), nil)
@@ -2250,7 +2243,6 @@ def create_menu_and_toolbar
     $save_as.signal_connect('activate') { save_as_do }
     $merge_current.signal_connect('activate') { merge_current }
     $merge.signal_connect('activate') { merge }
-    $merge_subalbums.signal_connect('activate') { merge_subalbums }
     $generate.signal_connect('activate') {
         save_current_file
         call_backend("booh-backend --config '#{$filename}' --verbose-level #{$verbose_level} #{additional_booh_options}",
index 819375c39a82f499c0273ce52e42d66ce62150c8..1c1ced82620bb2a4ceb6aa9d09be3a3dac554dde 100755 (executable)
@@ -46,7 +46,6 @@ $options = [
     [ '--config',        '-C', GetoptLong::REQUIRED_ARGUMENT, _("File containing config listing images and videos within directories with captions") ],
     [ '--config-skel',   '-k', GetoptLong::REQUIRED_ARGUMENT, _("Filename where the script will output a config skeleton") ],
     [ '--merge-config',  '-M', GetoptLong::REQUIRED_ARGUMENT, _("File containing config listing, where to merge new images/videos from --source, and change theme info") ],
-    [ '--merge-config-newdirs', '-N', GetoptLong::REQUIRED_ARGUMENT, _("File containing config listing, where to merge new subdirs from --source") ],
     [ '--merge-config-onedir',  '-O', GetoptLong::REQUIRED_ARGUMENT, _("File containing config listing, for merging the subdir specified with --dir") ],
     [ '--dir',           '-D', GetoptLong::REQUIRED_ARGUMENT, _("Directory for merge with --merge-config-onedir") ],
     [ '--use-config',    '-u', GetoptLong::REQUIRED_ARGUMENT, _("File containing config listing, where to change theme info") ],
@@ -140,17 +139,6 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") %
                 else
                     die _('Config file does not exist or is unreadable.')
                 end
-            when '--merge-config-newdirs'
-                arg = File.expand_path(arg)
-                if File.readable?(arg)
-                    msg 2, _("Merge config notice: backuping current config file to %s.backup") % arg
-                    $xmldoc = REXML::Document.new File.new(arg)
-                    File.rename(arg, "#{arg}.backup")
-                    $config_writeto = arg
-                    $mode = 'merge_config_newdirs'
-                else
-                    die _('Config file does not exist or is unreadable.')
-                end
             when '--merge-config-onedir'
                 arg = File.expand_path(arg)
                 if File.readable?(arg)
@@ -446,7 +434,7 @@ def find_previous_album(xmldir)
                 return nil
             end
         end
-    end while !xmldir.elements['image'] && !xmldir.elements['video']
+    end while !xmldir.child_byname_notattr('image', 'deleted') && !xmldir.child_byname_notattr('video', 'deleted')
     return File.reduce_path(relative_pos)
 end
 
@@ -474,7 +462,7 @@ def find_next_album(xmldir)
                 return nil
             end
         end
-    end while !xmldir.elements['image'] && !xmldir.elements['video']
+    end while !xmldir.child_byname_notattr('image', 'deleted') && !xmldir.child_byname_notattr('video', 'deleted')
     return File.reduce_path(relative_pos)
 end
 
@@ -519,17 +507,15 @@ def walk_source_dir
         end
 
         #- place xml document on proper node if exists, else create
-        newly_created_dir = false
         xmldir = optxpath[utf8(dir)]
         if $mode == 'use_config' || $mode == 'use_config_changetheme'
-            if !xmldir || (xmldir.attributes['already-generated'] && !$force)
+            if !xmldir || (xmldir.attributes['already-generated'] && !$force) || xmldir.attributes['deleted']
                 info("walking: #{dir}, 0 elements")
                 next
             end
         else
-            if $mode == 'gen_config' || (($mode == 'merge_config' || $mode == 'merge_config_newdirs') && !xmldir)
+            if $mode == 'gen_config' || ($mode == 'merge_config' && !xmldir)
                 #- add the <dir..> element if necessary
-                newly_created_dir = true
                 parent = File.dirname(dir)
                 xmldir = $xmldoc.elements["//dir[@path='#{utf8(parent)}']"]
                 if !xmldir
@@ -542,10 +528,10 @@ def walk_source_dir
 
         #- read images/videos entries from config or from directories depending on mode
         entries = []
-        if $mode == 'use_config' || $mode == 'use_config_changetheme' || ($mode == 'merge_config_newdirs' && !newly_created_dir)
+        if $mode == 'use_config' || $mode == 'use_config_changetheme'
             msg 2, _("Handling %s from config list...") % dir
             xmldir.elements.each { |element|
-                if %w(image video).include?(element.name)
+                if %w(image video).include?(element.name) && !element.attributes['deleted']
                     entries << from_utf8(element.attributes['filename'])
                 end
             }
@@ -793,7 +779,7 @@ def walk_source_dir
                         element.add_attribute('subdirs-captionfile', captionfile)
                     end
                 end
-                if element.elements['image'] || element.elements['video']
+                if element.child_byname_notattr('image', 'deleted') || element.child_byname_notattr('video', 'deleted')
                     if !element.attributes['thumbnails-caption']
                         element.add_attribute('thumbnails-caption', basename)
                     end
@@ -902,7 +888,7 @@ def walk_source_dir
         ios.close
 
         #- substitute "return to albums" and previous/next correctly
-        if xmldir.elements['image'] || xmldir.elements['video']
+        if xmldir.child_byname_notattr('image', 'deleted') || xmldir.child_byname_notattr('video', 'deleted')
             for sizeobj in $images_size
                 substInFile("#{dest_dir}/thumbnails-#{sizeobj['name']}.html") { |line|
                     sub_previous_next_album(previous_album, next_album, line)
index ab7b5639f92a7c963749d2a5287aa44b87aee7f9..df2d7d2fccdf8233e1263cb19ccfcc6bb0e6e734 100644 (file)
@@ -412,6 +412,15 @@ class REXML::Element
         end
         return nil
     end
+
+    def child_byname_notattr(name, attr)
+        elements.each(name) { |element|
+            if !element.attributes[attr]
+                return element
+            end
+        }
+        return nil
+    end
 end