[gnome-builder/wip/gtk4-port: 1483/1774] libide/vcs: use dup_name() and add name property




commit 6bbc41dc2e9784746da831e08aa6f68bf38638c9
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jun 13 16:03:19 2022 -0700

    libide/vcs: use dup_name() and add name property
    
    This makes it more like the branch object.

 src/libide/vcs/ide-vcs-tag.c             | 13 ++++++----
 src/libide/vcs/ide-vcs-tag.h             |  4 +--
 src/plugins/git/gbp-git-tag.c            | 44 ++++++++++++++++++++++++++++----
 src/plugins/vcsui/gbp-vcsui-tree-addin.c |  2 +-
 4 files changed, 50 insertions(+), 13 deletions(-)
---
diff --git a/src/libide/vcs/ide-vcs-tag.c b/src/libide/vcs/ide-vcs-tag.c
index 9c56c90ed..5ec2986bc 100644
--- a/src/libide/vcs/ide-vcs-tag.c
+++ b/src/libide/vcs/ide-vcs-tag.c
@@ -29,10 +29,13 @@ G_DEFINE_INTERFACE (IdeVcsTag, ide_vcs_tag, G_TYPE_OBJECT)
 static void
 ide_vcs_tag_default_init (IdeVcsTagInterface *iface)
 {
+  g_object_interface_install_property (iface,
+                                       g_param_spec_string ("name", NULL, NULL, NULL,
+                                                            (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
 }
 
 /**
- * ide_vcs_tag_get_name:
+ * ide_vcs_tag_dup_name:
  * @self: an #IdeVcsTag
  *
  * Gets the name of the tag, which is used in various UI elements
@@ -40,13 +43,13 @@ ide_vcs_tag_default_init (IdeVcsTagInterface *iface)
  *
  * Returns: (transfer full): a string containing the tag name
  */
-gchar *
-ide_vcs_tag_get_name (IdeVcsTag *self)
+char *
+ide_vcs_tag_dup_name (IdeVcsTag *self)
 {
   g_return_val_if_fail (IDE_IS_VCS_TAG (self), NULL);
 
-  if (IDE_VCS_TAG_GET_IFACE (self)->get_name)
-    return IDE_VCS_TAG_GET_IFACE (self)->get_name (self);
+  if (IDE_VCS_TAG_GET_IFACE (self)->dup_name)
+    return IDE_VCS_TAG_GET_IFACE (self)->dup_name (self);
 
   return NULL;
 }
diff --git a/src/libide/vcs/ide-vcs-tag.h b/src/libide/vcs/ide-vcs-tag.h
index 8145eaf47..3754532e3 100644
--- a/src/libide/vcs/ide-vcs-tag.h
+++ b/src/libide/vcs/ide-vcs-tag.h
@@ -33,10 +33,10 @@ struct _IdeVcsTagInterface
 {
   GTypeInterface parent;
 
-  gchar *(*get_name) (IdeVcsTag *self);
+  char *(*dup_name) (IdeVcsTag *self);
 };
 
 IDE_AVAILABLE_IN_ALL
-gchar *ide_vcs_tag_get_name (IdeVcsTag *self);
+char *ide_vcs_tag_dup_name (IdeVcsTag *self);
 
 G_END_DECLS
diff --git a/src/plugins/git/gbp-git-tag.c b/src/plugins/git/gbp-git-tag.c
index 9746fefa2..1ca85fa54 100644
--- a/src/plugins/git/gbp-git-tag.c
+++ b/src/plugins/git/gbp-git-tag.c
@@ -29,11 +29,11 @@
 struct _GbpGitTag
 {
   GObject parent_instance;
-  gchar *name;
+  char *name;
 };
 
-static gchar *
-gbp_git_tag_get_name (IdeVcsTag *tag)
+static char *
+gbp_git_tag_dup_name (IdeVcsTag *tag)
 {
   return g_strdup (GBP_GIT_TAG (tag)->name);
 }
@@ -41,11 +41,19 @@ gbp_git_tag_get_name (IdeVcsTag *tag)
 static void
 vcs_tag_iface_init (IdeVcsTagInterface *iface)
 {
-  iface->get_name = gbp_git_tag_get_name;
+  iface->dup_name = gbp_git_tag_dup_name;
 }
 
 G_DEFINE_FINAL_TYPE_WITH_CODE (GbpGitTag, gbp_git_tag, G_TYPE_OBJECT,
-                         G_IMPLEMENT_INTERFACE (IDE_TYPE_VCS_TAG, vcs_tag_iface_init))
+                               G_IMPLEMENT_INTERFACE (IDE_TYPE_VCS_TAG, vcs_tag_iface_init))
+
+enum {
+  PROP_0,
+  PROP_NAME,
+  N_PROPS
+};
+
+static GParamSpec *properties[N_PROPS];
 
 static void
 gbp_git_tag_finalize (GObject *object)
@@ -57,12 +65,38 @@ gbp_git_tag_finalize (GObject *object)
   G_OBJECT_CLASS (gbp_git_tag_parent_class)->finalize (object);
 }
 
+static void
+gbp_git_tag_get_property (GObject    *object,
+                          guint       prop_id,
+                          GValue     *value,
+                          GParamSpec *pspec)
+{
+  GbpGitTag *self = GBP_GIT_TAG (object);
+
+  switch (prop_id)
+    {
+    case PROP_NAME:
+      g_value_set_string (value, self->name);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
 static void
 gbp_git_tag_class_init (GbpGitTagClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
   object_class->finalize = gbp_git_tag_finalize;
+  object_class->get_property = gbp_git_tag_get_property;
+
+  properties [PROP_NAME] =
+    g_param_spec_string ("name", NULL, NULL, NULL,
+                         (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
 }
 
 static void
diff --git a/src/plugins/vcsui/gbp-vcsui-tree-addin.c b/src/plugins/vcsui/gbp-vcsui-tree-addin.c
index b1e9170a6..70c833698 100644
--- a/src/plugins/vcsui/gbp-vcsui-tree-addin.c
+++ b/src/plugins/vcsui/gbp-vcsui-tree-addin.c
@@ -333,7 +333,7 @@ gbp_vcsui_tree_addin_list_tags_cb (GObject      *object,
       for (guint i = 0; i < tags->len; i++)
         {
           IdeVcsTag *tag = g_ptr_array_index (tags, i);
-          g_autofree gchar *name = ide_vcs_tag_get_name (tag);
+          g_autofree gchar *name = ide_vcs_tag_dup_name (tag);
           g_autoptr(IdeTreeNode) child = NULL;
 
           child = g_object_new (IDE_TYPE_TREE_NODE,


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