gtkfilesystem.h 18.2 KB
Newer Older
Owen Taylor's avatar
Owen Taylor committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/* GTK - The GIMP Toolkit
 * gtkfilesystem.h: Abstract file system interfaces
 * Copyright (C) 2003, Red Hat, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifndef __GTK_FILE_SYSTEM_H__
#define __GTK_FILE_SYSTEM_H__

24 25 26 27 28 29 30 31
/* This is a "semi-private" header; it is meant only for
 * alternate GtkFileChooser backend modules; no stability guarantees 
 * are made at this point
 */
#ifndef GTK_FILE_SYSTEM_ENABLE_UNSUPPORTED
#error "GtkFileSystem is not supported API for general use"
#endif

Owen Taylor's avatar
Owen Taylor committed
32
#include <glib-object.h>
Owen Taylor's avatar
Owen Taylor committed
33
#include <gtk/gtkwidget.h>	/* For icon handling */
Owen Taylor's avatar
Owen Taylor committed
34 35 36 37 38

G_BEGIN_DECLS

typedef gint64 GtkFileTime;

39 40 41 42 43 44
typedef struct _GtkFileFolder       GtkFileFolder;
typedef struct _GtkFileFolderIface  GtkFileFolderIface;
typedef struct _GtkFileInfo         GtkFileInfo;
typedef struct _GtkFileSystem       GtkFileSystem;
typedef struct _GtkFileSystemIface  GtkFileSystemIface;
typedef struct _GtkFileSystemVolume GtkFileSystemVolume;
Owen Taylor's avatar
Owen Taylor committed
45

46 47
typedef struct _GtkFilePath        GtkFilePath;

Owen Taylor's avatar
Owen Taylor committed
48 49 50 51 52 53 54 55 56 57
/* Mask of information about a file, for monitoring and
 * gtk_file_system_get_info()
 */
typedef enum {
  GTK_FILE_INFO_DISPLAY_NAME      = 1 << 0,
  GTK_FILE_INFO_IS_FOLDER         = 1 << 1,
  GTK_FILE_INFO_IS_HIDDEN         = 1 << 2,
  GTK_FILE_INFO_MIME_TYPE         = 1 << 3,
  GTK_FILE_INFO_MODIFICATION_TIME = 1 << 4,
  GTK_FILE_INFO_SIZE              = 1 << 5,
58 59
  GTK_FILE_INFO_ICON              = 1 << 6,
  GTK_FILE_INFO_ALL               = (1 << 7) - 1
Owen Taylor's avatar
Owen Taylor committed
60 61 62 63 64 65 66 67 68
} GtkFileInfoType;

/* GError enumeration for GtkFileSystem
 */

#define GTK_FILE_SYSTEM_ERROR (gtk_file_system_error_quark ())

typedef enum
{
69
  GTK_FILE_SYSTEM_ERROR_NONEXISTENT,
Owen Taylor's avatar
Owen Taylor committed
70 71 72 73
  GTK_FILE_SYSTEM_ERROR_NOT_FOLDER,
  GTK_FILE_SYSTEM_ERROR_INVALID_URI,
  GTK_FILE_SYSTEM_ERROR_BAD_FILENAME,
  GTK_FILE_SYSTEM_ERROR_FAILED,
74
  GTK_FILE_SYSTEM_ERROR_ALREADY_EXISTS
Owen Taylor's avatar
Owen Taylor committed
75 76 77 78 79 80 81 82
} GtkFileSystemError;

GQuark     gtk_file_system_error_quark      (void);

/* Boxed-type for gtk_file_folder_get_info() results
 */
#define GTK_TYPE_FILE_INFO (gtk_file_info_get_type ())

Matthias Clasen's avatar
Matthias Clasen committed
83
GType       gtk_file_info_get_type (void) G_GNUC_CONST; 
Owen Taylor's avatar
Owen Taylor committed
84 85 86 87 88 89 90

GtkFileInfo *gtk_file_info_new  (void);
GtkFileInfo *gtk_file_info_copy (GtkFileInfo *info);
void         gtk_file_info_free (GtkFileInfo *info);


G_CONST_RETURN gchar *gtk_file_info_get_display_name      (const GtkFileInfo *info);
Owen Taylor's avatar
Owen Taylor committed
91
G_CONST_RETURN gchar *gtk_file_info_get_display_key       (const GtkFileInfo *info);
Owen Taylor's avatar
Owen Taylor committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
void                  gtk_file_info_set_display_name      (GtkFileInfo       *info,
							   const gchar       *display_name);
