From a2a1b5efeba8de666acb7fbc17ae2b2fa4b3891a Mon Sep 17 00:00:00 2001 From: Murray Cumming Date: Wed, 11 Jul 2007 15:22:41 +0000 Subject: [PATCH] 2007-07-11 Murray Cumming * src/modest-ui-actions.h: * src/modest-ui-actions.c: (modest_ui_actions_on_delete_message): Move some code into a new modest_ui_actions_refresh_message_window_after_delete() function so we can use it from elsewhere. * src/dbus_api/modest-dbus-callbacks.c: (on_idle_delete_message), (on_delete_message): Used an idle handler, as we do for the other D-Bus method handlers. Call modest_ui_actions_refresh_message_window_after_delete() if the deleted message was open in a window. This fixed projects.maemo.org bug NB#62862. pmo-trunk-r2707 --- ChangeLog2 | 16 +++++++ src/dbus_api/modest-dbus-callbacks.c | 81 ++++++++++++++++++++++------------ src/modest-ui-actions.c | 27 ++++++++---- src/modest-ui-actions.h | 2 + 4 files changed, 90 insertions(+), 36 deletions(-) diff --git a/ChangeLog2 b/ChangeLog2 index 902808d..7b252fb 100644 --- a/ChangeLog2 +++ b/ChangeLog2 @@ -15,6 +15,22 @@ 2007-07-11 Murray Cumming + * src/modest-ui-actions.h: + * src/modest-ui-actions.c: + (modest_ui_actions_on_delete_message): + Move some code into a new + modest_ui_actions_refresh_message_window_after_delete() + function so we can use it from elsewhere. + + * src/dbus_api/modest-dbus-callbacks.c: + (on_idle_delete_message), (on_delete_message): Used an idle + handler, as we do for the other D-Bus method handlers. + Call modest_ui_actions_refresh_message_window_after_delete() + if the deleted message was open in a window. This fixed + projects.maemo.org bug NB#62862. + +2007-07-11 Murray Cumming + * src/modest-main.c: (main): Only show the UI at the start if the showui command line option was given. For instance, run-standalone src/modest showui diff --git a/src/dbus_api/modest-dbus-callbacks.c b/src/dbus_api/modest-dbus-callbacks.c index ff8c9de..0643b3b 100644 --- a/src/dbus_api/modest-dbus-callbacks.c +++ b/src/dbus_api/modest-dbus-callbacks.c @@ -529,15 +529,15 @@ on_idle_open_message (gpointer user_data) uri = (char *) user_data; - g_debug ("%s: Trying to find msg by url: %s", __FUNCTION__, uri); + /* g_debug ("modest: %s: Trying to find msg by url: %s", __FUNCTION__, uri); */ msg = find_message_by_url (uri, &account); g_free (uri); if (msg == NULL) { - g_debug (" %s: message not found.", __FUNCTION__); + g_debug ("modest: %s: message not found.", __FUNCTION__); return FALSE; } - g_debug (" %s: Found message.", __FUNCTION__); + g_debug ("modest: %s: Found message.", __FUNCTION__); folder = tny_msg_get_folder (msg); if (modest_tny_folder_get_local_folder_type (folder) == TNY_FOLDER_TYPE_DRAFTS) { @@ -553,14 +553,14 @@ on_idle_open_message (gpointer user_data) gdk_threads_enter (); if (modest_window_mgr_find_registered_header (win_mgr, header, &msg_view)) { - g_debug ("window for this msg is open already"); + g_debug ("modest: %s: A window for this messsage is open already.", __FUNCTION__); if (!MODEST_IS_MSG_VIEW_WINDOW(msg_view)) - g_debug ("not a msg view"); + g_debug (" DEBUG: But the window is not a msg view"); else { gtk_window_present (GTK_WINDOW(msg_view)); } } else { - g_debug ("creating new window for this msg"); + /* g_debug ("creating new window for this msg"); */ modest_window_mgr_register_header (win_mgr, header); msg_view = modest_msg_view_window_new (msg,account_name, msg_uid); @@ -596,9 +596,8 @@ static gint on_open_message(GArray * arguments, gpointer data, osso_rpc_t * retv return OSSO_OK; } - -static gint -on_delete_message (GArray *arguments, gpointer data, osso_rpc_t *retval) +static gboolean +on_idle_delete_message (gpointer user_data) { TnyList *headers; TnyFolder *folder; @@ -608,22 +607,13 @@ on_delete_message (GArray *arguments, gpointer data, osso_rpc_t *retval) TnyMsg *msg; TnyAccount *account; GError *error; - osso_rpc_t val; const char *uri; const char *uid; gint res; - if (arguments->len != MODEST_DBUS_DELETE_MESSAGE_ARGS_COUNT) { - return OSSO_ERROR; - } - - val = g_array_index (arguments, - osso_rpc_t, - MODEST_DBUS_DELETE_MESSAGE_ARG_URI); - - uri = (const char *) val.value.s; + uri = (char *) user_data; - g_debug ("Searching message (delete message)"); + /* g_debug ("modest: %s Searching for message (delete message)"); */ msg = find_message_by_url (uri, &account); @@ -631,7 +621,7 @@ on_delete_message (GArray *arguments, gpointer data, osso_rpc_t *retval) return OSSO_ERROR; } - g_debug ("Found message"); + g_debug ("modest: %s: Found message", __FUNCTION__); msg_header = tny_msg_get_header (msg); uid = tny_header_get_uid (msg_header); @@ -653,7 +643,7 @@ on_delete_message (GArray *arguments, gpointer data, osso_rpc_t *retval) iter = tny_list_create_iterator (headers); header = NULL; - g_debug ("Searching header for msg in folder"); + /* g_debug ("Searching header for msg in folder"); */ while (!tny_iterator_is_done (iter)) { const char *cur_id; @@ -661,7 +651,7 @@ on_delete_message (GArray *arguments, gpointer data, osso_rpc_t *retval) cur_id = tny_header_get_uid (header); if (cur_id && uid && g_str_equal (cur_id, uid)) { - g_debug ("Found correspoding header from folder"); + /* g_debug ("Found corresponding header from folder"); */ break; } @@ -671,17 +661,20 @@ on_delete_message (GArray *arguments, gpointer data, osso_rpc_t *retval) } g_object_unref (iter); + iter = NULL; g_object_unref (headers); + headers = NULL; g_object_unref (msg_header); + msg_header = NULL; g_object_unref (msg); + msg = NULL; if (header == NULL) { g_object_unref (folder); return OSSO_ERROR; - } - - + } + error = NULL; res = OSSO_OK; tny_folder_remove_msg (folder, header, &error); @@ -691,11 +684,45 @@ on_delete_message (GArray *arguments, gpointer data, osso_rpc_t *retval) res = OSSO_ERROR; g_error_free (error); } - + + gdk_threads_enter (); + + ModestWindowMgr *win_mgr = modest_runtime_get_window_mgr (); + ModestWindow *msg_view = NULL; + if (modest_window_mgr_find_registered_header (win_mgr, header, &msg_view)) { + if (MODEST_IS_MSG_VIEW_WINDOW (msg_view)) + modest_ui_actions_refresh_message_window_after_delete (MODEST_MSG_VIEW_WINDOW (msg_view)); + } + + gdk_threads_leave (); + + g_object_unref (header); g_object_unref (folder); return res; } +static gint +on_delete_message (GArray *arguments, gpointer data, osso_rpc_t *retval) +{ + if (arguments->len != MODEST_DBUS_DELETE_MESSAGE_ARGS_COUNT) + return OSSO_ERROR; + + /* Use g_idle to context-switch into the application's thread: */ + + /* Get the arguments: */ + osso_rpc_t val = g_array_index (arguments, + osso_rpc_t, + MODEST_DBUS_DELETE_MESSAGE_ARG_URI); + gchar *uri = g_strdup (val.value.s); + + /* printf(" debug: to=%s\n", idle_data->to); */ + g_idle_add(on_idle_delete_message, (gpointer)uri); + + /* Note that we cannot report failures during sending, + * because that would be asynchronous. */ + return OSSO_OK; +} + static gboolean on_idle_send_receive(gpointer user_data) { diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index 1c5f9d7..6c9dae5 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -258,6 +258,20 @@ headers_action_delete (TnyHeader *header, /* modest_header_view_refilter (MODEST_HEADER_VIEW (user_data)); */ } +/** After deleing a message that is currently visible in a window, + * show the next message from the list, or close the window if there are no more messages. + **/ +void modest_ui_actions_refresh_message_window_after_delete (ModestMsgViewWindow* win) +{ + /* Close msg view window or select next */ + if (modest_msg_view_window_last_message_selected (win) && + modest_msg_view_window_first_message_selected (win)) { + modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (win)); + } else { + modest_msg_view_window_select_next_message (win); + } +} + void modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win) { @@ -284,7 +298,7 @@ modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win) header_list = get_selected_headers (win); if (!header_list) return; - /* Check if any of the headers is already opened, or in the process of being opened */ + /* Check if any of the headers are already opened, or in the process of being opened */ if (MODEST_IS_MAIN_WINDOW (win)) { gboolean found; iter = tny_list_create_iterator (header_list); @@ -324,7 +338,8 @@ modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win) message = g_strdup_printf(ngettext("emev_nc_delete_message", "emev_nc_delete_messages", tny_list_get_length(header_list)), desc); - /* Confirmation dialog */ + /* Confirmation dialog */ + printf("DEBUG: %s\n", __FUNCTION__); response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win), message); @@ -357,13 +372,7 @@ modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win) do_headers_action (win, headers_action_delete, header_view); if (MODEST_IS_MSG_VIEW_WINDOW (win)) { - /* Close msg view window or select next */ - if (modest_msg_view_window_last_message_selected (MODEST_MSG_VIEW_WINDOW (win)) && - modest_msg_view_window_first_message_selected (MODEST_MSG_VIEW_WINDOW (win))) { - modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (win)); - } else { - modest_msg_view_window_select_next_message (MODEST_MSG_VIEW_WINDOW (win)); - } + modest_ui_actions_refresh_message_window_after_delete (MODEST_MSG_VIEW_WINDOW (win)); /* Get main window */ mgr = modest_runtime_get_window_mgr (); diff --git a/src/modest-ui-actions.h b/src/modest-ui-actions.h index 91655be..93a874c 100644 --- a/src/modest-ui-actions.h +++ b/src/modest-ui-actions.h @@ -40,6 +40,8 @@ G_BEGIN_DECLS /* Menu & toolbar actions */ void modest_ui_actions_on_about (GtkAction *action, ModestWindow *win); +void modest_ui_actions_refresh_message_window_after_delete (ModestMsgViewWindow* win); + void modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win); void modest_ui_actions_on_delete_message_or_folder (GtkAction *action, ModestWindow *win); -- 1.7.9.5