evolution r36529 - in trunk: calendar calendar/gui calendar/gui/dialogs composer e-util mail widgets/misc
- From: mcrha svn gnome org
- To: svn-commits-list gnome org
- Subject: evolution r36529 - in trunk: calendar calendar/gui calendar/gui/dialogs composer e-util mail widgets/misc
- Date: Wed, 1 Oct 2008 12:29:46 +0000 (UTC)
Author: mcrha
Date: Wed Oct 1 12:29:46 2008
New Revision: 36529
URL: http://svn.gnome.org/viewvc/evolution?rev=36529&view=rev
Log:
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.
Modified:
trunk/calendar/ChangeLog
trunk/calendar/gui/dialogs/comp-editor.c
trunk/calendar/gui/e-cal-popup.c
trunk/composer/ChangeLog
trunk/composer/e-msg-composer.c
trunk/e-util/ChangeLog
trunk/e-util/e-util.c
trunk/e-util/e-util.h
trunk/mail/ChangeLog
trunk/mail/em-popup.c
trunk/mail/em-utils.c
trunk/widgets/misc/ChangeLog
trunk/widgets/misc/e-attachment.c
Modified: trunk/calendar/gui/dialogs/comp-editor.c
==============================================================================
--- trunk/calendar/gui/dialogs/comp-editor.c (original)
+++ trunk/calendar/gui/dialogs/comp-editor.c Wed Oct 1 12:29:46 2008
@@ -2843,7 +2843,7 @@
return;
}
- mime_type = e_util_guess_mime_type (file_name);
+ mime_type = e_util_guess_mime_type (file_name, TRUE);
if (mime_type) {
if (!g_ascii_strcasecmp (mime_type, "message/rfc822")) {
wrapper = (CamelDataWrapper *) camel_mime_message_new ();
Modified: trunk/calendar/gui/e-cal-popup.c
==============================================================================
--- trunk/calendar/gui/e-cal-popup.c (original)
+++ trunk/calendar/gui/e-cal-popup.c Wed Oct 1 12:29:46 2008
@@ -405,7 +405,7 @@
if (filename) {
gchar *name_type;
- name_type = e_util_guess_mime_type (filename);
+ name_type = e_util_guess_mime_type (filename, FALSE);
cp = g_content_type_from_mime_type (name_type);
apps = g_app_info_get_all_for_type (cp ? cp : name_type);
g_free (cp);
Modified: trunk/composer/e-msg-composer.c
==============================================================================
--- trunk/composer/e-msg-composer.c (original)
+++ trunk/composer/e-msg-composer.c Wed Oct 1 12:29:46 2008
@@ -3968,7 +3968,7 @@
return;
if (!g_ascii_strcasecmp (url->protocol, "file")) {
- type = e_util_guess_mime_type (uri + strlen ("file://"));
+ type = e_util_guess_mime_type (uri + strlen ("file://"), TRUE);
if (!type)
return;
@@ -4200,7 +4200,7 @@
camel_data_wrapper_construct_from_stream (wrapper, stream);
camel_object_unref (CAMEL_OBJECT (stream));
- mime_type = e_util_guess_mime_type (dec_file_name);
+ mime_type = e_util_guess_mime_type (dec_file_name, TRUE);
if (mime_type == NULL)
mime_type = g_strdup ("application/octet-stream");
camel_data_wrapper_set_mime_type (wrapper, mime_type);
Modified: trunk/e-util/e-util.c
==============================================================================
--- trunk/e-util/e-util.c (original)
+++ trunk/e-util/e-util.c Wed Oct 1 12:29:46 2008
@@ -1172,37 +1172,51 @@
/**
* 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;
- mime_type = g_content_type_get_mime_type (g_file_info_get_content_type (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 (fi);
- g_object_unref (file);
+ g_object_unref (file);
+ }
+ }
+
+ if (!mime_type) {
+ /* file doesn't exists locally, thus guess based on the filename */
+ gboolean uncertain = FALSE;
+ gchar *content_type;
+
+ 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;
}
Modified: trunk/e-util/e-util.h
==============================================================================
--- trunk/e-util/e-util.h (original)
+++ trunk/e-util/e-util.h Wed Oct 1 12:29:46 2008
@@ -116,7 +116,7 @@
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);
Modified: trunk/mail/em-popup.c
==============================================================================
--- trunk/mail/em-popup.c (original)
+++ trunk/mail/em-popup.c Wed Oct 1 12:29:46 2008
@@ -807,7 +807,7 @@
if (filename != NULL) {
gchar *name_type;
- name_type = e_util_guess_mime_type (filename);
+ name_type = e_util_guess_mime_type (filename, FALSE);
cp = g_content_type_from_mime_type (name_type);
apps = g_app_info_get_all_for_type (cp ? cp : name_type);
g_free (cp);
Modified: trunk/mail/em-utils.c
==============================================================================
--- trunk/mail/em-utils.c (original)
+++ trunk/mail/em-utils.c Wed Oct 1 12:29:46 2008
@@ -2260,7 +2260,7 @@
filename = camel_mime_part_get_filename (part);
if (filename != NULL)
- name_type = e_util_guess_mime_type (filename);
+ name_type = e_util_guess_mime_type (filename, FALSE);
dw = camel_medium_get_content_object((CamelMedium *)part);
if (!camel_data_wrapper_is_offline(dw)) {
Modified: trunk/widgets/misc/e-attachment.c
==============================================================================
--- trunk/widgets/misc/e-attachment.c (original)
+++ trunk/widgets/misc/e-attachment.c Wed Oct 1 12:29:46 2008
@@ -229,8 +229,7 @@
char *type;
gchar *content = NULL;
- type = e_util_guess_mime_type (file_name);
-
+ type = e_util_guess_mime_type (file_name, TRUE);
if (type && strcmp (type, "text/directory") == 0 &&
file_ext_is (file_name, ".vcf") &&
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]