From ee9a9871f25d1cbb863c76b57b5acadea4035695 Mon Sep 17 00:00:00 2001 From: Sergio Villar Senin Date: Tue, 24 Jun 2008 12:34:46 +0000 Subject: [PATCH] * Fixes NB#86564, do not hang when selecting all the messages of huge folders * Added a great performance improvement in the dimming rules manager pmo-trunk-r4758 --- src/modest-ui-actions.c | 2 +- src/modest-ui-dimming-manager.c | 74 ++++++++++++++++++++++++++++++++++++--- src/modest-ui-dimming-rules.c | 34 ++++++++++-------- 3 files changed, 91 insertions(+), 19 deletions(-) diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index e94eb7a..9a56876 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -4075,9 +4075,9 @@ modest_ui_actions_on_select_all (GtkAction *action, /* Set focuse on header view */ gtk_widget_grab_focus (header_view); - /* Enable window dimming management */ modest_window_enable_dimming (MODEST_WINDOW(window)); + modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window)); modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window)); } diff --git a/src/modest-ui-dimming-manager.c b/src/modest-ui-dimming-manager.c index 27384c6..3f33a2c 100644 --- a/src/modest-ui-dimming-manager.c +++ b/src/modest-ui-dimming-manager.c @@ -27,6 +27,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "modest-debug.h" #include "modest-ui-dimming-manager.h" #include "modest-dimming-rules-group-priv.h" @@ -40,6 +41,7 @@ static void _process_all_rules (gpointer key, gpointer value, gpointer user_data typedef struct _ModestUIDimmingManagerPrivate ModestUIDimmingManagerPrivate; struct _ModestUIDimmingManagerPrivate { GHashTable *groups_map; + GHashTable *delayed_calls; }; #define MODEST_UI_DIMMING_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ @@ -96,6 +98,10 @@ modest_ui_dimming_manager_init (ModestUIDimmingManager *obj) (GEqualFunc) g_str_equal, (GDestroyNotify) g_free, (GDestroyNotify) g_object_unref); + priv->delayed_calls = g_hash_table_new_full (g_str_hash, + g_str_equal, + g_free, + NULL); } static void @@ -106,7 +112,10 @@ modest_ui_dimming_manager_finalize (GObject *obj) priv = MODEST_UI_DIMMING_MANAGER_GET_PRIVATE(obj); if (priv->groups_map != NULL) - g_hash_table_destroy (priv->groups_map); + g_hash_table_unref (priv->groups_map); + + if (priv->delayed_calls != NULL) + g_hash_table_unref (priv->delayed_calls); G_OBJECT_CLASS(parent_class)->finalize (obj); } @@ -159,12 +168,56 @@ modest_ui_dimming_manager_process_dimming_rules (ModestUIDimmingManager *self) g_hash_table_foreach (priv->groups_map, _process_all_rules, NULL); } +typedef struct +{ + ModestDimmingRulesGroup *group; + ModestUIDimmingManager *manager; + gchar *name; +} DelayedDimmingRules; + +static gboolean +process_dimming_rules_delayed (gpointer data) +{ + DelayedDimmingRules *helper = (DelayedDimmingRules *) data; + gpointer timeout_handler; + ModestUIDimmingManagerPrivate *priv; + + /* We remove the timeout here because the execute action could + take too much time, and so this will be called again */ + priv = MODEST_UI_DIMMING_MANAGER_GET_PRIVATE(helper->manager); + timeout_handler = g_hash_table_lookup (priv->delayed_calls, helper->name); + + MODEST_DEBUG_BLOCK(g_print ("---------------------HIT %d\n", GPOINTER_TO_INT (timeout_handler));); + + if (GPOINTER_TO_INT (timeout_handler) > 0) { + g_source_remove (GPOINTER_TO_INT (timeout_handler)); + } + + modest_dimming_rules_group_execute (helper->group); + + return FALSE; +} + +static void +process_dimming_rules_delayed_destroyer (gpointer data) +{ + DelayedDimmingRules *helper = (DelayedDimmingRules *) data; + ModestUIDimmingManagerPrivate *priv; + + priv = MODEST_UI_DIMMING_MANAGER_GET_PRIVATE(helper->manager); + g_hash_table_remove (priv->delayed_calls, helper->name); + g_free (helper->name); + g_slice_free (DelayedDimmingRules, helper); +} + void modest_ui_dimming_manager_process_dimming_rules_group (ModestUIDimmingManager *self, const gchar *group_name) { ModestDimmingRulesGroup *group = NULL; ModestUIDimmingManagerPrivate *priv; + guint *handler, new_handler; + DelayedDimmingRules *helper; g_return_if_fail (group_name != NULL); @@ -173,9 +226,22 @@ modest_ui_dimming_manager_process_dimming_rules_group (ModestUIDimmingManager *s /* Search group by name */ group = MODEST_DIMMING_RULES_GROUP(g_hash_table_lookup (priv->groups_map, group_name)); g_return_if_fail (group != NULL); - - /* Performs group dimming rules checking */ - modest_dimming_rules_group_execute (group); + + /* If there was another pending dimming operation check then ignore this */ + handler = g_hash_table_lookup (priv->delayed_calls, group_name); + if (!handler) { + /* Create the helper and start the timeout */ + helper = g_slice_new (DelayedDimmingRules); + helper->group = group; + helper->manager = self; + helper->name = g_strdup (group_name); + new_handler = g_timeout_add_full (G_PRIORITY_DEFAULT, 500, process_dimming_rules_delayed, + helper, process_dimming_rules_delayed_destroyer); + g_hash_table_insert (priv->delayed_calls, g_strdup (group_name), GINT_TO_POINTER (new_handler)); + MODEST_DEBUG_BLOCK(g_print ("---------------------Adding %d\n", new_handler);); + } else { + MODEST_DEBUG_BLOCK(g_print ("---------------------Ignoring\n");); + } } diff --git a/src/modest-ui-dimming-rules.c b/src/modest-ui-dimming-rules.c index 2bf5454..caabb65 100644 --- a/src/modest-ui-dimming-rules.c +++ b/src/modest-ui-dimming-rules.c @@ -99,6 +99,7 @@ _define_main_window_dimming_state (ModestMainWindow *window) gboolean all_seen = TRUE; gboolean all_cached = TRUE; gboolean all_has_attach = TRUE; + TnyFolder *folder = NULL; g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(window), NULL); @@ -173,23 +174,28 @@ _define_main_window_dimming_state (ModestMainWindow *window) state->any_has_attachments = flags & TNY_HEADER_FLAG_ATTACHMENTS; /* sent in progress */ - msg_uid = modest_tny_send_queue_get_msg_id (header); - if (!state->sent_in_progress) { - cache_mgr = modest_runtime_get_cache_mgr (); - send_queue_cache = modest_cache_mgr_get_cache (cache_mgr, - MODEST_CACHE_MGR_CACHE_TYPE_SEND_QUEUE); - - g_hash_table_foreach (send_queue_cache, (GHFunc) fill_list_of_caches, &send_queues); + folder = tny_header_get_folder (header); + if (folder) { + if (modest_tny_folder_guess_folder_type (folder) == TNY_FOLDER_TYPE_OUTBOX) { + msg_uid = modest_tny_send_queue_get_msg_id (header); + if (!state->sent_in_progress) { + cache_mgr = modest_runtime_get_cache_mgr (); + send_queue_cache = modest_cache_mgr_get_cache (cache_mgr, + MODEST_CACHE_MGR_CACHE_TYPE_SEND_QUEUE); - for (node = send_queues; node != NULL && !found; node = g_slist_next (node)) { - send_queue = MODEST_TNY_SEND_QUEUE (node->data); - - /* Check if msg uid is being processed inside send queue */ - found = modest_tny_send_queue_msg_is_being_sent (send_queue, msg_uid); + g_hash_table_foreach (send_queue_cache, (GHFunc) fill_list_of_caches, &send_queues); + + for (node = send_queues; node != NULL && !found; node = g_slist_next (node)) { + send_queue = MODEST_TNY_SEND_QUEUE (node->data); + + /* Check if msg uid is being processed inside send queue */ + found = modest_tny_send_queue_msg_is_being_sent (send_queue, msg_uid); + } + state->sent_in_progress = found; + } } - state->sent_in_progress = found; + g_object_unref (folder); } - tny_iterator_next (iter); g_object_unref (header); } -- 1.7.9.5