[gnome-software] trivial: Export gs_app_to_string_append() so it can be used from GsApp subclasses



commit 550f461add9082d148edea9030e37c5bf850e295
Author: Richard Hughes <richard hughsie com>
Date:   Thu Jul 13 21:41:28 2017 +0100

    trivial: Export gs_app_to_string_append() so it can be used from GsApp subclasses

 lib/gs-app.c |   40 +++++++++++++++++++++++++++++++---------
 lib/gs-app.h |    6 +++++-
 2 files changed, 36 insertions(+), 10 deletions(-)
---
diff --git a/lib/gs-app.c b/lib/gs-app.c
index 8da3556..652b157 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -366,18 +366,37 @@ gs_app_kudos_to_string (guint64 kudos)
 gchar *
 gs_app_to_string (GsApp *app)
 {
+       GString *str = g_string_new ("GsApp:");
+       gs_app_to_string_append (app, str);
+       if (str->len > 0)
+               g_string_truncate (str, str->len - 1);
+       return g_string_free (str, FALSE);
+}
+
+/**
+ * gs_app_to_string_append:
+ * @app: a #GsApp
+ * @str: a #GString
+ *
+ * Appends the application to an existing string.
+ *
+ * Since: 3.26
+ **/
+void
+gs_app_to_string_append (GsApp *app, GString *str)
+{
+       GsAppClass *klass = GS_APP_GET_CLASS (app);
        GsAppPrivate *priv = gs_app_get_instance_private (app);
        AsImage *im;
        AsScreenshot *ss;
        GList *keys;
        GList *l;
-       GString *str;
        const gchar *tmp;
        guint i;
 
-       g_return_val_if_fail (GS_IS_APP (app), NULL);
+       g_return_if_fail (GS_IS_APP (app));
+       g_return_if_fail (str != NULL);
 
-       str = g_string_new ("GsApp:");
        g_string_append_printf (str, " [%p]\n", app);
        gs_app_kv_lpad (str, "kind", as_app_kind_to_string (priv->kind));
        gs_app_kv_lpad (str, "state", as_app_state_to_string (priv->state));
@@ -569,17 +588,20 @@ gs_app_to_string (GsApp *app)
        }
        g_list_free (keys);
 
+       /* add subclassed info */
+       if (klass->to_string != NULL)
+               klass->to_string (app, str);
+
        /* print runtime data too */
        if (priv->runtime != NULL) {
-               g_autofree gchar *runtime = gs_app_to_string (priv->runtime);
-               g_string_append_printf (str, "\n\tRuntime:\n\t%s\n", runtime);
+               g_string_append (str, "\n\tRuntime:\n\t");
+               gs_app_to_string_append (priv->runtime, str);
        }
        if (priv->update_runtime != NULL) {
-               g_autofree gchar *runtime = gs_app_to_string (priv->update_runtime);
-               g_string_append_printf (str, "\n\tUpdate Runtime:\n\t%s\n", runtime);
+               g_string_append (str, "\n\tUpdate Runtime:\n\t");
+               gs_app_to_string_append (priv->update_runtime, str);
        }
-
-       return g_string_free (str, FALSE);
+       g_string_append_printf (str, "\n");
 }
 
 typedef struct {
diff --git a/lib/gs-app.h b/lib/gs-app.h
index e09bf1a..a217be0 100644
--- a/lib/gs-app.h
+++ b/lib/gs-app.h
@@ -38,7 +38,9 @@ G_DECLARE_DERIVABLE_TYPE (GsApp, gs_app, GS, APP, GObject)
 struct _GsAppClass
 {
        GObjectClass             parent_class;
-       gpointer                 padding[31];
+       void                     (*to_string)   (GsApp          *app,
+                                                GString        *str);
+       gpointer                 padding[30];
 };
 
 /**
@@ -111,6 +113,8 @@ GsApp               *gs_app_new_from_unique_id      (const gchar    *unique_id);
 void            gs_app_set_from_unique_id      (GsApp          *app,
                                                 const gchar    *unique_id);
 gchar          *gs_app_to_string               (GsApp          *app);
+void            gs_app_to_string_append        (GsApp          *app,
+                                                GString        *str);
 
 const gchar    *gs_app_get_id                  (GsApp          *app);
 void            gs_app_set_id                  (GsApp          *app,


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