Add missing AUTHORS and ChangeLog.
[gnt.git] / gntfilesel.c
blob0d1c21b0b868c8abf0dea6524761b051e7b2b90e
1 /**
2 * GNT - The GLib Ncurses Toolkit
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.
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.
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.
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
23 #include "gntbutton.h"
24 #include "gntentry.h"
25 #include "gntfilesel.h"
26 #include "gntlabel.h"
27 #include "gntmarshal.h"
28 #include "gntstyle.h"
29 #include "gnttree.h"
31 #include <string.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <unistd.h>
36 #if 0
37 #include <glob.h>
38 #endif
40 enum
42 SIG_FILE_SELECTED,
43 SIGS
46 static GntWindowClass *parent_class = NULL;
47 static guint signals[SIGS] = { 0 };
48 static void (*orig_map)(GntWidget *widget);
49 static void (*orig_size_request)(GntWidget *widget);
51 static void select_activated_cb(GntWidget *button, GntFileSel *sel);
53 static void
54 gnt_file_sel_destroy(GntWidget *widget)
56 GntFileSel *sel = GNT_FILE_SEL(widget);
57 g_free(sel->current);
58 g_free(sel->suggest);
59 if (sel->tags) {
60 g_list_foreach(sel->tags, (GFunc)g_free, NULL);
61 g_list_free(sel->tags);
65 #if !GLIB_CHECK_VERSION(2,8,0)
66 /* ripped from glib/gfileutils.c */
67 static gchar *
68 g_build_path_va (const gchar *separator,
69 gchar **str_array)
71 GString *result;
72 gint separator_len = strlen (separator);
73 gboolean is_first = TRUE;
74 gboolean have_leading = FALSE;
75 const gchar *single_element = NULL;
76 const gchar *next_element;
77 const gchar *last_trailing = NULL;
78 gint i = 0;
80 result = g_string_new (NULL);
82 next_element = str_array[i++];
84 while (TRUE) {
85 const gchar *element;
86 const gchar *start;
87 const gchar *end;
89 if (next_element) {
90 element = next_element;
91 next_element = str_array[i++];
92 } else
93 break;
95 /* Ignore empty elements */
96 if (!*element)
97 continue;
99 start = element;
101 if (separator_len) {
102 while (start &&
103 strncmp (start, separator, separator_len) == 0)
104 start += separator_len;
107 end = start + strlen (start);
109 if (separator_len) {
110 while (end >= start + separator_len &&
111 strncmp (end - separator_len, separator, separator_len) == 0)
112 end -= separator_len;
114 last_trailing = end;
115 while (last_trailing >= element + separator_len &&
116 strncmp (last_trailing - separator_len, separator, separator_len) == 0)
117 last_trailing -= separator_len;
119 if (!have_leading) {
120 /* If the leading and trailing separator strings are in the
121 * same element and overlap, the result is exactly that element
123 if (last_trailing <= start)
124 single_element = element;
126 g_string_append_len (result, element, start - element);
127 have_leading = TRUE;
128 } else
129 single_element = NULL;
132 if (end == start)
133 continue;
135 if (!is_first)
136 g_string_append (result, separator);
138 g_string_append_len (result, start, end - start);
139 is_first = FALSE;
142 if (single_element) {
143 g_string_free (result, TRUE);
144 return g_strdup (single_element);
145 } else {
146 if (last_trailing)
147 g_string_append (result, last_trailing);
149 return g_string_free (result, FALSE);
153 static gchar *
154 g_build_pathv (const gchar *separator,
155 gchar **args)
157 if (!args)
158 return NULL;
160 return g_build_path_va (separator, args);
163 #endif
165 static char *
166 process_path(const char *path)
168 char **splits = NULL;
169 int i, j;
170 char *str, *ret;
172 splits = g_strsplit(path, G_DIR_SEPARATOR_S, -1);
173 for (i = 0, j = 0; splits[i]; i++) {
174 if (strcmp(splits[i], ".") == 0) {
175 } else if (strcmp(splits[i], "..") == 0) {
176 if (j)
177 j--;
178 } else {
179 if (i != j) {
180 g_free(splits[j]);
181 splits[j] = splits[i];
182 splits[i] = NULL;
184 j++;
187 g_free(splits[j]);
188 splits[j] = NULL;
189 str = g_build_pathv(G_DIR_SEPARATOR_S, splits);
190 ret = g_strdup_printf(G_DIR_SEPARATOR_S "%s", str);
191 g_free(str);
192 g_strfreev(splits);
193 return ret;
196 static void
197 update_location(GntFileSel *sel)
199 char *old;
200 const char *tmp;
201 tmp = sel->suggest ? sel->suggest :
202 (const char*)gnt_tree_get_selection_data(sel->dirsonly ? GNT_TREE(sel->dirs) : GNT_TREE(sel->files));
203 old = g_strdup_printf("%s%s%s", SAFE(sel->current), SAFE(sel->current)[1] ? G_DIR_SEPARATOR_S : "", tmp ? tmp : "");
204 gnt_entry_set_text(GNT_ENTRY(sel->location), old);
205 g_free(old);
208 static gboolean
209 is_tagged(GntFileSel *sel, const char *f)
211 char *ret = g_strdup_printf("%s%s%s", sel->current, sel->current[1] ? G_DIR_SEPARATOR_S : "", f);
212 gboolean find = g_list_find_custom(sel->tags, ret, (GCompareFunc)g_utf8_collate) != NULL;
213 g_free(ret);
214 return find;
217 GntFile* gnt_file_new_dir(const char *name)
219 GntFile *file = g_new0(GntFile, 1);
220 file->basename = g_strdup(name);
221 file->type = GNT_FILE_DIR;
222 return file;
225 GntFile* gnt_file_new(const char *name, unsigned long size)
227 GntFile *file = g_new0(GntFile, 1);
228 file->basename = g_strdup(name);
229 file->type = GNT_FILE_REGULAR;
230 file->size = size;
231 return file;
234 static gboolean
235 local_read_fn(const char *path, GList **files, GError **error)
237 GDir *dir;
238 GntFile *file;
239 const char *str;
241 dir = g_dir_open(path, 0, error);
242 if (dir == NULL || (error && *error)) {
243 return FALSE;
246 *files = NULL;
247 if (*path != '\0' && strcmp(path, G_DIR_SEPARATOR_S)) {
248 file = gnt_file_new_dir("..");
249 *files = g_list_prepend(*files, file);
252 while ((str = g_dir_read_name(dir)) != NULL) {
253 char *fp = g_build_filename(path, str, NULL);
254 struct stat st;
256 if (stat(fp, &st)) {
257 g_printerr("Error stating location %s\n", fp);
258 } else {
259 if (S_ISDIR(st.st_mode)) {
260 file = gnt_file_new_dir(str);
261 } else {
262 file = gnt_file_new(str, (long)st.st_size);
264 *files = g_list_prepend(*files, file);
266 g_free(fp);
269 *files = g_list_reverse(*files);
270 return TRUE;
273 static void
274 gnt_file_free(GntFile *file)
276 g_free(file->fullpath);
277 g_free(file->basename);
278 g_free(file);
281 static gboolean
282 location_changed(GntFileSel *sel, GError **err)
284 GList *files, *iter;
285 gboolean success;
287 if (!sel->dirs)
288 return TRUE;
290 gnt_tree_remove_all(GNT_TREE(sel->dirs));
291 if (sel->files)
292 gnt_tree_remove_all(GNT_TREE(sel->files));
293 gnt_entry_set_text(GNT_ENTRY(sel->location), NULL);
294 if (sel->current == NULL) {
295 if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(sel), GNT_WIDGET_MAPPED))
296 gnt_widget_draw(GNT_WIDGET(sel));
297 return TRUE;
300 /* XXX:\
301 * XXX: This is blocking.
302 * XXX:/
304 files = NULL;
305 if (sel->read_fn)
306 success = sel->read_fn(sel->current, &files, err);
307 else
308 success = local_read_fn(sel->current, &files, err);
310 if (!success || *err) {
311 g_printerr("GntFileSel: error opening location %s (%s)\n",
312 sel->current, *err ? (*err)->message : "reason unknown");
313 return FALSE;
316 for (iter = files; iter; iter = iter->next) {
317 GntFile *file = iter->data;
318 char *str = file->basename;
319 if (file->type == GNT_FILE_DIR) {
320 gnt_tree_add_row_after(GNT_TREE(sel->dirs), g_strdup(str),
321 gnt_tree_create_row(GNT_TREE(sel->dirs), str), NULL, NULL);
322 if (sel->multiselect && sel->dirsonly && is_tagged(sel, str))
323 gnt_tree_set_row_flags(GNT_TREE(sel->dirs), (gpointer)str, GNT_TEXT_FLAG_BOLD);
324 } else if (!sel->dirsonly) {
325 char size[128];
326 snprintf(size, sizeof(size), "%ld", file->size);
328 gnt_tree_add_row_after(GNT_TREE(sel->files), g_strdup(str),
329 gnt_tree_create_row(GNT_TREE(sel->files), str, size, ""), NULL, NULL);
330 if (sel->multiselect && is_tagged(sel, str))
331 gnt_tree_set_row_flags(GNT_TREE(sel->files), (gpointer)str, GNT_TEXT_FLAG_BOLD);
334 g_list_foreach(files, (GFunc)gnt_file_free, NULL);
335 g_list_free(files);
336 if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(sel), GNT_WIDGET_MAPPED))
337 gnt_widget_draw(GNT_WIDGET(sel));
338 return TRUE;
341 static gboolean
342 dir_key_pressed(GntTree *tree, const char *key, GntFileSel *sel)
344 if (strcmp(key, "\r") == 0) {
345 char *str = g_strdup(gnt_tree_get_selection_data(tree));
346 char *path, *dir;
348 if (!str)
349 return TRUE;
351 path = g_build_filename(sel->current, str, NULL);
352 dir = g_path_get_basename(sel->current);
353 if (!gnt_file_sel_set_current_location(sel, path)) {
354 gnt_tree_set_selected(tree, str);
355 } else if (strcmp(str, "..") == 0) {
356 gnt_tree_set_selected(tree, dir);
358 gnt_bindable_perform_action_named(GNT_BINDABLE(tree), "end-search", NULL);
359 g_free(dir);
360 g_free(str);
361 g_free(path);
362 return TRUE;
364 return FALSE;
367 static gboolean
368 location_key_pressed(GntTree *tree, const char *key, GntFileSel *sel)
370 char *path;
371 char *str;
372 #if 0
373 int count;
374 glob_t gl;
375 struct stat st;
376 int glob_ret;
377 #endif
378 if (strcmp(key, "\r"))
379 return FALSE;
381 str = (char*)gnt_entry_get_text(GNT_ENTRY(sel->location));
382 if (*str == G_DIR_SEPARATOR)
383 path = g_strdup(str);
384 else
385 path = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", sel->current, str);
386 str = process_path(path);
387 g_free(path);
388 path = str;
390 if (gnt_file_sel_set_current_location(sel, path))
391 goto success;
393 path = g_path_get_dirname(str);
394 g_free(str);
396 if (!gnt_file_sel_set_current_location(sel, path)) {
397 g_free(path);
398 return FALSE;
400 #if 0
401 /* XXX: there needs to be a way to allow other methods for globbing,
402 * like the read_fn stuff. */
403 glob_ret = glob(path, GLOB_MARK, NULL, &gl);
404 if (!glob_ret) { /* XXX: do something with the return value */
405 char *loc = g_path_get_dirname(gl.gl_pathv[0]);
407 stat(gl.gl_pathv[0], &st);
408 gnt_file_sel_set_current_location(sel, loc); /* XXX: check the return value */
409 g_free(loc);
410 if (!S_ISDIR(st.st_mode) && !sel->dirsonly) {
411 gnt_tree_remove_all(GNT_TREE(sel->files));
412 for (count = 0; count < gl.gl_pathc; count++) {
413 char *tmp = process_path(gl.gl_pathv[count]);
414 loc = g_path_get_dirname(tmp);
415 if (g_utf8_collate(sel->current, loc) == 0) {
416 char *base = g_path_get_basename(tmp);
417 char size[128];
418 snprintf(size, sizeof(size), "%ld", (long)st.st_size);
419 gnt_tree_add_row_after(GNT_TREE(sel->files), base,
420 gnt_tree_create_row(GNT_TREE(sel->files), base, size, ""), NULL, NULL);
422 g_free(loc);
423 g_free(tmp);
425 gnt_widget_draw(sel->files);
427 } else if (sel->files) {
428 gnt_tree_remove_all(GNT_TREE(sel->files));
429 gnt_widget_draw(sel->files);
431 globfree(&gl);
432 #endif
433 success:
434 g_free(path);
435 return TRUE;
438 static void
439 file_sel_changed(GntWidget *widget, gpointer old, gpointer current, GntFileSel *sel)
441 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_HAS_FOCUS)) {
442 g_free(sel->suggest);
443 sel->suggest = NULL;
444 update_location(sel);
448 static void
449 gnt_file_sel_map(GntWidget *widget)
451 GntFileSel *sel = GNT_FILE_SEL(widget);
452 GntWidget *hbox, *vbox;
454 if (sel->current == NULL)
455 gnt_file_sel_set_current_location(sel, g_get_home_dir());
457 vbox = gnt_vbox_new(FALSE);
458 gnt_box_set_pad(GNT_BOX(vbox), 0);
459 gnt_box_set_alignment(GNT_BOX(vbox), GNT_ALIGN_MID);
461 /* The dir. and files list */
462 hbox = gnt_hbox_new(FALSE);
463 gnt_box_set_pad(GNT_BOX(hbox), 0);
465 gnt_box_add_widget(GNT_BOX(hbox), sel->dirs);
467 if (!sel->dirsonly) {
468 gnt_box_add_widget(GNT_BOX(hbox), sel->files);
469 } else {
470 g_signal_connect(G_OBJECT(sel->dirs), "selection_changed", G_CALLBACK(file_sel_changed), sel);
473 gnt_box_add_widget(GNT_BOX(vbox), hbox);
474 gnt_box_add_widget(GNT_BOX(vbox), sel->location);
476 /* The buttons */
477 hbox = gnt_hbox_new(FALSE);
478 gnt_box_add_widget(GNT_BOX(hbox), sel->cancel);
479 gnt_box_add_widget(GNT_BOX(hbox), sel->select);
480 gnt_box_add_widget(GNT_BOX(vbox), hbox);
482 gnt_box_add_widget(GNT_BOX(sel), vbox);
483 orig_map(widget);
484 update_location(sel);
487 static gboolean
488 toggle_tag_selection(GntBindable *bind, GList *null)
490 GntFileSel *sel = GNT_FILE_SEL(bind);
491 char *str;
492 GList *find;
493 char *file;
494 GntWidget *tree;
496 if (!sel->multiselect)
497 return FALSE;
498 tree = sel->dirsonly ? sel->dirs : sel->files;
499 if (!gnt_widget_has_focus(tree) ||
500 gnt_tree_is_searching(GNT_TREE(tree)))
501 return FALSE;
503 file = gnt_tree_get_selection_data(GNT_TREE(tree));
505 str = gnt_file_sel_get_selected_file(sel);
506 if ((find = g_list_find_custom(sel->tags, str, (GCompareFunc)g_utf8_collate)) != NULL) {
507 g_free(find->data);
508 sel->tags = g_list_delete_link(sel->tags, find);
509 gnt_tree_set_row_flags(GNT_TREE(tree), file, GNT_TEXT_FLAG_NORMAL);
510 g_free(str);
511 } else {
512 sel->tags = g_list_prepend(sel->tags, str);
513 gnt_tree_set_row_flags(GNT_TREE(tree), file, GNT_TEXT_FLAG_BOLD);
516 gnt_bindable_perform_action_named(GNT_BINDABLE(tree), "move-down", NULL);
518 return TRUE;
521 static gboolean
522 clear_tags(GntBindable *bind, GList *null)
524 GntFileSel *sel = GNT_FILE_SEL(bind);
525 GntWidget *tree;
526 GList *iter;
528 if (!sel->multiselect)
529 return FALSE;
530 tree = sel->dirsonly ? sel->dirs : sel->files;
531 if (!gnt_widget_has_focus(tree) ||
532 gnt_tree_is_searching(GNT_TREE(tree)))
533 return FALSE;
535 g_list_foreach(sel->tags, (GFunc)g_free, NULL);
536 g_list_free(sel->tags);
537 sel->tags = NULL;
539 for (iter = GNT_TREE(tree)->list; iter; iter = iter->next)
540 gnt_tree_set_row_flags(GNT_TREE(tree), iter->data, GNT_TEXT_FLAG_NORMAL);
542 return TRUE;
545 static gboolean
546 up_directory(GntBindable *bind, GList *null)
548 char *path, *dir;
549 GntFileSel *sel = GNT_FILE_SEL(bind);
550 if (!gnt_widget_has_focus(sel->dirs) &&
551 !gnt_widget_has_focus(sel->files))
552 return FALSE;
553 if (gnt_tree_is_searching(GNT_TREE(sel->dirs)) ||
554 gnt_tree_is_searching(GNT_TREE(sel->files)))
555 return FALSE;
557 path = g_build_filename(sel->current, "..", NULL);
558 dir = g_path_get_basename(sel->current);
559 if (gnt_file_sel_set_current_location(sel, path))
560 gnt_tree_set_selected(GNT_TREE(sel->dirs), dir);
561 g_free(dir);
562 g_free(path);
563 return TRUE;
566 static void
567 gnt_file_sel_size_request(GntWidget *widget)
569 GntFileSel *sel;
570 if (widget->priv.height > 0)
571 return;
573 sel = GNT_FILE_SEL(widget);
574 sel->dirs->priv.height = 16;
575 sel->files->priv.height = 16;
576 orig_size_request(widget);
579 static void
580 gnt_file_sel_class_init(GntFileSelClass *klass)
582 GntBindableClass *bindable = GNT_BINDABLE_CLASS(klass);
583 GntWidgetClass *kl = GNT_WIDGET_CLASS(klass);
584 parent_class = GNT_WINDOW_CLASS(klass);
585 kl->destroy = gnt_file_sel_destroy;
586 orig_map = kl->map;
587 kl->map = gnt_file_sel_map;
588 orig_size_request = kl->size_request;
589 kl->size_request = gnt_file_sel_size_request;
591 signals[SIG_FILE_SELECTED] =
592 g_signal_new("file_selected",
593 G_TYPE_FROM_CLASS(klass),
594 G_SIGNAL_RUN_LAST,
595 G_STRUCT_OFFSET(GntFileSelClass, file_selected),
596 NULL, NULL,
597 gnt_closure_marshal_VOID__STRING_STRING,
598 G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING);
600 gnt_bindable_class_register_action(bindable, "toggle-tag", toggle_tag_selection, "t", NULL);
601 gnt_bindable_class_register_action(bindable, "clear-tags", clear_tags, "c", NULL);
602 gnt_bindable_class_register_action(bindable, "up-directory", up_directory, GNT_KEY_BACKSPACE, NULL);
603 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass));
605 GNTDEBUG;
608 static void
609 gnt_file_sel_init(GTypeInstance *instance, gpointer class)
611 GntFileSel *sel = GNT_FILE_SEL(instance);
613 sel->dirs = gnt_tree_new();
614 gnt_tree_set_compare_func(GNT_TREE(sel->dirs), (GCompareFunc)g_utf8_collate);
615 gnt_tree_set_hash_fns(GNT_TREE(sel->dirs), g_str_hash, g_str_equal, g_free);
616 gnt_tree_set_column_titles(GNT_TREE(sel->dirs), "Directories");
617 gnt_tree_set_show_title(GNT_TREE(sel->dirs), TRUE);
618 gnt_tree_set_col_width(GNT_TREE(sel->dirs), 0, 20);
619 g_signal_connect(G_OBJECT(sel->dirs), "key_pressed", G_CALLBACK(dir_key_pressed), sel);
621 sel->files = gnt_tree_new_with_columns(2); /* Name, Size */
622 gnt_tree_set_compare_func(GNT_TREE(sel->files), (GCompareFunc)g_utf8_collate);
623 gnt_tree_set_column_titles(GNT_TREE(sel->files), "Filename", "Size");
624 gnt_tree_set_show_title(GNT_TREE(sel->files), TRUE);
625 gnt_tree_set_col_width(GNT_TREE(sel->files), 0, 25);
626 gnt_tree_set_col_width(GNT_TREE(sel->files), 1, 10);
627 gnt_tree_set_column_is_right_aligned(GNT_TREE(sel->files), 1, TRUE);
628 g_signal_connect(G_OBJECT(sel->files), "selection_changed", G_CALLBACK(file_sel_changed), sel);
630 /* The location entry */
631 sel->location = gnt_entry_new(NULL);
632 g_signal_connect(G_OBJECT(sel->location), "key_pressed", G_CALLBACK(location_key_pressed), sel);
634 sel->cancel = gnt_button_new("Cancel");
635 sel->select = gnt_button_new("Select");
637 g_signal_connect_swapped(G_OBJECT(sel->files), "activate", G_CALLBACK(gnt_widget_activate), sel->select);
638 g_signal_connect(G_OBJECT(sel->select), "activate", G_CALLBACK(select_activated_cb), sel);
641 /******************************************************************************
642 * GntFileSel API
643 *****************************************************************************/
644 GType
645 gnt_file_sel_get_gtype(void)
647 static GType type = 0;
649 if(type == 0)
651 static const GTypeInfo info = {
652 sizeof(GntFileSelClass),
653 NULL, /* base_init */
654 NULL, /* base_finalize */
655 (GClassInitFunc)gnt_file_sel_class_init,
656 NULL, /* class_finalize */
657 NULL, /* class_data */
658 sizeof(GntFileSel),
659 0, /* n_preallocs */
660 gnt_file_sel_init, /* instance_init */
661 NULL
664 type = g_type_register_static(GNT_TYPE_WINDOW,
665 "GntFileSel",
666 &info, 0);
669 return type;
672 static void
673 select_activated_cb(GntWidget *button, GntFileSel *sel)
675 char *path = gnt_file_sel_get_selected_file(sel);
676 char *file = g_path_get_basename(path);
677 g_signal_emit(sel, signals[SIG_FILE_SELECTED], 0, path, file);
678 g_free(file);
679 g_free(path);
682 GntWidget *gnt_file_sel_new(void)
684 GntWidget *widget = g_object_new(GNT_TYPE_FILE_SEL, NULL);
685 return widget;
688 gboolean gnt_file_sel_set_current_location(GntFileSel *sel, const char *path)
690 char *old;
691 GError *error = NULL;
692 gboolean ret = TRUE;
694 old = sel->current;
695 sel->current = process_path(path);
696 if (!location_changed(sel, &error)) {
697 g_error_free(error);
698 error = NULL;
699 g_free(sel->current);
700 sel->current = old;
701 location_changed(sel, &error);
702 ret = FALSE;
703 } else
704 g_free(old);
706 update_location(sel);
707 return ret;
710 void gnt_file_sel_set_dirs_only(GntFileSel *sel, gboolean dirs)
712 sel->dirsonly = dirs;
715 gboolean gnt_file_sel_get_dirs_only(GntFileSel *sel)
717 return sel->dirsonly;
720 void gnt_file_sel_set_suggested_filename(GntFileSel *sel, const char *suggest)
722 g_free(sel->suggest);
723 sel->suggest = g_strdup(suggest);
726 char *gnt_file_sel_get_selected_file(GntFileSel *sel)
728 char *ret;
729 if (sel->dirsonly) {
730 ret = g_path_get_dirname(gnt_entry_get_text(GNT_ENTRY(sel->location)));
731 } else {
732 ret = g_strdup(gnt_entry_get_text(GNT_ENTRY(sel->location)));
734 return ret;
737 void gnt_file_sel_set_must_exist(GntFileSel *sel, gboolean must)
739 /*XXX: What do I do with this? */
740 sel->must_exist = must;
743 gboolean gnt_file_sel_get_must_exist(GntFileSel *sel)
745 return sel->must_exist;
748 void gnt_file_sel_set_multi_select(GntFileSel *sel, gboolean set)
750 sel->multiselect = set;
753 GList *gnt_file_sel_get_selected_multi_files(GntFileSel *sel)
755 GList *list = NULL, *iter;
756 char *str = gnt_file_sel_get_selected_file(sel);
758 for (iter = sel->tags; iter; iter = iter->next) {
759 list = g_list_prepend(list, g_strdup(iter->data));
760 if (g_utf8_collate(str, iter->data)) {
761 g_free(str);
762 str = NULL;
765 if (str)
766 list = g_list_prepend(list, str);
767 list = g_list_reverse(list);
768 return list;
771 void gnt_file_sel_set_read_fn(GntFileSel *sel, gboolean (*read_fn)(const char *path, GList **files, GError **error))
773 sel->read_fn = read_fn;