[gnome-software] Add depends, requires and conflicts at initialize time



commit 7ac55cfb3993f146a2a2078535a8512f405d163b
Author: Richard Hughes <richard hughsie com>
Date:   Sat May 21 14:48:41 2016 +0100

    Add depends, requires and conflicts at initialize time
    
    This means we can make plugins much simpler and also do dynamic configuration
    in the future.

 contrib/gs-plugin-example.c                 |    7 +--
 src/gs-plugin-loader.c                      |   34 ++++++------
 src/gs-plugin-private.h                     |    6 +--
 src/gs-plugin-vfuncs.h                      |   37 -------------
 src/gs-plugin.c                             |   75 ++++++++++-----------------
 src/gs-plugin.h                             |   20 +++++++
 src/plugins/gs-plugin-appstream.c           |   15 +----
 src/plugins/gs-plugin-dummy.c               |   14 +----
 src/plugins/gs-plugin-epiphany.c            |   15 +----
 src/plugins/gs-plugin-fedora-tagger-usage.c |   13 +----
 src/plugins/gs-plugin-flatpak.c             |   30 ++---------
 src/plugins/gs-plugin-hardcoded-blacklist.c |   12 ++---
 src/plugins/gs-plugin-icons.c               |   17 ++-----
 src/plugins/gs-plugin-key-colors.c          |   12 ++---
 src/plugins/gs-plugin-limba.c               |   16 ++----
 src/plugins/gs-plugin-menu-spec-refine.c    |   14 ++---
 src/plugins/gs-plugin-odrs.c                |   18 ++-----
 src/plugins/gs-plugin-ostree.c              |   27 +++------
 src/plugins/gs-plugin-packagekit-history.c  |   15 +----
 src/plugins/gs-plugin-packagekit-origin.c   |   13 +----
 src/plugins/gs-plugin-packagekit-refine.c   |   30 ++---------
 src/plugins/gs-plugin-packagekit-refresh.c  |   15 +----
 src/plugins/gs-plugin-provenance-license.c  |   13 +----
 src/plugins/gs-plugin-provenance.c          |   15 +----
 src/plugins/gs-plugin-rpm.c                 |   15 +----
 src/plugins/gs-plugin-steam.c               |   12 ++---
 src/plugins/gs-plugin-ubuntu-reviews.c      |   20 +------
 src/plugins/gs-plugin-xdg-app.c             |   15 +----
 28 files changed, 155 insertions(+), 390 deletions(-)
---
diff --git a/contrib/gs-plugin-example.c b/contrib/gs-plugin-example.c
index 537498b..aef62a6 100644
--- a/contrib/gs-plugin-example.c
+++ b/contrib/gs-plugin-example.c
@@ -30,11 +30,10 @@ gcc -shared -o libgs_plugin_example.so gs-plugin-example.c -fPIC \
  sudo cp libgs_plugin_example.so `pkg-config gnome-software --variable=plugindir`
  */
 
