Update to 24f58c58bb8d22c0e8e6c5ce43c536c47b719bc6
[gnt.git] / gntfilesel.c
blob01bbdf7fd0cf785e1569ea31dbc21af16bc135a1
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);
268 g_dir_close(dir);
270 *files = g_list_reverse(*files);
271 return TRUE;
274 static void
275 gnt_file_free(GntFile *file)
277 g_free(file->fullpath);
278 g_free(file->basename);
279 g_free(file);
282 static gboolean
283 location_changed(GntFileSel *sel, GError **err)
285 GList *files, *iter;
286 gboolean success;
288 if (!sel->dirs)
289 return TRUE;
291 gnt_tree_remove_all(GNT_TREE(sel->dirs));
292 if (sel->files)
293 gnt_tree_remove_all(GNT_TREE(sel->files));
294 gnt_entry_set_text(GNT_ENTRY(sel->location), NULL);
295 if (sel->current == NULL) {
296 if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(sel), GNT_WIDGET_MAPPED))
297 gnt_widget_draw(GNT_WIDGET(sel));
298 return TRUE;
301 /* XXX:\
302 * XXX: This is blocking.
303 * XXX:/
305 files = NULL;
306 if (sel->read_fn)
307 success = sel->read_fn(sel->current, &files, err);
308 else
309 success = local_read_fn(sel->current, &files, err);
311 if (!success || *err) {
312 g_printerr("GntFileSel: error opening location %s (%s)\n",
313 sel->current, *err ? (*err)->message : "reason unknown");
314 return FALSE;
317 for (iter = files; iter; iter = iter->next) {
318 GntFile *file = iter->data;
319 char *str = file->basename;
320 if (file->type == GNT_FILE_DIR) {
321 gnt_tree_add_row_after(GNT_TREE(sel->dirs), g_strdup(str),
322 gnt_tree_create_row(GNT_TREE(sel->dirs), str), NULL, NULL);
323 if (sel->multiselect && sel->dirsonly && is_tagged(sel, str))
324 gnt_tree_set_row_flags(GNT_TREE(sel->dirs), (gpointer)str, GNT_TEXT_FLAG_BOLD);
325 } else if (!sel->dirsonly) {
326 char size[128];
327 snprintf(size, sizeof(size), "%ld", file->size);
329 gnt_tree_add_row_after(GNT_TREE(sel->files), g_strdup(str),
330 gnt_tree_create_row(GNT_TREE(sel->files), str, size, ""), NULL, NULL);
331 if (sel->multiselect && is_tagged(sel, str))
332 gnt_tree_set_row_flags(GNT_TREE(sel->files), (gpointer)str, GNT_TEXT_FLAG_BOLD);
335 g_list_foreach(files, (GFunc)gnt_file_free, NULL);
336 g_list_free(files);
337 if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(sel), GNT_WIDGET_MAPPED))
338 gnt_widget_draw(GNT_WIDGET(sel));
339 return TRUE;
342 static gboolean
343 dir_key_pressed(GntTree *tree, const char *key, GntFileSel *sel)
345 if (strcmp(key, "\r") == 0 || strcmp(key, "\n") == 0) {
346 char *str = g_strdup(gnt_tree_get_selection_data(tree));
347 char *path, *dir;
349 if (!str)
350 return TRUE;
352 path = g_build_filename(sel->current, str, NULL);
353 dir = g_path_get_basename(sel->current);
354 if (!gnt_file_sel_set_current_location(sel, path)) {
355 gnt_tree_set_selected(tree, str);
356 } else if (strcmp(str, "..") == 0) {
357 gnt_tree_set_selected(tree, dir);
359 gnt_bindable_perform_action_named(GNT_BINDABLE(tree), "end-search", NULL);
360 g_free(dir);
361 g_free(str);
362 g_free(path);
363 return TRUE;
365 return FALSE;
368 static gboolean
369 location_key_pressed(GntTree *tree, const char *key, GntFileSel *sel)
371 char *path;
372 char *str;
373 #if 0
374 int count;
375 glob_t gl;
376 struct stat st;
377 int glob_ret;
378 #endif
379 if (strcmp(key, "\r") && strcmp(key, "\n"))
380 return FALSE;
382 str = (char*)gnt_entry_get_text(GNT_ENTRY(sel->location));
383 if (*str == G_DIR_SEPARATOR)
384 path = g_strdup(str);
385 else
386 path = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", sel->current, str);
387 str = process_path(path);
388 g_free(path);
389 path = str;
391 if (gnt_file_sel_set_current_location(sel, path))
392 goto success;
394 path = g_path_get_dirname(str);
395 g_free(str);
397 if (!gnt_file_sel_set_current_location(sel, path)) {
398 g_free(path);
399 return FALSE;
401 #if 0
402 /* XXX: there needs to be a way to allow other methods for globbing,
403 * like the read_fn stuff. */
404 glob_ret = glob(path, GLOB_MARK, NULL, &gl);
405 if (!glob_ret) { /* XXX: do something with the return value */
406 char *loc = g_path_get_dirname(gl.gl_pathv[0]);
408 stat(gl.gl_pathv[0], &st);
409 gnt_file_sel_set_current_location(sel, loc); /* XXX: check the return value */
410 g_free(loc);
411 if (!S_ISDIR(st.st_mode) && !sel->dirsonly) {
412 gnt_tree_remove_all(GNT_TREE(sel->files));
413 for (count = 0; count < gl.gl_pathc; count++) {
414 char *tmp = process_path(gl.gl_pathv[count]);
415 loc = g_path_get_dirname(tmp);
416 if (g_utf8_collate(sel->current, loc) == 0) {
417 char *base = g_path_get_basename(tmp);
418 char size[128];
419 snprintf(size, sizeof(size), "%ld", (long)st.st_size);
420 gnt_tree_add_row_after(GNT_TREE(sel->files), base,
421 gnt_tree_create_row(GNT_TREE(sel->files), base, size, ""), NULL, NULL);
423 g_free(loc);
424 g_free(tmp);
426 gnt_widget_draw(sel->files);
428 } else if (sel->files) {
429 gnt_tree_remove_all(GNT_TREE(sel->files));
430 gnt_widget_draw(sel->files);
432 globfree(&gl);
433 #endif
434 success:
435 g_free(path);
436 return TRUE;
439 static void
440 file_sel_changed(GntWidget *widget, gpointer old, gpointer current, GntFileSel *sel)
442 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_HAS_FOCUS)) {
443 g_free(sel->suggest);
444 sel->suggest = NULL;
445 update_location(sel);
449 static void
450 gnt_file_sel_map(GntWidget *widget)
452 GntFileSel *sel = GNT_FILE_SEL(widget);
453 GntWidget *hbox, *vbox;
455 if (sel->current == NULL)
456 gnt_file_sel_set_current_location(sel, g_get_home_dir());
458 vbox = gnt_vbox_new(FALSE);
459 gnt_box_set_pad(GNT_BOX(vbox), 0);
460 gnt_box_set_alignment(GNT_BOX(vbox), GNT_ALIGN_MID);
462 /* The dir. and files list */
463 hbox = gnt_hbox_new(FALSE);
464 gnt_box_set_pad(GNT_BOX(hbox), 0);
466 gnt_box_add_widget(GNT_BOX(hbox), sel->dirs);
468 if (!sel->dirsonly) {
469 gnt_box_add_widget(GNT_BOX(hbox), sel->files);
470 } else {
471 g_signal_connect(G_OBJECT(sel->dirs), "selection_changed", G_CALLBACK(file_sel_changed), sel);
474 gnt_box_add_widget(GNT_BOX(vbox), hbox);
475 gnt_box_add_widget(GNT_BOX(vbox), sel->location);
477 /* The buttons */
478 hbox = gnt_hbox_new(FALSE);
479 gnt_box_add_widget(GNT_BOX(hbox), sel->cancel);
480 gnt_box_add_widget(GNT_BOX(hbox), sel->select);
481 gnt_box_add_widget(GNT_BOX(vbox), hbox);
483 gnt_box_add_widget(GNT_BOX(sel), vbox);
484 orig_map(widget);
485 update_location(sel);
488 static gboolean
489 toggle_tag_selection(GntBindable *bind, GList *null)
491 GntFileSel *sel = GNT_FILE_SEL(bind);
492 char *str;
493 GList *find;
494 char *file;
495 GntWidget *tree;
497 if (!sel->multiselect)
498 return FALSE;
499 tree = sel->dirsonly ? sel->dirs : sel->files;
500 if (!gnt_widget_has_focus(tree) ||
501 gnt_tree_is_searching(GNT_TREE(tree)))
502 return FALSE;
504 file = gnt_tree_get_selection_data(GNT_TREE(tree));
506 str = gnt_file_sel_get_selected_file(sel);
507 if ((find = g_list_find_custom(sel->tags, str, (GCompareFunc)g_utf8_collate)) != NULL) {
508 g_free(find->data);
509 sel->tags = g_list_delete_link(sel->tags, find);
510 gnt_tree_set_row_flags(GNT_TREE(tree), file, GNT_TEXT_FLAG_NORMAL);
511 g_free(str);
512 } else {
513 sel->tags = g_list_prepend(sel->tags, str);
514 gnt_tree_set_row_flags(GNT_TREE(tree), file, GNT_TEXT_FLAG_BOLD);
517 gnt_bindable_perform_action_named(GNT_BINDABLE(tree), "move-down", NULL);
519 return TRUE;
522 static gboolean
523 clear_tags(GntBindable *bind, GList *null)
525 GntFileSel *sel = GNT_FILE_SEL(bind);
526 GntWidget *tree;
527 GList *iter;
529 if (!sel->multiselect)
530 return FALSE;
531 tree = sel->dirsonly ? sel->dirs : sel->files;
532 if (!gnt_widget_has_focus(tree) ||
533 gnt_tree_is_searching(GNT_TREE(tree)))
534 return FALSE;
536 g_list_foreach(sel->tags, (GFunc)g_free, NULL);
537 g_list_free(sel->tags);
538 sel->tags = NULL;
540 for (iter = GNT_TREE(tree)->list; iter; iter = iter->next)
541 gnt_tree_set_row_flags(GNT_TREE(tree), iter->data, GNT_TEXT_FLAG_NORMAL);
543 return TRUE;
546 static gboolean
547 up_directory(GntBindable *bind, GList *null)
549 char *path, *dir;
550 GntFileSel *sel = GNT_FILE_SEL(bind);
551 if (!gnt_widget_has_focus(sel->dirs) &&
552 !gnt_widget_has_focus(sel->files))
553 return FALSE;
554 if (gnt_tree_is_searching(GNT_TREE(sel->dirs)) ||
555 gnt_tree_is_searching(GNT_TREE(sel->files)))
556 return FALSE;
558 path = g_build_filename(sel->current, "..", NULL);
559 dir = g_path_get_basename(sel->current);
560 if (gnt_file_sel_set_current_location(sel, path))
561 gnt_tree_set_selected(GNT_TREE(sel->dirs), dir);
562 g_free(dir);
563 g_free(path);
564 return TRUE;
567 static void
568 gnt_file_sel_size_request(GntWidget *widget)
570 GntFileSel *sel;
571 if (widget->priv.height > 0)
572 return;
574 sel = GNT_FILE_SEL(widget);
575 sel->dirs->priv.height = 16;
576 sel->files->priv.height = 16;
577 orig_size_request(widget);
580 static void
581 gnt_file_sel_class_init(GntFileSelClass *klass)
583 GntBindableClass *bindable = GNT_BINDABLE_CLASS(klass);
584 GntWidgetClass *kl = GNT_WIDGET_CLASS(klass);
585 parent_class = GNT_WINDOW_CLASS(klass);
586 kl->destroy = gnt_file_sel_destroy;
587 orig_map = kl->map;
588 kl->map = gnt_file_sel_map;
589 orig_size_request = kl->size_request;
590 kl->size_request = gnt_file_sel_size_request;
592 signals[SIG_FILE_SELECTED] =
593 g_signal_new("file_selected",
594 G_TYPE_FROM_CLASS(klass),
595 G_SIGNAL_RUN_LAST,
596 G_STRUCT_OFFSET(GntFileSelClass, file_selected),
597 NULL, NULL,
598 gnt_closure_marshal_VOID__STRING_STRING,
599 G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING);
601 gnt_bindable_class_register_action(bindable, "toggle-tag", toggle_tag_selection, "t", NULL);
602 gnt_bindable_class_register_action(bindable, "clear-tags", clear_tags, "c", NULL);
603 gnt_bindable_class_register_action(bindable, "up-directory", up_directory, GNT_KEY_BACKSPACE, NULL);
604 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass));
606 GNTDEBUG;
609 static void
610 gnt_file_sel_init(GTypeInstance *instance, gpointer class)
612 GntFileSel *sel = GNT_FILE_SEL(instance);
614 sel->dirs = gnt_tree_new();
615 gnt_tree_set_compare_func(GNT_TREE(sel->dirs), (GCompareFunc)g_utf8_collate);
616 gnt_tree_set_hash_fns(GNT_TREE(sel->dirs), g_str_hash, g_str_equal, g_free);
617 gnt_tree_set_column_titles(GNT_TREE(sel->dirs), "Directories");
618 gnt_tree_set_show_title(GNT_TREE(sel->dirs), TRUE);
619 gnt_tree_set_col_width(GNT_TREE(sel->dirs), 0, 20);
620 g_signal_connect(G_OBJECT(sel->dirs), "key_pressed", G_CALLBACK(dir_key_pressed), sel);
622 sel->files = gnt_tree_new_with_columns(2); /* Name, Size */
623 gnt_tree_set_compare_func(GNT_TREE(sel->files), (GCompareFunc)g_utf8_collate);
624 gnt_tree_set_column_titles(GNT_TREE(sel->files), "Filename", "Size");
625 gnt_tree_set_show_title(GNT_TREE(sel->files), TRUE);
626 gnt_tree_set_col_width(GNT_TREE(sel->files), 0, 25);
627 gnt_tree_set_col_width(GNT_TREE(sel->files), 1, 10);
628 gnt_tree_set_column_is_right_aligned(GNT_TREE(sel->files), 1, TRUE);
629 g_signal_connect(G_OBJECT(sel->files), "selection_changed", G_CALLBACK(file_sel_changed), sel);
631 /* The location entry */
632 sel->location = gnt_entry_new(NULL);
633 g_signal_connect(G_OBJECT(sel->location), "key_pressed", G_CALLBACK(location_key_pressed), sel);
635 sel->cancel = gnt_button_new("Cancel");
636 sel->select = gnt_button_new("Select");
638 g_signal_connect_swapped(G_OBJECT(sel->files), "activate", G_CALLBACK(gnt_widget_activate), sel->select);
639 g_signal_connect(G_OBJECT(sel->select), "activate", G_CALLBACK(select_activated_cb), sel);
642 /******************************************************************************
643 * GntFileSel API
644 *****************************************************************************/
645 GType
646 gnt_file_sel_get_gtype(void)
648 static GType type = 0;
650 if(type == 0)
652 static const GTypeInfo info = {
653 sizeof(GntFileSelClass),
654 NULL, /* base_init */
655 NULL, /* base_finalize */
656 (GClassInitFunc)gnt_file_sel_class_init,
657 NULL, /* class_finalize */
658 NULL, /* class_data */
659 sizeof(GntFileSel),
660 0, /* n_preallocs */
661 gnt_file_sel_init, /* instance_init */
662 NULL
665 type = g_type_register_static(GNT_TYPE_WINDOW,
666 "GntFileSel",
667 &info, 0);
670 return type;
673 static void
674 select_activated_cb(GntWidget *button, GntFileSel *sel)
676 char *path = gnt_file_sel_get_selected_file(sel);
677 char *file = g_path_get_basename(path);
678 g_signal_emit(sel, signals[SIG_FILE_SELECTED], 0, path, file);
679 g_free(file);
680 g_free(path);
683 GntWidget *gnt_file_sel_new(void)
685 GntWidget *widget = g_object_new(GNT_TYPE_FILE_SEL, NULL);
686 return widget;
689 gboolean gnt_file_sel_set_current_location(GntFileSel *sel, const char *path)
691 char *old;
692 GError *error = NULL;
693 gboolean ret = TRUE;
695 old = sel->current;
696 sel->current = process_path(path);
697 if (!location_changed(sel, &error)) {
698 g_error_free(error);
699 error = NULL;
700 g_free(sel->current);
701 sel->current = old;
702 location_changed(sel, &error);
703 ret = FALSE;
704 } else
705 g_free(old);
707 update_location(sel);
708 return ret;
711 void gnt_file_sel_set_dirs_only(GntFileSel *sel, gboolean dirs)
713 sel->dirsonly = dirs;
716 gboolean gnt_file_sel_get_dirs_only(GntFileSel *sel)
718 return sel->dirsonly;
721 void gnt_file_sel_set_suggested_filename(GntFileSel *sel, const char *suggest)
723 g_free(sel->suggest);
724 sel->suggest = g_strdup(suggest);
727 char *gnt_file_sel_get_selected_file(GntFileSel *sel)
729 char *ret;
730 if (sel->dirsonly) {
731 ret = g_path_get_dirname(gnt_entry_get_text(GNT_ENTRY(sel->location)));
732 } else {
733 ret = g_strdup(gnt_entry_get_text(GNT_ENTRY(sel->location)));
735 return ret;
738 void gnt_file_sel_set_must_exist(GntFileSel *sel, gboolean must)
740 /*XXX: What do I do with this? */
741 sel->must_exist = must;
744 gboolean gnt_file_sel_get_must_exist(GntFileSel *sel)
746 return sel->must_exist;
749 void gnt_file_sel_set_multi_select(GntFileSel *sel, gboolean set)
751 sel->multiselect = set;
754 GList *gnt_file_sel_get_selected_multi_files(GntFileSel *sel)
756 GList *list = NULL, *iter;
757 char *str = gnt_file_sel_get_selected_file(sel);
759 for (iter = sel->tags; iter; iter = iter->next) {
760 list = g_list_prepend(list, g_strdup(iter->data));
761 if (g_utf8_collate(str, iter->data)) {
762 g_free(str);
763 str = NULL;
766 if (str)
767 list = g_list_prepend(list, str);
768 list = g_list_reverse(list);
769 return list;
772 void gnt_file_sel_set_read_fn(GntFileSel *sel, gboolean (*read_fn)(const char *path, GList **files, GError **error))
774 sel->read_fn = read_fn;