[gnome-software/603-gnome-software-reports-unknown-error-when-there-is-a-signing-issue: 90/91] packagekit: Ask the user what to do when there's a package signing issue




commit f9ebb007abe4d8c00a1f180029a1f4ab0bdf1546
Author: Milan Crha <mcrha redhat com>
Date:   Fri Jul 9 12:34:47 2021 +0200

    packagekit: Ask the user what to do when there's a package signing issue
    
    Ask the user what to do, rather than error out with a cryptic error
    message "could not do untrusted question as no klass support".
    
    Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/603

 plugins/packagekit/gs-packagekit-task.c           | 340 ++++++++++++++++++++++
 plugins/packagekit/gs-packagekit-task.h           |  32 ++
 plugins/packagekit/gs-plugin-packagekit-refresh.c |   7 +-
 plugins/packagekit/gs-plugin-packagekit.c         |  35 ++-
 plugins/packagekit/meson.build                    |   2 +
 po/POTFILES.in                                    |   1 +
 6 files changed, 399 insertions(+), 18 deletions(-)
---
diff --git a/plugins/packagekit/gs-packagekit-task.c b/plugins/packagekit/gs-packagekit-task.c
new file mode 100644
index 000000000..45c2e5bcf
--- /dev/null
+++ b/plugins/packagekit/gs-packagekit-task.c
@@ -0,0 +1,340 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ * vi:set noexpandtab tabstop=8 shiftwidth=8:
+ *
+ * Copyright (C) 2021 Red Hat <www.redhat.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include "config.h"
+
+#include <glib/gi18n-lib.h>
+
+#include "gs-packagekit-task.h"
+
+typedef struct _GsPackageKitTaskPrivate {
+       GWeakRef plugin_weakref; /* GsPlugin * */
+       GsPluginAction action;
+} GsPackageKitTaskPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (GsPackageKitTask, gs_packagekit_task, PK_TYPE_TASK)
+
+static void
+do_not_expand (GtkWidget *child,
+              gpointer data)
+{
+       gtk_container_child_set (GTK_CONTAINER (gtk_widget_get_parent (child)),
+                                child, "expand", FALSE, "fill", FALSE, NULL);
+}
+
+static gboolean
+unset_focus (GtkWidget *widget,
+            GdkEvent *event,
+            gpointer data)
+{
+       if (GTK_IS_WINDOW (widget))
+               gtk_window_set_focus (GTK_WINDOW (widget), NULL);
+       return FALSE;
+}
+
+static void
+insert_details_widget (GtkMessageDialog *dialog,
+                      const gchar *details)
+{
+       GtkWidget *message_area, *sw, *label;
+       GtkWidget *box, *tv;
+       GtkTextBuffer *buffer;
+       GList *children;
+       GtkStyleContext *style_context;
+       g_autoptr(GError) error = NULL;
+       g_autoptr(GtkCssProvider) css_provider = NULL;
+       PangoAttrList *attr_list;
+
+       g_assert (GTK_IS_MESSAGE_DIALOG (dialog));
+       g_assert (details != NULL);
+
+       gtk_window_set_resizable (GTK_WINDOW (dialog), TRUE);
+
+       message_area = gtk_message_dialog_get_message_area (dialog);
+       g_assert (GTK_IS_BOX (message_area));
+       /* make the hbox expand */
+       box = gtk_widget_get_parent (message_area);
+       gtk_container_child_set (GTK_CONTAINER (gtk_widget_get_parent (box)), box,
+                                "expand", TRUE, "fill", TRUE, NULL);
+       /* make the labels not expand */
+       gtk_container_foreach (GTK_CONTAINER (message_area), do_not_expand, NULL);
+
+       /* Find the secondary label and set its width_chars.   */
+       /* Otherwise the label will tend to expand vertically. */
+       children = gtk_container_get_children (GTK_CONTAINER (message_area));
+       if (children && children->next && GTK_IS_LABEL (children->next->data)) {
+               gtk_label_set_width_chars (GTK_LABEL (children->next->data), 40);
+       }
+
+       label = gtk_label_new (_("Details"));
+       gtk_widget_set_halign (label, GTK_ALIGN_START);
+       gtk_widget_set_visible (label, TRUE);
+       attr_list = pango_attr_list_new ();
+       pango_attr_list_insert (attr_list, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
+       gtk_label_set_attributes (GTK_LABEL (label), attr_list);
+       pango_attr_list_unref (attr_list);
+       gtk_container_add (GTK_CONTAINER (message_area), label);
+
+       sw = gtk_scrolled_window_new (NULL, NULL);
+       gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
+                                            GTK_SHADOW_IN);
+       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
+                                       GTK_POLICY_NEVER,
+                                       GTK_POLICY_AUTOMATIC);
+       gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (sw), 150);
+       gtk_widget_set_visible (sw, TRUE);
+
+       tv = gtk_text_view_new ();
+       buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (tv));
+       gtk_text_view_set_editable (GTK_TEXT_VIEW (tv), FALSE);
+       gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (tv), GTK_WRAP_WORD);
+       gtk_style_context_add_class (gtk_widget_get_style_context (tv),
+                                    "gs-packagekit-question-details");
+       style_context = gtk_widget_get_style_context (tv);
+       css_provider = gtk_css_provider_new ();
+       gtk_css_provider_load_from_data (css_provider,
+               ".gs-packagekit-question-details {\n"
+               "       font-family: Monospace;\n"
+               "       font-size: smaller;\n"
+               "       padding: 16px;\n"
+               "}", -1, &error);
+       if (error)
+               g_warning ("GsPackageKitTask: Failed to parse CSS: %s", error->message);
+       gtk_style_context_add_provider (style_context, GTK_STYLE_PROVIDER (css_provider),
+                                       GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+
+       gtk_text_buffer_set_text (buffer, details, -1);
+       gtk_widget_set_visible (tv, TRUE);
+
+       gtk_container_add (GTK_CONTAINER (sw), tv);
+       gtk_widget_set_vexpand (sw, TRUE);
+       gtk_container_add (GTK_CONTAINER (message_area), sw);
+       gtk_container_child_set (GTK_CONTAINER (message_area), sw, "pack-type", GTK_PACK_END, NULL);
+
+       g_signal_connect (dialog, "map-event", G_CALLBACK (unset_focus), NULL);
+}
+
+static gboolean
+gs_packagekit_task_user_accepted (const gchar *title,
+                                 const gchar *msg,
+                                 const gchar *details,
+                                 const gchar *ok_label)
+{
+       GtkWidget *dialog;
+       GtkWindow *parent = NULL;
+       GApplication *application = g_application_get_default ();
+       gint response;
+
+       if (application && GTK_IS_APPLICATION (application))
+               parent = gtk_application_get_active_window (GTK_APPLICATION (application));
+
+       dialog = gtk_message_dialog_new_with_markup (parent,
+                                                    GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                    GTK_MESSAGE_QUESTION,
+                                                    GTK_BUTTONS_NONE,
+                                                    "<big><b>%s</b></big>", title);
+       gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+                                                 "%s", msg);
+       if (details != NULL)
+               insert_details_widget (GTK_MESSAGE_DIALOG (dialog), details);
+       gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Cancel"), GTK_RESPONSE_CANCEL);
+       gtk_dialog_add_button (GTK_DIALOG (dialog), ok_label, GTK_RESPONSE_OK);
+
+       response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+       gtk_widget_destroy (dialog);
+
+       return response == GTK_RESPONSE_OK;
+}
+
+typedef struct _QuestionData {
+       GWeakRef task_weakref;
+       guint request;
+       gchar *title;
+       gchar *msg;
+       gchar *details;
+       gchar *ok_label;
+} QuestionData;
+
+static QuestionData *
+question_data_new (GsPackageKitTask *task,
+                  guint request,
+                  const gchar *title,
+                  const gchar *msg,
+                  const gchar *details,
+                  const gchar *ok_label)
+{
+       QuestionData *qd;
+
+       qd = g_slice_new0 (QuestionData);
+       g_weak_ref_init (&qd->task_weakref, task);
+       qd->request = request;
+       qd->title = g_strdup (title);
+       qd->msg = g_strdup (msg);
+       qd->details = g_strdup (details);
+       qd->ok_label = g_strdup (ok_label);
+
+       return qd;
+}
+
+static void
+question_data_free (gpointer ptr)
+{
+       QuestionData *qd = ptr;
+
+       if (qd) {
+               g_weak_ref_clear (&qd->task_weakref);
+               g_free (qd->title);
+               g_free (qd->msg);
+               g_free (qd->details);
+               g_free (qd->ok_label);
+               g_slice_free (QuestionData, qd);
+       }
+}
+
+static gboolean
+gs_packagekit_task_question_idle_cb (gpointer user_data)
+{
+       QuestionData *qd = user_data;
+       PkTask *task;
+
+       task = g_weak_ref_get (&qd->task_weakref);
+       if (task) {
+               if (gs_packagekit_task_user_accepted (qd->title, qd->msg, qd->details, qd->ok_label))
+                       pk_task_user_accepted (task, qd->request);
+               else
+                       pk_task_user_declined (task, qd->request);
+               g_object_unref (task);
+       }
+
+       return G_SOURCE_REMOVE;
+}
+
+static void
+gs_packagekit_task_schedule_question (GsPackageKitTask *task,
+                                     guint request,
+                                     const gchar *title,
+                                     const gchar *msg,
+                                     const gchar *details,
+                                     const gchar *ok_label)
+{
+       QuestionData *qd;
+
+       qd = question_data_new (task, request, title, msg, details, ok_label);
+       g_idle_add_full (G_PRIORITY_HIGH_IDLE, gs_packagekit_task_question_idle_cb, qd, question_data_free);
+}
+
+static void
+gs_packagekit_task_untrusted_question (PkTask *task,
+                                      guint request,
+                                      PkResults *results)
+{
+       GsPackageKitTask *gs_task = GS_PACKAGEKIT_TASK (task);
+       GsPackageKitTaskPrivate *priv = gs_packagekit_task_get_instance_private (gs_task);
+       g_autoptr(PkError) error = NULL;
+       const gchar *title;
+       const gchar *msg;
+       const gchar *details;
+       const gchar *ok_label;
+
+       switch (priv->action) {
+       case GS_PLUGIN_ACTION_INSTALL:
+               title = _("Install Unsigned Software?");
+               msg = _("Software that is to be installed is not signed. It will not be possible to verify 
the origin of updates to this software, or whether updates have been tampered with.");
+               ok_label = _("_Install");
+               break;
+       case GS_PLUGIN_ACTION_DOWNLOAD:
+       case GS_PLUGIN_ACTION_UPDATE:
+               title = _("Update Unsigned Software?");
+               msg = _("Unsigned updates are available. Without a signature, it is not possible to verify 
the origin of the update, or whether it has been tampered with. Software updates will be disabled until 
unsigned updates are either removed or updated.");
+               ok_label = _("_Update");
+               break;
+       default:
+               pk_task_user_declined (task, request);
+               return;
+       }
+
+       error = pk_results_get_error_code (results);
+       if (error)
+               details = pk_error_get_details (error);
+       else
+               details = NULL;
+
+       gs_packagekit_task_schedule_question (gs_task, request, title, msg, details, ok_label);
+}
+
+static void
+gs_packagekit_task_finalize (GObject *object)
+{
+       GsPackageKitTask *task = GS_PACKAGEKIT_TASK (object);
+       GsPackageKitTaskPrivate *priv = gs_packagekit_task_get_instance_private (task);
+
+       g_weak_ref_clear (&priv->plugin_weakref);
+
+       G_OBJECT_CLASS (gs_packagekit_task_parent_class)->finalize (object);
+}
+
+static void
+gs_packagekit_task_class_init (GsPackageKitTaskClass *klass)
+{
+       GObjectClass *object_class;
+       PkTaskClass *task_class;
+
+       task_class = PK_TASK_CLASS (klass);
+       task_class->untrusted_question = gs_packagekit_task_untrusted_question;
+
+       object_class = G_OBJECT_CLASS (klass);
+       object_class->finalize = gs_packagekit_task_finalize;
+}
+
+static void
+gs_packagekit_task_init (GsPackageKitTask *task)
+{
+       GsPackageKitTaskPrivate *priv = gs_packagekit_task_get_instance_private (task);
+
+       g_weak_ref_init (&priv->plugin_weakref, NULL);
+}
+
+PkTask *
+gs_packagekit_task_new (GsPlugin *plugin)
+{
+       GsPackageKitTask *task;
+       GsPackageKitTaskPrivate *priv;
+
+       g_return_val_if_fail (GS_IS_PLUGIN (plugin), NULL);
+
+       task = g_object_new (GS_TYPE_PACKAGEKIT_TASK, NULL);
+       priv = gs_packagekit_task_get_instance_private (task);
+
+       g_weak_ref_set (&priv->plugin_weakref, plugin);
+
+       return PK_TASK (task);
+}
+
+void
+gs_packagekit_task_setup (GsPackageKitTask *task,
+                         GsPluginAction action,
+                         gboolean interactive)
+{
+       GsPackageKitTaskPrivate *priv = gs_packagekit_task_get_instance_private (task);
+
+       g_return_if_fail (GS_IS_PACKAGEKIT_TASK (task));
+
+       priv->action = action;
+       pk_client_set_interactive (PK_CLIENT (task), interactive);
+}
+
+GsPluginAction
+gs_packagekit_task_get_action (GsPackageKitTask *task)
+{
+       GsPackageKitTaskPrivate *priv = gs_packagekit_task_get_instance_private (task);
+
+       g_return_val_if_fail (GS_IS_PACKAGEKIT_TASK (task), GS_PLUGIN_ACTION_UNKNOWN);
+
+       return priv->action;
+}
diff --git a/plugins/packagekit/gs-packagekit-task.h b/plugins/packagekit/gs-packagekit-task.h
new file mode 100644
index 000000000..ff8ef42e3
--- /dev/null
+++ b/plugins/packagekit/gs-packagekit-task.h
@@ -0,0 +1,32 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ * vi:set noexpandtab tabstop=8 shiftwidth=8:
+ *
+ * Copyright (C) 2021 Red Hat <www.redhat.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#pragma once
+
+#include <glib-object.h>
+#include <gnome-software.h>
+#include <packagekit-glib2/packagekit.h>
+
+G_BEGIN_DECLS
+
+#define GS_TYPE_PACKAGEKIT_TASK (gs_packagekit_task_get_type ())
+
+G_DECLARE_DERIVABLE_TYPE (GsPackageKitTask, gs_packagekit_task, GS, PACKAGEKIT_TASK, PkTask)
+
+struct _GsPackageKitTaskClass
+{
+       PkTaskClass parent_class;
+};
+
+PkTask         *gs_packagekit_task_new         (GsPlugin               *plugin);
+void            gs_packagekit_task_setup       (GsPackageKitTask       *task,
+                                                GsPluginAction          action,
+                                                gboolean                interactive);
+GsPluginAction  gs_packagekit_task_get_action  (GsPackageKitTask       *task);
+
+G_END_DECLS
diff --git a/plugins/packagekit/gs-plugin-packagekit-refresh.c 
b/plugins/packagekit/gs-plugin-packagekit-refresh.c
index 338cc3874..4e888b7e4 100644
--- a/plugins/packagekit/gs-plugin-packagekit-refresh.c
+++ b/plugins/packagekit/gs-plugin-packagekit-refresh.c
@@ -14,6 +14,7 @@
 
 #include "gs-metered.h"
 #include "gs-packagekit-helper.h"
+#include "gs-packagekit-task.h"
 #include "packagekit-common.h"
 
 /*
@@ -33,7 +34,7 @@ gs_plugin_initialize (GsPlugin *plugin)
        GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
 
        g_mutex_init (&priv->task_mutex);
-       priv->task = pk_task_new ();
+       priv->task = gs_packagekit_task_new (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), gs_plugin_has_flags (plugin, 
GS_PLUGIN_FLAGS_INTERACTIVE));
@@ -69,7 +70,7 @@ _download_only (GsPlugin *plugin, GsAppList *list,
         * we end up downloading a different set of packages than what was
         * shown to the user */
        pk_client_set_cache_age (PK_CLIENT (priv->task), G_MAXUINT);
-       pk_client_set_interactive (PK_CLIENT (priv->task), gs_plugin_has_flags (plugin, 
GS_PLUGIN_FLAGS_INTERACTIVE));
+       gs_packagekit_task_setup (GS_PACKAGEKIT_TASK (priv->task), GS_PLUGIN_ACTION_DOWNLOAD, 
gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_INTERACTIVE));
        results = pk_client_get_updates (PK_CLIENT (priv->task),
                                         pk_bitfield_value (PK_FILTER_ENUM_NONE),
                                         cancellable,
@@ -179,7 +180,7 @@ gs_plugin_refresh (GsPlugin *plugin,
        g_mutex_lock (&priv->task_mutex);
        /* cache age of 1 is user-initiated */
        pk_client_set_background (PK_CLIENT (priv->task), cache_age > 1);
-       pk_client_set_interactive (PK_CLIENT (priv->task), gs_plugin_has_flags (plugin, 
GS_PLUGIN_FLAGS_INTERACTIVE));
+       gs_packagekit_task_setup (GS_PACKAGEKIT_TASK (priv->task), GS_PLUGIN_ACTION_REFRESH, 
gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_INTERACTIVE));
        pk_client_set_cache_age (PK_CLIENT (priv->task), cache_age);
        /* refresh the metadata */
        results = pk_client_refresh_cache (PK_CLIENT (priv->task),
diff --git a/plugins/packagekit/gs-plugin-packagekit.c b/plugins/packagekit/gs-plugin-packagekit.c
index 56d7e2760..be8f8ab51 100644
--- a/plugins/packagekit/gs-plugin-packagekit.c
+++ b/plugins/packagekit/gs-plugin-packagekit.c
@@ -19,6 +19,7 @@
 #include "packagekit-common.h"
 #include "gs-markdown.h"
 #include "gs-packagekit-helper.h"
+#include "gs-packagekit-task.h"
 
 /*
  * SECTION:
@@ -79,7 +80,7 @@ gs_plugin_initialize (GsPlugin *plugin)
 
        /* core */
        g_mutex_init (&priv->task_mutex);
-       priv->task = pk_task_new ();
+       priv->task = gs_packagekit_task_new (plugin);
        pk_client_set_background (PK_CLIENT (priv->task), FALSE);
        pk_client_set_cache_age (PK_CLIENT (priv->task), G_MAXUINT);
        pk_client_set_interactive (PK_CLIENT (priv->task), gs_plugin_has_flags (plugin, 
GS_PLUGIN_FLAGS_INTERACTIVE));
@@ -98,7 +99,7 @@ gs_plugin_initialize (GsPlugin *plugin)
 
        /* local */
        g_mutex_init (&priv->task_mutex_local);
-       priv->task_local = pk_task_new ();
+       priv->task_local = gs_packagekit_task_new (plugin);
        pk_client_set_background (PK_CLIENT (priv->task_local), FALSE);
        pk_client_set_interactive (PK_CLIENT (priv->task_local), gs_plugin_has_flags (plugin, 
GS_PLUGIN_FLAGS_INTERACTIVE));
 
@@ -131,7 +132,7 @@ gs_plugin_initialize (GsPlugin *plugin)
 
        /* upgrade */
        g_mutex_init (&priv->task_mutex_upgrade);
-       priv->task_upgrade = pk_task_new ();
+       priv->task_upgrade = gs_packagekit_task_new (plugin);
        pk_task_set_only_download (priv->task_upgrade, TRUE);
        pk_client_set_background (PK_CLIENT (priv->task_upgrade), TRUE);
        pk_client_set_cache_age (PK_CLIENT (priv->task_upgrade), 60 * 60 * 24);
@@ -203,7 +204,7 @@ gs_plugin_add_sources_related (GsPlugin *plugin,
                                         PK_FILTER_ENUM_NOT_COLLECTIONS,
                                         -1);
        g_mutex_lock (&priv->task_mutex);
-       pk_client_set_interactive (PK_CLIENT (priv->task), gs_plugin_has_flags (plugin, 
GS_PLUGIN_FLAGS_INTERACTIVE));
+       gs_packagekit_task_setup (GS_PACKAGEKIT_TASK (priv->task), GS_PLUGIN_ACTION_GET_SOURCES, 
gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_INTERACTIVE));
        results = pk_client_get_packages (PK_CLIENT(priv->task),
                                           filter,
                                           cancellable,
@@ -266,7 +267,7 @@ gs_plugin_add_sources (GsPlugin *plugin,
                                         PK_FILTER_ENUM_NOT_DEVELOPMENT,
                                         -1);
        g_mutex_lock (&priv->task_mutex);
-       pk_client_set_interactive (PK_CLIENT (priv->task), gs_plugin_has_flags (plugin, 
GS_PLUGIN_FLAGS_INTERACTIVE));
+       gs_packagekit_task_setup (GS_PACKAGEKIT_TASK (priv->task), GS_PLUGIN_ACTION_GET_SOURCES, 
gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_INTERACTIVE));
        results = pk_client_get_repo_list (PK_CLIENT(priv->task),
                                           filter,
                                           cancellable,
@@ -330,7 +331,7 @@ gs_plugin_app_origin_repo_enable (GsPlugin *plugin,
        /* do sync call */
        gs_plugin_status_update (plugin, app, GS_PLUGIN_STATUS_WAITING);
        g_mutex_lock (&priv->task_mutex);
-       pk_client_set_interactive (PK_CLIENT (priv->task), gs_plugin_has_flags (plugin, 
GS_PLUGIN_FLAGS_INTERACTIVE));
+       gs_packagekit_task_setup (GS_PACKAGEKIT_TASK (priv->task), GS_PLUGIN_ACTION_INSTALL, 
gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_INTERACTIVE));
        results = pk_client_repo_enable (PK_CLIENT (priv->task),
                                         repo_id,
                                         TRUE,
@@ -377,7 +378,7 @@ gs_plugin_repo_enable (GsPlugin *plugin,
        gs_app_set_state (app, GS_APP_STATE_INSTALLING);
        gs_packagekit_helper_add_app (helper, app);
        g_mutex_lock (&priv->task_mutex);
-       pk_client_set_interactive (PK_CLIENT (priv->task), gs_plugin_has_flags (plugin, 
GS_PLUGIN_FLAGS_INTERACTIVE));
+       gs_packagekit_task_setup (GS_PACKAGEKIT_TASK (priv->task), GS_PLUGIN_ACTION_INSTALL, 
gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_INTERACTIVE));
        results = pk_client_repo_enable (PK_CLIENT (priv->task),
                                         gs_app_get_id (app),
                                         TRUE,
@@ -464,6 +465,7 @@ gs_plugin_app_install (GsPlugin *plugin,
                /* actually install the package */
                gs_packagekit_helper_add_app (helper, app);
                g_mutex_lock (&priv->task_mutex);
+               gs_packagekit_task_setup (GS_PACKAGEKIT_TASK (priv->task), GS_PLUGIN_ACTION_INSTALL, 
gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_INTERACTIVE));
                results = pk_task_install_packages_sync (priv->task,
                                                         package_ids,
                                                         cancellable,
@@ -541,6 +543,7 @@ gs_plugin_app_install (GsPlugin *plugin,
                }
                gs_packagekit_helper_add_app (helper, app);
                g_mutex_lock (&priv->task_mutex);
+               gs_packagekit_task_setup (GS_PACKAGEKIT_TASK (priv->task), GS_PLUGIN_ACTION_INSTALL, 
gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_INTERACTIVE));
                results = pk_task_install_packages_sync (priv->task,
                                                         (gchar **) array_package_ids->pdata,
                                                         cancellable,
@@ -582,6 +585,7 @@ gs_plugin_app_install (GsPlugin *plugin,
                gs_app_set_state (app, GS_APP_STATE_INSTALLING);
                gs_packagekit_helper_add_app (helper, app);
                g_mutex_lock (&priv->task_mutex);
+               gs_packagekit_task_setup (GS_PACKAGEKIT_TASK (priv->task), GS_PLUGIN_ACTION_INSTALL, 
gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_INTERACTIVE));
                results = pk_task_install_files_sync (priv->task,
                                                      package_ids,
                                                      cancellable,
@@ -631,7 +635,7 @@ gs_plugin_repo_disable (GsPlugin *plugin,
        gs_app_set_state (app, GS_APP_STATE_REMOVING);
        gs_packagekit_helper_add_app (helper, app);
        g_mutex_lock (&priv->task_mutex);
-       pk_client_set_interactive (PK_CLIENT (priv->task), gs_plugin_has_flags (plugin, 
GS_PLUGIN_FLAGS_INTERACTIVE));
+       gs_packagekit_task_setup (GS_PACKAGEKIT_TASK (priv->task), GS_PLUGIN_ACTION_REMOVE, 
gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_INTERACTIVE));
        results = pk_client_repo_enable (PK_CLIENT (priv->task),
                                         gs_app_get_id (app),
                                         FALSE,
@@ -712,6 +716,7 @@ gs_plugin_app_remove (GsPlugin *plugin,
        gs_app_set_state (app, GS_APP_STATE_REMOVING);
        gs_packagekit_helper_add_app (helper, app);
        g_mutex_lock (&priv->task_mutex);
+       gs_packagekit_task_setup (GS_PACKAGEKIT_TASK (priv->task), GS_PLUGIN_ACTION_REMOVE, 
gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_INTERACTIVE));
        results = pk_task_remove_packages_sync (priv->task,
                                                package_ids,
                                                TRUE, GS_PACKAGEKIT_AUTOREMOVE,
@@ -783,7 +788,7 @@ gs_plugin_add_updates (GsPlugin *plugin,
        /* do sync call */
        gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_WAITING);
        g_mutex_lock (&priv->task_mutex);
-       pk_client_set_interactive (PK_CLIENT (priv->task), gs_plugin_has_flags (plugin, 
GS_PLUGIN_FLAGS_INTERACTIVE));
+       gs_packagekit_task_setup (GS_PACKAGEKIT_TASK (priv->task), GS_PLUGIN_ACTION_GET_UPDATES, 
gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_INTERACTIVE));
        results = pk_client_get_updates (PK_CLIENT (priv->task),
                                         pk_bitfield_value (PK_FILTER_ENUM_NONE),
                                         cancellable,
@@ -822,7 +827,7 @@ gs_plugin_add_search_files (GsPlugin *plugin,
                                         PK_FILTER_ENUM_ARCH,
                                         -1);
        g_mutex_lock (&priv->task_mutex);
-       pk_client_set_interactive (PK_CLIENT (priv->task), gs_plugin_has_flags (plugin, 
GS_PLUGIN_FLAGS_INTERACTIVE));
+       gs_packagekit_task_setup (GS_PACKAGEKIT_TASK (priv->task), GS_PLUGIN_ACTION_SEARCH_FILES, 
gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_INTERACTIVE));
        results = pk_client_search_files (PK_CLIENT (priv->task),
                                          filter,
                                          search,
@@ -855,7 +860,7 @@ gs_plugin_add_search_what_provides (GsPlugin *plugin,
                                         PK_FILTER_ENUM_ARCH,
                                         -1);
        g_mutex_lock (&priv->task_mutex);
-       pk_client_set_interactive (PK_CLIENT (priv->task), gs_plugin_has_flags (plugin, 
GS_PLUGIN_FLAGS_INTERACTIVE));
+       gs_packagekit_task_setup (GS_PACKAGEKIT_TASK (priv->task), GS_PLUGIN_ACTION_SEARCH_PROVIDES, 
gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_INTERACTIVE));
        results = pk_client_what_provides (PK_CLIENT (priv->task),
                                           filter,
                                           search,
@@ -1441,7 +1446,7 @@ gs_plugin_packagekit_refine_distro_upgrade (GsPlugin *plugin,
        g_mutex_lock (&priv->client_mutex_refine);
        cache_age_save = pk_client_get_cache_age (priv->client_refine);
        pk_client_set_cache_age (priv->client_refine, 60 * 60 * 24 * 7); /* once per week */
-       pk_client_set_interactive (priv->client_refine, gs_plugin_has_flags (plugin, 
GS_PLUGIN_FLAGS_INTERACTIVE));
+       gs_packagekit_task_setup (GS_PACKAGEKIT_TASK (priv->client_refine), GS_PLUGIN_ACTION_REFINE, 
gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_INTERACTIVE));
        results = pk_client_upgrade_system (priv->client_refine,
                                            pk_bitfield_from_enums (PK_TRANSACTION_FLAG_ENUM_SIMULATE, -1),
                                            gs_app_get_version (app),
@@ -2029,7 +2034,7 @@ gs_plugin_file_to_app (GsPlugin *plugin,
        files = g_strsplit (filename, "\t", -1);
        g_mutex_lock (&priv->task_mutex_local);
        pk_client_set_cache_age (PK_CLIENT (priv->task_local), G_MAXUINT);
-       pk_client_set_interactive (PK_CLIENT (priv->task_local), gs_plugin_has_flags (plugin, 
GS_PLUGIN_FLAGS_INTERACTIVE));
+       gs_packagekit_task_setup (GS_PACKAGEKIT_TASK (priv->task_local), GS_PLUGIN_ACTION_FILE_TO_APP, 
gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_INTERACTIVE));
        results = pk_client_get_details_local (PK_CLIENT (priv->task_local),
                                               files,
                                               cancellable,
@@ -2316,7 +2321,7 @@ gs_plugin_url_to_app (GsPlugin *plugin,
        package_ids[0] = g_strdup (path);
 
        g_mutex_lock (&priv->client_mutex_url_to_app);
-       pk_client_set_interactive (priv->client_url_to_app, gs_plugin_has_flags (plugin, 
GS_PLUGIN_FLAGS_INTERACTIVE));
+       gs_packagekit_task_setup (GS_PACKAGEKIT_TASK (priv->client_url_to_app), GS_PLUGIN_ACTION_URL_TO_APP, 
gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_INTERACTIVE));
        results = pk_client_resolve (priv->client_url_to_app,
                                     pk_bitfield_from_enums (PK_FILTER_ENUM_NEWEST, PK_FILTER_ENUM_ARCH, -1),
                                     package_ids,
@@ -2620,7 +2625,7 @@ gs_plugin_app_upgrade_download (GsPlugin *plugin,
        gs_app_set_state (app, GS_APP_STATE_INSTALLING);
        gs_packagekit_helper_set_progress_app (helper, app);
        g_mutex_lock (&priv->task_mutex_upgrade);
-       pk_client_set_interactive (PK_CLIENT (priv->task_upgrade), gs_plugin_has_flags (plugin, 
GS_PLUGIN_FLAGS_INTERACTIVE));
+       gs_packagekit_task_setup (GS_PACKAGEKIT_TASK (priv->task_upgrade), GS_PLUGIN_ACTION_UPGRADE_DOWNLOAD, 
gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_INTERACTIVE));
        results = pk_task_upgrade_system_sync (priv->task_upgrade,
                                               gs_app_get_version (app),
                                               PK_UPGRADE_KIND_ENUM_COMPLETE,
diff --git a/plugins/packagekit/meson.build b/plugins/packagekit/meson.build
index a7cfcd7d4..07f570c12 100644
--- a/plugins/packagekit/meson.build
+++ b/plugins/packagekit/meson.build
@@ -31,6 +31,7 @@ shared_module(
   sources : [
     'gs-plugin-packagekit.c',
     'gs-packagekit-helper.c',
+    'gs-packagekit-task.c',
     'packagekit-common.c',
     'gs-markdown.c',
   ],
@@ -65,6 +66,7 @@ shared_module(
   'gs_plugin_packagekit-refresh',
   sources : [
     'gs-plugin-packagekit-refresh.c',
+    'gs-packagekit-task.c',
     'gs-packagekit-helper.c',
     'packagekit-common.c',
   ],
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 9fe738f85..d83857eae 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -94,5 +94,6 @@ plugins/flatpak/gs-plugin-flatpak.c
 plugins/fwupd/gs-fwupd-app.c
 plugins/fwupd/gs-plugin-fwupd.c
 plugins/fwupd/org.gnome.Software.Plugin.Fwupd.metainfo.xml.in
+plugins/packagekit/gs-packagekit-task.c
 plugins/snap/gs-plugin-snap.c
 plugins/snap/org.gnome.Software.Plugin.Snap.metainfo.xml.in


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