gplugin/gplugin

Add a plugin with all basic setting types

16 months ago, Elliott Sales de Andrade
e425162a4e4e
Parents bc5116596aba
Children ec766bf5a520
Add a plugin with all basic setting types

This does the basic types, meaning enum, flags, string, double, and all
integral types.

Testing Done:
Compiled the schema, and loaded the plugin in the viewer.

Reviewed at https://reviews.imfreedom.org/r/2149/
--- a/gplugin/tests/plugins/meson.build Sat Dec 17 01:46:32 2022 -0600
+++ b/gplugin/tests/plugins/meson.build Fri Dec 23 00:26:49 2022 -0600
@@ -12,3 +12,5 @@
shared_library(lib, f'@lib@.c',
name_prefix: '', dependencies : [gplugin_dep, GLIB])
endforeach
+
+subdir('settings')
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplugin/tests/plugins/settings/im.pidgin.GPlugin.plugin.SettingsPlugin.gschema.xml Fri Dec 23 00:26:49 2022 -0600
@@ -0,0 +1,124 @@
+<?xml version="1.0" encoding="utf-8"?>
+<schemalist>
+ <enum id="im.pidgin.GPlugin.plugin.SettingsPlugin.Enum">
+ <value nick="Foo" value="0"/>
+ <value nick="Bar" value="1"/>
+ <value nick="Baz" value="2"/>
+ </enum>
+
+ <flags id="im.pidgin.GPlugin.plugin.SettingsPlugin.Flags">
+ <value nick="flag1" value="1"/>
+ <value nick="flag2" value="2"/>
+ <value nick="flag3" value="4"/>
+ </flags>
+
+ <schema path="/im/pidgin/gplugin/plugins/settings/" id="im.pidgin.GPlugin.plugin.SettingsPlugin">
+ <!-- Special (but still simple) types -->
+ <key name="enum" enum="im.pidgin.GPlugin.plugin.SettingsPlugin.Enum">
+ <default>"Foo"</default>
+ <summary>Enum setting</summary>
+ <description>
+ A setting that is an enumeration.
+ </description>
+ </key>
+
+ <key name="flags" flags="im.pidgin.GPlugin.plugin.SettingsPlugin.Flags">
+ <default>["flag1"]</default>
+ <summary>Flags setting</summary>
+ <description>
+ A setting that is a bitflag.
+ </description>
+ </key>
+
+ <key name="range" type="i">
+ <default>5</default>
+ <range min="2" max="10"/>
+ <summary>Range setting</summary>
+ <description>
+ A setting that is a 32-bit signed integer with a limited range.
+ </description>
+ </key>
+
+ <!-- Basic types -->
+ <key name="boolean" type="b">
+ <default>true</default>
+ <summary>Bool setting</summary>
+ <description>
+ A setting that is a boolean.
+ </description>
+ </key>
+
+ <key name="double" type="d">
+ <default>1234.56789</default>
+ <summary>Double setting</summary>
+ <description>
+ A setting that is a 64-bit floating-point number.
+ </description>
+ </key>
+
+ <key name="text" type="s">
+ <default>"information"</default>
+ <summary>Text setting</summary>
+ <description>
+ A setting that is a string.
+ </description>
+ </key>
+
+ <!-- All integral basic types -->
+ <key name="char" type="y">
+ <default>123</default>
+ <summary>Char setting</summary>
+ <description>
+ A setting that is an unsigned character.
+ </description>
+ </key>
+
+ <key name="int16" type="n">
+ <default>-1234</default>
+ <summary>Int16 setting</summary>
+ <description>
+ A setting that is a 16-bit signed integer.
+ </description>
+ </key>
+
+ <key name="uint16" type="q">
+ <default>12345</default>
+ <summary>UInt16 setting</summary>
+ <description>
+ A setting that is a 16-bit unsigned integer.
+ </description>
+ </key>
+
+ <key name="int32" type="i">
+ <default>-123456</default>
+ <summary>Int32 setting</summary>
+ <description>
+ A setting that is a 32-bit signed integer.
+ </description>
+ </key>
+
+ <key name="uint32" type="u">
+ <default>1234567</default>
+ <summary>UInt32 setting</summary>
+ <description>
+ A setting that is a 32-bit unsigned integer.
+ </description>
+ </key>
+
+ <key name="int64" type="x">
+ <default>-12345678901</default>
+ <summary>Int64 setting</summary>
+ <description>
+ A setting that is a 64-bit signed integer.
+ </description>
+ </key>
+
+ <key name="uint64" type="t">
+ <default>123456789012</default>
+ <summary>UInt64 setting</summary>
+ <description>
+ A setting that is a 64-bit unsigned integer.
+ </description>
+ </key>
+ </schema>
+</schemalist>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplugin/tests/plugins/settings/meson.build Fri Dec 23 00:26:49 2022 -0600
@@ -0,0 +1,10 @@
+shared_library('settings', 'settings.c',
+ name_prefix: '', dependencies : [gplugin_dep, GLIB])
+devenv.append('GPLUGIN_PLUGIN_PATH', meson.current_build_dir())
+
+settings_schemas = [
+ 'im.pidgin.GPlugin.plugin.SettingsPlugin.gschema.xml',
+]
+
+# Compile the schemas in the current directory for testing.
+gnome.compile_schemas(depend_files: files(settings_schemas))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplugin/tests/plugins/settings/settings.c Fri Dec 23 00:26:49 2022 -0600
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2022 Elliott Sales de Andrade <quantum.analyst@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <gplugin.h>
+#include <gplugin-native.h>
+
+static GPluginPluginInfo *
+settings_query(G_GNUC_UNUSED GError **error)
+{
+ const gchar *const authors[] = {"author1", NULL};
+
+ /* clang-format off */
+ return gplugin_plugin_info_new(
+ "gplugin/native-settings-plugin",
+ 0x01020304,
+ "name", "settings plugin (C)",
+ "category", "test",
+ "version", "version",
+ "summary", "summary",
+ "license-id", "license",
+ "description", "description",
+ "authors", authors,
+ "website", "website",
+ "settings-schema", "im.pidgin.GPlugin.plugin.SettingsPlugin",
+ NULL);
+ /* clang-format on */
+}
+
+static gboolean
+settings_load(GPluginPlugin *plugin, GError **error)
+{
+ if(!GPLUGIN_IS_PLUGIN(plugin)) {
+ g_set_error_literal(error, GPLUGIN_DOMAIN, 0, "plugin was not set");
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean
+settings_unload(
+ GPluginPlugin *plugin,
+ G_GNUC_UNUSED gboolean shutdown,
+ GError **error)
+{
+ if(!GPLUGIN_IS_PLUGIN(plugin)) {
+ g_set_error_literal(error, GPLUGIN_DOMAIN, 0, "plugin was not set");
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+GPLUGIN_NATIVE_PLUGIN_DECLARE(settings)