[gnome-software] Make the provenance plugin non-specific to Fedora



commit fc45c68e6b3e0b0d7b4cb38e3fec4b0edb773c9b
Author: Richard Hughes <richard hughsie com>
Date:   Tue Mar 1 14:36:58 2016 +0000

    Make the provenance plugin non-specific to Fedora
    
    Other distros want to do exactly the same, and we'll want to customize the list
    both for RHEL and for customer deployments.

 configure.ac                                       |    2 +-
 contrib/gnome-software.spec.in                     |    9 ++-
 data/org.gnome.software.gschema.xml                |    4 +
 src/plugins/Makefile.am                            |   10 ++--
 ...-fedora-provenance.c => gs-plugin-provenance.c} |   75 +++++++++++--------
 5 files changed, 61 insertions(+), 39 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 68a6f0d..44bfe01 100644
--- a/configure.ac
+++ b/configure.ac
@@ -203,7 +203,7 @@ AM_CONDITIONAL(HAVE_LIMBA, test x$enable_limba = xyes)
 
 # this refers to the gnome-software plugin API version
 # this is not in any way related to a package or soname version
-GS_PLUGIN_API_VERSION=8
+GS_PLUGIN_API_VERSION=9
 AC_SUBST(GS_PLUGIN_API_VERSION)
 AC_DEFINE_UNQUOTED([GS_PLUGIN_API_VERSION], "$GS_PLUGIN_API_VERSION", [the plugin API version])
 
diff --git a/contrib/gnome-software.spec.in b/contrib/gnome-software.spec.in
index ff2f809..8b7e866 100644
--- a/contrib/gnome-software.spec.in
+++ b/contrib/gnome-software.spec.in
@@ -34,7 +34,7 @@ BuildRequires: fwupd-devel
 BuildRequires: json-glib-devel
 
 # this is not a library version
-%define gs_plugin_version               8
+%define gs_plugin_version               9
 
 %description
 gnome-software is an application that makes it easy to add, remove
@@ -56,6 +56,12 @@ rm %{buildroot}%{_libdir}/gs-plugins-%{gs_plugin_version}/*.la
 desktop-file-edit %{buildroot}%{_datadir}/applications/org.gnome.Software.desktop \
     --set-key=X-AppInstall-Package --set-value=%{name}
 
+# set up for Fedora
+cat >> %{buildroot}%{_datadir}/glib-2.0/schemas/org.gnome.software-fedora.gschema.override << FOE
+[org.gnome.software]
+official-sources = [ 'fedora', 'fedora-debuginfo', 'fedora-source', 'koji-override-0', 'koji-override-1', 
'rawhide', 'rawhide-debuginfo', 'rawhide-source', 'updates', 'updates-debuginfo', 'updates-source', 
'updates-testing', 'updates-testing-debuginfo', 'updates-testing-source' ]
+FOE
+
 %find_lang %name --with-gnome
 
 %check
@@ -96,6 +102,7 @@ glib-compile-schemas %{_datadir}/glib-2.0/schemas &> /dev/null || :
 %{_datadir}/dbus-1/services/org.gnome.Software.service
 %{_datadir}/gnome-shell/search-providers/org.gnome.Software-search-provider.ini
 %{_datadir}/glib-2.0/schemas/org.gnome.software.gschema.xml
+%{_datadir}/glib-2.0/schemas/org.gnome.software-fedora.gschema.override
 %dir %{_datadir}/gnome-software/modulesets.d
 %{_datadir}/gnome-software/modulesets.d/*.xml
 
diff --git a/data/org.gnome.software.gschema.xml b/data/org.gnome.software.gschema.xml
index ed594cb..0a6db6f 100644
--- a/data/org.gnome.software.gschema.xml
+++ b/data/org.gnome.software.gschema.xml
@@ -54,5 +54,9 @@
       <summary>The minimum karma score for reviews</summary>
       <description>Reviews with karma less than this number will not be shown.</description>
     </key>
+    <key name="official-sources" type="as">
+      <default>[]</default>
+      <summary>A list of official sources that should not be considered 3rd party</summary>
+    </key>
   </schema>
 </schemalist>
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index d91c69e..07546c4 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -37,7 +37,7 @@ plugin_LTLIBRARIES =                                  \
        libgs_plugin_menu-spec-categories.la            \
        libgs_plugin_menu-spec-refine.la                \
        libgs_plugin_fedora_distro_upgrades.la          \
-       libgs_plugin_fedora_provenance.la               \
+       libgs_plugin_provenance.la                      \
        libgs_plugin_ubuntu-reviews.la                  \
        libgs_plugin_fedora_tagger_usage.la             \
        libgs_plugin_epiphany.la                        \
@@ -78,10 +78,10 @@ libgs_plugin_fedora_distro_upgrades_la_LIBADD = $(GS_PLUGIN_LIBS) $(JSON_GLIB_LI
 libgs_plugin_fedora_distro_upgrades_la_LDFLAGS = -module -avoid-version
 libgs_plugin_fedora_distro_upgrades_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(JSON_GLIB_CFLAGS) $(WARN_CFLAGS)
 
-libgs_plugin_fedora_provenance_la_SOURCES = gs-plugin-fedora-provenance.c
-libgs_plugin_fedora_provenance_la_LIBADD = $(GS_PLUGIN_LIBS)
-libgs_plugin_fedora_provenance_la_LDFLAGS = -module -avoid-version
-libgs_plugin_fedora_provenance_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
+libgs_plugin_provenance_la_SOURCES = gs-plugin-provenance.c
+libgs_plugin_provenance_la_LIBADD = $(GS_PLUGIN_LIBS)
+libgs_plugin_provenance_la_LDFLAGS = -module -avoid-version
+libgs_plugin_provenance_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
 
 libgs_plugin_fedora_tagger_usage_la_SOURCES = gs-plugin-fedora-tagger-usage.c
 libgs_plugin_fedora_tagger_usage_la_LIBADD = $(GS_PLUGIN_LIBS) $(SOUP_LIBS) $(SQLITE_LIBS)
diff --git a/src/plugins/gs-plugin-fedora-provenance.c b/src/plugins/gs-plugin-provenance.c
similarity index 62%
rename from src/plugins/gs-plugin-fedora-provenance.c
rename to src/plugins/gs-plugin-provenance.c
index f91eba3..eb60974 100644
--- a/src/plugins/gs-plugin-fedora-provenance.c
+++ b/src/plugins/gs-plugin-provenance.c
@@ -1,6 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  *
- * Copyright (C) 2013 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2015-2016 Richard Hughes <richard hughsie com>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -26,18 +26,36 @@
 /*
  * SECTION:
  * Sets the package provanance to TRUE if installed by an official
- * Fedora repo.
- *
- * It will self-disable if not run on a Fedora system.
+ * software source.
  */
 
