[gdm/wip/nielsdg/add-private-deprecated: 1/10] session-auditor: use G_DECLARE_DERIVABLE_TYPE



commit 3d3cc6ab194741bdce7b1ad86023db9098c266e6
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Sun Dec 23 18:21:14 2018 +0100

    session-auditor: use G_DECLARE_DERIVABLE_TYPE

 daemon/gdm-session-auditor.c | 59 ++++++++++++++++++++++++++++----------------
 daemon/gdm-session-auditor.h | 20 ++-------------
 2 files changed, 40 insertions(+), 39 deletions(-)
---
diff --git a/daemon/gdm-session-auditor.c b/daemon/gdm-session-auditor.c
index c4927094..548e54b9 100644
--- a/daemon/gdm-session-auditor.c
+++ b/daemon/gdm-session-auditor.c
@@ -34,12 +34,12 @@
 #include <glib-object.h>
 #include <glib/gi18n.h>
 
-struct _GdmSessionAuditorPrivate
+typedef struct _GdmSessionAuditorPrivate
 {
         char *username;
         char *hostname;
         char *display_device;
-};
+} GdmSessionAuditorPrivate;
 
 static void gdm_session_auditor_finalize (GObject *object);
 static void gdm_session_auditor_class_install_properties (GdmSessionAuditorClass *
@@ -61,7 +61,7 @@ enum {
         PROP_DISPLAY_DEVICE
 };
 
-G_DEFINE_TYPE (GdmSessionAuditor, gdm_session_auditor, G_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_PRIVATE (GdmSessionAuditor, gdm_session_auditor, G_TYPE_OBJECT)
 
 static void
 gdm_session_auditor_class_init (GdmSessionAuditorClass *auditor_class)
@@ -73,8 +73,6 @@ gdm_session_auditor_class_init (GdmSessionAuditorClass *auditor_class)
         object_class->finalize = gdm_session_auditor_finalize;
 
         gdm_session_auditor_class_install_properties (auditor_class);
-
-        g_type_class_add_private (auditor_class, sizeof (GdmSessionAuditorPrivate));
 }
 
 static void
@@ -108,23 +106,21 @@ gdm_session_auditor_class_install_properties (GdmSessionAuditorClass *auditor_cl
 static void
 gdm_session_auditor_init (GdmSessionAuditor *auditor)
 {
-        auditor->priv = G_TYPE_INSTANCE_GET_PRIVATE (auditor,
-                                                     GDM_TYPE_SESSION_AUDITOR,
-                                                     GdmSessionAuditorPrivate);
-
 }
 
 static void
 gdm_session_auditor_finalize (GObject *object)
 {
         GdmSessionAuditor *auditor;
+        GdmSessionAuditorPrivate *priv;
         GObjectClass *parent_class;
 
         auditor = GDM_SESSION_AUDITOR (object);
+        priv = gdm_session_auditor_get_instance_private (auditor);
 
-        g_free (auditor->priv->username);
-        g_free (auditor->priv->hostname);
-        g_free (auditor->priv->display_device);
+        g_free (priv->username);
+        g_free (priv->hostname);
+        g_free (priv->display_device);
 
         parent_class = G_OBJECT_CLASS (gdm_session_auditor_parent_class);
 
@@ -137,15 +133,19 @@ void
 gdm_session_auditor_set_username (GdmSessionAuditor *auditor,
                                   const char        *username)
 {
+        GdmSessionAuditorPrivate *priv;
+
         g_return_if_fail (GDM_IS_SESSION_AUDITOR (auditor));
 
-        if (username == auditor->priv->username) {
+        priv = gdm_session_auditor_get_instance_private (auditor);
+
+        if (username == priv->username) {
                 return;
         }
 
-        if ((username == NULL || auditor->priv->username == NULL) ||
-            strcmp (username, auditor->priv->username) != 0) {
-                auditor->priv->username = g_strdup (username);
+        if ((username == NULL || priv->username == NULL) ||
+            strcmp (username, priv->username) != 0) {
+                priv->username = g_strdup (username);
                 g_object_notify (G_OBJECT (auditor), "username");
         }
 }
@@ -154,34 +154,51 @@ static void
 gdm_session_auditor_set_hostname (GdmSessionAuditor *auditor,
                                   const char        *hostname)
 {
+        GdmSessionAuditorPrivate *priv;
+
         g_return_if_fail (GDM_IS_SESSION_AUDITOR (auditor));
-        auditor->priv->hostname = g_strdup (hostname);
+
+        priv = gdm_session_auditor_get_instance_private (auditor);
+        priv->hostname = g_strdup (hostname);
 }
 
 static void
 gdm_session_auditor_set_display_device (GdmSessionAuditor *auditor,
                                         const char        *display_device)
 {
+        GdmSessionAuditorPrivate *priv;
+
         g_return_if_fail (GDM_IS_SESSION_AUDITOR (auditor));
-        auditor->priv->display_device = g_strdup (display_device);
+
+        priv = gdm_session_auditor_get_instance_private (auditor);
+        priv->display_device = g_strdup (display_device);
 }
 
 static char *
 gdm_session_auditor_get_username (GdmSessionAuditor *auditor)
 {
-        return g_strdup (auditor->priv->username);
+        GdmSessionAuditorPrivate *priv;
+
+        priv = gdm_session_auditor_get_instance_private (auditor);
+        return g_strdup (priv->username);
 }
 
 static char *
 gdm_session_auditor_get_hostname (GdmSessionAuditor *auditor)
 {
-        return g_strdup (auditor->priv->hostname);
+        GdmSessionAuditorPrivate *priv;
+
+        priv = gdm_session_auditor_get_instance_private (auditor);
+        return g_strdup (priv->hostname);
 }
 
 static char *
 gdm_session_auditor_get_display_device (GdmSessionAuditor *auditor)
 {
-        return g_strdup (auditor->priv->display_device);
+        GdmSessionAuditorPrivate *priv;
+
+        priv = gdm_session_auditor_get_instance_private (auditor);
+        return g_strdup (priv->display_device);
 }
 
 static void
diff --git a/daemon/gdm-session-auditor.h b/daemon/gdm-session-auditor.h
index 1ebf390f..dde00f68 100644
--- a/daemon/gdm-session-auditor.h
+++ b/daemon/gdm-session-auditor.h
@@ -30,24 +30,9 @@
 #include <glib-object.h>
 
 G_BEGIN_DECLS
-#define GDM_TYPE_SESSION_AUDITOR (gdm_session_auditor_get_type ())
-#define GDM_SESSION_AUDITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDM_TYPE_SESSION_AUDITOR, 
GdmSessionAuditor))
-#define GDM_SESSION_AUDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDM_TYPE_SESSION_AUDITOR, 
GdmSessionAuditorClass))
-#define GDM_IS_SESSION_AUDITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GDM_TYPE_SESSION_AUDITOR))
-#define GDM_IS_SESSION_AUDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDM_TYPE_SESSION_AUDITOR))
-#define GDM_SESSION_AUDITOR_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), GDM_TYPE_SESSION_AUDITOR, 
GdmSessionAuditorClass))
-#define GDM_SESSION_AUDITOR_ERROR (gdm_session_auditor_error_quark ())
-typedef struct _GdmSessionAuditor GdmSessionAuditor;
-typedef struct _GdmSessionAuditorClass GdmSessionAuditorClass;
-typedef struct _GdmSessionAuditorPrivate GdmSessionAuditorPrivate;
-
-struct _GdmSessionAuditor
-{
-        GObject                   parent;
 
-        /*< private > */
-        GdmSessionAuditorPrivate *priv;
-};
+#define GDM_TYPE_SESSION_AUDITOR (gdm_session_auditor_get_type ())
+G_DECLARE_DERIVABLE_TYPE (GdmSessionAuditor, gdm_session_auditor, GDM, SESSION_AUDITOR, GObject)
 
 struct _GdmSessionAuditorClass
 {
@@ -63,7 +48,6 @@ struct _GdmSessionAuditorClass
         void               (* report_logout)                  (GdmSessionAuditor *auditor);
 };
 
-GType                     gdm_session_auditor_get_type           (void);
 GdmSessionAuditor        *gdm_session_auditor_new                (const char *hostname,
                                                                   const char *display_device);
 void                      gdm_session_auditor_set_username (GdmSessionAuditor *auditor,


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