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.
This commit is contained in:
Federico Mena Quintero 2004-04-07 17:52:03 +00:00 committed by Federico Mena Quintero
parent ac5b1b3193
commit d903e89ece
8 changed files with 186 additions and 23 deletions

View File

@ -1,3 +1,23 @@
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> 2004-04-06 Pablo Saratxaga <pablo@mandrakesoft.com>
* configure.in: Added Icelandic (is) to ALL_LINGUAS * configure.in: Added Icelandic (is) to ALL_LINGUAS

View File

@ -1,3 +1,23 @@
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> 2004-04-06 Pablo Saratxaga <pablo@mandrakesoft.com>
* configure.in: Added Icelandic (is) to ALL_LINGUAS * configure.in: Added Icelandic (is) to ALL_LINGUAS

View File

@ -1,3 +1,23 @@
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> 2004-04-06 Pablo Saratxaga <pablo@mandrakesoft.com>
* configure.in: Added Icelandic (is) to ALL_LINGUAS * configure.in: Added Icelandic (is) to ALL_LINGUAS

View File

@ -1,3 +1,23 @@
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> 2004-04-06 Pablo Saratxaga <pablo@mandrakesoft.com>
* configure.in: Added Icelandic (is) to ALL_LINGUAS * configure.in: Added Icelandic (is) to ALL_LINGUAS

View File

@ -1,3 +1,23 @@
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> 2004-04-06 Pablo Saratxaga <pablo@mandrakesoft.com>
* configure.in: Added Icelandic (is) to ALL_LINGUAS * configure.in: Added Icelandic (is) to ALL_LINGUAS

View File

@ -574,19 +574,22 @@ load_directory_callback (GtkFileChooserEntry *chooser_entry)
g_signal_connect (chooser_entry->current_folder, "files-removed", g_signal_connect (chooser_entry->current_folder, "files-removed",
G_CALLBACK (files_deleted_cb), chooser_entry); 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, chooser_entry->completion_store = gtk_list_store_new (N_COLUMNS,
G_TYPE_STRING, G_TYPE_STRING,
GTK_TYPE_FILE_PATH); GTK_TYPE_FILE_PATH);
if (child_paths) if (chooser_entry->file_part_pos != -1)
{ {
update_current_folder_files (chooser_entry, child_paths); gtk_file_folder_list_children (chooser_entry->current_folder,
add_completion_idle (chooser_entry); &child_paths,
gtk_file_paths_free (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_entry_completion_set_model (gtk_entry_get_completion (GTK_ENTRY (chooser_entry)),
GTK_TREE_MODEL (chooser_entry->completion_store)); GTK_TREE_MODEL (chooser_entry->completion_store));
@ -657,13 +660,14 @@ gtk_file_chooser_entry_activate (GtkEntry *entry)
*/ */
static void static void
gtk_file_chooser_entry_maybe_update_directory (GtkFileChooserEntry *chooser_entry, gtk_file_chooser_entry_maybe_update_directory (GtkFileChooserEntry *chooser_entry,
GtkFilePath *folder_path) GtkFilePath *folder_path,
gboolean force_reload)
{ {
gboolean queue_idle = FALSE; gboolean queue_idle = FALSE;
if (chooser_entry->current_folder_path) 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 /* We changed our current directory. We need to clear out the old
* directory information. * directory information.
@ -736,22 +740,25 @@ gtk_file_chooser_entry_changed (GtkEditable *editable)
{ {
folder_path = gtk_file_path_copy (chooser_entry->base_folder); folder_path = gtk_file_path_copy (chooser_entry->base_folder);
file_part = g_strdup (""); 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 else
file_part_pos = 0; {
file_part_len = strlen (file_part);
gtk_file_chooser_entry_maybe_update_directory (chooser_entry, folder_path); 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) if (chooser_entry->file_part)
g_free (chooser_entry->file_part); g_free (chooser_entry->file_part);
chooser_entry->file_part = file_part; chooser_entry->file_part = file_part;
chooser_entry->file_part_pos = file_part_pos; 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 static void

View File

@ -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 (GTK_IS_FILE_SYSTEM (file_system), FALSE);
g_return_val_if_fail (base_path != NULL, 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); g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
result = GTK_FILE_SYSTEM_GET_IFACE (file_system)->parse (file_system, base_path, str, result = GTK_FILE_SYSTEM_GET_IFACE (file_system)->parse (file_system, base_path, str,
&tmp_folder, &tmp_file_part, &tmp_folder, &tmp_file_part,
error); error);

View File

@ -32,6 +32,7 @@
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <pwd.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
@ -876,6 +877,48 @@ canonicalize_filename (gchar *filename)
*q = '\0'; *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 static gboolean
gtk_file_system_unix_parse (GtkFileSystem *file_system, gtk_file_system_unix_parse (GtkFileSystem *file_system,
const GtkFilePath *base_path, const GtkFilePath *base_path,
@ -885,6 +928,7 @@ gtk_file_system_unix_parse (GtkFileSystem *file_system,
GError **error) GError **error)
{ {
const char *base_filename; const char *base_filename;
gchar *filename;
gchar *last_slash; gchar *last_slash;
gboolean result = FALSE; 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 (base_filename != NULL, FALSE);
g_return_val_if_fail (g_path_is_absolute (base_filename), 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) if (!last_slash)
{ {
*folder = gtk_file_path_copy (base_path); *folder = gtk_file_path_copy (base_path);
*file_part = g_strdup (str); *file_part = g_strdup (filename);
result = TRUE; result = TRUE;
} }
else else
@ -905,10 +959,10 @@ gtk_file_system_unix_parse (GtkFileSystem *file_system,
gchar *folder_path; gchar *folder_path;
GError *tmp_error = NULL; GError *tmp_error = NULL;
if (last_slash == str) if (last_slash == filename)
folder_part = g_strdup ("/"); folder_part = g_strdup ("/");
else 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); NULL, NULL, &tmp_error);
if (!folder_part) if (!folder_part)
@ -941,6 +995,8 @@ gtk_file_system_unix_parse (GtkFileSystem *file_system,
} }
} }
g_free (filename);
return result; return result;
} }