[gnome-software/wip/mak/libas: 1/3] Use separate enum for OS update pseudo-apps




commit 46bfd0a0ebaf0fed06207b2766401a9e675287d1
Author: Matthias Klumpp <matthias tenstral net>
Date:   Fri Jan 8 02:14:18 2021 +0100

    Use separate enum for OS update pseudo-apps

 lib/gs-app.c                              | 44 ++++++++++++++++++++++++++++---
 lib/gs-app.h                              | 18 +++++++++++++
 lib/gs-plugin-loader.c                    | 11 ++++----
 plugins/core/gs-appstream.c               |  1 -
 plugins/core/gs-plugin-generic-updates.c  |  2 +-
 plugins/core/gs-self-test.c               |  6 +++--
 plugins/dummy/gs-self-test.c              |  3 ++-
 plugins/malcontent/gs-plugin-malcontent.c |  1 -
 src/gs-common.c                           | 32 +++++++++++-----------
 src/gs-installed-page.c                   |  8 +++---
 src/gs-update-dialog.c                    |  6 +++--
 src/gs-updates-section.c                  |  8 +++---
 12 files changed, 101 insertions(+), 39 deletions(-)
---
diff --git a/lib/gs-app.c b/lib/gs-app.c
index 1be4e236b..8c383092b 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -18,9 +18,8 @@
  * This object represents a 1:1 mapping to a .desktop file. The design is such
  * so you can't have different GsApp's for different versions or architectures
  * of a package. This rule really only applies to GsApps of kind %AS_COMPONENT_KIND_DESKTOP_APP
- * and %AS_COMPONENT_KIND_GENERIC. We allow GsApps of kind %AS_COMPONENT_KIND_OS_UPDATE or
- * %AS_COMPONENT_KIND_GENERIC, which don't correspond to desktop files, but instead
- * represent a system update and its individual components.
+ * and %AS_COMPONENT_KIND_GENERIC. We allow GsApps of kind %AS_COMPONENT_KIND_GENERIC, which
+ * don't correspond to desktop files, but instead represent a system update and its individual components.
  *
  * The #GsPluginLoader de-duplicates the GsApp instances that are produced by
  * plugins to ensure that there is a single instance of GsApp for each id, making
@@ -95,6 +94,7 @@ typedef struct
        guint64                  size_installed;
        guint64                  size_download;
        AsComponentKind          kind;
+       GsAppSpecialKind         special_kind;
        GsAppState               state;
        GsAppState               state_recover;
        AsComponentScope         scope;
@@ -884,6 +884,44 @@ gs_app_set_bundle_kind (GsApp *app, AsBundleKind bundle_kind)
        priv->unique_id_valid = FALSE;
 }
 
