[Xfce4-commits] [apps/xfdashboard] 04/04: Add flags to XfdashboardPlugin to define behaviours of plugin which can only be set once via xfdashboard_plugin_set_info() and only while loading.
noreply at xfce.org
noreply at xfce.org
Mon Jun 20 09:48:23 CEST 2016
This is an automated email from the git hooks/post-receive script.
nomad pushed a commit to branch master
in repository apps/xfdashboard.
commit 6847725570a2789d1c9166bc950549771ae4dd04
Author: Stephan Haller <nomad at froevel.de>
Date: Mon Jun 20 09:45:42 2016 +0200
Add flags to XfdashboardPlugin to define behaviours of plugin which can only be set once via xfdashboard_plugin_set_info() and only while loading.
Currently only early initialization of plugin can be requested so the plugin gets enabled on load, that means before theme is loaded and application's stage is created and set up. The default behaviour of plugins now is to get enabled after stage was created and set up.
---
libxfdashboard/plugin.c | 50 ++++++++++++++++
libxfdashboard/plugin.h | 17 ++++++
libxfdashboard/plugins-manager.c | 90 +++++++++++++++++++++++++---
plugins/clock-view/plugin.c | 1 +
plugins/gnome-shell-search-provider/plugin.c | 1 +
5 files changed, 152 insertions(+), 7 deletions(-)
diff --git a/libxfdashboard/plugin.c b/libxfdashboard/plugin.c
index c383bf5..0b325f1 100644
--- a/libxfdashboard/plugin.c
+++ b/libxfdashboard/plugin.c
@@ -30,6 +30,7 @@
#include <glib/gi18n-lib.h>
+#include <libxfdashboard/enums.h>
#include <libxfdashboard/marshal.h>
#include <libxfdashboard/compat.h>
@@ -56,6 +57,7 @@ struct _XfdashboardPluginPrivate
{
/* Properties related */
gchar *id;
+ XfdashboardPluginFlag flags;
gchar *name;
gchar *description;
gchar *author;
@@ -83,6 +85,7 @@ enum
PROP_FILENAME,
PROP_ID,
+ PROP_FLAGS,
PROP_NAME,
PROP_DESCRIPTION,
PROP_AUTHOR,
@@ -252,6 +255,28 @@ static void _xfdashboard_plugin_set_id(XfdashboardPlugin *self, const gchar *inI
}
}
+/* Set flags for plugin */
+static void _xfdashboard_plugin_set_flags(XfdashboardPlugin *self, XfdashboardPluginFlag inFlags)
+{
+ XfdashboardPluginPrivate *priv;
+
+ g_return_if_fail(XFDASHBOARD_IS_PLUGIN(self));
+ g_return_if_fail(self->priv->flags==XFDASHBOARD_PLUGIN_FLAG_NONE);
+ g_return_if_fail(self->priv->state==XFDASHBOARD_PLUGIN_STATE_NONE);
+
+ priv=self->priv;
+
+ /* Set value if changed */
+ if(priv->flags!=inFlags)
+ {
+ /* Set value */
+ priv->flags=inFlags;
+
+ /* Notify about property change */
+ g_object_notify_by_pspec(G_OBJECT(self), XfdashboardPluginProperties[PROP_FLAGS]);
+ }
+}
+
/* Set name for plugin */
static void _xfdashboard_plugin_set_name(XfdashboardPlugin *self, const gchar *inName)
{
@@ -668,6 +693,10 @@ static void _xfdashboard_plugin_set_property(GObject *inObject,
_xfdashboard_plugin_set_id(self, g_value_get_string(inValue));
break;
+ case PROP_FLAGS:
+ _xfdashboard_plugin_set_flags(self, g_value_get_flags(inValue));
+ break;
+
case PROP_NAME:
_xfdashboard_plugin_set_name(self, g_value_get_string(inValue));
break;
@@ -712,6 +741,10 @@ static void _xfdashboard_plugin_get_property(GObject *inObject,
g_value_set_string(outValue, priv->id);
break;
+ case PROP_FLAGS:
+ g_value_set_flags(outValue, priv->flags);
+ break;
+
case PROP_NAME:
g_value_set_string(outValue, priv->name);
break;
@@ -785,6 +818,14 @@ static void xfdashboard_plugin_class_init(XfdashboardPluginClass *klass)
NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
+ XfdashboardPluginProperties[PROP_FLAGS]=
+ g_param_spec_flags("flags",
+ _("Flags"),
+ _("Flags defining behaviour of this plugin"),
+ XFDASHBOARD_TYPE_PLUGIN_FLAG,
+ XFDASHBOARD_PLUGIN_FLAG_NONE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
XfdashboardPluginProperties[PROP_NAME]=
g_param_spec_string("name",
_("name"),
@@ -895,6 +936,7 @@ static void xfdashboard_plugin_init(XfdashboardPlugin *self)
priv->lastLoadingError=NULL;
priv->id=NULL;
+ priv->flags=XFDASHBOARD_PLUGIN_FLAG_NONE;
priv->name=NULL;
priv->description=NULL;
priv->author=NULL;
@@ -1012,6 +1054,14 @@ const gchar* xfdashboard_plugin_get_id(XfdashboardPlugin *self)
return(self->priv->id);
}
+/* Get flags of plugin */
+XfdashboardPluginFlag xfdashboard_plugin_get_flags(XfdashboardPlugin *self)
+{
+ g_return_val_if_fail(XFDASHBOARD_IS_PLUGIN(self), XFDASHBOARD_PLUGIN_FLAG_NONE);
+
+ return(self->priv->flags);
+}
+
/* Set plugin information */
void xfdashboard_plugin_set_info(XfdashboardPlugin *self,
const gchar *inFirstPropertyName, ...)
diff --git a/libxfdashboard/plugin.h b/libxfdashboard/plugin.h
index 90f4b73..51c18f4 100644
--- a/libxfdashboard/plugin.h
+++ b/libxfdashboard/plugin.h
@@ -34,6 +34,22 @@
G_BEGIN_DECLS
+/* Public definitions */
+/**
+ * XfdashboardPluginFlag:
+ * @XFDASHBOARD_PLUGIN_FLAG_NONE: Plugin does not request anything special.
+ * @XFDASHBOARD_PLUGIN_FLAG_EARLY_INITIALIZATION: Plugin requests to get enabled before the stage is initialized
+ *
+ * Flags defining behaviour of this XfdashboardPlugin.
+ */
+typedef enum /*< flags,prefix=XFDASHBOARD_PLUGIN_FLAG >*/
+{
+ XFDASHBOARD_PLUGIN_FLAG_NONE=0,
+
+ XFDASHBOARD_PLUGIN_FLAG_EARLY_INITIALIZATION=1 << 0,
+} XfdashboardPluginFlag;
+
+
/* Helper macros to declare, define and register GObject types in plugins */
#define XFDASHBOARD_DECLARE_PLUGIN_TYPE(inFunctionNamePrefix) \
void inFunctionNamePrefix##_register_plugin_type(XfdashboardPlugin *inPlugin);
@@ -100,6 +116,7 @@ GType xfdashboard_plugin_get_type(void) G_GNUC_CONST;
XfdashboardPlugin* xfdashboard_plugin_new(const gchar *inPluginFilename, GError **outError);
const gchar* xfdashboard_plugin_get_id(XfdashboardPlugin *self);
+XfdashboardPluginFlag xfdashboard_plugin_get_flags(XfdashboardPlugin *self);
void xfdashboard_plugin_set_info(XfdashboardPlugin *self,
const gchar *inFirstPropertyName, ...)
diff --git a/libxfdashboard/plugins-manager.c b/libxfdashboard/plugins-manager.c
index 5967abf..d2b7403 100644
--- a/libxfdashboard/plugins-manager.c
+++ b/libxfdashboard/plugins-manager.c
@@ -46,10 +46,14 @@ G_DEFINE_TYPE(XfdashboardPluginsManager,
struct _XfdashboardPluginsManagerPrivate
{
/* Instance related */
- gboolean isInited;
- GList *searchPaths;
- GList *plugins;
- XfconfChannel *xfconfChannel;
+ gboolean isInited;
+ GList *searchPaths;
+ GList *plugins;
+
+ XfconfChannel *xfconfChannel;
+
+ XfdashboardApplication *application;
+ guint applicationInitializedSignalID;
};
@@ -262,8 +266,12 @@ static gboolean _xfdashboard_plugins_manager_load_plugin(XfdashboardPluginsManag
return(FALSE);
}
- /* Enable plugin */
- xfdashboard_plugin_enable(plugin);
+ /* Enable plugin if early initialization is requested by plugin */
+ if(xfdashboard_plugin_get_flags(plugin) & XFDASHBOARD_PLUGIN_FLAG_EARLY_INITIALIZATION)
+ {
+ g_debug("Enabling plugin '%s' on load because early initialization was requested", inPluginID);
+ xfdashboard_plugin_enable(plugin);
+ }
/* Store enabled plugin in list of enabled plugins */
priv->plugins=g_list_prepend(priv->plugins, plugin);
@@ -408,6 +416,51 @@ static void _xfdashboard_plugins_manager_on_enabled_plugins_changed(XfdashboardP
if(enabledPlugins) g_strfreev(enabledPlugins);
}
+/* Application was fully initialized so enabled all loaded plugin except the
+ * ones which are already enabled, e.g. plugins which requested early initialization.
+ */
+static void _xfdashboard_plugins_manager_on_application_initialized(XfdashboardPluginsManager *self,
+ gpointer inUserData)
+{
+ XfdashboardPluginsManagerPrivate *priv;
+ GList *iter;
+ XfdashboardPlugin *plugin;
+
+ g_return_if_fail(XFDASHBOARD_IS_PLUGINS_MANAGER(self));
+ g_return_if_fail(XFDASHBOARD_IS_APPLICATION(inUserData));
+
+ priv=self->priv;
+
+ /* Iterate through all loaded plugins and enable all plugins which are
+ * not enabled yet.
+ */
+ g_debug("Plugin manager will now enable all remaining plugins because application is fully initialized now");
+ for(iter=priv->plugins; iter; iter=g_list_next(iter))
+ {
+ /* Get plugin */
+ plugin=XFDASHBOARD_PLUGIN(iter->data);
+
+ /* If plugin is not enabled do it now */
+ if(!xfdashboard_plugin_is_enabled(plugin))
+ {
+ /* Enable plugin */
+ g_debug("Enabling plugin '%s'", xfdashboard_plugin_get_id(plugin));
+ xfdashboard_plugin_enable(plugin);
+ }
+ }
+
+ /* Disconnect signal handler as this signal is emitted only once */
+ if(priv->application)
+ {
+ if(priv->applicationInitializedSignalID)
+ {
+ g_signal_handler_disconnect(priv->application, priv->applicationInitializedSignalID);
+ priv->applicationInitializedSignalID=0;
+ }
+
+ priv->application=NULL;
+ }
+}
/* IMPLEMENTATION: GObject */
@@ -433,6 +486,17 @@ static void _xfdashboard_plugins_manager_dispose(GObject *inObject)
XfdashboardPluginsManagerPrivate *priv=self->priv;
/* Release allocated resources */
+ if(priv->application)
+ {
+ if(priv->applicationInitializedSignalID)
+ {
+ g_signal_handler_disconnect(priv->application, priv->applicationInitializedSignalID);
+ priv->applicationInitializedSignalID=0;
+ }
+
+ priv->application=NULL;
+ }
+
if(priv->plugins)
{
g_list_free_full(priv->plugins, (GDestroyNotify)_xfdashboard_plugins_manager_dispose_remove_plugin);
@@ -481,12 +545,24 @@ static void xfdashboard_plugins_manager_init(XfdashboardPluginsManager *self)
priv->searchPaths=NULL;
priv->plugins=NULL;
priv->xfconfChannel=xfdashboard_application_get_xfconf_channel(NULL);
+ priv->application=xfdashboard_application_get_default();
- /* Connect signals */
+ /* Connect signal to get notified about changed of enabled-plugins
+ * property in Xfconf.
+ */
g_signal_connect_swapped(priv->xfconfChannel,
"property-changed::"ENABLED_PLUGINS_XFCONF_PROP,
G_CALLBACK(_xfdashboard_plugins_manager_on_enabled_plugins_changed),
self);
+
+ /* Connect signal to get notified when application is fully initialized
+ * to enable loaded plugins.
+ */
+ priv->applicationInitializedSignalID=
+ g_signal_connect_swapped(priv->application,
+ "initialized",
+ G_CALLBACK(_xfdashboard_plugins_manager_on_application_initialized),
+ self);
}
/* IMPLEMENTATION: Public API */
diff --git a/plugins/clock-view/plugin.c b/plugins/clock-view/plugin.c
index bc0763c..577db96 100644
--- a/plugins/clock-view/plugin.c
+++ b/plugins/clock-view/plugin.c
@@ -308,6 +308,7 @@ G_MODULE_EXPORT void plugin_init(XfdashboardPlugin *self)
/* Set plugin info */
xfdashboard_plugin_set_info(self,
+ "flags", XFDASHBOARD_PLUGIN_FLAG_EARLY_INITIALIZATION,
"name", _("Clock"),
"description", _("Adds new a view showing a clock"),
"author", "Stephan Haller <nomad at froevel.de>",
diff --git a/plugins/gnome-shell-search-provider/plugin.c b/plugins/gnome-shell-search-provider/plugin.c
index 3b77144..72a6bb9 100644
--- a/plugins/gnome-shell-search-provider/plugin.c
+++ b/plugins/gnome-shell-search-provider/plugin.c
@@ -429,6 +429,7 @@ G_MODULE_EXPORT void plugin_init(XfdashboardPlugin *self)
/* Set plugin info */
xfdashboard_plugin_set_info(self,
+ "flags", XFDASHBOARD_PLUGIN_FLAG_EARLY_INITIALIZATION,
"name", _("Gnome-Shell search provider"),
"description", _("Uses Gnome-Shell search providers as source for searches"),
"author", "Stephan Haller <nomad at froevel.de>",
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list