-const gchar **
-gs_plugin_order_before (GsPlugin *plugin)
+void
+gs_plugin_initialize (GsPlugin *plugin)
 {
-       static const gchar *deps[] = { "appstream", NULL };
-       return deps;
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_BEFORE, "appstream");
 }
 
 gboolean
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 4b189fe..c757ea4 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -3279,10 +3279,11 @@ gs_plugin_loader_setup (GsPluginLoader *plugin_loader,
 {
        GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
        const gchar *filename_tmp;
+       const gchar *plugin_name;
        gboolean changes;
+       GPtrArray *deps;
        GsPlugin *dep;
        GsPlugin *plugin;
-       const gchar **deps;
        guint dep_loop_check = 0;
        guint i;
        guint j;
@@ -3333,15 +3334,14 @@ gs_plugin_loader_setup (GsPluginLoader *plugin_loader,
                changes = FALSE;
                for (i = 0; i < priv->plugins->len; i++) {
                        plugin = g_ptr_array_index (priv->plugins, i);
-                       deps = gs_plugin_get_order_after (plugin);
-                       if (deps == NULL)
-                               continue;
-                       for (j = 0; deps[j] != NULL && !changes; j++) {
+                       deps = gs_plugin_get_rules (plugin, GS_PLUGIN_RULE_RUN_AFTER);
+                       for (j = 0; j < deps->len && !changes; j++) {
+                               plugin_name = g_ptr_array_index (deps, j);
                                dep = gs_plugin_loader_find_plugin (plugin_loader,
-                                                                   deps[j]);
+                                                                   plugin_name);
                                if (dep == NULL) {
                                        g_debug ("cannot find plugin '%s'",
-                                                deps[j]);
+                                                plugin_name);
                                        continue;
                                }
                                if (!gs_plugin_get_enabled (dep))
@@ -3361,15 +3361,14 @@ gs_plugin_loader_setup (GsPluginLoader *plugin_loader,
                }
                for (i = 0; i < priv->plugins->len; i++) {
                        plugin = g_ptr_array_index (priv->plugins, i);
-                       deps = gs_plugin_get_order_before (plugin);
-                       if (deps == NULL)
-                               continue;
-                       for (j = 0; deps[j] != NULL && !changes; j++) {
+                       deps = gs_plugin_get_rules (plugin, GS_PLUGIN_RULE_RUN_BEFORE);
+                       for (j = 0; j < deps->len && !changes; j++) {
+                               plugin_name = g_ptr_array_index (deps, j);
                                dep = gs_plugin_loader_find_plugin (plugin_loader,
-                                                                   deps[j]);
+                                                                   plugin_name);
                                if (dep == NULL) {
                                        g_debug ("cannot find plugin '%s'",
-                                                deps[j]);
+                                                plugin_name);
                                        continue;
                                }
                                if (!gs_plugin_get_enabled (dep))
@@ -3403,12 +3402,11 @@ gs_plugin_loader_setup (GsPluginLoader *plugin_loader,
                plugin = g_ptr_array_index (priv->plugins, i);
                if (!gs_plugin_get_enabled (plugin))
                        continue;
-               deps = gs_plugin_get_conflicts (plugin);
-               if (deps == NULL)
-                       continue;
-               for (j = 0; deps[j] != NULL && !changes; j++) {
+               deps = gs_plugin_get_rules (plugin, GS_PLUGIN_RULE_CONFLICTS);
+               for (j = 0; j < deps->len && !changes; j++) {
+                       plugin_name = g_ptr_array_index (deps, j);
                        dep = gs_plugin_loader_find_plugin (plugin_loader,
-                                                           deps[j]);
+                                                           plugin_name);
                        if (dep == NULL)
                                continue;
                        if (!gs_plugin_get_enabled (dep))
diff --git a/src/gs-plugin-private.h b/src/gs-plugin-private.h
index e081b5b..caf6df1 100644
--- a/src/gs-plugin-private.h
+++ b/src/gs-plugin-private.h
@@ -51,10 +51,8 @@ void          gs_plugin_set_soup_session             (GsPlugin       *plugin,
                                                         SoupSession    *soup_session);
 void            gs_plugin_set_running_other            (GsPlugin       *plugin,
                                                         gboolean        running_other);
-const gchar    **gs_plugin_get_order_after             (GsPlugin       *plugin);
-const gchar    **gs_plugin_get_order_before            (GsPlugin       *plugin);
-const gchar    **gs_plugin_get_conflicts               (GsPlugin       *plugin);
-
+GPtrArray      *gs_plugin_get_rules                    (GsPlugin       *plugin,
+                                                        GsPluginRule    rule);
 GModule                *gs_plugin_get_module                   (GsPlugin       *plugin);
 
 G_END_DECLS
diff --git a/src/gs-plugin-vfuncs.h b/src/gs-plugin-vfuncs.h
index 5b66783..867c517 100644
--- a/src/gs-plugin-vfuncs.h
+++ b/src/gs-plugin-vfuncs.h
@@ -137,43 +137,6 @@ gboolean    gs_plugin_add_search_what_provides     (GsPlugin       *plugin,
                                                         GError         **error);
 
 /**
- * gs_plugin_order_after:
- * @plugin: a #GsPlugin
- *
- * Any plugin names returned with this method will be ordered after this plugin.
- *
- * NOTE: If depsolving fails then gnome-software will not start.
- *
- * Returns: (element-type utf8): A list of deps
- **/
-const gchar    **gs_plugin_order_after                 (GsPlugin       *plugin);
-
-/**
- * gs_plugin_order_before:
- * @plugin: a #GsPlugin
- *
- * Any plugin names returned with this method will be ordered before this plugin.
- *
- * NOTE: If depsolving fails then gnome-software will not start.
- *
- * Returns: (element-type utf8): A list of deps
- **/
-const gchar    **gs_plugin_order_before                (GsPlugin       *plugin);
-
-/**
- * gs_plugin_get_conflicts:
- * @plugin: a #GsPlugin
- *
- * Any plugin names returned with this method will be disabled if this plugin
- * is enabled.
- *
- * NOTE: The depsolver is iterative and may not solve overly-complicated rules.
- *
- * Returns: (element-type utf8): A list of deps
- **/
-const gchar    **gs_plugin_get_conflicts               (GsPlugin       *plugin);
-
-/**
  * gs_plugin_setup:
  * @plugin: a #GsPlugin
  * @cancellable: a #GCancellable, or %NULL
diff --git a/src/gs-plugin.c b/src/gs-plugin.c
index 5fe945e..8d460bd 100644
--- a/src/gs-plugin.c
+++ b/src/gs-plugin.c
@@ -61,9 +61,7 @@ typedef struct
        GsPluginData            *data;                  /* for gs-plugin-{name}.c */
        GsPluginFlags            flags;
        SoupSession             *soup_session;
-       const gchar             **conflicts;            /* allow-none */
-       const gchar             **order_after;          /* allow-none */
-       const gchar             **order_before;         /* allow-none */
+       GPtrArray               *rules[GS_PLUGIN_RULE_LAST];
        gboolean                 enabled;
        gchar                   *locale;                /* allow-none */
        gchar                   *name;
@@ -130,9 +128,6 @@ GsPlugin *
 gs_plugin_create (const gchar *filename, GError **error)
 {
        GModule *module;
-       GsPluginGetDepsFunc order_after = NULL;
-       GsPluginGetDepsFunc order_before = NULL;
-       GsPluginGetDepsFunc plugin_conflicts = NULL;
        GsPlugin *plugin = NULL;
        GsPluginPrivate *priv;
        g_autofree gchar *basename = NULL;
@@ -159,24 +154,10 @@ gs_plugin_create (const gchar *filename, GError **error)
        }
        g_strdelimit (basename, ".", '\0');
 
-       /* get plugins this plugin depends on */
-       g_module_symbol (module,
-                        "gs_plugin_order_after",
-                        (gpointer *) &order_after);
-       g_module_symbol (module,
-                        "gs_plugin_order_before",
-                        (gpointer *) &order_before);
-       g_module_symbol (module,
-                        "gs_plugin_get_conflicts",
-                        (gpointer *) &plugin_conflicts);
-
        /* create new plugin */
        plugin = gs_plugin_new ();
        priv = gs_plugin_get_instance_private (plugin);
        priv->module = module;
-       priv->order_after = order_after != NULL ? order_after (plugin) : NULL;
-       priv->order_before = order_before != NULL ? order_before (plugin) : NULL;
-       priv->conflicts = plugin_conflicts != NULL ? plugin_conflicts (plugin) : NULL;
        priv->name = g_strdup (basename + 13);
        return plugin;
 }
@@ -189,6 +170,10 @@ gs_plugin_finalize (GObject *object)
 {
        GsPlugin *plugin = GS_PLUGIN (object);
        GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+       guint i;
+
+       for (i = 0; i < GS_PLUGIN_RULE_LAST; i++)
+               g_ptr_array_unref (priv->rules[i]);
 
        if (priv->timer_id > 0)
                g_source_remove (priv->timer_id);
@@ -554,48 +539,39 @@ gs_plugin_set_running_other (GsPlugin *plugin, gboolean running_other)
 }
 
 /**
- * gs_plugin_get_order_after:
- * @plugin: a #GsPlugin
- *
- * Gets the plugin IDs that should be run after this plugin.
- *
- * Returns: the NULL terminated list of IDs, e.g. ['appstream']
- **/
-const gchar **
-gs_plugin_get_order_after (GsPlugin *plugin)
-{
-       GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
-       return priv->order_after;
-}
-
-/**
- * gs_plugin_get_order_before:
+ * gs_plugin_add_rule:
  * @plugin: a #GsPlugin
+ * @rule: a #GsPluginRule, e.g. %GS_PLUGIN_RULE_CONFLICTS
+ * @name: a plugin name, e.g. "appstream"
  *
- * Gets the plugin IDs that should be run before this plugin.
+ * If the plugin name is found, the rule will be used to sort the plugin list,
+ * for example the plugin specified by @name will be ordered after this plugin
+ * when %GS_PLUGIN_RULE_RUN_AFTER is used.
  *
- * Returns: the NULL terminated list of IDs, e.g. ['appstream']
+ * NOTE: The depsolver is iterative and may not solve overly-complicated rules;
+ * If depsolving fails then gnome-software will not start.
  **/
-const gchar **
-gs_plugin_get_order_before (GsPlugin *plugin)
+void
+gs_plugin_add_rule (GsPlugin *plugin, GsPluginRule rule, const gchar *name)
 {
        GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
-       return priv->order_before;
+       g_ptr_array_add (priv->rules[rule], g_strdup (name));
 }
 
 /**
- * gs_plugin_get_conflicts:
+ * gs_plugin_get_rules:
  * @plugin: a #GsPlugin
+ * @rule: a #GsPluginRule, e.g. %GS_PLUGIN_RULE_CONFLICTS
  *
- * Gets the plugin IDs that should be disabled if this plugin is enabled.
+ * Gets the plugin IDs that should be run after this plugin.
  *
- * Returns: the NULL terminated list of IDs, e.g. ['appstream']
+ * Returns: (element-type utf8) (transfer none): the list of plugin names, e.g. ['appstream']
  **/
-const gchar **
-gs_plugin_get_conflicts (GsPlugin *plugin)
+GPtrArray *
+gs_plugin_get_rules (GsPlugin *plugin, GsPluginRule rule)
 {
        GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
-       return priv->conflicts;
+       return priv->rules[rule];
 }
 
 /**
@@ -1032,6 +1008,11 @@ static void
 gs_plugin_init (GsPlugin *plugin)
 {
        GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+       guint i;
+
+       for (i = 0; i < GS_PLUGIN_RULE_LAST; i++)
+               priv->rules[i] = g_ptr_array_new_with_free_func (g_free);
+
        priv->enabled = TRUE;
        priv->priority = 0.f;
        priv->scale = 1;
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index 7b9f597..21b25cc 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -197,6 +197,23 @@ typedef enum {
        GS_PLUGIN_REFRESH_FLAGS_LAST
 } GsPluginRefreshFlags;
 
+/**
+ * GsPluginRule:
+ * @GS_PLUGIN_RULE_CONFLICTS:          The plugin conflicts with another
+ * @GS_PLUGIN_RULE_RUN_AFTER:          Order the plugin after another
+ * @GS_PLUGIN_RULE_RUN_BEFORE:         Order the plugin before another
+ *
+ * The rules used for ordering plugins.
+ * Plugins are expected to add rules in gs_plugin_initialize().
+ **/
+typedef enum {
+       GS_PLUGIN_RULE_CONFLICTS,
+       GS_PLUGIN_RULE_RUN_AFTER,
+       GS_PLUGIN_RULE_RUN_BEFORE,
+       /*< private >*/
+       GS_PLUGIN_RULE_LAST
+} GsPluginRule;
+
 /* helpers */
 #define        GS_PLUGIN_ERROR                                 1
 
@@ -214,6 +231,9 @@ guint                gs_plugin_get_scale                    (GsPlugin       *plugin);
 const gchar    *gs_plugin_get_locale                   (GsPlugin       *plugin);
 AsProfile      *gs_plugin_get_profile                  (GsPlugin       *plugin);
 SoupSession    *gs_plugin_get_soup_session             (GsPlugin       *plugin);
+void            gs_plugin_add_rule                     (GsPlugin       *plugin,
+                                                        GsPluginRule    rule,
+                                                        const gchar    *name);
 
 /* helpers */
 GBytes         *gs_plugin_download_data                (GsPlugin       *plugin,
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index 99f946b..00a9baa 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -65,19 +65,10 @@ gs_plugin_initialize (GsPlugin *plugin)
        as_store_set_watch_flags (priv->store,
                                  AS_STORE_WATCH_FLAG_ADDED |
                                  AS_STORE_WATCH_FLAG_REMOVED);
-}
 
-/**
- * gs_plugin_order_after:
- */
-const gchar **
-gs_plugin_order_after (GsPlugin *plugin)
-{
-       static const gchar *deps[] = {
-               "menu-spec-categories", /* need category list */
-               "dpkg",                 /* need package name */
-               NULL };
-       return deps;
+       /* need category list and package name */
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "menu-spec-categories");
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "dpkg");
 }
 
 /**
diff --git a/src/plugins/gs-plugin-dummy.c b/src/plugins/gs-plugin-dummy.c
index a1db60b..0fa8cd6 100644
--- a/src/plugins/gs-plugin-dummy.c
+++ b/src/plugins/gs-plugin-dummy.c
@@ -33,17 +33,6 @@ struct GsPluginData {
 };
 
 /**
- * gs_plugin_order_after:
- */
-const gchar **
-gs_plugin_order_after (GsPlugin *plugin)
-{
-       static const gchar *deps[] = { "appstream",
-                                      NULL };
-       return deps;
-}
-
-/**
  * gs_plugin_initialize:
  */
 void
@@ -55,6 +44,9 @@ gs_plugin_initialize (GsPlugin *plugin)
                         gs_plugin_get_name (plugin));
                gs_plugin_set_enabled (plugin, FALSE);
        }
+
+       /* need help from appstream */
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "appstream");
 }
 
 /**
diff --git a/src/plugins/gs-plugin-epiphany.c b/src/plugins/gs-plugin-epiphany.c
index e415d5b..ea65916 100644
--- a/src/plugins/gs-plugin-epiphany.c
+++ b/src/plugins/gs-plugin-epiphany.c
@@ -34,18 +34,6 @@
  */
 
 /**
- * gs_plugin_order_after:
- */
-const gchar **
-gs_plugin_order_after (GsPlugin *plugin)
-{
-       static const gchar *deps[] = {
-               "appstream",
-               NULL };
-       return deps;
-}
-
-/**
  * gs_plugin_initialize:
  */
 void
