]> Pileus Git - ~andy/gtk/blob - gtk/gtkfilesystem.h
394938864533f26b11052c521cbe96c1c67ada5c
[~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 typedef struct _GtkFileSystemVolume GtkFileSystemVolume;
45
46 typedef struct _GtkFilePath        GtkFilePath;
47
48 /* Mask of information about a file, for monitoring and
49  * gtk_file_system_get_info()
50  */
51 typedef enum {
52   GTK_FILE_INFO_DISPLAY_NAME      = 1 << 0,
53   GTK_FILE_INFO_IS_FOLDER         = 1 << 1,
54   GTK_FILE_INFO_IS_HIDDEN         = 1 << 2,
55   GTK_FILE_INFO_MIME_TYPE         = 1 << 3,
56   GTK_FILE_INFO_MODIFICATION_TIME = 1 << 4,
57   GTK_FILE_INFO_SIZE              = 1 << 5,
58 #if 0
59   GTK_FILE_INFO_ICON              = 1 << 6,
60 #endif
61   GTK_FILE_INFO_ALL               = (1 << 7) - 1
62 } GtkFileInfoType;
63
64 #if 0
65 /* Icon type, supplemented by MIME type
66  */
67 typedef enum {
68   GTK_FILE_ICON_REGULAR,        /* Use mime type for icon */
69   GTK_FILE_ICON_BLOCK_DEVICE,
70   GTK_FILE_ICON_BROKEN_SYMBOLIC_LINK,
71   GTK_FILE_ICON_CHARACTER_DEVICE,
72   GTK_FILE_ICON_DIRECTORY,
73   GTK_FILE_ICON_EXECUTABLE,
74   GTK_FILE_ICON_FIFO,
75   GTK_FILE_ICON_SOCKET
76 } GtkFileIconType;
77 #endif
78
79 /* GError enumeration for GtkFileSystem
80  */
81
82 #define GTK_FILE_SYSTEM_ERROR (gtk_file_system_error_quark ())
83
84 typedef enum
85 {
86   GTK_FILE_SYSTEM_ERROR_NONEXISTENT,
87   GTK_FILE_SYSTEM_ERROR_NOT_FOLDER,
88   GTK_FILE_SYSTEM_ERROR_INVALID_URI,
89   GTK_FILE_SYSTEM_ERROR_BAD_FILENAME,
90   GTK_FILE_SYSTEM_ERROR_FAILED,
91 } GtkFileSystemError;
92
93 GQuark     gtk_file_system_error_quark      (void);
94
95 /* Boxed-type for gtk_file_folder_get_info() results
96  */
97 #define GTK_TYPE_FILE_INFO (gtk_file_info_get_type ())
98
99 GType       gtk_file_info_get_type (void);
100
101 GtkFileInfo *gtk_file_info_new  (void);
102 GtkFileInfo *gtk_file_info_copy (GtkFileInfo *info);
103 void         gtk_file_info_free (GtkFileInfo *info);
104
105
106 G_CONST_RETURN gchar *gtk_file_info_get_display_name      (const GtkFileInfo *info);
107 G_CONST_RETURN gchar *gtk_file_info_get_display_key       (const GtkFileInfo *info);
108 void                  gtk_file_info_set_display_name      (GtkFileInfo       *info,
109                                                            const gchar       *display_name);
110 gboolean              gtk_file_info_get_is_folder         (const GtkFileInfo *info);
111 void                  gtk_file_info_set_is_folder         (GtkFileInfo       *info,
112                                                            gboolean           is_folder);
113 gboolean              gtk_file_info_get_is_hidden         (const GtkFileInfo *info);
114 void                  gtk_file_info_set_is_hidden         (GtkFileInfo       *info,
115                                                            gboolean           is_hidden);
116 G_CONST_RETURN gchar *gtk_file_info_get_mime_type         (const GtkFileInfo *info);
117 void                  gtk_file_info_set_mime_type         (GtkFileInfo       *info,
118                                                            const gchar       *mime_type);
119 GtkFileTime           gtk_file_info_get_modification_time (const GtkFileInfo *info);
120 void                  gtk_file_info_set_modification_time (GtkFileInfo       *info,
121                                                            GtkFileTime        modification_time);
122 gint64                gtk_file_info_get_size              (const GtkFileInfo *info);
123 void                  gtk_file_info_set_size              (GtkFileInfo       *info,
124                                                            gint64             size);
125 #if 0
126 void                  gtk_file_info_set_icon_type         (GtkFileInfo       *info,
127                                                            GtkFileIconType    icon_type);
128 GtkFileIconType       gtk_file_info_get_icon_type         (const GtkFileInfo *info);
129 GdkPixbuf *           gtk_file_info_render_icon           (const GtkFileInfo *info,
130                                                            GtkWidget         *widget,
131                                                            gint               pixel_size);
132 #endif
133
134 /* The base GtkFileSystem interface
135  */
136 #define GTK_TYPE_FILE_SYSTEM             (gtk_file_system_get_type ())
137 #define GTK_FILE_SYSTEM(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FILE_SYSTEM, GtkFileSystem))
138 #define GTK_IS_FILE_SYSTEM(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FILE_SYSTEM))
139 #define GTK_FILE_SYSTEM_GET_IFACE(inst)  (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GTK_TYPE_FILE_SYSTEM, GtkFileSystemIface))
140
141 struct _GtkFileSystemIface
142 {
143   GTypeInterface base_iface;
144
145   /* Methods
146    */
147   GSList *           (*list_volumes)   (GtkFileSystem     *file_system);
148   GSList *           (*list_roots)     (GtkFileSystem     *file_system);
149
150   GtkFileInfo *      (*get_root_info)  (GtkFileSystem     *file_system,
151                                         const GtkFilePath *path,
152                                         GtkFileInfoType    types,
153                                         GError           **error);
154
155   GtkFileFolder *    (*get_folder)     (GtkFileSystem     *file_system,
156                                         const GtkFilePath *path,
157                                         GtkFileInfoType    types,
158                                         GError           **error);
159   gboolean           (*create_folder)  (GtkFileSystem     *file_system,
160                                         const GtkFilePath *path,
161                                         GError           **error);
162
163   /* Volumes
164    */
165
166   void          (*volume_free)             (GtkFileSystem        *file_system,
167                                             GtkFileSystemVolume  *volume);
168   GtkFilePath * (*volume_get_base_path)    (GtkFileSystem        *file_system,
169                                             GtkFileSystemVolume  *volume);
170   gboolean      (*volume_get_is_mounted)   (GtkFileSystem        *file_system,
171                                             GtkFileSystemVolume  *volume);
172   gboolean      (*volume_mount)            (GtkFileSystem        *file_system, 
173                                             GtkFileSystemVolume  *volume,
174                                             GError              **error);
175   char *        (*volume_get_display_name) (GtkFileSystem        *file_system, 
176                                             GtkFileSystemVolume  *volume);
177   GdkPixbuf *   (*volume_render_icon)      (GtkFileSystem        *file_system,
178                                             GtkFileSystemVolume  *volume,
179                                             GtkWidget            *widget,
180                                             gint                  pixel_size,
181                                             GError              **error);
182
183   /* Path Manipulation
184    */
185   gboolean      (*get_parent)      (GtkFileSystem      *file_system,
186                                     const GtkFilePath  *path,
187                                     GtkFilePath       **parent,
188                                     GError            **error);
189   GtkFilePath * (*make_path)        (GtkFileSystem     *file_system,
190                                      const GtkFilePath *base_path,
191                                      const gchar       *display_name,
192                                      GError           **error);
193   gboolean      (*parse)            (GtkFileSystem     *file_system,
194                                      const GtkFilePath *base_path,
195                                      const gchar       *str,
196                                      GtkFilePath      **folder,
197                                      gchar            **file_part,
198                                      GError           **error);
199   gchar *      (*path_to_uri)      (GtkFileSystem      *file_system,
200                                     const GtkFilePath  *path);
201   gchar *      (*path_to_filename) (GtkFileSystem      *file_system,
202                                     const GtkFilePath  *path);
203   GtkFilePath *(*uri_to_path)      (GtkFileSystem      *file_system,
204                                     const gchar        *uri);
205   GtkFilePath *(*filename_to_path) (GtkFileSystem      *file_system,
206                                     const gchar        *path);
207
208   /* Icons */
209
210   GdkPixbuf *  (*render_icon)    (GtkFileSystem     *file_system,
211                                   const GtkFilePath *path,
212                                   GtkWidget         *widget,
213                                   gint               pixel_size,
214                                   GError           **error);
215
216   /* Bookmarks */
217
218   gboolean       (*add_bookmark)           (GtkFileSystem     *file_system,
219                                             const GtkFilePath *path,
220                                             GError           **error);
221   gboolean       (*remove_bookmark)        (GtkFileSystem     *file_system,
222                                             const GtkFilePath *path,
223                                             GError           **error);
224   GSList *       (*list_bookmarks)         (GtkFileSystem *file_system);
225
226   /* Signals
227    */
228   void (*volumes_changed)   (GtkFileSystem *file_system);
229   void (*roots_changed)     (GtkFileSystem *file_system);
230   void (*bookmarks_changed) (GtkFileSystem *file_system);
231 };
232
233 GType             gtk_file_system_get_type       (void);
234
235 GSList *          gtk_file_system_list_volumes   (GtkFileSystem     *file_system);
236 GSList *          gtk_file_system_list_roots     (GtkFileSystem     *file_system);
237 GtkFileInfo *     gtk_file_system_get_root_info  (GtkFileSystem     *file_system,
238                                                   const GtkFilePath *path,
239                                                   GtkFileInfoType    types,
240                                                   GError           **error);
241
242 void              gtk_file_system_volume_free             (GtkFileSystem        *file_system,
243                                                            GtkFileSystemVolume  *volume);
244 GtkFilePath *     gtk_file_system_volume_get_base_path    (GtkFileSystem        *file_system,
245                                                            GtkFileSystemVolume  *volume);
246 gboolean          gtk_file_system_volume_get_is_mounted   (GtkFileSystem        *file_system,
247                                                            GtkFileSystemVolume  *volume);
248 gboolean          gtk_file_system_volume_mount            (GtkFileSystem        *file_system, 
249                                                            GtkFileSystemVolume  *volume,
250                                                            GError              **error);
251 char *            gtk_file_system_volume_get_display_name (GtkFileSystem        *file_system, 
252                                                            GtkFileSystemVolume  *volume);
253 GdkPixbuf *       gtk_file_system_volume_render_icon      (GtkFileSystem        *file_system,
254                                                            GtkFileSystemVolume  *volume,
255                                                            GtkWidget            *widget,
256                                                            gint                  pixel_size,
257                                                            GError              **error);
258
259 gboolean          gtk_file_system_get_parent     (GtkFileSystem     *file_system,
260                                                   const GtkFilePath *path,
261                                                   GtkFilePath      **parent,
262                                                   GError           **error);
263 GtkFileFolder    *gtk_file_system_get_folder     (GtkFileSystem     *file_system,
264                                                   const GtkFilePath *path,
265                                                   GtkFileInfoType    types,
266                                                   GError           **error);
267 gboolean          gtk_file_system_create_folder  (GtkFileSystem     *file_system,
268                                                   const GtkFilePath *path,
269                                                   GError           **error);
270 GtkFilePath *     gtk_file_system_make_path      (GtkFileSystem     *file_system,
271                                                   const GtkFilePath *base_path,
272                                                   const gchar       *display_name,
273                                                   GError           **error);
274 gboolean          gtk_file_system_parse          (GtkFileSystem     *file_system,
275                                                   const GtkFilePath *base_path,
276                                                   const gchar       *str,
277                                                   GtkFilePath      **folder,
278                                                   gchar            **file_part,
279                                                   GError           **error);
280
281 gchar *      gtk_file_system_path_to_uri      (GtkFileSystem     *file_system,
282                                                const GtkFilePath *path);
283 gchar *      gtk_file_system_path_to_filename (GtkFileSystem     *file_system,
284                                                const GtkFilePath *path);
285 GtkFilePath *gtk_file_system_uri_to_path      (GtkFileSystem     *file_system,
286                                                const gchar       *uri);
287 GtkFilePath *gtk_file_system_filename_to_path (GtkFileSystem     *file_system,
288                                                const gchar       *filename);
289
290 GdkPixbuf   *gtk_file_system_render_icon   (GtkFileSystem      *file_system,
291                                             const GtkFilePath  *path,
292                                             GtkWidget          *widget,
293                                             gint                pixel_size,
294                                             GError            **error);
295
296 gboolean gtk_file_system_add_bookmark    (GtkFileSystem     *file_system,
297                                           const GtkFilePath *path,
298                                           GError           **error);
299 gboolean gtk_file_system_remove_bookmark (GtkFileSystem     *file_system,
300                                           const GtkFilePath *path,
301                                           GError           **error);
302 GSList  *gtk_file_system_list_bookmarks  (GtkFileSystem     *file_system);
303
304
305 /*
306  * Detailed information about a particular folder
307  */
308 #define GTK_TYPE_FILE_FOLDER             (gtk_file_folder_get_type ())
309 #define GTK_FILE_FOLDER(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FILE_FOLDER, GtkFileFolder))
310 #define GTK_IS_FILE_FOLDER(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FILE_FOLDER))
311 #define GTK_FILE_FOLDER_GET_IFACE(inst)  (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GTK_TYPE_FILE_FOLDER, GtkFileFolderIface))
312
313 struct _GtkFileFolderIface
314 {
315   GTypeInterface base_iface;
316
317   /* Methods
318    */
319   GtkFileInfo *      (*get_info)       (GtkFileFolder     *folder,
320                                         const GtkFilePath *path,
321                                         GError           **error);
322   gboolean           (*list_children)  (GtkFileFolder     *folder,
323                                         GSList           **children,
324                                         GError           **error);
325
326   /* ??? refresh() ??? */
327
328   /* Signals
329    */
330   void (*deleted)       (GtkFileFolder *monitor);
331   void (*files_added)   (GtkFileFolder *monitor,
332                          GSList        *paths);
333   void (*files_changed) (GtkFileFolder *monitor,
334                          GSList        *paths);
335   void (*files_removed) (GtkFileFolder *monitor,
336                          GSList        *paths);
337 };
338
339 GType        gtk_file_folder_get_type      (void);
340 gboolean     gtk_file_folder_list_children (GtkFileFolder      *folder,
341                                             GSList            **children,
342                                             GError            **error);
343 GtkFileInfo *gtk_file_folder_get_info      (GtkFileFolder      *folder,
344                                             const GtkFilePath  *path,
345                                             GError            **error);
346
347 #ifdef __GNUC__
348 #define gtk_file_path_new_dup(str) \
349  ({ const gchar *__s = (str); (GtkFilePath *)g_strdup(__s); })
350 #define gtk_file_path_new_steal(str) \
351  ({ gchar *__s = (str); (GtkFilePath *)__s; })
352 #define gtk_file_path_get_string(path) \
353  ({ const GtkFilePath *__p = (path); (const gchar *)__p; })
354 #define gtk_file_path_free(path) \
355  ({ GtkFilePath *__p = (path); g_free (__p); })
356 #else /* __GNUC__ */
357 #define gtk_file_path_new_dup(str)     ((GtkFilePath *)g_strdup(str))
358 #define gtk_file_path_new_steal(str)   ((GtkFilePath *)(str))
359 #define gtk_file_path_get_string(str) ((const gchar *)(str))
360 #define gtk_file_path_free(path)       g_free (path)
361 #endif/* __GNUC__ */
362
363 #define gtk_file_path_copy(path)       gtk_file_path_new_dup (gtk_file_path_get_string(path))
364 #define gtk_file_path_compare(path1,path2) strcmp (gtk_file_path_get_string (path1), \
365                                                    gtk_file_path_get_string (path2))
366
367 GSList *gtk_file_paths_sort (GSList *paths);
368 GSList *gtk_file_paths_copy (GSList *paths);
369 void    gtk_file_paths_free (GSList *paths);
370
371 G_END_DECLS
372
373 #endif /* __GTK_FILE_SYSTEM_H__ */