[conduit] Port FolderTwoWay to the new config system



commit 15c2c380e3ed462cd15dd7f288c7db7e408b3729
Author: John Stowers <john stowers gmail com>
Date:   Sat Apr 25 13:21:39 2009 +1200

    Port FolderTwoWay to the new config system
    
    Remove obsolete FolderConfigurator, update the filebutton
    ConfigItem to use URIs instead of filenames, and port
    FolderTwoWay to config_setup
---
 conduit/gtkui/ConfigItems.py                    |   21 +++++++--
 conduit/modules/FileModule/FileConfiguration.py |   39 -----------------
 conduit/modules/FileModule/FileModule.py        |   53 ++++++++++-------------
 3 files changed, 39 insertions(+), 74 deletions(-)

diff --git a/conduit/gtkui/ConfigItems.py b/conduit/gtkui/ConfigItems.py
index 4df5c1e..d996553 100644
--- a/conduit/gtkui/ConfigItems.py
+++ b/conduit/gtkui/ConfigItems.py
@@ -14,6 +14,8 @@ log = logging.getLogger("gtkui.Config")
 
 from gettext import gettext as _
 
+import conduit.Vfs as Vfs
+
 class Error(Exception):
     """Base exception for all exceptions raised in this module."""
     pass
@@ -474,15 +476,24 @@ class ConfigFileButton(ItemBase):
     def __init__(self, *args, **kwargs):
         self.directory = kwargs.pop('directory', False)
         ItemBase.__init__(self, *args, **kwargs)
-        self._current_filename = None
+        self._current_uri = None
     
     def _selection_changed(self, filechooser):
-        if self._current_filename != filechooser.get_filename():
-            self._current_filename = filechooser.get_filename()
+        uri = filechooser.get_uri()
+        #if in folder mode, and no directory is selected, then
+        #default to the current directory. This hack was necessary in some
+        #old pygtk version, I am not sure if it is still required, as the
+        #filechooser seems to behave better now
+        if self.directory and not uri:
+            uri = filechooser.get_current_folder_uri()
+
+        if uri and self._current_uri != uri:
+            self._current_uri = uri
             self._value_changed()            
     
     def _build_widget(self):
         self.widget = gtk.FileChooserButton(self.title)
+        self.widget.props.local_only = not Vfs.backend_supports_remote_uri_schemes()
         self.widget.connect("selection-changed", self._selection_changed)
         if self.directory:
             self.widget.set_action(gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER)
@@ -490,10 +501,10 @@ class ConfigFileButton(ItemBase):
             self.widget.set_action(gtk.FILE_CHOOSER_ACTION_OPEN)
     
     def _set_value(self, value):
-        self.widget.set_filename(str(value))
+        self.widget.set_uri(str(value))
     
     def _get_value(self):
-        return self._current_filename
+        return self._current_uri
 
 class ConfigRadio(ItemBase):
     __item_name__ = 'radio'
diff --git a/conduit/modules/FileModule/FileConfiguration.py b/conduit/modules/FileModule/FileConfiguration.py
index 636f62c..8a96204 100644
--- a/conduit/modules/FileModule/FileConfiguration.py
+++ b/conduit/modules/FileModule/FileConfiguration.py
@@ -301,42 +301,3 @@ class _FileSourceConfigurator(Vfs.FolderScannerThreadManager):
                 warning.destroy()
                 dialog.emit_stop_by_name("response")
 