+/**
+ * gs_app_get_special_kind:
+ * @app: a #GsApp
+ *
+ * Gets the special occupation of the application.
+ *
+ * Returns: the #GsAppSpecialKind, e.g. %GS_APP_SPECIAL_KIND_OS_UPDATE
+ *
+ * Since: 40
+ **/
+GsAppSpecialKind gs_app_get_special_kind (GsApp *app)
+{
+       GsAppPrivate *priv = gs_app_get_instance_private (app);
+       g_return_if_fail (GS_IS_APP (app));
+       return priv->special_kind;
+}
+
+/**
+ * gs_app_set_special_kind:
+ * @app: a #GsApp
+ * @kind: a #GsAppSpecialKind, e.g. %GS_APP_SPECIAL_KIND_OS_UPDATE
+ *
+ * This sets the special occupation of the application (making
+ * the #AsComponentKind of this application %AS_COMPONENT_KIND_GENERIC
+ * per definition).
+ *
+ * Since: 40
+ **/
+void
+gs_app_set_special_kind        (GsApp *app, GsAppSpecialKind kind)
+{
+       GsAppPrivate *priv = gs_app_get_instance_private (app);
+       g_return_if_fail (GS_IS_APP (app));
+
+       priv->kind = AS_COMPONENT_KIND_GENERIC;
+       priv->special_kind = kind;
+}
+
 /**
  * gs_app_get_state:
  * @app: a #GsApp
diff --git a/lib/gs-app.h b/lib/gs-app.h
index 64ad98862..6ecd75924 100644
--- a/lib/gs-app.h
+++ b/lib/gs-app.h
@@ -62,6 +62,21 @@ typedef enum {
        GS_APP_STATE_LAST
 } GsAppState;
 
+/**
+ * GsAppSpecialKind:
+ * @GS_APP_SPECIAL_KIND_NONE:                  No special occupation
+ * @GS_APP_SPECIAL_KIND_OS_UPDATE:             Application represents an OS update
+ *
+ * A special occupation for #GsApp which does not match an AppStream component type
+ * (usually used for internal purposes in GNOME Software).
+ **/
+typedef enum {
+       GS_APP_SPECIAL_KIND_NONE,               /* Since: 40 */
+       GS_APP_SPECIAL_KIND_OS_UPDATE,          /* Since: 40 */
+       /*< private >*/
+       GS_APP_SPECIAL_KIND_LAST
+} GsAppSpecialKind;
+
 /**
  * GsAppKudo:
  * @GS_APP_KUDO_MY_LANGUAGE:           Localised in my language
@@ -234,6 +249,9 @@ void                 gs_app_set_scope               (GsApp          *app,
 AsBundleKind    gs_app_get_bundle_kind         (GsApp          *app);
 void            gs_app_set_bundle_kind         (GsApp          *app,
                                                 AsBundleKind    bundle_kind);
+GsAppSpecialKind gs_app_get_special_kind       (GsApp          *app);
+void            gs_app_set_special_kind        (GsApp          *app,
+                                                GsAppSpecialKind kind);
 void            gs_app_set_state_recover       (GsApp          *app);
 guint           gs_app_get_progress            (GsApp          *app);
 void            gs_app_set_progress            (GsApp          *app,
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index 6f6aa0c49..4c88404f4 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -1306,8 +1306,9 @@ gs_plugin_loader_app_is_valid (GsApp *app, gpointer user_data)
 
        /* don't show unconverted packages in the application view */
        if (!gs_plugin_job_has_refine_flags (helper->plugin_job,
-                                                GS_PLUGIN_REFINE_FLAGS_ALLOW_PACKAGES) &&
-           (gs_app_get_kind (app) == AS_COMPONENT_KIND_GENERIC)) {
+                                            GS_PLUGIN_REFINE_FLAGS_ALLOW_PACKAGES) &&
+           (gs_app_get_kind (app) == AS_COMPONENT_KIND_GENERIC) &&
+           (gs_app_get_special_kind (app) == GS_APP_SPECIAL_KIND_NONE)) {
                g_debug ("app invalid as only a %s: %s",
                         as_component_kind_to_string (gs_app_get_kind (app)),
                         gs_plugin_loader_get_app_str (app));
@@ -2283,7 +2284,7 @@ gs_plugin_loader_plugin_dir_changed_cb (GFileMonitor *monitor,
        /* add app */
        gs_plugin_event_set_action (event, GS_PLUGIN_ACTION_SETUP);
        app = gs_plugin_loader_app_create (plugin_loader,
-               "system/*/*/*/org.gnome.Software.desktop/*");
+               "system/*/*/org.gnome.Software.desktop/*");
        if (app != NULL)
                gs_plugin_event_set_app (event, app);
 
@@ -3904,7 +3905,7 @@ gs_plugin_loader_app_create (GsPluginLoader *plugin_loader, const gchar *unique_
        /* use the plugin loader to convert a wildcard app*/
        app = gs_app_new (NULL);
        gs_app_add_quirk (app, GS_APP_QUIRK_IS_WILDCARD);
-       gs_app_set_from_unique_id (app, unique_id);
+       gs_app_set_from_unique_id (app, unique_id, AS_COMPONENT_KIND_UNKNOWN);
        gs_app_list_add (list, app);
        plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REFINE, NULL);
        helper = gs_plugin_loader_helper_new (plugin_loader, plugin_job);
@@ -3946,7 +3947,7 @@ gs_plugin_loader_app_create (GsPluginLoader *plugin_loader, const gchar *unique_
 GsApp *
 gs_plugin_loader_get_system_app (GsPluginLoader *plugin_loader)
 {
-       return gs_plugin_loader_app_create (plugin_loader, "*/*/*/*/system/*");
+       return gs_plugin_loader_app_create (plugin_loader, "*/*/*/system/*");
 }
 
 /**
diff --git a/plugins/core/gs-appstream.c b/plugins/core/gs-appstream.c
index 9a2d458f2..6d320c285 100644
--- a/plugins/core/gs-appstream.c
+++ b/plugins/core/gs-appstream.c
@@ -711,7 +711,6 @@ gs_appstream_refine_app (GsPlugin *plugin,
        case AS_COMPONENT_KIND_GENERIC:
        case AS_COMPONENT_KIND_INPUT_METHOD:
        case AS_COMPONENT_KIND_LOCALIZATION:
-       case AS_COMPONENT_KIND_OS_UPDATE:
        case AS_COMPONENT_KIND_OPERATING_SYSTEM:
        case AS_COMPONENT_KIND_RUNTIME:
        case AS_COMPONENT_KIND_REPOSITORY:
diff --git a/plugins/core/gs-plugin-generic-updates.c b/plugins/core/gs-plugin-generic-updates.c
index 2a45a4585..319529f71 100644
--- a/plugins/core/gs-plugin-generic-updates.c
+++ b/plugins/core/gs-plugin-generic-updates.c
@@ -47,7 +47,7 @@ gs_plugin_generic_updates_get_os_update (GsPlugin *plugin)
        app = gs_app_new (id);
        gs_app_add_quirk (app, GS_APP_QUIRK_IS_PROXY);
        gs_app_set_management_plugin (app, "");
-       gs_app_set_kind (app, AS_COMPONENT_KIND_OS_UPDATE);
+       gs_app_set_special_kind (app, GS_APP_SPECIAL_KIND_OS_UPDATE);
        gs_app_set_state (app, GS_APP_STATE_UPDATABLE_LIVE);
        gs_app_set_name (app,
                         GS_APP_QUALITY_NORMAL,
diff --git a/plugins/core/gs-self-test.c b/plugins/core/gs-self-test.c
index f2c285890..90bf7b4f5 100644
--- a/plugins/core/gs-self-test.c
+++ b/plugins/core/gs-self-test.c
@@ -146,7 +146,8 @@ gs_plugins_core_generic_updates_func (GsPluginLoader *plugin_loader)
 
        /* make sure the os update is valid */
        g_assert_cmpstr (gs_app_get_id (os_update), ==, "org.gnome.Software.OsUpdate");
-       g_assert_cmpint (gs_app_get_kind (os_update), ==, AS_COMPONENT_KIND_OS_UPDATE);
+       g_assert_cmpint (gs_app_get_kind (os_update), ==, AS_COMPONENT_KIND_GENERIC);
+       g_assert_cmpint (gs_app_get_special_kind (os_update), ==, GS_APP_SPECIAL_KIND_OS_UPDATE);
        g_assert (gs_app_has_quirk (os_update, GS_APP_QUIRK_IS_PROXY));
 
        /* must have two related apps, the ones we added earlier */
@@ -171,7 +172,8 @@ gs_plugins_core_generic_updates_func (GsPluginLoader *plugin_loader)
        /* no OsUpdate item created */
        for (guint i = 0; i < gs_app_list_length (list_wildcard); i++) {
                GsApp *app_tmp = gs_app_list_index (list_wildcard, i);
-               g_assert_cmpint (gs_app_get_kind (app_tmp), !=, AS_COMPONENT_KIND_OS_UPDATE);
+               g_assert_cmpint (gs_app_get_kind (app_tmp), !=, AS_COMPONENT_KIND_GENERIC);
+               g_assert_cmpint (gs_app_get_special_kind (app_tmp), !=, GS_APP_SPECIAL_KIND_OS_UPDATE);
                g_assert (!gs_app_has_quirk (app_tmp, GS_APP_QUIRK_IS_PROXY));
        }
 }
diff --git a/plugins/dummy/gs-self-test.c b/plugins/dummy/gs-self-test.c
index de0e91959..b51ca1665 100644
--- a/plugins/dummy/gs-self-test.c
+++ b/plugins/dummy/gs-self-test.c
@@ -277,7 +277,8 @@ gs_plugins_dummy_updates_func (GsPluginLoader *plugin_loader)
        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_COMPONENT_KIND_OS_UPDATE);
