Adium

Changeset 23663

Show
Ignore:
Timestamp:
05/26/2008 09:17:26 AM (6 months ago)
Author:
evands
Message:
  • Handle dragging from iTunes to the contact list and message window/message text entry view, using [23662]'s -[NSPasteboard(AIPasteboardAdditions) filesFromITunesDragPasteboard]. Fixes #5114
  • Cleaned up some ugly pasteboard analyzing code in AIAbstractListController
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Frameworks/Adium Framework/Source/AIAbstractListController.m

    r23647 r23663  
    4040#import <AIUtilities/AIApplicationAdditions.h> 
    4141#import <AIUtilities/AIOutlineViewAdditions.h> 
     42#import <AIUtilities/AIPasteboardAdditions.h> 
    4243#import <Adium/KFTypeSelectTableView.h> 
    4344#import "AIMessageWindowController.h" 
     
    202203 
    203204        //Dragging 
    204         [contactListView registerForDraggedTypes:[NSArray arrayWithObjects:@"AIListObject", @"AIListObjectUniqueIDs", NSFilenamesPboardType, NSURLPboardType, NSStringPboardType, nil]]; 
     205        [contactListView registerForDraggedTypes: 
     206         [NSArray arrayWithObjects:@"AIListObject", @"AIListObjectUniqueIDs", 
     207          NSFilenamesPboardType, NSURLPboardType, 
     208          AIiTunesTrackPboardType, NSStringPboardType, nil]]; 
    205209         
    206210        [contactListView reloadData]; 
  • trunk/Frameworks/Adium Framework/Source/AIMessageEntryTextView.m

    r23556 r23663  
    3434#import <AIUtilities/AIImageAdditions.h> 
    3535#import <AIUtilities/AIFileManagerAdditions.h> 
     36#import <AIUtilities/AIPasteboardAdditions.h> 
    3637 
    3738#import <AIUtilities/AITigerCompatibility.h> 
     
    5657 
    5758#define FILES_AND_IMAGES_TYPES [NSArray arrayWithObjects: \ 
    58         NSFilenamesPboardType, NSTIFFPboardType, NSPDFPboardType, NSPICTPboardType, nil] 
     59        NSFilenamesPboardType, AIiTunesTrackPboardType, NSTIFFPboardType, NSPDFPboardType, NSPICTPboardType, nil] 
    5960 
    6061#define PASS_TO_SUPERCLASS_DRAG_TYPE_ARRAY [NSArray arrayWithObjects: \ 
     
    11641165#pragma mark Drag and drop 
    11651166 
    1166 /*An NSTextView which has setImportsGraphics:YES as of 10.3 gets the following drag types by default: 
    1167 "NSColor pasteboard type" 
    1168 "NSFilenamesPboardType" 
    1169 "Apple PDF pasteboard type" 
    1170 "Apple PICT pasteboard type" 
    1171 "NeXT Encapsulated PostScript v1.2 pasteboard type" 
    1172 "NeXT TIFF v4.0 pasteboard type" 
    1173 "CorePasteboardFlavorType 0x6D6F6F76" 
    1174 "Apple HTML pasteboard type" 
    1175 "NeXT RTFD pasteboard type" 
    1176 "NeXT Rich Text Format v1.0 pasteboard type" 
    1177 "NSStringPboardType" 
    1178 "NSFilenamesPboardType" 
     1167/*An NSTextView which has setImportsGraphics:YES as of 10.5 gets the following drag types by default: 
     1168 "NeXT RTFD pasteboard type", 
     1169 "NeXT Rich Text Format v1.0 pasteboard type", 
     1170 "Apple HTML pasteboard type", 
     1171 NSFilenamesPboardType, 
     1172 "CorePasteboardFlavorType 0x6D6F6F76", 
     1173 "Apple PDF pasteboard type", 
     1174 "NeXT TIFF v4.0 pasteboard type", 
     1175 "Apple PICT pasteboard type", 
     1176 "NeXT Encapsulated PostScript v1.2 pasteboard type", 
     1177 "Apple PNG pasteboard type", 
     1178 WebURLsWithTitlesPboardType, 
     1179 "CorePasteboardFlavorType 0x75726C20", 
     1180 "Apple URL pasteboard type", 
     1181 NSStringPboardType, 
     1182 "NSColor pasteboard type", 
     1183 "NeXT font pasteboard type", 
     1184 "NeXT ruler pasteboard type", 
    11791185*/ 
    1180 /* 
     1186 
    11811187- (NSArray *)acceptableDragTypes; 
    11821188{ 
     
    11841190     
    11851191    dragTypes = [NSMutableArray arrayWithArray:[super acceptableDragTypes]]; 
     1192        [dragTypes addObject:AIiTunesTrackPboardType]; 
     1193 
    11861194    return dragTypes; 
    11871195} 
    1188 */ 
     1196 
     1197- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender 
     1198
     1199        NSPasteboard    *pasteboard = [sender draggingPasteboard]; 
     1200 
     1201        if ([pasteboard availableTypeFromArray:FILES_AND_IMAGES_TYPES]) 
     1202                return NSDragOperationCopy; 
     1203        else  
     1204                return [super draggingEntered:sender]; 
     1205
     1206 
     1207- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender 
     1208
     1209        NSPasteboard    *pasteboard = [sender draggingPasteboard]; 
     1210         
     1211        if ([pasteboard availableTypeFromArray:FILES_AND_IMAGES_TYPES]) 
     1212                return NSDragOperationCopy; 
     1213        else  
     1214                return [super draggingUpdated:sender]; 
     1215
    11891216 
    11901217//We don't need to prepare for the types we are handling in performDragOperation: below 
     
    12221249- (void)addAttachmentsFromPasteboard:(NSPasteboard *)pasteboard 
    12231250{ 
    1224         if ([pasteboard availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]]) { 
     1251        NSString *availableType; 
     1252        if ((availableType = [pasteboard availableTypeFromArray:[NSArray arrayWithObjects:NSFilenamesPboardType, AIiTunesTrackPboardType, nil]])) { 
    12251253                //The pasteboard points to one or more files on disc.  Use them directly. 
    1226                 NSArray                 *files = [pasteboard propertyListForType:NSFilenamesPboardType]; 
     1254                NSArray                 *files = nil; 
     1255                if ([availableType isEqualToString:NSFilenamesPboardType]) { 
     1256                        files = [pasteboard propertyListForType:NSFilenamesPboardType]; 
     1257                         
     1258                } else if ([availableType isEqualToString:AIiTunesTrackPboardType]) { 
     1259                        files = [pasteboard filesFromITunesDragPasteboard]; 
     1260                } 
     1261                 
    12271262                NSEnumerator    *enumerator = [files objectEnumerator]; 
    12281263                NSString                *path; 
  • trunk/Source/AIListController.m

    r23645 r23663  
    3434#import <AIUtilities/AIAttributedStringAdditions.h> 
    3535#import <AIUtilities/AIAutoScrollView.h> 
     36#import <AIUtilities/AIPasteboardAdditions.h> 
    3637#import <AIUtilities/AIWindowAdditions.h> 
    3738#import <AIUtilities/AIOutlineViewAdditions.h> 
     
    617618                           [types containsObject:NSRTFPboardType] || 
    618619                           [types containsObject:NSURLPboardType] || 
    619                            [types containsObject:NSStringPboardType]) { 
     620                           [types containsObject:NSStringPboardType] || 
     621                           [types containsObject:AIiTunesTrackPboardType]) { 
    620622                retVal = ((item && [item isKindOfClass:[AIListContact class]]) ? NSDragOperationLink : NSDragOperationNone); 
    621623 
     
    631633        BOOL            success = YES; 
    632634        NSPasteboard *draggingPasteboard = [info draggingPasteboard]; 
    633         NSString        *availableType = [draggingPasteboard availableTypeFromArray:[NSArray arrayWithObject:@"AIListObject"]]
    634          
    635     if ([availableType isEqualToString:@"AIListObject"]) { 
     635        NSString        *availableType
     636         
     637    if ((availableType = [draggingPasteboard availableTypeFromArray:[NSArray arrayWithObject:@"AIListObject"]])) { 
    636638                //Kill the selection now, (in a more finder-esque way) 
    637639                [outlineView deselectAll:nil]; 
     
    654656                         
    655657                } else if ([item isMemberOfClass:[AIMetaContact class]]) { 
    656                         //Ordering gets implemented here. 
    657                         NSString        *availableType = [[info draggingPasteboard] availableTypeFromArray:[NSArray arrayWithObject:@"AIListObject"]]; 
    658                          
    659                         //No longer in a drag, so allow tooltips again 
    660                         if ([availableType isEqualToString:@"AIListObject"]) { 
    661                                  
    662                                 //If we don't have drag items, we are dragging from another instance; build our own dragItems array 
    663                                 //using the supplied internalObjectIDs 
    664                                 if (!dragItems) { 
    665                                         if ([[[info draggingPasteboard] availableTypeFromArray:[NSArray arrayWithObject:@"AIListObjectUniqueIDs"]] isEqualToString:@"AIListObjectUniqueIDs"]) { 
    666                                                 NSArray                 *dragItemsUniqueIDs; 
    667                                                 NSMutableArray  *arrayOfDragItems; 
    668                                                 NSString                *uniqueID; 
    669                                                 NSEnumerator    *enumerator; 
    670                                                  
    671                                                 dragItemsUniqueIDs = [draggingPasteboard propertyListForType:@"AIListObjectUniqueIDs"]; 
    672                                                 arrayOfDragItems = [NSMutableArray array]; 
    673                                                  
    674                                                 enumerator = [dragItemsUniqueIDs objectEnumerator]; 
    675                                                 while ((uniqueID = [enumerator nextObject])) { 
    676                                                         [arrayOfDragItems addObject:[[adium contactController] existingListObjectWithUniqueID:uniqueID]]; 
    677                                                 } 
    678                                                  
    679                                                 //We will release this when the drag is completed 
    680                                                 dragItems = [arrayOfDragItems retain]; 
     658                        //Ordering gets implemented here.                        
     659                                 
     660                        //If we don't have drag items, we are dragging from another instance; build our own dragItems array 
     661                        //using the supplied internalObjectIDs 
     662                        if (!dragItems) { 
     663                                NSArray                 *dragItemsUniqueIDs; 
     664                                NSMutableArray  *arrayOfDragItems; 
     665                                NSString                *uniqueID; 
     666                                NSEnumerator    *enumerator; 
     667                                 
     668                                dragItemsUniqueIDs = [draggingPasteboard propertyListForType:@"AIListObjectUniqueIDs"]; 
     669                                arrayOfDragItems = [NSMutableArray array]; 
     670                                 
     671                                enumerator = [dragItemsUniqueIDs objectEnumerator]; 
     672                                while ((uniqueID = [enumerator nextObject])) { 
     673                                        [arrayOfDragItems addObject:[[adium contactController] existingListObjectWithUniqueID:uniqueID]]; 
     674                                } 
     675                                 
     676                                //We will release this when the drag is completed 
     677                                dragItems = [arrayOfDragItems retain]; 
     678                        } 
     679                         
     680                        //The tree root is not associated with our root contact list group, so we need to make that association here 
     681                        if (item == nil) item = contactList; 
     682                         
     683                        //Move the list object to its new location 
     684                        if ([item isKindOfClass:[AIMetaContact class]]) { 
     685                                 
     686                                NSMutableArray  *realDragItems = [NSMutableArray array]; 
     687                                NSEnumerator    *enumerator; 
     688                                AIListObject    *aDragItem; 
     689                                 
     690                                enumerator = [dragItems objectEnumerator]; 
     691                                while ((aDragItem = [enumerator nextObject])) { 
     692                                        if ([aDragItem isMemberOfClass:[AIListContact class]]) { 
     693                                                //For listContacts, add all contacts with the same service and UID (on all accounts) 
     694                                                [realDragItems addObjectsFromArray:[[[adium contactController] allContactsWithService:[aDragItem service]  
     695                                                                                                                                                                                                                  UID:[aDragItem UID] 
     696                                                                                                                                                                                                 existingOnly:YES] allObjects]]; 
     697                                        } else { 
     698                                                [realDragItems addObject:aDragItem]; 
    681699                                        } 
    682700                                } 
    683701                                 
    684                                 //The tree root is not associated with our root contact list group, so we need to make that association here 
    685                                 if (item == nil) item = contactList; 
    686                                  
    687                                 //Move the list object to its new location 
    688                                 if ([item isKindOfClass:[AIMetaContact class]]) { 
    689                                          
    690                                         NSMutableArray  *realDragItems = [NSMutableArray array]; 
    691                                         NSEnumerator    *enumerator; 
    692                                         AIListObject    *aDragItem; 
    693                                          
    694                                         enumerator = [dragItems objectEnumerator]; 
    695                                         while ((aDragItem = [enumerator nextObject])) { 
    696                                                 if ([aDragItem isMemberOfClass:[AIListContact class]]) { 
    697                                                         //For listContacts, add all contacts with the same service and UID (on all accounts) 
    698                                                         [realDragItems addObjectsFromArray:[[[adium contactController] allContactsWithService:[aDragItem service]  
    699                                                                                                                                                                                                                           UID:[aDragItem UID] 
    700                                                                                                                                                                                                          existingOnly:YES] allObjects]]; 
    701                                                 } else { 
    702                                                         [realDragItems addObject:aDragItem]; 
    703                                                 } 
    704                                         } 
    705                                          
    706                                         [[adium contactController] moveListObjects:realDragItems intoObject:item index:index]; 
    707                                         [outlineView reloadData]; 
    708                                 } 
    709                         } 
    710                          
     702                                [[adium contactController] moveListObjects:realDragItems intoObject:item index:index]; 
     703                                [outlineView reloadData]; 
     704                        } 
     705                 
    711706                        //Call super and return its value 
    712                         return [super outlineView:outlineView acceptDrop:info item:item childIndex:index]; 
    713                          
     707                        return [super outlineView:outlineView acceptDrop:info item:item childIndex:index];               
    714708                         
    715709                } else if ([item isKindOfClass:[AIListContact class]]) { 
     
    739733                                                                                   AILocalizedString(@"Once combined, Adium will treat these contacts as a single individual both on your contact list and when sending messages.\n\nYou may un-combine these contacts by getting info on the combined contact.","Explanation of metacontact creation")); 
    740734                } 
    741         } else if ([[[info draggingPasteboard] types] containsObject:NSFilenamesPboardType]) { 
     735 
     736                 
     737        } else if ((availableType = [[info draggingPasteboard] availableTypeFromArray:[NSArray arrayWithObjects: 
     738                                                                                                                                                                   NSFilenamesPboardType, AIiTunesTrackPboardType, nil]])) { 
    742739                //Drag and Drop file transfer for the contact list. 
    743                 NSString                *file; 
    744                 NSArray                 *files = [[info draggingPasteboard] propertyListForType:NSFilenamesPboardType]; 
    745                 NSEnumerator    *enumerator = [files objectEnumerator]; 
    746  
    747740                AIListContact   *targetFileTransferContact = [[adium contactController] preferredContactForContentType:CONTENT_FILE_TRANSFER_TYPE 
    748741                                                                                                                                                                                          forListContact:item]; 
    749742                if (targetFileTransferContact) { 
     743                        NSArray                 *files = nil; 
     744                        NSString                *file; 
     745                        NSEnumerator    *enumerator; 
     746                         
     747                        if ([availableType isEqualToString:NSFilenamesPboardType]) { 
     748                                files = [[info draggingPasteboard] propertyListForType:NSFilenamesPboardType]; 
     749                                 
     750                        } else if ([availableType isEqualToString:AIiTunesTrackPboardType]) { 
     751                                files = [[info draggingPasteboard] filesFromITunesDragPasteboard]; 
     752                        } 
     753 
     754                        enumerator = [files objectEnumerator]; 
    750755                        while ((file = [enumerator nextObject])) { 
    751756                                [[adium fileTransferController] sendFile:file toListContact:targetFileTransferContact]; 
    752757                        } 
     758 
    753759                } else { 
    754760                        AILogWithSignature(@"No contact available to receive files"); 
     
    756762                } 
    757763 
    758         } else if ([[[info draggingPasteboard] types] containsObject:NSRTFPboardType] || 
    759                                 [[[info draggingPasteboard] types] containsObject:NSURLPboardType] || 
    760                                 [[[info draggingPasteboard] types] containsObject:NSStringPboardType]) { 
     764        } else if ((availableType = [[info draggingPasteboard] availableTypeFromArray:[NSArray arrayWithObjects:NSRTFPboardType, 
     765                                                                                                                                                                   NSURLPboardType, NSStringPboardType, nil]])) { 
    761766                //Drag and drop text sending via the contact list. 
    762767                if ([item isKindOfClass:[AIListContact class]]) { 
     
    766771                        NSAttributedString                              *messageAttributedString = nil; 
    767772                         
    768                         if([[[info draggingPasteboard] types] containsObject:NSRTFPboardType]) { 
     773                        if ([availableType isEqualToString:NSRTFPboardType]) { 
    769774                                //for RTF data, we want to preserve the formatting, so use dataForType: 
    770775                                messageAttributedString = [NSAttributedString stringWithData:[[info draggingPasteboard] dataForType:NSRTFPboardType]]; 
    771776                        } 
    772                         else if([[[info draggingPasteboard] types] containsObject:NSURLPboardType]) { 
     777                        else if ([availableType isEqualToString:NSURLPboardType]) { 
    773778                                //NSURLPboardType contains an NSURL object 
    774                                 messageAttributedString = [NSAttributedString stringWithString:[[NSURL URLFromPasteboard:[info draggingPasteboard]]absoluteString]]; 
    775                         } 
    776                         else if([[[info draggingPasteboard] types] containsObject:NSStringPboardType]) { 
     779                                messageAttributedString = [NSAttributedString stringWithString:[[NSURL URLFromPasteboard:[info draggingPasteboard]] absoluteString]]; 
     780                        } 
     781                        else if ([availableType isEqualToString:NSStringPboardType]) { 
    777782                                //this is just plain text, so stringForType: works fine 
    778                                 messageAttributedString = [NSAttributedString stringWithString:[[info draggingPasteboard]stringForType:NSStringPboardType]]; 
     783                                messageAttributedString = [NSAttributedString stringWithString:[[info draggingPasteboard] stringForType:NSStringPboardType]]; 
    779784                        } 
    780785