1 /* 2 * GNT - The GLib Ncurses Toolkit 3 * 4 * GNT is the legal property of its developers, whose names are too numerous 5 * to list here. Please refer to the COPYRIGHT file distributed with this 6 * source distribution. 7 * 8 * This library is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 21 */ 22 23 #ifndef GNT_FILE_SEL_H 24 #define GNT_FILE_SEL_H 25 /** 26 * SECTION:gntfilesel 27 * @section_id: libgnt-gntfilesel 28 * @title: GntFileSel 29 * @short_description: A widget for selecting a file or directory 30 */ 31 32 #include "gnt.h" 33 #include "gntcolors.h" 34 #include "gntkeys.h" 35 #include "gntwindow.h" 36 37 #define GNT_TYPE_FILE_SEL (gnt_file_sel_get_gtype()) 38 #define GNT_FILE_SEL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_FILE_SEL, GntFileSel)) 39 #define GNT_FILE_SEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GNT_TYPE_FILE_SEL, GntFileSelClass)) 40 #define GNT_IS_FILE_SEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GNT_TYPE_FILE_SEL)) 41 #define GNT_IS_FILE_SEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GNT_TYPE_FILE_SEL)) 42 #define GNT_FILE_SEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GNT_TYPE_FILE_SEL, GntFileSelClass)) 43 44 #ifndef GNT_DISABLE_DEPRECATED 45 /** 46 * GNT_FILE_SEL_FLAGS: 47 * 48 * Deprecated: 2.14.0: This is an internal implementation detail. 49 */ 50 #define GNT_FILE_SEL_FLAGS(obj) (GNT_FILE_SEL(obj)->priv.flags) 51 /** 52 * GNT_FILE_SEL_SET_FLAGS: 53 * 54 * Deprecated: 2.14.0: This is an internal implementation detail. 55 */ 56 #define GNT_FILE_SEL_SET_FLAGS(obj, flags) (GNT_FILE_SEL_FLAGS(obj) |= flags) 57 /** 58 * GNT_FILE_SEL_UNSET_FLAGS: 59 * 60 * Deprecated: 2.14.0: This is an internal implementation detail. 61 */ 62 #define GNT_FILE_SEL_UNSET_FLAGS(obj, flags) (GNT_FILE_SEL_FLAGS(obj) &= ~(flags)) 63 #endif 64 65 typedef struct _GntFileSel GntFileSel; 66 typedef struct _GntFileSelClass GntFileSelClass; 67 #ifndef GNT_DISABLE_DEPRECATED 68 /** 69 * GntFileSelPriv: 70 * 71 * Deprecated: 2.14.0: This is an internal implementation detail. 72 */ 73 typedef struct _GntFileSelPriv GntFileSelPriv; 74 /** 75 * GntFile: 76 * 77 * Deprecated: 2.14.0: This is an internal implementation detail. Use #GFile 78 * from GIO for a similar abstraction. 79 */ 80 typedef struct _GntFile GntFile; 81 #endif 82 83 /** 84 * GntFileSel: 85 * 86 * Access to any fields is deprecated. See inline comments for replacements. 87 */ 88 struct _GntFileSel 89 { 90 GntWindow parent; 91 92 GntWidget *GNTSEAL(dirs); /* list of files */ 93 GntWidget *GNTSEAL(files); /* list of directories */ 94 GntWidget *GNTSEAL(location); /* location entry */ 95 96 GntWidget *GNTSEAL(select); /* select button */ 97 GntWidget *GNTSEAL(cancel); /* cancel button */ 98 99 char *GNTSEAL(current); /* Full path of the current location */ 100 char *GNTSEAL(suggest); /* Suggested filename */ 101 /* XXX: someone should make these useful */ 102 gboolean GNTSEAL(must_exist); /* Make sure the selected file (the name entered in 'location') exists */ 103 gboolean GNTSEAL(dirsonly); /* Show only directories */ 104 gboolean GNTSEAL(multiselect); 105 GList *GNTSEAL(tags); /* List of tagged files when multiselect is set */ 106 107 gboolean (*GNTSEAL(read_fn))(const char *path, GList **files, GError **error); 108 }; 109 110 struct _GntFileSelClass 111 { 112 GntWindowClass parent; 113 114 void (*file_selected)(GntFileSel *sel, const char *path, const char *filename); 115 void (*cancelled)(GntFileSel *sel); 116 117 /*< private >*/ 118 void (*gnt_reserved1)(void); 119 void (*gnt_reserved2)(void); 120 void (*gnt_reserved3)(void); 121 }; 122 123 #ifndef GNT_DISABLE_DEPRECATED 124 /** 125 * GntFileType: 126 * 127 * Deprecated: 2.14.0: This is an internal implementation detail. Use #GFile 128 * from GIO for a similar abstraction. 129 */ 130 typedef enum _GntFileType 131 { 132 GNT_FILE_REGULAR, 133 GNT_FILE_DIR 134 } GntFileType; 135 136 struct _GntFile 137 { 138 char *GNTSEAL(fullpath); 139 char *GNTSEAL(basename); 140 GntFileType GNTSEAL(type); 141 unsigned long GNTSEAL(size); 142 }; 143 #endif 144 145 G_BEGIN_DECLS 146 147 /** 148 * gnt_file_sel_get_gtype: 149 * 150 * Returns: GType for GntFileSel. 151 */ 152 GType gnt_file_sel_get_gtype(void); 153 154 /** 155 * gnt_file_sel_new: 156 * 157 * Create a new file selector. 158 * 159 * Returns: The newly created file selector. 160 */ 161 GntWidget * gnt_file_sel_new(void); 162 163 /** 164 * gnt_file_sel_set_current_location: 165 * @sel: The file selector. 166 * @path: The current path of the selector. 167 * 168 * Set the current location of the file selector. 169 * 170 * Returns: %TRUE if the current location was successfully changed, %FALSE otherwise. 171 */ 172 gboolean gnt_file_sel_set_current_location(GntFileSel *sel, const char *path); 173 174 /** 175 * gnt_file_sel_set_dirs_only: 176 * @sel: The file selector. 177 * @dirs: %TRUE if only directories can be selected, %FALSE if files 178 * can also be selected. 179 * 180 * Set wheter to only allow selecting directories. 181 */ 182 void gnt_file_sel_set_dirs_only(GntFileSel *sel, gboolean dirs); 183 184 /** 185 * gnt_file_sel_get_dirs_only: 186 * @sel: The file selector. 187 * 188 * Check whether the file selector allows only selecting directories. 189 * 190 * Returns: %TRUE if only directories can be selected. 191 */ 192 gboolean gnt_file_sel_get_dirs_only(GntFileSel *sel); 193 194 /** 195 * gnt_file_sel_set_must_exist: 196 * @sel: The file selector. 197 * @must: %TRUE if the selected file must exist. 198 * 199 * Set whether a selected file must exist. 200 */ 201 void gnt_file_sel_set_must_exist(GntFileSel *sel, gboolean must); 202 203 /** 204 * gnt_file_sel_get_must_exist: 205 * @sel: The file selector. 206 * 207 * Check whether the selector allows selecting non-existent files. 208 * 209 * Returns: %TRUE if the selected file must exist, %FALSE if a non-existent 210 * file can be selected. 211 */ 212 gboolean gnt_file_sel_get_must_exist(GntFileSel *sel); 213 214 /** 215 * gnt_file_sel_get_selected_file: 216 * @sel: The file selector. 217 * 218 * Get the selected file in the selector. 219 * 220 * Returns: The path of the selected file. The caller should g_free the returned 221 * string. 222 */ 223 char * gnt_file_sel_get_selected_file(GntFileSel *sel); 224 225 /** 226 * gnt_file_sel_get_selected_multi_files: 227 * @sel: The file selector. 228 * 229 * Get the list of selected files in the selector. 230 * 231 * Returns: (transfer full) (element-type filename): A list of paths for the 232 * selected files. The caller must g_free() the contents of the list, 233 * and g_list_free() the list. 234 */ 235 GList * gnt_file_sel_get_selected_multi_files(GntFileSel *sel); 236 237 /** 238 * gnt_file_sel_set_multi_select: 239 * @sel: The file selector. 240 * @set: %TRUE if selecting multiple files should be allowed. 241 * 242 * Allow selecting multiple files. 243 */ 244 void gnt_file_sel_set_multi_select(GntFileSel *sel, gboolean set); 245 246 /** 247 * gnt_file_sel_set_suggested_filename: 248 * @sel: The file selector. 249 * @suggest: The suggested filename. 250 * 251 * Set the suggested file to have selected at startup. 252 */ 253 void gnt_file_sel_set_suggested_filename(GntFileSel *sel, const char *suggest); 254 255 #ifndef GNT_DISABLE_DEPRECATED 256 /** 257 * gnt_file_sel_set_read_fn: 258 * @sel: The file selector. 259 * @read_fn: The custom read function. 260 * 261 * Set custom functions to read the names of files. 262 * 263 * Deprecated: 2.14.0: This is an internal implementation detail. 264 */ 265 void gnt_file_sel_set_read_fn(GntFileSel *sel, gboolean (*read_fn)(const char *path, GList **files, GError **error)); 266 267 /** 268 * gnt_file_new: 269 * @name: The name of the file. 270 * @size: The size of the file. 271 * 272 * Create a new GntFile. 273 * 274 * Returns: The newly created GntFile. 275 * 276 * Deprecated: 2.14.0: This is an internal implementation detail. 277 */ 278 GntFile* gnt_file_new(const char *name, unsigned long size); 279 280 /** 281 * gnt_file_new_dir: 282 * @name: The name of the directory. 283 * 284 * Create a new GntFile for a directory. 285 * 286 * Returns: The newly created GntFile. 287 * 288 * Deprecated: 2.14.0: This is an internal implementation detail. 289 */ 290 GntFile* gnt_file_new_dir(const char *name); 291 #endif 292 293 G_END_DECLS 294 295 #endif /* GNT_FILE_SEL_H */ 296 297