gplugin/gplugin

Split plugin row closure functions into a separate file

18 months ago, Elliott Sales de Andrade
2ab8afb6e8be
Parents acb56ed64e56
Children fcd52dc4273e
Split plugin row closure functions into a separate file

This will enable re-using them for the plugin page.

Testing Done:
Compile only.

Reviewed at https://reviews.imfreedom.org/r/1839/
--- a/gplugin-gtk4/data/plugin-row.ui Sun Sep 25 23:58:35 2022 -0500
+++ b/gplugin-gtk4/data/plugin-row.ui Mon Sep 26 00:03:15 2022 -0500
@@ -19,14 +19,14 @@
<object class="GtkSwitch" id="enable">
<property name="valign">center</property>
<binding name="sensitive">
- <closure type="gboolean" function="gplugin_gtk_plugin_row_lookup_sensitive_cb">
+ <closure type="gboolean" function="gplugin_gtk_lookup_plugin_state_sensitivity">
<lookup name="state" type="GPluginPlugin">
<lookup name="plugin">GPluginGtkPluginRow</lookup>
</lookup>
</closure>
</binding>
<binding name="state">
- <closure type="gboolean" function="gplugin_gtk_plugin_row_lookup_state_cb">
+ <closure type="gboolean" function="gplugin_gtk_lookup_plugin_state">
<lookup name="state" type="GPluginPlugin">
<lookup name="plugin">GPluginGtkPluginRow</lookup>
</lookup>
@@ -46,7 +46,7 @@
<property name="css-classes">heading</property>
<property name="hexpand">1</property>
<binding name="label">
- <closure type="gchararray" function="gplugin_gtk_plugin_row_lookup_name_cb">
+ <closure type="gchararray" function="gplugin_gtk_lookup_plugin_name">
<lookup name="info" type="GPluginPlugin">
<lookup name="plugin">GPluginGtkPluginRow</lookup>
</lookup>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplugin-gtk4/gplugin-gtk-plugin-closures.c Mon Sep 26 00:03:15 2022 -0500
@@ -0,0 +1,104 @@
+/*
+ * 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 <glib/gi18n-lib.h>
+
+#include <gplugin.h>
+
+#include <gplugin-gtk-plugin-closures.h>
+
+/******************************************************************************
+ * Private API
+ *****************************************************************************/
+
+gchar *
+gplugin_gtk_lookup_plugin_name(
+ G_GNUC_UNUSED GtkClosureExpression *expression,
+ GPluginPluginInfo *info,
+ const gchar *filename,
+ G_GNUC_UNUSED gpointer data)
+{
+ const gchar *name = NULL;
+ gchar *basename = NULL;
+ gchar *unnamed = NULL;
+
+ name = gplugin_plugin_info_get_name(info);
+ if(name != NULL) {
+ return g_strdup(name);
+ }
+
+ /* Add a default name if unavailable. */
+ basename = g_path_get_basename(filename);
+ unnamed = g_strdup_printf(_("Unnamed Plugin: %s"), basename);
+ g_free(basename);
+
+ return unnamed;
+}
+
+gboolean
+gplugin_gtk_lookup_plugin_state_sensitivity(
+ G_GNUC_UNUSED GtkClosureExpression *expression,
+ GPluginPluginState state,
+ G_GNUC_UNUSED gpointer data)
+{
+ gboolean result = FALSE;
+
+ switch(state) {
+ case GPLUGIN_PLUGIN_STATE_QUERIED:
+ case GPLUGIN_PLUGIN_STATE_REQUERY:
+ case GPLUGIN_PLUGIN_STATE_LOADED:
+ result = TRUE;
+ break;
+
+ case GPLUGIN_PLUGIN_STATE_UNLOAD_FAILED:
+ case GPLUGIN_PLUGIN_STATE_ERROR:
+ case GPLUGIN_PLUGIN_STATE_LOAD_FAILED:
+ case GPLUGIN_PLUGIN_STATE_UNKNOWN:
+ default:
+ result = FALSE;
+ break;
+ }
+
+ return result;
+}
+
+gboolean
+gplugin_gtk_lookup_plugin_state(
+ G_GNUC_UNUSED GtkClosureExpression *expression,
+ GPluginPluginState state,
+ G_GNUC_UNUSED gpointer data)
+{
+ gboolean result = FALSE;
+
+ switch(state) {
+ case GPLUGIN_PLUGIN_STATE_LOADED:
+ case GPLUGIN_PLUGIN_STATE_UNLOAD_FAILED:
+ result = TRUE;
+ break;
+
+ case GPLUGIN_PLUGIN_STATE_QUERIED:
+ case GPLUGIN_PLUGIN_STATE_REQUERY:
+ case GPLUGIN_PLUGIN_STATE_ERROR:
+ case GPLUGIN_PLUGIN_STATE_LOAD_FAILED:
+ case GPLUGIN_PLUGIN_STATE_UNKNOWN:
+ default:
+ result = FALSE;
+ break;
+ }
+
+ return result;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplugin-gtk4/gplugin-gtk-plugin-closures.h Mon Sep 26 00:03:15 2022 -0500
@@ -0,0 +1,55 @@
+/*
+ * 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/>.
+ */
+
+#if !defined(GPLUGIN_GTK_GLOBAL_HEADER_INSIDE) && \
+ !defined(GPLUGIN_GTK_COMPILATION)
+#error "only <gplugin-gtk.h> may be included directly"
+#endif
+
+#ifndef GPLUGIN_GTK_PLUGIN_CLOSURES_H
+#define GPLUGIN_GTK_PLUGIN_CLOSURES_H
+
+#include <glib.h>
+
+#include <gtk/gtk.h>
+
+#include <gplugin.h>
+
+G_BEGIN_DECLS
+
+G_GNUC_INTERNAL
+gchar *gplugin_gtk_lookup_plugin_name(
+ GtkClosureExpression *expression,
+ GPluginPluginInfo *info,
+ const gchar *filename,
+ gpointer data);
+
+G_GNUC_INTERNAL
+gboolean gplugin_gtk_lookup_plugin_state_sensitivity(
+ GtkClosureExpression *expression,
+ GPluginPluginState state,
+ gpointer data);
+
+G_GNUC_INTERNAL
+gboolean gplugin_gtk_lookup_plugin_state(
+ GtkClosureExpression *expression,
+ GPluginPluginState state,
+ gpointer data);
+
+G_END_DECLS
+
+#endif /* GPLUGIN_GTK_PLUGIN_CLOSURES_H */
--- a/gplugin-gtk4/gplugin-gtk-plugin-row.c Sun Sep 25 23:58:35 2022 -0500
+++ b/gplugin-gtk4/gplugin-gtk-plugin-row.c Mon Sep 26 00:03:15 2022 -0500
@@ -19,6 +19,7 @@
#include <gplugin.h>
+#include <gplugin-gtk-plugin-closures.h>
#include <gplugin-gtk-plugin-row.h>
/**
@@ -223,84 +224,6 @@
return TRUE;
}
-static gchar *
-gplugin_gtk_plugin_row_lookup_name_cb(
- G_GNUC_UNUSED GtkClosureExpression *expression,
- GPluginPluginInfo *info,
- const gchar *filename,
- G_GNUC_UNUSED gpointer data)
-{
- const gchar *name = NULL;
- gchar *basename = NULL;
- gchar *unnamed = NULL;
-
- name = gplugin_plugin_info_get_name(info);
- if(name != NULL) {
- return g_strdup(name);
- }
-
- /* Add a default name if unavailable. */
- basename = g_path_get_basename(filename);
- unnamed = g_strdup_printf(_("Unnamed Plugin: %s"), basename);
- g_free(basename);
-
- return unnamed;
-}
-
-static gboolean
-gplugin_gtk_plugin_row_lookup_sensitive_cb(
- G_GNUC_UNUSED GtkClosureExpression *expression,
- GPluginPluginState state,
- G_GNUC_UNUSED gpointer data)
-{
- gboolean result = FALSE;
-
- switch(state) {
- case GPLUGIN_PLUGIN_STATE_QUERIED:
- case GPLUGIN_PLUGIN_STATE_REQUERY:
- case GPLUGIN_PLUGIN_STATE_LOADED:
- result = TRUE;
- break;
-
- case GPLUGIN_PLUGIN_STATE_UNLOAD_FAILED:
- case GPLUGIN_PLUGIN_STATE_ERROR:
- case GPLUGIN_PLUGIN_STATE_LOAD_FAILED:
- case GPLUGIN_PLUGIN_STATE_UNKNOWN:
- default:
- result = FALSE;
- break;
- }
-
- return result;
-}
-
-static gboolean
-gplugin_gtk_plugin_row_lookup_state_cb(
- G_GNUC_UNUSED GtkClosureExpression *expression,
- GPluginPluginState state,
- G_GNUC_UNUSED gpointer data)
-{
- gboolean result = FALSE;
-
- switch(state) {
- case GPLUGIN_PLUGIN_STATE_LOADED:
- case GPLUGIN_PLUGIN_STATE_UNLOAD_FAILED:
- result = TRUE;
- break;
-
- case GPLUGIN_PLUGIN_STATE_QUERIED:
- case GPLUGIN_PLUGIN_STATE_REQUERY:
- case GPLUGIN_PLUGIN_STATE_ERROR:
- case GPLUGIN_PLUGIN_STATE_LOAD_FAILED:
- case GPLUGIN_PLUGIN_STATE_UNKNOWN:
- default:
- result = FALSE;
- break;
- }
-
- return result;
-}
-
/******************************************************************************
* GObject Implementation
*****************************************************************************/
@@ -458,13 +381,13 @@
gplugin_gtk_plugin_row_enable_state_set_cb);
gtk_widget_class_bind_template_callback(
widget_class,
- gplugin_gtk_plugin_row_lookup_name_cb);
+ gplugin_gtk_lookup_plugin_name);
gtk_widget_class_bind_template_callback(
widget_class,
- gplugin_gtk_plugin_row_lookup_sensitive_cb);
+ gplugin_gtk_lookup_plugin_state);
gtk_widget_class_bind_template_callback(
widget_class,
- gplugin_gtk_plugin_row_lookup_state_cb);
+ gplugin_gtk_lookup_plugin_state_sensitivity);
/* Details */
gtk_widget_class_bind_template_child(
--- a/gplugin-gtk4/meson.build Sun Sep 25 23:58:35 2022 -0500
+++ b/gplugin-gtk4/meson.build Mon Sep 26 00:03:15 2022 -0500
@@ -19,9 +19,11 @@
]
GPLUGIN_GTK4_PRIVATE_SOURCES = [
+ 'gplugin-gtk-plugin-closures.c',
]
GPLUGIN_GTK4_PRIVATE_HEADERS = [
+ 'gplugin-gtk-plugin-closures.h',
]
GPLUGIN_GTK4_PUBLIC_BUILT_SOURCES = [