[gnome-builder] libide/tweaks: include plugin info in tweaks



commit d5a25316532cbc7123f30549ef520a0cd9660f0b
Author: Christian Hergert <chergert redhat com>
Date:   Wed Aug 17 18:39:21 2022 -0700

    libide/tweaks: include plugin info in tweaks
    
    We really need to have copyright/author attribution for plugins in some
    way, so this just gets some essentials in place.

 src/libide/gui/ide-application-plugins.c        |  15 ++-
 src/libide/plugins/ide-plugin-view.c            | 130 ++++++++++++++++++++++++
 src/libide/plugins/ide-plugin-view.h            |  35 +++++++
 src/libide/plugins/ide-plugin-view.ui           | 121 ++++++++++++++++++++++
 src/libide/plugins/ide-plugin.c                 |  47 +++++++++
 src/libide/plugins/libide-plugins.gresource.xml |   6 ++
 src/libide/plugins/meson.build                  |  16 ++-
 7 files changed, 365 insertions(+), 5 deletions(-)
---
diff --git a/src/libide/gui/ide-application-plugins.c b/src/libide/gui/ide-application-plugins.c
index 5224e35fd..1a32edde4 100644
--- a/src/libide/gui/ide-application-plugins.c
+++ b/src/libide/gui/ide-application-plugins.c
@@ -29,6 +29,7 @@
 #include "ide-application-private.h"
 
 #include "ide-plugin-section-private.h"
