[gnome-software: 1/10] gs-app: Add a has-translations property




commit 98a4fd37a6561e8eae67059d0c5621ff1a6f0ca7
Author: Philip Withnall <pwithnall endlessos org>
Date:   Wed Aug 11 15:24:17 2021 +0100

    gs-app: Add a has-translations property
    
    This is true if the app knows which translations it has (i.e. a
    `<languages>` element is present in its appdata).
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1354

 lib/gs-app.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 lib/gs-app.h |  4 ++++
 2 files changed, 74 insertions(+), 1 deletion(-)
---
diff --git a/lib/gs-app.c b/lib/gs-app.c
index 7411400eb..457f37c0e 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -133,6 +133,7 @@ typedef struct
        gboolean                 is_update_downloaded;
        GPtrArray               *version_history; /* (element-type AsRelease) (nullable) (owned) */
        GPtrArray               *relations;  /* (nullable) (element-type AsRelation) (owned) */
+       gboolean                 has_translations;
 } GsAppPrivate;
 
 typedef enum {
@@ -166,9 +167,10 @@ typedef enum {
        PROP_PERMISSIONS,
        PROP_RELATIONS,
        PROP_ORIGIN_UI,
+       PROP_HAS_TRANSLATIONS,
 } GsAppProperty;
 
-static GParamSpec *obj_props[PROP_ORIGIN_UI + 1] = { NULL, };
+static GParamSpec *obj_props[PROP_HAS_TRANSLATIONS + 1] = { NULL, };
 
 G_DEFINE_TYPE_WITH_PRIVATE (GsApp, gs_app, G_TYPE_OBJECT)
 
@@ -4877,6 +4879,9 @@ gs_app_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *
        case PROP_ORIGIN_UI:
                g_value_take_string (value, gs_app_get_origin_ui (app));
                break;
+       case PROP_HAS_TRANSLATIONS:
+               g_value_set_boolean (value, gs_app_get_has_translations (app));
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -4988,6 +4993,9 @@ gs_app_set_property (GObject *object, guint prop_id, const GValue *value, GParam
        case PROP_ORIGIN_UI:
                gs_app_set_origin_ui (app, g_value_get_string (value));
                break;
+       case PROP_HAS_TRANSLATIONS:
+               gs_app_set_has_translations (app, g_value_get_boolean (value));
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -5416,6 +5424,21 @@ gs_app_class_init (GsAppClass *klass)
                                     NULL,
                                     G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
 
+       /**
+        * GsApp:has-translations
+        *
+        * Whether the app has any information about provided translations. If
+        * this is %TRUE, the app provides information about the translations
+        * it ships. If %FALSE, the app does not provide any information (but
+        * might ship translations which aren’t mentioned).
+        *
+        * Since: 41
+        */
+       obj_props[PROP_HAS_TRANSLATIONS] =
+               g_param_spec_boolean ("has-translations", NULL, NULL,
+                                     FALSE,
+                                     G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+
        g_object_class_install_properties (object_class, G_N_ELEMENTS (obj_props), obj_props);
 }
 
@@ -5966,3 +5989,49 @@ gs_app_set_relations (GsApp     *app,
 
        gs_app_queue_notify (app, obj_props[PROP_RELATIONS]);
 }
+
+/**
+ * gs_app_get_has_translations:
+ * @app: a #GsApp
+ *
+ * Get the value of #GsApp:has-translations.
+ *
+ * Returns: %TRUE if the app has translation metadata, %FALSE otherwise
+ * Since: 41
+ */
+gboolean
+gs_app_get_has_translations (GsApp *app)
+{
+       GsAppPrivate *priv = gs_app_get_instance_private (app);
+
+       g_return_val_if_fail (GS_IS_APP (app), FALSE);
+
+       return priv->has_translations;
+}
+
+/**
+ * gs_app_set_has_translations:
+ * @app: a #GsApp
+ * @has_translations: %TRUE if the app has translation metadata, %FALSE otherwise
+ *
+ * Set the value of #GsApp:has-translations.
+ *
+ * Since: 41
+ */
+void
+gs_app_set_has_translations (GsApp    *app,
+                             gboolean  has_translations)
+{
+       GsAppPrivate *priv = gs_app_get_instance_private (app);
+       g_autoptr(GMutexLocker) locker = NULL;
+
+       g_return_if_fail (GS_IS_APP (app));
+
+       locker = g_mutex_locker_new (&priv->mutex);
+
+       if (priv->has_translations == has_translations)
+               return;
+
+       priv->has_translations = has_translations;
+       gs_app_queue_notify (app, obj_props[PROP_HAS_TRANSLATIONS]);
+}
diff --git a/lib/gs-app.h b/lib/gs-app.h
index 8068b85f7..58a6184fd 100644
--- a/lib/gs-app.h
+++ b/lib/gs-app.h
@@ -499,4 +499,8 @@ void                 gs_app_add_relation            (GsApp          *app,
 void            gs_app_set_relations           (GsApp          *app,
                                                 GPtrArray      *relations);
 
+gboolean        gs_app_get_has_translations    (GsApp          *app);
+void            gs_app_set_has_translations    (GsApp          *app,
+                                                gboolean        has_translations);
+
 G_END_DECLS


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