@@ -60,6 +48,9 @@ gs_plugin_initialize (GsPlugin *plugin)
                g_debug ("disabling '%s' as epiphany does not exist",
                         gs_plugin_get_name (plugin));
        }
+
+       /* need help from appstream */
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "appstream");
 }
 
 /**
diff --git a/src/plugins/gs-plugin-fedora-tagger-usage.c b/src/plugins/gs-plugin-fedora-tagger-usage.c
index 0be547e..ab07623 100644
--- a/src/plugins/gs-plugin-fedora-tagger-usage.c
+++ b/src/plugins/gs-plugin-fedora-tagger-usage.c
@@ -58,18 +58,9 @@ gs_plugin_initialize (GsPlugin *plugin)
                g_debug ("disabling '%s' as we're not Fedora", gs_plugin_get_name (plugin));
                return;
        }
-}
 
-/**
- * gs_plugin_order_after:
- */
-const gchar **
-gs_plugin_order_after (GsPlugin *plugin)
-{
-       static const gchar *deps[] = {
-               "packagekit",           /* after the install/remove has succeeded */
-               NULL };
-       return deps;
+       /* after the install/remove has succeeded */
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "packagekit");
 }
 
 /**
diff --git a/src/plugins/gs-plugin-flatpak.c b/src/plugins/gs-plugin-flatpak.c
index 9a26803..c13cf11 100644
--- a/src/plugins/gs-plugin-flatpak.c
+++ b/src/plugins/gs-plugin-flatpak.c
@@ -44,36 +44,18 @@ struct GsPluginData {
 };
 
 /**
- * gs_plugin_order_after:
- */
-const gchar **
-gs_plugin_order_after (GsPlugin *plugin)
-{
-       static const gchar *deps[] = {
-               "appstream",
-               NULL };
-       return deps;
-}
-
-/**
- * gs_plugin_get_conflicts:
- */
-const gchar **
-gs_plugin_get_conflicts (GsPlugin *plugin)
-{
-       static const gchar *deps[] = {
-               "xdg-app",
-               NULL };
-       return deps;
-}
-
-/**
  * gs_plugin_initialize:
  */
 void
 gs_plugin_initialize (GsPlugin *plugin)
 {
        gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
+
+       /* getting app properties from appstream is quicker */
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "appstream");
+
+       /* this is the old name */
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "xdg-app");
 }
 
 /**
diff --git a/src/plugins/gs-plugin-hardcoded-blacklist.c b/src/plugins/gs-plugin-hardcoded-blacklist.c
index 554caec..efa2b0b 100644
--- a/src/plugins/gs-plugin-hardcoded-blacklist.c
+++ b/src/plugins/gs-plugin-hardcoded-blacklist.c
@@ -30,15 +30,13 @@
  */
 
 /**
- * gs_plugin_order_after:
+ * gs_plugin_initialize:
  */
