Commit c796ee4c authored by Darin Adler's avatar Darin Adler

Added interface to get a NautilusFile for a specific file rather than a

	* libnautilus/nautilus-directory.h:
	(nautilus_file_get):
	(nautilus_file_detach):
	(nautilus_directory_finalize):
	(nautilus_file_unref):
	Added interface to get a NautilusFile for a specific file rather than
	a file from a directory that we are scanning.

	* libnautilus/nautilus-glib-extensions.c:
	(check_tm_to_g_date):
	A little cleanup of the self-check code.

	* libnautilus/Makefile.am:
	libnautilus/libnautilus.h:
	libnautilus/nautilus-alloc.h:
	libnautilus/nautilus-directory.h:
	Moved g_alloca into its own header file so you don't have to include
	all the Bonobo stuff just to use g_alloca.
parent 6d547890
2000-01-26 Darin Adler <darin@eazel.com>
* libnautilus/nautilus-directory.h:
(nautilus_file_get):
(nautilus_file_detach):
(nautilus_directory_finalize):
(nautilus_file_unref):
Added interface to get a NautilusFile for a specific file rather than
a file from a directory that we are scanning.
* libnautilus/nautilus-glib-extensions.c:
(check_tm_to_g_date):
A little cleanup of the self-check code.
* libnautilus/Makefile.am:
libnautilus/libnautilus.h:
libnautilus/nautilus-alloc.h:
libnautilus/nautilus-directory.h:
Moved g_alloca into its own header file so you don't have to include
all the Bonobo stuff just to use g_alloca.
2000-01-26 Andy Hertzfeld <andy@eazel.com>
* src/file-manager/fm-icon-cache.c:
......
......@@ -30,6 +30,7 @@ libnautilusinclude_HEADERS= \
gtkflist.h \
gtkscrollframe.h \
nautilus.h \
nautilus-alloc.h \
nautilus-background.h \
nautilus-debug.h \
nautilus-directory.h \
......
......@@ -4,6 +4,7 @@
* libnautilus: A library for nautilus view components.
*
* Copyright (C) 1999, 2000 Red Hat, Inc.
* Copyright (C) 2000 Eazel, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -22,23 +23,18 @@
* Author: Elliot Lee <sopwith@redhat.com>
*
*/
/* libnautilus.h: Main library header file */
#ifndef LIBNAUTILUS_H
#define LIBNAUTILUS_H 1
#ifdef HAVE_ALLOCA_H
#include <alloca.h>
#endif
#ifndef g_alloca
#define g_alloca alloca
#endif
#define LIBNAUTILUS_H
#include <bonobo/gnome-bonobo.h>
#include <libnautilus/nautilus.h>
#include <libnautilus/nautilus-alloc.h>
#include <libnautilus/nautilus-directory.h>
#include <libnautilus/ntl-view-frame.h>
#include <libnautilus/ntl-meta-view-frame.h>
#include <libnautilus/ntl-content-view-frame.h>
#endif
#endif /* LIBNAUTILUS_H */
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
Nautilus extensions to things like malloc and alloca.
Copyright (C) 2000 Eazel, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public
License along with this program; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Author: Darin Adler <darin@eazel.com>
*/
#ifdef HAVE_ALLOCA_H
#include <alloca.h>
#endif
#ifndef g_alloca
#define g_alloca alloca
#endif
......@@ -27,12 +27,14 @@
#endif
#include "nautilus-directory.h"
#include "libnautilus.h"
#include <stdlib.h>
#include <gtk/gtkmain.h>
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-i18n.h>
#include <libgnomevfs/gnome-vfs-types.h>
#include <libgnomevfs/gnome-vfs-uri.h>
#include <libgnomevfs/gnome-vfs-file-info.h>
......@@ -43,6 +45,7 @@
#include <gnome-xml/tree.h>
#include <gnome-xml/xmlmemory.h>
#include "nautilus-alloc.h"
#include "nautilus-glib-extensions.h"
#include "nautilus-gtk-macros.h"
#include "nautilus-lib-self-check-functions.h"
......@@ -73,6 +76,8 @@ static void nautilus_directory_write_metafile (NautilusDirectory *directory);
static void nautilus_directory_request_write_metafile (NautilusDirectory *directory);
static void nautilus_directory_remove_write_metafile_idle (NautilusDirectory *directory);
static void nautilus_file_detach (NautilusFile *file);
NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusDirectory, nautilus_directory, GTK_TYPE_OBJECT)
struct _NautilusDirectoryDetails
......@@ -132,20 +137,12 @@ nautilus_directory_finalize (GtkObject *object)
g_hash_table_remove (directory_objects, directory->details->uri_text);
/* Unref all the files. */
/* Let go of all the files. */
while (directory->details->files != NULL) {
NautilusFile *file;
file = directory->details->files->data;
/* Detach the file from this directory. */
g_assert (file->directory == directory);
file->directory = NULL;
/* Let the reference go. */
nautilus_file_unref (file);
directory->details->files = g_list_remove_link (directory->details->files, directory->details->files);
nautilus_file_detach (directory->details->files->data);
directory->details->files = g_list_remove_link
(directory->details->files, directory->details->files);
}
g_free (directory->details->uri_text);
......@@ -760,7 +757,7 @@ nautilus_directory_new_file (NautilusDirectory *directory, GnomeVFSFileInfo *inf
gnome_vfs_file_info_ref (info);
file = g_new (NautilusFile, 1);
file->ref_count = 1;
file->ref_count = 0;
file->directory = directory;
file->info = info;
......@@ -769,18 +766,79 @@ nautilus_directory_new_file (NautilusDirectory *directory, GnomeVFSFileInfo *inf
return file;
}
/**
* nautilus_file_get:
* @uri: URI of file to get.
*
* Get a file given a uri.
* Returns a referenced object. Unref when finished.
* If two windows are viewing the same uri, the file object is shared.
*/
NautilusFile *
nautilus_file_get (const char *uri)
{
GnomeVFSResult result;
GnomeVFSFileInfo file_info;
GnomeVFSURI *vfs_uri, *directory_vfs_uri;
char *directory_uri;
NautilusDirectory *directory;
NautilusFile *file;
/* Get info on the file. */
result = gnome_vfs_get_file_info (uri, &file_info,
GNOME_VFS_FILE_INFO_FASTMIMETYPE, NULL);
if (result != GNOME_VFS_OK)
return NULL;
/* Make VFS version of URI. */
vfs_uri = gnome_vfs_uri_new (uri);
if (vfs_uri == NULL)
return NULL;
/* Make VFS version of directory URI. */
directory_vfs_uri = gnome_vfs_uri_get_parent (vfs_uri);
gnome_vfs_uri_unref (vfs_uri);
if (directory_vfs_uri == NULL)
return NULL;
/* Make text version of directory URI. */
directory_uri = gnome_vfs_uri_to_string (directory_vfs_uri,
GNOME_VFS_URI_HIDE_NONE);
gnome_vfs_uri_unref (directory_vfs_uri);
/* Get object that represents the directory. */
directory = nautilus_directory_get (directory_uri);
g_free (directory_uri);
if (directory == NULL)
return NULL;
file = nautilus_directory_new_file (directory, &file_info);
gtk_object_unref (GTK_OBJECT (directory));
return file;
}
void
nautilus_file_unref (NautilusFile *file)
{
g_return_if_fail (file != NULL);
g_return_if_fail (file->ref_count != 0);
g_assert (file->ref_count != 0);
g_assert (file->directory != NULL);
/* Decrement the ref count. */
if (--file->ref_count != 0)
return;
/* No references left, so it's time to release our hold on the directory. */
gtk_object_unref (GTK_OBJECT (file->directory));
}
static void
nautilus_file_detach (NautilusFile *file)
{
g_assert (file->ref_count == 0);
/* Destroy the file object. */
g_assert (file->directory == NULL);
gnome_vfs_file_info_unref (file->info);
}
......@@ -868,7 +926,7 @@ nautilus_file_get_date_as_string (NautilusFile *file)
today = g_date_new ();
g_date_set_time (today, time (NULL));
/* Overflow results in a large number; fine for our purposes */
/* Overflow results in a large number; fine for our purposes. */
file_date_age = g_date_julian (today) - g_date_julian (file_date);
g_date_free (file_date);
......@@ -902,7 +960,6 @@ nautilus_file_get_date_as_string (NautilusFile *file)
format = _("%-m/%-d/%y %-I:%M %p");
}
return nautilus_strdup_strftime (format, file_time);
}
......
......@@ -105,6 +105,9 @@ gboolean nautilus_directory_is_ready_for_layout (NautilusDirectory
NautilusFile * nautilus_directory_new_file (NautilusDirectory *directory,
GnomeVFSFileInfo *info);
/* Getting at a single file. */
NautilusFile * nautilus_file_get (const char *uri);
/* Basic operations on file objects. */
void nautilus_file_ref (NautilusFile *file);
void nautilus_file_unref (NautilusFile *file);
......
......@@ -81,23 +81,22 @@ static void
check_tm_to_g_date (time_t time)
{
struct tm *before_conversion;
struct tm *after_conversion;
struct tm after_conversion;
GDate *date;
before_conversion = localtime (&time);
date = nautilus_g_date_new_tm (before_conversion);
after_conversion = g_new0 (struct tm, 1);
g_date_to_struct_tm (date, after_conversion);
g_date_to_struct_tm (date, &after_conversion);
NAUTILUS_CHECK_INTEGER_RESULT (after_conversion->tm_mday,
g_date_free (date);
NAUTILUS_CHECK_INTEGER_RESULT (after_conversion.tm_mday,
before_conversion->tm_mday);
NAUTILUS_CHECK_INTEGER_RESULT (after_conversion->tm_mon,
NAUTILUS_CHECK_INTEGER_RESULT (after_conversion.tm_mon,
before_conversion->tm_mon);
NAUTILUS_CHECK_INTEGER_RESULT (after_conversion->tm_year,
NAUTILUS_CHECK_INTEGER_RESULT (after_conversion.tm_year,
before_conversion->tm_year);
g_free (after_conversion);
}
void
......
......@@ -30,6 +30,7 @@ libnautilusinclude_HEADERS= \
gtkflist.h \
gtkscrollframe.h \
nautilus.h \
nautilus-alloc.h \
nautilus-background.h \
nautilus-debug.h \
nautilus-directory.h \
......
......@@ -4,6 +4,7 @@
* libnautilus: A library for nautilus view components.
*
* Copyright (C) 1999, 2000 Red Hat, Inc.
* Copyright (C) 2000 Eazel, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -22,23 +23,18 @@
* Author: Elliot Lee <sopwith@redhat.com>
*
*/
/* libnautilus.h: Main library header file */
#ifndef LIBNAUTILUS_H
#define LIBNAUTILUS_H 1
#ifdef HAVE_ALLOCA_H
#include <alloca.h>
#endif
#ifndef g_alloca
#define g_alloca alloca
#endif
#define LIBNAUTILUS_H
#include <bonobo/gnome-bonobo.h>
#include <libnautilus/nautilus.h>
#include <libnautilus/nautilus-alloc.h>
#include <libnautilus/nautilus-directory.h>
#include <libnautilus/ntl-view-frame.h>
#include <libnautilus/ntl-meta-view-frame.h>
#include <libnautilus/ntl-content-view-frame.h>
#endif
#endif /* LIBNAUTILUS_H */
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
Nautilus extensions to things like malloc and alloca.
Copyright (C) 2000 Eazel, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public
License along with this program; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Author: Darin Adler <darin@eazel.com>
*/
#ifdef HAVE_ALLOCA_H
#include <alloca.h>
#endif
#ifndef g_alloca
#define g_alloca alloca
#endif
......@@ -27,12 +27,14 @@
#endif
#include "nautilus-directory.h"
#include "libnautilus.h"
#include <stdlib.h>
#include <gtk/gtkmain.h>
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-i18n.h>
#include <libgnomevfs/gnome-vfs-types.h>
#include <libgnomevfs/gnome-vfs-uri.h>
#include <libgnomevfs/gnome-vfs-file-info.h>
......@@ -43,6 +45,7 @@
#include <gnome-xml/tree.h>
#include <gnome-xml/xmlmemory.h>
#include "nautilus-alloc.h"
#include "nautilus-glib-extensions.h"
#include "nautilus-gtk-macros.h"
#include "nautilus-lib-self-check-functions.h"
......@@ -73,6 +76,8 @@ static void nautilus_directory_write_metafile (NautilusDirectory *directory);
static void nautilus_directory_request_write_metafile (NautilusDirectory *directory);
static void nautilus_directory_remove_write_metafile_idle (NautilusDirectory *directory);
static void nautilus_file_detach (NautilusFile *file);
NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusDirectory, nautilus_directory, GTK_TYPE_OBJECT)
struct _NautilusDirectoryDetails
......@@ -132,20 +137,12 @@ nautilus_directory_finalize (GtkObject *object)
g_hash_table_remove (directory_objects, directory->details->uri_text);
/* Unref all the files. */
/* Let go of all the files. */
while (directory->details->files != NULL) {
NautilusFile *file;
file = directory->details->files->data;
/* Detach the file from this directory. */
g_assert (file->directory == directory);
file->directory = NULL;
/* Let the reference go. */
nautilus_file_unref (file);
directory->details->files = g_list_remove_link (directory->details->files, directory->details->files);
nautilus_file_detach (directory->details->files->data);
directory->details->files = g_list_remove_link
(directory->details->files, directory->details->files);
}
g_free (directory->details->uri_text);
......@@ -760,7 +757,7 @@ nautilus_directory_new_file (NautilusDirectory *directory, GnomeVFSFileInfo *inf
gnome_vfs_file_info_ref (info);
file = g_new (NautilusFile, 1);
file->ref_count = 1;
file->ref_count = 0;
file->directory = directory;
file->info = info;
......@@ -769,18 +766,79 @@ nautilus_directory_new_file (NautilusDirectory *directory, GnomeVFSFileInfo *inf
return file;
}
/**
* nautilus_file_get:
* @uri: URI of file to get.
*
* Get a file given a uri.
* Returns a referenced object. Unref when finished.
* If two windows are viewing the same uri, the file object is shared.
*/
NautilusFile *
nautilus_file_get (const char *uri)
{
GnomeVFSResult result;
GnomeVFSFileInfo file_info;
GnomeVFSURI *vfs_uri, *directory_vfs_uri;
char *directory_uri;
NautilusDirectory *directory;
NautilusFile *file;
/* Get info on the file. */
result = gnome_vfs_get_file_info (uri, &file_info,
GNOME_VFS_FILE_INFO_FASTMIMETYPE, NULL);
if (result != GNOME_VFS_OK)
return NULL;
/* Make VFS version of URI. */
vfs_uri = gnome_vfs_uri_new (uri);
if (vfs_uri == NULL)
return NULL;
/* Make VFS version of directory URI. */
directory_vfs_uri = gnome_vfs_uri_get_parent (vfs_uri);
gnome_vfs_uri_unref (vfs_uri);
if (directory_vfs_uri == NULL)
return NULL;
/* Make text version of directory URI. */
directory_uri = gnome_vfs_uri_to_string (directory_vfs_uri,
GNOME_VFS_URI_HIDE_NONE);
gnome_vfs_uri_unref (directory_vfs_uri);
/* Get object that represents the directory. */
directory = nautilus_directory_get (directory_uri);
g_free (directory_uri);
if (directory == NULL)
return NULL;
file = nautilus_directory_new_file (directory, &file_info);
gtk_object_unref (GTK_OBJECT (directory));
return file;
}
void
nautilus_file_unref (NautilusFile *file)
{
g_return_if_fail (file != NULL);
g_return_if_fail (file->ref_count != 0);
g_assert (file->ref_count != 0);
g_assert (file->directory != NULL);
/* Decrement the ref count. */
if (--file->ref_count != 0)
return;
/* No references left, so it's time to release our hold on the directory. */
gtk_object_unref (GTK_OBJECT (file->directory));
}
static void
nautilus_file_detach (NautilusFile *file)
{
g_assert (file->ref_count == 0);
/* Destroy the file object. */
g_assert (file->directory == NULL);
gnome_vfs_file_info_unref (file->info);
}
......@@ -868,7 +926,7 @@ nautilus_file_get_date_as_string (NautilusFile *file)
today = g_date_new ();
g_date_set_time (today, time (NULL));
/* Overflow results in a large number; fine for our purposes */
/* Overflow results in a large number; fine for our purposes. */
file_date_age = g_date_julian (today) - g_date_julian (file_date);
g_date_free (file_date);
......@@ -902,7 +960,6 @@ nautilus_file_get_date_as_string (NautilusFile *file)
format = _("%-m/%-d/%y %-I:%M %p");
}
return nautilus_strdup_strftime (format, file_time);
}
......
......@@ -105,6 +105,9 @@ gboolean nautilus_directory_is_ready_for_layout (NautilusDirectory
NautilusFile * nautilus_directory_new_file (NautilusDirectory *directory,
GnomeVFSFileInfo *info);
/* Getting at a single file. */
NautilusFile * nautilus_file_get (const char *uri);
/* Basic operations on file objects. */
void nautilus_file_ref (NautilusFile *file);
void nautilus_file_unref (NautilusFile *file);
......
......@@ -81,23 +81,22 @@ static void
check_tm_to_g_date (time_t time)
{
struct tm *before_conversion;
struct tm *after_conversion;
struct tm after_conversion;
GDate *date;
before_conversion = localtime (&time);
date = nautilus_g_date_new_tm (before_conversion);
after_conversion = g_new0 (struct tm, 1);
g_date_to_struct_tm (date, after_conversion);
g_date_to_struct_tm (date, &after_conversion);
NAUTILUS_CHECK_INTEGER_RESULT (after_conversion->tm_mday,
g_date_free (date);
NAUTILUS_CHECK_INTEGER_RESULT (after_conversion.tm_mday,
before_conversion->tm_mday);
NAUTILUS_CHECK_INTEGER_RESULT (after_conversion->tm_mon,
NAUTILUS_CHECK_INTEGER_RESULT (after_conversion.tm_mon,
before_conversion->tm_mon);
NAUTILUS_CHECK_INTEGER_RESULT (after_conversion->tm_year,
NAUTILUS_CHECK_INTEGER_RESULT (after_conversion.tm_year,
before_conversion->tm_year);
g_free (after_conversion);
}
void
......
......@@ -30,6 +30,7 @@ libnautilusinclude_HEADERS= \
gtkflist.h \
gtkscrollframe.h \
nautilus.h \
nautilus-alloc.h \
nautilus-background.h \
nautilus-debug.h \
nautilus-directory.h \
......
......@@ -4,6 +4,7 @@
* libnautilus: A library for nautilus view components.
*
* Copyright (C) 1999, 2000 Red Hat, Inc.
* Copyright (C) 2000 Eazel, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -22,23 +23,18 @@
* Author: Elliot Lee <sopwith@redhat.com>
*
*/
/* libnautilus.h: Main library header file */
#ifndef LIBNAUTILUS_H
#define LIBNAUTILUS_H 1
#ifdef HAVE_ALLOCA_H
#include <alloca.h>
#endif
#ifndef g_alloca
#define g_alloca alloca
#endif
#define LIBNAUTILUS_H
#include <bonobo/gnome-bonobo.h>
#include <libnautilus/nautilus.h>
#include <libnautilus/nautilus-alloc.h>
#include <libnautilus/nautilus-directory.h>
#include <libnautilus/ntl-view-frame.h>
#include <libnautilus/ntl-meta-view-frame.h>
#include <libnautilus/ntl-content-view-frame.h>
#endif
#endif /* LIBNAUTILUS_H */
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
Nautilus extensions to things like malloc and alloca.
Copyright (C) 2000 Eazel, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public
License along with this program; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Author: Darin Adler <darin@eazel.com>
*/
#ifdef HAVE_ALLOCA_H
#include <alloca.h>
#endif
#ifndef g_alloca
#define g_alloca alloca
#endif
......@@ -27,12 +27,14 @@
#endif
#include "nautilus-directory.h"
#include "libnautilus.h"
#include <stdlib.h>
#include <gtk/gtkmain.h>
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-i18n.h>
#include <libgnomevfs/gnome-vfs-types.h>
#include <libgnomevfs/gnome-vfs-uri.h>
#include <libgnomevfs/gnome-vfs-file-info.h>
......@@ -43,6 +45,7 @@
#include <gnome-xml/tree.h>
#include <gnome-xml/xmlmemory.h>
#include "nautilus-alloc.h"
#include "nautilus-glib-extensions.h"
#include "nautilus-gtk-macros.h"
#include "nautilus-lib-self-check-functions.h"
......@@ -73,6 +76,8 @@ static void nautilus_directory_write_metafile (NautilusDirectory *directory);
static void nautilus_directory_request_write_metafile (NautilusDirectory *directory);
static void nautilus_directory_remove_write_metafile_idle (NautilusDirectory *directory);
static void nautilus_file_detach (NautilusFile *file);
NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusDirectory, nautilus_directory, GTK_TYPE_OBJECT)
struct _NautilusDirectoryDetails
......@@ -132,20 +137,12 @@ nautilus_directory_finalize (GtkObject *object)
g_hash_table_remove (directory_objects, directory->details->uri_text);
/* Unref all the files. */
/* Let go of all the files. */
while (directory->details->files != NULL) {
NautilusFile *file;
file = directory->details->files->data;
/* Detach the file from this directory. */
g_assert (file->directory == directory);
file->directory = NULL;
/* Let the reference go. */
nautilus_file_unref (file);
directory->details->files = g_list_remove_link (directory->details->files, directory->details->files);
nautilus_file_detach (directory->details->files->data);
directory->details->files = g_list_remove_link
(directory->details->files, directory->details->files);
}
g_free (directory->details->uri_text);
......@@ -760,7 +757,7 @@ nautilus_directory_new_file (NautilusDirectory *directory, GnomeVFSFileInfo *inf
gnome_vfs_file_info_ref (info);
file = g_new (NautilusFile, 1);
file->ref_count = 1;