gboolean              gtk_file_info_get_is_folder         (const GtkFileInfo *info);
void                  gtk_file_info_set_is_folder         (GtkFileInfo       *info,
							   gboolean           is_folder);
gboolean              gtk_file_info_get_is_hidden         (const GtkFileInfo *info);
void                  gtk_file_info_set_is_hidden         (GtkFileInfo       *info,
							   gboolean           is_hidden);
G_CONST_RETURN gchar *gtk_file_info_get_mime_type         (const GtkFileInfo *info);
void                  gtk_file_info_set_mime_type         (GtkFileInfo       *info,
							   const gchar       *mime_type);
GtkFileTime           gtk_file_info_get_modification_time (const GtkFileInfo *info);
void                  gtk_file_info_set_modification_time (GtkFileInfo       *info,
							   GtkFileTime        modification_time);
gint64                gtk_file_info_get_size              (const GtkFileInfo *info);
void                  gtk_file_info_set_size              (GtkFileInfo       *info,
							   gint64             size);

110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
void                  gtk_file_info_set_icon_name         (GtkFileInfo       *info,
							   const gchar       *con_name);
G_CONST_RETURN gchar *gtk_file_info_get_icon_name         (const GtkFileInfo *info);
GdkPixbuf            *gtk_file_info_render_icon           (const GtkFileInfo *info,
							   GtkWidget         *widget,
							   gint               pixel_size,
							   GError           **error);

/* GtkFileSystemHandle
 */

#define GTK_TYPE_FILE_SYSTEM_HANDLE            (gtk_file_system_handle_get_type ())
#define GTK_FILE_SYSTEM_HANDLE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FILE_SYSTEM_HANDLE, GtkFileSystemHandle))
#define GTK_IS_FILE_SYSTEM_HANDLE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FILE_SYSTEM_HANDLE))
#define GTK_FILE_SYSTEM_HANDLE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FILE_SYSTEM_HANDLE, GtkFileSystemHandleUnixClass))
#define GTK_IS_FILE_SYSTEM_HANDLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FILE_SYSTEM_HANDLE))
#define GTK_FILE_SYSTEM_HANDLE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FILE_SYSTEM_HANDLE, GtkFileSystemHandleClass))

typedef struct _GtkFileSystemHandle       GtkFileSystemHandle;
typedef struct _GtkFileSystemHandleClass  GtkFileSystemHandleClass;

struct _GtkFileSystemHandle
{
  GObject parent_instance;

  GtkFileSystem *file_system;

  guint cancelled : 1;
};

struct _GtkFileSystemHandleClass
{
  GObjectClass parent_class;
};

GType gtk_file_system_handle_get_type (void);

Owen Taylor's avatar
Owen Taylor committed
147 148 149 150 151 152 153
/* The base GtkFileSystem interface
 */
#define GTK_TYPE_FILE_SYSTEM             (gtk_file_system_get_type ())
#define GTK_FILE_SYSTEM(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FILE_SYSTEM, GtkFileSystem))
#define GTK_IS_FILE_SYSTEM(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FILE_SYSTEM))
#define GTK_FILE_SYSTEM_GET_IFACE(inst)  (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GTK_TYPE_FILE_SYSTEM, GtkFileSystemIface))

154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
/* Callbacks for the asynchronous GtkFileSystem operations
 */

typedef void (* GtkFileSystemGetInfoCallback) (GtkFileSystemHandle *handle,
					       const GtkFileInfo   *file_info,
					       const GError        *error,
					       gpointer             data);
typedef void (* GtkFileSystemGetFolderCallback) (GtkFileSystemHandle *handle,
						 GtkFileFolder       *folder,
						 const GError        *error,
						 gpointer             data);
typedef void (* GtkFileSystemCreateFolderCallback) (GtkFileSystemHandle *handle,
						    const GtkFilePath   *path,
						    const GError        *error,
						    gpointer             data);
typedef void (* GtkFileSystemVolumeMountCallback) (GtkFileSystemHandle *handle,
						   GtkFileSystemVolume *volume,
						   const GError        *error,
						   gpointer             data);

/*
 */

Owen Taylor's avatar
Owen Taylor committed
177 178 179 180 181 182
struct _GtkFileSystemIface
{
  GTypeInterface base_iface;

