forked from AuroraMiddleware/gtk
Pass statbufs down to xdg_mime_get_mime_type_for_file() where possible, to
2005-09-01 Matthias Clasen <mclasen@redhat.com> * gtk/gtkfilesystemunix.c: Pass statbufs down to xdg_mime_get_mime_type_for_file() where possible, to avoid useless re-stating.
This commit is contained in:
parent
9a4ec3526d
commit
6224a37708
@ -1,5 +1,9 @@
|
||||
2005-09-01 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* gtk/gtkfilesystemunix.c: Pass statbufs down to
|
||||
xdg_mime_get_mime_type_for_file() where possible, to avoid
|
||||
useless re-stating.
|
||||
|
||||
* gtk/gtkaction.c (gtk_action_get_accel_closure): Fix doc
|
||||
typo. (#314921, Guillaume Cottenceau)
|
||||
|
||||
|
@ -1,5 +1,9 @@
|
||||
2005-09-01 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* gtk/gtkfilesystemunix.c: Pass statbufs down to
|
||||
xdg_mime_get_mime_type_for_file() where possible, to avoid
|
||||
useless re-stating.
|
||||
|
||||
* gtk/gtkaction.c (gtk_action_get_accel_closure): Fix doc
|
||||
typo. (#314921, Guillaume Cottenceau)
|
||||
|
||||
|
@ -1224,7 +1224,7 @@ get_icon_type_from_path (GtkFileSystemUnix *system_unix,
|
||||
|
||||
icon_type = get_icon_type (filename, NULL);
|
||||
if (icon_type == ICON_REGULAR)
|
||||
*mime_type = xdg_mime_get_mime_type_for_file (filename);
|
||||
*mime_type = xdg_mime_get_mime_type_for_file (filename, NULL);
|
||||
|
||||
return icon_type;
|
||||
}
|
||||
@ -1923,7 +1923,7 @@ create_stat_info_entry_and_emit_add (GtkFileFolderUnix *folder_unix,
|
||||
entry->statbuf = *statbuf;
|
||||
|
||||
if ((folder_unix->types & GTK_FILE_INFO_MIME_TYPE) != 0)
|
||||
entry->mime_type = g_strdup (xdg_mime_get_mime_type_for_file (filename));
|
||||
entry->mime_type = g_strdup (xdg_mime_get_mime_type_for_file (filename, statbuf));
|
||||
|
||||
g_hash_table_insert (folder_unix->stat_info,
|
||||
g_strdup (basename),
|
||||
@ -2002,7 +2002,7 @@ gtk_file_folder_unix_get_info (GtkFileFolder *folder,
|
||||
}
|
||||
|
||||
if ((types & GTK_FILE_INFO_MIME_TYPE) != 0)
|
||||
mime_type = xdg_mime_get_mime_type_for_file (filename);
|
||||
mime_type = xdg_mime_get_mime_type_for_file (filename, &statbuf);
|
||||
else
|
||||
mime_type = NULL;
|
||||
|
||||
@ -2150,9 +2150,12 @@ cb_fill_in_mime_type (gpointer key, gpointer value, gpointer user_data)
|
||||
struct stat_info_entry *entry = value;
|
||||
GtkFileFolderUnix *folder_unix = user_data;
|
||||
char *fullname = g_build_filename (folder_unix->filename, basename, NULL);
|
||||
struct stat *statbuf = NULL;
|
||||
|
||||
/* FIXME: Should not need to re-stat. */
|
||||
const char *mime_type = xdg_mime_get_mime_type_for_file (fullname);
|
||||
if (folder_unix->have_stat)
|
||||
statbuf = &entry->statbuf;
|
||||
|
||||
const char *mime_type = xdg_mime_get_mime_type_for_file (fullname, statbuf);
|
||||
entry->mime_type = g_strdup (mime_type);
|
||||
|
||||
g_free (fullname);
|
||||
|
@ -1,3 +1,11 @@
|
||||
2005-09-01 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* xdgmime.h:
|
||||
* xdgmime.c (xdg_mime_get_mime_type_for_file): Take
|
||||
a struct statbuf * as argument.
|
||||
|
||||
* test-mime.c (main): Adjust.
|
||||
|
||||
2005-08-24 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* === Released 2.8.2 ===
|
||||
|
@ -108,7 +108,7 @@ main (int argc, char *argv[])
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
file_name = argv[i];
|
||||
result = xdg_mime_get_mime_type_for_file (file_name);
|
||||
result = xdg_mime_get_mime_type_for_file (file_name, NULL);
|
||||
printf ("File \"%s\" has a mime-type of %s\n", file_name, result);
|
||||
}
|
||||
|
||||
|
@ -447,14 +447,15 @@ xdg_mime_get_mime_type_for_data (const void *data,
|
||||
}
|
||||
|
||||
const char *
|
||||
xdg_mime_get_mime_type_for_file (const char *file_name)
|
||||
xdg_mime_get_mime_type_for_file (const char *file_name,
|
||||
struct stat *statbuf)
|
||||
{
|
||||
const char *mime_type;
|
||||
FILE *file;
|
||||
unsigned char *data;
|
||||
int max_extent;
|
||||
int bytes_read;
|
||||
struct stat statbuf;
|
||||
struct stat buf;
|
||||
const char *base_name;
|
||||
|
||||
if (file_name == NULL)
|
||||
@ -473,10 +474,17 @@ xdg_mime_get_mime_type_for_file (const char *file_name)
|
||||
if (mime_type != XDG_MIME_TYPE_UNKNOWN)
|
||||
return mime_type;
|
||||
|
||||
if (stat (file_name, &statbuf) != 0)
|
||||
return XDG_MIME_TYPE_UNKNOWN;
|
||||
if (!statbuf)
|
||||
{
|
||||
if (stat (file_name, &buf) != 0)
|
||||
return XDG_MIME_TYPE_UNKNOWN;
|
||||
|
||||
if (!S_ISREG (statbuf.st_mode))
|
||||
statbuf = &buf;
|
||||
}
|
||||
else
|
||||
printf ("don't restat\n");
|
||||
|
||||
if (!S_ISREG (statbuf->st_mode))
|
||||
return XDG_MIME_TYPE_UNKNOWN;
|
||||
|
||||
/* FIXME: Need to make sure that max_extent isn't totally broken. This could
|
||||
|
@ -30,6 +30,7 @@
|
||||
#define __XDG_MIME_H__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -69,7 +70,8 @@ extern const char *xdg_mime_type_unknown;
|
||||
|
||||
const char *xdg_mime_get_mime_type_for_data (const void *data,
|
||||
size_t len);
|
||||
const char *xdg_mime_get_mime_type_for_file (const char *file_name);
|
||||
const char *xdg_mime_get_mime_type_for_file (const char *file_name,
|
||||
struct stat *statbuf);
|
||||
const char *xdg_mime_get_mime_type_from_file_name (const char *file_name);
|
||||
int xdg_mime_is_valid_mime_type (const char *mime_type);
|
||||
int xdg_mime_mime_type_equal (const char *mime_a,
|
||||
|
Loading…
Reference in New Issue
Block a user