[gnome-software] Move creation of the OS update to a plugin
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Move creation of the OS update to a plugin
- Date: Tue, 13 Dec 2016 21:08:20 +0000 (UTC)
commit 9c7ced8642b1a924c744074d7edd57a16719a3ac
Author: Richard Hughes <richard hughsie com>
Date: Tue Dec 13 17:01:39 2016 +0000
Move creation of the OS update to a plugin
contrib/gnome-software.spec.in | 1 +
po/POTFILES.in | 1 +
src/gs-plugin-loader.c | 72 -------------------
src/gs-self-test.c | 6 +-
src/plugins/Makefile.am | 6 ++
src/plugins/gs-plugin-generic-updates.c | 116 +++++++++++++++++++++++++++++++
src/plugins/meson.build | 12 +++
7 files changed, 140 insertions(+), 74 deletions(-)
---
diff --git a/contrib/gnome-software.spec.in b/contrib/gnome-software.spec.in
index b8ced21..49f3d14 100644
--- a/contrib/gnome-software.spec.in
+++ b/contrib/gnome-software.spec.in
@@ -164,6 +164,7 @@ glib-compile-schemas %{_datadir}/glib-2.0/schemas &> /dev/null || :
%{_libdir}/gs-plugins-%{gs_plugin_version}/libgs_plugin_fedora-tagger-usage.so
%{_libdir}/gs-plugins-%{gs_plugin_version}/libgs_plugin_flatpak.so
%{_libdir}/gs-plugins-%{gs_plugin_version}/libgs_plugin_fwupd.so
+%{_libdir}/gs-plugins-%{gs_plugin_version}/libgs_plugin_generic-updates.so
%{_libdir}/gs-plugins-%{gs_plugin_version}/libgs_plugin_hardcoded-blacklist.so
%{_libdir}/gs-plugins-%{gs_plugin_version}/libgs_plugin_hardcoded-featured.so
%{_libdir}/gs-plugins-%{gs_plugin_version}/libgs_plugin_hardcoded-popular.so
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 7d5eb92..f42b414 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -67,6 +67,7 @@ src/gs-shell-loading.c
src/gs-shell-loading.ui
src/plugins/gs-desktop-common.c
src/plugins/gs-install-appstream.c
+src/plugins/gs-plugin-generic-updates.c
src/plugins/org.gnome.Software.Plugin.Epiphany.metainfo.xml.in
src/plugins/org.gnome.Software.Plugin.Flatpak.metainfo.xml.in
src/plugins/org.gnome.Software.Plugin.Fwupd.metainfo.xml.in
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index a29cbd9..466e993 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -1182,69 +1182,6 @@ gs_plugin_loader_run_action (GsPluginLoaderJob *job,
/******************************************************************************/
-static gboolean
-gs_plugin_loader_merge_into_os_update (GsApp *app)
-{
- if (gs_app_get_kind (app) == AS_APP_KIND_GENERIC)
- return TRUE;
- if (gs_app_get_kind (app) == AS_APP_KIND_SOURCE)
- return TRUE;
- return FALSE;
-}
-
-static void
-gs_plugin_loader_add_os_update_item (GsAppList *list)
-{
- gboolean has_os_update = FALSE;
- guint i;
- GsApp *app_tmp;
- g_autoptr(GError) error = NULL;
- g_autoptr(GdkPixbuf) pixbuf = NULL;
- g_autoptr(GsApp) app_os = NULL;
- g_autoptr(AsIcon) ic = NULL;
-
- /* do we have any packages left that are not apps? */
- for (i = 0; i < gs_app_list_length (list); i++) {
- app_tmp = gs_app_list_index (list, i);
- if (gs_plugin_loader_merge_into_os_update (app_tmp)) {
- has_os_update = TRUE;
- break;
- }
- }
- if (!has_os_update)
- return;
-
- /* create new meta object */
- app_os = gs_app_new ("os-update.virtual");
- gs_app_set_management_plugin (app_os, "");
- gs_app_set_kind (app_os, AS_APP_KIND_OS_UPDATE);
- gs_app_set_state (app_os, AS_APP_STATE_UPDATABLE_LIVE);
- gs_app_set_name (app_os,
- GS_APP_QUALITY_NORMAL,
- /* TRANSLATORS: this is a group of updates that are not
- * packages and are not shown in the main list */
- _("OS Updates"));
- gs_app_set_summary (app_os,
- GS_APP_QUALITY_NORMAL,
- /* TRANSLATORS: this is a longer description of the
- * "OS Updates" string */
- _("Includes performance, stability and security improvements."));
- gs_app_set_description (app_os,
- GS_APP_QUALITY_NORMAL,
- gs_app_get_summary (app_os));
- for (i = 0; i < gs_app_list_length (list); i++) {
- app_tmp = gs_app_list_index (list, i);
- if (!gs_plugin_loader_merge_into_os_update (app_tmp))
- continue;
- gs_app_add_related (app_os, app_tmp);
- }
- ic = as_icon_new ();
- as_icon_set_kind (ic, AS_ICON_KIND_STOCK);
- as_icon_set_name (ic, "software-update-available-symbolic");
- gs_app_add_icon (app_os, ic);
- gs_app_list_add (list, app_os);
-}
-
static void
gs_plugin_loader_get_updates_thread_cb (GTask *task,
gpointer object,
@@ -1286,15 +1223,6 @@ gs_plugin_loader_get_updates_thread_cb (GTask *task,
}
}
- /* add OS Update item if required */
- gs_plugin_loader_add_os_update_item (job->list);
- job->function_name = "gs_plugin_add_updates_*";
- job->refine_flags = GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON;
- if (!gs_plugin_loader_run_refine (job, job->list, cancellable, &error)) {
- g_task_return_error (task, error);
- return;
- }
-
/* remove any apps that are not proper applications or OS updates */
gs_app_list_filter (job->list,
gs_plugin_loader_app_is_valid_updatable, job);
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index 59d22ac..fbc7af9 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -571,7 +571,8 @@ gs_plugin_loader_updates_func (GsPluginLoader *plugin_loader)
/* get the updates list */
list = gs_plugin_loader_get_updates (plugin_loader,
- GS_PLUGIN_REFINE_FLAGS_DEFAULT,
+ GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON |
+ GS_PLUGIN_REFINE_FLAGS_REQUIRE_UPDATE_DETAILS,
GS_PLUGIN_FAILURE_FLAGS_FATAL_ANY,
NULL,
&error);
@@ -589,7 +590,7 @@ gs_plugin_loader_updates_func (GsPluginLoader *plugin_loader)
/* get the virtual non-apps OS update */
app = gs_app_list_index (list, 1);
- g_assert_cmpstr (gs_app_get_id (app), ==, "os-update.virtual");
+ g_assert_cmpstr (gs_app_get_id (app), ==, "org.gnome.Software.OsUpdate");
g_assert_cmpstr (gs_app_get_name (app), ==, "OS Updates");
g_assert_cmpstr (gs_app_get_summary (app), ==, "Includes performance, stability and security
improvements.");
g_assert_cmpint (gs_app_get_kind (app), ==, AS_APP_KIND_OS_UPDATE);
@@ -1377,6 +1378,7 @@ main (int argc, char **argv)
"epiphany",
"flatpak",
"fwupd",
+ "generic-updates",
"hardcoded-blacklist",
"desktop-categories",
"desktop-menu-path",
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index 85014ce..6853865 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -41,6 +41,7 @@ plugin_LTLIBRARIES = \
libgs_plugin_desktop-menu-path.la \
libgs_plugin_dummy.la \
libgs_plugin_dpkg.la \
+ libgs_plugin_generic-updates.la \
libgs_plugin_hardcoded-blacklist.la \
libgs_plugin_hardcoded-popular.la \
libgs_plugin_hardcoded-featured.la \
@@ -133,6 +134,11 @@ libgs_plugin_dpkg_la_LIBADD = $(GS_PLUGIN_LIBS)
libgs_plugin_dpkg_la_LDFLAGS = -module -avoid-version
libgs_plugin_dpkg_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
+libgs_plugin_generic_updates_la_SOURCES = gs-plugin-generic-updates.c
+libgs_plugin_generic_updates_la_LIBADD = $(GS_PLUGIN_LIBS)
+libgs_plugin_generic_updates_la_LDFLAGS = -module -avoid-version
+libgs_plugin_generic_updates_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
+
if HAVE_EXTERNAL_APPSTREAM
libgs_plugin_external_appstream_la_SOURCES = \
gs-plugin-external-appstream.c
diff --git a/src/plugins/gs-plugin-generic-updates.c b/src/plugins/gs-plugin-generic-updates.c
new file mode 100644
index 0000000..b9b5ed5
--- /dev/null
+++ b/src/plugins/gs-plugin-generic-updates.c
@@ -0,0 +1,116 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2016 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/gi18n.h>
+#include <gnome-software.h>
+
+void
+gs_plugin_initialize (GsPlugin *plugin)
+{
+ gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "appstream");
+}
+
+static gboolean
+gs_plugin_generic_updates_merge_os_update (GsApp *app)
+{
+ if (gs_app_get_kind (app) == AS_APP_KIND_GENERIC)
+ return TRUE;
+ if (gs_app_get_kind (app) == AS_APP_KIND_SOURCE)
+ return TRUE;
+ return FALSE;
+}
+
+static GsApp *
+gs_plugin_generic_updates_get_os_update (GsPlugin *plugin)
+{
+ GsApp *app;
+ const gchar *id = "org.gnome.Software.OsUpdate";
+ g_autoptr(AsIcon) ic = NULL;
+
+ /* look in cache */
+ app = gs_plugin_cache_lookup (plugin, id);
+ if (app != NULL)
+ return app;
+
+ /* create new */
+ app = gs_app_new (id);
+ gs_app_set_management_plugin (app, "");
+ gs_app_set_kind (app, AS_APP_KIND_OS_UPDATE);
+ gs_app_set_state (app, AS_APP_STATE_UPDATABLE_LIVE);
+ gs_app_set_name (app,
+ GS_APP_QUALITY_NORMAL,
+ /* TRANSLATORS: this is a group of updates that are not
+ * packages and are not shown in the main list */
+ _("OS Updates"));
+ gs_app_set_summary (app,
+ GS_APP_QUALITY_NORMAL,
+ /* TRANSLATORS: this is a longer description of the
+ * "OS Updates" string */
+ _("Includes performance, stability and security improvements."));
+ gs_app_set_description (app,
+ GS_APP_QUALITY_NORMAL,
+ gs_app_get_summary (app));
+ ic = as_icon_new ();
+ as_icon_set_kind (ic, AS_ICON_KIND_STOCK);
+ as_icon_set_name (ic, "software-update-available-symbolic");
+ gs_app_add_icon (app, ic);
+ gs_plugin_cache_add (plugin, id, app);
+ return app;
+}
+
+gboolean
+gs_plugin_refine (GsPlugin *plugin,
+ GsAppList *list,
+ GsPluginRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
+{
+ g_autoptr(GsApp) app = NULL;
+ g_autoptr(GsAppList) os_updates = gs_app_list_new ();
+
+ /* not from get_updates() */
+ if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_UPDATE_DETAILS) == 0)
+ return TRUE;
+
+ /* do we have any packages left that are not apps? */
+ for (guint i = 0; i < gs_app_list_length (list); i++) {
+ GsApp *app_tmp = gs_app_list_index (list, i);
+ if (gs_plugin_generic_updates_merge_os_update (app_tmp))
+ gs_app_list_add (os_updates, app_tmp);
+ }
+ if (gs_app_list_length (os_updates) == 0)
+ return TRUE;
+
+ /* create new meta object */
+ app = gs_plugin_generic_updates_get_os_update (plugin);
+ for (guint i = 0; i < gs_app_list_length (os_updates); i++) {
+ GsApp *app_tmp = gs_app_list_index (os_updates, i);
+ g_debug ("moving %s to parent %s",
+ gs_app_get_unique_id (app_tmp),
+ gs_app_get_unique_id (app));
+ gs_app_add_related (app, app_tmp);
+ gs_app_list_remove (list, app_tmp);
+ }
+ gs_app_list_add (list, app);
+ return TRUE;
+}
diff --git a/src/plugins/meson.build b/src/plugins/meson.build
index 745c439..24a0ad4 100644
--- a/src/plugins/meson.build
+++ b/src/plugins/meson.build
@@ -34,6 +34,18 @@ shared_module('gs_plugin_dpkg',
dependencies : plugin_libs
)
+shared_module('gs_plugin_generic-updates',
+ sources : 'gs-plugin-generic-updates.c',
+ include_directories : [
+ include_directories('..'),
+ include_directories('../..'),
+ ],
+ install : true,
+ install_dir: plugin_dir,
+ c_args : cargs,
+ dependencies : plugin_libs
+)
+
if get_option('enable-external-appstream')
executable(
'gnome-software-install-appstream',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]