]> Pileus Git - ~andy/gtk/blob - gtk/gtkfilesystem.h
8eefad487b3d8858a506414c8ee06a96540f4ffe
[~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 #include <glib-object.h>
25 #include <gtk/gtkwidget.h>      /* For icon handling */
26
27 G_BEGIN_DECLS
28
29 typedef gint64 GtkFileTime;
30
31 typedef struct _GtkFileFolder      GtkFileFolder;
32 typedef struct _GtkFileFolderIface GtkFileFolderIface;
33 typedef struct _GtkFileInfo        GtkFileInfo;
34 typedef struct _GtkFileSystem      GtkFileSystem;
35 typedef struct _GtkFileSystemIface GtkFileSystemIface;
36
37 typedef struct _GtkFilePath        GtkFilePath;
38
39 /* Mask of information about a file, for monitoring and
40  * gtk_file_system_get_info()
41  */
42 typedef enum {
43   GTK_FILE_INFO_DISPLAY_NAME      = 1 << 0,
44   GTK_FILE_INFO_IS_FOLDER         = 1 << 1,
45   GTK_FILE_INFO_IS_HIDDEN         = 1 << 2,
46   GTK_FILE_INFO_MIME_TYPE         = 1 << 3,
47   GTK_FILE_INFO_MODIFICATION_TIME = 1 << 4,
48   GTK_FILE_INFO_SIZE              = 1 << 5,
49   GTK_FILE_INFO_ICON              = 1 << 6,
50   GTK_FILE_INFO_ALL               = (1 << 7) - 1
51 } GtkFileInfoType;
52
53 /* Icon type, supplemented by MIME type
54  */
55 typedef enum {
56   GTK_FILE_ICON_REGULAR,        /* Use mime type for icon */
57   GTK_FILE_ICON_BLOCK_DEVICE,
58   GTK_FILE_ICON_BROKEN_SYMBOLIC_LINK,
59   GTK_FILE_ICON_CHARACTER_DEVICE,
60   GTK_FILE_ICON_DIRECTORY,
61   GTK_FILE_ICON_EXECUTABLE,
62   GTK_FILE_ICON_FIFO,
63   GTK_FILE_ICON_SOCKET
64 } GtkFileIconType;
65
66 /* GError enumeration for GtkFileSystem
67  */
68
69 #define GTK_FILE_SYSTEM_ERROR (gtk_file_system_error_quark ())
70
71 typedef enum
72 {
73   GTK_FILE_SYSTEM_ERROR_NONEXISTENT,
74   GTK_FILE_SYSTEM_ERROR_NOT_FOLDER,
75   GTK_FILE_SYSTEM_ERROR_INVALID_URI,
76   GTK_FILE_SYSTEM_ERROR_BAD_FILENAME,
77   GTK_FILE_SYSTEM_ERROR_FAILED,
78 } GtkFileSystemError;
79
80 GQuark     gtk_file_system_error_quark      (void);
81
82 /* Boxed-type for gtk_file_folder_get_info() results
83  */
84 #define GTK_TYPE_FILE_INFO (gtk_file_info_get_type ())
85
86 GType       gtk_file_info_get_type (void);
87
88 GtkFileInfo *gtk_file_info_new  (void);
89 GtkFileInfo *gtk_file_info_copy (GtkFileInfo *info);
90 void         gtk_file_info_free (GtkFileInfo *info);
91
92
93 G_CONST_RETURN gchar *gtk_file_info_get_display_name      (const GtkFileInfo *info);
94 G_CONST_RETURN gchar *gtk_file_info_get_display_key       (const GtkFileInfo *info);
95 void                  gtk_file_info_set_display_name      (GtkFileInfo       *info,
96                                                            const gchar       *display_name);
97 gboolean              gtk_file_info_get_is_folder         (const GtkFileInfo *info);
98 void                  gtk_file_info_set_is_folder         (GtkFileInfo       *info,
99                                                            gboolean           is_folder);
100 gboolean              gtk_file_info_get_is_hidden         (const GtkFileInfo *info);
101 void                  gtk_file_info_set_is_hidden         (GtkFileInfo       *info,
102                                                            gboolean           is_hidden);
103 G_CONST_RETURN gchar *gtk_file_info_get_mime_type         (const GtkFileInfo *info);
104 void                  gtk_file_info_set_mime_type         (GtkFileInfo       *info,
105                                                            const gchar       *mime_type);
106 GtkFileTime           gtk_file_info_get_modification_time (const GtkFileInfo *info);
107 void                  gtk_file_info_set_modification_time (GtkFileInfo       *info,
108                                                            GtkFileTime        modification_time);
109 gint64                gtk_file_info_get_size              (const GtkFileInfo *info);
110 void                  gtk_file_info_set_size              (GtkFileInfo       *info,
111                                                            gint64             size);
112 void                  gtk_file_info_set_icon_type         (GtkFileInfo       *info,
113                                                            GtkFileIconType    icon_type);
114 GtkFileIconType       gtk_file_info_get_icon_type         (const GtkFileInfo *info);
115 GdkPixbuf *           gtk_file_info_render_icon           (const GtkFileInfo *info,
116                                                            GtkWidget         *widget,
117                                                            gint               pixel_size);
118
119 /* The base GtkFileSystem interface
120  */
121 #define GTK_TYPE_FILE_SYSTEM             (gtk_file_system_get_type ())
122 #define GTK_FILE_SYSTEM(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FILE_SYSTEM, GtkFileSystem))
123 #define GTK_IS_FILE_SYSTEM(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FILE_SYSTEM))
124 #define GTK_FILE_SYSTEM_GET_IFACE(inst)  (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GTK_TYPE_FILE_SYSTEM, GtkFileSystemIface))
125
126 struct _GtkFileSystemIface
127 {
128   GTypeInterface base_iface;
129
130   /* Methods
131    */
132   GSList *           (*list_roots)     (GtkFileSystem     *file_system);
133
134   GtkFileInfo *      (*get_root_info)  (GtkFileSystem     *file_system,
135                                         const GtkFilePath *path,
136                                         GtkFileInfoType    types,
137                                         GError           **error);
138
139   GtkFileFolder *    (*get_folder)     (GtkFileSystem     *file_system,
140                                         const GtkFilePath *path,
141                                         GtkFileInfoType    types,
142                                         GError           **error);
143   gboolean           (*create_folder)  (GtkFileSystem     *file_system,
144                                         const GtkFilePath *path,
145                                         GError           **error);
146
147   gboolean           (*supports_shortcuts) (GtkFileSystem *file_system);
148   GSList *           (*list_shortcuts)     (GtkFileSystem *file_system,
149                                             GError       **error);
150   gboolean           (*set_shortcuts)      (GtkFileSystem *file_system,
151                                             GSList        *shortcuts,
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   /* Bookmarks */
180
181   gboolean       (*get_supports_bookmarks) (GtkFileSystem *file_system);
182   void           (*set_bookmarks)          (GtkFileSystem *file_system,
183                                             GSList        *bookmarks,
184                                             GError       **error);
185   GSList *       (*list_bookmarks)         (GtkFileSystem *file_system);
186
187   /* Signals
188    */
189   void (*roots_changed)     (GtkFileSystem *file_system);
190   void (*bookmarks_changed) (GtkFileSystem *file_system);
191 };
192
193 GType             gtk_file_system_get_type       (void);
194
195 GSList *          gtk_file_system_list_roots     (GtkFileSystem     *file_system);
196 GtkFileInfo *     gtk_file_system_get_root_info  (GtkFileSystem     *file_system,
197                                                   const GtkFilePath *path,
198                                                   GtkFileInfoType    types,
199                                                   GError           **error);
200
201 gboolean          gtk_file_system_supports_shortcuts (GtkFileSystem *file_system);
202 GSList *          gtk_file_system_list_shortcuts     (GtkFileSystem *file_system,
203                                                       GError       **error);
204 gboolean          gtk_file_system_set_shortcuts      (GtkFileSystem *file_system,
205                                                       GSList        *shortcuts,
206                                                       GError       **error);
207
208 gboolean          gtk_file_system_get_parent     (GtkFileSystem     *file_system,
209                                                   const GtkFilePath *path,
210                                                   GtkFilePath      **parent,
211                                                   GError           **error);
212 GtkFileFolder    *gtk_file_system_get_folder     (GtkFileSystem     *file_system,
213                                                   const GtkFilePath *path,
214                                                   GtkFileInfoType    types,
215                                                   GError           **error);
216 gboolean          gtk_file_system_create_folder  (GtkFileSystem     *file_system,
217                                                   const GtkFilePath *path,
218                                                   GError           **error);
219 GtkFilePath *     gtk_file_system_make_path      (GtkFileSystem     *file_system,
220                                                   const GtkFilePath *base_path,
221                                                   const gchar       *display_name,
222                                                   GError           **error);
223 gboolean          gtk_file_system_parse          (GtkFileSystem     *file_system,
224                                                   const GtkFilePath *base_path,
225                                                   const gchar       *str,
226                                                   GtkFilePath      **folder,
227                                                   gchar            **file_part,
228                                                   GError           **error);
229
230 gchar *      gtk_file_system_path_to_uri      (GtkFileSystem     *file_system,
231                                                const GtkFilePath *path);
232 gchar *      gtk_file_system_path_to_filename (GtkFileSystem     *file_system,
233                                                const GtkFilePath *path);
234 GtkFilePath *gtk_file_system_uri_to_path      (GtkFileSystem     *file_system,
235                                                const gchar       *uri);
236 GtkFilePath *gtk_file_system_filename_to_path (GtkFileSystem     *file_system,
237                                                const gchar       *filename);
238
239 gboolean gtk_file_system_get_supports_bookmarks (GtkFileSystem *file_system);
240
241 void    gtk_file_system_set_bookmarks  (GtkFileSystem *file_system,
242                                         GSList        *bookmarks,
243                                         GError       **error);
244 GSList *gtk_file_system_list_bookmarks (GtkFileSystem *file_system);
245
246
247 /*
248  * Detailed information about a particular folder
249  */
250 #define GTK_TYPE_FILE_FOLDER             (gtk_file_folder_get_type ())
251 #define GTK_FILE_FOLDER(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FILE_FOLDER, GtkFileFolder))
252 #define GTK_IS_FILE_FOLDER(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FILE_FOLDER))
253 #define GTK_FILE_FOLDER_GET_IFACE(inst)  (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GTK_TYPE_FILE_FOLDER, GtkFileFolderIface))
254
255 struct _GtkFileFolderIface
256 {
257   GTypeInterface base_iface;
258
259   /* Methods
260    */
261   GtkFileInfo *      (*get_info)       (GtkFileFolder     *folder,
262                                         const GtkFilePath *path,
263                                         GError           **error);
264   gboolean           (*list_children)  (GtkFileFolder     *folder,
265                                         GSList           **children,
266                                         GError           **error);
267
268   /* ??? refresh() ??? */
269
270   /* Signals
271    */
272   void (*deleted)       (GtkFileFolder *monitor);
273   void (*files_added)   (GtkFileFolder *monitor,
274                          GSList        *paths);
275   void (*files_changed) (GtkFileFolder *monitor,
276                          GSList        *paths);
277   void (*files_removed) (GtkFileFolder *monitor,
278                          GSList        *paths);
279 };
280
281 GType        gtk_file_folder_get_type      (void);
282 gboolean     gtk_file_folder_list_children (GtkFileFolder      *folder,
283                                             GSList            **children,
284                                             GError            **error);
285 GtkFileInfo *gtk_file_folder_get_info      (GtkFileFolder      *folder,
286                                             const GtkFilePath  *path,
287                                             GError            **error);
288
289 #ifdef __GNUC__
290 #define gtk_file_path_new_dup(str) \
291  ({ const gchar *__s = (str); (GtkFilePath *)g_strdup(__s); })
292 #define gtk_file_path_new_steal(str) \
293  ({ gchar *__s = (str); (GtkFilePath *)__s; })
294 #define gtk_file_path_get_string(path) \
295  ({ const GtkFilePath *__p = (path); (const gchar *)__p; })
296 #define gtk_file_path_free(path) \
297  ({ GtkFilePath *__p = (path); g_free (__p); })
298 #else /* __GNUC__ */
299 #define gtk_file_path_new_dup(str)     ((GtkFilePath *)g_strdup(str))
300 #define gtk_file_path_new_steal(str)   ((GtkFilePath *)(str))
301 #define gtk_file_path_get_string(path) ((const gchar *)(str))
302 #define gtk_file_path_free(path)       g_free (path)
303 #endif/* __GNUC__ */
304
305 #define gtk_file_path_copy(path)       gtk_file_path_new_dup (gtk_file_path_get_string(path))
306 #define gtk_file_path_compare(path1,path2) strcmp (gtk_file_path_get_string (path1), \
307                                                    gtk_file_path_get_string (path2))
308
309 GSList *gtk_file_paths_sort (GSList *paths);
310 GSList *gtk_file_paths_copy (GSList *paths);
311 void    gtk_file_paths_free (GSList *paths);
312
313 G_END_DECLS
314
315 #endif /* __GTK_FILE_SYSTEM_H__ */