[gnome-software] packagekit-refine: implement refining from package-name to package-id



commit 5d9053072c9760dd0cfd28deac655add1b500114
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Sun Sep 1 19:58:04 2013 +0200

    packagekit-refine: implement refining from package-name to package-id
    
    This is necessary to actually install the applications (or remove,
    in case we want to remove a featured app that didn't go through
    packagekit)
    
    https://bugzilla.gnome.org/show_bug.cgi?id=707185

 src/gs-application.c                      |    2 +-
 src/plugins/gs-plugin-packagekit-refine.c |  103 +++++++++++++++++++++++++----
 2 files changed, 92 insertions(+), 13 deletions(-)
---
diff --git a/src/gs-application.c b/src/gs-application.c
index 7a42056..ade3eba 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -158,7 +158,7 @@ gs_application_startup (GApplication *application)
         gs_plugin_loader_set_enabled (app->plugin_loader, "hardcoded-menu-spec", TRUE);
         gs_plugin_loader_set_enabled (app->plugin_loader, "local-ratings", TRUE);
         gs_plugin_loader_set_enabled (app->plugin_loader, "packagekit", TRUE);
-//        gs_plugin_loader_set_enabled (app->plugin_loader, "packagekit-refine", TRUE);
+        gs_plugin_loader_set_enabled (app->plugin_loader, "packagekit-refine", TRUE);
         gs_plugin_loader_set_enabled (app->plugin_loader, "appstream", TRUE);
         gs_plugin_loader_set_enabled (app->plugin_loader, "desktopdb", TRUE);
         gs_plugin_loader_set_enabled (app->plugin_loader, "datadir-apps", TRUE);
diff --git a/src/plugins/gs-plugin-packagekit-refine.c b/src/plugins/gs-plugin-packagekit-refine.c
index 1d97c43..a8c17bb 100644
--- a/src/plugins/gs-plugin-packagekit-refine.c
+++ b/src/plugins/gs-plugin-packagekit-refine.c
@@ -59,7 +59,7 @@ gs_plugin_initialize (GsPlugin *plugin)
 gdouble
 gs_plugin_get_priority (GsPlugin *plugin)
 {
-       return -150.0f;
+       return 150.0f;
 }
 
 /**
@@ -127,13 +127,13 @@ gs_plugin_packagekit_progress_cb (PkProgress *progress,
                gs_plugin_status_update (plugin, NULL, plugin_status);
 }
 
-/**
- * gs_plugin_packagekit_refine_app:
- */
 static gboolean
-gs_plugin_packagekit_refine_app (GsPlugin *plugin, GsApp *app, GCancellable *cancellable, GError **error)
+gs_plugin_packagekit_refine_package (GsPlugin      *plugin,
+                                    GsApp         *app,
+                                    const char    *package_name,
+                                    GCancellable  *cancellable,
+                                    GError       **error)
 {
-       const gchar *filename;
        const gchar *to_array[] = { NULL, NULL };
        gboolean ret = TRUE;
        GPtrArray *array = NULL;
@@ -142,14 +142,71 @@ gs_plugin_packagekit_refine_app (GsPlugin *plugin, GsApp *app, GCancellable *can
        PkPackage *package;
        PkResults *results = NULL;
 
-       filename = gs_app_get_metadata_item (app, "datadir-desktop-filename");
-       if (filename == NULL) {
-               g_warning ("refining %s without filename not supported -- "
-                          "perhaps not installed and no AppStream data",
-                          gs_app_get_id (app));
-               gs_app_set_state (app, GS_APP_STATE_UNKNOWN);
+       to_array[0] = package_name;
+       results = pk_client_resolve (plugin->priv->client,
+                                    pk_bitfield_from_enums (PK_FILTER_ENUM_NEWEST, -1),
+                                    (gchar **) to_array,
+                                    cancellable,
+                                    gs_plugin_packagekit_progress_cb, plugin,
+                                    error);
+       if (results == NULL) {
+               ret = FALSE;
+               goto out;
+       }
+
+       /* check error code */
+       error_code = pk_results_get_error_code (results);
+       if (error_code != NULL) {
+               ret = FALSE;
+               g_set_error (error,
+                            GS_PLUGIN_ERROR,
+                            GS_PLUGIN_ERROR_FAILED,
+                            "failed to resolve: %s, %s",
+                            pk_error_enum_to_string (pk_error_get_code (error_code)),
+                            pk_error_get_details (error_code));
                goto out;
        }
+
+       /* get results */
+       packages = pk_results_get_package_array (results);
+       if (packages->len == 1) {
+               package = g_ptr_array_index (packages, 0);
+               gs_app_set_metadata (app, "package-id", pk_package_get_id (package));
+               gs_app_set_state (app,
+                                 pk_package_get_info (package) == PK_INFO_ENUM_INSTALLED ?
+                                 GS_APP_STATE_INSTALLED :
+                                 GS_APP_STATE_AVAILABLE);
+       } else {
+               g_warning ("Failed to find one package for %s, %s, [%d]",
+                          gs_app_get_id (app), package_name, packages->len);
+       }
+out:
+       if (packages != NULL)
+               g_ptr_array_unref (packages);
+       if (error_code != NULL)
+               g_object_unref (error_code);
+       if (array != NULL)
+               g_ptr_array_unref (array);
+       if (results != NULL)
+               g_object_unref (results);
+       return ret;
+}
+
+static gboolean
+gs_plugin_packagekit_refine_from_desktop (GsPlugin      *plugin,
+                                         GsApp         *app,
+                                         const char    *filename,
+                                         GCancellable  *cancellable,
+                                         GError       **error)
+{
+       const gchar *to_array[] = { NULL, NULL };
+       gboolean ret = TRUE;
+       GPtrArray *array = NULL;
+       GPtrArray *packages = NULL;
+       PkError *error_code = NULL;
+       PkPackage *package;
+       PkResults *results = NULL;
+
        to_array[0] = filename;
        results = pk_client_search_files (plugin->priv->client,
                                          pk_bitfield_from_enums (PK_FILTER_ENUM_INSTALLED, -1),
@@ -198,6 +255,28 @@ out:
 }
 
 /**
+ * gs_plugin_packagekit_refine_app:
+ */
+static gboolean
+gs_plugin_packagekit_refine_app (GsPlugin *plugin, GsApp *app, GCancellable *cancellable, GError **error)
+{
+       const gchar *filename;
+       const gchar *package_name;
+
+       package_name = gs_app_get_metadata_item (app, "package-name");
+       if (package_name != NULL)
+               return gs_plugin_packagekit_refine_package (plugin, app, package_name, cancellable, error);
+
+       filename = gs_app_get_metadata_item (app, "datadir-desktop-filename");
+       if (filename != NULL)
+               return gs_plugin_packagekit_refine_from_desktop (plugin, app, filename, cancellable, error);
+
+       g_warning ("refining %s without .desktop filename or package-name not supported",
+                  gs_app_get_id (app));
+       return TRUE;
+}
+
+/**
  * gs_plugin_refine:
  */
 gboolean


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