-const gchar **
-gs_plugin_order_after (GsPlugin *plugin)
+void
+gs_plugin_initialize (GsPlugin *plugin)
 {
-       static const gchar *deps[] = {
-               "appstream",            /* need ID */
-               NULL };
-       return deps;
+       /* need ID */
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "appstream");
 }
 
 /**
diff --git a/src/plugins/gs-plugin-icons.c b/src/plugins/gs-plugin-icons.c
index 05f58c0..90fe28d 100644
--- a/src/plugins/gs-plugin-icons.c
+++ b/src/plugins/gs-plugin-icons.c
@@ -50,6 +50,10 @@ gs_plugin_initialize (GsPlugin *plugin)
        priv->icon_theme = gtk_icon_theme_new ();
        priv->icon_theme_paths = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
        g_mutex_init (&priv->icon_theme_lock);
+
+       /* needs remote icons downloaded */
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "appstream");
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "epiphany");
 }
 
 /**
@@ -65,19 +69,6 @@ gs_plugin_destroy (GsPlugin *plugin)
 }
 
 /**
- * gs_plugin_order_after:
- */
-const gchar **
-gs_plugin_order_after (GsPlugin *plugin)
-{
-       static const gchar *deps[] = {
-               "appstream",            /* needs remote icons downloaded */
-               "epiphany",             /* "" */
-               NULL };
-       return deps;
-}
-
-/**
  * gs_plugin_icons_download:
  */
 static gboolean
