diff options
author | Milan Crha <mcrha@redhat.com> | 2008-10-01 20:29:46 +0800 |
---|---|---|
committer | Milan Crha <mcrha@src.gnome.org> | 2008-10-01 20:29:46 +0800 |
commit | 77ff19dd8394167cdc9765af20a62bdaed18e308 (patch) | |
tree | cbc6da9a817aad2d87acab9199a37a69a08851bf /e-util | |
parent | 11fd4c56d352e7e25cd95cf083b071e982cf42ba (diff) | |
download | gsoc2013-evolution-77ff19dd8394167cdc9765af20a62bdaed18e308.tar.gz gsoc2013-evolution-77ff19dd8394167cdc9765af20a62bdaed18e308.tar.zst gsoc2013-evolution-77ff19dd8394167cdc9765af20a62bdaed18e308.zip |
** Fix for bug #554418
2008-10-01 Milan Crha <mcrha@redhat.com>
** Fix for bug #554418
* e-util/e-util.h: (e_util_guess_mime_type):
* e-util/e-util.c: (e_util_guess_mime_type): Guess mime_type based on
the file content only when permitted by the caller, otherwise
check based on the filename only, where it fallbacks if file
content guess fails.
* mail/em-utils.c: (em_utils_snoop_type):
* mail/em-popup.c: (emp_standard_menu_factory):
Guess mime_type based on the filename only.
* composer/e-msg-composer.c: (handle_uri),
(e_msg_composer_add_inline_image_from_file): Guess mime_type based
on the file content, if failed, then on the filename.
* widgets/misc/e-attachment.c: (attachment_guess_mime_type):
Allow guessing mime_type based on the file content.
* calendar/gui/dialogs/comp-editor.c: (set_attachment_list):
* calendar/gui/e-cal-popup.c: (ecalp_standard_menu_factory):
Allow/disallow guessing of the mime_type based on the file content.
svn path=/trunk/; revision=36529
Diffstat (limited to 'e-util')
-rw-r--r-- | e-util/ChangeLog | 10 | ||||
-rw-r--r-- | e-util/e-util.c | 50 | ||||
-rw-r--r-- | e-util/e-util.h | 2 |
3 files changed, 43 insertions, 19 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog index e85172b9ea..4c2e1d14d6 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,13 @@ +2008-10-01 Milan Crha <mcrha@redhat.com> + + ** Fix for bug #554418 + + * e-util.h: (e_util_guess_mime_type): + * e-util.c: (e_util_guess_mime_type): Guess mime_type based on + the file content only when permitted by the caller, otherwise + check based on the filename only, where it fallbacks if file + content guess fails. + 2008-09-29 Sankar P <psankar@novell.com> License Changes diff --git a/e-util/e-util.c b/e-util/e-util.c index 21f448b15b..97cd6265a6 100644 --- a/e-util/e-util.c +++ b/e-util/e-util.c @@ -1172,37 +1172,51 @@ e_file_lock_exists () /** * e_util_guess_mime_type: * @filename: it's a local file name, or URI. + * @localfile: set to TRUE if can check the local file content, FALSE to check only based on the filename itself. * Returns: NULL or newly allocated string with a mime_type of the given file. Free with g_free. * - * Guesses mime_type for the given file_name. + * Guesses mime_type for the given filename. **/ char * -e_util_guess_mime_type (const char *filename) +e_util_guess_mime_type (const char *filename, gboolean localfile) { - GFile *file; - GFileInfo *fi; - char *mime_type; + char *mime_type = NULL; g_return_val_if_fail (filename != NULL, NULL); - if (strstr (filename, "://")) - file = g_file_new_for_uri (filename); - else - file = g_file_new_for_path (filename); + if (localfile) { + GFile *file; - if (!file) - return NULL; + if (strstr (filename, "://")) + file = g_file_new_for_uri (filename); + else + file = g_file_new_for_path (filename); - fi = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL); - if (!fi) { - g_object_unref (file); - return NULL; + if (file) { + GFileInfo *fi; + + fi = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL); + if (fi) { + mime_type = g_content_type_get_mime_type (g_file_info_get_content_type (fi)); + + g_object_unref (fi); + } + + g_object_unref (file); + } } - mime_type = g_content_type_get_mime_type (g_file_info_get_content_type (fi)); + if (!mime_type) { + /* file doesn't exists locally, thus guess based on the filename */ + gboolean uncertain = FALSE; + gchar *content_type; - g_object_unref (fi); - g_object_unref (file); + content_type = g_content_type_guess (filename, NULL, 0, &uncertain); + if (content_type) { + mime_type = g_content_type_get_mime_type (content_type); + g_free (content_type); + } + } return mime_type; } diff --git a/e-util/e-util.h b/e-util/e-util.h index bb6f2ba5fc..78ec9e53c9 100644 --- a/e-util/e-util.h +++ b/e-util/e-util.h @@ -116,7 +116,7 @@ gboolean e_file_lock_create (void); void e_file_lock_destroy (void); gboolean e_file_lock_exists (void); -gchar * e_util_guess_mime_type (const gchar *filename); +gchar * e_util_guess_mime_type (const gchar *filename, gboolean localfile); gchar * e_util_filename_to_uri (const gchar *filename); gchar * e_util_uri_to_filename (const gchar *uri); |