[conduit/config-unstable] More work porting the FileModule to the new config system. Kind of works now



commit a6bb2b02059afa05473fc4eae9a27af4df407607
Author: John Stowers <john stowers gmail com>
Date:   Sat Apr 25 15:41:55 2009 +1200

    More work porting the FileModule to the new config system. Kind of works now
---
 conduit/modules/FileModule/FileConfiguration.py |   92 +++---
 conduit/modules/FileModule/FileModule.py        |   21 +-
 conduit/modules/FileModule/config.glade         |  369 -----------------------
 3 files changed, 66 insertions(+), 416 deletions(-)

diff --git a/conduit/modules/FileModule/FileConfiguration.py b/conduit/modules/FileModule/FileConfiguration.py
index 2f65974..15c0fb9 100644
--- a/conduit/modules/FileModule/FileConfiguration.py
+++ b/conduit/modules/FileModule/FileConfiguration.py
@@ -5,7 +5,6 @@ import logging
 log = logging.getLogger("modules.File")
 
 import conduit
-import conduit.utils as Utils
 import conduit.Vfs as Vfs
 import conduit.gtkui.Database as Database
 import conduit.dataproviders.File as FileDataProvider
@@ -30,45 +29,13 @@ class _FileSourceConfigurator(Vfs.FolderScannerThreadManager, Configurator.BaseC
         # FIXME: icon handling should be done better on Maemo
         pass        
 
-    def __init__(self, config_view, db, dp):
+    def __init__(self, dataprovider, configurator, db):
         Vfs.FolderScannerThreadManager.__init__(self)
-        Configurator.BaseConfigController.__init__(self)
-        self.tree = Utils.dataprovider_glade_get_widget(
-                        __file__,
-                        "config.glade",
-                        "FilesFrame"
-                        )
-        dic = { "on_addfile_clicked" : self.on_addfile_clicked,
-                "on_adddir_clicked" : self.on_adddir_clicked,
-                "on_remove_clicked" : self.on_remove_clicked,
-                None : None
-                }
-        self.tree.signal_autoconnect(dic)
+        Configurator.BaseConfigContainer.__init__(self, dataprovider, configurator)
         self.db = db
         self.tree_model = Database.GenericDBListStore("config", self.db)
-        self.dataprovider = dp
-
-        self._make_view()
-
-        #setup dnd onto the file list
-        targets = [ ( "text/uri-list", 0, 0 ) ]
-        f = self.tree.get_widget("filesscrolledwindow")
-        f.drag_dest_set(
-            gtk.DEST_DEFAULT_MOTION | gtk.DEST_DEFAULT_HIGHLIGHT | gtk.DEST_DEFAULT_DROP,
-            targets,
-            gtk.gdk.ACTION_COPY
-            )
-        f.connect("drag_data_received", self._dnd_data_get)
-
-        self.filesFrame = self.tree.get_widget("FilesFrame")
 
-        #self.dlg = self.tree.get_widget("FileSourceConfigDialog")
-
-        #connect to dialog response signal because we want to validate that
-        #the user has named all the groups before we let them quit
-        #self.dlg.connect("response",self.on_response)
-        #self.dlg.set_transient_for(self.mainWindow)
-        #self.dlg.show_all()
+        self._make_ui()
 
         #Now go an background scan some folders to populate the UI estimates.
         for oid,uri in self.db.select("SELECT oid,URI FROM config WHERE TYPE=? and SCAN_COMPLETE=?",(FileDataProvider.TYPE_FOLDER,False,)):
@@ -92,14 +59,53 @@ class _FileSourceConfigurator(Vfs.FolderScannerThreadManager, Configurator.BaseC
             except Exception, err:
                 log.debug("Error adding %s\n%s" % (uri,err))
 
-    def _make_view(self):
+    def _make_ui(self):
         """
-        Creates the treeview and connects the tree_model and appropriate
-        cell_data_funcs
+        Creates the ui
         """
-        #Config the treeview when the DP is used as a source
-        self.view = self.tree.get_widget("treeview1")
-        self.view.set_model( self.tree_model )
+        self.frame = gtk.Frame("Files and Folders to Synchronize")
+        self.frame.props.shadow_type = gtk.SHADOW_NONE
+
+        align = gtk.Alignment(0.5,0.5,1.0,1.0)
+        align.props.left_padding = 12
+        self.frame.add(align)
+
+        sw = gtk.ScrolledWindow()
+        sw.props.hscrollbar_policy = gtk.POLICY_AUTOMATIC 
+        sw.props.vscrollbar_policy = gtk.POLICY_AUTOMATIC 
+        sw.props.shadow_type= gtk.SHADOW_IN
+        #setup dnd onto the file list
+        sw.drag_dest_set(
+            gtk.DEST_DEFAULT_MOTION | gtk.DEST_DEFAULT_HIGHLIGHT | gtk.DEST_DEFAULT_DROP,
+            [ ( "text/uri-list", 0, 0 ) ],
+            gtk.gdk.ACTION_COPY
+            )
+        sw.connect("drag_data_received", self._dnd_data_get)
+
+        af = gtk.Button("_Add File")
+        af.set_image(gtk.image_new_from_stock(gtk.STOCK_ADD, gtk.ICON_SIZE_BUTTON))
+        af.connect("clicked", self.on_addfile_clicked)
+        ad = gtk.Button("Add _Directory")
+        ad.set_image(gtk.image_new_from_stock(gtk.STOCK_ADD, gtk.ICON_SIZE_BUTTON))
+        ad.connect("clicked", self.on_adddir_clicked)
+        r = gtk.Button(stock=gtk.STOCK_REMOVE)
+        r.connect("clicked", self.on_remove_clicked)
+
+        hbb = gtk.HButtonBox()
+        hbb.props.layout_style = gtk.BUTTONBOX_SPREAD
+        hbb.props.spacing = 3
+        hbb.add(af)
+        hbb.add(ad)
+        hbb.add(r)
+
+        vb = gtk.VBox()
+        vb.pack_start(sw, expand=True, fill=True)
+        vb.pack_end(hbb, expand=False, fill=True, padding=5)
+        align.add(vb)
+
+        self.view = gtk.TreeView(self.tree_model)
+        sw.add(self.view)
+
         #First column is an icon (folder of File)
         iconRenderer = gtk.CellRendererPixbuf()
         column1 = gtk.TreeViewColumn(_("Icon"), iconRenderer)
@@ -232,7 +238,7 @@ class _FileSourceConfigurator(Vfs.FolderScannerThreadManager, Configurator.BaseC
         pass
 
     def get_config_widget(self):
-        return self.filesFrame
+        return self.frame
 
     def hide(self):
         self.cancel_all_threads()
diff --git a/conduit/modules/FileModule/FileModule.py b/conduit/modules/FileModule/FileModule.py
index 1799f0b..efe552a 100644
--- a/conduit/modules/FileModule/FileModule.py
+++ b/conduit/modules/FileModule/FileModule.py
@@ -41,13 +41,26 @@ class FileSource(FileDataProvider.FileSource):
             folder, group = folder.split("---FIXME---")
             self._add_folder(folder, group)
 
-    def get_config_controller(self, config_view):
+    def get_config_container(self, configContainerKlass, name, icon, configurator):
         Utils.dataprovider_add_dir_to_path(__file__, "")
         import FileConfiguration
-        f = FileConfiguration._FileSourceConfigurator(config_view, self.db, self)
+        f = FileConfiguration._FileSourceConfigurator(self, configurator, self.db)
+
+        f.name = name
+        f.icon = icon
+        f.connect('apply', self.config_apply)
+        f.connect('cancel', self.config_cancel)
+        f.connect('show', self.config_show)
+        f.connect('hide', self.config_hide)
+
+        ##FIXME FIXME: This seems wrong. Under what configurators is this a bad
+        #idea. Perhaps the configurators api should be changed to 
+        #configurator.add_container()
+        #which first checks if a container is not allready added, before adding it
+        configurator.set_containers([f])
+
         return f
-        #response = f.show_dialog()
-    
+
     '''
     def set_configuration_(self, config):
         for f in config.get("files",[]):
diff --git a/conduit/modules/FileModule/config.glade b/conduit/modules/FileModule/config.glade
deleted file mode 100644
index 2301d94..0000000
--- a/conduit/modules/FileModule/config.glade
+++ /dev/null
@@ -1,369 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
-<!--*- mode: xml -*-->
-<glade-interface>
-  <widget class="GtkDialog" id="FileSourceConfigDialog">
-    <property name="visible">True</property>
-    <property name="border_width">5</property>
-    <property name="title" translatable="yes">File Configuration</property>
-    <property name="resizable">False</property>
-    <property name="window_position">GTK_WIN_POS_CENTER</property>
-    <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
-    <property name="gravity">GDK_GRAVITY_CENTER</property>
-    <property name="has_separator">False</property>
-    <child internal-child="vbox">
-      <widget class="GtkVBox" id="vbox35">
-        <property name="visible">True</property>
-        <property name="spacing">5</property>
-        <child>
-          <widget class="GtkFrame" id="frame7">
-            <property name="visible">True</property>
-            <property name="label_xalign">0</property>
-            <property name="shadow_type">GTK_SHADOW_NONE</property>
-            <child>
-              <widget class="GtkAlignment" id="alignment15">
-                <property name="visible">True</property>
-                <property name="left_padding">12</property>
-                <child>
-                  <widget class="GtkVBox" id="vbox36">
-                    <property name="visible">True</property>
-                    <child>
-                      <widget class="GtkScrolledWindow" id="filesscrolledwindow">
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
-                        <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
-                        <property name="shadow_type">GTK_SHADOW_IN</property>
-                        <child>
-                          <widget class="GtkTreeView" id="treeview1">
-                            <property name="height_request">200</property>
-                            <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="border_width">2</property>
-                            <property name="headers_visible">False</property>
-                            <property name="enable_search">False</property>
-                          </widget>
-                        </child>
-                      </widget>
-                    </child>
-                    <child>
-                      <widget class="GtkHButtonBox" id="hbuttonbox15">
-                        <property name="visible">True</property>
-                        <property name="spacing">3</property>
-                        <property name="layout_style">GTK_BUTTONBOX_SPREAD</property>
-                        <child>
-                          <widget class="GtkButton" id="button39">
-                            <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="can_default">True</property>
-                            <property name="response_id">0</property>
-                            <signal name="clicked" handler="on_addfile_clicked"/>
-                            <child>
-                              <widget class="GtkAlignment" id="alignment16">
-                                <property name="visible">True</property>
-                                <property name="xscale">0</property>
-                                <property name="yscale">0</property>
-                                <child>
-                                  <widget class="GtkHBox" id="hbox21">
-                                    <property name="visible">True</property>
-                                    <property name="spacing">2</property>
-                                    <child>
-                                      <widget class="GtkImage" id="image74">
-                                        <property name="visible">True</property>
-                                        <property name="stock">gtk-add</property>
-                                      </widget>
-                                      <packing>
-                                        <property name="expand">False</property>
-                                        <property name="fill">False</property>
-                                      </packing>
-                                    </child>
-                                    <child>
-                                      <widget class="GtkLabel" id="label79">
-                                        <property name="visible">True</property>
-                                        <property name="label" translatable="yes">Add File</property>
-                                        <property name="use_underline">True</property>
-                                      </widget>
-                                      <packing>
-                                        <property name="expand">False</property>
-                                        <property name="fill">False</property>
-                                        <property name="position">1</property>
-                                      </packing>
-                                    </child>
-                                  </widget>
-                                </child>
-                              </widget>
-                            </child>
-                          </widget>
-                        </child>
-                        <child>
-                          <widget class="GtkButton" id="button40">
-                            <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="can_default">True</property>
-                            <property name="response_id">0</property>
-                            <signal name="clicked" handler="on_adddir_clicked"/>
-                            <child>
-                              <widget class="GtkAlignment" id="alignment17">
-                                <property name="visible">True</property>
-                                <property name="xscale">0</property>
-                                <property name="yscale">0</property>
-                                <child>
-                                  <widget class="GtkHBox" id="hbox22">
-                                    <property name="visible">True</property>
-                                    <property name="spacing">2</property>
-                                    <child>
-                                      <widget class="GtkImage" id="image75">
-                                        <property name="visible">True</property>
-                                        <property name="stock">gtk-add</property>
-                                      </widget>
-                                      <packing>
-                                        <property name="expand">False</property>
-                                        <property name="fill">False</property>
-                                      </packing>
-                                    </child>
-                                    <child>
-                                      <widget class="GtkLabel" id="label80">
-                                        <property name="visible">True</property>
-                                        <property name="label" translatable="yes">Add Directory</property>
-                                        <property name="use_underline">True</property>
-                                      </widget>
-                                      <packing>
-                                        <property name="expand">False</property>
-                                        <property name="fill">False</property>
-                                        <property name="position">1</property>
-                                      </packing>
-                                    </child>
-                                  </widget>
-                                </child>
-                              </widget>
-                            </child>
-                          </widget>
-                          <packing>
-                            <property name="position">1</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <widget class="GtkButton" id="button41">
-                            <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="can_default">True</property>
-                            <property name="label">gtk-remove</property>
-                            <property name="use_stock">True</property>
-                            <property name="response_id">0</property>
-                            <signal name="clicked" handler="on_remove_clicked"/>
-                          </widget>
-                          <packing>
-                            <property name="position">2</property>
-                          </packing>
-                        </child>
-                      </widget>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="padding">5</property>
-                        <property name="pack_type">GTK_PACK_END</property>
-                        <property name="position">1</property>
-                      </packing>
-                    </child>
-                  </widget>
-                </child>
-              </widget>
-            </child>
-            <child>
-              <widget class="GtkLabel" id="label81">
-                <property name="visible">True</property>
-                <property name="label" translatable="yes">&lt;b&gt;Items to Synchronize&lt;/b&gt;</property>
-                <property name="use_markup">True</property>
-              </widget>
-              <packing>
-                <property name="type">label_item</property>
-              </packing>
-            </child>
-          </widget>
-          <packing>
-            <property name="position">1</property>
-          </packing>
-        </child>
-        <child internal-child="action_area">
-          <widget class="GtkHButtonBox" id="hbuttonbox14">
-            <property name="visible">True</property>
-            <property name="layout_style">GTK_BUTTONBOX_END</property>
-            <child>
-              <widget class="GtkButton" id="button37">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="label">gtk-cancel</property>
-                <property name="use_stock">True</property>
-                <property name="response_id">-6</property>
-              </widget>
-            </child>
-            <child>
-              <widget class="GtkButton" id="button38">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="label">gtk-ok</property>
-                <property name="use_stock">True</property>
-                <property name="response_id">-5</property>
-              </widget>
-              <packing>
-                <property name="position">1</property>
-              </packing>
-            </child>
-          </widget>
-          <packing>
-            <property name="expand">False</property>
-            <property name="pack_type">GTK_PACK_END</property>
-          </packing>
-        </child>
-      </widget>
-    </child>
-  </widget>
-  <widget class="GtkDialog" id="FolderTwoWayConfigDialog">
-    <property name="visible">True</property>
-    <property name="title" translatable="yes">Folder Configuration</property>
-    <property name="resizable">False</property>
-    <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
-    <child internal-child="vbox">
-      <widget class="GtkVBox" id="dialog-vbox1">
-        <property name="visible">True</property>
-        <property name="spacing">5</property>
-        <child>
-          <widget class="GtkVBox" id="vbox37">
-            <property name="visible">True</property>
-            <property name="spacing">5</property>
-            <child>
-              <widget class="GtkLabel" id="label83">
-                <property name="visible">True</property>
-                <property name="xalign">0</property>
-                <property name="label" translatable="yes">Folder Location:</property>
-              </widget>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-              </packing>
-            </child>
-            <child>
-              <widget class="GtkFileChooserButton" id="filechooserbutton1">
-                <property name="visible">True</property>
-                <property name="local_only">False</property>
-                <property name="action">GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER</property>
-                <property name="title" translatable="yes">Select A Folder</property>
-              </widget>
-              <packing>
-                <property name="position">1</property>
-              </packing>
-            </child>
-            <child>
-              <widget class="GtkExpander" id="expander1">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <child>
-                  <widget class="GtkVBox" id="vbox38">
-                    <property name="visible">True</property>
-                    <child>
-                      <widget class="GtkCheckButton" id="hidden">
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="label" translatable="yes">Include Hidden Files</property>
-                        <property name="use_underline">True</property>
-                        <property name="response_id">0</property>
-                        <property name="draw_indicator">True</property>
-                      </widget>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">False</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <widget class="GtkCheckButton" id="ignoreMtime">
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="label" translatable="yes">Ignore File Modification Times</property>
-                        <property name="use_underline">True</property>
-                        <property name="response_id">0</property>
-                        <property name="draw_indicator">True</property>
-                      </widget>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">False</property>
-                        <property name="position">1</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <widget class="GtkCheckButton" id="followSymlinks">
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="label" translatable="yes">Follow Symbolic Links</property>
-                        <property name="use_underline">True</property>
-                        <property name="response_id">0</property>
-                        <property name="draw_indicator">True</property>
-                      </widget>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">False</property>
-                        <property name="position">2</property>
-                      </packing>
-                    </child>
-                  </widget>
-                </child>
-                <child>
-                  <widget class="GtkLabel" id="label85">
-                    <property name="visible">True</property>
-                    <property name="label" translatable="yes">Advanced</property>
-                  </widget>
-                  <packing>
-                    <property name="type">label_item</property>
-                  </packing>
-                </child>
-              </widget>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">2</property>
-              </packing>
-            </child>
-          </widget>
-          <packing>
-            <property name="expand">False</property>
-            <property name="padding">5</property>
-            <property name="position">2</property>
-          </packing>
-        </child>
-        <child internal-child="action_area">
-          <widget class="GtkHButtonBox" id="dialog-action_area1">
-            <property name="visible">True</property>
-            <property name="layout_style">GTK_BUTTONBOX_END</property>
-            <child>
-              <widget class="GtkButton" id="cancelbutton1">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="label">gtk-cancel</property>
-                <property name="use_stock">True</property>
-                <property name="response_id">-6</property>
-              </widget>
-            </child>
-            <child>
-              <widget class="GtkButton" id="okbutton1">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="label">gtk-ok</property>
-                <property name="use_stock">True</property>
-                <property name="response_id">-5</property>
-              </widget>
-              <packing>
-                <property name="position">1</property>
-              </packing>
-            </child>
-          </widget>
-          <packing>
-            <property name="expand">False</property>
-            <property name="pack_type">GTK_PACK_END</property>
-          </packing>
-        </child>
-      </widget>
-    </child>
-  </widget>
-</glade-interface>



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