mirror of
https://github.com/transmission/transmission
synced 2024-12-25 09:13:06 +00:00
Patch by Brian Webster to automatically download and open torrents by dragging url's onto the window/dock icon.
This commit is contained in:
parent
8ebdd6070a
commit
ed82ce2223
4 changed files with 362 additions and 265 deletions
|
@ -91,12 +91,14 @@
|
|||
Badger * fBadger;
|
||||
|
||||
NSMutableArray * fAutoImportedNames;
|
||||
NSMutableDictionary * fPendingTorrentDownloads;
|
||||
}
|
||||
|
||||
- (void) openFiles: (NSArray *) filenames;
|
||||
- (void) openFiles: (NSArray *) filenames ignoreDownloadFolder: (BOOL) ignore;
|
||||
- (void) openFilesAsk: (NSMutableArray *) files;
|
||||
- (void) openShowSheet: (id) sender;
|
||||
- (void) openURL: (NSURL *) torrentURL;
|
||||
|
||||
- (void) quitSheetDidEnd: (NSWindow *) sheet returnCode: (int) returnCode contextInfo: (void *) contextInfo;
|
||||
|
||||
|
|
|
@ -107,6 +107,7 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
|
|||
|
||||
fTorrents = [[NSMutableArray alloc] initWithCapacity: 10];
|
||||
fDisplayedTorrents = [[NSMutableArray alloc] initWithCapacity: 10];
|
||||
fPendingTorrentDownloads = [[NSMutableDictionary alloc] init];
|
||||
|
||||
fDefaults = [NSUserDefaults standardUserDefaults];
|
||||
|
||||
|
@ -140,6 +141,7 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
|
|||
[fFilterType release];
|
||||
|
||||
[fAutoImportedNames release];
|
||||
[fPendingTorrentDownloads release];
|
||||
|
||||
tr_close(fLib);
|
||||
[super dealloc];
|
||||
|
@ -217,6 +219,7 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
|
|||
[[fTableView tableColumnWithIdentifier: @"Torrent"] setDataCell: [[TorrentCell alloc] init]];
|
||||
|
||||
[fTableView registerForDraggedTypes: [NSArray arrayWithObjects: NSFilenamesPboardType,
|
||||
NSURLPboardType,
|
||||
TORRENT_TABLE_VIEW_DATA_TYPE, nil]];
|
||||
|
||||
//register for sleep notifications
|
||||
|
@ -348,6 +351,16 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
|
|||
[self checkAutoImportDirectory];
|
||||
}
|
||||
|
||||
- (void) applicationDidFinishLaunching: (NSNotification *) notification
|
||||
{
|
||||
[NSApp setServicesProvider:self];
|
||||
|
||||
//register for dock icon drags
|
||||
[[NSAppleEventManager sharedAppleEventManager] setEventHandler: self
|
||||
andSelector: @selector(handleOpenContentsEvent:replyEvent:)
|
||||
forEventClass: kCoreEventClass andEventID: kAEOpenContents];
|
||||
}
|
||||
|
||||
- (BOOL) applicationShouldHandleReopen: (NSApplication *) app hasVisibleWindows: (BOOL) visibleWindows
|
||||
{
|
||||
if (![fWindow isVisible] && ![[fPrefsController window] isVisible])
|
||||
|
@ -439,10 +452,67 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
|
|||
[self openFiles: filenames ignoreDownloadFolder: NO];
|
||||
}
|
||||
|
||||
- (void) handleOpenContentsEvent: (NSAppleEventDescriptor *) event replyEvent: (NSAppleEventDescriptor *) replyEvent
|
||||
{
|
||||
NSURL * url;
|
||||
NSString * urlString;
|
||||
|
||||
NSAppleEventDescriptor * directObject = [event paramDescriptorForKeyword: keyDirectObject];
|
||||
if ([directObject descriptorType] == typeAEList)
|
||||
{
|
||||
unsigned i;
|
||||
for (i = 1; i <= [directObject numberOfItems]; i++)
|
||||
if ((urlString = [[directObject descriptorAtIndex: i] stringValue]))
|
||||
{
|
||||
url = [[NSURL alloc] initWithString: urlString];
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if ((urlString = [directObject stringValue]))
|
||||
url = [[NSURL alloc] initWithString: urlString];
|
||||
else;
|
||||
|
||||
if (url)
|
||||
{
|
||||
[self openURL: url];
|
||||
[url release];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) openURL: (NSURL *) url
|
||||
{
|
||||
#warning check for .torrent
|
||||
NSURLDownload * torrentDownload = [[NSURLDownload alloc] initWithRequest: [NSURLRequest requestWithURL: url]
|
||||
delegate: self];
|
||||
|
||||
NSString * tempPath = [NSTemporaryDirectory() stringByAppendingPathComponent: [[url path] lastPathComponent]];
|
||||
NSLog(tempPath);[torrentDownload setDestination: tempPath allowOverwrite: NO];
|
||||
[fPendingTorrentDownloads setObject: tempPath forKey: url];
|
||||
[torrentDownload release];
|
||||
}
|
||||
|
||||
- (void) download: (NSURLDownload *)download didFailWithError: (NSError *) error
|
||||
{
|
||||
[fPendingTorrentDownloads removeObjectForKey: [[download request] URL]];
|
||||
|
||||
NSRunAlertPanel(NSLocalizedString(@"Torrent download failed",
|
||||
@"Torrent download error -> title"), [NSString stringWithFormat:
|
||||
NSLocalizedString(@"The torrent could not be downloaded from %@ because an error occurred (%@)",
|
||||
@"Torrent download failed -> message"), [[[download request] URL] absoluteString],
|
||||
[error localizedDescription]], NSLocalizedString(@"OK", @"Torrent download failed -> button"), nil, nil);
|
||||
}
|
||||
|
||||
- (void) downloadDidFinish: (NSURLDownload *) download
|
||||
{
|
||||
#warning try to open, if not delete
|
||||
|
||||
[self openFiles: [NSArray arrayWithObject: [fPendingTorrentDownloads objectForKey: [[download request] URL]]]
|
||||
ignoreDownloadFolder: NO];
|
||||
}
|
||||
|
||||
- (void) openFiles: (NSArray *) filenames ignoreDownloadFolder: (BOOL) ignore
|
||||
{
|
||||
NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"], * torrentPath;
|
||||
|
||||
NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"];
|
||||
if (ignore || [downloadChoice isEqualToString: @"Ask"])
|
||||
{
|
||||
[self openFilesAsk: [filenames mutableCopy]];
|
||||
|
@ -450,6 +520,7 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
|
|||
}
|
||||
|
||||
Torrent * torrent;
|
||||
NSString * torrentPath;
|
||||
NSEnumerator * enumerator = [filenames objectEnumerator];
|
||||
while ((torrentPath = [enumerator nextObject]))
|
||||
{
|
||||
|
@ -1639,6 +1710,11 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
|
|||
return NSDragOperationGeneric;
|
||||
}
|
||||
}
|
||||
else if ([[pasteboard types] containsObject: NSURLPboardType])
|
||||
{
|
||||
[fTableView setDropRow: row dropOperation: NSTableViewDropAbove];
|
||||
return NSDragOperationGeneric;
|
||||
}
|
||||
else if ([[pasteboard types] containsObject: TORRENT_TABLE_VIEW_DATA_TYPE])
|
||||
{
|
||||
[fTableView setDropRow: row dropOperation: NSTableViewDropAbove];
|
||||
|
@ -1665,7 +1741,13 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
|
|||
[self application: NSApp openFiles: filesToOpen];
|
||||
[filesToOpen release];
|
||||
}
|
||||
else
|
||||
else if ([[pasteboard types] containsObject: NSURLPboardType])
|
||||
{
|
||||
NSURL * url;
|
||||
if ((url = [NSURL URLFromPasteboard:pasteboard]))
|
||||
[self openURL: url];
|
||||
}
|
||||
else if ([[pasteboard types] containsObject: TORRENT_TABLE_VIEW_DATA_TYPE])
|
||||
{
|
||||
//remember selected rows if needed
|
||||
NSArray * selectedTorrents = nil;
|
||||
|
@ -1717,6 +1799,7 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
|
|||
[indexSet release];
|
||||
}
|
||||
}
|
||||
else;
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
|
|
@ -49,6 +49,18 @@
|
|||
<string>MainMenu</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
<key>NSServices</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>NSPortName</key>
|
||||
<string>Transmission</string>
|
||||
<key>NSSendTypes</key>
|
||||
<array>
|
||||
<string>NSStringPboardType</string>
|
||||
<string>NSURLPboardType</string>
|
||||
</array>
|
||||
</dict>
|
||||
</array>
|
||||
<key>SUCheckAtStartup</key>
|
||||
<false/>
|
||||
<key>SUFeedURL</key>
|
||||
|
|
|
@ -96,7 +96,7 @@
|
|||
+ (NSString *) stringForRatioWithDownload: (uint64_t) down upload: (uint64_t) up
|
||||
{
|
||||
if (down == 0)
|
||||
return up == 0 ? @"N/A" : [NSString stringWithUTF8String: "\xE2\x88\x9E"];
|
||||
return up == 0 ? NSLocalizedString(@"N/A", "No Ratio") : [NSString stringWithUTF8String: "\xE2\x88\x9E"];
|
||||
|
||||
float ratio = (float) up / (float) down;
|
||||
if (ratio < 10.0)
|
||||
|
|
Loading…
Reference in a new issue