diff --git a/src/plugins/gs-plugin-key-colors.c b/src/plugins/gs-plugin-key-colors.c
index 3089712..1fc5f03 100644
--- a/src/plugins/gs-plugin-key-colors.c
+++ b/src/plugins/gs-plugin-key-colors.c
@@ -24,15 +24,13 @@
 #include <gnome-software.h>
 
 /**
- * gs_plugin_order_after:
+ * gs_plugin_initialize:
  */
-const gchar **
-gs_plugin_order_after (GsPlugin *plugin)
+void
+gs_plugin_initialize (GsPlugin *plugin)
 {
-       static const gchar *deps[] = {
-               "icons",        /* need icon */
-               NULL };
-       return deps;
+       /* need icon */
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "icons");
 }
 
 typedef struct {
diff --git a/src/plugins/gs-plugin-limba.c b/src/plugins/gs-plugin-limba.c
index b13bfbe..aee22cd 100644
--- a/src/plugins/gs-plugin-limba.c
+++ b/src/plugins/gs-plugin-limba.c
@@ -35,18 +35,6 @@ struct GsPluginData {
 };
 
 /**
- * gs_plugin_order_after:
- */
-const gchar **
-gs_plugin_order_after (GsPlugin *plugin)
-{
-       static const gchar *deps[] = { "appstream",
-                                      "packagekit",
-                                      NULL };
-       return deps;
-}
-
-/**
  * gs_plugin_initialize:
  */
 void
@@ -54,6 +42,10 @@ gs_plugin_initialize (GsPlugin *plugin)
 {
        GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
        priv->mgr = li_manager_new ();
+
+       /* need help from appstream */
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "appstream");
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "packagekit");
 }
 
 /**
diff --git a/src/plugins/gs-plugin-menu-spec-refine.c b/src/plugins/gs-plugin-menu-spec-refine.c
index cf10c7d..9a9e69f 100644
--- a/src/plugins/gs-plugin-menu-spec-refine.c
+++ b/src/plugins/gs-plugin-menu-spec-refine.c
@@ -33,16 +33,14 @@
  */
 
 /**
- * gs_plugin_order_after:
+ * gs_plugin_initialize:
  */
