Commit 5ed6ea8a authored by Ramiro Estrugo's avatar Ramiro Estrugo
Browse files

Change file utilities special directory access functions to always return

* libnautilus-extensions/nautilus-directory.c:
(construct_alternate_metafile_uri):
* libnautilus-extensions/nautilus-file-utilities.c:
(nautilus_make_path), (nautilus_get_user_directory),
(nautilus_get_desktop_directory),
(nautilus_get_user_main_directory),
(nautilus_get_pixmap_directory):
* libnautilus-extensions/nautilus-file-utilities.h:
* libnautilus-extensions/nautilus-global-preferences.c:
(global_preferences_register_for_ui):
* libnautilus-extensions/nautilus-icon-factory.c:
(get_themed_icon_file_path):
* libnautilus-extensions/nautilus-preferences-item.c:
(add_icon_themes):
* src/file-manager/fm-properties-window.c: (get_property_names):
* src/nautilus-application.c:
(nautilus_application_check_user_directories):
* src/nautilus-bookmark-list.c:
(nautilus_bookmark_list_get_file_path):
* src/nautilus-desktop-window.c: (nautilus_desktop_window_new):
* src/nautilus-first-time-druid.c: (druid_finished):
* src/nautilus-property-browser.c:
(nautilus_property_browser_drag_data_get), (make_drag_image),
(remove_color), (remove_background), (remove_emblem),
(get_xml_path), (add_background_to_browser), (add_color_to_file),
(emblem_dialog_clicked), (make_properties_from_directory):
Change file utilities special directory access functions to always
return allocated strings.  Change all callers to match the new
functions and free the results.

