evolution r36530 - in branches/gnome-2-24: 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 r36530 - in branches/gnome-2-24: calendar calendar/gui calendar/gui/dialogs composer e-util mail widgets/misc
- Date: Wed, 1 Oct 2008 12:30:42 +0000 (UTC)
Author: mcrha
Date: Wed Oct 1 12:30:42 2008
New Revision: 36530
URL: http://svn.gnome.org/viewvc/evolution?rev=36530&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:
branches/gnome-2-24/calendar/ChangeLog
branches/gnome-2-24/calendar/gui/dialogs/comp-editor.c
branches/gnome-2-24/calendar/gui/e-cal-popup.c
branches/gnome-2-24/composer/ChangeLog
branches/gnome-2-24/composer/e-msg-composer.c
branches/gnome-2-24/e-util/ChangeLog
branches/gnome-2-24/e-util/e-util.c
branches/gnome-2-24/e-util/e-util.h
branches/gnome-2-24/mail/ChangeLog
branches/gnome-2-24/mail/em-popup.c
branches/gnome-2-24/mail/em-utils.c
branches/gnome-2-24/widgets/misc/ChangeLog
branches/gnome-2-24/widgets/misc/e-attachment.c
Modified: branches/gnome-2-24/calendar/gui/dialogs/comp-editor.c
==============================================================================
--- branches/gnome-2-24/calendar/gui/dialogs/comp-editor.c (original)
+++ branches/gnome-2-24/calendar/gui/dialogs/comp-editor.c Wed Oct 1 12:30:42 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: branches/gnome-2-24/calendar/gui/e-cal-popup.c
==============================================================================
--- branches/gnome-2-24/calendar/gui/e-cal-popup.c (original)
+++ branches/gnome-2-24/calendar/gui/e-cal-popup.c Wed Oct 1 12:30:42 2008
@@ -406,7 +406,7 @@
if (filename) {
gchar *name_type;
- name_type = e_util_guess_mime_type (filename);
+ name_type = e_util_guess_mime_type (filename, FALSE);
apps = g_app_info_get_all_for_type (name_type);
g_free (name_type);
}
Modified: branches/gnome-2-24/composer/e-msg-composer.c
==============================================================================
--- branches/gnome-2-24/composer/e-msg-composer.c (original)
+++ branches/gnome-2-24/composer/e-msg-composer.c Wed Oct 1 12:30:42 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: branches/gnome-2-24/e-util/e-util.c
==============================================================================
--- branches/gnome-2-24/e-util/e-util.c (original)
+++ branches/gnome-2-24/e-util/e-util.c Wed Oct 1 12:30:42 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: branches/gnome-2-24/e-util/e-util.h
==============================================================================
--- branches/gnome-2-24/e-util/e-util.h (original)
+++ branches/gnome-2-24/e-util/e-util.h Wed Oct 1 12:30:42 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: branches/gnome-2-24/mail/em-popup.c
==============================================================================
--- branches/gnome-2-24/mail/em-popup.c (original)
+++ branches/gnome-2-24/mail/em-popup.c Wed Oct 1 12:30:42 2008
@@ -808,7 +808,7 @@
if (filename != NULL) {
gchar *name_type;
- name_type = e_util_guess_mime_type (filename);
+ name_type = e_util_guess_mime_type (filename, FALSE);
apps = g_app_info_get_all_for_type (name_type);
g_free (name_type);
}
Modified: branches/gnome-2-24/mail/em-utils.c
==============================================================================
--- branches/gnome-2-24/mail/em-utils.c (original)
+++ branches/gnome-2-24/mail/em-utils.c Wed Oct 1 12:30:42 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: branches/gnome-2-24/widgets/misc/e-attachment.c
==============================================================================
--- branches/gnome-2-24/widgets/misc/e-attachment.c (original)
+++ branches/gnome-2-24/widgets/misc/e-attachment.c Wed Oct 1 12:30:42 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]