[gnome-software] Automatically assign the management plugin from the AppStream metadata



commit d23159f059603448a4c843933b0788dacb8c86a4
Author: Richard Hughes <richard hughsie com>
Date:   Wed Jan 20 14:52:44 2016 +0000

    Automatically assign the management plugin from the AppStream metadata
    
    Also, remove any trace of bundles on the GsApp; the bundle ID is now set as
    the application source with the correct management value set.

 src/gs-app.c                              |   26 ---------------
 src/gs-app.h                              |    4 --
 src/plugins/gs-plugin-appstream.c         |   48 ++++++++++++++++++++++++++---
 src/plugins/gs-plugin-limba.c             |   43 ++++++-------------------
 src/plugins/gs-plugin-packagekit-refine.c |    6 +++
 5 files changed, 60 insertions(+), 67 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index 550b1a2..1ea6e22 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -102,7 +102,6 @@ struct _GsApp
        guint64                  kudos;
        gboolean                 to_be_installed;
        gboolean                 provenance;
-       AsBundle                *bundle;
        gboolean                 licence_is_free;
 };
 
@@ -2069,30 +2068,6 @@ gs_app_set_to_be_installed (GsApp *app, gboolean to_be_installed)
 }
 
 /**
- * gs_app_set_bundle:
- */
-void
-gs_app_set_bundle (GsApp *app, AsBundle *bundle)
-{
-       g_return_if_fail (GS_IS_APP (app));
-
-       /* set default bundle */
-       g_clear_object (&app->bundle);
-       if (bundle != NULL)
-               app->bundle = g_object_ref (bundle);
-}
-
-/**
- * gs_app_get_bundle:
- */
-AsBundle*
-gs_app_get_bundle (GsApp *app)
-{
-       g_return_val_if_fail (GS_IS_APP (app), NULL);
-       return app->bundle;
-}
-
-/**
  * gs_app_get_provenance:
  */
 gboolean
@@ -2322,7 +2297,6 @@ gs_app_dispose (GObject *object)
 {
        GsApp *app = GS_APP (object);
 
-       g_clear_object (&app->bundle);
        g_clear_object (&app->featured_pixbuf);
        g_clear_object (&app->icon);
        g_clear_object (&app->pixbuf);
diff --git a/src/gs-app.h b/src/gs-app.h
index f57e4a0..e26896b 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -250,10 +250,6 @@ void                gs_app_set_search_sort_key     (GsApp          *app,
                                                 guint           match_value);
 const gchar    *gs_app_get_search_sort_key     (GsApp          *app);
 
-AsBundle       *gs_app_get_bundle              (GsApp          *app);
-void            gs_app_set_bundle              (GsApp          *app,
-                                                AsBundle       *bundle);
-
 gboolean        gs_app_get_provenance          (GsApp          *app);
 void            gs_app_set_provenance          (GsApp          *app,
                                                 gboolean        provenance);
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index 0fb1031..9685905 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -468,6 +468,40 @@ gs_plugin_appstream_copy_metadata (GsApp *app, AsApp *item)
 }
 
 /**
+ * gs_plugin_refine_item_management_plugin:
+ */
+static void
+gs_plugin_refine_item_management_plugin (GsApp *app, AsApp *item)
+{
+       GPtrArray *bundles;
+       const gchar *management_plugin = NULL;
+       guint i;
+
+       /* find the default bundle kind */
+       bundles = as_app_get_bundles (item);
+       for (i = 0; i < bundles->len; i++) {
+               AsBundle *bundle = g_ptr_array_index (bundles, i);
+               if (as_bundle_get_kind (bundle) == AS_BUNDLE_KIND_XDG_APP) {
+                       management_plugin = "XgdApp";
+                       gs_app_add_source (app, as_bundle_get_id (bundle));
+                       break;
+               }
+               if (as_bundle_get_kind (bundle) == AS_BUNDLE_KIND_LIMBA) {
+                       management_plugin = "Limba";
+                       gs_app_add_source (app, as_bundle_get_id (bundle));
+                       break;
+               }
+       }
+
+       /* fall back to PackageKit */
+       if (management_plugin == NULL &&
+           as_app_get_pkgname_default (item) != NULL)
+               management_plugin = "PackageKit";
+       if (management_plugin != NULL)
+               gs_app_set_management_plugin (app, management_plugin);
+}
+
+/**
  * gs_plugin_refine_item:
  */
 static gboolean
