[gnome-builder/wip/gtk4-port] libide/projects: make IdeProjectTemplate a class



commit 497c5f0c51d4e31bc173a33aa289cad019836307
Author: Christian Hergert <chergert redhat com>
Date:   Thu May 26 17:04:55 2022 -0700

    libide/projects: make IdeProjectTemplate a class
    
    So that we can do things like properties and bind stuff in UI files.

 src/libide/projects/ide-project-template.c     | 88 ++++++++++++++++++--------
 src/libide/projects/ide-project-template.h     | 31 +++++----
 src/plugins/meson-templates/meson_templates.py |  2 +-
 3 files changed, 77 insertions(+), 44 deletions(-)
---
diff --git a/src/libide/projects/ide-project-template.c b/src/libide/projects/ide-project-template.c
index 9ceb0b7b6..2bc7690dd 100644
--- a/src/libide/projects/ide-project-template.c
+++ b/src/libide/projects/ide-project-template.c
@@ -24,51 +24,85 @@
 
 #include "ide-project-template.h"
 
-G_DEFINE_INTERFACE (IdeProjectTemplate, ide_project_template, G_TYPE_OBJECT)
+G_DEFINE_TYPE (IdeProjectTemplate, ide_project_template, IDE_TYPE_TEMPLATE_BASE)
+
+enum {
+  PROP_0,
+  PROP_ID,
+  PROP_NAME,
+  N_PROPS
+};
+
+static GParamSpec *properties [N_PROPS];
 
 static void