+       g_assert_cmpint (gs_app_get_kind (app), ==, AS_COMPONENT_KIND_GENERIC);
+       g_assert_cmpint (gs_app_get_special_kind (app), ==, GS_APP_SPECIAL_KIND_OS_UPDATE);
        g_assert_cmpint (gs_app_get_state (app), ==, GS_APP_STATE_UPDATABLE);
        g_assert_cmpint (gs_app_list_length (gs_app_get_related (app)), ==, 2);
 
diff --git a/plugins/malcontent/gs-plugin-malcontent.c b/plugins/malcontent/gs-plugin-malcontent.c
index afff5fa7d..22b89d17d 100644
--- a/plugins/malcontent/gs-plugin-malcontent.c
+++ b/plugins/malcontent/gs-plugin-malcontent.c
@@ -70,7 +70,6 @@ app_is_expected_to_have_content_rating (GsApp *app)
        case AS_COMPONENT_KIND_GENERIC:
        case AS_COMPONENT_KIND_INPUT_METHOD:
        case AS_COMPONENT_KIND_LOCALIZATION:
-       case AS_COMPONENT_KIND_OS_UPDATE:
        case AS_COMPONENT_KIND_OPERATING_SYSTEM:
        case AS_COMPONENT_KIND_RUNTIME:
        case AS_COMPONENT_KIND_REPOSITORY:
