[gnome-panel/wip/muktupavels/api: 5/7] libgnome-panel: add gp_module_is_applet_disabled



commit b6814d5969bc9ea8ac3f02845658fd223161fdd8
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Tue Apr 14 18:41:35 2020 +0300

    libgnome-panel: add gp_module_is_applet_disabled

 libgnome-panel/gp-module-private.h |  58 ++++++++++--------
 libgnome-panel/gp-module.c         | 120 +++++++++++++------------------------
 2 files changed, 73 insertions(+), 105 deletions(-)
---
diff --git a/libgnome-panel/gp-module-private.h b/libgnome-panel/gp-module-private.h
index b627d5a49..0081aa68a 100644
--- a/libgnome-panel/gp-module-private.h
+++ b/libgnome-panel/gp-module-private.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016-2018 Alberts Muktupāvels
+ * Copyright (C) 2016-2020 Alberts Muktupāvels
  *
  * 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
@@ -33,40 +33,46 @@ typedef enum
 #define GP_MODULE_ERROR gp_module_error_quark ()
 GQuark gp_module_error_quark (void);
 
-GpModule            *gp_module_new_from_path         (const gchar   *path);
+GpModule            *gp_module_new_from_path          (const gchar      *path);
 
-const gchar         *gp_module_get_id                (GpModule      *module);
+const gchar         *gp_module_get_id                 (GpModule         *module);
 
-const gchar         *gp_module_get_version           (GpModule      *module);
+const gchar         *gp_module_get_version            (GpModule         *module);
 
-const gchar * const *gp_module_get_applets           (GpModule      *module);
+const gchar * const *gp_module_get_applets            (GpModule         *module);
 
-GpAppletInfo        *gp_module_get_applet_info       (GpModule      *module,
-                                                      const gchar   *applet,
-                                                      GError       **error);
+GpAppletInfo        *gp_module_get_applet_info        (GpModule         *module,
+                                                       const gchar      *applet,
+                                                       GError          **error);
 
-const gchar         *gp_module_get_applet_id_from_iid (GpModule     *module,
-                                                       const gchar  *old_iid);
+const gchar         *gp_module_get_applet_id_from_iid (GpModule         *module,
+                                                       const gchar      *old_iid);
 
-GtkWidget           *gp_module_get_standalone_menu    (GpModule     *module,
-                                                       gboolean      enable_tooltips,
-                                                       gboolean      locked_down,
-                                                       guint         menu_icon_size);
+GtkWidget           *gp_module_get_standalone_menu    (GpModule         *module,
+                                                       gboolean          enable_tooltips,
+                                                       gboolean          locked_down,
+                                                       guint             menu_icon_size);
 
-GpApplet            *gp_module_applet_new             (GpModule     *module,
-                                                       const gchar  *applet,
-                                                       const gchar  *settings_path,
-                                                       GVariant     *initial_settings,
-                                                       GError      **error);
+GpApplet            *gp_module_applet_new             (GpModule         *module,
+                                                       const gchar      *applet,
+                                                       const gchar      *settings_path,
+                                                       GVariant         *initial_settings,
+                                                       GError          **error);
 
-GtkWidget           *gp_module_create_about_dialog    (GpModule     *module,
-                                                       GtkWindow    *parent,
-                                                       const char   *applet);
+GtkWidget           *gp_module_create_about_dialog    (GpModule         *module,
+                                                       GtkWindow        *parent,
+                                                       const char       *applet);
 
-void                 gp_module_show_help              (GpModule     *module,
-                                                       GtkWindow    *parent,
-                                                       const char   *applet,
-                                                       const char   *page);
+void                 gp_module_show_help              (GpModule         *module,
+                                                       GtkWindow        *parent,
+                                                       const char       *applet,
+                                                       const char       *page);
+
+gboolean             gp_module_is_applet_disabled     (GpModule         *module,
+                                                       const char       *applet,
+                                                       const char       *backend,
+                                                       GpLockdownFlags   lockdowns,
+                                                       char            **reason);
 
 G_END_DECLS
 
