Commit 7e54248b authored by Owen Taylor's avatar Owen Taylor Committed by Owen Taylor

auto-ize.

Wed Jul 16 16:50:31 2003  Owen Taylor  <otaylor@redhat.com>

        * configure.ac Makefile.am: auto-ize.

        * xdgmime/: Add freedesktop.org MIME spec implementatin
        by Jonathan Blandford.

        * gtkfilesystem.[ch]: Add gtk_file_info_render_icon()
        gtk_file_info_set/get_icon_type to do icon handling
        based on MIME type. Add a simple icon caching system.

        * gtkfilesystemgnomevfs.c: Implement ensure_types()
        so that extending the set of types for a loaded
        directory works. Set the MIME type to get the default
        icon handling.

        * gtkfilesystemunix.c: Look up the MIME type using
        xdgmime.

        * gtkfilechooserimpldefault.c: Display icons in the list.
parent bc8567d4
...@@ -25,10 +25,12 @@ ...@@ -25,10 +25,12 @@
#include "gtkfilechooser.h" #include "gtkfilechooser.h"
#include "gtkfilesystemmodel.h" #include "gtkfilesystemmodel.h"
#include <gtk/gtkcellrendererpixbuf.h>
#include <gtk/gtkcellrenderertext.h> #include <gtk/gtkcellrenderertext.h>
#include <gtk/gtkentry.h> #include <gtk/gtkentry.h>
#include <gtk/gtkhbox.h> #include <gtk/gtkhbox.h>
#include <gtk/gtkhpaned.h> #include <gtk/gtkhpaned.h>
#include <gtk/gtkicontheme.h>
#include <gtk/gtklabel.h> #include <gtk/gtklabel.h>
#include <gtk/gtkscrolledwindow.h> #include <gtk/gtkscrolledwindow.h>
#include <gtk/gtktreeview.h> #include <gtk/gtktreeview.h>
...@@ -119,6 +121,11 @@ static void tree_name_data_func (GtkTreeViewColumn *tree_column, ...@@ -119,6 +121,11 @@ static void tree_name_data_func (GtkTreeViewColumn *tree_column,
GtkTreeModel *tree_model, GtkTreeModel *tree_model,
GtkTreeIter *iter, GtkTreeIter *iter,
gpointer data); gpointer data);
static void list_icon_data_func (GtkTreeViewColumn *tree_column,
GtkCellRenderer *cell,
GtkTreeModel *tree_model,
GtkTreeIter *iter,
gpointer data);
static void list_name_data_func (GtkTreeViewColumn *tree_column, static void list_name_data_func (GtkTreeViewColumn *tree_column,
GtkCellRenderer *cell, GtkCellRenderer *cell,
GtkTreeModel *tree_model, GtkTreeModel *tree_model,
...@@ -130,7 +137,7 @@ static void list_size_data_func (GtkTreeViewColumn *tree_column, ...@@ -130,7 +137,7 @@ static void list_size_data_func (GtkTreeViewColumn *tree_column,
GtkTreeIter *iter, GtkTreeIter *iter,
gpointer data); gpointer data);
GObjectClass *parent_class; static GObjectClass *parent_class;
GType GType
_gtk_file_chooser_impl_default_get_type (void) _gtk_file_chooser_impl_default_get_type (void)
...@@ -174,6 +181,8 @@ gtk_file_chooser_impl_default_class_init (GtkFileChooserImplDefaultClass *class) ...@@ -174,6 +181,8 @@ gtk_file_chooser_impl_default_class_init (GtkFileChooserImplDefaultClass *class)
{ {
GObjectClass *gobject_class = G_OBJECT_CLASS (class); GObjectClass *gobject_class = G_OBJECT_CLASS (class);
parent_class = g_type_class_peek_parent (class);
gobject_class->finalize = gtk_file_chooser_impl_default_finalize; gobject_class->finalize = gtk_file_chooser_impl_default_finalize;
gobject_class->constructor = gtk_file_chooser_impl_default_constructor; gobject_class->constructor = gtk_file_chooser_impl_default_constructor;
gobject_class->set_property = gtk_file_chooser_impl_default_set_property; gobject_class->set_property = gtk_file_chooser_impl_default_set_property;
...@@ -350,11 +359,19 @@ gtk_file_chooser_impl_default_constructor (GType type, ...@@ -350,11 +359,19 @@ gtk_file_chooser_impl_default_constructor (GType type,
column = gtk_tree_view_column_new (); column = gtk_tree_view_column_new ();
gtk_tree_view_column_set_title (column, "File name"); gtk_tree_view_column_set_title (column, "File name");
renderer = gtk_cell_renderer_pixbuf_new ();
gtk_tree_view_column_pack_start (column, renderer, TRUE);
gtk_tree_view_column_set_cell_data_func (column, renderer,
list_icon_data_func, impl, NULL);
gtk_tree_view_column_set_sort_column_id (column, 0);
renderer = gtk_cell_renderer_text_new (); renderer = gtk_cell_renderer_text_new ();
gtk_tree_view_column_pack_start (column, renderer, TRUE); gtk_tree_view_column_pack_start (column, renderer, TRUE);
gtk_tree_view_column_set_cell_data_func (column, renderer, gtk_tree_view_column_set_cell_data_func (column, renderer,
list_name_data_func, impl, NULL); list_name_data_func, impl, NULL);
gtk_tree_view_column_set_sort_column_id (column, 0); gtk_tree_view_column_set_sort_column_id (column, 0);
gtk_tree_view_append_column (GTK_TREE_VIEW (impl->list), column); gtk_tree_view_append_column (GTK_TREE_VIEW (impl->list), column);
column = gtk_tree_view_column_new (); column = gtk_tree_view_column_new ();
...@@ -822,6 +839,7 @@ tree_selection_changed (GtkTreeSelection *selection, ...@@ -822,6 +839,7 @@ tree_selection_changed (GtkTreeSelection *selection,
impl->list_model = _gtk_file_system_model_new (impl->file_system, impl->list_model = _gtk_file_system_model_new (impl->file_system,
file_path, 0, file_path, 0,
GTK_FILE_INFO_ICON |
GTK_FILE_INFO_DISPLAY_NAME | GTK_FILE_INFO_DISPLAY_NAME |
GTK_FILE_INFO_SIZE); GTK_FILE_INFO_SIZE);
_gtk_file_system_model_set_show_folders (impl->list_model, FALSE); _gtk_file_system_model_set_show_folders (impl->list_model, FALSE);
...@@ -915,7 +933,7 @@ entry_activate (GtkEntry *entry, ...@@ -915,7 +933,7 @@ entry_activate (GtkEntry *entry,
} }
} }
const GtkFileInfo * static const GtkFileInfo *
get_list_file_info (GtkFileChooserImplDefault *impl, get_list_file_info (GtkFileChooserImplDefault *impl,
GtkTreeIter *iter) GtkTreeIter *iter)
{ {
...@@ -946,6 +964,30 @@ tree_name_data_func (GtkTreeViewColumn *tree_column, ...@@ -946,6 +964,30 @@ tree_name_data_func (GtkTreeViewColumn *tree_column,
} }
} }
static void
list_icon_data_func (GtkTreeViewColumn *tree_column,
GtkCellRenderer *cell,
GtkTreeModel *tree_model,
GtkTreeIter *iter,
gpointer data)
{
GtkFileChooserImplDefault *impl = data;
const GtkFileInfo *info = get_list_file_info (impl, iter);
if (info)
{
GtkWidget *widget = GTK_TREE_VIEW_COLUMN (tree_column)->tree_view;
GdkPixbuf *pixbuf = gtk_file_info_render_icon (info, widget, 36);
g_object_set (cell,
"pixbuf", pixbuf,
NULL);
if (pixbuf)
g_object_unref (pixbuf);
}
}
static void static void
list_name_data_func (GtkTreeViewColumn *tree_column, list_name_data_func (GtkTreeViewColumn *tree_column,
GtkCellRenderer *cell, GtkCellRenderer *cell,
......
...@@ -50,7 +50,7 @@ static void gtk_file_chooser_dialog_get_property (GObject *obj ...@@ -50,7 +50,7 @@ static void gtk_file_chooser_dialog_get_property (GObject *obj
GValue *value, GValue *value,
GParamSpec *pspec); GParamSpec *pspec);
GObjectClass *parent_class; static GObjectClass *parent_class;
GType GType
gtk_file_chooser_dialog_get_type (void) gtk_file_chooser_dialog_get_type (void)
......
...@@ -67,8 +67,8 @@ static void gtk_file_chooser_entry_do_insert_text (GtkEditable *editabl ...@@ -67,8 +67,8 @@ static void gtk_file_chooser_entry_do_insert_text (GtkEditable *editabl
static void clear_completion_callback (GtkFileChooserEntry *chooser_entry, static void clear_completion_callback (GtkFileChooserEntry *chooser_entry,
GParamSpec *pspec); GParamSpec *pspec);
GObjectClass *parent_class; static GObjectClass *parent_class;
GtkEditableClass *parent_editable_iface; static GtkEditableClass *parent_editable_iface;
GType GType
_gtk_file_chooser_entry_get_type (void) _gtk_file_chooser_entry_get_type (void)
......
...@@ -48,7 +48,7 @@ static void gtk_file_chooser_widget_get_property (GObject *obj ...@@ -48,7 +48,7 @@ static void gtk_file_chooser_widget_get_property (GObject *obj
GValue *value, GValue *value,
GParamSpec *pspec); GParamSpec *pspec);
GObjectClass *parent_class; static GObjectClass *parent_class;
GType GType
gtk_file_chooser_widget_get_type (void) gtk_file_chooser_widget_get_type (void)
...@@ -130,7 +130,7 @@ gtk_file_chooser_widget_constructor (GType type, ...@@ -130,7 +130,7 @@ gtk_file_chooser_widget_constructor (GType type,
gtk_widget_push_composite_child (); gtk_widget_push_composite_child ();
if (!priv->file_system) if (!priv->file_system)
priv->file_system = _gtk_file_system_unix_new (); priv->file_system = gtk_file_system_unix_new ();
priv->impl = _gtk_file_chooser_impl_default_new (priv->file_system); priv->impl = _gtk_file_chooser_impl_default_new (priv->file_system);
gtk_box_pack_start (GTK_BOX (object), priv->impl, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (object), priv->impl, TRUE, TRUE, 0);
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
* Boston, MA 02111-1307, USA. * Boston, MA 02111-1307, USA.
*/ */
#include <gtk/gtkicontheme.h>
#include "gtkfilesystem.h" #include "gtkfilesystem.h"
#include <string.h> #include <string.h>
...@@ -29,7 +31,7 @@ struct _GtkFileInfo ...@@ -29,7 +31,7 @@ struct _GtkFileInfo
gchar *display_name; gchar *display_name;
gchar *display_key; gchar *display_key;
gchar *mime_type; gchar *mime_type;
GdkPixbuf *icon; GtkFileIconType icon_type : 4;
guint is_folder : 1; guint is_folder : 1;
guint is_hidden : 1; guint is_hidden : 1;
}; };
...@@ -84,8 +86,6 @@ gtk_file_info_copy (GtkFileInfo *info) ...@@ -84,8 +86,6 @@ gtk_file_info_copy (GtkFileInfo *info)
new_info->display_name = g_strdup (new_info->display_name); new_info->display_name = g_strdup (new_info->display_name);
if (new_info->mime_type) if (new_info->mime_type)
new_info->mime_type = g_strdup (new_info->mime_type); new_info->mime_type = g_strdup (new_info->mime_type);
if (new_info->icon)
g_object_ref (new_info->icon);
return new_info; return new_info;
} }
...@@ -99,8 +99,6 @@ gtk_file_info_free (GtkFileInfo *info) ...@@ -99,8 +99,6 @@ gtk_file_info_free (GtkFileInfo *info)
g_free (info->display_name); g_free (info->display_name);
if (info->mime_type) if (info->mime_type)
g_free (info->mime_type); g_free (info->mime_type);
if (info->icon)
g_object_unref (info->icon);
} }
G_CONST_RETURN gchar * G_CONST_RETURN gchar *
...@@ -134,7 +132,6 @@ gtk_file_info_get_display_key (const GtkFileInfo *info) ...@@ -134,7 +132,6 @@ gtk_file_info_get_display_key (const GtkFileInfo *info)
((GtkFileInfo *)info)->display_key = g_utf8_collate_key (info->display_name, -1); ((GtkFileInfo *)info)->display_key = g_utf8_collate_key (info->display_name, -1);
} }
return info->display_key; return info->display_key;
} }
...@@ -244,31 +241,166 @@ gtk_file_info_set_size (GtkFileInfo *info, ...@@ -244,31 +241,166 @@ gtk_file_info_set_size (GtkFileInfo *info,
info->size = size; info->size = size;
} }
GdkPixbuf * void
gtk_file_info_get_icon (const GtkFileInfo *info) gtk_file_info_set_icon_type (GtkFileInfo *info,
GtkFileIconType icon_type)
{ {
g_return_val_if_fail (info != NULL, NULL); g_return_if_fail (info != NULL);
return info->icon; info->icon_type = icon_type;
} }
void GtkFileIconType
gtk_file_info_set_icon (GtkFileInfo *info, gtk_file_info_get_icon_type (const GtkFileInfo *info)
GdkPixbuf *icon)
{ {
g_return_if_fail (info != NULL); g_return_val_if_fail (info != NULL, GTK_FILE_ICON_REGULAR);
g_return_if_fail (icon == NULL || GDK_IS_PIXBUF (icon));
return info->icon_type;
}
if (icon != info->icon) typedef struct _IconCacheElement IconCacheElement;
struct _IconCacheElement
{
gint size;
GdkPixbuf *pixbuf;
};
static void
icon_cache_element_free (IconCacheElement *element)
{
if (element->pixbuf)
g_object_unref (element->pixbuf);
g_free (element);
}
static void
icon_theme_changed (GtkIconTheme *icon_theme)
{
GHashTable *cache;
/* Difference from the initial creation is that we don't
* reconnect the signal
*/
cache = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify)g_free,
(GDestroyNotify)icon_cache_element_free);
g_object_set_data_full (G_OBJECT (icon_theme), "gtk-file-icon-cache",
cache, (GDestroyNotify)g_hash_table_destroy);
}
static GdkPixbuf *
get_cached_icon (GtkWidget *widget,
const gchar *name,
gint pixel_size)
{
GtkIconTheme *icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (widget));
GHashTable *cache = g_object_get_data (G_OBJECT (icon_theme), "gtk-file-icon-cache");
IconCacheElement *element;
if (!cache)
{
cache = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify)g_free,
(GDestroyNotify)icon_cache_element_free);
g_object_set_data_full (G_OBJECT (icon_theme), "gtk-file-icon-cache",
cache, (GDestroyNotify)g_hash_table_destroy);
g_signal_connect (icon_theme, "changed",
G_CALLBACK (icon_theme_changed), NULL);
}
element = g_hash_table_lookup (cache, name);
if (!element)
{ {
if (info->icon) element = g_new0 (IconCacheElement, 1);
g_object_unref (info->icon); g_hash_table_insert (cache, g_strdup (name), element);
}
if (element->size != pixel_size)
{
if (element->pixbuf)
g_object_unref (element->pixbuf);
element->size = pixel_size;
element->pixbuf = gtk_icon_theme_load_icon (icon_theme, name,
pixel_size, 0, NULL);
}
info->icon = icon; return element->pixbuf ? g_object_ref (element->pixbuf) : NULL;
}
GdkPixbuf *
gtk_file_info_render_icon (const GtkFileInfo *info,
GtkWidget *widget,
gint pixel_size)
{
const gchar *separator;
GdkPixbuf *pixbuf;
GString *icon_name;
g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (widget != NULL, NULL);
g_return_val_if_fail (pixel_size > 0, NULL);
if (info->icon_type != GTK_FILE_ICON_REGULAR)
{
const char *name = NULL; /* Quiet gcc */
if (info->icon) switch (info->icon_type)
g_object_ref (info->icon); {
case GTK_FILE_ICON_BLOCK_DEVICE:
name ="gnome-fs-blockdev";
break;
case GTK_FILE_ICON_BROKEN_SYMBOLIC_LINK:
name = "gnome-fs-symlink";
break;
case GTK_FILE_ICON_CHARACTER_DEVICE:
name = "gnome-fs-chardev";
break;
case GTK_FILE_ICON_DIRECTORY:
name = "gnome-fs-directory";
break;
case GTK_FILE_ICON_EXECUTABLE:
name ="gnome-fs-executable";
break;
case GTK_FILE_ICON_FIFO:
name = "gnome-fs-fifo";
break;
case GTK_FILE_ICON_SOCKET:
name = "gnome-fs-socket";
break;
case GTK_FILE_ICON_REGULAR:
g_assert_not_reached ();
}
return get_cached_icon (widget, name, pixel_size);
} }
if (!info->mime_type)
return NULL;
separator = strchr (info->mime_type, '/');
if (!separator)
return NULL;
icon_name = g_string_new ("gnome-mime-");
g_string_append_len (icon_name, info->mime_type, separator - info->mime_type);
g_string_append_c (icon_name, '-');
g_string_append (icon_name, separator + 1);
pixbuf = get_cached_icon (widget, icon_name->str, pixel_size);
g_string_free (icon_name, TRUE);
if (pixbuf)
return pixbuf;
icon_name = g_string_new ("gnome-mime-");
g_string_append_len (icon_name, info->mime_type, separator - info->mime_type);
pixbuf = get_cached_icon (widget, icon_name->str, pixel_size);
g_string_free (icon_name, TRUE);
if (pixbuf)
return pixbuf;
return get_cached_icon (widget, "gnome-fs-regular", pixel_size);
} }
/***************************************** /*****************************************
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#define __GTK_FILE_SYSTEM_H__ #define __GTK_FILE_SYSTEM_H__
#include <glib-object.h> #include <glib-object.h>
#include <gdk-pixbuf/gdk-pixbuf.h> #include <gtk/gtkwidget.h> /* For icon handling */
G_BEGIN_DECLS G_BEGIN_DECLS
...@@ -50,6 +50,19 @@ typedef enum { ...@@ -50,6 +50,19 @@ typedef enum {
GTK_FILE_INFO_ALL = (1 << 7) - 1 GTK_FILE_INFO_ALL = (1 << 7) - 1
} GtkFileInfoType; } GtkFileInfoType;
/* Icon type, supplemented by MIME type
*/
typedef enum {
GTK_FILE_ICON_REGULAR, /* Use mime type for icon */
GTK_FILE_ICON_BLOCK_DEVICE,
GTK_FILE_ICON_BROKEN_SYMBOLIC_LINK,
GTK_FILE_ICON_CHARACTER_DEVICE,
GTK_FILE_ICON_DIRECTORY,
GTK_FILE_ICON_EXECUTABLE,
GTK_FILE_ICON_FIFO,
GTK_FILE_ICON_SOCKET
} GtkFileIconType;
/* GError enumeration for GtkFileSystem /* GError enumeration for GtkFileSystem
*/ */
...@@ -96,9 +109,12 @@ void gtk_file_info_set_modification_time (GtkFileInfo *in ...@@ -96,9 +109,12 @@ void gtk_file_info_set_modification_time (GtkFileInfo *in
gint64 gtk_file_info_get_size (const GtkFileInfo *info); gint64 gtk_file_info_get_size (const GtkFileInfo *info);
void gtk_file_info_set_size (GtkFileInfo *info, void gtk_file_info_set_size (GtkFileInfo *info,
gint64 size); gint64 size);
GdkPixbuf * gtk_file_info_get_icon (const GtkFileInfo *info); void gtk_file_info_set_icon_type (GtkFileInfo *info,
void gtk_file_info_set_icon (GtkFileInfo *info, GtkFileIconType icon_type);
GdkPixbuf *icon); GtkFileIconType gtk_file_info_get_icon_type (const GtkFileInfo *info);
GdkPixbuf * gtk_file_info_render_icon (const GtkFileInfo *info,
GtkWidget *widget,
gint pixel_size);
/* The base GtkFileSystem interface /* The base GtkFileSystem interface
*/ */
......
...@@ -35,7 +35,7 @@ typedef struct _GtkFileSystemModel GtkFileSystemModel; ...@@ -35,7 +35,7 @@ typedef struct _GtkFileSystemModel GtkFileSystemModel;
GType _gtk_file_system_model_get_type (void); GType _gtk_file_system_model_get_type (void);
enum { typedef enum {
GTK_FILE_SYSTEM_MODEL_INFO, GTK_FILE_SYSTEM_MODEL_INFO,
GTK_FILE_SYSTEM_MODEL_DISPLAY_NAME, GTK_FILE_SYSTEM_MODEL_DISPLAY_NAME,
GTK_FILE_SYSTEM_MODEL_N_COLUMNS GTK_FILE_SYSTEM_MODEL_N_COLUMNS
......
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
#include "gtkfilesystem.h" #include "gtkfilesystem.h"
#include "gtkfilesystemunix.h" #include "gtkfilesystemunix.h"
#include "xdgmime/xdgmime.h"
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
...@@ -66,8 +68,8 @@ struct _GtkFileFolderUnix ...@@ -66,8 +68,8 @@ struct _GtkFileFolderUnix
gchar *filename; gchar *filename;
}; };
GObjectClass *system_parent_class; static GObjectClass *system_parent_class;
GObjectClass *folder_parent_class; static GObjectClass *folder_parent_class;
static void gtk_file_system_unix_class_init (GtkFileSystemUnixClass *class); static void gtk_file_system_unix_class_init (GtkFileSystemUnixClass *class);
static void gtk_file_system_unix_iface_init (GtkFileSystemIface *iface); static void gtk_file_system_unix_iface_init (GtkFileSystemIface *iface);
...@@ -135,7 +137,7 @@ static GtkFileInfo *filename_get_info (const gchar *filename, ...@@ -135,7 +137,7 @@ static GtkFileInfo *filename_get_info (const gchar *filename,
* GtkFileSystemUnix * GtkFileSystemUnix
*/ */
GType GType
_gtk_file_system_unix_get_type (void) gtk_file_system_unix_get_type (void)
{ {
static GType file_system_unix_type = 0; static GType file_system_unix_type = 0;
...@@ -173,7 +175,7 @@ _gtk_file_system_unix_get_type (void) ...@@ -173,7 +175,7 @@ _gtk_file_system_unix_get_type (void)
} }
/** /**
* _gtk_file_system_unix_new: * gtk_file_system_unix_new:
* *
* Creates a new #GtkFileSystemUnix object. #GtkFileSystemUnix * Creates a new #GtkFileSystemUnix object. #GtkFileSystemUnix
* implements the #GtkFileSystem interface with direct access to * implements the #GtkFileSystem interface with direct access to
...@@ -182,7 +184,7 @@ _gtk_file_system_unix_get_type (void) ...@@ -182,7 +184,7 @@ _gtk_file_system_unix_get_type (void)
* Return value: the new #GtkFileSystemUnix object * Return value: the new #GtkFileSystemUnix object
**/ **/
GtkFileSystem * GtkFileSystem *
_gtk_file_system_unix_new (void) gtk_file_system_unix_new (void)
{ {
return g_object_new (GTK_TYPE_FILE_SYSTEM_UNIX, NULL); return g_object_new (GTK_TYPE_FILE_SYSTEM_UNIX, NULL);
} }
...@@ -678,6 +680,7 @@ filename_get_info (const gchar *filename, ...@@ -678,6 +680,7 @@ filename_get_info (const gchar *filename,
GError **error) GError **error)
{ {
GtkFileInfo *info; GtkFileInfo *info;
GtkFileIconType icon_type = GTK_FILE_ICON_REGULAR;
struct stat statbuf; struct stat statbuf;
/* If stat fails, try to fall back to lstat to catch broken links /* If stat fails, try to fall back to lstat to catch broken links
...@@ -735,9 +738,36 @@ filename_get_info (const gchar *filename, ...@@ -735,9 +738,36 @@ filename_get_info (const gchar *filename,
gtk_file_info_set_is_folder (info, S_ISDIR (statbuf.st_mode)); gtk_file_info_set_is_folder (info, S_ISDIR (statbuf.st_mode));
} }
if (types & GTK_FILE_INFO_MIME_TYPE) if (types & GTK_FILE_INFO_ICON)
{
if (S_ISBLK (statbuf.st_mode))
icon_type = GTK_FILE_ICON_BLOCK_DEVICE;
else if (S_ISLNK (statbuf.st_mode))
icon_type = GTK_FILE_ICON_BROKEN_SYMBOLIC_LINK;
else if (S_ISCHR (statbuf.st_mode))
icon_type = GTK_FILE_ICON_CHARACTER_DEVICE;
else if (S_ISDIR (statbuf.st_mode))
icon_type = GTK_FILE_ICON_DIRECTORY;
else if (S_ISFIFO (statbuf.st_mode))
icon_type = GTK_FILE_ICON_FIFO;
else if (S_ISSOCK (statbuf.st_mode))
icon_type = GTK_FILE_ICON_SOCKET;
gtk_file_info_set_icon_type (info, icon_type);
}
if ((types & GTK_FILE_INFO_MIME_TYPE) ||
((types & GTK_FILE_INFO_ICON) && icon_type == GTK_FILE_ICON_REGULAR))
{ {
gtk_file_info_set_mime_type (info, "application/octet-stream"); const char *mime_type = xdg_mime_get_mime_type_for_file (filename);
gtk_file_info_set_mime_type (info, mime_type);
if ((types & GTK_FILE_INFO_ICON) && icon_type == GTK_FILE_ICON_REGULAR &&
(statbuf.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) &&
(strcmp (mime_type, XDG_MIME_TYPE_UNKNOWN) == 0 ||
strcmp (mime_type, "application/x-executable") == 0 ||
strcmp (mime_type, "application/x-shellscript") == 0))
gtk_file_info_set_icon_type (info, GTK_FILE_ICON_EXECUTABLE);
} }
if (types & GTK_FILE_INFO_MODIFICATION_TIME) if (types & GTK_FILE_INFO_MODIFICATION_TIME)
...@@ -750,11 +780,6 @@ filename_get_info (const gchar *filename, ...@@ -750,11 +780,6 @@ filename_get_info (const gchar *filename,
gtk_file_info_set_size (info, (gint64)statbuf.st_size); gtk_file_info_set_size (info, (gint64)statbuf.st_size);
} }
if (types & GTK_FILE_INFO_ICON)
{
/* NOT YET IMPLEMENTED */
}
return info; return info;
} }
......
...@@ -26,14 +26,14 @@ ...@@ -26,14 +26,14 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define GTK_TYPE_FILE_SYSTEM_UNIX (_gtk_file_system_unix_get_type ()) #define GTK_TYPE_FILE_SYSTEM_UNIX (gtk_file_system_unix_get_type ())
#define GTK_FILE_SYSTEM_UNIX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FILE_SYSTEM_UNIX, GtkFileSystemUnix)) #define GTK_FILE_SYSTEM_UNIX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FILE_SYSTEM_UNIX, GtkFileSystemUnix))
#define GTK_IS_FILE_SYSTEM_UNIX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FILE_SYSTEM_UNIX)) #define GTK_IS_FILE_SYSTEM_UNIX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FILE_SYSTEM_UNIX))
typedef struct _GtkFileSystemUnix GtkFileSystemUnix; typedef struct _GtkFileSystemUnix GtkFileSystemUnix;