+#include "ide-plugin-view.h"
 
 static void
 ide_application_changed_plugin_cb (GSettings      *settings,
@@ -510,7 +511,8 @@ create_plugin_toggle (IdeTweaksWidget *instance,
 {
   g_autofree char *schema_path = NULL;
   g_autoptr(GSettings) settings = NULL;
-  AdwActionRow *row;
+  AdwExpanderRow *row;
+  GtkWidget *view;
   GtkSwitch *toggle;
   const char *id;
 
@@ -523,12 +525,17 @@ create_plugin_toggle (IdeTweaksWidget *instance,
   toggle = g_object_new (GTK_TYPE_SWITCH,
                          "valign", GTK_ALIGN_CENTER,
                          NULL);
-  row = g_object_new (ADW_TYPE_ACTION_ROW,
+  row = g_object_new (ADW_TYPE_EXPANDER_ROW,
                       "title", ide_plugin_get_name (plugin),
                       "subtitle", ide_plugin_get_description (plugin),
-                      "activatable-widget", toggle,
+                      "show-enable-switch", FALSE,
                       NULL);
-  adw_action_row_add_suffix (row, GTK_WIDGET (toggle));
+  adw_expander_row_add_action (row, GTK_WIDGET (toggle));
+
+  view = g_object_new (IDE_TYPE_PLUGIN_VIEW,
+                       "plugin", plugin,
+                       NULL);
+  adw_expander_row_add_row (row, GTK_WIDGET (view));
 
   schema_path = g_strdup_printf ("/org/gnome/builder/plugins/%s/", id);
   settings = g_settings_new_with_path ("org.gnome.builder.plugin", schema_path);
diff --git a/src/libide/plugins/ide-plugin-view.c b/src/libide/plugins/ide-plugin-view.c
new file mode 100644
index 000000000..e053a7419
--- /dev/null
+++ b/src/libide/plugins/ide-plugin-view.c
@@ -0,0 +1,130 @@
+/* ide-plugin-view.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-view"
+
+#include "config.h"
+
+#include "ide-plugin-view.h"
+
+struct _IdePluginView
+{
+  GtkWidget  parent_instance;
+  IdePlugin *plugin;
+};
+
+enum {
+  PROP_0,
+  PROP_PLUGIN,
+  N_PROPS
+};
+
+G_DEFINE_FINAL_TYPE (IdePluginView, ide_plugin_view, GTK_TYPE_WIDGET)
+
+static GParamSpec *properties [N_PROPS];
+
+static void
+ide_plugin_view_dispose (GObject *object)
+{
+  IdePluginView *self = (IdePluginView *)object;
+  GtkWidget *child;
+
+  while ((child = gtk_widget_get_first_child (GTK_WIDGET (self))))
+    gtk_widget_unparent (child);
+
+  g_clear_object (&self->plugin);
+
+  G_OBJECT_CLASS (ide_plugin_view_parent_class)->dispose (object);
+}
+
+static void
+ide_plugin_view_get_property (GObject    *object,
+                              guint       prop_id,
+                              GValue     *value,
+                              GParamSpec *pspec)
+{
+  IdePluginView *self = IDE_PLUGIN_VIEW (object);
+
+  switch (prop_id)
+    {
+    case PROP_PLUGIN:
+      g_value_set_object (value, self->plugin);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_plugin_view_set_property (GObject      *object,
+                              guint         prop_id,
+                              const GValue *value,
+                              GParamSpec   *pspec)
+{
+  IdePluginView *self = IDE_PLUGIN_VIEW (object);
+
+  switch (prop_id)
+    {
+    case PROP_PLUGIN:
+      self->plugin = g_value_dup_object (value);
+      for (guint i = 1; i < N_PROPS; i++)
+        g_object_notify_by_pspec (object, properties[i]);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ide_plugin_view_class_init (IdePluginViewClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->dispose = ide_plugin_view_dispose;
+  object_class->get_property = ide_plugin_view_get_property;
+  object_class->set_property = ide_plugin_view_set_property;
+
+  properties[PROP_PLUGIN] =
+    g_param_spec_object ("plugin", NULL, NULL,
+                         IDE_TYPE_PLUGIN,
+                         (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+
+  gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
+  gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/libide-plugins/ide-plugin-view.ui");
+}
+
+static void
+ide_plugin_view_init (IdePluginView *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+GtkWidget *
+ide_plugin_view_new (IdePlugin *plugin)
+{
+  return g_object_new (IDE_TYPE_PLUGIN_VIEW,
+                       "plugin", plugin,
+                       NULL);
+}
diff --git a/src/libide/plugins/ide-plugin-view.h b/src/libide/plugins/ide-plugin-view.h
new file mode 100644
index 000000000..14b26f5f3
--- /dev/null
+++ b/src/libide/plugins/ide-plugin-view.h
@@ -0,0 +1,35 @@
+/* ide-plugin-view.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
+
+#include <gtk/gtk.h>
+
+#include "ide-plugin.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_PLUGIN_VIEW (ide_plugin_view_get_type())
+
+G_DECLARE_FINAL_TYPE (IdePluginView, ide_plugin_view, IDE, PLUGIN_VIEW, GtkWidget)
+
+GtkWidget *ide_plugin_view_new (IdePlugin *plugin);
+
+G_END_DECLS
diff --git a/src/libide/plugins/ide-plugin-view.ui b/src/libide/plugins/ide-plugin-view.ui
new file mode 100644
index 000000000..a90e6b583
--- /dev/null
+++ b/src/libide/plugins/ide-plugin-view.ui
@@ -0,0 +1,121 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="IdePluginView" parent="GtkWidget">
+    <child>
+      <object class="GtkGrid">
+        <property name="margin-top">6</property>
+        <property name="margin-bottom">6</property>
+        <property name="margin-start">6</property>
+        <property name="margin-end">6</property>
+        <property name="column-spacing">12</property>
+        <property name="row-spacing">6</property>
+        <child>
+          <object class="GtkLabel">
+            <property name="xalign">0</property>
+            <property name="hexpand">true</property>
+            <property name="margin-top">6</property>
+            <property name="margin-bottom">6</property>
+            <property name="selectable">true</property>
+            <binding name="label">
+              <lookup name="copyright" type="IdePlugin">
+                <lookup name="plugin">IdePluginView</lookup>
+              </lookup>
+            </binding>
+            <layout>
+              <property name="row">0</property>
+              <property name="column">0</property>
+              <property name="column-span">2</property>
+            </layout>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel">
+            <property name="xalign">0</property>
+            <property name="label" translatable="yes">Authors</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
+            <layout>
+              <property name="row">1</property>
+              <property name="column">0</property>
+            </layout>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel">
+            <property name="xalign">0</property>
+            <property name="hexpand">true</property>
+            <property name="selectable">true</property>
+            <binding name="label">
+              <lookup name="authors" type="IdePlugin">
+                <lookup name="plugin">IdePluginView</lookup>
+              </lookup>
+            </binding>
+            <layout>
+              <property name="row">1</property>
+              <property name="column">1</property>
+            </layout>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel">
+            <property name="xalign">0</property>
+            <property name="label" translatable="yes">Version</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
+            <layout>
+              <property name="row">2</property>
+              <property name="column">0</property>
+            </layout>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel">
+            <property name="xalign">0</property>
+            <property name="hexpand">true</property>
+            <property name="selectable">true</property>
+            <binding name="label">
+              <lookup name="version" type="IdePlugin">
+                <lookup name="plugin">IdePluginView</lookup>
+              </lookup>
+            </binding>
+            <layout>
+              <property name="row">2</property>
+              <property name="column">1</property>
+            </layout>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel">
+            <property name="xalign">0</property>
+            <property name="label" translatable="yes">Website</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
+            <layout>
+              <property name="row">3</property>
+              <property name="column">0</property>
+            </layout>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel">
+            <property name="xalign">0</property>
+            <property name="hexpand">true</property>
+            <property name="selectable">true</property>
+            <binding name="label">
+              <lookup name="website" type="IdePlugin">
+                <lookup name="plugin">IdePluginView</lookup>
+              </lookup>
+            </binding>
+            <layout>
+              <property name="row">3</property>
+              <property name="column">1</property>
+            </layout>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/libide/plugins/ide-plugin.c b/src/libide/plugins/ide-plugin.c
index c6e076d74..ea21cf523 100644
--- a/src/libide/plugins/ide-plugin.c
+++ b/src/libide/plugins/ide-plugin.c
@@ -35,13 +35,17 @@ struct _IdePlugin
 
 enum {
   PROP_0,
+  PROP_AUTHORS,
   PROP_CATEGORY,
   PROP_CATEGORY_ID,
+  PROP_COPYRIGHT,
   PROP_DESCRIPTION,
   PROP_ID,
   PROP_INFO,
   PROP_NAME,
   PROP_SECTION,
+  PROP_VERSION,
+  PROP_WEBSITE,
   N_PROPS
 };
 
@@ -74,6 +78,29 @@ ide_plugin_get_property (GObject    *object,
 
   switch (prop_id)
     {
+    case PROP_COPYRIGHT:
+      g_value_set_string (value, peas_plugin_info_get_copyright (self->info));
+      break;
+
+    case PROP_WEBSITE:
+      {
+        const char *str = peas_plugin_info_get_website (self->info);
+        g_value_set_string (value, str ? str : "https://gitlab.gnome.org/GNOME/gnome-builder";);
+      }
+      break;
+
+    case PROP_VERSION:
+      {
+        const char *str = peas_plugin_info_get_version (self->info);
+        g_value_set_string (value, str ? str : PACKAGE_VERSION);
+      }
+      break;
+
+    case PROP_AUTHORS:
+      g_value_take_string (value,
+                           g_strjoinv (", ", (char **)peas_plugin_info_get_authors (self->info)));
+      break;
+
     case PROP_ID:
       g_value_set_string (value, ide_plugin_get_id (self));
       break;
@@ -135,6 +162,26 @@ ide_plugin_class_init (IdePluginClass *klass)
   object_class->get_property = ide_plugin_get_property;
   object_class->set_property = ide_plugin_set_property;
 
+  properties[PROP_AUTHORS] =
+    g_param_spec_string ("authors", NULL, NULL,
+                         NULL,
+                         (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+  properties[PROP_COPYRIGHT] =
+    g_param_spec_string ("copyright", NULL, NULL,
+                         NULL,
+                         (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+  properties[PROP_WEBSITE] =
+    g_param_spec_string ("website", NULL, NULL,
+                         NULL,
+                         (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+  properties[PROP_VERSION] =
+    g_param_spec_string ("version", NULL, NULL,
+                         NULL,
+                         (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
   properties[PROP_INFO] =
     g_param_spec_boxed ("info", NULL, NULL,
                          PEAS_TYPE_PLUGIN_INFO,
diff --git a/src/libide/plugins/libide-plugins.gresource.xml b/src/libide/plugins/libide-plugins.gresource.xml
new file mode 100644
index 000000000..866e496fb
--- /dev/null
+++ b/src/libide/plugins/libide-plugins.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/libide-plugins">
+    <file preprocess="xml-stripblanks">ide-plugin-view.ui</file>
+  </gresource>
+</gresources>
diff --git a/src/libide/plugins/meson.build b/src/libide/plugins/meson.build
index e607b54ec..f89007e3e 100644
--- a/src/libide/plugins/meson.build
+++ b/src/libide/plugins/meson.build
@@ -15,6 +15,9 @@ libide_plugins_public_headers = [
 
 libide_plugins_private_headers = [
   'ide-extension-util-private.h',
+  'ide-plugin-private.h',
+  'ide-plugin-section-private.h',
+  'ide-plugin-view.h',
 ]
 
 install_headers(libide_plugins_public_headers, subdir: libide_plugins_header_subdir)
@@ -32,8 +35,19 @@ libide_plugins_public_sources = [
 
 libide_plugins_private_sources = [
   'ide-extension-util.c',
+  'ide-plugin-view.c',
 ]
 
+#
+# Generated Resource Files
+#
+
+libide_plugins_resources = gnome.compile_resources(
+  'ide-plugins-resources',
+  'libide-plugins.gresource.xml',
+  c_name: 'ide_plugins',
+)
+
 #
 # Library Definitions
 #
@@ -47,7 +61,7 @@ libide_plugins_deps = [
 ]
 
 libide_plugins = static_library('ide-plugins-' + libide_api_version,
-  libide_plugins_public_sources, libide_plugins_private_sources,
+  libide_plugins_public_sources + libide_plugins_private_sources + libide_plugins_resources,
    dependencies: libide_plugins_deps,
          c_args: libide_args + release_args + ['-DIDE_PLUGINS_COMPILATION'],
 )


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