-ide_project_template_default_init (IdeProjectTemplateInterface *iface)
+ide_project_template_get_property (GObject    *object,
+                                   guint       prop_id,
+                                   GValue     *value,
+                                   GParamSpec *pspec)
 {
+  IdeProjectTemplate *self = IDE_PROJECT_TEMPLATE (object);
+
+  switch (prop_id)
+    {
+    case PROP_ID:
+      g_value_take_string (value, ide_project_template_get_id (self));
+      break;
+
+    case PROP_NAME:
+      g_value_take_string (value, ide_project_template_get_name (self));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
 }
 
-gchar *
-ide_project_template_get_id (IdeProjectTemplate *self)
+static void
+ide_project_template_class_init (IdeProjectTemplateClass *klass)
 {
-  g_return_val_if_fail (IDE_IS_PROJECT_TEMPLATE (self), NULL);
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->get_property = ide_project_template_get_property;
+
+  properties [PROP_ID] =
+    g_param_spec_string ("id", NULL, NULL, NULL,
+                         (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+  properties [PROP_NAME] =
+    g_param_spec_string ("name", NULL, NULL, NULL,
+                         (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
 
-  return IDE_PROJECT_TEMPLATE_GET_IFACE (self)->get_id (self);
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+ide_project_template_init (IdeProjectTemplate *self)
+{
 }
 
 gchar *
-ide_project_template_get_name (IdeProjectTemplate *self)
+ide_project_template_get_id (IdeProjectTemplate *self)
 {
   g_return_val_if_fail (IDE_IS_PROJECT_TEMPLATE (self), NULL);
 
-  return IDE_PROJECT_TEMPLATE_GET_IFACE (self)->get_name (self);
+  return IDE_PROJECT_TEMPLATE_GET_CLASS (self)->get_id (self);
 }
 
 gchar *
-ide_project_template_get_description (IdeProjectTemplate *self)
+ide_project_template_get_name (IdeProjectTemplate *self)
 {
   g_return_val_if_fail (IDE_IS_PROJECT_TEMPLATE (self), NULL);
 
-  return IDE_PROJECT_TEMPLATE_GET_IFACE (self)->get_description (self);
+  return IDE_PROJECT_TEMPLATE_GET_CLASS (self)->get_name (self);
 }
 
-/**
- * ide_project_template_get_widget:
- * @self: An #IdeProjectTemplate
- *
- * Get's the configuration widget for the template if there is one.
- *
- * Returns: (transfer none): a #GtkWidget.
- */
-GtkWidget *
-ide_project_template_get_widget (IdeProjectTemplate *self)
+gchar *
+ide_project_template_get_description (IdeProjectTemplate *self)
 {
   g_return_val_if_fail (IDE_IS_PROJECT_TEMPLATE (self), NULL);
 
-  return IDE_PROJECT_TEMPLATE_GET_IFACE (self)->get_widget (self);
+  return IDE_PROJECT_TEMPLATE_GET_CLASS (self)->get_description (self);
 }
 
 /**
@@ -86,7 +120,7 @@ ide_project_template_get_languages (IdeProjectTemplate *self)
 {
   g_return_val_if_fail (IDE_IS_PROJECT_TEMPLATE (self), NULL);
 
-  return IDE_PROJECT_TEMPLATE_GET_IFACE (self)->get_languages (self);
+  return IDE_PROJECT_TEMPLATE_GET_CLASS (self)->get_languages (self);
 }
 
 gchar *
@@ -94,7 +128,7 @@ ide_project_template_get_icon_name (IdeProjectTemplate *self)
 {
   g_return_val_if_fail (IDE_IS_PROJECT_TEMPLATE (self), NULL);
 
-  return IDE_PROJECT_TEMPLATE_GET_IFACE (self)->get_icon_name (self);
+  return IDE_PROJECT_TEMPLATE_GET_CLASS (self)->get_icon_name (self);
 }
 
 /**
@@ -124,7 +158,7 @@ ide_project_template_expand_async (IdeProjectTemplate  *self,
   g_return_if_fail (g_hash_table_contains (params, "name"));
   g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
 
-  IDE_PROJECT_TEMPLATE_GET_IFACE (self)->expand_async (self, params, cancellable, callback, user_data);
+  IDE_PROJECT_TEMPLATE_GET_CLASS (self)->expand_async (self, params, cancellable, callback, user_data);
 }
 
 gboolean
@@ -135,7 +169,7 @@ ide_project_template_expand_finish (IdeProjectTemplate  *self,
   g_return_val_if_fail (IDE_IS_PROJECT_TEMPLATE (self), FALSE);
   g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
 
-  return IDE_PROJECT_TEMPLATE_GET_IFACE (self)->expand_finish (self, result, error);
+  return IDE_PROJECT_TEMPLATE_GET_CLASS (self)->expand_finish (self, result, error);
 }
 
 /**
@@ -152,8 +186,8 @@ ide_project_template_get_priority (IdeProjectTemplate *self)
 {
   g_return_val_if_fail (IDE_IS_PROJECT_TEMPLATE (self), 0);
 
-  if (IDE_PROJECT_TEMPLATE_GET_IFACE (self)->get_priority)
-    return IDE_PROJECT_TEMPLATE_GET_IFACE (self)->get_priority (self);
+  if (IDE_PROJECT_TEMPLATE_GET_CLASS (self)->get_priority)
+    return IDE_PROJECT_TEMPLATE_GET_CLASS (self)->get_priority (self);
 
   return 0;
 }
diff --git a/src/libide/projects/ide-project-template.h b/src/libide/projects/ide-project-template.h
index 23af6fcff..8e21e8cde 100644
--- a/src/libide/projects/ide-project-template.h
+++ b/src/libide/projects/ide-project-template.h
@@ -27,21 +27,22 @@
 #include <libide-core.h>
 #include <gtk/gtk.h>
 
+#include "ide-template-base.h"
+
 G_BEGIN_DECLS
 
 #define IDE_TYPE_PROJECT_TEMPLATE (ide_project_template_get_type())
 
-IDE_AVAILABLE_IN_3_32
-G_DECLARE_INTERFACE (IdeProjectTemplate, ide_project_template, IDE, PROJECT_TEMPLATE, GObject)
+IDE_AVAILABLE_IN_ALL
+G_DECLARE_DERIVABLE_TYPE (IdeProjectTemplate, ide_project_template, IDE, PROJECT_TEMPLATE, IdeTemplateBase)
 
-struct _IdeProjectTemplateInterface
+struct _IdeProjectTemplateClass
 {
-  GTypeInterface parent;
+  IdeTemplateBaseClass parent_instance;
 
   gchar      *(*get_id)          (IdeProjectTemplate   *self);
   gchar      *(*get_name)        (IdeProjectTemplate   *self);
   gchar      *(*get_description) (IdeProjectTemplate   *self);
-  GtkWidget  *(*get_widget)      (IdeProjectTemplate   *self);
   gchar     **(*get_languages)   (IdeProjectTemplate   *self);
   gchar      *(*get_icon_name)   (IdeProjectTemplate   *self);
   void        (*expand_async)    (IdeProjectTemplate   *self,
@@ -55,31 +56,29 @@ struct _IdeProjectTemplateInterface
   gint        (*get_priority)    (IdeProjectTemplate   *self);
 };
 
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 gchar      *ide_project_template_get_id          (IdeProjectTemplate   *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 gint        ide_project_template_get_priority    (IdeProjectTemplate   *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 gchar      *ide_project_template_get_name        (IdeProjectTemplate   *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 gchar      *ide_project_template_get_description (IdeProjectTemplate   *self);
-IDE_AVAILABLE_IN_3_32
-GtkWidget  *ide_project_template_get_widget      (IdeProjectTemplate   *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 gchar     **ide_project_template_get_languages   (IdeProjectTemplate   *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 gchar      *ide_project_template_get_icon_name   (IdeProjectTemplate   *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 void        ide_project_template_expand_async    (IdeProjectTemplate   *self,
                                                   GHashTable           *params,
                                                   GCancellable         *cancellable,
                                                   GAsyncReadyCallback   callback,
                                                   gpointer              user_data);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 gboolean    ide_project_template_expand_finish   (IdeProjectTemplate   *self,
                                                   GAsyncResult         *result,
                                                   GError              **error);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 gint        ide_project_template_compare         (IdeProjectTemplate   *a,
                                                   IdeProjectTemplate   *b);
 
diff --git a/src/plugins/meson-templates/meson_templates.py b/src/plugins/meson-templates/meson_templates.py
index 68eb88ec0..118a29b68 100644
--- a/src/plugins/meson-templates/meson_templates.py
+++ b/src/plugins/meson-templates/meson_templates.py
@@ -64,7 +64,7 @@ class MesonTemplateLocator(Template.TemplateLocator):
         return super().do_locate(self, path)
 
 
-class MesonTemplate(Ide.TemplateBase, Ide.ProjectTemplate):
+class MesonTemplate(Ide.ProjectTemplate):
     def __init__(self, id, name, icon_name, description, languages, priority):
         super().__init__()
         self.id = id


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