[gnome-software] Get the available updates using the plugins, rather than just using PackageKit
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Get the available updates using the plugins, rather than just using PackageKit
- Date: Mon, 11 Mar 2013 20:11:16 +0000 (UTC)
commit 336a4fae5e34b2b60aa3411c3ae3434c44a08307
Author: Richard Hughes <richard hughsie com>
Date: Mon Mar 11 19:30:30 2013 +0000
Get the available updates using the plugins, rather than just using PackageKit
po/POTFILES.in | 1 +
src/gs-main.c | 428 +++---------------------------------
src/gs-plugin-loader.c | 40 +++-
src/gs-self-test.c | 6 +-
src/plugins/README | 2 +
src/plugins/gs-plugin-packagekit.c | 129 ++++++++++-
6 files changed, 189 insertions(+), 417 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 263ab71..0f8545c 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -2,3 +2,4 @@ src/gnome-software.desktop.in
[type: gettext/glade]src/gnome-software.ui
src/gs-app-widget.c
src/gs-main.c
+src/gs-plugin-loader.c
diff --git a/src/gs-main.c b/src/gs-main.c
index e53448b..dd4b349 100644
--- a/src/gs-main.c
+++ b/src/gs-main.c
@@ -53,12 +53,10 @@ typedef struct {
GtkApplication *application;
GtkBuilder *builder;
GtkIconSize custom_icon_size;
- PkDesktop *desktop;
PkTask *task;
guint waiting_tab_id;
EggListBox *list_box_installed;
EggListBox *list_box_updates;
- GsApp *os_update;
GtkCssProvider *provider;
gboolean ignore_primary_buttons;
GsPluginLoader *plugin_loader;
@@ -424,274 +422,17 @@ gs_main_app_widget_button_clicked_cb (GsAppWidget *app_widget, GsMainPrivate *pr
// gs_app_widget_set_status (app_widget, "Installing...");
}
-/**
- * gs_main_installed_add_package:
- **/
-static void
-gs_main_installed_add_package (GsMainPrivate *priv, PkPackage *pkg)
-{
- const gchar *description;
- gchar *update_changelog = NULL;
- gchar *update_text = NULL;
- GdkPixbuf *pixbuf;
- GsApp *app = NULL;
- GtkWidget *widget;
-
- widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_new"));
- pixbuf = gtk_widget_render_icon_pixbuf (widget,
- "icon-missing",
- priv->custom_icon_size);
-
- widget = gs_app_widget_new ();
- g_signal_connect (widget, "button-clicked",
- G_CALLBACK (gs_main_app_widget_button_clicked_cb),
- priv);
- gs_app_widget_set_kind (GS_APP_WIDGET (widget),
- GS_APP_WIDGET_KIND_UPDATE);
-
- /* try to get update data if it's present */
- g_object_get (pkg,
- "update-text", &update_text,
- "update-changelog", &update_changelog,
- NULL);
- if (update_text != NULL && update_text[0] != '\0')
- description = update_text;
- else if (update_changelog != NULL && update_changelog[0] != '\0')
- description = update_changelog;
- else
- description = pk_package_get_summary (pkg);
- gs_app_set_summary (app, description);
- gs_app_set_id (app, pk_package_get_id (pkg));
- gs_app_set_name (app, pk_package_get_summary (pkg));
- gs_app_set_pixbuf (app, pixbuf);
- gs_app_set_version (app, pk_package_get_version (pkg));
- gs_app_widget_set_app (GS_APP_WIDGET (widget), app);
- gtk_container_add (GTK_CONTAINER (priv->list_box_updates), widget);
- gtk_widget_show (widget);
- if (pixbuf != NULL)
- g_object_unref (pixbuf);
- g_object_unref (app);
- g_free (update_text);
- g_free (update_changelog);
-}
-
-/**
- * gs_main_installed_add_desktop_file:
- **/
-static void
-gs_main_installed_add_desktop_file (GsMainPrivate *priv,
- PkPackage *pkg,
- const gchar *desktop_file)
-{
- gboolean ret;
- gchar *comment = NULL;
- gchar *icon = NULL;
- gchar *name = NULL;
- gchar *version_tmp = NULL;
- GdkPixbuf *pixbuf = NULL;
- GError *error = NULL;
- GKeyFile *key_file;
- GtkWidget *widget;
- GsApp *app = NULL;
-
- /* load desktop file */
- key_file = g_key_file_new ();
- ret = g_key_file_load_from_file (key_file,
- desktop_file,
- G_KEY_FILE_NONE,
- &error);
- if (!ret) {
- g_warning ("failed to get files for %s: %s",
- pk_package_get_id (pkg),
- error->message);
- g_error_free (error);
- goto out;
- }
-
- /* get desktop data */
- name = g_key_file_get_string (key_file,
- G_KEY_FILE_DESKTOP_GROUP,
- G_KEY_FILE_DESKTOP_KEY_NAME,
- NULL);
- if (name == NULL)
- name = g_strdup (pk_package_get_name (pkg));
- icon = g_key_file_get_string (key_file,
- G_KEY_FILE_DESKTOP_GROUP,
- G_KEY_FILE_DESKTOP_KEY_ICON,
- NULL);
- if (icon == NULL)
- icon = g_strdup (GTK_STOCK_MISSING_IMAGE);
-
- /* prefer the update text */
- g_object_get (pkg,
- "update-text", &comment,
- NULL);
- if (comment == NULL || comment[0] == '\0') {
- g_object_get (pkg,
- "update-changelog", &comment,
- NULL);
- }
- if (comment == NULL || comment[0] == '\0') {
- comment = g_key_file_get_string (key_file,
- G_KEY_FILE_DESKTOP_GROUP,
- G_KEY_FILE_DESKTOP_KEY_COMMENT,
- NULL);
- }
- if (comment == NULL)
- comment = g_strdup (pk_package_get_summary (pkg));
-
- /* load icon */
- if (icon != NULL && icon[0] == '/') {
- pixbuf = gdk_pixbuf_new_from_file_at_size (icon,
- GS_MAIN_ICON_SIZE,
- GS_MAIN_ICON_SIZE,
- &error);
- } else {
- pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
- icon,
- GS_MAIN_ICON_SIZE,
- GTK_ICON_LOOKUP_USE_BUILTIN |
- GTK_ICON_LOOKUP_FORCE_SIZE,
- &error);
- if (pixbuf == NULL) {
- widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_new"));
- pixbuf = gtk_widget_render_icon_pixbuf (widget,
- icon,
- priv->custom_icon_size);
- }
- }
- if (pixbuf == NULL) {
- widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_new"));
- pixbuf = gtk_widget_render_icon_pixbuf (widget,
- GTK_STOCK_MISSING_IMAGE,
- priv->custom_icon_size);
- g_warning ("Failed to open theme icon or builtin %s: %s",
- icon,
- error->message);
- g_error_free (error);
- }
-
- /* add to list store */
- widget = gs_app_widget_new ();
- g_signal_connect (widget, "button-clicked",
- G_CALLBACK (gs_main_app_widget_button_clicked_cb),
- priv);
- gs_app_widget_set_kind (GS_APP_WIDGET (widget),
- GS_APP_WIDGET_KIND_UPDATE);
- app = gs_app_new (pk_package_get_id (pkg));
- gs_app_set_summary (app, comment);
- gs_app_set_name (app, name);
- gs_app_set_pixbuf (app, pixbuf);
- gs_app_set_version (app, pk_package_get_version (pkg));
- gs_app_widget_set_app (GS_APP_WIDGET (widget), app);
- gtk_container_add (GTK_CONTAINER (priv->list_box_updates), widget);
- gtk_widget_show (widget);
-out:
- if (app != NULL)
- g_object_unref (app);
- if (pixbuf != NULL)
- g_object_unref (pixbuf);
- g_key_file_unref (key_file);
- g_free (name);
- g_free (comment);
- g_free (icon);
- g_free (version_tmp);
-}
-
+#if 0
/**
* gs_main_installed_add_os_update:
**/
static void
gs_main_installed_add_os_update (GsMainPrivate *priv, PkPackage *pkg)
{
- GdkPixbuf *pixbuf = NULL;
- GError *error = NULL;
- GtkWidget *widget;
-
- /* try to find existing OS Update entry */
- if (priv->os_update != NULL) {
- gs_app_set_name (priv->os_update, _("OS Updates"));
- goto out;
- }
-
- /* add OS Update entry */
- widget = gs_app_widget_new ();
- pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
- "software-update-available-symbolic",
- GS_MAIN_ICON_SIZE,
- GTK_ICON_LOOKUP_USE_BUILTIN |
- GTK_ICON_LOOKUP_FORCE_SIZE,
- &error);
- if (pixbuf == NULL) {
- g_warning ("Failed to find software-update-available-symbolic: %s",
- error->message);
- g_error_free (error);
- }
-
- priv->os_update = gs_app_new ("");
- g_signal_connect (widget, "button-clicked",
- G_CALLBACK (gs_main_app_widget_button_clicked_cb),
- priv);
- gs_app_widget_set_kind (GS_APP_WIDGET (widget),
- GS_APP_WIDGET_KIND_UPDATE);
- gs_app_set_name (priv->os_update, _("OS Update"));
- gs_app_set_summary (priv->os_update, _("Includes performance, stability and security improvements for
all users"));
- gs_app_set_pixbuf (priv->os_update, pixbuf);
- gs_app_set_version (priv->os_update, "3.4.3");
- gs_app_widget_set_app (GS_APP_WIDGET (widget), priv->os_update);
-
/* TRANSLATORS: the update requires the user to reboot the computer */
gs_app_widget_set_status (GS_APP_WIDGET (widget), _("Requires restart"));
- gtk_container_add (GTK_CONTAINER (priv->list_box_updates), widget);
- gtk_widget_show_all (widget);
- g_object_add_weak_pointer (G_OBJECT (widget),
- (gpointer *) &widget);
-out:
- if (pixbuf != NULL)
- g_object_unref (pixbuf);
-}
-
-/**
- * gs_main_installed_add_package:
- **/
-static void
-gs_main_installed_add_item (GsMainPrivate *priv, PkPackage *pkg)
-{
- const gchar *desktop_file;
- GError *error = NULL;
- GPtrArray *files = NULL;
- guint i;
-
- /* try to get the list of desktop files for this package */
- files = pk_desktop_get_shown_for_package (priv->desktop,
- pk_package_get_name (pkg),
- &error);
- if (files == NULL) {
- g_warning ("failed to get files for %s: %s",
- pk_package_get_id (pkg),
- error->message);
- g_error_free (error);
- gs_main_installed_add_package (priv, pkg);
- goto out;
- }
- if (files->len == 0) {
- g_debug ("not an application %s",
- pk_package_get_id (pkg));
- gs_main_installed_add_os_update (priv, pkg);
- goto out;
- }
-
- /* add each of the desktop files */
- for (i = 0; i < files->len; i++) {
- desktop_file = g_ptr_array_index (files, i);
- gs_main_installed_add_desktop_file (priv,
- pkg,
- desktop_file);
- }
-out:
- if (files != NULL)
- g_ptr_array_unref (files);
}
+#endif
/**
* _gtk_container_remove_all_cb:
@@ -715,140 +456,46 @@ _gtk_container_remove_all (GtkContainer *container)
}
/**
- * gs_main_get_update_details_cb:
- **/
-static void
-gs_main_get_update_details_cb (PkPackageSack *sack,
- GAsyncResult *res,
- GsMainPrivate *priv)
-{
- gboolean ret;
- GError *error = NULL;
- GPtrArray *array = NULL;
- guint i;
- PkPackage *package;
-
- /* add packages */
- ret = pk_package_sack_merge_generic_finish (sack, res, &error);
- if (!ret) {
- g_warning ("failed to get-update-details: %s", error->message);
- g_error_free (error);
- goto out;
- }
-
- /* clear existing updates */
- array = pk_package_sack_get_array (sack);
- for (i = 0; i < array->len; i++) {
- package = g_ptr_array_index (array, i);
- g_debug ("add update %s", pk_package_get_id (package));
- gs_main_installed_add_item (priv, package);
- }
-out:
- if (array != NULL)
- g_ptr_array_unref (array);
-}
-
-/**
- * gs_main_is_package_an_app:
- **/
-static gboolean
-gs_main_is_package_an_app (GsMainPrivate *priv, PkPackage *pkg)
-{
- gboolean ret = FALSE;
- GPtrArray *files;
-
- files = pk_desktop_get_shown_for_package (priv->desktop,
- pk_package_get_name (pkg),
- NULL);
- if (files == NULL)
- goto out;
- if (files->len == 0)
- goto out;
- ret = TRUE;
-out:
- if (files != NULL)
- g_ptr_array_unref (files);
- return ret;
-}
-
-/**
* gs_main_get_updates_cb:
**/
static void
-gs_main_get_updates_cb (PkClient *client,
+gs_main_get_updates_cb (GsPluginLoader *plugin_loader,
GAsyncResult *res,
GsMainPrivate *priv)
{
- gboolean ret;
GError *error = NULL;
- GPtrArray *array = NULL;
- guint i;
- PkError *error_code = NULL;
- PkPackage *package;
- PkPackageSack *sack_apps = NULL;
- PkPackageSack *sack_system = NULL;
- PkResults *results;
- gboolean got_one_system_update = FALSE;
+ GList *list;
+ GList *l;
+ GsApp *app;
+ GtkWidget *widget;
/* get the results */
- results = pk_client_generic_finish (client, res, &error);
- if (results == NULL) {
- g_warning ("failed to get-updates: %s", error->message);
+ list = gs_plugin_loader_get_updates_finish (plugin_loader, res, &error);
+ if (list == NULL) {
+ g_warning ("failed to get updates: %s", error->message);
g_error_free (error);
goto out;
}
-
- /* check error code */
- error_code = pk_results_get_error_code (results);
- if (error_code != NULL) {
- g_warning ("failed to get-packages: %s, %s",
- pk_error_enum_to_string (pk_error_get_code (error_code)),
- pk_error_get_details (error_code));
- goto out;
- }
-
- /* filter out the requests for apps and os-updates, and do the
- * latter after the UI has loaded */
- sack_apps = pk_package_sack_new ();
- sack_system = pk_package_sack_new ();
- array = pk_results_get_package_array (results);
- for (i = 0; i < array->len; i++) {
- package = g_ptr_array_index (array, i);
- ret = gs_main_is_package_an_app (priv, package);
- if (ret) {
- pk_package_sack_add_package (sack_apps, package);
- } else {
- /* ensure we load at least one of the os updates
- * in the fast path */
- if (!got_one_system_update) {
- got_one_system_update = TRUE;
- pk_package_sack_add_package (sack_apps, package);
- } else {
- pk_package_sack_add_package (sack_system, package);
- }
- }
+ for (l = list; l != NULL; l = l->next) {
+ app = GS_APP (l->data);
+ g_debug ("adding update %s", gs_app_get_id (app));
+ widget = gs_app_widget_new ();
+ g_signal_connect (widget, "button-clicked",
+ G_CALLBACK (gs_main_app_widget_button_clicked_cb),
+ priv);
+ gs_app_widget_set_kind (GS_APP_WIDGET (widget),
+ GS_APP_WIDGET_KIND_UPDATE);
+ gs_app_widget_set_app (GS_APP_WIDGET (widget), app);
+ gtk_container_add (GTK_CONTAINER (priv->list_box_updates), widget);
+ gtk_widget_show (widget);
}
- /* get the update details */
- pk_package_sack_get_update_detail_async (sack_apps,
- priv->cancellable,
- (PkProgressCallback) gs_main_progress_cb, priv,
- (GAsyncReadyCallback) gs_main_get_update_details_cb, priv);
- pk_package_sack_get_update_detail_async (sack_system,
- priv->cancellable,
- NULL, priv,
- (GAsyncReadyCallback) gs_main_get_update_details_cb, priv);
+ /* focus back to the text extry */
+ widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "entry_search"));
+ gtk_widget_grab_focus (widget);
out:
- if (array != NULL)
- g_ptr_array_unref (array);
- if (error_code != NULL)
- g_object_unref (error_code);
- if (sack_apps != NULL)
- g_object_unref (sack_apps);
- if (sack_system != NULL)
- g_object_unref (sack_system);
- if (results != NULL)
- g_object_unref (results);
+ if (list != NULL)
+ g_list_free_full (list, (GDestroyNotify) g_object_unref);
}
/**
@@ -918,15 +565,10 @@ gs_main_get_installed (GsMainPrivate *priv)
static void
gs_main_get_updates (GsMainPrivate *priv)
{
- PkBitfield filter;
_gtk_container_remove_all (GTK_CONTAINER (priv->list_box_updates));
- filter = pk_bitfield_from_enums (PK_FILTER_ENUM_ARCH,
- -1);
- pk_client_get_updates_async (PK_CLIENT(priv->task),
- filter,
- priv->cancellable,
- (PkProgressCallback) gs_main_progress_cb, priv,
- (GAsyncReadyCallback) gs_main_get_updates_cb, priv);
+ gs_plugin_loader_get_updates_async (priv->plugin_loader,
+ priv->cancellable,
+ (GAsyncReadyCallback) gs_main_get_updates_cb, priv);
}
@@ -1465,15 +1107,6 @@ main (int argc, char **argv)
"background", FALSE,
NULL);
- /* get localized data from sqlite database */
- priv->desktop = pk_desktop_new ();
- ret = pk_desktop_open_database (priv->desktop, &error);
- if (!ret) {
- g_warning ("failed to open database: %s", error->message);
- g_error_free (error);
- goto out;
- }
-
/* load the plugins */
priv->plugin_loader = gs_plugin_loader_new ();
gs_plugin_loader_set_location (priv->plugin_loader, NULL);
@@ -1499,7 +1132,6 @@ out:
if (priv != NULL) {
g_object_unref (priv->plugin_loader);
g_object_unref (priv->task);
- g_object_unref (priv->desktop);
g_object_unref (priv->cancellable);
g_object_unref (priv->application);
if (priv->provider != NULL)
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 0c4d926..44e0aaa 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -21,6 +21,8 @@
#include "config.h"
+#include <glib/gi18n.h>
+
#include "gs-plugin-loader.h"
#include "gs-plugin.h"
@@ -160,7 +162,14 @@ gs_plugin_loader_run_results (GsPluginLoader *plugin_loader,
if (!ret)
goto out;
- /* success */
+ /* no results */
+ if (list == NULL) {
+ g_set_error (error,
+ GS_PLUGIN_LOADER_ERROR,
+ GS_PLUGIN_LOADER_ERROR_FAILED,
+ "no updates to show");
+ goto out;
+ }
out:
if (!ret) {
g_list_free_full (list, (GDestroyNotify) g_object_unref);
@@ -257,6 +266,7 @@ cd_plugin_loader_get_updates_thread_cb (GSimpleAsyncResult *res,
GCancellable *cancellable)
{
gboolean has_os_update = FALSE;
+ GdkPixbuf *pixbuf = NULL;
GError *error = NULL;
GList *l;
GsApp *app;
@@ -288,7 +298,8 @@ cd_plugin_loader_get_updates_thread_cb (GSimpleAsyncResult *res,
/* smush them all together */
if (has_os_update) {
- str_summary = g_string_new ("This updates the system:\n");
+ str_summary = g_string_new (_("Includes performance, stability and security improvements for
all users"));
+ g_string_append (str_summary, "\n\n\n");
str_id = g_string_new ("os-update:");
for (l = state->list; l != NULL; l = l->next) {
app_tmp = GS_APP (l->data);
@@ -296,17 +307,33 @@ cd_plugin_loader_get_updates_thread_cb (GSimpleAsyncResult *res,
continue;
g_string_append_printf (str_id, "%s,",
gs_app_get_id (app_tmp));
- g_string_append_printf (str_summary, "%s\n",
- gs_app_get_summary (app_tmp));
+ g_string_append_printf (str_summary, "%s:\n\n%s\n\n",
+ gs_app_get_metadata_item (app_tmp, "update-name"),
+ gs_app_get_metadata_item (app_tmp, "update-details"));
}
g_string_truncate (str_id, str_id->len - 1);
g_string_truncate (str_summary, str_summary->len - 1);
+ /* load icon */
+ pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
+ "software-update-available-symbolic",
+ 64,
+ GTK_ICON_LOOKUP_USE_BUILTIN |
+ GTK_ICON_LOOKUP_FORCE_SIZE,
+ &error);
+ if (pixbuf == NULL) {
+ g_warning ("Failed to find software-update-available-symbolic: %s",
+ error->message);
+ g_error_free (error);
+ }
+
/* create new meta object */
app = gs_app_new (str_id->str);
gs_app_set_kind (app, GS_APP_KIND_OS_UPDATE);
- gs_app_set_name (app, "OS Update");
+ gs_app_set_name (app, _("OS Updates"));
gs_app_set_summary (app, str_summary->str);
+ gs_app_set_version (app, "3.6.3");
+ gs_app_set_pixbuf (app, pixbuf);
gs_plugin_add_app (&state->list, app);
/* remove any packages that are not proper applications or
@@ -327,11 +354,12 @@ cd_plugin_loader_get_updates_thread_cb (GSimpleAsyncResult *res,
state->ret = TRUE;
cd_plugin_loader_get_all_state_finish (state, NULL);
out:
+ if (pixbuf != NULL)
+ g_object_unref (pixbuf);
if (str_id != NULL)
g_string_free (str_id, TRUE);
if (str_summary != NULL)
g_string_free (str_summary, TRUE);
- return;
}
/**
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index eb1d420..3d7328c 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -110,12 +110,12 @@ gs_plugin_loader_func (void)
list = gs_plugin_loader_get_updates (loader, NULL, &error);
g_assert_no_error (error);
g_assert (list != NULL);
- g_assert_cmpint (_status_changed_cnt, ==, 2);
+ g_assert_cmpint (_status_changed_cnt, >=, 1);
g_assert_cmpint (g_list_length (list), ==, 2);
app = g_list_nth_data (list, 0);
g_assert_cmpstr (gs_app_get_id (app), ==,
"os-update:gnome-boxes-libs;0.0.1;i386;updates-testing,libvirt-glib-devel;0.0.1;noarch;fedora");
- g_assert_cmpstr (gs_app_get_name (app), ==, "OS Update");
- g_assert_cmpstr (gs_app_get_summary (app), ==, "This updates the system:\nDo not segfault when using
newer versons of libvirt.\nFix several memory leaks.");
+ g_assert_cmpstr (gs_app_get_name (app), ==, "OS Updates");
+ g_assert_cmpstr (gs_app_get_summary (app), ==, "Includes performance, stability and security
improvements for all users\nDo not segfault when using newer versons of libvirt.\nFix several memory leaks.");
g_assert_cmpint (gs_app_get_kind (app), ==, GS_APP_KIND_OS_UPDATE);
app = g_list_nth_data (list, 1);
diff --git a/src/plugins/README b/src/plugins/README
index 24af80c..9342a76 100644
--- a/src/plugins/README
+++ b/src/plugins/README
@@ -88,6 +88,8 @@ Refines: <nothing>
Sets: {package-id}
{package-name}
{package-summary}
+ {update-name}
+ {update-details}
== desktopdb ==
Overview: Uses the PackageKit desktop.db cache to map package names to
diff --git a/src/plugins/gs-plugin-packagekit.c b/src/plugins/gs-plugin-packagekit.c
index ddb236e..74ecfa2 100644
--- a/src/plugins/gs-plugin-packagekit.c
+++ b/src/plugins/gs-plugin-packagekit.c
@@ -138,11 +138,15 @@ gs_plugin_add_search (GsPlugin *plugin,
}
/**
- * gs_plugin_packagekit_add_results:
+ * gs_plugin_packagekit_add_installed_results:
*/
static gboolean
-gs_plugin_packagekit_add_results (GsPlugin *plugin, GList **list, PkResults *results)
+gs_plugin_packagekit_add_installed_results (GsPlugin *plugin,
+ GList **list,
+ PkResults *results,
+ GError **error)
{
+ gboolean ret = TRUE;
GPtrArray *array = NULL;
GsApp *app;
guint i;
@@ -152,9 +156,13 @@ gs_plugin_packagekit_add_results (GsPlugin *plugin, GList **list, PkResults *res
/* check error code */
error_code = pk_results_get_error_code (results);
if (error_code != NULL) {
- g_warning ("failed to get-packages: %s, %s",
- pk_error_enum_to_string (pk_error_get_code (error_code)),
- pk_error_get_details (error_code));
+ ret = FALSE;
+ g_set_error (error,
+ GS_PLUGIN_ERROR,
+ GS_PLUGIN_ERROR_FAILED,
+ "failed to get-packages: %s, %s",
+ pk_error_enum_to_string (pk_error_get_code (error_code)),
+ pk_error_get_details (error_code));
goto out;
}
@@ -182,7 +190,7 @@ out:
g_object_unref (error_code);
if (array != NULL)
g_ptr_array_unref (array);
- return TRUE;
+ return ret;
}
/**
@@ -218,7 +226,10 @@ gs_plugin_add_installed (GsPlugin *plugin,
}
/* add results */
- ret = gs_plugin_packagekit_add_results (plugin, list, results);
+ ret = gs_plugin_packagekit_add_installed_results (plugin,
+ list,
+ results,
+ error);
if (!ret)
goto out;
out:
@@ -228,6 +239,76 @@ out:
}
/**
+ * gs_plugin_packagekit_add_updates_results:
+ */
+static gboolean
+gs_plugin_packagekit_add_updates_results (GsPlugin *plugin,
+ GList **list,
+ PkResults *results,
+ GError **error)
+{
+ gboolean ret = TRUE;
+ gchar *package_id;
+ gchar **split;
+ gchar *update_text;
+ GPtrArray *array = NULL;
+ GsApp *app;
+ guint i;
+ PkError *error_code = NULL;
+ PkUpdateDetail *update_detail;
+
+ /* 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 get-update-details: %s, %s",
+ pk_error_enum_to_string (pk_error_get_code (error_code)),
+ pk_error_get_details (error_code));
+ goto out;
+ }
+
+ /* get data */
+ array = pk_results_get_update_detail_array (results);
+ if (array->len == 0) {
+ ret = FALSE;
+ g_set_error_literal (error,
+ GS_PLUGIN_ERROR,
+ GS_PLUGIN_ERROR_FAILED,
+ "no update details were returned");
+ goto out;
+ }
+ for (i = 0; i < array->len; i++) {
+ update_detail = g_ptr_array_index (array, i);
+ g_object_get (update_detail,
+ "package-id", &package_id,
+ "update-text", &update_text,
+ NULL);
+ split = pk_package_id_split (package_id);
+ app = gs_app_new (package_id);
+ gs_app_set_metadata (app, "package-id", package_id);
+ gs_app_set_metadata (app, "package-name", split[PK_PACKAGE_ID_NAME]);
+ gs_app_set_metadata (app, "update-name", split[PK_PACKAGE_ID_NAME]);
+ gs_app_set_metadata (app, "update-details", update_text);
+ gs_app_set_version (app, split[PK_PACKAGE_ID_VERSION]);
+ gs_app_set_state (app, GS_APP_STATE_INSTALLED);
+ gs_app_set_kind (app, GS_APP_KIND_PACKAGE);
+ gs_plugin_add_app (list, app);
+ g_free (package_id);
+ g_free (update_text);
+ g_strfreev (split);
+ }
+out:
+ if (error_code != NULL)
+ g_object_unref (error_code);
+ if (array != NULL)
+ g_ptr_array_unref (array);
+ return ret;
+}
+
+/**
* gs_plugin_add_updates:
*/
gboolean
@@ -237,15 +318,18 @@ gs_plugin_add_updates (GsPlugin *plugin,
GError **error)
{
gboolean ret = TRUE;
+ gchar **package_ids = NULL;
PkBitfield filter;
- PkResults *results;
+ PkPackageSack *sack = NULL;
+ PkResults *results = NULL;
+ PkResults *results2 = NULL;
/* update UI as this might take some time */
gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_WAITING);
/* do sync call */
filter = pk_bitfield_from_enums (PK_FILTER_ENUM_ARCH, -1);
- results = pk_client_get_updates (PK_CLIENT(plugin->priv->task),
+ results = pk_client_get_updates (PK_CLIENT (plugin->priv->task),
filter,
cancellable,
gs_plugin_packagekit_progress_cb, plugin,
@@ -255,11 +339,36 @@ gs_plugin_add_updates (GsPlugin *plugin,
goto out;
}
+ /* get update details */
+ sack = pk_results_get_package_sack (results);
+ if (pk_package_sack_get_size (sack) == 0)
+ goto out;
+ package_ids = pk_package_sack_get_ids (sack);
+ results2 = pk_client_get_update_detail (PK_CLIENT (plugin->priv->task),
+ package_ids,
+ cancellable,
+ gs_plugin_packagekit_progress_cb, plugin,
+ error);
+ if (results2 == NULL) {
+ ret = FALSE;
+ goto out;
+ }
+
/* add results */
- ret = gs_plugin_packagekit_add_results (plugin, list, results);
+ ret = gs_plugin_packagekit_add_updates_results (plugin,
+ list,
+ results2,
+ error);
+ if (!ret)
+ goto out;
out:
+ g_strfreev (package_ids);
+ if (sack != NULL)
+ g_object_unref (sack);
if (results != NULL)
g_object_unref (results);
+ if (results2 != NULL)
+ g_object_unref (results2);
return ret;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]