Mercurial > ~mikael > mcabber > hg
comparison mcabber/mcabber/hooks.c @ 1839:f0a07658e009
Update UNREAD event data
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sat, 27 Mar 2010 18:42:37 +0100 |
parents | d10c291d31a7 |
children | 2e133fc0e3d9 |
comparison
equal
deleted
inserted
replaced
1838:d10c291d31a7 | 1839:f0a07658e009 |
---|---|
650 } | 650 } |
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 | |
656 // Previous static variables are initialized with an unlikely value | 655 // Previous static variables are initialized with an unlikely value |
657 static guint prev_unread = 65535; | 656 static guint prev_unread = 65535; |
658 static guint prev_attention = 65535; | 657 static guint prev_attention = 65535; |
659 static guint prev_muc_unread = 65535; | 658 static guint prev_muc_unread = 65535; |
660 static guint prev_muc_attention = 65535; | 659 static guint prev_muc_attention = 65535; |
660 gchar *str_unread; | |
661 | 661 |
662 // Do not call the handlers if the unread values haven't changed | 662 // Do not call the handlers if the unread values haven't changed |
663 if (unread_count == prev_unread && | 663 if (unread_count == prev_unread && |
664 attention_count == prev_attention && | 664 attention_count == prev_attention && |
665 muc_unread == prev_muc_unread && | 665 muc_unread == prev_muc_unread && |
666 muc_attention == prev_muc_attention) | 666 muc_attention == prev_muc_attention) |
667 return; | 667 return; |
668 | 668 |
669 gchar *str_unread = g_strdup_printf("%u", unread_count); | 669 #ifdef MODULES_ENABLE |
670 gchar *str_attention = g_strdup_printf("%u", attention_count); | 670 { |
671 gchar *str_muc_unread = g_strdup_printf("%u", muc_unread); | 671 str_unread = g_strdup_printf("%u", unread_count); |
672 gchar *str_muc_attention = g_strdup_printf("%u", muc_attention); | 672 gchar *str_attention = g_strdup_printf("%u", attention_count); |
673 hk_arg_t args[] = { | 673 gchar *str_muc_unread = g_strdup_printf("%u", muc_unread); |
674 { "unread", str_unread }, // All unread | 674 gchar *str_muc_attention = g_strdup_printf("%u", muc_attention); |
675 { "attention", str_attention }, // Attention (private) | 675 hk_arg_t args[] = { |
676 { "muc_unread", str_muc_unread }, // MUC unread | 676 { "unread", str_unread }, // All unread |
677 { "muc_attention", str_muc_attention }, // MUC attention (highlight) | 677 { "attention", str_attention }, // Attention (private) |
678 { NULL, NULL }, | 678 { "muc_unread", str_muc_unread }, // MUC unread |
679 }; | 679 { "muc_attention", str_muc_attention }, // MUC attention (highlight) |
680 hk_run_handlers(HOOK_UNREAD_LIST_CHANGE, args); | 680 { NULL, NULL }, |
681 g_free(str_unread); | 681 }; |
682 g_free(str_attention); | 682 hk_run_handlers(HOOK_UNREAD_LIST_CHANGE, args); |
683 g_free(str_muc_unread); | 683 g_free(str_unread); |
684 g_free(str_muc_attention); | 684 g_free(str_attention); |
685 g_free(str_muc_unread); | |
686 g_free(str_muc_attention); | |
687 } | |
688 #endif | |
685 | 689 |
686 prev_unread = unread_count; | 690 prev_unread = unread_count; |
687 prev_attention = attention_count; | 691 prev_attention = attention_count; |
688 prev_muc_unread = muc_unread; | 692 prev_muc_unread = muc_unread; |
689 prev_muc_attention = muc_attention; | 693 prev_muc_attention = muc_attention; |
690 #endif | 694 |
695 /* Call external command */ | |
696 str_unread = g_strdup_printf("%u %u %u %u", unread_count, attention_count, | |
697 muc_unread, muc_attention); | |
698 hk_ext_cmd("", 'U', (guchar)MIN(255, unread_count), str_unread); | |
699 g_free(str_unread); | |
691 } | 700 } |
692 | 701 |
693 | 702 |
694 /* External commands */ | 703 /* External commands */ |
695 | 704 |
710 // Launch an external command (process) for the given event. | 719 // Launch an external command (process) for the given event. |
711 // For now, data should be NULL. | 720 // For now, data should be NULL. |
712 void hk_ext_cmd(const char *bjid, guchar type, guchar info, const char *data) | 721 void hk_ext_cmd(const char *bjid, guchar type, guchar info, const char *data) |
713 { | 722 { |
714 pid_t pid; | 723 pid_t pid; |
715 char *arg_type = NULL; | 724 const char *arg_type = NULL; |
716 char *arg_info = NULL; | 725 const char *arg_info = NULL; |
717 char *arg_data = NULL; | 726 const char *arg_data = NULL; |
718 char status_str[2]; | 727 char status_str[2]; |
719 char *datafname = NULL; | 728 char *datafname = NULL; |
720 char unread_str[16]; | |
721 | 729 |
722 if (!extcmd) return; | 730 if (!extcmd) return; |
723 | 731 |
724 // Prepare arg_* (external command parameters) | 732 // Prepare arg_* (external command parameters) |
725 switch (type) { | 733 switch (type) { |
742 arg_info = status_str; | 750 arg_info = status_str; |
743 } | 751 } |
744 break; | 752 break; |
745 case 'U': /* Unread buffer count */ | 753 case 'U': /* Unread buffer count */ |
746 arg_type = "UNREAD"; | 754 arg_type = "UNREAD"; |
747 g_snprintf(unread_str, sizeof unread_str, "%d", info); | 755 arg_info = data; |
748 arg_info = unread_str; /* number of remaining unread bjids */ | |
749 break; | 756 break; |
750 default: | 757 default: |
751 return; | 758 return; |
752 } | 759 } |
753 | 760 |