register to automatically accept when a user clicks a magnet link

This commit is contained in:
Mitchell Livingston
2009-11-26 16:38:21 +00:00
parent 400ed672fc
commit f401399efd
4 changed files with 50 additions and 34 deletions

View File

@@ -127,7 +127,7 @@ typedef enum
- (void) invalidOpenAlert: (NSString *) filename;
- (void) duplicateOpenAlert: (NSString *) name;
- (void) openURL: (NSURL *) torrentURL;
- (void) openURL: (NSString *) urlString;
- (void) openURLEndSheet: (id) sender;
- (void) openURLCancelEndSheet: (id) sender;
- (void) openURLShowSheet: (id) sender;

View File

@@ -345,6 +345,14 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
tr_sessionSetRPCCallback(fLib, rpcCallback, self);
//register for dock icon drags
[[NSAppleEventManager sharedAppleEventManager] setEventHandler: self andSelector: @selector(handleOpenContentsEvent:replyEvent:)
forEventClass: kCoreEventClass andEventID: kAEOpenContents];
//register for magnet URLs
[[NSAppleEventManager sharedAppleEventManager] setEventHandler: self andSelector: @selector(handleOpenContentsEvent:replyEvent:)
forEventClass: kInternetEventClass andEventID: kAEGetURL];
[GrowlApplicationBridge setGrowlDelegate: self];
[[UKKQueue sharedFileWatcher] setDelegate: self];
@@ -566,10 +574,6 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
{
[NSApp setServicesProvider: self];
//register for dock icon drags
[[NSAppleEventManager sharedAppleEventManager] setEventHandler: self andSelector: @selector(handleOpenContentsEvent:replyEvent:)
forEventClass: kCoreEventClass andEventID: kAEOpenContents];
//auto importing
[self checkAutoImportDirectory];
@@ -757,7 +761,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
urlString = [directObject stringValue];
if (urlString)
[self openURL: [NSURL URLWithString: urlString]];
[self openURL: urlString];
}
- (void) download: (NSURLDownload *) download decideDestinationWithSuggestedFilename: (NSString *) suggestedName
@@ -1080,9 +1084,31 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
[alert release];
}
- (void) openURL: (NSURL *) url
- (void) openURL: (NSString *) urlString
{
[[NSURLDownload alloc] initWithRequest: [NSURLRequest requestWithURL: url] delegate: self];
if ([urlString rangeOfString: @"magnet:" options: (NSAnchoredSearch | NSCaseInsensitiveSearch)].location != NSNotFound)
[self openMagnet: urlString];
else
{
if ([urlString rangeOfString: @"://"].location == NSNotFound)
{
if ([urlString rangeOfString: @"."].location == NSNotFound)
{
NSInteger beforeCom;
if ((beforeCom = [urlString rangeOfString: @"/"].location) != NSNotFound)
urlString = [NSString stringWithFormat: @"http://www.%@.com/%@",
[urlString substringToIndex: beforeCom],
[urlString substringFromIndex: beforeCom + 1]];
else
urlString = [NSString stringWithFormat: @"http://www.%@.com/", urlString];
}
else
urlString = [@"http://" stringByAppendingString: urlString];
}
NSURL * url = [NSURL URLWithString: urlString];
[[NSURLDownload alloc] initWithRequest: [NSURLRequest requestWithURL: url] delegate: self];
}
}
- (void) openURLShowSheet: (id) sender
@@ -1129,30 +1155,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
return;
NSString * urlString = [fURLSheetTextField stringValue];
if ([urlString rangeOfString: @"magnet:" options: (NSAnchoredSearch | NSCaseInsensitiveSearch)].location != NSNotFound)
[self openMagnet: urlString];
else
{
if ([urlString rangeOfString: @"://"].location == NSNotFound)
{
if ([urlString rangeOfString: @"."].location == NSNotFound)
{
NSInteger beforeCom;
if ((beforeCom = [urlString rangeOfString: @"/"].location) != NSNotFound)
urlString = [NSString stringWithFormat: @"http://www.%@.com/%@",
[urlString substringToIndex: beforeCom],
[urlString substringFromIndex: beforeCom + 1]];
else
urlString = [NSString stringWithFormat: @"http://www.%@.com/", urlString];
}
else
urlString = [@"http://" stringByAppendingString: urlString];
}
NSURL * url = [NSURL URLWithString: urlString];
[self performSelectorOnMainThread: @selector(openURL:) withObject: url waitUntilDone: NO];
}
[self performSelectorOnMainThread: @selector(openURL:) withObject: urlString waitUntilDone: NO];
}
- (void) createFile: (id) sender
@@ -2875,7 +2878,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
NSURL * url;
if ((url = [NSURL URLFromPasteboard: pasteboard]))
{
[self openURL: url];
[[NSURLDownload alloc] initWithRequest: [NSURLRequest requestWithURL: url] delegate: self];
return YES;
}
}

View File

@@ -45,6 +45,18 @@
<string>TR##</string>
<key>CFBundleShortVersionString</key>
<string>VERSION_STRING_INFOPLIST</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>magnet</string>
<string>dht</string>
</array>
<key>CFBundleURLName</key>
<string>BitTorrent Magnet URL</string>
</dict>
</array>
<key>CFBundleVersion</key>
<string>SVN_REVISION_NUM</string>
<key>CFBundleGetInfoString</key>

View File

@@ -909,7 +909,8 @@ int trashDataFile(const char * filename)
- (NSString *) progressString
{
if ([self isMagnet])
return NSLocalizedString(@"Magnetized transfer - acquiring torrent information", "Torrent -> progress string");
return [NSString stringWithFormat: @"%@ - %@", NSLocalizedString(@"Magnetized transfer", "Torrent -> progress string"),
NSLocalizedString(@"torrent information needed", "Torrent -> progress string")];
NSString * string;