[gnome-software: 10/13] lib: Use enum and flag types for GObject properties rather than guint64
- From: Phaedrus Leeds <mwleeds src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 10/13] lib: Use enum and flag types for GObject properties rather than guint64
- Date: Thu, 28 Jan 2021 19:27:36 +0000 (UTC)
commit 24436caa5bcd08889d5cde7b7473534fdb6e96c4
Author: Philip Withnall <pwithnall endlessos org>
Date: Tue Jan 26 16:45:41 2021 +0000
lib: Use enum and flag types for GObject properties rather than guint64
This means that the varargs handling for `g_object_new()` should be able
to read the correct number of bytes off the stack to set the properties
correctly at construction time, regardless of whether built for i386 or
x86_64.
It will also improve type safety and the amount of information exposed
to language bindings.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
Fixes: #1007
lib/gs-app-list.c | 8 ++++----
lib/gs-app.c | 30 +++++++++++++++++++-----------
lib/gs-plugin-job.c | 41 ++++++++++++++++++++---------------------
lib/gs-plugin.c | 10 ++++++----
4 files changed, 49 insertions(+), 40 deletions(-)
---
diff --git a/lib/gs-app-list.c b/lib/gs-app-list.c
index f2ceff40..f1542a76 100644
--- a/lib/gs-app-list.c
+++ b/lib/gs-app-list.c
@@ -24,6 +24,7 @@
#include "gs-app-private.h"
#include "gs-app-list-private.h"
#include "gs-app-collation.h"
+#include "gs-enums.h"
struct _GsAppList
{
@@ -884,7 +885,7 @@ gs_app_list_get_property (GObject *object, guint prop_id, GValue *value, GParamS
GsAppList *self = GS_APP_LIST (object);
switch (prop_id) {
case PROP_STATE:
- g_value_set_uint (value, self->state);
+ g_value_set_enum (value, self->state);
break;
case PROP_PROGRESS:
g_value_set_uint (value, self->progress);
@@ -926,9 +927,8 @@ gs_app_list_class_init (GsAppListClass *klass)
/**
* GsAppList:state:
*/
- pspec = g_param_spec_uint ("state", NULL, NULL,
- GS_APP_STATE_UNKNOWN,
- GS_APP_STATE_LAST,
+ pspec = g_param_spec_enum ("state", NULL, NULL,
+ GS_TYPE_APP_STATE,
GS_APP_STATE_UNKNOWN,
G_PARAM_READABLE);
g_object_class_install_property (object_class, PROP_STATE, pspec);
diff --git a/lib/gs-app.c b/lib/gs-app.c
index 281054bd..9dc4465f 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -40,6 +40,7 @@
#include "gs-app-collation.h"
#include "gs-app-private.h"
+#include "gs-enums.h"
#include "gs-os-release.h"
#include "gs-plugin.h"
#include "gs-utils.h"
@@ -4275,7 +4276,7 @@ gs_app_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *
g_value_set_uint (value, priv->kind);
break;
case PROP_STATE:
- g_value_set_uint (value, priv->state);
+ g_value_set_enum (value, priv->state);
break;
case PROP_PROGRESS:
g_value_set_uint (value, priv->progress);
@@ -4290,7 +4291,10 @@ gs_app_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *
g_value_set_uint64 (value, priv->release_date);
break;
case PROP_QUIRK:
- g_value_set_uint64 (value, priv->quirk);
+ g_value_set_flags (value, priv->quirk);
+ break;
+ case PROP_PENDING_ACTION:
+ g_value_set_enum (value, priv->pending_action);
break;
case PROP_KEY_COLORS:
g_value_set_boxed (value, priv->key_colors);
@@ -4339,7 +4343,7 @@ gs_app_set_property (GObject *object, guint prop_id, const GValue *value, GParam
gs_app_set_kind (app, g_value_get_uint (value));
break;
case PROP_STATE:
- gs_app_set_state_internal (app, g_value_get_uint (value));
+ gs_app_set_state_internal (app, g_value_get_enum (value));
break;
case PROP_PROGRESS:
gs_app_set_progress (app, g_value_get_uint (value));
@@ -4354,7 +4358,11 @@ gs_app_set_property (GObject *object, guint prop_id, const GValue *value, GParam
gs_app_set_release_date (app, g_value_get_uint64 (value));
break;
case PROP_QUIRK:
- priv->quirk = g_value_get_uint64 (value);
+ priv->quirk = g_value_get_flags (value);
+ break;
+ case PROP_PENDING_ACTION:
+ /* Read only */
+ g_assert_not_reached ();
break;
case PROP_KEY_COLORS:
gs_app_set_key_colors (app, g_value_get_boxed (value));
@@ -4492,6 +4500,7 @@ gs_app_class_init (GsAppClass *klass)
/**
* GsApp:kind:
*/
+ /* FIXME: Should use AS_TYPE_APP_KIND when it’s available */
obj_props[PROP_KIND] = g_param_spec_uint ("kind", NULL, NULL,
AS_APP_KIND_UNKNOWN,
AS_APP_KIND_LAST,
@@ -4501,9 +4510,8 @@ gs_app_class_init (GsAppClass *klass)
/**
* GsApp:state:
*/
- obj_props[PROP_STATE] = g_param_spec_uint ("state", NULL, NULL,
- GS_APP_STATE_UNKNOWN,
- GS_APP_STATE_LAST,
+ obj_props[PROP_STATE] = g_param_spec_enum ("state", NULL, NULL,
+ GS_TYPE_APP_STATE,
GS_APP_STATE_UNKNOWN,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
@@ -4548,15 +4556,15 @@ gs_app_class_init (GsAppClass *klass)
/**
* GsApp:quirk:
*/
- obj_props[PROP_QUIRK] = g_param_spec_uint64 ("quirk", NULL, NULL,
- 0, G_MAXUINT64, 0,
+ obj_props[PROP_QUIRK] = g_param_spec_flags ("quirk", NULL, NULL,
+ GS_TYPE_APP_QUIRK, GS_APP_QUIRK_NONE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
/**
* GsApp:pending-action:
*/
- obj_props[PROP_PENDING_ACTION] = g_param_spec_uint64 ("pending-action", NULL, NULL,
- 0, G_MAXUINT64, 0,
+ obj_props[PROP_PENDING_ACTION] = g_param_spec_enum ("pending-action", NULL, NULL,
+ GS_TYPE_PLUGIN_ACTION, GS_PLUGIN_ACTION_UNKNOWN,
G_PARAM_READABLE);
/**
diff --git a/lib/gs-plugin-job.c b/lib/gs-plugin-job.c
index 1ce320fe..4e00e4f4 100644
--- a/lib/gs-plugin-job.c
+++ b/lib/gs-plugin-job.c
@@ -11,6 +11,7 @@
#include <glib.h>
+#include "gs-enums.h"
#include "gs-plugin-private.h"
#include "gs-plugin-job-private.h"
@@ -407,19 +408,19 @@ gs_plugin_job_get_property (GObject *obj, guint prop_id, GValue *value, GParamSp
switch (prop_id) {
case PROP_ACTION:
- g_value_set_uint (value, self->action);
+ g_value_set_enum (value, self->action);
break;
case PROP_AGE:
g_value_set_uint64 (value, self->age);
break;
case PROP_REFINE_FLAGS:
- g_value_set_uint64 (value, self->refine_flags);
+ g_value_set_flags (value, self->refine_flags);
break;
case PROP_FILTER_FLAGS:
- g_value_set_uint64 (value, self->filter_flags);
+ g_value_set_flags (value, self->filter_flags);
break;
case PROP_DEDUPE_FLAGS:
- g_value_set_uint64 (value, self->dedupe_flags);
+ g_value_set_flags (value, self->dedupe_flags);
break;
case PROP_INTERACTIVE:
g_value_set_boolean (value, self->interactive);
@@ -461,19 +462,19 @@ gs_plugin_job_set_property (GObject *obj, guint prop_id, const GValue *value, GP
switch (prop_id) {
case PROP_ACTION:
- gs_plugin_job_set_action (self, g_value_get_uint (value));
+ gs_plugin_job_set_action (self, g_value_get_enum (value));
break;
case PROP_AGE:
gs_plugin_job_set_age (self, g_value_get_uint64 (value));
break;
case PROP_REFINE_FLAGS:
- gs_plugin_job_set_refine_flags (self, g_value_get_uint64 (value));
+ gs_plugin_job_set_refine_flags (self, g_value_get_flags (value));
break;
case PROP_FILTER_FLAGS:
- gs_plugin_job_set_filter_flags (self, g_value_get_uint64 (value));
+ gs_plugin_job_set_filter_flags (self, g_value_get_flags (value));
break;
case PROP_DEDUPE_FLAGS:
- gs_plugin_job_set_dedupe_flags (self, g_value_get_uint64 (value));
+ gs_plugin_job_set_dedupe_flags (self, g_value_get_flags (value));
break;
case PROP_INTERACTIVE:
gs_plugin_job_set_interactive (self, g_value_get_boolean (value));
@@ -531,10 +532,8 @@ gs_plugin_job_class_init (GsPluginJobClass *klass)
object_class->get_property = gs_plugin_job_get_property;
object_class->set_property = gs_plugin_job_set_property;
- pspec = g_param_spec_uint ("action", NULL, NULL,
- GS_PLUGIN_ACTION_UNKNOWN,
- GS_PLUGIN_ACTION_LAST,
- GS_PLUGIN_ACTION_UNKNOWN,
+ pspec = g_param_spec_enum ("action", NULL, NULL,
+ GS_TYPE_PLUGIN_ACTION, GS_PLUGIN_ACTION_UNKNOWN,
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_ACTION, pspec);
@@ -543,19 +542,19 @@ gs_plugin_job_class_init (GsPluginJobClass *klass)
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_AGE, pspec);
- pspec = g_param_spec_uint64 ("refine-flags", NULL, NULL,
- 0, G_MAXUINT64, 0,
- G_PARAM_READWRITE);
+ pspec = g_param_spec_flags ("refine-flags", NULL, NULL,
+ GS_TYPE_PLUGIN_REFINE_FLAGS, GS_PLUGIN_REFINE_FLAGS_DEFAULT,
+ G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_REFINE_FLAGS, pspec);
- pspec = g_param_spec_uint64 ("filter-flags", NULL, NULL,
- 0, G_MAXUINT64, 0,
- G_PARAM_READWRITE);
+ pspec = g_param_spec_flags ("filter-flags", NULL, NULL,
+ GS_TYPE_PLUGIN_REFINE_FLAGS, GS_PLUGIN_REFINE_FLAGS_DEFAULT,
+ G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_FILTER_FLAGS, pspec);
- pspec = g_param_spec_uint64 ("dedupe-flags", NULL, NULL,
- 0, G_MAXUINT64, 0,
- G_PARAM_READWRITE);
+ pspec = g_param_spec_flags ("dedupe-flags", NULL, NULL,
+ GS_TYPE_APP_LIST_FILTER_FLAGS, GS_APP_LIST_FILTER_FLAG_NONE,
+ G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_DEDUPE_FLAGS, pspec);
pspec = g_param_spec_boolean ("interactive", NULL, NULL,
diff --git a/lib/gs-plugin.c b/lib/gs-plugin.c
index c517de0f..cf1d788d 100644
--- a/lib/gs-plugin.c
+++ b/lib/gs-plugin.c
@@ -41,6 +41,7 @@
#endif
#include "gs-app-list-private.h"
+#include "gs-enums.h"
#include "gs-os-release.h"
#include "gs-plugin-private.h"
#include "gs-plugin.h"
@@ -1948,7 +1949,7 @@ gs_plugin_set_property (GObject *object, guint prop_id, const GValue *value, GPa
GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
switch (prop_id) {
case PROP_FLAGS:
- priv->flags = g_value_get_uint64 (value);
+ priv->flags = g_value_get_flags (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -1963,7 +1964,7 @@ gs_plugin_get_property (GObject *object, guint prop_id, GValue *value, GParamSpe
GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
switch (prop_id) {
case PROP_FLAGS:
- g_value_set_uint64 (value, priv->flags);
+ g_value_set_flags (value, priv->flags);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -1981,8 +1982,9 @@ gs_plugin_class_init (GsPluginClass *klass)
object_class->get_property = gs_plugin_get_property;
object_class->finalize = gs_plugin_finalize;
- pspec = g_param_spec_uint64 ("flags", NULL, NULL,
- 0, G_MAXUINT64, 0, G_PARAM_READWRITE);
+ pspec = g_param_spec_flags ("flags", NULL, NULL,
+ GS_TYPE_PLUGIN_FLAGS, GS_PLUGIN_FLAGS_NONE,
+ G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_FLAGS, pspec);
signals [SIGNAL_UPDATES_CHANGED] =
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]