-class _FolderTwoWayConfigurator:
-    def __init__(self, mainWindow, folder, includeHidden, compareIgnoreMtime, followSymlinks):
-        log.debug("Starting new folder chooser at %s" % folder)
-        self.folder = folder
-        self.includeHidden = includeHidden
-        self.compareIgnoreMtime = compareIgnoreMtime
-        self.followSymlinks = followSymlinks
-
-        tree = Utils.dataprovider_glade_get_widget(
-                        __file__, 
-                        "config.glade",
-						"FolderTwoWayConfigDialog"
-						)
-        self.folderChooser = tree.get_widget("filechooserbutton1")
-        self.folderChooser.set_current_folder_uri(self.folder)
-        self.hiddenCb = tree.get_widget("hidden")
-        self.hiddenCb.set_active(includeHidden)
-        self.mtimeCb = tree.get_widget("ignoreMtime")
-        self.mtimeCb.set_active(self.compareIgnoreMtime)
-        self.followSymlinksCb = tree.get_widget("followSymlinks")
-        self.followSymlinksCb.set_active(self.followSymlinks)
-
-        self.dlg = tree.get_widget("FolderTwoWayConfigDialog")
-        self.dlg.connect("response",self.on_response)
-        self.dlg.set_transient_for(mainWindow)
-
-    def on_response(self, dialog, response_id):
-        if response_id == gtk.RESPONSE_OK:
-            self.folder = self.folderChooser.get_uri()
-            log.debug("Folderconfig returned %s" % self.folder)
-            self.includeHidden = self.hiddenCb.get_active()
-            self.compareIgnoreMtime = self.mtimeCb.get_active()
-            self.followSymlinks = self.followSymlinksCb.get_active() 
-
-    def show_dialog(self):
-        self.dlg.show_all()
-        self.dlg.run()
-        self.dlg.destroy()
-        return self.folder, self.includeHidden, self.compareIgnoreMtime, self.followSymlinks
diff --git a/conduit/modules/FileModule/FileModule.py b/conduit/modules/FileModule/FileModule.py
index 3b76b6f..d9894ab 100644
--- a/conduit/modules/FileModule/FileModule.py
+++ b/conduit/modules/FileModule/FileModule.py
@@ -79,48 +79,41 @@ class FolderTwoWay(FileDataProvider.FolderTwoWay, AutoSync.AutoSync):
                 self.DEFAULT_FOLLOW_SYMLINKS
                 )
         AutoSync.AutoSync.__init__(self)
+
         self._monitor = Vfs.FileMonitor()
         self._monitor.connect("changed", self._monitor_folder_cb)
 
+        self.update_configuration(
+            folder = (self.DEFAULT_FOLDER, self._set_folder, lambda: self.folder),
+            includeHidden = self.DEFAULT_HIDDEN,
+            compareIgnoreMtime = self.DEFAULT_COMPARE_IGNORE_MTIME,
+            followSymlinks = self.DEFAULT_FOLLOW_SYMLINKS
+        )
+
     def __del__(self):
         self._monitor.cancel()
-            
-    def configure(self, window):
-        Utils.dataprovider_add_dir_to_path(__file__, "")
-        import FileConfiguration
-        f = FileConfiguration._FolderTwoWayConfigurator(
-                                    window,
-                                    self.folder,
-                                    self.includeHidden,
-                                    self.compareIgnoreMtime,
-                                    self.followSymlinks)
-        self.folder, self.includeHidden, self.compareIgnoreMtime, self.followSymlinks = f.show_dialog()
-        self._monitor_folder()
-        
-    def set_configuration(self, config):
-        self.folder = config.get("folder", self.DEFAULT_FOLDER)
-        self.includeHidden = config.get("includeHidden", self.DEFAULT_HIDDEN)
-        self.compareIgnoreMtime = config.get("compareIgnoreMtime", self.DEFAULT_COMPARE_IGNORE_MTIME)
-        self.followSymlinks = config.get("followSymlinks", self.DEFAULT_FOLLOW_SYMLINKS)        
-        self._monitor_folder()
-
-    def get_configuration(self):
-        return {
-            "folder" : self.folder,
-            "includeHidden" : self.includeHidden,
-            "compareIgnoreMtime" : self.compareIgnoreMtime,
-            "followSymlinks" : self.followSymlinks
-            }
 
+    def _set_folder(self, f):
+        log.debug("Setting folder: %s" % f)
+        self.folder = f
+        self._monitor.add(f, self._monitor.MONITOR_DIRECTORY)
+
+    def config_setup(self, config):
+        config.add_item("Select folder", "filebutton", order = 1,
+            config_name = "folder",
+            directory = True,
+        )
+        config.add_section("Advanced")
+        config.add_item("Include hidden files", "check", config_name = "includeHidden")
+        config.add_item("Ignore file modification times", 'check', config_name = "compareIgnoreMtime")
+        config.add_item("Follow symbolic links", 'check', config_name = "followSymlinks")
+            
     def get_UID(self):
         return self.folder
         
     def get_name(self):
         return Vfs.uri_get_filename(self.folder)
 
-    def _monitor_folder(self):
-        self._monitor.add(self.folder, self._monitor.MONITOR_DIRECTORY)
-
     def _monitor_folder_cb(self, sender, event_uri, event):
         """
         Called when a file in the current folder is changed, added or deleted



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