]> Pileus Git - ~andy/gtk/blob - gtk/gtkfilesystem.h
gtk/gtk.symbols rename _gtk_file_system_create to gtk_file_system_create
[~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   GTK_FILE_INFO_ICON              = 1 << 6,
59   GTK_FILE_INFO_ALL               = (1 << 7) - 1
60 } GtkFileInfoType;
61
62 /* GError enumeration for GtkFileSystem
63  */
64
65 #define GTK_FILE_SYSTEM_ERROR (gtk_file_system_error_quark ())
66
67 typedef enum
68 {
69   GTK_FILE_SYSTEM_ERROR_NONEXISTENT,
70   GTK_FILE_SYSTEM_ERROR_NOT_FOLDER,
71   GTK_FILE_SYSTEM_ERROR_INVALID_URI,
72   GTK_FILE_SYSTEM_ERROR_BAD_FILENAME,
73   GTK_FILE_SYSTEM_ERROR_FAILED,
74   GTK_FILE_SYSTEM_ERROR_ALREADY_EXISTS
75 } GtkFileSystemError;
76
77 GQuark     gtk_file_system_error_quark      (void);
78
79 /* Boxed-type for gtk_file_folder_get_info() results
80  */
81 #define GTK_TYPE_FILE_INFO (gtk_file_info_get_type ())
82
83 GType       gtk_file_info_get_type (void) G_GNUC_CONST; 
84
85 GtkFileInfo *gtk_file_info_new  (void);
86 GtkFileInfo *gtk_file_info_copy (GtkFileInfo *info);
87 void         gtk_file_info_free (GtkFileInfo *info);
88
89
90 G_CONST_RETURN gchar *gtk_file_info_get_display_name      (const GtkFileInfo *info);
91 G_CONST_RETURN gchar *gtk_file_info_get_display_key       (const GtkFileInfo *info);
92 void                  gtk_file_info_set_display_name      (GtkFileInfo       *info,
93                                                            const gchar       *display_name);
94 gboolean              gtk_file_info_get_is_folder         (const GtkFileInfo *info);
95 void                  gtk_file_info_set_is_folder         (GtkFileInfo       *info,
96                                                            gboolean           is_folder);
97 gboolean              gtk_file_info_get_is_hidden         (const GtkFileInfo *info);
98 void                  gtk_file_info_set_is_hidden         (GtkFileInfo       *info,
99                                                            gboolean           is_hidden);
100 G_CONST_RETURN gchar *gtk_file_info_get_mime_type         (const GtkFileInfo *info);
101 void                  gtk_file_info_set_mime_type         (GtkFileInfo       *info,
102                                                            const gchar       *mime_type);
103 GtkFileTime           gtk_file_info_get_modification_time (const GtkFileInfo *info);
104 void                  gtk_file_info_set_modification_time (GtkFileInfo       *info,
105                                                            GtkFileTime        modification_time);
106 gint64                gtk_file_info_get_size              (const GtkFileInfo *info);
107 void                  gtk_file_info_set_size              (GtkFileInfo       *info,
108                                                            gint64             size);
109
110 void                  gtk_file_info_set_icon_name         (GtkFileInfo       *info,
111                                                            const gchar       *con_name);
112 G_CONST_RETURN gchar *gtk_file_info_get_icon_name         (const GtkFileInfo *info);
113 GdkPixbuf            *gtk_file_info_render_icon           (const GtkFileInfo *info,
114                                                            GtkWidget         *widget,
115                                                            gint               pixel_size,
116                                                            GError           **error);
117
118 /* GtkFileSystemHandle
119  */
120
121 #define GTK_TYPE_FILE_SYSTEM_HANDLE            (gtk_file_system_handle_get_type ())
122 #define GTK_FILE_SYSTEM_HANDLE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FILE_SYSTEM_HANDLE, GtkFileSystemHandle))
123 #define GTK_IS_FILE_SYSTEM_HANDLE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FILE_SYSTEM_HANDLE))
124 #define GTK_FILE_SYSTEM_HANDLE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FILE_SYSTEM_HANDLE, GtkFileSystemHandleUnixClass))
125 #define GTK_IS_FILE_SYSTEM_HANDLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FILE_SYSTEM_HANDLE))
126 #define GTK_FILE_SYSTEM_HANDLE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FILE_SYSTEM_HANDLE, GtkFileSystemHandleClass))
127
128 typedef struct _GtkFileSystemHandle       GtkFileSystemHandle;
129 typedef struct _GtkFileSystemHandleClass  GtkFileSystemHandleClass;
130
131 struct _GtkFileSystemHandle
132 {
133   GObject parent_instance;
134
135   GtkFileSystem *file_system;
136
137   guint cancelled : 1;
138 };
139
140 struct _GtkFileSystemHandleClass
141 {
142   GObjectClass parent_class;
143 };
144
145 GType gtk_file_system_handle_get_type (void);
146
147 /* The base GtkFileSystem interface
148  */
149 #define GTK_TYPE_FILE_SYSTEM             (gtk_file_system_get_type ())
150 #define GTK_FILE_SYSTEM(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FILE_SYSTEM, GtkFileSystem))
151 #define GTK_IS_FILE_SYSTEM(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FILE_SYSTEM))
152 #define GTK_FILE_SYSTEM_GET_IFACE(inst)  (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GTK_TYPE_FILE_SYSTEM, GtkFileSystemIface))
153
154 /* Callbacks for the asynchronous GtkFileSystem operations
155  */
156
157 typedef void (* GtkFileSystemGetInfoCallback) (GtkFileSystemHandle *handle,
158                                                const GtkFileInfo   *file_info,
159                                                const GError        *error,
160                                                gpointer             data);
161 typedef void (* GtkFileSystemGetFolderCallback) (GtkFileSystemHandle *handle,
162                                                  GtkFileFolder       *folder,
163                                                  const GError        *error,
164                                                  gpointer             data);
165 typedef void (* GtkFileSystemCreateFolderCallback) (GtkFileSystemHandle *handle,
166                                                     const GtkFilePath   *path,
167                                                     const GError        *error,
168                                                     gpointer             data);
169 typedef void (* GtkFileSystemVolumeMountCallback) (GtkFileSystemHandle *handle,
170                                                    GtkFileSystemVolume *volume,
171                                                    const GError        *error,
172                                                    gpointer             data);
173
174 /*
175  */
176
177 struct _GtkFileSystemIface
178 {
179   GTypeInterface base_iface;
180
181   /* Methods
182    */
183   GSList *              (*list_volumes)        (GtkFileSystem     *file_system);
184   GtkFileSystemVolume * (*get_volume_for_path) (GtkFileSystem     *file_system,
185                                                 const GtkFilePath *path);
186
187   GtkFileSystemHandle * (*get_folder)  (GtkFileSystem                  *file_system,
188                                         const GtkFilePath              *path,
189                                         GtkFileInfoType                 types,
190                                         GtkFileSystemGetFolderCallback  callback,
191                                         gpointer                        data);
192   GtkFileSystemHandle * (*get_info) (GtkFileSystem                *file_system,
193                                      const GtkFilePath            *path,
194                                      GtkFileInfoType               types,
195                                      GtkFileSystemGetInfoCallback  callback,
196                                      gpointer                      data);
197   GtkFileSystemHandle * (*create_folder)  (GtkFileSystem                     *file_system,
198                                            const GtkFilePath                 *path,
199                                            GtkFileSystemCreateFolderCallback  callback,
200                                            gpointer                           data);
201
202   void               (*cancel_operation) (GtkFileSystemHandle *handle);
203
204   /* Volumes
205    */
206   void          (*volume_free)             (GtkFileSystem        *file_system,
207                                             GtkFileSystemVolume  *volume);
208   GtkFilePath * (*volume_get_base_path)    (GtkFileSystem        *file_system,
209                                             GtkFileSystemVolume  *volume);
210   gboolean      (*volume_get_is_mounted)   (GtkFileSystem        *file_system,
211                                             GtkFileSystemVolume  *volume);
212   GtkFileSystemHandle * (*volume_mount)    (GtkFileSystem                    *file_system,
213                                             GtkFileSystemVolume              *volume,
214                                             GtkFileSystemVolumeMountCallback  callback,
215                                             gpointer                          data);
216   char *        (*volume_get_display_name) (GtkFileSystem        *file_system,
217                                             GtkFileSystemVolume  *volume);
218   gchar *       (*volume_get_icon_name)    (GtkFileSystem        *file_system,
219                                             GtkFileSystemVolume  *volume,
220                                             GError              **error);
221
222   /* Path Manipulation
223    */
224   gboolean      (*get_parent)      (GtkFileSystem      *file_system,
225                                     const GtkFilePath  *path,
226                                     GtkFilePath       **parent,
227                                     GError            **error);
228   GtkFilePath * (*make_path)        (GtkFileSystem     *file_system,
229                                      const GtkFilePath *base_path,
230                                      const gchar       *display_name,
231                                      GError           **error);
232   gboolean      (*parse)            (GtkFileSystem     *file_system,
233                                      const GtkFilePath *base_path,
234                                      const gchar       *str,
235                                      GtkFilePath      **folder,
236                                      gchar            **file_part,
237                                      GError           **error);
238   gchar *      (*path_to_uri)      (GtkFileSystem      *file_system,
239                                     const GtkFilePath  *path);
240   gchar *      (*path_to_filename) (GtkFileSystem      *file_system,
241                                     const GtkFilePath  *path);
242   GtkFilePath *(*uri_to_path)      (GtkFileSystem      *file_system,
243                                     const gchar        *uri);
244   GtkFilePath *(*filename_to_path) (GtkFileSystem      *file_system,
245                                     const gchar        *path);
246
247   /* Bookmarks 
248    */
249   gboolean       (*insert_bookmark)        (GtkFileSystem     *file_system,
250                                             const GtkFilePath *path,
251                                             gint               position,
252                                             GError           **error);
253   gboolean       (*remove_bookmark)        (GtkFileSystem     *file_system,
254                                             const GtkFilePath *path,
255                                             GError           **error);
256   GSList *       (*list_bookmarks)         (GtkFileSystem     *file_system);
257
258   /* Signals 
259    */
260   void (*volumes_changed)   (GtkFileSystem *file_system);
261   void (*bookmarks_changed) (GtkFileSystem *file_system);
262
263   /* Bookmark labels 
264    */
265   gchar *        (*get_bookmark_label)     (GtkFileSystem     *file_system,
266                                             const GtkFilePath *path);
267   void           (*set_bookmark_label)     (GtkFileSystem     *file_system,
268                                             const GtkFilePath *path,
269                                             const gchar       *label);
270 };
271
272 GType             gtk_file_system_get_type       (void) G_GNUC_CONST;
273
274 GSList *          gtk_file_system_list_volumes   (GtkFileSystem     *file_system);
275
276 GtkFileSystemVolume *gtk_file_system_get_volume_for_path (GtkFileSystem     *file_system,
277                                                           const GtkFilePath *path);
278
279 void              gtk_file_system_volume_free             (GtkFileSystem        *file_system,
280                                                            GtkFileSystemVolume  *volume);
281 GtkFilePath *     gtk_file_system_volume_get_base_path    (GtkFileSystem        *file_system,
282                                                            GtkFileSystemVolume  *volume);
283 gboolean          gtk_file_system_volume_get_is_mounted   (GtkFileSystem        *file_system,
284                                                            GtkFileSystemVolume  *volume);
285 GtkFileSystemHandle *gtk_file_system_volume_mount         (GtkFileSystem                    *file_system,
286                                                            GtkFileSystemVolume              *volume,
287                                                            GtkFileSystemVolumeMountCallback  callback,
288                                                            gpointer                          data);
289 char *            gtk_file_system_volume_get_display_name (GtkFileSystem        *file_system, 
290                                                            GtkFileSystemVolume  *volume);
291 GdkPixbuf *       gtk_file_system_volume_render_icon      (GtkFileSystem        *file_system,
292                                                            GtkFileSystemVolume  *volume,
293                                                            GtkWidget            *widget,
294                                                            gint                  pixel_size,
295                                                            GError              **error);
296 gchar *           gtk_file_system_volume_get_icon_name    (GtkFileSystem        *file_system,
297                                                            GtkFileSystemVolume  *volume,
298                                                            GError              **error);
299
300 gboolean          gtk_file_system_get_parent     (GtkFileSystem     *file_system,
301                                                   const GtkFilePath *path,
302                                                   GtkFilePath      **parent,
303                                                   GError           **error);
304 GtkFileSystemHandle *gtk_file_system_get_folder  (GtkFileSystem                  *file_system,
305                                                   const GtkFilePath              *path,
306                                                   GtkFileInfoType                 types,
307                                                   GtkFileSystemGetFolderCallback  callback,
308                                                   gpointer                        data);
309 GtkFileSystemHandle *gtk_file_system_get_info    (GtkFileSystem                  *file_system,
310                                                   const GtkFilePath              *path,
311                                                   GtkFileInfoType                 types,
312                                                   GtkFileSystemGetInfoCallback    callback,
313                                                   gpointer                        data);
314 GtkFileSystemHandle *gtk_file_system_create_folder (GtkFileSystem                     *file_system,
315                                                     const GtkFilePath                 *path,
316                                                     GtkFileSystemCreateFolderCallback  callback,
317                                                     gpointer                           data);
318 void              gtk_file_system_cancel_operation (GtkFileSystemHandle *handle);
319 GtkFilePath *     gtk_file_system_make_path      (GtkFileSystem     *file_system,
320                                                   const GtkFilePath *base_path,
321                                                   const gchar       *display_name,
322                                                   GError           **error);
323 gboolean          gtk_file_system_parse          (GtkFileSystem     *file_system,
324                                                   const GtkFilePath *base_path,
325                                                   const gchar       *str,
326                                                   GtkFilePath      **folder,
327                                                   gchar            **file_part,
328                                                   GError           **error);
329
330 gchar *      gtk_file_system_path_to_uri      (GtkFileSystem     *file_system,
331                                                const GtkFilePath *path);
332 gchar *      gtk_file_system_path_to_filename (GtkFileSystem     *file_system,
333                                                const GtkFilePath *path);
334 GtkFilePath *gtk_file_system_uri_to_path      (GtkFileSystem     *file_system,
335                                                const gchar       *uri);
336 GtkFilePath *gtk_file_system_filename_to_path (GtkFileSystem     *file_system,
337                                                const gchar       *filename);
338
339 gboolean     gtk_file_system_path_is_local    (GtkFileSystem     *filesystem,
340                                                const GtkFilePath *path);
341
342 gboolean gtk_file_system_insert_bookmark (GtkFileSystem     *file_system,
343                                           const GtkFilePath *path,
344                                           gint               position,
345                                           GError           **error);
346 gboolean gtk_file_system_remove_bookmark (GtkFileSystem     *file_system,
347                                           const GtkFilePath *path,
348                                           GError           **error);
349 GSList  *gtk_file_system_list_bookmarks  (GtkFileSystem     *file_system);
350
351 gchar   *gtk_file_system_get_bookmark_label (GtkFileSystem     *file_system,
352                                              const GtkFilePath *path);
353 void     gtk_file_system_set_bookmark_label (GtkFileSystem     *file_system,
354                                              const GtkFilePath *path,
355                                              const gchar       *label);
356
357 /*
358  * Detailed information about a particular folder
359  */
360 #define GTK_TYPE_FILE_FOLDER             (gtk_file_folder_get_type ())
361 #define GTK_FILE_FOLDER(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FILE_FOLDER, GtkFileFolder))
362 #define GTK_IS_FILE_FOLDER(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FILE_FOLDER))
363 #define GTK_FILE_FOLDER_GET_IFACE(inst)  (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GTK_TYPE_FILE_FOLDER, GtkFileFolderIface))
364
365 struct _GtkFileFolderIface
366 {
367   GTypeInterface base_iface;
368
369   /* Methods
370    */
371   GtkFileInfo *      (*get_info)       (GtkFileFolder     *folder,
372                                         const GtkFilePath *path,
373                                         GError           **error);
374   gboolean           (*list_children)  (GtkFileFolder     *folder,
375                                         GSList           **children,
376                                         GError           **error);
377
378   /* ??? refresh() ??? */
379
380   /* Signals
381    */
382   void (*deleted)       (GtkFileFolder *monitor);
383   void (*files_added)   (GtkFileFolder *monitor,
384                          GSList        *paths);
385   void (*files_changed) (GtkFileFolder *monitor,
386                          GSList        *paths);
387   void (*files_removed) (GtkFileFolder *monitor,
388                          GSList        *paths);
389
390   /* Method / signal */
391   gboolean (*is_finished_loading) (GtkFileFolder *folder);
392   void     (*finished_loading)    (GtkFileFolder *folder);
393 };
394
395 GType        gtk_file_folder_get_type      (void) G_GNUC_CONST;
396 gboolean     gtk_file_folder_list_children (GtkFileFolder      *folder,
397                                             GSList            **children,
398                                             GError            **error);
399 GtkFileInfo *gtk_file_folder_get_info      (GtkFileFolder      *folder,
400                                             const GtkFilePath  *path,
401                                             GError            **error);
402
403 gboolean     gtk_file_folder_is_finished_loading (GtkFileFolder *folder);
404
405
406 /* GtkFilePath */
407 #define GTK_TYPE_FILE_PATH             (gtk_file_path_get_type ())
408
409 GType   gtk_file_path_get_type (void) G_GNUC_CONST;
410 #ifdef __GNUC__
411 #define gtk_file_path_new_dup(str) \
412  ({ const gchar *__s = (str); (GtkFilePath *)g_strdup(__s); })
413 #define gtk_file_path_new_steal(str) \
414  ({ gchar *__s = (str); (GtkFilePath *)__s; })
415 #define gtk_file_path_get_string(path) \
416  ({ const GtkFilePath *__p = (path); (const gchar *)__p; })
417 #define gtk_file_path_free(path) \
418  ({ GtkFilePath *__p = (path); g_free (__p); })
419 #else /* __GNUC__ */
420 #define gtk_file_path_new_dup(str)     ((GtkFilePath *)g_strdup(str))
421 #define gtk_file_path_new_steal(str)   ((GtkFilePath *)(str))
422 #define gtk_file_path_get_string(str) ((const gchar *)(str))
423 #define gtk_file_path_free(path)       g_free (path)
424 #endif/* __GNUC__ */
425
426 #define gtk_file_path_copy(path)       gtk_file_path_new_dup (gtk_file_path_get_string(path))
427 #ifdef G_OS_WIN32
428 int _gtk_file_system_win32_path_compare (const gchar *path1,
429                                          const gchar *path2);
430 #define gtk_file_path_compare(path1,path2) \
431   _gtk_file_system_win32_path_compare (gtk_file_path_get_string (path1), \
432                                        gtk_file_path_get_string (path2))
433 #else
434 #define gtk_file_path_compare(path1,path2) strcmp (gtk_file_path_get_string (path1), \
435                                                    gtk_file_path_get_string (path2))
436 #endif
437
438 GSList *gtk_file_paths_sort (GSList *paths);
439 GSList *gtk_file_paths_copy (GSList *paths);
440 void    gtk_file_paths_free (GSList *paths);
441
442 /* GtkFileSystem modules support */
443
444 GtkFileSystem  *gtk_file_system_create (const char *file_system_name);
445
446 G_END_DECLS
447
448 #endif /* __GTK_FILE_SYSTEM_H__ */