-const gchar **
-gs_plugin_order_after (GsPlugin *plugin)
+void
+gs_plugin_initialize (GsPlugin *plugin)
 {
-       static const gchar *deps[] = {
-               "appstream",            /* need GsApp category data */
-               "menu-spec-categories", /* need menu-spec data */
-               NULL };
-       return deps;
+       /* need category and menu-spec data */
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "appstream");
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "menu-spec-categories");
 }
 
 /**
diff --git a/src/plugins/gs-plugin-odrs.c b/src/plugins/gs-plugin-odrs.c
index 13ad8a4..4b2b90f 100644
--- a/src/plugins/gs-plugin-odrs.c
+++ b/src/plugins/gs-plugin-odrs.c
@@ -72,21 +72,11 @@ gs_plugin_initialize (GsPlugin *plugin)
                g_warning ("failed to get distro name");
                priv->distro = g_strdup ("Unknown");
        }
-}
-
 
-/**
- * gs_plugin_order_after:
- */
-const gchar **
-gs_plugin_order_after (GsPlugin *plugin)
-{
-       static const gchar *deps[] = {
-               "appstream",    /* need application IDs */
-               "xdg-app",      /* need version */
-               "flatpak",      /* need version */
-               NULL };
-       return deps;
+       /* need application IDs and version */
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "appstream");
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "xdg-app");
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "flatpak");
 }
 
 /**
diff --git a/src/plugins/gs-plugin-ostree.c b/src/plugins/gs-plugin-ostree.c
index c593041..5148282 100644
--- a/src/plugins/gs-plugin-ostree.c
+++ b/src/plugins/gs-plugin-ostree.c
@@ -44,25 +44,16 @@ gs_plugin_initialize (GsPlugin *plugin)
                gs_plugin_set_enabled (plugin, FALSE);
                return;
        }
-}
 
-/**
- * gs_plugin_get_conflicts:
- */
-const gchar **
-gs_plugin_get_conflicts (GsPlugin *plugin)
-{
-       static const gchar *deps[] = {
-               "packagekit",
-               "packagekit-history",
-               "packagekit-offline",
-               "packagekit-origin",
-               "packagekit-proxy",
-               "packagekit-refine",
-               "packagekit-refresh",
-               "systemd-updates",
-               NULL };
-       return deps;
+       /* ostree can't install packages live */
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "packagekit");
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "packagekit-history");
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "packagekit-offline");
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "packagekit-origin");
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "packagekit-proxy");
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "packagekit-refine");
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "packagekit-refresh");
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "systemd-updates");
 }
 
 /**
diff --git a/src/plugins/gs-plugin-packagekit-history.c b/src/plugins/gs-plugin-packagekit-history.c
index 9e8093e..08677aa 100644
--- a/src/plugins/gs-plugin-packagekit-history.c
+++ b/src/plugins/gs-plugin-packagekit-history.c
@@ -44,19 +44,10 @@ void
 gs_plugin_initialize (GsPlugin *plugin)
 {
        gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
-}
 
-/**
- * gs_plugin_order_after:
- */
-const gchar **
-gs_plugin_order_after (GsPlugin *plugin)
-{
-       static const gchar *deps[] = {
-               "appstream",            /* need pkgname */
-               "packagekit-refine",    /* need pkgname */
-               NULL };
-       return deps;
+       /* need pkgname */
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "appstream");
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "packagekit-refine");
 }
 
 /**
diff --git a/src/plugins/gs-plugin-packagekit-origin.c b/src/plugins/gs-plugin-packagekit-origin.c
index 38a6bc5..d96c428 100644
--- a/src/plugins/gs-plugin-packagekit-origin.c
+++ b/src/plugins/gs-plugin-packagekit-origin.c
@@ -56,18 +56,9 @@ gs_plugin_initialize (GsPlugin *plugin)
                                                       g_str_equal,
                                                       g_free,
                                                       g_free);
-}
 
-/**
- * gs_plugin_order_after:
- */
-const gchar **
-gs_plugin_order_after (GsPlugin *plugin)
-{
-       static const gchar *deps[] = {
-               "packagekit-refine",    /* need origin */
-               NULL };
-       return deps;
+       /* need origin */
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "packagekit-refine");
 }
 
 /**
diff --git a/src/plugins/gs-plugin-packagekit-refine.c b/src/plugins/gs-plugin-packagekit-refine.c
index 738fc9e..122d234 100644
--- a/src/plugins/gs-plugin-packagekit-refine.c
+++ b/src/plugins/gs-plugin-packagekit-refine.c
@@ -45,18 +45,6 @@ struct GsPluginData {
 };
 
 /**
- * gs_plugin_get_conflicts:
- */
-const gchar **
-gs_plugin_get_conflicts (GsPlugin *plugin)
-{
-       static const gchar *deps[] = {
-               "rpm",
-               NULL };
-       return deps;
-}
-
-/**
  * gs_plugin_initialize:
  */
 static void
