[gnome-software: 3/9] gs-application: Add a debug property




commit cbf28d00fe6fc2c58a8019d3b32189075cb22776
Author: Philip Withnall <pwithnall endlessos org>
Date:   Thu Feb 18 10:35:18 2021 +0000

    gs-application: Add a debug property
    
    This allows the `GsApplication` to store a pointer to the `GsDebug`
    instance for the process. It doesn’t do anything with it yet, but will
    do in subsequent commits.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 src/gs-application.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/gs-application.h |  3 +-
 src/gs-main.c        |  2 +-
 3 files changed, 93 insertions(+), 3 deletions(-)
---
diff --git a/src/gs-application.c b/src/gs-application.c
index 0cda0b9d4..88af2d470 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -30,6 +30,7 @@
 #include "gs-dbus-helper.h"
 #endif
 
+#include "gs-debug.h"
 #include "gs-first-run-dialog.h"
 #include "gs-shell.h"
 #include "gs-update-monitor.h"
@@ -53,10 +54,17 @@ struct _GsApplication {
        GSettings       *settings;
        GSimpleActionGroup      *action_map;
        guint            shell_loaded_handler_id;
+       GsDebug         *debug;  /* (owned) (not nullable) */
 };
 
 G_DEFINE_TYPE (GsApplication, gs_application, GTK_TYPE_APPLICATION);
 
+typedef enum {
+       PROP_DEBUG = 1,
+} GsApplicationProperty;
+
+static GParamSpec *obj_props[PROP_DEBUG + 1] = { NULL, };
+
 enum {
        INSTALL_RESOURCES_DONE,
        LAST_SIGNAL
@@ -1020,6 +1028,55 @@ gs_application_activate (GApplication *application)
        gs_application_show_first_run_dialog (GS_APPLICATION (application));
 }
 
+static void
+gs_application_constructed (GObject *object)
+{
+       GsApplication *self = GS_APPLICATION (object);
+
+       G_OBJECT_CLASS (gs_application_parent_class)->constructed (object);
+
+       /* Check on our construct-only properties */
+       g_assert (self->debug != NULL);
+}
+
+static void
+gs_application_get_property (GObject    *object,
+                             guint       prop_id,
+                             GValue     *value,
+                             GParamSpec *pspec)
+{
+       GsApplication *self = GS_APPLICATION (object);
+
+       switch ((GsApplicationProperty) prop_id) {
+       case PROP_DEBUG:
+               g_value_set_object (value, self->debug);
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+}
+
+static void
+gs_application_set_property (GObject      *object,
+                             guint         prop_id,
+                             const GValue *value,
+                             GParamSpec   *pspec)
+{
+       GsApplication *self = GS_APPLICATION (object);
+
+       switch ((GsApplicationProperty) prop_id) {
+       case PROP_DEBUG:
+               /* Construct only */
+               g_assert (self->debug == NULL);
+               self->debug = g_value_dup_object (value);
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+}
+
 static void
 gs_application_dispose (GObject *object)
 {
@@ -1037,6 +1094,7 @@ gs_application_dispose (GObject *object)
 #endif
        g_clear_object (&app->settings);
        g_clear_object (&app->action_map);
+       g_clear_object (&app->debug);
 
        G_OBJECT_CLASS (gs_application_parent_class)->dispose (object);
 }
@@ -1054,6 +1112,7 @@ get_page_interaction_from_string (const gchar *interaction)
 static int
 gs_application_handle_local_options (GApplication *app, GVariantDict *options)
 {
+       GsApplication *self = GS_APPLICATION (app);
        const gchar *id;
        const gchar *pkgname;
        const gchar *local_filename;
@@ -1169,6 +1228,9 @@ gs_application_class_init (GsApplicationClass *klass)
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
        GApplicationClass *application_class = G_APPLICATION_CLASS (klass);
 
+       object_class->constructed = gs_application_constructed;
+       object_class->get_property = gs_application_get_property;
+       object_class->set_property = gs_application_set_property;
        object_class->dispose = gs_application_dispose;
 
        application_class->startup = gs_application_startup;
@@ -1178,6 +1240,23 @@ gs_application_class_init (GsApplicationClass *klass)
        application_class->dbus_register = gs_application_dbus_register;
        application_class->dbus_unregister = gs_application_dbus_unregister;
 
+       /**
+        * GsApplication:debug: (nullable)
+        *
+        * A #GsDebug object to control debug and logging output from the
+        * application and everything within it.
+        *
+        * This may be %NULL if you don’t care about log output.
+        *
+        * Since: 40
+        */
+       obj_props[PROP_DEBUG] =
+               g_param_spec_object ("debug", NULL, NULL,
+                                    GS_TYPE_DEBUG,
+                                    G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+
+       g_object_class_install_properties (object_class, G_N_ELEMENTS (obj_props), obj_props);
+
        /**
         * GsApplication::install-resources-done:
         * @ident: Operation identificator, as string
@@ -1198,13 +1277,23 @@ gs_application_class_init (GsApplicationClass *klass)
                G_TYPE_STRING, G_TYPE_ERROR);
 }
 
+/**
+ * gs_application_new:
+ * @debug: (transfer none) (not nullable): a #GsDebug for the application instance
+ *
+ * Create a new #GsApplication.
+ *
+ * Returns: (transfer full): a new #GsApplication
+ * Since: 40
+ */
 GsApplication *
-gs_application_new (void)
+gs_application_new (GsDebug *debug)
 {
        return g_object_new (GS_APPLICATION_TYPE,
                             "application-id", "org.gnome.Software",
                             "flags", G_APPLICATION_HANDLES_OPEN,
                             "inactivity-timeout", 12000,
+                            "debug", debug,
                             NULL);
 }
 
diff --git a/src/gs-application.h b/src/gs-application.h
index 6085fb1f1..40bad4d4c 100644
--- a/src/gs-application.h
+++ b/src/gs-application.h
@@ -11,12 +11,13 @@
 #include <gtk/gtk.h>
 
 #include "gnome-software-private.h"
+#include "gs-debug.h"
 
 #define GS_APPLICATION_TYPE (gs_application_get_type ())
 
 G_DECLARE_FINAL_TYPE (GsApplication, gs_application, GS, APPLICATION, GtkApplication)
 
-GsApplication  *gs_application_new             (void);
+GsApplication  *gs_application_new                     (GsDebug *debug);
 GsPluginLoader *gs_application_get_plugin_loader       (GsApplication *application);
 gboolean        gs_application_has_active_window       (GsApplication *application);
 void            gs_application_emit_install_resources_done
diff --git a/src/gs-main.c b/src/gs-main.c
index ed0be685f..03e8c91a4 100644
--- a/src/gs-main.c
+++ b/src/gs-main.c
@@ -43,7 +43,7 @@ main (int argc, char **argv)
        umask (022);
 
        /* redirect logs */
-       application = gs_application_new ();
+       application = gs_application_new (debug);
        appinfo = g_desktop_app_info_new ("org.gnome.Software.desktop");
        g_set_application_name (g_app_info_get_name (G_APP_INFO (appinfo)));
        status = g_application_run (G_APPLICATION (application), argc, argv);


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