[gnome-panel/wip/muktupavels/more-api: 1/4] libgnome-panel: add gp_module_is_applet_available
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel/wip/muktupavels/more-api: 1/4] libgnome-panel: add gp_module_is_applet_available
- Date: Mon, 13 Apr 2020 23:00:34 +0000 (UTC)
commit 90a6a1e272ea2f620c11000eaea574d39c715e2c
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Mon Apr 13 20:23:21 2020 +0300
libgnome-panel: add gp_module_is_applet_available
To be used by panel to check if applet can be added to panel.
libgnome-panel/Makefile.am | 1 +
libgnome-panel/gp-module-private.h | 55 +++++++++++++-----------
libgnome-panel/gp-module.c | 72 +++++++++++++++++++++++++------
libgnome-panel/gp-module.h | 87 +++++++++++++++++++++++++++++---------
4 files changed, 158 insertions(+), 57 deletions(-)
---
diff --git a/libgnome-panel/Makefile.am b/libgnome-panel/Makefile.am
index 386b5a108..7e77a876a 100644
--- a/libgnome-panel/Makefile.am
+++ b/libgnome-panel/Makefile.am
@@ -62,6 +62,7 @@ libgnome_panel_include_HEADERS = \
ENUM_TYPES = \
$(srcdir)/gp-applet.h \
+ $(srcdir)/gp-module.h \
$(NULL)
gp-enum-types.c: gp-enum-types.c.in gp-enum-types.h $(ENUM_TYPES)
diff --git a/libgnome-panel/gp-module-private.h b/libgnome-panel/gp-module-private.h
index b627d5a49..6cfc534c5 100644
--- a/libgnome-panel/gp-module-private.h
+++ b/libgnome-panel/gp-module-private.h
@@ -33,40 +33,45 @@ 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_available (GpModule *module,
+ const char *applet,
+ GpLockdownFlags flags,
+ char **reason);
G_END_DECLS
diff --git a/libgnome-panel/gp-module.c b/libgnome-panel/gp-module.c
index 0e131d6f3..8a14618b0 100644
--- a/libgnome-panel/gp-module.c
+++ b/libgnome-panel/gp-module.c
@@ -127,27 +127,31 @@ typedef void (* LoadFunc) (GpModule *module);
struct _GpModule
{
- GObject parent;
+ GObject parent;
- gchar *path;
- GModule *library;
+ gchar *path;
+ GModule *library;
- guint32 abi_version;
+ guint32 abi_version;
- gchar *id;
- gchar *version;
+ gchar *id;
+ gchar *version;
- gchar *gettext_domain;
+ gchar *gettext_domain;
- gchar **applet_ids;
+ gchar **applet_ids;
- GpGetAppletInfoFunc get_applet_info_func;
+ GpGetAppletInfoFunc get_applet_info_func;
- GetAppletIdFromIidFunc compatibility_func;
+ GetAppletIdFromIidFunc compatibility_func;
- GetStandaloneMenuFunc standalone_menu_func;
+ GetStandaloneMenuFunc standalone_menu_func;
- GHashTable *applets;
+ GpIsAppletAvailableFunc available_func;
+ gpointer available_func_user_data;
+ GDestroyNotify available_func_destroy_func;
+
+ GHashTable *applets;
};
G_DEFINE_TYPE (GpModule, gp_module, G_TYPE_OBJECT)
@@ -308,6 +312,14 @@ gp_module_finalize (GObject *object)
g_clear_pointer (&module->applet_ids, g_strfreev);
g_clear_pointer (&module->applets, g_hash_table_destroy);
+ if (module->available_func_destroy_func != NULL)
+ {
+ module->available_func_destroy_func (module->available_func_user_data);
+
+ module->available_func_user_data = NULL;
+ module->available_func = NULL;
+ }
+
G_OBJECT_CLASS (gp_module_parent_class)->finalize (object);
}
@@ -579,6 +591,26 @@ gp_module_set_standalone_menu (GpModule *module,
module->standalone_menu_func = func;
}
+/**
+ * gp_module_set_available_func:
+ * @module: a #GpModule
+ * @func: the function to call to create a menu
+ * @user_data: user data for @func
+ * @destroy_func: destroy notify for @user_data
+ *
+ * Specifies a function to be used to check if applet can be added to panel.
+ */
+void
+gp_module_set_available_func (GpModule *module,
+ GpIsAppletAvailableFunc func,
+ gpointer user_data,
+ GDestroyNotify destroy_func)
+{
+ module->available_func = func;
+ module->available_func_user_data = user_data;
+ module->available_func_destroy_func = destroy_func;
+}
+
GtkWidget *
gp_module_get_standalone_menu (GpModule *module,
gboolean enable_tooltips,
@@ -746,3 +778,19 @@ gp_module_show_help (GpModule *module,
g_free (help_uri);
g_free (message);
}
+
+gboolean
+gp_module_is_applet_available (GpModule *module,
+ const char *applet,
+ GpLockdownFlags flags,
+ char **reason)
+{
+ gpointer user_data;
+
+ if (module->available_func == NULL)
+ return TRUE;
+
+ user_data = module->available_func_user_data;
+
+ return module->available_func (applet, flags, reason, user_data);
+}
diff --git a/libgnome-panel/gp-module.h b/libgnome-panel/gp-module.h
index 9cd79ebe4..5f00471d7 100644
--- a/libgnome-panel/gp-module.h
+++ b/libgnome-panel/gp-module.h
@@ -30,6 +30,31 @@ G_BEGIN_DECLS
*/
#define GP_MODULE_ABI_VERSION 0x0001
+/**
+ * GpLockdownFlags:
+ * @GP_LOCKDOWN_FLAGS_NONE: No flags set.
+ * @GP_LOCKDOWN_FLAGS_FORCE_QUIT: Force quit is disabled.
+ * @GP_LOCKDOWN_FLAGS_LOCKED_DOWN: Complete panel lockdown is enabled.
+ * @GP_LOCKDOWN_FLAGS_COMMAND_LINE: Command line is disabled.
+ * @GP_LOCKDOWN_FLAGS_LOCK_SCREEN: Lock screen is disabled.
+ * @GP_LOCKDOWN_FLAGS_LOG_OUT: Log out is disabled.
+ * @GP_LOCKDOWN_FLAGS_USER_SWITCHING: User switching is disabled.
+ *
+ * Flags indicating active lockdowns.
+ */
+typedef enum
+{
+ GP_LOCKDOWN_FLAGS_NONE = 0,
+
+ GP_LOCKDOWN_FLAGS_FORCE_QUIT = 1 << 0,
+ GP_LOCKDOWN_FLAGS_LOCKED_DOWN = 1 << 1,
+
+ GP_LOCKDOWN_FLAGS_COMMAND_LINE = 1 << 2,
+ GP_LOCKDOWN_FLAGS_LOCK_SCREEN = 1 << 3,
+ GP_LOCKDOWN_FLAGS_LOG_OUT = 1 << 4,
+ GP_LOCKDOWN_FLAGS_USER_SWITCHING = 1 << 5
+} GpLockdownFlags;
+
/**
* GpGetAppletInfoFunc:
* @id: the applet id
@@ -38,7 +63,7 @@ G_BEGIN_DECLS
*
* Returns: (transfer full): returns a #GpAppletInfo.
*/
-typedef GpAppletInfo * (* GpGetAppletInfoFunc) (const gchar *id);
+typedef GpAppletInfo * (* GpGetAppletInfoFunc) (const gchar *id);
/**
* GetAppletIdFromIidFunc:
@@ -49,7 +74,7 @@ typedef GpAppletInfo * (* GpGetAppletInfoFunc) (const gchar *id);
*
* Returns: (transfer none): the applet id, or %NULL.
*/
-typedef const gchar * (* GetAppletIdFromIidFunc) (const gchar *iid);
+typedef const gchar * (* GetAppletIdFromIidFunc) (const gchar *iid);
/**
* GetStandaloneMenuFunc:
@@ -62,9 +87,26 @@ typedef const gchar * (* GetAppletIdFromIidFunc) (const gchar *iid);
*
* Returns: (transfer full): returns a #GtkMenu.
*/
-typedef GtkWidget * (* GetStandaloneMenuFunc) (gboolean enable_tooltips,
- gboolean locked_down,
- guint menu_icon_size);
+typedef GtkWidget * (* GetStandaloneMenuFunc) (gboolean enable_tooltips,
+ gboolean locked_down,
+ guint menu_icon_size);
+
+/**
+ * GpIsAppletAvailableFunc:
+ * @id: the applet id
+ * @flags: a #GpLockdownFlags with active lockdowns
+ * @reason: (out) (transfer full) (allow-none): return location for reason, or %NULL
+ * @user_data: user data that was passed to gp_module_set_available_func()
+ *
+ * Returns a #TRUE if applet can be added to panel. If @reason is non-%NULL
+ * this function must provide reason why applet is not available.
+ *
+ * Returns: returns a #TRUE if applet can be added to panel.
+ */
+typedef gboolean (* GpIsAppletAvailableFunc) (const char *id,
+ GpLockdownFlags flags,
+ char **reason,
+ gpointer user_data);
/**
* GP_TYPE_MODULE:
@@ -74,29 +116,34 @@ typedef GtkWidget * (* GetStandaloneMenuFunc) (gboolean enable_tooltips,
#define GP_TYPE_MODULE (gp_module_get_type ())
G_DECLARE_FINAL_TYPE (GpModule, gp_module, GP, MODULE, GObject)
-void gp_module_set_abi_version (GpModule *module,
- guint32 abi_version);
+void gp_module_set_abi_version (GpModule *module,
+ guint32 abi_version);
-void gp_module_set_gettext_domain (GpModule *module,
- const gchar *gettext_domain);
+void gp_module_set_gettext_domain (GpModule *module,
+ const gchar *gettext_domain);
-void gp_module_set_id (GpModule *module,
- const gchar *id);
+void gp_module_set_id (GpModule *module,
+ const gchar *id);
-void gp_module_set_version (GpModule *module,
- const gchar *version);
+void gp_module_set_version (GpModule *module,
+ const gchar *version);
-void gp_module_set_applet_ids (GpModule *module,
+void gp_module_set_applet_ids (GpModule *module,
...);
-void gp_module_set_get_applet_info (GpModule *module,
- GpGetAppletInfoFunc func);
+void gp_module_set_get_applet_info (GpModule *module,
+ GpGetAppletInfoFunc func);
+
+void gp_module_set_compatibility (GpModule *module,
+ GetAppletIdFromIidFunc func);
-void gp_module_set_compatibility (GpModule *module,
- GetAppletIdFromIidFunc func);
+void gp_module_set_standalone_menu (GpModule *module,
+ GetStandaloneMenuFunc func);
-void gp_module_set_standalone_menu (GpModule *module,
- GetStandaloneMenuFunc func);
+void gp_module_set_available_func (GpModule *module,
+ GpIsAppletAvailableFunc func,
+ gpointer user_data,
+ GDestroyNotify destroy_func);
/**
* gp_module_load:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]