[hitori: 1/2] Use G_DECLARE_FINAL_TYPE() to declare type
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [hitori: 1/2] Use G_DECLARE_FINAL_TYPE() to declare type
- Date: Thu, 20 Dec 2018 15:51:21 +0000 (UTC)
commit a9f4486524f83e22c5bad4a39db91bc545bde4f5
Author: Jonathan Kang <jonathankang gnome org>
Date: Thu Dec 20 21:30:25 2018 +0800
Use G_DECLARE_FINAL_TYPE() to declare type
g_type_class_add_private has been deprecated since glib version 2.58.
Use this convenient macro G_DECLARE_FINAL_TYPE() for emitting the usual
declarations in the header files for type HitoriApplication. This way we
can avoid the deprecated g_type_class_add_private as well.
src/main.c | 36 +++++++++++++++++++++++-------------
src/main.h | 23 +++++------------------
2 files changed, 28 insertions(+), 31 deletions(-)
---
diff --git a/src/main.c b/src/main.c
index 53807f8..a3859a6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -35,18 +35,18 @@ static void startup (GApplication *application);
static void activate (GApplication *application);
static gint handle_command_line (GApplication *application, GApplicationCommandLine *command_line);
-struct _HitoriApplicationPrivate {
+typedef struct {
/* Command line parameters. */
gboolean debug;
gint seed;
-};
+} HitoriApplicationPrivate;
typedef enum {
PROP_DEBUG = 1,
PROP_SEED
} HitoriProperty;
-G_DEFINE_TYPE (HitoriApplication, hitori_application, GTK_TYPE_APPLICATION)
+G_DEFINE_TYPE_WITH_PRIVATE (HitoriApplication, hitori_application, GTK_TYPE_APPLICATION)
static void
hitori_application_class_init (HitoriApplicationClass *klass)
@@ -54,8 +54,6 @@ hitori_application_class_init (HitoriApplicationClass *klass)
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GApplicationClass *gapplication_class = G_APPLICATION_CLASS (klass);
- g_type_class_add_private (klass, sizeof (HitoriApplicationPrivate));
-
gobject_class->constructed = constructed;
gobject_class->get_property = get_property;
gobject_class->set_property = set_property;
@@ -80,10 +78,12 @@ hitori_application_class_init (HitoriApplicationClass *klass)
static void
hitori_application_init (HitoriApplication *self)
{
- self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, HITORI_TYPE_APPLICATION, HitoriApplicationPrivate);
+ HitoriApplicationPrivate *priv;
+
+ priv = hitori_application_get_instance_private (self);
- self->priv->debug = FALSE;
- self->priv->seed = -1;
+ priv->debug = FALSE;
+ priv->seed = -1;
}
static void
@@ -108,7 +108,9 @@ constructed (GObject *object)
static void
get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
- HitoriApplicationPrivate *priv = HITORI_APPLICATION (object)->priv;
+ HitoriApplicationPrivate *priv;
+
+ priv = hitori_application_get_instance_private (HITORI_APPLICATION (object));
switch (property_id) {
case PROP_DEBUG:
@@ -127,7 +129,9 @@ get_property (GObject *object, guint property_id, GValue *value, GParamSpec *psp
static void
set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
- HitoriApplicationPrivate *priv = HITORI_APPLICATION (object)->priv;
+ HitoriApplicationPrivate *priv;
+
+ priv = hitori_application_get_instance_private (HITORI_APPLICATION (object));
switch (property_id) {
case PROP_DEBUG:
@@ -146,8 +150,12 @@ set_property (GObject *object, guint property_id, const GValue *value, GParamSpe
static void
debug_handler (const char *log_domain, GLogLevelFlags log_level, const char *message, HitoriApplication
*self)
{
+ HitoriApplicationPrivate *priv;
+
+ priv = hitori_application_get_instance_private (self);
+
/* Only display debug messages if we've been run with --debug */
- if (self->priv->debug == TRUE) {
+ if (priv->debug == TRUE) {
g_log_default_handler (log_domain, log_level, message, NULL);
}
}
@@ -166,7 +174,9 @@ static void
activate (GApplication *application)
{
HitoriApplication *self = HITORI_APPLICATION (application);
- HitoriApplicationPrivate *priv = self->priv;
+ HitoriApplicationPrivate *priv;
+
+ priv = hitori_application_get_instance_private (self);
/* Create the interface. */
if (self->window == NULL) {
@@ -199,7 +209,7 @@ activate (GApplication *application)
static gint
handle_command_line (GApplication *application, GApplicationCommandLine *command_line)
{
- HitoriApplicationPrivate *priv = HITORI_APPLICATION (application)->priv;
+ HitoriApplicationPrivate *priv = hitori_application_get_instance_private (HITORI_APPLICATION
(application));
GOptionContext *context;
GError *error = NULL;
gchar **args, **argv;
diff --git a/src/main.h b/src/main.h
index e9ee576..8b307ef 100644
--- a/src/main.h
+++ b/src/main.h
@@ -2,7 +2,7 @@
/*
* Hitori
* Copyright (C) Philip Withnall 2007-2009 <philip tecnocode co uk>
- *
+ *
* Hitori is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
@@ -61,18 +61,11 @@ typedef struct {
guchar status;
} HitoriCell;
-#define HITORI_TYPE_APPLICATION (hitori_application_get_type ())
-#define HITORI_APPLICATION(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), HITORI_TYPE_APPLICATION,
HitoriApplication))
-#define HITORI_APPLICATION_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), HITORI_TYPE_APPLICATION,
HitoriApplicationClass))
-#define HITORI_IS_APPLICATION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), HITORI_TYPE_APPLICATION))
-#define HITORI_IS_APPLICATION_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), HITORI_TYPE_APPLICATION))
-#define HITORI_APPLICATION_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o),
HITORI_TYPE_APPLICATION, HitoriApplicationClass))
-
-typedef struct _HitoriApplicationPrivate HitoriApplicationPrivate;
+#define HITORI_TYPE_APPLICATION (hitori_application_get_type ())
+G_DECLARE_FINAL_TYPE (HitoriApplication, hitori_application, HITORI, APPLICATION, GtkApplication)
-typedef struct {
+struct _HitoriApplication {
GtkApplication parent;
- HitoriApplicationPrivate *priv;
/* FIXME: This should all be merged into priv. */
GtkWidget *window;
@@ -107,13 +100,7 @@ typedef struct {
guint timeout_id;
GSettings *settings;
-} HitoriApplication;
-
-typedef struct {
- GtkApplicationClass parent;
-} HitoriApplicationClass;
-
-GType hitori_application_get_type (void) G_GNUC_CONST;
+};
HitoriApplication *hitori_application_new (void) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]