Adium

Changeset 24080

Show
Ignore:
Timestamp:
06/28/2008 09:50:58 AM (5 months ago)
Author:
evands
Message:

Fixed a bunch of stupidity I did a long time ago in ESAddressBookIntegrationPlugin related to automatic contact image syncing, including the following cute snippet:

if (!existingABImage ||
	(objectUserIcon && [(objectUserIconData = [objectUserIcon PNGRepresentation]) isEqualToData:[existingABImage PNGRepresentation]])) {
	[person setImageData:objectUserIconData];
}

which says, "If the person doesn't currently have an image, or the existing image is the same as the new one, set the new one." It also would never set objectUserIconData if there were no existing image. This meant syncing worked in no cases.

That's all fixed now. Fixes #10105

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Source/ESAddressBookIntegrationPlugin.h

    r24027 r24080  
    6262    BOOL                useNickName; 
    6363        BOOL                            useMiddleName; 
    64     BOOL                automaticSync; 
     64    BOOL                automaticUserIconSync; 
    6565        BOOL                            createMetaContacts; 
    6666         
  • trunk/Source/ESAddressBookIntegrationPlugin.m

    r24073 r24080  
    361361- (void)listObjectAttributesChanged:(NSNotification *)notification 
    362362{ 
     363        if (!automaticUserIconSync) return; 
     364 
    363365        AIListObject    *inObject = [notification object]; 
    364366        NSSet                   *keys = [[notification userInfo] objectForKey:@"Keys"]; 
     
    367369                [inObject isKindOfClass:[AIListContact class]]) { 
    368370                AIListContact *listContact = (AIListContact *)inObject; 
    369  
    370                 //Only update when the serverside icon changes if there is no Adium preference overriding it 
    371                 if (![AIUserIcons manuallySetUserIconDataForObject:listContact]) { 
    372                         //Find the person 
    373                         ABPerson *person = [listContact addressBookPerson]; 
    374  
    375                         if (person && (person != [sharedAddressBook me])) { 
    376                                 NSData  *existingABImageData = [person imageData]; 
    377                                 NSImage *existingABImage = (existingABImageData ? [[NSImage alloc] initWithData:[person imageData]] : nil); 
    378                                 NSImage *objectUserIcon = [listContact userIcon]; 
    379                                 NSData  *objectUserIconData = nil; 
    380  
    381                                 AILogWithSignature(@"%@ will be updated to %p if %i", person, objectUserIcon, 
    382                                                                    !existingABImage || 
    383                                                                    (objectUserIcon && [(objectUserIconData = [objectUserIcon PNGRepresentation]) isEqualToData:[existingABImage PNGRepresentation]])); 
    384                                  
    385                                 if (!existingABImage || 
    386                                         (objectUserIcon && [(objectUserIconData = [objectUserIcon PNGRepresentation]) isEqualToData:[existingABImage PNGRepresentation]])) { 
     371                ABPerson *person = [listContact addressBookPerson]; 
     372                         
     373                if (person && (person != [sharedAddressBook me])) { 
     374                        NSData  *existingABImageData = [person imageData]; 
     375                        NSImage *existingABImage = (existingABImageData ? [[[NSImage alloc] initWithData:[person imageData]] autorelease] : nil); 
     376                        NSImage *objectUserIcon = [listContact userIcon]; 
     377                         
     378                        if (!existingABImage || objectUserIcon) { 
     379                                NSData  *objectUserIconData = [objectUserIcon PNGRepresentation]; 
     380                                 
     381                                if (![objectUserIconData isEqualToData:[existingABImage PNGRepresentation]]) { 
    387382                                        [person setImageData:objectUserIconData]; 
    388383                                         
     
    513508                enableImport = [[prefDict objectForKey:KEY_AB_ENABLE_IMPORT] boolValue]; 
    514509                displayFormat = [[prefDict objectForKey:KEY_AB_DISPLAYFORMAT] intValue]; 
    515         automaticSync = [[prefDict objectForKey:KEY_AB_IMAGE_SYNC] boolValue]; 
     510        automaticUserIconSync = [[prefDict objectForKey:KEY_AB_IMAGE_SYNC] boolValue]; 
    516511        useNickName = [[prefDict objectForKey:KEY_AB_USE_NICKNAME] boolValue]; 
    517512                useMiddleName = [[prefDict objectForKey:KEY_AB_USE_MIDDLE] boolValue]; 
     
    545540                } 
    546541                 
    547                 if (automaticSync) { 
     542                if (automaticUserIconSync) { 
    548543                        [[adium notificationCenter] addObserver:self 
    549544                                                                                   selector:@selector(listObjectAttributesChanged:) 
     
    553548                        [[adium notificationCenter] removeObserver:self name:ListObject_AttributesChanged object:nil]; 
    554549                } 
    555  
    556     } else if (automaticSync && ([group isEqualToString:PREF_GROUP_USERICONS]) && object) { 
    557                 //Set an icon to the address book 
    558                 ABPerson *person = [[self class] personForListObject:object]; 
    559                 if (person) { 
    560                         NSData  *existingABImageData = [person imageData]; 
    561                         NSImage *existingABImage = (existingABImageData ? [[NSImage alloc] initWithData:[person imageData]] : nil); 
    562                         NSImage *objectUserIcon = [object userIcon]; 
    563                         NSData  *objectUserIconData = nil; 
    564  
    565                         if (!existingABImage || 
    566                                 (objectUserIcon && [(objectUserIconData = [objectUserIcon PNGRepresentation]) isEqualToData:[existingABImage PNGRepresentation]])) { 
    567                                 [person setImageData:objectUserIconData]; 
    568                         } 
    569                 } 
    570         } 
     550    } 
    571551} 
    572552