XML document object can be accessed directly by $xmldoc, need to synchronize that...
authorGuillaume Cottenceau <gcottenc@gmail.com>
Wed, 2 Jul 2008 08:29:17 +0000 (10:29 +0200)
committerGuillaume Cottenceau <gcottenc@gmail.com>
Wed, 2 Jul 2008 08:29:17 +0000 (10:29 +0200)
bin/booh
lib/booh/Synchronizator.rb

index b9c62ff..29bed57 100755 (executable)
--- a/bin/booh
+++ b/bin/booh
@@ -49,6 +49,7 @@ $options = [
 
 #- default values for some globals 
 $xmldir = nil
+$xmlaccesslock = Object.new
 $modified = false
 $current_cursor = nil
 $ignore_videos = false
@@ -97,7 +98,7 @@ def read_config
     $config = {}
     $config_file = File.expand_path('~/.booh-gui-rc')
     if File.readable?($config_file)
-        $xmldoc = REXML::Document.new(File.new($config_file))
+        $xmldoc = Synchronizator.new(REXML::Document.new(File.new($config_file)), $xmlaccesslock)
         $xmldoc.root.elements.each { |element|
             txt = element.get_text
             if txt
@@ -188,7 +189,7 @@ def write_config
         $config['last-opens'] = $config['last-opens'][-10, 10]
     end
 
-    $xmldoc = Document.new "<booh-gui-rc version='#{$VERSION}'/>"
+    $xmldoc = Synchronizator.new(Document.new("<booh-gui-rc version='#{$VERSION}'/>"), $xmlaccesslock)
     $xmldoc << XMLDecl.new(XMLDecl::DEFAULT_VERSION, $CURRENT_CHARSET)
     $config.each_pair { |key, value|
         elem = $xmldoc.root.add_element key
@@ -1859,7 +1860,7 @@ def ask_save_modifications(msg1, msg2, *options)
                 #- already-generated markers in original file
                 if $generated_outofline
                     begin
-                        $xmldoc = REXML::Document.new File.new($orig_filename)
+                        $xmldoc = Synchronizator.new(REXML::Document.new(File.new($orig_filename)), $xmlaccesslock)
                         mark_document_as_dirty
                         ios = File.open($orig_filename, "w")
                         $xmldoc.write(ios, 0)
@@ -2326,7 +2327,7 @@ def change_dir
     $subalbums = Gtk::Table.new(0, 0, true)
     current_y_sub_albums = 0
 
-    $xmldir = Synchronizator.new($xmldoc.elements["//dir[@path='#{$current_path}']"])
+    $xmldir = Synchronizator.new($xmldoc.elements["//dir[@path='#{$current_path}']"], $xmlaccesslock)
     $subalbums_edits = {}
     subalbums_counter = 0
     subalbums_edits_bypos = {}
@@ -2830,7 +2831,7 @@ def open_file(filename)
     end
 
     begin
-        $xmldoc = REXML::Document.new File.new(filename)
+        $xmldoc = Synchronizator.new(REXML::Document.new(File.new(filename)), $xmlaccesslock)
     rescue Exception
         $xmldoc = nil
     end
index 3226301..35bd115 100644 (file)
@@ -41,12 +41,13 @@ class ObjectWrapper
 end
 
 class Synchronizator < ObjectWrapper
-    def initialize(wrapped_object)
-        super
-        @__wrapped_object.extend(MonitorMixin)
+    def initialize(wrapped_object, monitor_object)
+        super(wrapped_object)
+        @__monitor_object = monitor_object
+        @__monitor_object.extend(MonitorMixin)
     end
     def __wrap(id, *args, &block)
-        @__wrapped_object.synchronize {
+        @__monitor_object.synchronize {
             super(id, *args, &block)
         }
     end