[Xfce4-commits] r29754 - in thunar/branches/migration-to-gio: . thunar
Jannis Pohlmann
jannis at xfce.org
Fri Apr 10 21:42:47 CEST 2009
Author: jannis
Date: 2009-04-10 19:42:47 +0000 (Fri, 10 Apr 2009)
New Revision: 29754
Added:
thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.c
thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.h
Modified:
thunar/branches/migration-to-gio/ChangeLog
thunar/branches/migration-to-gio/thunar/Makefile.am
Log:
* thunar/Makefile.am, thunar/thunar-gio-extensions.{c,h}: Add a set of
functions extending the GIO API, like g_file_new_for_home(),
g_file_list_new_from_string(), g_file_list_to_string() and more.
Modified: thunar/branches/migration-to-gio/ChangeLog
===================================================================
--- thunar/branches/migration-to-gio/ChangeLog 2009-04-10 19:42:40 UTC (rev 29753)
+++ thunar/branches/migration-to-gio/ChangeLog 2009-04-10 19:42:47 UTC (rev 29754)
@@ -1,5 +1,11 @@
2009-04-10 Jannis Pohlmann <jannis at xfce.org>
+ * thunar/Makefile.am, thunar/thunar-gio-extensions.{c,h}: Add a set of
+ functions extending the GIO API, like g_file_new_for_home(),
+ g_file_list_new_from_string(), g_file_list_to_string() and more.
+
+2009-04-10 Jannis Pohlmann <jannis at xfce.org>
+
* AUTHORS: Put my name in. Yeah, yeah ...
* configure.in.in, thunar/Makefile.am, thunarx/Makefile.am: Add
dependency on GIO. Bump required GTK+/GLib version to 2.14/2.16.
Modified: thunar/branches/migration-to-gio/thunar/Makefile.am
===================================================================
--- thunar/branches/migration-to-gio/thunar/Makefile.am 2009-04-10 19:42:40 UTC (rev 29753)
+++ thunar/branches/migration-to-gio/thunar/Makefile.am 2009-04-10 19:42:47 UTC (rev 29754)
@@ -76,6 +76,8 @@
thunar-folder.h \
thunar-gdk-extensions.c \
thunar-gdk-extensions.h \
+ thunar-gio-extensions.c \
+ thunar-gio-extensions.h \
thunar-gobject-extensions.c \
thunar-gobject-extensions.h \
thunar-gtk-extensions.c \
Added: thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.c (rev 0)
+++ thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.c 2009-04-10 19:42:47 UTC (rev 29754)
@@ -0,0 +1,182 @@
+/* $Id$ */
+/*-
+ * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
+ *
+ * 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; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * 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 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
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gio/gio.h>
+
+#include <libxfce4util/libxfce4util.h>
+
+#include <thunar/thunar-gio-extensions.h>
+
+
+
+GFile *
+g_file_new_for_home (void)
+{
+ return g_file_new_for_path (xfce_get_homedir ());
+}
+
+
+
+GFile *
+g_file_new_for_root (void)
+{
+ return g_file_new_for_uri ("file:///");
+}
+
+
+
+GFile *
+g_file_new_for_trash (void)
+{
+ return g_file_new_for_uri ("trash:///");
+}
+
+
+
+gboolean
+g_file_is_root (GFile *file)
+{
+ GFile *parent;
+ gboolean is_root = FALSE;
+
+ parent = g_file_get_parent (file);
+ if (G_UNLIKELY (parent == NULL))
+ is_root = TRUE;
+ g_object_unref (parent);
+
+ return is_root;
+}
+
+
+
+/**
+ * g_file_list_new_from_string:
+ * @string : a string representation of an URI list.
+ *
+ * Splits an URI list conforming to the text/uri-list
+ * mime type defined in RFC 2483 into individual URIs,
+ * discarding any comments and whitespace. The resulting
+ * list will hold one #GFile for each URI.
+ *
+ * If @string contains no URIs, this function
+ * will return %NULL.
+ *
+ * Return value: the list of #GFile<!---->s or %NULL.
+ **/
+GList *
+g_file_list_new_from_string (const gchar *string)
+{
+ GFile *file;
+ GList *list = NULL;
+ gchar **uris;
+ gsize n;
+
+ uris = g_uri_list_extract_uris (string);
+
+ for (n = 0; uris != NULL && uris[n] != NULL; ++n)
+ list = g_list_append (list, g_file_new_for_uri (uris[n]));
+
+ g_strfreev (uris);
+
+ return list;
+}
+
+
+
+/**
+ * g_file_list_to_string:
+ * @list : a list of #GFile<!---->s.
+ *
+ * Free the returned value using g_free() when you
+ * are done with it.
+ *
+ * Return value: the string representation of @list conforming to the
+ * text/uri-list mime type defined in RFC 2483.
+ **/
+gchar *
+g_file_list_to_string (GList *list)
+{
+ GString *string;
+ gchar *uri;
+ GList *lp;
+
+ /* allocate initial string */
+ string = g_string_new (NULL);
+
+ for (lp = list; lp != NULL; lp = lp->next)
+ {
+ uri = g_file_get_uri (lp->data);
+ /* TODO Would UTF-8 in URIs be ok? */
+ string = g_string_append_uri_escaped (string,
+ uri,
+ G_URI_RESERVED_CHARS_ALLOWED_IN_PATH,
+ FALSE);
+ g_free (uri);
+
+ string = g_string_append (string, "\r\n");
+ }
+
+ return g_string_free (string, FALSE);
+}
+
+
+
+/**
+ * g_file_list_copy:
+ * @list : a list of #GFile<!---->s.
+ *
+ * Takes a deep copy of @list and returns the
+ * result. The caller is responsible to free the
+ * returned list using g_file_list_free().
+ *
+ * Return value: a deep copy of @list.
+ **/
+GList*
+g_file_list_copy (GList *list)
+{
+ GList *copy = NULL;
+ GList *lp;
+
+ for (list = NULL, lp = g_list_last (list); lp != NULL; lp = lp->prev)
+ copy = g_list_prepend (copy, g_object_ref (lp->data));
+
+ return list;
+}
+
+
+
+/**
+ * g_file_list_free:
+ * @list : a list of #GFile<!---->s.
+ *
+ * Frees the #GFile<!---->s in @list and
+ * the @list itself.
+ **/
+void
+g_file_list_free (GList *list)
+{
+ GList *lp;
+ for (lp = list; lp != NULL; lp = lp->next)
+ g_object_unref (lp->data);
+ g_list_free (list);
+}
Added: thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.h
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.h (rev 0)
+++ thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.h 2009-04-10 19:42:47 UTC (rev 29754)
@@ -0,0 +1,40 @@
+/* $Id$ */
+/*-
+ * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
+ *
+ * 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; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * 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 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
+ */
+
+#ifndef __THUNAR_GLIB_EXTENSIONS_H__
+#define __THUNAR_GLIB_EXTENSIONS_H__
+
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+GFile *g_file_new_for_home (void);
+GFile *g_file_new_for_root (void);
+GFile *g_file_new_for_trash (void);
+
+gboolean g_file_is_root (GFile *file);
+
+GList *g_file_list_new_from_string (const gchar *string);
+gchar *g_file_list_to_string (GList *list);
+GList *g_file_list_copy (GList *list);
+void g_file_list_free (GList *list);
+
+G_END_DECLS
+
+#endif /* !__THUNAR_GLIB_EXTENSIONS_H__ */
More information about the Xfce4-commits
mailing list