comparison pidgin/gtkstatusbox.c @ 28821:a5b8f6f2b112

only need to loop over active accounts once for this
author Ka-Hing Cheung <khc@hxbc.us>
date Mon, 26 Oct 2009 01:11:53 +0000
parents 95f2ddd033f8
children 9e8d0537d37d
comparison
equal deleted inserted replaced
28820:95f2ddd033f8 28821:a5b8f6f2b112
994 994
995 /* This returns NULL if the active accounts don't have identical 995 /* This returns NULL if the active accounts don't have identical
996 * statuses and a token account if they do */ 996 * statuses and a token account if they do */
997 static PurpleAccount* check_active_accounts_for_identical_statuses(void) 997 static PurpleAccount* check_active_accounts_for_identical_statuses(void)
998 { 998 {
999 PurpleAccount *acct = NULL, *acct2; 999 GList *iter, *active_accts = purple_accounts_get_all_active();
1000 GList *tmp, *tmp2, *active_accts = purple_accounts_get_all_active(); 1000 PurpleAccount *acct1 = NULL;
1001 GList *s, *s1, *s2; 1001 const char *prpl1 = NULL;
1002 1002
1003 for (tmp = active_accts; tmp; tmp = tmp->next) { 1003 if (active_accts) {
1004 acct = tmp->data; 1004 acct1 = active_accts->data;
1005 s = purple_account_get_status_types(acct); 1005 prpl1 = purple_account_get_protocol_id(acct1);
1006 for (tmp2 = tmp->next; tmp2; tmp2 = tmp2->next) { 1006 } else {
1007 acct2 = tmp2->data; 1007 /* there's no enabled account */
1008 1008 return NULL;
1009 /* Only actually look at the statuses if the accounts use the same prpl */ 1009 }
1010 if (strcmp(purple_account_get_protocol_id(acct), purple_account_get_protocol_id(acct2))) { 1010
1011 acct = NULL; 1011 /* start at the second account */
1012 for (iter = active_accts->next; iter; iter = iter->next) {
1013 PurpleAccount *acct2 = iter->data;
1014 GList *s1, *s2;
1015
1016 if (!g_str_equal(prpl1, purple_account_get_protocol_id(acct2))) {
1017 acct1 = NULL;
1018 break;
1019 }
1020
1021 for (s1 = purple_account_get_status_types(acct1),
1022 s2 = purple_account_get_status_types(acct2); s1 && s2;
1023 s1 = s1->next, s2 = s2->next) {
1024 PurpleStatusType *st1 = s1->data, *st2 = s2->data;
1025 /* TODO: Are these enough to consider the statuses identical? */
1026 if (purple_status_type_get_primitive(st1) != purple_status_type_get_primitive(st2)
1027 || strcmp(purple_status_type_get_id(st1), purple_status_type_get_id(st2))
1028 || strcmp(purple_status_type_get_name(st1), purple_status_type_get_name(st2))) {
1029 acct1 = NULL;
1012 break; 1030 break;
1013 } 1031 }
1014 1032 }
1015 s2 = purple_account_get_status_types(acct2); 1033
1016 1034 if (s1 != s2) {/* Will both be NULL if matched */
1017 s1 = s; 1035 acct1 = NULL;
1018 while (s1 && s2) {
1019 PurpleStatusType *st1 = s1->data, *st2 = s2->data;
1020 /* TODO: Are these enough to consider the statuses identical? */
1021 if (purple_status_type_get_primitive(st1) != purple_status_type_get_primitive(st2)
1022 || strcmp(purple_status_type_get_id(st1), purple_status_type_get_id(st2))
1023 || strcmp(purple_status_type_get_name(st1), purple_status_type_get_name(st2))) {
1024 acct = NULL;
1025 break;
1026 }
1027
1028 s1 = s1->next;
1029 s2 = s2->next;
1030 }
1031
1032 if (s1 != s2) {/* Will both be NULL if matched */
1033 acct = NULL;
1034 break;
1035 }
1036 }
1037 if (!acct)
1038 break; 1036 break;
1039 } 1037 }
1038 }
1039
1040 g_list_free(active_accts); 1040 g_list_free(active_accts);
1041 1041
1042 return acct; 1042 return acct1;
1043 } 1043 }
1044 1044
1045 static void 1045 static void
1046 add_account_statuses(PidginStatusBox *status_box, PurpleAccount *account) 1046 add_account_statuses(PidginStatusBox *status_box, PurpleAccount *account)
1047 { 1047 {