Also change the file utilities functions to always create the
special directories if needed.
parent 9ac57fc3
2000-07-05 Ramiro Estrugo <ramiro@eazel.com>
* libnautilus-extensions/nautilus-directory.c:
(construct_alternate_metafile_uri):
* libnautilus-extensions/nautilus-file-utilities.c:
(nautilus_make_path), (nautilus_get_user_directory),
(nautilus_get_desktop_directory),
(nautilus_get_user_main_directory),
(nautilus_get_pixmap_directory):
* libnautilus-extensions/nautilus-file-utilities.h:
* libnautilus-extensions/nautilus-global-preferences.c:
(global_preferences_register_for_ui):
* libnautilus-extensions/nautilus-icon-factory.c:
(get_themed_icon_file_path):
* libnautilus-extensions/nautilus-preferences-item.c:
(add_icon_themes):
* src/file-manager/fm-properties-window.c: (get_property_names):
* src/nautilus-application.c:
(nautilus_application_check_user_directories):
* src/nautilus-bookmark-list.c:
(nautilus_bookmark_list_get_file_path):
* src/nautilus-desktop-window.c: (nautilus_desktop_window_new):
* src/nautilus-first-time-druid.c: (druid_finished):
* src/nautilus-property-browser.c:
(nautilus_property_browser_drag_data_get), (make_drag_image),
(remove_color), (remove_background), (remove_emblem),
(get_xml_path), (add_background_to_browser), (add_color_to_file),
(emblem_dialog_clicked), (make_properties_from_directory):
Change file utilities special directory access functions to always
return allocated strings. Change all callers to match the new
functions and free the results.
Also change the file utilities functions to always create the
special directories if needed.
2000-07-05 Ramiro Estrugo <ramiro@eazel.com>
* libnautilus-extensions/nautilus-global-preferences.c:
......
......@@ -362,9 +362,13 @@ construct_alternate_metafile_uri (GnomeVFSURI *uri)
GnomeVFSResult result;
GnomeVFSURI *nautilus_directory_uri, *metafiles_directory_uri, *alternate_uri;
char *uri_as_string, *escaped_uri, *file_name;
char *user_directory;
/* Ensure that the metafiles directory exists. */
nautilus_directory_uri = gnome_vfs_uri_new (nautilus_get_user_directory ());
user_directory = nautilus_get_user_directory ();
nautilus_directory_uri = gnome_vfs_uri_new (user_directory);
g_free (user_directory);
metafiles_directory_uri = gnome_vfs_uri_append_file_name (nautilus_directory_uri,
METAFILES_DIRECTORY_NAME);
gnome_vfs_uri_unref (nautilus_directory_uri);
......
......@@ -130,12 +130,12 @@ nautilus_make_uri_from_input (const char *location)
* Return value: the combined path name.
**/
char *
nautilus_make_path(const char *path, const char* name)
nautilus_make_path (const char *path, const char* name)
{
gboolean insert_separator;
int path_length;
char *result;
path_length = strlen (path);
insert_separator = path_length > 0 &&
name[0] != '\0' &&
......@@ -150,10 +150,6 @@ nautilus_make_path(const char *path, const char* name)
return result;
}
/* FIXME bugzilla.eazel.com 1117: Change file-utilities.c to always create user
* directories if needed. See bug for details.
*/
/**
* nautilus_get_user_directory:
*
......@@ -161,19 +157,16 @@ nautilus_make_path(const char *path, const char* name)
*
* Return value: the directory path.
**/
const char *
char *
nautilus_get_user_directory (void)
{
static char *user_directory = NULL;
if (user_directory == NULL) {
user_directory = nautilus_make_path (g_get_home_dir (),
NAUTILUS_USER_DIRECTORY_NAME);
char *user_directory = NULL;
if (!g_file_exists (user_directory)) {
mkdir (user_directory, DEFAULT_NAUTILUS_DIRECTORY_MODE);
}
user_directory = nautilus_make_path (g_get_home_dir (),
NAUTILUS_USER_DIRECTORY_NAME);
if (!g_file_exists (user_directory)) {
mkdir (user_directory, DEFAULT_NAUTILUS_DIRECTORY_MODE);
}
return user_directory;
......@@ -186,18 +179,18 @@ nautilus_get_user_directory (void)
*
* Return value: the directory path.
**/
const char *
char *
nautilus_get_desktop_directory (void)
{
static char *desktop_directory = NULL;
char *desktop_directory = NULL;
char *user_directory;
if (desktop_directory == NULL) {
desktop_directory = nautilus_make_path (nautilus_get_user_directory (),
DESKTOP_DIRECTORY_NAME);
if (!g_file_exists (desktop_directory)) {
mkdir (desktop_directory, DEFAULT_DESKTOP_DIRECTORY_MODE);
}
user_directory = nautilus_get_user_directory ();
desktop_directory = nautilus_make_path (user_directory, DESKTOP_DIRECTORY_NAME);
g_free (user_directory);
if (!g_file_exists (desktop_directory)) {
mkdir (desktop_directory, DEFAULT_DESKTOP_DIRECTORY_MODE);
}
return desktop_directory;
......@@ -232,85 +225,82 @@ nautilus_user_main_directory_exists(void)
*
* Return value: the directory path.
**/
const char *
char *
nautilus_get_user_main_directory (void)
{
static char *user_main_directory = NULL;
char *user_main_directory = NULL;
GnomeVFSResult result;
NautilusFile *file;
char *file_uri, *image_uri, *temp_str;
char *source_directory_uri, *destination_directory_uri;
GList *source_name_list, *destination_name_list;
if (user_main_directory == NULL)
{
user_main_directory = g_strdup_printf ("%s/%s",
g_get_home_dir(),
NAUTILUS_USER_MAIN_DIRECTORY_NAME);
user_main_directory = g_strdup_printf ("%s/%s",
g_get_home_dir(),
NAUTILUS_USER_MAIN_DIRECTORY_NAME);
if (!g_file_exists (user_main_directory)) {
source_directory_uri = nautilus_get_uri_from_local_path (NAUTILUS_DATADIR);
destination_directory_uri = nautilus_get_uri_from_local_path (g_get_home_dir());
source_name_list = g_list_prepend (NULL, "top");
destination_name_list = g_list_prepend (NULL, NAUTILUS_USER_MAIN_DIRECTORY_NAME);
result = gnome_vfs_xfer (source_directory_uri, source_name_list,
destination_directory_uri, destination_name_list,
GNOME_VFS_XFER_RECURSIVE, GNOME_VFS_XFER_ERROR_MODE_ABORT,
GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
NULL, NULL);
g_free (source_directory_uri);
g_free (destination_directory_uri);
g_list_free (source_name_list);
g_list_free (destination_name_list);
/* FIXME bugzilla.eazel.com 1286:
* Is a g_warning good enough here? This seems like a big problem.
*/
if (result != GNOME_VFS_OK) {
g_warning ("could not install the novice home directory. Make sure you typed 'make install'");
}
if (!g_file_exists (user_main_directory)) {
source_directory_uri = nautilus_get_uri_from_local_path (NAUTILUS_DATADIR);
destination_directory_uri = nautilus_get_uri_from_local_path (g_get_home_dir());
source_name_list = g_list_prepend (NULL, "top");
destination_name_list = g_list_prepend (NULL, NAUTILUS_USER_MAIN_DIRECTORY_NAME);
result = gnome_vfs_xfer (source_directory_uri, source_name_list,
destination_directory_uri, destination_name_list,
GNOME_VFS_XFER_RECURSIVE, GNOME_VFS_XFER_ERROR_MODE_ABORT,
GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
NULL, NULL);
g_free (source_directory_uri);
g_free (destination_directory_uri);
g_list_free (source_name_list);
g_list_free (destination_name_list);
/* FIXME bugzilla.eazel.com 1286:
* Is a g_warning good enough here? This seems like a big problem.
*/
if (result != GNOME_VFS_OK) {
g_warning ("could not install the novice home directory. Make sure you typed 'make install'");
}
/* assign a custom image for the directory icon */
file_uri = nautilus_get_uri_from_local_path (user_main_directory);
temp_str = nautilus_pixmap_file ("nautilus-logo.png");
image_uri = nautilus_get_uri_from_local_path (temp_str);
g_free (temp_str);
file = nautilus_file_get (file_uri);
g_free (file_uri);
if (file != NULL) {
nautilus_file_set_metadata (file,
NAUTILUS_METADATA_KEY_CUSTOM_ICON,
NULL,
image_uri);
nautilus_file_unref (file);
}
/* now do the same for the about file */
temp_str = g_strdup_printf ("%s/About.html", user_main_directory);
file_uri = nautilus_get_uri_from_local_path (temp_str);
g_free (temp_str);
file = nautilus_file_get (file_uri);
if (file != NULL) {
nautilus_file_set_metadata (file,
NAUTILUS_METADATA_KEY_CUSTOM_ICON,
NULL,
image_uri);
nautilus_file_unref (file);
}
g_free (file_uri);
g_free (image_uri);
/* install the default link set */
nautilus_link_set_install(user_main_directory, "apps");
/*
nautilus_link_set_install(user_main_directory, "search_engines");
*/
/* assign a custom image for the directory icon */
file_uri = nautilus_get_uri_from_local_path (user_main_directory);
temp_str = nautilus_pixmap_file ("nautilus-logo.png");
image_uri = nautilus_get_uri_from_local_path (temp_str);
g_free (temp_str);
file = nautilus_file_get (file_uri);
g_free (file_uri);
if (file != NULL) {
nautilus_file_set_metadata (file,
NAUTILUS_METADATA_KEY_CUSTOM_ICON,
NULL,
image_uri);
nautilus_file_unref (file);
}
/* now do the same for the about file */
temp_str = g_strdup_printf ("%s/About.html", user_main_directory);
file_uri = nautilus_get_uri_from_local_path (temp_str);
g_free (temp_str);
file = nautilus_file_get (file_uri);
if (file != NULL) {
nautilus_file_set_metadata (file,
NAUTILUS_METADATA_KEY_CUSTOM_ICON,
NULL,
image_uri);
nautilus_file_unref (file);
}
g_free (file_uri);
g_free (image_uri);
/* install the default link set */
nautilus_link_set_install(user_main_directory, "apps");
/*
nautilus_link_set_install(user_main_directory, "search_engines");
*/
}
return user_main_directory;
......@@ -323,10 +313,14 @@ nautilus_get_user_main_directory (void)
*
* Return value: the directory path.
**/
const char *
char *
nautilus_get_pixmap_directory (void)
{
return DATADIR "/pixmaps/nautilus";
char *pixmap_directory;
pixmap_directory = g_strdup_printf ("%s/%s", DATADIR, "pixmaps/nautilus");
return pixmap_directory;
}
/**
......
......@@ -38,14 +38,14 @@ char * nautilus_make_uri_from_input (const char
char * nautilus_make_path (const char *path,
const char *name);
/* Return paths that don't need to be destroyed. We will probably
* change these to return ones that do need to be destroyed for
* consistency soon.
/* Return paths that NEED to be destroyed.
* These functions are meant to return something something that is not NULL and
* is guranteed to exist.
*/
const char * nautilus_get_user_directory (void);
const char * nautilus_get_user_main_directory (void);
const char * nautilus_get_desktop_directory (void);
const char * nautilus_get_pixmap_directory (void);
char * nautilus_get_user_directory (void);
char * nautilus_get_user_main_directory (void);
char * nautilus_get_desktop_directory (void);
char * nautilus_get_pixmap_directory (void);
/* see if the user_main_directory exists. This must be called before
"nautilus_get_user_main_directory", which creates it */
......
......@@ -624,12 +624,11 @@ global_preferences_register_for_ui (void)
TRUE);
{
const char *user_main_directory;
char *novice_home_location;
char *intermediate_home_location;
char *hacker_home_location;
char *user_main_directory;
char *novice_home_location;
char *intermediate_home_location;
char *hacker_home_location;
/* FIXME bugzilla.eazel.com 715: This call needs to be spanked to conform. Should return a strduped string */
user_main_directory = nautilus_get_user_main_directory ();
novice_home_location = g_strdup_printf ("file://%s", user_main_directory);
......@@ -642,6 +641,7 @@ global_preferences_register_for_ui (void)
intermediate_home_location,
hacker_home_location);
g_free (user_main_directory);
g_free (novice_home_location);
g_free (intermediate_home_location);
g_free (hacker_home_location);
......
......@@ -644,10 +644,13 @@ get_themed_icon_file_path (const char *theme_name,
if (path == NULL && nautilus_str_has_prefix (icon_name, "emblem-")) {
for (i = 0; i < NAUTILUS_N_ELEMENTS (icon_file_name_suffixes); i++) {
char *user_directory;
user_directory = nautilus_get_user_directory ();
path = g_strdup_printf ("%s/emblems/%s%s",
nautilus_get_user_directory(),
user_directory,
icon_name + 7,
icon_file_name_suffixes[i]);
g_free (user_directory);
if (g_file_exists (path)) {
break;
......
......@@ -500,9 +500,13 @@ add_icon_themes(NautilusStringList *theme_list, char *required_file)
GnomeVFSResult result;
GnomeVFSFileInfo *current_file_info;
GnomeVFSDirectoryList *list;
char *pixmap_directory;
pixmap_directory = nautilus_get_pixmap_directory ();
/* get the uri for the images directory */
directory_uri = nautilus_get_uri_from_local_path (nautilus_get_pixmap_directory ());
directory_uri = nautilus_get_uri_from_local_path (pixmap_directory);
g_free (pixmap_directory);
result = gnome_vfs_directory_list_load (&list, directory_uri,
GNOME_VFS_FILE_INFO_DEFAULT, NULL, NULL);
......
......@@ -362,9 +362,13 @@ construct_alternate_metafile_uri (GnomeVFSURI *uri)
GnomeVFSResult result;
GnomeVFSURI *nautilus_directory_uri, *metafiles_directory_uri, *alternate_uri;
char *uri_as_string, *escaped_uri, *file_name;
char *user_directory;
/* Ensure that the metafiles directory exists. */
nautilus_directory_uri = gnome_vfs_uri_new (nautilus_get_user_directory ());
user_directory = nautilus_get_user_directory ();
nautilus_directory_uri = gnome_vfs_uri_new (user_directory);
g_free (user_directory);
metafiles_directory_uri = gnome_vfs_uri_append_file_name (nautilus_directory_uri,
METAFILES_DIRECTORY_NAME);
gnome_vfs_uri_unref (nautilus_directory_uri);
......
......@@ -130,12 +130,12 @@ nautilus_make_uri_from_input (const char *location)
* Return value: the combined path name.
**/
char *
nautilus_make_path(const char *path, const char* name)
nautilus_make_path (const char *path, const char* name)
{
gboolean insert_separator;
int path_length;
char *result;
path_length = strlen (path);
insert_separator = path_length > 0 &&
name[0] != '\0' &&
......@@ -150,10 +150,6 @@ nautilus_make_path(const char *path, const char* name)
return result;
}
/* FIXME bugzilla.eazel.com 1117: Change file-utilities.c to always create user
* directories if needed. See bug for details.
*/
/**
* nautilus_get_user_directory:
*
......@@ -161,19 +157,16 @@ nautilus_make_path(const char *path, const char* name)
*
* Return value: the directory path.
**/
const char *
char *
nautilus_get_user_directory (void)
{
static char *user_directory = NULL;
if (user_directory == NULL) {
user_directory = nautilus_make_path (g_get_home_dir (),
NAUTILUS_USER_DIRECTORY_NAME);
char *user_directory = NULL;
if (!g_file_exists (user_directory)) {
mkdir (user_directory, DEFAULT_NAUTILUS_DIRECTORY_MODE);
}
user_directory = nautilus_make_path (g_get_home_dir (),
NAUTILUS_USER_DIRECTORY_NAME);
if (!g_file_exists (user_directory)) {
mkdir (user_directory, DEFAULT_NAUTILUS_DIRECTORY_MODE);
}
return user_directory;
......@@ -186,18 +179,18 @@ nautilus_get_user_directory (void)
*
* Return value: the directory path.
**/
const char *
char *
nautilus_get_desktop_directory (void)
{
static char *desktop_directory = NULL;
char *desktop_directory = NULL;
char *user_directory;
if (desktop_directory == NULL) {
desktop_directory = nautilus_make_path (nautilus_get_user_directory (),
DESKTOP_DIRECTORY_NAME);
if (!g_file_exists (desktop_directory)) {
mkdir (desktop_directory, DEFAULT_DESKTOP_DIRECTORY_MODE);
}
user_directory = nautilus_get_user_directory ();
desktop_directory = nautilus_make_path (user_directory, DESKTOP_DIRECTORY_NAME);
g_free (user_directory);
if (!g_file_exists (desktop_directory)) {
mkdir (desktop_directory, DEFAULT_DESKTOP_DIRECTORY_MODE);
}
return desktop_directory;
......@@ -232,85 +225,82 @@ nautilus_user_main_directory_exists(void)
*
* Return value: the directory path.
**/
const char *
char *
nautilus_get_user_main_directory (void)
{
static char *user_main_directory = NULL;
char *user_main_directory = NULL;
GnomeVFSResult result;
NautilusFile *file;
char *file_uri, *image_uri, *temp_str;
char *source_directory_uri, *destination_directory_uri;
GList *source_name_list, *destination_name_list;
if (user_main_directory == NULL)
{
user_main_directory = g_strdup_printf ("%s/%s",
g_get_home_dir(),
NAUTILUS_USER_MAIN_DIRECTORY_NAME);
user_main_directory = g_strdup_printf ("%s/%s",
g_get_home_dir(),
NAUTILUS_USER_MAIN_DIRECTORY_NAME);
if (!g_file_exists (user_main_directory)) {
source_directory_uri = nautilus_get_uri_from_local_path (NAUTILUS_DATADIR);
destination_directory_uri = nautilus_get_uri_from_local_path (g_get_home_dir());
source_name_list = g_list_prepend (NULL, "top");
destination_name_list = g_list_prepend (NULL, NAUTILUS_USER_MAIN_DIRECTORY_NAME);
result = gnome_vfs_xfer (source_directory_uri, source_name_list,
destination_directory_uri, destination_name_list,
GNOME_VFS_XFER_RECURSIVE, GNOME_VFS_XFER_ERROR_MODE_ABORT,
GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
NULL, NULL);
g_free (source_directory_uri);
g_free (destination_directory_uri);
g_list_free (source_name_list);
g_list_free (destination_name_list);
/* FIXME bugzilla.eazel.com 1286:
* Is a g_warning good enough here? This seems like a big problem.
*/
if (result != GNOME_VFS_OK) {
g_warning ("could not install the novice home directory. Make sure you typed 'make install'");
}
if (!g_file_exists (user_main_directory)) {
source_directory_uri = nautilus_get_uri_from_local_path (NAUTILUS_DATADIR);
destination_directory_uri = nautilus_get_uri_from_local_path (g_get_home_dir());
source_name_list = g_list_prepend (NULL, "top");
destination_name_list = g_list_prepend (NULL, NAUTILUS_USER_MAIN_DIRECTORY_NAME);
result = gnome_vfs_xfer (source_directory_uri, source_name_list,
destination_directory_uri, destination_name_list,
GNOME_VFS_XFER_RECURSIVE, GNOME_VFS_XFER_ERROR_MODE_ABORT,
GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
NULL, NULL);
g_free (source_directory_uri);
g_free (destination_directory_uri);
g_list_free (source_name_list);
g_list_free (destination_name_list);
/* FIXME bugzilla.eazel.com 1286:
* Is a g_warning good enough here? This seems like a big problem.
*/
if (result != GNOME_VFS_OK) {
g_warning ("could not install the novice home directory. Make sure you typed 'make install'");
}
/* assign a custom image for the directory icon */
file_uri = nautilus_get_uri_from_local_path (user_main_directory);
temp_str = nautilus_pixmap_file ("nautilus-logo.png");
image_uri = nautilus_get_uri_from_local_path (temp_str);
g_free (temp_str);
file = nautilus_file_get (file_uri);
g_free (file_uri);
if (file != NULL) {
nautilus_file_set_metadata (file,
NAUTILUS_METADATA_KEY_CUSTOM_ICON,
NULL,
image_uri);
nautilus_file_unref (file);
}
/* now do the same for the about file */
temp_str = g_strdup_printf ("%s/About.html", user_main_directory);
file_uri = nautilus_get_uri_from_local_path (temp_str);
g_free (temp_str);
file = nautilus_file_get (file_uri);
if (file != NULL) {
nautilus_file_set_metadata (file,
NAUTILUS_METADATA_KEY_CUSTOM_ICON,
NULL,
image_uri);
nautilus_file_unref (file);
}
g_free (file_uri);
g_free (image_uri);
/* install the default link set */
nautilus_link_set_install(user_main_directory, "apps");
/*
nautilus_link_set_install(user_main_directory, "search_engines");
*/
/* assign a custom image for the directory icon */
file_uri = nautilus_get_uri_from_local_path (user_main_directory);
temp_str = nautilus_pixmap_file ("nautilus-logo.png");
image_uri = nautilus_get_uri_from_local_path (temp_str);
g_free (temp_str);
file = nautilus_file_get (file_uri);
g_free (file_uri);
if (file != NULL) {
nautilus_file_set_metadata (file,
NAUTILUS_METADATA_KEY_CUSTOM_ICON,
NULL,
image_uri);
nautilus_file_unref (file);
}
/* now do the same for the about file */
temp_str = g_strdup_printf ("%s/About.html", user_main_directory);
file_uri = nautilus_get_uri_from_local_path (temp_str);
g_free (temp_str);