[gnome-software: 2/15] gs-app-tile: Add a GsAppTile:app property
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 2/15] gs-app-tile: Add a GsAppTile:app property
- Date: Tue, 20 Apr 2021 16:08:57 +0000 (UTC)
commit 6529c910f82c8ceb13ad09784e0a9f13d1a2e5bb
Author: Philip Withnall <pwithnall endlessos org>
Date: Tue Apr 20 13:44:15 2021 +0100
gs-app-tile: Add a GsAppTile:app property
This exposes the existing functionality as a GObject property, which may
be useful for signals or binding in future.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
src/gs-app-tile.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 84 insertions(+), 13 deletions(-)
---
diff --git a/src/gs-app-tile.c b/src/gs-app-tile.c
index 8e2a70a54..794482b86 100644
--- a/src/gs-app-tile.c
+++ b/src/gs-app-tile.c
@@ -19,6 +19,61 @@ typedef struct {
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GsAppTile, gs_app_tile, GTK_TYPE_BUTTON)
+typedef enum {
+ PROP_APP = 1,
+} GsAppTileProperty;
+
+static GParamSpec *obj_props[PROP_APP + 1] = { NULL, };
+
+static void
+gs_app_tile_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+ GsAppTile *self = GS_APP_TILE (object);
+ GsAppTilePrivate *priv = gs_app_tile_get_instance_private (self);
+
+ switch ((GsAppTileProperty) prop_id) {
+ case PROP_APP:
+ g_value_set_object (value, priv->app);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gs_app_tile_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+ GsAppTile *self = GS_APP_TILE (object);
+
+ switch ((GsAppTileProperty) prop_id) {
+ case PROP_APP:
+ gs_app_tile_set_app (self, g_value_get_object (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gs_app_tile_dispose (GObject *object)
+{
+ GsAppTile *self = GS_APP_TILE (object);
+
+ gs_app_tile_set_app (self, NULL);
+
+ G_OBJECT_CLASS (gs_app_tile_parent_class)->dispose (object);
+}
+
+/**
+ * gs_app_tile_get_app:
+ * @self: a #GsAppTile
+ *
+ * Get the value of #GsAppTile:app.
+ *
+ * Returns: (nullable) (transfer none): the #GsAppTile:app property
+ */
GsApp *
gs_app_tile_get_app (GsAppTile *self)
{
@@ -46,6 +101,13 @@ gs_app_tile_state_changed_cb (GsApp *app, GParamSpec *pspec, GsAppTile *self)
priv->app_state_changed_idle_id = g_idle_add (gs_app_tile_state_changed_idle_cb, self);
}
+/**
+ * gs_app_tile_set_app:
+ * @self: a #GsAppTile
+ * @app: (transfer none) (nullable): the new value for #GsAppTile:app
+ *
+ * Set the value of #GsAppTile:app.
+ */
void
gs_app_tile_set_app (GsAppTile *self, GsApp *app)
{
@@ -75,26 +137,35 @@ gs_app_tile_set_app (GsAppTile *self, GsApp *app)
G_CALLBACK (gs_app_tile_state_changed_cb), self);
klass->refresh (self);
}
-}
-static void
-gs_app_tile_finalize (GObject *object)
-{
- GsAppTile *self = GS_APP_TILE (object);
- GsAppTilePrivate *priv = gs_app_tile_get_instance_private (self);
- if (priv->app != NULL)
- g_signal_handlers_disconnect_by_func (priv->app, gs_app_tile_state_changed_cb, self);
- g_clear_handle_id (&priv->app_state_changed_idle_id, g_source_remove);
- g_clear_object (&priv->app);
-
- G_OBJECT_CLASS (gs_app_tile_parent_class)->finalize (object);
+ g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_APP]);
}
void
gs_app_tile_class_init (GsAppTileClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = gs_app_tile_finalize;
+
+ object_class->get_property = gs_app_tile_get_property;
+ object_class->set_property = gs_app_tile_set_property;
+ object_class->dispose = gs_app_tile_dispose;
+
+ /**
+ * GsAppTile:app: (nullable)
+ *
+ * The app to display in this tile.
+ *
+ * Set this to %NULL to display a loading/empty tile.
+ *
+ * Since: 41
+ */
+ obj_props[PROP_APP] =
+ g_param_spec_object ("app", "App",
+ "The app to display in this tile.",
+ GS_TYPE_APP,
+ G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, G_N_ELEMENTS (obj_props), obj_props);
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]