From 37d30fd988ac2014f6497f6a0fedcfb3268aa51c Mon Sep 17 00:00:00 2001 From: Yevgen Muntyan <17531749+muntyan@users.noreply.github.com> Date: Wed, 5 Apr 2006 22:36:52 -0500 Subject: [PATCH] Check mime type returned by xdgmime --- moo/mooutils/moofileview/moofile.c | 34 +++++++++++++++++------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/moo/mooutils/moofileview/moofile.c b/moo/mooutils/moofileview/moofile.c index 6afefab6..af8ab716 100644 --- a/moo/mooutils/moofileview/moofile.c +++ b/moo/mooutils/moofileview/moofile.c @@ -627,6 +627,22 @@ static gboolean get_stat_a_bit (MooFolder *folder) } +inline static void +get_mime_type (MooFile *file, + const char *path) +{ + if (file->flags & MOO_FILE_HAS_STAT) + file->mime_type = xdg_mime_get_mime_type_for_file (path, &file->statbuf); + else + file->mime_type = xdg_mime_get_mime_type_for_file (path, NULL); + + if (file->mime_type && file->mime_type[0]) + file->flags |= MOO_FILE_HAS_MIME_TYPE; + else + g_message ("%s: oops", G_STRLOC); +} + + static gboolean get_icons_a_bit (MooFolder *folder) { gboolean done = FALSE; @@ -660,12 +676,8 @@ static gboolean get_icons_a_bit (MooFolder *folder) { char *path = FILE_PATH (folder, file); - if (file->flags & MOO_FILE_HAS_STAT) - file->mime_type = xdg_mime_get_mime_type_for_file (path, &file->statbuf); - else - file->mime_type = xdg_mime_get_mime_type_for_file (path, NULL); + get_mime_type (file, path); - file->flags |= MOO_FILE_HAS_MIME_TYPE; file->flags |= MOO_FILE_HAS_ICON; file->icon = get_icon (file, folder->priv->path); folder_emit_files (folder, FILES_CHANGED, changed); @@ -921,12 +933,8 @@ static void file_created (MooFolder *folder, { char *path = FILE_PATH (folder, file); - if (file->flags & MOO_FILE_HAS_STAT) - file->mime_type = xdg_mime_get_mime_type_for_file (path, &file->statbuf); - else - file->mime_type = xdg_mime_get_mime_type_for_file (path, NULL); + get_mime_type (file, path); - file->flags |= MOO_FILE_HAS_MIME_TYPE; file->flags |= MOO_FILE_HAS_ICON; file->icon = get_icon (file, folder->priv->path); g_free (path); @@ -1051,12 +1059,8 @@ char **moo_folder_get_file_info (MooFolder *folder, { char *path = FILE_PATH (folder, file); - if (file->flags & MOO_FILE_HAS_STAT) - file->mime_type = xdg_mime_get_mime_type_for_file (path, &file->statbuf); - else - file->mime_type = xdg_mime_get_mime_type_for_file (path, NULL); + get_mime_type (file, path); - file->flags |= MOO_FILE_HAS_MIME_TYPE; file->flags |= MOO_FILE_HAS_ICON; file->icon = get_icon (file, folder->priv->path); g_free (path);