@@ -81,19 +69,13 @@ gs_plugin_initialize (GsPlugin *plugin)
        pk_client_set_background (priv->client, FALSE);
        pk_client_set_interactive (priv->client, FALSE);
        pk_client_set_cache_age (priv->client, G_MAXUINT);
-}
 
-/**
- * gs_plugin_order_after:
- */
-const gchar **
-gs_plugin_order_after (GsPlugin *plugin)
-{
-       static const gchar *deps[] = {
-               "appstream",            /* need pkgname */
-               "packagekit",           /* need package_id */
-               NULL };
-       return deps;
+       /* we can get better results than the RPM plugin */
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "rpm");
+
+       /* need pkgname and ID */
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "appstream");
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "packagekit");
 }
 
 /**
diff --git a/src/plugins/gs-plugin-packagekit-refresh.c b/src/plugins/gs-plugin-packagekit-refresh.c
index 266bb2c..7d461f5 100644
--- a/src/plugins/gs-plugin-packagekit-refresh.c
+++ b/src/plugins/gs-plugin-packagekit-refresh.c
@@ -38,18 +38,6 @@ struct GsPluginData {
 };
 
 /**
- * gs_plugin_get_conflicts:
- */
-const gchar **
-gs_plugin_get_conflicts (GsPlugin *plugin)
-{
-       static const gchar *deps[] = {
-               "dpkg",
-               NULL };
-       return deps;
-}
-
-/**
  * gs_plugin_initialize:
  */
 void
@@ -60,6 +48,9 @@ gs_plugin_initialize (GsPlugin *plugin)
        pk_task_set_only_download (priv->task, TRUE);
        pk_client_set_background (PK_CLIENT (priv->task), TRUE);
        pk_client_set_interactive (PK_CLIENT (priv->task), FALSE);
