[sabayon] Remove hard coded names from Details pane sort function SORTPRIORITY must be set in each source cons



commit 070885b04ccf7bc42e3e4f0fa44744e2b92433e2
Author: Warren Togami <wtogami redhat com>
Date:   Thu Feb 4 21:53:55 2010 -0500

    Remove hard coded names from Details pane sort function
    SORTPRIORITY must be set in each source constructor.  Lower numbers appear before
    higher numbers in the Details pane view.

 admin-tool/editorwindow.py   |   43 +++++++++++++++--------------------------
 lib/sources/filessource.py   |    1 +
 lib/sources/gconfsource.py   |    1 +
 lib/sources/mozillasource.py |    1 +
 lib/sources/paneldelegate.py |    1 +
 lib/sources/testsource.py    |    1 +
 lib/userprofile.py           |    2 +
 7 files changed, 23 insertions(+), 27 deletions(-)
---
diff --git a/admin-tool/editorwindow.py b/admin-tool/editorwindow.py
index 2523554..b6c7f6b 100755
--- a/admin-tool/editorwindow.py
+++ b/admin-tool/editorwindow.py
@@ -58,11 +58,12 @@ class ProfileModel (gtk.ListStore):
     (
         COLUMN_SOURCE,
         COLUMN_PATH,
-        COLUMN_DESCRIPTION
-    ) = range (3)
+        COLUMN_DESCRIPTION,
+        COLUMN_SORTPRIORITY
+    ) = range (4)
 
     def __init__ (self, profile):
-        gtk.ListStore.__init__ (self, str, str, str)
+        gtk.ListStore.__init__ (self, str, str, str, int)
 
         self.profile = profile
         self.reload ()
@@ -75,15 +76,17 @@ class ProfileModel (gtk.ListStore):
             if source is None:
                 source = self.profile.get_delegate (source_name)
             
-            dprint ("  source %s, path %s, description %s",
+            dprint ("  source %s, path %s, description %s, sortpriority %d",
                     source_name,
                     path,
-                    source.get_path_description (path))
+                    source.get_path_description (path),
+                    source.SORTPRIORITY)
             
             self.set (self.prepend (),
                       self.COLUMN_SOURCE,          source_name,
                       self.COLUMN_PATH,            path,
-                      self.COLUMN_DESCRIPTION,     source.get_path_description (path))
+                      self.COLUMN_DESCRIPTION,     source.get_path_description (path),
+                      self.COLUMN_SORTPRIORITY,       source.SORTPRIORITY)
 
 
 class ProfileEditorWindow:
@@ -225,35 +228,21 @@ class ProfileEditorWindow:
     # Sort by Source then alphabetically
     # Generally this means GConf and other app specific prefs are listed before files
     def __pref_object_sort_func (self, model, iter1, iter2):
-        source1 = model.get_value (iter1, ProfileModel.COLUMN_SOURCE)
-        source2 = model.get_value (iter2, ProfileModel.COLUMN_SOURCE)
-        path1   = model.get_value (iter1, ProfileModel.COLUMN_PATH)
-        path2   = model.get_value (iter2, ProfileModel.COLUMN_PATH)
-
-        # FIXME: Add priority integer to source modules to get rid of hardcoded priorities here
-        # This is temporarily hard-coded here to make the change self-contained and easy to understand.
-        def __source_to_priority (source):
-            if source == "GConf":
-                return 10
-            if source == "Firefox":
-                return 90
-            if source == "Files":
-                return 255
-            return 500
-
-        priority1 = __source_to_priority(source1)
-        priority2 = __source_to_priority(source2)
+        sortprio1 = model.get_value (iter1, ProfileModel.COLUMN_SORTPRIORITY)
+        sortprio2 = model.get_value (iter2, ProfileModel.COLUMN_SORTPRIORITY)
+        path1      = model.get_value (iter1, ProfileModel.COLUMN_PATH)
+        path2      = model.get_value (iter2, ProfileModel.COLUMN_PATH)
         