diff --git a/src/gs-common.c b/src/gs-common.c
index 2573e7912..acbecc4b5 100644
--- a/src/gs-common.c
+++ b/src/gs-common.c
@@ -118,14 +118,6 @@ gs_app_notify_installed (GsApp *app)
        g_autoptr(GNotification) n = NULL;
 
        switch (gs_app_get_kind (app)) {
-       case AS_COMPONENT_KIND_OS_UPDATE:
-               /* TRANSLATORS: this is the summary of a notification that OS updates
-                * have been successfully installed */
-               summary = g_strdup (_("OS updates are now installed"));
-               /* TRANSLATORS: this is the body of a notification that OS updates
-                * have been successfully installed */
-               body = _("Recently installed updates are available to review");
-               break;
        case AS_COMPONENT_KIND_DESKTOP_APP:
                /* TRANSLATORS: this is the summary of a notification that an application
                 * has been successfully installed */
@@ -141,13 +133,23 @@ gs_app_notify_installed (GsApp *app)
                }
                break;
        default:
-               /* TRANSLATORS: this is the summary of a notification that a component
-                * has been successfully installed */
-               summary = g_strdup_printf (_("%s is now installed"), gs_app_get_name (app));
-               if (gs_app_has_quirk (app, GS_APP_QUIRK_NEEDS_REBOOT)) {
-                       /* TRANSLATORS: an application has been installed, but
-                        * needs a reboot to complete the installation */
-                       body = _("A restart is required for the changes to take effect.");
+               if ((gs_app_get_kind (app) == AS_COMPONENT_KIND_GENERIC) &&
+                   (gs_app_get_special_kind (app) == GS_APP_SPECIAL_KIND_OS_UPDATE)) {
+                       /* TRANSLATORS: this is the summary of a notification that OS updates
+                       * have been successfully installed */
+                       summary = g_strdup (_("OS updates are now installed"));
+                       /* TRANSLATORS: this is the body of a notification that OS updates
+                       * have been successfully installed */
+                       body = _("Recently installed updates are available to review");
+               } else {
+                       /* TRANSLATORS: this is the summary of a notification that a component
+                       * has been successfully installed */
+                       summary = g_strdup_printf (_("%s is now installed"), gs_app_get_name (app));
+                       if (gs_app_has_quirk (app, GS_APP_QUIRK_NEEDS_REBOOT)) {
+                               /* TRANSLATORS: an application has been installed, but
+                               * needs a reboot to complete the installation */
+                               body = _("A restart is required for the changes to take effect.");
+                       }
                }
                break;
        }