diff --git a/libgnome-panel/gp-module.c b/libgnome-panel/gp-module.c
index 0e131d6f3..509979217 100644
--- a/libgnome-panel/gp-module.c
+++ b/libgnome-panel/gp-module.c
@@ -112,14 +112,6 @@
 #include <gtk/gtk.h>
 #include <stdarg.h>
 
-#ifdef GDK_WINDOWING_WAYLAND
-#include <gdk/gdkwayland.h>
-#endif
-
-#ifdef GDK_WINDOWING_X11
-#include <gdk/gdkx.h>
-#endif
-
 #include "gp-applet-info-private.h"
 #include "gp-module-private.h"
 
@@ -167,68 +159,6 @@ get_applets (va_list args)
   return (gchar **) g_ptr_array_free (array, FALSE);
 }
 
-static gboolean
-match_backend (GpAppletInfo *info)
-{
-  GdkDisplay *display;
-  gchar **backends;
-  gboolean match;
-  guint i;
-
-  if (info->backends == NULL)
-    return TRUE;
-
-  display = gdk_display_get_default ();
-  backends = g_strsplit (info->backends, ",", -1);
-  match = FALSE;
-
-  for (i = 0; backends[i] != NULL; i++)
-    {
-      if (g_strcmp0 (backends[i], "*") == 0)
-        {
-          match = TRUE;
-          break;
-        }
-
-#ifdef GDK_WINDOWING_WAYLAND
-      if (g_strcmp0 (backends[i], "wayland") == 0 &&
-          GDK_IS_WAYLAND_DISPLAY (display))
-        {
-          match = TRUE;
-          break;
-        }
-#endif
-
-#ifdef GDK_WINDOWING_X11
-      if (g_strcmp0 (backends[i], "x11") == 0 && GDK_IS_X11_DISPLAY (display))
-        {
-          match = TRUE;
-          break;
-        }
-#endif
-    }
-
-  g_strfreev (backends);
-
-  return match;
-}
-
-static const gchar *
-get_current_backend (void)
-{
-#ifdef GDK_WINDOWING_WAYLAND
-  if (GDK_IS_WAYLAND_DISPLAY (gdk_display_get_default ()))
-    return "wayland";
-#endif
-
-#ifdef GDK_WINDOWING_X11
-  if (GDK_IS_X11_DISPLAY (gdk_display_get_default ()))
-    return "x11";
-#endif
-
-  return "unknown";
-}
-
 static gboolean
 is_valid_applet (GpModule     *module,
                  const gchar  *applet,
@@ -624,15 +554,6 @@ gp_module_applet_new (GpModule     *module,
   if (info == NULL)
     return NULL;
 
-  if (!match_backend (info))
-    {
-      g_set_error (error, GP_MODULE_ERROR, GP_MODULE_ERROR_MISSING_APPLET_TYPE,
-                   "Applet '%s' from module '%s' does not work with current backend '%s'",
-                   applet, module->id, get_current_backend ());
-
-      return NULL;
-    }
-
   type = info->get_applet_type_func ();
   if (type == G_TYPE_NONE)
     {
@@ -746,3 +667,44 @@ gp_module_show_help (GpModule   *module,
   g_free (help_uri);
   g_free (message);
 }
+
+gboolean
+gp_module_is_applet_disabled (GpModule         *module,
+                              const char       *applet,
+                              const char       *backend,
+                              GpLockdownFlags   lockdowns,
+                              char            **reason)
+{
+  GpAppletInfo *info;
+
+  g_return_val_if_fail (reason == NULL || *reason == NULL, FALSE);
+
+  info = get_applet_info (module, applet, NULL);
+  g_assert (info != NULL);
+
+  if (info->is_disabled_func == NULL)
+    return FALSE;
+
+  if (info->backends != NULL)
+    {
+      char **backends;
+
+      backends = g_strsplit (info->backends, ",", -1);
+
+      if (!g_strv_contains ((const char * const *) backends, backend))
+        {
+          if (reason != NULL)
+            {
+              *reason = g_strdup_printf (_("Backend “%s” is not supported."),
+                                         backend);
+            }
+
+          g_strfreev (backends);
+          return TRUE;
+        }
+
+      g_strfreev (backends);
+    }
+
+  return info->is_disabled_func (lockdowns, reason);
+}


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