[gnome-software] Report progress from PackageKit using plugin status



commit 009d6d4f6fc054e9acc9d97496a6de1a7bbdc007
Author: Richard Hughes <richard hughsie com>
Date:   Mon Mar 11 13:44:01 2013 +0000

    Report progress from PackageKit using plugin status

 src/Makefile.am                    |    2 +
 src/gs-main.c                      |   18 ++++++++-
 src/gs-plugin-loader.c             |    6 +++
 src/gs-plugin.c                    |   75 ++++++++++++++++++++++++++++++++++++
 src/gs-plugin.h                    |   11 ++++-
 src/plugins/gs-plugin-packagekit.c |   63 +++++++++++++++++++++++++++--
 6 files changed, 167 insertions(+), 8 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index d99017f..65f876f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -33,6 +33,7 @@ gnome_software_SOURCES =                              \
        gs-app.h                                        \
        gs-app-widget.c                                 \
        gs-app-widget.h                                 \
+       gs-plugin.c                                     \
        gs-plugin.h                                     \
        gs-plugin-loader.c                              \
        gs-plugin-loader.h                              \
@@ -73,6 +74,7 @@ check_PROGRAMS =                                              \
 
 gs_self_test_SOURCES =                                         \
        gs-app.c                                                \
+       gs-plugin.c                                             \
        gs-plugin-loader.c                                      \
        gs-plugin-loader-sync.c                                 \
        gs-self-test.c
