Update to 24f58c58bb8d22c0e8e6c5ce43c536c47b719bc6
[gnt.git] / gntfilesel.h
blobbb6b1d6cf95b65fe26da23bace5efa6cba31fb4d
1 /**
2 * @file gntfilesel.h File selector API
3 * @ingroup gnt
4 */
5 /*
6 * GNT - The GLib Ncurses Toolkit
8 * GNT is the legal property of its developers, whose names are too numerous
9 * to list here. Please refer to the COPYRIGHT file distributed with this
10 * source distribution.
12 * This library is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
27 #ifndef GNT_FILE_SEL_H
28 #define GNT_FILE_SEL_H
30 #include "gntwindow.h"
31 #include "gnt.h"
32 #include "gntcolors.h"
33 #include "gntkeys.h"
35 #define GNT_TYPE_FILE_SEL (gnt_file_sel_get_gtype())
36 #define GNT_FILE_SEL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_FILE_SEL, GntFileSel))
37 #define GNT_FILE_SEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GNT_TYPE_FILE_SEL, GntFileSelClass))
38 #define GNT_IS_FILE_SEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GNT_TYPE_FILE_SEL))
39 #define GNT_IS_FILE_SEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GNT_TYPE_FILE_SEL))
40 #define GNT_FILE_SEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GNT_TYPE_FILE_SEL, GntFileSelClass))
42 #define GNT_FILE_SEL_FLAGS(obj) (GNT_FILE_SEL(obj)->priv.flags)
43 #define GNT_FILE_SEL_SET_FLAGS(obj, flags) (GNT_FILE_SEL_FLAGS(obj) |= flags)
44 #define GNT_FILE_SEL_UNSET_FLAGS(obj, flags) (GNT_FILE_SEL_FLAGS(obj) &= ~(flags))
46 typedef struct _GntFileSel GntFileSel;
47 typedef struct _GntFileSelPriv GntFileSelPriv;
48 typedef struct _GntFileSelClass GntFileSelClass;
49 typedef struct _GntFile GntFile;
51 struct _GntFileSel
53 GntWindow parent;
55 GntWidget *dirs; /* list of files */
56 GntWidget *files; /* list of directories */
57 GntWidget *location; /* location entry */
59 GntWidget *select; /* select button */
60 GntWidget *cancel; /* cancel button */
62 char *current; /* Full path of the current location */
63 char *suggest; /* Suggested filename */
64 /* XXX: someone should make these useful */
65 gboolean must_exist; /* Make sure the selected file (the name entered in 'location') exists */
66 gboolean dirsonly; /* Show only directories */
67 gboolean multiselect;
68 GList *tags; /* List of tagged files when multiselect is set */
70 gboolean (*read_fn)(const char *path, GList **files, GError **error);
73 struct _GntFileSelClass
75 GntWindowClass parent;
77 void (*file_selected)(GntFileSel *sel, const char *path, const char *filename);
78 void (*gnt_reserved1)(void);
79 void (*gnt_reserved2)(void);
80 void (*gnt_reserved3)(void);
81 void (*gnt_reserved4)(void);
84 typedef enum _GntFileType
86 GNT_FILE_REGULAR,
87 GNT_FILE_DIR
88 } GntFileType;
90 struct _GntFile
92 char *fullpath;
93 char *basename;
94 GntFileType type;
95 unsigned long size;
98 G_BEGIN_DECLS
101 * @return GType for GntFileSel.
103 GType gnt_file_sel_get_gtype(void);
106 * Create a new file selector.
108 * @return The newly created file selector.
110 GntWidget * gnt_file_sel_new(void);
113 * Set the current location of the file selector.
115 * @param sel The file selector.
116 * @param path The current path of the selector.
118 * @return @c TRUE if the current location was successfully changed, @c FALSE otherwise.
120 gboolean gnt_file_sel_set_current_location(GntFileSel *sel, const char *path);
123 * Set wheter to only allow selecting directories.
125 * @param sel The file selector.
126 * @param dirs @c TRUE if only directories can be selected, @c FALSE if files
127 * can also be selected.
129 void gnt_file_sel_set_dirs_only(GntFileSel *sel, gboolean dirs);
132 * Check whether the file selector allows only selecting directories.
134 * @param sel The file selector.
136 * @return @c TRUE if only directories can be selected.
138 gboolean gnt_file_sel_get_dirs_only(GntFileSel *sel);
141 * Set whether a selected file must exist.
143 * @param sel The file selector.
144 * @param must @c TRUE if the selected file must exist.
146 void gnt_file_sel_set_must_exist(GntFileSel *sel, gboolean must);
149 * Check whether the selector allows selecting non-existent files.
151 * @param sel The file selector.
153 * @return @c TRUE if the selected file must exist, @c FALSE if a non-existent
154 * file can be selected.
156 gboolean gnt_file_sel_get_must_exist(GntFileSel *sel);
159 * Get the selected file in the selector.
161 * @param sel The file selector.
163 * @return The path of the selected file. The caller should g_free the returned
164 * string.
166 char * gnt_file_sel_get_selected_file(GntFileSel *sel);
169 * Get the list of selected files in the selector.
171 * @param sel The file selector.
173 * @return A list of paths for the selected files. The caller must g_free the
174 * contents of the list, and g_list_free the list.
176 GList * gnt_file_sel_get_selected_multi_files(GntFileSel *sel);
179 * Allow selecting multiple files.
181 * @param sel The file selector.
182 * @param set @c TRUE if selecting multiple files should be allowed.
184 void gnt_file_sel_set_multi_select(GntFileSel *sel, gboolean set);
187 * Set the suggested file to have selected at startup.
189 * @param sel The file selector.
190 * @param suggest The suggested filename.
192 void gnt_file_sel_set_suggested_filename(GntFileSel *sel, const char *suggest);
195 * Set custom functions to read the names of files.
197 * @param sel The file selector.
198 * @param read_fn The custom read function.
200 void gnt_file_sel_set_read_fn(GntFileSel *sel, gboolean (*read_fn)(const char *path, GList **files, GError **error));
203 * Create a new GntFile.
205 * @param name The name of the file.
206 * @param size The size of the file.
208 * @return The newly created GntFile.
210 GntFile* gnt_file_new(const char *name, unsigned long size);
213 * Create a new GntFile for a directory.
215 * @param name The name of the directory.
217 * @return The newly created GntFile.
219 GntFile* gnt_file_new_dir(const char *name);
221 G_END_DECLS
223 #endif /* GNT_FILE_SEL_H */