Author: kelnos Date: 2008-07-29 04:57:49 +0000 (Tue, 29 Jul 2008) New Revision: 27395
Added: xfconf/trunk/tests/list-channels/ xfconf/trunk/tests/list-channels/Makefile.am xfconf/trunk/tests/list-channels/t-list-channels.c Modified: xfconf/trunk/common/xfconf-dbus.xml xfconf/trunk/configure.ac.in xfconf/trunk/docs/reference/tmpl/xfconf-backend.sgml xfconf/trunk/docs/reference/xfconf-sections.txt xfconf/trunk/tests/Makefile.am xfconf/trunk/xfconf-query/main.c xfconf/trunk/xfconf/xfconf-binding.c xfconf/trunk/xfconf/xfconf-channel.c xfconf/trunk/xfconf/xfconf.h xfconf/trunk/xfconf/xfconf.symbols xfconf/trunk/xfconfd/xfconf-backend-perchannel-xml.c xfconf/trunk/xfconfd/xfconf-backend.c xfconf/trunk/xfconfd/xfconf-backend.h xfconf/trunk/xfconfd/xfconf-daemon.c Log: add ListChannels() method to dbus iface and xfconf_list_channels() Modified: xfconf/trunk/common/xfconf-dbus.xml =================================================================== --- xfconf/trunk/common/xfconf-dbus.xml 2008-07-28 21:11:38 UTC (rev 27394) +++ xfconf/trunk/common/xfconf-dbus.xml 2008-07-29 04:57:49 UTC (rev 27395) @@ -96,6 +96,16 @@ <arg direction="in" name="property" type="s"/> <arg direction="in" name="recursive" type="b"/> </method> + + <!-- + Array{String} org.xfce.Xfconf.ListChannels() + + Returns a list of all known channels as an array of + strings. + --> + <method name="ListChannels"> + <arg direction="out" name="channels" type="as"/> + </method> <!-- void org.xfce.Xfconf.PropertyChanged(String channel, Modified: xfconf/trunk/configure.ac.in =================================================================== --- xfconf/trunk/configure.ac.in 2008-07-28 21:11:38 UTC (rev 27394) +++ xfconf/trunk/configure.ac.in 2008-07-29 04:57:49 UTC (rev 27395) @@ -219,6 +219,7 @@ tests/set-properties/Makefile tests/has-properties/Makefile tests/get-properties/Makefile +tests/list-channels/Makefile tests/remove-properties/Makefile tests/property-changed-signal/Makefile xfconf/Makefile Modified: xfconf/trunk/docs/reference/tmpl/xfconf-backend.sgml =================================================================== --- xfconf/trunk/docs/reference/tmpl/xfconf-backend.sgml 2008-07-28 21:11:38 UTC (rev 27394) +++ xfconf/trunk/docs/reference/tmpl/xfconf-backend.sgml 2008-07-29 04:57:49 UTC (rev 27395) @@ -32,6 +32,7 @@ @get_all: See xfconf_backend_get_all(). @exists: See xfconf_backend_exists(). @remove: See xfconf_backend_remove(). [EMAIL PROTECTED]: See xfconf_backend_list_channels(). @flush: See xfconf_backend_flush(). @register_property_changed_func: See xfconf_backend_register_property_changed_func(). @_xb_reserved0: Reserved for future expansion. Modified: xfconf/trunk/docs/reference/xfconf-sections.txt =================================================================== --- xfconf/trunk/docs/reference/xfconf-sections.txt 2008-07-28 21:11:38 UTC (rev 27394) +++ xfconf/trunk/docs/reference/xfconf-sections.txt 2008-07-29 04:57:49 UTC (rev 27395) @@ -56,7 +56,6 @@ xfconf_backend_get_all xfconf_backend_exists xfconf_backend_remove -xfconf_backend_remove_channel xfconf_backend_flush xfconf_backend_register_property_changed_func <SUBSECTION Standard> Modified: xfconf/trunk/tests/Makefile.am =================================================================== --- xfconf/trunk/tests/Makefile.am 2008-07-28 21:11:38 UTC (rev 27394) +++ xfconf/trunk/tests/Makefile.am 2008-07-29 04:57:49 UTC (rev 27395) @@ -4,6 +4,7 @@ property-changed-signal \ has-properties \ get-properties \ + list-channels \ remove-properties clean-local: Added: xfconf/trunk/tests/list-channels/Makefile.am =================================================================== --- xfconf/trunk/tests/list-channels/Makefile.am (rev 0) +++ xfconf/trunk/tests/list-channels/Makefile.am 2008-07-29 04:57:49 UTC (rev 27395) @@ -0,0 +1,6 @@ +check_PROGRAMS = \ + t-list-channels + +t_list_channels_SOURCES = t-list-channels.c + +include $(top_srcdir)/tests/Makefile.inc Copied: xfconf/trunk/tests/list-channels/t-list-channels.c (from rev 27394, xfconf/trunk/xfconf/xfconf.h) =================================================================== --- xfconf/trunk/tests/list-channels/t-list-channels.c (rev 0) +++ xfconf/trunk/tests/list-channels/t-list-channels.c 2008-07-29 04:57:49 UTC (rev 27395) @@ -0,0 +1,41 @@ +/* + * xfconf + * + * Copyright (c) 2008 Brian Tarricone <[EMAIL PROTECTED]> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License ONLY. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "tests-common.h" + +int +main(int argc, + char **argv) +{ + gchar **channels; + gint i; + + if(!xfconf_tests_start()) + return 1; + + TEST_OPERATION((channels = xfconf_list_channels())); + + for(i = 0; channels[i]; ++i) + g_print("Channel %d: %s\n", i, channels[i]); + TEST_OPERATION((i == 1)); + + xfconf_tests_end(); + + return 0; +} Modified: xfconf/trunk/xfconf/xfconf-binding.c =================================================================== --- xfconf/trunk/xfconf/xfconf-binding.c 2008-07-28 21:11:38 UTC (rev 27394) +++ xfconf/trunk/xfconf/xfconf-binding.c 2008-07-29 04:57:49 UTC (rev 27395) @@ -25,7 +25,7 @@ #include <string.h> #endif -#include "xfconf-binding.h" +#include "xfconf.h" #include "xfconf-alias.h" #include "xfconf-common-private.h" Modified: xfconf/trunk/xfconf/xfconf-channel.c =================================================================== --- xfconf/trunk/xfconf/xfconf-channel.c 2008-07-28 21:11:38 UTC (rev 27394) +++ xfconf/trunk/xfconf/xfconf-channel.c 2008-07-29 04:57:49 UTC (rev 27395) @@ -31,8 +31,8 @@ #include "xfconf-marshal.h" #include "xfconf-types.h" #include "xfconf-common-private.h" +#include "xfconf.h" #include "xfconf-alias.h" -#include "xfconf.h" #define ALIGN_VAL(val, align) ( ((val) + ((align) -1)) & ~((align) - 1) ) @@ -1963,7 +1963,30 @@ return ret; } +/** + * xfconf_list_channels: + * + * Lists all channels known in the Xfconf configuration store. + * + * Returns: A newly-allocated array of strings. Free with + * g_strfreev() when no longer needed. + **/ +/* this really belongs in xfconf.c, but i don't feel like including + * xfconf-dbus-bindings.h twice, or copying the ERROR macros */ +gchar ** +xfconf_list_channels() +{ + DBusGProxy *proxy = _xfconf_get_dbus_g_proxy(); + gchar **channels = NULL; + ERROR_DEFINE; + if(!xfconf_client_list_channels(proxy, &channels, ERROR)) + ERROR_CHECK; + return channels; +} + + + #define __XFCONF_CHANNEL_C__ #include "common/xfconf-aliasdef.c" Modified: xfconf/trunk/xfconf/xfconf.h =================================================================== --- xfconf/trunk/xfconf/xfconf.h 2008-07-28 21:11:38 UTC (rev 27394) +++ xfconf/trunk/xfconf/xfconf.h 2008-07-29 04:57:49 UTC (rev 27395) @@ -42,6 +42,8 @@ void xfconf_array_free(GPtrArray *arr); +gchar **xfconf_list_channels(); + G_END_DECLS #endif /* __XFCONF_H__ */ Modified: xfconf/trunk/xfconf/xfconf.symbols =================================================================== --- xfconf/trunk/xfconf/xfconf.symbols 2008-07-28 21:11:38 UTC (rev 27394) +++ xfconf/trunk/xfconf/xfconf.symbols 2008-07-29 04:57:49 UTC (rev 27395) @@ -91,6 +91,7 @@ xfconf_channel_set_struct xfconf_channel_set_struct_valist xfconf_channel_set_structv +xfconf_list_channels #endif #endif Modified: xfconf/trunk/xfconf-query/main.c =================================================================== --- xfconf/trunk/xfconf-query/main.c 2008-07-28 21:11:38 UTC (rev 27394) +++ xfconf/trunk/xfconf-query/main.c 2008-07-29 04:57:49 UTC (rev 27395) @@ -160,8 +160,17 @@ /** Check if the channel is specified */ if(!channel_name) { - g_print("No channel specified, aborting...\n"); - return 1; + gchar **channels; + gint i; + + g_print("Channels:\n"); + + channels = xfconf_list_channels(); + for(i = 0; channels[i]; ++i) + g_print(" %s\n", channels[i]); + g_strfreev(channels); + + return 0; } /** Check if the property is specified */ Modified: xfconf/trunk/xfconfd/xfconf-backend-perchannel-xml.c =================================================================== --- xfconf/trunk/xfconfd/xfconf-backend-perchannel-xml.c 2008-07-28 21:11:38 UTC (rev 27394) +++ xfconf/trunk/xfconfd/xfconf-backend-perchannel-xml.c 2008-07-29 04:57:49 UTC (rev 27395) @@ -158,6 +158,9 @@ const gchar *property, gboolean recursive, GError **error); +static gboolean xfconf_backend_perchannel_xml_list_channels(XfconfBackend *backend, + GSList **channels, + GError **error); static gboolean xfconf_backend_perchannel_xml_flush(XfconfBackend *backend, GError **error); static void xfconf_backend_perchannel_xml_register_property_changed_func(XfconfBackend *backend, @@ -242,6 +245,7 @@ iface->get_all = xfconf_backend_perchannel_xml_get_all; iface->exists = xfconf_backend_perchannel_xml_exists; iface->remove = xfconf_backend_perchannel_xml_remove; + iface->list_channels = xfconf_backend_perchannel_xml_list_channels; iface->flush = xfconf_backend_perchannel_xml_flush; iface->register_property_changed_func = xfconf_backend_perchannel_xml_register_property_changed_func; } @@ -629,6 +633,36 @@ } static gboolean +xfconf_backend_perchannel_xml_list_channels(XfconfBackend *backend, + GSList **channels, + GError **error) +{ + gchar **dirs; + gint i; + GDir *dir; + const gchar *name; + + dirs = xfce_resource_lookup_all(XFCE_RESOURCE_CONFIG, CONFIG_DIR_STEM); + for(i = 0; dirs[i]; ++i) { + dir = g_dir_open(dirs[i], 0, 0); + if(!dir) + continue; + + while((name = g_dir_read_name(dir))) { + if(g_str_has_suffix(name, ".xml")) { + /* FIXME: maybe validate the files' contents a bit? */ + *channels = g_slist_prepend(*channels, + g_strndup(name, strlen(name) - 4)); + } + } + + g_dir_close(dir); + } + + return TRUE; +} + +static gboolean xfconf_backend_perchannel_xml_flush(XfconfBackend *backend, GError **error) { Modified: xfconf/trunk/xfconfd/xfconf-backend.c =================================================================== --- xfconf/trunk/xfconfd/xfconf-backend.c 2008-07-28 21:11:38 UTC (rev 27394) +++ xfconf/trunk/xfconfd/xfconf-backend.c 2008-07-29 04:57:49 UTC (rev 27395) @@ -405,6 +405,31 @@ } /** + * xfconf_backend_list_channels: + * @backend: The #XfconfBackend. + * @channels: A pointer to a #GSList head. + * + * Instructs the backend to return a list of channels with + * configuration data stored in the configuration store. + * + * Return value: The backend should return %TRUE if the operation + * was successful, or %FALSE otherwise. On %FALSE, + * @error should be set to a description of the failure. + **/ +gboolean +xfconf_backend_list_channels(XfconfBackend *backend, + GSList **channels, + GError **error) +{ + XfconfBackendInterface *iface = XFCONF_BACKEND_GET_INTERFACE(backend); + + xfconf_backend_return_val_if_fail(iface && iface->list_channels + && (!error || !*error), FALSE); + + return iface->list_channels(backend, channels, error); +} + +/** * xfconf_backend_flush * @backend: The #XfconfBackend. * @error: An error return. Modified: xfconf/trunk/xfconfd/xfconf-backend.h =================================================================== --- xfconf/trunk/xfconfd/xfconf-backend.h 2008-07-28 21:11:38 UTC (rev 27394) +++ xfconf/trunk/xfconfd/xfconf-backend.h 2008-07-29 04:57:49 UTC (rev 27395) @@ -93,6 +93,10 @@ const gchar *property, gboolean recursive, GError **error); + + gboolean (*list_channels)(XfconfBackend *backend, + GSList **channels, + GError **error); gboolean (*flush)(XfconfBackend *backend, GError **error); @@ -143,6 +147,10 @@ gboolean recursive, GError **error); +gboolean xfconf_backend_list_channels(XfconfBackend *backend, + GSList **channels, + GError **error); + gboolean xfconf_backend_flush(XfconfBackend *backend, GError **error); Modified: xfconf/trunk/xfconfd/xfconf-daemon.c =================================================================== --- xfconf/trunk/xfconfd/xfconf-daemon.c 2008-07-28 21:11:38 UTC (rev 27394) +++ xfconf/trunk/xfconfd/xfconf-daemon.c 2008-07-29 04:57:49 UTC (rev 27395) @@ -21,6 +21,8 @@ #include <config.h> #endif +#include <string.h> + #include <dbus/dbus-glib-lowlevel.h> #include <libxfce4util/libxfce4util.h> @@ -57,6 +59,9 @@ const gchar *property, gboolean recursive, GError **error); +static gboolean xfconf_list_channels(XfconfDaemon *xfconfd, + gchar ***channels, + GError **error); static gboolean xfconf_gui_show_list(XfconfDaemon *xfconfd, const gchar *display, GError **error); @@ -339,6 +344,34 @@ } static gboolean +xfconf_list_channels(XfconfDaemon *xfconfd, + gchar ***channels, + GError **error) +{ + GSList *lchannels = NULL, *chans_tmp, *lc; + GList *l; + gint i; + + /* FIXME: with multiple backends, this can cause duplicates */ + for(l = xfconfd->backends; l; l = l->next) { + chans_tmp = NULL; + if(xfconf_backend_list_channels(l->data, &chans_tmp, error)) + lchannels = g_slist_concat(lchannels, chans_tmp); + else if(error) + g_clear_error(error); + } + + *channels = g_malloc(sizeof(gchar *) * (g_slist_length(lchannels) + 1)); + for(lc = lchannels, i = 0; lc; lc = lc->next, ++i) + (*channels)[i] = lc->data; + (*channels)[i] = NULL; + g_slist_free(lchannels); + + return TRUE; +} + + +static gboolean xfconf_gui_show_list(XfconfDaemon *xfconfd, const gchar *display, GError **error) _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org http://foo-projects.org/mailman/listinfo/xfce4-commits