  /* Methods
   */
183 184 185
  GSList *              (*list_volumes)        (GtkFileSystem     *file_system);
  GtkFileSystemVolume * (*get_volume_for_path) (GtkFileSystem     *file_system,
						const GtkFilePath *path);
186

187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
  GtkFileSystemHandle * (*get_folder)  (GtkFileSystem                  *file_system,
					const GtkFilePath              *path,
					GtkFileInfoType                 types,
					GtkFileSystemGetFolderCallback  callback,
					gpointer                        data);
  GtkFileSystemHandle * (*get_info) (GtkFileSystem                *file_system,
				     const GtkFilePath            *path,
				     GtkFileInfoType               types,
				     GtkFileSystemGetInfoCallback  callback,
				     gpointer                      data);
  GtkFileSystemHandle * (*create_folder)  (GtkFileSystem                     *file_system,
					   const GtkFilePath                 *path,
					   GtkFileSystemCreateFolderCallback  callback,
					   gpointer                           data);

  void               (*cancel_operation) (GtkFileSystemHandle *handle);
203

204 205 206 207 208 209 210 211
  /* Volumes
   */
  void          (*volume_free)             (GtkFileSystem        *file_system,
					    GtkFileSystemVolume  *volume);
  GtkFilePath * (*volume_get_base_path)    (GtkFileSystem        *file_system,
					    GtkFileSystemVolume  *volume);
  gboolean      (*volume_get_is_mounted)   (GtkFileSystem        *file_system,
					    GtkFileSystemVolume  *volume);
212 213 214 215 216
  GtkFileSystemHandle * (*volume_mount)    (GtkFileSystem                    *file_system,
					    GtkFileSystemVolume              *volume,
					    GtkFileSystemVolumeMountCallback  callback,
					    gpointer                          data);
  char *        (*volume_get_display_name) (GtkFileSystem        *file_system,
217
					    GtkFileSystemVolume  *volume);
218
  gchar *       (*volume_get_icon_name)    (GtkFileSystem        *file_system,
219 220 221
					    GtkFileSystemVolume  *volume,
					    GError              **error);

222
  /* Path Manipulation
Owen Taylor's avatar
Owen Taylor committed
223
   */
224 225 226 227 228 229 230
  gboolean      (*get_parent)      (GtkFileSystem      *file_system,
				    const GtkFilePath  *path,
				    GtkFilePath       **parent,
				    GError            **error);
  GtkFilePath * (*make_path)        (GtkFileSystem     *file_system,
				     const GtkFilePath *base_path,
				     const gchar       *display_name,
231
				     GError           **error);
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
  gboolean      (*parse)            (GtkFileSystem     *file_system,
				     const GtkFilePath *base_path,
				     const gchar       *str,
				     GtkFilePath      **folder,
				     gchar            **file_part,
				     GError           **error);
  gchar *      (*path_to_uri)      (GtkFileSystem      *file_system,
				    const GtkFilePath  *path);
  gchar *      (*path_to_filename) (GtkFileSystem      *file_system,
				    const GtkFilePath  *path);
  GtkFilePath *(*uri_to_path)      (GtkFileSystem      *file_system,
				    const gchar        *uri);
  GtkFilePath *(*filename_to_path) (GtkFileSystem      *file_system,
				    const gchar        *path);

247 248
  /* Bookmarks 
   */
249
  gboolean       (*insert_bookmark)        (GtkFileSystem     *file_system,
250
					    const GtkFilePath *path,
251
					    gint               position,
252 253 254 255
					    GError           **error);
  gboolean       (*remove_bookmark)        (GtkFileSystem     *file_system,
					    const GtkFilePath *path,
					    GError           **error);
256
  GSList *       (*list_bookmarks)         (GtkFileSystem     *file_system);
257

258
  /* Signals 
Owen Taylor's avatar
Owen Taylor committed
259
   */
260
  void (*volumes_changed)   (GtkFileSystem *file_system);
261
  void (*bookmarks_changed) (GtkFileSystem *file_system);
262 263 264 265 266 267 268 269

  /* Bookmark labels 
   */
  gchar *        (*get_bookmark_label)     (GtkFileSystem     *file_system,
					    const GtkFilePath *path);
  void           (*set_bookmark_label)     (GtkFileSystem     *file_system,
					    const GtkFilePath *path,
					    const gchar       *label);
Owen Taylor's avatar
Owen Taylor committed
270 271
};

Matthias Clasen's avatar
Matthias Clasen committed
272
GType             gtk_file_system_get_type       (void) G_GNUC_CONST;
Owen Taylor's avatar
Owen Taylor committed
273

