[gegl/wip/Jehan/runtime-availability-check: 1/2] gegl: add a class method is_available to GeglOperation.




commit 7c8c298c63d744b5481d133e14948d48dfdffd4a
Author: Jehan <jehan girinstud io>
Date:   Mon Dec 14 19:02:25 2020 +0100

    gegl: add a class method is_available to GeglOperation.
    
    If set, this class method will be run at runtime to determine whether to
    hide an operation or not. This can be useful for operations relying on
    runtime dependencies.

 gegl/operation/gegl-operation.h  | 9 ++++++++-
 gegl/operation/gegl-operations.c | 7 ++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)
---
diff --git a/gegl/operation/gegl-operation.h b/gegl/operation/gegl-operation.h
index 12d3bc62b..904315594 100644
--- a/gegl/operation/gegl-operation.h
+++ b/gegl/operation/gegl-operation.h
@@ -154,7 +154,14 @@ struct _GeglOperationClass
 
   GeglClRunData *cl_data;
 
-  gpointer      pad[9];
+  /* Class method for runtime checks for an operation availability. In
+   * particular it allows for operations to be built and installed while
+   * depending on runtime dependencies. If is_available() is set and returns
+   * %FALSE, then the operation will be set invisible.
+   */
+  gboolean      (*is_available)              (void);
+
+  gpointer      pad[8];
 };
 
 GeglRectangle   gegl_operation_get_invalidated_by_change
diff --git a/gegl/operation/gegl-operations.c b/gegl/operation/gegl-operations.c
index e52ab38e9..5af4b4e44 100644
--- a/gegl/operation/gegl-operations.c
+++ b/gegl/operation/gegl-operations.c
@@ -221,7 +221,12 @@ gegl_operations_update_visible (void)
 
       operation_license = g_hash_table_lookup (operation_class->keys, "license");
 
-      if (!operation_license || gegl_operations_check_license (operation_license))
+      if (GEGL_OPERATION_CLASS (object_class)->is_available &&
+          ! GEGL_OPERATION_CLASS (object_class)->is_available ())
+        {
+          GEGL_NOTE (GEGL_DEBUG_MISC, "Operation %s is not available", iter_key);
+        }
+      else if (!operation_license || gegl_operations_check_license (operation_license))
         {
           if (operation_license)
             {


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