From 3a94e0b7b483aed5947a58511a06686ece5a386e Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Thu, 17 May 2007 23:14:53 +0000 Subject: [PATCH] allow torrent files not ending in .torrent to be opened by dragging to the window --- macosx/Badger.m | 9 +++++---- macosx/Controller.m | 21 +++++++++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/macosx/Badger.m b/macosx/Badger.m index 274e58c29..0a9554de5 100644 --- a/macosx/Badger.m +++ b/macosx/Badger.m @@ -124,8 +124,8 @@ * uploadRateString = checkUpload && uploadRate >= 0.1 ? [NSString stringForSpeedAbbrev: uploadRate] : nil; NSImage * dockIcon = nil; - BOOL speedBadge; - if (speedBadge = (uploadRateString || downloadRateString)) + BOOL speedChange; + if (speedChange = (uploadRateString || downloadRateString)) { dockIcon = [fDockIcon copy]; @@ -171,14 +171,15 @@ } //update dock badge - if (baseChange || fSpeedBadge || speedBadge) + if (baseChange || fSpeedBadge || speedChange) { if (!dockIcon) dockIcon = [fDockIcon retain]; [NSApp setApplicationIconImage: dockIcon]; [dockIcon release]; + + fSpeedBadge = speedChange; } - fSpeedBadge = speedBadge; [fLock unlock]; } diff --git a/macosx/Controller.m b/macosx/Controller.m index c7c476321..af2bffa04 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -2007,15 +2007,21 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy NSPasteboard * pasteboard = [info draggingPasteboard]; if ([[pasteboard types] containsObject: NSFilenamesPboardType]) { - //check if any files to add have "torrent" as an extension + //check if any files can be added NSEnumerator * enumerator = [[pasteboard propertyListForType: NSFilenamesPboardType] objectEnumerator]; NSString * file; while ((file = [enumerator nextObject])) - if ([[file pathExtension] caseInsensitiveCompare: @"torrent"] == NSOrderedSame) + { + tr_torrent_t * tempTor; + int error; + if ((tempTor = tr_torrentInit(fLib, [file UTF8String], NULL, 0, &error))) { + tr_torrentClose(fLib, tempTor); + [fTableView setDropRow: -1 dropOperation: NSTableViewDropOn]; return NSDragOperationGeneric; } + } } else if ([[pasteboard types] containsObject: NSURLPboardType]) { @@ -2038,13 +2044,20 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy NSPasteboard * pasteboard = [info draggingPasteboard]; if ([[pasteboard types] containsObject: NSFilenamesPboardType]) { - //create an array of files with the "torrent" extension + //create an array of files that can be opened NSMutableArray * filesToOpen = [[NSMutableArray alloc] init]; NSEnumerator * enumerator = [[pasteboard propertyListForType: NSFilenamesPboardType] objectEnumerator]; NSString * file; while ((file = [enumerator nextObject])) - if ([[file pathExtension] caseInsensitiveCompare: @"torrent"] == NSOrderedSame) + { + tr_torrent_t * tempTor; + int error; + if ((tempTor = tr_torrentInit(fLib, [file UTF8String], NULL, 0, &error))) + { + tr_torrentClose(fLib, tempTor); [filesToOpen addObject: file]; + } + } [self application: NSApp openFiles: filesToOpen]; [filesToOpen release];