1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* gnome-vfs-utils.h - Public utility functions for the GNOME Virtual
5 Copyright (C) 1999 Free Software Foundation
6 Copyright (C) 2000 Eazel, Inc.
8 The Gnome Library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version.
13 The Gnome Library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
18 You should have received a copy of the GNU Library General Public
19 License along with the Gnome Library; see the file COPYING.LIB. If not,
20 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.
23 Authors: Ettore Perazzoli <ettore@comm2000.it>
24 John Sullivan <sullivan@eazel.com>
27 #ifndef GNOME_VFS_UTILS_H
28 #define GNOME_VFS_UTILS_H
30 #include <glib/gmessages.h>
31 #include <libgnomevfs/gnome-vfs-file-size.h>
32 #include <libgnomevfs/gnome-vfs-result.h>
33 #include <libgnomevfs/gnome-vfs-uri.h>
34 #include <libgnomevfs/gnome-vfs-handle.h>
39 GNOME_VFS_MAKE_URI_DIR_NONE = 0,
40 GNOME_VFS_MAKE_URI_DIR_HOMEDIR = 1 << 0,
41 GNOME_VFS_MAKE_URI_DIR_CURRENT = 1 << 1
42 } GnomeVFSMakeURIDirs;
44 /* Makes a human-readable string. */
45 char *gnome_vfs_format_file_size_for_display (GnomeVFSFileSize size);
47 /* Converts unsafe characters to % sequences so the string can be
48 * used as a piece of a URI. Escapes all reserved URI characters.
50 char *gnome_vfs_escape_string (const char *string);
52 /* Converts unsafe characters to % sequences so the path can be
53 * used as a piece of a URI. Escapes all reserved URI characters
56 char *gnome_vfs_escape_path_string (const char *path);
58 /* Converts unsafe characters to % sequences so the host/path segment
59 * can be used as a piece of a URI. Allows ":" and "@" in the host
60 * section (everything up to the first "/"), and after that, it behaves
61 * like gnome_vfs_escape_path_string.
63 char *gnome_vfs_escape_host_and_path_string (const char *path);
65 /* Converts only slashes and % characters to % sequences. This is useful
66 * for code that wants to use an arbitrary string as a file name. To use
67 * it in a URI, you have to escape again, of course.
69 char *gnome_vfs_escape_slashes (const char *string);
72 /* Escapes all the characters that match any of the @match_set */
73 char *gnome_vfs_escape_set (const char *string,
74 const char *match_set);
76 /* Returns NULL if any of the illegal character appear in escaped
77 * form. If the illegal characters are in there unescaped, that's OK.
78 * Typically you pass "/" for illegal characters when converting to a
79 * Unix path, since pieces of Unix paths can't contain "/". ASCII 0
80 * is always illegal due to the limitations of NULL-terminated strings.
82 char *gnome_vfs_unescape_string (const char *escaped_string,
83 const char *illegal_characters);
85 /* returns a copy of uri, converted to a canonical form */
86 char *gnome_vfs_make_uri_canonical (const char *uri);
88 /* returns a copy of path, converted to a canonical form */
89 char *gnome_vfs_make_path_name_canonical (const char *path);
91 /* returns a copy of path, with initial ~ expanded, or just copy of path
92 * if there's no initial ~
94 char *gnome_vfs_expand_initial_tilde (const char *path);
96 /* Prepare an escaped string for display. Unlike gnome_vfs_unescape_string,
97 * this doesn't return NULL if an illegal sequences appears in the string,
98 * instead doing its best to provide a useful result.
100 char *gnome_vfs_unescape_string_for_display (const char *escaped);
102 /* Turn a "file://" URI in string form into a local path. Returns NULL
103 * if it's not a URI that can be converted.
105 char *gnome_vfs_get_local_path_from_uri (const char *uri);
107 /* Turn a path into a "file://" URI. */
108 char *gnome_vfs_get_uri_from_local_path (const char *local_full_path);
110 /* Check whether a string starts with an executable command */
111 gboolean gnome_vfs_is_executable_command_string (const char *command_string);
113 /* Free the list, freeing each item data with a g_free */
114 void gnome_vfs_list_deep_free (GList *list);
117 /* Return amount of free space on target */
118 GnomeVFSResult gnome_vfs_get_volume_free_space (const GnomeVFSURI *vfs_uri,
119 GnomeVFSFileSize *size);
121 char *gnome_vfs_icon_path_from_filename (const char *filename);
123 /* Convert a file descriptor to a handle */
124 GnomeVFSResult gnome_vfs_open_fd (GnomeVFSHandle **handle,
127 /* TRUE if the current thread is the thread with the main glib event loop */
128 gboolean gnome_vfs_is_primary_thread (void);
131 * GNOME_VFS_ASSERT_PRIMARY_THREAD:
133 * Asserts that the current thread is the thread with
134 * the main glib event loop
136 #define GNOME_VFS_ASSERT_PRIMARY_THREAD g_assert (gnome_vfs_is_primary_thread())
139 * GNOME_VFS_ASSERT_SECONDARY_THREAD:
141 * Asserts that the current thread is NOT the thread with
142 * the main glib event loop
144 #define GNOME_VFS_ASSERT_SECONDARY_THREAD g_assert (!gnome_vfs_is_primary_thread())
146 /* Reads the contents of an entire file into memory */
147 GnomeVFSResult gnome_vfs_read_entire_file (const char *uri,
149 char **file_contents);
151 char * gnome_vfs_format_uri_for_display (const char *uri);
152 char * gnome_vfs_make_uri_from_input (const char *uri);
153 char * gnome_vfs_make_uri_from_input_with_dirs (const char *uri,
154 GnomeVFSMakeURIDirs dirs);
155 char * gnome_vfs_make_uri_canonical_strip_fragment (const char *uri);
156 gboolean gnome_vfs_uris_match (const char *uri_1,
158 char * gnome_vfs_get_uri_scheme (const char *uri);
159 char * gnome_vfs_make_uri_from_shell_arg (const char *uri);
162 #ifndef GNOME_VFS_DISABLE_DEPRECATED
163 char * gnome_vfs_make_uri_full_from_relative (const char *base_uri,
164 const char *relative_uri);
165 #endif /* GNOME_VFS_DISABLE_DEPRECATED */
167 GnomeVFSResult gnome_vfs_url_show (const char *url);
168 GnomeVFSResult gnome_vfs_url_show_with_env (const char *url,
174 #endif /* GNOME_VFS_UTILS_H */