[gnome-builder] foundry: add concept of short-ids



commit 4ff30342f77c616acc3a9b2c3f8e2560280b3f25
Author: Christian Hergert <chergert redhat com>
Date:   Tue Aug 3 16:03:22 2021 -0700

    foundry: add concept of short-ids
    
    Sort of a hack for now so we can have something without the arch in it.
    However, long term, we want to instead use a RuntimeInfo object from
    configs rather than the runtime itself so it can be lazily resolved.

 src/libide/foundry/ide-runtime.c | 45 ++++++++++++++++++++++++++++++++++++++++
 src/libide/foundry/ide-runtime.h |  5 +++++
 2 files changed, 50 insertions(+)
---
diff --git a/src/libide/foundry/ide-runtime.c b/src/libide/foundry/ide-runtime.c
index a0670f3ef..894762c4d 100644
--- a/src/libide/foundry/ide-runtime.c
+++ b/src/libide/foundry/ide-runtime.c
@@ -38,6 +38,7 @@
 typedef struct
 {
   gchar *id;
+  gchar *short_id;
   gchar *category;
   gchar *name;
   gchar *display_name;
@@ -48,6 +49,7 @@ G_DEFINE_TYPE_WITH_PRIVATE (IdeRuntime, ide_runtime, IDE_TYPE_OBJECT)
 enum {
   PROP_0,
   PROP_ID,
+  PROP_SHORT_ID,
   PROP_CATEGORY,
   PROP_DISPLAY_NAME,
   PROP_NAME,
@@ -326,6 +328,7 @@ ide_runtime_finalize (GObject *object)
   IdeRuntimePrivate *priv = ide_runtime_get_instance_private (self);
 
   g_clear_pointer (&priv->id, g_free);
+  g_clear_pointer (&priv->short_id, g_free);
   g_clear_pointer (&priv->display_name, g_free);
   g_clear_pointer (&priv->name, g_free);
 
@@ -346,6 +349,10 @@ ide_runtime_get_property (GObject    *object,
       g_value_set_string (value, ide_runtime_get_id (self));
       break;
 
+    case PROP_SHORT_ID:
+      g_value_set_string (value, ide_runtime_get_short_id (self));
+      break;
+
     case PROP_CATEGORY:
       g_value_set_string (value, ide_runtime_get_category (self));
       break;
@@ -377,6 +384,10 @@ ide_runtime_set_property (GObject      *object,
       ide_runtime_set_id (self, g_value_get_string (value));
       break;
 
+    case PROP_SHORT_ID:
+      ide_runtime_set_short_id (self, g_value_get_string (value));
+      break;
+
     case PROP_CATEGORY:
       ide_runtime_set_category (self, g_value_get_string (value));
       break;
@@ -419,6 +430,13 @@ ide_runtime_class_init (IdeRuntimeClass *klass)
                          NULL,
                          (G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
 
+  properties [PROP_SHORT_ID] =
+    g_param_spec_string ("short-id",
+                         "Short Id",
+                         "The short runtime identifier",
+                         NULL,
+                         (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
   properties [PROP_CATEGORY] =
     g_param_spec_string ("category",
                          "Category",
@@ -475,6 +493,33 @@ ide_runtime_set_id (IdeRuntime  *self,
     }
 }
 
+const gchar *
+ide_runtime_get_short_id (IdeRuntime  *self)
+{
+  IdeRuntimePrivate *priv = ide_runtime_get_instance_private (self);
+
+  g_return_val_if_fail (IDE_IS_RUNTIME (self), NULL);
+
+  return priv->short_id ? priv->short_id : priv->id;
+}
+
+void
+ide_runtime_set_short_id (IdeRuntime  *self,
+                          const gchar *short_id)
+{
+  IdeRuntimePrivate *priv = ide_runtime_get_instance_private (self);
+
+  g_return_if_fail (IDE_IS_RUNTIME (self));
+  g_return_if_fail (short_id != NULL);
+
+  if (!ide_str_equal0 (short_id, priv->short_id))
+    {
+      g_free (priv->short_id);
+      priv->short_id = g_strdup (short_id);
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_SHORT_ID]);
+    }
+}
+
 const gchar *
 ide_runtime_get_category (IdeRuntime  *self)
 {
diff --git a/src/libide/foundry/ide-runtime.h b/src/libide/foundry/ide-runtime.h
index aae54d3b4..65bf2e238 100644
--- a/src/libide/foundry/ide-runtime.h
+++ b/src/libide/foundry/ide-runtime.h
@@ -93,6 +93,11 @@ IDE_AVAILABLE_IN_3_32
 void                    ide_runtime_set_id                   (IdeRuntime      *self,
                                                               const gchar     *id);
 IDE_AVAILABLE_IN_3_32
+const gchar            *ide_runtime_get_short_id             (IdeRuntime      *self);
+IDE_AVAILABLE_IN_3_32
+void                    ide_runtime_set_short_id             (IdeRuntime      *self,
+                                                              const gchar     *short_id);
+IDE_AVAILABLE_IN_3_32
 const gchar            *ide_runtime_get_category             (IdeRuntime      *self);
 IDE_AVAILABLE_IN_3_32
 void                    ide_runtime_set_category             (IdeRuntime      *self,


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