274
GSList *          gtk_file_system_list_volumes   (GtkFileSystem     *file_system);
275 276 277

GtkFileSystemVolume *gtk_file_system_get_volume_for_path (GtkFileSystem     *file_system,
							  const GtkFilePath *path);
278

279 280 281 282 283 284
void              gtk_file_system_volume_free             (GtkFileSystem        *file_system,
							   GtkFileSystemVolume  *volume);
GtkFilePath *     gtk_file_system_volume_get_base_path    (GtkFileSystem        *file_system,
							   GtkFileSystemVolume  *volume);
gboolean          gtk_file_system_volume_get_is_mounted   (GtkFileSystem        *file_system,
							   GtkFileSystemVolume  *volume);
285 286 287 288
GtkFileSystemHandle *gtk_file_system_volume_mount         (GtkFileSystem                    *file_system,
							   GtkFileSystemVolume              *volume,
							   GtkFileSystemVolumeMountCallback  callback,
							   gpointer                          data);
289 290 291 292 293 294 295
char *            gtk_file_system_volume_get_display_name (GtkFileSystem        *file_system, 
							   GtkFileSystemVolume  *volume);
GdkPixbuf *       gtk_file_system_volume_render_icon      (GtkFileSystem        *file_system,
							   GtkFileSystemVolume  *volume,
							   GtkWidget            *widget,
							   gint                  pixel_size,
							   GError              **error);
296 297 298
gchar *           gtk_file_system_volume_get_icon_name    (GtkFileSystem        *file_system,
							   GtkFileSystemVolume  *volume,
							   GError              **error);
299

300 301 302 303
gboolean          gtk_file_system_get_parent     (GtkFileSystem     *file_system,
						  const GtkFilePath *path,
						  GtkFilePath      **parent,
						  GError           **error);
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
GtkFileSystemHandle *gtk_file_system_get_folder  (GtkFileSystem                  *file_system,
						  const GtkFilePath              *path,
						  GtkFileInfoType                 types,
						  GtkFileSystemGetFolderCallback  callback,
						  gpointer                        data);
GtkFileSystemHandle *gtk_file_system_get_info    (GtkFileSystem                  *file_system,
						  const GtkFilePath              *path,
						  GtkFileInfoType                 types,
						  GtkFileSystemGetInfoCallback    callback,
						  gpointer                        data);
GtkFileSystemHandle *gtk_file_system_create_folder (GtkFileSystem                     *file_system,
						    const GtkFilePath                 *path,
						    GtkFileSystemCreateFolderCallback  callback,
						    gpointer                           data);
void              gtk_file_system_cancel_operation (GtkFileSystemHandle *handle);
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
GtkFilePath *     gtk_file_system_make_path      (GtkFileSystem     *file_system,
						  const GtkFilePath *base_path,
						  const gchar       *display_name,
						  GError           **error);
gboolean          gtk_file_system_parse          (GtkFileSystem     *file_system,
						  const GtkFilePath *base_path,
						  const gchar       *str,
						  GtkFilePath      **folder,
						  gchar            **file_part,
						  GError           **error);

gchar *      gtk_file_system_path_to_uri      (GtkFileSystem     *file_system,
					       const GtkFilePath *path);
gchar *      gtk_file_system_path_to_filename (GtkFileSystem     *file_system,
					       const GtkFilePath *path);
GtkFilePath *gtk_file_system_uri_to_path      (GtkFileSystem     *file_system,
					       const gchar       *uri);
GtkFilePath *gtk_file_system_filename_to_path (GtkFileSystem     *file_system,
					       const gchar       *filename);

339 340 341
gboolean     gtk_file_system_path_is_local    (GtkFileSystem     *filesystem,
					       const GtkFilePath *path);

342
gboolean gtk_file_system_insert_bookmark (GtkFileSystem     *file_system,
343
					  const GtkFilePath *path,
344
					  gint               position,
345 346 347 348 349
					  GError           **error);
gboolean gtk_file_system_remove_bookmark (GtkFileSystem     *file_system,
					  const GtkFilePath *path,
					  GError           **error);
GSList  *gtk_file_system_list_bookmarks  (GtkFileSystem     *file_system);
350

351 352 353 354 355
gchar   *gtk_file_system_get_bookmark_label (GtkFileSystem     *file_system,
					     const GtkFilePath *path);
void     gtk_file_system_set_bookmark_label (GtkFileSystem     *file_system,
					     const GtkFilePath *path,
					     const gchar       *label);