+
+       /* we can return better results than dpkg directly */
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "dpkg");
 }
 
 /**
diff --git a/src/plugins/gs-plugin-provenance-license.c b/src/plugins/gs-plugin-provenance-license.c
index 0094c86..387ca4e 100644
--- a/src/plugins/gs-plugin-provenance-license.c
+++ b/src/plugins/gs-plugin-provenance-license.c
@@ -106,18 +106,9 @@ gs_plugin_initialize (GsPlugin *plugin)
                          G_CALLBACK (gs_plugin_provenance_license_changed_cb), plugin);
        priv->sources = gs_plugin_provenance_license_get_sources (plugin);
        priv->license_id = gs_plugin_provenance_license_get_id (plugin);
-}
 
-/**
- * gs_plugin_order_after:
- */
-const gchar **
-gs_plugin_order_after (GsPlugin *plugin)
-{
-       static const gchar *deps[] = {
-               "provenance",
-               NULL };
-       return deps;
+       /* need this set */
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "provenance");
 }
 
 /**
diff --git a/src/plugins/gs-plugin-provenance.c b/src/plugins/gs-plugin-provenance.c
index 0070ee4..f634c7f 100644
--- a/src/plugins/gs-plugin-provenance.c
+++ b/src/plugins/gs-plugin-provenance.c
@@ -76,19 +76,10 @@ gs_plugin_initialize (GsPlugin *plugin)
        g_signal_connect (priv->settings, "changed",
                          G_CALLBACK (gs_plugin_provenance_settings_changed_cb), plugin);
        priv->sources = gs_plugin_provenance_get_sources (plugin);
-}
 
-/**
- * gs_plugin_order_after:
- */
-const gchar **
-gs_plugin_order_after (GsPlugin *plugin)
-{
-       static const gchar *deps[] = {
-               "dummy",
-               "packagekit-refine",    /* after the package source is set */
-               NULL };
-       return deps;
+       /* after the package source is set */
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "dummy");
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "packagekit-refine");
 }
 
 /**
diff --git a/src/plugins/gs-plugin-rpm.c b/src/plugins/gs-plugin-rpm.c
index 872699f..2bf9788 100644
--- a/src/plugins/gs-plugin-rpm.c
+++ b/src/plugins/gs-plugin-rpm.c
@@ -29,18 +29,6 @@
 #include <gnome-software.h>
 
 /**
- * gs_plugin_order_after:
- */
-const gchar **
-gs_plugin_order_after (GsPlugin *plugin)
-{
-       static const gchar *deps[] = {
-               "appstream",    /* need application IDs */
-               NULL };
-       return deps;
-}
-
-/**
  * gs_plugin_initialize:
  */
 void
@@ -54,6 +42,9 @@ gs_plugin_initialize (GsPlugin *plugin)
 
        /* open transaction */
        rpmReadConfigFiles(NULL, NULL);
+
+       /* need application IDs */
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "appstream");
 }
 
 G_DEFINE_AUTO_CLEANUP_FREE_FUNC(rpmts, rpmtsFree, NULL);
diff --git a/src/plugins/gs-plugin-steam.c b/src/plugins/gs-plugin-steam.c
index d1fb779..6bd6dc1 100644
--- a/src/plugins/gs-plugin-steam.c
+++ b/src/plugins/gs-plugin-steam.c
@@ -27,15 +27,13 @@
 #define GS_PLUGIN_STEAM_SCREENSHOT_URI "http://cdn.akamai.steamstatic.com/steam/apps";
 
 /**
- * gs_plugin_order_after:
+ * gs_plugin_initialize:
  */
-const gchar **
-gs_plugin_order_after (GsPlugin *plugin)
+void
+gs_plugin_initialize (GsPlugin *plugin)
 {
-       static const gchar *deps[] = {
-               "appstream",            /* need metadata */
-               NULL };
-       return deps;
+       /* need metadata */
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "appstream");
 }
 
 typedef enum {
diff --git a/src/plugins/gs-plugin-ubuntu-reviews.c b/src/plugins/gs-plugin-ubuntu-reviews.c
index 64052b1..2afe86f 100644
--- a/src/plugins/gs-plugin-ubuntu-reviews.c
+++ b/src/plugins/gs-plugin-ubuntu-reviews.c
@@ -63,25 +63,9 @@ gs_plugin_initialize (GsPlugin *plugin)
                                                  "gnome-software",
                                                  "ubuntu-reviews.db",
                                                  NULL);
-}
-
-const gchar **
-gs_plugin_order_after (GsPlugin *plugin)
-{
-       static const gchar *deps[] = { NULL };
-       return deps;
-}
 
-/**
- * gs_plugin_get_conflicts:
- */
-const gchar **
-gs_plugin_get_conflicts (GsPlugin *plugin)
-{
-       static const gchar *deps[] = {
-               "odrs",
-               NULL };
-       return deps;
+       /* we have more reviews than ORDS */
+       gs_plugin_add_conflict (plugin, "odrs");
 }
 
 void
diff --git a/src/plugins/gs-plugin-xdg-app.c b/src/plugins/gs-plugin-xdg-app.c
index 1bbf081..b5084f3 100644
--- a/src/plugins/gs-plugin-xdg-app.c
+++ b/src/plugins/gs-plugin-xdg-app.c
@@ -48,24 +48,15 @@ struct GsPluginData {
 };
 
 /**
- * gs_plugin_order_after:
- */
-const gchar **
-gs_plugin_order_after (GsPlugin *plugin)
-{
-       static const gchar *deps[] = {
-               "appstream",
-               NULL };
-       return deps;
-}
-
-/**
  * gs_plugin_initialize:
  */
 void
 gs_plugin_initialize (GsPlugin *plugin)
 {
        gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
+
+       /* getting app properties from appstream is quicker */
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "appstream");
 }
 
 /**


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