Mercurial > pidgin.yaz
comparison src/status.c @ 10012:a38881ec9c0f
[gaim-migrate @ 10929]
i'm fairly certain this is all better
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Sat, 11 Sep 2004 05:41:50 +0000 |
parents | 56e34a659db2 |
children | f1f239fa8973 |
comparison
equal
deleted
inserted
replaced
10011:32467b63f55a | 10012:a38881ec9c0f |
---|---|
116 | 116 |
117 typedef struct | 117 typedef struct |
118 { | 118 { |
119 GaimAccount *account; | 119 GaimAccount *account; |
120 char *name; | 120 char *name; |
121 guint id; | |
122 | |
123 } GaimStatusBuddyKey; | 121 } GaimStatusBuddyKey; |
124 | 122 |
125 | 123 |
126 #if 0 | 124 #if 0 |
127 static GList *stored_statuses = NULL; | 125 static GList *stored_statuses = NULL; |
216 va_list args; | 214 va_list args; |
217 | 215 |
218 g_return_val_if_fail(primitive != GAIM_STATUS_UNSET, NULL); | 216 g_return_val_if_fail(primitive != GAIM_STATUS_UNSET, NULL); |
219 g_return_val_if_fail(id != NULL, NULL); | 217 g_return_val_if_fail(id != NULL, NULL); |
220 g_return_val_if_fail(name != NULL, NULL); | 218 g_return_val_if_fail(name != NULL, NULL); |
221 g_return_val_if_fail(attr_id != NULL, NULL); | 219 g_return_val_if_fail(attr_id != NULL, NULL); |
222 g_return_val_if_fail(attr_name != NULL, NULL); | 220 g_return_val_if_fail(attr_name != NULL, NULL); |
223 g_return_val_if_fail(attr_value != NULL, NULL); | 221 g_return_val_if_fail(attr_value != NULL, NULL); |
224 | 222 |
225 status_type = gaim_status_type_new_full(primitive, id, name, saveable, | 223 status_type = gaim_status_type_new_full(primitive, id, name, saveable, |
226 user_settable, independent); | 224 user_settable, independent); |
559 current_time, tmp); | 557 current_time, tmp); |
560 g_free(tmp); | 558 g_free(tmp); |
561 } | 559 } |
562 } | 560 } |
563 | 561 |
564 if (ops != NULL && ops->status_changed != NULL) | 562 |
565 ops->status_changed(buddy, new_status); | 563 |
564 if (ops != NULL && ops->update != NULL) | |
565 ops->update(gaim_get_blist(), (GaimBlistNode*)buddy); | |
566 } | 566 } |
567 | 567 |
568 static void | 568 static void |
569 notify_status_update(GaimPresence *presence, GaimStatus *old_status, | 569 notify_status_update(GaimPresence *presence, GaimStatus *old_status, |
570 GaimStatus *new_status) | 570 GaimStatus *new_status) |
634 { | 634 { |
635 const GList *l; | 635 const GList *l; |
636 | 636 |
637 for (l = gaim_presence_get_statuses(presence); l != NULL; l = l->next) | 637 for (l = gaim_presence_get_statuses(presence); l != NULL; l = l->next) |
638 { | 638 { |
639 GaimStatus *temp_status = (GaimStatus *)l->data; | 639 GaimStatusType *temp_type = l->data; |
640 GaimStatusType *temp_type; | 640 GaimStatus *temp_status = NULL; |
641 | 641 |
642 if (!gaim_status_compare(temp_status, status)) | 642 if (!gaim_status_compare(temp_status, status)) |
643 continue; | 643 continue; |
644 | 644 |
645 temp_type = gaim_status_get_type(temp_status); | |
646 | |
647 if (gaim_status_type_is_independent(temp_type)) | 645 if (gaim_status_type_is_independent(temp_type)) |
648 continue; | 646 continue; |
649 | 647 |
648 | |
649 temp_status = (GaimStatus *)g_hash_table_lookup( | |
650 presence->status_table, | |
651 gaim_status_type_get_id(temp_type)); | |
652 | |
650 if (gaim_status_is_active(temp_status)) | 653 if (gaim_status_is_active(temp_status)) |
651 { | 654 { |
652 /* | 655 /* |
653 * Since we don't want an infinite loop, we have to set | 656 * Since we don't want an infinite loop, we have to set |
654 * the active variable ourself. | 657 * the active variable ourself. |
913 } | 916 } |
914 | 917 |
915 GaimPresence * | 918 GaimPresence * |
916 gaim_presence_new_for_account(GaimAccount *account) | 919 gaim_presence_new_for_account(GaimAccount *account) |
917 { | 920 { |
918 GaimPresence *presence; | 921 GaimPresence *presence = NULL; |
919 | |
920 g_return_val_if_fail(account != NULL, NULL); | 922 g_return_val_if_fail(account != NULL, NULL); |
921 | 923 |
922 presence = gaim_presence_new(GAIM_PRESENCE_CONTEXT_ACCOUNT); | 924 presence = gaim_presence_new(GAIM_PRESENCE_CONTEXT_ACCOUNT); |
923 presence->u.account = account; | 925 presence->u.account = account; |
924 presence->statuses = gaim_prpl_get_statuses(account, presence); | 926 presence->statuses = gaim_prpl_get_statuses(account, presence); |
944 gaim_presence_new_for_buddy(GaimBuddy *buddy) | 946 gaim_presence_new_for_buddy(GaimBuddy *buddy) |
945 { | 947 { |
946 GaimPresence *presence; | 948 GaimPresence *presence; |
947 GaimStatusBuddyKey *key; | 949 GaimStatusBuddyKey *key; |
948 GaimAccount *account; | 950 GaimAccount *account; |
949 gchar *hash_seed; | |
950 | 951 |
951 g_return_val_if_fail(buddy != NULL, NULL); | 952 g_return_val_if_fail(buddy != NULL, NULL); |
952 | |
953 account = buddy->account; | 953 account = buddy->account; |
954 hash_seed = g_strdup_printf("%s:%s:%s", buddy->name, account->username, | 954 |
955 account->protocol_id); | 955 account = buddy->account; |
956 | 956 |
957 key = g_new0(GaimStatusBuddyKey, 1); | 957 key = g_new0(GaimStatusBuddyKey, 1); |
958 key->account = buddy->account; | 958 key->account = buddy->account; |
959 key->name = g_strdup(buddy->name); | 959 key->name = g_strdup(buddy->name); |
960 key->id = g_str_hash(hash_seed); | |
961 | |
962 g_free(hash_seed); | |
963 hash_seed = NULL; | |
964 | 960 |
965 presence = g_hash_table_lookup(buddy_presences, key); | 961 presence = g_hash_table_lookup(buddy_presences, key); |
966 if (presence == NULL) | 962 if (presence == NULL) |
967 { | 963 { |
968 presence = gaim_presence_new(GAIM_PRESENCE_CONTEXT_BUDDY); | 964 presence = gaim_presence_new(GAIM_PRESENCE_CONTEXT_BUDDY); |
1301 | 1297 |
1302 g_return_val_if_fail(presence != NULL, NULL); | 1298 g_return_val_if_fail(presence != NULL, NULL); |
1303 g_return_val_if_fail(status_id != NULL, NULL); | 1299 g_return_val_if_fail(status_id != NULL, NULL); |
1304 | 1300 |
1305 /* What's the purpose of this hash table? */ | 1301 /* What's the purpose of this hash table? */ |
1306 status = (GaimStatus *)g_hash_table_lookup(presence->status_table, | 1302 status = (GaimStatus *)g_hash_table_lookup(presence->status_table, |
1307 status_id); | 1303 status_id); |
1308 | 1304 |
1309 if (status == NULL) { | 1305 if (status == NULL) { |
1310 for (l = gaim_presence_get_statuses(presence); | 1306 for (l = gaim_presence_get_statuses(presence); |
1311 l != NULL && status == NULL; l = l->next) | 1307 l != NULL && status == NULL; l = l->next) |
1312 { | 1308 { |
1313 GaimStatus *temp_status = l->data; | 1309 GaimStatus *temp_status = l->data; |
1314 | 1310 |
1315 if (!strcmp(status_id, gaim_status_get_id(temp_status))) | 1311 if (!strcmp(status_id, gaim_status_get_id(temp_status))) |
1316 status = temp_status; | 1312 status = temp_status; |
1317 } | 1313 } |
1318 | 1314 |
1319 if (status != NULL) | 1315 if (status != NULL) |
1320 g_hash_table_insert(presence->status_table, | 1316 g_hash_table_insert(presence->status_table, |
1321 g_strdup(gaim_status_get_id(status)), status); | 1317 g_strdup(gaim_status_get_id(status)), status); |
1322 } | 1318 } |
1323 | 1319 |
1324 return status; | 1320 return status; |
1325 } | 1321 } |
1326 | 1322 |
1327 GaimStatus * | 1323 GaimStatus * |
1491 int index = GPOINTER_TO_INT(data); | 1487 int index = GPOINTER_TO_INT(data); |
1492 | 1488 |
1493 primitive_scores[index] = GPOINTER_TO_INT(value); | 1489 primitive_scores[index] = GPOINTER_TO_INT(value); |
1494 } | 1490 } |
1495 | 1491 |
1496 guint | 1492 guint |
1497 gaim_buddy_presences_hash(gconstpointer key) | 1493 gaim_buddy_presences_hash(gconstpointer key) |
1498 { | 1494 { |
1499 return ((GaimStatusBuddyKey *)key)->id; | 1495 const GaimStatusBuddyKey *me = key; |
1500 } | 1496 guint ret; |
1501 | 1497 char *str; |
1502 gboolean | 1498 |
1499 str = g_strdup_printf("%p%s", me->account, me->name); | |
1500 ret = g_str_hash(str); | |
1501 g_free(str); | |
1502 | |
1503 return ret; | |
1504 } | |
1505 | |
1506 gboolean | |
1503 gaim_buddy_presences_equal(gconstpointer a, gconstpointer b) | 1507 gaim_buddy_presences_equal(gconstpointer a, gconstpointer b) |
1504 { | 1508 { |
1505 GaimStatusBuddyKey *key_a = (GaimStatusBuddyKey *)a; | 1509 GaimStatusBuddyKey *key_a = (GaimStatusBuddyKey *)a; |
1506 GaimStatusBuddyKey *key_b = (GaimStatusBuddyKey *)b; | 1510 GaimStatusBuddyKey *key_b = (GaimStatusBuddyKey *)b; |
1507 | 1511 |
1508 if (key_a->id == key_b->id) | 1512 if(key_a->account == key_b->account && |
1513 !strcmp(key_a->name, key_b->name)) | |
1509 return TRUE; | 1514 return TRUE; |
1510 else | 1515 else |
1511 return FALSE; | 1516 return FALSE; |
1512 } | 1517 } |
1513 | 1518 |
1547 GINT_TO_POINTER(GAIM_STATUS_EXTENDED_AWAY)); | 1552 GINT_TO_POINTER(GAIM_STATUS_EXTENDED_AWAY)); |
1548 gaim_prefs_connect_callback("/core/status/scores/idle", | 1553 gaim_prefs_connect_callback("/core/status/scores/idle", |
1549 score_pref_changed_cb, | 1554 score_pref_changed_cb, |
1550 GINT_TO_POINTER(SCORE_IDLE)); | 1555 GINT_TO_POINTER(SCORE_IDLE)); |
1551 | 1556 |
1552 /* XXX - I don't think this is destroyed correctly. --Mark */ | |
1553 buddy_presences = g_hash_table_new(gaim_buddy_presences_hash, | 1557 buddy_presences = g_hash_table_new(gaim_buddy_presences_hash, |
1554 gaim_buddy_presences_equal); | 1558 gaim_buddy_presences_equal); |
1555 } | 1559 } |
1556 | 1560 |
1557 void | 1561 void |