[gdm/wip/nielsdg/add-private-deprecated: 9/20] xdmcp-display: use G_DECLARE_DERIVABLE_TYPE



commit 3e4ab962a0a13f5ec4d0e095c3c5b75062502f09
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Sun Dec 23 15:36:03 2018 +0100

    xdmcp-display: use G_DECLARE_DERIVABLE_TYPE

 daemon/gdm-xdmcp-display.c | 49 +++++++++++++++++++++++++++-------------------
 daemon/gdm-xdmcp-display.h | 23 ++++------------------
 2 files changed, 33 insertions(+), 39 deletions(-)
---
diff --git a/daemon/gdm-xdmcp-display.c b/daemon/gdm-xdmcp-display.c
index 630844f2..f4020672 100644
--- a/daemon/gdm-xdmcp-display.c
+++ b/daemon/gdm-xdmcp-display.c
@@ -46,14 +46,12 @@
 #include "gdm-settings-direct.h"
 #include "gdm-settings-keys.h"
 
-#define GDM_XDMCP_DISPLAY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_XDMCP_DISPLAY, 
GdmXdmcpDisplayPrivate))
-
-struct GdmXdmcpDisplayPrivate
+typedef struct _GdmXdmcpDisplayPrivate
 {
         GdmAddress             *remote_address;
         gint32                  session_number;
         guint                   connection_attempts;
-};
+} GdmXdmcpDisplayPrivate;
 
 enum {
         PROP_0,
@@ -66,36 +64,45 @@ enum {
 static void     gdm_xdmcp_display_class_init    (GdmXdmcpDisplayClass *klass);
 static void     gdm_xdmcp_display_init          (GdmXdmcpDisplay      *xdmcp_display);
 
-G_DEFINE_TYPE (GdmXdmcpDisplay, gdm_xdmcp_display, GDM_TYPE_DISPLAY)
+G_DEFINE_TYPE_WITH_PRIVATE (GdmXdmcpDisplay, gdm_xdmcp_display, GDM_TYPE_DISPLAY)
 
 gint32
 gdm_xdmcp_display_get_session_number (GdmXdmcpDisplay *display)
 {
+        GdmXdmcpDisplayPrivate *priv;
+
         g_return_val_if_fail (GDM_IS_XDMCP_DISPLAY (display), 0);
 
-        return display->priv->session_number;
+        priv = gdm_xdmcp_display_get_instance_private (display);
+        return priv->session_number;
 }
 
 GdmAddress *
 gdm_xdmcp_display_get_remote_address (GdmXdmcpDisplay *display)
 {
+        GdmXdmcpDisplayPrivate *priv;
+
         g_return_val_if_fail (GDM_IS_XDMCP_DISPLAY (display), NULL);
 
-        return display->priv->remote_address;
+        priv = gdm_xdmcp_display_get_instance_private (display);
+        return priv->remote_address;
 }
 
 static void
 _gdm_xdmcp_display_set_remote_address (GdmXdmcpDisplay *display,
                                        GdmAddress      *address)
 {
-        if (display->priv->remote_address != NULL) {
-                gdm_address_free (display->priv->remote_address);
+        GdmXdmcpDisplayPrivate *priv;
+
+        priv = gdm_xdmcp_display_get_instance_private (display);
+        if (priv->remote_address != NULL) {
+                gdm_address_free (priv->remote_address);
         }
 
         g_assert (address != NULL);
 
         gdm_address_debug (address);
-        display->priv->remote_address = gdm_address_copy (address);
+        priv->remote_address = gdm_address_copy (address);
 }
 
 static void
@@ -105,15 +112,17 @@ gdm_xdmcp_display_set_property (GObject      *object,
                                 GParamSpec   *pspec)
 {
         GdmXdmcpDisplay *self;
+        GdmXdmcpDisplayPrivate *priv;
 
         self = GDM_XDMCP_DISPLAY (object);
+        priv = gdm_xdmcp_display_get_instance_private (self);
 
         switch (prop_id) {
         case PROP_REMOTE_ADDRESS:
                 _gdm_xdmcp_display_set_remote_address (self, g_value_get_boxed (value));
                 break;
         case PROP_SESSION_NUMBER:
-                self->priv->session_number = g_value_get_int (value);
+                priv->session_number = g_value_get_int (value);
                 break;
         default:
                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -128,15 +137,17 @@ gdm_xdmcp_display_get_property (GObject    *object,
                                 GParamSpec *pspec)
 {
         GdmXdmcpDisplay *self;
+        GdmXdmcpDisplayPrivate *priv;
 
         self = GDM_XDMCP_DISPLAY (object);
+        priv = gdm_xdmcp_display_get_instance_private (self);
 
         switch (prop_id) {
         case PROP_REMOTE_ADDRESS:
-                g_value_set_boxed (value, self->priv->remote_address);
+                g_value_set_boxed (value, priv->remote_address);
                 break;
         case PROP_SESSION_NUMBER:
-                g_value_set_int (value, self->priv->session_number);
+                g_value_set_int (value, priv->session_number);
                 break;
         default:
                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -187,16 +198,18 @@ gdm_xdmcp_display_prepare (GdmDisplay *display)
 static gboolean
 idle_connect_to_display (GdmXdmcpDisplay *self)
 {
+        GdmXdmcpDisplayPrivate *priv;
         gboolean res;
 
-        self->priv->connection_attempts++;
+        priv = gdm_xdmcp_display_get_instance_private (self);
+        priv->connection_attempts++;
 
         res = gdm_display_connect (GDM_DISPLAY (self));
         if (res) {
                 g_object_set (G_OBJECT (self), "status", GDM_DISPLAY_MANAGED, NULL);
         } else {
-                if (self->priv->connection_attempts >= MAX_CONNECT_ATTEMPTS) {
-                        g_warning ("Unable to connect to display after %d tries - bailing out", 
self->priv->connection_attempts);
+                if (priv->connection_attempts >= MAX_CONNECT_ATTEMPTS) {
+                        g_warning ("Unable to connect to display after %d tries - bailing out", 
priv->connection_attempts);
                         gdm_display_unmanage (GDM_DISPLAY (self));
                         return FALSE;
                 }
@@ -226,8 +239,6 @@ gdm_xdmcp_display_class_init (GdmXdmcpDisplayClass *klass)
         display_class->prepare = gdm_xdmcp_display_prepare;
         display_class->manage = gdm_xdmcp_display_manage;
 
-        g_type_class_add_private (klass, sizeof (GdmXdmcpDisplayPrivate));
-
         g_object_class_install_property (object_class,
                                          PROP_REMOTE_ADDRESS,
                                          g_param_spec_boxed ("remote-address",
@@ -254,8 +265,6 @@ gdm_xdmcp_display_init (GdmXdmcpDisplay *xdmcp_display)
 
         gboolean allow_remote_autologin;
 
-        xdmcp_display->priv = GDM_XDMCP_DISPLAY_GET_PRIVATE (xdmcp_display);
-
         allow_remote_autologin = FALSE;
         gdm_settings_direct_get_boolean (GDM_KEY_ALLOW_REMOTE_AUTOLOGIN, &allow_remote_autologin);
 
diff --git a/daemon/gdm-xdmcp-display.h b/daemon/gdm-xdmcp-display.h
index e127614e..c103eaa5 100644
--- a/daemon/gdm-xdmcp-display.h
+++ b/daemon/gdm-xdmcp-display.h
@@ -31,28 +31,13 @@
 
 G_BEGIN_DECLS
 
-#define GDM_TYPE_XDMCP_DISPLAY         (gdm_xdmcp_display_get_type ())
-#define GDM_XDMCP_DISPLAY(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), GDM_TYPE_XDMCP_DISPLAY, 
GdmXdmcpDisplay))
-#define GDM_XDMCP_DISPLAY_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), GDM_TYPE_XDMCP_DISPLAY, 
GdmXdmcpDisplayClass))
-#define GDM_IS_XDMCP_DISPLAY(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), GDM_TYPE_XDMCP_DISPLAY))
-#define GDM_IS_XDMCP_DISPLAY_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), GDM_TYPE_XDMCP_DISPLAY))
-#define GDM_XDMCP_DISPLAY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GDM_TYPE_XDMCP_DISPLAY, 
GdmXdmcpDisplayClass))
+#define GDM_TYPE_XDMCP_DISPLAY (gdm_xdmcp_display_get_type ())
+G_DECLARE_DERIVABLE_TYPE (GdmXdmcpDisplay, gdm_xdmcp_display, GDM, XDMCP_DISPLAY, GdmDisplay)
 
-typedef struct GdmXdmcpDisplayPrivate GdmXdmcpDisplayPrivate;
-
-typedef struct
-{
-        GdmDisplay              parent;
-        GdmXdmcpDisplayPrivate *priv;
-} GdmXdmcpDisplay;
-
-typedef struct
+struct _GdmXdmcpDisplayClass
 {
         GdmDisplayClass   parent_class;
-
-} GdmXdmcpDisplayClass;
-
-GType                     gdm_xdmcp_display_get_type                 (void);
+};
 
 gint32                    gdm_xdmcp_display_get_session_number       (GdmXdmcpDisplay         *display);
 GdmAddress              * gdm_xdmcp_display_get_remote_address       (GdmXdmcpDisplay         *display);


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