]> Pileus Git - ~andy/gtk/blob - gtk/gtkfilesystem.h
Move interface definition into a private header so it can refer to
[~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 <gdk-pixbuf/gdk-pixbuf.h>
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 } GtkFileInfoType;
51
52 /* GError enumeration for GtkFileSystem
53  */
54
55 #define GTK_FILE_SYSTEM_ERROR (gtk_file_system_error_quark ())
56
57 typedef enum
58 {
59   GTK_FILE_SYSTEM_ERROR_NONEXISTANT,
60   GTK_FILE_SYSTEM_ERROR_NOT_FOLDER,
61   GTK_FILE_SYSTEM_ERROR_INVALID_URI,
62   GTK_FILE_SYSTEM_ERROR_BAD_FILENAME,
63   GTK_FILE_SYSTEM_ERROR_FAILED,
64 } GtkFileSystemError;
65
66 GQuark     gtk_file_system_error_quark      (void);
67
68 /* Boxed-type for gtk_file_folder_get_info() results
69  */
70 #define GTK_TYPE_FILE_INFO (gtk_file_info_get_type ())
71
72 GType       gtk_file_info_get_type (void);
73
74 GtkFileInfo *gtk_file_info_new  (void);
75 GtkFileInfo *gtk_file_info_copy (GtkFileInfo *info);
76 void         gtk_file_info_free (GtkFileInfo *info);
77
78
79 G_CONST_RETURN gchar *gtk_file_info_get_display_name      (const GtkFileInfo *info);
80 G_CONST_RETURN gchar *gtk_file_info_get_display_key       (const GtkFileInfo *info);
81 void                  gtk_file_info_set_display_name      (GtkFileInfo       *info,
82                                                            const gchar       *display_name);
83 gboolean              gtk_file_info_get_is_folder         (const GtkFileInfo *info);
84 void                  gtk_file_info_set_is_folder         (GtkFileInfo       *info,
85                                                            gboolean           is_folder);
86 gboolean              gtk_file_info_get_is_hidden         (const GtkFileInfo *info);
87 void                  gtk_file_info_set_is_hidden         (GtkFileInfo       *info,
88                                                            gboolean           is_hidden);
89 G_CONST_RETURN gchar *gtk_file_info_get_mime_type         (const GtkFileInfo *info);
90 void                  gtk_file_info_set_mime_type         (GtkFileInfo       *info,
91                                                            const gchar       *mime_type);
92 GtkFileTime           gtk_file_info_get_modification_time (const GtkFileInfo *info);
93 void                  gtk_file_info_set_modification_time (GtkFileInfo       *info,
94                                                            GtkFileTime        modification_time);
95 gint64                gtk_file_info_get_size              (const GtkFileInfo *info);
96 void                  gtk_file_info_set_size              (GtkFileInfo       *info,
97                                                            gint64             size);
98 GdkPixbuf *           gtk_file_info_get_icon              (const GtkFileInfo *info);
99 void                  gtk_file_info_set_icon              (GtkFileInfo       *info,
100                                                            GdkPixbuf         *icon);
101
102 /* The base GtkFileSystem interface
103  */
104 #define GTK_TYPE_FILE_SYSTEM             (gtk_file_system_get_type ())
105 #define GTK_FILE_SYSTEM(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FILE_SYSTEM, GtkFileSystem))
106 #define GTK_IS_FILE_SYSTEM(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FILE_SYSTEM))
107 #define GTK_FILE_SYSTEM_GET_IFACE(inst)  (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GTK_TYPE_FILE_SYSTEM, GtkFileSystemIface))
108
109 struct _GtkFileSystemIface
110 {
111   GTypeInterface base_iface;
112
113   /* Methods
114    */
115   GSList *           (*list_roots)     (GtkFileSystem     *file_system);
116
117   GtkFileInfo *      (*get_root_info)  (GtkFileSystem     *file_system,
118                                         const GtkFilePath *path,
119                                         GtkFileInfoType    types,
120                                         GError           **error);
121   
122   GtkFileFolder *    (*get_folder)     (GtkFileSystem     *file_system,
123                                         const GtkFilePath *path,
124                                         GtkFileInfoType    types,
125                                         GError           **error);
126   gboolean           (*create_folder)  (GtkFileSystem     *file_system,
127                                         const GtkFilePath *path,
128                                         GError           **error);
129
130   /* Path Manipulation
131    */
132   gboolean      (*get_parent)      (GtkFileSystem      *file_system,
133                                     const GtkFilePath  *path,
134                                     GtkFilePath       **parent,
135                                     GError            **error);
136   GtkFilePath * (*make_path)        (GtkFileSystem     *file_system,
137                                      const GtkFilePath *base_path,
138                                      const gchar       *display_name,
139                                      GError           **error);                                 
140   gboolean      (*parse)            (GtkFileSystem     *file_system,
141                                      const GtkFilePath *base_path,
142                                      const gchar       *str,
143                                      GtkFilePath      **folder,
144                                      gchar            **file_part,
145                                      GError           **error);
146   gchar *      (*path_to_uri)      (GtkFileSystem      *file_system,
147                                     const GtkFilePath  *path);
148   gchar *      (*path_to_filename) (GtkFileSystem      *file_system,
149                                     const GtkFilePath  *path);
150   GtkFilePath *(*uri_to_path)      (GtkFileSystem      *file_system,
151                                     const gchar        *uri);
152   GtkFilePath *(*filename_to_path) (GtkFileSystem      *file_system,
153                                     const gchar        *path);
154
155   /* Signals
156    */
157   void (*roots_changed) (GtkFileSystem *file_system);
158 };
159
160 GType             gtk_file_system_get_type       (void);
161
162 GSList *          gtk_file_system_list_roots     (GtkFileSystem     *file_system);
163 GtkFileInfo *     gtk_file_system_get_root_info  (GtkFileSystem     *file_system,
164                                                   const GtkFilePath *path,
165                                                   GtkFileInfoType    types,
166                                                   GError           **error);
167   
168 gboolean          gtk_file_system_get_parent     (GtkFileSystem     *file_system,
169                                                   const GtkFilePath *path,
170                                                   GtkFilePath      **parent,
171                                                   GError           **error);
172 GtkFileFolder    *gtk_file_system_get_folder     (GtkFileSystem     *file_system,
173                                                   const GtkFilePath *path,
174                                                   GtkFileInfoType    types,
175                                                   GError           **error);
176 gboolean          gtk_file_system_create_folder  (GtkFileSystem     *file_system,
177                                                   const GtkFilePath *path,
178                                                   GError           **error);
179 GtkFilePath *     gtk_file_system_make_path      (GtkFileSystem     *file_system,
180                                                   const GtkFilePath *base_path,
181                                                   const gchar       *display_name,
182                                                   GError           **error);
183 gboolean          gtk_file_system_parse          (GtkFileSystem     *file_system,
184                                                   const GtkFilePath *base_path,
185                                                   const gchar       *str,
186                                                   GtkFilePath      **folder,
187                                                   gchar            **file_part,
188                                                   GError           **error);
189
190 gchar *      gtk_file_system_path_to_uri      (GtkFileSystem     *file_system,
191                                                const GtkFilePath *path);
192 gchar *      gtk_file_system_path_to_filename (GtkFileSystem     *file_system,
193                                                const GtkFilePath *path);
194 GtkFilePath *gtk_file_system_uri_to_path      (GtkFileSystem     *file_system,
195                                                const gchar       *uri);
196 GtkFilePath *gtk_file_system_filename_to_path (GtkFileSystem     *file_system,
197                                                const gchar       *filename);
198
199 /*
200  * Detailed information about a particular folder
201  */
202 #define GTK_TYPE_FILE_FOLDER             (gtk_file_folder_get_type ())
203 #define GTK_FILE_FOLDER(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FILE_FOLDER, GtkFileFolder))
204 #define GTK_IS_FILE_FOLDER(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FILE_FOLDER))
205 #define GTK_FILE_FOLDER_GET_IFACE(inst)  (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GTK_TYPE_FILE_FOLDER, GtkFileFolderIface))
206
207 struct _GtkFileFolderIface
208 {
209   GTypeInterface base_iface;
210
211   /* Methods
212    */
213   GtkFileInfo *      (*get_info)       (GtkFileFolder     *folder,
214                                         const GtkFilePath *path,
215                                         GError           **error);
216   gboolean           (*list_children)  (GtkFileFolder     *folder,
217                                         GSList           **children,
218                                         GError           **error);
219
220   /* ??? refresh() ??? */
221
222   /* Signals
223    */
224   void (*deleted)       (GtkFileFolder *monitor);
225   void (*files_added)   (GtkFileFolder *monitor,
226                          GSList        *paths);
227   void (*files_changed) (GtkFileFolder *monitor,
228                          GSList        *paths);
229   void (*files_removed) (GtkFileFolder *monitor,
230                          GSList        *paths);
231 };
232
233 GType        gtk_file_folder_get_type      (void);
234 gboolean     gtk_file_folder_list_children (GtkFileFolder      *folder,
235                                             GSList            **children,
236                                             GError            **error);
237 GtkFileInfo *gtk_file_folder_get_info      (GtkFileFolder      *folder,
238                                             const GtkFilePath  *path,
239                                             GError            **error);
240
241 #ifdef __GNUC__
242 #define gtk_file_path_new_dup(str) \
243  ({ const gchar *__s = (str); (GtkFilePath *)g_strdup(__s); })
244 #define gtk_file_path_new_steal(str) \
245  ({ gchar *__s = (str); (GtkFilePath *)__s; })
246 #define gtk_file_path_get_string(path) \
247  ({ const GtkFilePath *__p = (path); (const gchar *)__p; })
248 #define gtk_file_path_free(path) \
249  ({ GtkFilePath *__p = (path); g_free (__p); })
250 #else /* __GNUC__ */
251 #define gtk_file_path_new_dup(str)     ((GtkFilePath *)g_strdup(str))
252 #define gtk_file_path_new_steal(str)   ((GtkFilePath *)(str))
253 #define gtk_file_path_get_string(path) ((const gchar *)(str))
254 #define gtk_file_path_free(path)       g_free (path)
255 #endif/* __GNUC__ */
256
257 #define gtk_file_path_copy(path)       gtk_file_path_new_dup (gtk_file_path_get_string(path))
258 #define gtk_file_path_compare(path1,path2) strcmp (gtk_file_path_get_string (path1), \
259                                                    gtk_file_path_get_string (path2))
260
261 GSList *gtk_file_paths_sort (GSList *paths);
262 void    gtk_file_paths_free (GSList *paths);
263
264 G_END_DECLS
265
266 #endif /* __GTK_FILE_SYSTEM_H__ */