[gnome-builder] libide/plugins: add PeasPluginInfo object wrapper



commit 3ac6dedf82b923e3c02b4909bf3c876c059cf5de
Author: Christian Hergert <chergert redhat com>
Date:   Wed Aug 17 14:51:00 2022 -0700

    libide/plugins: add PeasPluginInfo object wrapper
    
    Until we have a solution to wrap PeasPluginInfo into objects from the
    libpeas library, we need something to wrap here so we can use it in
    list models.

 src/libide/plugins/ide-plugin.c     | 185 ++++++++++++++++++++++++++++++++++++
 src/libide/plugins/ide-plugin.h     |  47 +++++++++
 src/libide/plugins/libide-plugins.h |   1 +
 src/libide/plugins/meson.build      |   2 +
 4 files changed, 235 insertions(+)
---
diff --git a/src/libide/plugins/ide-plugin.c b/src/libide/plugins/ide-plugin.c
new file mode 100644
index 000000000..ce6bbd81d
--- /dev/null
+++ b/src/libide/plugins/ide-plugin.c
@@ -0,0 +1,185 @@
+/* ide-plugin.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "ide-plugin"
+
+#include "config.h"
+
+#include "ide-plugin.h"
+
+struct _IdePlugin
+{
+  GObject parent_object;
+  PeasPluginInfo *info;
+};
+
+enum {
+  PROP_0,
+  PROP_DESCRIPTION,
+  PROP_INFO,
+  PROP_NAME,
+  PROP_SECTION,
+  N_PROPS
+};
+
+G_DEFINE_FINAL_TYPE (IdePlugin, ide_plugin, G_TYPE_OBJECT)
+
+static GParamSpec *properties [N_PROPS];
+
+static void
+ide_plugin_dispose (GObject *object)
+{
+  IdePlugin *self = (IdePlugin *)object;
+
+  if (self->info != NULL)
+    {
+      g_boxed_free (PEAS_TYPE_PLUGIN_INFO, self->info);
+      self->info = NULL;
+    }
+
+  G_OBJECT_CLASS (ide_plugin_parent_class)->dispose (object);
+}
+
+static void
+ide_plugin_get_property (GObject    *object,
+                         guint       prop_id,
+                         GValue     *value,
+                         GParamSpec *pspec)
+{
+  IdePlugin *self = IDE_PLUGIN (object);
+
+  switch (prop_id)
+    {
+    case PROP_INFO:
+      g_value_set_boxed (value, self->info);
+      break;
+
+    case PROP_NAME:
+      g_value_set_string (value, ide_plugin_get_name (self));
+      break;
+
+    case PROP_DESCRIPTION:
+      g_value_set_string (value, ide_plugin_get_description (self));
+      break;
+
+    case PROP_SECTION:
+      g_value_set_string (value, ide_plugin_get_section (self));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_plugin_set_property (GObject      *object,
+                         guint         prop_id,
+                         const GValue *value,
+                         GParamSpec   *pspec)
+{
+  IdePlugin *self = IDE_PLUGIN (object);
+
+  switch (prop_id)
+    {
+    case PROP_INFO:
+      self->info = g_value_dup_boxed (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_plugin_class_init (IdePluginClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->dispose = ide_plugin_dispose;
+  object_class->get_property = ide_plugin_get_property;
+  object_class->set_property = ide_plugin_set_property;
+
+  properties[PROP_INFO] =
+    g_param_spec_boxed ("info", NULL, NULL,
+                         PEAS_TYPE_PLUGIN_INFO,
+                         (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
+  properties[PROP_NAME] =
+    g_param_spec_string ("name", NULL, NULL,
+                         NULL,
+                         (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+  properties[PROP_DESCRIPTION] =
+    g_param_spec_string ("description", NULL, NULL,
+                         NULL,
+                         (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+  properties[PROP_SECTION] =
+    g_param_spec_string ("section", NULL, NULL,
+                         NULL,
+                         (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+ide_plugin_init (IdePlugin *self)
+{
+}
+
+/**
+ * ide_plugin_get_info:
+ * @self: a #IdePlugin
+ *
+ * Get the underlying #PeasPluginInfo.
+ *
+ * Returns: (transfer none): a #PeasPluginInfo
+ */
+PeasPluginInfo *
+ide_plugin_get_info (IdePlugin *self)
+{
+  g_return_val_if_fail (IDE_IS_PLUGIN (self), NULL);
+
+  return self->info;
+}
+
+const char *
+ide_plugin_get_name (IdePlugin *self)
+{
+  g_return_val_if_fail (IDE_IS_PLUGIN (self), NULL);
+
+  return peas_plugin_info_get_name (self->info);
+}
+
+const char *
+ide_plugin_get_description (IdePlugin *self)
+{
+  g_return_val_if_fail (IDE_IS_PLUGIN (self), NULL);
+
+  return peas_plugin_info_get_description (self->info);
+}
+
+const char *
+ide_plugin_get_section (IdePlugin *self)
+{
+  g_return_val_if_fail (IDE_IS_PLUGIN (self), NULL);
+
+  return peas_plugin_info_get_external_data (self->info, "Section");
+}
diff --git a/src/libide/plugins/ide-plugin.h b/src/libide/plugins/ide-plugin.h
new file mode 100644
index 000000000..6675ce2c8
--- /dev/null
+++ b/src/libide/plugins/ide-plugin.h
@@ -0,0 +1,47 @@
+/* ide-plugin.h
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#if !defined (IDE_PLUGINS_INSIDE) && !defined (IDE_PLUGINS_COMPILATION)
+# error "Only <libide-plugins.h> can be included directly."
+#endif
+
+#include <libpeas/peas.h>
+
+#include <libide-core.h>
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_PLUGIN (ide_plugin_get_type())
+
+IDE_AVAILABLE_IN_ALL
+G_DECLARE_FINAL_TYPE (IdePlugin, ide_plugin, IDE, PLUGIN, GObject)
+
+IDE_AVAILABLE_IN_ALL
+PeasPluginInfo *ide_plugin_get_info        (IdePlugin *self);
+IDE_AVAILABLE_IN_ALL
+const char     *ide_plugin_get_name        (IdePlugin *self);
+IDE_AVAILABLE_IN_ALL
+const char     *ide_plugin_get_description (IdePlugin *self);
+IDE_AVAILABLE_IN_ALL
+const char     *ide_plugin_get_section     (IdePlugin *self);
+
+G_END_DECLS
diff --git a/src/libide/plugins/libide-plugins.h b/src/libide/plugins/libide-plugins.h
index 91065a612..3d3bbf2c8 100644
--- a/src/libide/plugins/libide-plugins.h
+++ b/src/libide/plugins/libide-plugins.h
@@ -27,6 +27,7 @@ G_BEGIN_DECLS
 #define IDE_PLUGINS_INSIDE
 # include "ide-extension-adapter.h"
 # include "ide-extension-set-adapter.h"
+# include "ide-plugin.h"
 #undef IDE_PLUGINS_INSIDE
 
 G_END_DECLS
diff --git a/src/libide/plugins/meson.build b/src/libide/plugins/meson.build
index c3337a283..8a4d5b844 100644
--- a/src/libide/plugins/meson.build
+++ b/src/libide/plugins/meson.build
@@ -8,6 +8,7 @@ libide_include_directories += include_directories('.')
 libide_plugins_public_headers = [
   'ide-extension-adapter.h',
   'ide-extension-set-adapter.h',
+  'ide-plugin.h',
   'libide-plugins.h',
 ]
 
@@ -24,6 +25,7 @@ install_headers(libide_plugins_public_headers, subdir: libide_plugins_header_sub
 libide_plugins_public_sources = [
   'ide-extension-adapter.c',
   'ide-extension-set-adapter.c',
+  'ide-plugin.c',
 ]
 
 libide_plugins_private_sources = [


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