356

Owen Taylor's avatar
Owen Taylor committed
357 358 359 360 361 362 363 364 365 366 367 368 369 370
/*
 * Detailed information about a particular folder
 */
#define GTK_TYPE_FILE_FOLDER             (gtk_file_folder_get_type ())
#define GTK_FILE_FOLDER(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FILE_FOLDER, GtkFileFolder))
#define GTK_IS_FILE_FOLDER(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FILE_FOLDER))
#define GTK_FILE_FOLDER_GET_IFACE(inst)  (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GTK_TYPE_FILE_FOLDER, GtkFileFolderIface))

struct _GtkFileFolderIface
{
  GTypeInterface base_iface;

  /* Methods
   */
371 372 373 374 375 376
  GtkFileInfo *      (*get_info)       (GtkFileFolder     *folder,
					const GtkFilePath *path,
				        GError           **error);
  gboolean           (*list_children)  (GtkFileFolder     *folder,
				        GSList           **children,
				        GError           **error);
Owen Taylor's avatar
Owen Taylor committed
377 378 379 380 381

  /* ??? refresh() ??? */

  /* Signals
   */
382
  void (*deleted)       (GtkFileFolder *monitor);
Owen Taylor's avatar
Owen Taylor committed
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);
Federico Mena Quintero's avatar
Federico Mena Quintero committed
389 390 391 392

  /* Method / signal */
  gboolean (*is_finished_loading) (GtkFileFolder *folder);
  void     (*finished_loading)    (GtkFileFolder *folder);
Owen Taylor's avatar
Owen Taylor committed
393 394
};

Matthias Clasen's avatar
Matthias Clasen committed
395
GType        gtk_file_folder_get_type      (void) G_GNUC_CONST;
396 397 398 399 400 401 402
gboolean     gtk_file_folder_list_children (GtkFileFolder      *folder,
					    GSList            **children,
					    GError            **error);
GtkFileInfo *gtk_file_folder_get_info      (GtkFileFolder      *folder,
					    const GtkFilePath  *path,
					    GError            **error);

Federico Mena Quintero's avatar
Federico Mena Quintero committed
403 404
gboolean     gtk_file_folder_is_finished_loading (GtkFileFolder *folder);

405 406 407 408

/* GtkFilePath */
#define GTK_TYPE_FILE_PATH             (gtk_file_path_get_type ())

Matthias Clasen's avatar
Matthias Clasen committed
409
GType   gtk_file_path_get_type (void) G_GNUC_CONST;
410 411 412 413 414 415 416 417 418 419 420 421
#ifdef __GNUC__
#define gtk_file_path_new_dup(str) \
 ({ const gchar *__s = (str); (GtkFilePath *)g_strdup(__s); })
#define gtk_file_path_new_steal(str) \
 ({ gchar *__s = (str); (GtkFilePath *)__s; })
#define gtk_file_path_get_string(path) \
 ({ const GtkFilePath *__p = (path); (const gchar *)__p; })
#define gtk_file_path_free(path) \
 ({ GtkFilePath *__p = (path); g_free (__p); })
#else /* __GNUC__ */
#define gtk_file_path_new_dup(str)     ((GtkFilePath *)g_strdup(str))
#define gtk_file_path_new_steal(str)   ((GtkFilePath *)(str))
422
#define gtk_file_path_get_string(str) ((const gchar *)(str))
423 424 425 426
#define gtk_file_path_free(path)       g_free (path)
#endif/* __GNUC__ */

#define gtk_file_path_copy(path)       gtk_file_path_new_dup (gtk_file_path_get_string(path))
427 428 429 430 431 432 433
#ifdef G_OS_WIN32
int _gtk_file_system_win32_path_compare (const gchar *path1,
					 const gchar *path2);
#define gtk_file_path_compare(path1,path2) \
  _gtk_file_system_win32_path_compare (gtk_file_path_get_string (path1), \
	                               gtk_file_path_get_string (path2))
#else
434 435
#define gtk_file_path_compare(path1,path2) strcmp (gtk_file_path_get_string (path1), \
						   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);
Owen Taylor's avatar
Owen Taylor committed
441

442 443
/* GtkFileSystem modules support */

444
GtkFileSystem  *gtk_file_system_create (const char *file_system_name);
445

Owen Taylor's avatar
Owen Taylor committed
446 447 448
G_END_DECLS

#endif /* __GTK_FILE_SYSTEM_H__ */