info = (OpenMsgPerformerInfo *) user_data;
if (canceled || err) {
- modest_platform_run_information_dialog (NULL, _("mail_ni_ui_folder_get_msg_folder_error"), TRUE);
+ if (!canceled)
+ modest_platform_run_information_dialog (NULL, _("mail_ni_ui_folder_get_msg_folder_error"), TRUE);
g_idle_add (notify_error_in_dbus_callback, NULL);
on_find_msg_async_destroy (info);
return;
/* Try to get the message, if it's already downloaded
we don't need to connect */
if (account) {
- if (TNY_ACCOUNT (local_folders_account) == account) {
+ TnyDevice *device;
+ gboolean device_online;
+
+ device = modest_runtime_get_device ();
+ device_online = tny_device_is_online (device);
+ if (!device_online || TNY_ACCOUNT (local_folders_account) == account) {
folder = tny_store_account_find_folder (TNY_STORE_ACCOUNT (account), uri, NULL);
} else {
folder = NULL;
- info->connect = TRUE;
}
} else {
folder = modest_tny_local_folders_account_get_merged_outbox (local_folders_account);
g_object_unref (local_folders_account);
+ info->connect = FALSE;
}
if (folder) {
TnyMsg *msg = tny_folder_find_msg (folder, uri, NULL);
return FALSE;
}
g_free (uid);
- } else {
+ } else if (header) {
if (g_list_find_custom (priv->window_list, header, (GCompareFunc) compare_headers)) {
g_debug ("%s found another view window showing the same header", __FUNCTION__);
g_object_unref (header);
return FALSE;
}
}
- g_object_unref (header);
+ if (header)
+ g_object_unref (header);
}
/* Do not go backwards */
/* Try to get the message, if it's already downloaded
we don't need to connect */
if (account) {
- folder = tny_store_account_find_folder (TNY_STORE_ACCOUNT (account), msg_uid, NULL);
+ folder = modest_tny_folder_store_find_folder_from_uri (TNY_FOLDER_STORE (account), msg_uid);
} else {
ModestTnyAccountStore *account_store;
ModestTnyLocalFoldersAccount *local_folders_account;
TnyMsg *msg = tny_folder_find_msg (folder, msg_uid, NULL);
if (msg) {
tny_msg_view_set_msg (TNY_MSG_VIEW (priv->msg_view), msg);
+ update_window_title (MODEST_MSG_VIEW_WINDOW (window));
update_branding (MODEST_MSG_VIEW_WINDOW (window));
g_object_unref (msg);
} else {
}
/* Register the header - it'll be unregistered in the callback */
- modest_window_mgr_register_header (modest_runtime_get_window_mgr (), info->header, NULL);
+ if (info->header)
+ modest_window_mgr_register_header (modest_runtime_get_window_mgr (), info->header, NULL);
/* New mail operation */
mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
tny_header_view_set_header (TNY_HEADER_VIEW (priv->msg_view), header);
gtk_window_set_title (GTK_WINDOW (window), _CS("ckdg_pb_updating"));
+ if (folder)
+ g_object_ref (folder);
+
mgr = modest_runtime_get_window_mgr ();
/* Msg download completed */
if (!header || !(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED)) {
if (header) {
folder = tny_header_get_folder (header);
- } else {
- g_object_ref (folder);
}
info = g_slice_new (MsgReaderInfo);
info->msg_uid = g_strdup (msg_uid);
if (header) {
folder = tny_header_get_folder (header);
- } else {
- g_object_ref (folder);
}
account = tny_folder_get_account (folder);
info = g_slice_new (MsgReaderInfo);
info->msg_uid = g_strdup (msg_uid);
- if (info->folder)
+ if (folder)
info->folder = g_object_ref (folder);
else
info->folder = NULL;
- if (info->header)
+ if (header)
info->header = g_object_ref (header);
else
info->header = NULL;
}
/* Register the header - it'll be unregistered in the callback */
- modest_window_mgr_register_header (modest_runtime_get_window_mgr (), info->header, NULL);
+ if (info->header)
+ modest_window_mgr_register_header (modest_runtime_get_window_mgr (), info->header, NULL);
/* New mail operation */
mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
frees:
/* Frees. The row_reference will be freed by the view_msg_cb callback */
g_free (info->uid);
- g_object_unref (info->header);
+ if (info->header)
+ g_object_unref (info->header);
+ if (info->folder)
+ g_object_unref (info->folder);
g_slice_free (MsgReaderInfo, info);
}
MsgReaderInfo *info;
mgr = modest_runtime_get_window_mgr ();
- already_showing = modest_window_mgr_find_registered_header (mgr, header, &msg_window);
+ already_showing = header && modest_window_mgr_find_registered_header (mgr, header, &msg_window);
if (already_showing && (msg_window != MODEST_WINDOW (window))) {
gboolean retval;
if (msg_window)
return TRUE;
}
+ if (folder)
+ g_object_ref (folder);
+
+
/* Msg download completed */
if (!header || !(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED)) {
/* Ask the user if he wants to download the message if
if (response == GTK_RESPONSE_CANCEL)
return FALSE;
- if (header)
+ if (header) {
+ if (folder) g_object_unref (folder);
folder = tny_header_get_folder (header);
- else
- g_object_ref (folder);
+ }
info = g_slice_new (MsgReaderInfo);
info->msg_uid = g_strdup (msg_uid);
if (header)
}
}
- if (header)
+ if (header) {
+ if (folder) g_object_unref (folder);
folder = tny_header_get_folder (header);
- else
- g_object_ref (folder);
+ }
account = tny_folder_get_account (folder);
info = g_slice_new (MsgReaderInfo);
info->msg_uid = g_strdup (msg_uid);
g_slice_free (ModestMailOperationState, state);
tny_folder_find_msg_async (folder, msg_uid, get_msg_async_cb, get_msg_status_cb, helper);
-
- g_object_unref (G_OBJECT (folder));
}
void
/* Clean */
if (info->more_msgs)
g_object_unref (info->more_msgs);
- g_object_unref (info->header);
+ if (info->header)
+ g_object_unref (info->header);
g_object_unref (info->mail_op);
g_slice_free (GetMsgInfo, info);
} else if (info->more_msgs) {
return fname;
}
+
+TnyFolder *
+modest_tny_folder_store_find_folder_from_uri (TnyFolderStore *folder_store, const gchar *uri)
+{
+ TnyList *children;
+ TnyIterator *iterator;
+ TnyFolder *result;
+
+ result = NULL;
+ children = TNY_LIST (tny_simple_list_new ());
+ tny_folder_store_get_folders (folder_store, children, NULL, FALSE, NULL);
+
+ for (iterator = tny_list_create_iterator (children);
+ !tny_iterator_is_done (iterator) && (result == NULL);
+ tny_iterator_next (iterator)) {
+ TnyFolderStore *child;
+
+ child = TNY_FOLDER_STORE (tny_iterator_get_current (iterator));
+
+ if (TNY_IS_FOLDER (child)) {
+ gchar *folder_url;
+
+ folder_url = tny_folder_get_url_string (TNY_FOLDER (child));
+ if (g_str_has_prefix (uri, folder_url))
+ result = g_object_ref (child);
+ g_free (folder_url);
+ }
+
+ if ((child == NULL) && TNY_IS_FOLDER_STORE (child)) {
+ result = modest_tny_folder_store_find_folder_from_uri (child, uri);
+ }
+
+ g_object_unref (child);
+ }
+
+ g_object_unref (iterator);
+ g_object_unref (children);
+
+ return result;
+}
TnyFolderStore *ancestor);
/**
+ * modest_tny_folder_store_find_folder_from_uri:
+ * @folder_store: a #TnyFolderStore
+ * @uri: a string
+ *
+ * This method tries to find a folder in @folder_store. The idea is
+ * being as fast as possible being synchronous. This is accomplished
+ * avoiding network access.
+ *
+ * Returns: %NULL if folder is not found, or a #TnyFolder.
+ */
+TnyFolder *modest_tny_folder_store_find_folder_from_uri (TnyFolderStore *folder_store, const gchar *uri);
+
+/**
* modest_tny_folder_get_display_name:
* @folder: a #TnyFolder
*
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);
-
MODEST_DEBUG_BLOCK(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)));
+ if (has_uid (priv->preregistered_uids, uid)) {
+ 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));