(fixes NB#57213, NB#57671, NB#57575).
* src/modest-platform.h:
* (modest_platform_activate_file): now it gets a mime_type parameter,
in case it was detected previously.
* src/gnome/modest-platform.c:
* (modest_platform_activate_file): updated API to get mime type
* src/maemo/modest-platform.c:
* (guess_mime_type_from_file): fixed a trivial bug, that broke the
detection.
* (modest_platform_activate_file): use mime type to open the file
if available, or uses guess_mime_type if no type is provided.
* src/maemo/modest-msg-view-window.c:
* (..._view_attachment). Preserve the extension on saving the
attachments to temporary file to view it.
* (..._view_attachment). Get the mime type of the mime part, and
pass it to the activate_file call.
* src/maemo/modest-maemo-utils.c:
* (..._create_temp_stream): now accepts a preferred extension for
the temporary file.
pmo-trunk-r2067
}
gboolean
-modest_platform_activate_file (const gchar *path)
+modest_platform_activate_file (const gchar *path, const gchar *mime_type)
{
modest_runtime_not_implemented (NULL);
return FALSE;
}
TnyFsStream *
-modest_maemo_utils_create_temp_stream (gchar **path)
+modest_maemo_utils_create_temp_stream (const gchar *extension, gchar **path)
{
- TnyStream *tmp_fs_stream;
+ TnyStream *tmp_fs_stream = NULL;
gint fd;
- gchar *filepath;
+ gchar *filepath = NULL;
+ gchar *template = NULL;
- fd = g_file_open_tmp (NULL, &filepath, NULL);
+ if (extension != NULL)
+ template = g_strdup_printf ("XXXXXX.%s", extension);
+
+ fd = g_file_open_tmp (template, &filepath, NULL);
+ g_free (template);
if (path != NULL)
*path = filepath;
if (fd == -1) {
/**
* modest_maemo_utils_create_temp_stream:
+ * @extension: a string with the extension the file should get, or %NULL
* @path: a string with the created file path
*
* Creates a temporary fs stream
*
* Returns: a #TnyFsStream, or %NULL if operation failed.
*/
-TnyFsStream *modest_maemo_utils_create_temp_stream (gchar **path);
+TnyFsStream *modest_maemo_utils_create_temp_stream (const gchar *extension, gchar **path);
/**
* modest_protocol_info_protocol_is_local_store:
if (!TNY_IS_MSG (mime_part)) {
gchar *filepath = NULL;
- TnyFsStream *temp_stream = modest_maemo_utils_create_temp_stream (&filepath);
+ const gchar *att_filename = tny_mime_part_get_filename (mime_part);
+ gchar *extension = NULL;
+ TnyFsStream *temp_stream = NULL;
+
+ if (att_filename) {
+ extension = g_strrstr (att_filename, ".");
+ if (extension != NULL)
+ extension++;
+ }
+
+ temp_stream = modest_maemo_utils_create_temp_stream (extension, &filepath);
if (temp_stream) {
+ const gchar *content_type;
+ content_type = tny_mime_part_get_content_type (mime_part);
tny_mime_part_decode_to_stream (mime_part, TNY_STREAM (temp_stream));
- modest_platform_activate_file (filepath);
+
+ modest_platform_activate_file (filepath, content_type);
g_object_unref (temp_stream);
g_free (filepath);
/* TODO: delete temporary file */
return octet_stream;
for (i = 0; i != G_N_ELEMENTS(mime_map); ++i) {
- if (g_ascii_strcasecmp (mime_map[i][0], ext + 1)) /* +1: ignore '.'*/
+ if (!g_ascii_strcasecmp (mime_map[i][0], ext + 1)) /* +1: ignore '.'*/
return mime_map[i][1];
}
return octet_stream;
g_return_val_if_fail (name || mime_type, NULL);
- if (!mime_type || g_ascii_strcasecmp (mime_type, "application/octet-stream"))
+ if (!mime_type || !g_ascii_strcasecmp (mime_type, "application/octet-stream"))
mime_str = g_string_new (guess_mime_type_from_name(name));
else {
mime_str = g_string_new (mime_type);
}
gboolean
-modest_platform_activate_file (const gchar *path)
+modest_platform_activate_file (const gchar *path, const gchar *mime_type)
{
gint result;
DBusConnection *con;
gchar *uri_path = NULL;
+ GString *mime_str = NULL;
+
+ if (!mime_type || !g_ascii_strcasecmp (mime_type, "application/octet-stream"))
+ mime_str = g_string_new (guess_mime_type_from_name(path));
+ else {
+ mime_str = g_string_new (mime_type);
+ g_string_ascii_down (mime_str);
+ }
uri_path = g_strconcat ("file://", path, NULL);
con = osso_get_dbus_connection (osso_context);
#ifdef MODEST_HILDON_VERSION_0
- result = osso_mime_open_file (con, uri_path);
+ result = osso_mime_open_file_with_mime_type (con, uri_path, mime_str->str);
+ g_string_free (mime_str, TRUE);
if (result != 1)
hildon_banner_show_information (NULL, NULL, _("mcen_ni_noregistered_viewer"));
return result != 1;
#else
- result = hildon_mime_open_file (con, uri_path);
+ result = hildon_mime_open_file_with_mime_type (con, uri_path, mime_str->str);
+ g_string_free (mime_str, TRUE);
if (result != 1)
hildon_banner_show_information (NULL, NULL, _("mcen_ni_noregistered_viewer"));
/**
* modest_platform_activate_file:
* @path: the path to activate
+ * @mime_type: the mime type of the path, or %NULL to guess
*
* This function activates a file
*
* Returns: %TRUE if successful, %FALSE if not.
**/
-gboolean modest_platform_activate_file (const gchar *path);
+gboolean modest_platform_activate_file (const gchar *path, const gchar *mime_type);
/**
* modest_platform_show_uri_popup: