int main(int argc, char **argv) { XfconfChannel *channel; if(!xfconf_tests_start()) return 1; channel = xfconf_channel_new(TEST_CHANNEL_NAME); { gchar **strlist = xfconf_channel_get_string_list(channel, test_strlist_property); gint i; if(!strlist) { g_critical("Test failed: xfconf_channel_get_string_list() returned NULL"); xfconf_tests_end(); return 1; } for(i = 0; strlist[i] && test_strlist[i]; ++i) { if(strcmp(strlist[i], test_strlist[i])) { g_critical("Test failed: string list values don't match (%s != %s)", strlist[i], test_strlist[i]); xfconf_tests_end(); return 1; } } if(strlist[i] || test_strlist[i]) { g_critical("Test failed: in string list, element %d should be NULL (0x%p, 0x%p)", i, strlist[i], test_strlist[i]); xfconf_tests_end(); return 1; } g_strfreev(strlist); } g_object_unref(G_OBJECT(channel)); xfconf_tests_end(); return 0; }
/** * xfdashboard_plugins_manager_setup: * @self: A #XfdashboardPluginsManager * * Initializes the plugin manager at @self by loading all enabled plugins. This * function can only be called once and is initialized by the application at * start-up. So you usually do not have to call this function or it does anything * as the plugin manager is already setup. * * The plugin manager will continue initializing successfully even if a plugin * could not be loaded. In this case just a warning is printed. * * Return value: Returns %TRUE if plugin manager was initialized successfully * or was already initialized. Otherwise %FALSE will be returned. */ gboolean xfdashboard_plugins_manager_setup(XfdashboardPluginsManager *self) { XfdashboardPluginsManagerPrivate *priv; gchar *path; const gchar *envPath; gchar **enabledPlugins; gchar **iter; GError *error; g_return_val_if_fail(XFDASHBOARD_IS_PLUGINS_MANAGER(self), FALSE); priv=self->priv; error=NULL; /* If plugin manager is already initialized then return immediately */ if(priv->isInited) return(TRUE); /* Add search paths. Some paths may fail because they already exist * in list of search paths. So this should not fail this function. */ envPath=g_getenv("XFDASHBOARD_PLUGINS_PATH"); if(envPath) { _xfdashboard_plugins_manager_add_search_path(self, envPath); } path=g_build_filename(g_get_user_data_dir(), "xfdashboard", "plugins", NULL); _xfdashboard_plugins_manager_add_search_path(self, path); g_free(path); path=g_build_filename(PACKAGE_LIBDIR, "xfdashboard", "plugins", NULL); _xfdashboard_plugins_manager_add_search_path(self, path); g_free(path); /* Get list of enabled plugins and try to load them */ enabledPlugins=xfconf_channel_get_string_list(xfdashboard_application_get_xfconf_channel(NULL), ENABLED_PLUGINS_XFCONF_PROP); /* Try to load all enabled plugin and collect each error occurred. */ for(iter=enabledPlugins; iter && *iter; iter++) { gchar *pluginID; /* Get plugin name */ pluginID=*iter; XFDASHBOARD_DEBUG(self, PLUGINS, "Try to load plugin '%s'", pluginID); /* Try to load plugin */ if(!_xfdashboard_plugins_manager_load_plugin(self, pluginID, &error)) { /* Show error message */ g_warning(_("Could not load plugin '%s': %s"), pluginID, error ? error->message : _("Unknown error")); /* Release allocated resources */ if(error) { g_error_free(error); error=NULL; } } else { XFDASHBOARD_DEBUG(self, PLUGINS, "Loaded plugin '%s'", pluginID); } } /* If we get here then initialization was successful so set flag that * this plugin manager is initialized and return with TRUE result. */ priv->isInited=TRUE; /* Release allocated resources */ if(enabledPlugins) g_strfreev(enabledPlugins); return(TRUE); }
/* Property for list of enabled plugins in xfconf has changed */ static void _xfdashboard_plugins_manager_on_enabled_plugins_changed(XfdashboardPluginsManager *self, const gchar *inProperty, const GValue *inValue, gpointer inUserData) { XfdashboardPluginsManagerPrivate *priv; gchar **enabledPlugins; g_return_if_fail(XFDASHBOARD_IS_PLUGINS_MANAGER(self)); g_return_if_fail(XFCONF_IS_CHANNEL(inUserData)); priv=self->priv; /* If plugin managed is not inited do not load or "unload" any plugin */ if(!priv->isInited) return; /* Get new list of enabled plugins */ enabledPlugins=xfconf_channel_get_string_list(xfdashboard_application_get_xfconf_channel(NULL), ENABLED_PLUGINS_XFCONF_PROP); /* Iterate through list of loaded plugin and check if it also in new list * of enabled plugins. If it is not then disable this plugin. */ if(priv->plugins) { GList *iter; XfdashboardPlugin *plugin; const gchar *pluginID; iter=priv->plugins; while(iter) { GList *nextIter; gchar **listIter; gchar *listIterPluginID; gboolean found; /* Get next item getting iterated before doing anything * because the current item may get removed and the iterator * would get invalid. */ nextIter=g_list_next(iter); /* Get currently iterated plugin */ plugin=XFDASHBOARD_PLUGIN(iter->data); /* Get plugin ID */ pluginID=xfdashboard_plugin_get_id(plugin); /* Check if plugin ID is still in new list of enabled plugins */ found=FALSE; for(listIter=enabledPlugins; !found && *listIter; listIter++) { /* Get plugin ID of new enabled plugins currently iterated */ listIterPluginID=*listIter; /* Check if plugin ID matches this iterated one. If so, * set flag that plugin was found. */ if(g_strcmp0(pluginID, listIterPluginID)==0) found=TRUE; } /* Check that found flag is set. If it is not then disable plugin */ if(!found) { XFDASHBOARD_DEBUG(self, PLUGINS, "Disable plugin '%s'", pluginID); /* Disable plugin */ xfdashboard_plugin_disable(plugin); } /* Move iterator to next item */ iter=nextIter; } } /* Iterate through new list of enabled plugin and check if it is already * or still in the list of loaded plugins. If it not in this list then * try to load this plugin. If it is then enable it again when it is in * disable state. */ if(enabledPlugins) { gchar **iter; gchar *pluginID; GError *error; XfdashboardPlugin *plugin; error=NULL; /* Iterate through new list of enabled plugins and load new plugins */ for(iter=enabledPlugins; *iter; iter++) { /* Get plugin ID to check */ pluginID=*iter; /* Check if a plugin with this ID exists already */ plugin=_xfdashboard_plugins_manager_find_plugin_by_id(self, pluginID); if(!plugin) { /* The plugin does not exist so try to load it */ if(!_xfdashboard_plugins_manager_load_plugin(self, pluginID, &error)) { /* Show error message */ g_warning(_("Could not load plugin '%s': %s"), pluginID, error ? error->message : _("Unknown error")); /* Release allocated resources */ if(error) { g_error_free(error); error=NULL; } } else { XFDASHBOARD_DEBUG(self, PLUGINS, "Loaded plugin '%s'", pluginID); } } else { /* The plugin exists already so check if it is disabled and * re-enable it. */ if(!xfdashboard_plugin_is_enabled(plugin)) { XFDASHBOARD_DEBUG(self, PLUGINS, "Re-enable plugin '%s'", pluginID); xfdashboard_plugin_enable(plugin); } } } } /* Release allocated resources */ if(enabledPlugins) g_strfreev(enabledPlugins); }