diff --git a/src/gs-main.c b/src/gs-main.c
index 6b3cfff..e53448b 100644
--- a/src/gs-main.c
+++ b/src/gs-main.c
@@ -246,9 +246,25 @@ gs_main_plugin_loader_status_changed_cb (GsPluginLoader *plugin_loader,
        const gchar *status_text = NULL;
 
        /* translate */
-       if (status == GS_PLUGIN_STATUS_WAITING) {
+       switch (status) {
+       case GS_PLUGIN_STATUS_WAITING:
                /* TRANSLATORS: we're waiting for something to happen */
                status_text = _("Waiting...");
+               break;
+       case GS_PLUGIN_STATUS_SETUP:
+               /* TRANSLATORS: we're waiting for something to happen */
+               status_text = _("Setting up...");
+               break;
+       case GS_PLUGIN_STATUS_DOWNLOADING:
+               /* TRANSLATORS: we're waiting for something to happen */
+               status_text = _("Downloading...");
+               break;
+       case GS_PLUGIN_STATUS_QUERYING:
+               /* TRANSLATORS: we're waiting for something to happen */
+               status_text = _("Querying...");
+               break;
+       default:
+               break;
        }
 
        /* update the label */
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 75c9f58..fdf4a60 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -845,6 +845,12 @@ gs_plugin_loader_status_to_string (GsPluginStatus status)
                return "waiting";
        if (status == GS_PLUGIN_STATUS_FINISHED)
                return "finished";
+       if (status == GS_PLUGIN_STATUS_SETUP)
+               return "setup";
+       if (status == GS_PLUGIN_STATUS_DOWNLOADING)
+               return "downloading";
+       if (status == GS_PLUGIN_STATUS_QUERYING)
+               return "querying";
        return "unknown";
 }
 
diff --git a/src/gs-plugin.c b/src/gs-plugin.c
new file mode 100644
index 0000000..4a97d42
--- /dev/null
+++ b/src/gs-plugin.c
@@ -0,0 +1,75 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2013 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include <glib.h>
+
+#include "gs-plugin.h"
+
+/**
+ * gs_plugin_add_app:
+ **/
+void
+gs_plugin_add_app (GList **list, GsApp *app)
+{
+       *list = g_list_prepend (*list, app);
+}
+
+typedef struct {
+       GsPlugin        *plugin;
+       GsApp           *app;
+       GsPluginStatus   status;
+} GsPluginStatusHelper;
+
+/**
+ * gs_plugin_status_update_cb:
+ **/
+static gboolean
+gs_plugin_status_update_cb (gpointer user_data)
+{
+       GsPluginStatusHelper *helper = (GsPluginStatusHelper *) user_data;
+
+       /* call back into the loader */
+       helper->plugin->status_update_fn (helper->plugin,
+                                         helper->app,
+                                         helper->status,
+                                         helper->plugin->status_update_user_data);
+       if (helper->app != NULL)
+               g_object_unref (helper->app);
+       g_slice_free (GsPluginStatusHelper, helper);
+       return FALSE;
+}
+
+/**
+ * gs_plugin_status_update:
+ **/
+void
+gs_plugin_status_update (GsPlugin *plugin, GsApp *app, GsPluginStatus status)
+{
+       GsPluginStatusHelper *helper;
+       helper = g_slice_new0 (GsPluginStatusHelper);
+       helper->plugin = plugin;
+       helper->status = status;
+       if (app != NULL)
+               helper->app = g_object_ref (app);
+       g_idle_add (gs_plugin_status_update_cb, helper);
+}
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index df850b5..7b34320 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -38,6 +38,9 @@ typedef enum {
        GS_PLUGIN_STATUS_UNKNOWN,
        GS_PLUGIN_STATUS_WAITING,
        GS_PLUGIN_STATUS_FINISHED,
+       GS_PLUGIN_STATUS_SETUP,
+       GS_PLUGIN_STATUS_DOWNLOADING,
+       GS_PLUGIN_STATUS_QUERYING,
        GS_PLUGIN_STATUS_LAST
 } GsPluginStatus;
 
@@ -65,10 +68,9 @@ typedef enum {
 } GsPluginError;
 
 /* helpers */
-#define        gs_plugin_add_app(l,a)                          (*l=g_list_prepend(*l,a))
-#define        gs_plugin_status_update(p,a,s)                  
(p->status_update_fn(p,a,s,p->status_update_user_data))
 #define        GS_PLUGIN_ERROR                                 1
 #define        GS_PLUGIN_GET_PRIVATE(x)                        g_new0 (x,1)
+#define        GS_PLUGIN(x)                                    ((GsPlugin *) x);
 
 typedef const gchar    *(*GsPluginGetNameFunc)         (void);
 typedef gdouble                 (*GsPluginGetPriorityFunc)     (GsPlugin       *plugin);
@@ -94,6 +96,11 @@ typedef gboolean      (*GsPluginRefineFunc)          (GsPlugin       *plugin,
 const gchar    *gs_plugin_get_name                     (void);
 void            gs_plugin_initialize                   (GsPlugin       *plugin);
 void            gs_plugin_destroy                      (GsPlugin       *plugin);
+void            gs_plugin_add_app                      (GList          **list,
+                                                        GsApp          *app);
+void            gs_plugin_status_update                (GsPlugin       *plugin,
+                                                        GsApp          *app,
+                                                        GsPluginStatus  status);
 gboolean        gs_plugin_add_search                   (GsPlugin       *plugin,
                                                         const gchar    *value,
                                                         GList          *list,
diff --git a/src/plugins/gs-plugin-packagekit.c b/src/plugins/gs-plugin-packagekit.c
index 6e5347c..ddb236e 100644
--- a/src/plugins/gs-plugin-packagekit.c
+++ b/src/plugins/gs-plugin-packagekit.c
@@ -72,6 +72,59 @@ gs_plugin_destroy (GsPlugin *plugin)
 }
 
 /**
+ * gs_plugin_packagekit_progress_cb:
+ **/
+static void
+gs_plugin_packagekit_progress_cb (PkProgress *progress,
+                                 PkProgressType type,
+                                 gpointer user_data)
+{
+       GsPluginStatus plugin_status = GS_PLUGIN_STATUS_UNKNOWN;
+       PkStatusEnum status;
+       GsPlugin *plugin = GS_PLUGIN (user_data);
+
+       if (type != PK_PROGRESS_TYPE_STATUS)
+               return;
+       g_object_get (progress,
+                     "status", &status,
+                     NULL);
+
+       /* set label */
+       switch (status) {
+       case PK_STATUS_ENUM_SETUP:
+       case PK_STATUS_ENUM_FINISHED:
+       case PK_STATUS_ENUM_UNKNOWN:
+               break;
+       case PK_STATUS_ENUM_WAIT:
+       case PK_STATUS_ENUM_WAITING_FOR_LOCK:
+               plugin_status = GS_PLUGIN_STATUS_WAITING;
+               break;
+       case PK_STATUS_ENUM_LOADING_CACHE:
+               plugin_status = GS_PLUGIN_STATUS_SETUP;
+               break;
+       case PK_STATUS_ENUM_DOWNLOAD:
+       case PK_STATUS_ENUM_DOWNLOAD_REPOSITORY:
+       case PK_STATUS_ENUM_DOWNLOAD_PACKAGELIST:
+       case PK_STATUS_ENUM_DOWNLOAD_FILELIST:
+       case PK_STATUS_ENUM_DOWNLOAD_CHANGELOG:
+       case PK_STATUS_ENUM_DOWNLOAD_GROUP:
+       case PK_STATUS_ENUM_DOWNLOAD_UPDATEINFO:
+               plugin_status = GS_PLUGIN_STATUS_DOWNLOADING;
+               break;
+       case PK_STATUS_ENUM_QUERY:
+       case PK_STATUS_ENUM_INFO:
+               plugin_status = GS_PLUGIN_STATUS_QUERYING;
+               break;
+       default:
+               g_warning ("no mapping for %s",
+                          pk_status_enum_to_string (status));
+               break;
+       }
+       if (plugin_status != GS_PLUGIN_STATUS_UNKNOWN)
+               gs_plugin_status_update (plugin, NULL, plugin_status);
+}
+
+/**
  * gs_plugin_add_search:
  */
 gboolean
@@ -156,8 +209,8 @@ gs_plugin_add_installed (GsPlugin *plugin,
                                         -1);
        results = pk_client_get_packages (PK_CLIENT(plugin->priv->task),
                                          filter,
-                                         NULL, NULL,
                                          cancellable,
+                                         gs_plugin_packagekit_progress_cb, plugin,
                                          error);
        if (results == NULL) {
                ret = FALSE;
@@ -194,8 +247,8 @@ gs_plugin_add_updates (GsPlugin *plugin,
        filter = pk_bitfield_from_enums (PK_FILTER_ENUM_ARCH, -1);
        results = pk_client_get_updates (PK_CLIENT(plugin->priv->task),
                                         filter,
-                                        NULL, NULL,
                                         cancellable,
+                                        gs_plugin_packagekit_progress_cb, plugin,
                                         error);
        if (results == NULL) {
                ret = FALSE;
@@ -239,7 +292,7 @@ gs_plugin_app_install (GsPlugin *plugin,
        results = pk_task_install_packages_sync (plugin->priv->task,
                                                 (gchar **) to_array,
                                                 cancellable,
-                                                NULL, NULL,
+                                                gs_plugin_packagekit_progress_cb, plugin,
                                                 error);
        if (results == NULL) {
                ret = FALSE;
@@ -298,7 +351,7 @@ gs_plugin_app_remove (GsPlugin *plugin,
                                                (gchar **) to_array,
                                                FALSE, FALSE,
                                                cancellable,
-                                               NULL, NULL,
+                                               gs_plugin_packagekit_progress_cb, plugin,
                                                error);
        if (results == NULL) {
                ret = FALSE;
@@ -356,7 +409,7 @@ gs_plugin_app_update (GsPlugin *plugin,
        results = pk_task_update_packages_sync (plugin->priv->task,
                                                (gchar **) to_array,
                                                cancellable,
-                                               NULL, NULL,
+                                               gs_plugin_packagekit_progress_cb, plugin,
                                                error);
        if (results == NULL) {
                ret = FALSE;


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