]> Pileus Git - ~andy/gtk/blob - gtk/gtkfilesystem.h
New get_volume_for_path() method. (struct _GtkFileSystemIface): Finally
[~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   GtkFileSystemVolume * (*get_volume_for_path) (GtkFileSystem     *file_system,
149                                                 const GtkFilePath *path);
150
151   GtkFileFolder *    (*get_folder)     (GtkFileSystem     *file_system,
152                                         const GtkFilePath *path,
153                                         GtkFileInfoType    types,
154                                         GError           **error);
155   gboolean           (*create_folder)  (GtkFileSystem     *file_system,
156                                         const GtkFilePath *path,
157                                         GError           **error);
158
159   /* Volumes
160    */
161
162   void          (*volume_free)             (GtkFileSystem        *file_system,
163                                             GtkFileSystemVolume  *volume);
164   GtkFilePath * (*volume_get_base_path)    (GtkFileSystem        *file_system,
165                                             GtkFileSystemVolume  *volume);
166   gboolean      (*volume_get_is_mounted)   (GtkFileSystem        *file_system,
167                                             GtkFileSystemVolume  *volume);
168   gboolean      (*volume_mount)            (GtkFileSystem        *file_system, 
169                                             GtkFileSystemVolume  *volume,
170                                             GError              **error);
171   char *        (*volume_get_display_name) (GtkFileSystem        *file_system, 
172                                             GtkFileSystemVolume  *volume);
173   GdkPixbuf *   (*volume_render_icon)      (GtkFileSystem        *file_system,
174                                             GtkFileSystemVolume  *volume,
175                                             GtkWidget            *widget,
176                                             gint                  pixel_size,
177                                             GError              **error);
178
179   /* Path Manipulation
180    */
181   gboolean      (*get_parent)      (GtkFileSystem      *file_system,
182                                     const GtkFilePath  *path,
183                                     GtkFilePath       **parent,
184                                     GError            **error);
185   GtkFilePath * (*make_path)        (GtkFileSystem     *file_system,
186                                      const GtkFilePath *base_path,
187                                      const gchar       *display_name,
188                                      GError           **error);
189   gboolean      (*parse)            (GtkFileSystem     *file_system,
190                                      const GtkFilePath *base_path,
191                                      const gchar       *str,
192                                      GtkFilePath      **folder,
193                                      gchar            **file_part,
194                                      GError           **error);
195   gchar *      (*path_to_uri)      (GtkFileSystem      *file_system,
196                                     const GtkFilePath  *path);
197   gchar *      (*path_to_filename) (GtkFileSystem      *file_system,
198                                     const GtkFilePath  *path);
199   GtkFilePath *(*uri_to_path)      (GtkFileSystem      *file_system,
200                                     const gchar        *uri);
201   GtkFilePath *(*filename_to_path) (GtkFileSystem      *file_system,
202                                     const gchar        *path);
203
204   /* Icons */
205
206   GdkPixbuf *  (*render_icon)    (GtkFileSystem     *file_system,
207                                   const GtkFilePath *path,
208                                   GtkWidget         *widget,
209                                   gint               pixel_size,
210                                   GError           **error);
211
212   /* Bookmarks */
213
214   gboolean       (*add_bookmark)           (GtkFileSystem     *file_system,
215                                             const GtkFilePath *path,
216                                             GError           **error);
217   gboolean       (*remove_bookmark)        (GtkFileSystem     *file_system,
218                                             const GtkFilePath *path,
219                                             GError           **error);
220   GSList *       (*list_bookmarks)         (GtkFileSystem *file_system);
221
222   /* Signals
223    */
224   void (*volumes_changed)   (GtkFileSystem *file_system);
225   void (*bookmarks_changed) (GtkFileSystem *file_system);
226 };
227
228 GType             gtk_file_system_get_type       (void);
229
230 GSList *          gtk_file_system_list_volumes   (GtkFileSystem     *file_system);
231
232 GtkFileSystemVolume *gtk_file_system_get_volume_for_path (GtkFileSystem     *file_system,
233                                                           const GtkFilePath *path);
234
235 void              gtk_file_system_volume_free             (GtkFileSystem        *file_system,
236                                                            GtkFileSystemVolume  *volume);
237 GtkFilePath *     gtk_file_system_volume_get_base_path    (GtkFileSystem        *file_system,
238                                                            GtkFileSystemVolume  *volume);
239 gboolean          gtk_file_system_volume_get_is_mounted   (GtkFileSystem        *file_system,
240                                                            GtkFileSystemVolume  *volume);
241 gboolean          gtk_file_system_volume_mount            (GtkFileSystem        *file_system, 
242                                                            GtkFileSystemVolume  *volume,
243                                                            GError              **error);
244 char *            gtk_file_system_volume_get_display_name (GtkFileSystem        *file_system, 
245                                                            GtkFileSystemVolume  *volume);
246 GdkPixbuf *       gtk_file_system_volume_render_icon      (GtkFileSystem        *file_system,
247                                                            GtkFileSystemVolume  *volume,
248                                                            GtkWidget            *widget,
249                                                            gint                  pixel_size,
250                                                            GError              **error);
251
252 gboolean          gtk_file_system_get_parent     (GtkFileSystem     *file_system,
253                                                   const GtkFilePath *path,
254                                                   GtkFilePath      **parent,
255                                                   GError           **error);
256 GtkFileFolder    *gtk_file_system_get_folder     (GtkFileSystem     *file_system,
257                                                   const GtkFilePath *path,
258                                                   GtkFileInfoType    types,
259                                                   GError           **error);
260 gboolean          gtk_file_system_create_folder  (GtkFileSystem     *file_system,
261                                                   const GtkFilePath *path,
262                                                   GError           **error);
263 GtkFilePath *     gtk_file_system_make_path      (GtkFileSystem     *file_system,
264                                                   const GtkFilePath *base_path,
265                                                   const gchar       *display_name,
266                                                   GError           **error);
267 gboolean          gtk_file_system_parse          (GtkFileSystem     *file_system,
268                                                   const GtkFilePath *base_path,
269                                                   const gchar       *str,
270                                                   GtkFilePath      **folder,
271                                                   gchar            **file_part,
272                                                   GError           **error);
273
274 gchar *      gtk_file_system_path_to_uri      (GtkFileSystem     *file_system,
275                                                const GtkFilePath *path);
276 gchar *      gtk_file_system_path_to_filename (GtkFileSystem     *file_system,
277                                                const GtkFilePath *path);
278 GtkFilePath *gtk_file_system_uri_to_path      (GtkFileSystem     *file_system,
279                                                const gchar       *uri);
280 GtkFilePath *gtk_file_system_filename_to_path (GtkFileSystem     *file_system,
281                                                const gchar       *filename);
282
283 GdkPixbuf   *gtk_file_system_render_icon   (GtkFileSystem      *file_system,
284                                             const GtkFilePath  *path,
285                                             GtkWidget          *widget,
286                                             gint                pixel_size,
287                                             GError            **error);
288
289 gboolean gtk_file_system_add_bookmark    (GtkFileSystem     *file_system,
290                                           const GtkFilePath *path,
291                                           GError           **error);
292 gboolean gtk_file_system_remove_bookmark (GtkFileSystem     *file_system,
293                                           const GtkFilePath *path,
294                                           GError           **error);
295 GSList  *gtk_file_system_list_bookmarks  (GtkFileSystem     *file_system);
296
297
298 /*
299  * Detailed information about a particular folder
300  */
301 #define GTK_TYPE_FILE_FOLDER             (gtk_file_folder_get_type ())
302 #define GTK_FILE_FOLDER(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FILE_FOLDER, GtkFileFolder))
303 #define GTK_IS_FILE_FOLDER(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FILE_FOLDER))
304 #define GTK_FILE_FOLDER_GET_IFACE(inst)  (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GTK_TYPE_FILE_FOLDER, GtkFileFolderIface))
305
306 struct _GtkFileFolderIface
307 {
308   GTypeInterface base_iface;
309
310   /* Methods
311    */
312   GtkFileInfo *      (*get_info)       (GtkFileFolder     *folder,
313                                         const GtkFilePath *path,
314                                         GError           **error);
315   gboolean           (*list_children)  (GtkFileFolder     *folder,
316                                         GSList           **children,
317                                         GError           **error);
318
319   /* ??? refresh() ??? */
320
321   /* Signals
322    */
323   void (*deleted)       (GtkFileFolder *monitor);
324   void (*files_added)   (GtkFileFolder *monitor,
325                          GSList        *paths);
326   void (*files_changed) (GtkFileFolder *monitor,
327                          GSList        *paths);
328   void (*files_removed) (GtkFileFolder *monitor,
329                          GSList        *paths);
330 };
331
332 GType        gtk_file_folder_get_type      (void);
333 gboolean     gtk_file_folder_list_children (GtkFileFolder      *folder,
334                                             GSList            **children,
335                                             GError            **error);
336 GtkFileInfo *gtk_file_folder_get_info      (GtkFileFolder      *folder,
337                                             const GtkFilePath  *path,
338                                             GError            **error);
339
340 #ifdef __GNUC__
341 #define gtk_file_path_new_dup(str) \
342  ({ const gchar *__s = (str); (GtkFilePath *)g_strdup(__s); })
343 #define gtk_file_path_new_steal(str) \
344  ({ gchar *__s = (str); (GtkFilePath *)__s; })
345 #define gtk_file_path_get_string(path) \
346  ({ const GtkFilePath *__p = (path); (const gchar *)__p; })
347 #define gtk_file_path_free(path) \
348  ({ GtkFilePath *__p = (path); g_free (__p); })
349 #else /* __GNUC__ */
350 #define gtk_file_path_new_dup(str)     ((GtkFilePath *)g_strdup(str))
351 #define gtk_file_path_new_steal(str)   ((GtkFilePath *)(str))
352 #define gtk_file_path_get_string(str) ((const gchar *)(str))
353 #define gtk_file_path_free(path)       g_free (path)
354 #endif/* __GNUC__ */
355
356 #define gtk_file_path_copy(path)       gtk_file_path_new_dup (gtk_file_path_get_string(path))
357 #define gtk_file_path_compare(path1,path2) strcmp (gtk_file_path_get_string (path1), \
358                                                    gtk_file_path_get_string (path2))
359
360 GSList *gtk_file_paths_sort (GSList *paths);
361 GSList *gtk_file_paths_copy (GSList *paths);
362 void    gtk_file_paths_free (GSList *paths);
363
364 G_END_DECLS
365
366 #endif /* __GTK_FILE_SYSTEM_H__ */