diff --git a/src/gs-installed-page.c b/src/gs-installed-page.c
index 2f69ffea0..b9da99f14 100644
--- a/src/gs-installed-page.c
+++ b/src/gs-installed-page.c
@@ -336,9 +336,6 @@ gs_installed_page_get_app_sort_key (GsApp *app)
 
        /* sort apps by kind */
        switch (gs_app_get_kind (app)) {
-       case AS_COMPONENT_KIND_OS_UPDATE:
-               g_string_append (key, "1:");
-               break;
        case AS_COMPONENT_KIND_DESKTOP_APP:
                g_string_append (key, "2:");
                break;
@@ -361,7 +358,10 @@ gs_installed_page_get_app_sort_key (GsApp *app)
                g_string_append (key, "7:");
                break;
        default:
-               g_string_append (key, "8:");
+               if (gs_app_get_special_kind (app) == GS_APP_SPECIAL_KIND_OS_UPDATE)
+                       g_string_append (key, "1:");
+               else
+                       g_string_append (key, "8:");
                break;
        }
 
diff --git a/src/gs-update-dialog.c b/src/gs-update-dialog.c
index ebed476ec..8a2ab703e 100644
--- a/src/gs-update-dialog.c
+++ b/src/gs-update-dialog.c
@@ -162,7 +162,8 @@ set_updates_description_ui (GsUpdateDialog *dialog, GsApp *app)
 
        /* set window title */
        kind = gs_app_get_kind (app);
-       if (kind == AS_COMPONENT_KIND_OS_UPDATE) {
+       if ((kind == AS_COMPONENT_KIND_GENERIC) &&
+           (gs_app_get_special_kind (app) == GS_APP_SPECIAL_KIND_OS_UPDATE)) {
                gtk_window_set_title (GTK_WINDOW (dialog), gs_app_get_name (app));
        } else if (gs_app_get_source_default (app) != NULL &&
                   gs_app_get_update_version (app) != NULL) {
@@ -636,7 +637,8 @@ gs_update_dialog_show_update_details (GsUpdateDialog *dialog, GsApp *app)
 
        /* set update description */
        kind = gs_app_get_kind (app);
-       if (kind == AS_COMPONENT_KIND_OS_UPDATE) {
+       if ((kind == AS_COMPONENT_KIND_GENERIC) &&
+           (gs_app_get_special_kind (app) == GS_APP_SPECIAL_KIND_OS_UPDATE)) {
                GsAppList *related;
                GsApp *app_related;
                GsUpdateDialogSection section;
diff --git a/src/gs-updates-section.c b/src/gs-updates-section.c
index b30a25ff4..651aee9a9 100644
--- a/src/gs-updates-section.c
+++ b/src/gs-updates-section.c
@@ -142,9 +142,6 @@ _get_app_sort_key (GsApp *app)
 
        /* sort apps by kind */
        switch (gs_app_get_kind (app)) {
-       case AS_COMPONENT_KIND_OS_UPDATE:
-               g_string_append (key, "1:");
-               break;
        case AS_COMPONENT_KIND_DESKTOP_APP:
                g_string_append (key, "2:");
                break;
@@ -167,7 +164,10 @@ _get_app_sort_key (GsApp *app)
                g_string_append (key, "7:");
                break;
        default:
-               g_string_append (key, "8:");
+               if (gs_app_get_special_kind (app) == GS_APP_SPECIAL_KIND_OS_UPDATE)
+                       g_string_append (key, "1:");
+               else
+                       g_string_append (key, "8:");
                break;
        }
 


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