@@ -509,6 +543,9 @@ gs_plugin_refine_item (GsPlugin *plugin, GsApp *app, AsApp *item, GError **error
                }
        }
 
+       /* set management plugin automatically */
+       gs_plugin_refine_item_management_plugin (app, item);
+
        /* set id */
        if (as_app_get_id (item) != NULL && gs_app_get_id (app) == NULL)
                gs_app_set_id (app, as_app_get_id (item));
@@ -556,6 +593,12 @@ gs_plugin_refine_item (GsPlugin *plugin, GsApp *app, AsApp *item, GError **error
                gs_app_add_kudo (app, GS_APP_KUDO_HAS_KEYWORDS);
        }
 
+       /* set origin */
+       if (as_app_get_origin (item) != NULL &&
+           gs_app_get_origin (app) == NULL) {
+               gs_app_set_origin (app, as_app_get_origin (item));
+       }
+
        /* set description */
        tmp = as_app_get_description (item, NULL);
        if (tmp != NULL) {
@@ -584,11 +627,6 @@ gs_plugin_refine_item (GsPlugin *plugin, GsApp *app, AsApp *item, GError **error
            gs_app_get_project_group (app) == NULL)
                gs_app_set_project_group (app, as_app_get_project_group (item));
 
-       /* set default bundle (if any) */
-       if (as_app_get_bundle_default (item) != NULL &&
-           gs_app_get_bundle (app) == NULL)
-               gs_app_set_bundle (app, as_app_get_bundle_default (item));
-
        /* this is a core application for the desktop and cannot be removed */
        if (_as_app_has_compulsory_for_desktop (item, "GNOME") &&
            gs_app_get_kind (app) == GS_APP_KIND_NORMAL)
diff --git a/src/plugins/gs-plugin-limba.c b/src/plugins/gs-plugin-limba.c
index a111c67..bccd918 100644
--- a/src/plugins/gs-plugin-limba.c
+++ b/src/plugins/gs-plugin-limba.c
@@ -70,29 +70,17 @@ gs_plugin_destroy (GsPlugin *plugin)
 static gboolean
 gs_plugin_refine_app (GsPlugin *plugin, GsApp *app, GError **error)
 {
-       AsBundle *bundle;
        LiPkgInfo *pki;
        GError *local_error = NULL;
 
-       bundle = gs_app_get_bundle (app);
-
-       /* check if we should process this application */
-       if (bundle == NULL)
-               return TRUE;
-       if (as_bundle_get_kind (bundle) != AS_BUNDLE_KIND_LIMBA)
-               return TRUE;
-
        pki = li_manager_get_software_by_pkid (plugin->priv->mgr,
-                                               as_bundle_get_id (bundle),
+                                               gs_app_get_source_default (app),
                                                &local_error);
        if (local_error != NULL) {
                g_propagate_error (error, local_error);
                return FALSE;
        }
 
-       /* we will handle installations and removals of this application */
-       gs_app_set_management_plugin (app, "Limba");
-
        if (pki == NULL)
                return TRUE;
 
@@ -124,7 +112,8 @@ gs_plugin_refine (GsPlugin *plugin,
        for (l = *list; l != NULL; l = l->next) {
                app = GS_APP (l->data);
 
-               if (gs_app_get_bundle (app) == NULL)
+               /* not us */
+               if (g_strcmp0 (gs_app_get_management_plugin (app), "Limba") != 0)
                        continue;
 
                if (!gs_plugin_refine_app (plugin, app, error))
@@ -145,23 +134,18 @@ gs_plugin_app_remove (GsPlugin *plugin,
                        GError **error)
 {
        g_autoptr(LiManager) mgr = NULL;
-       AsBundle *bundle;
        GError *local_error = NULL;
 
-       bundle = gs_app_get_bundle (app);
-
-       /* check if we can remove this application */
-       if (bundle == NULL)
-               return TRUE;
-       if (as_bundle_get_kind (bundle) != AS_BUNDLE_KIND_LIMBA)
+       /* not us */
+       if (g_strcmp0 (gs_app_get_management_plugin (app), "Limba") != 0)
                return TRUE;
 
        mgr = li_manager_new ();
 
        gs_app_set_state (app, AS_APP_STATE_REMOVING);
        li_manager_remove_software (mgr,
-                               as_bundle_get_id (bundle),
-                               &local_error);
+                                   gs_app_get_source_default (app),
+                                   &local_error);
        if (local_error != NULL) {
                gs_app_set_state (app, AS_APP_STATE_INSTALLED);
                g_propagate_error (error, local_error);
@@ -183,22 +167,17 @@ gs_plugin_app_install (GsPlugin *plugin,
                        GError **error)
 {
        g_autoptr(LiInstaller) inst = NULL;
-       AsBundle *bundle;
        GError *local_error = NULL;
 
-       bundle = gs_app_get_bundle (app);
-
-       /* check if we can install this application */
-       if (bundle == NULL)
-               return TRUE;
-       if (as_bundle_get_kind (bundle) != AS_BUNDLE_KIND_LIMBA)
+       /* not us */
+       if (g_strcmp0 (gs_app_get_management_plugin (app), "Limba") != 0)
                return TRUE;
 
        /* create new installer and select remote package */
        inst = li_installer_new ();
        li_installer_open_remote (inst,
-                               as_bundle_get_id (bundle),
-                               &local_error);
+                                 gs_app_get_source_default (app),
+                                 &local_error);
        if (local_error != NULL) {
                g_propagate_error (error, local_error);
                return FALSE;
diff --git a/src/plugins/gs-plugin-packagekit-refine.c b/src/plugins/gs-plugin-packagekit-refine.c
index f68cbc3..d393cb8 100644
--- a/src/plugins/gs-plugin-packagekit-refine.c
+++ b/src/plugins/gs-plugin-packagekit-refine.c
@@ -663,6 +663,8 @@ gs_plugin_refine_require_details (GsPlugin *plugin,
                app = GS_APP (l->data);
                if (gs_app_get_id_kind (app) == AS_ID_KIND_WEB_APP)
                        continue;
+               if (g_strcmp0 (gs_app_get_management_plugin (app), "PackageKit") != 0)
+                       continue;
                if (gs_app_get_source_id_default (app) == NULL)
                        continue;
                if (!gs_plugin_refine_app_needs_details (plugin, flags, app))
@@ -870,6 +872,8 @@ gs_plugin_refine (GsPlugin *plugin,
                app = GS_APP (l->data);
                if (gs_app_get_id_kind (app) == AS_ID_KIND_WEB_APP)
                        continue;
+               if (g_strcmp0 (gs_app_get_management_plugin (app), "PackageKit") != 0)
+                       continue;
                sources = gs_app_get_sources (app);
                if (sources->len == 0)
                        continue;
@@ -936,6 +940,8 @@ gs_plugin_refine (GsPlugin *plugin,
                app = GS_APP (l->data);
                if (gs_app_get_state (app) != AS_APP_STATE_UPDATABLE)
                        continue;
+               if (g_strcmp0 (gs_app_get_management_plugin (app), "PackageKit") != 0)
+                       continue;
                if (gs_plugin_refine_requires_update_details (app, flags))
                        updatedetails_all = g_list_prepend (updatedetails_all, app);
        }


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