Updating branch refs/heads/master to fd8d82d61bf59129583dc2dab7edae54be214f31 (commit) from 7d6875461d59e7b7c558f5586ceb4df92b3c57a9 (commit)
commit fd8d82d61bf59129583dc2dab7edae54be214f31 Author: Jannis Pohlmann <jan...@xfce.org> Date: Wed Sep 30 15:09:16 2009 +0200 Always check for "file" and add it if necessary. Clearly the better way. .../font-thumbnailer/font-thumbnailer-provider.c | 21 +----- .../pixbuf-thumbnailer-provider.c | 42 ++++-------- tumbler/Makefile.am | 4 +- tumbler/tumbler-util.c | 69 ++++++++++++++++++++ .../{tumbler-glib-extensions.h => tumbler-util.h} | 20 ++---- tumbler/tumbler.h | 1 + 6 files changed, 95 insertions(+), 62 deletions(-) diff --git a/plugins/font-thumbnailer/font-thumbnailer-provider.c b/plugins/font-thumbnailer/font-thumbnailer-provider.c index 4e5b669..65158a5 100644 --- a/plugins/font-thumbnailer/font-thumbnailer-provider.c +++ b/plugins/font-thumbnailer/font-thumbnailer-provider.c @@ -111,27 +111,12 @@ font_thumbnailer_provider_get_thumbnailers (TumblerThumbnailerProvider *provider "application/x-font-type1", NULL, }; - const gchar *const *supported_schemes; FontThumbnailer *thumbnailer; GList *thumbnailers = NULL; GStrv uri_schemes; - guint length; - guint n; - GVfs *vfs; /* determine the URI schemes supported by GIO */ - vfs = g_vfs_get_default (); - supported_schemes = g_vfs_get_supported_uri_schemes (vfs); - - /* copy the supported schemes array and add the file scheme, which for - * some odd reason is not included by default. Bug filed on - * http://bugzilla.gnome.org/show_bug.cgi?id=596867 */ - length = g_strv_length ((gchar **)supported_schemes); - uri_schemes = g_new0 (gchar *, length + 1); - uri_schemes[0] = (gchar *)"file"; - for (n = 0; n < length; ++n) - uri_schemes[1+n] = (gchar *)supported_schemes[n]; - uri_schemes[n] = NULL; + uri_schemes = tumbler_util_get_supported_uri_schemes (); /* create the pixbuf thumbnailer */ thumbnailer = g_object_new (TYPE_FONT_THUMBNAILER, @@ -141,8 +126,8 @@ font_thumbnailer_provider_get_thumbnailers (TumblerThumbnailerProvider *provider /* add the thumbnailer to the list */ thumbnailers = g_list_append (thumbnailers, thumbnailer); - /* free URI schemes array (not its contents) */ - g_free (uri_schemes); + /* free URI schemes */ + g_strfreev (uri_schemes); return thumbnailers; } diff --git a/plugins/pixbuf-thumbnailer/pixbuf-thumbnailer-provider.c b/plugins/pixbuf-thumbnailer/pixbuf-thumbnailer-provider.c index 320503a..6b4fc1e 100644 --- a/plugins/pixbuf-thumbnailer/pixbuf-thumbnailer-provider.c +++ b/plugins/pixbuf-thumbnailer/pixbuf-thumbnailer-provider.c @@ -103,34 +103,20 @@ pixbuf_thumbnailer_provider_init (PixbufThumbnailerProvider *provider) static GList * pixbuf_thumbnailer_provider_get_thumbnailers (TumblerThumbnailerProvider *provider) { - PixbufThumbnailer *thumbnailer; - const gchar *const *supported_schemes; - GHashTable *types; - GSList *formats; - GSList *fp; - GList *keys; - GList *lp; - GList *thumbnailers = NULL; - GStrv format_types; - GStrv mime_types; - GStrv uri_schemes; - GVfs *vfs; - guint length; - guint n; + PixbufThumbnailer *thumbnailer; + GHashTable *types; + GSList *formats; + GSList *fp; + GList *keys; + GList *lp; + GList *thumbnailers = NULL; + GStrv format_types; + GStrv mime_types; + GStrv uri_schemes; + guint n; /* determine which URI schemes are supported by GIO */ - vfs = g_vfs_get_default (); - supported_schemes = g_vfs_get_supported_uri_schemes (vfs); - - /* copy the supported schemes array and add the file scheme, which for - * some odd reason is not included by default. Bug filed on - * http://bugzilla.gnome.org/show_bug.cgi?id=596867 */ - length = g_strv_length ((gchar **)supported_schemes); - uri_schemes = g_new0 (gchar *, length + 1); - uri_schemes[0] = (gchar *)"file"; - for (n = 0; n < length; ++n) - uri_schemes[1+n] = (gchar *)supported_schemes[n]; - uri_schemes[n] = NULL; + uri_schemes = tumbler_util_get_supported_uri_schemes (); /* create a hash table to collect unique MIME types */ types = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); @@ -177,8 +163,8 @@ pixbuf_thumbnailer_provider_get_thumbnailers (TumblerThumbnailerProvider *provid "uri-schemes", uri_schemes, "mime-types", mime_types, NULL); - /* free URI schemes array (not its contents) and MIME types */ - g_free (uri_schemes); + /* free URI schemes and MIME types */ + g_strfreev (uri_schemes); g_strfreev (mime_types); /* add the thumbnailer to the list */ diff --git a/tumbler/Makefile.am b/tumbler/Makefile.am index 393e99e..e2023ce 100644 --- a/tumbler/Makefile.am +++ b/tumbler/Makefile.am @@ -42,6 +42,7 @@ libtumbler_headers = \ tumbler-thumbnailer-provider.h \ tumbler-thumbnailer.h \ tumbler-thumbnail.h \ + tumbler-util.h \ tumbler.h libtumbler_sources = \ @@ -56,7 +57,8 @@ libtumbler_sources = \ tumbler-provider-plugin.c \ tumbler-thumbnailer-provider.c \ tumbler-thumbnailer.c \ - tumbler-thumbnail.c + tumbler-thumbnail.c \ + tumbler-util.c libtumblerincludedir = $(includedir)/tumbler-$(TUMBLER_VERSION_API)/tumbler diff --git a/tumbler/tumbler-util.c b/tumbler/tumbler-util.c new file mode 100644 index 0000000..1d5910e --- /dev/null +++ b/tumbler/tumbler-util.c @@ -0,0 +1,69 @@ +/* vi:set et ai sw=2 sts=2 ts=2: */ +/*- + * Copyright (c) 2009 Jannis Pohlmann <jan...@xfce.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 Library General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <glib.h> +#include <gio/gio.h> + +#include <tumbler/tumbler-util.h> + + + +GStrv +tumbler_util_get_supported_uri_schemes (void) +{ + const gchar *const *vfs_schemes; + GStrv uri_schemes; + gboolean file_scheme_found = FALSE; + guint length; + guint n; + GVfs *vfs; + + /* determine the URI schemes supported by GIO */ + vfs = g_vfs_get_default (); + vfs_schemes = g_vfs_get_supported_uri_schemes (vfs); + + /* search for the "file" scheme */ + for (n = 0; !file_scheme_found && vfs_schemes[n] != NULL; ++n) + if (g_strcmp0 (vfs_schemes[n], "file") == 0) + file_scheme_found = TRUE; + + /* check if the "file" scheme is included */ + if (file_scheme_found) + { + /* it is, so simply copy the array */ + uri_schemes = g_strdupv ((GStrv) vfs_schemes); + } + else + { + /* it is not, so we need to copy the array and add "file" */ + length = g_strv_length ((GStrv) vfs_schemes); + uri_schemes = g_new0 (gchar *, length + 1); + uri_schemes[0] = g_strdup ("file"); + for (n = 0; n < length; ++n) + uri_schemes[1+n] = g_strdup (vfs_schemes[n]); + uri_schemes[n] = NULL; + } + + return uri_schemes; +} diff --git a/tumbler/tumbler-glib-extensions.h b/tumbler/tumbler-util.h similarity index 58% copy from tumbler/tumbler-glib-extensions.h copy to tumbler/tumbler-util.h index 0b08aeb..d1e1846 100644 --- a/tumbler/tumbler-glib-extensions.h +++ b/tumbler/tumbler-util.h @@ -18,25 +18,15 @@ * Boston, MA 02110-1301, USA. */ -#if !defined (TUMBLER_INSIDE_TUMBLER_H) && !defined (TUMBLER_COMPILATION) -#error "Only <tumbler/tumbler.h> may be included directly. This file might disappear or change contents." -#endif +#ifndef __TUMBLER_UTIL_H__ +#define __TUMBLER_UTIL_H__ -#ifndef __TUMBLER_GLIB_EXTENSIONS_H__ -#define __TUMBLER_GLIB_EXTENSIONS_H__ - -#include <glib-object.h> +#include <glib.h> G_BEGIN_DECLS -#define TUMBLER_ADD_INTERFACE(TYPE_IFACE, iface_init) \ -{ \ - static const GInterfaceInfo tumbler_add_interface_info = { \ - (GInterfaceInitFunc) iface_init, NULL, NULL \ - }; \ - g_type_module_add_interface (type_module, g_define_type_id, TYPE_IFACE, &tumbler_add_interface_info); \ -} +GStrv tumbler_util_get_supported_uri_schemes (void) G_GNUC_MALLOC; G_END_DECLS -#endif /* !__TUMBLER_GLIB_EXTENSIONS_H__ */ +#endif /* !__TUMBLER_UTIL_H__ */ diff --git a/tumbler/tumbler.h b/tumbler/tumbler.h index b2f4429..98661a5 100644 --- a/tumbler/tumbler.h +++ b/tumbler/tumbler.h @@ -37,6 +37,7 @@ #include <tumbler/tumbler-thumbnailer-provider.h> #include <tumbler/tumbler-thumbnailer.h> #include <tumbler/tumbler-thumbnail.h> +#include <tumbler/tumbler-util.h> #undef TUMBLER_INSIDE_TUMBLER_H _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org http://foo-projects.org/mailman/listinfo/xfce4-commits