if they're already openened) (fixes NB#65279).
* src/widgets/modest-window-mgr.[ch]:
* Now modest_window_mgr_register_header accepts an alt_uid
parameter in case the header does not provide an uid.
* src/maemo/modest-msg-view-window.c:
* Now we pass a hash base to the create_temp_stream method used
to create a temporary file to view an attachment. This hash
is used to open always the file in the same directory.
* Now the attachment messages are opened passing a "attachment
id" that works similar to a message id. This identifies the
message in the window manager properly.
* src/modest-ui-actions.c, src/dbus_api/modest-dbus-callbacs.c:
* Use new modest_window_mgr_register_header call.
* src/maemo/modest-maemo-utils.[ch]:
* Now ..._create_temp_stream accepts an additional parameter
hash_base. This hash_base is used to generate the "random"
directory the temporary file is created. This is used to
force files created from attachments get the same path.
pmo-trunk-r3529
if (!already_opened) {
/* g_debug ("creating new window for this msg"); */
- modest_window_mgr_register_header (win_mgr, header);
+ modest_window_mgr_register_header (win_mgr, header, NULL);
const gchar *modest_account_name =
modest_tny_account_get_parent_modest_account_name_for_server_account (account);
}
TnyFsStream *
-modest_maemo_utils_create_temp_stream (const gchar *orig_name, gchar **path)
+modest_maemo_utils_create_temp_stream (const gchar *orig_name, const gchar *hash_base, gchar **path)
{
gint fd;
gchar *filepath = NULL;
gchar *tmpdir;
+ guint hash_number;
/* hmmm... maybe we need a modest_text_utils_validate_file_name? */
g_return_val_if_fail (orig_name || strlen(orig_name) == 0, NULL);
}
/* make a random subdir under /tmp or /var/tmp */
- tmpdir = g_strdup_printf ("%s/%d", g_get_tmp_dir (), (guint)random());
- if (g_mkdir (tmpdir, 0755) == -1) {
+ if (hash_base != NULL) {
+ hash_number = g_str_hash (hash_base);
+ } else {
+ hash_number = (guint) random ();
+ }
+ tmpdir = g_strdup_printf ("%s/%u", g_get_tmp_dir (), hash_number);
+ if ((g_access (tmpdir, R_OK) == -1) && (g_mkdir (tmpdir, 0755) == -1)) {
g_warning ("%s: failed to create dir '%s': %s",
__FUNCTION__, tmpdir, g_strerror(errno));
g_free (tmpdir);
/**
* modest_maemo_utils_create_temp_stream:
* @orig_name: a string with the original name of the extension, or %NULL
+ * @hash_base: if %NULL, subdir will be random. If not, it will be a hash
+ * of this.
* @path: a string with the created file path
*
* Creates a temporary fs stream, in a random subdir of /tmp or /var/tmp.
*
* Returns: a #TnyFsStream, or %NULL if operation failed.
*/
-TnyFsStream *modest_maemo_utils_create_temp_stream (const gchar *orig_name, gchar **path);
+TnyFsStream *modest_maemo_utils_create_temp_stream (const gchar *orig_name, const gchar *hash_base, gchar **path);
/**
* modest_maemo_utils_get_supported_secure_authentication_methods:
modest_msg_view_window_view_attachment (ModestMsgViewWindow *window, TnyMimePart *mime_part)
{
ModestMsgViewWindowPrivate *priv;
+ const gchar *msg_uid;
+ gchar *attachment_uid = NULL;
+ gint attachment_index = 0;
+ GList *attachments;
+
g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (window));
g_return_if_fail (TNY_IS_MIME_PART (mime_part) || (mime_part == NULL));
-
priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (window);
+ msg_uid = modest_msg_view_window_get_message_uid (MODEST_MSG_VIEW_WINDOW (window));
+ attachments = modest_msg_view_get_attachments (MODEST_MSG_VIEW (priv->msg_view));
+ attachment_index = g_list_index (attachments, mime_part);
+ g_list_free (attachments);
+
+ if (msg_uid && attachment_index >= 0) {
+ attachment_uid = g_strdup_printf ("%s/%d", msg_uid, attachment_index);
+ }
+
if (mime_part == NULL) {
gboolean error = FALSE;
GList *selected_attachments = modest_msg_view_get_selected_attachments (MODEST_MSG_VIEW (priv->msg_view));
gchar *filepath = NULL;
const gchar *att_filename = tny_mime_part_get_filename (mime_part);
TnyFsStream *temp_stream = NULL;
-
- temp_stream = modest_maemo_utils_create_temp_stream (att_filename, &filepath);
+ temp_stream = modest_maemo_utils_create_temp_stream (att_filename, attachment_uid, &filepath);
if (temp_stream) {
const gchar *content_type;
g_warning ("window for is already being created");
} else {
/* it's not found, so create a new window for it */
- modest_window_mgr_register_header (mgr, header); /* register the uid before building the window */
+ modest_window_mgr_register_header (mgr, header, attachment_uid); /* register the uid before building the window */
gchar *account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (window)));
if (!account)
account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr ());
- msg_win = modest_msg_view_window_new_for_attachment (TNY_MSG (mime_part), account, NULL);
+ msg_win = modest_msg_view_window_new_for_attachment (TNY_MSG (mime_part), account, attachment_uid);
modest_window_set_zoom (MODEST_WINDOW (msg_win),
modest_window_get_zoom (MODEST_WINDOW (window)));
modest_window_mgr_register_window (mgr, msg_win);
while (!tny_iterator_is_done (iter_not_opened)) {
TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter_not_opened));
if (header) {
- modest_window_mgr_register_header (mgr, header);
+ modest_window_mgr_register_header (mgr, header, NULL);
g_object_unref (header);
}
tny_iterator_next (iter_not_opened);
}
} else {
ModestMailOperation *mail_op = NULL;
- modest_window_mgr_register_header (modest_runtime_get_window_mgr (), header);
+ modest_window_mgr_register_header (modest_runtime_get_window_mgr (), header, NULL);
mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (win),
modest_ui_actions_get_msgs_full_error_handler,
NULL, NULL);
void
-modest_window_mgr_register_header (ModestWindowMgr *self, TnyHeader *header)
+modest_window_mgr_register_header (ModestWindowMgr *self, TnyHeader *header, const gchar *alt_uid)
{
ModestWindowMgrPrivate *priv;
gchar* uid;
priv = MODEST_WINDOW_MGR_GET_PRIVATE (self);
uid = modest_tny_folder_get_header_unique_id (header);
-
+ if (uid == NULL)
+ uid = g_strdup (alt_uid);
+
if (!has_uid (priv->preregistered_uids, uid)) {
g_debug ("registering new uid %s", uid);
priv->preregistered_uids = append_uid (priv->preregistered_uids, uid);
} else
g_debug ("already had uid %s", uid);
-
+
g_free (uid);
}
priv = MODEST_WINDOW_MGR_GET_PRIVATE (self);
uid = modest_tny_folder_get_header_unique_id (header);
-
+
if (!has_uid (priv->preregistered_uids, uid)) {
g_debug ("trying to unregister non-existing uid %s", uid);
priv->preregistered_uids = append_uid (priv->preregistered_uids, uid);
} else
g_debug ("unregistering uid %s", uid);
-
+
if (has_uid (priv->preregistered_uids, uid)) {
priv->preregistered_uids = remove_uid (priv->preregistered_uids, uid);
if (has_uid (priv->preregistered_uids, uid))
else
g_debug ("uid %s removed", uid);
}
-
+
g_free (uid);
}
return 1;
}
-
void
modest_window_mgr_close_all_windows (ModestWindowMgr *self)
{
ModestWindowMgrPrivate *priv = NULL;
GList *wins = NULL;
gboolean ret_value = FALSE;
-
+
g_return_if_fail (MODEST_IS_WINDOW_MGR (self));
priv = MODEST_WINDOW_MGR_GET_PRIVATE (self);
if (win)
*win = NULL;
-
+
has_header = has_uid (priv->preregistered_uids, uid);
-
+
item = g_list_find_custom (priv->window_list, uid, (GCompareFunc) compare_msguids);
if (item) {
has_window = TRUE;
}
}
}
-
g_free (uid);
+
return has_header || has_window;
}
if (MODEST_IS_MSG_VIEW_WINDOW(window)) {
const gchar *uid = modest_msg_view_window_get_message_uid
(MODEST_MSG_VIEW_WINDOW (window));
-
+
if (!has_uid (priv->preregistered_uids, uid))
g_debug ("weird: no uid for window (%s)", uid);
g_debug ("registering window for %s", uid ? uid : "<none>");
-
+
priv->preregistered_uids =
remove_uid (priv->preregistered_uids,
modest_msg_view_window_get_message_uid
(MODEST_MSG_VIEW_WINDOW (window)));
-
} else if (MODEST_IS_MSG_EDIT_WINDOW(window)) {
const gchar *uid = modest_msg_edit_window_get_message_uid
(MODEST_MSG_EDIT_WINDOW (window));
* modest_window_mgr_register_header
* @self: a #ModestWindowMgr
* @header: a valid #TnyHeader
+ * @alt_uid: alternative uid in case @header does not provide one
*
* register the uid, even before the window is created. thus, we know when
* some window creation might already be underway. the uid will automatically be
* removed when the window itself will registered
*
**/
-void modest_window_mgr_register_header (ModestWindowMgr *self, TnyHeader *header);
+void modest_window_mgr_register_header (ModestWindowMgr *self, TnyHeader *header, const gchar *alt_uid);
/**