-        if priority1 < priority2:
+        if sortprio1 < sortprio2:
             return -1
-        if priority1 == priority2:
+        if sortprio1 == sortprio2:
             if path1 < path2:
                 return -1
             if path1 == path2:
                 return 0
             if path1 > path2:
                 return 1
-        if priority1 > priority2:
+        if sortprio1 > sortprio2:
             return 1
 
     def __setup_treeview (self):
diff --git a/lib/sources/filessource.py b/lib/sources/filessource.py
index 8d9ab33..f4e8e98 100755
--- a/lib/sources/filessource.py
+++ b/lib/sources/filessource.py
@@ -90,6 +90,7 @@ class FilesSource (userprofile.ProfileSource):
                                                     self.__handle_monitor_event)
         self.monitor.set_directories_to_ignore (DIRECTORIES_TO_IGNORE)
         self.monitor.set_files_to_ignore (FILES_TO_IGNORE)
+        self.SORTPRIORITY = 500
 
     def __handle_monitor_event (self, path, event):
         if event == dirmonitor.DELETED or os.path.isfile (path) or os.path.isdir (path):
diff --git a/lib/sources/gconfsource.py b/lib/sources/gconfsource.py
index 5a88985..cc3758d 100755
--- a/lib/sources/gconfsource.py
+++ b/lib/sources/gconfsource.py
@@ -131,6 +131,7 @@ class GConfSource (userprofile.ProfileSource):
         self.mandatory_client     = None
         self.mandatory_alt_client = None
         self.enforce_mandatory    = True
+        self.SORTPRIORITY         = 10
 
     def get_path_description (self, path):
         if path == GCONF_DEFAULTS_SOURCE:
diff --git a/lib/sources/mozillasource.py b/lib/sources/mozillasource.py
index 5f037a9..75945ba 100644
--- a/lib/sources/mozillasource.py
+++ b/lib/sources/mozillasource.py
@@ -152,6 +152,7 @@ class MozillaDelegate(userprofile.SourceDelegate):
         self.committed_bookmarks = mozilla_bookmarks.BookmarkFolder("Null", None)
         self.committed_mandatory_bookmarks = mozilla_bookmarks.BookmarkFolder("Null", None)
         self.ini_file = None
+        self.SORTPRIORITY = 50
 
     def get_full_path(self, path):
         return os.path.join(self.home_dir, path)        
diff --git a/lib/sources/paneldelegate.py b/lib/sources/paneldelegate.py
index 8aa15cc..20f8a10 100755
--- a/lib/sources/paneldelegate.py
+++ b/lib/sources/paneldelegate.py
@@ -181,6 +181,7 @@ class PanelDelegate (userprofile.SourceDelegate):
             self.added        = added
             self.removed      = removed
             self.gconf_client = self.delegate.get_gconf_client ()
+            self.SORTPRIORITY = 60
     
         def _copy_tree (self, dir):
             if not self.gconf_client.dir_exists(dir):
diff --git a/lib/sources/testsource.py b/lib/sources/testsource.py
index 37c5bac..6ac48cf 100755
--- a/lib/sources/testsource.py
+++ b/lib/sources/testsource.py
@@ -51,6 +51,7 @@ class TestSource (userprofile.ProfileSource):
     def __init__ (self, storage):
         userprofile.ProfileSource.__init__ (self, "test", "get_test_delegate")
         self.storage = storage
+        self.SORTPRIORITY = 75
 
     def commit_change (self, change):
         pass
diff --git a/lib/userprofile.py b/lib/userprofile.py
index cf0c0e3..4308874 100755
--- a/lib/userprofile.py
+++ b/lib/userprofile.py
@@ -229,6 +229,8 @@ class ProfileSource (gobject.GObject):
         self.delegates = []
         if delegate_constructor:
             self.delegates = module_loader.construct_objects (delegate_constructor, self)
+        # Set the priority level for sorting in Details view, lower numbers appear first
+        self.SORTPRIORITY = 1000
     
     def get_delegate (self, delegate_name):
         """Return a delegate named @delegate_name."""



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