[pitivi] preferences: Classify plugins in System and User plugins



commit 37c14c159a7614bee0c1933aaa05dba10af49aeb
Author: Fabian Orccon <cfoch fabian gmail com>
Date:   Tue Aug 29 17:48:41 2017 +0200

    preferences: Classify plugins in System and User plugins
    
    Summary: Depends on D1853
    
    Reviewers: thiblahute, aleb
    
    Reviewed By: aleb
    
    Maniphest Tasks: T3193
    
    Differential Revision: https://phabricator.freedesktop.org/D1841

 pitivi/dialogs/prefs.py |   50 +++++++++++++++++++++++++++++-----------------
 pitivi/pluginmanager.py |   20 ++++++++++++++++++
 2 files changed, 51 insertions(+), 19 deletions(-)
---
diff --git a/pitivi/dialogs/prefs.py b/pitivi/dialogs/prefs.py
index 04abe86..6f78983 100644
--- a/pitivi/dialogs/prefs.py
+++ b/pitivi/dialogs/prefs.py
@@ -30,6 +30,7 @@ from gi.repository import Gtk
 from gi.repository import Peas
 
 from pitivi.configure import get_ui_dir
+from pitivi.pluginmanager import PluginManager
 from pitivi.settings import GlobalSettings
 from pitivi.utils import widgets
 from pitivi.utils.loggable import Loggable
@@ -673,7 +674,11 @@ class PluginManagerStore(Gio.ListStore):
 
     def reload(self):
         self.remove_all()
-        for plugin_info in self.app.plugin_manager.engine.get_plugin_list():
+        plugins = self.app.plugin_manager.engine.get_plugin_list()
+        # Firstly, sort the plugins according the number assigned to the
+        # pluginmanager.PluginType object. Secondly, sort alphabetically.
+        for plugin_info in sorted(plugins,
+                                  key=lambda x: (PluginManager.get_plugin_type(x), x.get_name())):
             item = PluginItem(self.app, plugin_info)
             self.append(item)
 
@@ -746,24 +751,31 @@ class PluginsBox(Gtk.ListBox):
 
     def _add_header_func(self, row, before, unused_user_data):
         """Adds a header for a new section in the model."""
-        if row.get_index() == 0:
-            header = Gtk.Label()
-            header.set_use_markup(True)
-
-            group_title = _("Plugins")
-            header.set_markup("<b>%s</b>" % group_title)
-            header.props.margin_top = PADDING * 3
-            header.props.margin_bottom = PADDING
-            header.props.margin_left = PADDING * 2
-            header.props.margin_right = PADDING * 2
-            header.props.xalign = 0
-            alter_style_class("group_title", header, "font-size: small;")
-            header.get_style_context().add_class("group_title")
-            box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
-            box.add(header)
-            box.get_style_context().add_class("background")
-            box.show_all()
-            row.set_header(box)
+        current_type = PluginManager.get_plugin_type(row.plugin_info)
+        if before is not None:
+            previous_type = PluginManager.get_plugin_type(before.plugin_info)
+        else:
+            previous_type = None
+        if previous_type != current_type:
+            self._set_header(row, str(current_type))
+
+    def _set_header(self, row, group_title):
+        header = Gtk.Label()
+        header.set_use_markup(True)
+
+        header.set_markup("<b>%s</b>" % group_title)
+        header.props.margin_top = PADDING * 3
+        header.props.margin_bottom = PADDING
+        header.props.margin_left = PADDING * 2
+        header.props.margin_right = PADDING * 2
+        header.props.xalign = 0
+        alter_style_class("group_title", header, "font-size: small;")
+        header.get_style_context().add_class("group_title")
+        box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
+        box.add(header)
+        box.get_style_context().add_class("background")
+        box.show_all()
+        row.set_header(box)
 
 
 class PluginPreferencesPage(Gtk.ScrolledWindow):
diff --git a/pitivi/pluginmanager.py b/pitivi/pluginmanager.py
index e748488..c9a0ebc 100644
--- a/pitivi/pluginmanager.py
+++ b/pitivi/pluginmanager.py
@@ -17,6 +17,8 @@
 # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 # Boston, MA 02110-1301, USA.
 import os
+from enum import IntEnum
+from gettext import gettext as _
 
 from gi.repository import GObject
 from gi.repository import Peas
@@ -41,6 +43,17 @@ class API(GObject.GObject):
         self.app = app
 
 
+class PluginType(IntEnum):
+    SYSTEM = 1
+    USER = 2
+
+    def __str__(self):
+        if self.value == PluginType.USER:
+            return _("User plugins")
+        elif self.value == PluginType.SYSTEM:
+            return _("System plugins")
+
+
 class PluginManager(Loggable):
     """Pitivi Plugin Manager to handle a set of plugins.
 
@@ -73,6 +86,13 @@ class PluginManager(Loggable):
         """Gets the engine's plugin list."""
         return self.engine.get_plugin_list()
 
+    @classmethod
+    def get_plugin_type(cls, plugin_info):
+        paths = [plugin_info.get_data_dir(), get_plugins_dir()]
+        if os.path.commonprefix(paths) == get_plugins_dir():
+            return PluginType.SYSTEM
+        return PluginType.USER
+
     def _load_plugins(self):
         """Loads plugins from settings."""
         plugin_names = self.app.settings.ActivePlugins


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