comparison mcabber/mcabber/hooks.c @ 1838:d10c291d31a7

Do not call hk_unread_list_change() too frequently
author Mikael Berthe <mikael@lilotux.net>
date Sat, 27 Mar 2010 18:09:29 +0100
parents 6ac5718f8d25
children f0a07658e009
comparison
equal deleted inserted replaced
1837:a09eddfdb6e8 1838:d10c291d31a7
651 651
652 void hk_unread_list_change(guint unread_count, guint attention_count, 652 void hk_unread_list_change(guint unread_count, guint attention_count,
653 guint muc_unread, guint muc_attention) 653 guint muc_unread, guint muc_attention)
654 { 654 {
655 #ifdef MODULES_ENABLE 655 #ifdef MODULES_ENABLE
656 // Previous static variables are initialized with an unlikely value
657 static guint prev_unread = 65535;
658 static guint prev_attention = 65535;
659 static guint prev_muc_unread = 65535;
660 static guint prev_muc_attention = 65535;
661
662 // Do not call the handlers if the unread values haven't changed
663 if (unread_count == prev_unread &&
664 attention_count == prev_attention &&
665 muc_unread == prev_muc_unread &&
666 muc_attention == prev_muc_attention)
667 return;
668
656 gchar *str_unread = g_strdup_printf("%u", unread_count); 669 gchar *str_unread = g_strdup_printf("%u", unread_count);
657 gchar *str_attention = g_strdup_printf("%u", attention_count); 670 gchar *str_attention = g_strdup_printf("%u", attention_count);
658 gchar *str_muc_unread = g_strdup_printf("%u", muc_unread); 671 gchar *str_muc_unread = g_strdup_printf("%u", muc_unread);
659 gchar *str_muc_attention = g_strdup_printf("%u", muc_attention); 672 gchar *str_muc_attention = g_strdup_printf("%u", muc_attention);
660 hk_arg_t args[] = { 673 hk_arg_t args[] = {
667 hk_run_handlers(HOOK_UNREAD_LIST_CHANGE, args); 680 hk_run_handlers(HOOK_UNREAD_LIST_CHANGE, args);
668 g_free(str_unread); 681 g_free(str_unread);
669 g_free(str_attention); 682 g_free(str_attention);
670 g_free(str_muc_unread); 683 g_free(str_muc_unread);
671 g_free(str_muc_attention); 684 g_free(str_muc_attention);
685
686 prev_unread = unread_count;
687 prev_attention = attention_count;
688 prev_muc_unread = muc_unread;
689 prev_muc_attention = muc_attention;
672 #endif 690 #endif
673 } 691 }
674 692
675 693
676 /* External commands */ 694 /* External commands */