+struct GsPluginPrivate {
+       GSettings               *settings;
+       gchar                   **sources;
+};
+
 /**
  * gs_plugin_get_name:
  */
 const gchar *
 gs_plugin_get_name (void)
 {
-       return "fedora-provenance";
+       return "provenance";
+}
+
+/**
+ * gs_plugin_provenance_settings_changed_cb:
+ */
+static void
+gs_plugin_provenance_settings_changed_cb (GSettings *settings,
+                                         const gchar *key,
+                                         GsPlugin *plugin)
+{
+       if (g_strcmp0 (key, "official-sources") == 0) {
+               g_strfreev (plugin->priv->sources);
+               plugin->priv->sources = g_settings_get_strv (plugin->priv->settings,
+                                                            "official-sources");
+       }
 }
 
 /**
@@ -46,12 +64,12 @@ gs_plugin_get_name (void)
 void
 gs_plugin_initialize (GsPlugin *plugin)
 {
-       /* check that we are running on Fedora */
-       if (!gs_plugin_check_distro_id (plugin, "fedora")) {
-               gs_plugin_set_enabled (plugin, FALSE);
-               g_debug ("disabling '%s' as we're not Fedora", plugin->name);
-               return;
-       }
+       plugin->priv = GS_PLUGIN_GET_PRIVATE (GsPluginPrivate);
+       plugin->priv->settings = g_settings_new ("org.gnome.software");
+       g_signal_connect (plugin->priv->settings, "changed",
+                         G_CALLBACK (gs_plugin_provenance_settings_changed_cb), plugin);
+       plugin->priv->sources = g_settings_get_strv (plugin->priv->settings,
+                                                  "official-sources");
 }
 
 /**
@@ -72,35 +90,28 @@ gs_plugin_get_deps (GsPlugin *plugin)
 void
 gs_plugin_destroy (GsPlugin *plugin)
 {
+       g_strfreev (plugin->priv->sources);
+       g_object_unref (plugin->priv->settings);
 }
 
 /**
- * gs_plugin_fedora_provenance_refine_app:
+ * gs_plugin_provenance_refine_app:
  */
 static void
-gs_plugin_fedora_provenance_refine_app (GsApp *app)
+gs_plugin_provenance_refine_app (GsPlugin *plugin, GsApp *app)
 {
        const gchar *origin;
+       const gchar * const *sources;
        guint i;
-       const gchar *valid[] = { "fedora",
-                                "fedora-debuginfo",
-                                "fedora-source",
-                                "koji-override-0",
-                                "koji-override-1",
-                                "rawhide",
-                                "rawhide-debuginfo",
-                                "rawhide-source",
-                                "updates",
-                                "updates-debuginfo",
-                                "updates-source",
-                                "updates-testing",
-                                "updates-testing-debuginfo",
-                                "updates-testing-source",
-                                NULL };
+
+       /* nothing to search */
+       sources = (const gchar * const *) plugin->priv->sources;
+       if (sources == NULL || sources[0] == NULL)
+               return;
 
        /* simple case */
        origin = gs_app_get_origin (app);
-       if (origin != NULL && g_strv_contains (valid, origin)) {
+       if (origin != NULL && g_strv_contains (sources, origin)) {
                gs_app_add_quirk (app, AS_APP_QUIRK_PROVENANCE);
                return;
        }
@@ -114,8 +125,8 @@ gs_plugin_fedora_provenance_refine_app (GsApp *app)
                return;
        if (g_str_has_prefix (origin + 1, "installed:"))
                origin += 10;
-       for (i = 0; valid[i] != NULL; i++) {
-               if (g_strcmp0 (origin + 1, valid[i]) == 0) {
+       for (i = 0; sources[i] != NULL; i++) {
+               if (g_strcmp0 (origin + 1, sources[i]) == 0) {
                        gs_app_add_quirk (app, AS_APP_QUIRK_PROVENANCE);
                        break;
                }
@@ -144,7 +155,7 @@ gs_plugin_refine (GsPlugin *plugin,
                app = GS_APP (l->data);
                if (gs_app_has_quirk (app, AS_APP_QUIRK_PROVENANCE))
                        continue;
-               gs_plugin_fedora_provenance_refine_app (app);
+               gs_plugin_provenance_refine_app (plugin, app);
        }
        return TRUE;
 }


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