Normalize directories paths; moo_folder_get_parent()
This commit is contained in:
parent
9cebfb590b
commit
ffe2e1e672
@ -227,7 +227,6 @@ MooFolder *moo_folder_new (MooFileSystem *fs,
|
|||||||
MooFileFlags wanted,
|
MooFileFlags wanted,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
char *norm_path;
|
|
||||||
GDir *dir;
|
GDir *dir;
|
||||||
MooFolder *folder;
|
MooFolder *folder;
|
||||||
GError *file_error = NULL;
|
GError *file_error = NULL;
|
||||||
@ -235,10 +234,8 @@ MooFolder *moo_folder_new (MooFileSystem *fs,
|
|||||||
g_return_val_if_fail (MOO_IS_FILE_SYSTEM (fs), NULL);
|
g_return_val_if_fail (MOO_IS_FILE_SYSTEM (fs), NULL);
|
||||||
|
|
||||||
g_return_val_if_fail (path != NULL, NULL);
|
g_return_val_if_fail (path != NULL, NULL);
|
||||||
norm_path = moo_normalize_path (path);
|
|
||||||
g_return_val_if_fail (norm_path != NULL, NULL);
|
|
||||||
|
|
||||||
dir = g_dir_open (norm_path, 0, &file_error);
|
dir = g_dir_open (path, 0, &file_error);
|
||||||
|
|
||||||
if (!dir)
|
if (!dir)
|
||||||
{
|
{
|
||||||
@ -274,13 +271,12 @@ MooFolder *moo_folder_new (MooFileSystem *fs,
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_error_free (file_error);
|
g_error_free (file_error);
|
||||||
g_free (norm_path);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
folder = g_object_new (MOO_TYPE_FOLDER, NULL);
|
folder = g_object_new (MOO_TYPE_FOLDER, NULL);
|
||||||
folder->priv->fs = fs;
|
folder->priv->fs = fs;
|
||||||
folder->priv->path = norm_path;
|
folder->priv->path = g_strdup (path);
|
||||||
|
|
||||||
folder->priv->dir = dir;
|
folder->priv->dir = dir;
|
||||||
|
|
||||||
@ -678,6 +674,22 @@ MooFile *moo_folder_get_file (MooFolder *folder,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MooFolder *moo_folder_get_parent (MooFolder *folder,
|
||||||
|
MooFileFlags wanted)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (MOO_IS_FOLDER (folder), NULL);
|
||||||
|
return moo_file_system_get_parent_folder (folder->priv->fs,
|
||||||
|
folder, wanted);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MooFileSystem *moo_folder_get_file_system (MooFolder *folder)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (MOO_IS_FOLDER (folder), NULL);
|
||||||
|
return folder->priv->fs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/********************************************************************/
|
/********************************************************************/
|
||||||
/* MooFile
|
/* MooFile
|
||||||
*/
|
*/
|
||||||
@ -810,12 +822,6 @@ gboolean moo_file_test (const MooFile *file,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *moo_normalize_path (const char *path)
|
|
||||||
{
|
|
||||||
return g_strdup (path);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const char *moo_file_get_display_basename (const MooFile *file)
|
const char *moo_file_get_display_basename (const MooFile *file)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (file != NULL, NULL);
|
g_return_val_if_fail (file != NULL, NULL);
|
||||||
|
@ -117,8 +117,6 @@ GType moo_file_flags_get_type (void) G_GNUC_CONST;
|
|||||||
GType moo_file_info_get_type (void) G_GNUC_CONST;
|
GType moo_file_info_get_type (void) G_GNUC_CONST;
|
||||||
GType moo_folder_get_type (void) G_GNUC_CONST;
|
GType moo_folder_get_type (void) G_GNUC_CONST;
|
||||||
|
|
||||||
char *moo_normalize_path (const char *path);
|
|
||||||
|
|
||||||
MooFile *moo_file_ref (MooFile *file);
|
MooFile *moo_file_ref (MooFile *file);
|
||||||
void moo_file_unref (MooFile *file);
|
void moo_file_unref (MooFile *file);
|
||||||
|
|
||||||
@ -138,11 +136,15 @@ GdkPixbuf *moo_file_get_icon (const MooFile *file,
|
|||||||
GtkIconSize size);
|
GtkIconSize size);
|
||||||
|
|
||||||
|
|
||||||
const char *moo_folder_get_path (MooFolder *folder);
|
const char *moo_folder_get_path (MooFolder *folder);
|
||||||
/* list should be freed and elements unref'ed */
|
/* list should be freed and elements unref'ed */
|
||||||
GSList *moo_folder_list_files (MooFolder *folder);
|
GSList *moo_folder_list_files (MooFolder *folder);
|
||||||
MooFile *moo_folder_get_file (MooFolder *folder,
|
MooFile *moo_folder_get_file (MooFolder *folder,
|
||||||
const char *basename);
|
const char *basename);
|
||||||
|
/* result should be unref'ed */
|
||||||
|
MooFolder *moo_folder_get_parent (MooFolder *folder,
|
||||||
|
MooFileFlags wanted);
|
||||||
|
char *moo_folder_get_parent_path (MooFolder *folder);
|
||||||
|
|
||||||
|
|
||||||
#ifdef MOO_FILE_SYSTEM_COMPILATION
|
#ifdef MOO_FILE_SYSTEM_COMPILATION
|
||||||
|
@ -28,23 +28,31 @@ static MooFileSystem *fs_instance = NULL;
|
|||||||
|
|
||||||
static void moo_file_system_finalize (GObject *object);
|
static void moo_file_system_finalize (GObject *object);
|
||||||
|
|
||||||
static MooFolder*get_folder_default (MooFileSystem *fs,
|
static MooFolder *get_folder_default (MooFileSystem *fs,
|
||||||
const char *path,
|
const char *path,
|
||||||
MooFileFlags wanted,
|
MooFileFlags wanted,
|
||||||
GError **error);
|
GError **error);
|
||||||
static gboolean create_folder_default (MooFileSystem *fs,
|
static MooFolder *get_parent_folder_default (MooFileSystem *fs,
|
||||||
const char *path,
|
MooFolder *folder,
|
||||||
GError **error);
|
MooFileFlags flags);
|
||||||
static gboolean delete_file_default (MooFileSystem *fs,
|
|
||||||
const char *path,
|
// static gboolean create_folder_default (MooFileSystem *fs,
|
||||||
GError **error);
|
// const char *path,
|
||||||
static char *get_parent_default (MooFileSystem *fs,
|
// GError **error);
|
||||||
const char *path,
|
// static gboolean delete_file_default (MooFileSystem *fs,
|
||||||
GError **error);
|
// const char *path,
|
||||||
static char *make_path_default (MooFileSystem *fs,
|
// GError **error);
|
||||||
const char *base_path,
|
// static char *get_parent_default (MooFileSystem *fs,
|
||||||
const char *display_name,
|
// const char *path,
|
||||||
GError **error);
|
// GError **error);
|
||||||
|
// static char *make_path_default (MooFileSystem *fs,
|
||||||
|
// const char *base_path,
|
||||||
|
// const char *display_name,
|
||||||
|
// GError **error);
|
||||||
|
|
||||||
|
static char *normalize_folder_path (const char *path);
|
||||||
|
static char *normalize_path (const char *path);
|
||||||
|
static char *normalize_path_unix (const char *path);
|
||||||
|
|
||||||
|
|
||||||
/* MOO_TYPE_FILE_SYSTEM */
|
/* MOO_TYPE_FILE_SYSTEM */
|
||||||
@ -67,10 +75,11 @@ static void moo_file_system_class_init (MooFileSystemClass *klass)
|
|||||||
gobject_class->finalize = moo_file_system_finalize;
|
gobject_class->finalize = moo_file_system_finalize;
|
||||||
|
|
||||||
klass->get_folder = get_folder_default;
|
klass->get_folder = get_folder_default;
|
||||||
klass->create_folder = create_folder_default;
|
klass->get_parent_folder = get_parent_folder_default;
|
||||||
klass->delete_file = delete_file_default;
|
// klass->create_folder = create_folder_default;
|
||||||
klass->get_parent = get_parent_default;
|
// klass->delete_file = delete_file_default;
|
||||||
klass->make_path = make_path_default;
|
// klass->get_parent = get_parent_default;
|
||||||
|
// klass->make_path = make_path_default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -116,41 +125,52 @@ MooFolder *moo_file_system_get_folder (MooFileSystem *fs,
|
|||||||
MooFileFlags wanted,
|
MooFileFlags wanted,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
|
g_return_val_if_fail (MOO_IS_FILE_SYSTEM (fs), NULL);
|
||||||
return MOO_FILE_SYSTEM_GET_CLASS(fs)->get_folder (fs, path, wanted, error);
|
return MOO_FILE_SYSTEM_GET_CLASS(fs)->get_folder (fs, path, wanted, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
gboolean moo_file_system_create_folder (MooFileSystem *fs,
|
MooFolder *moo_file_system_get_parent_folder (MooFileSystem *fs,
|
||||||
const char *path,
|
MooFolder *folder,
|
||||||
GError **error)
|
MooFileFlags wanted)
|
||||||
{
|
{
|
||||||
return MOO_FILE_SYSTEM_GET_CLASS(fs)->create_folder (fs, path, error);
|
g_return_val_if_fail (MOO_IS_FILE_SYSTEM (fs), NULL);
|
||||||
|
g_return_val_if_fail (MOO_IS_FOLDER (folder), NULL);
|
||||||
|
return MOO_FILE_SYSTEM_GET_CLASS(fs)->get_parent_folder (fs, folder, wanted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
gboolean moo_file_system_delete_file(MooFileSystem *fs,
|
// gboolean moo_file_system_create_folder (MooFileSystem *fs,
|
||||||
const char *path,
|
// const char *path,
|
||||||
GError **error)
|
// GError **error)
|
||||||
{
|
// {
|
||||||
return MOO_FILE_SYSTEM_GET_CLASS(fs)->delete_file (fs, path, error);
|
// return MOO_FILE_SYSTEM_GET_CLASS(fs)->create_folder (fs, path, error);
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
char *moo_file_system_get_parent (MooFileSystem *fs,
|
// gboolean moo_file_system_delete_file(MooFileSystem *fs,
|
||||||
const char *path,
|
// const char *path,
|
||||||
GError **error)
|
// GError **error)
|
||||||
{
|
// {
|
||||||
return MOO_FILE_SYSTEM_GET_CLASS(fs)->get_parent (fs, path, error);
|
// return MOO_FILE_SYSTEM_GET_CLASS(fs)->delete_file (fs, path, error);
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
char *moo_file_system_make_path (MooFileSystem *fs,
|
// char *moo_file_system_get_parent (MooFileSystem *fs,
|
||||||
const char *base_path,
|
// const char *path,
|
||||||
const char *display_name,
|
// GError **error)
|
||||||
GError **error)
|
// {
|
||||||
{
|
// return MOO_FILE_SYSTEM_GET_CLASS(fs)->get_parent (fs, path, error);
|
||||||
return MOO_FILE_SYSTEM_GET_CLASS(fs)->make_path (fs, base_path, display_name, error);
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
|
// char *moo_file_system_make_path (MooFileSystem *fs,
|
||||||
|
// const char *base_path,
|
||||||
|
// const char *display_name,
|
||||||
|
// GError **error)
|
||||||
|
// {
|
||||||
|
// return MOO_FILE_SYSTEM_GET_CLASS(fs)->make_path (fs, base_path, display_name, error);
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
@ -163,11 +183,18 @@ MooFolder *get_folder_default (MooFileSystem *fs,
|
|||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
MooFolder *folder;
|
MooFolder *folder;
|
||||||
|
char *norm_path;
|
||||||
|
|
||||||
g_return_val_if_fail (path != NULL, NULL);
|
g_return_val_if_fail (path != NULL, NULL);
|
||||||
|
|
||||||
|
/* TODO: this is not gonna work on windows, where '' is the 'root',
|
||||||
|
containing drives */
|
||||||
g_return_val_if_fail (g_path_is_absolute (path), NULL);
|
g_return_val_if_fail (g_path_is_absolute (path), NULL);
|
||||||
|
|
||||||
folder = g_hash_table_lookup (fs->priv->folders, path);
|
norm_path = normalize_folder_path (path);
|
||||||
|
g_return_val_if_fail (norm_path != NULL, NULL);
|
||||||
|
|
||||||
|
folder = g_hash_table_lookup (fs->priv->folders, norm_path);
|
||||||
|
|
||||||
if (folder)
|
if (folder)
|
||||||
{
|
{
|
||||||
@ -176,79 +203,103 @@ MooFolder *get_folder_default (MooFileSystem *fs,
|
|||||||
return folder;
|
return folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!g_file_test (path, G_FILE_TEST_IS_DIR))
|
if (!g_file_test (norm_path, G_FILE_TEST_IS_DIR))
|
||||||
{
|
{
|
||||||
g_set_error (error, MOO_FILE_ERROR,
|
g_set_error (error, MOO_FILE_ERROR,
|
||||||
MOO_FILE_ERROR_NOT_FOLDER,
|
MOO_FILE_ERROR_NOT_FOLDER,
|
||||||
"'%s' is not a folder", path);
|
"'%s' is not a folder", norm_path);
|
||||||
|
g_free (norm_path);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
folder = moo_folder_new (fs, path, wanted, error);
|
folder = moo_folder_new (fs, norm_path, wanted, error);
|
||||||
|
|
||||||
if (folder)
|
if (folder)
|
||||||
g_hash_table_insert (fs->priv->folders,
|
g_hash_table_insert (fs->priv->folders,
|
||||||
g_strdup (path),
|
g_strdup (norm_path),
|
||||||
g_object_ref (folder));
|
g_object_ref (folder));
|
||||||
|
|
||||||
|
g_free (norm_path);
|
||||||
return folder;
|
return folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static gboolean create_folder_default (G_GNUC_UNUSED MooFileSystem *fs,
|
static MooFolder *get_parent_folder_default (MooFileSystem *fs,
|
||||||
const char *path,
|
MooFolder *folder,
|
||||||
GError **error)
|
MooFileFlags wanted)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (path != NULL, FALSE);
|
char *parent_path;
|
||||||
g_return_val_if_fail (g_path_is_absolute (path), FALSE);
|
MooFolder *parent;
|
||||||
g_set_error (error, MOO_FILE_ERROR,
|
|
||||||
MOO_FILE_ERROR_NOT_IMPLEMENTED,
|
g_return_val_if_fail (MOO_IS_FILE_SYSTEM (fs), NULL);
|
||||||
"don't know how to create folder '%s'", path);
|
g_return_val_if_fail (MOO_IS_FOLDER (folder), NULL);
|
||||||
return FALSE;
|
g_return_val_if_fail (moo_folder_get_file_system (folder) == fs, NULL);
|
||||||
|
|
||||||
|
parent_path = g_strdup_printf ("%s/..", moo_folder_get_path (folder));
|
||||||
|
|
||||||
|
parent = moo_file_system_get_folder (fs, parent_path, wanted, NULL);
|
||||||
|
g_assert (parent != NULL);
|
||||||
|
|
||||||
|
g_free (parent_path);
|
||||||
|
|
||||||
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static gboolean delete_file_default (G_GNUC_UNUSED MooFileSystem *fs,
|
// static gboolean create_folder_default (G_GNUC_UNUSED MooFileSystem *fs,
|
||||||
const char *path,
|
// const char *path,
|
||||||
GError **error)
|
// GError **error)
|
||||||
{
|
// {
|
||||||
g_return_val_if_fail (path != NULL, FALSE);
|
// g_return_val_if_fail (path != NULL, FALSE);
|
||||||
g_return_val_if_fail (g_path_is_absolute (path), FALSE);
|
// g_return_val_if_fail (g_path_is_absolute (path), FALSE);
|
||||||
g_set_error (error, MOO_FILE_ERROR,
|
// g_set_error (error, MOO_FILE_ERROR,
|
||||||
MOO_FILE_ERROR_NOT_IMPLEMENTED,
|
// MOO_FILE_ERROR_NOT_IMPLEMENTED,
|
||||||
"don't know how to delete file '%s'", path);
|
// "don't know how to create folder '%s'", path);
|
||||||
return FALSE;
|
// return FALSE;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
static char *get_parent_default (G_GNUC_UNUSED MooFileSystem *fs,
|
// static gboolean delete_file_default (G_GNUC_UNUSED MooFileSystem *fs,
|
||||||
const char *path,
|
// const char *path,
|
||||||
GError **error)
|
// GError **error)
|
||||||
{
|
// {
|
||||||
g_return_val_if_fail (path != NULL, NULL);
|
// g_return_val_if_fail (path != NULL, FALSE);
|
||||||
g_return_val_if_fail (g_path_is_absolute (path), NULL);
|
// g_return_val_if_fail (g_path_is_absolute (path), FALSE);
|
||||||
g_set_error (error, MOO_FILE_ERROR,
|
// g_set_error (error, MOO_FILE_ERROR,
|
||||||
MOO_FILE_ERROR_NOT_IMPLEMENTED,
|
// MOO_FILE_ERROR_NOT_IMPLEMENTED,
|
||||||
"don't know how to delete file '%s'", path);
|
// "don't know how to delete file '%s'", path);
|
||||||
return NULL;
|
// return FALSE;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
static char *make_path_default (G_GNUC_UNUSED MooFileSystem *fs,
|
// static char *get_parent_default (G_GNUC_UNUSED MooFileSystem *fs,
|
||||||
const char *base_path,
|
// const char *path,
|
||||||
const char *display_name,
|
// GError **error)
|
||||||
GError **error)
|
// {
|
||||||
{
|
// g_return_val_if_fail (path != NULL, NULL);
|
||||||
g_return_val_if_fail (base_path != NULL, NULL);
|
// g_return_val_if_fail (g_path_is_absolute (path), NULL);
|
||||||
g_return_val_if_fail (display_name != NULL, NULL);
|
// g_set_error (error, MOO_FILE_ERROR,
|
||||||
g_return_val_if_fail (g_path_is_absolute (base_path), NULL);
|
// MOO_FILE_ERROR_NOT_IMPLEMENTED,
|
||||||
|
// "don't know how to delete file '%s'", path);
|
||||||
g_set_error (error, MOO_FILE_ERROR,
|
// return NULL;
|
||||||
MOO_FILE_ERROR_NOT_IMPLEMENTED,
|
// }
|
||||||
"don't know how to make path of '%s' and '%s'",
|
//
|
||||||
base_path, display_name);
|
//
|
||||||
return NULL;
|
// static char *make_path_default (G_GNUC_UNUSED MooFileSystem *fs,
|
||||||
}
|
// const char *base_path,
|
||||||
|
// const char *display_name,
|
||||||
|
// GError **error)
|
||||||
|
// {
|
||||||
|
// g_return_val_if_fail (base_path != NULL, NULL);
|
||||||
|
// g_return_val_if_fail (display_name != NULL, NULL);
|
||||||
|
// g_return_val_if_fail (g_path_is_absolute (base_path), NULL);
|
||||||
|
//
|
||||||
|
// g_set_error (error, MOO_FILE_ERROR,
|
||||||
|
// MOO_FILE_ERROR_NOT_IMPLEMENTED,
|
||||||
|
// "don't know how to make path of '%s' and '%s'",
|
||||||
|
// base_path, display_name);
|
||||||
|
// return NULL;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
GQuark moo_file_error_quark (void)
|
GQuark moo_file_error_quark (void)
|
||||||
@ -258,3 +309,119 @@ GQuark moo_file_error_quark (void)
|
|||||||
quark = g_quark_from_static_string ("moo-file-error-quark");
|
quark = g_quark_from_static_string ("moo-file-error-quark");
|
||||||
return quark;
|
return quark;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static char *normalize_path_unix (const char *path)
|
||||||
|
{
|
||||||
|
GPtrArray *comps;
|
||||||
|
gboolean first_slash;
|
||||||
|
char **pieces, **p;
|
||||||
|
char *normpath;
|
||||||
|
|
||||||
|
g_return_val_if_fail (path != NULL, NULL);
|
||||||
|
|
||||||
|
first_slash = (path[0] == '/');
|
||||||
|
|
||||||
|
pieces = g_strsplit (path, "/", 0);
|
||||||
|
g_return_val_if_fail (pieces != NULL, NULL);
|
||||||
|
|
||||||
|
comps = g_ptr_array_new ();
|
||||||
|
|
||||||
|
for (p = pieces; *p != NULL; ++p)
|
||||||
|
{
|
||||||
|
char *s = *p;
|
||||||
|
gboolean push = TRUE;
|
||||||
|
gboolean pop = FALSE;
|
||||||
|
|
||||||
|
if (!strcmp (s, "") || !strcmp (s, "."))
|
||||||
|
{
|
||||||
|
push = FALSE;
|
||||||
|
}
|
||||||
|
else if (!strcmp (s, ".."))
|
||||||
|
{
|
||||||
|
if (!comps->len && first_slash)
|
||||||
|
{
|
||||||
|
push = FALSE;
|
||||||
|
}
|
||||||
|
else if (comps->len)
|
||||||
|
{
|
||||||
|
push = FALSE;
|
||||||
|
pop = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pop)
|
||||||
|
{
|
||||||
|
g_free (comps->pdata[comps->len - 1]);
|
||||||
|
g_ptr_array_remove_index (comps, comps->len - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (push)
|
||||||
|
g_ptr_array_add (comps, g_strdup (s));
|
||||||
|
}
|
||||||
|
|
||||||
|
g_ptr_array_add (comps, NULL);
|
||||||
|
|
||||||
|
if (comps->len == 1)
|
||||||
|
{
|
||||||
|
if (first_slash)
|
||||||
|
normpath = g_strdup ("/");
|
||||||
|
else
|
||||||
|
normpath = g_strdup ("");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char *tmp = g_strjoinv ("/", (char**) comps->pdata);
|
||||||
|
|
||||||
|
if (first_slash)
|
||||||
|
{
|
||||||
|
normpath = g_strdup_printf ("/%s", tmp);
|
||||||
|
g_free (tmp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
normpath = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
g_strfreev (pieces);
|
||||||
|
g_strfreev ((char**) comps->pdata);
|
||||||
|
g_ptr_array_free (comps, FALSE);
|
||||||
|
|
||||||
|
return normpath;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static char *normalize_path (const char *path)
|
||||||
|
{
|
||||||
|
return normalize_path_unix (path);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static char *normalize_folder_path (const char *path)
|
||||||
|
{
|
||||||
|
guint len;
|
||||||
|
char *normpath, *tmp;
|
||||||
|
|
||||||
|
g_return_val_if_fail (path != NULL, NULL);
|
||||||
|
|
||||||
|
tmp = normalize_path (path);
|
||||||
|
len = strlen (tmp);
|
||||||
|
g_return_val_if_fail (len > 0, tmp);
|
||||||
|
|
||||||
|
if (tmp[len-1] != '/')
|
||||||
|
{
|
||||||
|
normpath = g_strdup_printf ("%s/", tmp);
|
||||||
|
g_free (tmp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_assert (len == 1);
|
||||||
|
normpath = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_print ("path: '%s'\nnormpath: '%s'\n",
|
||||||
|
path, normpath);
|
||||||
|
|
||||||
|
return normpath;
|
||||||
|
}
|
||||||
|
@ -50,47 +50,40 @@ struct _MooFileSystemClass
|
|||||||
const char *path,
|
const char *path,
|
||||||
MooFileFlags flags,
|
MooFileFlags flags,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
MooFolder* (*get_parent_folder)(MooFileSystem *fs,
|
||||||
gboolean (*create_folder) (MooFileSystem *fs,
|
MooFolder *folder,
|
||||||
const char *path,
|
MooFileFlags flags);
|
||||||
GError **error);
|
|
||||||
gboolean (*delete_file) (MooFileSystem *fs,
|
|
||||||
const char *path,
|
|
||||||
GError **error);
|
|
||||||
|
|
||||||
char* (*get_parent) (MooFileSystem *fs,
|
|
||||||
const char *path,
|
|
||||||
GError **error);
|
|
||||||
char* (*make_path) (MooFileSystem *fs,
|
|
||||||
const char *base_path,
|
|
||||||
const char *display_name,
|
|
||||||
GError **error);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
GType moo_file_system_get_type (void) G_GNUC_CONST;
|
GType moo_file_system_get_type (void) G_GNUC_CONST;
|
||||||
|
|
||||||
MooFileSystem *moo_file_system_create (void);
|
MooFileSystem *moo_file_system_create (void);
|
||||||
|
|
||||||
MooFolder *moo_file_system_get_folder (MooFileSystem *fs,
|
MooFolder *moo_file_system_get_folder (MooFileSystem *fs,
|
||||||
const char *path,
|
const char *path,
|
||||||
MooFileFlags wanted,
|
MooFileFlags wanted,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
MooFolder *moo_file_system_get_parent_folder (MooFileSystem *fs,
|
||||||
|
MooFolder *folder,
|
||||||
|
MooFileFlags wanted);
|
||||||
|
|
||||||
gboolean moo_file_system_create_folder (MooFileSystem *fs,
|
MooFileSystem *moo_folder_get_file_system (MooFolder *folder);
|
||||||
const char *path,
|
|
||||||
GError **error);
|
|
||||||
gboolean moo_file_system_delete_file(MooFileSystem *fs,
|
|
||||||
const char *path,
|
|
||||||
GError **error);
|
|
||||||
|
|
||||||
char *moo_file_system_get_parent (MooFileSystem *fs,
|
// gboolean moo_file_system_create_folder (MooFileSystem *fs,
|
||||||
const char *path,
|
// const char *path,
|
||||||
GError **error);
|
// GError **error);
|
||||||
char *moo_file_system_make_path (MooFileSystem *fs,
|
// gboolean moo_file_system_delete_file (MooFileSystem *fs,
|
||||||
const char *base_path,
|
// const char *path,
|
||||||
const char *display_name,
|
// GError **error);
|
||||||
GError **error);
|
//
|
||||||
|
// char *moo_file_system_get_parent (MooFileSystem *fs,
|
||||||
|
// const char *path,
|
||||||
|
// GError **error);
|
||||||
|
// char *moo_file_system_make_path (MooFileSystem *fs,
|
||||||
|
// const char *base_path,
|
||||||
|
// const char *display_name,
|
||||||
|
// GError **error);
|
||||||
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
@ -78,6 +78,7 @@ struct _MooFileViewPrivate {
|
|||||||
gboolean show_hidden_files;
|
gboolean show_hidden_files;
|
||||||
gboolean show_two_dots;
|
gboolean show_two_dots;
|
||||||
History *history;
|
History *history;
|
||||||
|
gboolean select_first;
|
||||||
char *name_to_select;
|
char *name_to_select;
|
||||||
char *temp_visible; /* tempporary visible name, for interactive search */
|
char *temp_visible; /* tempporary visible name, for interactive search */
|
||||||
GtkTreeRowReference *temp_visible_row; /* row containing temp_visible (in the store) */
|
GtkTreeRowReference *temp_visible_row; /* row containing temp_visible (in the store) */
|
||||||
@ -112,9 +113,12 @@ static gboolean moo_file_view_key_press (GtkWidget *widget,
|
|||||||
static void moo_file_view_set_file_mgr (MooFileView *fileview,
|
static void moo_file_view_set_file_mgr (MooFileView *fileview,
|
||||||
MooEditFileMgr *mgr);
|
MooEditFileMgr *mgr);
|
||||||
|
|
||||||
static gboolean moo_file_view_chdir_real(MooFileView *fileview,
|
static void moo_file_view_set_current_dir (MooFileView *fileview,
|
||||||
const char *dir,
|
MooFolder *folder);
|
||||||
GError **error);
|
static gboolean moo_file_view_chdir_real (MooFileView *fileview,
|
||||||
|
const char *dir,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
static void moo_file_view_go_up (MooFileView *fileview);
|
static void moo_file_view_go_up (MooFileView *fileview);
|
||||||
static void moo_file_view_go_home (MooFileView *fileview);
|
static void moo_file_view_go_home (MooFileView *fileview);
|
||||||
static void moo_file_view_go_back (MooFileView *fileview);
|
static void moo_file_view_go_back (MooFileView *fileview);
|
||||||
@ -582,17 +586,18 @@ static gboolean clear_list_in_idle (MooFileView *fileview)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean moo_file_view_chdir_real(MooFileView *fileview,
|
static void moo_file_view_set_current_dir (MooFileView *fileview,
|
||||||
const char *new_dir,
|
MooFolder *folder)
|
||||||
GError **error)
|
|
||||||
{
|
{
|
||||||
char *real_new_dir;
|
|
||||||
MooFolder *folder;
|
|
||||||
GSList *files;
|
GSList *files;
|
||||||
|
|
||||||
g_return_val_if_fail (MOO_IS_FILE_VIEW (fileview), FALSE);
|
g_return_if_fail (MOO_IS_FILE_VIEW (fileview));
|
||||||
|
g_return_if_fail (!folder || MOO_IS_FOLDER (folder));
|
||||||
|
|
||||||
if (!new_dir)
|
if (folder == fileview->priv->current_dir)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!folder)
|
||||||
{
|
{
|
||||||
if (fileview->priv->current_dir)
|
if (fileview->priv->current_dir)
|
||||||
{
|
{
|
||||||
@ -603,12 +608,54 @@ static gboolean moo_file_view_chdir_real(MooFileView *fileview,
|
|||||||
gtk_list_store_clear (fileview->priv->store);
|
gtk_list_store_clear (fileview->priv->store);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileview->priv->current_dir &&
|
disconnect_folder (fileview);
|
||||||
!strcmp (moo_folder_get_path (fileview->priv->current_dir), new_dir))
|
if (fileview->priv->current_dir)
|
||||||
return TRUE;
|
g_object_unref (fileview->priv->current_dir);
|
||||||
|
|
||||||
|
fileview->priv->current_dir = g_object_ref (folder);
|
||||||
|
|
||||||
|
history_goto (fileview, moo_folder_get_path (folder));
|
||||||
|
|
||||||
|
fileview->priv->need_to_clear = TRUE;
|
||||||
|
g_idle_add_full (G_PRIORITY_LOW,
|
||||||
|
(GSourceFunc) clear_list_in_idle,
|
||||||
|
fileview, NULL);
|
||||||
|
fileview->priv->process_changes_now = TRUE;
|
||||||
|
|
||||||
|
if (fileview->priv->files)
|
||||||
|
g_hash_table_destroy (fileview->priv->files);
|
||||||
|
fileview->priv->files =
|
||||||
|
g_hash_table_new_full (g_direct_hash, g_direct_equal,
|
||||||
|
(GDestroyNotify) moo_file_unref,
|
||||||
|
(GDestroyNotify) gtk_tree_row_reference_free);
|
||||||
|
|
||||||
|
connect_folder (fileview);
|
||||||
|
|
||||||
|
fileview->priv->select_first = TRUE;
|
||||||
|
files = moo_folder_list_files (folder);
|
||||||
|
fileview_add_files (fileview, files);
|
||||||
|
g_slist_foreach (files, (GFunc) moo_file_unref, NULL);
|
||||||
|
g_slist_free (files);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static gboolean moo_file_view_chdir_real(MooFileView *fileview,
|
||||||
|
const char *new_dir,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
char *real_new_dir;
|
||||||
|
MooFolder *folder;
|
||||||
|
|
||||||
|
g_return_val_if_fail (MOO_IS_FILE_VIEW (fileview), FALSE);
|
||||||
|
|
||||||
|
if (!new_dir)
|
||||||
|
{
|
||||||
|
moo_file_view_set_current_dir (fileview, NULL);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
if (g_path_is_absolute (new_dir) || !fileview->priv->current_dir)
|
if (g_path_is_absolute (new_dir) || !fileview->priv->current_dir)
|
||||||
{
|
{
|
||||||
@ -629,34 +676,8 @@ static gboolean moo_file_view_chdir_real(MooFileView *fileview,
|
|||||||
if (!folder)
|
if (!folder)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
disconnect_folder (fileview);
|
moo_file_view_set_current_dir (fileview, folder);
|
||||||
if (fileview->priv->current_dir)
|
g_object_unref (folder);
|
||||||
g_object_unref (fileview->priv->current_dir);
|
|
||||||
|
|
||||||
fileview->priv->current_dir = folder;
|
|
||||||
|
|
||||||
history_goto (fileview, moo_folder_get_path (folder));
|
|
||||||
|
|
||||||
fileview->priv->need_to_clear = TRUE;
|
|
||||||
g_idle_add_full (G_PRIORITY_LOW,
|
|
||||||
(GSourceFunc) clear_list_in_idle,
|
|
||||||
fileview, NULL);
|
|
||||||
fileview->priv->process_changes_now = TRUE;
|
|
||||||
|
|
||||||
if (fileview->priv->files)
|
|
||||||
g_hash_table_destroy (fileview->priv->files);
|
|
||||||
fileview->priv->files =
|
|
||||||
g_hash_table_new_full (g_direct_hash, g_direct_equal,
|
|
||||||
(GDestroyNotify) moo_file_unref,
|
|
||||||
(GDestroyNotify) gtk_tree_row_reference_free);
|
|
||||||
|
|
||||||
connect_folder (fileview);
|
|
||||||
|
|
||||||
files = moo_folder_list_files (folder);
|
|
||||||
fileview_add_files (fileview, files);
|
|
||||||
g_slist_foreach (files, (GFunc) moo_file_unref, NULL);
|
|
||||||
g_slist_free (files);
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -796,12 +817,20 @@ static void add_one_file (MooFileView *fileview,
|
|||||||
COLUMN_SIZE, NULL,
|
COLUMN_SIZE, NULL,
|
||||||
COLUMN_DATE, NULL, -1);
|
COLUMN_DATE, NULL, -1);
|
||||||
|
|
||||||
if (fileview->priv->name_to_select &&
|
if (fileview->priv->name_to_select)
|
||||||
!strcmp (fileview->priv->name_to_select,
|
|
||||||
moo_file_get_display_basename (file)))
|
|
||||||
{
|
{
|
||||||
g_free (fileview->priv->name_to_select);
|
if (!strcmp (fileview->priv->name_to_select,
|
||||||
fileview->priv->name_to_select = NULL;
|
moo_file_get_display_basename (file)))
|
||||||
|
{
|
||||||
|
g_free (fileview->priv->name_to_select);
|
||||||
|
fileview->priv->name_to_select = NULL;
|
||||||
|
moo_file_view_select_file (fileview,
|
||||||
|
moo_file_get_display_basename (file));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (fileview->priv->select_first)
|
||||||
|
{
|
||||||
|
fileview->priv->select_first = FALSE;
|
||||||
moo_file_view_select_file (fileview,
|
moo_file_view_select_file (fileview,
|
||||||
moo_file_get_display_basename (file));
|
moo_file_get_display_basename (file));
|
||||||
}
|
}
|
||||||
@ -811,8 +840,10 @@ static void add_one_file (MooFileView *fileview,
|
|||||||
static gboolean fileview_add_files_in_idle (MooFileView *fileview)
|
static gboolean fileview_add_files_in_idle (MooFileView *fileview)
|
||||||
{
|
{
|
||||||
if (fileview->priv->need_to_clear)
|
if (fileview->priv->need_to_clear)
|
||||||
|
{
|
||||||
gtk_list_store_clear (fileview->priv->store);
|
gtk_list_store_clear (fileview->priv->store);
|
||||||
fileview->priv->need_to_clear = FALSE;
|
fileview->priv->need_to_clear = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (fileview->priv->remove_files_idle)
|
if (fileview->priv->remove_files_idle)
|
||||||
remove_a_bit (fileview);
|
remove_a_bit (fileview);
|
||||||
@ -1581,36 +1612,28 @@ gboolean moo_file_view_chdir (MooFileView *fileview,
|
|||||||
|
|
||||||
static void moo_file_view_go_up (MooFileView *fileview)
|
static void moo_file_view_go_up (MooFileView *fileview)
|
||||||
{
|
{
|
||||||
char *dirname, *basename;
|
MooFolder *parent;
|
||||||
GError *error = NULL;
|
char *name;
|
||||||
|
|
||||||
g_return_if_fail (fileview->priv->current_dir != NULL);
|
g_return_if_fail (fileview->priv->current_dir != NULL);
|
||||||
|
|
||||||
basename = g_path_get_basename (moo_folder_get_path (fileview->priv->current_dir));
|
parent = moo_folder_get_parent (fileview->priv->current_dir,
|
||||||
dirname = g_path_get_dirname (moo_folder_get_path (fileview->priv->current_dir));
|
MOO_FILE_HAS_ICON);
|
||||||
|
|
||||||
/* TODO TODO do something about top-level directories */
|
g_print ("current dir: '%s'\nparent dir: '%s'\n",
|
||||||
if (!strcmp (basename, dirname))
|
moo_folder_get_path (fileview->priv->current_dir),
|
||||||
goto out;
|
moo_folder_get_path (parent));
|
||||||
|
|
||||||
if (!moo_file_view_chdir (fileview, dirname, &error))
|
if (parent != fileview->priv->current_dir)
|
||||||
{
|
{
|
||||||
g_warning ("%s: could not go up", G_STRLOC);
|
name = g_filename_display_basename (
|
||||||
|
moo_folder_get_path (fileview->priv->current_dir));
|
||||||
if (error)
|
moo_file_view_set_current_dir (fileview, parent);
|
||||||
{
|
moo_file_view_select_file (fileview, name);
|
||||||
g_warning ("%s: %s", G_STRLOC, error->message);
|
g_free (name);
|
||||||
g_error_free (error);
|
|
||||||
}
|
|
||||||
|
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
moo_file_view_select_file (fileview, basename);
|
g_object_unref (parent);
|
||||||
|
|
||||||
out:
|
|
||||||
g_free (dirname);
|
|
||||||
g_free (basename);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2719,12 +2742,24 @@ static gboolean search_entry_key_press (G_GNUC_UNUSED GtkWidget *entry,
|
|||||||
GdkEventKey *event,
|
GdkEventKey *event,
|
||||||
MooFileView *fileview)
|
MooFileView *fileview)
|
||||||
{
|
{
|
||||||
|
GtkWidget *filewidget;
|
||||||
switch (event->keyval)
|
switch (event->keyval)
|
||||||
{
|
{
|
||||||
case GDK_Escape:
|
case GDK_Escape:
|
||||||
stop_interactive_search (fileview, TRUE);
|
stop_interactive_search (fileview, TRUE);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
case GDK_Up:
|
||||||
|
case GDK_KP_Up:
|
||||||
|
case GDK_Down:
|
||||||
|
case GDK_KP_Down:
|
||||||
|
stop_interactive_search (fileview, TRUE);
|
||||||
|
filewidget = get_file_view_widget (fileview);
|
||||||
|
gtk_widget_grab_focus (filewidget);
|
||||||
|
GTK_WIDGET_CLASS(G_OBJECT_GET_CLASS (filewidget))->
|
||||||
|
key_press_event (filewidget, event);
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -2896,7 +2931,11 @@ void moo_file_view_select_file (MooFileView *fileview,
|
|||||||
if (!filter_path)
|
if (!filter_path)
|
||||||
{
|
{
|
||||||
gtk_tree_path_free (path);
|
gtk_tree_path_free (path);
|
||||||
file_widget_move_selection (fileview, NULL);
|
if (gtk_tree_model_get_iter_first (fileview->priv->filter_model,
|
||||||
|
&filter_iter))
|
||||||
|
file_widget_move_selection (fileview, &filter_iter);
|
||||||
|
else
|
||||||
|
fileview->priv->select_first = TRUE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user