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