Commit 94c8b8b8 authored by Michael Meeks's avatar Michael Meeks Committed by Michael Meeks

pass in info if we have it already.

2002-08-07  Michael Meeks  <michael@ximian.com>

        * libnautilus-private/nautilus-file.c
        (nautilus_file_can_rename): pass in info if we
        have it already.

        * src/file-manager/fm-desktop-icon-view.c
        (update_trash_link_and_delete_copies),
        (update_home_link_and_delete_copies),
        (delete_all_mount_links): kill in favour of
        (update_desktop_directory): so we don't stat / mime
        sniff everything 3+ times.
        (update_link_and_delete_copies): push this method and
        it's file / sniff loop upwards.

        * src/file-manager/fm-directory-view.c
        (special_link_in_selection): upd.
        (fm_directory_link_type_in_selection): kill, unused.

        * libnautilus-private/nautilus-link.c
        (get_link_style_for_local_file): operate on the passed
        in GnomeVFSInfo if we have it.

        * libnautilus-private/nautilus-dnd.c
        (nautilus_drag_selection_includes_special_link): upd
        for efficiency.
parent ca662271
2002-08-07 Michael Meeks <michael@ximian.com>
* libnautilus-private/nautilus-file.c
(nautilus_file_can_rename): pass in info if we
have it already.
* src/file-manager/fm-desktop-icon-view.c
(update_trash_link_and_delete_copies),
(update_home_link_and_delete_copies),
(delete_all_mount_links): kill in favour of
(update_desktop_directory): so we don't stat / mime
sniff everything 3+ times.
(update_link_and_delete_copies): push this method and
it's file / sniff loop upwards.
* src/file-manager/fm-directory-view.c
(special_link_in_selection): upd.
(fm_directory_link_type_in_selection): kill, unused.
* libnautilus-private/nautilus-link.c
(get_link_style_for_local_file): operate on the passed
in GnomeVFSInfo if we have it.
* libnautilus-private/nautilus-dnd.c
(nautilus_drag_selection_includes_special_link): upd
for efficiency.
2002-08-06 Alex Graveley <alex@ximian.com>
* libnautilus-private/nautilus-file.c (rename_guts): Use
......
......@@ -739,6 +739,7 @@ nautilus_drag_selection_includes_special_link (GList *selection_list)
GList *node;
char *uri, *local_path;
gboolean link_in_selection;
GnomeVFSFileInfo *info;
link_in_selection = FALSE;
......@@ -747,10 +748,20 @@ nautilus_drag_selection_includes_special_link (GList *selection_list)
/* FIXME bugzilla.gnome.org 43020: This does sync. I/O and works only locally. */
local_path = gnome_vfs_get_local_path_from_uri (uri);
link_in_selection = local_path != NULL
&& (nautilus_link_local_is_trash_link (local_path) || nautilus_link_local_is_home_link (local_path) ||
nautilus_link_local_is_volume_link (local_path));
g_free (local_path);
if (local_path) {
info = gnome_vfs_file_info_new ();
gnome_vfs_get_file_info
(local_path, info,
GNOME_VFS_FILE_INFO_GET_MIME_TYPE |
GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
/* assume info is blank on failure */
link_in_selection = (nautilus_link_local_is_trash_link (local_path, info) ||
nautilus_link_local_is_home_link (local_path, info) ||
nautilus_link_local_is_volume_link (local_path, info));
gnome_vfs_file_info_unref (info);
g_free (local_path);
}
if (link_in_selection) {
break;
......
......@@ -770,7 +770,7 @@ nautilus_file_can_rename (NautilusFile *file)
/* FIXME: This reads the link file every time -- seems
* bad to do that even though it's known to be local.
*/
switch (nautilus_link_local_get_link_type (path)) {
switch (nautilus_link_local_get_link_type (path, file->details->info)) {
case NAUTILUS_LINK_TRASH:
case NAUTILUS_LINK_MOUNT:
can_rename = FALSE;
......
......@@ -69,26 +69,32 @@ get_link_style_for_mime_type (const char *mime_type)
}
static LinkStyle
get_link_style_for_local_file (const char *uri)
get_link_style_for_local_file (const char *uri, GnomeVFSFileInfo *opt_info)
{
LinkStyle type;
GnomeVFSFileInfo *info;
GnomeVFSResult result;
GnomeVFSFileInfo *info;
info = gnome_vfs_file_info_new ();
if (!(info = opt_info)) {
info = gnome_vfs_file_info_new ();
result = gnome_vfs_get_file_info (uri, info,
GNOME_VFS_FILE_INFO_GET_MIME_TYPE
| GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
result = gnome_vfs_get_file_info (uri, info,
GNOME_VFS_FILE_INFO_GET_MIME_TYPE |
GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
if (result != GNOME_VFS_OK) {
gnome_vfs_file_info_unref (info);
info = NULL;
}
}
if (result == GNOME_VFS_OK
&& (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE) != 0) {
if (info && info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE) {
type = get_link_style_for_mime_type (info->mime_type);
} else {
type = not_link;
}
gnome_vfs_file_info_unref (info);
if (!opt_info && info)
gnome_vfs_file_info_unref (info);
return type;
}
......@@ -121,7 +127,7 @@ nautilus_link_local_set_icon (const char *uri, const char *icon_name)
NautilusFile *file;
GList *attributes;
switch (get_link_style_for_local_file (uri)) {
switch (get_link_style_for_local_file (uri, NULL)) {
case desktop:
result = nautilus_link_desktop_file_local_set_icon (uri, icon_name);
break;
......@@ -148,7 +154,7 @@ nautilus_link_local_set_link_uri (const char *uri, const char *link_uri)
NautilusFile *file;
GList *attributes;
switch (get_link_style_for_local_file (uri)) {
switch (get_link_style_for_local_file (uri, NULL)) {
case desktop:
/* FIXME: May want to implement this for desktop files too */
result = FALSE;
......@@ -174,7 +180,7 @@ gboolean
nautilus_link_local_set_type (const char *uri,
NautilusLinkType type)
{
switch (get_link_style_for_local_file (uri)) {
switch (get_link_style_for_local_file (uri, NULL)) {
case desktop:
/* FIXME: May want to implement this for desktop files too */
return FALSE;
......@@ -189,7 +195,7 @@ nautilus_link_local_set_type (const char *uri,
char *
nautilus_link_local_get_additional_text (const char *uri)
{
switch (get_link_style_for_local_file (uri)) {
switch (get_link_style_for_local_file (uri, NULL)) {
case desktop:
return nautilus_link_desktop_file_local_get_additional_text (uri);
case historical:
......@@ -203,7 +209,7 @@ nautilus_link_local_get_additional_text (const char *uri)
char *
nautilus_link_local_get_link_uri (const char *uri)
{
switch (get_link_style_for_local_file (uri)) {
switch (get_link_style_for_local_file (uri, NULL)) {
case desktop:
return nautilus_link_desktop_file_local_get_link_uri (uri);
case historical:
......@@ -215,9 +221,9 @@ nautilus_link_local_get_link_uri (const char *uri)
/* Returns the link type of the link file. */
NautilusLinkType
nautilus_link_local_get_link_type (const char *uri)
nautilus_link_local_get_link_type (const char *uri, GnomeVFSFileInfo *info)
{
switch (get_link_style_for_local_file (uri)) {
switch (get_link_style_for_local_file (uri, info)) {
case desktop:
return nautilus_link_desktop_file_local_get_link_type (uri);
case historical:
......@@ -273,27 +279,27 @@ nautilus_link_get_link_icon_given_file_contents (const char *uri,
}
gboolean
nautilus_link_local_is_volume_link (const char *uri)
nautilus_link_local_is_volume_link (const char *uri, GnomeVFSFileInfo *info)
{
return (nautilus_link_local_get_link_type (uri) == NAUTILUS_LINK_MOUNT);
return (nautilus_link_local_get_link_type (uri, info) == NAUTILUS_LINK_MOUNT);
}
gboolean
nautilus_link_local_is_home_link (const char *uri)
nautilus_link_local_is_home_link (const char *uri, GnomeVFSFileInfo *info)
{
return (nautilus_link_local_get_link_type (uri) == NAUTILUS_LINK_HOME);
return (nautilus_link_local_get_link_type (uri, info) == NAUTILUS_LINK_HOME);
}
gboolean
nautilus_link_local_is_trash_link (const char *uri)
nautilus_link_local_is_trash_link (const char *uri, GnomeVFSFileInfo *info)
{
return (nautilus_link_local_get_link_type (uri) == NAUTILUS_LINK_TRASH);
return (nautilus_link_local_get_link_type (uri, info) == NAUTILUS_LINK_TRASH);
}
gboolean
nautilus_link_local_is_special_link (const char *uri)
{
switch (nautilus_link_local_get_link_type (uri)) {
switch (nautilus_link_local_get_link_type (uri, NULL)) {
case NAUTILUS_LINK_HOME:
if (eel_preferences_get_boolean (NAUTILUS_PREFERENCES_DESKTOP_IS_HOME_DIR)) {
return FALSE;
......
......@@ -28,6 +28,7 @@
#include <gdk/gdktypes.h>
#include <libgnome/gnome-desktop-item.h>
#include <libgnomevfs/gnome-vfs-file-info.h>
/* Link types */
typedef enum {
......@@ -79,23 +80,27 @@ char * nautilus_link_local_get_additional_text (const char
/* Returns the link type of a link file.
* Works only if the file is local and does sync. I/O
*/
NautilusLinkType nautilus_link_local_get_link_type (const char *uri);
NautilusLinkType nautilus_link_local_get_link_type (const char *uri,
GnomeVFSFileInfo *info);
/* Returns if a link is a mount link.
* Works only if the file is local and does sync. I/O
* the Mime type field is neccessary for correct detection.
*/
gboolean nautilus_link_local_is_volume_link (const char *uri);
gboolean nautilus_link_local_is_volume_link (const char *uri,
GnomeVFSFileInfo *info);
/* Returns if a link is a home link.
* Works only if the file is local and does sync. I/O
* the Mime type field is neccessary for correct detection.
*/
gboolean nautilus_link_local_is_home_link (const char *uri);
gboolean nautilus_link_local_is_home_link (const char *uri,
GnomeVFSFileInfo *info);
/* Returns if a link is a trash link.
* Works only if the file is local and does sync. I/O
* the Mime type field is neccessary for correct detection.
*/
gboolean nautilus_link_local_is_trash_link (const char *uri);
gboolean nautilus_link_local_is_trash_link (const char *uri,
GnomeVFSFileInfo *info);
/* Returns TRUE if the link is special (i.e. can NOT be copied or deleted), FALSE otherwise.
* Works only if the file is local and does sync. I/O
......
......@@ -605,6 +605,7 @@ nautilus_thumbnail_load_framed_image (const char *path)
(pixbuf, frame,
left_offset, top_offset, right_offset, bottom_offset);
g_object_unref (pixbuf);
return pixbuf_with_frame;
}
......
......@@ -98,6 +98,12 @@ typedef struct {
char *mount_path;
} MountParameters;
typedef enum {
DELETE_MOUNT_LINKS = 1<<0,
UPDATE_HOME_LINK = 1<<1,
UPDATE_TRASH_LINK = 1<<2
} UpdateType;
static void fm_desktop_icon_view_init (FMDesktopIconView *desktop_icon_view);
static void fm_desktop_icon_view_class_init (FMDesktopIconViewClass *klass);
static void fm_desktop_icon_view_trash_state_changed_callback (NautilusTrashMonitor *trash,
......@@ -111,9 +117,7 @@ static void volume_mounted_callback (NautilusVolum
static void volume_unmounted_callback (NautilusVolumeMonitor *monitor,
NautilusVolume *volume,
FMDesktopIconView *icon_view);
static void delete_all_mount_links (void);
static void update_home_link_and_delete_copies (void);
static void update_trash_link_and_delete_copies (void);
static void update_desktop_directory (UpdateType type);
static gboolean real_supports_auto_layout (FMIconView *view);
static void real_merge_menus (FMDirectoryView *view);
static void real_update_menus (FMDirectoryView *view);
......@@ -263,7 +267,7 @@ fm_desktop_icon_view_finalize (GObject *object)
}
/* Delete all of the link files. */
delete_all_mount_links ();
update_desktop_directory (DELETE_MOUNT_LINKS);
eel_preferences_remove_callback (NAUTILUS_PREFERENCES_HOME_URI,
home_uri_changed,
......@@ -525,7 +529,7 @@ default_zoom_level_changed (gpointer user_data)
static void
home_uri_changed (gpointer callback_data)
{
update_home_link_and_delete_copies ();
update_desktop_directory (UPDATE_HOME_LINK);
}
static gboolean
......@@ -673,9 +677,7 @@ fm_desktop_icon_view_init (FMDesktopIconView *desktop_icon_view)
nautilus_icon_container_set_layout_mode (icon_container,
NAUTILUS_ICON_LAYOUT_T_B_L_R);
delete_all_mount_links ();
update_home_link_and_delete_copies ();
update_trash_link_and_delete_copies ();
update_desktop_directory (DELETE_MOUNT_LINKS | UPDATE_HOME_LINK | UPDATE_TRASH_LINK);
/* Create initial mount links */
nautilus_volume_monitor_each_mounted_volume (nautilus_volume_monitor_get (),
......@@ -949,7 +951,7 @@ trash_link_is_selection (FMDirectoryView *view)
/* It's probably OK that this only works for local
* items, since the trash we care about is on the desktop.
*/
if (nautilus_link_local_is_trash_link (uri)) {
if (nautilus_link_local_is_trash_link (uri, NULL)) {
result = TRUE;
}
g_free (uri);
......@@ -977,7 +979,7 @@ volume_link_is_selection (FMDirectoryView *view)
/* It's probably OK that this only works for local
* items, since the volume we care about is on the desktop.
*/
if (nautilus_link_local_is_volume_link (uri)) {
if (nautilus_link_local_is_volume_link (uri, NULL)) {
result = TRUE;
}
g_free (uri);
......@@ -1087,124 +1089,6 @@ volume_unmounted_callback (NautilusVolumeMonitor *monitor,
g_free (link_path);
}
/* update_link_and_delete_copies
*
* Look for a particular type of link on the desktop. If the right
* link is there, update its target URI. Delete any extra links of
* that type.
*
* @is_link_function: predicate function to test whether a link is the right type.
* @link_name: if non-NULL, only a link with this name is considered a match.
* @link_target_uri: new URI to set as link target.
*/
static gboolean
update_link_and_delete_copies (gboolean (*is_link_function) (const char *path),
const char *link_name,
const char *link_target_uri)
{
DIR *dir;
gboolean found_link;
struct dirent *dir_entry;
char *link_path;
dir = opendir (desktop_directory);
if (dir == NULL) {
return FALSE;
}
found_link = FALSE;
while ((dir_entry = readdir (dir)) != NULL) {
link_path = g_build_filename (desktop_directory, dir_entry->d_name, NULL);
if ((* is_link_function) (link_path)) {
if (!found_link &&
(link_name == NULL || strcmp (dir_entry->d_name, link_name) == 0)) {
nautilus_link_local_set_link_uri (link_path, link_target_uri);
found_link = TRUE;
} else {
unlink_and_notify (link_path);
}
}
g_free (link_path);
}
closedir (dir);
return found_link;
}
/* update_home_link_and_delete_copies
*
* Add an icon representing the user's home directory on the desktop.
* Create if necessary
*/
static void
update_home_link_and_delete_copies (void)
{
char *home_link_name, *home_uri;
/* Note to translators: If it's hard to compose a good home
* icon name from the user name, you can use a string without
* an "%s" here, in which case the home icon name will not
* include the user's name, which should be fine. To avoid a
* warning, put "%.0s" somewhere in the string, which will
* match the user name string passed by the C code, but not
* put the user name in the final string.
*/
home_link_name = g_strdup_printf (_("%s's Home"), g_get_user_name ());
#ifdef WEB_NAVIGATION_ENABLED
home_uri = eel_preferences_get (NAUTILUS_PREFERENCES_HOME_URI);
#else
home_uri = gnome_vfs_get_uri_from_local_path (g_get_home_dir ());
#endif
if (!update_link_and_delete_copies (nautilus_link_local_is_home_link,
NULL,
home_uri)
&& !eel_preferences_get_boolean (NAUTILUS_PREFERENCES_DESKTOP_IS_HOME_DIR)) {
nautilus_link_local_create (desktop_directory,
home_link_name,
"desktop-home",
home_uri,
NULL,
NAUTILUS_LINK_HOME);
}
g_free (home_link_name);
g_free (home_uri);
}
static void
update_trash_link_and_delete_copies (void)
{
/* Check for trash link */
if (!update_link_and_delete_copies (nautilus_link_local_is_trash_link,
TRASH_LINK_NAME,
EEL_TRASH_URI)) {
nautilus_link_local_create (desktop_directory,
TRASH_LINK_NAME,
"trash-empty",
EEL_TRASH_URI,
NULL,
NAUTILUS_LINK_TRASH);
}
/* Make sure link represents current trash state */
fm_desktop_icon_view_trash_state_changed_callback (nautilus_trash_monitor_get (),
nautilus_trash_monitor_is_empty (),
NULL);
}
static void
delete_all_mount_links (void)
{
update_link_and_delete_copies (nautilus_link_local_is_volume_link,
"", "");
}
static MountParameters *
mount_parameters_new (FMDesktopIconView *view, const char *mount_path)
{
......@@ -1564,3 +1448,125 @@ real_supports_zooming (FMDirectoryView *view)
*/
return FALSE;
}
/* update_desktop_directory
*
* Look for a particular type of link on the desktop. If the right
* link is there, update its target URI. Delete any extra links of
* that type.
*/
static void
update_desktop_directory (UpdateType type)
{
char *link_path;
GnomeVFSResult result;
GList *desktop_files, *l;
GnomeVFSFileInfo *info;
char *home_uri = NULL;
char *home_link_name = NULL;
gboolean found_home_link;
gboolean found_trash_link;
if (type & UPDATE_HOME_LINK) {
/* Note to translators: If it's hard to compose a good home
* icon name from the user name, you can use a string without
* an "%s" here, in which case the home icon name will not
* include the user's name, which should be fine. To avoid a
* warning, put "%.0s" somewhere in the string, which will
* match the user name string passed by the C code, but not
* put the user name in the final string.
*/
home_link_name = g_strdup_printf (_("%s's Home"), g_get_user_name ());
#ifdef WEB_NAVIGATION_ENABLED
home_uri = eel_preferences_get (NAUTILUS_PREFERENCES_HOME_URI);
#else
home_uri = gnome_vfs_get_uri_from_local_path (g_get_home_dir ());
#endif
}
result = gnome_vfs_directory_list_load
(&desktop_files, desktop_directory,
GNOME_VFS_FILE_INFO_GET_MIME_TYPE |
GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
found_home_link = found_trash_link = FALSE;
if (result != GNOME_VFS_OK) {
desktop_files = NULL;
}
for (l = desktop_files; l; l = l->next) {
info = l->data;
if (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_TYPE &&
info->type != GNOME_VFS_FILE_TYPE_REGULAR &&
info->type != GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK) {
continue;
}
link_path = g_build_filename (desktop_directory, info->name, NULL);
if (type & DELETE_MOUNT_LINKS &&
nautilus_link_local_is_volume_link (link_path, info)) {
unlink_and_notify (link_path);
}
if (type & UPDATE_HOME_LINK &&
nautilus_link_local_is_home_link (link_path, info)) {
if (!found_home_link) {
nautilus_link_local_set_link_uri (link_path, home_uri);
found_home_link = TRUE;
} else {
unlink_and_notify (link_path); /* kill duplicates */
}
}
if (type & UPDATE_TRASH_LINK &&
nautilus_link_local_is_trash_link (link_path, info)) {
if (!found_trash_link &&
!strcmp (TRASH_LINK_NAME, info->name)) {
nautilus_link_local_set_link_uri (link_path, EEL_TRASH_URI);
found_trash_link = TRUE;
} else {
unlink_and_notify (link_path); /* kill duplicates */
}
}
g_free (link_path);
}
gnome_vfs_file_info_list_free (desktop_files);
if (type & UPDATE_HOME_LINK && !found_home_link &&
!eel_preferences_get_boolean (NAUTILUS_PREFERENCES_DESKTOP_IS_HOME_DIR)) {
nautilus_link_local_create (desktop_directory,
home_link_name,
"desktop-home",
home_uri,
NULL,
NAUTILUS_LINK_HOME);
}
if (type & UPDATE_TRASH_LINK) {
if (!found_trash_link) {
nautilus_link_local_create (desktop_directory,
TRASH_LINK_NAME,
"trash-empty",
EEL_TRASH_URI,
NULL,
NAUTILUS_LINK_TRASH);
}
/* Make sure link represents current trash state */
fm_desktop_icon_view_trash_state_changed_callback (nautilus_trash_monitor_get (),
nautilus_trash_monitor_is_empty (),
NULL);
}
g_free (home_link_name);
g_free (home_uri);
}
......@@ -2882,42 +2882,6 @@ fm_directory_view_duplicate_selection (FMDirectoryView *view, GList *files,
eel_g_list_free_deep (uris);
}
gboolean
fm_directory_link_type_in_selection (FMDirectoryView *view,
NautilusLinkType link_type)
{
gboolean saw_link;
GList *selection, *node;
NautilusFile *file;
char *uri;
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), FALSE);
saw_link = FALSE;
selection = fm_directory_view_get_selection (FM_DIRECTORY_VIEW (view));
for (node = selection; node != NULL; node = node->next) {
file = NAUTILUS_FILE (node->data);
uri = nautilus_file_get_uri (file);
/* FIXME: This reads the link file every single time. */
saw_link = nautilus_file_is_local (file)
&& nautilus_file_is_nautilus_link (file)
&& nautilus_link_local_get_link_type (uri) == link_type;
g_free (uri);
if (saw_link) {
break;
}
}
nautilus_file_list_free (selection);
return saw_link;
}
/* special_link_in_selection
*
* Return TRUE if one of our special links is in the selection.
......
......@@ -276,7 +276,7 @@ get_sort_category (NautilusFile *file)
uri = nautilus_file_get_uri (file);
switch (nautilus_link_local_get_link_type (uri)) {
switch (nautilus_link_local_get_link_type (uri, NULL)) {
case NAUTILUS_LINK_HOME:
category = SORT_HOME_LINK;
break;
......
......@@ -2255,7 +2255,7 @@ get_target_file (NautilusFile *file)
if (nautilus_file_is_local (file)) {
uri = nautilus_file_get_uri (file);
switch (nautilus_link_local_get_link_type (uri)) {
switch (nautilus_link_local_get_link_type (uri, NULL)) {
case NAUTILUS_LINK_MOUNT:
case NAUTILUS_LINK_TRASH:
case NAUTILUS_LINK_HOME:
......
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