[gnome-software] Add a plugin to query the PackageKit prepared-update file directly



commit 248000549436263e0749986217cd2e0368f8e6c1
Author: Richard Hughes <richard hughsie com>
Date:   Fri Sep 20 15:50:56 2013 +0100

    Add a plugin to query the PackageKit prepared-update file directly
    
    This ensures the update list presented to the user is ready-to-go and means we
    don't have to manually check the offline update is ready to go after the user
    presses the button.
    
    If you're not using the systemd-updates offline updates functionality you
    probably want to be using the old packagekit-updates plugin instead.

 src/gs-application.c                    |    2 +-
 src/plugins/Makefile.am                 |    6 ++
 src/plugins/gs-plugin-systemd-updates.c |   97 +++++++++++++++++++++++++++++++
 3 files changed, 104 insertions(+), 1 deletions(-)
---
diff --git a/src/gs-application.c b/src/gs-application.c
index 9d7c75e..fd284d5 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -169,7 +169,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-updates", TRUE);
+       gs_plugin_loader_set_enabled (app->plugin_loader, "systemd-updates", TRUE);
        gs_plugin_loader_set_enabled (app->plugin_loader, "packagekit-refine", TRUE);
        gs_plugin_loader_set_enabled (app->plugin_loader, "packagekit-history", TRUE);
        gs_plugin_loader_set_enabled (app->plugin_loader, "packagekit-offline", TRUE);
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index eb76d20..2c38826 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -40,6 +40,7 @@ plugin_LTLIBRARIES =                                  \
        libgs_plugin_hardcoded-ratings.la               \
        libgs_plugin_hardcoded-screenshots.la           \
        libgs_plugin_local-ratings.la                   \
+       libgs_plugin_systemd-updates.la                 \
        libgs_plugin_packagekit-refine.la               \
        libgs_plugin_packagekit-updates.la              \
        libgs_plugin_packagekit-offline.la              \
@@ -125,6 +126,11 @@ libgs_plugin_packagekit_updates_la_LIBADD = $(GS_PLUGIN_LIBS) $(PACKAGEKIT_LIBS)
 libgs_plugin_packagekit_updates_la_LDFLAGS = -module -avoid-version
 libgs_plugin_packagekit_updates_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARNINGFLAGS_C)
 
+libgs_plugin_systemd_updates_la_SOURCES = gs-plugin-systemd-updates.c
+libgs_plugin_systemd_updates_la_LIBADD = $(GS_PLUGIN_LIBS) $(PACKAGEKIT_LIBS)
+libgs_plugin_systemd_updates_la_LDFLAGS = -module -avoid-version
+libgs_plugin_systemd_updates_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARNINGFLAGS_C)
+
 libgs_plugin_packagekit_history_la_SOURCES = gs-plugin-packagekit-history.c
 libgs_plugin_packagekit_history_la_LIBADD = $(GS_PLUGIN_LIBS)
 libgs_plugin_packagekit_history_la_LDFLAGS = -module -avoid-version
diff --git a/src/plugins/gs-plugin-systemd-updates.c b/src/plugins/gs-plugin-systemd-updates.c
new file mode 100644
index 0000000..7e41d2f
--- /dev/null
+++ b/src/plugins/gs-plugin-systemd-updates.c
@@ -0,0 +1,97 @@
+/* -*- 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>
+
+#define I_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE
+#include <packagekit-glib2/packagekit.h>
+
+#include <gs-plugin.h>
+
+/**
+ * gs_plugin_get_name:
+ */
+const gchar *
+gs_plugin_get_name (void)
+{
+       return "systemd-updates";
+}
+
+/**
+ * gs_plugin_get_priority:
+ */
+gdouble
+gs_plugin_get_priority (GsPlugin *plugin)
+{
+       return 10.0f;
+}
+
+#define PK_PREPARED_UPDATE_FN  "/var/lib/PackageKit/prepared-update"
+
+/**
+ * gs_plugin_add_updates:
+ */
+gboolean
+gs_plugin_add_updates (GsPlugin *plugin,
+                      GList **list,
+                      GCancellable *cancellable,
+                      GError **error)
+{
+       GsApp *app;
+       gboolean ret;
+       gchar **package_ids = NULL;
+       gchar **split;
+       gchar *data = NULL;
+       guint i;
+
+       /* does the file exist ? */
+       if (!g_file_test (PK_PREPARED_UPDATE_FN, G_FILE_TEST_EXISTS)) {
+               ret = TRUE;
+               goto out;
+       }
+
+       /* get the list of packages to update */
+       ret = g_file_get_contents (PK_PREPARED_UPDATE_FN, &data, NULL, error);
+       if (!ret)
+               goto out;
+
+       /* add them to the new array */
+       package_ids = g_strsplit (data, "\n", -1);
+       for (i = 0; package_ids[i] != NULL; i++) {
+               g_warning ("%s", package_ids[i]);
+               app = gs_app_new (NULL);
+               gs_app_set_management_plugin (app, "PackageKit");
+               gs_app_set_metadata (app,
+                                    "PackageKit::package-id",
+                                    package_ids[i]);
+               split = pk_package_id_split (package_ids[i]);
+               gs_app_set_source (app, split[PK_PACKAGE_ID_NAME]);
+               gs_app_set_update_version (app, split[PK_PACKAGE_ID_VERSION]);
+               gs_app_set_state (app, GS_APP_STATE_UPDATABLE);
+               gs_app_set_kind (app, GS_APP_KIND_PACKAGE);
+               gs_plugin_add_app (list, app);
+               g_strfreev (split);
+       }
+out:
+       g_free (data);
+       g_strfreev (package_ids);
+       return ret;
+}


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