1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-02-22 14:10:34 +00:00

Fix "NSFilenamesPboardType is deprecated" (#4221)

This commit is contained in:
A Cœur 2022-11-24 07:09:32 +08:00 committed by GitHub
parent b612020576
commit 3ecf0dfccd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 26 deletions

View file

@ -28,7 +28,7 @@ typedef NS_ENUM(unsigned int, addType) { //
@interface Controller
: NSObject<NSApplicationDelegate, NSURLDownloadDelegate, NSUserNotificationCenterDelegate, NSPopoverDelegate, NSSharingServiceDelegate, NSSharingServicePickerDelegate, NSSoundDelegate, NSToolbarDelegate, NSWindowDelegate, QLPreviewPanelDataSource, QLPreviewPanelDelegate, VDKQueueDelegate, SUUpdaterDelegate>
- (void)openFiles:(NSArray*)filenames addType:(addType)type forcePath:(NSString*)path;
- (void)openFiles:(NSArray<NSString*>*)filenames addType:(addType)type forcePath:(NSString*)path;
- (void)askOpenConfirmed:(AddWindowController*)addController add:(BOOL)add;
- (void)openCreatedFile:(NSNotification*)notification;
@ -52,7 +52,7 @@ typedef NS_ENUM(unsigned int, addType) { //
- (IBAction)resumeSelectedTorrents:(id)sender;
- (IBAction)resumeAllTorrents:(id)sender;
- (void)resumeTorrents:(NSArray*)torrents;
- (void)resumeTorrents:(NSArray<Torrent*>*)torrents;
- (IBAction)resumeSelectedTorrentsNoWait:(id)sender;
- (IBAction)resumeWaitingTorrents:(id)sender;
@ -84,7 +84,7 @@ typedef NS_ENUM(unsigned int, addType) { //
- (IBAction)announceSelectedTorrents:(id)sender;
- (IBAction)verifySelectedTorrents:(id)sender;
- (void)verifyTorrents:(NSArray*)torrents;
- (void)verifyTorrents:(NSArray<Torrent*>*)torrents;
@property(nonatomic, readonly) NSArray<Torrent*>* selectedTorrents;

View file

@ -665,7 +665,7 @@ void onTorrentCompletenessChanged(tr_torrent* tor, tr_completeness status, bool
"Main window -> 3rd bottom left button (remove all) tooltip");
[self.fTableView registerForDraggedTypes:@[ kTorrentTableViewDataType ]];
[self.fWindow registerForDraggedTypes:@[ NSFilenamesPboardType, NSURLPboardType ]];
[self.fWindow registerForDraggedTypes:@[ NSPasteboardTypeFileURL, NSPasteboardTypeURL ]];
//sort the sort menu items (localization is from strings file)
NSMutableArray* sortMenuItems = [NSMutableArray arrayWithCapacity:7];
@ -1184,12 +1184,12 @@ void onTorrentCompletenessChanged(tr_torrent* tor, tr_completeness status, bool
}
}
- (void)application:(NSApplication*)app openFiles:(NSArray*)filenames
- (void)application:(NSApplication*)app openFiles:(NSArray<NSString*>*)filenames
{
[self openFiles:filenames addType:ADD_MANUAL forcePath:nil];
}
- (void)openFiles:(NSArray*)filenames addType:(addType)type forcePath:(NSString*)path
- (void)openFiles:(NSArray<NSString*>*)filenames addType:(addType)type forcePath:(NSString*)path
{
BOOL deleteTorrentFile, canToggleDelete = NO;
switch (type)
@ -1695,7 +1695,7 @@ void onTorrentCompletenessChanged(tr_torrent* tor, tr_completeness status, bool
[self resumeTorrents:torrents];
}
- (void)resumeTorrents:(NSArray*)torrents
- (void)resumeTorrents:(NSArray<Torrent*>*)torrents
{
for (Torrent* torrent in torrents)
{
@ -3896,25 +3896,31 @@ void onTorrentCompletenessChanged(tr_torrent* tor, tr_completeness status, bool
- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)info
{
NSPasteboard* pasteboard = info.draggingPasteboard;
if ([pasteboard.types containsObject:NSFilenamesPboardType])
if ([pasteboard.types containsObject:NSPasteboardTypeFileURL])
{
//check if any torrent files can be added
BOOL torrent = NO;
NSArray* files = [pasteboard propertyListForType:NSFilenamesPboardType];
for (NSString* file in files)
NSArray<NSURL*>* files = [pasteboard readObjectsForClasses:@[ NSURL.class ]
options:@{ NSPasteboardURLReadingFileURLsOnlyKey : @YES }];
for (NSURL* file in files)
{
if ([[NSWorkspace.sharedWorkspace typeOfFile:file error:NULL] isEqualToString:@"org.bittorrent.torrent"] ||
if ([[NSWorkspace.sharedWorkspace typeOfFile:file.path error:NULL] isEqualToString:@"org.bittorrent.torrent"] ||
[file.pathExtension caseInsensitiveCompare:@"torrent"] == NSOrderedSame)
{
torrent = YES;
auto metainfo = tr_torrent_metainfo{};
if (metainfo.parseTorrentFile(file.UTF8String))
if (metainfo.parseTorrentFile(file.path.UTF8String))
{
if (!self.fOverlayWindow)
{
self.fOverlayWindow = [[DragOverlayWindow alloc] initWithLib:self.fLib forWindow:self.fWindow];
}
[self.fOverlayWindow setTorrents:files];
NSMutableArray<NSString*>* filesToOpen = [NSMutableArray arrayWithCapacity:files.count];
for (NSURL* file in files)
{
[filesToOpen addObject:file.path];
}
[self.fOverlayWindow setTorrents:filesToOpen];
return NSDragOperationCopy;
}
@ -3933,7 +3939,7 @@ void onTorrentCompletenessChanged(tr_torrent* tor, tr_completeness status, bool
return NSDragOperationCopy;
}
}
else if ([pasteboard.types containsObject:NSURLPboardType])
else if ([pasteboard.types containsObject:NSPasteboardTypeURL])
{
if (!self.fOverlayWindow)
{
@ -3963,23 +3969,24 @@ void onTorrentCompletenessChanged(tr_torrent* tor, tr_completeness status, bool
}
NSPasteboard* pasteboard = info.draggingPasteboard;
if ([pasteboard.types containsObject:NSFilenamesPboardType])
if ([pasteboard.types containsObject:NSPasteboardTypeFileURL])
{
BOOL torrent = NO, accept = YES;
//create an array of files that can be opened
NSArray* files = [pasteboard propertyListForType:NSFilenamesPboardType];
NSMutableArray* filesToOpen = [NSMutableArray arrayWithCapacity:files.count];
for (NSString* file in files)
NSArray<NSURL*>* files = [pasteboard readObjectsForClasses:@[ NSURL.class ]
options:@{ NSPasteboardURLReadingFileURLsOnlyKey : @YES }];
NSMutableArray<NSString*>* filesToOpen = [NSMutableArray arrayWithCapacity:files.count];
for (NSURL* file in files)
{
if ([[NSWorkspace.sharedWorkspace typeOfFile:file error:NULL] isEqualToString:@"org.bittorrent.torrent"] ||
if ([[NSWorkspace.sharedWorkspace typeOfFile:file.path error:NULL] isEqualToString:@"org.bittorrent.torrent"] ||
[file.pathExtension caseInsensitiveCompare:@"torrent"] == NSOrderedSame)
{
torrent = YES;
auto metainfo = tr_torrent_metainfo{};
if (metainfo.parseTorrentFile(file.UTF8String))
if (metainfo.parseTorrentFile(file.path.UTF8String))
{
[filesToOpen addObject:file];
[filesToOpen addObject:file.path];
}
}
}
@ -3992,7 +3999,7 @@ void onTorrentCompletenessChanged(tr_torrent* tor, tr_completeness status, bool
{
if (!torrent && files.count == 1)
{
[CreatorWindowController createTorrentFile:self.fLib forFile:[NSURL fileURLWithPath:files[0]]];
[CreatorWindowController createTorrentFile:self.fLib forFile:files[0]];
}
else
{
@ -4002,7 +4009,7 @@ void onTorrentCompletenessChanged(tr_torrent* tor, tr_completeness status, bool
return accept;
}
else if ([pasteboard.types containsObject:NSURLPboardType])
else if ([pasteboard.types containsObject:NSPasteboardTypeURL])
{
NSURL* url;
if ((url = [NSURL URLFromPasteboard:pasteboard]))
@ -4094,7 +4101,7 @@ void onTorrentCompletenessChanged(tr_torrent* tor, tr_completeness status, bool
[self.fWindow.toolbar validateVisibleItems];
}
- (NSArray*)quickLookableTorrents
- (NSArray<Torrent*>*)quickLookableTorrents
{
NSArray* selectedTorrents = self.fTableView.selectedTorrents;
NSMutableArray* qlArray = [NSMutableArray arrayWithCapacity:selectedTorrents.count];

View file

@ -10,7 +10,7 @@
- (instancetype)initWithLib:(tr_session*)lib forWindow:(NSWindow*)window;
- (void)setTorrents:(NSArray*)files;
- (void)setTorrents:(NSArray<NSString*>*)files;
- (void)setFile:(NSString*)file;
- (void)setURL:(NSString*)url;

View file

@ -59,7 +59,7 @@
[NSNotificationCenter.defaultCenter removeObserver:self];
}
- (void)setTorrents:(NSArray*)files
- (void)setTorrents:(NSArray<NSString*>*)files
{
uint64_t size = 0;
NSUInteger count = 0;