grim/guifications2

Backed out changeset 96be5252de77

2009-09-23, John Bailey
08153800669a
Backed out changeset 96be5252de77

This was crashy.
--- a/src/gf_display.c Mon Aug 24 00:19:59 2009 -0500
+++ b/src/gf_display.c Wed Sep 23 23:07:54 2009 -0400
@@ -930,79 +930,9 @@
return FALSE;
}
-static inline gboolean
-gf_display_condense_check_buddy(GfEventInfo *info1, GfEventInfo *info2) {
- PurpleAccount *account1 = NULL, *account2 = NULL;
- PurpleBuddy *buddy1 = NULL, *buddy2 = NULL;
- const gchar *name1 = NULL, *name2 = NULL;
-
- buddy1 = gf_event_info_get_buddy(info1);
- buddy2 = gf_event_info_get_buddy(info2);
-
- /* if we don't have any buddies, we can't do anything, so bail */
- if(!buddy1 || !buddy2)
- return FALSE;
-
- name1 = purple_buddy_get_name(buddy1);
- name2 = purple_buddy_get_name(buddy2);
-
- account1 = purple_buddy_get_account(buddy1);
- account2 = purple_buddy_get_account(buddy2);
-
- return (!g_utf8_collate(name1, name2) && account1 == account2);
-}
-
-static inline gboolean
-gf_display_condense_check_contact(GfEventInfo *info1, GfEventInfo *info2) {
- PurpleBuddy *buddy1 = NULL, *buddy2 = NULL;
- PurpleContact *contact1 = NULL, *contact2 = NULL;
-
- buddy1 = gf_event_info_get_buddy(info1);
- buddy2 = gf_event_info_get_buddy(info2);
-
- /* if we don't have any buddies, we can't do anything, so bail */
- if(!buddy1 || !buddy2)
- return FALSE;
-
- contact1 = purple_buddy_get_contact(buddy1);
- contact2 = purple_buddy_get_contact(buddy2);
-
- return (contact1 == contact2);
-}
-
-static inline gboolean
-gf_display_condense_check_target(GfEventInfo *info1, GfEventInfo *info2) {
- PurpleConversation *conv1 = NULL, *conv2 = NULL;
- const gchar *target1 = NULL, *target2 = NULL;
-
- conv1 = gf_event_info_get_conversation(info1);
- conv2 = gf_event_info_get_conversation(info2);
-
- /* if we don't have any conversations, we can't do anythin, so bail */
- if(!conv1 || !conv2)
- return FALSE;
-
- if(conv1 != conv2)
- return FALSE;
-
- target1 = gf_event_info_get_target(info1);
- target2 = gf_event_info_get_target(info2);
-
- return (!g_utf8_collate(target1, target2));
-}
-
-#define GF_DISPLAY_CHECK_PRIORITY G_STMT_START { \
- if(priority1 >= priority2) { \
- gf_display_destroy(display); \
- continue; \
- } else { \
- ret = TRUE; \
- } \
-} G_STMT_END
-
-/* Yes this big ugly function... isn't so big and ugly anymore...
+/* Yes this big ugly function has a purpose...
* It checks for existing notification from the same buddy, or conv with
- * with the same target, and condenses contacts by the use of helper funcs.
+ * with the same target, and condenses contacts.
*
* It returns TRUE if the new notification/event should be destroyed because
* theres a matching notification that has a higher priority than the new
@@ -1013,28 +943,104 @@
GfDisplay *display = NULL;
GfEvent *event1 = NULL, *event2 = NULL;
GfEventPriority priority1, priority2;
+ PurpleBuddy *buddy1 = NULL, *buddy2 = NULL;
+ PurpleContact *contact1 = NULL, *contact2 = NULL;
+ PurpleConversation *conv1 = NULL, *conv2 = NULL;
GList *l = NULL, *ll = NULL;
+ gchar *ck1 = NULL, *ck2 = NULL;
+ const gchar *target1 = NULL, *target2 = NULL;
gboolean ret = FALSE;
event1 = gf_event_info_get_event(info);
priority1 = gf_event_get_priority(event1);
+ buddy1 = gf_event_info_get_buddy(info);
+ conv1 = gf_event_info_get_conversation(info);
+ target1 = gf_event_info_get_target(info);
+
+ if(buddy1)
+ contact1 = purple_buddy_get_contact(buddy1);
+
+ if(target1)
+ ck1 = g_utf8_collate_key(target1, -1);
+
for(l = displays; l; l = ll) {
display = GF_DISPLAY(l->data);
ll = l->next;
+ event2 = gf_event_info_get_event(display->info);
priority2 = gf_event_get_priority(event2);
- if(gf_display_condense_check_buddy(info, display->info))
- GF_DISPLAY_CHECK_PRIORITY;
+ conv2 = gf_event_info_get_conversation(display->info);
+
+ if(buddy1) {
+ buddy2 = gf_event_info_get_buddy(display->info);
+
+ /* check contacts */
+ if(buddy2) {
+ contact2 = purple_buddy_get_contact(buddy2);
+
+ if(contact1 && contact1 == contact2) {
+ ck2 = g_utf8_collate_key(buddy2->name, -1);
+
+ if(!(buddy1->account == buddy2->account &&
+ !strcmp(ck1, ck2)))
+ {
+ g_free(ck2);
+ ck2 = NULL;
+ if(priority1 >= priority2) {
+ gf_event_info_set_is_contact(info, TRUE);
+ gf_display_destroy(display);
+ continue;
+ } else {
+ ret = TRUE;
+ break;
+ }
+ } else {
+ g_free(ck2);
+ ck2 = NULL;
+ }
+ }
+ }
- if(gf_display_condense_check_contact(info, display->info))
- GF_DISPLAY_CHECK_PRIORITY;
+ /* check for duplicate buddies */
+ if(buddy1 == buddy2) {
+ if(priority1 >= priority2) {
+ gf_display_destroy(display);
+ continue;
+ } else {
+ ret = TRUE;
+ break;
+ }
+ }
+ }
+
+ /* check for duplicate targets from the same conv */
+ if(ck1 && conv1 && conv1 == conv2) {
+ target2 = gf_event_info_get_target(display->info);
+
+ if(target2)
+ ck2 = g_utf8_collate_key(target2, -1);
- if(gf_display_condense_check_target(info, display->info))
- GF_DISPLAY_CHECK_PRIORITY;
+ if(ck2 && !strcmp(ck1, ck2)) {
+ g_free(ck2);
+
+ if(priority1 >= priority2) {
+ gf_display_destroy(display);
+ continue;
+ } else {
+ ret = TRUE;
+ break;
+ }
+ } else {
+ g_free(ck2);
+ }
+ }
}
+ if(ck1)
+ g_free(ck1);
+
/* we only check the stack count if ret is true, because that means one
* has been removed, so we have space.
*/