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




commit 29660543f820516eb532d114b4e217ad191cc70c
Author: Matthias Klumpp <matthias tenstral net>
Date:   Tue Feb 9 23:48:48 2021 +0100

    Use separate enum for OS update pseudo-apps

 lib/gs-app.c                              | 63 +++++++++++++++++++++++++++++++
 lib/gs-app.h                              | 19 ++++++++++
 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, 124 insertions(+), 36 deletions(-)
---
diff --git a/lib/gs-app.c b/lib/gs-app.c
index b86351ad9..b6ce933a7 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -100,6 +100,7 @@ typedef struct
        guint64                  size_installed;
        guint64                  size_download;
        AsComponentKind          kind;
+       GsAppSpecialKind         special_kind;
        GsAppState               state;
        GsAppState               state_recover;
        AsComponentScope         scope;
@@ -136,6 +137,7 @@ enum {
        PROP_DESCRIPTION,
        PROP_RATING,
        PROP_KIND,
+       PROP_SPECIAL_KIND,
        PROP_STATE,
        PROP_PROGRESS,
        PROP_CAN_CANCEL_INSTALLATION,
@@ -879,6 +881,48 @@ 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_val_if_fail (GS_IS_APP (app), GS_APP_SPECIAL_KIND_NONE);
+       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));
+
+       if (priv->special_kind == kind)
+               return;
+       gs_app_set_kind (app, AS_COMPONENT_KIND_GENERIC);
+       priv->special_kind = kind;
+       gs_app_queue_notify (app, obj_props[PROP_SPECIAL_KIND]);
+}
+
 /**
  * gs_app_get_state:
  * @app: a #GsApp
@@ -4363,6 +4407,9 @@ gs_app_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *
        case PROP_KIND:
                g_value_set_uint (value, priv->kind);
                break;
+       case PROP_SPECIAL_KIND:
+               g_value_set_enum (value, priv->special_kind);
+               break;
        case PROP_STATE:
                g_value_set_enum (value, priv->state);
                break;
@@ -4430,6 +4477,9 @@ gs_app_set_property (GObject *object, guint prop_id, const GValue *value, GParam
        case PROP_KIND:
                gs_app_set_kind (app, g_value_get_uint (value));
                break;
+       case PROP_SPECIAL_KIND:
+               gs_app_set_special_kind (app, g_value_get_enum (value));
+               break;
        case PROP_STATE:
                gs_app_set_state_internal (app, g_value_get_enum (value));
                break;
@@ -4595,6 +4645,19 @@ gs_app_class_init (GsAppClass *klass)
                                   AS_COMPONENT_KIND_UNKNOWN,
                                   G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
 
+       /**
+        * GsApp:special-kind:
+        *
+        * GNOME Software specific occupation of the #GsApp entity
+        * that does not reflect a software type defined by AppStream.
+        *
+        * Since: 40
+        */
+       obj_props[PROP_SPECIAL_KIND] = g_param_spec_enum ("special-kind", NULL, NULL,
+                                       GS_TYPE_APP_SPECIAL_KIND,
+                                       GS_APP_SPECIAL_KIND_NONE,
+                                       G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+
        /**
         * GsApp:state:
         */
diff --git a/lib/gs-app.h b/lib/gs-app.h
index b958561f9..78af6e526 100644
--- a/lib/gs-app.h
+++ b/lib/gs-app.h
@@ -61,6 +61,22 @@ typedef enum {
        GS_APP_STATE_LAST  /*< skip >*/
 } 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. #AsComponentKind can not represent certain
+ * GNOME Software specific features, like representing a #GsApp as OS updates
+ * which have no associated AppStream entry.
+ * They are represented by a #GsApp of kind %AS_COMPONENT_KIND_GENERIC and a value
+ * from #GsAppSpecialKind. which does not match any AppStream component type.
+ **/
+typedef enum {
+       GS_APP_SPECIAL_KIND_NONE,               /* Since: 40 */
+       GS_APP_SPECIAL_KIND_OS_UPDATE,          /* Since: 40 */
+} GsAppSpecialKind;
+
 /**
  * GsAppKudo:
  * @GS_APP_KUDO_MY_LANGUAGE:           Localised in my language
@@ -230,6 +246,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 cd41040e3..8e06b3b4f 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -1305,8 +1305,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));
@@ -2225,7 +2226,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);
 
@@ -3832,7 +3833,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);
@@ -3874,7 +3875,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 f7b9844cf..d7df3843f 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 6cc118f2e..53be465a9 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 2017e1392..8e7e7ca87 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..404f9ae93 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 965bacf2c..21bb128e5 100644
--- a/src/gs-installed-page.c
+++ b/src/gs-installed-page.c
@@ -339,9 +339,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;
@@ -364,7 +361,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 82dc5311a..059188b13 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 7678e5779..f925b1fbe 100644
--- a/src/gs-updates-section.c
+++ b/src/gs-updates-section.c
@@ -151,9 +151,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;
@@ -176,7 +173,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]