]> Pileus Git - ~andy/gtk/blob - gtk/gtkfilesystem.h
Changew index to filter_index to fix compilation error.
[~andy/gtk] / gtk / gtkfilesystem.h
1 /* GTK - The GIMP Toolkit
2  * gtkfilesystem.h: Abstract file system interfaces
3  * Copyright (C) 2003, Red Hat, Inc.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #ifndef __GTK_FILE_SYSTEM_H__
22 #define __GTK_FILE_SYSTEM_H__
23
24 /* This is a "semi-private" header; it is meant only for
25  * alternate GtkFileChooser backend modules; no stability guarantees 
26  * are made at this point
27  */
28 #ifndef GTK_FILE_SYSTEM_ENABLE_UNSUPPORTED
29 #error "GtkFileSystem is not supported API for general use"
30 #endif
31
32 #include <glib-object.h>
33 #include <gtk/gtkwidget.h>      /* For icon handling */
34
35 G_BEGIN_DECLS
36
37 typedef gint64 GtkFileTime;
38
39 typedef struct _GtkFileFolder      GtkFileFolder;
40 typedef struct _GtkFileFolderIface GtkFileFolderIface;
41 typedef struct _GtkFileInfo        GtkFileInfo;
42 typedef struct _GtkFileSystem      GtkFileSystem;
43 typedef struct _GtkFileSystemIface GtkFileSystemIface;
44
45 typedef struct _GtkFilePath        GtkFilePath;
46
47 /* Mask of information about a file, for monitoring and
48  * gtk_file_system_get_info()
49  */
50 typedef enum {
51   GTK_FILE_INFO_DISPLAY_NAME      = 1 << 0,
52   GTK_FILE_INFO_IS_FOLDER         = 1 << 1,
53   GTK_FILE_INFO_IS_HIDDEN         = 1 << 2,
54   GTK_FILE_INFO_MIME_TYPE         = 1 << 3,
55   GTK_FILE_INFO_MODIFICATION_TIME = 1 << 4,
56   GTK_FILE_INFO_SIZE              = 1 << 5,
57   GTK_FILE_INFO_ICON              = 1 << 6,
58   GTK_FILE_INFO_ALL               = (1 << 7) - 1
59 } GtkFileInfoType;
60
61 /* Icon type, supplemented by MIME type
62  */
63 typedef enum {
64   GTK_FILE_ICON_REGULAR,        /* Use mime type for icon */
65   GTK_FILE_ICON_BLOCK_DEVICE,
66   GTK_FILE_ICON_BROKEN_SYMBOLIC_LINK,
67   GTK_FILE_ICON_CHARACTER_DEVICE,
68   GTK_FILE_ICON_DIRECTORY,
69   GTK_FILE_ICON_EXECUTABLE,
70   GTK_FILE_ICON_FIFO,
71   GTK_FILE_ICON_SOCKET
72 } GtkFileIconType;
73
74 /* GError enumeration for GtkFileSystem
75  */
76
77 #define GTK_FILE_SYSTEM_ERROR (gtk_file_system_error_quark ())
78
79 typedef enum
80 {
81   GTK_FILE_SYSTEM_ERROR_NONEXISTENT,
82   GTK_FILE_SYSTEM_ERROR_NOT_FOLDER,
83   GTK_FILE_SYSTEM_ERROR_INVALID_URI,
84   GTK_FILE_SYSTEM_ERROR_BAD_FILENAME,
85   GTK_FILE_SYSTEM_ERROR_FAILED,
86 } GtkFileSystemError;
87
88 GQuark     gtk_file_system_error_quark      (void);
89
90 /* Boxed-type for gtk_file_folder_get_info() results
91  */
92 #define GTK_TYPE_FILE_INFO (gtk_file_info_get_type ())
93
94 GType       gtk_file_info_get_type (void);
95
96 GtkFileInfo *gtk_file_info_new  (void);
97 GtkFileInfo *gtk_file_info_copy (GtkFileInfo *info);
98 void         gtk_file_info_free (GtkFileInfo *info);
99
100
101 G_CONST_RETURN gchar *gtk_file_info_get_display_name      (const GtkFileInfo *info);
102 G_CONST_RETURN gchar *gtk_file_info_get_display_key       (const GtkFileInfo *info);
103 void                  gtk_file_info_set_display_name      (GtkFileInfo       *info,
104                                                            const gchar       *display_name);
105 gboolean              gtk_file_info_get_is_folder         (const GtkFileInfo *info);
106 void                  gtk_file_info_set_is_folder         (GtkFileInfo       *info,
107                                                            gboolean           is_folder);
108 gboolean              gtk_file_info_get_is_hidden         (const GtkFileInfo *info);
109 void                  gtk_file_info_set_is_hidden         (GtkFileInfo       *info,
110                                                            gboolean           is_hidden);
111 G_CONST_RETURN gchar *gtk_file_info_get_mime_type         (const GtkFileInfo *info);
112 void                  gtk_file_info_set_mime_type         (GtkFileInfo       *info,
113                                                            const gchar       *mime_type);
114 GtkFileTime           gtk_file_info_get_modification_time (const GtkFileInfo *info);
115 void                  gtk_file_info_set_modification_time (GtkFileInfo       *info,
116                                                            GtkFileTime        modification_time);
117 gint64                gtk_file_info_get_size              (const GtkFileInfo *info);
118 void                  gtk_file_info_set_size              (GtkFileInfo       *info,
119                                                            gint64             size);
120 void                  gtk_file_info_set_icon_type         (GtkFileInfo       *info,
121                                                            GtkFileIconType    icon_type);
122 GtkFileIconType       gtk_file_info_get_icon_type         (const GtkFileInfo *info);
123 GdkPixbuf *           gtk_file_info_render_icon           (const GtkFileInfo *info,
124                                                            GtkWidget         *widget,
125                                                            gint               pixel_size);
126
127 /* The base GtkFileSystem interface
128  */
129 #define GTK_TYPE_FILE_SYSTEM             (gtk_file_system_get_type ())
130 #define GTK_FILE_SYSTEM(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FILE_SYSTEM, GtkFileSystem))
131 #define GTK_IS_FILE_SYSTEM(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FILE_SYSTEM))
132 #define GTK_FILE_SYSTEM_GET_IFACE(inst)  (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GTK_TYPE_FILE_SYSTEM, GtkFileSystemIface))
133
134 struct _GtkFileSystemIface
135 {
136   GTypeInterface base_iface;
137
138   /* Methods
139    */
140   GSList *           (*list_roots)     (GtkFileSystem     *file_system);
141
142   GtkFileInfo *      (*get_root_info)  (GtkFileSystem     *file_system,
143                                         const GtkFilePath *path,
144                                         GtkFileInfoType    types,
145                                         GError           **error);
146
147   GtkFileFolder *    (*get_folder)     (GtkFileSystem     *file_system,
148                                         const GtkFilePath *path,
149                                         GtkFileInfoType    types,
150                                         GError           **error);
151   gboolean           (*create_folder)  (GtkFileSystem     *file_system,
152                                         const GtkFilePath *path,
153                                         GError           **error);
154
155   /* Path Manipulation
156    */
157   gboolean      (*get_parent)      (GtkFileSystem      *file_system,
158                                     const GtkFilePath  *path,
159                                     GtkFilePath       **parent,
160                                     GError            **error);
161   GtkFilePath * (*make_path)        (GtkFileSystem     *file_system,
162                                      const GtkFilePath *base_path,
163                                      const gchar       *display_name,
164                                      GError           **error);
165   gboolean      (*parse)            (GtkFileSystem     *file_system,
166                                      const GtkFilePath *base_path,
167                                      const gchar       *str,
168                                      GtkFilePath      **folder,
169                                      gchar            **file_part,
170                                      GError           **error);
171   gchar *      (*path_to_uri)      (GtkFileSystem      *file_system,
172                                     const GtkFilePath  *path);
173   gchar *      (*path_to_filename) (GtkFileSystem      *file_system,
174                                     const GtkFilePath  *path);
175   GtkFilePath *(*uri_to_path)      (GtkFileSystem      *file_system,
176                                     const gchar        *uri);
177   GtkFilePath *(*filename_to_path) (GtkFileSystem      *file_system,
178                                     const gchar        *path);
179
180   /* Bookmarks */
181
182   gboolean       (*add_bookmark)           (GtkFileSystem     *file_system,
183                                             const GtkFilePath *path,
184                                             GError           **error);
185   gboolean       (*remove_bookmark)        (GtkFileSystem     *file_system,
186                                             const GtkFilePath *path,
187                                             GError           **error);
188   GSList *       (*list_bookmarks)         (GtkFileSystem *file_system);
189
190   /* Signals
191    */
192   void (*roots_changed)     (GtkFileSystem *file_system);
193   void (*bookmarks_changed) (GtkFileSystem *file_system);
194 };
195
196 GType             gtk_file_system_get_type       (void);
197
198 GSList *          gtk_file_system_list_roots     (GtkFileSystem     *file_system);
199 GtkFileInfo *     gtk_file_system_get_root_info  (GtkFileSystem     *file_system,
200                                                   const GtkFilePath *path,
201                                                   GtkFileInfoType    types,
202                                                   GError           **error);
203
204 gboolean          gtk_file_system_get_parent     (GtkFileSystem     *file_system,
205                                                   const GtkFilePath *path,
206                                                   GtkFilePath      **parent,
207                                                   GError           **error);
208 GtkFileFolder    *gtk_file_system_get_folder     (GtkFileSystem     *file_system,
209                                                   const GtkFilePath *path,
210                                                   GtkFileInfoType    types,
211                                                   GError           **error);
212 gboolean          gtk_file_system_create_folder  (GtkFileSystem     *file_system,
213                                                   const GtkFilePath *path,
214                                                   GError           **error);
215 GtkFilePath *     gtk_file_system_make_path      (GtkFileSystem     *file_system,
216                                                   const GtkFilePath *base_path,
217                                                   const gchar       *display_name,
218                                                   GError           **error);
219 gboolean          gtk_file_system_parse          (GtkFileSystem     *file_system,
220                                                   const GtkFilePath *base_path,
221                                                   const gchar       *str,
222                                                   GtkFilePath      **folder,
223                                                   gchar            **file_part,
224                                                   GError           **error);
225
226 gchar *      gtk_file_system_path_to_uri      (GtkFileSystem     *file_system,
227                                                const GtkFilePath *path);
228 gchar *      gtk_file_system_path_to_filename (GtkFileSystem     *file_system,
229                                                const GtkFilePath *path);
230 GtkFilePath *gtk_file_system_uri_to_path      (GtkFileSystem     *file_system,
231                                                const gchar       *uri);
232 GtkFilePath *gtk_file_system_filename_to_path (GtkFileSystem     *file_system,
233                                                const gchar       *filename);
234
235 gboolean gtk_file_system_add_bookmark    (GtkFileSystem     *file_system,
236                                           const GtkFilePath *path,
237                                           GError           **error);
238 gboolean gtk_file_system_remove_bookmark (GtkFileSystem     *file_system,
239                                           const GtkFilePath *path,
240                                           GError           **error);
241 GSList  *gtk_file_system_list_bookmarks  (GtkFileSystem     *file_system);
242
243
244 /*
245  * Detailed information about a particular folder
246  */
247 #define GTK_TYPE_FILE_FOLDER             (gtk_file_folder_get_type ())
248 #define GTK_FILE_FOLDER(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FILE_FOLDER, GtkFileFolder))
249 #define GTK_IS_FILE_FOLDER(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FILE_FOLDER))
250 #define GTK_FILE_FOLDER_GET_IFACE(inst)  (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GTK_TYPE_FILE_FOLDER, GtkFileFolderIface))
251
252 struct _GtkFileFolderIface
253 {
254   GTypeInterface base_iface;
255
256   /* Methods
257    */
258   GtkFileInfo *      (*get_info)       (GtkFileFolder     *folder,
259                                         const GtkFilePath *path,
260                                         GError           **error);
261   gboolean           (*list_children)  (GtkFileFolder     *folder,
262                                         GSList           **children,
263                                         GError           **error);
264
265   /* ??? refresh() ??? */
266
267   /* Signals
268    */
269   void (*deleted)       (GtkFileFolder *monitor);
270   void (*files_added)   (GtkFileFolder *monitor,
271                          GSList        *paths);
272   void (*files_changed) (GtkFileFolder *monitor,
273                          GSList        *paths);
274   void (*files_removed) (GtkFileFolder *monitor,
275                          GSList        *paths);
276 };
277
278 GType        gtk_file_folder_get_type      (void);
279 gboolean     gtk_file_folder_list_children (GtkFileFolder      *folder,
280                                             GSList            **children,
281                                             GError            **error);
282 GtkFileInfo *gtk_file_folder_get_info      (GtkFileFolder      *folder,
283                                             const GtkFilePath  *path,
284                                             GError            **error);
285
286 #ifdef __GNUC__
287 #define gtk_file_path_new_dup(str) \
288  ({ const gchar *__s = (str); (GtkFilePath *)g_strdup(__s); })
289 #define gtk_file_path_new_steal(str) \
290  ({ gchar *__s = (str); (GtkFilePath *)__s; })
291 #define gtk_file_path_get_string(path) \
292  ({ const GtkFilePath *__p = (path); (const gchar *)__p; })
293 #define gtk_file_path_free(path) \
294  ({ GtkFilePath *__p = (path); g_free (__p); })
295 #else /* __GNUC__ */
296 #define gtk_file_path_new_dup(str)     ((GtkFilePath *)g_strdup(str))
297 #define gtk_file_path_new_steal(str)   ((GtkFilePath *)(str))
298 #define gtk_file_path_get_string(str) ((const gchar *)(str))
299 #define gtk_file_path_free(path)       g_free (path)
300 #endif/* __GNUC__ */
301
302 #define gtk_file_path_copy(path)       gtk_file_path_new_dup (gtk_file_path_get_string(path))
303 #define gtk_file_path_compare(path1,path2) strcmp (gtk_file_path_get_string (path1), \
304                                                    gtk_file_path_get_string (path2))
305
306 GSList *gtk_file_paths_sort (GSList *paths);
307 GSList *gtk_file_paths_copy (GSList *paths);
308 void    gtk_file_paths_free (GSList *paths);
309
310 G_END_DECLS
311
312 #endif /* __GTK_FILE_SYSTEM_H__ */