--- a/gntfilesel.c Tue May 21 01:25:14 2019 +0000
+++ b/gntfilesel.c Tue May 21 01:33:29 2019 +0000
@@ -59,8 +59,6 @@
gboolean dirsonly; /* Show only directories */
GList *tags; /* List of tagged files when multiselect is set */
- gboolean (*read_fn)(const char *path, GList **files, GError **error);
@@ -158,79 +156,12 @@
-GntFile* gnt_file_new_dir(const char *name)
- GntFile *file = g_new0(GntFile, 1);
- file->basename = g_strdup(name);
- file->type = GNT_FILE_DIR;
-GntFile* gnt_file_new(const char *name, unsigned long size)
- GntFile *file = g_new0(GntFile, 1);
- file->basename = g_strdup(name);
- file->type = GNT_FILE_REGULAR;
-local_read_fn(const char *path, GList **files, GError **error)
- dir = g_dir_open(path, 0, error);
- if (dir == NULL || (error && *error)) {
- if (*path != '\0' && strcmp(path, G_DIR_SEPARATOR_S)) {
- file = gnt_file_new_dir("..");
- *files = g_list_prepend(*files, file);
- while ((str = g_dir_read_name(dir)) != NULL) {
- char *fp = g_build_filename(path, str, NULL);
- gnt_warning("Error stating location %s", fp);
- if (S_ISDIR(st.st_mode)) {
- file = gnt_file_new_dir(str);
- file = gnt_file_new(str, (long)st.st_size);
- *files = g_list_prepend(*files, file);
- *files = g_list_reverse(*files);
-gnt_file_free(GntFile *file)
- g_return_if_fail(file != NULL);
- g_free(file->fullpath);
- g_free(file->basename);
location_changed(GntFileSel *sel, GError **err)
GntFileSelPrivate *priv = gnt_file_sel_get_instance_private(sel);
@@ -252,50 +183,74 @@
- success = priv->read_fn(priv->current, &files, err);
- success = local_read_fn(priv->current, &files, err);
- if (!success || *err) {
+ dir = g_dir_open(priv->current, 0, err); + if (dir == NULL || *err) { gnt_warning("error opening location %s (%s)", priv->current,
*err ? (*err)->message : "reason unknown");
- for (iter = files; iter; iter = iter->next) {
- GntFile *file = iter->data;
- char *str = file->basename;
- if (file->type == GNT_FILE_DIR) {
- gnt_tree_add_row_after(
- GNT_TREE(priv->dirs), g_strdup(str),
- gnt_tree_create_row(GNT_TREE(priv->dirs), str),
- if (priv->multiselect && priv->dirsonly &&
- gnt_tree_set_row_flags(GNT_TREE(priv->dirs),
- } else if (!priv->dirsonly) {
- snprintf(size, sizeof(size), "%ld", file->size);
+ if (*priv->current != '\0' && + g_path_is_absolute(priv->current) && + *g_path_skip_root(priv->current) != '\0') { + gnt_tree_add_row_after( + GNT_TREE(priv->dirs), g_strdup(".."), + gnt_tree_create_row(GNT_TREE(priv->dirs), ".."), NULL, + if (priv->multiselect && priv->dirsonly && + is_tagged(sel, "..")) { + gnt_tree_set_row_flags(GNT_TREE(priv->dirs), "..", + while ((str = g_dir_read_name(dir)) != NULL) { + gchar *fp = g_build_filename(priv->current, str, NULL); + gnt_warning("Error stating location %s", fp); + /* Just there to silence const warnings; the key is + * suitably copied when necessary. */ + gchar *key = (gchar *)str; - gnt_tree_add_row_after(
- GNT_TREE(priv->files), g_strdup(str),
- gnt_tree_create_row(GNT_TREE(priv->files), str,
- if (priv->multiselect && is_tagged(sel, str)) {
- gnt_tree_set_row_flags(GNT_TREE(priv->files),
+ if (S_ISDIR(st.st_mode)) { + gnt_tree_add_row_after( + GNT_TREE(priv->dirs), g_strdup(str), + GNT_TREE(priv->dirs), key), + if (priv->multiselect && priv->dirsonly && + gnt_tree_set_row_flags( + GNT_TREE(priv->dirs), key, + size = g_format_size((guint64)st.st_size); + gnt_tree_add_row_after( + GNT_TREE(priv->files), g_strdup(str), + GNT_TREE(priv->files), key, + if (priv->multiselect && is_tagged(sel, str)) { + gnt_tree_set_row_flags( + GNT_TREE(priv->files), key, - g_list_free_full(files, (GDestroyNotify)gnt_file_free);
if (gnt_widget_get_mapped(GNT_WIDGET(sel))) {
gnt_widget_draw(GNT_WIDGET(sel));
@@ -786,46 +741,3 @@
list = g_list_reverse(list);
-void gnt_file_sel_set_read_fn(GntFileSel *sel, gboolean (*read_fn)(const char *path, GList **files, GError **error))
- GntFileSelPrivate *priv = NULL;
- g_return_if_fail(GNT_IS_FILE_SEL(sel));
- priv = gnt_file_sel_get_instance_private(sel);
- priv->read_fn = read_fn;
-/**************************************************************************
- **************************************************************************/
-gnt_file_copy(GntFile *file)
- g_return_val_if_fail(file != NULL, NULL);
- file_new = g_new(GntFile, 1);
- file_new->fullpath = g_strdup(file->fullpath);
- file_new->basename = g_strdup(file->basename);
- type = g_boxed_type_register_static("GntFile",
- (GBoxedCopyFunc)gnt_file_copy,
- (GBoxedFreeFunc)gnt_file_free);
--- a/gntfilesel.h Tue May 21 01:25:14 2019 +0000
+++ b/gntfilesel.h Tue May 21 01:33:29 2019 +0000
@@ -35,35 +35,6 @@
#define GNT_TYPE_FILE_SEL gnt_file_sel_get_type()
-#define GNT_TYPE_FILE gnt_file_get_type()
-#ifndef GNT_DISABLE_DEPRECATED
- * Deprecated: 2.14.0: This is an internal implementation detail. Use #GFile
- * from GIO for a similar abstraction.
- * Deprecated: 2.14.0: This is an internal implementation detail. Use #GFile
- * from GIO for a similar abstraction.
@@ -89,17 +60,6 @@
void (*gnt_reserved4)(void);
-#ifndef GNT_DISABLE_DEPRECATED
- * Returns: The #GType for the #GntFile boxed structure.
- * Deprecated: 2.14.0: This is an internal implementation detail.
-GType gnt_file_get_type(void);
@@ -201,44 +161,6 @@
void gnt_file_sel_set_suggested_filename(GntFileSel *sel, const char *suggest);
-#ifndef GNT_DISABLE_DEPRECATED
- * gnt_file_sel_set_read_fn:
- * @sel: The file selector.
- * @read_fn: The custom read function.
- * Set custom functions to read the names of files.
- * Deprecated: 2.14.0: This is an internal implementation detail.
-void gnt_file_sel_set_read_fn(GntFileSel *sel, gboolean (*read_fn)(const char *path, GList **files, GError **error));
- * @name: The name of the file.
- * @size: The size of the file.
- * Create a new GntFile.
- * Returns: The newly created GntFile.
- * Deprecated: 2.14.0: This is an internal implementation detail.
-GntFile* gnt_file_new(const char *name, unsigned long size);
- * @name: The name of the directory.
- * Create a new GntFile for a directory.
- * Returns: The newly created GntFile.
- * Deprecated: 2.14.0: This is an internal implementation detail.
-GntFile* gnt_file_new_dir(const char *name);
#endif /* GNT_FILE_SEL_H */