Commit d903e89e authored by Federico Mena Quintero's avatar Federico Mena Quintero Committed by Federico Mena Quintero

Fix #132500.

2004-04-07  Federico Mena Quintero  <federico@ximian.com>

	Fix #132500.

	* gtk/gtkfilesystem.c (gtk_file_system_parse): Ensure that the
	passed-in 'str' is not NULL.

	* gtk/gtkfilesystemunix.c (expand_tilde): New helper function;
	expands "~/" or "~foo/" at the beginning of a filename.
	(gtk_file_system_unix_parse): Use expand_tilde() before doing
	anything else.

	* gtk/gtkfilechooserentry.c
	(gtk_file_chooser_entry_maybe_update_directory): Take in a
	force_reload argument.
	(gtk_file_chooser_entry_changed): If gtk_file_system_parse()
	returns an error, set the file_part_pos to -1.
	(load_directory_callback): Only populate the model if the
	file_part_pos is not -1.
parent ac5b1b31
2004-04-07 Federico Mena Quintero <federico@ximian.com>
Fix #132500.
* gtk/gtkfilesystem.c (gtk_file_system_parse): Ensure that the
passed-in 'str' is not NULL.
* gtk/gtkfilesystemunix.c (expand_tilde): New helper function;
expands "~/" or "~foo/" at the beginning of a filename.
(gtk_file_system_unix_parse): Use expand_tilde() before doing
anything else.
* gtk/gtkfilechooserentry.c
(gtk_file_chooser_entry_maybe_update_directory): Take in a
force_reload argument.
(gtk_file_chooser_entry_changed): If gtk_file_system_parse()
returns an error, set the file_part_pos to -1.
(load_directory_callback): Only populate the model if the
file_part_pos is not -1.
2004-04-06 Pablo Saratxaga <pablo@mandrakesoft.com>
* configure.in: Added Icelandic (is) to ALL_LINGUAS
......
2004-04-07 Federico Mena Quintero <federico@ximian.com>
Fix #132500.
* gtk/gtkfilesystem.c (gtk_file_system_parse): Ensure that the
passed-in 'str' is not NULL.
* gtk/gtkfilesystemunix.c (expand_tilde): New helper function;
expands "~/" or "~foo/" at the beginning of a filename.
(gtk_file_system_unix_parse): Use expand_tilde() before doing
anything else.
* gtk/gtkfilechooserentry.c
(gtk_file_chooser_entry_maybe_update_directory): Take in a
force_reload argument.
(gtk_file_chooser_entry_changed): If gtk_file_system_parse()
returns an error, set the file_part_pos to -1.
(load_directory_callback): Only populate the model if the
file_part_pos is not -1.
2004-04-06 Pablo Saratxaga <pablo@mandrakesoft.com>
* configure.in: Added Icelandic (is) to ALL_LINGUAS
......
2004-04-07 Federico Mena Quintero <federico@ximian.com>
Fix #132500.
* gtk/gtkfilesystem.c (gtk_file_system_parse): Ensure that the
passed-in 'str' is not NULL.
* gtk/gtkfilesystemunix.c (expand_tilde): New helper function;
expands "~/" or "~foo/" at the beginning of a filename.
(gtk_file_system_unix_parse): Use expand_tilde() before doing
anything else.
* gtk/gtkfilechooserentry.c
(gtk_file_chooser_entry_maybe_update_directory): Take in a
force_reload argument.
(gtk_file_chooser_entry_changed): If gtk_file_system_parse()
returns an error, set the file_part_pos to -1.
(load_directory_callback): Only populate the model if the
file_part_pos is not -1.
2004-04-06 Pablo Saratxaga <pablo@mandrakesoft.com>
* configure.in: Added Icelandic (is) to ALL_LINGUAS
......
2004-04-07 Federico Mena Quintero <federico@ximian.com>
Fix #132500.
* gtk/gtkfilesystem.c (gtk_file_system_parse): Ensure that the
passed-in 'str' is not NULL.
* gtk/gtkfilesystemunix.c (expand_tilde): New helper function;
expands "~/" or "~foo/" at the beginning of a filename.
(gtk_file_system_unix_parse): Use expand_tilde() before doing
anything else.
* gtk/gtkfilechooserentry.c
(gtk_file_chooser_entry_maybe_update_directory): Take in a
force_reload argument.
(gtk_file_chooser_entry_changed): If gtk_file_system_parse()
returns an error, set the file_part_pos to -1.
(load_directory_callback): Only populate the model if the
file_part_pos is not -1.
2004-04-06 Pablo Saratxaga <pablo@mandrakesoft.com>
* configure.in: Added Icelandic (is) to ALL_LINGUAS
......
2004-04-07 Federico Mena Quintero <federico@ximian.com>
Fix #132500.
* gtk/gtkfilesystem.c (gtk_file_system_parse): Ensure that the
passed-in 'str' is not NULL.
* gtk/gtkfilesystemunix.c (expand_tilde): New helper function;
expands "~/" or "~foo/" at the beginning of a filename.
(gtk_file_system_unix_parse): Use expand_tilde() before doing
anything else.
* gtk/gtkfilechooserentry.c
(gtk_file_chooser_entry_maybe_update_directory): Take in a
force_reload argument.
(gtk_file_chooser_entry_changed): If gtk_file_system_parse()
returns an error, set the file_part_pos to -1.
(load_directory_callback): Only populate the model if the
file_part_pos is not -1.
2004-04-06 Pablo Saratxaga <pablo@mandrakesoft.com>
* configure.in: Added Icelandic (is) to ALL_LINGUAS
......
......@@ -574,19 +574,22 @@ load_directory_callback (GtkFileChooserEntry *chooser_entry)
g_signal_connect (chooser_entry->current_folder, "files-removed",
G_CALLBACK (files_deleted_cb), chooser_entry);
gtk_file_folder_list_children (chooser_entry->current_folder,
&child_paths,
NULL); /* NULL-GError */
chooser_entry->completion_store = gtk_list_store_new (N_COLUMNS,
G_TYPE_STRING,
GTK_TYPE_FILE_PATH);
if (child_paths)
if (chooser_entry->file_part_pos != -1)
{
update_current_folder_files (chooser_entry, child_paths);
add_completion_idle (chooser_entry);
gtk_file_paths_free (child_paths);
}
gtk_file_folder_list_children (chooser_entry->current_folder,
&child_paths,
NULL); /* NULL-GError */
if (child_paths)
{
update_current_folder_files (chooser_entry, child_paths);
add_completion_idle (chooser_entry);
gtk_file_paths_free (child_paths);
}
}
gtk_entry_completion_set_model (gtk_entry_get_completion (GTK_ENTRY (chooser_entry)),
GTK_TREE_MODEL (chooser_entry->completion_store));
......@@ -657,13 +660,14 @@ gtk_file_chooser_entry_activate (GtkEntry *entry)
*/
static void
gtk_file_chooser_entry_maybe_update_directory (GtkFileChooserEntry *chooser_entry,
GtkFilePath *folder_path)
GtkFilePath *folder_path,
gboolean force_reload)
{
gboolean queue_idle = FALSE;
if (chooser_entry->current_folder_path)
{
if (gtk_file_path_compare (folder_path, chooser_entry->current_folder_path) != 0)
if (gtk_file_path_compare (folder_path, chooser_entry->current_folder_path) != 0 || force_reload)
{
/* We changed our current directory. We need to clear out the old
* directory information.
......@@ -736,22 +740,25 @@ gtk_file_chooser_entry_changed (GtkEditable *editable)
{
folder_path = gtk_file_path_copy (chooser_entry->base_folder);
file_part = g_strdup ("");
file_part_pos = -1;
}
file_part_len = strlen (file_part);
total_len = strlen (text);
if (total_len > file_part_len)
file_part_pos = g_utf8_strlen (text, total_len - file_part_len);
else
file_part_pos = 0;
gtk_file_chooser_entry_maybe_update_directory (chooser_entry, folder_path);
{
file_part_len = strlen (file_part);
total_len = strlen (text);
if (total_len > file_part_len)
file_part_pos = g_utf8_strlen (text, total_len - file_part_len);
else
file_part_pos = 0;
}
if (chooser_entry->file_part)
g_free (chooser_entry->file_part);
chooser_entry->file_part = file_part;
chooser_entry->file_part_pos = file_part_pos;
gtk_file_chooser_entry_maybe_update_directory (chooser_entry, folder_path, file_part_pos == -1);
}
static void
......
......@@ -592,9 +592,9 @@ gtk_file_system_parse (GtkFileSystem *file_system,
g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), FALSE);
g_return_val_if_fail (base_path != NULL, FALSE);
g_return_val_if_fail (str != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
result = GTK_FILE_SYSTEM_GET_IFACE (file_system)->parse (file_system, base_path, str,
&tmp_folder, &tmp_file_part,
error);
......
......@@ -32,6 +32,7 @@
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <pwd.h>
#include <unistd.h>
#include <stdio.h>
#include <time.h>
......@@ -876,6 +877,48 @@ canonicalize_filename (gchar *filename)
*q = '\0';
}
/* Takes a user-typed filename and expands a tilde at the beginning of the string */
static char *
expand_tilde (const char *filename)
{
const char *notilde;
const char *slash;
const char *home;
if (filename[0] != '~')
return g_strdup (filename);
notilde = filename + 1;
slash = strchr (notilde, G_DIR_SEPARATOR);
if (!slash)
return NULL;
if (slash == notilde)
{
home = g_get_home_dir ();
if (!home)
return g_strdup (filename);
}
else
{
char *username;
struct passwd *passwd;
username = g_strndup (notilde, slash - notilde);
passwd = getpwnam (username);
g_free (username);
if (!passwd)
return g_strdup (filename);
home = passwd->pw_dir;
}
return g_build_filename (home, G_DIR_SEPARATOR_S, slash + 1, NULL);
}
static gboolean
gtk_file_system_unix_parse (GtkFileSystem *file_system,
const GtkFilePath *base_path,
......@@ -885,6 +928,7 @@ gtk_file_system_unix_parse (GtkFileSystem *file_system,
GError **error)
{
const char *base_filename;
gchar *filename;
gchar *last_slash;
gboolean result = FALSE;
......@@ -892,11 +936,21 @@ gtk_file_system_unix_parse (GtkFileSystem *file_system,
g_return_val_if_fail (base_filename != NULL, FALSE);
g_return_val_if_fail (g_path_is_absolute (base_filename), FALSE);
last_slash = strrchr (str, G_DIR_SEPARATOR);
filename = expand_tilde (str);
if (!filename)
{
g_set_error (error,
GTK_FILE_SYSTEM_ERROR,
GTK_FILE_SYSTEM_ERROR_BAD_FILENAME,
"%s", ""); /* nothing for now, as we are string-frozen */
return FALSE;
}
last_slash = strrchr (filename, G_DIR_SEPARATOR);
if (!last_slash)
{
*folder = gtk_file_path_copy (base_path);
*file_part = g_strdup (str);
*file_part = g_strdup (filename);
result = TRUE;
}
else
......@@ -905,10 +959,10 @@ gtk_file_system_unix_parse (GtkFileSystem *file_system,
gchar *folder_path;
GError *tmp_error = NULL;
if (last_slash == str)
if (last_slash == filename)
folder_part = g_strdup ("/");
else
folder_part = g_filename_from_utf8 (str, last_slash - str,
folder_part = g_filename_from_utf8 (filename, last_slash - filename,
NULL, NULL, &tmp_error);
if (!folder_part)
......@@ -941,6 +995,8 @@ gtk_file_system_unix_parse (GtkFileSystem *file_system,
}
}
g_free (filename);
return result;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment